Skip to content

Commit ee82f8f

Browse files
author
Jim Miller
committed
Fix camera disambiguation in secure keyguard
When there are multiple activities that respond to MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE we need to show the disambiguation dialog to the user. However the disambiguation "dialog" is actully an activity themed as a dialog. Hence, we can't show it in the secure keyguard. This works around the issue by prompting the user for their credentials directly when the intent needs disambiguation. This will take them out of keyguard and prompt them for which activity they want to use. We'll provide a more robust solution in a future release. Fixes bug 7109816 Change-Id: I94e643d3cb503e1ce6de24c82400b4d5fcbb9d95
1 parent 1f7a09b commit ee82f8f

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

core/java/com/android/internal/widget/LockPatternUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ public class LockPatternUtils {
125125
private final ContentResolver mContentResolver;
126126
private DevicePolicyManager mDevicePolicyManager;
127127
private ILockSettings mLockSettingsService;
128-
private int mCurrentUserId = UserHandle.USER_NULL;
128+
129+
// The current user is set by KeyguardViewMediator and shared by all LockPatternUtils.
130+
private static volatile int sCurrentUserId = UserHandle.USER_NULL;
129131

130132
public DevicePolicyManager getDevicePolicyManager() {
131133
if (mDevicePolicyManager == null) {
@@ -215,13 +217,13 @@ public void reportSuccessfulPasswordAttempt() {
215217
}
216218

217219
public void setCurrentUser(int userId) {
218-
mCurrentUserId = userId;
220+
sCurrentUserId = userId;
219221
}
220222

221223
public int getCurrentUser() {
222-
if (mCurrentUserId != UserHandle.USER_NULL) {
224+
if (sCurrentUserId != UserHandle.USER_NULL) {
223225
// Someone is regularly updating using setCurrentUser() use that value.
224-
return mCurrentUserId;
226+
return sCurrentUserId;
225227
}
226228
try {
227229
return ActivityManagerNative.getDefault().getCurrentUser().id;

policy/src/com/android/internal/policy/impl/keyguard/KeyguardFaceUnlockView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public void onUserSwitched(int userId) {
153153
if (mBiometricUnlock != null) {
154154
mBiometricUnlock.stop();
155155
}
156-
mLockPatternUtils.setCurrentUser(userId);
156+
// No longer required; static value set by KeyguardViewMediator
157+
// mLockPatternUtils.setCurrentUser(userId);
157158
}
158159
};
159160

policy/src/com/android/internal/policy/impl/keyguard/KeyguardSelectorView.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import android.content.ComponentName;
2424
import android.content.Context;
2525
import android.content.Intent;
26+
import android.content.pm.PackageManager;
27+
import android.content.pm.ResolveInfo;
2628
import android.os.RemoteException;
2729
import android.os.UserHandle;
2830
import android.provider.MediaStore;
@@ -38,6 +40,8 @@
3840
import com.android.internal.widget.multiwaveview.GlowPadView.OnTriggerListener;
3941
import com.android.internal.R;
4042

43+
import java.util.List;
44+
4145
public class KeyguardSelectorView extends LinearLayout implements KeyguardSecurityView {
4246
private static final boolean DEBUG = KeyguardHostView.DEBUG;
4347
private static final String TAG = "SecuritySelectorView";
@@ -116,12 +120,39 @@ public KeyguardSelectorView(Context context) {
116120
this(context, null);
117121
}
118122

123+
private boolean wouldLaunchResolverActivity(Intent intent) {
124+
PackageManager packageManager = mContext.getPackageManager();
125+
ResolveInfo resolved = packageManager.resolveActivityAsUser(intent,
126+
PackageManager.MATCH_DEFAULT_ONLY, mLockPatternUtils.getCurrentUser());
127+
final List<ResolveInfo> appList = packageManager.queryIntentActivitiesAsUser(
128+
intent, PackageManager.MATCH_DEFAULT_ONLY, mLockPatternUtils.getCurrentUser());
129+
// If the list contains the above resolved activity, then it can't be
130+
// ResolverActivity itself.
131+
for (int i = 0; i < appList.size(); i++) {
132+
ResolveInfo tmp = appList.get(i);
133+
if (tmp.activityInfo.name.equals(resolved.activityInfo.name)
134+
&& tmp.activityInfo.packageName.equals(resolved.activityInfo.packageName)) {
135+
return false;
136+
}
137+
}
138+
return true;
139+
}
140+
119141
protected void launchCamera() {
120142
if (mLockPatternUtils.isSecure()) {
121143
// Launch the secure version of the camera
122-
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
144+
final Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
123145
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
124-
launchActivity(intent, true);
146+
147+
if (wouldLaunchResolverActivity(intent)) {
148+
// TODO: Show disambiguation dialog instead.
149+
// For now, we'll treat this like launching any other app from secure keyguard.
150+
// When they do, user sees the system's ResolverActivity which lets them choose
151+
// which secure camera to use.
152+
launchActivity(intent, false);
153+
} else {
154+
launchActivity(intent, true);
155+
}
125156
} else {
126157
// Launch the normal camera
127158
launchActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA), false);

policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ public boolean isSecure() {
907907

908908
/**
909909
* Update the newUserId. Call while holding WindowManagerService lock.
910+
* NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
911+
*
910912
* @param newUserId The id of the incoming user.
911913
*/
912914
public void setCurrentUser(int newUserId) {

0 commit comments

Comments
 (0)