98 Commits

Author SHA1 Message Date
Bill Lin
00190cf8a6 Merge changes from topic "migrate_CtsStagedInstallTest_RollbackTest"
am: 63e6d6af01

Change-Id: I362c1a03a1f8c106f684cd6a28fe63fbd5532d9c
2019-11-25 05:36:35 -08:00
Richard Uhler
5a6df15108 Increase timeout in testNativeWatchdogTriggersRollback
am: 5f01cb9246

Change-Id: I4677f053787074ef445bba8d18ace8ad66c711ff
2019-11-25 05:36:26 -08:00
Richard Uhler
79e8fcb4ae Fix flaky testEnableRollbackTimeoutFailsRollback test
am: 1d66bf8c48

Change-Id: Id8c792c9a0926fbd7b8e287c6547eb250caca5fb
2019-11-25 05:36:13 -08:00
Oli Lan
170a519878 Wait for available rollbacks in RollbackTest.
am: 77a40731f8

Change-Id: I83b8f07f333e318bb7fd31b2bec3f868b1848c6c
2019-11-25 05:35:57 -08:00
Richard Uhler
a39bd708e4 Update to new RollbackUtils.sendCrashBroadcast API.
am: 3e7ef5ae0b

Change-Id: I518d37f8d2eef80f63c88530ed4aa581c27b9e75
2019-11-25 05:33:56 -08:00
Gavin Corkery
4bcb79bb71 Extend ROLLBACK_COMMITTED broadcast for the multi-user case
am: e92720ddb9

Change-Id: I28bb0d0574c80df5f6d6628bc6026d99770faaf5
2019-11-25 05:33:06 -08:00
Richard Uhler
01178b4f9d Cleanup some obsolete TODOs and unused code.
am: cda1a17516

Change-Id: I56bce126042670678002ddbbfcf14ff9f94860c3
2019-11-25 05:24:46 -08:00
Gavin Corkery
1a6ea95489 Add multi-user test for the general non-staged case
This test makes assertions about the case where there are two
users running a test application. It verifies that each user can
have its own unique userdata for the same app, and that upgrades
and downgrades are applicable for all users on the device.

Test: atest MultiUserRollbackTest
Test: atest RollbackTest
Bug: 140401995
Change-Id: I77a18cf99ec8d7f30696119919dae8859f9fb25b
Merged-In: I5e5c154758b3f0e4731696c813519ac798fbbae9
2019-11-21 17:53:11 +08:00
Richard Uhler
5f01cb9246 Increase timeout in testNativeWatchdogTriggersRollback
Bumps a timeout from 1 minute to 5 minutes, because in practice a lot
more needs to happen in that time window than we expect to fit in 1
minute.

Bug: 140223710
Test: atest StagedRollbackTest:com.android.tests.rollback.host.StagedRollbackTest#testNativeWatchdogTriggersRollback
Change-Id: I2e937f8e1f87356815a834241ad5e9ec1e953892
Merged-In: I2a98e71102fc1cbf6ea712e070d6db49cdb05cba
2019-11-21 17:52:54 +08:00
Richard Uhler
1d66bf8c48 Fix flaky testEnableRollbackTimeoutFailsRollback test
We no longer block on the handler thread in getAvailableRollbacks. That
means it is possible we see an available rollback left over from a
previous test run. Update the test to ensure previous rollbacks are
removed and give sufficient time to make a new rollback available before
concluding that no rollback will be made available in this case.

Test: atest RollbackTest:com.android.tests.rollback.RollbackTest#testEnableRollbackTimeoutFailsRollback
Change-Id: I8b22320bb3ee60152ab808706913eff43ab7cc9f
Merged-In: Id94d5452836b07d6f802758bd0dfdd3c276a3c05
2019-11-21 17:52:02 +08:00
Oli Lan
77a40731f8 Wait for available rollbacks in RollbackTest.
This changes RollbackTest to retry checks for available rollbacks for
a certain period of time, using a new RollbackUtils method
waitForAvailableRollbacks.

Currently many of the tests in RollbackTest are flaky due to race conditions
between checking for available rollbacks and the installer onFinished callback.
This CL should fix all of those issues.

