Merge "Import translations. DO NOT MERGE" into ub-launcher3-master
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
index e8d4c19..15072a2 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -851,16 +851,6 @@
Interpolator interpolator, GestureEndTarget target, PointF velocityPxPerMs) {
mGestureEndTarget = target;
- if (mGestureEndTarget.canBeContinued) {
- // Because we might continue this gesture, e.g. for consecutive quick switch, we need to
- // stabilize the task list so that tasks don't rearrange in the middle of the gesture.
- RecentsModel.INSTANCE.get(mContext).startStabilizationSession();
- } else if (mGestureEndTarget.isLauncher) {
- // Otherwise, if we're going to home or overview,
- // we reset the tasks to a consistent start state.
- RecentsModel.INSTANCE.get(mContext).endStabilizationSession();
- }
-
if (mGestureEndTarget == HOME) {
HomeAnimationFactory homeAnimFactory;
if (mActivity != null) {
@@ -1003,10 +993,12 @@
// Launch the task user scrolled to (mRecentsView.getNextPage()).
if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
// We finish recents animation inside launchTask() when live tile is enabled.
- mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(false);
+ mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(false /* animate */,
+ true /* freezeTaskList */);
} else {
mRecentsAnimationWrapper.finish(true /* toRecents */, () -> {
- mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(false);
+ mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(
+ false /* animate */, true /* freezeTaskList */);
});
}
TOUCH_INTERACTION_LOG.addLog("finishRecentsAnimation", false);
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
index eb17e3e..6ba89c9 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
@@ -250,7 +250,11 @@
}
public void launchTask(boolean animate) {
- launchTask(animate, (result) -> {
+ launchTask(animate, false /* freezeTaskList */);
+ }
+
+ public void launchTask(boolean animate, boolean freezeTaskList) {
+ launchTask(animate, freezeTaskList, (result) -> {
if (!result) {
notifyTaskLaunchFailed(TAG);
}
@@ -259,25 +263,33 @@
public void launchTask(boolean animate, Consumer<Boolean> resultCallback,
Handler resultCallbackHandler) {
+ launchTask(animate, false /* freezeTaskList */, resultCallback, resultCallbackHandler);
+ }
+
+ public void launchTask(boolean animate, boolean freezeTaskList, Consumer<Boolean> resultCallback,
+ Handler resultCallbackHandler) {
if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
if (isRunningTask()) {
getRecentsView().finishRecentsAnimation(false /* toRecents */,
() -> resultCallbackHandler.post(() -> resultCallback.accept(true)));
} else {
- launchTaskInternal(animate, resultCallback, resultCallbackHandler);
+ launchTaskInternal(animate, freezeTaskList, resultCallback, resultCallbackHandler);
}
} else {
- launchTaskInternal(animate, resultCallback, resultCallbackHandler);
+ launchTaskInternal(animate, freezeTaskList, resultCallback, resultCallbackHandler);
}
}
- private void launchTaskInternal(boolean animate, Consumer<Boolean> resultCallback,
- Handler resultCallbackHandler) {
+ private void launchTaskInternal(boolean animate, boolean freezeTaskList,
+ Consumer<Boolean> resultCallback, Handler resultCallbackHandler) {
if (mTask != null) {
final ActivityOptions opts;
if (animate) {
opts = ((BaseDraggingActivity) fromContext(getContext()))
.getActivityLaunchOptions(this);
+ if (freezeTaskList) {
+ ActivityOptionsCompat.setFreezeRecentTasksList(opts);
+ }
ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(mTask.key,
opts, resultCallback, resultCallbackHandler);
} else {
@@ -288,6 +300,9 @@
resultCallbackHandler.post(() -> resultCallback.accept(true));
}
}, resultCallbackHandler);
+ if (freezeTaskList) {
+ ActivityOptionsCompat.setFreezeRecentTasksList(opts);
+ }
ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(mTask.key,
opts, (success) -> {
if (resultCallback != null && !success) {
diff --git a/quickstep/src/com/android/quickstep/NavBarModeOverlayResourceObserver.java b/quickstep/src/com/android/quickstep/NavBarModeOverlayResourceObserver.java
new file mode 100644
index 0000000..3136632
--- /dev/null
+++ b/quickstep/src/com/android/quickstep/NavBarModeOverlayResourceObserver.java
@@ -0,0 +1,89 @@
+/*
+ * 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 com.android.quickstep;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.Resources;
+import android.util.Log;
+
+import com.android.systemui.shared.system.QuickStepContract;
+
+/**
+ * Observer for the resource config that specifies the navigation bar mode.
+ */
+public class NavBarModeOverlayResourceObserver extends BroadcastReceiver {
+
+ private static final String TAG = "NavBarModeOverlayResourceObserver";
+
+ private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED";
+ private static final String NAV_BAR_INTERACTION_MODE_RES_NAME =
+ "config_navBarInteractionMode";
+
+ private final Context mContext;
+ private final OnChangeListener mOnChangeListener;
+
+ public NavBarModeOverlayResourceObserver(Context context, OnChangeListener listener) {
+ mContext = context;
+ mOnChangeListener = listener;
+ }
+
+ public void register() {
+ IntentFilter filter = new IntentFilter(ACTION_OVERLAY_CHANGED);
+ filter.addDataScheme("package");
+ mContext.registerReceiver(this, filter);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ mOnChangeListener.onNavBarModeChanged(getSystemIntegerRes(context,
+ NAV_BAR_INTERACTION_MODE_RES_NAME));
+ }
+
+ public interface OnChangeListener {
+ void onNavBarModeChanged(int mode);
+ }
+
+ public static boolean isSwipeUpModeEnabled(Context context) {
+ return QuickStepContract.isSwipeUpMode(getSystemIntegerRes(context,
+ NAV_BAR_INTERACTION_MODE_RES_NAME));
+ }
+
+ public static boolean isEdgeToEdgeModeEnabled(Context context) {
+ return QuickStepContract.isGesturalMode(getSystemIntegerRes(context,
+ NAV_BAR_INTERACTION_MODE_RES_NAME));
+ }
+
+ public static boolean isLegacyModeEnabled(Context context) {
+ return QuickStepContract.isLegacyMode(getSystemIntegerRes(context,
+ NAV_BAR_INTERACTION_MODE_RES_NAME));
+ }
+
+ private static int getSystemIntegerRes(Context context, String resName) {
+ Resources res = context.getResources();
+ int resId = res.getIdentifier(resName, "integer", "android");
+
+ if (resId != 0) {
+ return res.getInteger(resId);
+ } else {
+ Log.e(TAG, "Failed to get system resource ID. Incompatible framework version?");
+ return -1;
+ }
+ }
+}
\ No newline at end of file
diff --git a/quickstep/src/com/android/quickstep/OverviewInteractionState.java b/quickstep/src/com/android/quickstep/OverviewInteractionState.java
index a0ab301..903701d 100644
--- a/quickstep/src/com/android/quickstep/OverviewInteractionState.java
+++ b/quickstep/src/com/android/quickstep/OverviewInteractionState.java
@@ -15,7 +15,6 @@
*/
package com.android.quickstep;
-import static com.android.quickstep.SwipeUpSetting.newSwipeUpSettingsObserver;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_QUICK_SCRUB;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_SWIPE_UP;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON;
@@ -28,10 +27,11 @@
import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.DiscoveryBounce;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.MainThreadInitializedObject;
-import com.android.launcher3.util.SecureSettingsObserver;
import com.android.launcher3.util.UiThreadHelper;
import com.android.systemui.shared.recents.ISystemUiProxy;
+import com.android.systemui.shared.system.QuickStepContract;
import androidx.annotation.WorkerThread;
@@ -58,7 +58,8 @@
private static final int MSG_SET_BACK_BUTTON_ALPHA = 201;
private static final int MSG_SET_SWIPE_UP_ENABLED = 202;
- private final SecureSettingsObserver mSwipeUpSettingObserver;
+ // TODO: Discriminate between swipe up and edge to edge
+ private final NavBarModeOverlayResourceObserver mSwipeUpSettingObserver;
private final Context mContext;
private final Handler mUiHandler;
@@ -66,7 +67,7 @@
// These are updated on the background thread
private ISystemUiProxy mISystemUiProxy;
- private boolean mSwipeUpEnabled = true;
+ private boolean mSwipeUpEnabled;
private float mBackButtonAlpha = 1;
private Runnable mOnSwipeUpSettingChangedListener;
@@ -80,15 +81,15 @@
mUiHandler = new Handler(this::handleUiMessage);
mBgHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleBgMessage);
- if (SwipeUpSetting.isSwipeUpSettingAvailable()) {
- mSwipeUpSettingObserver =
- newSwipeUpSettingsObserver(context, this::notifySwipeUpSettingChanged);
+ mSwipeUpEnabled = NavBarModeOverlayResourceObserver.isSwipeUpModeEnabled(mContext)
+ || NavBarModeOverlayResourceObserver.isEdgeToEdgeModeEnabled(mContext);
+ if (SwipeUpSetting.isSystemNavigationSettingAvailable()) {
+ mSwipeUpSettingObserver = new NavBarModeOverlayResourceObserver(context,
+ this::notifySwipeUpSettingChanged);
mSwipeUpSettingObserver.register();
- mSwipeUpEnabled = mSwipeUpSettingObserver.getValue();
resetHomeBounceSeenOnQuickstepEnabledFirstTime();
} else {
mSwipeUpSettingObserver = null;
- mSwipeUpEnabled = SwipeUpSetting.isSwipeUpEnabledDefaultValue();
}
}
@@ -175,7 +176,13 @@
}
}
- private void notifySwipeUpSettingChanged(boolean swipeUpEnabled) {
+ private void notifySwipeUpSettingChanged(int mode) {
+ boolean swipeUpEnabled = !QuickStepContract.isLegacyMode(mode);
+ boolean gesturalEnabled = QuickStepContract.isGesturalMode(mode);
+
+ FeatureFlags.SWIPE_HOME.updateStorage(mContext, gesturalEnabled);
+ FeatureFlags.ENABLE_ASSISTANT_GESTURE.updateStorage(mContext, gesturalEnabled);
+
mUiHandler.removeMessages(MSG_SET_SWIPE_UP_ENABLED);
mUiHandler.obtainMessage(MSG_SET_SWIPE_UP_ENABLED, swipeUpEnabled ? 1 : 0, 0).
sendToTarget();
diff --git a/quickstep/src/com/android/quickstep/RecentTasksList.java b/quickstep/src/com/android/quickstep/RecentTasksList.java
index e15a3f1..06a36c9 100644
--- a/quickstep/src/com/android/quickstep/RecentTasksList.java
+++ b/quickstep/src/com/android/quickstep/RecentTasksList.java
@@ -44,7 +44,6 @@
private final KeyguardManagerCompat mKeyguardManager;
private final MainThreadExecutor mMainThreadExecutor;
private final BackgroundExecutor mBgThreadExecutor;
- private final TaskListStabilizer mStabilizer = new TaskListStabilizer();
// The list change id, increments as the task list changes in the system
private int mChangeId;
@@ -74,14 +73,6 @@
});
}
- public void startStabilizationSession() {
- mStabilizer.startStabilizationSession();
- }
-
- public void endStabilizationSession() {
- mStabilizer.endStabilizationSession();
- }
-
/**
* Asynchronously fetches the list of recent tasks, reusing cached list if available.
*
@@ -93,7 +84,7 @@
final int requestLoadId = mChangeId;
Runnable resultCallback = callback == null
? () -> { }
- : () -> callback.accept(mStabilizer.reorder(mTasks));
+ : () -> callback.accept(mTasks);
if (mLastLoadedId == mChangeId && (!mLastLoadHadKeysOnly || loadKeysOnly)) {
// The list is up to date, callback with the same list
diff --git a/quickstep/src/com/android/quickstep/RecentsModel.java b/quickstep/src/com/android/quickstep/RecentsModel.java
index 56bc8570..a65bc33 100644
--- a/quickstep/src/com/android/quickstep/RecentsModel.java
+++ b/quickstep/src/com/android/quickstep/RecentsModel.java
@@ -90,14 +90,6 @@
return mThumbnailCache;
}
- public void startStabilizationSession() {
- mTaskList.startStabilizationSession();
- }
-
- public void endStabilizationSession() {
- mTaskList.endStabilizationSession();
- }
-
/**
* Fetches the list of recent tasks.
*
diff --git a/quickstep/src/com/android/quickstep/SwipeUpSetting.java b/quickstep/src/com/android/quickstep/SwipeUpSetting.java
index 381ab9f..7f830f9 100644
--- a/quickstep/src/com/android/quickstep/SwipeUpSetting.java
+++ b/quickstep/src/com/android/quickstep/SwipeUpSetting.java
@@ -16,23 +16,18 @@
package com.android.quickstep;
-import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
-
-import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
-import com.android.launcher3.util.SecureSettingsObserver;
-import com.android.launcher3.util.SecureSettingsObserver.OnChangeListener;
-
public final class SwipeUpSetting {
private static final String TAG = "SwipeUpSetting";
private static final String SWIPE_UP_SETTING_AVAILABLE_RES_NAME =
"config_swipe_up_gesture_setting_available";
- private static final String SWIPE_UP_ENABLED_DEFAULT_RES_NAME =
- "config_swipe_up_gesture_default";
+ public static boolean isSystemNavigationSettingAvailable() {
+ return getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME);
+ }
private static boolean getSystemBooleanRes(String resName) {
Resources res = Resources.getSystem();
@@ -45,18 +40,4 @@
return false;
}
}
-
- public static boolean isSwipeUpSettingAvailable() {
- return getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME);
- }
-
- public static boolean isSwipeUpEnabledDefaultValue() {
- return getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
- }
-
- public static SecureSettingsObserver newSwipeUpSettingsObserver(Context context,
- OnChangeListener listener) {
- return new SecureSettingsObserver(context.getContentResolver(), listener,
- SWIPE_UP_SETTING_NAME, isSwipeUpEnabledDefaultValue() ? 1 : 0);
- }
}
diff --git a/quickstep/src/com/android/quickstep/TaskListStabilizer.java b/quickstep/src/com/android/quickstep/TaskListStabilizer.java
deleted file mode 100644
index 4c63f81..0000000
--- a/quickstep/src/com/android/quickstep/TaskListStabilizer.java
+++ /dev/null
@@ -1,145 +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 com.android.quickstep;
-
-import android.app.ActivityManager.RecentTaskInfo;
-import android.content.ComponentName;
-import android.os.Process;
-import android.os.SystemClock;
-
-import com.android.launcher3.util.IntArray;
-import com.android.systemui.shared.recents.model.Task;
-import com.android.systemui.shared.recents.model.Task.TaskKey;
-import com.android.systemui.shared.system.ActivityManagerWrapper;
-import com.android.systemui.shared.system.TaskStackChangeListener;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Keeps the task list stable during quick switch gestures. So if you swipe right to switch from app
- * A to B, you can then swipe right again to get to app C or left to get back to A.
- */
-public class TaskListStabilizer {
-
- private static final long TASK_CACHE_TIMEOUT_MS = 5000;
-
- private final TaskStackChangeListener mTaskStackListener = new TaskStackChangeListener() {
-
- @Override
- public void onTaskCreated(int taskId, ComponentName componentName) {
- endStabilizationSession();
- }
-
- @Override
- public void onTaskRemoved(int taskId) {
- endStabilizationSession();
- }
- };
-
- // Task ids ordered based on recency, 0th index is the least recent task
- private final IntArray mSystemOrder;
- private final IntArray mStabilizedOrder;
-
- // Wrapper objects used for sorting tasks
- private final ArrayList<TaskWrapper> mTaskWrappers = new ArrayList<>();
-
- private boolean mInStabilizationSession;
- private long mSessionStartTime;
-
- public TaskListStabilizer() {
- // Initialize the task ids map
- List<RecentTaskInfo> rawTasks = ActivityManagerWrapper.getInstance().getRecentTasks(
- Integer.MAX_VALUE, Process.myUserHandle().getIdentifier());
- mSystemOrder = new IntArray(rawTasks.size());
- for (RecentTaskInfo info : rawTasks) {
- mSystemOrder.add(new TaskKey(info).id);
- }
- // We will lazily copy the task id's from mSystemOrder when a stabilization session starts.
- mStabilizedOrder = new IntArray(rawTasks.size());
-
- ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
- }
-
- public synchronized void startStabilizationSession() {
- if (!mInStabilizationSession) {
- mStabilizedOrder.clear();
- mStabilizedOrder.addAll(mSystemOrder);
- }
- mInStabilizationSession = true;
- mSessionStartTime = SystemClock.uptimeMillis();
- }
-
- public synchronized void endStabilizationSession() {
- mInStabilizationSession = false;
- }
-
- public synchronized ArrayList<Task> reorder(ArrayList<Task> tasks) {
- mSystemOrder.clear();
- for (Task task : tasks) {
- mSystemOrder.add(task.key.id);
- }
-
- if ((SystemClock.uptimeMillis() - mSessionStartTime) > TASK_CACHE_TIMEOUT_MS) {
- endStabilizationSession();
- }
-
- if (!mInStabilizationSession) {
- return tasks;
- }
-
- // Ensure that we have enough wrappers
- int taskCount = tasks.size();
- for (int i = taskCount - mTaskWrappers.size(); i > 0; i--) {
- mTaskWrappers.add(new TaskWrapper());
- }
-
- List<TaskWrapper> listToSort = mTaskWrappers.size() == taskCount
- ? mTaskWrappers : mTaskWrappers.subList(0, taskCount);
- int missingTaskIndex = -taskCount;
-
- for (int i = 0; i < taskCount; i++){
- TaskWrapper wrapper = listToSort.get(i);
- wrapper.task = tasks.get(i);
- wrapper.index = mStabilizedOrder.indexOf(wrapper.task.key.id);
-
- // Ensure that missing tasks are put in the front, in the order they appear in the
- // original list
- if (wrapper.index < 0) {
- wrapper.index = missingTaskIndex;
- missingTaskIndex++;
- }
- }
- Collections.sort(listToSort);
-
- ArrayList<Task> result = new ArrayList<>(taskCount);
- for (int i = 0; i < taskCount; i++) {
- result.add(listToSort.get(i).task);
- }
- return result;
- }
-
- private static class TaskWrapper implements Comparable<TaskWrapper> {
- Task task;
- int index;
-
- @Override
- public int compareTo(TaskWrapper other) {
- return Integer.compare(index, other.index);
- }
- }
-}
diff --git a/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java b/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java
index f89842a..12bd0ca 100644
--- a/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java
+++ b/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java
@@ -16,25 +16,29 @@
package com.android.quickstep;
+import static androidx.test.InstrumentationRegistry.getInstrumentation;
+
import static com.android.quickstep.QuickStepOnOffRule.Mode.BOTH;
import static com.android.quickstep.QuickStepOnOffRule.Mode.OFF;
import static com.android.quickstep.QuickStepOnOffRule.Mode.ON;
-import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
+import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_2BUTTON_OVERLAY;
+import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_3BUTTON_OVERLAY;
+import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_GESTURAL_OVERLAY;
-import static org.junit.Assert.assertTrue;
-
-import android.provider.Settings;
+import android.content.Context;
import android.util.Log;
-import androidx.test.InstrumentationRegistry;
+import androidx.test.uiautomator.UiDevice;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.TestHelpers;
+import com.android.systemui.shared.system.QuickStepContract;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
+import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -76,53 +80,59 @@
return new Statement() {
@Override
public void evaluate() throws Throwable {
- if (SwipeUpSetting.isSwipeUpSettingAvailable()) {
- try {
- if (mode == ON || mode == BOTH) {
- evaluateWithQuickstepOn();
- }
- if (mode == OFF || mode == BOTH) {
- evaluateWithQuickstepOff();
- }
- } finally {
- setSwipeUpSetting(null);
+ final Context context = getInstrumentation().getContext();
+ final String prevOverlayPkg = QuickStepContract.isGesturalMode(context)
+ ? NAV_BAR_MODE_GESTURAL_OVERLAY
+ : QuickStepContract.isSwipeUpMode(context)
+ ? NAV_BAR_MODE_2BUTTON_OVERLAY
+ : NAV_BAR_MODE_3BUTTON_OVERLAY;
+ try {
+ if (mode == ON || mode == BOTH) {
+ evaluateWithQuickstepOn();
}
- } else {
- // Execute without changing the setting, if the requested mode is
- // compatible.
- final boolean swipeUpEnabledDefaultValue =
- SwipeUpSetting.isSwipeUpEnabledDefaultValue();
- if (mode == BOTH ||
- mode == ON && swipeUpEnabledDefaultValue ||
- mode == OFF && !swipeUpEnabledDefaultValue) {
- evaluateWithoutChangingSetting(base);
+ if (mode == OFF || mode == BOTH) {
+ evaluateWithQuickstepOff();
}
+ } finally {
+ setActiveOverlay(prevOverlayPkg);
}
}
- public void setSwipeUpSetting(String value) {
- Log.d(TAG, "setSwipeUpSetting: " + value);
- assertTrue("Couldn't change Quickstep mode",
- Settings.Secure.putString(
- InstrumentationRegistry.getInstrumentation().getTargetContext().
- getContentResolver(),
- SWIPE_UP_SETTING_NAME,
- value));
- }
-
public void evaluateWithoutChangingSetting(Statement base) throws Throwable {
base.evaluate();
}
private void evaluateWithQuickstepOff() throws Throwable {
- setSwipeUpSetting("0");
+ setActiveOverlay(NAV_BAR_MODE_3BUTTON_OVERLAY);
evaluateWithoutChangingSetting(base);
}
private void evaluateWithQuickstepOn() throws Throwable {
- setSwipeUpSetting("1");
+ setActiveOverlay(NAV_BAR_MODE_2BUTTON_OVERLAY);
base.evaluate();
}
+
+ private void setActiveOverlay(String overlayPackage) {
+ setOverlayPackageEnabled(NAV_BAR_MODE_3BUTTON_OVERLAY,
+ overlayPackage == NAV_BAR_MODE_3BUTTON_OVERLAY);
+ setOverlayPackageEnabled(NAV_BAR_MODE_2BUTTON_OVERLAY,
+ overlayPackage == NAV_BAR_MODE_2BUTTON_OVERLAY);
+ setOverlayPackageEnabled(NAV_BAR_MODE_GESTURAL_OVERLAY,
+ overlayPackage == NAV_BAR_MODE_GESTURAL_OVERLAY);
+
+ // TODO: Wait until nav bar mode has applied
+ }
+
+ private void setOverlayPackageEnabled(String overlayPackage, boolean enable) {
+ Log.d(TAG, "setOverlayPackageEnabled: " + overlayPackage + " " + enable);
+ final String action = enable ? "enable" : "disable";
+ try {
+ UiDevice.getInstance(getInstrumentation()).executeShellCommand(
+ "cmd overlay " + action + " " + overlayPackage);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
};
} else {
return base;
diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml
index b2f3575..bc658e4 100644
--- a/res/values-land/dimens.xml
+++ b/res/values-land/dimens.xml
@@ -27,9 +27,6 @@
<!-- Dynamic grid -->
<dimen name="dynamic_grid_icon_drawable_padding">4dp</dimen>
- <dimen name="dynamic_grid_cell_layout_padding">0dp</dimen>
- <dimen name="dynamic_grid_cell_layout_bottom_padding">5.5dp</dimen>
-
<!-- Hotseat -->
<dimen name="dynamic_grid_hotseat_side_padding">16dp</dimen>
</resources>
diff --git a/res/values/config.xml b/res/values/config.xml
index 6bd01b5..4b68b50 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -70,6 +70,7 @@
<string name="instant_app_resolver_class" translatable="false"></string>
<string name="main_process_initializer_class" translatable="false"></string>
<string name="system_shortcut_factory_class" translatable="false"></string>
+ <string name="app_launch_tracker_class" translatable="false"></string>
<!-- Package name of the default wallpaper picker. -->
<string name="wallpaper_picker_package" translatable="false"></string>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 04e4591..7822e05 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -22,13 +22,10 @@
<dimen name="dynamic_grid_edge_margin">8dp</dimen>
<dimen name="dynamic_grid_page_indicator_line_height">1dp</dimen>
<dimen name="dynamic_grid_icon_drawable_padding">8dp</dimen>
- <dimen name="dynamic_grid_workspace_top_padding">8dp</dimen>
- <dimen name="dynamic_grid_workspace_page_spacing">8dp</dimen>
<!-- Minimum space between workspace and hotseat in spring loaded mode -->
<dimen name="dynamic_grid_min_spring_loaded_space">8dp</dimen>
<dimen name="dynamic_grid_cell_layout_padding">5.5dp</dimen>
- <dimen name="dynamic_grid_cell_layout_bottom_padding">0dp</dimen>
<dimen name="dynamic_grid_cell_padding_x">8dp</dimen>
<!-- Hotseat -->
diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java
index ff9dd13..18599ac 100644
--- a/src/com/android/launcher3/BaseDraggingActivity.java
+++ b/src/com/android/launcher3/BaseDraggingActivity.java
@@ -16,6 +16,8 @@
package com.android.launcher3;
+import static com.android.launcher3.model.AppLaunchTracker.CONTAINER_SEARCH;
+
import android.app.ActivityOptions;
import android.content.ActivityNotFoundException;
import android.content.Intent;
@@ -32,10 +34,13 @@
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.compat.LauncherAppsCompat;
+import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.uioverrides.DisplayRotationListener;
import com.android.launcher3.uioverrides.WallpaperColorInfo;
+import androidx.annotation.Nullable;
+
/**
* Extension of BaseActivity allowing support for drag-n-drop
*/
@@ -148,7 +153,8 @@
public abstract ActivityOptions getActivityLaunchOptions(View v);
- public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
+ public boolean startActivitySafely(View v, Intent intent, @Nullable ItemInfo item,
+ @Nullable String sourceContainer) {
if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
return false;
@@ -169,13 +175,17 @@
&& !((ShortcutInfo) item).isPromise();
if (isShortcut) {
// Shortcuts need some special checks due to legacy reasons.
- startShortcutIntentSafely(intent, optsBundle, item);
+ startShortcutIntentSafely(intent, optsBundle, item, sourceContainer);
} else if (user == null || user.equals(Process.myUserHandle())) {
// Could be launching some bookkeeping activity
startActivity(intent, optsBundle);
+ AppLaunchTracker.INSTANCE.get(this).onStartApp(intent.getComponent(),
+ Process.myUserHandle(), sourceContainer);
} else {
LauncherAppsCompat.getInstance(this).startActivityForProfile(
intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
+ AppLaunchTracker.INSTANCE.get(this).onStartApp(intent.getComponent(), user,
+ sourceContainer);
}
getUserEventDispatcher().logAppLaunch(v, intent);
getStatsLogManager().logAppLaunch(v, intent);
@@ -187,7 +197,8 @@
return false;
}
- private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) {
+ private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info,
+ @Nullable String sourceContainer) {
try {
StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
try {
@@ -202,6 +213,8 @@
String packageName = intent.getPackage();
DeepShortcutManager.getInstance(this).startShortcut(
packageName, id, intent.getSourceBounds(), optsBundle, info.user);
+ AppLaunchTracker.INSTANCE.get(this).onStartShortcut(packageName, id, info.user,
+ sourceContainer);
} else {
// Could be launching some bookkeeping activity
startActivity(intent, optsBundle);
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 7919d29..6397e14 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -16,8 +16,6 @@
package com.android.launcher3;
-import android.appwidget.AppWidgetHostView;
-import android.content.ComponentName;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -70,9 +68,6 @@
public final int cellLayoutPaddingLeftRightPx;
public final int cellLayoutBottomPaddingPx;
public final int edgeMarginPx;
- public final Rect defaultWidgetPadding;
- public final int defaultPageSpacingPx;
- private final int topWorkspacePadding;
public float workspaceSpringLoadShrinkFactor;
public final int workspaceSpringLoadedBottomSpace;
@@ -177,26 +172,25 @@
: Configuration.ORIENTATION_PORTRAIT);
res = context.getResources();
-
- ComponentName cn = new ComponentName(context.getPackageName(),
- this.getClass().getName());
- defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
+
int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
- cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier *
- res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
- cellLayoutBottomPaddingPx =
- res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_bottom_padding);
+ int cellLayoutPadding = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
+ if (isLandscape) {
+ cellLayoutPaddingLeftRightPx = 0;
+ cellLayoutBottomPaddingPx = cellLayoutPadding;
+ } else {
+ cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
+ cellLayoutBottomPaddingPx = 0;
+ }
+
verticalDragHandleSizePx = res.getDimensionPixelSize(
R.dimen.vertical_drag_handle_size);
verticalDragHandleOverlapWorkspace =
res.getDimensionPixelSize(R.dimen.vertical_drag_handle_overlap_workspace);
- defaultPageSpacingPx =
- res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
- topWorkspacePadding =
- res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
+
iconDrawablePaddingOriginalPx =
res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
@@ -360,7 +354,7 @@
if (!isVerticalLayout) {
int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
- - verticalDragHandleSizePx - topWorkspacePadding;
+ - verticalDragHandleSizePx - edgeMarginPx;
float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
workspaceSpringLoadShrinkFactor = Math.min(
res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
@@ -471,15 +465,15 @@
((inv.numColumns - 1) * cellWidthPx)));
availablePaddingX = (int) Math.min(availablePaddingX,
widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
- int availablePaddingY = Math.max(0, heightPx - topWorkspacePadding - paddingBottom
+ int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
- (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
- hotseatBarBottomPaddingPx);
- padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
+ padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
} else {
// Pad the top and bottom of the workspace with search/hotseat bar sizes
padding.set(desiredWorkspaceLeftRightMarginPx,
- topWorkspacePadding,
+ edgeMarginPx,
desiredWorkspaceLeftRightMarginPx,
paddingBottom);
}
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java
index d025a9b..0543e8d 100644
--- a/src/com/android/launcher3/DropTargetBar.java
+++ b/src/com/android/launcher3/DropTargetBar.java
@@ -104,7 +104,7 @@
/ (2 * (grid.inv.numColumns + 1)))
+ grid.edgeMarginPx;
} else {
- gap = grid.desiredWorkspaceLeftRightMarginPx - grid.defaultWidgetPadding.right;
+ gap = grid.desiredWorkspaceLeftRightMarginPx - grid.inv.defaultWidgetPadding.right;
}
lp.width = grid.availableWidthPx - 2 * gap;
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index f081303..c4495c7 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -20,7 +20,9 @@
import static com.android.launcher3.Utilities.getDevicePrefs;
import android.annotation.TargetApi;
+import android.appwidget.AppWidgetHostView;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -29,6 +31,7 @@
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Point;
+import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
@@ -114,6 +117,7 @@
public DeviceProfile portraitProfile;
public Point defaultWallpaperSize;
+ public Rect defaultWidgetPadding;
private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
private ConfigMonitor mConfigMonitor;
@@ -235,6 +239,10 @@
} else {
defaultWallpaperSize = new Point(Math.max(smallSide * 2, largeSide), largeSide);
}
+
+ ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
+ defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
+
return closestProfile.name;
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index f283a6c..867001a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -97,6 +97,7 @@
import com.android.launcher3.logging.StatsLogUtils;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
+import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.popup.PopupContainerWithArrow;
@@ -694,7 +695,7 @@
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- startActivitySafely(v, intent, null);
+ startActivitySafely(v, intent, null, null);
} else {
// TODO: Show a snack bar with link to settings
Toast.makeText(this, getString(R.string.msg_no_phone_permission,
@@ -798,6 +799,7 @@
getUserEventDispatcher().startSession();
UiFactory.onLauncherStateOrResumeChanged(this);
+ AppLaunchTracker.INSTANCE.get(this).onReturnedToHome();
}
}
@@ -1652,8 +1654,9 @@
}
}
- public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
- boolean success = super.startActivitySafely(v, intent, item);
+ public boolean startActivitySafely(View v, Intent intent, ItemInfo item,
+ @Nullable String sourceContainer) {
+ boolean success = super.startActivitySafely(v, intent, item, sourceContainer);
if (success && v instanceof BubbleTextView) {
// This is set to the view that launched the activity that navigated the user away
// from launcher. Since there is no callback for when the activity has finished
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 720a692..d05f916 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -298,12 +298,12 @@
if (grid.shouldFadeAdjacentWorkspaceScreens()) {
// In landscape mode the page spacing is set to the default.
- setPageSpacing(grid.defaultPageSpacingPx);
+ setPageSpacing(grid.edgeMarginPx);
} else {
// In portrait, we want the pages spaced such that there is no
// overhang of the previous / next page into the current page viewport.
// We assume symmetrical padding in portrait mode.
- setPageSpacing(Math.max(grid.defaultPageSpacingPx, padding.left + 1));
+ setPageSpacing(Math.max(grid.edgeMarginPx, padding.left + 1));
}
int paddingLeftRight = grid.cellLayoutPaddingLeftRightPx;
diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
index 69b4bdb..3cfa0b1 100644
--- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
+++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
@@ -32,6 +32,7 @@
import com.android.launcher3.R;
import com.android.launcher3.allapps.AlphabeticalAppsList.AdapterItem;
import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.PackageManagerHelper;
@@ -263,12 +264,8 @@
case VIEW_TYPE_SEARCH_MARKET:
View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market,
parent, false);
- searchMarketView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mLauncher.startActivitySafely(v, mMarketSearchIntent, null);
- }
- });
+ searchMarketView.setOnClickListener(v -> mLauncher.startActivitySafely(
+ v, mMarketSearchIntent, null, AppLaunchTracker.CONTAINER_SEARCH));
return new ViewHolder(searchMarketView);
case VIEW_TYPE_ALL_APPS_DIVIDER:
return new ViewHolder(mLayoutInflater.inflate(
diff --git a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java
index 91be504..4515dde 100644
--- a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java
+++ b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java
@@ -28,6 +28,7 @@
import com.android.launcher3.ExtendedEditText;
import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
+import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageManagerHelper;
@@ -111,7 +112,8 @@
return false;
}
return mLauncher.startActivitySafely(v,
- PackageManagerHelper.getMarketSearchIntent(mLauncher, query), null);
+ PackageManagerHelper.getMarketSearchIntent(mLauncher, query), null,
+ AppLaunchTracker.CONTAINER_SEARCH);
}
@Override
diff --git a/src/com/android/launcher3/config/BaseFlags.java b/src/com/android/launcher3/config/BaseFlags.java
index c260fa3..106d901 100644
--- a/src/com/android/launcher3/config/BaseFlags.java
+++ b/src/com/android/launcher3/config/BaseFlags.java
@@ -180,7 +180,7 @@
currentValue = getFromStorage(context, defaultValue);
}
- void updateStorage(Context context, boolean value) {
+ public void updateStorage(Context context, boolean value) {
SharedPreferences.Editor editor = context.getSharedPreferences(FLAGS_PREF_NAME,
Context.MODE_PRIVATE).edit();
if (value == defaultValue) {
@@ -272,7 +272,7 @@
}
@Override
- void updateStorage(Context context, boolean value) {
+ public void updateStorage(Context context, boolean value) {
if (contentResolver == null) {
return;
}
diff --git a/src/com/android/launcher3/model/AppLaunchTracker.java b/src/com/android/launcher3/model/AppLaunchTracker.java
new file mode 100644
index 0000000..1613d47
--- /dev/null
+++ b/src/com/android/launcher3/model/AppLaunchTracker.java
@@ -0,0 +1,56 @@
+/*
+ * 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 com.android.launcher3.model;
+
+import static com.android.launcher3.util.ResourceBasedOverride.Overrides.getObject;
+
+import android.content.ComponentName;
+import android.os.UserHandle;
+
+import com.android.launcher3.R;
+import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
+import com.android.launcher3.util.MainThreadInitializedObject;
+import com.android.launcher3.util.ResourceBasedOverride;
+
+import androidx.annotation.Nullable;
+
+/**
+ * Callback for receiving various app launch events
+ */
+public class AppLaunchTracker implements ResourceBasedOverride {
+
+ /**
+ * Derived from LauncherEvent proto.
+ * TODO: Use proper descriptive constants
+ */
+ public static final String CONTAINER_DEFAULT = Integer.toString(ContainerType.WORKSPACE);
+ public static final String CONTAINER_ALL_APPS = Integer.toString(ContainerType.ALLAPPS);
+ public static final String CONTAINER_PREDICTIONS = Integer.toString(ContainerType.PREDICTION);
+ public static final String CONTAINER_SEARCH = Integer.toString(ContainerType.SEARCHRESULT);
+
+
+ public static final MainThreadInitializedObject<AppLaunchTracker> INSTANCE =
+ new MainThreadInitializedObject<>(c ->
+ getObject(AppLaunchTracker.class, c, R.string.app_launch_tracker_class));
+
+ public void onStartShortcut(String packageName, String shortcutId, UserHandle user,
+ @Nullable String container) { }
+
+ public void onStartApp(ComponentName componentName, UserHandle user,
+ @Nullable String container) { }
+
+ public void onReturnedToHome() { }
+}
diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java
index fdc1b39..e7b82926 100644
--- a/src/com/android/launcher3/popup/SystemShortcut.java
+++ b/src/com/android/launcher3/popup/SystemShortcut.java
@@ -195,7 +195,7 @@
return view -> {
Intent intent = new PackageManagerHelper(view.getContext()).getMarketIntent(
itemInfo.getTargetComponent().getPackageName());
- activity.startActivitySafely(view, intent, itemInfo);
+ activity.startActivitySafely(view, intent, itemInfo, null);
AbstractFloatingView.closeAllOpenViews(activity);
};
}
diff --git a/src/com/android/launcher3/touch/ItemClickHandler.java b/src/com/android/launcher3/touch/ItemClickHandler.java
index 52fef9f..3639090 100644
--- a/src/com/android/launcher3/touch/ItemClickHandler.java
+++ b/src/com/android/launcher3/touch/ItemClickHandler.java
@@ -22,6 +22,8 @@
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED;
import static com.android.launcher3.Launcher.REQUEST_BIND_PENDING_APPWIDGET;
import static com.android.launcher3.Launcher.REQUEST_RECONFIGURE_APPWIDGET;
+import static com.android.launcher3.model.AppLaunchTracker.CONTAINER_ALL_APPS;
+import static com.android.launcher3.model.AppLaunchTracker.CONTAINER_DEFAULT;
import android.app.AlertDialog;
import android.content.Intent;
@@ -48,6 +50,8 @@
import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.widget.WidgetAddFlowHandler;
+import androidx.annotation.Nullable;
+
/**
* Class for handling clicks on workspace and all-apps items
*/
@@ -56,9 +60,13 @@
/**
* Instance used for click handling on items
*/
- public static final OnClickListener INSTANCE = ItemClickHandler::onClick;
+ public static final OnClickListener INSTANCE = getInstance(null);
- private static void onClick(View v) {
+ public static final OnClickListener getInstance(String sourceContainer) {
+ return v -> onClick(v, sourceContainer);
+ }
+
+ private static void onClick(View v, String sourceContainer) {
// Make sure that rogue clicks don't get through while allapps is launching, or after the
// view has detached (it's possible for this to happen if the view is removed mid touch).
if (v.getWindowToken() == null) {
@@ -72,13 +80,14 @@
Object tag = v.getTag();
if (tag instanceof ShortcutInfo) {
- onClickAppShortcut(v, (ShortcutInfo) tag, launcher);
+ onClickAppShortcut(v, (ShortcutInfo) tag, launcher, sourceContainer);
} else if (tag instanceof FolderInfo) {
if (v instanceof FolderIcon) {
onClickFolderIcon(v);
}
} else if (tag instanceof AppInfo) {
- startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher);
+ startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher,
+ sourceContainer == null ? CONTAINER_ALL_APPS: sourceContainer);
} else if (tag instanceof LauncherAppWidgetInfo) {
if (v instanceof PendingAppWidgetHostView) {
onClickPendingWidget((PendingAppWidgetHostView) v, launcher);
@@ -154,7 +163,7 @@
private static void startMarketIntentForPackage(View v, Launcher launcher, String packageName) {
ItemInfo item = (ItemInfo) v.getTag();
Intent intent = new PackageManagerHelper(launcher).getMarketIntent(packageName);
- launcher.startActivitySafely(v, intent, item);
+ launcher.startActivitySafely(v, intent, item, null);
}
/**
@@ -162,7 +171,8 @@
*
* @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
*/
- public static void onClickAppShortcut(View v, ShortcutInfo shortcut, Launcher launcher) {
+ public static void onClickAppShortcut(View v, ShortcutInfo shortcut, Launcher launcher,
+ @Nullable String sourceContainer) {
if (shortcut.isDisabled()) {
final int disabledFlags = shortcut.runtimeStatusFlags & ShortcutInfo.FLAG_DISABLED_MASK;
if ((disabledFlags &
@@ -201,10 +211,11 @@
}
// Start activities
- startAppShortcutOrInfoActivity(v, shortcut, launcher);
+ startAppShortcutOrInfoActivity(v, shortcut, launcher, sourceContainer);
}
- private static void startAppShortcutOrInfoActivity(View v, ItemInfo item, Launcher launcher) {
+ private static void startAppShortcutOrInfoActivity(View v, ItemInfo item, Launcher launcher,
+ @Nullable String sourceContainer) {
Intent intent;
if (item instanceof PromiseAppInfo) {
PromiseAppInfo promiseAppInfo = (PromiseAppInfo) item;
@@ -227,6 +238,6 @@
intent.setPackage(null);
}
}
- launcher.startActivitySafely(v, intent, item);
+ launcher.startActivitySafely(v, intent, item, sourceContainer);
}
}
diff --git a/src/com/android/launcher3/views/OptionsPopupView.java b/src/com/android/launcher3/views/OptionsPopupView.java
index e259cfe..6a2f0ff 100644
--- a/src/com/android/launcher3/views/OptionsPopupView.java
+++ b/src/com/android/launcher3/views/OptionsPopupView.java
@@ -217,7 +217,7 @@
if (!TextUtils.isEmpty(pickerPackage)) {
intent.setPackage(pickerPackage);
}
- return launcher.startActivitySafely(v, intent, null);
+ return launcher.startActivitySafely(v, intent, null, null);
}
public static class OptionItem {
diff --git a/tests/Android.mk b/tests/Android.mk
index b9b703d..ca7395a 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -35,8 +35,8 @@
../src/com/android/launcher3/TestProtocol.java
endif
-LOCAL_SDK_VERSION := current
LOCAL_MODULE := ub-launcher-aosp-tapl
+LOCAL_SDK_VERSION := current
include $(BUILD_STATIC_JAVA_LIBRARY)
@@ -47,18 +47,18 @@
LOCAL_MODULE_TAGS := tests
LOCAL_STATIC_JAVA_LIBRARIES := \
- androidx.test.runner \
- androidx.test.rules \
- androidx.test.uiautomator_uiautomator \
- mockito-target-minus-junit4
+ androidx.test.runner \
+ androidx.test.rules \
+ androidx.test.uiautomator_uiautomator \
+ mockito-target-minus-junit4
ifneq (,$(wildcard frameworks/base))
- LOCAL_PRIVATE_PLATFORM_APIS := true
- LOCAL_STATIC_JAVA_LIBRARIES += launcher-aosp-tapl
+ LOCAL_PRIVATE_PLATFORM_APIS := true
+ LOCAL_STATIC_JAVA_LIBRARIES += launcher-aosp-tapl
else
- LOCAL_SDK_VERSION := 28
- LOCAL_MIN_SDK_VERSION := 21
- LOCAL_STATIC_JAVA_LIBRARIES += ub-launcher-aosp-tapl
+ LOCAL_SDK_VERSION := 28
+ LOCAL_MIN_SDK_VERSION := 21
+ LOCAL_STATIC_JAVA_LIBRARIES += ub-launcher-aosp-tapl
endif
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
index fbb4f51..68b16d6 100644
--- a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
@@ -145,7 +145,7 @@
assertFalse(mDevice.findObject(new UiSelector().description(info.label)).exists());
}
- @Test
+ @Test @Ignore
public void testPendingWidget_autoRestored() {
// A non-restored widget with no config screen gets restored automatically.
LauncherAppWidgetProviderInfo info = TestViewHelpers.findWidgetProvider(this, false);
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index 122151e..b785007 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -29,7 +29,7 @@
public class AllApps extends LauncherInstrumentation.VisibleContainer {
private static final int MAX_SCROLL_ATTEMPTS = 40;
private static final int MIN_INTERACT_SIZE = 100;
- private static final int FLING_SPEED = 3000;
+ private static final int FLING_SPEED = LauncherInstrumentation.needSlowGestures() ? 1000 : 3000;
private final int mHeight;
@@ -60,47 +60,59 @@
*/
@NonNull
public AppIcon getAppIcon(String appName) {
- final UiObject2 allAppsContainer = verifyActiveContainer();
- final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher);
- if (!hasClickableIcon(allAppsContainer, appIconSelector)) {
- scrollBackToBeginning();
- int attempts = 0;
- while (!hasClickableIcon(allAppsContainer, appIconSelector) &&
- allAppsContainer.scroll(Direction.DOWN, 0.8f)) {
- LauncherInstrumentation.assertTrue(
- "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS,
- ++attempts <= MAX_SCROLL_ATTEMPTS);
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to get app icon on all apps")) {
+ final UiObject2 allAppsContainer = verifyActiveContainer();
+ final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher);
+ if (!hasClickableIcon(allAppsContainer, appIconSelector)) {
+ scrollBackToBeginning();
+ int attempts = 0;
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled")) {
+ while (!hasClickableIcon(allAppsContainer, appIconSelector) &&
+ allAppsContainer.scroll(Direction.DOWN, 0.8f)) {
+ mLauncher.assertTrue(
+ "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS,
+ ++attempts <= MAX_SCROLL_ATTEMPTS);
+ verifyActiveContainer();
+ }
+ }
verifyActiveContainer();
}
- }
- verifyActiveContainer();
- final UiObject2 appIcon = mLauncher.getObjectInContainer(allAppsContainer, appIconSelector);
- ensureIconVisible(appIcon, allAppsContainer);
- return new AppIcon(mLauncher, appIcon);
+ final UiObject2 appIcon = mLauncher.getObjectInContainer(allAppsContainer,
+ appIconSelector);
+ ensureIconVisible(appIcon, allAppsContainer);
+ return new AppIcon(mLauncher, appIcon);
+ }
}
private void scrollBackToBeginning() {
- final UiObject2 allAppsContainer = verifyActiveContainer();
- final UiObject2 searchBox =
- mLauncher.waitForObjectInContainer(allAppsContainer, "search_container_all_apps");
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to scroll back in all apps")) {
+ final UiObject2 allAppsContainer = verifyActiveContainer();
+ final UiObject2 searchBox =
+ mLauncher.waitForObjectInContainer(allAppsContainer,
+ "search_container_all_apps");
- int attempts = 0;
- allAppsContainer.setGestureMargins(0, searchBox.getVisibleBounds().bottom + 1, 0, 5);
+ int attempts = 0;
+ allAppsContainer.setGestureMargins(0, searchBox.getVisibleBounds().bottom + 1, 0, 5);
- for (int scroll = getScroll(allAppsContainer);
- scroll != 0;
- scroll = getScroll(allAppsContainer)) {
- LauncherInstrumentation.assertTrue("Negative scroll position", scroll > 0);
+ for (int scroll = getScroll(allAppsContainer);
+ scroll != 0;
+ scroll = getScroll(allAppsContainer)) {
+ mLauncher.assertTrue("Negative scroll position", scroll > 0);
- LauncherInstrumentation.assertTrue(
- "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS,
- ++attempts <= MAX_SCROLL_ATTEMPTS);
+ mLauncher.assertTrue(
+ "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS,
+ ++attempts <= MAX_SCROLL_ATTEMPTS);
- allAppsContainer.scroll(Direction.UP, 1);
+ allAppsContainer.scroll(Direction.UP, 1);
+ }
+
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled up")) {
+ verifyActiveContainer();
+ }
}
-
- verifyActiveContainer();
}
private int getScroll(UiObject2 allAppsContainer) {
@@ -115,8 +127,11 @@
// to reveal the app icon to have the MIN_INTERACT_SIZE
final float pct = Math.max(((float) (MIN_INTERACT_SIZE - appHeight)) / mHeight, 0.2f);
allAppsContainer.scroll(Direction.DOWN, pct);
- mLauncher.waitForIdle();
- verifyActiveContainer();
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "scrolled an icon in all apps to make it visible - and then")) {
+ mLauncher.waitForIdle();
+ verifyActiveContainer();
+ }
}
}
@@ -124,21 +139,29 @@
* Flings forward (down) and waits the fling's end.
*/
public void flingForward() {
- final UiObject2 allAppsContainer = verifyActiveContainer();
- // Start the gesture in the center to avoid starting at elements near the top.
- allAppsContainer.setGestureMargins(0, 0, 0, mHeight / 2);
- allAppsContainer.fling(Direction.DOWN, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
- verifyActiveContainer();
+ try(LauncherInstrumentation.Closable c =
+ mLauncher.addContextLayer("want to fling forward in all apps")) {
+ final UiObject2 allAppsContainer = verifyActiveContainer();
+ // Start the gesture in the center to avoid starting at elements near the top.
+ allAppsContainer.setGestureMargins(0, 0, 0, mHeight / 2);
+ allAppsContainer.fling(Direction.DOWN,
+ (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
+ verifyActiveContainer();
+ }
}
/**
* Flings backward (up) and waits the fling's end.
*/
public void flingBackward() {
- final UiObject2 allAppsContainer = verifyActiveContainer();
- // Start the gesture in the center, for symmetry with forward.
- allAppsContainer.setGestureMargins(0, mHeight / 2, 0, 0);
- allAppsContainer.fling(Direction.UP, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
- verifyActiveContainer();
+ try(LauncherInstrumentation.Closable c =
+ mLauncher.addContextLayer("want to fling backward in all apps")) {
+ final UiObject2 allAppsContainer = verifyActiveContainer();
+ // Start the gesture in the center, for symmetry with forward.
+ allAppsContainer.setGestureMargins(0, mHeight / 2, 0, 0);
+ allAppsContainer.fling(Direction.UP,
+ (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
+ verifyActiveContainer();
+ }
}
}
diff --git a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java
index dcc51b5..c3b671b 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java
@@ -42,20 +42,24 @@
*/
@NonNull
public Overview switchBackToOverview() {
- final UiObject2 allAppsContainer = verifyActiveContainer();
- // Swipe from the search box to the bottom.
- final UiObject2 qsb = mLauncher.waitForObjectInContainer(
- allAppsContainer, "search_container_all_apps");
- final Point start = qsb.getVisibleCenter();
- final int swipeHeight = mLauncher.getTestInfo(
- TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT).
- getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to switch back from all apps to overview")) {
+ final UiObject2 allAppsContainer = verifyActiveContainer();
+ // Swipe from the search box to the bottom.
+ final UiObject2 qsb = mLauncher.waitForObjectInContainer(
+ allAppsContainer, "search_container_all_apps");
+ final Point start = qsb.getVisibleCenter();
+ final int swipeHeight = mLauncher.getTestInfo(
+ TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT).
+ getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
- final int endY = start.y + swipeHeight + mLauncher.getTouchSlop();
- LauncherInstrumentation.log("AllAppsFromOverview.switchBackToOverview before swipe");
- mLauncher.swipe(start.x, start.y, start.x, endY, OVERVIEW_STATE_ORDINAL);
+ final int endY = start.y + swipeHeight + mLauncher.getTouchSlop();
+ LauncherInstrumentation.log("AllAppsFromOverview.switchBackToOverview before swipe");
+ mLauncher.swipe(start.x, start.y, start.x, endY, OVERVIEW_STATE_ORDINAL);
- return new Overview(mLauncher);
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("swiped down")) {
+ return new Overview(mLauncher);
+ }
+ }
}
-
}
diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java
index ef509ed..26c0ca4 100644
--- a/tests/tapl/com/android/launcher3/tapl/Background.java
+++ b/tests/tapl/com/android/launcher3/tapl/Background.java
@@ -57,11 +57,14 @@
*/
@NonNull
public BaseOverview switchToOverview() {
- verifyActiveContainer();
- goToOverviewUnchecked(BACKGROUND_APP_STATE_ORDINAL);
- assertTrue("Overview not visible", mLauncher.getDevice().wait(
- Until.hasObject(By.pkg(getOverviewPackageName())), WAIT_TIME_MS));
- return new BaseOverview(mLauncher);
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to switch from background to overview")) {
+ verifyActiveContainer();
+ goToOverviewUnchecked(BACKGROUND_APP_STATE_ORDINAL);
+ assertTrue("Overview not visible", mLauncher.getDevice().wait(
+ Until.hasObject(By.pkg(getOverviewPackageName())), WAIT_TIME_MS));
+ return new BaseOverview(mLauncher);
+ }
}
protected void goToOverviewUnchecked(int expectedState) {
diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
index 234c3bf..4205188 100644
--- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
+++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
@@ -44,42 +44,54 @@
* Flings forward (left) and waits the fling's end.
*/
public void flingForward() {
- LauncherInstrumentation.log("Overview.flingForward before fling");
- final UiObject2 overview = verifyActiveContainer();
- final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
- overview.setGestureMargins(margin, 0, 0, 0);
- overview.fling(Direction.LEFT, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
- mLauncher.waitForIdle();
- verifyActiveContainer();
+ try (LauncherInstrumentation.Closable c =
+ mLauncher.addContextLayer("want to fling forward in overview")) {
+ LauncherInstrumentation.log("Overview.flingForward before fling");
+ final UiObject2 overview = verifyActiveContainer();
+ final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
+ overview.setGestureMargins(margin, 0, 0, 0);
+ overview.fling(Direction.LEFT, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
+ mLauncher.waitForIdle();
+ verifyActiveContainer();
+ }
}
/**
* Dismissed all tasks by scrolling to Clear-all button and pressing it.
*/
public Workspace dismissAllTasks() {
- final BySelector clearAllSelector = mLauncher.getLauncherObjectSelector("clear_all");
- for (int i = 0;
- i < FLINGS_FOR_DISMISS_LIMIT
- && !verifyActiveContainer().hasObject(clearAllSelector);
- ++i) {
- flingForward();
- }
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "dismissing all tasks")) {
+ final BySelector clearAllSelector = mLauncher.getLauncherObjectSelector("clear_all");
+ for (int i = 0;
+ i < FLINGS_FOR_DISMISS_LIMIT
+ && !verifyActiveContainer().hasObject(clearAllSelector);
+ ++i) {
+ flingForward();
+ }
- mLauncher.getObjectInContainer(verifyActiveContainer(), clearAllSelector).click();
- return new Workspace(mLauncher);
+ mLauncher.getObjectInContainer(verifyActiveContainer(), clearAllSelector).click();
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
+ "dismissed all tasks")) {
+ return new Workspace(mLauncher);
+ }
+ }
}
/**
* Flings backward (right) and waits the fling's end.
*/
public void flingBackward() {
- LauncherInstrumentation.log("Overview.flingBackward before fling");
- final UiObject2 overview = verifyActiveContainer();
- final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
- overview.setGestureMargins(0, 0, margin, 0);
- overview.fling(Direction.RIGHT, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
- mLauncher.waitForIdle();
- verifyActiveContainer();
+ try (LauncherInstrumentation.Closable c =
+ mLauncher.addContextLayer("want to fling backward in overview")) {
+ LauncherInstrumentation.log("Overview.flingBackward before fling");
+ final UiObject2 overview = verifyActiveContainer();
+ final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
+ overview.setGestureMargins(0, 0, margin, 0);
+ overview.fling(Direction.RIGHT, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
+ mLauncher.waitForIdle();
+ verifyActiveContainer();
+ }
}
/**
@@ -89,18 +101,21 @@
*/
@NonNull
public OverviewTask getCurrentTask() {
- verifyActiveContainer();
- final List<UiObject2> taskViews = mLauncher.getDevice().findObjects(
- mLauncher.getLauncherObjectSelector("snapshot"));
- LauncherInstrumentation.assertNotEquals("Unable to find a task", 0, taskViews.size());
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to get current task")) {
+ verifyActiveContainer();
+ final List<UiObject2> taskViews = mLauncher.getDevice().findObjects(
+ mLauncher.getLauncherObjectSelector("snapshot"));
+ mLauncher.assertNotEquals("Unable to find a task", 0, taskViews.size());
- // taskViews contains up to 3 task views: the 'main' (having the widest visible
- // part) one in the center, and parts of its right and left siblings. Find the
- // main task view by its width.
- final UiObject2 widestTask = Collections.max(taskViews,
- (t1, t2) -> Integer.compare(t1.getVisibleBounds().width(),
- t2.getVisibleBounds().width()));
+ // taskViews contains up to 3 task views: the 'main' (having the widest visible
+ // part) one in the center, and parts of its right and left siblings. Find the
+ // main task view by its width.
+ final UiObject2 widestTask = Collections.max(taskViews,
+ (t1, t2) -> Integer.compare(t1.getVisibleBounds().width(),
+ t2.getVisibleBounds().width()));
- return new OverviewTask(mLauncher, widestTask, this);
+ return new OverviewTask(mLauncher, widestTask, this);
+ }
}
}
\ No newline at end of file
diff --git a/tests/tapl/com/android/launcher3/tapl/Home.java b/tests/tapl/com/android/launcher3/tapl/Home.java
index f8bd85a..20c116c 100644
--- a/tests/tapl/com/android/launcher3/tapl/Home.java
+++ b/tests/tapl/com/android/launcher3/tapl/Home.java
@@ -48,8 +48,14 @@
@NonNull
@Override
public Overview switchToOverview() {
- verifyActiveContainer();
- goToOverviewUnchecked(OVERVIEW_STATE_ORDINAL);
- return new Overview(mLauncher);
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to switch from home to overview")) {
+ verifyActiveContainer();
+ goToOverviewUnchecked(OVERVIEW_STATE_ORDINAL);
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
+ "performed the switch action")) {
+ return new Overview(mLauncher);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/tests/tapl/com/android/launcher3/tapl/Launchable.java b/tests/tapl/com/android/launcher3/tapl/Launchable.java
index 481281a..7a2b7af 100644
--- a/tests/tapl/com/android/launcher3/tapl/Launchable.java
+++ b/tests/tapl/com/android/launcher3/tapl/Launchable.java
@@ -59,10 +59,10 @@
private Background launch(String errorMessage, BySelector selector) {
LauncherInstrumentation.log("Launchable.launch before click " +
mObject.getVisibleCenter());
- LauncherInstrumentation.assertTrue(
+ mLauncher.assertTrue(
"Launching an app didn't open a new window: " + mObject.getText(),
mObject.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS));
- LauncherInstrumentation.assertTrue(
+ mLauncher.assertTrue(
"App didn't start: " + errorMessage,
mLauncher.getDevice().wait(Until.hasObject(selector),
LauncherInstrumentation.WAIT_TIME_MS));
@@ -79,6 +79,9 @@
this,
new Point(device.getDisplayWidth() / 2, device.getDisplayHeight() / 2),
DRAG_SPEED);
- return new Workspace(mLauncher);
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "dragged launchable to workspace")) {
+ return new Workspace(mLauncher);
+ }
}
}
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index f44022b..fd6ddce 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -17,19 +17,19 @@
package com.android.launcher3.tapl;
import static com.android.launcher3.TestProtocol.BACKGROUND_APP_STATE_ORDINAL;
-import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
import android.app.ActivityManager;
import android.app.Instrumentation;
import android.app.UiAutomation;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.graphics.Point;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.SystemClock;
-import android.provider.Settings;
import android.util.Log;
import android.view.InputDevice;
import android.view.MotionEvent;
@@ -47,12 +47,14 @@
import androidx.test.uiautomator.Until;
import com.android.launcher3.TestProtocol;
-import com.android.quickstep.SwipeUpSetting;
+import com.android.systemui.shared.system.QuickStepContract;
import org.junit.Assert;
import java.io.IOException;
import java.lang.ref.WeakReference;
+import java.util.Deque;
+import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeoutException;
@@ -90,11 +92,16 @@
* @return UI object for the container.
*/
final UiObject2 verifyActiveContainer() {
- assertTrue("Attempt to use a stale container", this == sActiveContainer.get());
+ mLauncher.assertTrue("Attempt to use a stale container",
+ this == sActiveContainer.get());
return mLauncher.verifyContainerType(getContainerType());
}
}
+ interface Closable extends AutoCloseable {
+ void close();
+ }
+
private static final String WORKSPACE_RES_ID = "workspace";
private static final String APPS_RES_ID = "apps_view";
private static final String OVERVIEW_RES_ID = "overview_panel";
@@ -108,6 +115,7 @@
private final Instrumentation mInstrumentation;
private int mExpectedRotation = Surface.ROTATION_0;
private final Uri mTestProviderUri;
+ private final Deque<String> mDiagnosticContext = new LinkedList<>();
/**
* Constructs the root of TAPL hierarchy. You get all other objects from it.
@@ -161,45 +169,58 @@
return isSwipeUpEnabled() ? NavigationModel.TWO_BUTTON : NavigationModel.THREE_BUTTON;
}
+ static boolean needSlowGestures() {
+ return Build.MODEL.contains("Cuttlefish");
+ }
+
private boolean isSwipeUpEnabled() {
- final boolean swipeUpEnabledDefaultValue = SwipeUpSetting.isSwipeUpEnabledDefaultValue();
- return SwipeUpSetting.isSwipeUpSettingAvailable() ?
- Settings.Secure.getInt(
- mInstrumentation.getTargetContext().getContentResolver(),
- SWIPE_UP_SETTING_NAME,
- swipeUpEnabledDefaultValue ? 1 : 0) == 1 :
- swipeUpEnabledDefaultValue;
+ final Context baseContext = mInstrumentation.getTargetContext();
+ try {
+ // Workaround, use constructed context because both the instrumentation context and the
+ // app context are not constructed with resources that take overlays into account
+ Context ctx = baseContext.createPackageContext(getLauncherPackageName(), 0);
+ return !QuickStepContract.isLegacyMode(ctx);
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
}
static void log(String message) {
Log.d(TAG, message);
}
- private static void fail(String message) {
- Assert.fail("http://go/tapl : " + message);
+ Closable addContextLayer(String piece) {
+ mDiagnosticContext.addLast(piece);
+ return () -> mDiagnosticContext.removeLast();
}
- static void assertTrue(String message, boolean condition) {
+ private void fail(String message) {
+ final String ctxt = mDiagnosticContext.isEmpty() ? "" : String.join(", ",
+ mDiagnosticContext) + "; ";
+ Assert.fail("http://go/tapl : " + ctxt + message);
+ }
+
+ void assertTrue(String message, boolean condition) {
if (!condition) {
fail(message);
}
}
- static void assertNotNull(String message, Object object) {
+ void assertNotNull(String message, Object object) {
assertTrue(message, object != null);
}
- static private void failEquals(String message, Object actual) {
+ private void failEquals(String message, Object actual) {
fail(message + ". " + "Actual: " + actual);
}
- static private void assertEquals(String message, int expected, int actual) {
+ private void assertEquals(String message, int expected, int actual) {
if (expected != actual) {
fail(message + " expected: " + expected + " but was: " + actual);
}
}
- static void assertNotEquals(String message, int unexpected, int actual) {
+ void assertNotEquals(String message, int unexpected, int actual) {
if (unexpected == actual) {
failEquals(message, actual);
}
@@ -217,49 +238,52 @@
(mDevice.findObject(By.res(SYSTEMUI_PACKAGE, "recent_apps")) == null));
log("verifyContainerType: " + containerType);
- switch (containerType) {
- case WORKSPACE: {
- waitForLauncherObject(APPS_RES_ID);
- waitUntilGone(OVERVIEW_RES_ID);
- waitUntilGone(WIDGETS_RES_ID);
- return waitForLauncherObject(WORKSPACE_RES_ID);
- }
- case WIDGETS: {
- waitUntilGone(WORKSPACE_RES_ID);
- waitUntilGone(APPS_RES_ID);
- waitUntilGone(OVERVIEW_RES_ID);
- return waitForLauncherObject(WIDGETS_RES_ID);
- }
- case ALL_APPS: {
- waitUntilGone(WORKSPACE_RES_ID);
- waitUntilGone(OVERVIEW_RES_ID);
- waitUntilGone(WIDGETS_RES_ID);
- return waitForLauncherObject(APPS_RES_ID);
- }
- case OVERVIEW: {
- if (mDevice.isNaturalOrientation()) {
+ try (Closable c = addContextLayer(
+ "but the current state is not " + containerType.name())) {
+ switch (containerType) {
+ case WORKSPACE: {
waitForLauncherObject(APPS_RES_ID);
- } else {
- waitUntilGone(APPS_RES_ID);
+ waitUntilGone(OVERVIEW_RES_ID);
+ waitUntilGone(WIDGETS_RES_ID);
+ return waitForLauncherObject(WORKSPACE_RES_ID);
}
- // Fall through
- }
- case BASE_OVERVIEW: {
- waitUntilGone(WORKSPACE_RES_ID);
- waitUntilGone(WIDGETS_RES_ID);
+ case WIDGETS: {
+ waitUntilGone(WORKSPACE_RES_ID);
+ waitUntilGone(APPS_RES_ID);
+ waitUntilGone(OVERVIEW_RES_ID);
+ return waitForLauncherObject(WIDGETS_RES_ID);
+ }
+ case ALL_APPS: {
+ waitUntilGone(WORKSPACE_RES_ID);
+ waitUntilGone(OVERVIEW_RES_ID);
+ waitUntilGone(WIDGETS_RES_ID);
+ return waitForLauncherObject(APPS_RES_ID);
+ }
+ case OVERVIEW: {
+ if (mDevice.isNaturalOrientation()) {
+ waitForLauncherObject(APPS_RES_ID);
+ } else {
+ waitUntilGone(APPS_RES_ID);
+ }
+ // Fall through
+ }
+ case BASE_OVERVIEW: {
+ waitUntilGone(WORKSPACE_RES_ID);
+ waitUntilGone(WIDGETS_RES_ID);
- return waitForLauncherObject(OVERVIEW_RES_ID);
+ return waitForLauncherObject(OVERVIEW_RES_ID);
+ }
+ case BACKGROUND: {
+ waitUntilGone(WORKSPACE_RES_ID);
+ waitUntilGone(APPS_RES_ID);
+ waitUntilGone(OVERVIEW_RES_ID);
+ waitUntilGone(WIDGETS_RES_ID);
+ return null;
+ }
+ default:
+ fail("Invalid state: " + containerType);
+ return null;
}
- case BACKGROUND: {
- waitUntilGone(WORKSPACE_RES_ID);
- waitUntilGone(APPS_RES_ID);
- waitUntilGone(OVERVIEW_RES_ID);
- waitUntilGone(WIDGETS_RES_ID);
- return null;
- }
- default:
- fail("Invalid state: " + containerType);
- return null;
}
}
@@ -351,7 +375,9 @@
*/
@NonNull
public Workspace getWorkspace() {
- return new Workspace(this);
+ try (LauncherInstrumentation.Closable c = addContextLayer("want to get workspace object")) {
+ return new Workspace(this);
+ }
}
/**
@@ -373,7 +399,9 @@
*/
@NonNull
public Widgets getAllWidgets() {
- return new Widgets(this);
+ try (LauncherInstrumentation.Closable c = addContextLayer("want to get widgets")) {
+ return new Widgets(this);
+ }
}
/**
@@ -384,7 +412,9 @@
*/
@NonNull
public Overview getOverview() {
- return new Overview(this);
+ try (LauncherInstrumentation.Closable c = addContextLayer("want to get overview")) {
+ return new Overview(this);
+ }
}
/**
@@ -408,7 +438,9 @@
*/
@NonNull
public AllApps getAllApps() {
- return new AllApps(this);
+ try (LauncherInstrumentation.Closable c = addContextLayer("want to get all apps object")) {
+ return new AllApps(this);
+ }
}
/**
@@ -421,7 +453,9 @@
*/
@NonNull
public AllAppsFromOverview getAllAppsFromOverview() {
- return new AllAppsFromOverview(this);
+ try (LauncherInstrumentation.Closable c = addContextLayer("want to get all apps object")) {
+ return new AllAppsFromOverview(this);
+ }
}
void waitUntilGone(String resId) {
diff --git a/tests/tapl/com/android/launcher3/tapl/Overview.java b/tests/tapl/com/android/launcher3/tapl/Overview.java
index 5c8d5eb..41932c8 100644
--- a/tests/tapl/com/android/launcher3/tapl/Overview.java
+++ b/tests/tapl/com/android/launcher3/tapl/Overview.java
@@ -20,11 +20,11 @@
import android.graphics.Point;
-import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
-
import androidx.annotation.NonNull;
import androidx.test.uiautomator.UiObject2;
+import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
+
/**
* Overview pane.
*/
@@ -47,14 +47,20 @@
*/
@NonNull
public AllAppsFromOverview switchToAllApps() {
- verifyActiveContainer();
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to switch from overview to all apps")) {
+ verifyActiveContainer();
- // Swipe from navbar to the top.
- final UiObject2 navBar = mLauncher.waitForSystemUiObject("navigation_bar_frame");
- final Point start = navBar.getVisibleCenter();
- LauncherInstrumentation.log("Overview.switchToAllApps before swipe");
- mLauncher.swipe(start.x, start.y, start.x, 0, ALL_APPS_STATE_ORDINAL);
+ // Swipe from navbar to the top.
+ final UiObject2 navBar = mLauncher.waitForSystemUiObject("navigation_bar_frame");
+ final Point start = navBar.getVisibleCenter();
+ LauncherInstrumentation.log("Overview.switchToAllApps before swipe");
+ mLauncher.swipe(start.x, start.y, start.x, 0, ALL_APPS_STATE_ORDINAL);
- return new AllAppsFromOverview(mLauncher);
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
+ "swiped all way up from overview")) {
+ return new AllAppsFromOverview(mLauncher);
+ }
+ }
}
}
diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
index 7ccd49b..b966851 100644
--- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
+++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
@@ -44,10 +44,13 @@
* Swipes the task up.
*/
public void dismiss() {
- verifyActiveContainer();
- // Dismiss the task via flinging it up.
- mTask.fling(Direction.DOWN, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
- mLauncher.waitForIdle();
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to dismiss a task")) {
+ verifyActiveContainer();
+ // Dismiss the task via flinging it up.
+ mTask.fling(Direction.DOWN, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
+ mLauncher.waitForIdle();
+ }
}
/**
@@ -55,7 +58,7 @@
*/
public Background open() {
verifyActiveContainer();
- LauncherInstrumentation.assertTrue("Launching task didn't open a new window: " +
+ mLauncher.assertTrue("Launching task didn't open a new window: " +
mTask.getParent().getContentDescription(),
mTask.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS));
return new Background(mLauncher);
diff --git a/tests/tapl/com/android/launcher3/tapl/Widgets.java b/tests/tapl/com/android/launcher3/tapl/Widgets.java
index 89affd1..2de53c3 100644
--- a/tests/tapl/com/android/launcher3/tapl/Widgets.java
+++ b/tests/tapl/com/android/launcher3/tapl/Widgets.java
@@ -34,21 +34,37 @@
* Flings forward (down) and waits the fling's end.
*/
public void flingForward() {
- final UiObject2 widgetsContainer = verifyActiveContainer();
- widgetsContainer.setGestureMargin(100);
- widgetsContainer.fling(Direction.DOWN, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
- verifyActiveContainer();
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to fling forward in widgets")) {
+ LauncherInstrumentation.log("Widgets.flingForward enter");
+ final UiObject2 widgetsContainer = verifyActiveContainer();
+ widgetsContainer.setGestureMargin(100);
+ widgetsContainer.fling(Direction.DOWN,
+ (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("flung forward")) {
+ verifyActiveContainer();
+ }
+ LauncherInstrumentation.log("Widgets.flingForward exit");
+ }
}
/**
* Flings backward (up) and waits the fling's end.
*/
public void flingBackward() {
- final UiObject2 widgetsContainer = verifyActiveContainer();
- widgetsContainer.setGestureMargin(100);
- widgetsContainer.fling(Direction.UP, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
- mLauncher.waitForIdle();
- verifyActiveContainer();
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to fling backwards in widgets")) {
+ LauncherInstrumentation.log("Widgets.flingBackward enter");
+ final UiObject2 widgetsContainer = verifyActiveContainer();
+ widgetsContainer.setGestureMargin(100);
+ widgetsContainer.fling(Direction.UP,
+ (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
+ mLauncher.waitForIdle();
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("flung back")) {
+ verifyActiveContainer();
+ }
+ LauncherInstrumentation.log("Widgets.flingBackward exit");
+ }
}
@Override
diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java
index 7d97acd..9979f50 100644
--- a/tests/tapl/com/android/launcher3/tapl/Workspace.java
+++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java
@@ -36,7 +36,7 @@
public final class Workspace extends Home {
private static final float FLING_SPEED = 3500.0F;
private final UiObject2 mHotseat;
- private final int ICON_DRAG_SPEED = 2000;
+ private final int ICON_DRAG_SPEED = LauncherInstrumentation.needSlowGestures() ? 100 : 570;
Workspace(LauncherInstrumentation launcher) {
super(launcher);
@@ -50,21 +50,27 @@
*/
@NonNull
public AllApps switchToAllApps() {
- verifyActiveContainer();
- final UiObject2 hotseat = mHotseat;
- final Point start = hotseat.getVisibleCenter();
- final int swipeHeight = mLauncher.getTestInfo(
- TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT).
- getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
- mLauncher.swipe(
- start.x,
- start.y,
- start.x,
- start.y - swipeHeight - mLauncher.getTouchSlop(),
- ALL_APPS_STATE_ORDINAL
- );
+ try(LauncherInstrumentation.Closable c =
+ mLauncher.addContextLayer("want to switch from workspace to all apps")) {
+ verifyActiveContainer();
+ final UiObject2 hotseat = mHotseat;
+ final Point start = hotseat.getVisibleCenter();
+ final int swipeHeight = mLauncher.getTestInfo(
+ TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT).
+ getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
+ mLauncher.swipe(
+ start.x,
+ start.y,
+ start.x,
+ start.y - swipeHeight - mLauncher.getTouchSlop(),
+ ALL_APPS_STATE_ORDINAL
+ );
- return new AllApps(mLauncher);
+ try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
+ "swiped to all apps")) {
+ return new AllApps(mLauncher);
+ }
+ }
}
/**
@@ -75,9 +81,13 @@
*/
@Nullable
public AppIcon tryGetWorkspaceAppIcon(String appName) {
- final UiObject2 workspace = verifyActiveContainer();
- final UiObject2 icon = workspace.findObject(AppIcon.getAppIconSelector(appName, mLauncher));
- return icon != null ? new AppIcon(mLauncher, icon) : null;
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+ "want to get a workspace icon")) {
+ final UiObject2 workspace = verifyActiveContainer();
+ final UiObject2 icon = workspace.findObject(
+ AppIcon.getAppIconSelector(appName, mLauncher));
+ return icon != null ? new AppIcon(mLauncher, icon) : null;
+ }
}
@@ -107,7 +117,7 @@
getHotseatAppIcon("Messages"),
new Point(mLauncher.getDevice().getDisplayWidth(),
workspace.getVisibleBounds().centerY()),
- ICON_DRAG_SPEED);
+ (int) (ICON_DRAG_SPEED * mLauncher.getDisplayDensity()));
verifyActiveContainer();
}
assertTrue("Home screen workspace didn't become scrollable",
@@ -165,7 +175,9 @@
public Widgets openAllWidgets() {
verifyActiveContainer();
mLauncher.getDevice().pressKeyCode(KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON);
- return new Widgets(mLauncher);
+ try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer("pressed Ctrl+W")) {
+ return new Widgets(mLauncher);
+ }
}
@Override