239 Commits

Author SHA1 Message Date
Chandan Nath
101f60b732 Merge "Dump information for all users running backup in backup dumpsys." 2020-01-10 15:01:47 +00:00
nathch
5d51c314c2 Dump information for all users running backup in backup dumpsys.
Currently backup dumpsys in bugreport only contains information
for system user making it hard to debug backup bugs in non-system
users. Therefore, add dumpsys information for all users running backup.

For system user, keep the dumpsys format the same for compatibility with
cts and gts tests. For non-system users, add a prefix "User <userid>:"
to all dumpsys headers.

The changes in Android.bp and AndroidManifest.xml are to support mocking
of the static method DumpUtils.checkDumpAndUsageStatsPermission in the
test testDump_systemUserFirst

Bug: 143867387

Test: atest com.android.server.backup.BackupManagerServiceTest

Test: atest com.android.server.backup.UserBackupManagerServiceTest

Test: adb shell pm create-user test1 -> say this gives 11
adb shell am start-user 11
adb shell bmgr --user 11 activate true
adb shell dumpsys backup users -> "Backup Manager is running for users: 0 11"
adb shell dumpsys backup -> contains both
"Backup Manager is enabled / setup complete / not pending init" and
"User 11:Backup Manager is disabled / not setup complete / not pending init"
adb shell pm remove-user 11

Test: "adb bugreport" on device with secondary user as created above and check that result
contains dumpsys for both system and secondary users.

Test: atest -v CtsBackupTestCases
Test: atest -v CtsBackupHostTestCases

Change-Id: Ib94c168f8e89b0ba8f398152ea744fe3d626efc4
2020-01-10 13:10:45 +00:00
WyattRiley
fa1ef8d34d Adding History of Location Requests to Dumpsys
Bug: 141716920
Test: m -j ROBOTEST_FILTER=LocationRequestStatisticsTest RunFrameworksServicesRoboTests
Test: On device verified history
Change-Id: Ia862e64415ef6132422ea3b2f1a22197e9b44c44
2020-01-07 23:09:58 -08:00
Ruslan Tkhakokhov
9e111f19df Add BackupManager#excludeKeysFromRestore()
Add the method as a hidden API for now. Move to System API later.

Bug: 145126096
Test: 1. Call BM#excludeKeyFromRestore for a test package
      2. Reboot the device
      3. Run restore for the test package
      4. Verify excluded keys are not restored

Change-Id: Ice57299eaf54cee8428b86e2d4f78de12b8db4fc
2019-11-28 20:33:24 +00:00
Suprabh Shukla
f7cffa7aaf Exposing WorkSource hidden APIs as system APIs
Users of these APIs are planning to move to apex.

Test: atest FrameworksCoreTests:android.os.WorkSourceTest
atest CtsOsTestCases:android.os.cts.WorkSourceTest

Bug: 143551137
Change-Id: I2e97a8b469254ea92e3ee21571ee8ae3cbb9abbe
2019-11-20 14:26:47 -08:00
Al Sutton
ad52c6bc3a Move backup encryption to separate APK
Test: atest -c --rebuild-module-info BackupEncryptionRoboTests
Change-Id: I5a8ac3a9c010bd3c516464dee333cef406c5dcfa
2019-09-06 10:22:33 +01:00
Bernardo Rufino
15bf74cf26 Merge Trampoline and BMS
Perform the merge by:
1. Moving lifecycle inside Trampoline without IDE support
(since we'll rename Trampoline in this CL as well, making the published binder
the same).
2. Move constants to Trampoline without IDE support as well (again, we'll
rename Trampoline).
3. Change the last usages of BMS constructor to use
Trampoline's. Now BMS is effectively empty.
4. Delete BMS.
5. Rename Trampoline to BMS with IDE support (renaming related classes
and variables that the IDE could find).
6. \o/

Split CL into Path Sets to ease review:
Base > PS2: Steps 1..4 (+121 -333)
PS2 > PS4: Step 5 (+214 -204)