The previous attempt to resolve this by adding NewRollbacks speculatively to
the results of getAvailableRollbacks was not successful. This CL reverts that
change so that getAvailableRollbacks once again only returns rollbacks that are
actually available.

Bug: 136548146
Test: atest RollbackTest run on cuttlefish on acloud repeatedly
Change-Id: I0389ef2413e7642fe2f6ef1a33aef218dd1896ed
Merged-In: I27e2513b34f49af2f41cd627a5d2550541831e11
2019-11-21 17:51:11 +08:00
Richard Uhler
3e7ef5ae0b Update to new RollbackUtils.sendCrashBroadcast API.
Bug: 139108668
Test: atest StagedRollbackTest:com.android.tests.rollback.host.StagedRollbackTest#testBadApkOnly
2
Merged-In: Iaaa728aa58d894ba546677e8295faba2ebfc5e64

Change-Id: I877a2d5ee00a2d58fa748c45d4eaffd54b3b0127
2019-11-21 17:14:00 +08:00
Gavin Corkery
e92720ddb9 Extend ROLLBACK_COMMITTED broadcast for the multi-user case
For the case where there are multiple users on the device,
the ROLLBACK_COMMITTED broadcast should be sent to all
users for which the package is being rolled back.

Test: atest RollbackTest
Test: atest SecondaryUserRollbackTest
Bug: 139060321
Change-Id: I901ff8a3331c7a8a8585c855a0caead347321d5d
Merged-In: I8e20da321f52ebf9e6d584a8c59d2a3106a32212
2019-11-21 17:13:59 +08:00
shafik
7ef8104354 Test Native Watchdog triggers RollbackManager rollback
Test flow:
    * Staged install com.google.android.modulemetadata
    * Crash a native process (apexd) enough times to trigger a rollback
    * Wait for device reboot (automatically)
    * Assert rollback of com.google.android.modulemetadata has been
    committed

Test: atest StagedRollbackTest#testNativeWatchdogTriggersRollback
Bug: 135864628
Change-Id: I5176cc7890e251e7ccc10abdfcfee3a5190721b2
Merged-In: Ibe726c140939190adb3db9c18b3b442ba59548a3
2019-11-21 17:10:56 +08:00
shafik
b9f1521715 Uninstall testapps before running SecondaryUserRollbackTest
Add target_preparer for uninstalling TestApp.A and TestApp.B before
running SecondaryUserRollbackTest.
Also, fix the tearDown command after each case to uninstall the right
apps.

Test: atest SecondaryUserRollbackTest ; atest SecondaryUserRollbackTest
Bug: 136538996
Change-Id: I35edde58eb8b520f167bace7848956d091155158
Merged-In: I3d5decae03bf9d2f9d78a534399214da05a6d372
2019-11-21 17:10:56 +08:00
Gavin Corkery
bcf89b81f5 Add test for rollback of userdata with multiple rollbacks
This test ensures that if a staged install is abandoned, and then
staged again, the userdata snapshot will match the correct rollback.
Since there will be multiple rollbacks in the ENABLING state for the
same package, it is important to ensure that the userdata for the
abandoned rollback is not used.

Test: atest StagedRollbackTest
Bug: 134035054
Change-Id: Ic977e747103c9a9a44592846de73287788cbac6d
Merged-In: Icae7226dfb393c5ffc31dd0116f61141e84f5a42
2019-11-21 17:08:32 +08:00
Richard Uhler
0c48af84fe Add TestApi to block the RollbackManagerHandlerThread.
To eliminate flakiness when testing timeout conditions for
RollbackTest.testEnableRollbackTimeoutFailsRollback.

Test: atest RollbackTest.testEnableRollbackTimeoutFailsRollback in a loop
Bug: 134373106
Change-Id: I2d1de148a83231f3fd48cc05b7320fa5fdf091ce
Merged-In: I01f3e769711ffa51fa714ff4bc81e70887f427ad
2019-11-21 16:58:45 +08:00
shafik
af4df0e7c6 Migrate RollbackTest and StagedRollbackTest to cts utils
Replace the usage of RollbackTestUtils with the API offered by
com.android.cts.install.lib and com.android.cts.rollback.lib.

