@@ -81,13 +81,45 @@ private void startAssistActivity() {
8181
8282 // Close Recent Apps if needed
8383 mBar .animateCollapsePanels (CommandQueue .FLAG_EXCLUDE_SEARCH_PANEL );
84-
84+ boolean isKeyguardShowing = false ;
8585 try {
86- mWm .showAssistant ();
86+ isKeyguardShowing = mWm .isKeyguardLocked ();
8787 } catch (RemoteException e ) {
88- // too bad, so sad...
88+
89+ }
90+
91+ if (isKeyguardShowing ) {
92+ // Have keyguard show the bouncer and launch the activity if the user succeeds.
93+ try {
94+ mWm .showAssistant ();
95+ } catch (RemoteException e ) {
96+ // too bad, so sad...
97+ }
98+ onAnimationStarted ();
99+ } else {
100+ // Otherwise, keyguard isn't showing so launch it from here.
101+ Intent intent = ((SearchManager ) mContext .getSystemService (Context .SEARCH_SERVICE ))
102+ .getAssistIntent (mContext , UserHandle .USER_CURRENT );
103+ if (intent == null ) return ;
104+
105+ try {
106+ ActivityManagerNative .getDefault ().dismissKeyguardOnNextActivity ();
107+ } catch (RemoteException e ) {
108+ // too bad, so sad...
109+ }
110+
111+ try {
112+ ActivityOptions opts = ActivityOptions .makeCustomAnimation (mContext ,
113+ R .anim .search_launch_enter , R .anim .search_launch_exit ,
114+ getHandler (), this );
115+ intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
116+ mContext .startActivityAsUser (intent , opts .toBundle (),
117+ new UserHandle (UserHandle .USER_CURRENT ));
118+ } catch (ActivityNotFoundException e ) {
119+ Slog .w (TAG , "Activity not found for " + intent .getAction ());
120+ onAnimationStarted ();
121+ }
89122 }
90- onAnimationStarted ();
91123 }
92124
93125 class GlowPadTriggerListener implements GlowPadView .OnTriggerListener {
0 commit comments