-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera-allow-camera-to-use-power-key-as-shutter.patch
146 lines (122 loc) · 6.38 KB
/
Camera-allow-camera-to-use-power-key-as-shutter.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From c405e7598b381eed4ace7fd650bf3740f25e439f Mon Sep 17 00:00:00 2001
From: Kyle Harrison <[email protected]>
Date: Tue, 29 May 2018 19:35:46 +0100
Subject: [PATCH] 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
PhoneWindowManager: add mTopFullscreenOpaqueWindowState null check to fix exception
Discovered through extensive testing with double press power for camera combined
with long press power for torch (though these features are not required to
trigger the issue), lack of null check here can occasionally result in either of:
1) screen is off, power press will NOT turn the screen on (needs to be woken
via fingerprint, power cable connect or leave device for a minute or
so and it will eventually wake on power press again).
OR
2) screen is on, power press will not turn the screen off
It requires pressing power shortly after screen off or screen on at just
the right time to trigger. Issue is reproducible on angler.
E InputManager-JNI: An exception was thrown by callback 'interceptKeyBeforeQueueing'.
E InputManager-JNI: java.lang.NullPointerException: Attempt to invoke interface method
'android.view.WindowManager$LayoutParams android.view.WindowManagerPolicy$WindowState.getAttrs()'
on a null object reference
E InputManager-JNI: at com.android.server.policy.PhoneWindowManager.interceptKeyBeforeQueueing(PhoneWindowManager.java:6647)
E InputManager-JNI: at com.android.server.wm.InputMonitor.interceptKeyBeforeQueueing(InputMonitor.java:399)
E InputManager-JNI: at com.android.server.input.InputManagerService.interceptKeyBeforeQueueing(InputManagerService.java:1979)
Change-Id: I77d094130d58b152fdfa515f53661543976b33bf
(cherry picked from commit dc0c974e6a904dc637b8c49ed67d34f17fea5532)
core: Update PREVENT_POWER_KEY permission for M
Change-Id: Iac053a317314fad08545c8dc411ad44f977b8f3e
WindowManager: Add clearPrivateFlags
Change-Id: I0b51a52bf26f3566e74063e22f5c1b187c74b525
fix derp
Change-Id: Ie592990dc3442e0ab4e2643c52a7139c76568bde
---
core/java/android/view/Window.java | 9 +++++++++
core/java/android/view/WindowManager.java | 6 ++++++
core/res/AndroidManifest.xml | 6 ++++++
.../com/android/server/policy/PhoneWindowManager.java | 6 ++++++
4 files changed, 27 insertions(+)
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 3d6af414a3a..06b20d42ab8 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -1088,6 +1088,11 @@ public abstract class Window {
setFlags(0, flags);
}
+ /** @hide */
+ public void clearPrivateFlags(int flags) {
+ setPrivateFlags(0, flags);
+ }
+
/**
* Set the flags of the window, as per the
* {@link WindowManager.LayoutParams WindowManager.LayoutParams}
@@ -1115,6 +1120,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 654b40a5bfd..56869860abd 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -1463,6 +1463,12 @@ public interface WindowManager extends ViewManager {
*/
public static final int PRIVATE_FLAG_WAS_NOT_FULLSCREEN = 0x04000000;
+ /**
+ * 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 3ed60045fdb..f165ee2aed3 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -3575,6 +3575,12 @@
android:description="@string/permdesc_accessFontManager"
android:protectionLevel="signatureOrSystem" />
+ <!-- Allows an application to override the power key action
+ @hide <p>Not for use by third-party applications.
+ -->
+ <permission android:name="android.permission.PREVENT_POWER_KEY"
+ android:protectionLevel="signature|privileged" />
+
<application android:process="system"
android:persistent="true"
android:hasCode="false"
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index e7df7aa0d70..12e361d274b 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -6632,6 +6632,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
case KeyEvent.KEYCODE_POWER: {
+ if (mTopFullscreenOpaqueWindowState != null
+ && (mTopFullscreenOpaqueWindowState.getAttrs().privateFlags
+ & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY) != 0
+ && mScreenOnFully) {
+ return result;
+ }
// Any activity on the power button stops the accessibility shortcut
cancelPendingAccessibilityShortcutAction();
result &= ~ACTION_PASS_TO_USER;
--
2.17.0