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

Commit 446251dc authored by Mark Renouf's avatar Mark Renouf
Browse files

Adds OnBackPressedOnTaskRoot

This allows Bubbles to be collapsed instead of finished
when there is only one activity in the stack.

Bug: 126852149
Test: launch activity, press back
Change-Id: Iad8db0549853e3f385d54fc6b6cea5e502d37139
parent e74b7d23
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ java_defaults {
        "core/java/android/app/IInstrumentationWatcher.aidl",
        "core/java/android/app/INotificationManager.aidl",
        "core/java/android/app/IProcessObserver.aidl",
        "core/java/android/app/IRequestFinishCallback.aidl",
        "core/java/android/app/ISearchManager.aidl",
        "core/java/android/app/ISearchManagerCallback.aidl",
        "core/java/android/app/IServiceConnection.aidl",
+19 −1
Original line number Diff line number Diff line
@@ -3666,7 +3666,25 @@ public class Activity extends ContextThemeWrapper

        FragmentManager fragmentManager = mFragments.getFragmentManager();

        if (fragmentManager.isStateSaved() || !fragmentManager.popBackStackImmediate()) {
        if (!fragmentManager.isStateSaved() && fragmentManager.popBackStackImmediate()) {
            return;
        }
        if (!isTaskRoot()) {
            // If the activity is not the root of the task, allow finish to proceed normally.
            finishAfterTransition();
            return;
        }
        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 IRequestFinishCallback.Stub() {
                        public void requestFinish() {
                            finishAfterTransition();
                        }
                    });
        } catch (RemoteException e) {
            finishAfterTransition();
        }
    }
+9 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ 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;
@@ -484,4 +485,12 @@ interface IActivityTaskManager {
     * @param activityToken The token of the target activity to restart.
     */
    void restartActivityProcessIfVisible(in IBinder activityToken);

    /**
     * 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.
     */
    void onBackPressedOnTaskRoot(in IBinder activityToken, in IRequestFinishCallback callback);
}
+27 −0
Original line number Diff line number Diff line
/*
 * 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();
}
+8 −0
Original line number Diff line number Diff line
@@ -161,4 +161,12 @@ oneway interface ITaskStackListener {
     * @see com.android.server.wm.AppWindowToken#inSizeCompatMode
     */
    void onSizeCompatModeActivityChanged(int displayId, in IBinder activityToken);

    /**
     * Reports that an Activity received a back key press when there were no additional activities
     * on the back stack.
     *
     * @param taskInfo info about the task which received the back press
     */
    void onBackPressedOnTaskRoot(in ActivityManager.RunningTaskInfo taskInfo);
}
Loading