Skip to content
Open
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 @@ -68,4 +68,6 @@ interface IPowerManager

// controls whether PowerManager should doze after the screen turns off or not
void setDozeAfterScreenOff(boolean on);

void wakeUpWithProximityCheck(long time, String reason, String opPackageName);
}
16 changes: 16 additions & 0 deletions core/java/android/os/PowerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,22 @@ public void wakeUp(long time, String reason) {
}
}

/**
* Forces the device to wake up from sleep only if
* nothing is blocking the proximity sensor
*
* @see #wakeUp
*
* @hide
*/
public void wakeUpWithProximityCheck(long time, String reason) {
try {
mService.wakeUpWithProximityCheck(time, reason, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}

/**
* Forces the device to start napping.
* <p>
Expand Down
5 changes: 5 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -3904,6 +3904,11 @@ public boolean validate(@Nullable String value) {
public static final String DOCK_SOUNDS_ENABLED = Global.DOCK_SOUNDS_ENABLED;

private static final Validator DOCK_SOUNDS_ENABLED_VALIDATOR = BOOLEAN_VALIDATOR;
/**
* Check the proximity sensor during wakeup
* @hide
*/
public static final String PROXIMITY_ON_WAKE = "proximity_on_wake";

/**
* Whether to play sounds when the keyguard is shown and dismissed.
Expand Down
26 changes: 26 additions & 0 deletions core/java/com/android/internal/os/DeviceKeyHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2012 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 com.android.internal.os;

import android.view.KeyEvent;

public interface DeviceKeyHandler {

/**
* Invoked when an unknown key was detected by the system, letting the device handle
* this special keys prior to pass the key to the active app.
*
* @param event The key event to be handled
* @return If the event is consume
*/
public boolean handleKeyEvent(KeyEvent event);
}
13 changes: 13 additions & 0 deletions core/res/res/values/custom_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,17 @@
<!-- Whether to cleanup fingerprints upon connection to the daemon and when user switches -->
<bool name="config_cleanupUnusedFingerprints">true</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>
<bool name="config_proximityCheckOnWakeEnabledByDefault">false</bool>

<!-- Path to the library that contains a device specific key handler -->
<string name="config_deviceKeyHandlerLib" translatable="false"></string>

<!-- Name of that key handler class -->
<string name="config_deviceKeyHandlerClass" translatable="false"></string>

</resources>
13 changes: 13 additions & 0 deletions core/res/res/values/custom_symbols.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,17 @@
<!-- Whether to cleanup fingerprints upon connection to the daemon and when user switches -->
<java-symbol type="bool" name="config_cleanupUnusedFingerprints" />

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

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

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

<!-- Device KeyHandler -->
<java-symbol type="string" name="config_deviceKeyHandlerLib" />
<java-symbol type="string" name="config_deviceKeyHandlerClass" />

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
Expand Down Expand Up @@ -283,6 +284,9 @@
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.os.DeviceKeyHandler;
import com.android.internal.policy.PhoneWindow;
import com.android.internal.policy.IKeyguardService;
import com.android.internal.policy.IShortcutService;
import com.android.internal.policy.KeyguardDismissCallback;
import com.android.internal.policy.PhoneWindow;
Expand Down Expand Up @@ -310,6 +314,9 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.lang.reflect.Constructor;

import dalvik.system.PathClassLoader;

/**
* WindowManagerPolicy implementation for the Android phone UI. This
Expand Down Expand Up @@ -505,6 +512,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
/** Amount of time (in milliseconds) a toast window can be shown. */
public static final int TOAST_WINDOW_TIMEOUT = 3500; // 3.5 seconds

private DeviceKeyHandler mDeviceKeyHandler;

/**
* Lock protecting internal state. Must not call out into window
* manager with lock held. (This lock will be acquired in places
Expand Down Expand Up @@ -2789,6 +2798,28 @@ public void onShowingChanged() {
mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mProximityWakeLock = mContext.getSystemService(PowerManager.class)
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ProximityWakeLock");

String deviceKeyHandlerLib = mContext.getResources().getString(
com.android.internal.R.string.config_deviceKeyHandlerLib);

String deviceKeyHandlerClass = mContext.getResources().getString(
com.android.internal.R.string.config_deviceKeyHandlerClass);

if (!deviceKeyHandlerLib.isEmpty() && !deviceKeyHandlerClass.isEmpty()) {
PathClassLoader loader = new PathClassLoader(deviceKeyHandlerLib,
getClass().getClassLoader());
try {
Class<?> klass = loader.loadClass(deviceKeyHandlerClass);
Constructor<?> constructor = klass.getConstructor(Context.class);
mDeviceKeyHandler = (DeviceKeyHandler) constructor.newInstance(
mContext);
if(DEBUG) Slog.d(TAG, "Device key handler loaded");
} catch (Exception e) {
Slog.w(TAG, "Could not instantiate device key handler "
+ deviceKeyHandlerClass + " from class "
+ deviceKeyHandlerLib, e);
}
}
}

/**
Expand Down Expand Up @@ -5028,6 +5059,18 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
return -1;
}

// Specific device key handling
if (mDeviceKeyHandler != null) {
try {
// The device only should consume known keys.
if (mDeviceKeyHandler.handleKeyEvent(event)) {
return -1;
}
} catch (Exception e) {
Slog.w(TAG, "Could not dispatch event to device key handler", e);
}
}

if (down) {
long shortcutCode = keyCode;
if (event.isCtrlPressed()) {
Expand Down Expand Up @@ -7178,7 +7221,8 @@ public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
if (isValidGlobalKey(keyCode)
&& mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
if (isWakeKey) {
wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey,
"android.policy:KEY", true);
}
return result;
}
Expand All @@ -7195,6 +7239,18 @@ public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
// Trigger haptic feedback only for "real" events.
&& source != InputDevice.SOURCE_CUSTOM;

// Specific device key handling
if (mDeviceKeyHandler != null) {
try {
// The device only should consume known keys.
if (mDeviceKeyHandler.handleKeyEvent(event)) {
return 0;
}
} catch (Exception e) {
Slog.w(TAG, "Could not dispatch event to device key handler", e);
}
}

// Handle special keys.
switch (keyCode) {
case KeyEvent.KEYCODE_BACK: {
Expand Down Expand Up @@ -7543,7 +7599,8 @@ public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
}

if (isWakeKey) {
wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY",
event.getKeyCode() == KeyEvent.KEYCODE_WAKEUP); // Check prox only on wake key
}

return result;
Expand Down Expand Up @@ -8020,6 +8077,11 @@ private void wakeUpFromPowerKey(long eventTime) {
}

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) {
final boolean theaterModeEnabled = isTheaterModeEnabled();
if (!wakeInTheaterMode && theaterModeEnabled) {
return false;
Expand All @@ -8030,7 +8092,11 @@ private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason)
Settings.Global.THEATER_MODE_ON, 0);
}

mPowerManager.wakeUp(wakeTime, reason);
if (withProximityCheck) {
mPowerManager.wakeUpWithProximityCheck(wakeTime, reason);
} else {
mPowerManager.wakeUp(wakeTime, reason);
}
return true;
}

Expand Down
Loading