From 98ec92375d75630c10595bfcbae184ad7350e2d3 Mon Sep 17 00:00:00 2001 From: Esteban Talavera Date: Fri, 14 Jul 2017 16:14:07 +0100 Subject: [PATCH] Enforce policy for camera gesture in keyguard If the admin has disabled the camera for secure keyguards, in addition to removing the bottom-right hand corner camera button do not allow the camera to be opened via the camera gesture either. Bug: 63334090 Merged-In: I104688eaad719528376e2851f837d5956a6a1169 Test: Manually tested launching the camera on secure and non-secure keyguard and non-keyguard, both via camera icon and gesture Change-Id: I104688eaad719528376e2851f837d5956a6a1169 --- .../phone/KeyguardBottomAreaView.java | 21 ++----------------- .../phone/NotificationPanelView.java | 6 ++++++ .../systemui/statusbar/phone/StatusBar.java | 18 ++++++++++++++-- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java index 6fe8827c4c878..e9f6e95b2f48c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java @@ -397,24 +397,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 && mStatusBar != null) { - try { - final int userId = ActivityManager.getService().getCurrentUser().id; - final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId); - final boolean disabledBecauseKeyguardSecure = - (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0 - && mStatusBar.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); @@ -865,7 +847,8 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL @Override public IconState getIcon() { ResolveInfo resolved = resolveCameraIntent(); - mIconState.isVisible = !isCameraDisabledByDpm() && resolved != null + boolean isCameraDisabled = (mStatusBar != null) && !mStatusBar.isCameraAllowedByAdmin(); + mIconState.isVisible = !isCameraDisabled && resolved != null && getResources().getBoolean(R.bool.config_keyguardShowCameraAffordance) && mUserSetupComplete; mIconState.drawable = mContext.getDrawable(R.drawable.ic_camera_alt_24dp); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java index 6aab8e10543e3..54c12a187dc22 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java @@ -31,6 +31,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.util.AttributeSet; +import android.util.EventLog; import android.util.FloatProperty; import android.util.MathUtils; import android.view.MotionEvent; @@ -2440,6 +2441,11 @@ 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; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index f58fe8290a438..d2994bd4fca17 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -1,5 +1,3 @@ - - /* * Copyright (C) 2010 The Android Open Source Project * @@ -5040,6 +5038,18 @@ public class StatusBar extends SystemUI implements DemoMode, } } + 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 void notifyFpAuthModeChanged() { updateDozing(); } @@ -5062,6 +5072,10 @@ public class StatusBar extends SystemUI implements DemoMode, } public boolean isKeyguardShowing() { + if (mStatusBarKeyguardViewManager == null) { + Slog.i(TAG, "isKeyguardShowing() called before startKeyguard(), returning true"); + return true; + } return mStatusBarKeyguardViewManager.isShowing(); }