Skip to content

Commit 5b81de4

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Fix Camera and GoogleNow launching in keyguard" into jb-mr1-dev
2 parents b07e89f + 5f75aa1 commit 5b81de4

File tree

3 files changed

+61
-14
lines changed

3 files changed

+61
-14
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ public void keyguardDoneDrawing() {
221221
mViewMediatorCallback.keyguardDoneDrawing();
222222
}
223223

224+
@Override
225+
public void setOnDismissRunnable(Runnable runnable) {
226+
KeyguardHostView.this.setOnDismissRunnable(runnable);
227+
}
228+
224229
};
225230

226231
public void takeEmergencyCallAction() {
@@ -273,7 +278,7 @@ public boolean onClickHandler(final View view,
273278
final android.app.PendingIntent pendingIntent,
274279
final Intent fillInIntent) {
275280
if (pendingIntent.isActivity()) {
276-
mLaunchRunnable = new Runnable() {
281+
setOnDismissRunnable(new Runnable() {
277282
public void run() {
278283
try {
279284
// TODO: Unregister this handler if PendingIntent.FLAG_ONE_SHOT?
@@ -292,7 +297,7 @@ public void run() {
292297
"unknown exception: ", e);
293298
}
294299
}
295-
};
300+
});
296301

297302
mCallback.dismiss(false);
298303
return true;
@@ -307,6 +312,14 @@ public void reset() {
307312
requestFocus();
308313
}
309314

315+
/**
316+
* Sets a runnable to run when keyguard is dismissed
317+
* @param runnable
318+
*/
319+
protected void setOnDismissRunnable(Runnable runnable) {
320+
mLaunchRunnable = runnable;
321+
}
322+
310323
private KeyguardSecurityView getSecurityView(int securitySelectorId) {
311324
final int children = mViewFlipper.getChildCount();
312325
for (int child = 0; child < children; child++) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ public interface KeyguardSecurityCallback {
5757
*/
5858
void showBackupUnlock();
5959

60+
/**
61+
* Used to inform keyguard when the current view is done drawing.
62+
*/
6063
void keyguardDoneDrawing();
6164

65+
/**
66+
* Sets a runnable to launch after the user enters their
67+
* @param runnable
68+
*/
69+
void setOnDismissRunnable(Runnable runnable);
70+
6271
}

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public void onTrigger(View v, int target) {
6161
((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
6262
.getAssistIntent(mContext, UserHandle.USER_CURRENT);
6363
if (assistIntent != null) {
64-
launchActivity(assistIntent);
64+
launchActivity(assistIntent, false);
6565
} else {
6666
Log.w(TAG, "Failed to get intent for assist activity");
6767
}
6868
mCallback.userActivity(0);
6969
break;
7070

7171
case com.android.internal.R.drawable.ic_lockscreen_camera:
72-
launchActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA));
72+
launchCamera();
7373
mCallback.userActivity(0);
7474
break;
7575

@@ -128,6 +128,16 @@ public KeyguardSelectorView(Context context) {
128128
this(context, null);
129129
}
130130

131+
protected void launchCamera() {
132+
if (mLockPatternUtils.isSecure()) {
133+
// Launch the secure version of the camera
134+
launchActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE), true);
135+
} else {
136+
// Launch the normal camera
137+
launchActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA), false);
138+
}
139+
}
140+
131141
public KeyguardSelectorView(Context context, AttributeSet attrs) {
132142
super(context, attrs);
133143
mLockPatternUtils = new LockPatternUtils(getContext());
@@ -217,21 +227,36 @@ public void setLockPatternUtils(LockPatternUtils utils) {
217227
/**
218228
* Launches the said intent for the current foreground user.
219229
* @param intent
230+
* @param showsWhileLocked true if the activity can be run on top of keyguard.
231+
* See {@link WindowManager#FLAG_SHOW_WHEN_LOCKED}
220232
*/
221-
private void launchActivity(Intent intent) {
233+
private void launchActivity(final Intent intent, boolean showsWhileLocked) {
222234
intent.setFlags(
223235
Intent.FLAG_ACTIVITY_NEW_TASK
224236
| Intent.FLAG_ACTIVITY_SINGLE_TOP
225237
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
226-
try {
227-
ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
228-
} catch (RemoteException e) {
229-
Log.w(TAG, "can't dismiss keyguard on launch");
230-
}
231-
try {
232-
mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
233-
} catch (ActivityNotFoundException e) {
234-
Log.w(TAG, "Activity not found for intent + " + intent.getAction());
238+
boolean isSecure = mLockPatternUtils.isSecure();
239+
if (!isSecure || showsWhileLocked) {
240+
if (!isSecure) try {
241+
ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
242+
} catch (RemoteException e) {
243+
Log.w(TAG, "can't dismiss keyguard on launch");
244+
}
245+
try {
246+
mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
247+
} catch (ActivityNotFoundException e) {
248+
Log.w(TAG, "Activity not found for intent + " + intent.getAction());
249+
}
250+
} else {
251+
// Create a runnable to start the activity and ask the user to enter their
252+
// credentials.
253+
mCallback.setOnDismissRunnable(new Runnable() {
254+
@Override
255+
public void run() {
256+
mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
257+
}
258+
});
259+
mCallback.dismiss(false);
235260
}
236261
}
237262

0 commit comments

Comments
 (0)