diff options
author | Adnan Begovic <adnan@cyngn.com> | 2016-03-25 12:37:26 -0700 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2016-03-25 14:14:14 -0700 |
commit | 279ce42664be4a958e01dd41fecefbe36eaa5074 (patch) | |
tree | 115d30726290d53d449aeaadf144308c08019199 | |
parent | ccdb292eecc53c1343eaae0f4e0e9342326bad16 (diff) | |
download | vendor_cmsdk-279ce42664be4a958e01dd41fecefbe36eaa5074.zip vendor_cmsdk-279ce42664be4a958e01dd41fecefbe36eaa5074.tar.gz vendor_cmsdk-279ce42664be4a958e01dd41fecefbe36eaa5074.tar.bz2 |
cmsdk: Mandate performance 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: I50f5993ff9c5107fdeaa9a5aa95377235eb3ac02
TICKET: CYNGNOS-2294
4 files changed, 27 insertions, 2 deletions
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java index 4b03ba0..0665a5b 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/PerformanceManagerService.java @@ -29,6 +29,7 @@ import android.os.Message; import android.os.Process; import android.os.SystemProperties; import android.text.TextUtils; +import android.util.Log; import android.util.Slog; import com.android.server.ServiceThread; @@ -110,7 +111,13 @@ public class PerformanceManagerService extends SystemService { @Override public void onStart() { - publishBinderService(CMContextConstants.CM_PERFORMANCE_SERVICE, mBinder); + if (mContext.getPackageManager().hasSystemFeature( + CMContextConstants.Features.PERFORMANCE)) { + publishBinderService(CMContextConstants.CM_PERFORMANCE_SERVICE, mBinder); + } else { + Log.wtf(TAG, "CM performance service started by system server but feature xml not" + + " declared. Not publishing binder service!"); + } publishLocalService(PerformanceManagerInternal.class, new LocalService()); } diff --git a/src/java/cyanogenmod/app/CMContextConstants.java b/src/java/cyanogenmod/app/CMContextConstants.java index 83a7c2d..e34f211 100644 --- a/src/java/cyanogenmod/app/CMContextConstants.java +++ b/src/java/cyanogenmod/app/CMContextConstants.java @@ -165,5 +165,13 @@ public final class CMContextConstants { */ @SdkConstant(SdkConstant.SdkConstantType.FEATURE) public static final String THEMES = "org.cyanogenmod.theme"; + + /** + * Feature for {@link PackageManager#getSystemAvailableFeatures} and + * {@link PackageManager#hasSystemFeature}: The device includes the cm performance service + * utilized by the cmsdk. + */ + @SdkConstant(SdkConstant.SdkConstantType.FEATURE) + public static final String PERFORMANCE = "org.cyanogenmod.performance"; } } diff --git a/src/java/cyanogenmod/power/PerformanceManager.java b/src/java/cyanogenmod/power/PerformanceManager.java index 393e905..9b44399 100644 --- a/src/java/cyanogenmod/power/PerformanceManager.java +++ b/src/java/cyanogenmod/power/PerformanceManager.java @@ -78,7 +78,12 @@ public class PerformanceManager { private PerformanceManager(Context context) { sService = getService(); - + if (context.getPackageManager().hasSystemFeature( + CMContextConstants.Features.PERFORMANCE) && sService == null) { + throw new RuntimeException("Unable to get PerformanceManagerService. The service" + + " either crashed, was not started, or the interface has been called to early" + + " in SystemServer init"); + } try { if (sService != null) { mNumberOfProfiles = sService.getNumberOfProfiles(); diff --git a/tests/src/org/cyanogenmod/tests/power/unit/PerfomanceManagerTest.java b/tests/src/org/cyanogenmod/tests/power/unit/PerfomanceManagerTest.java index 7b00a5c..7bc3430 100644 --- a/tests/src/org/cyanogenmod/tests/power/unit/PerfomanceManagerTest.java +++ b/tests/src/org/cyanogenmod/tests/power/unit/PerfomanceManagerTest.java @@ -17,6 +17,8 @@ package org.cyanogenmod.tests.power.unit; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; + +import cyanogenmod.app.CMContextConstants; import cyanogenmod.power.IPerformanceManager; import cyanogenmod.power.PerformanceManager; @@ -34,6 +36,9 @@ public class PerfomanceManagerTest extends AndroidTestCase { @Override protected void setUp() throws Exception { super.setUp(); + // Only run this if we support performance abstraction + org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature( + CMContextConstants.Features.PERFORMANCE)); mCMPerformanceManager = PerformanceManager.getInstance(mContext); // Save the perf profile for later restore. mSavedPerfProfile = mCMPerformanceManager.getPowerProfile(); |