Test: m -j
Test: adb shell dumpsys backup
Test: atest BackupManagerServiceTest BackupManagerServiceRoboTest
Bug: 135661048
Change-Id: Ia6cd340d3c5fcdb9c8f409035d032efeb090cd20
2019-08-16 14:54:18 +01:00
Bernardo Rufino
aa032460ca Move getServiceForUserIfCallerHasPermission() to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I7758e00635d385272b64bbc8d64dd0fd0ad600d2
2019-08-15 20:10:21 +01:00
Bernardo Rufino
0948c30a11 Move dump() to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I49bb231552eca269f4e694fe9ec91814f67822dc
2019-08-15 18:56:23 +01:00
Bernardo Rufino
f410de02e2 Move adb backup/restore operations to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I7f839a37780c5164878fd9640486c209f99620cc
2019-08-15 14:41:48 +01:00
Bernardo Rufino
a83c2e0865 Move restore operations to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I11d8912bca23eb9391e01016fab59346b0a6ac8c
2019-08-15 11:43:51 +01:00
Bernardo Rufino
b6bc6e2f4a Move backup operations to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: Ia44b7b839c2f871535e18d648be49277b46e3b11
2019-08-15 11:43:47 +01:00
Bernardo Rufino
7dedc861b6 Move settings operations to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I47e8072898555fd881ffa7b3d546e858fad01c6d
2019-08-15 10:25:45 +01:00
Bernardo Rufino
470f8be8b4 Move updateTransportAttributes() to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I4527e24a35f8a65f87cb3d9d383485546b4b64e8
2019-08-14 16:02:29 +01:00
Bernardo Rufino
b188863fcc Move more transport operations to Trampoline
From BMS. Namely:
* selectBackupTransport()
* selectBackupTransportAsync()
* getConfigurationIntent()
* getDestinationString()
* getDataManagementIntent()
* getDataManagementLabel()

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I9dbc0c4dfa73bd9738ae658ff24f986000ffc54b
2019-08-14 15:53:51 +01:00
Bernardo Rufino
dd1fbf2b15 Move some transport operations to Trampoline
From BMS. Namely:
* initializeTransports()
* clearBackupData()
* getCurrentTransport()
* getCurrentTransportComponent()
* listAllTransports()
* listAllTransportComponents()

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: Ib81550b4da7615f3713c340beccd3f85eb08ca7f
2019-08-14 15:40:44 +01:00
Bernardo Rufino
ae1b0d8885 Move backup agent operations to Trampoline.
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I7e118631e293d8eb808cf47e857b9102eab60d37
2019-08-14 14:54:20 +01:00
Bernardo Rufino
9b55bfbd17 Move start and stop of sub-systems to Trampoline
From BMS. Moved mUserServices list creation from BMS to Trampoline.
BMS still uses it but the plan is to move gradually in multiple
CLs to eventually delete it. Both are dealing with the same instance
because of this. Start and stop of sub-system (uBMS) is now handled in
Trampoline. getUserServices() was also moved. BMS robolectric tests were moved
to Trampoline *robolectric* tests to simplify this CL. After we merge BMS and
Trampoline, we can look into moving tests away from Robolectric.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I4e612d06fe006c12f215a94f210450a5e6316b75
2019-08-13 18:36:24 +01:00
Bernardo Rufino
ce725e3019 Merge "Move transport whitelist to Trampoline" 2019-08-09 10:28:10 +00:00
Bernardo Rufino
973194fa35 Move transport whitelist to Trampoline
From BMS.

Test: adb shell bmgr whitelist
Bug: 135661048
Change-Id: Ice0b49dc574cb1dfd7348a956e80abcd6c73cfa2
2019-08-08 18:59:46 +01:00
Ruslan Tkhakokhov
cb28da9cb1 Fix Robolectric tests that use JobScheduler
In ag/8881405 registering JobScheduler with SystemRegistryService has moved int JobSchedulerFrameworkInitializer. Make sure that class is loaded before the tests are run.

