Merge "Streamline package-installed handling by the Backup Manager" into ics-mr1
This commit is contained in:
committed by
Android (Google) Code Review
commit
2cf18d2878
@@ -195,7 +195,7 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
boolean mProvisioned;
|
boolean mProvisioned;
|
||||||
boolean mAutoRestore;
|
boolean mAutoRestore;
|
||||||
PowerManager.WakeLock mWakelock;
|
PowerManager.WakeLock mWakelock;
|
||||||
HandlerThread mHandlerThread = new HandlerThread("backup", Process.THREAD_PRIORITY_BACKGROUND);
|
HandlerThread mHandlerThread;
|
||||||
BackupHandler mBackupHandler;
|
BackupHandler mBackupHandler;
|
||||||
PendingIntent mRunBackupIntent, mRunInitIntent;
|
PendingIntent mRunBackupIntent, mRunInitIntent;
|
||||||
BroadcastReceiver mRunBackupReceiver, mRunInitReceiver;
|
BroadcastReceiver mRunBackupReceiver, mRunInitReceiver;
|
||||||
@@ -1310,14 +1310,10 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
}
|
}
|
||||||
if (added) {
|
if (added) {
|
||||||
synchronized (mBackupParticipants) {
|
synchronized (mBackupParticipants) {
|
||||||
for (String pkgName : pkgList) {
|
if (replacing) {
|
||||||
if (replacing) {
|
updatePackageParticipantsLocked(pkgList);
|
||||||
// The package was just upgraded
|
} else {
|
||||||
updatePackageParticipantsLocked(pkgName);
|
addPackageParticipantsLocked(pkgList);
|
||||||
} else {
|
|
||||||
// The package was just added
|
|
||||||
addPackageParticipantsLocked(pkgName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1325,9 +1321,7 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
// The package is being updated. We'll receive a PACKAGE_ADDED shortly.
|
// The package is being updated. We'll receive a PACKAGE_ADDED shortly.
|
||||||
} else {
|
} else {
|
||||||
synchronized (mBackupParticipants) {
|
synchronized (mBackupParticipants) {
|
||||||
for (String pkgName : pkgList) {
|
removePackageParticipantsLocked(pkgList);
|
||||||
removePackageParticipantsLocked(pkgName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1349,26 +1343,26 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add the backup agents in the given package to our set of known backup participants.
|
// Add the backup agents in the given packages to our set of known backup participants.
|
||||||
// If 'packageName' is null, adds all backup agents in the whole system.
|
// If 'packageNames' is null, adds all backup agents in the whole system.
|
||||||
void addPackageParticipantsLocked(String packageName) {
|
void addPackageParticipantsLocked(String[] packageNames) {
|
||||||
// Look for apps that define the android:backupAgent attribute
|
// Look for apps that define the android:backupAgent attribute
|
||||||
if (DEBUG) Slog.v(TAG, "addPackageParticipantsLocked: " + packageName);
|
|
||||||
List<PackageInfo> targetApps = allAgentPackages();
|
List<PackageInfo> targetApps = allAgentPackages();
|
||||||
addPackageParticipantsLockedInner(packageName, targetApps);
|
if (packageNames != null) {
|
||||||
|
if (DEBUG) Slog.v(TAG, "addPackageParticipantsLocked: #" + packageNames.length);
|
||||||
|
for (String packageName : packageNames) {
|
||||||
|
addPackageParticipantsLockedInner(packageName, targetApps);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (DEBUG) Slog.v(TAG, "addPackageParticipantsLocked: all");
|
||||||
|
addPackageParticipantsLockedInner(null, targetApps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPackageParticipantsLockedInner(String packageName,
|
private void addPackageParticipantsLockedInner(String packageName,
|
||||||
List<PackageInfo> targetPkgs) {
|
List<PackageInfo> targetPkgs) {
|
||||||
if (MORE_DEBUG) {
|
if (MORE_DEBUG) {
|
||||||
Slog.v(TAG, "Adding " + targetPkgs.size() + " backup participants:");
|
Slog.v(TAG, "Examining " + packageName + " for backup agent");
|
||||||
for (PackageInfo p : targetPkgs) {
|
|
||||||
Slog.v(TAG, " " + p + " agent=" + p.applicationInfo.backupAgentName
|
|
||||||
+ " uid=" + p.applicationInfo.uid
|
|
||||||
+ " killAfterRestore="
|
|
||||||
+ (((p.applicationInfo.flags & ApplicationInfo.FLAG_KILL_AFTER_RESTORE) != 0) ? "true" : "false")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PackageInfo pkg : targetPkgs) {
|
for (PackageInfo pkg : targetPkgs) {
|
||||||
@@ -1380,6 +1374,7 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
mBackupParticipants.put(uid, set);
|
mBackupParticipants.put(uid, set);
|
||||||
}
|
}
|
||||||
set.add(pkg.applicationInfo);
|
set.add(pkg.applicationInfo);
|
||||||
|
if (MORE_DEBUG) Slog.v(TAG, "Agent found; added");
|
||||||
|
|
||||||
// If we've never seen this app before, schedule a backup for it
|
// If we've never seen this app before, schedule a backup for it
|
||||||
if (!mEverStoredApps.contains(pkg.packageName)) {
|
if (!mEverStoredApps.contains(pkg.packageName)) {
|
||||||
@@ -1391,34 +1386,32 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the given package's entry from our known active set. If
|
// Remove the given packages' entries from our known active set.
|
||||||
// 'packageName' is null, *all* participating apps will be removed.
|
void removePackageParticipantsLocked(String[] packageNames) {
|
||||||
void removePackageParticipantsLocked(String packageName) {
|
if (packageNames == null) {
|
||||||
if (DEBUG) Slog.v(TAG, "removePackageParticipantsLocked: " + packageName);
|
Slog.w(TAG, "removePackageParticipants with null list");
|
||||||
List<String> allApps = new ArrayList<String>();
|
return;
|
||||||
if (packageName != null) {
|
}
|
||||||
allApps.add(packageName);
|
|
||||||
} else {
|
if (DEBUG) Slog.v(TAG, "removePackageParticipantsLocked: #" + packageNames.length);
|
||||||
// all apps with agents
|
List<PackageInfo> knownPackages = allAgentPackages();
|
||||||
List<PackageInfo> knownPackages = allAgentPackages();
|
for (String pkg : packageNames) {
|
||||||
for (PackageInfo pkg : knownPackages) {
|
removePackageParticipantsLockedInner(pkg, knownPackages);
|
||||||
allApps.add(pkg.packageName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
removePackageParticipantsLockedInner(packageName, allApps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removePackageParticipantsLockedInner(String packageName,
|
private void removePackageParticipantsLockedInner(String packageName,
|
||||||
List<String> allPackageNames) {
|
List<PackageInfo> allPackages) {
|
||||||
if (MORE_DEBUG) {
|
if (MORE_DEBUG) {
|
||||||
Slog.v(TAG, "removePackageParticipantsLockedInner (" + packageName
|
Slog.v(TAG, "removePackageParticipantsLockedInner (" + packageName
|
||||||
+ ") removing " + allPackageNames.size() + " entries");
|
+ ") removing from " + allPackages.size() + " entries");
|
||||||
for (String p : allPackageNames) {
|
for (PackageInfo p : allPackages) {
|
||||||
Slog.v(TAG, " - " + p);
|
Slog.v(TAG, " - " + p.packageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String pkg : allPackageNames) {
|
for (PackageInfo pkg : allPackages) {
|
||||||
if (packageName == null || pkg.equals(packageName)) {
|
if (packageName == null || pkg.packageName.equals(packageName)) {
|
||||||
|
/*
|
||||||
int uid = -1;
|
int uid = -1;
|
||||||
try {
|
try {
|
||||||
PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
|
PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
|
||||||
@@ -1427,22 +1420,28 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
// we don't know this package name, so just skip it for now
|
// we don't know this package name, so just skip it for now
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
final int uid = pkg.applicationInfo.uid;
|
||||||
|
if (MORE_DEBUG) Slog.i(TAG, " found pkg " + packageName + " uid=" + uid);
|
||||||
|
|
||||||
HashSet<ApplicationInfo> set = mBackupParticipants.get(uid);
|
HashSet<ApplicationInfo> set = mBackupParticipants.get(uid);
|
||||||
if (set != null) {
|
if (set != null) {
|
||||||
// Find the existing entry with the same package name, and remove it.
|
// Find the existing entry with the same package name, and remove it.
|
||||||
// We can't just remove(app) because the instances are different.
|
// We can't just remove(app) because the instances are different.
|
||||||
for (ApplicationInfo entry: set) {
|
for (ApplicationInfo entry: set) {
|
||||||
|
if (MORE_DEBUG) Slog.i(TAG, " checking against " + entry.packageName);
|
||||||
if (entry.packageName.equals(pkg)) {
|
if (entry.packageName.equals(pkg)) {
|
||||||
if (MORE_DEBUG) Slog.v(TAG, " removing participant " + pkg);
|
if (MORE_DEBUG) Slog.v(TAG, " removing participant " + pkg);
|
||||||
set.remove(entry);
|
set.remove(entry);
|
||||||
removeEverBackedUp(pkg);
|
removeEverBackedUp(pkg.packageName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (set.size() == 0) {
|
if (set.size() == 0) {
|
||||||
mBackupParticipants.delete(uid);
|
mBackupParticipants.delete(uid);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (MORE_DEBUG) Slog.i(TAG, " ... not found in uid mapping");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1477,21 +1476,20 @@ class BackupManagerService extends IBackupManager.Stub {
|
|||||||
|
|
||||||
// Reset the given package's known backup participants. Unlike add/remove, the update
|
// Reset the given package's known backup participants. Unlike add/remove, the update
|
||||||
// action cannot be passed a null package name.
|
// action cannot be passed a null package name.
|
||||||
void updatePackageParticipantsLocked(String packageName) {
|
void updatePackageParticipantsLocked(String[] packageNames) {
|
||||||
if (packageName == null) {
|
if (packageNames == null) {
|
||||||
Slog.e(TAG, "updatePackageParticipants called with null package name");
|
Slog.e(TAG, "updatePackageParticipants called with null package list");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DEBUG) Slog.v(TAG, "updatePackageParticipantsLocked: " + packageName);
|
if (DEBUG) Slog.v(TAG, "updatePackageParticipantsLocked: #" + packageNames.length);
|
||||||
|
|
||||||
// brute force but small code size
|
if (packageNames.length > 0) {
|
||||||
List<PackageInfo> allApps = allAgentPackages();
|
List<PackageInfo> allApps = allAgentPackages();
|
||||||
List<String> allAppNames = new ArrayList<String>();
|
for (String packageName : packageNames) {
|
||||||
for (PackageInfo pkg : allApps) {
|
removePackageParticipantsLockedInner(packageName, allApps);
|
||||||
allAppNames.add(pkg.packageName);
|
addPackageParticipantsLockedInner(packageName, allApps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
removePackageParticipantsLockedInner(packageName, allAppNames);
|
|
||||||
addPackageParticipantsLockedInner(packageName, allApps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called from the backup task: record that the given app has been successfully
|
// Called from the backup task: record that the given app has been successfully
|
||||||
|
|||||||
Reference in New Issue
Block a user