Disable more hotkeys while in setup.
Disables fallback key processing for CALL, CAMERA, and HEADSETHOOK
buttons.
Bug: 19767816
Change-Id: I423103c367e05827c939cd8d8dbecb6012b0e9f0
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 77a1fa9..72e4b4b 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -56,6 +56,7 @@
import android.speech.RecognizerIntent;
import android.text.TextUtils;
import android.util.Log;
+import android.util.Slog;
import android.util.SparseArray;
import android.view.KeyEvent;
@@ -715,11 +716,19 @@
Log.w(TAG, "Attempted to dispatch null or non-media key event.");
return;
}
+
final int pid = Binder.getCallingPid();
final int uid = Binder.getCallingUid();
final long token = Binder.clearCallingIdentity();
-
try {
+ if (!isUserSetupComplete()) {
+ // Global media key handling can have the side-effect of starting new
+ // activities which is undesirable while setup is in progress.
+ Slog.i(TAG, "Not dispatching media key event because user "
+ + "setup is in progress.");
+ return;
+ }
+
synchronized (mLock) {
// If we don't have a media button receiver to fall back on
// include non-playing sessions for dispatching
@@ -1007,6 +1016,11 @@
return keyCode == KeyEvent.KEYCODE_HEADSETHOOK;
}
+ private boolean isUserSetupComplete() {
+ return Settings.Secure.getIntForUser(getContext().getContentResolver(),
+ Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
+ }
+
// we only handle public stream types, which are 0-5
private boolean isValidLocalStreamType(int streamType) {
return streamType >= AudioManager.STREAM_VOICE_CALL