diff options
author | Adrian Roos <roosa@google.com> | 2014-06-02 17:48:07 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-06-02 17:48:07 +0000 |
commit | e205192c722e4fa1b37ee1b31dced21cf89ffbb4 (patch) | |
tree | f8f26f50dec19d36e608c1910fb5b14dd48e3294 | |
parent | 08847c83448558fbe2dfb8290d2ba119f9c0be18 (diff) | |
parent | a06905b8f716ceaccd9244bc2e58777a7d770488 (diff) |
Merge "Fix keyguard camera logic" into lmp-preview-dev
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java | 72 |
1 files changed, 56 insertions, 16 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 994b3292e551..97aa993864ca 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.os.RemoteException; import android.os.UserHandle; import android.provider.MediaStore; @@ -32,6 +33,10 @@ import android.view.View; import android.view.accessibility.AccessibilityManager; import android.widget.FrameLayout; import android.widget.ImageView; + +import com.android.internal.widget.LockPatternUtils; +import com.android.keyguard.KeyguardUpdateMonitor; +import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.systemui.R; /** @@ -43,6 +48,11 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL final static String TAG = "PhoneStatusBar/KeyguardBottomAreaView"; + private static final Intent SECURE_CAMERA_INTENT = + new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE) + .addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + private static final Intent INSECURE_CAMERA_INTENT = + new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); private static final Intent PHONE_INTENT = new Intent(Intent.ACTION_DIAL); private ImageView mCameraImageView; @@ -51,6 +61,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL private ActivityStarter mActivityStarter; private UnlockMethodCache mUnlockMethodCache; + private LockPatternUtils mLockPatternUtils; public KeyguardBottomAreaView(Context context) { super(context); @@ -72,10 +83,11 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL @Override protected void onFinishInflate() { super.onFinishInflate(); + mLockPatternUtils = new LockPatternUtils(mContext); mCameraImageView = (ImageView) findViewById(R.id.camera_button); mPhoneImageView = (ImageView) findViewById(R.id.phone_button); mLockIcon = (ImageView) findViewById(R.id.lock_icon); - watchForDevicePolicyChanges(); + watchForCameraPolicyChanges(); watchForAccessibilityChanges(); updateCameraVisibility(); updatePhoneVisibility(); @@ -88,8 +100,19 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL mActivityStarter = activityStarter; } + private Intent getCameraIntent() { + KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); + boolean currentUserHasTrust = updateMonitor.getUserHasTrust( + mLockPatternUtils.getCurrentUser()); + return mLockPatternUtils.isSecure() && !currentUserHasTrust + ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT; + } + private void updateCameraVisibility() { - boolean visible = !isCameraDisabledByDpm(); + ResolveInfo resolved = mContext.getPackageManager().resolveActivityAsUser(getCameraIntent(), + PackageManager.MATCH_DEFAULT_ONLY, + mLockPatternUtils.getCurrentUser()); + boolean visible = !isCameraDisabledByDpm() && resolved != null; mCameraImageView.setVisibility(visible ? View.VISIBLE : View.GONE); } @@ -122,19 +145,12 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL return false; } - private void watchForDevicePolicyChanges() { + private void watchForCameraPolicyChanges() { final IntentFilter filter = new IntentFilter(); filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); - getContext().registerReceiver(new BroadcastReceiver() { - public void onReceive(Context context, Intent intent) { - post(new Runnable() { - @Override - public void run() { - updateCameraVisibility(); - } - }); - } - }, filter); + getContext().registerReceiverAsUser(mDevicePolicyReceiver, + UserHandle.ALL, filter, null, null); + KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback); } private void watchForAccessibilityChanges() { @@ -171,9 +187,12 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL } public void launchCamera() { - mContext.startActivityAsUser( - new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE), - UserHandle.CURRENT); + Intent intent = getCameraIntent(); + if (intent == SECURE_CAMERA_INTENT) { + mContext.startActivityAsUser(intent, UserHandle.CURRENT); + } else { + mActivityStarter.startActivity(intent); + } } public void launchPhone() { @@ -186,6 +205,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL super.onVisibilityChanged(changedView, visibility); if (changedView == this && visibility == VISIBLE) { updateTrust(); + updateCameraVisibility(); } } @@ -214,5 +234,25 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL @Override public void onMethodSecureChanged(boolean methodSecure) { updateTrust(); + updateCameraVisibility(); } + + private final BroadcastReceiver mDevicePolicyReceiver = new BroadcastReceiver() { + public void onReceive(Context context, Intent intent) { + post(new Runnable() { + @Override + public void run() { + updateCameraVisibility(); + } + }); + } + }; + + private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback = + new KeyguardUpdateMonitorCallback() { + @Override + public void onUserSwitchComplete(int userId) { + updateCameraVisibility(); + } + }; } |