Bug: 138840929
Test: atest RunBackupFrameworksServicesRoboTest
Change-Id: Idacab9f8597b57df5b61a5c6619090a242a76264
2019-08-07 19:05:34 +00:00
Chandan Nath
038f7d69b7 Merge "Add stop method to backup handler thread." 2019-08-07 10:56:48 +00:00
nathch
15bee2d83d Add stop method to backup handler thread.
This manually cherry picks ag/8713360 into master. I had to do a manual
cherry pick as the cherry pick from gerrit fails with:
"Could not perform action: Cannot create new patch set of change 8677635
because it is abandoned"

Currently we call .quit() on the underlying thread which will cause all
messages to stop being processed. This has the side effect that, because
the backup system is a state machine where the state transitions are
messages, the message to transition into a state where the WakeLock is
released may not occur when a user is torn down.

This change adds a stop method we can call instead of .quit() on the
thread which drops any remaining messages and then releases the
WakeLock.

We also wrap the wakelock acquire/release calls to prevent any acquire/release on
the underlying wakelock after a quit. For the acquire, this avoids a non-released
wakelock and for the release, this avoids a runtime exception which can happen
when we release a released wakelock

Test: atest CtsBackupTestCases CtsBackupHostTestCases
Test: m RunBackupFrameworksServicesRoboTests && atest RunBackupFrameworksServicesRoboTests
Bug: 136264323
Change-Id: Ic8742bf01a0ff71bd57dd73b01a423d3432bf7b2
2019-08-06 18:09:40 +01:00
Bernardo Rufino
d1df67ef43 Eagerly initialize BMS in Trampoline's constructor
After multi-user BMS became a lightweight class as well, so no need to
lazily initialize it. This lays the ground for unifying Trampoline and
BMS.

Test: atest TrampolineTest
Test: adb shell bmgr backupnow <package>
Bug: 135247112
Bug: 135661048
Change-Id: Ia7f69d2ed282c6dfe6443a601f27229d43802fe6
2019-08-05 14:35:40 +01:00
Colin Cross
99a6e44eab Merge "Convert frameworks/base/services/robotests to Android.bp" into stage-aosp-master am: 6c074332a9 am: 789419cf51 am: 1c58fb2928
am: 62d5b19f0c

Change-Id: I73e16fe06428d037fcf71fb65c5ce1c6e663fa75
2019-07-24 20:21:13 -07:00
Colin Cross
1c58fb2928 Merge "Convert frameworks/base/services/robotests to Android.bp" into stage-aosp-master am: 6c074332a9
am: 789419cf51

Change-Id: I678ad1d2b4a0e9c27e522159d31fbdcab6b6eef0
2019-07-24 19:18:31 -07:00
Colin Cross
c65ca26446 Convert frameworks/base/services/robotests to Android.bp
See build/soong/README.md for more information.

Bug: 122332340
Test: m RunFrameworksServicesRoboTests RunBackupFrameworksServicesRoboTests
Change-Id: I3c768074c181a6072c7c1fee4a66faa8b4f5c2f4
2019-07-24 15:14:39 -07:00
nathch
842369a82b DO NOT MERGE Add stop method to backup handler thread.
Currently we call .quit() on the underlying thread which will cause all
messages to stop being processed. This has the side effect that, because
the backup system is a state machine where the state transitions are
messages, the message to transition into a state where the WakeLock is
released may not occur when a user is torn down.

This change adds a stop method we can call instead of .quit() on the
thread which drops any remaining messages and then releases the
WakeLock.

We also wrap the wakelock acquire/release calls to prevent any acquire/release on
the underlying wakelock after a quit. For the acquire, this avoids a non-released
wakelock and for the release, this avoids a runtime exception which can happen
when we release a released wakelock

Test: atest CtsBackupTestCases CtsBackupHostTestCases
Test: m RunBackupFrameworksServicesRoboTests && atest RunBackupFrameworksServicesRoboTests
Test: blaze run -- //experimental/users/nathch/py/bug_repros:repro 136264323 -m acquire_quit  -log DEBUG
Test: blaze run -- //experimental/users/nathch/py/bug_repros:repro 136264323 -m quit_acquire  -log DEBUG
Test: blaze run -- //experimental/users/nathch/py/bug_repros:repro 136264323 -m acquire_quit_release  -log DEBUG
Bug: 136264323

