cmsdk: Mandate profile 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. TICKET: CYNGNOS-2288 Change-Id: Id0adcc1eaa4a0512faf25f11057c45dc2ac733e0
This commit is contained in:
parent
cdf85adde1
commit
21a567428d
@ -169,7 +169,13 @@ public class ProfileManagerService extends SystemService {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mHandler = new Handler(mHandlerCallback);
|
||||
publishBinderService(CMContextConstants.CM_PROFILE_SERVICE, mService);
|
||||
if (context.getPackageManager().hasSystemFeature(
|
||||
CMContextConstants.Features.PROFILES)) {
|
||||
publishBinderService(CMContextConstants.CM_PROFILE_SERVICE, mService);
|
||||
} else {
|
||||
Log.wtf(TAG, "CM profile service started by system server but feature xml not" +
|
||||
" declared. Not publishing binder service!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -133,5 +133,13 @@ public final class CMContextConstants {
|
||||
*/
|
||||
@SdkConstant(SdkConstant.SdkConstantType.FEATURE)
|
||||
public static final String STATUSBAR = "org.cyanogenmod.statusbar";
|
||||
|
||||
/**
|
||||
* Feature for {@link PackageManager#getSystemAvailableFeatures} and
|
||||
* {@link PackageManager#hasSystemFeature}: The device includes the cm profiles service
|
||||
* utilized by the cmsdk.
|
||||
*/
|
||||
@SdkConstant(SdkConstant.SdkConstantType.FEATURE)
|
||||
public static final String PROFILES = "org.cyanogenmod.profiles";
|
||||
}
|
||||
}
|
||||
|
@ -221,6 +221,13 @@ public class ProfileManager {
|
||||
mContext = context;
|
||||
}
|
||||
sService = getService();
|
||||
|
||||
if (context.getPackageManager().hasSystemFeature(
|
||||
cyanogenmod.app.CMContextConstants.Features.PROFILES) && sService == null) {
|
||||
throw new RuntimeException("Unable to get ProfileManagerService. The service either" +
|
||||
" crashed, was not started, or the interface has been called to early in" +
|
||||
" SystemServer init");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,7 @@ package org.cyanogenmod.tests.profiles.unit;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import cyanogenmod.app.CMContextConstants;
|
||||
import cyanogenmod.app.ProfileManager;
|
||||
import cyanogenmod.app.IProfileManager;
|
||||
import cyanogenmod.providers.CMSettings;
|
||||
@ -32,6 +33,9 @@ public class ProfileManagerTest extends AndroidTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mProfileManager = ProfileManager.getInstance(mContext);
|
||||
// Only run this if we support profiles service
|
||||
org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
|
||||
CMContextConstants.Features.PROFILES));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
|
@ -23,6 +23,7 @@ import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import cyanogenmod.app.CMContextConstants;
|
||||
import cyanogenmod.app.Profile;
|
||||
import cyanogenmod.profiles.AirplaneModeSettings;
|
||||
import cyanogenmod.profiles.BrightnessSettings;
|
||||
@ -39,6 +40,9 @@ public class ProfileTest extends AndroidTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// Only run this if we support profiles service
|
||||
org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
|
||||
CMContextConstants.Features.PROFILES));
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
|
Loading…
Reference in New Issue
Block a user