Commit Graph

620 Commits

Author SHA1 Message Date
Al Sutton
eff34ec911 Merge "Rename variable to avoid mis-labelling as a TODO comment" 2019-12-31 10:07:32 +00:00
Chandan Nath
e4df2f6cbc Merge "remove unused private fields and unnecessary TODOs" 2019-12-30 20:40:06 +00:00
nathch
5e5a4486b0 remove unused private fields and unnecessary TODOs
1. the private members in BackupManagerServiceTest were all unused
2. remove TODO for b/124359804 which is marked as wont-fix.
3. remove adb backup multi-user TODOs as adb backup is deprecated and we
don't intend to extend multi-user support to it.

Bug: 136738613

Test: m -j
Change-Id: Ia4c6ebce7b9bb7ab8bfe1f6a18f9b67ec6098cd2
2019-12-30 11:01:46 +00:00
Al Sutton
1b8c06fa0b Rename variable to avoid mis-labelling as a TODO comment
Currently this variable gets picked up by simple scans for work
labelled TODO. By renaming it we can use simple filters to find
work in need of doing.

Bug: None
Test: atest BackupFrameworksServicesRoboTests
Change-Id: I5a5b5c6e49febae2636b6b4dc97ab3e922aa3eef
2019-12-30 10:55:24 +00:00
nathch
84c99f332e Remove duplicate code in initializing transports
Use enforceCallingOrSelfPermission which is the same as
enforceCallingPermission except it grants own permissions
when not processing an IPC.

Also remove unused private field from KeyValueBackupTask

Bug: 146939599
Bug: 136738613

Test: 1) adb shell bmgr enable true
2) adb shell bmgr enable false
3) adb shell am broadcast -a "android.app.backup.intent.INIT"
logcat is as expected:
BackupManagerService: Backup enabled => false
BackupManagerService: Running a device init; 3 pending
BackupManagerService: initializeTransport(): [com.android.localtransport/.LocalTransport, com.google.android.gms/.backup.migrate.service.D2dTransport, com.google.android.gms/.backup.BackupTransportService]
BackupManagerService: Initializing (wiping) backup transport storage: com.android.localtransport/.LocalTransport
....
BackupManagerService: Initializing (wiping) backup transport storage: com.google.android.gms/.backup.migrate.service.D2dTransport
...
BackupManagerService: Initializing (wiping) backup transport storage: com.google.android.gms/.backup.BackupTransportService

Change-Id: I98d87f3163cd7fbc1f7aa6712ec421cc8efd5d29
2019-12-28 12:59:17 +00:00
Carmen Agimof
79dc7ed61e Merge "Do not try to do a restore at install if the user is not ready for backup." 2019-12-13 16:41:21 +00:00
Carmen Agimof
4e55418864 Do not try to do a restore at install if the user is not ready for
backup.

Bug: 144155744

This solves a bug which makes staged installs hang. This is
happening because when installing, the PackageManager is waiting for a response to be sent back from
the BackupManagerService after it finishes restoring. In the case of staged installs which happen at boot,
isUserReadyForBackup is false, so the method does nothing and the
PackageManager keeps on waiting on a response.

Test: 1) atest RunBackupFrameworksServicesRoboTests and atest AutoRestoreHostSideTest
2) Manual:
   - Applied ag/9722795
   - run `atest com.android.tests.rollback.host.StagedRollbackTest#testStagedInstallHang`
   - The log file doesn't contain any "Watchdog: *** WATCHDOG KILLING SYSTEM PROCESS: Blocked in handler on main thread (main)".

Change-Id: I294c309b0c7e5a9e12bdbd0c3fc4946767f91cee
2019-12-12 16:29:00 +00:00
Ruslan Tkhakokhov
d7f5fdb43b Pass excluded keys to the backup agent in onRestore
Pass the list of the keys excluded from KV restore to the backup agent to make it aware of what data has been removed (in case it has any application-level consequences) as well as the data that should be removed by the agent itself.

Bug: 145126096
Test: atest CtsBackupTestCases
Change-Id: I34415b149b379fb5bb67b0fbcd70ec9b9858acfe
2019-12-11 13:43:32 +00:00
Ruslan Tkhakokhov
d1b4b81680 Fix NPE while reading leftover journals in BMS
Thisis the NPE bug we saw a while ago but it  has been coming up in test runs recently (b/). Let's fix the NPE for now and we can work on the underlying issue later.

Bug: 136730045
Test: atest DataChangedJournalTest
Change-Id: I7267f507be4c797491d86ebb8bc5e6c3c17652a3
2019-11-29 17:36:01 +00: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
Ruslan Tkhakokhov
004e85f798 Route EncryptedLocalTransport KV backup/restore through encryption code
Bug: 142227548
Test: Verify the device boots successfully
      Verify EncryptedLocalTransport APK is present
      Verify manual backup/restore using bmgr for LocalTransport and EncryptedLocalTransport
      For LocalTransport (unencrypted) and EncryptedLocalTransport:
        atest CtsBackupTestCases
        atest CtsBackupHostTestCases
        atest GtsBackupTestCases
        atest GtsBackupHostTestCases


Change-Id: Iac3a8a50d7f761442a4b784cfba3a980e900dd7f
2019-10-16 08:58:01 +00:00
nathch
b85b36ac09 Move transport client code into its own lib
We will route backup through the BackupEncryption APK which will
implement an intermediate transport which will encrypt (or decrypt) the data when
sending it (receiving it) from the real transport.

Since both backup services and IntermediateTransport need to bind to
IBackupTransport, they both need the transport client code so we move that
into its own lib.

Bug: 139269919

