cmsdk: Mandate partner 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: Ic980225df9c115e97f7147cf043cf92bbb225f01 TICKET: CYNGNOS-2293
This commit is contained in:
parent
279ce42664
commit
b271dcf279
|
@ -60,7 +60,13 @@ public class PartnerInterfaceService extends SystemService {
|
|||
public PartnerInterfaceService(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
publishBinderService(CMContextConstants.CM_PARTNER_INTERFACE, mService);
|
||||
if (mContext.getPackageManager().hasSystemFeature(
|
||||
CMContextConstants.Features.PERFORMANCE)) {
|
||||
publishBinderService(CMContextConstants.CM_PARTNER_INTERFACE, mService);
|
||||
} else {
|
||||
Log.wtf(TAG, "CM partner service started by system server but feature xml not" +
|
||||
" declared. Not publishing binder service!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -173,5 +173,13 @@ public final class CMContextConstants {
|
|||
*/
|
||||
@SdkConstant(SdkConstant.SdkConstantType.FEATURE)
|
||||
public static final String PERFORMANCE = "org.cyanogenmod.performance";
|
||||
|
||||
/**
|
||||
* Feature for {@link PackageManager#getSystemAvailableFeatures} and
|
||||
* {@link PackageManager#hasSystemFeature}: The device includes the cm partner service
|
||||
* utilized by the cmsdk.
|
||||
*/
|
||||
@SdkConstant(SdkConstant.SdkConstantType.FEATURE)
|
||||
public static final String PARTNER = "org.cyanogenmod.partner";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,12 @@ public class PartnerInterface {
|
|||
mContext = context;
|
||||
}
|
||||
sService = getService();
|
||||
if (context.getPackageManager().hasSystemFeature(
|
||||
CMContextConstants.Features.PARTNER) && sService == null) {
|
||||
throw new RuntimeException("Unable to get PartnerInterfaceService. The service" +
|
||||
" either crashed, was not started, or the interface has been called to early" +
|
||||
" in SystemServer init");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,8 @@ import android.test.suitebuilder.annotation.SmallTest;
|
|||
import android.provider.Settings;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import cyanogenmod.app.CMContextConstants;
|
||||
import cyanogenmod.app.PartnerInterface;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -45,6 +47,9 @@ public class CMPartnerInterfaceTest extends AndroidTestCase {
|
|||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// Only run this if we support partner interfaces
|
||||
org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
|
||||
CMContextConstants.Features.PARTNER));
|
||||
mPartnerInterface = PartnerInterface.getInstance(getContext());
|
||||
|
||||
setupAirplaneModeTests();
|
||||
|
|
Loading…
Reference in New Issue