193 Commits

Author SHA1 Message Date
Anton Philippov
bc44678fb1 Add null check in BackupManagerService$PerformBackupTask.handleCancel()
handleCancel() can be called before we start backing up any particular
package, therefore we need to properly handle log messages in that case.

Bug: 36638539
Test: manual
Change-Id: Ic96e2fbad5c0a79640a3419d187e8b5e4d265de3
(cherry picked from commit 519a87db8fabb49f299aa384aeb5cfe4dfedf907)
2017-03-28 11:25:44 +00:00
Johan Toras Halseth
b59a4b85ad Add support for key-value packages to adb backup/restore.
For adding CTS tests for packages having key-value backup agents, we add
support for key-value backups to the adb backup/restore command.
Previously, packages not supporting fullbackup would just be skipped on
this command. Now, by adding the -keyvalue flag to the adb backup command,
packages supporting key-value will also be added to the resulting
tarball. Similarly, if the tarball being supplied to adb restore
contains data from key-value packages, it will be restored.

This will later be utilized for writing CTS tests for such packages.

Test: adb backup -includekeyvalue -all && adb restore backup.ab

Change-Id: I7b4ccfb7072d01d29a888952145d7cce90a4f59e
2017-03-24 23:51:48 +00:00
Michal Karpinski
8e4d6d0ef8 Explicitly rebind to a transport after timeout
When a TransportConnection received onServiceDisconnected() we give automatic rebinding
a chance, but if it doesn't happen within a few minutes we take matters into our hands
and attempt to rebind explicitly.
The timeout is significantly lower if the device is still unprovisioned - this is to increase
chances of proper transport binding during the setup process.

Bug: 34464359
Bug: 30964151
Test: manual, by crashing gms and gms.persistent process with "adb shell cmd activity crash #pid"
      and waiting for timeout to kick in
Change-Id: Ia7e5b0e54faf48ba8566f50057a3cae8bb3ab137
2017-03-22 11:37:48 +00:00
jackqdyulei
455e90add2 Add BatterySaverPolicy for power save mode
The BatterySaverPolicy is designed to consolidate all battery saver
knobs into a central location. Usually it is consistent to
mLowPowerModeEnabled unless it gets different data for specific
service. By adding these knobs, we can effectively tune the battery
saver.

This cl sets up the framework for BatterySaverPolicy and updates
following service to get battery saver data from BatterySaverPolicy

1. GnssLocationProvider
2. VibratorService
3. WindowManagerService
4. BackupManagerService
5. SoundTriggerService
6. NetworkPolicyManagerService

Screen brightness will come in a following cl.

Bug: 34693888
Test: FrameworksServicesTests

Change-Id: I6b040e93391614b44d136a485faa4a332c396e51
2017-03-08 09:20:36 -08:00
Michal Karpinski
eb4ab301e1 BackupManagerService#cancelBackups() releases mCurrentOpLock sooner
Incoming operations don't have to block until all backup ops to be
cancelled are handled.

Test: make gts -j40 && gts-tradefed run gts -m GtsGmscoreHostTestCases -t com.google.android.gts.backup.BackupManagerHostTest
Bug: 35767318
Change-Id: I1c6f7a1cfbfc18483311044a75e46cd4e8f9f4f3
2017-03-06 13:42:27 +00:00
Anton Philippov
fb887a69b6 Pass an empty list to PerformBackupTask constructor instead of null
Recent changes to PerformBackupTask made it expect empty list rather
than null for the ArrayList<String> pendingFullBackups argument.

Bug: 35420596
Test: manual
Change-Id: I8e1f69e78856b9bb8fc8aa9ab1adcac634314a36
2017-03-03 21:19:36 +00:00
Anton Philippov
b870c8e3e2 Merge "Add more instrumentation to BackupManagerService" 2017-03-03 15:09:04 +00:00
Anton Philippov
deb244d3e5 Add more instrumentation to BackupManagerService
Test: manual
Change-Id: I41096b47f594c5254f499778bab996dfdfc13f66
2017-03-02 16:50:50 +00:00
Michal Karpinski
55e15bcc3a Use iterator to remove elements from collection when traversing it
Per Java documentation "Iterator.remove is the only safe way to
modify a collection during iteration; the behavior is unspecified
if the underlying collection is modified in any other way while
the iteration is in progress."

Test: updated gmscore to check that onPackageRemoved() works correctly
Bug: 35846264
Change-Id: I878e581db3bf60b9c6b2cf861f66d8b427202b02
2017-03-02 12:05:57 +00:00
Shreyas Basarge
ba9e399ffd Merge "Disallow parallel backups" 2017-02-23 18:27:25 +00:00
Shreyas Basarge
6a4b9a33dc Merge "Serialize restore operations" 2017-02-23 18:26:57 +00:00
Shreyas Basarge
a88d8e04af Serialize restore operations
This cl introduces logic to serialize restore
operations. An incoming restore operation will
wait for the currently running restore to
complete.

