Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.voiceinteraction; |
| 18 | |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 20 | import android.annotation.CallbackExecutor; |
| 21 | import android.annotation.NonNull; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 24 | import android.app.ActivityManagerInternal; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 25 | import android.app.AppGlobals; |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 26 | import android.app.role.OnRoleHoldersChangedListener; |
| 27 | import android.app.role.RoleManager; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.ContentResolver; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
| 34 | import android.content.pm.IPackageManager; |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManagerInternal; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 37 | import android.content.pm.ResolveInfo; |
| 38 | import android.content.pm.ServiceInfo; |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 39 | import android.content.pm.ShortcutServiceInternal; |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 40 | import android.content.res.Resources; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 41 | import android.database.ContentObserver; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 42 | import android.hardware.soundtrigger.IRecognitionStatusCallback; |
| 43 | import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel; |
| 44 | import android.hardware.soundtrigger.SoundTrigger.ModuleProperties; |
| 45 | import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 46 | import android.os.Binder; |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 47 | import android.os.Bundle; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 48 | import android.os.Handler; |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 49 | import android.os.IBinder; |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 50 | import android.os.Parcel; |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 51 | import android.os.RemoteCallback; |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 52 | import android.os.RemoteCallbackList; |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 53 | import android.os.RemoteException; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 55 | import android.os.UserManager; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 56 | import android.provider.Settings; |
| 57 | import android.service.voice.IVoiceInteractionService; |
| 58 | import android.service.voice.IVoiceInteractionSession; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 59 | import android.service.voice.VoiceInteractionManagerInternal; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 60 | import android.service.voice.VoiceInteractionService; |
| 61 | import android.service.voice.VoiceInteractionServiceInfo; |
Dianne Hackborn | 2ee5c36 | 2015-05-29 17:58:53 -0700 | [diff] [blame] | 62 | import android.service.voice.VoiceInteractionSession; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 63 | import android.speech.RecognitionService; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 64 | import android.text.TextUtils; |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 65 | import android.util.ArraySet; |
Jorim Jaggi | b835dd7 | 2015-06-08 12:28:42 -0700 | [diff] [blame] | 66 | import android.util.Log; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 67 | import android.util.Slog; |
Sandeep | d701820 | 2014-07-10 15:15:39 -0700 | [diff] [blame] | 68 | |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 69 | import com.android.internal.app.IVoiceActionCheckCallback; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 70 | import com.android.internal.app.IVoiceInteractionManagerService; |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 71 | import com.android.internal.app.IVoiceInteractionSessionListener; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 72 | import com.android.internal.app.IVoiceInteractionSessionShowCallback; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 73 | import com.android.internal.app.IVoiceInteractor; |
| 74 | import com.android.internal.content.PackageMonitor; |
| 75 | import com.android.internal.os.BackgroundThread; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 76 | import com.android.internal.util.DumpUtils; |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 77 | import com.android.internal.util.Preconditions; |
Fyodor Kupolov | ab781c2 | 2017-12-19 16:44:26 -0800 | [diff] [blame] | 78 | import com.android.server.FgThread; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 79 | import com.android.server.LocalServices; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 80 | import com.android.server.SystemService; |
| 81 | import com.android.server.UiThread; |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 82 | import com.android.server.soundtrigger.SoundTriggerInternal; |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 83 | import com.android.server.wm.ActivityTaskManagerInternal; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 84 | |
| 85 | import java.io.FileDescriptor; |
| 86 | import java.io.PrintWriter; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 87 | import java.util.List; |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 88 | import java.util.concurrent.Executor; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * SystemService that publishes an IVoiceInteractionManagerService. |
| 92 | */ |
| 93 | public class VoiceInteractionManagerService extends SystemService { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 94 | static final String TAG = "VoiceInteractionManagerService"; |
Joe Onorato | 3973b1a | 2016-02-01 17:45:31 -0800 | [diff] [blame] | 95 | static final boolean DEBUG = false; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 96 | |
| 97 | final Context mContext; |
| 98 | final ContentResolver mResolver; |
Sandeep Siddhartha | 2883ba6 | 2014-07-16 21:02:08 -0700 | [diff] [blame] | 99 | final DatabaseHelper mDbHelper; |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 100 | final ActivityManagerInternal mAmInternal; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 101 | final ActivityTaskManagerInternal mAtmInternal; |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 102 | final UserManager mUserManager; |
| 103 | final ArraySet<Integer> mLoadedKeyphraseIds = new ArraySet<>(); |
| 104 | ShortcutServiceInternal mShortcutServiceInternal; |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 105 | SoundTriggerInternal mSoundTriggerInternal; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 106 | |
Annie Chin | d953ab6 | 2016-07-07 11:57:33 -0700 | [diff] [blame] | 107 | private final RemoteCallbackList<IVoiceInteractionSessionListener> |
| 108 | mVoiceInteractionSessionListeners = new RemoteCallbackList<>(); |
| 109 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 110 | public VoiceInteractionManagerService(Context context) { |
| 111 | super(context); |
| 112 | mContext = context; |
| 113 | mResolver = context.getContentResolver(); |
Sandeep Siddhartha | 2883ba6 | 2014-07-16 21:02:08 -0700 | [diff] [blame] | 114 | mDbHelper = new DatabaseHelper(context); |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 115 | mServiceStub = new VoiceInteractionManagerServiceStub(); |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 116 | mAmInternal = Preconditions.checkNotNull( |
| 117 | LocalServices.getService(ActivityManagerInternal.class)); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 118 | mAtmInternal = Preconditions.checkNotNull( |
| 119 | LocalServices.getService(ActivityTaskManagerInternal.class)); |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 120 | mUserManager = Preconditions.checkNotNull( |
| 121 | context.getSystemService(UserManager.class)); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 122 | |
| 123 | PackageManagerInternal packageManagerInternal = LocalServices.getService( |
| 124 | PackageManagerInternal.class); |
| 125 | packageManagerInternal.setVoiceInteractionPackagesProvider( |
| 126 | new PackageManagerInternal.PackagesProvider() { |
| 127 | @Override |
| 128 | public String[] getPackages(int userId) { |
| 129 | mServiceStub.initForUser(userId); |
| 130 | ComponentName interactor = mServiceStub.getCurInteractor(userId); |
| 131 | if (interactor != null) { |
| 132 | return new String[] {interactor.getPackageName()}; |
| 133 | } |
| 134 | return null; |
| 135 | } |
| 136 | }); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void onStart() { |
| 141 | publishBinderService(Context.VOICE_INTERACTION_MANAGER_SERVICE, mServiceStub); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 142 | publishLocalService(VoiceInteractionManagerInternal.class, new LocalService()); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void onBootPhase(int phase) { |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 147 | if (PHASE_SYSTEM_SERVICES_READY == phase) { |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 148 | mShortcutServiceInternal = Preconditions.checkNotNull( |
| 149 | LocalServices.getService(ShortcutServiceInternal.class)); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 150 | mSoundTriggerInternal = LocalServices.getService(SoundTriggerInternal.class); |
| 151 | } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 152 | mServiceStub.systemRunning(isSafeMode()); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | @Override |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 157 | public void onStartUser(int userHandle) { |
| 158 | mServiceStub.initForUser(userHandle); |
| 159 | } |
| 160 | |
| 161 | @Override |
Amith Yamasani | 37f9de9 | 2016-04-19 17:04:28 -0700 | [diff] [blame] | 162 | public void onUnlockUser(int userHandle) { |
| 163 | mServiceStub.initForUser(userHandle); |
| 164 | mServiceStub.switchImplementationIfNeeded(false); |
| 165 | } |
| 166 | |
| 167 | @Override |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 168 | public void onSwitchUser(int userHandle) { |
| 169 | mServiceStub.switchUser(userHandle); |
| 170 | } |
| 171 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 172 | class LocalService extends VoiceInteractionManagerInternal { |
| 173 | @Override |
| 174 | public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { |
| 175 | if (DEBUG) { |
| 176 | Slog.i(TAG, "startLocalVoiceInteraction " + callingActivity); |
| 177 | } |
| 178 | VoiceInteractionManagerService.this.mServiceStub.startLocalVoiceInteraction( |
| 179 | callingActivity, options); |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public boolean supportsLocalVoiceInteraction() { |
| 184 | return VoiceInteractionManagerService.this.mServiceStub.supportsLocalVoiceInteraction(); |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 189 | if (DEBUG) { |
| 190 | Slog.i(TAG, "stopLocalVoiceInteraction " + callingActivity); |
| 191 | } |
| 192 | VoiceInteractionManagerService.this.mServiceStub.stopLocalVoiceInteraction( |
| 193 | callingActivity); |
| 194 | } |
| 195 | } |
| 196 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 197 | // implementation entry point and binder service |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 198 | private final VoiceInteractionManagerServiceStub mServiceStub; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 199 | |
| 200 | class VoiceInteractionManagerServiceStub extends IVoiceInteractionManagerService.Stub { |
| 201 | |
| 202 | VoiceInteractionManagerServiceImpl mImpl; |
| 203 | |
| 204 | private boolean mSafeMode; |
| 205 | private int mCurUser; |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 206 | private boolean mCurUserUnlocked; |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 207 | private final boolean mEnableService; |
| 208 | |
| 209 | VoiceInteractionManagerServiceStub() { |
Dianne Hackborn | 31cb01d | 2017-08-30 16:21:28 -0700 | [diff] [blame] | 210 | mEnableService = shouldEnableService(mContext); |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 211 | new RoleObserver(mContext.getMainExecutor()); |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 212 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 213 | |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 214 | // TODO: VI Make sure the caller is the current user or profile |
| 215 | void startLocalVoiceInteraction(final IBinder token, Bundle options) { |
| 216 | if (mImpl == null) return; |
| 217 | |
| 218 | final long caller = Binder.clearCallingIdentity(); |
| 219 | try { |
| 220 | mImpl.showSessionLocked(options, |
| 221 | VoiceInteractionSession.SHOW_SOURCE_ACTIVITY, |
| 222 | new IVoiceInteractionSessionShowCallback.Stub() { |
| 223 | @Override |
| 224 | public void onFailed() { |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public void onShown() { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 229 | mAtmInternal.onLocalVoiceInteractionStarted(token, |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 230 | mImpl.mActiveSession.mSession, |
| 231 | mImpl.mActiveSession.mInteractor); |
| 232 | } |
| 233 | }, |
| 234 | token); |
| 235 | } finally { |
| 236 | Binder.restoreCallingIdentity(caller); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | public void stopLocalVoiceInteraction(IBinder callingActivity) { |
| 241 | if (mImpl == null) return; |
| 242 | |
| 243 | final long caller = Binder.clearCallingIdentity(); |
| 244 | try { |
| 245 | mImpl.finishLocked(callingActivity, true); |
| 246 | } finally { |
| 247 | Binder.restoreCallingIdentity(caller); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | public boolean supportsLocalVoiceInteraction() { |
| 252 | if (mImpl == null) return false; |
| 253 | |
| 254 | return mImpl.supportsLocalVoiceInteraction(); |
| 255 | } |
| 256 | |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 257 | @Override |
| 258 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 259 | throws RemoteException { |
| 260 | try { |
| 261 | return super.onTransact(code, data, reply, flags); |
| 262 | } catch (RuntimeException e) { |
| 263 | // The activity manager only throws security exceptions, so let's |
| 264 | // log all others. |
| 265 | if (!(e instanceof SecurityException)) { |
| 266 | Slog.wtf(TAG, "VoiceInteractionManagerService Crash", e); |
| 267 | } |
| 268 | throw e; |
| 269 | } |
| 270 | } |
| 271 | |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 272 | public void initForUser(int userHandle) { |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 273 | if (DEBUG) Slog.d(TAG, "**************** initForUser user=" + userHandle); |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 274 | String curInteractorStr = Settings.Secure.getStringForUser( |
| 275 | mContext.getContentResolver(), |
| 276 | Settings.Secure.VOICE_INTERACTION_SERVICE, userHandle); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 277 | ComponentName curRecognizer = getCurRecognizer(userHandle); |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 278 | VoiceInteractionServiceInfo curInteractorInfo = null; |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 279 | if (DEBUG) Slog.d(TAG, "curInteractorStr=" + curInteractorStr |
| 280 | + " curRecognizer=" + curRecognizer); |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 281 | if (curInteractorStr == null && curRecognizer != null && mEnableService) { |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 282 | // If there is no interactor setting, that means we are upgrading |
| 283 | // from an older platform version. If the current recognizer is not |
| 284 | // set or matches the preferred recognizer, then we want to upgrade |
| 285 | // the user to have the default voice interaction service enabled. |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 286 | // Note that we don't do this for low-RAM devices, since we aren't |
| 287 | // supporting voice interaction services there. |
Cedric Ho | 80cf221 | 2015-05-19 15:44:31 -0700 | [diff] [blame] | 288 | curInteractorInfo = findAvailInteractor(userHandle, curRecognizer.getPackageName()); |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 289 | if (curInteractorInfo != null) { |
| 290 | // Looks good! We'll apply this one. To make it happen, we clear the |
| 291 | // recognizer so that we don't think we have anything set and will |
| 292 | // re-apply the settings. |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 293 | if (DEBUG) Slog.d(TAG, "No set interactor, found avail: " |
| 294 | + curInteractorInfo.getServiceInfo().name); |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 295 | curRecognizer = null; |
| 296 | } |
| 297 | } |
| 298 | |
Cedric Ho | 80cf221 | 2015-05-19 15:44:31 -0700 | [diff] [blame] | 299 | // If forceInteractorPackage exists, try to apply the interactor from this package if |
| 300 | // possible and ignore the regular interactor setting. |
| 301 | String forceInteractorPackage = |
| 302 | getForceVoiceInteractionServicePackage(mContext.getResources()); |
| 303 | if (forceInteractorPackage != null) { |
| 304 | curInteractorInfo = findAvailInteractor(userHandle, forceInteractorPackage); |
| 305 | if (curInteractorInfo != null) { |
| 306 | // We'll apply this one. Clear the recognizer and re-apply the settings. |
| 307 | curRecognizer = null; |
| 308 | } |
| 309 | } |
| 310 | |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 311 | // If we are on a svelte device, make sure an interactor is not currently |
| 312 | // enabled; if it is, turn it off. |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 313 | if (!mEnableService && curInteractorStr != null) { |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 314 | if (!TextUtils.isEmpty(curInteractorStr)) { |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 315 | if (DEBUG) Slog.d(TAG, "Svelte device; disabling interactor"); |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 316 | setCurInteractor(null, userHandle); |
| 317 | curInteractorStr = ""; |
| 318 | } |
| 319 | } |
| 320 | |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 321 | if (curRecognizer != null) { |
| 322 | // If we already have at least a recognizer, then we probably want to |
| 323 | // leave things as they are... unless something has disappeared. |
| 324 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 325 | ServiceInfo interactorInfo = null; |
| 326 | ServiceInfo recognizerInfo = null; |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 327 | ComponentName curInteractor = !TextUtils.isEmpty(curInteractorStr) |
| 328 | ? ComponentName.unflattenFromString(curInteractorStr) : null; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 329 | try { |
Sudheer Shanka | 9260d56 | 2017-04-10 15:32:52 -0700 | [diff] [blame] | 330 | recognizerInfo = pm.getServiceInfo(curRecognizer, |
| 331 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 332 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userHandle); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 333 | if (curInteractor != null) { |
Sudheer Shanka | 9260d56 | 2017-04-10 15:32:52 -0700 | [diff] [blame] | 334 | interactorInfo = pm.getServiceInfo(curInteractor, |
| 335 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 336 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userHandle); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 337 | } |
| 338 | } catch (RemoteException e) { |
| 339 | } |
| 340 | // If the apps for the currently set components still exist, then all is okay. |
| 341 | if (recognizerInfo != null && (curInteractor == null || interactorInfo != null)) { |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 342 | if (DEBUG) Slog.d(TAG, "Current interactor/recognizer okay, done!"); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 343 | return; |
| 344 | } |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 345 | if (DEBUG) Slog.d(TAG, "Bad recognizer (" + recognizerInfo + ") or interactor (" |
| 346 | + interactorInfo + ")"); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 349 | // Initializing settings, look for an interactor first (but only on non-svelte). |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 350 | if (curInteractorInfo == null && mEnableService) { |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 351 | curInteractorInfo = findAvailInteractor(userHandle, null); |
| 352 | } |
Dianne Hackborn | c0e4aaa | 2014-11-14 10:55:50 -0800 | [diff] [blame] | 353 | |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 354 | if (curInteractorInfo != null) { |
| 355 | // Eventually it will be an error to not specify this. |
| 356 | setCurInteractor(new ComponentName(curInteractorInfo.getServiceInfo().packageName, |
| 357 | curInteractorInfo.getServiceInfo().name), userHandle); |
| 358 | if (curInteractorInfo.getRecognitionService() != null) { |
| 359 | setCurRecognizer( |
| 360 | new ComponentName(curInteractorInfo.getServiceInfo().packageName, |
| 361 | curInteractorInfo.getRecognitionService()), userHandle); |
| 362 | return; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | // No voice interactor, we'll just set up a simple recognizer. |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 367 | initSimpleRecognizer(curInteractorInfo, userHandle); |
| 368 | } |
| 369 | |
| 370 | public void initSimpleRecognizer(VoiceInteractionServiceInfo curInteractorInfo, |
| 371 | int userHandle) { |
| 372 | ComponentName curRecognizer = findAvailRecognizer(null, userHandle); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 373 | if (curRecognizer != null) { |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 374 | if (curInteractorInfo == null) { |
| 375 | setCurInteractor(null, userHandle); |
| 376 | } |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 377 | setCurRecognizer(curRecognizer, userHandle); |
| 378 | } |
| 379 | } |
| 380 | |
Dianne Hackborn | 31cb01d | 2017-08-30 16:21:28 -0700 | [diff] [blame] | 381 | private boolean shouldEnableService(Context context) { |
Robin Lee | ba3af56 | 2018-11-13 18:48:19 +0100 | [diff] [blame] | 382 | // VoiceInteractionService should not be enabled on devices that have not declared the |
| 383 | // recognition feature (including low-ram devices where notLowRam="true" takes effect), |
| 384 | // unless the device's configuration has explicitly set the config flag for a fixed |
Dianne Hackborn | 31cb01d | 2017-08-30 16:21:28 -0700 | [diff] [blame] | 385 | // voice interaction service. |
Robin Lee | ba3af56 | 2018-11-13 18:48:19 +0100 | [diff] [blame] | 386 | if (getForceVoiceInteractionServicePackage(context.getResources()) != null) { |
| 387 | return true; |
| 388 | } |
| 389 | return context.getPackageManager() |
| 390 | .hasSystemFeature(PackageManager.FEATURE_VOICE_RECOGNIZERS); |
Cedric Ho | 80cf221 | 2015-05-19 15:44:31 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | private String getForceVoiceInteractionServicePackage(Resources res) { |
| 394 | String interactorPackage = |
| 395 | res.getString(com.android.internal.R.string.config_forceVoiceInteractionServicePackage); |
| 396 | return TextUtils.isEmpty(interactorPackage) ? null : interactorPackage; |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 399 | public void systemRunning(boolean safeMode) { |
| 400 | mSafeMode = safeMode; |
| 401 | |
| 402 | mPackageMonitor.register(mContext, BackgroundThread.getHandler().getLooper(), |
| 403 | UserHandle.ALL, true); |
| 404 | new SettingsObserver(UiThread.getHandler()); |
| 405 | |
| 406 | synchronized (this) { |
| 407 | mCurUser = ActivityManager.getCurrentUser(); |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 408 | switchImplementationIfNeededLocked(false); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
| 412 | public void switchUser(int userHandle) { |
Fyodor Kupolov | ab781c2 | 2017-12-19 16:44:26 -0800 | [diff] [blame] | 413 | FgThread.getHandler().post(() -> { |
| 414 | synchronized (this) { |
| 415 | mCurUser = userHandle; |
| 416 | mCurUserUnlocked = false; |
| 417 | switchImplementationIfNeededLocked(false); |
| 418 | } |
| 419 | }); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Amith Yamasani | 37f9de9 | 2016-04-19 17:04:28 -0700 | [diff] [blame] | 422 | void switchImplementationIfNeeded(boolean force) { |
| 423 | synchronized (this) { |
| 424 | switchImplementationIfNeededLocked(force); |
| 425 | } |
| 426 | } |
| 427 | |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 428 | void switchImplementationIfNeededLocked(boolean force) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 429 | if (!mSafeMode) { |
| 430 | String curService = Settings.Secure.getStringForUser( |
| 431 | mResolver, Settings.Secure.VOICE_INTERACTION_SERVICE, mCurUser); |
| 432 | ComponentName serviceComponent = null; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 433 | ServiceInfo serviceInfo = null; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 434 | if (curService != null && !curService.isEmpty()) { |
| 435 | try { |
| 436 | serviceComponent = ComponentName.unflattenFromString(curService); |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 437 | serviceInfo = AppGlobals.getPackageManager() |
| 438 | .getServiceInfo(serviceComponent, 0, mCurUser); |
| 439 | } catch (RuntimeException | RemoteException e) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 440 | Slog.wtf(TAG, "Bad voice interaction service name " + curService, e); |
| 441 | serviceComponent = null; |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 442 | serviceInfo = null; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 443 | } |
| 444 | } |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 445 | |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 446 | final boolean hasComponent = serviceComponent != null && serviceInfo != null; |
| 447 | |
| 448 | if (mUserManager.isUserUnlockingOrUnlocked(mCurUser)) { |
| 449 | if (hasComponent) { |
| 450 | mShortcutServiceInternal.setShortcutHostPackage(TAG, |
| 451 | serviceComponent.getPackageName(), mCurUser); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 452 | mAtmInternal.setAllowAppSwitches(TAG, |
Dianne Hackborn | 08bd3ea | 2017-11-22 13:59:17 -0800 | [diff] [blame] | 453 | serviceInfo.applicationInfo.uid, mCurUser); |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 454 | } else { |
| 455 | mShortcutServiceInternal.setShortcutHostPackage(TAG, null, mCurUser); |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 456 | mAtmInternal.setAllowAppSwitches(TAG, -1, mCurUser); |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 460 | if (force || mImpl == null || mImpl.mUser != mCurUser |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 461 | || !mImpl.mComponent.equals(serviceComponent)) { |
Chris Thornton | f967da9 | 2016-05-02 19:22:57 -0700 | [diff] [blame] | 462 | unloadAllKeyphraseModels(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 463 | if (mImpl != null) { |
| 464 | mImpl.shutdownLocked(); |
| 465 | } |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 466 | if (hasComponent) { |
Winson Chung | bccd4b5 | 2017-12-13 11:08:39 -0800 | [diff] [blame] | 467 | setImplLocked(new VoiceInteractionManagerServiceImpl(mContext, |
| 468 | UiThread.getHandler(), this, mCurUser, serviceComponent)); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 469 | mImpl.startLocked(); |
| 470 | } else { |
Winson Chung | bccd4b5 | 2017-12-13 11:08:39 -0800 | [diff] [blame] | 471 | setImplLocked(null); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
Cedric Ho | 80cf221 | 2015-05-19 15:44:31 -0700 | [diff] [blame] | 477 | VoiceInteractionServiceInfo findAvailInteractor(int userHandle, String packageName) { |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 478 | List<ResolveInfo> available = |
| 479 | mContext.getPackageManager().queryIntentServicesAsUser( |
Svetoslav Ganov | b625e19 | 2016-06-02 15:25:12 -0700 | [diff] [blame] | 480 | new Intent(VoiceInteractionService.SERVICE_INTERFACE), |
| 481 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 482 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
| 483 | | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, userHandle); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 484 | int numAvailable = available.size(); |
| 485 | |
| 486 | if (numAvailable == 0) { |
| 487 | Slog.w(TAG, "no available voice interaction services found for user " + userHandle); |
| 488 | return null; |
| 489 | } else { |
| 490 | // Find first system package. We never want to allow third party services to |
| 491 | // be automatically selected, because those require approval of the user. |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 492 | VoiceInteractionServiceInfo foundInfo = null; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 493 | for (int i=0; i<numAvailable; i++) { |
| 494 | ServiceInfo cur = available.get(i).serviceInfo; |
| 495 | if ((cur.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) { |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 496 | ComponentName comp = new ComponentName(cur.packageName, cur.name); |
| 497 | try { |
| 498 | VoiceInteractionServiceInfo info = new VoiceInteractionServiceInfo( |
| 499 | mContext.getPackageManager(), comp, userHandle); |
| 500 | if (info.getParseError() == null) { |
Cedric Ho | 80cf221 | 2015-05-19 15:44:31 -0700 | [diff] [blame] | 501 | if (packageName == null || info.getServiceInfo().packageName.equals( |
| 502 | packageName)) { |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 503 | if (foundInfo == null) { |
| 504 | foundInfo = info; |
| 505 | } else { |
| 506 | Slog.w(TAG, "More than one voice interaction service, " |
| 507 | + "picking first " |
| 508 | + new ComponentName( |
| 509 | foundInfo.getServiceInfo().packageName, |
| 510 | foundInfo.getServiceInfo().name) |
| 511 | + " over " |
| 512 | + new ComponentName(cur.packageName, cur.name)); |
| 513 | } |
| 514 | } |
| 515 | } else { |
| 516 | Slog.w(TAG, "Bad interaction service " + comp + ": " |
| 517 | + info.getParseError()); |
| 518 | } |
| 519 | } catch (PackageManager.NameNotFoundException e) { |
| 520 | Slog.w(TAG, "Failure looking up interaction service " + comp); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
Dianne Hackborn | 16ec080 | 2014-08-15 18:32:33 -0700 | [diff] [blame] | 525 | return foundInfo; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
| 529 | ComponentName getCurInteractor(int userHandle) { |
| 530 | String curInteractor = Settings.Secure.getStringForUser( |
| 531 | mContext.getContentResolver(), |
| 532 | Settings.Secure.VOICE_INTERACTION_SERVICE, userHandle); |
| 533 | if (TextUtils.isEmpty(curInteractor)) { |
| 534 | return null; |
| 535 | } |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 536 | if (DEBUG) Slog.d(TAG, "getCurInteractor curInteractor=" + curInteractor |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 537 | + " user=" + userHandle); |
| 538 | return ComponentName.unflattenFromString(curInteractor); |
| 539 | } |
| 540 | |
| 541 | void setCurInteractor(ComponentName comp, int userHandle) { |
| 542 | Settings.Secure.putStringForUser(mContext.getContentResolver(), |
| 543 | Settings.Secure.VOICE_INTERACTION_SERVICE, |
| 544 | comp != null ? comp.flattenToShortString() : "", userHandle); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 545 | if (DEBUG) Slog.d(TAG, "setCurInteractor comp=" + comp |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 546 | + " user=" + userHandle); |
| 547 | } |
| 548 | |
| 549 | ComponentName findAvailRecognizer(String prefPackage, int userHandle) { |
| 550 | List<ResolveInfo> available = |
| 551 | mContext.getPackageManager().queryIntentServicesAsUser( |
Sudheer Shanka | 9260d56 | 2017-04-10 15:32:52 -0700 | [diff] [blame] | 552 | new Intent(RecognitionService.SERVICE_INTERFACE), |
| 553 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 554 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userHandle); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 555 | int numAvailable = available.size(); |
| 556 | |
| 557 | if (numAvailable == 0) { |
| 558 | Slog.w(TAG, "no available voice recognition services found for user " + userHandle); |
| 559 | return null; |
| 560 | } else { |
| 561 | if (prefPackage != null) { |
| 562 | for (int i=0; i<numAvailable; i++) { |
| 563 | ServiceInfo serviceInfo = available.get(i).serviceInfo; |
| 564 | if (prefPackage.equals(serviceInfo.packageName)) { |
| 565 | return new ComponentName(serviceInfo.packageName, serviceInfo.name); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | if (numAvailable > 1) { |
| 570 | Slog.w(TAG, "more than one voice recognition service found, picking first"); |
| 571 | } |
| 572 | |
| 573 | ServiceInfo serviceInfo = available.get(0).serviceInfo; |
| 574 | return new ComponentName(serviceInfo.packageName, serviceInfo.name); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | ComponentName getCurRecognizer(int userHandle) { |
| 579 | String curRecognizer = Settings.Secure.getStringForUser( |
| 580 | mContext.getContentResolver(), |
| 581 | Settings.Secure.VOICE_RECOGNITION_SERVICE, userHandle); |
| 582 | if (TextUtils.isEmpty(curRecognizer)) { |
| 583 | return null; |
| 584 | } |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 585 | if (DEBUG) Slog.d(TAG, "getCurRecognizer curRecognizer=" + curRecognizer |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 586 | + " user=" + userHandle); |
| 587 | return ComponentName.unflattenFromString(curRecognizer); |
| 588 | } |
| 589 | |
| 590 | void setCurRecognizer(ComponentName comp, int userHandle) { |
| 591 | Settings.Secure.putStringForUser(mContext.getContentResolver(), |
| 592 | Settings.Secure.VOICE_RECOGNITION_SERVICE, |
| 593 | comp != null ? comp.flattenToShortString() : "", userHandle); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 594 | if (DEBUG) Slog.d(TAG, "setCurRecognizer comp=" + comp |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 595 | + " user=" + userHandle); |
| 596 | } |
| 597 | |
Dianne Hackborn | e956365 | 2016-08-18 17:33:41 -0700 | [diff] [blame] | 598 | ComponentName getCurAssistant(int userHandle) { |
| 599 | String curAssistant = Settings.Secure.getStringForUser( |
| 600 | mContext.getContentResolver(), |
| 601 | Settings.Secure.ASSISTANT, userHandle); |
| 602 | if (TextUtils.isEmpty(curAssistant)) { |
| 603 | return null; |
| 604 | } |
| 605 | if (DEBUG) Slog.d(TAG, "getCurAssistant curAssistant=" + curAssistant |
| 606 | + " user=" + userHandle); |
| 607 | return ComponentName.unflattenFromString(curAssistant); |
| 608 | } |
| 609 | |
Jorim Jaggi | cc3a46a | 2015-06-25 15:55:43 -0700 | [diff] [blame] | 610 | void resetCurAssistant(int userHandle) { |
| 611 | Settings.Secure.putStringForUser(mContext.getContentResolver(), |
| 612 | Settings.Secure.ASSISTANT, null, userHandle); |
| 613 | } |
| 614 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 615 | @Override |
Dianne Hackborn | ffeecb1 | 2015-02-25 11:08:11 -0800 | [diff] [blame] | 616 | public void showSession(IVoiceInteractionService service, Bundle args, int flags) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 617 | synchronized (this) { |
James O'Leary | 596708b | 2019-01-30 14:52:21 -0500 | [diff] [blame] | 618 | enforceIsCurrentVoiceInteractionService(service); |
| 619 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 620 | final long caller = Binder.clearCallingIdentity(); |
| 621 | try { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 622 | mImpl.showSessionLocked(args, flags, null, null); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 623 | } finally { |
| 624 | Binder.restoreCallingIdentity(caller); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | @Override |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 630 | public boolean deliverNewSession(IBinder token, IVoiceInteractionSession session, |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 631 | IVoiceInteractor interactor) { |
| 632 | synchronized (this) { |
| 633 | if (mImpl == null) { |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 634 | throw new SecurityException( |
| 635 | "deliverNewSession without running voice interaction service"); |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 636 | } |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 637 | final long caller = Binder.clearCallingIdentity(); |
| 638 | try { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 639 | return mImpl.deliverNewSessionLocked(token, session, interactor); |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 640 | } finally { |
| 641 | Binder.restoreCallingIdentity(caller); |
| 642 | } |
| 643 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 644 | } |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 645 | |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 646 | @Override |
Dianne Hackborn | ffeecb1 | 2015-02-25 11:08:11 -0800 | [diff] [blame] | 647 | public boolean showSessionFromSession(IBinder token, Bundle sessionArgs, int flags) { |
| 648 | synchronized (this) { |
| 649 | if (mImpl == null) { |
| 650 | Slog.w(TAG, "showSessionFromSession without running voice interaction service"); |
| 651 | return false; |
| 652 | } |
Dianne Hackborn | ffeecb1 | 2015-02-25 11:08:11 -0800 | [diff] [blame] | 653 | final long caller = Binder.clearCallingIdentity(); |
| 654 | try { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 655 | return mImpl.showSessionLocked(sessionArgs, flags, null, null); |
Dianne Hackborn | ffeecb1 | 2015-02-25 11:08:11 -0800 | [diff] [blame] | 656 | } finally { |
| 657 | Binder.restoreCallingIdentity(caller); |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | @Override |
| 663 | public boolean hideSessionFromSession(IBinder token) { |
| 664 | synchronized (this) { |
| 665 | if (mImpl == null) { |
| 666 | Slog.w(TAG, "hideSessionFromSession without running voice interaction service"); |
| 667 | return false; |
| 668 | } |
Dianne Hackborn | ffeecb1 | 2015-02-25 11:08:11 -0800 | [diff] [blame] | 669 | final long caller = Binder.clearCallingIdentity(); |
| 670 | try { |
Jorim Jaggi | b835dd7 | 2015-06-08 12:28:42 -0700 | [diff] [blame] | 671 | return mImpl.hideSessionLocked(); |
Dianne Hackborn | ffeecb1 | 2015-02-25 11:08:11 -0800 | [diff] [blame] | 672 | } finally { |
| 673 | Binder.restoreCallingIdentity(caller); |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | @Override |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 679 | public int startVoiceActivity(IBinder token, Intent intent, String resolvedType) { |
| 680 | synchronized (this) { |
| 681 | if (mImpl == null) { |
| 682 | Slog.w(TAG, "startVoiceActivity without running voice interaction service"); |
| 683 | return ActivityManager.START_CANCELED; |
| 684 | } |
| 685 | final int callingPid = Binder.getCallingPid(); |
| 686 | final int callingUid = Binder.getCallingUid(); |
| 687 | final long caller = Binder.clearCallingIdentity(); |
| 688 | try { |
| 689 | return mImpl.startVoiceActivityLocked(callingPid, callingUid, token, |
| 690 | intent, resolvedType); |
| 691 | } finally { |
| 692 | Binder.restoreCallingIdentity(caller); |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | @Override |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 698 | public int startAssistantActivity(IBinder token, Intent intent, String resolvedType) { |
| 699 | synchronized (this) { |
| 700 | if (mImpl == null) { |
| 701 | Slog.w(TAG, "startAssistantActivity without running voice interaction service"); |
| 702 | return ActivityManager.START_CANCELED; |
| 703 | } |
| 704 | final int callingPid = Binder.getCallingPid(); |
| 705 | final int callingUid = Binder.getCallingUid(); |
| 706 | final long caller = Binder.clearCallingIdentity(); |
| 707 | try { |
| 708 | return mImpl.startAssistantActivityLocked(callingPid, callingUid, token, |
| 709 | intent, resolvedType); |
| 710 | } finally { |
| 711 | Binder.restoreCallingIdentity(caller); |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | @Override |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 717 | public void requestDirectActions(@NonNull IBinder token, int taskId, |
| 718 | @NonNull IBinder assistToken, @Nullable RemoteCallback cancellationCallback, |
| 719 | @NonNull RemoteCallback resultCallback) { |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 720 | synchronized (this) { |
| 721 | if (mImpl == null) { |
| 722 | Slog.w(TAG, "requestDirectActions without running voice interaction service"); |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 723 | resultCallback.sendResult(null); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | final long caller = Binder.clearCallingIdentity(); |
| 727 | try { |
Svet Ganov | 3b6be08 | 2019-04-28 10:21:01 -0700 | [diff] [blame] | 728 | mImpl.requestDirectActionsLocked(token, taskId, assistToken, |
| 729 | cancellationCallback, resultCallback); |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 730 | } finally { |
| 731 | Binder.restoreCallingIdentity(caller); |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | @Override |
| 737 | public void performDirectAction(@NonNull IBinder token, @NonNull String actionId, |
| 738 | @NonNull Bundle arguments, int taskId, IBinder assistToken, |
| 739 | @Nullable RemoteCallback cancellationCallback, |
| 740 | @NonNull RemoteCallback resultCallback) { |
| 741 | synchronized (this) { |
| 742 | if (mImpl == null) { |
| 743 | Slog.w(TAG, "performDirectAction without running voice interaction service"); |
| 744 | resultCallback.sendResult(null); |
| 745 | return; |
| 746 | } |
| 747 | final long caller = Binder.clearCallingIdentity(); |
| 748 | try { |
| 749 | mImpl.performDirectActionLocked(token, actionId, arguments, taskId, |
| 750 | assistToken, cancellationCallback, resultCallback); |
| 751 | } finally { |
| 752 | Binder.restoreCallingIdentity(caller); |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | @Override |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 758 | public void setKeepAwake(IBinder token, boolean keepAwake) { |
| 759 | synchronized (this) { |
| 760 | if (mImpl == null) { |
| 761 | Slog.w(TAG, "setKeepAwake without running voice interaction service"); |
| 762 | return; |
| 763 | } |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 764 | final long caller = Binder.clearCallingIdentity(); |
| 765 | try { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 766 | mImpl.setKeepAwakeLocked(token, keepAwake); |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 767 | } finally { |
| 768 | Binder.restoreCallingIdentity(caller); |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | @Override |
Dianne Hackborn | 4e88bcd | 2015-07-01 13:41:03 -0700 | [diff] [blame] | 774 | public void closeSystemDialogs(IBinder token) { |
| 775 | synchronized (this) { |
| 776 | if (mImpl == null) { |
| 777 | Slog.w(TAG, "closeSystemDialogs without running voice interaction service"); |
| 778 | return; |
| 779 | } |
Dianne Hackborn | 4e88bcd | 2015-07-01 13:41:03 -0700 | [diff] [blame] | 780 | final long caller = Binder.clearCallingIdentity(); |
| 781 | try { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 782 | mImpl.closeSystemDialogsLocked(token); |
Dianne Hackborn | 4e88bcd | 2015-07-01 13:41:03 -0700 | [diff] [blame] | 783 | } finally { |
| 784 | Binder.restoreCallingIdentity(caller); |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | @Override |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 790 | public void finish(IBinder token) { |
| 791 | synchronized (this) { |
| 792 | if (mImpl == null) { |
| 793 | Slog.w(TAG, "finish without running voice interaction service"); |
| 794 | return; |
| 795 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 796 | final long caller = Binder.clearCallingIdentity(); |
| 797 | try { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 798 | mImpl.finishLocked(token, false); |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 799 | } finally { |
| 800 | Binder.restoreCallingIdentity(caller); |
| 801 | } |
| 802 | } |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Dianne Hackborn | 1de1186 | 2015-07-15 14:20:51 -0700 | [diff] [blame] | 805 | @Override |
| 806 | public void setDisabledShowContext(int flags) { |
| 807 | synchronized (this) { |
| 808 | if (mImpl == null) { |
| 809 | Slog.w(TAG, "setDisabledShowContext without running voice interaction service"); |
| 810 | return; |
| 811 | } |
Dianne Hackborn | 1de1186 | 2015-07-15 14:20:51 -0700 | [diff] [blame] | 812 | final int callingUid = Binder.getCallingUid(); |
| 813 | final long caller = Binder.clearCallingIdentity(); |
| 814 | try { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 815 | mImpl.setDisabledShowContextLocked(callingUid, flags); |
Dianne Hackborn | 1de1186 | 2015-07-15 14:20:51 -0700 | [diff] [blame] | 816 | } finally { |
| 817 | Binder.restoreCallingIdentity(caller); |
| 818 | } |
| 819 | } |
Dianne Hackborn | 1de1186 | 2015-07-15 14:20:51 -0700 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | @Override |
| 823 | public int getDisabledShowContext() { |
| 824 | synchronized (this) { |
| 825 | if (mImpl == null) { |
| 826 | Slog.w(TAG, "getDisabledShowContext without running voice interaction service"); |
| 827 | return 0; |
| 828 | } |
Dianne Hackborn | 1de1186 | 2015-07-15 14:20:51 -0700 | [diff] [blame] | 829 | final int callingUid = Binder.getCallingUid(); |
| 830 | final long caller = Binder.clearCallingIdentity(); |
| 831 | try { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 832 | return mImpl.getDisabledShowContextLocked(callingUid); |
Dianne Hackborn | 1de1186 | 2015-07-15 14:20:51 -0700 | [diff] [blame] | 833 | } finally { |
| 834 | Binder.restoreCallingIdentity(caller); |
| 835 | } |
| 836 | } |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 837 | } |
Dianne Hackborn | 1de1186 | 2015-07-15 14:20:51 -0700 | [diff] [blame] | 838 | |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 839 | @Override |
| 840 | public int getUserDisabledShowContext() { |
| 841 | synchronized (this) { |
| 842 | if (mImpl == null) { |
| 843 | Slog.w(TAG, |
| 844 | "getUserDisabledShowContext without running voice interaction service"); |
| 845 | return 0; |
| 846 | } |
| 847 | final int callingUid = Binder.getCallingUid(); |
| 848 | final long caller = Binder.clearCallingIdentity(); |
| 849 | try { |
| 850 | return mImpl.getUserDisabledShowContextLocked(callingUid); |
| 851 | } finally { |
| 852 | Binder.restoreCallingIdentity(caller); |
| 853 | } |
| 854 | } |
Dianne Hackborn | 1de1186 | 2015-07-15 14:20:51 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 857 | //----------------- Model management APIs --------------------------------// |
| 858 | |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 859 | @Override |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 860 | public KeyphraseSoundModel getKeyphraseSoundModel(int keyphraseId, String bcp47Locale) { |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 861 | enforceCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES); |
Sandeep | d701820 | 2014-07-10 15:15:39 -0700 | [diff] [blame] | 862 | |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 863 | if (bcp47Locale == null) { |
| 864 | throw new IllegalArgumentException("Illegal argument(s) in getKeyphraseSoundModel"); |
| 865 | } |
| 866 | |
| 867 | final int callingUid = UserHandle.getCallingUserId(); |
Sandeep Siddhartha | f63bc52 | 2014-07-22 09:49:49 -0700 | [diff] [blame] | 868 | final long caller = Binder.clearCallingIdentity(); |
| 869 | try { |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 870 | return mDbHelper.getKeyphraseSoundModel(keyphraseId, callingUid, bcp47Locale); |
Sandeep Siddhartha | f63bc52 | 2014-07-22 09:49:49 -0700 | [diff] [blame] | 871 | } finally { |
| 872 | Binder.restoreCallingIdentity(caller); |
Sandeep | d701820 | 2014-07-10 15:15:39 -0700 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | |
| 876 | @Override |
| 877 | public int updateKeyphraseSoundModel(KeyphraseSoundModel model) { |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 878 | enforceCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES); |
| 879 | if (model == null) { |
| 880 | throw new IllegalArgumentException("Model must not be null"); |
Sandeep Siddhartha | f63bc52 | 2014-07-22 09:49:49 -0700 | [diff] [blame] | 881 | } |
Sandeep Siddhartha | f8cf71d | 2014-07-16 22:53:19 -0700 | [diff] [blame] | 882 | |
Sandeep Siddhartha | f63bc52 | 2014-07-22 09:49:49 -0700 | [diff] [blame] | 883 | final long caller = Binder.clearCallingIdentity(); |
| 884 | try { |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 885 | if (mDbHelper.updateKeyphraseSoundModel(model)) { |
| 886 | synchronized (this) { |
| 887 | // Notify the voice interaction service of a change in sound models. |
| 888 | if (mImpl != null && mImpl.mService != null) { |
| 889 | mImpl.notifySoundModelsChangedLocked(); |
| 890 | } |
| 891 | } |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 892 | return SoundTriggerInternal.STATUS_OK; |
Sandeep Siddhartha | f63bc52 | 2014-07-22 09:49:49 -0700 | [diff] [blame] | 893 | } else { |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 894 | return SoundTriggerInternal.STATUS_ERROR; |
Sandeep Siddhartha | f63bc52 | 2014-07-22 09:49:49 -0700 | [diff] [blame] | 895 | } |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 896 | } finally { |
| 897 | Binder.restoreCallingIdentity(caller); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | @Override |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 902 | public int deleteKeyphraseSoundModel(int keyphraseId, String bcp47Locale) { |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 903 | enforceCallingPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 904 | |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 905 | if (bcp47Locale == null) { |
| 906 | throw new IllegalArgumentException( |
| 907 | "Illegal argument(s) in deleteKeyphraseSoundModel"); |
| 908 | } |
| 909 | |
| 910 | final int callingUid = UserHandle.getCallingUserId(); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 911 | final long caller = Binder.clearCallingIdentity(); |
Sandeep Siddhartha | 256e1a6 | 2014-08-05 11:56:58 -0700 | [diff] [blame] | 912 | boolean deleted = false; |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 913 | try { |
Arunesh Mishra | 2d1de78 | 2016-02-21 18:10:28 -0800 | [diff] [blame] | 914 | int unloadStatus = mSoundTriggerInternal.unloadKeyphraseModel(keyphraseId); |
| 915 | if (unloadStatus != SoundTriggerInternal.STATUS_OK) { |
| 916 | Slog.w(TAG, "Unable to unload keyphrase sound model:" + unloadStatus); |
| 917 | } |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 918 | deleted = mDbHelper.deleteKeyphraseSoundModel(keyphraseId, callingUid, bcp47Locale); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 919 | return deleted ? SoundTriggerInternal.STATUS_OK : SoundTriggerInternal.STATUS_ERROR; |
Sandeep Siddhartha | 256e1a6 | 2014-08-05 11:56:58 -0700 | [diff] [blame] | 920 | } finally { |
| 921 | if (deleted) { |
Sandeep Siddhartha | f63bc52 | 2014-07-22 09:49:49 -0700 | [diff] [blame] | 922 | synchronized (this) { |
Sandeep Siddhartha | 6daae96 | 2014-07-21 10:31:34 -0700 | [diff] [blame] | 923 | // Notify the voice interaction service of a change in sound models. |
| 924 | if (mImpl != null && mImpl.mService != null) { |
| 925 | mImpl.notifySoundModelsChangedLocked(); |
Sandeep Siddhartha | f8cf71d | 2014-07-16 22:53:19 -0700 | [diff] [blame] | 926 | } |
Chris Thornton | f967da9 | 2016-05-02 19:22:57 -0700 | [diff] [blame] | 927 | mLoadedKeyphraseIds.remove(keyphraseId); |
Sandeep Siddhartha | 2883ba6 | 2014-07-16 21:02:08 -0700 | [diff] [blame] | 928 | } |
Sandeep | d701820 | 2014-07-10 15:15:39 -0700 | [diff] [blame] | 929 | } |
Sandeep Siddhartha | f63bc52 | 2014-07-22 09:49:49 -0700 | [diff] [blame] | 930 | Binder.restoreCallingIdentity(caller); |
Sandeep | d701820 | 2014-07-10 15:15:39 -0700 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 934 | //----------------- SoundTrigger APIs --------------------------------// |
| 935 | @Override |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 936 | public boolean isEnrolledForKeyphrase(IVoiceInteractionService service, int keyphraseId, |
| 937 | String bcp47Locale) { |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 938 | synchronized (this) { |
James O'Leary | 596708b | 2019-01-30 14:52:21 -0500 | [diff] [blame] | 939 | enforceIsCurrentVoiceInteractionService(service); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 942 | if (bcp47Locale == null) { |
| 943 | throw new IllegalArgumentException("Illegal argument(s) in isEnrolledForKeyphrase"); |
| 944 | } |
| 945 | |
| 946 | final int callingUid = UserHandle.getCallingUserId(); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 947 | final long caller = Binder.clearCallingIdentity(); |
| 948 | try { |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 949 | KeyphraseSoundModel model = |
| 950 | mDbHelper.getKeyphraseSoundModel(keyphraseId, callingUid, bcp47Locale); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 951 | return model != null; |
| 952 | } finally { |
| 953 | Binder.restoreCallingIdentity(caller); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | @Override |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 958 | public ModuleProperties getDspModuleProperties(IVoiceInteractionService service) { |
| 959 | // Allow the call if this is the current voice interaction service. |
| 960 | synchronized (this) { |
James O'Leary | 596708b | 2019-01-30 14:52:21 -0500 | [diff] [blame] | 961 | enforceIsCurrentVoiceInteractionService(service); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 962 | |
| 963 | final long caller = Binder.clearCallingIdentity(); |
| 964 | try { |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 965 | return mSoundTriggerInternal.getModuleProperties(); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 966 | } finally { |
| 967 | Binder.restoreCallingIdentity(caller); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | @Override |
| 973 | public int startRecognition(IVoiceInteractionService service, int keyphraseId, |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 974 | String bcp47Locale, IRecognitionStatusCallback callback, |
| 975 | RecognitionConfig recognitionConfig) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 976 | // Allow the call if this is the current voice interaction service. |
| 977 | synchronized (this) { |
James O'Leary | 596708b | 2019-01-30 14:52:21 -0500 | [diff] [blame] | 978 | enforceIsCurrentVoiceInteractionService(service); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 979 | |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 980 | if (callback == null || recognitionConfig == null || bcp47Locale == null) { |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 981 | throw new IllegalArgumentException("Illegal argument(s) in startRecognition"); |
| 982 | } |
| 983 | } |
| 984 | |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 985 | int callingUid = UserHandle.getCallingUserId(); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 986 | final long caller = Binder.clearCallingIdentity(); |
| 987 | try { |
Sandeep Siddhartha | 8cf8f71 | 2014-09-15 12:51:08 -0700 | [diff] [blame] | 988 | KeyphraseSoundModel soundModel = |
| 989 | mDbHelper.getKeyphraseSoundModel(keyphraseId, callingUid, bcp47Locale); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 990 | if (soundModel == null |
| 991 | || soundModel.uuid == null |
| 992 | || soundModel.keyphrases == null) { |
| 993 | Slog.w(TAG, "No matching sound model found in startRecognition"); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 994 | return SoundTriggerInternal.STATUS_ERROR; |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 995 | } else { |
Chris Thornton | f967da9 | 2016-05-02 19:22:57 -0700 | [diff] [blame] | 996 | // Regardless of the status of the start recognition, we need to make sure |
| 997 | // that we unload this model if needed later. |
| 998 | synchronized (this) { |
| 999 | mLoadedKeyphraseIds.add(keyphraseId); |
| 1000 | } |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1001 | return mSoundTriggerInternal.startRecognition( |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1002 | keyphraseId, soundModel, callback, recognitionConfig); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1003 | } |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 1004 | } finally { |
| 1005 | Binder.restoreCallingIdentity(caller); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | @Override |
| 1010 | public int stopRecognition(IVoiceInteractionService service, int keyphraseId, |
| 1011 | IRecognitionStatusCallback callback) { |
| 1012 | // Allow the call if this is the current voice interaction service. |
| 1013 | synchronized (this) { |
James O'Leary | 596708b | 2019-01-30 14:52:21 -0500 | [diff] [blame] | 1014 | enforceIsCurrentVoiceInteractionService(service); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 1015 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1016 | |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 1017 | final long caller = Binder.clearCallingIdentity(); |
| 1018 | try { |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1019 | return mSoundTriggerInternal.stopRecognition(keyphraseId, callback); |
Sandeep Siddhartha | 452a642 | 2014-07-25 10:49:34 -0700 | [diff] [blame] | 1020 | } finally { |
| 1021 | Binder.restoreCallingIdentity(caller); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | |
Chris Thornton | f967da9 | 2016-05-02 19:22:57 -0700 | [diff] [blame] | 1025 | private synchronized void unloadAllKeyphraseModels() { |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 1026 | for (int i = 0; i < mLoadedKeyphraseIds.size(); i++) { |
Chris Thornton | f967da9 | 2016-05-02 19:22:57 -0700 | [diff] [blame] | 1027 | final long caller = Binder.clearCallingIdentity(); |
| 1028 | try { |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 1029 | int status = mSoundTriggerInternal.unloadKeyphraseModel( |
| 1030 | mLoadedKeyphraseIds.valueAt(i)); |
Chris Thornton | f967da9 | 2016-05-02 19:22:57 -0700 | [diff] [blame] | 1031 | if (status != SoundTriggerInternal.STATUS_OK) { |
Dianne Hackborn | c160fa4 | 2017-11-01 16:14:26 -0700 | [diff] [blame] | 1032 | Slog.w(TAG, "Failed to unload keyphrase " + mLoadedKeyphraseIds.valueAt(i) |
| 1033 | + ":" + status); |
Chris Thornton | f967da9 | 2016-05-02 19:22:57 -0700 | [diff] [blame] | 1034 | } |
| 1035 | } finally { |
| 1036 | Binder.restoreCallingIdentity(caller); |
| 1037 | } |
| 1038 | } |
| 1039 | mLoadedKeyphraseIds.clear(); |
| 1040 | } |
| 1041 | |
Sandeep | d701820 | 2014-07-10 15:15:39 -0700 | [diff] [blame] | 1042 | @Override |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 1043 | public ComponentName getActiveServiceComponentName() { |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 1044 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 1045 | synchronized (this) { |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 1046 | return mImpl != null ? mImpl.mComponent : null; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | @Override |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1051 | public boolean showSessionForActiveService(Bundle args, int sourceFlags, |
| 1052 | IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) { |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 1053 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
Jorim Jaggi | 25e12ab | 2015-04-02 11:46:28 -0700 | [diff] [blame] | 1054 | synchronized (this) { |
Jorim Jaggi | 25e12ab | 2015-04-02 11:46:28 -0700 | [diff] [blame] | 1055 | if (mImpl == null) { |
| 1056 | Slog.w(TAG, "showSessionForActiveService without running voice interaction" |
| 1057 | + "service"); |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1058 | return false; |
Jorim Jaggi | 25e12ab | 2015-04-02 11:46:28 -0700 | [diff] [blame] | 1059 | } |
Jorim Jaggi | 25e12ab | 2015-04-02 11:46:28 -0700 | [diff] [blame] | 1060 | final long caller = Binder.clearCallingIdentity(); |
| 1061 | try { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1062 | return mImpl.showSessionLocked(args, |
| 1063 | sourceFlags |
Dianne Hackborn | 2ee5c36 | 2015-05-29 17:58:53 -0700 | [diff] [blame] | 1064 | | VoiceInteractionSession.SHOW_WITH_ASSIST |
| 1065 | | VoiceInteractionSession.SHOW_WITH_SCREENSHOT, |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1066 | showCallback, activityToken); |
Jorim Jaggi | 25e12ab | 2015-04-02 11:46:28 -0700 | [diff] [blame] | 1067 | } finally { |
| 1068 | Binder.restoreCallingIdentity(caller); |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | @Override |
Jorim Jaggi | b835dd7 | 2015-06-08 12:28:42 -0700 | [diff] [blame] | 1074 | public void hideCurrentSession() throws RemoteException { |
| 1075 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
| 1076 | synchronized (this) { |
| 1077 | if (mImpl == null) { |
| 1078 | return; |
| 1079 | } |
| 1080 | final long caller = Binder.clearCallingIdentity(); |
| 1081 | try { |
| 1082 | if (mImpl.mActiveSession != null && mImpl.mActiveSession.mSession != null) { |
| 1083 | try { |
| 1084 | mImpl.mActiveSession.mSession.closeSystemDialogs(); |
| 1085 | } catch (RemoteException e) { |
| 1086 | Log.w(TAG, "Failed to call closeSystemDialogs", e); |
| 1087 | } |
| 1088 | } |
| 1089 | } finally { |
| 1090 | Binder.restoreCallingIdentity(caller); |
| 1091 | } |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | @Override |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 1096 | public void launchVoiceAssistFromKeyguard() { |
| 1097 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
| 1098 | synchronized (this) { |
| 1099 | if (mImpl == null) { |
| 1100 | Slog.w(TAG, "launchVoiceAssistFromKeyguard without running voice interaction" |
| 1101 | + "service"); |
| 1102 | return; |
| 1103 | } |
| 1104 | final long caller = Binder.clearCallingIdentity(); |
| 1105 | try { |
| 1106 | mImpl.launchVoiceAssistFromKeyguard(); |
| 1107 | } finally { |
| 1108 | Binder.restoreCallingIdentity(caller); |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | @Override |
Jorim Jaggi | 25e12ab | 2015-04-02 11:46:28 -0700 | [diff] [blame] | 1114 | public boolean isSessionRunning() { |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 1115 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
Jorim Jaggi | 25e12ab | 2015-04-02 11:46:28 -0700 | [diff] [blame] | 1116 | synchronized (this) { |
Jorim Jaggi | 25e12ab | 2015-04-02 11:46:28 -0700 | [diff] [blame] | 1117 | return mImpl != null && mImpl.mActiveSession != null; |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | @Override |
Jorim Jaggi | 5f560d0 | 2015-04-30 11:49:29 -0700 | [diff] [blame] | 1122 | public boolean activeServiceSupportsAssist() { |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 1123 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
| 1124 | synchronized (this) { |
Selim Cinek | 03872c0 | 2015-05-07 18:12:51 -0700 | [diff] [blame] | 1125 | return mImpl != null && mImpl.mInfo != null && mImpl.mInfo.getSupportsAssist(); |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | @Override |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 1130 | public boolean activeServiceSupportsLaunchFromKeyguard() throws RemoteException { |
| 1131 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
| 1132 | synchronized (this) { |
Selim Cinek | 03872c0 | 2015-05-07 18:12:51 -0700 | [diff] [blame] | 1133 | return mImpl != null && mImpl.mInfo != null |
| 1134 | && mImpl.mInfo.getSupportsLaunchFromKeyguard(); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | @Override |
Jorim Jaggi | 19695d9 | 2015-07-20 15:51:40 -0700 | [diff] [blame] | 1139 | public void onLockscreenShown() { |
| 1140 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
| 1141 | synchronized (this) { |
| 1142 | if (mImpl == null) { |
| 1143 | return; |
| 1144 | } |
| 1145 | final long caller = Binder.clearCallingIdentity(); |
| 1146 | try { |
| 1147 | if (mImpl.mActiveSession != null && mImpl.mActiveSession.mSession != null) { |
| 1148 | try { |
| 1149 | mImpl.mActiveSession.mSession.onLockscreenShown(); |
| 1150 | } catch (RemoteException e) { |
| 1151 | Log.w(TAG, "Failed to call onLockscreenShown", e); |
| 1152 | } |
| 1153 | } |
| 1154 | } finally { |
| 1155 | Binder.restoreCallingIdentity(caller); |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | @Override |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 1161 | public void registerVoiceInteractionSessionListener( |
| 1162 | IVoiceInteractionSessionListener listener) { |
| 1163 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
Annie Chin | d953ab6 | 2016-07-07 11:57:33 -0700 | [diff] [blame] | 1164 | synchronized (this) { |
| 1165 | mVoiceInteractionSessionListeners.register(listener); |
| 1166 | } |
| 1167 | } |
| 1168 | |
jiayuzhou | 21a353b | 2018-08-16 16:09:43 -0700 | [diff] [blame] | 1169 | @Override |
| 1170 | public void getActiveServiceSupportedActions(List<String> voiceActions, |
| 1171 | IVoiceActionCheckCallback callback) { |
| 1172 | enforceCallingPermission(Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE); |
| 1173 | synchronized (this) { |
| 1174 | if (mImpl == null) { |
| 1175 | try { |
| 1176 | callback.onComplete(null); |
| 1177 | } catch (RemoteException e) { |
| 1178 | } |
| 1179 | return; |
| 1180 | } |
| 1181 | final long caller = Binder.clearCallingIdentity(); |
| 1182 | try { |
| 1183 | mImpl.getActiveServiceSupportedActions(voiceActions, callback); |
| 1184 | } finally { |
| 1185 | Binder.restoreCallingIdentity(caller); |
| 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | |
Annie Chin | d953ab6 | 2016-07-07 11:57:33 -0700 | [diff] [blame] | 1190 | public void onSessionShown() { |
| 1191 | synchronized (this) { |
| 1192 | final int size = mVoiceInteractionSessionListeners.beginBroadcast(); |
| 1193 | for (int i = 0; i < size; ++i) { |
| 1194 | final IVoiceInteractionSessionListener listener = |
| 1195 | mVoiceInteractionSessionListeners.getBroadcastItem(i); |
| 1196 | try { |
| 1197 | listener.onVoiceSessionShown(); |
| 1198 | } catch (RemoteException e) { |
| 1199 | Slog.e(TAG, "Error delivering voice interaction open event.", e); |
| 1200 | } |
| 1201 | } |
| 1202 | mVoiceInteractionSessionListeners.finishBroadcast(); |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | public void onSessionHidden() { |
| 1207 | synchronized (this) { |
| 1208 | final int size = mVoiceInteractionSessionListeners.beginBroadcast(); |
| 1209 | for (int i = 0; i < size; ++i) { |
| 1210 | final IVoiceInteractionSessionListener listener = |
| 1211 | mVoiceInteractionSessionListeners.getBroadcastItem(i); |
| 1212 | try { |
| 1213 | listener.onVoiceSessionHidden(); |
| 1214 | |
| 1215 | } catch (RemoteException e) { |
| 1216 | Slog.e(TAG, "Error delivering voice interaction closed event.", e); |
| 1217 | } |
| 1218 | } |
| 1219 | mVoiceInteractionSessionListeners.finishBroadcast(); |
Annie Chin | 2045bdd | 2016-07-07 10:22:34 -0700 | [diff] [blame] | 1220 | } |
Annie Chin | ecb9f3e | 2016-06-27 16:01:52 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | @Override |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1224 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 1225 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 1226 | synchronized (this) { |
Dianne Hackborn | 958b9d2 | 2015-10-09 16:09:25 -0700 | [diff] [blame] | 1227 | pw.println("VOICE INTERACTION MANAGER (dumpsys voiceinteraction)"); |
Cedric Ho | c663d99 | 2015-04-23 15:16:47 -0700 | [diff] [blame] | 1228 | pw.println(" mEnableService: " + mEnableService); |
Dianne Hackborn | 18f0d35 | 2014-04-25 17:06:18 -0700 | [diff] [blame] | 1229 | if (mImpl == null) { |
| 1230 | pw.println(" (No active implementation)"); |
| 1231 | return; |
| 1232 | } |
| 1233 | mImpl.dumpLocked(fd, pw, args); |
| 1234 | } |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1235 | mSoundTriggerInternal.dump(fd, pw, args); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 1238 | @Override |
James O'Leary | 9c9dd98 | 2019-02-08 15:49:06 -0500 | [diff] [blame] | 1239 | public void setUiHints(IVoiceInteractionService service, Bundle hints) { |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 1240 | synchronized (this) { |
James O'Leary | 596708b | 2019-01-30 14:52:21 -0500 | [diff] [blame] | 1241 | enforceIsCurrentVoiceInteractionService(service); |
| 1242 | |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 1243 | final int size = mVoiceInteractionSessionListeners.beginBroadcast(); |
| 1244 | for (int i = 0; i < size; ++i) { |
| 1245 | final IVoiceInteractionSessionListener listener = |
| 1246 | mVoiceInteractionSessionListeners.getBroadcastItem(i); |
| 1247 | try { |
James O'Leary | 9c9dd98 | 2019-02-08 15:49:06 -0500 | [diff] [blame] | 1248 | listener.onSetUiHints(hints); |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 1249 | } catch (RemoteException e) { |
James O'Leary | 9c9dd98 | 2019-02-08 15:49:06 -0500 | [diff] [blame] | 1250 | Slog.e(TAG, "Error delivering UI hints.", e); |
Matt Casey | 4cff16f | 2019-01-14 14:56:06 -0500 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | mVoiceInteractionSessionListeners.finishBroadcast(); |
| 1254 | } |
| 1255 | } |
| 1256 | |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 1257 | private void enforceCallingPermission(String permission) { |
Dianne Hackborn | 17f6935 | 2015-07-17 18:04:14 -0700 | [diff] [blame] | 1258 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1259 | != PackageManager.PERMISSION_GRANTED) { |
Jorim Jaggi | 0b68ff4 | 2015-04-02 11:21:39 -0700 | [diff] [blame] | 1260 | throw new SecurityException("Caller does not hold the permission " + permission); |
| 1261 | } |
| 1262 | } |
| 1263 | |
James O'Leary | 596708b | 2019-01-30 14:52:21 -0500 | [diff] [blame] | 1264 | private void enforceIsCurrentVoiceInteractionService(IVoiceInteractionService service) { |
| 1265 | if (mImpl == null || mImpl.mService == null |
| 1266 | || service.asBinder() != mImpl.mService.asBinder()) { |
| 1267 | throw new |
| 1268 | SecurityException("Caller is not the current voice interaction service"); |
| 1269 | } |
| 1270 | } |
| 1271 | |
Winson Chung | bccd4b5 | 2017-12-13 11:08:39 -0800 | [diff] [blame] | 1272 | private void setImplLocked(VoiceInteractionManagerServiceImpl impl) { |
| 1273 | mImpl = impl; |
Wale Ogunwale | d0412b3 | 2018-05-08 09:25:50 -0700 | [diff] [blame] | 1274 | mAtmInternal.notifyActiveVoiceInteractionServiceChanged( |
Winson Chung | bccd4b5 | 2017-12-13 11:08:39 -0800 | [diff] [blame] | 1275 | getActiveServiceComponentName()); |
| 1276 | } |
| 1277 | |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1278 | class RoleObserver implements OnRoleHoldersChangedListener { |
| 1279 | private PackageManager mPm = mContext.getPackageManager(); |
| 1280 | private RoleManager mRm = mContext.getSystemService(RoleManager.class); |
| 1281 | |
| 1282 | RoleObserver(@NonNull @CallbackExecutor Executor executor) { |
| 1283 | mRm.addOnRoleHoldersChangedListenerAsUser(executor, this, UserHandle.ALL); |
Winson Chung | 28f5a88 | 2019-04-08 16:26:03 -0700 | [diff] [blame] | 1284 | UserHandle currentUser = UserHandle.of(LocalServices.getService( |
| 1285 | ActivityManagerInternal.class).getCurrentUserId()); |
Hai Zhang | c00c31e | 2019-06-03 18:50:33 +0000 | [diff] [blame] | 1286 | onRoleHoldersChanged(RoleManager.ROLE_ASSISTANT, currentUser); |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | private @NonNull String getDefaultRecognizer(@NonNull UserHandle user) { |
| 1290 | ResolveInfo resolveInfo = mPm.resolveServiceAsUser( |
| 1291 | new Intent(RecognitionService.SERVICE_INTERFACE), |
| 1292 | PackageManager.GET_META_DATA, user.getIdentifier()); |
| 1293 | |
| 1294 | if (resolveInfo == null || resolveInfo.serviceInfo == null) { |
| 1295 | Log.w(TAG, "Unable to resolve default voice recognition service."); |
| 1296 | return ""; |
| 1297 | } |
| 1298 | |
| 1299 | return new ComponentName(resolveInfo.serviceInfo.packageName, |
| 1300 | resolveInfo.serviceInfo.name).flattenToShortString(); |
| 1301 | } |
| 1302 | |
| 1303 | /** |
| 1304 | * Convert the assistant-role holder into settings. The rest of the system uses the |
| 1305 | * settings. |
| 1306 | * |
| 1307 | * @param roleName the name of the role whose holders are changed |
| 1308 | * @param user the user for this role holder change |
| 1309 | */ |
| 1310 | @Override |
| 1311 | public void onRoleHoldersChanged(@NonNull String roleName, @NonNull UserHandle user) { |
| 1312 | if (!roleName.equals(RoleManager.ROLE_ASSISTANT)) { |
| 1313 | return; |
| 1314 | } |
| 1315 | |
| 1316 | List<String> roleHolders = mRm.getRoleHoldersAsUser(roleName, user); |
| 1317 | |
Hai Zhang | 5cc4ae9 | 2019-02-08 11:42:34 -0800 | [diff] [blame] | 1318 | int userId = user.getIdentifier(); |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1319 | if (roleHolders.isEmpty()) { |
Hai Zhang | 5cc4ae9 | 2019-02-08 11:42:34 -0800 | [diff] [blame] | 1320 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
| 1321 | Settings.Secure.ASSISTANT, "", userId); |
| 1322 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
| 1323 | Settings.Secure.VOICE_INTERACTION_SERVICE, "", userId); |
| 1324 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
| 1325 | Settings.Secure.VOICE_RECOGNITION_SERVICE, getDefaultRecognizer(user), |
| 1326 | userId); |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1327 | } else { |
| 1328 | // Assistant is singleton role |
| 1329 | String pkg = roleHolders.get(0); |
| 1330 | |
| 1331 | // Try to set role holder as VoiceInteractionService |
| 1332 | List<ResolveInfo> services = mPm.queryIntentServicesAsUser( |
| 1333 | new Intent(VoiceInteractionService.SERVICE_INTERFACE).setPackage(pkg), |
Winson Chung | 28f5a88 | 2019-04-08 16:26:03 -0700 | [diff] [blame] | 1334 | PackageManager.GET_META_DATA |
| 1335 | | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 1336 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId); |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1337 | |
| 1338 | for (ResolveInfo resolveInfo : services) { |
| 1339 | ServiceInfo serviceInfo = resolveInfo.serviceInfo; |
| 1340 | |
| 1341 | VoiceInteractionServiceInfo voiceInteractionServiceInfo = |
| 1342 | new VoiceInteractionServiceInfo(mPm, serviceInfo); |
| 1343 | if (!voiceInteractionServiceInfo.getSupportsAssist()) { |
| 1344 | continue; |
| 1345 | } |
| 1346 | |
| 1347 | String serviceComponentName = serviceInfo.getComponentName() |
| 1348 | .flattenToShortString(); |
| 1349 | |
| 1350 | String serviceRecognizerName = new ComponentName(pkg, |
| 1351 | voiceInteractionServiceInfo.getRecognitionService()) |
| 1352 | .flattenToShortString(); |
| 1353 | |
Hai Zhang | 5cc4ae9 | 2019-02-08 11:42:34 -0800 | [diff] [blame] | 1354 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
| 1355 | Settings.Secure.ASSISTANT, serviceComponentName, userId); |
| 1356 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
| 1357 | Settings.Secure.VOICE_INTERACTION_SERVICE, serviceComponentName, |
| 1358 | userId); |
| 1359 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
| 1360 | Settings.Secure.VOICE_RECOGNITION_SERVICE, serviceRecognizerName, |
| 1361 | userId); |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1362 | |
| 1363 | return; |
| 1364 | } |
| 1365 | |
| 1366 | // If no service could be found try to set assist activity |
| 1367 | final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser( |
| 1368 | new Intent(Intent.ACTION_ASSIST).setPackage(pkg), |
Winson Chung | 28f5a88 | 2019-04-08 16:26:03 -0700 | [diff] [blame] | 1369 | PackageManager.MATCH_DEFAULT_ONLY |
| 1370 | | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 1371 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId); |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1372 | |
| 1373 | for (ResolveInfo resolveInfo : activities) { |
| 1374 | ActivityInfo activityInfo = resolveInfo.activityInfo; |
| 1375 | |
Hai Zhang | 5cc4ae9 | 2019-02-08 11:42:34 -0800 | [diff] [blame] | 1376 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1377 | Settings.Secure.ASSISTANT, |
Hai Zhang | 5cc4ae9 | 2019-02-08 11:42:34 -0800 | [diff] [blame] | 1378 | activityInfo.getComponentName().flattenToShortString(), userId); |
| 1379 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
| 1380 | Settings.Secure.VOICE_INTERACTION_SERVICE, "", userId); |
| 1381 | Settings.Secure.putStringForUser(getContext().getContentResolver(), |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1382 | Settings.Secure.VOICE_RECOGNITION_SERVICE, |
Hai Zhang | 5cc4ae9 | 2019-02-08 11:42:34 -0800 | [diff] [blame] | 1383 | getDefaultRecognizer(user), userId); |
Winson Chung | 28f5a88 | 2019-04-08 16:26:03 -0700 | [diff] [blame] | 1384 | return; |
Philip P. Moltmann | 5d89450 | 2019-01-17 10:31:00 -0800 | [diff] [blame] | 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1390 | class SettingsObserver extends ContentObserver { |
| 1391 | SettingsObserver(Handler handler) { |
| 1392 | super(handler); |
| 1393 | ContentResolver resolver = mContext.getContentResolver(); |
| 1394 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 5f531f1 | 2015-06-10 21:15:00 -0700 | [diff] [blame] | 1395 | Settings.Secure.VOICE_INTERACTION_SERVICE), false, this, |
| 1396 | UserHandle.USER_ALL); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | @Override public void onChange(boolean selfChange) { |
| 1400 | synchronized (VoiceInteractionManagerServiceStub.this) { |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 1401 | switchImplementationIfNeededLocked(false); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | PackageMonitor mPackageMonitor = new PackageMonitor() { |
| 1407 | @Override |
| 1408 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1409 | if (DEBUG) Slog.d(TAG, "onHandleForceStop uid=" + uid + " doit=" + doit); |
| 1410 | |
| 1411 | int userHandle = UserHandle.getUserId(uid); |
| 1412 | ComponentName curInteractor = getCurInteractor(userHandle); |
| 1413 | ComponentName curRecognizer = getCurRecognizer(userHandle); |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 1414 | boolean hitInt = false; |
| 1415 | boolean hitRec = false; |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1416 | for (String pkg : packages) { |
| 1417 | if (curInteractor != null && pkg.equals(curInteractor.getPackageName())) { |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 1418 | hitInt = true; |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1419 | break; |
| 1420 | } else if (curRecognizer != null |
| 1421 | && pkg.equals(curRecognizer.getPackageName())) { |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 1422 | hitRec = true; |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1423 | break; |
| 1424 | } |
| 1425 | } |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 1426 | if (hitInt && doit) { |
| 1427 | // The user is force stopping our current interactor. |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1428 | // Clear the current settings and restore default state. |
Amith Yamasani | f5c37eb | 2016-05-23 17:21:08 -0700 | [diff] [blame] | 1429 | synchronized (VoiceInteractionManagerServiceStub.this) { |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 1430 | Slog.i(TAG, "Force stopping current voice interactor: " |
| 1431 | + getCurInteractor(userHandle)); |
Chris Thornton | f967da9 | 2016-05-02 19:22:57 -0700 | [diff] [blame] | 1432 | unloadAllKeyphraseModels(); |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1433 | if (mImpl != null) { |
| 1434 | mImpl.shutdownLocked(); |
Winson Chung | bccd4b5 | 2017-12-13 11:08:39 -0800 | [diff] [blame] | 1435 | setImplLocked(null); |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1436 | } |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 1437 | |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1438 | setCurInteractor(null, userHandle); |
| 1439 | setCurRecognizer(null, userHandle); |
Jorim Jaggi | cc3a46a | 2015-06-25 15:55:43 -0700 | [diff] [blame] | 1440 | resetCurAssistant(userHandle); |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1441 | initForUser(userHandle); |
| 1442 | switchImplementationIfNeededLocked(true); |
Hai Zhang | 7f1b8f6 | 2019-03-08 16:44:27 -0800 | [diff] [blame] | 1443 | |
| 1444 | Context context = getContext(); |
| 1445 | context.getSystemService(RoleManager.class).clearRoleHoldersAsUser( |
| 1446 | RoleManager.ROLE_ASSISTANT, 0, UserHandle.of(userHandle), |
| 1447 | context.getMainExecutor(), successful -> { |
| 1448 | if (!successful) { |
| 1449 | Slog.e(TAG, |
| 1450 | "Failed to clear default assistant for force stop"); |
| 1451 | } |
| 1452 | }); |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1453 | } |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 1454 | } else if (hitRec && doit) { |
| 1455 | // We are just force-stopping the current recognizer, which is not |
| 1456 | // also the current interactor. |
| 1457 | synchronized (VoiceInteractionManagerServiceStub.this) { |
| 1458 | Slog.i(TAG, "Force stopping current voice recognizer: " |
| 1459 | + getCurRecognizer(userHandle)); |
| 1460 | initSimpleRecognizer(null, userHandle); |
| 1461 | } |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1462 | } |
Dianne Hackborn | 3d7ab61 | 2018-12-17 10:53:53 -0800 | [diff] [blame] | 1463 | return hitInt || hitRec; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | @Override |
| 1467 | public void onHandleUserStop(Intent intent, int userHandle) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | @Override |
Sudheer Shanka | 7a3d901 | 2017-04-11 17:19:22 -0700 | [diff] [blame] | 1471 | public void onPackageModified(String pkgName) { |
| 1472 | // If the package modified is not in the current user, then don't bother making |
| 1473 | // any changes as we are going to do any initialization needed when we switch users. |
| 1474 | if (mCurUser != getChangingUserId()) { |
| 1475 | return; |
| 1476 | } |
| 1477 | // Package getting updated will be handled by {@link #onSomePackagesChanged}. |
| 1478 | if (isPackageAppearing(pkgName) != PACKAGE_UNCHANGED) { |
| 1479 | return; |
| 1480 | } |
| 1481 | final ComponentName curInteractor = getCurInteractor(mCurUser); |
| 1482 | if (curInteractor == null) { |
| 1483 | final VoiceInteractionServiceInfo availInteractorInfo |
| 1484 | = findAvailInteractor(mCurUser, pkgName); |
| 1485 | if (availInteractorInfo != null) { |
| 1486 | final ComponentName availInteractor = new ComponentName( |
| 1487 | availInteractorInfo.getServiceInfo().packageName, |
| 1488 | availInteractorInfo.getServiceInfo().name); |
| 1489 | setCurInteractor(availInteractor, mCurUser); |
| 1490 | if (getCurRecognizer(mCurUser) == null && |
| 1491 | availInteractorInfo.getRecognitionService() != null) { |
| 1492 | setCurRecognizer(new ComponentName( |
| 1493 | availInteractorInfo.getServiceInfo().packageName, |
| 1494 | availInteractorInfo.getRecognitionService()), mCurUser); |
| 1495 | } |
| 1496 | } |
| 1497 | } else { |
| 1498 | if (didSomePackagesChange()) { |
| 1499 | // Package is changed |
| 1500 | if (curInteractor != null && pkgName.equals( |
| 1501 | curInteractor.getPackageName())) { |
| 1502 | switchImplementationIfNeeded(true); |
| 1503 | } |
| 1504 | } else { |
| 1505 | // Only some components are changed |
| 1506 | if (curInteractor != null |
| 1507 | && isComponentModified(curInteractor.getClassName())) { |
| 1508 | switchImplementationIfNeeded(true); |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | @Override |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1515 | public void onSomePackagesChanged() { |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1516 | int userHandle = getChangingUserId(); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 1517 | if (DEBUG) Slog.d(TAG, "onSomePackagesChanged user=" + userHandle); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1518 | |
Amith Yamasani | f5c37eb | 2016-05-23 17:21:08 -0700 | [diff] [blame] | 1519 | synchronized (VoiceInteractionManagerServiceStub.this) { |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1520 | ComponentName curInteractor = getCurInteractor(userHandle); |
| 1521 | ComponentName curRecognizer = getCurRecognizer(userHandle); |
Dianne Hackborn | e956365 | 2016-08-18 17:33:41 -0700 | [diff] [blame] | 1522 | ComponentName curAssistant = getCurAssistant(userHandle); |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1523 | if (curRecognizer == null) { |
| 1524 | // Could a new recognizer appear when we don't have one pre-installed? |
| 1525 | if (anyPackagesAppearing()) { |
| 1526 | curRecognizer = findAvailRecognizer(null, userHandle); |
| 1527 | if (curRecognizer != null) { |
| 1528 | setCurRecognizer(curRecognizer, userHandle); |
| 1529 | } |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1530 | } |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1531 | return; |
| 1532 | } |
| 1533 | |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1534 | if (curInteractor != null) { |
| 1535 | int change = isPackageDisappearing(curInteractor.getPackageName()); |
| 1536 | if (change == PACKAGE_PERMANENT_CHANGE) { |
| 1537 | // The currently set interactor is permanently gone; fall back to |
| 1538 | // the default config. |
| 1539 | setCurInteractor(null, userHandle); |
| 1540 | setCurRecognizer(null, userHandle); |
Dianne Hackborn | e956365 | 2016-08-18 17:33:41 -0700 | [diff] [blame] | 1541 | resetCurAssistant(userHandle); |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1542 | initForUser(userHandle); |
| 1543 | return; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1544 | } |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1545 | |
| 1546 | change = isPackageAppearing(curInteractor.getPackageName()); |
| 1547 | if (change != PACKAGE_UNCHANGED) { |
| 1548 | // If current interactor is now appearing, for any reason, then |
| 1549 | // restart our connection with it. |
| 1550 | if (mImpl != null && curInteractor.getPackageName().equals( |
| 1551 | mImpl.mComponent.getPackageName())) { |
| 1552 | switchImplementationIfNeededLocked(true); |
| 1553 | } |
| 1554 | } |
| 1555 | return; |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1556 | } |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1557 | |
Dianne Hackborn | e956365 | 2016-08-18 17:33:41 -0700 | [diff] [blame] | 1558 | if (curAssistant != null) { |
| 1559 | int change = isPackageDisappearing(curAssistant.getPackageName()); |
| 1560 | if (change == PACKAGE_PERMANENT_CHANGE) { |
| 1561 | // If the currently set assistant is being removed, then we should |
| 1562 | // reset back to the default state (which is probably that we prefer |
| 1563 | // to have the default full voice interactor enabled). |
| 1564 | setCurInteractor(null, userHandle); |
| 1565 | setCurRecognizer(null, userHandle); |
| 1566 | resetCurAssistant(userHandle); |
| 1567 | initForUser(userHandle); |
| 1568 | return; |
| 1569 | } |
| 1570 | } |
| 1571 | |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1572 | // There is no interactor, so just deal with a simple recognizer. |
| 1573 | int change = isPackageDisappearing(curRecognizer.getPackageName()); |
| 1574 | if (change == PACKAGE_PERMANENT_CHANGE |
| 1575 | || change == PACKAGE_TEMPORARY_CHANGE) { |
| 1576 | setCurRecognizer(findAvailRecognizer(null, userHandle), userHandle); |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1577 | |
Dianne Hackborn | b8004ff | 2015-06-15 13:35:16 -0700 | [diff] [blame] | 1578 | } else if (isPackageModified(curRecognizer.getPackageName())) { |
| 1579 | setCurRecognizer(findAvailRecognizer(curRecognizer.getPackageName(), |
| 1580 | userHandle), userHandle); |
| 1581 | } |
Dianne Hackborn | a351ab9 | 2014-08-08 17:35:50 -0700 | [diff] [blame] | 1582 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1583 | } |
| 1584 | }; |
| 1585 | } |
| 1586 | } |