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:
parent
19b267dfff
commit
a335ba39c2
|
@ -344,7 +344,13 @@ public class CMHardwareService extends SystemService implements ThermalUpdateCal
|
||||||
super(context);
|
super(context);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mCmHwImpl = getImpl(context);
|
mCmHwImpl = getImpl(context);
|
||||||
|
if (context.getPackageManager().hasSystemFeature(
|
||||||
|
CMContextConstants.Features.HARDWARE_ABSTRACTION)) {
|
||||||
publishBinderService(CMContextConstants.CM_HARDWARE_SERVICE, mService);
|
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
|
@Override
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package cyanogenmod.app;
|
package cyanogenmod.app;
|
||||||
|
|
||||||
|
import android.annotation.SdkConstant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
* TODO: We need to somehow make these managers accessible via getSystemService
|
* TODO: We need to somehow make these managers accessible via getSystemService
|
||||||
|
@ -111,4 +113,17 @@ public final class CMContextConstants {
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final String CM_ICON_CACHE_SERVICE = "cmiconcache";
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,6 +154,13 @@ public final class CMHardwareManager {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
sService = getService();
|
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) {
|
public boolean writePersistentString(String key, String value) {
|
||||||
try {
|
try {
|
||||||
if (checkService()) {
|
if (checkService()) {
|
||||||
return getService().writePersistentBytes(key,
|
return sService.writePersistentBytes(key,
|
||||||
value == null ? null : value.getBytes("UTF-8"));
|
value == null ? null : value.getBytes("UTF-8"));
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
@ -460,7 +467,7 @@ public final class CMHardwareManager {
|
||||||
public boolean writePersistentInt(String key, int value) {
|
public boolean writePersistentInt(String key, int value) {
|
||||||
try {
|
try {
|
||||||
if (checkService()) {
|
if (checkService()) {
|
||||||
return getService().writePersistentBytes(key,
|
return sService.writePersistentBytes(key,
|
||||||
ByteBuffer.allocate(4).putInt(value).array());
|
ByteBuffer.allocate(4).putInt(value).array());
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
@ -478,7 +485,7 @@ public final class CMHardwareManager {
|
||||||
public boolean writePersistentBytes(String key, byte[] value) {
|
public boolean writePersistentBytes(String key, byte[] value) {
|
||||||
try {
|
try {
|
||||||
if (checkService()) {
|
if (checkService()) {
|
||||||
return getService().writePersistentBytes(key, value);
|
return sService.writePersistentBytes(key, value);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
|
@ -494,7 +501,7 @@ public final class CMHardwareManager {
|
||||||
public String readPersistentString(String key) {
|
public String readPersistentString(String key) {
|
||||||
try {
|
try {
|
||||||
if (checkService()) {
|
if (checkService()) {
|
||||||
byte[] bytes = getService().readPersistentBytes(key);
|
byte[] bytes = sService.readPersistentBytes(key);
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
return new String(bytes, "UTF-8");
|
return new String(bytes, "UTF-8");
|
||||||
}
|
}
|
||||||
|
@ -515,7 +522,7 @@ public final class CMHardwareManager {
|
||||||
public int readPersistentInt(String key) {
|
public int readPersistentInt(String key) {
|
||||||
try {
|
try {
|
||||||
if (checkService()) {
|
if (checkService()) {
|
||||||
byte[] bytes = getService().readPersistentBytes(key);
|
byte[] bytes = sService.readPersistentBytes(key);
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
return ByteBuffer.wrap(bytes).getInt();
|
return ByteBuffer.wrap(bytes).getInt();
|
||||||
}
|
}
|
||||||
|
@ -534,7 +541,7 @@ public final class CMHardwareManager {
|
||||||
public byte[] readPersistentBytes(String key) {
|
public byte[] readPersistentBytes(String key) {
|
||||||
try {
|
try {
|
||||||
if (checkService()) {
|
if (checkService()) {
|
||||||
return getService().readPersistentBytes(key);
|
return sService.readPersistentBytes(key);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
|
@ -549,7 +556,7 @@ public final class CMHardwareManager {
|
||||||
public boolean deletePersistentObject(String key) {
|
public boolean deletePersistentObject(String key) {
|
||||||
try {
|
try {
|
||||||
if (checkService()) {
|
if (checkService()) {
|
||||||
return getService().writePersistentBytes(key, null);
|
return sService.writePersistentBytes(key, null);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.cyanogenmod.tests.hardware.unit;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
|
||||||
|
import cyanogenmod.app.CMContextConstants;
|
||||||
import cyanogenmod.hardware.CMHardwareManager;
|
import cyanogenmod.hardware.CMHardwareManager;
|
||||||
import cyanogenmod.hardware.ICMHardwareService;
|
import cyanogenmod.hardware.ICMHardwareService;
|
||||||
|
|
||||||
|
@ -30,6 +31,9 @@ public class CMHardwareManagerTest extends AndroidTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
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);
|
mCMHardwareManager = CMHardwareManager.getInstance(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.os.Parcel;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
import cyanogenmod.app.CMContextConstants;
|
||||||
import cyanogenmod.hardware.DisplayMode;
|
import cyanogenmod.hardware.DisplayMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +30,9 @@ public class DisplayModeTest extends AndroidTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
// Only run this if we support hardware abstraction
|
||||||
|
org.junit.Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
|
||||||
|
CMContextConstants.Features.HARDWARE_ABSTRACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.cyanogenmod.tests.hardware.unit;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
|
||||||
|
import cyanogenmod.app.CMContextConstants;
|
||||||
import cyanogenmod.hardware.CMHardwareManager;
|
import cyanogenmod.hardware.CMHardwareManager;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -31,6 +32,9 @@ public class PersistentStorageTest extends AndroidTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
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);
|
mHardwareManager = CMHardwareManager.getInstance(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue