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
This commit is contained in:
Adnan Begovic 2016-03-25 12:37:26 -07:00
parent ccdb292eec
commit 279ce42664
4 changed files with 27 additions and 2 deletions

View File

@ -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());
}

View File

@ -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";
}
}

View File

@ -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();

View File

@ -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();