Change-Id: I42dcf997fc44cde05695a563aa19c8e47f6f9f26
2019-07-24 17:46:09 +00:00
Bram Bonné
bfb4faa823 Ports over BackupStreamEncrypter and related classes.
Additional changes apart from style and dependency fixes:
- Removes Guava dependencies.
- Uses Slog for logging.

Bug: 111386661
Test: atest RunFrameworksServicesRoboTests
Change-Id: I2f96fd9f2d2ec0d771c326c619eaca4ab4fa80c4
2019-07-05 11:36:01 +02:00
Bram Bonné
8b8c2d6882 Ports DecryptedChunkFileOutput and related classes.
Bug: 111386661
Test: atest RunFrameworksServicesRoboTests
Change-Id: I439d96855ceae2f614adaf0c6701f89c65864468
2019-07-02 17:21:21 +02:00
nathch
e0e4c82385 Unsubscribe listeners when stopping UserBackupManagerService and remove unused code
Unsubscribe listeners as otherwise they schedule work on a stopped handler thread
after the user backup manager service is stopped

Also cleanup by removing unused code:
a) mBackupThread from BackupManagerService
b) TAG from BackupAgentTimeoutParameters
c) getRunningFullBackupTask from UserBackupManagerService

Bug: 135261178
Bug: 135180752

Test: 1. atest -v RunBackupFrameworksServicesRoboTests
2. atest -v $(find frameworks/base/services/tests/servicestests/src/com/android/server/backup -name '\''*Test.java'\'')
3. atest -v CtsBackupTestCases
4. atest -v CtsBackupHostTestCases

Change-Id: Ie199dd49c336a2519c0f8e6c8dda12d8cba8350a
2019-06-17 18:02:10 +01:00
Ruslan Tkhakokhov
279a46bdbb Merge "Add dumpsys param to dump users running backup service" into qt-dev am: 1d6b6aea68
am: 1ee06b99eb

Change-Id: Ie6f181748929faabb950849a0edee1594e94b343
2019-05-10 16:52:56 -07:00
Ruslan Tkhakokhov
e0399328c9 Add dumpsys param to dump users running backup service
This is required in CTS tests to know when UserBackupManagerService init is finished.

Bug: 131307343
Test: 1) atest RunBackupFrameworksServicesRoboTests
      2) atest CtsBackupTestCases
      3) atest CtsBackupHostTestCases
      4) atest GtsBackupTestCases
      5) atest GtsBackupHostTestCases

Change-Id: Ia220f32b5be793b3b36efb2985604e29b0015e53
2019-05-10 08:10:47 +00:00
Al Sutton
9b6ae901eb Re-add the logging to track when a backup transport is used which hasn't been initialised.
Test: atest RunBackupFrameworksServicesRoboTests
Fixes: 110781477
Change-Id: I8645fb4eab24dc531b93e865003d894dc1877d99
2019-04-25 13:25:31 +01:00
Ruslan Tkhakokhov
451e2d843d Merge "BroadcastReceiver in UserBackupManagerService can crash system_server" into qt-dev 2019-04-17 14:54:46 +00:00
Annie Meng
599e9b3cc2 Fix KeyValueBackupTaskTest shadow errors
Replace IPackageManager with PackageManagerInternal to avoid shadowing
ActivityThread. This shadow is prone to unrelated framework changes breaking
our tests.

Bug: 130540953
Test: 1) atest RunBackupFrameworksServicesRoboTests
2) atest AppBackupUtilsTest

Change-Id: Iea95a37da3df9d3f0887ed5ab30c7007306415a1
2019-04-16 16:00:19 +01:00
Ruslan Tkhakokhov
dd5e5e35b2 BroadcastReceiver in UserBackupManagerService can crash system_server
Make sure mBroadcastReceiver is initialized after its dependencies,
i.e. mTransportManager.

