Commit Graph

584 Commits

Author SHA1 Message Date
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
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
Al Sutton
db31ab6238 Set DEBUG_SCHEDULING to dalse by default
Change-Id: Id617362c7c1f097859d768179fcfa3fcda42dcb7
Test: atest CtsBackupTestCases CtsBackupHostTestCases GtsBackupTestCases GtsBackupHostTestCases
Fixes: 133822681
2019-06-03 17:18:16 +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
1ee06b99eb Merge "Add dumpsys param to dump users running backup service" into qt-dev
am: 1d6b6aea68

Change-Id: Icb7ff269427311f38219fc8088aea7c394ef5f96
2019-05-10 05:48:15 -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
Ruslan Tkhakokhov
a050ab3493 Merge "Restore can begin while clearing app data is in progress" into qt-dev am: c1da324980
am: b5a044d872

Change-Id: Ide10099cb4671e12e87f71e65813f1575fbe1798
2019-04-30 11:39:30 -07:00
Ruslan Tkhakokhov
b5a044d872 Merge "Restore can begin while clearing app data is in progress" into qt-dev
am: c1da324980

Change-Id: I3cb6ae4fda47ee82e608f3c7ab64ffedc5c65f1e
2019-04-30 10:06:23 -07:00
Ruslan Tkhakokhov
29621710fb Restore can begin while clearing app data is in progress
Increasing timeout should help as in the only recent instance where we
saw this bug, it just exceeded the timeout by a second. Mostly the clear
operation happens very fast. Plus no obvious other solution to this
without major changes to BMS.

Fixes: 130347754
Test: 1) atest CtsBackupTestCases
      2) atest CtsBackupHostTestCases
      3) atest GtsBackupTestCases
      4) atest GtsBackupHostTestCases

Change-Id: I462724f2ea9a9bddd3a876e7f69302c35d69a0cb
2019-04-26 11:40:40 +01: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
TreeHugger Robot
54db33f025 Merge "Switch to HexEncoding from ByteStringUtils" 2019-04-19 03:11:24 +00:00
Ruslan Tkhakokhov
b9cba444d8 Merge "BroadcastReceiver in UserBackupManagerService can crash system_server" into qt-dev am: 451e2d843d
am: a92bb9fa57

Change-Id: Iff4ab17ffc0746a653859af6acf1bb8e9d384890
2019-04-17 09:17:30 -07:00
Ruslan Tkhakokhov
a92bb9fa57 Merge "BroadcastReceiver in UserBackupManagerService can crash system_server" into qt-dev
am: 451e2d843d

Change-Id: Ia9bd1739203684ece631c53f6cdd1ab6d26e0f1c
2019-04-17 08:18:09 -07: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
8e1ea47201 Merge "Fix KeyValueBackupTaskTest shadow errors" into qt-dev am: e6763f287b
am: 13d6dcaf0a

Change-Id: I6e9728a48316b21ca00ac1dffbc0a7c0cb119ef0
2019-04-17 06:52:29 -07:00
Annie Meng
13d6dcaf0a Merge "Fix KeyValueBackupTaskTest shadow errors" into qt-dev
am: e6763f287b

Change-Id: I188d0a2905fd532333e55b0fc5191d0b63c5af86
2019-04-17 05:31:59 -07:00
Al Sutton
e2f8a0f11d Lower log level for errors which are limited to the backup of a single package
Change-Id: I6b086312496e152f613154d2942d1ec28ef64625
Fixes: 75718456
Test: Compilation will fail if the method being used now isn't
available.
2019-04-17 11:24:58 +01: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
Neil Fuller
a76674f153 resolve merge conflicts of fe9b32e4be to qt-dev-plus-aosp
Bug: None
Test: I solemnly swear I tested this conflict resolution.
Exempt-From-Owner-Approval: Merge conflict resolution for approved change
Change-Id: I39bda8417f709f86b5b389a75ff34df8a28a3d8d
2019-04-11 18:09:18 +00:00
Neil Fuller
6f34427eb2 Switch to HexEncoding from ByteStringUtils
Migration in preparation for deletion of ByteStringUtils.

Bug: 124232146
Test: build only
Change-Id: Iff3a6b11adb8bcc51417a2e96e42c2db8a2de257
2019-04-11 12:03:42 +01:00
Neil Fuller
b5d1c15ec2 Switch from Byte.toHexString() to HexEncoding
Switch from Byte.toHexString() to HexEncoding equivalents.

Bug: 124232146
Test: build only
Exempt-From-Owner-Approval: Cherry-picking OWNERS approved internal version
Merged-In: Id244e5247eb87c67446cbd65eb5d320f3617b8cd
Change-Id: Id244e5247eb87c67446cbd65eb5d320f3617b8cd
2019-04-11 09:27:45 +00:00
Neil Fuller
5c3f8c6562 Switch from Byte.toHexString() to HexEncoding
Switch from Byte.toHexString() to HexEncoding equivalents.

