livedisplay: Add some unit tests

* Test color temperature control and mode selection

Change-Id: Icc4fffef4c64cf3424e30890b5a4a37154482b3a
This commit is contained in:
Steve Kondik 2016-04-26 01:12:56 -07:00 committed by Steve Kondik
parent 35315d3c0f
commit 4595cfde0b
2 changed files with 154 additions and 0 deletions

View File

@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.REBOOT" /> <uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="cyanogenmod.permission.PUBLISH_CUSTOM_TILE" /> <uses-permission android:name="cyanogenmod.permission.PUBLISH_CUSTOM_TILE" />
<uses-permission android:name="cyanogenmod.permission.WRITE_SETTINGS"/> <uses-permission android:name="cyanogenmod.permission.WRITE_SETTINGS"/>
@ -24,6 +25,7 @@
<uses-permission android:name="cyanogenmod.permission.READ_THEMES" /> <uses-permission android:name="cyanogenmod.permission.READ_THEMES" />
<uses-permission android:name="cyanogenmod.permission.WRITE_THEMES" /> <uses-permission android:name="cyanogenmod.permission.WRITE_THEMES" />
<uses-permission android:name="cyanogenmod.permission.ACCESS_THEME_MANAGER" /> <uses-permission android:name="cyanogenmod.permission.ACCESS_THEME_MANAGER" />
<uses-permission android:name="cyanogenmod.permission.MANAGE_LIVEDISPLAY" />
<uses-permission android:name="android.permission.STATUS_BAR_SERVICE" /> <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />

View File

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