aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java8
-rw-r--r--src/java/cyanogenmod/app/CMContextConstants.java15
-rw-r--r--src/java/cyanogenmod/hardware/CMHardwareManager.java21
-rw-r--r--tests/src/org/cyanogenmod/tests/hardware/unit/CMHardwareManagerTest.java4
-rw-r--r--tests/src/org/cyanogenmod/tests/hardware/unit/DisplayModeTest.java4
-rw-r--r--tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java4
6 files changed, 48 insertions, 8 deletions
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java
index bfae235..3622d9f 100644
--- a/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java
+++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java
@@ -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
diff --git a/src/java/cyanogenmod/app/CMContextConstants.java b/src/java/cyanogenmod/app/CMContextConstants.java
index a1da29c..957f33c 100644
--- a/src/java/cyanogenmod/app/CMContextConstants.java
+++ b/src/java/cyanogenmod/app/CMContextConstants.java
@@ -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";
+ }
}
diff --git a/src/java/cyanogenmod/hardware/CMHardwareManager.java b/src/java/cyanogenmod/hardware/CMHardwareManager.java
index 7d97df6..5bfb858 100644
--- a/src/java/cyanogenmod/hardware/CMHardwareManager.java
+++ b/src/java/cyanogenmod/hardware/CMHardwareManager.java
@@ -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) {
}
diff --git a/tests/src/org/cyanogenmod/tests/hardware/unit/CMHardwareManagerTest.java b/tests/src/org/cyanogenmod/tests/hardware/unit/CMHardwareManagerTest.java
index 8e2af14..f8dfa4e 100644
--- a/tests/src/org/cyanogenmod/tests/hardware/unit/CMHardwareManagerTest.java
+++ b/tests/src/org/cyanogenmod/tests/hardware/unit/CMHardwareManagerTest.java
@@ -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);
}
diff --git a/tests/src/org/cyanogenmod/tests/hardware/unit/DisplayModeTest.java b/tests/src/org/cyanogenmod/tests/hardware/unit/DisplayModeTest.java
index a642b2c..4a3e1ef 100644
--- a/tests/src/org/cyanogenmod/tests/hardware/unit/DisplayModeTest.java
+++ b/tests/src/org/cyanogenmod/tests/hardware/unit/DisplayModeTest.java
@@ -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
diff --git a/tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java b/tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java
index 10bc390..eb58905 100644
--- a/tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java
+++ b/tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java
@@ -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);
}