cmsdk: Mandate telephony feature xml's for service implementation.

The feature xml plays two roles:

      1) To allow sdk interface (constructor) to throw when system
      service is unavailable. This allows for clearer platform
      development debugging.

      2) To allow for simpler disambiguation of what services to
      instrument in a modular environment.

Change-Id: Ib8e41130f143f784088b4566589a4ddc58aa2ace
TICKET: CYNGNOS-2291
This commit is contained in:
Adnan Begovic 2016-03-24 17:34:54 -07:00
parent fe7fd1d489
commit c406211045
3 changed files with 24 additions and 2 deletions

View File

@ -186,8 +186,13 @@ public class CMTelephonyManagerService extends SystemService {
if (localLOGD) { if (localLOGD) {
Log.d(TAG, "CM telephony manager service start: " + this); Log.d(TAG, "CM telephony manager service start: " + this);
} }
if (mContext.getPackageManager().hasSystemFeature(
CMContextConstants.Features.TELEPHONY)) {
publishBinderService(CMContextConstants.CM_TELEPHONY_MANAGER_SERVICE, mService); publishBinderService(CMContextConstants.CM_TELEPHONY_MANAGER_SERVICE, mService);
} else {
Log.wtf(TAG, "CM telephony service started by system server but feature xml not" +
" declared. Not publishing binder service!");
}
mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
} }

View File

@ -149,5 +149,13 @@ public final class CMContextConstants {
*/ */
@SdkConstant(SdkConstant.SdkConstantType.FEATURE) @SdkConstant(SdkConstant.SdkConstantType.FEATURE)
public static final String APP_SUGGEST = "org.cyanogenmod.appsuggest"; public static final String APP_SUGGEST = "org.cyanogenmod.appsuggest";
/**
* Feature for {@link PackageManager#getSystemAvailableFeatures} and
* {@link PackageManager#hasSystemFeature}: The device includes the cm telephony service
* utilized by the cmsdk.
*/
@SdkConstant(SdkConstant.SdkConstantType.FEATURE)
public static final String TELEPHONY = "org.cyanogenmod.telephony";
} }
} }

View File

@ -26,6 +26,8 @@ import android.util.Slog;
import java.util.List; import java.util.List;
import cyanogenmod.app.CMContextConstants;
/** /**
* The CMTelephonyManager allows you to view and manage the phone state and * The CMTelephonyManager allows you to view and manage the phone state and
* the data connection, with multiple SIMs support. * the data connection, with multiple SIMs support.
@ -55,6 +57,13 @@ public class CMTelephonyManager {
mContext = context; mContext = context;
} }
sService = getService(); sService = getService();
if (context.getPackageManager().hasSystemFeature(CMContextConstants.Features.TELEPHONY)
&& sService == null) {
throw new RuntimeException("Unable to get CMTelephonyManagerService. " +
"The service either crashed, was not started, or the interface has been " +
"called to early in SystemServer init");
}
} }
/** /**