Bug: 29010684

Test: Tested manually by installing an app while a restore was in
progress.

Change-Id: Ic88fdf2a6dcfab64853fe460c649380eea644774
2017-02-21 18:51:46 +00:00
Stefanot
2815496b32 Add more instrumentation to BackupManager.
This CL continues work of: ag/1835775 and ag/1870141 adding a few more
logging constans described here:
https://docs.google.com/document/d/1sUboR28LjkT1wRXOwVOV3tLo0qisiCvzxIGmzCVEjbI/edit#

Test: manual

BUG: 34873525
Change-Id: I8c81d8cfea5538e89de94919062eeff6ae09dce4
2017-02-21 12:44:32 +00:00
Shreyas Basarge
aac009b0f5 Disallow parallel backups
If a backup operation is in progress
when another backup operation is requested,
the new one is skipped. We have to skip the
second one because the current BackupTransport
interface cannot support parallel backups.

Bug: 29010684
Test: Tested manually. Work on GTS test in progress.

Change-Id: I6d8f49897bb42781bafed584a4b75b3b971f75eb
2017-02-17 22:16:31 +00:00
Shreyas Basarge
4edbf055ed Merge "Use separate message ids for backup and restore operations" 2017-02-17 10:14:50 +00:00
Shreyas Basarge
ab5071c90c Use separate message ids for backup and restore operations
This cl is part of a group of CLs to support
some parallelism in BackupManager's operations.
Separate message ids are used for handler messages
for backup and restore operations so that both
operations can run parallely.

Bug: 29010684
Test: Manually tested by installing a test backup agent that times out.
Change-Id: I57a5d063fb4446e610af81ac6f039d3fc8414a46
2017-02-16 23:56:50 +00:00
Shreyas Basarge
c4f91e5204 Merge "Fix NPE in BackupManagerService" 2017-02-16 19:27:54 +00:00
Shreyas Basarge
2d096ee435 Fix NPE in BackupManagerService
If none of the requested packages are valid packages,
we'd run into this issue where PerformBackupTask#mQueue
is null but we try to iterate over it in finalizeBackup()
Fix is to use an empty queue as the default value instead
of null.

Bug: 35380067
Test: Manually tested by trying to backup a non-existent package.
Change-Id: Ibb2d03d5f8270bcb448ee083ee02964236aca92b
2017-02-16 14:54:47 +00:00
Shreyas Basarge
0277db478d Better iteration over mCurrentOperations in cancelBackups
handleCancel was being called on an operation
while we are iterating over all operations.
This can cause issues if handleCancel modifies
the array containing all operations.

Test: Run cancelBackup GTS tests.

Change-Id: If3fbe7b5d9e61aa870f8f6e0dd1654e735c0c5b8
2017-02-16 14:16:14 +00:00
Shreyas Basarge
c3704427c9 BackupManager#cancelBackups() API
Introduces a cancelBackups() API for
BackupManager. When this function returns,
it is guaranteed that currently running
backup operations won't interact with
the active transport.

Bug: 34760860

Ref: https://docs.google.com/document/d/18MnfwkDfKNtXQBPRmL8vpVgfLgSWJsDja1Nm1QV5hOw/edit#heading=h.9p6yo0wx44k3

Test: GTS tests at ag/1893365

Change-Id: I67f78699bbe763ea71c85937fbc01a5b48694eed
2017-02-14 13:51:59 +00:00
Shreyas Basarge
b6e73c9670 BackupAgent#getBackupQuota() API
This cl adds a getBackupQuota() method
to the BackupAgent abstract class. This
can be used by the agent to determine
how much data it can back up.

Ref: https://docs.google.com/document/d/18MnfwkDfKNtXQBPRmL8vpVgfLgSWJsDja1Nm1QV5hOw/edit#heading=h.unncio2r7de2

Bug: 33750400

Test: GTS test at ag/1850525

Change-Id: I2eb5c0066c99732ec84cae9211f3a1edaad2baf1
2017-02-10 18:11:40 +00:00
Stefano Tommasini
afcea28827 Merge "Add instrumentation for BackupManager during restore." 2017-02-10 15:46:06 +00:00
Stefanot
f4e237c685 Add instrumentation for BackupManager during restore.
This CL adds more instumentation to
backup/restore operation in the BackupManager. For more details please
point to:
https://docs.google.com/document/d/1sUboR28LjkT1wRXOwVOV3tLo0qisiCvzxIGmzCVEjbI/edit#
This first Cl introduces 3 events that we sent to the monitor.
The base cl is ag/1835775

