diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java index 37eb76f..eb39063 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/ProfileManagerService.java @@ -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 diff --git a/src/java/cyanogenmod/app/CMContextConstants.java b/src/java/cyanogenmod/app/CMContextConstants.java index 761ce09..622732d 100644 --- a/src/java/cyanogenmod/app/CMContextConstants.java +++ b/src/java/cyanogenmod/app/CMContextConstants.java @@ -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"; } } diff --git a/src/java/cyanogenmod/app/ProfileManager.java b/src/java/cyanogenmod/app/ProfileManager.java index 499f583..c2470cb 100644 --- a/src/java/cyanogenmod/app/ProfileManager.java +++ b/src/java/cyanogenmod/app/ProfileManager.java @@ -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"); + } } /** diff --git a/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileManagerTest.java b/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileManagerTest.java index 37338b0..d044150 100644 --- a/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileManagerTest.java +++ b/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileManagerTest.java @@ -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 diff --git a/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java b/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java index f48b805..38ba56e 100644 --- a/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java +++ b/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java @@ -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