Bug: 124232146
Test: build only
Change-Id: Id244e5247eb87c67446cbd65eb5d320f3617b8cd
2019-04-08 14:55:29 +01:00
Chandan Nath
7053e28b59 [Multi-user] Clean up user state stored in the system user directory
when user is removed.

For non system users, backup state is stored in both the user's own dir and the system dir.
When the user is removed, the user's own dir gets removed by the OS. This code change ensures
that the part of the user backup state which is in the system dir also gets removed.

Bug: 127650374

Test: atest -v CtsBackupHostTestCases:android.cts.backup.MultiUserBackupStateTest

Change-Id: I4ea252e8e6da608e36ec3ac335666923d88a8748
2019-04-03 13:36:55 +01:00
Chandan Nath
4fe554ae58 isBackupServiceActive should not depend on whether the user is started
Bug: 129763613

Test: atest com.android.server.backup.TrampolineTest
Change-Id: Ia05451a4d45a14bc30353e268cb6616ceb49947e
2019-04-02 21:20:31 +01: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
Ruslan Tkhakokhov
57263a6c34 Fix runtime restart: at com.android.server.backup.restore.FullRestoreEngine
When a full backup operation times out, resources are cleaned up
including closing and nullifying pipes. However FullRestoreEngine.restoreOneFile()
doesn't stop execution and can access the pipes causing RuntimeException.

This CL adds a flag to show whether the operation has timed out and
checks it before accessing the pipes.

Bug: 126244736
Test: 1) atest RunBackupFrameworksServicesRoboTests
      2) atest CtsBackupTestCases
      3) atest CtsBackupHostTestCases
      4) atest GtsBackupTestCases
      5) atest GtsBackupHostTestCases
      6) Manual: Test full backup/restore flow using Flipboard app

Change-Id: If400142a6fceaa4065409774bbff1cad8b4c6163
2019-03-15 11:37:43 +00:00
Ruslan Tkhakokhov
70afec382d Fix BackupManager#getUserForSerialNumber
Test: atest ProfileSerialNumberHostSideTest

Currently BackupManager#getUserForSerialNumber goes through users
associated with the calling user (inluding the calling user itself) and
looks for the given serial number. However, to get the list of users it calls
UserManager#getUserProfiles that operates for the users associated with
the calling process (in our case - system user since the call is made
from BMS). While this works for our current use case (only support
backup for system user and their work profile, meaning
BackupManager#getUserForSerialNumber will only be called for system
user), it won't work for a full multi-user case.

Change-Id: Ia42a69a1216ed9a5dae596e44336290d2718de7a
2019-02-21 15:23:53 +00:00
Ruslan Tkhakokhov
d894401fee BackupManager shouldn't clear app's data during restore if agent wasn't invoked yet
Bug: 123738850
Test: 1) atest RunBackupFrameworksServicesRoboTests
      2) atest CtsBackupTestCases
      3) atest CtsBackupHostTestCases
      4) atest GtsBackupTestCases
      5) atest GtsBackupHostTestCases
      6) Manual: Force exceptions before/after agent was called, verify
                 the new behavior.

Change-Id: Ia9ddea2939fc6d72dd9bc060b0c47bc8da2b868d
2019-02-18 17:02:21 +00:00
Ruslan Tkhakokhov
aee28fd42f Use new manifest flag to gate clearing data during restore
Use the new manifest flag introduced in ag/5762489 to gate clearing data
during restore.

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

Change-Id: Ida4a9e96f44d1c740d217faed2b9f928e02865ec
2019-02-15 20:23:11 +00:00
Chandan Nath
953682187e [Multi-user]: R backwards compatibility in activating/deactivating the service
Bug: 123347794

In Q, backup is OFF by default for non-system users. In R, we will change that to ON
unless backup was explicitly deactivated with a (permissioned) call to
setBackupServiceActive.
Therefore, remember this for use in R. Basically the default in R will be
rememberFile.exists() ? rememberFile.value() : ON
Note that this has to be done right after the permission checks and before any other
action since we need to remember that a permissioned call was made irrespective of
whether the call changes the state or not.

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

Change-Id: I0897d6f9f8d8d8a9fc3c0faabfc9045b416dd25f
2019-02-14 13:19:05 +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
Stefano Tommasini
bd8491866c Merge "Create API in BackupManagerService for work profile serial id mapping." 2019-02-06 17:41:02 +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
924c8a92ac [Multi-user] Whitelist "android" for non-system user backup
Move to a whitelist of system apps that are eligible for backup in
non-system users.

Bug: 123349308
Test: "adb shell bmgr backupnow android" succeeds for system
and non-system users.

Change-Id: I7bc4982a6e105c2343636532dd2010aa43132d23
2019-01-31 17:23:12 +00:00