Add Brightness setting for VR Mode.
This change saves and loads a different brightness setting when the user
goes in and out of VR Mode.
Test: runtests frameworks-core
Test: Turn vr mode on and change brightness (should remain separate from
normal brightness)
Bug: 30984614
Change-Id: If3c3e81b592e0c6fd037e5783559683e5cb58379
diff --git a/services/core/java/com/android/server/lights/LightsService.java b/services/core/java/com/android/server/lights/LightsService.java
index bba0a50..e07156e 100644
--- a/services/core/java/com/android/server/lights/LightsService.java
+++ b/services/core/java/com/android/server/lights/LightsService.java
@@ -1,5 +1,4 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
+/* * Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,18 +16,13 @@
package com.android.server.lights;
import com.android.server.SystemService;
-import com.android.server.vr.VrManagerService;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
-import android.os.RemoteException;
import android.os.Trace;
-import android.os.UserHandle;
import android.provider.Settings;
-import android.service.vr.IVrManager;
-import android.service.vr.IVrStateCallbacks;
import android.util.Slog;
public class LightsService extends SystemService {
@@ -36,7 +30,6 @@
static final boolean DEBUG = false;
final LightImpl mLights[] = new LightImpl[LightsManager.LIGHT_ID_COUNT];
- private boolean mVrModeEnabled;
private final class LightImpl extends Light {
@@ -52,6 +45,13 @@
@Override
public void setBrightness(int brightness, int brightnessMode) {
synchronized (this) {
+ // LOW_PERSISTENCE cannot be manually set
+ if (brightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE) {
+ Slog.w(TAG, "setBrightness with LOW_PERSISTENCE unexpected #" + mId +
+ ": brightness=0x" + Integer.toHexString(brightness));
+ return;
+ }
+
int color = brightness & 0x000000ff;
color = 0xff000000 | (color << 16) | (color << 8) | color;
setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, brightnessMode);
@@ -80,11 +80,9 @@
@Override
public void pulse(int color, int onMS) {
synchronized (this) {
- if (mBrightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE) {
- return;
- }
if (mColor == 0 && !mFlashing) {
- setLightLocked(color, LIGHT_FLASH_HARDWARE, onMS, 1000, BRIGHTNESS_MODE_USER);
+ setLightLocked(color, LIGHT_FLASH_HARDWARE, onMS, 1000,
+ BRIGHTNESS_MODE_USER);
mColor = 0;
mH.sendMessageDelayed(Message.obtain(mH, 1, this), onMS);
}
@@ -98,17 +96,23 @@
}
}
- void enableLowPersistence() {
- synchronized(this) {
- setLightLocked(0, LIGHT_FLASH_NONE, 0, 0, BRIGHTNESS_MODE_LOW_PERSISTENCE);
- mLocked = true;
- }
- }
+ @Override
+ public void setVrMode(boolean enabled) {
+ synchronized (this) {
+ if (mVrModeEnabled != enabled) {
+ mVrModeEnabled = enabled;
- void disableLowPersistence() {
- synchronized(this) {
- mLocked = false;
- setLightLocked(mLastColor, LIGHT_FLASH_NONE, 0, 0, mLastBrightnessMode);
+ mUseLowPersistenceForVR =
+ (getVrDisplayMode() == Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE);
+ if (shouldBeInLowPersistenceMode()) {
+ mLastBrightnessMode = mBrightnessMode;
+ }
+
+ // NOTE: We do not trigger a call to setLightLocked here. We do not know the
+ // current brightness or other values when leaving VR so we avoid any incorrect
+ // jumps. The code that calls this method will immediately issue a brightness
+ // update which is when the change will occur.
+ }
}
}
@@ -119,7 +123,13 @@
}
private void setLightLocked(int color, int mode, int onMS, int offMS, int brightnessMode) {
- if (!mLocked && (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS ||
+ if (shouldBeInLowPersistenceMode()) {
+ brightnessMode = BRIGHTNESS_MODE_LOW_PERSISTENCE;
+ } else if (brightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE) {
+ brightnessMode = mLastBrightnessMode;
+ }
+
+ if ((color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS ||
mBrightnessMode != brightnessMode)) {
if (DEBUG) Slog.v(TAG, "setLight #" + mId + ": color=#"
+ Integer.toHexString(color) + ": brightnessMode=" + brightnessMode);
@@ -128,7 +138,6 @@
mMode = mode;
mOnMS = onMS;
mOffMS = offMS;
- mLastBrightnessMode = mBrightnessMode;
mBrightnessMode = brightnessMode;
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setLight(" + mId + ", 0x"
+ Integer.toHexString(color) + ")");
@@ -140,6 +149,10 @@
}
}
+ private boolean shouldBeInLowPersistenceMode() {
+ return mVrModeEnabled && mUseLowPersistenceForVR;
+ }
+
private int mId;
private int mColor;
private int mMode;
@@ -149,7 +162,8 @@
private int mBrightnessMode;
private int mLastBrightnessMode;
private int mLastColor;
- private boolean mLocked;
+ private boolean mVrModeEnabled;
+ private boolean mUseLowPersistenceForVR;
}
public LightsService(Context context) {
@@ -167,17 +181,6 @@
@Override
public void onBootPhase(int phase) {
- if (phase == PHASE_SYSTEM_SERVICES_READY) {
- IVrManager vrManager =
- (IVrManager) getBinderService(VrManagerService.VR_MANAGER_BINDER_SERVICE);
- if (vrManager != null) {
- try {
- vrManager.registerListener(mVrStateCallbacks);
- } catch (RemoteException e) {
- Slog.e(TAG, "Failed to register VR mode state listener: " + e);
- }
- }
- }
}
private int getVrDisplayMode() {
@@ -188,30 +191,6 @@
currentUser);
}
- private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() {
- @Override
- public void onVrStateChanged(boolean enabled) throws RemoteException {
- LightImpl l = mLights[LightsManager.LIGHT_ID_BACKLIGHT];
- int vrDisplayMode = getVrDisplayMode();
-
- // User leaves VR mode before altering display settings.
- if (enabled && vrDisplayMode == Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE) {
- if (!mVrModeEnabled) {
- if (DEBUG)
- Slog.v(TAG, "VR mode enabled, setting brightness to low persistence");
- l.enableLowPersistence();
- mVrModeEnabled = true;
- }
- } else {
- if (mVrModeEnabled) {
- if (DEBUG) Slog.v(TAG, "VR mode disabled, resetting brightnes");
- l.disableLowPersistence();
- mVrModeEnabled = false;
- }
- }
- }
- };
-
private final LightsManager mService = new LightsManager() {
@Override
public Light getLight(int id) {