Merge "Adopt shell permission only to set and unset time limit." into ub-launcher3-qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4c8d7a0401
@@ -31,14 +31,14 @@ public class DigitalWellBeingToastTest extends AbstractQuickStepTest {
|
|||||||
mTargetContext.getSystemService(UsageStatsManager.class);
|
mTargetContext.getSystemService(UsageStatsManager.class);
|
||||||
final int observerId = 0;
|
final int observerId = 0;
|
||||||
|
|
||||||
getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();
|
|
||||||
try {
|
try {
|
||||||
final String[] packages = new String[]{CALCULATOR_PACKAGE};
|
final String[] packages = new String[]{CALCULATOR_PACKAGE};
|
||||||
|
|
||||||
// Set time limit for app.
|
// Set time limit for app.
|
||||||
usageStatsManager.registerAppUsageLimitObserver(observerId, packages,
|
runWithShellPermission(() ->
|
||||||
Duration.ofSeconds(600), Duration.ofSeconds(300),
|
usageStatsManager.registerAppUsageLimitObserver(observerId, packages,
|
||||||
PendingIntent.getActivity(mTargetContext, -1, new Intent(), 0));
|
Duration.ofSeconds(600), Duration.ofSeconds(300),
|
||||||
|
PendingIntent.getActivity(mTargetContext, -1, new Intent(), 0)));
|
||||||
|
|
||||||
mLauncher.pressHome();
|
mLauncher.pressHome();
|
||||||
final DigitalWellBeingToast toast = getToast();
|
final DigitalWellBeingToast toast = getToast();
|
||||||
@@ -47,13 +47,14 @@ public class DigitalWellBeingToastTest extends AbstractQuickStepTest {
|
|||||||
assertEquals("Toast text: ", "5 minutes left today", toast.getTextView().getText());
|
assertEquals("Toast text: ", "5 minutes left today", toast.getTextView().getText());
|
||||||
|
|
||||||
// Unset time limit for app.
|
// Unset time limit for app.
|
||||||
usageStatsManager.unregisterAppUsageLimitObserver(observerId);
|
runWithShellPermission(
|
||||||
|
() -> usageStatsManager.unregisterAppUsageLimitObserver(observerId));
|
||||||
|
|
||||||
mLauncher.pressHome();
|
mLauncher.pressHome();
|
||||||
assertFalse("Toast is visible", getToast().isShown());
|
assertFalse("Toast is visible", getToast().isShown());
|
||||||
} finally {
|
} finally {
|
||||||
usageStatsManager.unregisterAppUsageLimitObserver(observerId);
|
runWithShellPermission(
|
||||||
getInstrumentation().getUiAutomation().dropShellPermissionIdentity();
|
() -> usageStatsManager.unregisterAppUsageLimitObserver(observerId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,4 +74,14 @@ public class DigitalWellBeingToastTest extends AbstractQuickStepTest {
|
|||||||
private TaskView getLatestTask(Launcher launcher) {
|
private TaskView getLatestTask(Launcher launcher) {
|
||||||
return launcher.<RecentsView>getOverviewPanel().getTaskViewAt(0);
|
return launcher.<RecentsView>getOverviewPanel().getTaskViewAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runWithShellPermission(Runnable action) {
|
||||||
|
getInstrumentation().getUiAutomation().adoptShellPermissionIdentity();
|
||||||
|
try {
|
||||||
|
action.run();
|
||||||
|
} finally {
|
||||||
|
getInstrumentation().getUiAutomation().dropShellPermissionIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user