From 2c6316be46e258a91d414916fcfab98f8dece0ea Mon Sep 17 00:00:00 2001 From: vadimt Date: Tue, 21 Jan 2020 18:55:28 -0800 Subject: [PATCH 01/63] Adding auto-investigation of one more flake Reshuffling the tests to make the investigator the outmost rule and run the code that throws the original exception inside the investigator. Change-Id: I714717a9b616862db5ce59116138ba7ea6ceb971 --- .../quickstep/FallbackRecentsTest.java | 5 +- .../StartLauncherViaGestureTests.java | 3 -- .../launcher3/ui/AbstractLauncherUiTest.java | 8 +-- .../util/rule/FailureInvestigator.java | 6 +++ .../util/rule/FailureRewriterRule.java | 54 +++++++++++++++++++ .../launcher3/util/rule/FailureWatcher.java | 27 ---------- .../util/rule/TestStabilityRule.java | 5 +- 7 files changed, 72 insertions(+), 36 deletions(-) create mode 100644 tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index 85cffaa107..04e32b0d28 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -56,6 +56,7 @@ import com.android.launcher3.tapl.OverviewTask; import com.android.launcher3.tapl.TestHelpers; import com.android.launcher3.testcomponent.TestCommandReceiver; import com.android.launcher3.util.Wait; +import com.android.launcher3.util.rule.FailureRewriterRule; import com.android.launcher3.util.rule.FailureWatcher; import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch; import com.android.quickstep.views.RecentsView; @@ -99,7 +100,9 @@ public class FallbackRecentsTest { Utilities.enableRunningInTestHarnessForTests(); } - mOrderSensitiveRules = RuleChain.outerRule(new NavigationModeSwitchRule(mLauncher)) + mOrderSensitiveRules = RuleChain + .outerRule(new FailureRewriterRule()) + .around(new NavigationModeSwitchRule(mLauncher)) .around(new FailureWatcher(mDevice)); mOtherLauncherActivity = context.getPackageManager().queryIntentActivities( diff --git a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java index 891bf240df..3d048a6413 100644 --- a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java +++ b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java @@ -18,9 +18,6 @@ package com.android.quickstep; import static com.android.launcher3.util.RaceConditionReproducer.enterEvt; import static com.android.launcher3.util.RaceConditionReproducer.exitEvt; -import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_PRESUBMIT; -import static com.android.launcher3.util.rule.TestStabilityRule.RUN_FLAFOR; -import static com.android.launcher3.util.rule.TestStabilityRule.UNBUNDLED_PRESUBMIT; import android.content.Intent; diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 60dad12483..ace04f3156 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -62,6 +62,7 @@ import com.android.launcher3.util.ContentWriter; import com.android.launcher3.util.LooperExecutor; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.Wait; +import com.android.launcher3.util.rule.FailureRewriterRule; import com.android.launcher3.util.rule.FailureWatcher; import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; @@ -161,9 +162,10 @@ public abstract class AbstractLauncherUiTest { @Rule public TestRule mOrderSensitiveRules = RuleChain. - outerRule(new TestStabilityRule()). - around(mActivityMonitor). - around(getRulesInsideActivityMonitor()); + outerRule(new FailureRewriterRule()) + .around(new TestStabilityRule()) + .around(mActivityMonitor) + .around(getRulesInsideActivityMonitor()); public UiDevice getDevice() { return mDevice; diff --git a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java index 56c885d85b..cada8d6fb1 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java +++ b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java @@ -47,6 +47,12 @@ class FailureInvestigator { logSinceTestsStart)) { return 147845913; } + } else if (matches("java.lang.AssertionError: Launcher build match not found", exception)) { + if (matches( + "TestStabilityRule: Launcher package: com.google.android.setupwizard", + logSinceTestsStart)) { + return 145935261; + } } return 0; diff --git a/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java b/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java new file mode 100644 index 0000000000..4cb309a34a --- /dev/null +++ b/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2020 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.util.rule; + +import android.util.Log; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class FailureRewriterRule implements TestRule { + private static final String TAG = "FailureRewriter"; + + private static final String testsStartTime = + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()); + + @Override + public Statement apply(Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + try { + base.evaluate(); + } catch (Throwable e) { + final int bug = + FailureInvestigator.getBugForFailure(e.toString(), testsStartTime); + if (bug == 0) throw e; + + Log.e(TAG, "Known bug found for the original failure " + + android.util.Log.getStackTraceString(e)); + throw new AssertionError( + "Detected a failure that matches a known bug b/" + bug); + } + } + }; + } +} diff --git a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java index feb89b925f..cdda0f0dcc 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java +++ b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java @@ -8,13 +8,10 @@ import androidx.test.uiautomator.UiDevice; import org.junit.rules.TestWatcher; import org.junit.runner.Description; -import org.junit.runners.model.Statement; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; public class FailureWatcher extends TestWatcher { private static final String TAG = "FailureWatcher"; @@ -38,30 +35,6 @@ public class FailureWatcher extends TestWatcher { } } - private static final String testsStartTime = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()); - - @Override - public Statement apply(Statement base, Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - try { - base.evaluate(); - } catch (Throwable e) { - final int bug = - FailureInvestigator.getBugForFailure(e.toString(), testsStartTime); - if (bug == 0) throw e; - - Log.e(TAG, "Known bug found for the original failure " - + android.util.Log.getStackTraceString(e)); - throw new AssertionError( - "Detected a failure that matches a known bug b/" + bug); - } - } - }; - } - @Override protected void failed(Throwable e, Description description) { onError(mDevice, description, e); diff --git a/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java b/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java index b394bcbd18..1feb4e736a 100644 --- a/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java +++ b/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java @@ -58,7 +58,7 @@ public class TestStabilityRule implements TestRule { public static final int PLATFORM_PRESUBMIT = 0x8; public static final int PLATFORM_POSTSUBMIT = 0x10; - public static final int RUN_FLAFOR = getRunFlavor(); + private static int sRunFlavor; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @@ -73,7 +73,8 @@ public class TestStabilityRule implements TestRule { return new Statement() { @Override public void evaluate() throws Throwable { - if ((stability.flavors() & RUN_FLAFOR) != 0) { + if (sRunFlavor == 0) sRunFlavor = getRunFlavor(); + if ((stability.flavors() & sRunFlavor) != 0) { Log.d(TAG, "Running " + description.getDisplayName()); base.evaluate(); } else { From 29d8b5495799ce98e103a51609bf56d89d7e4186 Mon Sep 17 00:00:00 2001 From: vadimt Date: Fri, 17 Jan 2020 18:31:42 -0800 Subject: [PATCH 02/63] Disabling events checks for successful gestures by default Launcher tests will still perform checks upon every gesture completion. All tests using tapl will still use events for diagnostics if the gesture fails. The benefit is that system health and other platform tests won't have to use expensive logcat, and moreover, wait seconds for the events to appear in logcat because of buffering in logcat. Change-Id: I3b5a0965d9432144d0c4a8b40ebe2fa89b19a689 --- .../src/com/android/quickstep/FallbackRecentsTest.java | 1 + .../android/launcher3/ui/AbstractLauncherUiTest.java | 1 + .../launcher3/tapl/LauncherInstrumentation.java | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index 85cffaa107..dde318ebc1 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -94,6 +94,7 @@ public class FallbackRecentsTest { mDevice = UiDevice.getInstance(instrumentation); mDevice.setOrientationNatural(); mLauncher = new LauncherInstrumentation(); + mLauncher.enableCheckEventsForSuccessfulGestures(); if (TestHelpers.isInLauncherProcess()) { Utilities.enableRunningInTestHarnessForTests(); diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 60dad12483..f4334b0e3d 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -102,6 +102,7 @@ public abstract class AbstractLauncherUiTest { protected String mTargetPackage; protected AbstractLauncherUiTest() { + mLauncher.enableCheckEventsForSuccessfulGestures(); try { mDevice.setOrientationNatural(); } catch (RemoteException e) { diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 63ec998615..a510df52d6 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -168,6 +168,7 @@ public final class LauncherInstrumentation { private List mExpectedEvents; private String mTimeBeforeFirstLogEvent; + private boolean mCheckEventsForSuccessfulGestures = false; private static Pattern getTouchEventPattern(String action) { // The pattern includes sanity checks that we don't get a multi-touch events or other @@ -239,6 +240,10 @@ public final class LauncherInstrumentation { } } + public void enableCheckEventsForSuccessfulGestures() { + mCheckEventsForSuccessfulGestures = true; + } + Context getContext() { return mInstrumentation.getContext(); } @@ -1219,6 +1224,11 @@ public final class LauncherInstrumentation { return; // There was a failure. Noo need to report another one. } + if (!mCheckEventsForSuccessfulGestures) { + stopRecordingEvents(); + return; + } + final String message = getEventMismatchMessage(true); if (message != null) { Assert.fail(formatSystemHealthMessage( From ff7cd03d43310c06a677f8962b5bdc42e2588d48 Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 23 Jan 2020 13:40:54 -0800 Subject: [PATCH 03/63] More readable formatting for events mismatch message This helps for longer event lists. Change-Id: Ie3565d2ccdde27d23770d01b4f9d4680bd8e229b --- .../tapl/LauncherInstrumentation.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index a510df52d6..71544444a7 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -411,7 +411,7 @@ public final class LauncherInstrumentation { final String eventMismatch = getEventMismatchMessage(false); if (eventMismatch != null) { - message = message + ",\nhaving produced wrong events:\n " + eventMismatch; + message = message + ", having produced " + eventMismatch; } Assert.fail(formatSystemHealthMessage(message)); @@ -1262,7 +1262,7 @@ public final class LauncherInstrumentation { return formatEventMismatchMessage("too few actual events", actual, i); } if (!mExpectedEvents.get(i).matcher(actual.get(i)).find()) { - return formatEventMismatchMessage("mismatched event", actual, i); + return formatEventMismatchMessage("a mismatched event", actual, i); } } @@ -1277,9 +1277,20 @@ public final class LauncherInstrumentation { return null; } + private String formatEventList(List events, int position) { + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < events.size(); ++i) { + sb.append("\n| "); + sb.append(i == position ? "---> " : " "); + sb.append(events.get(i).toString()); + } + if (position == events.size()) sb.append("\n| ---> (end)"); + return sb.toString(); + } + private String formatEventMismatchMessage(String message, List actual, int position) { - return message + ", pos=" + position - + ", expected=" + mExpectedEvents - + ", actual=" + actual; + return message + ":" + + "\nExpected:" + formatEventList(mExpectedEvents, position) + + "\nActual:" + formatEventList(actual, position); } } \ No newline at end of file From daed31893085cc52c2db5dd17b4092df9bcf4398 Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 23 Jan 2020 15:19:46 -0800 Subject: [PATCH 04/63] Recognizing a Launcher ANR Change-Id: Ib26df7b6e9f9e6b85f93d2aa2a4a0204430e304f --- .../android/launcher3/util/rule/FailureInvestigator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java index cada8d6fb1..831685a57e 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java +++ b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java @@ -53,6 +53,14 @@ class FailureInvestigator { logSinceTestsStart)) { return 145935261; } + } else if (matches("Launcher didn't initialize", exception)) { + if (matches( + "ActivityManager: Reason: executing service com.google.android.apps" + + ".nexuslauncher/com.android.launcher3.notification" + + ".NotificationListener", + logSinceTestsStart)) { + return 148238677; + } } return 0; From 68c57419c05f10ccce61a6412c4ac19c1aaa3160 Mon Sep 17 00:00:00 2001 From: Samuel Fufa Date: Thu, 23 Jan 2020 16:41:07 -0800 Subject: [PATCH 05/63] Log App Predictions from AiAi + Update edu screen strings Bug:142753423 Test:Manual Change-Id: If2424d134a5f9d2cafa248949a249ee2c7296276 --- .../hybridhotseat/HotseatPredictionController.java | 8 ++++++++ quickstep/res/values/strings.xml | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java index 8f6081bd69..c2b55ab0c9 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java @@ -56,6 +56,7 @@ import com.android.launcher3.appprediction.DynamicItemCache; import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.logging.FileLog; import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.touch.ItemLongClickListener; @@ -300,6 +301,7 @@ public class HotseatPredictionController implements DragController.DragListener, private void setPredictedApps(List appTargets) { mComponentKeyMappers.clear(); + StringBuilder predictionLog = new StringBuilder("predictedApps: [\n"); for (AppTarget appTarget : appTargets) { ComponentKey key; if (appTarget.getShortcutInfo() != null) { @@ -308,8 +310,14 @@ public class HotseatPredictionController implements DragController.DragListener, key = new ComponentKey(new ComponentName(appTarget.getPackageName(), appTarget.getClassName()), appTarget.getUser()); } + predictionLog.append(key.toString()); + predictionLog.append(",rank:"); + predictionLog.append(appTarget.getRank()); + predictionLog.append("\n"); mComponentKeyMappers.add(new ComponentKeyMapper(key, mDynamicItemCache)); } + predictionLog.append("]"); + FileLog.d(TAG, predictionLog.toString()); updateDependencies(); if (isReady()) { fillGapsWithPrediction(); diff --git a/quickstep/res/values/strings.xml b/quickstep/res/values/strings.xml index 2b21df8ed2..5f81e1f5e5 100644 --- a/quickstep/res/values/strings.xml +++ b/quickstep/res/values/strings.xml @@ -75,11 +75,11 @@ To pin a favorite app, drag it over a suggested app. To hide a suggested app, touch & hold it. - Your hotseat items have been moved to the last page. + Bottom row of apps moved to last screen - You can remove items from the hotseat manually to see suggested apps in their spot. + Bottom row won\'t be replaced. Manually drag apps for predictions. - I\'m in + Turn On No thanks From 8bcabc02c34f635b582d16368f99564b1d1fabe2 Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 23 Jan 2020 17:44:38 -0800 Subject: [PATCH 06/63] Logging the time that we use for the current events range It appears that sometimes logcat -d returns events that are earlier than that time, but we need to be sure. Example: ACTION_UP from the previous TAPL method: https://sponge.corp.google.com/target?show=FAILED&sortBy=STATUS&id=1aceab23-6d2a-4b2d-9630-47a74cafe7b9&target=com.google.android.apps.nexuslauncher.tests Change-Id: Ib83e1cc01402ef638f8ac8a0862e16c5773b82cd --- .../tapl/com/android/launcher3/tapl/LauncherInstrumentation.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 71544444a7..0a3462f4e1 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -1208,6 +1208,7 @@ public final class LauncherInstrumentation { mTimeBeforeFirstLogEvent = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") .format(new Date()) .replaceAll(" ", ""); + log("startRecordingEvents: " + mTimeBeforeFirstLogEvent); } private void stopRecordingEvents() { From 6098a8c8c046e2f3043edf2cb6172de13caf6c35 Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 23 Jan 2020 19:12:19 -0800 Subject: [PATCH 07/63] Adding events checking for Launcher starting apps Change-Id: Id651397f643280a9f99a470df029479bd1b41e5c --- .../src/com/android/quickstep/views/TaskView.java | 4 ++++ src/com/android/launcher3/BaseActivity.java | 4 ++++ src/com/android/launcher3/BaseDraggingActivity.java | 4 ++++ tests/tapl/com/android/launcher3/tapl/AppIcon.java | 9 +++++++++ .../com/android/launcher3/tapl/AppIconMenuItem.java | 10 ++++++++++ tests/tapl/com/android/launcher3/tapl/Background.java | 4 ++++ tests/tapl/com/android/launcher3/tapl/Launchable.java | 3 +++ .../tapl/com/android/launcher3/tapl/OverviewTask.java | 5 +++++ tests/tapl/com/android/launcher3/tapl/Widget.java | 4 ++++ 9 files changed, 47 insertions(+) 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 6e1b24a284..58e36bc8d0 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 @@ -57,6 +57,7 @@ import com.android.launcher3.anim.Interpolators; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.popup.SystemShortcut; +import com.android.launcher3.testing.TestLogging; import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch; @@ -331,6 +332,9 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { Consumer resultCallback, Handler resultCallbackHandler) { if (mTask != null) { final ActivityOptions opts; + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + TestLogging.recordEvent("startActivityFromRecentsAsync:" + mTask); + } if (animate) { opts = mActivity.getActivityLaunchOptions(this); if (freezeTaskList) { diff --git a/src/com/android/launcher3/BaseActivity.java b/src/com/android/launcher3/BaseActivity.java index 3ca4f5989d..f3c5191bbe 100644 --- a/src/com/android/launcher3/BaseActivity.java +++ b/src/com/android/launcher3/BaseActivity.java @@ -41,6 +41,7 @@ import com.android.launcher3.logging.StatsLogUtils; import com.android.launcher3.logging.StatsLogUtils.LogStateProvider; import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate; +import com.android.launcher3.testing.TestLogging; import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.util.SystemUiController; import com.android.launcher3.util.ViewCache; @@ -329,6 +330,9 @@ public abstract class BaseActivity extends Activity return; } try { + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + TestLogging.recordEvent("start: shortcut: " + packageName); + } getSystemService(LauncherApps.class).startShortcut(packageName, id, sourceBounds, startActivityOptions, user); } catch (SecurityException | IllegalStateException e) { diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index df15fc12fe..0283eac050 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -35,6 +35,7 @@ import androidx.annotation.Nullable; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.model.AppLaunchTracker; +import com.android.launcher3.testing.TestLogging; import com.android.launcher3.uioverrides.DisplayRotationListener; import com.android.launcher3.uioverrides.WallpaperColorInfo; import com.android.launcher3.util.PackageManagerHelper; @@ -164,6 +165,9 @@ public abstract class BaseDraggingActivity extends BaseActivity startShortcutIntentSafely(intent, optsBundle, item, sourceContainer); } else if (user == null || user.equals(Process.myUserHandle())) { // Could be launching some bookkeeping activity + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + TestLogging.recordEvent("start: activity: " + intent); + } startActivity(intent, optsBundle); AppLaunchTracker.INSTANCE.get(this).onStartApp(intent.getComponent(), Process.myUserHandle(), sourceContainer); diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java index 0a6ed7f2e9..3f814fd1eb 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java @@ -22,11 +22,15 @@ import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.UiObject2; +import java.util.regex.Pattern; + /** * App icon, whether in all apps or in workspace/ */ public final class AppIcon extends Launchable { + private static final Pattern START_EVENT = Pattern.compile("start:"); + AppIcon(LauncherInstrumentation launcher, UiObject2 icon) { super(launcher, icon); } @@ -49,4 +53,9 @@ public final class AppIcon extends Launchable { protected String getLongPressIndicator() { return "deep_shortcuts_container"; } + + @Override + protected void expectActivityStartEvents() { + mLauncher.expectEvent(START_EVENT); + } } diff --git a/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java b/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java index ba9c10e817..fadfd9ff38 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java @@ -18,10 +18,15 @@ package com.android.launcher3.tapl; import androidx.test.uiautomator.UiObject2; +import java.util.regex.Pattern; + /** * Menu item in an app icon menu. */ public class AppIconMenuItem extends Launchable { + + private static final Pattern START_SHORTCUT_EVENT = Pattern.compile("start: shortcut:"); + AppIconMenuItem(LauncherInstrumentation launcher, UiObject2 shortcut) { super(launcher, shortcut); } @@ -37,4 +42,9 @@ public class AppIconMenuItem extends Launchable { protected String getLongPressIndicator() { return "drop_target_bar"; } + + @Override + protected void expectActivityStartEvents() { + mLauncher.expectEvent(START_SHORTCUT_EVENT); + } } diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index c37e451a7d..5c4689bd15 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -16,6 +16,7 @@ package com.android.launcher3.tapl; +import static com.android.launcher3.tapl.OverviewTask.TASK_START_EVENT; import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; @@ -28,6 +29,8 @@ import androidx.test.uiautomator.UiObject2; import com.android.launcher3.testing.TestProtocol; +import java.util.regex.Pattern; + /** * Indicates the base state with a UI other than Overview running as foreground. It can also * indicate Launcher as long as Launcher is not in Overview state. @@ -191,6 +194,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer { recentsButton.click(); break; } + mLauncher.expectEvent(TASK_START_EVENT); } protected String getSwipeHeightRequestName() { diff --git a/tests/tapl/com/android/launcher3/tapl/Launchable.java b/tests/tapl/com/android/launcher3/tapl/Launchable.java index 1722d5b3a5..b20384ef6b 100644 --- a/tests/tapl/com/android/launcher3/tapl/Launchable.java +++ b/tests/tapl/com/android/launcher3/tapl/Launchable.java @@ -51,6 +51,8 @@ abstract class Launchable { } } + protected abstract void expectActivityStartEvents(); + private Background launch(BySelector selector) { LauncherInstrumentation.log("Launchable.launch before click " + mObject.getVisibleCenter() + " in " + mObject.getVisibleBounds()); @@ -59,6 +61,7 @@ abstract class Launchable { () -> mLauncher.clickLauncherObject(mObject), event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED, () -> "Launching an app didn't open a new window: " + mObject.getText()); + expectActivityStartEvents(); mLauncher.assertTrue( "App didn't start: " + selector, diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java index b21b2429a9..410e5a150f 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java @@ -22,10 +22,14 @@ import android.graphics.Rect; import androidx.test.uiautomator.UiObject2; +import java.util.regex.Pattern; + /** * A recent task in the overview panel carousel. */ public final class OverviewTask { + static final Pattern TASK_START_EVENT = + Pattern.compile("startActivityFromRecentsAsync"); private final LauncherInstrumentation mLauncher; private final UiObject2 mTask; private final BaseOverview mOverview; @@ -72,6 +76,7 @@ public final class OverviewTask { event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED, () -> "Launching task didn't open a new window: " + mTask.getParent().getContentDescription()); + mLauncher.expectEvent(TASK_START_EVENT); } return new Background(mLauncher); } diff --git a/tests/tapl/com/android/launcher3/tapl/Widget.java b/tests/tapl/com/android/launcher3/tapl/Widget.java index dfd74ed0fa..a658f16deb 100644 --- a/tests/tapl/com/android/launcher3/tapl/Widget.java +++ b/tests/tapl/com/android/launcher3/tapl/Widget.java @@ -31,4 +31,8 @@ public final class Widget extends Launchable { protected String getLongPressIndicator() { return "drop_target_bar"; } + + @Override + protected void expectActivityStartEvents() { + } } From 3fc86f40557a74df02a529eae48cffe599683294 Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Fri, 24 Jan 2020 11:23:15 -0800 Subject: [PATCH 08/63] Remove FeatureFlag dependency from FolderNameProvider Change-Id: If4ed2c953975f76947442959a2820ee72f1bd0ec --- src/com/android/launcher3/folder/FolderNameProvider.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/com/android/launcher3/folder/FolderNameProvider.java b/src/com/android/launcher3/folder/FolderNameProvider.java index 386de23b45..782b0e2ce6 100644 --- a/src/com/android/launcher3/folder/FolderNameProvider.java +++ b/src/com/android/launcher3/folder/FolderNameProvider.java @@ -24,7 +24,6 @@ import com.android.launcher3.AppInfo; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.WorkspaceItemInfo; -import com.android.launcher3.config.FeatureFlags; import java.util.ArrayList; import java.util.Arrays; @@ -42,7 +41,7 @@ import java.util.stream.Collectors; public class FolderNameProvider { private static final String TAG = "FolderNameProvider"; - private static final boolean DEBUG = FeatureFlags.FOLDER_NAME_SUGGEST.get(); + private static final boolean DEBUG = false; /** * IME usually has up to 3 suggest slots. In total, there are 4 suggest slots as the folder From a315ec5f17240bd18d206a41f54da1e2fc873b1f Mon Sep 17 00:00:00 2001 From: Muhammad Qureshi Date: Thu, 16 Jan 2020 15:16:23 -0800 Subject: [PATCH 09/63] Use autogenerated SysUiStatsLog for statsd logging StatsLogCompat is not needed because we can autogenerate StatsLog write calls that are public. This CL switches uses of StatsLogCompat to using SysUiStatsLog from SystemUI. Bug: 145952197 Test: m Test: fastboot flashall Test: adb shell cmd stats print-logs && adb logcat "*:S statsd:*" and inspect LAUNCHER_EVENT logging Change-Id: Ib4f90a79f436cdd7e058fdb7027c09a5a59cc4f9 (cherry picked from commit 33ec1e182eee652b7aa20a3f1248e957f5a70f35) --- .../quickstep/logging/StatsLogCompatManager.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java index a466f12b0d..53859ad5bf 100644 --- a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java +++ b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java @@ -43,7 +43,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType; import com.android.launcher3.userevent.nano.LauncherLogProto.ItemType; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.ComponentKey; -import com.android.systemui.shared.system.StatsLogCompat; +import com.android.systemui.shared.system.SysUiStatsLog; import com.google.protobuf.nano.MessageNano; @@ -72,8 +72,8 @@ public class StatsLogCompatManager extends StatsLogManager { if (ext.srcTarget[0] != null) { ext.srcTarget[0].item = LauncherTarget.APP_ICON; } - StatsLogCompat.write(LAUNCH_APP, srcState, BACKGROUND /* dstState */, - MessageNano.toByteArray(ext), true); + SysUiStatsLog.write(SysUiStatsLog.LAUNCHER_EVENT, LAUNCH_APP, srcState, + BACKGROUND /* dstState */, MessageNano.toByteArray(ext), true); } @Override @@ -82,8 +82,8 @@ public class StatsLogCompatManager extends StatsLogManager { ext.srcTarget = new LauncherTarget[SUPPORTED_TARGET_DEPTH]; int srcState = OVERVIEW; fillInLauncherExtension(v, ext); - StatsLogCompat.write(LAUNCH_TASK, srcState, BACKGROUND /* dstState */, - MessageNano.toByteArray(ext), true); + SysUiStatsLog.write(SysUiStatsLog.LAUNCHER_EVENT, LAUNCH_TASK, srcState, + BACKGROUND /* dstState */, MessageNano.toByteArray(ext), true); } @Override @@ -92,8 +92,8 @@ public class StatsLogCompatManager extends StatsLogManager { ext.srcTarget = new LauncherTarget[SUPPORTED_TARGET_DEPTH]; int srcState = OVERVIEW; fillInLauncherExtension(v, ext); - StatsLogCompat.write(DISMISS_TASK, srcState, BACKGROUND /* dstState */, - MessageNano.toByteArray(ext), true); + SysUiStatsLog.write(SysUiStatsLog.LAUNCHER_EVENT, DISMISS_TASK, srcState, + BACKGROUND /* dstState */, MessageNano.toByteArray(ext), true); } @Override @@ -103,7 +103,7 @@ public class StatsLogCompatManager extends StatsLogManager { int srcState = mStateProvider.getCurrentState(); fillInLauncherExtensionWithPageId(ext, pageId); int launcherAction = isSwipingToLeft ? Launcher.SWIPE_LEFT : Launcher.SWIPE_RIGHT; - StatsLogCompat.write(launcherAction, srcState, srcState, + SysUiStatsLog.write(SysUiStatsLog.LAUNCHER_EVENT, launcherAction, srcState, srcState, MessageNano.toByteArray(ext), true); } From f8b1d414bba6d30c837778b72c1e1a35a8b1d04a Mon Sep 17 00:00:00 2001 From: Vinit Nayak Date: Tue, 5 Nov 2019 14:23:26 -0800 Subject: [PATCH 10/63] Rotate quickswitch task thumbnails Previously we were only rotating thumbnails if the difference between them was portrait vs landscape, so a thumbnail in seascape with the launcher in landscape wouldn't be rotated. fixes: 143892437 Test: With launcher in portrait * Thumbnail in reverse portrait, landscape, seascape, normal With launcher in landscape * Thumbnail in seascape, normal, reverse portrait, landscape With launcher in seascape * Thumbnail in seascape, normal, reverse portrait, landscape Change-Id: I1dd82428c05e4338a90ddb7b381fe920735f7cfd --- .../quickstep/views/TaskThumbnailView.java | 103 ++++++++++++------ 1 file changed, 68 insertions(+), 35 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java index 3bc1509d46..056b1e304a 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java @@ -20,7 +20,6 @@ import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TI import static com.android.systemui.shared.system.WindowManagerWrapper.WINDOWING_MODE_FULLSCREEN; import android.content.Context; -import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; @@ -38,11 +37,11 @@ import android.graphics.Shader; import android.util.AttributeSet; import android.util.FloatProperty; import android.util.Property; +import android.view.Surface; import android.view.View; import android.view.ViewGroup; import com.android.launcher3.BaseActivity; -import com.android.launcher3.DeviceProfile; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; @@ -102,7 +101,7 @@ public class TaskThumbnailView extends View implements PluginListener 0 && windowingModeSupportsRotation; // Scale the screenshot to always fit the width of the card. - thumbnailScale = isRotated + + thumbnailScale = isOrientationDifferent ? getMeasuredWidth() / thumbnailHeight : getMeasuredWidth() / thumbnailWidth; } - if (isRotated) { - int rotationDir = profile.isVerticalBarLayout() && !profile.isSeascape() ? -1 : 1; - mMatrix.setRotate(90 * rotationDir); - int newLeftInset = rotationDir == 1 ? thumbnailInsets.bottom : thumbnailInsets.top; - int newTopInset = rotationDir == 1 ? thumbnailInsets.left : thumbnailInsets.right; - mClippedInsets.offsetTo(newLeftInset * scale, newTopInset * scale); - if (rotationDir == -1) { - // Crop the right/bottom side of the screenshot rather than left/top - float excessHeight = thumbnailWidth * thumbnailScale - getMeasuredHeight(); - mClippedInsets.offset(0, excessHeight); - } - mMatrix.postTranslate(-mClippedInsets.left, -mClippedInsets.top); - // Move the screenshot to the thumbnail window (rotation moved it out). - if (rotationDir == 1) { - mMatrix.postTranslate(mThumbnailData.thumbnail.getHeight(), 0); - } else { - mMatrix.postTranslate(0, mThumbnailData.thumbnail.getWidth()); - } - } else { - mClippedInsets.offsetTo(thumbnailInsets.left * scale, thumbnailInsets.top * scale); + if (!isRotated) { + // No Rotation + mClippedInsets.offsetTo(thumbnailInsets.left * scale, + thumbnailInsets.top * scale); mMatrix.setTranslate(-mClippedInsets.left, -mClippedInsets.top); + } else { + setThumbnailRotation(deltaRotate, thumbnailInsets, scale); } final float widthWithInsets; final float heightWithInsets; - if (isRotated) { + if (isOrientationDifferent) { widthWithInsets = mThumbnailData.thumbnail.getHeight() * thumbnailScale; heightWithInsets = mThumbnailData.thumbnail.getWidth() * thumbnailScale; } else { @@ -415,7 +403,7 @@ public class TaskThumbnailView extends View implements PluginListener Date: Fri, 24 Jan 2020 14:05:40 -0800 Subject: [PATCH 11/63] Additionally filtering events by time Logcat may return records before the time requested via -t. Filtering them out. Also using year in date, to avoid failing during new year night. Change-Id: I3c84d5fdf7882b3f551a1d430aa906fe1ae67aa7 --- .../tapl/LauncherInstrumentation.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 0a3462f4e1..5555eab900 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -68,6 +68,7 @@ import org.junit.Assert; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.ref.WeakReference; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; @@ -93,10 +94,13 @@ public final class LauncherInstrumentation { private static final String TAG = "Tapl"; private static final int ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME = 20; private static final int GESTURE_STEP_MS = 16; + private static final SimpleDateFormat DATE_TIME_FORMAT = + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); private static long START_TIME = System.currentTimeMillis(); static final Pattern EVENT_LOG_ENTRY = Pattern.compile( - "[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\.[0-9][0-9][0-9]" + "(?