Some additional changes (apart from style) were needed:
- ChunkOrderingType.java is an @IntDef referencing the possible values
for the ChunkOrderingType enum in the proto.
- EncryptedChunk.java is no longer an AutoValue class.
- Inlined some constants from Guava.
Bug: 111386661,116575321
Test: atest RunFrameworksServicesRoboTests
Change-Id: I7656cae13de0bd918be5016ffb155de4b8fd5f71
This fix also refactors PackageParser.SigningDetails to move the
pastSigningCertificatesFlags to be a data member of Signature; this
allows the capabilities of a previous signing certificate to be
accessed directly from the Signature object as opposed to relying
on the 1-1 mapping of the past certs and flags in the SigningDetails.
Fixes: 73927696
Fixes: 73925989
Test: adb shell am instrument -w -e class com.android.server.pm.PackageSignaturesTest \
com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I635f2d2209350d066d1fa2ef07460071da0c023e
Added 2 exceptions:
* TaskException: For what we used to call transport-level failures,
these bring queue processing to a halt.
* AgentException: For failures that happen due to the backup agent, these
only prevent the backup of the current package, still allowing backup
for the remaining packages in the queue.
These are usually thrown deep in the call stack and caught in backupPackage()
(and similarly backupPm()) and run(), the former for clean-up, where
they are re-thrown and the latter for further processing where they are
finally swallowed. The clean-up is more explicit now.
This enabled further refactoring of backupPackage()/backupPm(),
extractAgentData() and sendDataToTransport().
One change that I intend to revisit is reporting to the observer.
Previously we used to detect some exceptional cases and set mStatus
(which doesn't exist anymore) to other more general exceptional case and
then in this general case handling report the success/failure to the observer.
With the new exception-throwing model I changed this and the leaves are
actually responsible for reporting success/failure to the observer (see
changes in the reporter). This is to avoid too many changes in this CL.
I'm entertaining the idea of extracting out package backup as a separate
class and leave only queue-processing and generic bookkeeping to this
class.
Test: atest FrameworksServicesRoboTests
Test: adb shell bmgr backupnow <kv_package>
Change-Id: If3b1da7a5eb939e453f94fad76f5790696d1265a
Includes the proto definition of ChunksMetadata and related classes.
Some additional changes (apart from style) were needed:
- EncryptedChunkOrdering was modified to be a non-AutoValue class, and
tests were added.
- Protos are now read from an InputStream manually, as any protos should not
be used directly in the platform.
- Helper classes are added for reading from ProtoInputStream.
Bug: 111386661,116575321
Test: atest RunFrameworksServicesRoboTests
Change-Id: I8b74ad059d72e305be7817f79f8c61aa50f7b268
Forgot this one in the CL. Also added tests to catch this in presubmit.
Test: atest FrameworksServicesRoboTests
Test: adb shell bmgr backupnow <kv_package> and verify no MORE_DEBUG
logs
Change-Id: I14affca28609bcd855e13fdcc160994c71ed9695
Some changes were needed to the original code:
- Guava's EqualsTester tests are replaced by regular equals tests.
- Guava's primitives.UnsignedBytes.LexicographicalComparator needed to
be copied over, as no corresponding comparator exists in the framework.
Bug: 111386661
Test: atest RunFrameworksServicesRoboTests
Change-Id: I24fef4b47f7777b9be0c2e51f0be48e45b323987
In full backup, we backup additional metadata about the app
(manifest, widget, apk, obb) not specified by the app's backup agent.
This CL extracts these methods out to their own helper (AppMetadataBackupWriter)
and adds unit tests for these methods.
** Note: The backup behavior is the same, only the structure has changed.
Behavioral changes will be done in future CLs. **
What this CL covers:
- Move the backup of this extra app data out of the FullBackupEngine to
separate agent data backup and non-agent data backup.
- Move logic of deciding what data to backup from FullBackupEngine to
FullBackupRunner (where the writer is used).
- Add unit tests for metadata backup.
- Some style fixes/clean up.
Not covered (future CLs):
- Refactoring FullBackupEngine/FullBackupRunner mechanism.
- Streaming backup data directly instead of writing to temporary files.
- Separating out and fixing apk and obb backup.
Bug: 110081582
Test: 1) atest AppDataBackupWriterTest
2) atest RunFrameworksServicesRoboTests
3) atest GtsBackupHostTestCases
4) Verify success for:
- adb shell bmgr backupnow <full backup package>; adb restore 1 <full
backup package>
- adb backup <full backup package>; adb restore
- cloud backup and restore
5) Use local transport and adb backup to inspect manifest and widget data
written and file metadata consistent between runs.
6) Verify compatibility with adb backup -keyvalue manifest
Change-Id: Icb43fd2e0505c2416738ee3ef370b206363fac68
They connect the dots around handleCancel() calling markCancel() and
waitCancel(). Missed those.
Bug: 110082831
Test: atest KeyValueBackupTaskTest
Change-Id: I6a5de571f5ac41ea609d44e26c73df5efb3cb775
For both key-value and full-backup. This makes the tasks wait for the
quota exceeded call, allowing the agent to complete before being torn
down (as described in bug). Also added a short time-out (3s) in case of
misbehaving agents.
Bug: 68762178
Bug: 110082831
Test: atest FrameworksServicesRoboTests
Test: 1. while true; do atest FullBackupQuotaTest; done
2. Stop after ~50 executions, verify all succeeded.
Test: 1. while true; do atest KeyValueQuotaTest; done
2. Stop after ~50 executions, verify all succeeded.
Test: CtsBackupTestCases
Change-Id: Ib582e75a4d317ab53a6df8cb261966a04ef085fb
And not a success as it used to be.
Bug: 111051813
Bug: 110082831
Test: atest KeyValueBackupTaskTest
Test: 1. BackupApp throwing in onBackup.
2. adb shell bmgr backupnow com.google.android.apps.backupapp
3. Verify logs and that it threw and we did not save backup data for it.
Test: 1. BackupApp not throwing.
2. adb shell bmgr backupnow com.google.android.apps.backupapp
3. Verify logs and that data was sent to transport.
Change-Id: Idb7fe298f64786668989c30cdce53355aeef7277
Refactor sendDataToTransport():
* Instead of truncating backup data when reading backup data / writing widget
data, consider the IOException a transport-level failure. Added tests for
this.
* Extracted a few methods: validateBackupData(), updateFiles(),
handleTransportStatus().
* Put the if (size > 0) check outside try-catch block.
* Used try-with-resources.
* Clean files in case of transport error, quota exceeded.
Refactor finishTask():
* Extracted triggerTransportInitializationLocked(), assigned queue lock
to private final var in ctor.
* In triggerTransportInitializationLocked() set the status to T_ERROR if
we failed to query the name of the transport.
* Tests for TRANSPORT_NOT_INITIALIZED.
General:
* Small refactors in KVBT.
* Small refactors in test.
Bug: 110082831
Bug: 113311470
Test: adb shell bmgr backupnow <kv_package>
Test: 1. adb shell bmgr backupnow <kv_package>
2. Transport returns T_NOT_INITIALIZED
3. Make sure PM metadata state file is deleted.
Test: atest KeyValueBackupTaskTest
Change-Id: I8d85c24cba6da4fbaf14234e2ce6d8e0699a3eed
Created KeyValueBackupReporter, which includes:
* Logcat (main and event buffers).
* Backup observer.
* Backup manager monitor.
Also removed traces since they weren't very useful. Hopefully this will clear
KVBT of noise and help spot refactor opportunities. Did some small refactors
along w/ it.
Methods are starting to fit in one (big) screen :)
Bug: 110082831
Test: atest KeyValueBackupTaskTest
Test: adb shell bmgr backupnow <kv_package> and verify logs
Test: Kicked-off KV in different scenarios to check logs, this is
tracked in https://docs.google.com/spreadsheets/d/1EcZ61qapj2cW_Yr99gIlQz0QVJ_BQfVc_1dHBor2cOo/edit?usp=sharing
Test: adb shell bmgr backupnow <kv_package> <fb_package>
Verify PFTBT is kicked-off and logs
Change-Id: I1486049861543b5ad558b45cf0e0206532e20632
This is the first CL of key-value backup refactor.
* Method execute() that executed the state machine states is now empty
and run() is created with the initial version of the linear task. It's
basically composed of begin + loop + end. Although it still has the notion
of state, it's more restricted than before (with private methods returning
the next state). This is intentional to avoid making this CL too heavy to
review and to avoid too much behavioral changes here. In the next CLs I
intend to remove BackupState.
* Introduction of RemoteCall, which encapsulates an outbound call that
leaves the system_server, with time-out and cancellation built-in.
Agent calls are now triggered using this. As a result there is no more
operationComplete() method either.
* Cancellation now is cleaner. We don't need a step lock anymore, only a
(volatile) boolean that is checked in every queue iteration. If asked
to cancel during an ongoing agent call we rely on RemoteCall.cancel()
to return control of the task thread to us. We wait for the cancel
acknowledgement to preserve the contract of no more transport calls.
* PFTBT instantiation moved from the constructor to the run() method,
which makes more sense.
* No need for mFinished, mBackupData == null bookkeeping since time-outs,
cancellation and legitimate agent responses won't step into one another
anymore.
* Ternary (mQueue.isEmpty) ? BackupState.FINAL : BackupState.RUNNING_QUEUE gone
because we check this in the beginning of invokeNextAgent() and now we
don't pay the state-machine tick price associated with the handler.
* PerformBackupTask call sites now call static method start(), that
spins up a new dedicated thread for the task. This new thread is
assigned the same (process) priority as the backup thread
(THREAD_PRIORITY_BACKGROUND).
Work left for future CLs:
* RemoteCall spins up a new thread for kicking off the call, this is for
system agents that are executed inline. Old PBT also executed in the same
thread (backup handler thread), so maintaining this to keep this CL at
a reasonable size.
Test: atest PerformBackupTaskTest
Test: atest RunFrameworksServicesRoboTests
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/backup
Test: atest CtsBackupTestCases
Test: atest CtsBackupHostTestCases
Test: atest GtsBackupTestCases
Test: atest GtsBackupHostTestCases
Test: adb shell bmgr backupnow <kv_packages>
Test: 1. adb shell bmgr backup <p1> <p2>
2. adb shell bmgr run
A) 3. Cancel while sending <p1> data to transport
4. Verify <p1> is backed-up and not pending
Verify <p2> is not backed-up and is pending
B) 3. Cancel while waiting for <p1> agent
4. Verify <p1> is not backed-up and is pending
Verify <p2> is not backed-up and is pending
Change-Id: Ia456c4e807de95d662c9e923245be07e8996f58a
With KV Refactor in mind:
* Tests around calling agent.
* Tests around agent writing data.
* Tests around transport handling agent data.
* Small modification on ShadowBackupData{Input,Output} to allow empty data.
* Small refactor.
Test: atest PerformBackupTaskTest
Change-Id: Ia9296859926d09d5bbcb0532fb869ace110240e4
With KV Refactor in mind.
* Split empty queue test into multiple tests.
* Tests around packages failing backup pre-conditions.
* Added verifications for event logging.
* Renamed some tests to better reflect important parts of it.
* More tests about one package.
* Introduced PackageData to help mock packages, much like TransportData.
* Some small refactors.
Test: atest PerformBackupTaskTest
Change-Id: I23aba2b26e82f8643cc1c90f9408510ab34045fd
With KV Refactor in mind.
* Added tests around empty queue and single package backups.
* Refactored a bit some of the existing tests.
* Moved from mocking BMS to using a real instance and had to adjust a
few things for this.
Test: atest PerformBackupTaskTest
Change-Id: I0ee3be32c7cbac5ed2cdc2717408749907c15ade
Documentation is pretty vague:
https://developer.android.com/guide/topics/data/autobackup#XMLSyntax.
But there were a couple of issues:
* It was prematurely returning false without consuming the rest of the
includes (cause of the bug linked).
* It was using string comparison for checking if a file is in a
directory, which ended up flagging directories such as "a/b" as
containing files "a/b.txt".
Reviewers,
* Please, pay full attention to test cases.
* Since this is code move + code change, set diff as 2..latest to check
changes to the function.
Bug: 110720194
Test: atest BackupUtilsTest
Test: Backup and restore app w/ multiple directory includes, verify
everything restored
Change-Id: Ic0fea43156ce8fb641af69ae73679289a20c291c
BMS.backupNow is called from GMSCore, which has a different calling
identity than the framework. This causes an IllegalArgumentException due
to uid mismatch when backupNow tries to schedule a job.
This occurs when the following conditions are combined:
1) Battery saver mode enabled
2) Network change detected
3) Backup pass is scheduled for now
Bug: 79441902
Test: 1) m -j RunFrameworksServicesRoboTests
2) Manual: Enabled battery saver, modified code to run backupNow with
each network change and overwrite previously scheduled KeyValueJob.
Then, change wifi to trigger scheduling the KeyValueJob.
Verified:
- IllegalStateException b/c of uid mismatch without change
- No exception and correct calling uid with change
Change-Id: Iac90cd435e3fc32ff5428236aa15507b36aa833d
When the agent provides a prohibited key, the code flow will directly be returned
without excuting next backup state. The next state should be execute instantly to
make sure the backup mechanism can be executed properly.
Bug: 77272601
Test: 1.m -j RunFrameworksServicesRoboTests
2.Manual testing by test package with prohibited key.
- adb backup -all
- adb backup -shared
- adb backup -obb -all
- adb shell bmgr backupnow --all
- adb shell bmgr backupnow [test key value package]
- adb backup -keyvalue [test key value package]
Change-Id: I46e1aa8dd0f75cf54087b43cee50ee952d85abc1