Test: TODO

BUG: 34873525
Change-Id: I127fe739a7522078eecce2ae689a4607203a98da
2017-02-10 13:52:02 +00:00
Stefano Tommasini
7a1c94cc89 Merge "Add monitoring to backup in BackupManager." 2017-02-10 12:52:32 +00:00
Shreyas Basarge
ee1f9b26a8 Merge "Fix for bmgr whitelist" 2017-02-10 11:58:32 +00:00
Stefanot
b1f573dca3 Add monitoring to backup in BackupManager.
This is the first CL of many that will add instumentation to
backup/restore operation in the BackupManager. For more details please
point to:
https://docs.google.com/document/d/1sUboR28LjkT1wRXOwVOV3tLo0qisiCvzxIGmzCVEjbI/edit#
This first Cl introduces 3 events that we sent to the monitor.

Test: ag/1858962 (same topic)

BUG: 34873525

Change-Id: I6c338b6fd9f4d7c8670dac201897250b6b170677
2017-02-10 11:03:08 +00:00
Shreyas Basarge
bf2ec2c5d7 Fix for bmgr whitelist
The bmgr whitelist command was broken
after the selectTransport api cl. This
cl fixes it.

Bug: 34953486
Test: Verify that adb shell bmgr whitelist prints all whitelisted
transports
Change-Id: I3c3275258a45a035a0ca9404d1016ca5663cceaf
2017-02-09 23:11:43 +00:00
Shubham Ajmera
a6e5041a83 Merge "Replace RandomAccessFile with BufferedInputStream" 2017-02-09 12:14:23 +00:00
Shreyas Basarge
865303fce5 API to select backup transport
This cl adds an API to select a backup
transport by its component name and
receive a callback when BackupManager
is bound to the transport. Calling this API
will make BackupManager bind to the transport
if it isn't already bound to it.

Also fixes the issue where BackupManager would
detect only one transport per package.

Ref: go/backup-transport-switching

Bug: 33616220
Test: Manually tested. GTS tests will be put up shortly.

Change-Id: I8c23bdbb84ceb05eb1fad9b3a8b9c4441cb06c74
2017-01-24 17:28:48 +00:00
Shreyas Basarge
38e7486d38 Non incremental backup flag for requestBackup
This cl adds a new requestBackup API to
BackupManager that takes in an int flag
to indicate whether the caller wants the
entire key value set to be passed to the
transport and not just a diff.

Change-Id: Ia225797a58c4431fe742f2f116b257d006b30cd1

Bug: 33749084
Ref: go/request-backup-api-changes
Test: GTS Test at ag/1774002
2017-01-19 22:13:01 +00:00
Chris Tate
11e9cec138 Merge "Fix the deadlock problem" am: fa228e06f6 am: e8c0e1098e am: 35b99da33a
am: 0455c30035

Change-Id: Ib08f8deadfe6085d6d4368527892c799c42f0757
2016-12-02 23:02:58 +00:00
Chris Tate
e8c0e1098e Merge "Fix the deadlock problem"
am: fa228e06f6

Change-Id: I862d3cedcf38c81f22559439aa8f00ac2ab3cca3
2016-12-02 22:45:47 +00:00
pengzhicai
acaed3d29e Fix the deadlock problem
https://code.google.com/p/android/issues/detail?id=229020

Change-Id: Ib08f62dd916d09e666e58fb583555170d1e51da6
Signed-off-by: pengzhicai <pengzhicai@xiaomi.com>
2016-12-01 02:01:49 +00:00
Shubham Ajmera
274498e536 Replace RandomAccessFile with BufferedInputStream
com.android.server.backup.BackupManagerService#parseLeftoverJournals
uses input stream to read UTF. The method used RandomAccessFile to
perform the operation. The change replace the RandomAccessFile with
a Buffered InputStream.

Bug: 32866032
Test: `make`
Change-Id: I6594cecc49cb6efcfdf73beb5e425688cf890722
2016-11-16 11:10:06 +00:00
Sudheer Shanka
2250d56a0b Rename MountService to StorageManagerService.
Bug: 30977067
Test: Existing tests pass
Change-Id: Ieac0f11c2b249dcd60441b14c1f391e6f8131d42
2016-11-15 12:43:37 -08:00
Sudheer Shanka
dc589ac82b Update usage of ActivityManagerNative.
- Remove references to ActivityManagerProxy.
- Add isSystemReady to ActivityManager.

Bug: 30977067
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test android.server.cts
      adb shell am instrument -e class com.android.server.am.ActivityManagerTest,com.android.server.am.TaskStackChangedListenerTest \
          -w com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I07390b6124fb1515821f5c0b37baf6ae74adc8fa
