diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-09 19:10:44 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-09 19:10:44 +0000 |
commit | eb3f9d5ce447dbebe1bf19dffd520c8f39e95417 (patch) | |
tree | 07f9f8552c239f305bb68b9861dde51757fb334e | |
parent | 5c4ed33547da3cc3ce7fe06989c47e6762aa6e90 (diff) | |
parent | f1744af64eb2460238b68009ce24aa9d63f43c61 (diff) | |
download | platform_testing-oreo-m2-s2-release.tar.gz |
Snap for 4384531 from f1744af64eb2460238b68009ce24aa9d63f43c61 to oc-m2-releaseandroid-8.1.0_r8android-8.1.0_r52android-8.1.0_r50android-8.1.0_r47android-8.1.0_r46android-8.1.0_r43android-8.1.0_r41android-8.1.0_r36android-8.1.0_r35android-8.1.0_r33android-8.1.0_r30android-8.1.0_r26android-8.1.0_r25android-8.1.0_r20android-8.1.0_r2oreo-m7-releaseoreo-m6-s4-releaseoreo-m6-s3-releaseoreo-m6-s2-releaseoreo-m2-s5-releaseoreo-m2-s4-releaseoreo-m2-s3-releaseoreo-m2-s2-releaseoreo-m2-s1-releaseoreo-m2-release
Change-Id: I4df874595cdb6eb8def216686c770128ce30e0e6
-rw-r--r-- | libraries/aupt-lib/src/android/support/test/aupt/AuptTestRunner.java | 11 | ||||
-rw-r--r-- | libraries/launcher-helper/src/android/support/test/launcherhelper/TvLauncherStrategy.java | 74 |
2 files changed, 67 insertions, 18 deletions
diff --git a/libraries/aupt-lib/src/android/support/test/aupt/AuptTestRunner.java b/libraries/aupt-lib/src/android/support/test/aupt/AuptTestRunner.java index 2603abb4f..1cf66cd99 100644 --- a/libraries/aupt-lib/src/android/support/test/aupt/AuptTestRunner.java +++ b/libraries/aupt-lib/src/android/support/test/aupt/AuptTestRunner.java @@ -204,7 +204,11 @@ public class AuptTestRunner extends InstrumentationTestRunner { injectInstrumentation(test); } - super.runTest(result); + try { + super.runTest(result); + } finally { + mDataCollector.stop(); + } } }; @@ -228,11 +232,6 @@ public class AuptTestRunner extends InstrumentationTestRunner { super.onCreate(params); } - @Override - public void onDestroy() { - mDataCollector.stop(); - } - /* Option-parsing helpers */ private long parseLongParam(String key, long alternative) throws NumberFormatException { diff --git a/libraries/launcher-helper/src/android/support/test/launcherhelper/TvLauncherStrategy.java b/libraries/launcher-helper/src/android/support/test/launcherhelper/TvLauncherStrategy.java index 99dddd003..6f9ad537d 100644 --- a/libraries/launcher-helper/src/android/support/test/launcherhelper/TvLauncherStrategy.java +++ b/libraries/launcher-helper/src/android/support/test/launcherhelper/TvLauncherStrategy.java @@ -18,7 +18,9 @@ package android.support.test.launcherhelper; import android.app.Instrumentation; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Point; import android.os.RemoteException; import android.os.SystemClock; @@ -43,9 +45,11 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { private static final String LOG_TAG = TvLauncherStrategy.class.getSimpleName(); private static final String PACKAGE_LAUNCHER = "com.google.android.tvlauncher"; private static final String PACKAGE_SETTINGS = "com.android.tv.settings"; - private static final String CHANNEL_TITLE_WATCH_NEXT = "Watch Next"; + // Build version + private static final int BUILD_INT_BANDGAP = 1010100000; + // Wait time private static final int UI_APP_LAUNCH_WAIT_TIME_MS = 10000; private static final int UI_WAIT_TIME_MS = 5000; @@ -215,6 +219,31 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { } /** + * Get the launcher's version code. + * @return the version code. -1 if the launcher package is not found. + */ + public int getVersionCode() { + String pkg = getSupportedLauncherPackage(); + if (null == pkg || pkg.isEmpty()) { + throw new RuntimeException("Can't find version of empty package"); + } + if (mInstrumentation == null) { + Log.w(LOG_TAG, "Instrumentation is null. setInstrumentation should be called " + + "to get the version code"); + return -1; + } + PackageManager pm = mInstrumentation.getContext().getPackageManager(); + PackageInfo pInfo = null; + try { + pInfo = pm.getPackageInfo(pkg, 0); + return pInfo.versionCode; + } catch (NameNotFoundException e) { + Log.w(LOG_TAG, String.format("package name is not found: %s", pkg)); + return -1; + } + } + + /** * {@inheritDoc} */ @Override @@ -278,6 +307,10 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { * Returns a {@link BySelector} describing a given app in Apps View */ public BySelector getAppInAppsViewSelector(String appName) { + if (getVersionCode() > BUILD_INT_BANDGAP) { + // bandgap or higher + return By.res(getSupportedLauncherPackage(), "banner_image").desc(appName); + } return By.res(getSupportedLauncherPackage(), "app_title").text(appName); } @@ -553,11 +586,11 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { * down to the next row like a zigzag pattern until the app is found. */ protected UiObject2 selectAppInAllApps(BySelector appSelector, String packageName) { - openAllApps(true); + Assert.assertTrue(mDevice.hasObject(getAllAppsSelector())); // Assume that the focus always starts at the top left of the Apps view. final int maxScrollAttempts = 20; - final int margin = 10; + final int margin = 30; int attempts = 0; UiObject2 focused = null; UiObject2 expected = null; @@ -568,8 +601,8 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { if (expected == null) { mDPadUtil.pressDPadDown(); continue; - } else if (focused.getVisibleCenter().equals(expected.getVisibleCenter())) { - // The app icon is on the screen, and selected. + } else if (focused.hasObject(appSelector)) { + // The app icon is selected. Log.i(LOG_TAG, String.format("The app %s is selected", packageName)); break; } else { @@ -579,6 +612,7 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { Point targetPosition = expected.getVisibleCenter(); int dx = targetPosition.x - currentPosition.x; int dy = targetPosition.y - currentPosition.y; + Log.d(LOG_TAG, String.format("selectAppInAllApps: [dx,dx][%d,%d]", dx, dy)); if (dy > margin) { mDPadUtil.pressDPadDown(); continue; @@ -608,8 +642,8 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { * Search from left to right, and down to the next row, from right to left, and * down to the next row like a zigzag pattern until it founds a given app. */ - public UiObject2 selectAppInAllAppsZigZag(BySelector appSelector, String packageName) { - openAllApps(true); + protected UiObject2 selectAppInAllAppsZigZag(BySelector appSelector, String packageName) { + Assert.assertTrue(mDevice.hasObject(getAllAppsSelector())); Direction direction = Direction.RIGHT; UiObject2 app = select(appSelector, direction, UI_TRANSITION_WAIT_TIME_MS); while (app == null && move(Direction.DOWN)) { @@ -623,13 +657,31 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { } /** + * Select the given app in All Apps using the versioned BySelector for the app + */ + public UiObject2 selectAppInAllApps(String appName, String packageName) { + UiObject2 app = null; + int versionCode = getVersionCode(); + if (versionCode > BUILD_INT_BANDGAP) { + // bandgap or higher + Log.i(LOG_TAG, + String.format("selectAppInAllApps: app banner has app name [versionCode]%d", + versionCode)); + app = selectAppInAllApps(getAppInAppsViewSelector(appName), packageName); + } else { + app = selectAppInAllAppsZigZag(getAppInAppsViewSelector(appName), packageName); + } + return app; + } + + /** * Launch the given app in the Apps view. */ public boolean launchAppInAppsView(String appName, String packageName) { Log.d(LOG_TAG, String.format("launching in apps view [appName]%s [packageName]%s", appName, packageName)); openAllApps(true); - UiObject2 app = selectAppInAllAppsZigZag(getAppInAppsViewSelector(appName), packageName); + UiObject2 app = selectAppInAllApps(appName, packageName); if (app == null) { throw new RuntimeException( "Failed to navigate to the app icon in the Apps view: " + packageName); @@ -667,9 +719,7 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { app = selectBidirect(By.copy(favAppSelector).focused(true), Direction.RIGHT); } else { openAllApps(true); - // Find app in Apps View in zigzag mode with app selector for Apps View - // because the app title no longer appears until focused. - app = selectAppInAllAppsZigZag(getAppInAppsViewSelector(appName), packageName); + app = selectAppInAllApps(appName, packageName); } if (app == null) { throw new RuntimeException( @@ -739,7 +789,7 @@ public class TvLauncherStrategy implements ILeanbackLauncherStrategy { isGame = (appInfo.metaData != null && appInfo.metaData.getBoolean("isGame", false)) || ((appInfo.flags & ApplicationInfo.FLAG_IS_GAME) != 0); Log.i(LOG_TAG, String.format("The package %s isGame: %b", packageName, isGame)); - } catch (PackageManager.NameNotFoundException e) { + } catch (NameNotFoundException e) { Log.w(LOG_TAG, String.format("No package found: %s, error:%s", packageName, e.toString())); return false; |