Merge "Ignore non test package events for AppStandbyControllerTests" into rvc-dev am: 2ac647d545 am: 0de0eb9a4c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12788106 Change-Id: Ia6b44bf57525678761b3a4496e3931375e44c880
This commit is contained in:
@@ -141,10 +141,13 @@ public class AppStandbyControllerTests {
|
|||||||
private AppStandbyController mController;
|
private AppStandbyController mController;
|
||||||
|
|
||||||
private CountDownLatch mStateChangedLatch = new CountDownLatch(1);
|
private CountDownLatch mStateChangedLatch = new CountDownLatch(1);
|
||||||
|
private String mLatchPkgName = null;
|
||||||
private AppIdleStateChangeListener mListener = new AppIdleStateChangeListener() {
|
private AppIdleStateChangeListener mListener = new AppIdleStateChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAppIdleStateChanged(String packageName, int userId,
|
public void onAppIdleStateChanged(String packageName, int userId,
|
||||||
boolean idle, int bucket, int reason) {
|
boolean idle, int bucket, int reason) {
|
||||||
|
// Ignore events not related to mLatchPkgName, if set.
|
||||||
|
if (mLatchPkgName != null && !mLatchPkgName.equals(packageName)) return;
|
||||||
mStateChangedLatch.countDown();
|
mStateChangedLatch.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -387,6 +390,7 @@ public class AppStandbyControllerTests {
|
|||||||
mInjector.mElapsedRealtime, false));
|
mInjector.mElapsedRealtime, false));
|
||||||
|
|
||||||
controller.addListener(mListener);
|
controller.addListener(mListener);
|
||||||
|
mLatchPkgName = null;
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1390,7 +1394,7 @@ public class AppStandbyControllerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnexemptedSyncScheduled() throws Exception {
|
public void testUnexemptedSyncScheduled() throws Exception {
|
||||||
mStateChangedLatch = new CountDownLatch(1);
|
rearmLatch(PACKAGE_1);
|
||||||
mController.addListener(mListener);
|
mController.addListener(mListener);
|
||||||
assertEquals("Test package did not start in the Never bucket", STANDBY_BUCKET_NEVER,
|
assertEquals("Test package did not start in the Never bucket", STANDBY_BUCKET_NEVER,
|
||||||
getStandbyBucket(mController, PACKAGE_1));
|
getStandbyBucket(mController, PACKAGE_1));
|
||||||
@@ -1402,7 +1406,7 @@ public class AppStandbyControllerTests {
|
|||||||
|
|
||||||
setAndAssertBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE, REASON_MAIN_FORCED_BY_SYSTEM);
|
setAndAssertBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE, REASON_MAIN_FORCED_BY_SYSTEM);
|
||||||
|
|
||||||
mStateChangedLatch = new CountDownLatch(1);
|
rearmLatch(PACKAGE_1);
|
||||||
mController.postReportSyncScheduled(PACKAGE_1, USER_ID, false);
|
mController.postReportSyncScheduled(PACKAGE_1, USER_ID, false);
|
||||||
mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
|
mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
|
||||||
assertEquals("Unexempted sync scheduled should not elevate a non Never bucket",
|
assertEquals("Unexempted sync scheduled should not elevate a non Never bucket",
|
||||||
@@ -1413,7 +1417,7 @@ public class AppStandbyControllerTests {
|
|||||||
public void testExemptedSyncScheduled() throws Exception {
|
public void testExemptedSyncScheduled() throws Exception {
|
||||||
setAndAssertBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE, REASON_MAIN_FORCED_BY_SYSTEM);
|
setAndAssertBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE, REASON_MAIN_FORCED_BY_SYSTEM);
|
||||||
mInjector.mDeviceIdleMode = true;
|
mInjector.mDeviceIdleMode = true;
|
||||||
mStateChangedLatch = new CountDownLatch(1);
|
rearmLatch(PACKAGE_1);
|
||||||
mController.postReportSyncScheduled(PACKAGE_1, USER_ID, true);
|
mController.postReportSyncScheduled(PACKAGE_1, USER_ID, true);
|
||||||
mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
|
mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
|
||||||
assertEquals("Exempted sync scheduled in doze should set bucket to working set",
|
assertEquals("Exempted sync scheduled in doze should set bucket to working set",
|
||||||
@@ -1421,7 +1425,7 @@ public class AppStandbyControllerTests {
|
|||||||
|
|
||||||
setAndAssertBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE, REASON_MAIN_FORCED_BY_SYSTEM);
|
setAndAssertBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE, REASON_MAIN_FORCED_BY_SYSTEM);
|
||||||
mInjector.mDeviceIdleMode = false;
|
mInjector.mDeviceIdleMode = false;
|
||||||
mStateChangedLatch = new CountDownLatch(1);
|
rearmLatch(PACKAGE_1);
|
||||||
mController.postReportSyncScheduled(PACKAGE_1, USER_ID, true);
|
mController.postReportSyncScheduled(PACKAGE_1, USER_ID, true);
|
||||||
mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
|
mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
|
||||||
assertEquals("Exempted sync scheduled while not in doze should set bucket to active",
|
assertEquals("Exempted sync scheduled while not in doze should set bucket to active",
|
||||||
@@ -1590,10 +1594,19 @@ public class AppStandbyControllerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setAndAssertBucket(String pkg, int user, int bucket, int reason) throws Exception {
|
private void setAndAssertBucket(String pkg, int user, int bucket, int reason) throws Exception {
|
||||||
mStateChangedLatch = new CountDownLatch(1);
|
rearmLatch(pkg);
|
||||||
mController.setAppStandbyBucket(pkg, user, bucket, reason);
|
mController.setAppStandbyBucket(pkg, user, bucket, reason);
|
||||||
mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
|
mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
|
||||||
assertEquals("Failed to set package bucket", bucket,
|
assertEquals("Failed to set package bucket", bucket,
|
||||||
getStandbyBucket(mController, PACKAGE_1));
|
getStandbyBucket(mController, PACKAGE_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rearmLatch(String pkgName) {
|
||||||
|
mLatchPkgName = pkgName;
|
||||||
|
mStateChangedLatch = new CountDownLatch(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rearmLatch() {
|
||||||
|
rearmLatch(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user