summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2012-11-29 22:26:21 -0500
committerSteve Kondik <steve@cyngn.com>2015-10-23 16:27:01 -0500
commit8611337102e48b61932bfae32d860807ee5ee2ac (patch)
treeca5dcbf906bcd381b59e26a2db58c7f0b86439c4
parent877e66164ac51a61a700d5adb66a64f187e54740 (diff)
downloadframeworks_base-8611337102e48b61932bfae32d860807ee5ee2ac.zip
frameworks_base-8611337102e48b61932bfae32d860807ee5ee2ac.tar.gz
frameworks_base-8611337102e48b61932bfae32d860807ee5ee2ac.tar.bz2
Camera : allow camera to use power key as shutter
Provides a way for an app to take control of the power key. Used by the camera to make the power key control the shutter. Change-Id: I85a1e1761199f4604672be42a3a5005227f5451a (cherry picked from commit 15661444ae1faea831218f0c936b756de2f0698b) Prevent power key capture when screen is off The ability for an activity to capture the power key, which was added to support power key as shutter in the camera, should only allow the capture when the screen is on. Otherwise, if an activity that captures the power key is to the front when the device turns off, the user will be unable to turn it back on. Change-Id: Ib119d6914ec72554b404c1cc17eef3a932d5d402
-rw-r--r--core/java/android/view/Window.java4
-rw-r--r--core/java/android/view/WindowManager.java6
-rw-r--r--core/res/AndroidManifest.xml9
-rw-r--r--core/res/res/values/cm_strings.xml5
-rw-r--r--services/core/java/com/android/server/policy/PhoneWindowManager.java5
5 files changed, 29 insertions, 0 deletions
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 07984e9..284e12c 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -843,6 +843,10 @@ public abstract class Window {
}
private void setPrivateFlags(int flags, int mask) {
+ if ((flags & mask & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY) != 0){
+ mContext.enforceCallingOrSelfPermission("android.permission.PREVENT_POWER_KEY",
+ "No permission to prevent power key");
+ }
final WindowManager.LayoutParams attrs = getAttributes();
attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
dispatchWindowAttributesChanged(attrs);
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 45bc1df..f0431e9 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -1128,6 +1128,12 @@ public interface WindowManager extends ViewManager {
public static final int PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT = 0x00001000;
/**
+ * Window flag: Overrides default power key behavior
+ * @{hide}
+ */
+ public static final int PRIVATE_FLAG_PREVENT_POWER_KEY = 0x20000000;
+
+ /**
* Control flags that are private to the platform.
* @hide
*/
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 9ec663f..04b4033 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1137,6 +1137,15 @@
android:description="@string/permdesc_transmitIr"
android:protectionLevel="normal" />
+ <!-- Allows an application to override the power key action
+ @hide -->
+ <permission android:name="android.permission.PREVENT_POWER_KEY"
+ android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
+ android:protectionLevel="signatureOrSystem"
+ android:label="@string/permlab_preventpower"
+ android:description="@string/permdesc_preventpower" />
+
+
<!-- ==================================================== -->
<!-- Permissions related to changing audio settings -->
<!-- ==================================================== -->
diff --git a/core/res/res/values/cm_strings.xml b/core/res/res/values/cm_strings.xml
index 28a760c..2589bf4 100644
--- a/core/res/res/values/cm_strings.xml
+++ b/core/res/res/values/cm_strings.xml
@@ -45,4 +45,9 @@
<string name="permlab_changePhoneBlacklist">change phone blacklist</string>
<!-- [CHAR LIMIT=NONE] Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permdesc_changePhoneBlacklist">Allows an app to change the phone numbers that are blocked for incoming calls or messages.</string>
+
+ <string name="permlab_preventpower">override power key</string>
+ <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+ <string name="permdesc_preventpower">Allows an app to override the power key.</string>
+
</resources>
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index f70d6e6..28e33c7 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -5438,6 +5438,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
case KeyEvent.KEYCODE_POWER: {
+ if ((mTopFullscreenOpaqueWindowState.getAttrs().privateFlags
+ & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY) != 0
+ && mScreenOnFully) {
+ return result;
+ }
result &= ~ACTION_PASS_TO_USER;
isWakeKey = false; // wake-up will be handled separately
if (down) {