OSDN Git Service

Use a protected receiver for the keyguard delayed actions
authorKevin Chyn <kchyn@google.com>
Wed, 11 Apr 2018 19:55:45 +0000 (12:55 -0700)
committerKevin Chyn <kchyn@google.com>
Thu, 12 Apr 2018 00:52:20 +0000 (17:52 -0700)
Fixes: 33281221

Test: keyguard locks after the timeout
Test: with test app using code from comment #1, see the following logs
      BroadcastQueue: Permission Denial: broadcasting Intent { act=com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD

Change-Id: I8b6abbc63965a5f0b24a82949ba1925f420a1454

packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java

index d6e59c7..5f13fd9 100644 (file)
@@ -145,6 +145,8 @@ public class KeyguardViewMediator extends SystemUI {
     private static final String DELAYED_LOCK_PROFILE_ACTION =
             "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
 
+    private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
+
     // used for handler messages
     private static final int SHOW = 1;
     private static final int HIDE = 2;
@@ -688,11 +690,15 @@ public class KeyguardViewMediator extends SystemUI {
         mShowKeyguardWakeLock.setReferenceCounted(false);
 
         IntentFilter filter = new IntentFilter();
-        filter.addAction(DELAYED_KEYGUARD_ACTION);
-        filter.addAction(DELAYED_LOCK_PROFILE_ACTION);
         filter.addAction(Intent.ACTION_SHUTDOWN);
         mContext.registerReceiver(mBroadcastReceiver, filter);
 
+        final IntentFilter delayedActionFilter = new IntentFilter();
+        delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
+        delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
+        mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
+                SYSTEMUI_PERMISSION, null /* scheduler */);
+
         mKeyguardDisplayManager = new KeyguardDisplayManager(mContext, mViewMediatorCallback);
 
         mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
@@ -1456,7 +1462,10 @@ public class KeyguardViewMediator extends SystemUI {
         }
     }
 
-    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+    /**
+     * This broadcast receiver should be registered with the SystemUI permission.
+     */
+    private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
             if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
@@ -1478,7 +1487,14 @@ public class KeyguardViewMediator extends SystemUI {
                         }
                     }
                 }
-            } else if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
+            }
+        }
+    };
+
+    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
                 synchronized (KeyguardViewMediator.this){
                     mShuttingDown = true;
                 }