Test: atest RollbackTest
Test: atest StagedRollbackTest #testBadApkOnly

Bug: 132757394
Bug: 132422403
Change-Id: I1d6789b4fb7ae94ebf7066a6fd215e4ac48c04df
Merged-In: I25cb9dca103852d7ee3691e4df927e1fc5848074
2019-11-21 13:46:06 +08:00
shafik
f25aed4668 Add host side test for secondary user rollback
Run RollbackTest#testBasic only under a secondary user.

The host-driven test adds a new user and then installs the TEST (not the
test app) for that new user.
Note: this was the missing step in the previous attempt to test
RollbackTest under a secondary user.

Test: atest SecondaryUserRollbackTest
Test: test failed when multiuser support was removed from rollback
manager
Test: adb shell pm list packages --user 11 | grep rollback while running
the test in order to make sure the test is installing packages for the right user

Bug: 133852817
Bug: 129747710
Change-Id: I9e13f2cdaf825a53846765fa52bc425045f41df1
Merged-In: Id1e54769cc2a9631d1464c07bad2b685f78689bc
2019-11-21 13:46:06 +08:00
Richard Uhler
bb981e391c Reduce ENABLE_ROLLBACK timeout to 0 for timeout test.
testEnableRollbackTimeoutFailsRollback works by setting the enable
rollback timeout to 1 millisecond so that we will always time out, but
the test is failing some times because apparently we enable rollback
within the 1 millisecond limit. Reduce the timeout to 0 milliseconds to
try and reduce test flakiness.

Before lowering the timeout, the test failure was easy to reproduce
locally. After lowering the timeout I have not once been able to
reproduce the test failure locally.

Bug: 134373106
Test: atest RollbackTest:com.android.tests.rollback.RollbackTest#testEnableRollbackTimeoutFailsRollback
Change-Id: I44f9e786d2a2285475ee423e34d06f5b5a5271e1
Merged-In: Ia25561831616dd2f2644743a399b49e35d5d4ea4
2019-11-21 13:46:06 +08:00
Remi NGUYEN VAN
879655bccc Merge "Detect NetworkStack path in rollback test"
am: 5d4d3c178f

Change-Id: Ibfdc04ee71c85b3923bb3996b2150fe3637d1553
2019-11-11 09:10:00 -08:00
Remi NGUYEN VAN
1ebd5c44d2 Detect NetworkStack path in rollback test
The network stack module may be implemented by NetworkStack (updatable
version built against stable SDK) or NetworkStackNext (test version
shipped only in system images, built against in-development SDK).

Bug: 144168912
Test: atest StagedRollbackTest
Merged-In: I1788e323f763ca88b69b082f38078bee3bfe480d
Change-Id: I963cc20ae4356f1728f6dd1bbf14f48ded978756
2019-11-11 17:03:33 +09:00
Richard Uhler
d283dc938f Disable flaky testBadApkOnly test.
A proper fix for the flakiness has been submitted to more recent
versions of the RollbackTest.

Bug: 139108668
Bug: 139175593

Test: atest StagedRollbackTest

Change-Id: Iad20ac3744b0cf4adf0355150ce957de2a24304c
Merged-In: Iaaa728aa58d894ba546677e8295faba2ebfc5e64
2019-08-28 10:23:51 +01:00
Richard Uhler
9a97acb842 Disable testEnableRollbackTimeoutFailsRollback test.
The test is flaky because it is testing a race condition.

The flakiness is fixed with the help of some new @TestApi in
I01f3e769711ffa51fa714ff4bc81e70887f427ad. Disable the test on those
branches without the fix merged.

Bug: 134373106
Bug: 136605788
Test: atest RollbackTest

Change-Id: I05edfc142c14631b259ae7aaf2dd31af00363a35
Merged-In: I01f3e769711ffa51fa714ff4bc81e70887f427ad
(cherry picked from commit 75f942dfa807fe6d7b67d0ebca733e018fd66e02)
2019-08-20 17:16:35 +00:00
Richard Uhler
75f942dfa8 Disable testEnableRollbackTimeoutFailsRollback test.
The test is flaky because it is testing a race condition.

