aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/lineageos/tests/hardware/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/org/lineageos/tests/hardware/unit')
-rw-r--r--tests/src/org/lineageos/tests/hardware/unit/DisplayModeTest.java60
-rw-r--r--tests/src/org/lineageos/tests/hardware/unit/LineageHardwareManagerTest.java50
-rw-r--r--tests/src/org/lineageos/tests/hardware/unit/LiveDisplayManagerTest.java152
-rw-r--r--tests/src/org/lineageos/tests/hardware/unit/PersistentStorageTest.java174
-rw-r--r--tests/src/org/lineageos/tests/hardware/unit/UniqueDeviceIDTest.java89
5 files changed, 525 insertions, 0 deletions
diff --git a/tests/src/org/lineageos/tests/hardware/unit/DisplayModeTest.java b/tests/src/org/lineageos/tests/hardware/unit/DisplayModeTest.java
new file mode 100644
index 00000000..4a3e1ef2
--- /dev/null
+++ b/tests/src/org/lineageos/tests/hardware/unit/DisplayModeTest.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.cyanogenmod.tests.hardware.unit;
+
+import android.os.Parcel;
+import android.test.AndroidTestCase;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import cyanogenmod.app.CMContextConstants;
+import cyanogenmod.hardware.DisplayMode;
+
+/**
+ * Created by adnan on 9/1/15.
+ */
+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
+ public void testDisplayModeUnravelFromParcel() {
+ int expectedId = 1337;
+ String expectedName = "test";
+ DisplayMode expectedDisplayMode = new DisplayMode(expectedId, expectedName);
+ // Write to parcel
+ Parcel parcel = Parcel.obtain();
+ expectedDisplayMode.writeToParcel(parcel, 0);
+
+ // Rewind
+ parcel.setDataPosition(0);
+
+ // Verify data when unraveling
+ DisplayMode fromParcel = DisplayMode.CREATOR.createFromParcel(parcel);
+
+ assertNotNull(expectedDisplayMode.id);
+ assertNotNull(expectedDisplayMode.name);
+
+ assertEquals(expectedDisplayMode.id, fromParcel.id );
+ assertEquals(expectedDisplayMode.name,
+ fromParcel.name);
+ }
+}
diff --git a/tests/src/org/lineageos/tests/hardware/unit/LineageHardwareManagerTest.java b/tests/src/org/lineageos/tests/hardware/unit/LineageHardwareManagerTest.java
new file mode 100644
index 00000000..f8dfa4e3
--- /dev/null
+++ b/tests/src/org/lineageos/tests/hardware/unit/LineageHardwareManagerTest.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+
+/**
+ * Created by adnan on 9/1/15.
+ */
+public class CMHardwareManagerTest extends AndroidTestCase {
+ private CMHardwareManager mCMHardwareManager;
+ @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);
+ }
+
+ @SmallTest
+ public void testManagerExists() {
+ assertNotNull(mCMHardwareManager);
+ }
+
+ @SmallTest
+ public void testManagerServiceIsAvailable() {
+ ICMHardwareService icmStatusBarManager = mCMHardwareManager.getService();
+ assertNotNull(icmStatusBarManager);
+ }
+}
diff --git a/tests/src/org/lineageos/tests/hardware/unit/LiveDisplayManagerTest.java b/tests/src/org/lineageos/tests/hardware/unit/LiveDisplayManagerTest.java
new file mode 100644
index 00000000..09d74f35
--- /dev/null
+++ b/tests/src/org/lineageos/tests/hardware/unit/LiveDisplayManagerTest.java
@@ -0,0 +1,152 @@
+package org.cyanogenmod.tests.hardware.unit;
+
+import android.content.Context;
+import android.os.PowerManager;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.junit.Assume;
+
+import cyanogenmod.app.CMContextConstants;
+import cyanogenmod.hardware.CMHardwareManager;
+import cyanogenmod.hardware.ILiveDisplayService;
+import cyanogenmod.hardware.LiveDisplayConfig;
+import cyanogenmod.hardware.LiveDisplayManager;
+import cyanogenmod.util.ColorUtils;
+
+public class LiveDisplayManagerTest extends AndroidTestCase {
+
+ private static final String TAG = "LiveDisplayManagerTest";
+
+ private LiveDisplayManager mLiveDisplay;
+ private CMHardwareManager mHardware;
+
+ private PowerManager mPower;
+ private PowerManager.WakeLock mWakeLock;
+
+ private LiveDisplayConfig mConfig;
+ private int mInitialMode;
+
+ @SuppressWarnings("deprecation")
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Assume.assumeTrue(mContext.getPackageManager().hasSystemFeature(
+ CMContextConstants.Features.LIVEDISPLAY));
+
+ mLiveDisplay = LiveDisplayManager.getInstance(mContext);
+ if (mLiveDisplay.getConfig().hasModeSupport()) {
+ mInitialMode = mLiveDisplay.getMode();
+ }
+ mConfig = mLiveDisplay.getConfig();
+
+ mHardware = CMHardwareManager.getInstance(mContext);
+ mPower = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+ mWakeLock = mPower.newWakeLock(
+ PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, TAG);
+ mWakeLock.acquire();
+ }
+
+ @Override
+ protected void tearDown() {
+ mLiveDisplay.setMode(mInitialMode);
+ mWakeLock.release();
+ }
+
+ @SmallTest
+ public void testManagerExists() {
+ assertNotNull(mLiveDisplay);
+ }
+
+ @SmallTest
+ public void testManagerServiceIsAvailable() {
+ ILiveDisplayService service = LiveDisplayManager.getService();
+ assertNotNull(service);
+ }
+
+ @SmallTest
+ public void testConfig() {
+ assertNotNull(mConfig);
+
+ // at least GPU mode should be available
+ assertTrue(mConfig.isAvailable());
+ }
+
+ @SmallTest
+ public void testNightMode() throws Exception {
+ Assume.assumeTrue(mConfig.hasModeSupport());
+
+ int day = mLiveDisplay.getDayColorTemperature();
+ int night = mLiveDisplay.getNightColorTemperature();
+
+ mLiveDisplay.setMode(LiveDisplayManager.MODE_NIGHT);
+ assertColorTemperature(night);
+
+ // custom value
+ mLiveDisplay.setNightColorTemperature(3300);
+ assertColorTemperature(3300);
+
+ // "default"
+ mLiveDisplay.setNightColorTemperature(mConfig.getDefaultNightTemperature());
+ assertColorTemperature(mConfig.getDefaultNightTemperature());
+
+ mLiveDisplay.setNightColorTemperature(night);
+
+ // day should not have changed
+ assertEquals(day, mLiveDisplay.getDayColorTemperature());
+ }
+
+ @SmallTest
+ public void testDayMode() throws Exception {
+ Assume.assumeTrue(mConfig.hasModeSupport());
+
+ int day = mLiveDisplay.getDayColorTemperature();
+ int night = mLiveDisplay.getNightColorTemperature();
+
+ mLiveDisplay.setMode(LiveDisplayManager.MODE_DAY);
+ assertColorTemperature(day);
+
+ // custom value
+ mLiveDisplay.setDayColorTemperature(8000);
+ assertColorTemperature(8000);
+
+ // "default"
+ mLiveDisplay.setDayColorTemperature(mConfig.getDefaultDayTemperature());
+ assertColorTemperature(mConfig.getDefaultDayTemperature());
+
+ mLiveDisplay.setDayColorTemperature(day);
+
+ // night should not have changed
+ assertEquals(night, mLiveDisplay.getNightColorTemperature());
+ }
+
+ @SmallTest
+ public void testOutdoorMode() throws Exception {
+ Assume.assumeTrue(mConfig.hasFeature(LiveDisplayManager.MODE_OUTDOOR));
+
+ assertTrue(mHardware.isSupported(CMHardwareManager.FEATURE_SUNLIGHT_ENHANCEMENT));
+
+ mLiveDisplay.setMode(LiveDisplayManager.MODE_OUTDOOR);
+ Thread.sleep(1000);
+ assertTrue(mHardware.get(CMHardwareManager.FEATURE_SUNLIGHT_ENHANCEMENT));
+
+ mLiveDisplay.setMode(LiveDisplayManager.MODE_OFF);
+ Thread.sleep(1000);
+ assertFalse(mHardware.get(CMHardwareManager.FEATURE_SUNLIGHT_ENHANCEMENT));
+ }
+
+ private void assertColorTemperature(int degK) throws Exception {
+ Thread.sleep(2000);
+ assertEquals(degK, LiveDisplayManager.getService().getColorTemperature());
+ checkHardwareValue(ColorUtils.temperatureToRGB(degK));
+ }
+
+ private void checkHardwareValue(float[] expected) {
+ int[] hardware = mHardware.getDisplayColorCalibration();
+ int max = mHardware.getDisplayColorCalibrationMax();
+ assertEquals((int)Math.floor(expected[0] * max), hardware[0]);
+ assertEquals((int)Math.floor(expected[1] * max), hardware[1]);
+ assertEquals((int)Math.floor(expected[2] * max), hardware[2]);
+ }
+}
diff --git a/tests/src/org/lineageos/tests/hardware/unit/PersistentStorageTest.java b/tests/src/org/lineageos/tests/hardware/unit/PersistentStorageTest.java
new file mode 100644
index 00000000..eb58905c
--- /dev/null
+++ b/tests/src/org/lineageos/tests/hardware/unit/PersistentStorageTest.java
@@ -0,0 +1,174 @@
+/**
+ * Copyright (c) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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;
+import java.util.Random;
+import java.util.UUID;
+
+public class PersistentStorageTest extends AndroidTestCase {
+
+ private CMHardwareManager mHardwareManager;
+
+ @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);
+ }
+
+ @SmallTest
+ public void testUdidFailure() {
+ String key = "udid";
+ String value = "542bc67e510e82bd6d44e4f7015d7970";
+ assertTrue(mHardwareManager.writePersistentString(key, value));
+ }
+
+ @SmallTest
+ public void testPersistentStringInvalidInput() {
+ String testKey = UUID.randomUUID().toString();
+ String testString = "IM IN UR STORAGE";
+ String testKeyTooLong = getStringOfLength(65);
+ String testStringTooLong = getStringOfLength(4097);
+
+ assertFalse(mHardwareManager.writePersistentString(null, testString));
+ assertFalse(mHardwareManager.writePersistentString("", testString));
+ assertFalse(mHardwareManager.writePersistentString(testKeyTooLong, testString));
+ assertFalse(mHardwareManager.writePersistentString(testKey, testStringTooLong));
+ assertFalse(mHardwareManager.writePersistentString(testKey, ""));
+ assertNull(mHardwareManager.readPersistentString(testKey));
+ assertNull(mHardwareManager.readPersistentString(testKeyTooLong));
+ }
+
+ @SmallTest
+ public void testPersistentIntInvalidInput() {
+ String testKey = UUID.randomUUID().toString();
+ String testString = "IM IN UR STORAGE";
+ String testKeyTooLong = getStringOfLength(65);
+
+ assertFalse(mHardwareManager.writePersistentInt(null, 49152));
+ assertFalse(mHardwareManager.writePersistentInt("", 49152));
+ assertFalse(mHardwareManager.writePersistentInt(testKeyTooLong, 49152));
+ assertEquals(0, mHardwareManager.readPersistentInt(testKey));
+ assertEquals(0, mHardwareManager.readPersistentInt(testKeyTooLong));
+ }
+
+ @SmallTest
+ public void testPersistentBytesInvalidInput() {
+ String testKey = UUID.randomUUID().toString();
+ byte[] testArray = new byte[1024];
+ byte[] testArrayTooLong = new byte[4097];
+ String testKeyTooLong = getStringOfLength(65);
+
+ assertFalse(mHardwareManager.writePersistentBytes(null, testArray));
+ assertFalse(mHardwareManager.writePersistentBytes("", testArray));
+ assertFalse(mHardwareManager.writePersistentBytes(testKeyTooLong, testArray));
+ assertFalse(mHardwareManager.writePersistentBytes(testKey, testArrayTooLong));
+ assertFalse(mHardwareManager.writePersistentBytes(testKey, new byte[0]));
+ assertNull(mHardwareManager.readPersistentBytes(testKey));
+ assertNull(mHardwareManager.readPersistentBytes(testKeyTooLong));
+ }
+
+ @SmallTest
+ public void testPersistentString() {
+ assertTrue(mHardwareManager.isSupported(CMHardwareManager.FEATURE_PERSISTENT_STORAGE));
+
+ String testKey = UUID.randomUUID().toString();
+ String testString = "IM IN UR STORAGE";
+
+ // write + read
+ assertTrue(mHardwareManager.writePersistentString(testKey, testString));
+ assertEquals(testString, mHardwareManager.readPersistentString(testKey));
+
+ // rewrite + read
+ assertTrue(mHardwareManager.writePersistentString(testKey, testString + " AGAIN"));
+ assertEquals(testString + " AGAIN", mHardwareManager.readPersistentString(testKey));
+
+ // erase + read
+ assertTrue(mHardwareManager.deletePersistentObject(testKey));
+ assertNull(mHardwareManager.readPersistentString(testKey));
+
+ // erase through write null
+ assertTrue(mHardwareManager.writePersistentString(testKey, testString + " AGAIN"));
+ assertEquals(testString + " AGAIN", mHardwareManager.readPersistentString(testKey));
+ assertTrue(mHardwareManager.writePersistentString(testKey, null));
+ assertNull(mHardwareManager.readPersistentString(testKey));
+ }
+
+ @SmallTest
+ public void testPersistentInteger() {
+ assertTrue(mHardwareManager.isSupported(CMHardwareManager.FEATURE_PERSISTENT_STORAGE));
+
+ String testKey = UUID.randomUUID().toString();
+ int testInt = 49152;
+
+ // write + read
+ assertTrue(mHardwareManager.writePersistentInt(testKey, testInt));
+ assertEquals(testInt, mHardwareManager.readPersistentInt(testKey));
+
+ // rewrite + read
+ assertTrue(mHardwareManager.writePersistentInt(testKey, testInt * 2));
+ assertEquals(testInt * 2, mHardwareManager.readPersistentInt(testKey));
+
+ // erase + read
+ assertTrue(mHardwareManager.deletePersistentObject(testKey));
+ assertEquals(0, mHardwareManager.readPersistentInt(testKey));
+ }
+
+ @SmallTest
+ public void testPersistentBytes() {
+ assertTrue(mHardwareManager.isSupported(CMHardwareManager.FEATURE_PERSISTENT_STORAGE));
+
+ String testKey = UUID.randomUUID().toString();
+ byte[] testArray = new byte[1024];
+ byte[] testArray2 = new byte[4096];
+
+ new Random().nextBytes(testArray);
+ new Random().nextBytes(testArray2);
+
+ // write + read
+ assertTrue(mHardwareManager.writePersistentBytes(testKey, testArray));
+ assertTrue(Arrays.equals(testArray, mHardwareManager.readPersistentBytes(testKey)));
+
+ // write + read
+ assertTrue(mHardwareManager.writePersistentBytes(testKey, testArray2));
+ assertTrue(Arrays.equals(testArray2, mHardwareManager.readPersistentBytes(testKey)));
+
+ // erase + read
+ assertTrue(mHardwareManager.deletePersistentObject(testKey));
+ assertNull(mHardwareManager.readPersistentBytes(testKey));
+
+ // erase through write null
+ assertTrue(mHardwareManager.writePersistentBytes(testKey, testArray));
+ assertTrue(Arrays.equals(testArray, mHardwareManager.readPersistentBytes(testKey)));
+ assertTrue(mHardwareManager.writePersistentBytes(testKey, null));
+ assertNull(mHardwareManager.readPersistentBytes(testKey));
+ }
+
+ private String getStringOfLength(int length) {
+ char[] chars = new char[length];
+ Arrays.fill(chars, 'z');
+ return new String(chars);
+ }
+}
diff --git a/tests/src/org/lineageos/tests/hardware/unit/UniqueDeviceIDTest.java b/tests/src/org/lineageos/tests/hardware/unit/UniqueDeviceIDTest.java
new file mode 100644
index 00000000..9a0f13ab
--- /dev/null
+++ b/tests/src/org/lineageos/tests/hardware/unit/UniqueDeviceIDTest.java
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2016, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.cyanogenmod.tests.hardware.unit;
+
+import android.os.Build;
+import android.os.SystemProperties;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.text.TextUtils;
+
+import cyanogenmod.hardware.CMHardwareManager;
+
+public class UniqueDeviceIDTest extends AndroidTestCase {
+ private static final String TAG = UniqueDeviceIDTest.class.getSimpleName();
+ private static final int MINIMUM_LENGTH = 3;
+ private CMHardwareManager mCMHardwareManager;
+
+ //TODO: Use the TYPE declaration from CMHardwareManager public interface in future
+ private static final int TYPE_MMC0_CID = 0;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mCMHardwareManager = CMHardwareManager.getInstance(mContext);
+ }
+
+ @SmallTest
+ public void testGetSerialNumber() {
+ final int feature = CMHardwareManager.FEATURE_SERIAL_NUMBER;
+ if (mCMHardwareManager.isSupported(feature)) {
+ String notExpectedSerialNo = SystemProperties.get("ro.serialno");
+ String actualSerialNo = mCMHardwareManager.getSerialNumber();
+ assertNotNull(actualSerialNo);
+ assertNotSame(notExpectedSerialNo, actualSerialNo);
+ }
+ }
+
+ @SmallTest
+ public void testGetUniqueDeviceId() {
+ final int feature = CMHardwareManager.FEATURE_UNIQUE_DEVICE_ID;
+ assertFeatureEnabledOnRetail(feature);
+ if (mCMHardwareManager.isSupported(feature)) {
+ String uniqueDeviceId = mCMHardwareManager.getUniqueDeviceId();
+ //FIXME: This is based off the default implementation in cyngn/hw, make more robust
+ assertNotNull(uniqueDeviceId);
+ assertTrue(uniqueDeviceId.length() >= MINIMUM_LENGTH);
+ assertTrue(isValidHexNumberAndType(uniqueDeviceId.substring(0, 3)));
+ }
+ }
+
+ private void assertFeatureEnabledOnRetail(int feature) {
+ if (TextUtils.equals(Build.TYPE, "user")) {
+ assertTrue(mCMHardwareManager.isSupported(feature));
+ }
+ }
+
+ private static boolean isValidHexNumberAndType(String target) {
+ try {
+ long value = Long.parseLong(target, 16);
+ return isValidType((int) value);
+ }
+ catch (NumberFormatException ex) {
+ return false;
+ }
+ }
+
+ private static boolean isValidType(int value) {
+ switch (value) {
+ case TYPE_MMC0_CID:
+ return true;
+ default:
+ return false;
+ }
+ }
+}