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

Commit ceecec67 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add taskbar TAPL tests" into tm-dev am: 6b7e4690

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/17016894

Change-Id: I4b21cb49523448eacc8991c7089df99a62fb6264
parents b1f884b2 6b7e4690
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -208,6 +208,8 @@ filegroup {
    srcs: [
        "ext_tests/src/**/*.java",
        "ext_tests/src/**/*.kt",
        "quickstep/ext_tests/src/**/*.java",
        "quickstep/ext_tests/src/**/*.kt",
    ],
}

+39 −0
Original line number Diff line number Diff line
@@ -29,8 +29,10 @@ import android.view.View;
import androidx.annotation.Keep;
import androidx.annotation.Nullable;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutAndWidgetContainer;

import java.util.ArrayList;
import java.util.Collection;
@@ -205,6 +207,32 @@ public class DebugTestInformationHandler extends TestInformationHandler {
                }
            }

            case TestProtocol.REQUEST_USE_TEST_WORKSPACE_LAYOUT: {
                useTestWorkspaceLayout(true);
                return response;
            }

            case TestProtocol.REQUEST_USE_DEFAULT_WORKSPACE_LAYOUT: {
                useTestWorkspaceLayout(false);
                return response;
            }

            case TestProtocol.REQUEST_HOTSEAT_ICON_NAMES: {
                return getLauncherUIProperty(Bundle::putStringArrayList, l -> {
                    ShortcutAndWidgetContainer hotseatIconsContainer =
                            l.getHotseat().getShortcutsAndWidgets();
                    ArrayList<String> hotseatIconNames = new ArrayList<>();

                    for (int i = 0; i < hotseatIconsContainer.getChildCount(); i++) {
                        // Use unchecked cast to catch changes in hotseat layout
                        BubbleTextView icon = (BubbleTextView) hotseatIconsContainer.getChildAt(i);
                        hotseatIconNames.add((String) icon.getText());
                    }

                    return hotseatIconNames;
                });
            }

            case TestProtocol.REQUEST_GET_ACTIVITIES_CREATED_COUNT: {
                response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, sActivitiesCreatedCount);
                return response;
@@ -223,4 +251,15 @@ public class DebugTestInformationHandler extends TestInformationHandler {
                return super.call(method, arg, extras);
        }
    }

    private void useTestWorkspaceLayout(boolean useTestWorkspaceLayout) {
        final long identity = Binder.clearCallingIdentity();
        try {
            LauncherSettings.Settings.call(mContext.getContentResolver(), useTestWorkspaceLayout
                    ? LauncherSettings.Settings.METHOD_SET_USE_TEST_WORKSPACE_LAYOUT_FLAG
                    : LauncherSettings.Settings.METHOD_CLEAR_USE_TEST_WORKSPACE_LAYOUT_FLAG);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }
}
+120 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 com.android.quickstep;

import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;

import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.android.launcher3.BaseQuickstepLauncher;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.taskbar.LauncherTaskbarUIController;
import com.android.launcher3.testing.DebugTestInformationHandler;
import com.android.launcher3.testing.TestProtocol;

import java.util.concurrent.ExecutionException;

/**
 * Class to handle requests from tests, including debug ones, to Quickstep Launcher builds.
 */
public abstract class DebugQuickstepTestInformationHandler extends QuickstepTestInformationHandler {

    private final DebugTestInformationHandler mDebugTestInformationHandler;

    public DebugQuickstepTestInformationHandler(Context context) {
        super(context);
        mDebugTestInformationHandler = new DebugTestInformationHandler(context);
    }