Bug: 130408863
Test: 1) atest RunBackupFrameworksServicesRoboTests
      2) atest CtsBackupTestCases
      3) atest CtsBackupHostTestCases
      4) atest GtsBackupTestCases
      5) atest GtsBackupHostTestCases

Manual test:
1) Before fix: Add Thread.sleep() before mTransportManager is
initialized in constructor and tirgger PACKAGE_CHANGED event. Verify
broadcast receiver callback is triggered and systen_process crashes.
2) After fix: Add Thread.sleep() before mTransportManager is
initialized in constructor and tirgger PACKAGE_CHANGED event. Verify
broadcast receiver callback is not triggered.

Change-Id: If1628628176a08a2d33d020ce270de92b606d6df
2019-04-16 12:14:51 +01:00
Colin Cross
0a2d8cbb26 Convert frameworks/base/cmds/media and bmgr to Android.bp
See build/soong/README.md for more information.

Bug: 122332340
Test: m media
Test: m RunBackupFrameworksServicesRoboTests
Change-Id: Ieb54feb3902bddfd5a571369fbf50161ae646647
2019-03-29 12:41:25 -07:00
Annie Meng
4eb4efc466 API Review: Make dataManagementLabel a CharSequence
Make the data management label a CharSequence for the system APIs:
- BackupManager#updateTransportAttributes
- BackupManager#getDataManagementLabel
- BackupTransport#dataManagementLabel

Renames dataManagementLabel -> dataManagementIntentLabel to change
return type

Removes getDataManagementLabel AIDL method as usages converted to use
"forUser" version in topic CL.

Bug: 113856654
Test: 1) atest RunBackupFrameworksServicesRoboTests
2) atest BackupManagerTransportAttributesHostSideTest
3) atest $(find \
frameworks/base/services/tests/servicestests/src/com/android/server/backup \
-name '*Test.java')
4) Manual: boot and verify transports registered properly using old API;
Modify LocalTransport to use new API, verify success

Change-Id: Ia48017156debe0a29684909f58927fa1fbf972f9
2019-03-20 12:13:10 +00:00
Ruslan Tkhakokhov
507e6f834d API Review: Internal RestoreSession#restorePackages
Bug: 120843781
Test: 1) atest RunBackupFrameworksServicesRoboTests
      2) atest CtsBackupTestCases
      3) atest CtsBackupHostTestCases
      4) atest GtsBackupTestCases
      5) atest GtsBackupHostTestCases

Change-Id: Ice42aedd702e1c16b074d7a00d7b15d8f4aaf733
2019-03-18 12:26:02 +00:00
Annie Meng
36953aa154 Move chunking backup tests to correct test target
Bug: 124311427
Test: atest RunBackupFrameworksServicesRoboTests -> verify moved tests
run;
atest RunFrameworksServicesRoboTests -> verify only location tests run

Change-Id: I9086a97c6ca0e269bbec14ac7e2056f283b0fb51
2019-02-13 10:28:41 +00:00
Bram Bonné
985b1800d4 Renames ChunkListing.java to ChunkListingMap.java.
Bug: 111386661
Test: atest RunBackupFrameworksServicesRoboTests
Change-Id: I94327204ed39b4b4a6138eb6ddd1b28732a16363
2019-02-12 09:29:19 +00:00
Bram Bonné
af4ba04daf Merge "Ports DiffScriptBackupWriter from gmscore to AOSP." 2019-02-07 09:36:51 +00:00
Bram Bonné
02cf411d27 Ports DiffScriptBackupWriter from gmscore to AOSP.
A few additional changes (apart from style and usual dependencies) were
needed:
- Additional dependencies (not part of Backup & Restore code) were
ported over:
	- ByteRange
	- DiffScriptWriter
	- OutputStreamWrapper
	- SingleStreamDiffScriptWriter

- DiffScripBackupWriter.ENCRYPTION_DIFF_SCRIPT_MAX_CHUNK_SIZE_BYTES is
now a constant rather than a flag.
- Additional tests were added for SingleStreamDiffScriptWriter.

