@@ -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