    @Override
    public Bundle call(String method, String arg, @Nullable Bundle extras) {
        Bundle response = new Bundle();
        switch (method) {
            case TestProtocol.REQUEST_ENABLE_MANUAL_TASKBAR_STASHING:
                runOnUIThread(l -> {
                    enableManualTaskbarStashing(l, true);
                });
                return response;

            case TestProtocol.REQUEST_DISABLE_MANUAL_TASKBAR_STASHING:
                runOnUIThread(l -> {
                    enableManualTaskbarStashing(l, false);
                });
                return response;

            case TestProtocol.REQUEST_UNSTASH_TASKBAR_IF_STASHED:
                runOnUIThread(l -> {
                    enableManualTaskbarStashing(l, true);

                    BaseQuickstepLauncher quickstepLauncher = (BaseQuickstepLauncher) l;
                    LauncherTaskbarUIController taskbarUIController =
                            quickstepLauncher.getTaskbarUIController();

                    // Allow null-pointer to catch illegal states.
                    taskbarUIController.unstashTaskbarIfStashed();

                    enableManualTaskbarStashing(l, false);
                });
                return response;

            case TestProtocol.REQUEST_STASHED_TASKBAR_HEIGHT: {
                final Resources resources = mContext.getResources();
                response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD,
                        resources.getDimensionPixelSize(R.dimen.taskbar_stashed_size));
                return response;
            }

            default:
                response = super.call(method, arg, extras);
                if (response != null) return response;
                return mDebugTestInformationHandler.call(method, arg, extras);
        }
    }

    private void enableManualTaskbarStashing(Launcher launcher, boolean enable) {
        BaseQuickstepLauncher quickstepLauncher = (BaseQuickstepLauncher) launcher;
        LauncherTaskbarUIController taskbarUIController =
                quickstepLauncher.getTaskbarUIController();

        // Allow null-pointer to catch illegal states.
        taskbarUIController.enableManualStashingForTests(enable);
    }

    /**
     * Runs the given command on the UI thread.
     */
    private static void runOnUIThread(UIThreadCommand command) {
        try {
            MAIN_EXECUTOR.submit(() -> {
                command.execute(Launcher.ACTIVITY_TRACKER.getCreatedActivity());
                return null;
            }).get();
        } catch (ExecutionException | InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    private interface UIThreadCommand {

        void execute(Launcher launcher);
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.TaskTransitionSpec;
import android.view.WindowManagerGlobal;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.android.launcher3.BaseQuickstepLauncher;
import com.android.launcher3.DeviceProfile;
@@ -117,6 +118,24 @@ public class LauncherTaskbarUIController extends TaskbarUIController {
                shouldDelayLauncherStateAnim);
    }

    /**
     * Enables manual taskbar stashing. This method should only be used for tests that need to
     * stash/unstash the taskbar.
     */
    @VisibleForTesting
    public void enableManualStashingForTests(boolean enableManualStashing) {
        mControllers.taskbarStashController.enableManualStashingForTests(enableManualStashing);
    }

    /**
     * Unstashes the Taskbar if it is stashed. This method should only be used to unstash the
     * taskbar at the end of a test.
     */
    @VisibleForTesting
    public void unstashTaskbarIfStashed() {
        mControllers.taskbarStashController.onLongPressToUnstashTaskbar();
    }

    /**
     * Should be called from onResume() and onPause(), and animates the Taskbar accordingly.
     */
+7 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.taskbar.allapps.TaskbarAllAppsController;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.NavigationMode;
@@ -646,12 +648,16 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
                        Toast.makeText(this, R.string.safemode_shortcut_error,
                                Toast.LENGTH_SHORT).show();
                    } else  if (info.isPromise()) {
                        TestLogging.recordEvent(
                                TestProtocol.SEQUENCE_MAIN, "start: taskbarPromiseIcon");
                        intent = new PackageManagerHelper(this)
                                .getMarketIntent(info.getTargetPackage())
                                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                    } else if (info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                        TestLogging.recordEvent(
                                TestProtocol.SEQUENCE_MAIN, "start: taskbarDeepShortcut");
                        String id = info.getDeepShortcutId();
                        String packageName = intent.getPackage();
                        getSystemService(LauncherApps.class)
@@ -680,6 +686,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
        Intent intent = new Intent(info.getIntent())
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "start: taskbarAppIcon");
            if (info.user.equals(Process.myUserHandle())) {
                // TODO(b/216683257): Use startActivityForResult for search results that require it.
                startActivity(intent);
Loading