Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/java/android/os/IPowerManager.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ interface IPowerManager

void setKeyboardLight(boolean on, int key);

// sets the delay after which to check the proximity to decide whether
// to wake the device
void wakeUpWithProximityCheck(long time, String reason, String opPackageName);
}
1 change: 0 additions & 1 deletion core/java/android/os/PowerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,6 @@ public void wakeUpWithProximityCheck(long time, String reason) {
try {
mService.wakeUpWithProximityCheck(time, reason, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}

Expand Down
7 changes: 7 additions & 0 deletions core/res/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2947,4 +2947,11 @@

<!-- Whether notify fingerprint client of successful cancelled authentication -->
<bool name="config_notifyClientOnFingerprintCancelSuccess">false</bool>

<!-- Default value for proximity check on screen wake
NOTE ! - Enable for devices that have a fast response proximity sensor (ideally < 300ms)
-->
<bool name="config_proximityCheckOnWake">false</bool>
<integer name="config_proximityCheckTimeout">250</integer>

</resources>
6 changes: 6 additions & 0 deletions packages/SystemUI/res/values-sw900dp/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@
<!-- Nav bar button default ordering/layout -->
<string name="config_navBarLayout" translatable="false">back,home;space;menu_ime,recent</string>

<!-- Proximity check on screen on -->
<java-symbol type="bool" name="config_proximityCheckOnWake" />

<!-- Proximity check timeout on screen on -->
<java-symbol type="integer" name="config_proximityCheckTimeout" />

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ private void updatePowerState() {
} else {
setProximitySensorEnabled(false);
mWaitingForNegativeProximity = false;
mProximity = PROXIMITY_UNKNOWN;
}
if (mScreenOffBecauseOfProximity
&& mProximity != PROXIMITY_POSITIVE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7372,15 +7372,15 @@ public void finishedWakingUp() {
}

private void wakeUpFromPowerKey(long eventTime) {
wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER", true);
}

private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
return wakeUp(wakeTime, wakeInTheaterMode, reason, false);
}

private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason,
final boolean withProximityCheck) {
boolean withProximityCheck) {
final boolean theaterModeEnabled = isTheaterModeEnabled();
if (!wakeInTheaterMode && theaterModeEnabled) {
return false;
Expand Down
131 changes: 124 additions & 7 deletions services/core/java/com/android/server/power/PowerManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
import java.util.ArrayList;
import java.util.Arrays;

import slim.provider.SlimSettings;

import static android.os.PowerManagerInternal.POWER_HINT_INTERACTION;
import static android.os.PowerManagerInternal.WAKEFULNESS_ASLEEP;
import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE;
Expand All @@ -118,6 +120,8 @@ public final class PowerManagerService extends SystemService
private static final int MSG_SCREEN_BRIGHTNESS_BOOST_TIMEOUT = 3;
// Message: Polling to look for long held wake locks.
private static final int MSG_CHECK_FOR_LONG_WAKELOCKS = 4;
// Message: Sent when the screen on is requested.
private static final int MSG_WAKE_UP = 5;

private static final int MSG_WAKE_UP = 5;

Expand Down Expand Up @@ -196,6 +200,9 @@ public final class PowerManagerService extends SystemService
private static final int HALT_MODE_REBOOT = 1;
private static final int HALT_MODE_REBOOT_SAFE_MODE = 2;

// Threshold for proximity check on wakeup
private static final float PROXIMITY_NEAR_THRESHOLD = 5.0f;

private static final int BUTTON_ON_DURATION = 5 * 1000;

private static final float PROXIMITY_NEAR_THRESHOLD = 5.0f;
Expand Down Expand Up @@ -571,6 +578,14 @@ public final class PowerManagerService extends SystemService
private SensorEventListener mProximityListener;
private android.os.PowerManager.WakeLock mProximityWakeLock;

private SensorManager mSensorManager;
private Sensor mProximitySensor;
private boolean mProximityWakeEnabled;
private int mProximityTimeOut;
private boolean mProximityWakeSupported;
android.os.PowerManager.WakeLock mProximityWakeLock;
SensorEventListener mProximityListener;

public PowerManagerService(Context context) {
super(context);
mContext = context;
Expand Down Expand Up @@ -768,6 +783,9 @@ mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"),
resolver.registerContentObserver(CMSettings.System.getUriFor(
CMSettings.System.PROXIMITY_ON_WAKE),
false, mSettingsObserver, UserHandle.USER_ALL);
resolver.registerContentObserver(SlimSettings.System.getUriFor(
SlimSettings.System.PROXIMITY_ON_WAKE),
false, mSettingsObserver, UserHandle.USER_ALL);

// Go.
readConfigurationLocked();
Expand Down Expand Up @@ -816,15 +834,14 @@ private void readConfigurationLocked() {
com.android.internal.R.fraction.config_maximumScreenDimRatio, 1, 1);
mSupportsDoubleTapWakeConfig = resources.getBoolean(
com.android.internal.R.bool.config_supportDoubleTapWake);
mProximityWakeSupported = resources.getBoolean(
org.cyanogenmod.platform.internal.R.bool.config_proximityCheckOnWake);
mProximityWakeEnabledByDefaultConfig = resources.getBoolean(
org.cyanogenmod.platform.internal.R.bool.config_proximityCheckOnWakeEnabledByDefault);
mProximityTimeOut = resources.getInteger(
org.cyanogenmod.platform.internal.R.integer.config_proximityCheckTimeout);
com.android.internal.R.integer.config_proximityCheckTimeout);
mProximityWakeSupported = resources.getBoolean(
com.android.internal.R.bool.config_proximityCheckOnWake);
if (mProximityWakeSupported) {
mProximityWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ProximityWakeLock");
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mProximityWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"ProximityWakeLock");
}
}

Expand Down Expand Up @@ -853,9 +870,14 @@ private void updateSettingsLocked() {
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC);
mTheaterModeEnabled = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.THEATER_MODE_ON, 0) == 1;
<<<<<<< HEAD
mWakeUpWhenPluggedOrUnpluggedSetting = CMSettings.Global.getInt(resolver,
CMSettings.Global.WAKE_WHEN_PLUGGED_OR_UNPLUGGED,
(mWakeUpWhenPluggedOrUnpluggedConfig ? 1 : 0));
=======
mProximityWakeEnabled = SlimSettings.System.getInt(resolver,
SlimSettings.System.PROXIMITY_ON_WAKE, 0) == 1;
>>>>>>> 929a2a8a003... [1/3] frameworks_base: Add ProximityWake