The flakiness is fixed with the help of some new @TestApi in
I01f3e769711ffa51fa714ff4bc81e70887f427ad. Disable the test on those
branches without the fix merged.

Bug: 134373106
Bug: 136605788
Test: atest RollbackTest

Change-Id: I05edfc142c14631b259ae7aaf2dd31af00363a35
Merged-In: I01f3e769711ffa51fa714ff4bc81e70887f427ad
2019-07-11 09:32:43 +01:00
Zimuzo
e77a3e1de2 Add network health check watchdog triggered rollback tests
This cl improves code coverage for the PackageWatchdog explicit health
checks.

Updating the NetworkStack triggers an explicit health check with
a time deadline. At the deadline, if network is unavailable on the device,
the update is rolled back, if network is available, nothing happens.

Bug: 132640467
Test: atest StagedRollbackTest

Change-Id: I16a40244de9345930a1c981188aa33546fe872fc
2019-05-30 13:30:26 +01:00
Dario Freni
27ef26c880 Remove tests already covered by CTS.
Bug: 132429173
Bug: 127933960
Test: atest --test-mapping
frameworks/base/services/core/java/com/android/server/rollback/
Change-Id: I88685044d046180866c3cb63538a700cec775fc5
2019-05-22 15:16:37 +01:00
Richard Uhler
bf1bf9607d Add watchdog triggered staged rollback test
Test: atest StagedRollbackTest
Bug: 132758573
Bug: 132866890
Change-Id: I80e4ebf3659702992f32504690ea5ec4bab88534
2019-05-17 14:38:34 +01:00
shafik
4831ad7039 Fail to enable rollback if enable rollback times out
Make PackageManager send a ACTION_CANCEL_ENABLE_ROLLBACK intent to
RollbackManager. RollbackManager marks the relevant rollback as invalid.
Allow enable rollback to continue as usual, before making the rollback
available, RollbackManager checks whether it's valid. If it's not, the
rollback data is deleted.

Add a test case for expired rollback enabling attempt in RollbackTest.

Test: atest RollbackTest#testEnableRollbackTimeoutFailsRollback
Test: manual -
      * Set ENABLE_ROLLBACK_TIMEOUT_MILLIS to 1 ms using DeviceConfig
      * Install a mainline module with rollback enabled
      * adb shell dumpsys rollback
      * observe that no rollback was made available
Fixes: 131679409

Change-Id: Iaa4dbff002b820aff1fc3e1b985f129cf5ebe2e6
2019-05-09 12:38:04 +01:00
TreeHugger Robot
df10681a03 Merge "Fix handling of multi-package enable rollback failures." into qt-dev 2019-05-03 11:31:34 +00:00
Richard Uhler
4756970d3f Fix handling of multi-package enable rollback failures.
Failure to enable rollback for one of the packages in a multi-package
install should fail to enable rollback for all packages in the
multi-package install. That was not the case prior to this CL, which
could lead to partial rollbacks.

Keep track of how many child sessions we expect to enable rollback for
and double check that we succeeded before making the rollback available.
This involves some cleanup of how we track parent vs child sessions when
enabling rollback.

Bug: 128656191
Test: atest RollbackTest, with new test added.

Change-Id: I737896cdc1915396748c5c1959b5397af793258a
2019-05-03 10:48:04 +01:00
Richard Uhler
2124d4b313 Ensure race between rollback and roll forward is properly handled
If rollback for a package is committed at the same time the package is
updated, it's possible we will incorrectly roll back the newly updated
version of the application.

Add a hidden API to the package installer that lets you set a required
existing version of a package to be updated. If the expected package
version is not installed at the time of commit, the update install
fails.

The RollbackManager uses this new API to ensure that rollback will fail
if the package in question was just updated.

Test: atest RollbackTest, with new test added and manual confirmation
      that the race condition was exercised by the new test.
Bug: 128831080

Change-Id: Ifa5627e257d2ef13e2b213ef0dbc93932797ce0d
2019-05-01 09:10:36 +00:00
Richard Uhler
1924d6dbb8 Expire rollback when apex is updated.
RollbackManager relies on package changed broadcasts to expire rollbacks
when an application is updated, but we don't receive package changed
broadcasts for apex.

