OSDN Git Service

Enforce policy for camera gesture in keyguard
authorTony Mak <tonymak@google.com>
Fri, 28 Jul 2017 10:53:56 +0000 (11:53 +0100)
committerDan Pasanen <dan.pasanen@gmail.com>
Mon, 2 Oct 2017 22:55:44 +0000 (22:55 +0000)
Test:
1. Set lock screen, set keyguard policy. Lock the device.
   Observe that double tap is not showing camera

2. Set lock screen, unset the keyguard policy. Lock the device.
   Observe that double tap is showing camera

3. Unset lock screen (swipe), set the keyguard policy. Lock the device.
   Observe that double tap is showing camera.

4. Unset lock screen (swipe), unset the keyguard policy. Lock the device.
   Observe that double tap is showing camera.

Bug: 63787722
Merged-In: I104688eaad719528376e2851f837d5956a6a1169

Change-Id: I42e6d9015682998176fe41971356bde22e1b37b2
(cherry picked from commit 65f02e8ba7a9f013d6971b3d6d1bd95f1785cb3d)

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java

index ce8a9fc..68161f6 100644 (file)
@@ -2710,4 +2710,23 @@ public abstract class BaseStatusBar extends SystemUI implements
             mAssistManager.startAssist(args);
         }
     }
+
+    public boolean isCameraAllowedByAdmin() {
+       if (mDevicePolicyManager.getCameraDisabled(null, mCurrentUserId)) {
+           return false;
+       } else if (isKeyguardShowing() && isKeyguardSecure()) {
+           // Check if the admin has disabled the camera specifically for the keyguard
+           return (mDevicePolicyManager.getKeyguardDisabledFeatures(null, mCurrentUserId)
+                   & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) == 0;
+       }
+       return true;
+    }
+
+    public boolean isKeyguardShowing() {
+        if (mStatusBarKeyguardViewManager == null) {
+            Slog.i(TAG, "isKeyguardShowing() called before startKeyguard(), returning true");
+            return true;
+        }
+        return mStatusBarKeyguardViewManager.isShowing();
+    }
 }
index 266c693..b4402a4 100644 (file)
@@ -380,7 +380,9 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
                 visible = !mShortcutHelper.isTargetEmpty(Shortcuts.RIGHT_SHORTCUT);
             } else {
                 ResolveInfo resolved = resolveCameraIntent();
-                visible = !isCameraDisabledByDpm() && resolved != null
+                boolean isCameraDisabled =
+                        (mPhoneStatusBar != null) && !mPhoneStatusBar.isCameraAllowedByAdmin();
+                visible = !isCameraDisabled && resolved != null
                         && getResources().getBoolean(R.bool.config_keyguardShowCameraAffordance);
             }
         }
@@ -422,24 +424,6 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
                 && pm.resolveActivity(PHONE_INTENT, 0) != null;
     }
 
-    private boolean isCameraDisabledByDpm() {
-        final DevicePolicyManager dpm =
-                (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
-        if (dpm != null && mPhoneStatusBar != null) {
-            try {
-                final int userId = ActivityManagerNative.getDefault().getCurrentUser().id;
-                final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId);
-                final  boolean disabledBecauseKeyguardSecure =
-                        (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0
-                                && mPhoneStatusBar.isKeyguardSecure();
-                return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure;
-            } catch (RemoteException e) {
-                Log.e(TAG, "Can't get userId", e);
-            }
-        }
-        return false;
-    }
-
     private void watchForCameraPolicyChanges() {
         final IntentFilter filter = new IntentFilter();
         filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
index bc9fce0..aff7cf3 100644 (file)
@@ -31,6 +31,7 @@ import android.graphics.Paint;
 import android.graphics.Rect;
 import android.os.PowerManager;
 import android.util.AttributeSet;
+import android.util.EventLog;
 import android.util.MathUtils;
 import android.view.GestureDetector;
 import android.view.MotionEvent;
@@ -2415,6 +2416,10 @@ public class NotificationPanelView extends PanelView implements
      * @param keyguardIsShowing whether keyguard is being shown
      */
     public boolean canCameraGestureBeLaunched(boolean keyguardIsShowing) {
+        if (!mStatusBar.isCameraAllowedByAdmin()) {
+            EventLog.writeEvent(0x534e4554, "63787722", -1, "");
+            return false;
+        }
         ResolveInfo resolveInfo = mKeyguardBottomArea.resolveCameraIntent();
         String packageToLaunch = (resolveInfo == null || resolveInfo.activityInfo == null)
                 ? null : resolveInfo.activityInfo.packageName;