Test: atest -v RunBackupFrameworksServicesRoboTests
Test: atest -v $(find frameworks/base/services/tests/servicestests/src/com/android/server/backup -name '\''*Test.java'\'')'
Test: atest -v CtsBackupTestCases CtsBackupHostTestCases
Change-Id: Id986162ac71adf8638e5797169ef70e0d3d58b0c
2019-09-22 17:23:17 +01:00
Al Sutton
e4accbe31f Capture all exceptions rather than just IO ones.
If an exception which isn't in the IOException hierarchy gets
thrown within this code it can bring down the system_server, so
we should capture and log any exception rather than letting it
propagate out and bring down system_server.

I decided not to capture all Throwables because they represent
more serious runtime errors that probably should bring down
system_server.

Fixes: 140472631
Test: m -j (compilation means we're OK).
Change-Id: Ibbd9612d1e9b42c100ce7fda0b7463ac3f10704e
2019-09-12 08:36:28 +01: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
0c8b84e4a3 Move {get,set}AncestralSerialNumber() to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I48fd336dce36f39a7b0e7af5f0f9740ee2b4e246
2019-08-14 18:24:18 +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
1cc1768e7f Move isAbleToServeUser() to Trampoline
From BMS.

Test: atest BackupManagerServiceTest TrampolineRoboTest TrampolineTest
Bug: 135661048
Change-Id: I222d11dffd29d4ce1f30c3d68837110a2058a8aa
2019-08-14 14:32:55 +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
TreeHugger Robot
99a06dbb3d Merge "Move ACTION_USER_REMOVED broadcast receiver to Trampoline" 2019-08-09 17:34:43 +00:00
Bernardo Rufino
7d04bfd788 Move ACTION_USER_REMOVED broadcast receiver to Trampoline
From BMS.

Test: Inflate user 11 then remove it, make sure directory /data/backup/11 is
      removed
Bug: 135661048
Change-Id: I482e7fb4c8ccd630ab812a396d3570be996c2a62
2019-08-09 12:26:34 +01:00
Bernardo Rufino
ce725e3019 Merge "Move transport whitelist to Trampoline" 2019-08-09 10:28:10 +00:00
Bernardo Rufino
e736756815 Merge "Move sInstance to Trampoline" 2019-08-09 10:23:28 +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
Bernardo Rufino
11b651c295 Move sInstance to Trampoline
Test: Trigger KV and Full-backup jobs
Test: adb shell bmgr backupnow <package>
Bug: 135661048
Change-Id: If569ad290f2f57a30e859367f3fac289cf23e85d
2019-08-08 14:44:55 +01: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
Al Sutton
d222a61756 Infer the activation state from the presence of a BackupManagerService.
The filesystem is checked when the BMS is created for a user so we
don't need to recheck it every time we perform a backup related
operation because wihout the BMS we shouldn't say the system is
read for the user to back up their data.

Change-Id: Iaaa7d7381182ba7e05173cc4f5d25ce61054e210
Test: atest CtsBackupTestCases CtsBackupHostTestCases TrampolineTest BackupManagerServiceTest
Fixes: 133584471
2019-07-18 15:38:20 +01:00
Al Sutton
66fa3fb2cc [Cleanup] Rename variable to match standards
Change-Id: I8098f338602f90f9597f8cc7f703fb0b9459680f
Test: m -j (Build will fail if there are references to the old name)
2019-07-17 15:47:06 +01:00
nathch
a4405523b1 replace "android" by PLATFORM_PACKAGE_NAME
Bug: 123624096

Test: atest -v CtsBackupTestCases CtsBackupHostTestCases
Change-Id: I73abf9b1a230d895daaa80ca8a5e4157f1d96438
2019-07-12 17:18:45 +01:00
TreeHugger Robot
c255afdd89 Merge "remove unused code from PerformAdbRestoreTask" 2019-07-08 14:28:38 +00:00
nathch
4c37ddb46b remove unused code from PerformAdbRestoreTask
Bug: 8483208

Test: atest -v CtsBackupTestCases
Change-Id: I31c3f291725807e6cb29a1362b2ab9556095b089
2019-07-08 11:14:37 +01:00
Bram Bonné
77feda8167 Merge "Ports over BackupStreamEncrypter and related classes." 2019-07-05 14:45:43 +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
Chandan Nath
3c870a71e2 Merge "remove unused code" 2019-07-04 20:47:53 +00:00
nathch
eefaaa5573 remove unused code
1) FullRestoreEngine: mAllowObbs, mBytes are not used
2) PerformUnifiedRestoreTask: mSavedStateName is not used

also, use final,private where possible

Bug: 136738613

Test: atest -v CtsBackupTestCases CtsBackupHostTestCases
Change-Id: Ic65bbefdd47ba6f0c8ba9d117256972e15af2f8e
2019-07-04 15:08:13 +01: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
TreeHugger Robot
798a07f597 Merge "Readable constant in BackupManagerConstants" 2019-06-24 15:09:01 +00:00
Bernardo Rufino
3d460b95d1 Readable constant in BackupManagerConstants
Test: 1. adb shell dumpsys jobscheduler | grep -C 4 FullBackupJob
         Check Capabilities = NOT_METERED & INTERNET & NOT_RESTRICTED & TRUSTED
                              & VALIDATED
      2. adb shell dumpsys jobscheduler | grep -C 4 KeyValueBackupJob
         Check Capabilities = INTERNET & NOT_RESTRICTED & TRUSTED & VALIDATED

Change-Id: I4ca7c31995eb754beea602e94d664392e0959164
2019-06-20 09:59:18 +01: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