This change adds an extra check when starting RollbackManager to see if
any apex versions have changed and expires rollbacks as appropriate.

Adds a test case to cover the scenario and refactors the test code
to properly set up the test apex in all cases with minimal reboots.

Bug: 126358044
Test: atest StagedRollbackTest, with new test added.
Change-Id: I7ea4953e4aff8d1c7560d6c61e6be5e4e8e1f194
2019-04-26 13:22:51 +01:00
Richard Uhler
e846376e62 Add test for rollback of same version apk.
The test is marked @Ignore because of a bug in RollbackManager that
fails to expire a rollback when there is a new update of an apk to its
same version code:

STACKTRACE:
java.lang.AssertionError: expected null, but was:<android.content.rollback.RollbackInfo@28c0495>
  at org.junit.Assert.fail(Assert.java:88)
  at org.junit.Assert.failNotNull(Assert.java:755)
  at org.junit.Assert.assertNull(Assert.java:737)
  at org.junit.Assert.assertNull(Assert.java:747)
  at com.android.tests.rollback.RollbackTestUtils.getUniqueRollbackInfoForPackage(RollbackTestUtils.java:321)
  at com.android.tests.rollback.RollbackTest.testSameVersionUpdate(RollbackTest.java:795)

Bug: 120200473
Test: atest RollbackTest
Change-Id: Ib03692c170ee689fcf667689dad25647e55f984f
2019-04-23 15:58:33 +01:00
Richard Uhler
0741b41d94 Block getAvailableRollbacks on the handler thread.
To reduce flakiness in the CTS test, which checks for an available
rollback immediately after an app update is committed.

Remove sleeps from the RollbackTest that should no longer be needed.

Test: atest RollbackTest CtsRollbackManagerTestCases
Bug: 127933960
Change-Id: I60adb0f58eaba02d08ecd44b44866a8505c58238
2019-03-27 15:20:06 +00:00
Richard Uhler
fbac4ca9ad Fix issues with RollbackTest
* Add missing permission needed in testBadUpdateRollback test.
* Re-enable testRollbackWithSplits test now that the build issues have
  been sorted out.

Bug: 127920549
Test: atest RollbackTest
Change-Id: I5bd70aea4f1ad0345d7a37e78c0f3b5ef0615ed1
2019-03-21 11:12:12 +00:00
TreeHugger Robot
a1feb4cd63 Merge "Refine broadcast in commitRollback" 2019-03-20 19:12:02 +00:00
Zimuzo Ezeozue
1c6c5dece8 Merge "Fix flaky RollbackTest#testBadUpdateRollback" 2019-03-20 17:21:20 +00:00
shafik
74fec184ac Refine broadcast in commitRollback
Silence qualified user warning by using sendBroadcastAsUser.
The user is UserHandle.SYSTEM.
Limit recievers to those holding MANAGE_ROLLBACKS permission.

Test: warning does not appear in logcat when running atest RollbackTest
Fixes: 128280826
Change-Id: I85b905d2b20f3993859ec87948f309c1934a4a26
2019-03-20 17:05:47 +00:00
Zimuzo
790a3ccfa6 Fix flaky RollbackTest#testBadUpdateRollback
Added wait for ACTION_ROLLBACK_COMMITTED and also
minor RollbackTestUtils refactoring.

Test: atest RollbackTest
Bug: 126497394
Change-Id: Ia31b98974733ea19cd73c2688971ea853834e195
2019-03-20 14:39:11 +00:00
Richard Uhler
ce844797cd Merge "Only allow rollback to be enabled on modules." 2019-03-20 09:40:13 +00:00
Matt Pape
12187ae675 Remove interface for Rollback and Rollback Boot.
Per API council feedback, we are making changes to include only the
namespace in the system API defined in DeviceConfig.java. Strings which
define property names should be defined in code local to the feature
instead.

Bug: 126411407
Test: atest FrameworksCoreTests:DeviceConfigTest
      atest FrameworksServicesTests:PackageManagerServiceTest