if (mSupportsDoubleTapWakeConfig) {
boolean doubleTapWakeEnabled = Settings.Secure.getIntForUser(resolver,
Expand Down Expand Up @@ -3506,6 +3528,22 @@ public String toString() {
}
}

private void cleanupProximity() {
synchronized (mProximityWakeLock) {
cleanupProximityLocked();
}
}

private void cleanupProximityLocked() {
if (mProximityWakeLock.isHeld()) {
mProximityWakeLock.release();
}
if (mProximityListener != null) {
mSensorManager.unregisterListener(mProximityListener);
mProximityListener = null;
}
}

private final class BinderService extends IPowerManager.Stub {
@Override // Binder call
public void acquireWakeLockWithUid(IBinder lock, int flags, String tag,
Expand Down Expand Up @@ -3660,6 +3698,7 @@ public void userActivity(long eventTime, int event, int flags) {
}
}

<<<<<<< HEAD
@Override // Binder call
public void setKeyboardVisibility(boolean visible) {
synchronized (mLock) {
Expand Down Expand Up @@ -3711,6 +3750,13 @@ public void wakeUpWithProximityCheck(long eventTime, String reason, String opPac
*/
private void wakeUp(long eventTime, String reason, String opPackageName,
final boolean checkProximity) {
=======
/**
* @hide
*/
private void wakeUp(final long eventTime, final String reason, final String opPackageName,
boolean checkProximity) {
>>>>>>> 929a2a8a003... [1/3] frameworks_base: Add ProximityWake
if (eventTime > SystemClock.uptimeMillis()) {
throw new IllegalArgumentException("event time must not be in the future");
}
Expand All @@ -3719,7 +3765,11 @@ private void wakeUp(long eventTime, String reason, String opPackageName,
android.Manifest.permission.DEVICE_POWER, null);

final int uid = Binder.getCallingUid();
<<<<<<< HEAD
final Runnable r = new Runnable() {
=======
Runnable r = new Runnable() {
>>>>>>> 929a2a8a003... [1/3] frameworks_base: Add ProximityWake
@Override
public void run() {
final long ident = Binder.clearCallingIdentity();
Expand All @@ -3734,9 +3784,76 @@ public void run() {
runWithProximityCheck(r);
} else {
r.run();
<<<<<<< HEAD
=======
}
}

private void runWithProximityCheck(Runnable r) {
if (mHandler.hasMessages(MSG_WAKE_UP)) {
// There is already a message queued;
return;
}

TelephonyManager tm = (TelephonyManager)mContext.getSystemService(
Context.TELEPHONY_SERVICE);
boolean hasIncomingCall = tm.getCallState() == TelephonyManager.CALL_STATE_RINGING;

if (mProximityWakeSupported && mProximityWakeEnabled && mProximitySensor != null
&& !hasIncomingCall) {
Message msg = mHandler.obtainMessage(MSG_WAKE_UP);
msg.obj = r;
mHandler.sendMessageDelayed(msg, mProximityTimeOut);
runPostProximityCheck(r);
} else {
r.run();
}
}

private void runPostProximityCheck(final Runnable r) {
if (mSensorManager == null) {
r.run();
return;
>>>>>>> 929a2a8a003... [1/3] frameworks_base: Add ProximityWake
}
synchronized (mProximityWakeLock) {
mProximityWakeLock.acquire();
mProximityListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
cleanupProximityLocked();
if (!mHandler.hasMessages(MSG_WAKE_UP)) {
Slog.w(TAG, "The proximity sensor took too long, wake event already triggered!");
return;
}
mHandler.removeMessages(MSG_WAKE_UP);
float distance = event.values[0];
if (distance >= PROXIMITY_NEAR_THRESHOLD ||
distance >= mProximitySensor.getMaximumRange()) {
r.run();
} else {
Slog.w(TAG, "Not waking up. Proximity sensor blocked.");
}
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
};
mSensorManager.registerListener(mProximityListener,
mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
}
}

@Override // Binder call
public void wakeUpWithProximityCheck(long eventTime, String reason, String opPackageName) {
wakeUp(eventTime, reason, opPackageName, true);
}

@Override // Binder call
public void wakeUp(long eventTime, String reason, String opPackageName) {
wakeUp(eventTime, reason, opPackageName, false);
}

@Override // Binder call
public void goToSleep(long eventTime, int reason, int flags) {
if (eventTime > SystemClock.uptimeMillis()) {
Expand Down