2016-11-14 11:27:12 -08:00
Sudheer Shanka
f734114280 Move IMountService to aidl.
Bug: 30977067
Test: Existing tests passing.
Change-Id: Icadfdcbc79708d3826b4e11afe35f5963aabcd4c
2016-10-27 12:36:37 -07:00
Sudheer Shanka
cc6418feb7 Move ApplicationThread to aidl.
Bug: 30977067
Test: Existing tests are passing, dump commands still working.
Change-Id: Iecb382e8720dfb1b6b707272497e3793e6995edb
2016-10-19 11:29:47 -07:00
Christopher Tate
d990e4d3df Respect restoreAnyVersion=true in full-data restore path
The scheduling mechanism was properly checking for it, but the raw
data-handling engine wasn't.  Now it is.

Bug 32054889

Change-Id: Id57ea12be8e2674c4f678f058278b8c14865b6fa
2016-10-11 15:29:39 -07:00
Chris Tate
a46b7f44c0 Merge "Turn down restore-time logspam" into nyc-mr1-dev 2016-07-15 18:05:07 +00:00
Christopher Tate
4c307258ac Turn down restore-time logspam
Bug 30160827

Change-Id: I14ccf0a31e5a6882bf189c28c79d1c139ec44bcc
2016-07-15 10:56:05 -07:00
Chris Tate
4595bc7f12 Merge "Thread-safe pipe teardown during restore operations" into nyc-mr1-dev 2016-07-15 01:38:03 +00:00
Chris Tate
69818781f3 Merge "Explicitly flush compress/encrypt stream before close" into nyc-mr1-dev 2016-07-12 22:47:00 +00:00
Chris Tate
1165790f70 Merge "Harden framework against backup transport crashes" into nyc-mr1-dev 2016-07-12 21:00:29 +00:00
Christopher Tate
ad869cc908 Thread-safe pipe teardown during restore operations
Bug 29135140

Change-Id: Id474f180815318618ec28ff953dc0cab892f781e
2016-07-12 13:56:35 -07:00
Christopher Tate
bf13ccf4b7 Back up / restore lock wallpapers
If writing both system + lock wallpapers winds up hitting the
transport-defined quota, the next backup operation steps back
to storing only the system wallpaper.

Also makes sure to unbind full-backup target agents following
the backup operation.  In practice this usually doesn't matter
because the target gets killed following the operation, but
the wallpaper agent runs in the system process where this does
not happen, so was mistakenly being left in place and reused
for the next operation, failing to re-run the full create +
backup lifecycle.

Bug 28968107

Change-Id: I219c2ddd7e899a430ef4cf693b1259464c15eed5
2016-07-12 18:34:05 +00:00
Fyodor Kupolov
4e8ce9ec4e Schedule backup of a package on a background thread
Scheduling involves writing to journal file. This part can be done on the
background thread in order to speed up the unlocking. Deferring writes to
journal file should be safe, because the system will reschedule backups in
case of a crash.

Bug: 29619732
Bug: 29645167
Change-Id: I0667ac2bf159e0f40b7a5066f41ea0841df98437
2016-07-06 18:20:29 -07:00
Christopher Tate
59397a8e05 Explicitly flush compress/encrypt stream before close
We're losing the stream footer for mysterious reasons; maybe this
will help even though supposedly close() is expected to flush pending
buffered writes anyway.  In particular, an explicit flush of the
compression stage will generate a SYNC_FLUSH point, which ordinary
deflate-at-close operation does not.

Bug 28056941

Change-Id: I96580411257932d7addb176c6672eae72a5ac6f7
2016-07-06 16:27:32 -07:00
Christopher Tate
a2a6533d65 Harden framework against backup transport crashes
Make sure we catch any exception thrown back from the transport,
rather than relying on it to maintain the interface surface.  Some
exceptions turn out to be beyond the call-target's control to
prevent.

Bug 29761883

Change-Id: Ifafbac300e7d7dab793237b2fd47d3122751435f
2016-07-06 16:27:32 -07:00
Christopher Tate
5cb5e89d77 Fix adb backup/restore
* Exclude key/value-only backup participants until we have a chance to
  augment the archive format with proper handling.

* Don't back up 'stopped' apps, which would un-stop them

* Fix unspecified-user bindService/startActivity invocations

* Teach adb restore about the onRestoreFinished() lifecycle method

* Implement proper app timeout handling in the adb data flows

* Backstop wallpaper backup against rare leftover-state issues

Bug 28056941

Change-Id: Ia59c71a2c74a632a2c2a527b9b7374229c440d46
2016-06-22 13:53:41 -07:00