Loading quickstep/recents_ui_overrides/src/com/android/quickstep/views/DigitalWellBeingToast.java +4 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import android.os.UserHandle; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; Loading Loading @@ -69,6 +68,10 @@ public final class DigitalWellBeingToast extends LinearLayout { mLauncherApps = context.getSystemService(LauncherApps.class); } public TextView getTextView() { return mText; } @Override protected void onFinishInflate() { super.onFinishInflate(); Loading quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java +4 −0 Original line number Diff line number Diff line Loading @@ -212,6 +212,10 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { return mMenuView; } public DigitalWellBeingToast getDigitalWellBeingToast() { return mDigitalWellBeingToast; } /** * Updates this task view to the given {@param task}. */ Loading quickstep/tests/src/com/android/quickstep/DigitalWellBeingToastTest.java 0 → 100644 +76 −0 Original line number Diff line number Diff line package com.android.quickstep; import static androidx.test.InstrumentationRegistry.getInstrumentation; import static com.android.launcher3.LauncherState.OVERVIEW; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.app.PendingIntent; import android.app.usage.UsageStatsManager; import android.content.Intent; import com.android.launcher3.Launcher; import com.android.quickstep.views.DigitalWellBeingToast; import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.TaskView; import org.junit.Test; import java.time.Duration; public class DigitalWellBeingToastTest extends AbstractQuickStepTest { private static final String CALCULATOR_PACKAGE = resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR); @Test public void testToast() throws Exception { final UsageStatsManager usageStatsManager = mTargetContext.getSystemService(UsageStatsManager.class); final int observerId = 0; getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(); try { final String[] packages = new String[]{CALCULATOR_PACKAGE}; // Set time limit for app. usageStatsManager.registerAppUsageLimitObserver(observerId, packages, Duration.ofSeconds(600), Duration.ofSeconds(300), PendingIntent.getActivity(mTargetContext, -1, new Intent(), 0)); mLauncher.pressHome(); final DigitalWellBeingToast toast = getToast(); assertTrue("Toast is not visible", toast.isShown()); assertEquals("Toast text: ", "5 minutes left today", toast.getTextView().getText()); // Unset time limit for app. usageStatsManager.unregisterAppUsageLimitObserver(observerId); mLauncher.pressHome(); assertFalse("Toast is visible", getToast().isShown()); } finally { usageStatsManager.unregisterAppUsageLimitObserver(observerId); getInstrumentation().getUiAutomation().dropShellPermissionIdentity(); } } private DigitalWellBeingToast getToast() { executeOnLauncher(launcher -> launcher.getStateManager().goToState(OVERVIEW)); waitForState("Launcher internal state didn't switch to Overview", OVERVIEW); waitForLauncherCondition("No latest task", launcher -> getLatestTask(launcher) != null); return getFromLauncher(launcher -> { final TaskView task = getLatestTask(launcher); assertTrue("Latest task is not Calculator", CALCULATOR_PACKAGE.equals(task.getTask().getTopComponent().getPackageName())); return task.getDigitalWellBeingToast(); }); } private TaskView getLatestTask(Launcher launcher) { return launcher.<RecentsView>getOverviewPanel().getTaskViewAt(0); } } tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -361,7 +361,7 @@ public abstract class AbstractLauncherUiTest { mDevice.wait(Until.hasObject(By.pkg(packageName).depth(0)), LONG_WAIT_TIME_MS)); } protected String resolveSystemApp(String category) { protected static String resolveSystemApp(String category) { return getInstrumentation().getContext().getPackageManager().resolveActivity( new Intent(Intent.ACTION_MAIN).addCategory(category), PackageManager.MATCH_SYSTEM_ONLY). Loading Loading
quickstep/recents_ui_overrides/src/com/android/quickstep/views/DigitalWellBeingToast.java +4 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import android.os.UserHandle; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; Loading Loading @@ -69,6 +68,10 @@ public final class DigitalWellBeingToast extends LinearLayout { mLauncherApps = context.getSystemService(LauncherApps.class); } public TextView getTextView() { return mText; } @Override protected void onFinishInflate() { super.onFinishInflate(); Loading
quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java +4 −0 Original line number Diff line number Diff line Loading @@ -212,6 +212,10 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { return mMenuView; } public DigitalWellBeingToast getDigitalWellBeingToast() { return mDigitalWellBeingToast; } /** * Updates this task view to the given {@param task}. */ Loading
quickstep/tests/src/com/android/quickstep/DigitalWellBeingToastTest.java 0 → 100644 +76 −0 Original line number Diff line number Diff line package com.android.quickstep; import static androidx.test.InstrumentationRegistry.getInstrumentation; import static com.android.launcher3.LauncherState.OVERVIEW; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.app.PendingIntent; import android.app.usage.UsageStatsManager; import android.content.Intent; import com.android.launcher3.Launcher; import com.android.quickstep.views.DigitalWellBeingToast; import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.TaskView; import org.junit.Test; import java.time.Duration; public class DigitalWellBeingToastTest extends AbstractQuickStepTest { private static final String CALCULATOR_PACKAGE = resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR); @Test public void testToast() throws Exception { final UsageStatsManager usageStatsManager = mTargetContext.getSystemService(UsageStatsManager.class); final int observerId = 0; getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(); try { final String[] packages = new String[]{CALCULATOR_PACKAGE}; // Set time limit for app. usageStatsManager.registerAppUsageLimitObserver(observerId, packages, Duration.ofSeconds(600), Duration.ofSeconds(300), PendingIntent.getActivity(mTargetContext, -1, new Intent(), 0)); mLauncher.pressHome(); final DigitalWellBeingToast toast = getToast(); assertTrue("Toast is not visible", toast.isShown()); assertEquals("Toast text: ", "5 minutes left today", toast.getTextView().getText()); // Unset time limit for app. usageStatsManager.unregisterAppUsageLimitObserver(observerId); mLauncher.pressHome(); assertFalse("Toast is visible", getToast().isShown()); } finally { usageStatsManager.unregisterAppUsageLimitObserver(observerId); getInstrumentation().getUiAutomation().dropShellPermissionIdentity(); } } private DigitalWellBeingToast getToast() { executeOnLauncher(launcher -> launcher.getStateManager().goToState(OVERVIEW)); waitForState("Launcher internal state didn't switch to Overview", OVERVIEW); waitForLauncherCondition("No latest task", launcher -> getLatestTask(launcher) != null); return getFromLauncher(launcher -> { final TaskView task = getLatestTask(launcher); assertTrue("Latest task is not Calculator", CALCULATOR_PACKAGE.equals(task.getTask().getTopComponent().getPackageName())); return task.getDigitalWellBeingToast(); }); } private TaskView getLatestTask(Launcher launcher) { return launcher.<RecentsView>getOverviewPanel().getTaskViewAt(0); } }
tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -361,7 +361,7 @@ public abstract class AbstractLauncherUiTest { mDevice.wait(Until.hasObject(By.pkg(packageName).depth(0)), LONG_WAIT_TIME_MS)); } protected String resolveSystemApp(String category) { protected static String resolveSystemApp(String category) { return getInstrumentation().getContext().getPackageManager().resolveActivity( new Intent(Intent.ACTION_MAIN).addCategory(category), PackageManager.MATCH_SYSTEM_ONLY). Loading