cmsdk: Mandate cmhw feature xml's for service implementation.

The features 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: I41f4ac60af076743909c6090fd50c3ad045bc9e1
This commit is contained in:
Adnan Begovic 2016-03-14 08:13:57 -07:00
parent 19b267dfff
commit a335ba39c2
6 changed files with 48 additions and 8 deletions

View File

@ -344,7 +344,13 @@ public class CMHardwareService extends SystemService implements ThermalUpdateCal
super(context);
mContext = context;
mCmHwImpl = getImpl(context);
publishBinderService(CMContextConstants.CM_HARDWARE_SERVICE, mService);
if (context.getPackageManager().hasSystemFeature(
CMContextConstants.Features.HARDWARE_ABSTRACTION)) {
publishBinderService(CMContextConstants.CM_HARDWARE_SERVICE, mService);
} else {
Log.wtf(TAG, "CM hardware service started by system server but feature xml not" +
" declared. Not publishing binder service!");
}
}
@Override

View File

@ -16,6 +16,8 @@
package cyanogenmod.app;
import android.annotation.SdkConstant;
/**
* @hide
* TODO: We need to somehow make these managers accessible via getSystemService
@ -111,4 +113,17 @@ public final class CMContextConstants {
* @hide
*/
public static final String CM_ICON_CACHE_SERVICE = "cmiconcache";
/**
* Features supported by the CMSDK.
*/
public static class Features {
/**
* Feature for {@link PackageManager#getSystemAvailableFeatures} and
* {@link PackageManager#hasSystemFeature}: The device includes the hardware abstraction
* framework service utilized by the cmsdk.
*/
@SdkConstant(SdkConstant.SdkConstantType.FEATURE)
public static final String HARDWARE_ABSTRACTION = "org.cyanogenmod.hardware";
}
}

View File

@ -154,6 +154,13 @@ public final class CMHardwareManager {
mContext = context;
}
sService = getService();
if (context.getPackageManager().hasSystemFeature(
CMContextConstants.Features.HARDWARE_ABSTRACTION) && !checkService()) {
throw new RuntimeException("Unable to get CMHardwareService. The service either" +
" crashed, was not started, or the interface has been called to early in" +
" SystemServer init");
}
}
/**
@ -440,7 +447,7 @@ public final class CMHardwareManager {
public boolean writePersistentString(String key, String value) {
try {
if (checkService()) {
return getService().writePersistentBytes(key,
return sService.writePersistentBytes(key,
value == null ? null : value.getBytes("UTF-8"));
}
} catch (RemoteException e) {
@ -460,7 +467,7 @@ public final class CMHardwareManager {
public boolean writePersistentInt(String key, int value) {
try {
if (checkService()) {
return getService().writePersistentBytes(key,
return sService.writePersistentBytes(key,
ByteBuffer.allocate(4).putInt(value).array());
}
} catch (RemoteException e) {
@ -478,7 +485,7 @@ public final class CMHardwareManager {
public boolean writePersistentBytes(String key, byte[] value) {
try {
if (checkService()) {
return getService().writePersistentBytes(key, value);
return sService.writePersistentBytes(key, value);
}
} catch (RemoteException e) {
}
@ -494,7 +501,7 @@ public final class CMHardwareManager {
public String readPersistentString(String key) {
try {
if (checkService()) {
byte[] bytes = getService().readPersistentBytes(key);
byte[] bytes = sService.readPersistentBytes(key);
if (bytes != null) {
return new String(bytes, "UTF-8");
}
@ -515,7 +522,7 @@ public final class CMHardwareManager {
public int readPersistentInt(String key) {
try {
if (checkService()) {
byte[] bytes = getService().readPersistentBytes(key);
byte[] bytes = sService.readPersistentBytes(key);
if (bytes != null) {
return ByteBuffer.wrap(bytes).getInt();
}
@ -534,7 +541,7 @@ public final class CMHardwareManager {
public byte[] readPersistentBytes(String key) {
try {
if (checkService()) {
return getService().readPersistentBytes(key);
return sService.readPersistentBytes(key);
}
} catch (RemoteException e) {
}
@ -549,7 +556,7 @@ public final class CMHardwareManager {
public boolean deletePersistentObject(String key) {
try {
if (checkService()) {
return getService().writePersistentBytes(key, null);
return sService.writePersistentBytes(key, null);
}
} catch (RemoteException e) {
}

View File

@ -19,6 +19,7 @@ package org.cyanogenmod.tests.hardware.unit;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import cyanogenmod.app.CMContextConstants;
import cyanogenmod.hardware.CMHardwareManager;
import cyanogenmod.hardware.ICMHardwareService;
@ -30,6 +31,9 @@ public class CMHardwareManagerTest extends AndroidTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
// Only run this if we support hardware abstraction
org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
CMContextConstants.Features.HARDWARE_ABSTRACTION));
mCMHardwareManager = CMHardwareManager.getInstance(mContext);
}

View File

@ -20,6 +20,7 @@ import android.os.Parcel;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import cyanogenmod.app.CMContextConstants;
import cyanogenmod.hardware.DisplayMode;
/**
@ -29,6 +30,9 @@ public class DisplayModeTest extends AndroidTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
// Only run this if we support hardware abstraction
org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
CMContextConstants.Features.HARDWARE_ABSTRACTION));
}
@SmallTest

View File

@ -18,6 +18,7 @@ package org.cyanogenmod.tests.hardware.unit;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import cyanogenmod.app.CMContextConstants;
import cyanogenmod.hardware.CMHardwareManager;
import java.util.Arrays;
@ -31,6 +32,9 @@ public class PersistentStorageTest extends AndroidTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
// Only run this if we support hardware abstraction
org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
CMContextConstants.Features.HARDWARE_ABSTRACTION));
mHardwareManager = CMHardwareManager.getInstance(mContext);
}