Move task to back when the back button is pressed on root task
This CL changes the behavior of pressing the back button on a root activity so that the task is moved to the back, instead of the activity being finished. This removes the IRequestFinishCallback which IActivityTaskManager would previously have triggered to make the Activity finish itself. Bug: 146418616 Test: atest WmTests Test: manual: flash crosshatch, press back button on a root activity, observe task is moved to back. Change-Id: I48ec35f841ab3b306fe80845150000c390908f5e
This commit is contained in:
@@ -417,9 +417,6 @@ android.app.INotificationManager
|
||||
android.app.IProcessObserver$Stub$Proxy
|
||||
android.app.IProcessObserver$Stub
|
||||
android.app.IProcessObserver
|
||||
android.app.IRequestFinishCallback$Stub$Proxy
|
||||
android.app.IRequestFinishCallback$Stub
|
||||
android.app.IRequestFinishCallback
|
||||
android.app.ISearchManager$Stub$Proxy
|
||||
android.app.ISearchManager$Stub
|
||||
android.app.ISearchManager
|
||||
|
||||
@@ -150,7 +150,6 @@ import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -3798,22 +3797,6 @@ public class Activity extends ContextThemeWrapper
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final class RequestFinishCallback extends IRequestFinishCallback.Stub {
|
||||
private final WeakReference<Activity> mActivityRef;
|
||||
|
||||
RequestFinishCallback(WeakReference<Activity> activityRef) {
|
||||
mActivityRef = activityRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFinish() {
|
||||
Activity activity = mActivityRef.get();
|
||||
if (activity != null) {
|
||||
activity.mHandler.post(activity::finishAfterTransition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity has detected the user's press of the back
|
||||
* key. The default implementation simply finishes the current activity,
|
||||
@@ -3837,9 +3820,8 @@ public class Activity extends ContextThemeWrapper
|
||||
try {
|
||||
// Inform activity task manager that the activity received a back press
|
||||
// while at the root of the task. This call allows ActivityTaskManager
|
||||
// to intercept or defer finishing.
|
||||
ActivityTaskManager.getService().onBackPressedOnTaskRoot(mToken,
|
||||
new RequestFinishCallback(new WeakReference<>(this)));
|
||||
// to intercept or move the task to the back.
|
||||
ActivityTaskManager.getService().onBackPressedOnTaskRoot(mToken);
|
||||
} catch (RemoteException e) {
|
||||
finishAfterTransition();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.app.IAppTask;
|
||||
import android.app.IAssistDataReceiver;
|
||||
import android.app.IInstrumentationWatcher;
|
||||
import android.app.IProcessObserver;
|
||||
import android.app.IRequestFinishCallback;
|
||||
import android.app.IServiceConnection;
|
||||
import android.app.IStopUserCallback;
|
||||
import android.app.ITaskStackListener;
|
||||
@@ -458,9 +457,7 @@ interface IActivityTaskManager {
|
||||
|
||||
/**
|
||||
* Reports that an Activity received a back key press when there were no additional activities
|
||||
* on the back stack. If the Activity should be finished, the callback will be invoked. A
|
||||
* callback is used instead of finishing the activity directly from the server such that the
|
||||
* client may perform actions prior to finishing.
|
||||
* on the back stack.
|
||||
*/
|
||||
void onBackPressedOnTaskRoot(in IBinder activityToken, in IRequestFinishCallback callback);
|
||||
void onBackPressedOnTaskRoot(in IBinder activityToken);
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.app;
|
||||
|
||||
/**
|
||||
* This callback allows ActivityTaskManager to ask the calling Activity
|
||||
* to finish in response to a call to onBackPressedOnTaskRoot.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
oneway interface IRequestFinishCallback {
|
||||
void requestFinish();
|
||||
}
|
||||
@@ -145,7 +145,6 @@ import android.app.IActivityTaskManager;
|
||||
import android.app.IApplicationThread;
|
||||
import android.app.IAssistDataReceiver;
|
||||
import android.app.INotificationManager;
|
||||
import android.app.IRequestFinishCallback;
|
||||
import android.app.ITaskStackListener;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
@@ -2464,7 +2463,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) {
|
||||
public void onBackPressedOnTaskRoot(IBinder token) {
|
||||
synchronized (mGlobalLock) {
|
||||
ActivityRecord r = ActivityRecord.isInStackLocked(token);
|
||||
if (r == null) {
|
||||
@@ -2478,18 +2477,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
// callback
|
||||
} else if (stack != null && (stack.isSingleTaskInstance())) {
|
||||
// Single-task stacks are used for activities which are presented in floating
|
||||
// windows above full screen activities. Instead of directly finishing the
|
||||
// task, a task change listener is used to notify SystemUI so the action can be
|
||||
// handled specially.
|
||||
// windows above full screen activities. A task change listener is used to notify
|
||||
// SystemUI so the back action can be handled specially.
|
||||
final Task task = r.getTask();
|
||||
mTaskChangeNotificationController
|
||||
.notifyBackPressedOnTaskRoot(task.getTaskInfo());
|
||||
} else {
|
||||
try {
|
||||
callback.requestFinish();
|
||||
} catch (RemoteException e) {
|
||||
Slog.e(TAG, "Failed to invoke request finish callback", e);
|
||||
}
|
||||
moveActivityTaskToBack(token, false /* nonRoot */);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningTaskInfo;
|
||||
import android.app.ActivityManager.StackInfo;
|
||||
import android.app.IRequestFinishCallback;
|
||||
import android.app.PictureInPictureParams;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
@@ -976,8 +975,7 @@ public class WindowOrganizerTests extends WindowTestsBase {
|
||||
assertTrue(stack.isOrganized());
|
||||
|
||||
// Verify a back pressed does not call the organizer
|
||||
mWm.mAtmService.onBackPressedOnTaskRoot(activity.token,
|
||||
new IRequestFinishCallback.Default());
|
||||
mWm.mAtmService.onBackPressedOnTaskRoot(activity.token);
|
||||
verify(organizer, never()).onBackPressedOnTaskRoot(any());
|
||||
|
||||
// Enable intercepting back
|
||||
@@ -985,8 +983,7 @@ public class WindowOrganizerTests extends WindowTestsBase {
|
||||
true);
|
||||
|
||||
// Verify now that the back press does call the organizer
|
||||
mWm.mAtmService.onBackPressedOnTaskRoot(activity.token,
|
||||
new IRequestFinishCallback.Default());
|
||||
mWm.mAtmService.onBackPressedOnTaskRoot(activity.token);
|
||||
verify(organizer, times(1)).onBackPressedOnTaskRoot(any());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user