Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9fb217d authored by Joanne Chung's avatar Joanne Chung Committed by Automerger Merge Worker
Browse files

Merge "Fix finishTranslation doesn't work if start Activity in the same task"...

Merge "Fix finishTranslation doesn't work if start Activity in the same task" into tm-dev am: 313d6bfe

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



Change-Id: I30ab83817f1da2b5724df43025902317e0c4d559
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 87d54066 313d6bfe
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -387,11 +387,16 @@ public abstract class ActivityTaskManagerInternal {
    public abstract ComponentName getActivityName(IBinder activityToken);
    public abstract ComponentName getActivityName(IBinder activityToken);


    /**
    /**
     * @return the activity token and IApplicationThread for the top activity in the task or null
     * Returns non-finishing Activity that have a process attached for the given task and the token
     * if there isn't a top activity with a valid process.
     * with the activity token and the IApplicationThread or null if there is no Activity with a
     * valid process. Given the null token for the task will return the top Activity in the task.
     *
     * @param taskId the Activity task id.
     * @param token the Activity token, set null if get top Activity for the given task id.
     */
     */
    @Nullable
    @Nullable
    public abstract ActivityTokens getTopActivityForTask(int taskId);
    public abstract ActivityTokens getAttachedNonFinishingActivityForTask(int taskId,
            IBinder token);


    public abstract IIntentSender getIntentSender(int type, String packageName,
    public abstract IIntentSender getIntentSender(int type, String packageName,
            @Nullable String featureId, int callingUid, int userId, IBinder token, String resultWho,
            @Nullable String featureId, int callingUid, int userId, IBinder token, String resultWho,
+24 −12
Original line number Original line Diff line number Diff line
@@ -2944,7 +2944,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        final long callingId = Binder.clearCallingIdentity();
        final long callingId = Binder.clearCallingIdentity();
        LocalService.ActivityTokens tokens = null;
        LocalService.ActivityTokens tokens = null;
        try {
        try {
            tokens = mInternal.getTopActivityForTask(taskId);
            tokens = mInternal.getAttachedNonFinishingActivityForTask(taskId, null);
        } finally {
        } finally {
            Binder.restoreCallingIdentity(callingId);
            Binder.restoreCallingIdentity(callingId);
        }
        }
@@ -5804,7 +5804,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
        }


        @Override
        @Override
        public ActivityTokens getTopActivityForTask(int taskId) {
        public ActivityTokens getAttachedNonFinishingActivityForTask(int taskId,
                IBinder token) {
            synchronized (mGlobalLock) {
            synchronized (mGlobalLock) {
                final Task task = mRootWindowContainer.anyTaskForId(taskId,
                final Task task = mRootWindowContainer.anyTaskForId(taskId,
                        MATCH_ATTACHED_TASK_ONLY);
                        MATCH_ATTACHED_TASK_ONLY);
@@ -5813,19 +5814,30 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                            + " Requested task not found");
                            + " Requested task not found");
                    return null;
                    return null;
                }
                }
                final ActivityRecord activity = task.getTopNonFinishingActivity();
                final List<ActivityRecord> list = new ArrayList<>();
                if (activity == null) {
                task.forAllActivities(r -> {
                    Slog.w(TAG, "getApplicationThreadForTopActivity failed:"
                    if (!r.finishing) {
                            + " Requested activity not found");
                        list.add(r);
                    return null;
                    }
                    }
                if (!activity.attachedToProcess()) {
                });
                    Slog.w(TAG, "getApplicationThreadForTopActivity failed: No process for "
                if (list.size() <= 0) {
                            + activity);
                    return null;
                    return null;
                }
                }
                return new ActivityTokens(activity.token, activity.assistToken,
                // pass null, get top Activity
                        activity.app.getThread(), activity.shareableActivityToken);
                if (token == null && list.get(0).attachedToProcess()) {
                    ActivityRecord topRecord = list.get(0);
                    return new ActivityTokens(topRecord.token, topRecord.assistToken,
                            topRecord.app.getThread(), topRecord.shareableActivityToken);
                }
                // find the expected Activity
                for (int i = 0; i < list.size(); i++) {
                    ActivityRecord record = list.get(i);
                    if (record.shareableActivityToken == token && record.attachedToProcess()) {
                        return new ActivityTokens(record.token, record.assistToken,
                                record.app.getThread(), record.shareableActivityToken);
                    }
                }
                return null;
            }
            }
        }
        }


