Merge "Fix Assistant breaks after stopping the app." into tm-dev am: 4c41912939

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17651837

Change-Id: I97cfce253d2fe0af725a7e5612fc5cc8a210fe94
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Joanne Chung
2022-05-04 04:51:52 +00:00
committed by Automerger Merge Worker
2 changed files with 45 additions and 0 deletions

View File

@@ -323,6 +323,16 @@ public class VoiceInteractionManagerService extends SystemService {
new RoleObserver(mContext.getMainExecutor());
}
void handleUserStop(String packageName, int userHandle) {
synchronized (VoiceInteractionManagerServiceStub.this) {
ComponentName curInteractor = getCurInteractor(userHandle);
if (curInteractor != null && packageName.equals(curInteractor.getPackageName())) {
Slog.d(TAG, "switchImplementation for user stop.");
switchImplementationIfNeededLocked(true);
}
}
}
@Override
public @NonNull IVoiceInteractionSoundTriggerSession createSoundTriggerSessionAsOriginator(
@NonNull Identity originatorIdentity, IBinder client) {
@@ -2071,6 +2081,7 @@ public class VoiceInteractionManagerService extends SystemService {
}
PackageMonitor mPackageMonitor = new PackageMonitor() {
@Override
public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
if (DEBUG) Slog.d(TAG, "onHandleForceStop uid=" + uid + " doit=" + doit);
@@ -2103,11 +2114,17 @@ public class VoiceInteractionManagerService extends SystemService {
}
setCurInteractor(null, userHandle);
// TODO: should not reset null here. But even remove this line, the
// initForUser() still reset it because the interactor will be null. Keep
// it now but we should still need to fix it.
setCurRecognizer(null, userHandle);
resetCurAssistant(userHandle);
initForUser(userHandle);
switchImplementationIfNeededLocked(true);
// When resetting the interactor, the recognizer and the assistant settings
// value, we also need to reset the assistant role to keep the values
// consistent. Clear the assistant role will reset to the default value.
Context context = getContext();
context.getSystemService(RoleManager.class).clearRoleHoldersAsUser(
RoleManager.ROLE_ASSISTANT, 0, UserHandle.of(userHandle),

View File

@@ -29,6 +29,7 @@ import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
import android.app.AppGlobals;
import android.app.ApplicationExitInfo;
import android.app.IActivityManager;
import android.app.IActivityTaskManager;
import android.content.BroadcastReceiver;
@@ -38,6 +39,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.ServiceInfo;
import android.hardware.soundtrigger.IRecognitionStatusCallback;
import android.hardware.soundtrigger.SoundTrigger;
@@ -149,6 +151,32 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
resetHotwordDetectionConnectionLocked();
}
}
@Override
public void onBindingDied(ComponentName name) {
Slog.d(TAG, "onBindingDied to " + name);
String packageName = name.getPackageName();
ParceledListSlice<ApplicationExitInfo> plistSlice = null;
try {
plistSlice = mAm.getHistoricalProcessExitReasons(packageName, 0, 1, mUser);
} catch (RemoteException e) {
// do nothing. The local binder so it can not throw it.
}
if (plistSlice == null) {
return;
}
List<ApplicationExitInfo> list = plistSlice.getList();
if (list.isEmpty()) {
return;
}
// TODO(b/229956310): Refactor the logic of PackageMonitor and onBindingDied
ApplicationExitInfo info = list.get(0);
if (info.getReason() == ApplicationExitInfo.REASON_USER_REQUESTED
&& info.getSubReason() == ApplicationExitInfo.SUBREASON_STOP_APP) {
// only handle user stopped the application from the task manager
mServiceStub.handleUserStop(packageName, mUser);
}
}
};
VoiceInteractionManagerServiceImpl(Context context, Handler handler,