Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 1 | package com.android.systemui.assist; |
| 2 | |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 3 | import android.annotation.NonNull; |
| 4 | import android.annotation.Nullable; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 5 | import android.app.ActivityManager; |
| 6 | import android.app.ActivityOptions; |
| 7 | import android.app.SearchManager; |
| 8 | import android.content.ActivityNotFoundException; |
| 9 | import android.content.ComponentName; |
| 10 | import android.content.Context; |
| 11 | import android.content.Intent; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 12 | import android.content.pm.ActivityInfo; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 13 | import android.content.pm.PackageManager; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 14 | import android.content.res.Configuration; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 15 | import android.content.res.Resources; |
| 16 | import android.graphics.PixelFormat; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 17 | import android.os.AsyncTask; |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 18 | import android.os.Binder; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 19 | import android.os.Bundle; |
Xiyuan Xia | e6de8b9 | 2015-06-06 22:18:05 -0700 | [diff] [blame] | 20 | import android.os.Handler; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 21 | import android.os.RemoteException; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 22 | import android.os.UserHandle; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 23 | import android.provider.Settings; |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 24 | import android.service.voice.VoiceInteractionSession; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | import android.view.Gravity; |
| 27 | import android.view.LayoutInflater; |
| 28 | import android.view.View; |
| 29 | import android.view.ViewGroup; |
| 30 | import android.view.WindowManager; |
| 31 | import android.widget.ImageView; |
| 32 | |
Adrian Roos | e917508 | 2015-06-15 13:23:14 -0700 | [diff] [blame] | 33 | import com.android.internal.app.AssistUtils; |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 34 | import com.android.internal.app.IVoiceInteractionSessionListener; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 35 | import com.android.internal.app.IVoiceInteractionSessionShowCallback; |
Kaori Katou | 70554e0 | 2016-08-04 17:11:07 +0900 | [diff] [blame] | 36 | import com.android.keyguard.KeyguardUpdateMonitor; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 37 | import com.android.settingslib.applications.InterestingConfigChanges; |
| 38 | import com.android.systemui.ConfigurationChangedReceiver; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 39 | import com.android.systemui.R; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 40 | import com.android.systemui.SysUiServiceProvider; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 41 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Adrian Roos | e917508 | 2015-06-15 13:23:14 -0700 | [diff] [blame] | 43 | |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 44 | /** |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 45 | * Class to manage everything related to assist in SystemUI. |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 46 | */ |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 47 | public class AssistManager implements ConfigurationChangedReceiver { |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 48 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 49 | private static final String TAG = "AssistManager"; |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 50 | |
| 51 | // Note that VERBOSE logging may leak PII (e.g. transcription contents). |
| 52 | private static final boolean VERBOSE = false; |
| 53 | |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 54 | private static final String ASSIST_ICON_METADATA_NAME = |
| 55 | "com.android.systemui.action_assist_icon"; |
| 56 | |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 57 | private static final long TIMEOUT_SERVICE = 2500; |
| 58 | private static final long TIMEOUT_ACTIVITY = 1000; |
| 59 | |
Annie Chin | 4c249ff | 2016-07-08 14:52:00 -0700 | [diff] [blame] | 60 | protected final Context mContext; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 61 | private final WindowManager mWindowManager; |
Adrian Roos | 4f43dc0 | 2015-06-17 16:43:38 -0700 | [diff] [blame] | 62 | private final AssistDisclosure mAssistDisclosure; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 63 | private final InterestingConfigChanges mInterestingConfigChanges; |
Adrian Roos | 4f43dc0 | 2015-06-17 16:43:38 -0700 | [diff] [blame] | 64 | |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 65 | private AssistOrbContainer mView; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 66 | private final DeviceProvisionedController mDeviceProvisionedController; |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 67 | protected final AssistUtils mAssistUtils; |
Rajeev Kumar | 3e08430 | 2017-09-25 19:08:12 -0700 | [diff] [blame] | 68 | private final boolean mShouldEnableOrb; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 69 | |
| 70 | private IVoiceInteractionSessionShowCallback mShowCallback = |
| 71 | new IVoiceInteractionSessionShowCallback.Stub() { |
| 72 | |
| 73 | @Override |
| 74 | public void onFailed() throws RemoteException { |
| 75 | mView.post(mHideRunnable); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void onShown() throws RemoteException { |
| 80 | mView.post(mHideRunnable); |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | private Runnable mHideRunnable = new Runnable() { |
| 85 | @Override |
| 86 | public void run() { |
| 87 | mView.removeCallbacks(this); |
| 88 | mView.show(false /* show */, true /* animate */); |
| 89 | } |
| 90 | }; |
| 91 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 92 | public AssistManager(DeviceProvisionedController controller, Context context) { |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 93 | mContext = context; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 94 | mDeviceProvisionedController = controller; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 95 | mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Adrian Roos | e917508 | 2015-06-15 13:23:14 -0700 | [diff] [blame] | 96 | mAssistUtils = new AssistUtils(context); |
Adrian Roos | 4f43dc0 | 2015-06-17 16:43:38 -0700 | [diff] [blame] | 97 | mAssistDisclosure = new AssistDisclosure(context, new Handler()); |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 98 | |
| 99 | registerVoiceInteractionSessionListener(); |
Jason Monk | 3edad31 | 2017-06-05 11:33:48 -0400 | [diff] [blame] | 100 | mInterestingConfigChanges = new InterestingConfigChanges(ActivityInfo.CONFIG_ORIENTATION |
| 101 | | ActivityInfo.CONFIG_LOCALE | ActivityInfo.CONFIG_UI_MODE |
| 102 | | ActivityInfo.CONFIG_SCREEN_LAYOUT | ActivityInfo.CONFIG_ASSETS_PATHS); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 103 | onConfigurationChanged(context.getResources().getConfiguration()); |
Rajeev Kumar | 3e08430 | 2017-09-25 19:08:12 -0700 | [diff] [blame] | 104 | mShouldEnableOrb = !ActivityManager.isLowRamDeviceStatic(); |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | protected void registerVoiceInteractionSessionListener() { |
| 108 | mAssistUtils.registerVoiceInteractionSessionListener( |
| 109 | new IVoiceInteractionSessionListener.Stub() { |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 110 | @Override |
| 111 | public void onVoiceSessionShown() throws RemoteException { |
| 112 | if (VERBOSE) { |
| 113 | Log.v(TAG, "Voice open"); |
| 114 | } |
| 115 | } |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 116 | |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 117 | @Override |
| 118 | public void onVoiceSessionHidden() throws RemoteException { |
| 119 | if (VERBOSE) { |
| 120 | Log.v(TAG, "Voice closed"); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | @Override |
James O'Leary | 9c9dd98 | 2019-02-08 15:49:06 -0500 | [diff] [blame] | 125 | public void onSetUiHints(Bundle hints) { |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 126 | if (VERBOSE) { |
James O'Leary | 9c9dd98 | 2019-02-08 15:49:06 -0500 | [diff] [blame] | 127 | Log.v(TAG, "UI hints received"); |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | }); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 133 | public void onConfigurationChanged(Configuration newConfiguration) { |
| 134 | if (!mInterestingConfigChanges.applyNewConfig(mContext.getResources())) { |
| 135 | return; |
| 136 | } |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 137 | boolean visible = false; |
| 138 | if (mView != null) { |
| 139 | visible = mView.isShowing(); |
| 140 | mWindowManager.removeView(mView); |
| 141 | } |
| 142 | |
| 143 | mView = (AssistOrbContainer) LayoutInflater.from(mContext).inflate( |
| 144 | R.layout.assist_orb, null); |
| 145 | mView.setVisibility(View.GONE); |
| 146 | mView.setSystemUiVisibility( |
| 147 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 148 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 149 | WindowManager.LayoutParams lp = getLayoutParams(); |
| 150 | mWindowManager.addView(mView, lp); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 151 | if (visible) { |
| 152 | mView.show(true /* show */, false /* animate */); |
| 153 | } |
| 154 | } |
| 155 | |
Annie Chin | 937a991 | 2016-05-31 10:14:23 -0700 | [diff] [blame] | 156 | protected boolean shouldShowOrb() { |
| 157 | return true; |
| 158 | } |
| 159 | |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 160 | public void startAssist(Bundle args) { |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 161 | final ComponentName assistComponent = getAssistInfo(); |
| 162 | if (assistComponent == null) { |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 163 | return; |
| 164 | } |
Xiyuan Xia | e6de8b9 | 2015-06-06 22:18:05 -0700 | [diff] [blame] | 165 | |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 166 | final boolean isService = assistComponent.equals(getVoiceInteractorComponentName()); |
Annie Chin | 937a991 | 2016-05-31 10:14:23 -0700 | [diff] [blame] | 167 | if (!isService || (!isVoiceSessionRunning() && shouldShowOrb())) { |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 168 | showOrb(assistComponent, isService); |
Xiyuan Xia | e6de8b9 | 2015-06-06 22:18:05 -0700 | [diff] [blame] | 169 | mView.postDelayed(mHideRunnable, isService |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 170 | ? TIMEOUT_SERVICE |
| 171 | : TIMEOUT_ACTIVITY); |
| 172 | } |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 173 | startAssistInternal(args, assistComponent, isService); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Jorim Jaggi | b835dd7 | 2015-06-08 12:28:42 -0700 | [diff] [blame] | 176 | public void hideAssist() { |
Adrian Roos | e917508 | 2015-06-15 13:23:14 -0700 | [diff] [blame] | 177 | mAssistUtils.hideCurrentSession(); |
Jorim Jaggi | b835dd7 | 2015-06-08 12:28:42 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 180 | private WindowManager.LayoutParams getLayoutParams() { |
| 181 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 182 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 183 | mContext.getResources().getDimensionPixelSize(R.dimen.assist_orb_scrim_height), |
| 184 | WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING, |
| 185 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 186 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 187 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, |
| 188 | PixelFormat.TRANSLUCENT); |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 189 | lp.token = new Binder(); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 190 | lp.gravity = Gravity.BOTTOM | Gravity.START; |
| 191 | lp.setTitle("AssistPreviewPanel"); |
| 192 | lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED |
| 193 | | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
| 194 | return lp; |
| 195 | } |
| 196 | |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 197 | private void showOrb(@NonNull ComponentName assistComponent, boolean isService) { |
| 198 | maybeSwapSearchIcon(assistComponent, isService); |
Rajeev Kumar | 3e08430 | 2017-09-25 19:08:12 -0700 | [diff] [blame] | 199 | if (mShouldEnableOrb) { |
| 200 | mView.show(true /* show */, true /* animate */); |
| 201 | } |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 204 | private void startAssistInternal(Bundle args, @NonNull ComponentName assistComponent, |
| 205 | boolean isService) { |
| 206 | if (isService) { |
| 207 | startVoiceInteractor(args); |
| 208 | } else { |
| 209 | startAssistActivity(args, assistComponent); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 213 | private void startAssistActivity(Bundle args, @NonNull ComponentName assistComponent) { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 214 | if (!mDeviceProvisionedController.isDeviceProvisioned()) { |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 215 | return; |
| 216 | } |
| 217 | |
| 218 | // Close Recent Apps if needed |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 219 | SysUiServiceProvider.getComponent(mContext, CommandQueue.class).animateCollapsePanels( |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 220 | CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL | CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, |
| 221 | false /* force */); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 222 | |
Adrian Roos | 4f43dc0 | 2015-06-17 16:43:38 -0700 | [diff] [blame] | 223 | boolean structureEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 224 | Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1, UserHandle.USER_CURRENT) != 0; |
| 225 | |
Steven Wu | 2b71d79 | 2018-05-08 11:03:17 -0400 | [diff] [blame] | 226 | final SearchManager searchManager = |
| 227 | (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 228 | if (searchManager == null) { |
| 229 | return; |
| 230 | } |
| 231 | final Intent intent = searchManager.getAssistIntent(structureEnabled); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 232 | if (intent == null) { |
| 233 | return; |
| 234 | } |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 235 | intent.setComponent(assistComponent); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 236 | intent.putExtras(args); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 237 | |
Adrian Roos | 4f43dc0 | 2015-06-17 16:43:38 -0700 | [diff] [blame] | 238 | if (structureEnabled) { |
| 239 | showDisclosure(); |
| 240 | } |
| 241 | |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 242 | try { |
| 243 | final ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext, |
| 244 | R.anim.search_launch_enter, R.anim.search_launch_exit); |
| 245 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 246 | AsyncTask.execute(new Runnable() { |
| 247 | @Override |
| 248 | public void run() { |
| 249 | mContext.startActivityAsUser(intent, opts.toBundle(), |
| 250 | new UserHandle(UserHandle.USER_CURRENT)); |
| 251 | } |
| 252 | }); |
| 253 | } catch (ActivityNotFoundException e) { |
| 254 | Log.w(TAG, "Activity not found for " + intent.getAction()); |
| 255 | } |
| 256 | } |
| 257 | |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 258 | private void startVoiceInteractor(Bundle args) { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 259 | mAssistUtils.showSessionForActiveService(args, |
| 260 | VoiceInteractionSession.SHOW_SOURCE_ASSIST_GESTURE, mShowCallback, null); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 263 | public void launchVoiceAssistFromKeyguard() { |
Adrian Roos | e917508 | 2015-06-15 13:23:14 -0700 | [diff] [blame] | 264 | mAssistUtils.launchVoiceAssistFromKeyguard(); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 267 | public boolean canVoiceAssistBeLaunchedFromKeyguard() { |
Adrian Roos | e917508 | 2015-06-15 13:23:14 -0700 | [diff] [blame] | 268 | return mAssistUtils.activeServiceSupportsLaunchFromKeyguard(); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | public ComponentName getVoiceInteractorComponentName() { |
Adrian Roos | e917508 | 2015-06-15 13:23:14 -0700 | [diff] [blame] | 272 | return mAssistUtils.getActiveServiceComponentName(); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | private boolean isVoiceSessionRunning() { |
Adrian Roos | e917508 | 2015-06-15 13:23:14 -0700 | [diff] [blame] | 276 | return mAssistUtils.isSessionRunning(); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 279 | private void maybeSwapSearchIcon(@NonNull ComponentName assistComponent, boolean isService) { |
| 280 | replaceDrawable(mView.getOrb().getLogo(), assistComponent, ASSIST_ICON_METADATA_NAME, |
| 281 | isService); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | public void replaceDrawable(ImageView v, ComponentName component, String name, |
| 285 | boolean isService) { |
| 286 | if (component != null) { |
| 287 | try { |
| 288 | PackageManager packageManager = mContext.getPackageManager(); |
| 289 | // Look for the search icon specified in the activity meta-data |
| 290 | Bundle metaData = isService |
| 291 | ? packageManager.getServiceInfo( |
| 292 | component, PackageManager.GET_META_DATA).metaData |
| 293 | : packageManager.getActivityInfo( |
| 294 | component, PackageManager.GET_META_DATA).metaData; |
| 295 | if (metaData != null) { |
| 296 | int iconResId = metaData.getInt(name); |
| 297 | if (iconResId != 0) { |
| 298 | Resources res = packageManager.getResourcesForApplication( |
| 299 | component.getPackageName()); |
| 300 | v.setImageDrawable(res.getDrawable(iconResId)); |
| 301 | return; |
| 302 | } |
| 303 | } |
| 304 | } catch (PackageManager.NameNotFoundException e) { |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 305 | if (VERBOSE) { |
| 306 | Log.v(TAG, "Assistant component " |
| 307 | + component.flattenToShortString() + " not found"); |
| 308 | } |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 309 | } catch (Resources.NotFoundException nfe) { |
| 310 | Log.w(TAG, "Failed to swap drawable from " |
| 311 | + component.flattenToShortString(), nfe); |
| 312 | } |
| 313 | } |
| 314 | v.setImageDrawable(null); |
| 315 | } |
| 316 | |
Yohei Yukawa | 528e468 | 2015-09-10 22:21:04 -0700 | [diff] [blame] | 317 | @Nullable |
| 318 | private ComponentName getAssistInfo() { |
Kaori Katou | 70554e0 | 2016-08-04 17:11:07 +0900 | [diff] [blame] | 319 | return mAssistUtils.getAssistComponentForUser(KeyguardUpdateMonitor.getCurrentUser()); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 320 | } |
Adrian Roos | 4f43dc0 | 2015-06-17 16:43:38 -0700 | [diff] [blame] | 321 | |
| 322 | public void showDisclosure() { |
| 323 | mAssistDisclosure.postShow(); |
| 324 | } |
Selim Cinek | 9a63499 | 2015-06-23 01:10:07 -0400 | [diff] [blame] | 325 | |
Jorim Jaggi | 19695d9 | 2015-07-20 15:51:40 -0700 | [diff] [blame] | 326 | public void onLockscreenShown() { |
| 327 | mAssistUtils.onLockscreenShown(); |
| 328 | } |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 329 | } |