Merge "Move display power controller to display manager service. (DO NOT MERGE)" into klp-modular-dev
This commit is contained in:
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package android.hardware.display;
|
package android.hardware.display;
|
||||||
|
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.view.DisplayInfo;
|
import android.view.DisplayInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,6 +27,36 @@ import android.view.DisplayInfo;
|
|||||||
* @hide Only for use within the system server.
|
* @hide Only for use within the system server.
|
||||||
*/
|
*/
|
||||||
public abstract class DisplayManagerInternal {
|
public abstract class DisplayManagerInternal {
|
||||||
|
/**
|
||||||
|
* Called by the power manager to initialize power management facilities.
|
||||||
|
*/
|
||||||
|
public abstract void initPowerManagement(DisplayPowerCallbacks callbacks,
|
||||||
|
Handler handler, SensorManager sensorManager);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by the power manager to request a new power state.
|
||||||
|
* <p>
|
||||||
|
* The display power controller makes a copy of the provided object and then
|
||||||
|
* begins adjusting the power state to match what was requested.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param request The requested power state.
|
||||||
|
* @param waitForNegativeProximity If true, issues a request to wait for
|
||||||
|
* negative proximity before turning the screen back on, assuming the screen
|
||||||
|
* was turned off by the proximity sensor.
|
||||||
|
* @return True if display is ready, false if there are important changes that must
|
||||||
|
* be made asynchronously (such as turning the screen on), in which case the caller
|
||||||
|
* should grab a wake lock, watch for {@link DisplayPowerCallbacks#onStateChanged()}
|
||||||
|
* then try the request again later until the state converges.
|
||||||
|
*/
|
||||||
|
public abstract boolean requestPowerState(DisplayPowerRequest request,
|
||||||
|
boolean waitForNegativeProximity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the proximity sensor screen-off function is available.
|
||||||
|
*/
|
||||||
|
public abstract boolean isProximitySensorAvailable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the power manager to blank all displays.
|
* Called by the power manager to blank all displays.
|
||||||
*/
|
*/
|
||||||
@ -98,6 +131,137 @@ public abstract class DisplayManagerInternal {
|
|||||||
public abstract void setDisplayHasContent(int displayId, boolean hasContent,
|
public abstract void setDisplayHasContent(int displayId, boolean hasContent,
|
||||||
boolean inTraversal);
|
boolean inTraversal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the requested power state of the display.
|
||||||
|
*
|
||||||
|
* This object is intended to describe the general characteristics of the
|
||||||
|
* power state, such as whether the screen should be on or off and the current
|
||||||
|
* brightness controls leaving the DisplayPowerController to manage the
|
||||||
|
* details of how the transitions between states should occur. The goal is for
|
||||||
|
* the PowerManagerService to focus on the global power state and not
|
||||||
|
* have to micro-manage screen off animations, auto-brightness and other effects.
|
||||||
|
*/
|
||||||
|
public static final class DisplayPowerRequest {
|
||||||
|
public static final int SCREEN_STATE_OFF = 0;
|
||||||
|
public static final int SCREEN_STATE_DOZE = 1;
|
||||||
|
public static final int SCREEN_STATE_DIM = 2;
|
||||||
|
public static final int SCREEN_STATE_BRIGHT = 3;
|
||||||
|
|
||||||
|
// The requested minimum screen power state: off, doze, dim or bright.
|
||||||
|
public int screenState;
|
||||||
|
|
||||||
|
// If true, the proximity sensor overrides the screen state when an object is
|
||||||
|
// nearby, turning it off temporarily until the object is moved away.
|
||||||
|
public boolean useProximitySensor;
|
||||||
|
|
||||||
|
// The desired screen brightness in the range 0 (minimum / off) to 255 (brightest).
|
||||||
|
// The display power controller may choose to clamp the brightness.
|
||||||
|
// When auto-brightness is enabled, this field should specify a nominal default
|
||||||
|
// value to use while waiting for the light sensor to report enough data.
|
||||||
|
public int screenBrightness;
|
||||||
|
|
||||||
|
// The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter).
|
||||||
|
public float screenAutoBrightnessAdjustment;
|
||||||
|
|
||||||
|
// If true, enables automatic brightness control.
|
||||||
|
public boolean useAutoBrightness;
|
||||||
|
|
||||||
|
// If true, prevents the screen from completely turning on if it is currently off.
|
||||||
|
// The display does not enter a "ready" state if this flag is true and screen on is
|
||||||
|
// blocked. The window manager policy blocks screen on while it prepares the keyguard to
|
||||||
|
// prevent the user from seeing intermediate updates.
|
||||||
|
//
|
||||||
|
// Technically, we may not block the screen itself from turning on (because that introduces
|
||||||
|
// extra unnecessary latency) but we do prevent content on screen from becoming
|
||||||
|
// visible to the user.
|
||||||
|
public boolean blockScreenOn;
|
||||||
|
|
||||||
|
public DisplayPowerRequest() {
|
||||||
|
screenState = SCREEN_STATE_BRIGHT;
|
||||||
|
useProximitySensor = false;
|
||||||
|
screenBrightness = PowerManager.BRIGHTNESS_ON;
|
||||||
|
screenAutoBrightnessAdjustment = 0.0f;
|
||||||
|
useAutoBrightness = false;
|
||||||
|
blockScreenOn = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayPowerRequest(DisplayPowerRequest other) {
|
||||||
|
copyFrom(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true if we want the screen on in any mode, including doze.
|
||||||
|
public boolean wantScreenOnAny() {
|
||||||
|
return screenState != SCREEN_STATE_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true if we want the screen on in a normal mode, excluding doze.
|
||||||
|
// This is usually what we want to tell the rest of the system. For compatibility
|
||||||
|
// reasons, we pretend the screen is off when dozing.
|
||||||
|
public boolean wantScreenOnNormal() {
|
||||||
|
return screenState == SCREEN_STATE_DIM || screenState == SCREEN_STATE_BRIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean wantLightSensorEnabled() {
|
||||||
|
// Specifically, we don't want the light sensor while dozing.
|
||||||
|
return useAutoBrightness && wantScreenOnNormal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyFrom(DisplayPowerRequest other) {
|
||||||
|
screenState = other.screenState;
|
||||||
|
useProximitySensor = other.useProximitySensor;
|
||||||
|
screenBrightness = other.screenBrightness;
|
||||||
|
screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
|
||||||
|
useAutoBrightness = other.useAutoBrightness;
|
||||||
|
blockScreenOn = other.blockScreenOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return o instanceof DisplayPowerRequest
|
||||||
|
&& equals((DisplayPowerRequest)o);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(DisplayPowerRequest other) {
|
||||||
|
return other != null
|
||||||
|
&& screenState == other.screenState
|
||||||
|
&& useProximitySensor == other.useProximitySensor
|
||||||
|
&& screenBrightness == other.screenBrightness
|
||||||
|
&& screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
|
||||||
|
&& useAutoBrightness == other.useAutoBrightness
|
||||||
|
&& blockScreenOn == other.blockScreenOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return 0; // don't care
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "screenState=" + screenState
|
||||||
|
+ ", useProximitySensor=" + useProximitySensor
|
||||||
|
+ ", screenBrightness=" + screenBrightness
|
||||||
|
+ ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
|
||||||
|
+ ", useAutoBrightness=" + useAutoBrightness
|
||||||
|
+ ", blockScreenOn=" + blockScreenOn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronous callbacks from the power controller to the power manager service.
|
||||||
|
*/
|
||||||
|
public interface DisplayPowerCallbacks {
|
||||||
|
void onStateChanged();
|
||||||
|
void onProximityPositive();
|
||||||
|
void onProximityNegative();
|
||||||
|
|
||||||
|
void acquireSuspendBlocker();
|
||||||
|
void releaseSuspendBlocker();
|
||||||
|
|
||||||
|
void blankAllDisplays();
|
||||||
|
void unblankAllDisplays();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called within a Surface transaction whenever the size or orientation of a
|
* Called within a Surface transaction whenever the size or orientation of a
|
||||||
* display may have changed. Provides an opportunity for the client to
|
* display may have changed. Provides an opportunity for the client to
|
||||||
|
@ -21,6 +21,7 @@ import com.android.internal.util.IndentingPrintWriter;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
import android.hardware.display.DisplayManager;
|
import android.hardware.display.DisplayManager;
|
||||||
import android.hardware.display.DisplayManagerGlobal;
|
import android.hardware.display.DisplayManagerGlobal;
|
||||||
import android.hardware.display.DisplayManagerInternal;
|
import android.hardware.display.DisplayManagerInternal;
|
||||||
@ -172,6 +173,9 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
|
private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
|
||||||
new CopyOnWriteArrayList<DisplayTransactionListener>();
|
new CopyOnWriteArrayList<DisplayTransactionListener>();
|
||||||
|
|
||||||
|
// Display power controller.
|
||||||
|
private DisplayPowerController mDisplayPowerController;
|
||||||
|
|
||||||
// Set to true if all displays have been blanked by the power manager.
|
// Set to true if all displays have been blanked by the power manager.
|
||||||
private int mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_UNKNOWN;
|
private int mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_UNKNOWN;
|
||||||
|
|
||||||
@ -936,6 +940,10 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
pw.println(" " + i + ": mPid=" + callback.mPid
|
pw.println(" " + i + ": mPid=" + callback.mPid
|
||||||
+ ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
|
+ ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mDisplayPowerController != null) {
|
||||||
|
mDisplayPowerController.dump(pw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1313,6 +1321,27 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class LocalService extends DisplayManagerInternal {
|
private final class LocalService extends DisplayManagerInternal {
|
||||||
|
@Override
|
||||||
|
public void initPowerManagement(DisplayPowerCallbacks callbacks, Handler handler,
|
||||||
|
SensorManager sensorManager) {
|
||||||
|
synchronized (mSyncRoot) {
|
||||||
|
mDisplayPowerController = new DisplayPowerController(
|
||||||
|
mContext, callbacks, handler, sensorManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requestPowerState(DisplayPowerRequest request,
|
||||||
|
boolean waitForNegativeProximity) {
|
||||||
|
return mDisplayPowerController.requestPowerState(request,
|
||||||
|
waitForNegativeProximity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isProximitySensorAvailable() {
|
||||||
|
return mDisplayPowerController.isProximitySensorAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void blankAllDisplaysFromPowerManager() {
|
public void blankAllDisplaysFromPowerManager() {
|
||||||
blankAllDisplaysFromPowerManagerInternal();
|
blankAllDisplaysFromPowerManagerInternal();
|
||||||
|
@ -14,8 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.power;
|
package com.android.server.display;
|
||||||
|
|
||||||
|
import com.android.internal.app.IBatteryStats;
|
||||||
|
import com.android.server.LocalServices;
|
||||||
|
import com.android.server.am.BatteryStatsService;
|
||||||
import com.android.server.lights.LightsManager;
|
import com.android.server.lights.LightsManager;
|
||||||
import com.android.server.twilight.TwilightListener;
|
import com.android.server.twilight.TwilightListener;
|
||||||
import com.android.server.twilight.TwilightManager;
|
import com.android.server.twilight.TwilightManager;
|
||||||
@ -29,10 +32,13 @@ import android.hardware.Sensor;
|
|||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
|
import android.hardware.display.DisplayManagerInternal.DisplayPowerCallbacks;
|
||||||
|
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
import android.os.RemoteException;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.util.FloatMath;
|
import android.util.FloatMath;
|
||||||
@ -160,23 +166,15 @@ final class DisplayPowerController {
|
|||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
// Notifier for sending asynchronous notifications.
|
|
||||||
private final Notifier mNotifier;
|
|
||||||
|
|
||||||
// The display suspend blocker.
|
|
||||||
// Held while there are pending state change notifications.
|
|
||||||
private final SuspendBlocker mDisplaySuspendBlocker;
|
|
||||||
|
|
||||||
// The display blanker.
|
|
||||||
private final DisplayBlanker mDisplayBlanker;
|
|
||||||
|
|
||||||
// Our handler.
|
// Our handler.
|
||||||
private final DisplayControllerHandler mHandler;
|
private final DisplayControllerHandler mHandler;
|
||||||
|
|
||||||
// Asynchronous callbacks into the power manager service.
|
// Asynchronous callbacks into the power manager service.
|
||||||
// Only invoked from the handler thread while no locks are held.
|
// Only invoked from the handler thread while no locks are held.
|
||||||
private final Callbacks mCallbacks;
|
private final DisplayPowerCallbacks mCallbacks;
|
||||||
private Handler mCallbackHandler;
|
|
||||||
|
// Battery stats.
|
||||||
|
private final IBatteryStats mBatteryStats;
|
||||||
|
|
||||||
// The lights service.
|
// The lights service.
|
||||||
private final LightsManager mLights;
|
private final LightsManager mLights;
|
||||||
@ -350,19 +348,14 @@ final class DisplayPowerController {
|
|||||||
/**
|
/**
|
||||||
* Creates the display power controller.
|
* Creates the display power controller.
|
||||||
*/
|
*/
|
||||||
public DisplayPowerController(Looper looper, Context context, Notifier notifier,
|
public DisplayPowerController(Context context,
|
||||||
LightsManager lights, TwilightManager twilight, SensorManager sensorManager,
|
DisplayPowerCallbacks callbacks, Handler handler, SensorManager sensorManager) {
|
||||||
SuspendBlocker displaySuspendBlocker, DisplayBlanker displayBlanker,
|
mHandler = new DisplayControllerHandler(handler.getLooper());
|
||||||
Callbacks callbacks, Handler callbackHandler) {
|
|
||||||
mHandler = new DisplayControllerHandler(looper);
|
|
||||||
mNotifier = notifier;
|
|
||||||
mDisplaySuspendBlocker = displaySuspendBlocker;
|
|
||||||
mDisplayBlanker = displayBlanker;
|
|
||||||
mCallbacks = callbacks;
|
mCallbacks = callbacks;
|
||||||
mCallbackHandler = callbackHandler;
|
|
||||||
|
|
||||||
mLights = lights;
|
mBatteryStats = BatteryStatsService.getService();
|
||||||
mTwilight = twilight;
|
mLights = LocalServices.getService(LightsManager.class);
|
||||||
|
mTwilight = LocalServices.getService(TwilightManager.class);
|
||||||
mSensorManager = sensorManager;
|
mSensorManager = sensorManager;
|
||||||
|
|
||||||
final Resources resources = context.getResources();
|
final Resources resources = context.getResources();
|
||||||
@ -527,7 +520,7 @@ final class DisplayPowerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
mPowerState = new DisplayPowerState(new ElectronBeam(), mDisplayBlanker,
|
mPowerState = new DisplayPowerState(new ElectronBeam(), mCallbacks,
|
||||||
mLights.getLight(LightsManager.LIGHT_ID_BACKLIGHT));
|
mLights.getLight(LightsManager.LIGHT_ID_BACKLIGHT));
|
||||||
|
|
||||||
mElectronBeamOnAnimator = ObjectAnimator.ofFloat(
|
mElectronBeamOnAnimator = ObjectAnimator.ofFloat(
|
||||||
@ -779,10 +772,14 @@ final class DisplayPowerController {
|
|||||||
private void setScreenOn(boolean on) {
|
private void setScreenOn(boolean on) {
|
||||||
if (mPowerState.isScreenOn() != on) {
|
if (mPowerState.isScreenOn() != on) {
|
||||||
mPowerState.setScreenOn(on);
|
mPowerState.setScreenOn(on);
|
||||||
|
try {
|
||||||
if (on) {
|
if (on) {
|
||||||
mNotifier.onScreenOn();
|
mBatteryStats.noteScreenOn();
|
||||||
} else {
|
} else {
|
||||||
mNotifier.onScreenOff();
|
mBatteryStats.noteScreenOff();
|
||||||
|
}
|
||||||
|
} catch (RemoteException ex) {
|
||||||
|
// same process
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -811,7 +808,11 @@ final class DisplayPowerController {
|
|||||||
|
|
||||||
private void animateScreenBrightness(int target, int rate) {
|
private void animateScreenBrightness(int target, int rate) {
|
||||||
if (mScreenBrightnessRampAnimator.animateTo(target, rate)) {
|
if (mScreenBrightnessRampAnimator.animateTo(target, rate)) {
|
||||||
mNotifier.onScreenBrightness(target);
|
try {
|
||||||
|
mBatteryStats.noteScreenBrightness(target);
|
||||||
|
} catch (RemoteException ex) {
|
||||||
|
// same process
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -896,13 +897,13 @@ final class DisplayPowerController {
|
|||||||
private void clearPendingProximityDebounceTime() {
|
private void clearPendingProximityDebounceTime() {
|
||||||
if (mPendingProximityDebounceTime >= 0) {
|
if (mPendingProximityDebounceTime >= 0) {
|
||||||
mPendingProximityDebounceTime = -1;
|
mPendingProximityDebounceTime = -1;
|
||||||
mDisplaySuspendBlocker.release(); // release wake lock
|
mCallbacks.releaseSuspendBlocker(); // release wake lock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPendingProximityDebounceTime(long debounceTime) {
|
private void setPendingProximityDebounceTime(long debounceTime) {
|
||||||
if (mPendingProximityDebounceTime < 0) {
|
if (mPendingProximityDebounceTime < 0) {
|
||||||
mDisplaySuspendBlocker.acquire(); // acquire wake lock
|
mCallbacks.acquireSuspendBlocker(); // acquire wake lock
|
||||||
}
|
}
|
||||||
mPendingProximityDebounceTime = debounceTime;
|
mPendingProximityDebounceTime = debounceTime;
|
||||||
}
|
}
|
||||||
@ -1172,48 +1173,48 @@ final class DisplayPowerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendOnStateChangedWithWakelock() {
|
private void sendOnStateChangedWithWakelock() {
|
||||||
mDisplaySuspendBlocker.acquire();
|
mCallbacks.acquireSuspendBlocker();
|
||||||
mCallbackHandler.post(mOnStateChangedRunnable);
|
mHandler.post(mOnStateChangedRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Runnable mOnStateChangedRunnable = new Runnable() {
|
private final Runnable mOnStateChangedRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mCallbacks.onStateChanged();
|
mCallbacks.onStateChanged();
|
||||||
mDisplaySuspendBlocker.release();
|
mCallbacks.releaseSuspendBlocker();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void sendOnProximityPositiveWithWakelock() {
|
private void sendOnProximityPositiveWithWakelock() {
|
||||||
mDisplaySuspendBlocker.acquire();
|
mCallbacks.acquireSuspendBlocker();
|
||||||
mCallbackHandler.post(mOnProximityPositiveRunnable);
|
mHandler.post(mOnProximityPositiveRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Runnable mOnProximityPositiveRunnable = new Runnable() {
|
private final Runnable mOnProximityPositiveRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mCallbacks.onProximityPositive();
|
mCallbacks.onProximityPositive();
|
||||||
mDisplaySuspendBlocker.release();
|
mCallbacks.releaseSuspendBlocker();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void sendOnProximityNegativeWithWakelock() {
|
private void sendOnProximityNegativeWithWakelock() {
|
||||||
mDisplaySuspendBlocker.acquire();
|
mCallbacks.acquireSuspendBlocker();
|
||||||
mCallbackHandler.post(mOnProximityNegativeRunnable);
|
mHandler.post(mOnProximityNegativeRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Runnable mOnProximityNegativeRunnable = new Runnable() {
|
private final Runnable mOnProximityNegativeRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mCallbacks.onProximityNegative();
|
mCallbacks.onProximityNegative();
|
||||||
mDisplaySuspendBlocker.release();
|
mCallbacks.releaseSuspendBlocker();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void dump(final PrintWriter pw) {
|
public void dump(final PrintWriter pw) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
pw.println();
|
pw.println();
|
||||||
pw.println("Display Controller Locked State:");
|
pw.println("Display Power Controller Locked State:");
|
||||||
pw.println(" mDisplayReadyLocked=" + mDisplayReadyLocked);
|
pw.println(" mDisplayReadyLocked=" + mDisplayReadyLocked);
|
||||||
pw.println(" mPendingRequestLocked=" + mPendingRequestLocked);
|
pw.println(" mPendingRequestLocked=" + mPendingRequestLocked);
|
||||||
pw.println(" mPendingRequestChangedLocked=" + mPendingRequestChangedLocked);
|
pw.println(" mPendingRequestChangedLocked=" + mPendingRequestChangedLocked);
|
||||||
@ -1223,7 +1224,7 @@ final class DisplayPowerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pw.println();
|
pw.println();
|
||||||
pw.println("Display Controller Configuration:");
|
pw.println("Display Power Controller Configuration:");
|
||||||
pw.println(" mScreenBrightnessDozeConfig=" + mScreenBrightnessDozeConfig);
|
pw.println(" mScreenBrightnessDozeConfig=" + mScreenBrightnessDozeConfig);
|
||||||
pw.println(" mScreenBrightnessDimConfig=" + mScreenBrightnessDimConfig);
|
pw.println(" mScreenBrightnessDimConfig=" + mScreenBrightnessDimConfig);
|
||||||
pw.println(" mScreenBrightnessRangeMinimum=" + mScreenBrightnessRangeMinimum);
|
pw.println(" mScreenBrightnessRangeMinimum=" + mScreenBrightnessRangeMinimum);
|
||||||
@ -1243,7 +1244,7 @@ final class DisplayPowerController {
|
|||||||
|
|
||||||
private void dumpLocal(PrintWriter pw) {
|
private void dumpLocal(PrintWriter pw) {
|
||||||
pw.println();
|
pw.println();
|
||||||
pw.println("Display Controller Thread State:");
|
pw.println("Display Power Controller Thread State:");
|
||||||
pw.println(" mPowerRequest=" + mPowerRequest);
|
pw.println(" mPowerRequest=" + mPowerRequest);
|
||||||
pw.println(" mWaitingForNegativeProximity=" + mWaitingForNegativeProximity);
|
pw.println(" mWaitingForNegativeProximity=" + mWaitingForNegativeProximity);
|
||||||
|
|
||||||
@ -1302,15 +1303,6 @@ final class DisplayPowerController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Asynchronous callbacks from the power controller to the power manager service.
|
|
||||||
*/
|
|
||||||
public interface Callbacks {
|
|
||||||
void onStateChanged();
|
|
||||||
void onProximityPositive();
|
|
||||||
void onProximityNegative();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class DisplayControllerHandler extends Handler {
|
private final class DisplayControllerHandler extends Handler {
|
||||||
public DisplayControllerHandler(Looper looper) {
|
public DisplayControllerHandler(Looper looper) {
|
||||||
super(looper, null, true /*async*/);
|
super(looper, null, true /*async*/);
|
@ -14,10 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.power;
|
package com.android.server.display;
|
||||||
|
|
||||||
import com.android.server.lights.Light;
|
import com.android.server.lights.Light;
|
||||||
|
|
||||||
|
import android.hardware.display.DisplayManagerInternal.DisplayPowerCallbacks;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@ -32,8 +33,8 @@ import java.io.PrintWriter;
|
|||||||
/**
|
/**
|
||||||
* Controls the display power state.
|
* Controls the display power state.
|
||||||
* <p>
|
* <p>
|
||||||
* This component is similar in nature to a {@link View} except that it describes
|
* This component is similar in nature to a {@link android.view.View} except that it
|
||||||
* the properties of a display. When properties are changed, the component
|
* describes the properties of a display. When properties are changed, the component
|
||||||
* invalidates itself and posts a callback to apply the changes in a consistent order.
|
* invalidates itself and posts a callback to apply the changes in a consistent order.
|
||||||
* This mechanism enables multiple properties of the display power state to be animated
|
* This mechanism enables multiple properties of the display power state to be animated
|
||||||
* together smoothly by the animation framework. Some of the work to blank or unblank
|
* together smoothly by the animation framework. Some of the work to blank or unblank
|
||||||
@ -43,8 +44,7 @@ import java.io.PrintWriter;
|
|||||||
* that belongs to the {@link DisplayPowerController}.
|
* that belongs to the {@link DisplayPowerController}.
|
||||||
* </p><p>
|
* </p><p>
|
||||||
* We don't need to worry about holding a suspend blocker here because the
|
* We don't need to worry about holding a suspend blocker here because the
|
||||||
* {@link PowerManagerService} does that for us whenever there is a change
|
* power manager does that for us whenever there is a change in progress.
|
||||||
* in progress.
|
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
final class DisplayPowerState {
|
final class DisplayPowerState {
|
||||||
@ -55,7 +55,7 @@ final class DisplayPowerState {
|
|||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
private final Choreographer mChoreographer;
|
private final Choreographer mChoreographer;
|
||||||
private final ElectronBeam mElectronBeam;
|
private final ElectronBeam mElectronBeam;
|
||||||
private final DisplayBlanker mDisplayBlanker;
|
private final DisplayPowerCallbacks mCallbacks;
|
||||||
private final Light mBacklight;
|
private final Light mBacklight;
|
||||||
private final PhotonicModulator mPhotonicModulator;
|
private final PhotonicModulator mPhotonicModulator;
|
||||||
|
|
||||||
@ -72,11 +72,11 @@ final class DisplayPowerState {
|
|||||||
private Runnable mCleanListener;
|
private Runnable mCleanListener;
|
||||||
|
|
||||||
public DisplayPowerState(ElectronBeam electronBean,
|
public DisplayPowerState(ElectronBeam electronBean,
|
||||||
DisplayBlanker displayBlanker, Light backlight) {
|
DisplayPowerCallbacks callbacks, Light backlight) {
|
||||||
mHandler = new Handler(true /*async*/);
|
mHandler = new Handler(true /*async*/);
|
||||||
mChoreographer = Choreographer.getInstance();
|
mChoreographer = Choreographer.getInstance();
|
||||||
mElectronBeam = electronBean;
|
mElectronBeam = electronBean;
|
||||||
mDisplayBlanker = displayBlanker;
|
mCallbacks = callbacks;
|
||||||
mBacklight = backlight;
|
mBacklight = backlight;
|
||||||
mPhotonicModulator = new PhotonicModulator();
|
mPhotonicModulator = new PhotonicModulator();
|
||||||
|
|
||||||
@ -403,13 +403,13 @@ final class DisplayPowerState {
|
|||||||
+ ", backlight=" + backlight);
|
+ ", backlight=" + backlight);
|
||||||
}
|
}
|
||||||
if (onChanged && on) {
|
if (onChanged && on) {
|
||||||
mDisplayBlanker.unblankAllDisplays();
|
mCallbacks.unblankAllDisplays();
|
||||||
}
|
}
|
||||||
if (backlightChanged) {
|
if (backlightChanged) {
|
||||||
mBacklight.setBrightness(backlight);
|
mBacklight.setBrightness(backlight);
|
||||||
}
|
}
|
||||||
if (onChanged && !on) {
|
if (onChanged && !on) {
|
||||||
mDisplayBlanker.blankAllDisplays();
|
mCallbacks.blankAllDisplays();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.power;
|
package com.android.server.display;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.server.power;
|
package com.android.server.display;
|
||||||
|
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.util.IntProperty;
|
import android.util.IntProperty;
|
@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 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.
|
|
||||||
* 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 com.android.server.power;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Blanks or unblanks all displays.
|
|
||||||
*/
|
|
||||||
interface DisplayBlanker {
|
|
||||||
public void blankAllDisplays();
|
|
||||||
public void unblankAllDisplays();
|
|
||||||
}
|
|
@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 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.
|
|
||||||
* 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 com.android.server.power;
|
|
||||||
|
|
||||||
import android.os.PowerManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes the requested power state of the display.
|
|
||||||
*
|
|
||||||
* This object is intended to describe the general characteristics of the
|
|
||||||
* power state, such as whether the screen should be on or off and the current
|
|
||||||
* brightness controls leaving the {@link DisplayPowerController} to manage the
|
|
||||||
* details of how the transitions between states should occur. The goal is for
|
|
||||||
* the {@link PowerManagerService} to focus on the global power state and not
|
|
||||||
* have to micro-manage screen off animations, auto-brightness and other effects.
|
|
||||||
*/
|
|
||||||
final class DisplayPowerRequest {
|
|
||||||
public static final int SCREEN_STATE_OFF = 0;
|
|
||||||
public static final int SCREEN_STATE_DOZE = 1;
|
|
||||||
public static final int SCREEN_STATE_DIM = 2;
|
|
||||||
public static final int SCREEN_STATE_BRIGHT = 3;
|
|
||||||
|
|
||||||
// The requested minimum screen power state: off, doze, dim or bright.
|
|
||||||
public int screenState;
|
|
||||||
|
|
||||||
// If true, the proximity sensor overrides the screen state when an object is
|
|
||||||
// nearby, turning it off temporarily until the object is moved away.
|
|
||||||
public boolean useProximitySensor;
|
|
||||||
|
|
||||||
// The desired screen brightness in the range 0 (minimum / off) to 255 (brightest).
|
|
||||||
// The display power controller may choose to clamp the brightness.
|
|
||||||
// When auto-brightness is enabled, this field should specify a nominal default
|
|
||||||
// value to use while waiting for the light sensor to report enough data.
|
|
||||||
public int screenBrightness;
|
|
||||||
|
|
||||||
// The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter).
|
|
||||||
public float screenAutoBrightnessAdjustment;
|
|
||||||
|
|
||||||
// If true, enables automatic brightness control.
|
|
||||||
public boolean useAutoBrightness;
|
|
||||||
|
|
||||||
// If true, prevents the screen from completely turning on if it is currently off.
|
|
||||||
// The display does not enter a "ready" state if this flag is true and screen on is
|
|
||||||
// blocked. The window manager policy blocks screen on while it prepares the keyguard to
|
|
||||||
// prevent the user from seeing intermediate updates.
|
|
||||||
//
|
|
||||||
// Technically, we may not block the screen itself from turning on (because that introduces
|
|
||||||
// extra unnecessary latency) but we do prevent content on screen from becoming
|
|
||||||
// visible to the user.
|
|
||||||
public boolean blockScreenOn;
|
|
||||||
|
|
||||||
public DisplayPowerRequest() {
|
|
||||||
screenState = SCREEN_STATE_BRIGHT;
|
|
||||||
useProximitySensor = false;
|
|
||||||
screenBrightness = PowerManager.BRIGHTNESS_ON;
|
|
||||||
screenAutoBrightnessAdjustment = 0.0f;
|
|
||||||
useAutoBrightness = false;
|
|
||||||
blockScreenOn = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DisplayPowerRequest(DisplayPowerRequest other) {
|
|
||||||
copyFrom(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if we want the screen on in any mode, including doze.
|
|
||||||
public boolean wantScreenOnAny() {
|
|
||||||
return screenState != SCREEN_STATE_OFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if we want the screen on in a normal mode, excluding doze.
|
|
||||||
// This is usually what we want to tell the rest of the system. For compatibility
|
|
||||||
// reasons, we pretend the screen is off when dozing.
|
|
||||||
public boolean wantScreenOnNormal() {
|
|
||||||
return screenState == SCREEN_STATE_DIM || screenState == SCREEN_STATE_BRIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean wantLightSensorEnabled() {
|
|
||||||
// Specifically, we don't want the light sensor while dozing.
|
|
||||||
return useAutoBrightness && wantScreenOnNormal();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyFrom(DisplayPowerRequest other) {
|
|
||||||
screenState = other.screenState;
|
|
||||||
useProximitySensor = other.useProximitySensor;
|
|
||||||
screenBrightness = other.screenBrightness;
|
|
||||||
screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
|
|
||||||
useAutoBrightness = other.useAutoBrightness;
|
|
||||||
blockScreenOn = other.blockScreenOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return o instanceof DisplayPowerRequest
|
|
||||||
&& equals((DisplayPowerRequest)o);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(DisplayPowerRequest other) {
|
|
||||||
return other != null
|
|
||||||
&& screenState == other.screenState
|
|
||||||
&& useProximitySensor == other.useProximitySensor
|
|
||||||
&& screenBrightness == other.screenBrightness
|
|
||||||
&& screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
|
|
||||||
&& useAutoBrightness == other.useAutoBrightness
|
|
||||||
&& blockScreenOn == other.blockScreenOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return 0; // don't care
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "screenState=" + screenState
|
|
||||||
+ ", useProximitySensor=" + useProximitySensor
|
|
||||||
+ ", screenBrightness=" + screenBrightness
|
|
||||||
+ ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
|
|
||||||
+ ", useAutoBrightness=" + useAutoBrightness
|
|
||||||
+ ", blockScreenOn=" + blockScreenOn;
|
|
||||||
}
|
|
||||||
}
|
|
@ -188,51 +188,6 @@ final class Notifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the screen is turned on.
|
|
||||||
*/
|
|
||||||
public void onScreenOn() {
|
|
||||||
if (DEBUG) {
|
|
||||||
Slog.d(TAG, "onScreenOn");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mBatteryStats.noteScreenOn();
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the screen is turned off.
|
|
||||||
*/
|
|
||||||
public void onScreenOff() {
|
|
||||||
if (DEBUG) {
|
|
||||||
Slog.d(TAG, "onScreenOff");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mBatteryStats.noteScreenOff();
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the screen changes brightness.
|
|
||||||
*/
|
|
||||||
public void onScreenBrightness(int brightness) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Slog.d(TAG, "onScreenBrightness: brightness=" + brightness);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mBatteryStats.noteScreenBrightness(brightness);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the device is waking up from sleep and the
|
* Called when the device is waking up from sleep and the
|
||||||
* display is about to be turned on.
|
* display is about to be turned on.
|
||||||
|
@ -24,7 +24,6 @@ import com.android.server.LocalServices;
|
|||||||
import com.android.server.ServiceThread;
|
import com.android.server.ServiceThread;
|
||||||
import com.android.server.lights.Light;
|
import com.android.server.lights.Light;
|
||||||
import com.android.server.lights.LightsManager;
|
import com.android.server.lights.LightsManager;
|
||||||
import com.android.server.twilight.TwilightManager;
|
|
||||||
import com.android.server.Watchdog;
|
import com.android.server.Watchdog;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
@ -39,6 +38,7 @@ import android.database.ContentObserver;
|
|||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.hardware.SystemSensorManager;
|
import android.hardware.SystemSensorManager;
|
||||||
import android.hardware.display.DisplayManagerInternal;
|
import android.hardware.display.DisplayManagerInternal;
|
||||||
|
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
@ -177,7 +177,6 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
private PowerManagerHandler mHandler;
|
private PowerManagerHandler mHandler;
|
||||||
private WindowManagerPolicy mPolicy;
|
private WindowManagerPolicy mPolicy;
|
||||||
private Notifier mNotifier;
|
private Notifier mNotifier;
|
||||||
private DisplayPowerController mDisplayPowerController;
|
|
||||||
private WirelessChargerDetector mWirelessChargerDetector;
|
private WirelessChargerDetector mWirelessChargerDetector;
|
||||||
private SettingsObserver mSettingsObserver;
|
private SettingsObserver mSettingsObserver;
|
||||||
private DreamManagerInternal mDreamManager;
|
private DreamManagerInternal mDreamManager;
|
||||||
@ -258,9 +257,6 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
// screen is coming up.
|
// screen is coming up.
|
||||||
private final ScreenOnBlockerImpl mScreenOnBlocker;
|
private final ScreenOnBlockerImpl mScreenOnBlocker;
|
||||||
|
|
||||||
// The display blanker used to turn the screen on or off.
|
|
||||||
private final DisplayBlankerImpl mDisplayBlanker;
|
|
||||||
|
|
||||||
// True if systemReady() has been called.
|
// True if systemReady() has been called.
|
||||||
private boolean mSystemReady;
|
private boolean mSystemReady;
|
||||||
|
|
||||||
@ -417,7 +413,6 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
mHoldingDisplaySuspendBlocker = true;
|
mHoldingDisplaySuspendBlocker = true;
|
||||||
|
|
||||||
mScreenOnBlocker = new ScreenOnBlockerImpl();
|
mScreenOnBlocker = new ScreenOnBlockerImpl();
|
||||||
mDisplayBlanker = new DisplayBlankerImpl();
|
|
||||||
mWakefulness = WAKEFULNESS_AWAKE;
|
mWakefulness = WAKEFULNESS_AWAKE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,7 +452,7 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
// into the activity manager to check permissions. Unfortunately the
|
// into the activity manager to check permissions. Unfortunately the
|
||||||
// activity manager is not running when the constructor is called, so we
|
// activity manager is not running when the constructor is called, so we
|
||||||
// have to defer setting the screen state until this point.
|
// have to defer setting the screen state until this point.
|
||||||
mDisplayBlanker.unblankAllDisplays();
|
mDisplayPowerCallbacks.unblankAllDisplays();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPolicy(WindowManagerPolicy policy) {
|
void setPolicy(WindowManagerPolicy policy) {
|
||||||
@ -484,20 +479,16 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"),
|
mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"),
|
||||||
mScreenOnBlocker, mPolicy);
|
mScreenOnBlocker, mPolicy);
|
||||||
|
|
||||||
// The display power controller runs on the power manager service's
|
|
||||||
// own handler thread to ensure timely operation.
|
|
||||||
mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(),
|
|
||||||
mContext, mNotifier, mLightsManager,
|
|
||||||
LocalServices.getService(TwilightManager.class), sensorManager,
|
|
||||||
mDisplaySuspendBlocker, mDisplayBlanker,
|
|
||||||
mDisplayPowerControllerCallbacks, mHandler);
|
|
||||||
|
|
||||||
mWirelessChargerDetector = new WirelessChargerDetector(sensorManager,
|
mWirelessChargerDetector = new WirelessChargerDetector(sensorManager,
|
||||||
createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"),
|
createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"),
|
||||||
mHandler);
|
mHandler);
|
||||||
mSettingsObserver = new SettingsObserver(mHandler);
|
mSettingsObserver = new SettingsObserver(mHandler);
|
||||||
mAttentionLight = mLightsManager.getLight(LightsManager.LIGHT_ID_ATTENTION);
|
mAttentionLight = mLightsManager.getLight(LightsManager.LIGHT_ID_ATTENTION);
|
||||||
|
|
||||||
|
// Initialize display power management.
|
||||||
|
mDisplayManagerInternal.initPowerManagement(
|
||||||
|
mDisplayPowerCallbacks, mHandler, sensorManager);
|
||||||
|
|
||||||
// Register for broadcasts from other components of the system.
|
// Register for broadcasts from other components of the system.
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||||
@ -810,7 +801,7 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
|
case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
|
||||||
return mSystemReady && mDisplayPowerController.isProximitySensorAvailable();
|
return mSystemReady && mDisplayManagerInternal.isProximitySensorAvailable();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -1633,7 +1624,7 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
|
|
||||||
mDisplayPowerRequest.blockScreenOn = mScreenOnBlocker.isHeld();
|
mDisplayPowerRequest.blockScreenOn = mScreenOnBlocker.isHeld();
|
||||||
|
|
||||||
mDisplayReady = mDisplayPowerController.requestPowerState(mDisplayPowerRequest,
|
mDisplayReady = mDisplayManagerInternal.requestPowerState(mDisplayPowerRequest,
|
||||||
mRequestWaitForNegativeProximity);
|
mRequestWaitForNegativeProximity);
|
||||||
mRequestWaitForNegativeProximity = false;
|
mRequestWaitForNegativeProximity = false;
|
||||||
|
|
||||||
@ -1675,8 +1666,10 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
return DisplayPowerRequest.SCREEN_STATE_DIM;
|
return DisplayPowerRequest.SCREEN_STATE_DIM;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final DisplayPowerController.Callbacks mDisplayPowerControllerCallbacks =
|
private final DisplayManagerInternal.DisplayPowerCallbacks mDisplayPowerCallbacks =
|
||||||
new DisplayPowerController.Callbacks() {
|
new DisplayManagerInternal.DisplayPowerCallbacks() {
|
||||||
|
private boolean mBlanked;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStateChanged() {
|
public void onStateChanged() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
@ -1704,6 +1697,51 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
updatePowerStateLocked();
|
updatePowerStateLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acquireSuspendBlocker() {
|
||||||
|
mDisplaySuspendBlocker.acquire();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void releaseSuspendBlocker() {
|
||||||
|
mDisplaySuspendBlocker.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void blankAllDisplays() {
|
||||||
|
synchronized (this) {
|
||||||
|
mBlanked = true;
|
||||||
|
mDisplayManagerInternal.blankAllDisplaysFromPowerManager();
|
||||||
|
if (!mDecoupleInteractiveModeFromDisplayConfig) {
|
||||||
|
setInteractiveModeLocked(false);
|
||||||
|
}
|
||||||
|
if (!mDecoupleAutoSuspendModeFromDisplayConfig) {
|
||||||
|
setAutoSuspendModeLocked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unblankAllDisplays() {
|
||||||
|
synchronized (this) {
|
||||||
|
if (!mDecoupleAutoSuspendModeFromDisplayConfig) {
|
||||||
|
setAutoSuspendModeLocked(false);
|
||||||
|
}
|
||||||
|
if (!mDecoupleInteractiveModeFromDisplayConfig) {
|
||||||
|
setInteractiveModeLocked(true);
|
||||||
|
}
|
||||||
|
mDisplayManagerInternal.unblankAllDisplaysFromPowerManager();
|
||||||
|
mBlanked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
synchronized (this) {
|
||||||
|
return "blanked=" + mBlanked;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private boolean shouldUseProximitySensorLocked() {
|
private boolean shouldUseProximitySensorLocked() {
|
||||||
@ -2018,7 +2056,6 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
private void dumpInternal(PrintWriter pw) {
|
private void dumpInternal(PrintWriter pw) {
|
||||||
pw.println("POWER MANAGER (dumpsys power)\n");
|
pw.println("POWER MANAGER (dumpsys power)\n");
|
||||||
|
|
||||||
final DisplayPowerController dpc;
|
|
||||||
final WirelessChargerDetector wcd;
|
final WirelessChargerDetector wcd;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
pw.println("Power Manager State:");
|
pw.println("Power Manager State:");
|
||||||
@ -2123,16 +2160,11 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
pw.println("Screen On Blocker: " + mScreenOnBlocker);
|
pw.println("Screen On Blocker: " + mScreenOnBlocker);
|
||||||
|
|
||||||
pw.println();
|
pw.println();
|
||||||
pw.println("Display Blanker: " + mDisplayBlanker);
|
pw.println("Display Power: " + mDisplayPowerCallbacks);
|
||||||
|
|
||||||
dpc = mDisplayPowerController;
|
|
||||||
wcd = mWirelessChargerDetector;
|
wcd = mWirelessChargerDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpc != null) {
|
|
||||||
dpc.dump(pw);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wcd != null) {
|
if (wcd != null) {
|
||||||
wcd.dump(pw);
|
wcd.dump(pw);
|
||||||
}
|
}
|
||||||
@ -2467,45 +2499,6 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class DisplayBlankerImpl implements DisplayBlanker {
|
|
||||||
private boolean mBlanked;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void blankAllDisplays() {
|
|
||||||
synchronized (this) {
|
|
||||||
mBlanked = true;
|
|
||||||
mDisplayManagerInternal.blankAllDisplaysFromPowerManager();
|
|
||||||
if (!mDecoupleInteractiveModeFromDisplayConfig) {
|
|
||||||
setInteractiveModeLocked(false);
|
|
||||||
}
|
|
||||||
if (!mDecoupleAutoSuspendModeFromDisplayConfig) {
|
|
||||||
setAutoSuspendModeLocked(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unblankAllDisplays() {
|
|
||||||
synchronized (this) {
|
|
||||||
if (!mDecoupleAutoSuspendModeFromDisplayConfig) {
|
|
||||||
setAutoSuspendModeLocked(false);
|
|
||||||
}
|
|
||||||
if (!mDecoupleInteractiveModeFromDisplayConfig) {
|
|
||||||
setInteractiveModeLocked(true);
|
|
||||||
}
|
|
||||||
mDisplayManagerInternal.unblankAllDisplaysFromPowerManager();
|
|
||||||
mBlanked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
synchronized (this) {
|
|
||||||
return "blanked=" + mBlanked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class BinderService extends IPowerManager.Stub {
|
private final class BinderService extends IPowerManager.Stub {
|
||||||
@Override // Binder call
|
@Override // Binder call
|
||||||
public void acquireWakeLockWithUid(IBinder lock, int flags, String tag,
|
public void acquireWakeLockWithUid(IBinder lock, int flags, String tag,
|
||||||
@ -2830,7 +2823,7 @@ public final class PowerManagerService extends com.android.server.SystemService
|
|||||||
*
|
*
|
||||||
* @param adj The overridden brightness, or Float.NaN to disable the override.
|
* @param adj The overridden brightness, or Float.NaN to disable the override.
|
||||||
*
|
*
|
||||||
* @see Settings.System#SCREEN_AUTO_BRIGHTNESS_ADJ
|
* @see android.provider.Settings.System#SCREEN_AUTO_BRIGHTNESS_ADJ
|
||||||
*/
|
*/
|
||||||
@Override // Binder call
|
@Override // Binder call
|
||||||
public void setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(float adj) {
|
public void setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(float adj) {
|
||||||
|
Reference in New Issue
Block a user