Skip to content

Commit c6e570d

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Fix camera disambiguation in secure keyguard" into jb-mr1-dev
2 parents c12dd97 + ee82f8f commit c6e570d

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";
@@ -118,12 +122,39 @@ public KeyguardSelectorView(Context context) {
118122
this(context, null);
119123
}
120124

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

895895
/**
896896
* Update the newUserId. Call while holding WindowManagerService lock.
897+
* NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
898+
*
897899
* @param newUserId The id of the incoming user.
898900
*/
899901
public void setCurrentUser(int newUserId) {

0 commit comments

Comments
 (0)