Bug: 111386661
Test: atest RunBackupFrameworksServicesRoboTests
Change-Id: Ia3234bb8d665211e6fa91d6a92d190171b0d2dc1
2019-02-06 18:00:30 +01:00
Stefano Tommasini
471a35da6c Create API in BackupManagerService for work profile serial id mapping.
The launcher needs to know the serial id of the ancenstral device's work
profile  and the serial id of the current device's work profile in order
to properly perform a restore.

Test: atest BackupManagerService
Bug: 111301511

Change-Id: Ia929dcc2cb599f935183be1820b1c45f2d6e1de7
2019-02-05 18:16:49 +00:00
Annie Meng
21a91fbbd0 [Multi-user] Schedule full backup jobs immediately
All other schedule call sites for full backup and key value schedule
inline. The operation should be quick and scheduling on a separate
handler makes testing flaky.

Test: 1) atest RunBackupFrameworksServicesRoboTests
2) atest ScheduledBackupHostSideTest
3) atest ProfileScheduledJobHostSideTest
Change-Id: Id6ae557080da5a98c2ac572ca6b4b7973b7a9c29
2019-01-28 19:29:57 +00:00
Ruslan Tkhakokhov
6712b72a48 [Multi-user] Verfiy full backup/restore flow
Bug: 121198030
Test: 1) atest RunBackupFrameworksServicesRoboTests
2) atest $(find \
frameworks/base/services/tests/servicestests/src/com/android/server/backup \
-name '*Test.java')
3) atest CtsBackupTestCases
4) atest CtsBackupHostTestCases
5) atest GtsBackupTestCases
6) atest GtsBackupHostTestCases

Manual testing:
1. Start secondary user -> verify fb-schedule file is created, full backup queue initialised
2. Verify fullbackup of 1 package for system/secondary users, [package] only exists for current user:
  * bmgr --user [user-id] fullbackup [package]
  * Verify in logs that backup is successful
  * Uninstall/install [package]
  * Verify data is restored
3. Verify fullbackup of 1 package for secondary user, [package] eixtst for user 0:
  * bmgr fullbackup [package]
  * bmgr --user [user-id] fullbackup [package]
  * Verify in logs that backup is successful
  * Uninstall/install [package] for secondary user
  * bmgr --user [user-id] restore [token] [package]
  * Verify the data restored is different from system user data and belongs to [user-id]
3. Verify backup of all packages for system/secondary users:
  * bmgr --user [user-id] backupnow --all
  * Verify system packages (android, settings, wallpaper) are skipped for secondary user
  * Verify in logs that backup is successful
  * Uninstall/install [package]
  * Verify data is restored

Base -> Patchset 2: Update method calls to use asUser versions
Patchset 2 -> Patchset 3: Update opComplete callback to accept userId
Patchset 3 -> Patchset 4: Gate system packages from backup/restore for non-system users

Change-Id: Ic3986709ba4d46c0af9da45bb4dd682ee2aef3ce
2019-01-23 15:57:11 +00:00
Annie Meng
53cf520817 [Multi-user] Convert various calls to use user id
Changes various transport, restore and general bookkeeping flows. Also
performs restorecon recursively to relabel child directories properly.

Bug: 121198605
Bug: 121197942
Bug: 121198606
Test: 1) atest RunBackupFrameworksServicesRoboTests
2) user unlocked -> transports registered successfully
3) adb shell bmgr backupnow [package]
4) Cloud restore backup set from 3) -> apps + widgets successful
5) atest BackupManagerTransportAttributesHostSideTest
6) Add secondary user -> check all directories/files relabelled
Change-Id: I26b23fd7bf10b792658fa7c44941be50aee65521
2019-01-16 12:51:12 +00:00
Annie Meng
ca1b5b9f9a Merge "[Multi-user] Convert key-value flow to use user id" 2019-01-14 23:43:16 +00:00
Ruslan Tkhakokhov
1cf011cd76 Merge "[Multi-User] Make JobScheduler logic multi-user aware" 2019-01-14 20:07:14 +00:00