Merge "Removing static launcher activity dependency from FirstFrameAnimationHelper" into ub-launcher3-master
diff --git a/quickstep/src/com/android/quickstep/NormalizedIconLoader.java b/quickstep/src/com/android/quickstep/NormalizedIconLoader.java
index f875bb7..a4a2e56 100644
--- a/quickstep/src/com/android/quickstep/NormalizedIconLoader.java
+++ b/quickstep/src/com/android/quickstep/NormalizedIconLoader.java
@@ -42,12 +42,15 @@
private final SparseArray<BitmapInfo> mDefaultIcons = new SparseArray<>();
private final DrawableFactory mDrawableFactory;
+ private final boolean mDisableColorExtraction;
private LauncherIcons mLauncherIcons;
public NormalizedIconLoader(Context context, TaskKeyLruCache<Drawable> iconCache,
- LruCache<ComponentName, ActivityInfo> activityInfoCache) {
+ LruCache<ComponentName, ActivityInfo> activityInfoCache,
+ boolean disableColorExtraction) {
super(context, iconCache, activityInfoCache);
mDrawableFactory = DrawableFactory.get(context);
+ mDisableColorExtraction = disableColorExtraction;
}
@Override
@@ -74,6 +77,9 @@
int primaryColor, boolean isInstantApp) {
if (mLauncherIcons == null) {
mLauncherIcons = LauncherIcons.obtain(mContext);
+ if (mDisableColorExtraction) {
+ mLauncherIcons.disableColorExtraction();
+ }
}
mLauncherIcons.setWrapperBackgroundColor(primaryColor);
diff --git a/quickstep/src/com/android/quickstep/RecentsModel.java b/quickstep/src/com/android/quickstep/RecentsModel.java
index fa4e016..a9b7326 100644
--- a/quickstep/src/com/android/quickstep/RecentsModel.java
+++ b/quickstep/src/com/android/quickstep/RecentsModel.java
@@ -94,7 +94,9 @@
protected IconLoader createNewIconLoader(Context context,
TaskKeyLruCache<Drawable> iconCache,
LruCache<ComponentName, ActivityInfo> activityInfoCache) {
- return new NormalizedIconLoader(context, iconCache, activityInfoCache);
+ // Disable finding the dominant color since we don't need to use it
+ return new NormalizedIconLoader(context, iconCache, activityInfoCache,
+ true /* disableColorExtraction */);
}
};
mRecentsTaskLoader.startLoader(mContext);
diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java
index d6635dc..f5fbf80 100644
--- a/src/com/android/launcher3/BaseDraggingActivity.java
+++ b/src/com/android/launcher3/BaseDraggingActivity.java
@@ -19,7 +19,9 @@
import android.app.ActivityOptions;
import android.content.ActivityNotFoundException;
import android.content.Intent;
+import android.content.res.Configuration;
import android.graphics.Rect;
+import android.os.Build;
import android.os.Bundle;
import android.os.Process;
import android.os.StrictMode;
@@ -81,13 +83,33 @@
@Override
public void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo) {
+ updateTheme();
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ updateTheme();
+ }
+
+ private void updateTheme() {
+ WallpaperColorInfo wallpaperColorInfo = WallpaperColorInfo.getInstance(this);
if (mThemeRes != getThemeRes(wallpaperColorInfo)) {
recreate();
}
}
protected int getThemeRes(WallpaperColorInfo wallpaperColorInfo) {
- if (wallpaperColorInfo.isDark()) {
+ boolean darkTheme;
+ if (Utilities.ATLEAST_Q) {
+ Configuration configuration = getResources().getConfiguration();
+ int nightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
+ darkTheme = nightMode == Configuration.UI_MODE_NIGHT_YES;
+ } else {
+ darkTheme = wallpaperColorInfo.isDark();
+ }
+
+ if (darkTheme) {
return wallpaperColorInfo.supportsDarkText() ?
R.style.AppTheme_Dark_DarkText : R.style.AppTheme_Dark;
} else {
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index a851318..1c12464 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -83,6 +83,10 @@
private static final Matrix sMatrix = new Matrix();
private static final Matrix sInverseMatrix = new Matrix();
+ public static final boolean ATLEAST_Q = Build.VERSION.CODENAME.length() == 1
+ && Build.VERSION.CODENAME.charAt(0) >= 'Q'
+ && Build.VERSION.CODENAME.charAt(0) <= 'Z';
+
public static final boolean ATLEAST_P =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P;
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 40cf0f3..cf7842a 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -390,6 +390,26 @@
}
}
+ // Used by tests only
+ private boolean isDescendantViewVisible(int viewId) {
+ final View view = findViewById(viewId);
+ if (view == null) return false;
+
+ if (!view.isShown()) return false;
+
+ return view.getGlobalVisibleRect(new Rect());
+ }
+
+ // Used by tests only
+ public boolean isPersonalTabVisible() {
+ return isDescendantViewVisible(R.id.tab_personal);
+ }
+
+ // Used by tests only
+ public boolean isWorkTabVisible() {
+ return isDescendantViewVisible(R.id.tab_work);
+ }
+
public AlphabeticalAppsList getApps() {
return mAH[AdapterHolder.MAIN].appsList;
}
diff --git a/src/com/android/launcher3/graphics/BitmapInfo.java b/src/com/android/launcher3/graphics/BitmapInfo.java
index ab906e2..c905a78 100644
--- a/src/com/android/launcher3/graphics/BitmapInfo.java
+++ b/src/com/android/launcher3/graphics/BitmapInfo.java
@@ -35,9 +35,15 @@
}
public static BitmapInfo fromBitmap(Bitmap bitmap) {
+ return fromBitmap(bitmap, null);
+ }
+
+ public static BitmapInfo fromBitmap(Bitmap bitmap, ColorExtractor dominantColorExtractor) {
BitmapInfo info = new BitmapInfo();
info.icon = bitmap;
- info.color = ColorExtractor.findDominantColorByHue(bitmap);
+ info.color = dominantColorExtractor != null
+ ? dominantColorExtractor.findDominantColorByHue(bitmap)
+ : 0;
return info;
}
}
diff --git a/src/com/android/launcher3/graphics/ColorExtractor.java b/src/com/android/launcher3/graphics/ColorExtractor.java
index e9d72b7..da5da9c 100644
--- a/src/com/android/launcher3/graphics/ColorExtractor.java
+++ b/src/com/android/launcher3/graphics/ColorExtractor.java
@@ -18,22 +18,32 @@
import android.graphics.Bitmap;
import android.graphics.Color;
import android.util.SparseArray;
+import java.util.Arrays;
/**
* Utility class for extracting colors from a bitmap.
*/
public class ColorExtractor {
- public static int findDominantColorByHue(Bitmap bitmap) {
- return findDominantColorByHue(bitmap, 20);
+ private final int NUM_SAMPLES = 20;
+ private final float[] mTmpHsv = new float[3];
+ private final float[] mTmpHueScoreHistogram = new float[360];
+ private final int[] mTmpPixels = new int[NUM_SAMPLES];
+ private final SparseArray<Float> mTmpRgbScores = new SparseArray<>();
+
+ /**
+ * This picks a dominant color, looking for high-saturation, high-value, repeated hues.
+ * @param bitmap The bitmap to scan
+ */
+ public int findDominantColorByHue(Bitmap bitmap) {
+ return findDominantColorByHue(bitmap, NUM_SAMPLES);
}
/**
* This picks a dominant color, looking for high-saturation, high-value, repeated hues.
* @param bitmap The bitmap to scan
- * @param samples The approximate max number of samples to use.
*/
- public static int findDominantColorByHue(Bitmap bitmap, int samples) {
+ public int findDominantColorByHue(Bitmap bitmap, int samples) {
final int height = bitmap.getHeight();
final int width = bitmap.getWidth();
int sampleStride = (int) Math.sqrt((height * width) / samples);
@@ -42,15 +52,18 @@
}
// This is an out-param, for getting the hsv values for an rgb
- float[] hsv = new float[3];
+ float[] hsv = mTmpHsv;
+ Arrays.fill(hsv, 0);
// First get the best hue, by creating a histogram over 360 hue buckets,
// where each pixel contributes a score weighted by saturation, value, and alpha.
- float[] hueScoreHistogram = new float[360];
+ float[] hueScoreHistogram = mTmpHueScoreHistogram;
+ Arrays.fill(hueScoreHistogram, 0);
float highScore = -1;
int bestHue = -1;
- int[] pixels = new int[samples];
+ int[] pixels = mTmpPixels;
+ Arrays.fill(pixels, 0);
int pixelCount = 0;
for (int y = 0; y < height; y += sampleStride) {
@@ -82,7 +95,8 @@
}
}
- SparseArray<Float> rgbScores = new SparseArray<>();
+ SparseArray<Float> rgbScores = mTmpRgbScores;
+ rgbScores.clear();
int bestColor = 0xff000000;
highScore = -1;
// Go back over the RGB colors that match the winning hue,
diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java
index 333fe59..0167a1d 100644
--- a/src/com/android/launcher3/graphics/LauncherIcons.java
+++ b/src/com/android/launcher3/graphics/LauncherIcons.java
@@ -90,6 +90,7 @@
synchronized (sPoolSync) {
// Clear any temporary state variables
mWrapperBackgroundColor = DEFAULT_WRAPPER_BACKGROUND;
+ mDisableColorExtractor = false;
next = sPool;
sPool = this;
@@ -105,6 +106,8 @@
private final Context mContext;
private final Canvas mCanvas;
private final PackageManager mPm;
+ private final ColorExtractor mColorExtractor;
+ private boolean mDisableColorExtractor;
private final int mFillResIconDpi;
private final int mIconBitmapSize;
@@ -121,6 +124,7 @@
private LauncherIcons(Context context) {
mContext = context.getApplicationContext();
mPm = mContext.getPackageManager();
+ mColorExtractor = new ColorExtractor();
InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
mFillResIconDpi = idp.fillResIconDpi;
@@ -196,7 +200,7 @@
* The bitmap is also visually normalized with other icons.
*/
public BitmapInfo createBadgedIconBitmap(Drawable icon, UserHandle user, int iconAppTargetSdk,
- boolean isInstantApp, float [] scale) {
+ boolean isInstantApp, float[] scale) {
if (scale == null) {
scale = new float[1];
}
@@ -223,7 +227,7 @@
} else {
result = bitmap;
}
- return BitmapInfo.fromBitmap(result);
+ return BitmapInfo.fromBitmap(result, mDisableColorExtractor ? null : mColorExtractor);
}
/**
@@ -245,6 +249,14 @@
mWrapperBackgroundColor = (Color.alpha(color) < 255) ? DEFAULT_WRAPPER_BACKGROUND : color;
}
+ /**
+ * Disables the dominant color extraction for all icons loaded through this session (until
+ * this instance is recycled).
+ */
+ public void disableColorExtraction() {
+ mDisableColorExtractor = true;
+ }
+
private Drawable normalizeAndWrapToAdaptiveIcon(Drawable icon, int iconAppTargetSdk,
RectF outIconBounds, float[] outScale) {
float scale = 1f;
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/dynamicui/WallpaperManagerCompatVL.java b/src_ui_overrides/com/android/launcher3/uioverrides/dynamicui/WallpaperManagerCompatVL.java
index 4a8bbbd..7529f17 100644
--- a/src_ui_overrides/com/android/launcher3/uioverrides/dynamicui/WallpaperManagerCompatVL.java
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/dynamicui/WallpaperManagerCompatVL.java
@@ -18,7 +18,6 @@
import static android.app.WallpaperManager.FLAG_SYSTEM;
import static com.android.launcher3.Utilities.getDevicePrefs;
-import static com.android.launcher3.graphics.ColorExtractor.findDominantColorByHue;
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
@@ -47,6 +46,7 @@
import android.util.Pair;
import com.android.launcher3.Utilities;
+import com.android.launcher3.graphics.ColorExtractor;
import java.io.IOException;
import java.util.ArrayList;
@@ -169,6 +169,7 @@
private HandlerThread mWorkerThread;
private Handler mWorkerHandler;
+ private ColorExtractor mColorExtractor;
@Override
public void onCreate() {
@@ -176,6 +177,7 @@
mWorkerThread = new HandlerThread("ColorExtractionService");
mWorkerThread.start();
mWorkerHandler = new Handler(mWorkerThread.getLooper());
+ mColorExtractor = new ColorExtractor();
}
@Override
@@ -258,7 +260,8 @@
String value = VERSION_PREFIX + wallpaperId;
if (bitmap != null) {
- int color = findDominantColorByHue(bitmap, MAX_WALLPAPER_EXTRACTION_AREA);
+ int color = mColorExtractor.findDominantColorByHue(bitmap,
+ MAX_WALLPAPER_EXTRACTION_AREA);
value += "," + color;
}
diff --git a/tests/Android.mk b/tests/Android.mk
index 7a7d203..180fc0c 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -17,7 +17,8 @@
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator mockito-target-minus-junit4
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator mockito-target-minus-junit4 \
+ ub-launcher-aosp-tapl
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_FULL_LIBS_MANIFEST_FILES := $(LOCAL_PATH)/AndroidManifest-common.xml
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index dd91fe8..46a6446 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -15,6 +15,9 @@
*/
package com.android.launcher3.ui;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
import android.app.Instrumentation;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -36,24 +39,30 @@
import android.util.Log;
import android.view.MotionEvent;
+import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.LauncherState;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.LauncherAppsCompat;
+import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.testcomponent.AppWidgetNoConfig;
import com.android.launcher3.testcomponent.AppWidgetWithConfig;
+import com.android.launcher3.util.Condition;
+import com.android.launcher3.util.Wait;
+import com.android.launcher3.util.rule.LauncherActivityRule;
import org.junit.Before;
+import org.junit.Rule;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import java.util.function.Consumer;
+import java.util.function.Function;
/**
* Base class for all instrumentation tests providing various utility methods.
@@ -65,19 +74,23 @@
public static final long SHORT_UI_TIMEOUT= 300;
public static final long DEFAULT_UI_TIMEOUT = 3000;
- public static final long LARGE_UI_TIMEOUT = 10000;
public static final long DEFAULT_WORKER_TIMEOUT_SECS = 5;
protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
protected UiDevice mDevice;
+ protected LauncherInstrumentation mLauncher;
protected Context mTargetContext;
protected String mTargetPackage;
private static final String TAG = "AbstractLauncherUiTest";
+ @Rule
+ public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
+
@Before
public void setUp() throws Exception {
mDevice = UiDevice.getInstance(getInstrumentation());
+ mLauncher = new LauncherInstrumentation(mDevice);
mTargetContext = InstrumentationRegistry.getTargetContext();
mTargetPackage = mTargetContext.getPackageName();
}
@@ -236,6 +249,33 @@
}
}
+ protected <T> T getFromLauncher(Function<Launcher, T> f) {
+ return getOnUiThread(() -> f.apply(mActivityMonitor.getActivity()));
+ }
+
+ protected void executeOnLauncher(Consumer<Launcher> f) {
+ getFromLauncher(launcher -> {
+ f.accept(launcher);
+ return null;
+ });
+ }
+
+ // Cannot be used between a Tapl call injecting a gesture and a tapl call expecting the
+ // results of that gesture because the wait can hide flakeness.
+ protected boolean waitForState(LauncherState state) {
+ return waitForLauncherCondition(launcher -> launcher.getStateManager().getState() == state);
+ }
+
+ // Cannot be used after injecting any gesture using Tapl because this can hide flakiness.
+ protected boolean waitForLauncherCondition(Function<Launcher, Boolean> condition) {
+ return Wait.atMost(new Condition() {
+ @Override
+ public boolean isTrue() {
+ return getFromLauncher(condition);
+ }
+ }, DEFAULT_ACTIVITY_TIMEOUT);
+ }
+
/**
* Finds a widget provider which can fit on the home screen.
* @param hasConfigureScreen if true, a provider with a config screen is returned.
diff --git a/tests/src/com/android/launcher3/ui/AllAppsAppLaunchTest.java b/tests/src/com/android/launcher3/ui/AllAppsAppLaunchTest.java
deleted file mode 100644
index b95a850..0000000
--- a/tests/src/com/android/launcher3/ui/AllAppsAppLaunchTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.android.launcher3.ui;
-
-import android.content.pm.LauncherActivityInfo;
-import android.support.test.filters.LargeTest;
-import android.support.test.runner.AndroidJUnit4;
-import android.support.test.uiautomator.By;
-import android.support.test.uiautomator.UiObject2;
-import android.support.test.uiautomator.Until;
-
-import com.android.launcher3.util.Condition;
-import com.android.launcher3.util.Wait;
-import com.android.launcher3.util.rule.LauncherActivityRule;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Test for verifying apps is launched from all-apps
- */
-@LargeTest
-@RunWith(AndroidJUnit4.class)
-public class AllAppsAppLaunchTest extends AbstractLauncherUiTest {
-
- @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
-
- @Test
- public void testAppLauncher_portrait() throws Exception {
- lockRotation(true);
- performTest();
- }
-
- @Test
- public void testAppLauncher_landscape() throws Exception {
- lockRotation(false);
- performTest();
- }
-
- private void performTest() throws Exception {
- mActivityMonitor.startLauncher();
-
- LauncherActivityInfo testApp = getChromeApp();
-
- // Open all apps and wait for load complete
- final UiObject2 appsContainer = openAllApps();
- assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));
-
- // Open app and verify app launched
- scrollAndFind(appsContainer, By.text(testApp.getLabel().toString())).click();
- assertTrue(mDevice.wait(Until.hasObject(By.pkg(
- testApp.getComponentName().getPackageName()).depth(0)), DEFAULT_UI_TIMEOUT));
- }
-}
diff --git a/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java b/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java
index 00f30ad..8b9c584 100644
--- a/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java
+++ b/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java
@@ -1,5 +1,7 @@
package com.android.launcher3.ui;
+import static org.junit.Assert.assertTrue;
+
import android.content.pm.LauncherActivityInfo;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
@@ -9,15 +11,12 @@
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
-import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.assertTrue;
-
/**
* Test for dragging an icon from all-apps to homescreen.
*/
@@ -25,7 +24,6 @@
@RunWith(AndroidJUnit4.class)
public class AllAppsIconToHomeTest extends AbstractLauncherUiTest {
- @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher();
@Test
diff --git a/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java b/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java
index 69f6c87..f913470 100644
--- a/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java
+++ b/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java
@@ -1,5 +1,8 @@
package com.android.launcher3.ui;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import android.content.pm.LauncherActivityInfo;
import android.graphics.Point;
import android.support.test.filters.LargeTest;
@@ -12,16 +15,12 @@
import com.android.launcher3.R;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
-import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
/**
* Test for verifying that shortcuts are shown and can be launched after long pressing an app
*/
@@ -29,7 +28,6 @@
@RunWith(AndroidJUnit4.class)
public class ShortcutsLaunchTest extends AbstractLauncherUiTest {
- @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher();
@Test
diff --git a/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java b/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java
index fad06a6..4f5c113 100644
--- a/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java
+++ b/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java
@@ -1,5 +1,8 @@
package com.android.launcher3.ui;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import android.content.pm.LauncherActivityInfo;
import android.graphics.Point;
import android.support.test.filters.LargeTest;
@@ -12,16 +15,12 @@
import com.android.launcher3.R;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
-import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
/**
* Test for dragging a deep shortcut to the home screen.
*/
@@ -29,7 +28,6 @@
@RunWith(AndroidJUnit4.class)
public class ShortcutsToHomeTest extends AbstractLauncherUiTest {
- @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher();
@Test
diff --git a/tests/src/com/android/launcher3/ui/WorkTabTest.java b/tests/src/com/android/launcher3/ui/WorkTabTest.java
index 6244434..2f867f3 100644
--- a/tests/src/com/android/launcher3/ui/WorkTabTest.java
+++ b/tests/src/com/android/launcher3/ui/WorkTabTest.java
@@ -15,15 +15,13 @@
*/
package com.android.launcher3.ui;
+import static com.android.launcher3.LauncherState.ALL_APPS;
+
+import static org.junit.Assert.assertTrue;
+
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
-import android.support.test.uiautomator.UiObject2;
-import android.support.test.uiautomator.Until;
-import com.android.launcher3.R;
-import com.android.launcher3.util.Condition;
-import com.android.launcher3.util.Wait;
-import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import org.junit.After;
@@ -32,14 +30,10 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.assertTrue;
-
@LargeTest
@RunWith(AndroidJUnit4.class)
public class WorkTabTest extends AbstractLauncherUiTest {
@Rule
- public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
- @Rule
public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher();
private int mProfileUserId;
@@ -66,17 +60,13 @@
public void workTabExists() {
mActivityMonitor.startLauncher();
- // Open all apps and wait for load complete
- final UiObject2 appsContainer = openAllApps();
- assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2),
- LARGE_UI_TIMEOUT));
+ executeOnLauncher(launcher -> launcher.getStateManager().goToState(ALL_APPS));
/*
- assertTrue("Personal tab is missing",
- mDevice.wait(Until.hasObject(getSelectorForId(R.id.tab_personal)),
- LARGE_UI_TIMEOUT));
- assertTrue("Work tab is missing",
- mDevice.wait(Until.hasObject(getSelectorForId(R.id.tab_work)), LARGE_UI_TIMEOUT));
+ assertTrue("Personal tab is missing", waitForLauncherCondition(
+ launcher -> launcher.getAppsView().isPersonalTabVisible()));
+ assertTrue("Work tab is missing", waitForLauncherCondition(
+ launcher -> launcher.getAppsView().isWorkTabVisible()));
*/
}
}
\ No newline at end of file
diff --git a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java
index a5c2e69..7f6dd44 100644
--- a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java
@@ -15,6 +15,11 @@
*/
package com.android.launcher3.ui.widget;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.support.test.filters.LargeTest;
@@ -31,7 +36,6 @@
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
-import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import com.android.launcher3.widget.WidgetCell;
@@ -40,11 +44,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-
/**
* Test to verify widget configuration is properly shown.
*/
@@ -52,7 +51,6 @@
@RunWith(AndroidJUnit4.class)
public class AddConfigWidgetTest extends AbstractLauncherUiTest {
- @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grandWidgetBind();
private LauncherAppWidgetProviderInfo mWidgetInfo;
@@ -126,12 +124,8 @@
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
} else {
// Verify that the widget id is deleted.
- assertTrue(Wait.atMost(new Condition() {
- @Override
- public boolean isTrue() throws Throwable {
- return mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null;
- }
- }, DEFAULT_ACTIVITY_TIMEOUT));
+ assertTrue(Wait.atMost(() -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null,
+ DEFAULT_ACTIVITY_TIMEOUT));
}
}
@@ -145,8 +139,7 @@
/**
* Condition for searching widget id
*/
- private class WidgetSearchCondition extends Condition
- implements Workspace.ItemOperator {
+ private class WidgetSearchCondition implements Condition, Workspace.ItemOperator {
@Override
public boolean isTrue() throws Throwable {
diff --git a/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java
index 19f7db7..d89f26e 100644
--- a/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java
@@ -15,6 +15,8 @@
*/
package com.android.launcher3.ui.widget;
+import static org.junit.Assert.assertTrue;
+
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
@@ -28,7 +30,6 @@
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
-import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import com.android.launcher3.widget.WidgetCell;
@@ -36,8 +37,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.junit.Assert.assertTrue;
-
/**
* Test to add widget from widget tray
*/
@@ -45,7 +44,6 @@
@RunWith(AndroidJUnit4.class)
public class AddWidgetTest extends AbstractLauncherUiTest {
- @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grandWidgetBind();
@Test
diff --git a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
index b557119..c8c3896 100644
--- a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
@@ -15,6 +15,11 @@
*/
package com.android.launcher3.ui.widget;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
@@ -30,21 +35,20 @@
import android.support.test.uiautomator.UiSelector;
import com.android.launcher3.LauncherAppWidgetHost;
-import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.Workspace;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.util.LooperExecutor;
-import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
+import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.PendingAddWidgetInfo;
+import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.widget.WidgetHostViewLoader;
import org.junit.After;
@@ -58,11 +62,6 @@
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
/**
* Tests for bind widget flow.
*
@@ -72,7 +71,6 @@
@RunWith(AndroidJUnit4.class)
public class BindWidgetTest extends AbstractLauncherUiTest {
- @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grandWidgetBind();
private ContentResolver mResolver;
diff --git a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
index dcb564a..ec0a051 100644
--- a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
@@ -15,6 +15,10 @@
*/
package com.android.launcher3.ui.widget;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
@@ -40,7 +44,6 @@
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
-import com.android.launcher3.util.rule.LauncherActivityRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import com.android.launcher3.widget.WidgetCell;
@@ -52,10 +55,6 @@
import java.util.UUID;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-
/**
* Test to verify pin item request flow.
*/
@@ -63,7 +62,6 @@
@RunWith(AndroidJUnit4.class)
public class RequestPinItemTest extends AbstractLauncherUiTest {
- @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grandWidgetBind();
@Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher();
@@ -200,7 +198,7 @@
/**
* Condition for for an item
*/
- private class ItemSearchCondition extends Condition {
+ private class ItemSearchCondition implements Condition {
private final ItemOperator mOp;
diff --git a/tests/src/com/android/launcher3/util/Condition.java b/tests/src/com/android/launcher3/util/Condition.java
index e9ee67c..78c652a 100644
--- a/tests/src/com/android/launcher3/util/Condition.java
+++ b/tests/src/com/android/launcher3/util/Condition.java
@@ -8,47 +8,36 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-public abstract class Condition {
+public interface Condition {
- public abstract boolean isTrue() throws Throwable;
+ boolean isTrue() throws Throwable;
/**
* Converts the condition to be run on UI thread.
*/
- public static Condition runOnUiThread(final Condition condition) {
+ static Condition runOnUiThread(final Condition condition) {
final MainThreadExecutor executor = new MainThreadExecutor();
- return new Condition() {
- @Override
- public boolean isTrue() throws Throwable {
- final AtomicBoolean value = new AtomicBoolean(false);
- final Throwable[] exceptions = new Throwable[1];
- final CountDownLatch latch = new CountDownLatch(1);
- executor.execute(new Runnable() {
- @Override
- public void run() {
- try {
- value.set(condition.isTrue());
- } catch (Throwable e) {
- exceptions[0] = e;
- }
-
- }
- });
- latch.await(1, TimeUnit.SECONDS);
- if (exceptions[0] != null) {
- throw exceptions[0];
+ return () -> {
+ final AtomicBoolean value = new AtomicBoolean(false);
+ final Throwable[] exceptions = new Throwable[1];
+ final CountDownLatch latch = new CountDownLatch(1);
+ executor.execute(() -> {
+ try {
+ value.set(condition.isTrue());
+ } catch (Throwable e) {
+ exceptions[0] = e;
}
- return value.get();
+
+ });
+ latch.await(1, TimeUnit.SECONDS);
+ if (exceptions[0] != null) {
+ throw exceptions[0];
}
+ return value.get();
};
}
- public static Condition minChildCount(final UiObject2 obj, final int childCount) {
- return new Condition() {
- @Override
- public boolean isTrue() {
- return obj.getChildCount() >= childCount;
- }
- };
+ static Condition minChildCount(final UiObject2 obj, final int childCount) {
+ return () -> obj.getChildCount() >= childCount;
}
}