+14 −11
Original line number Original line Diff line number Diff line
@@ -232,23 +232,26 @@ final class TranslationManagerServiceImpl extends
    public void updateUiTranslationStateLocked(@UiTranslationState int state,
    public void updateUiTranslationStateLocked(@UiTranslationState int state,
            TranslationSpec sourceSpec, TranslationSpec targetSpec, List<AutofillId> viewIds,
            TranslationSpec sourceSpec, TranslationSpec targetSpec, List<AutofillId> viewIds,
            IBinder token, int taskId, UiTranslationSpec uiTranslationSpec) {
            IBinder token, int taskId, UiTranslationSpec uiTranslationSpec) {
        // Get top activity for a given task id
        // If the app starts a new Activity in the same task then the finish or pause API
        final ActivityTokens taskTopActivityTokens =
        // is called, the operation doesn't work if we only check task top Activity. The top
                mActivityTaskManagerInternal.getTopActivityForTask(taskId);
        // Activity is the new Activity, the original Activity is paused in the same task.
        if (taskTopActivityTokens == null
        // To make sure the operation still work, we use the token to find the target Activity in
                || taskTopActivityTokens.getShareableActivityToken() != token) {
        // this task, not the top Activity only.
            Slog.w(TAG, "Unknown activity or it was finished to query for update translation "
        ActivityTokens candidateActivityTokens =
                    + "state for token=" + token + " taskId=" + taskId + " for state= " + state);
                mActivityTaskManagerInternal.getAttachedNonFinishingActivityForTask(taskId, token);
        if (candidateActivityTokens == null) {
            Slog.w(TAG, "Unknown activity or it was finished to query for update "
                    + "translation state for token=" + token + " taskId=" + taskId + " for "
                    + "state= " + state);
            return;
            return;
        }
        }
        mLastActivityTokens = new WeakReference<>(taskTopActivityTokens);
        mLastActivityTokens = new WeakReference<>(candidateActivityTokens);
        if (state == STATE_UI_TRANSLATION_FINISHED) {
        if (state == STATE_UI_TRANSLATION_FINISHED) {
            mWaitingFinishedCallbackActivities.add(token);
            mWaitingFinishedCallbackActivities.add(token);
        }
        }

        IBinder activityToken = candidateActivityTokens.getActivityToken();
        IBinder activityToken = taskTopActivityTokens.getActivityToken();
        try {
        try {
            taskTopActivityTokens.getApplicationThread().updateUiTranslationState(
            candidateActivityTokens.getApplicationThread().updateUiTranslationState(
                    activityToken, state, sourceSpec, targetSpec,
                    activityToken, state, sourceSpec, targetSpec,
                    viewIds, uiTranslationSpec);
                    viewIds, uiTranslationSpec);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
+4 −4
Original line number Original line Diff line number Diff line
@@ -311,8 +311,8 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
            callback.sendResult(null);
            callback.sendResult(null);
            return;
            return;
        }
        }
        final ActivityTokens tokens = LocalServices.getService(
        final ActivityTokens tokens = LocalServices.getService(ActivityTaskManagerInternal.class)
                ActivityTaskManagerInternal.class).getTopActivityForTask(taskId);
                .getAttachedNonFinishingActivityForTask(taskId, null);
        if (tokens == null || tokens.getAssistToken() != assistToken) {
        if (tokens == null || tokens.getAssistToken() != assistToken) {
            Slog.w(TAG, "Unknown activity to query for direct actions");
            Slog.w(TAG, "Unknown activity to query for direct actions");
            callback.sendResult(null);
            callback.sendResult(null);
@@ -336,8 +336,8 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
            resultCallback.sendResult(null);
            resultCallback.sendResult(null);
            return;
            return;
        }
        }
        final ActivityTokens tokens = LocalServices.getService(
        final ActivityTokens tokens = LocalServices.getService(ActivityTaskManagerInternal.class)
                ActivityTaskManagerInternal.class).getTopActivityForTask(taskId);
                .getAttachedNonFinishingActivityForTask(taskId, null);
        if (tokens == null || tokens.getAssistToken() != assistToken) {
        if (tokens == null || tokens.getAssistToken() != assistToken) {
            Slog.w(TAG, "Unknown activity to perform a direct action");
            Slog.w(TAG, "Unknown activity to perform a direct action");
            resultCallback.sendResult(null);
            resultCallback.sendResult(null);