Change-Id: Ie3b0539f51a582fb7583ece88e5d3bde0cc1efd7
2019-03-18 13:20:44 -07:00
Richard Uhler
1fc10c1209 Only allow rollback to be enabled on modules.
Only allow rollback to be enabled on the modules included in a mainline
update. We don't want to support rollbacks for all apks in general yet.

Enforce that only installers granted the MANAGE_ROLLBACKS permission can
enable rollback for a package.

Introduce a new TEST_MANAGE_ROLLBACKS permission that can be used to
enable rollback on packages that are not modules. This allows us to
continue testing rollbacks, given we can't do a mainline update as part
of the rollback tests.

Test: atest RollbackTest, with new tests for permissions added.
Bug: 128277794
Change-Id: I29ab9a750a1283592b8a855322ece516e42260ca
2019-03-18 14:05:28 +00:00
Shafik Nassar
ddb007f669 Merge "Test staged rollback for apk and apex install" 2019-03-13 00:29:09 +00:00
shafik
26b3e5b955 Test staged rollback for apk and apex install
In addition, add some methods to RollbackTestUtils to make old code
reusable for the new test.

Bug: 124043688
Test: atest StagedRollbackTest
Change-Id: I2b259671861c4081f13922f03ea2e251568e06bc
2019-03-12 12:19:14 +00:00
Richard Uhler
8a9774550d Use test stubs for RollbackTests, not system stubs.
Adds @TestApi for all system apis needed for RollbackTests.

Removes @SystemApi for RollbackManager.expireRollbackForPackage and
RollbackManager.reloadPersistedData, which were always intended to be
used solely for testing.

Bug: 127282563
Test: atest RollbackTest StagedRollbackTest
Change-Id: I183b8a484b4a08f36fc19d64241ab408d28c64ca
2019-03-12 12:14:37 +00:00
shafik
92ea53f448 API cleanup: add boolean param to setEnableRollback
Mark PackageInstaller.SessionParams#setEnableRollback() as @removed and
@deprecated.
Add PackageInstaller.SessionParams#setEnableRollback(enable).
Replace old API usages in RollbackTestUtils with the new API.

Also, add PackageInstaller.SessionInfo#getEnableRollback().

Fixes: 127282838
Test: atest RollbackTest
Change-Id: I696680207be5ac06560d2abb525f91a100301b4c
2019-03-11 09:48:54 +00:00
TreeHugger Robot
1d5ead8dbf Merge "Avoid building RollbackTestApps into the device image." 2019-03-07 19:13:25 +00:00
Richard Uhler
a7291341e3 Avoid building RollbackTestApps into the device image.
The current approach for including built apks as java resources in
RollbackTest.apk appears to cause the RollbackTestApp apks to be
included in the device release image. Convert the Android.mk for
RollbackTest to Android.bp to work around this issue.

This breaks the split apk tests, but we can figure out how to address
that later. Marking the split apk tests @Ignore for now.

Bug: 123695037
Bug: 127520966
Test: make -j80 dist tests, verify no RollbackT*.apk is included in the
      built device image.
Test: atest RollbackTest; atest StagedRollbackTest, verify no
      RollbackT*.apk is included in the built system image.

Change-Id: Ib413785b0974faddf19ac8dd7387b2642dab37e4
2019-03-07 14:57:53 +00:00
shafik
f90c69f42f Test Rollback Manager can handle time change
Test flow:
	* Install app A with rollback enabled
	* Wait half of the expiration time
	* Install app B with rollback enabled
	* Move time forward by expiration time
	* Wait half of the expiration time
	- At this point, an expiration check should run and expire app A
	but not app B
	* Assert app A rollback is expired
	* Assert app B rollback is not expired
	* Wait half of the expiration time
	* Assert app B rollback is expired

Note: installing app A before app B is done solely to schedule an
expiration check before app B rollback has expired

Test: atest RollbackTest#testTimeChangeDoesNotAffectLifetime
Test: run the same test without the registering the time change handler
in RollbackManagerServiceImpl - test fails
Bug: 124095332

Change-Id: I4bc2d449e4195e059fa43e7568783683a60e2197
2019-03-05 10:55:53 +00:00