From 46cc43c6fa7623820d4ae9149496cf96bb15f8a3 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 19 Feb 2013 14:08:59 -0800 Subject: Full backup/restore now handles OBBs sensibly OBB backup/ restore is no longer handled within the target app process. This is done to avoid having to require that OBB-using apps have full read/write permission for external storage. The new OBB backup service is a new component running in the same app as the already-existing shared storage backup agent. The backup infrastructure delegates backup/restore of apps' OBB contents to this component (because the system process may not itself read/write external storage). From the command line, OBB backup is enabled by using new -obb / -noobb flags with adb backup. The default is noobb. Finally, a couple of nit fixes: - buffer-size mismatch between the writer and reader of chunked file data has been corrected; now the reading side won't be issuing an extra pipe read per chunk. - bu now explicitly closes the transport socket fd after adopting it. This was benign but triggered a logged warning about leaked fds. Bug: 6718844 Change-Id: Ie252494e2327e9ab97cf9ed87c298410a8618492 --- cmds/bu/src/com/android/commands/bu/Backup.java | 28 +++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'cmds/bu/src') diff --git a/cmds/bu/src/com/android/commands/bu/Backup.java b/cmds/bu/src/com/android/commands/bu/Backup.java index 046ccca9b02a..73fd66072d7f 100644 --- a/cmds/bu/src/com/android/commands/bu/Backup.java +++ b/cmds/bu/src/com/android/commands/bu/Backup.java @@ -22,6 +22,7 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; +import java.io.IOException; import java.util.ArrayList; public final class Backup { @@ -64,6 +65,7 @@ public final class Backup { private void doFullBackup(int socketFd) { ArrayList packages = new ArrayList(); boolean saveApks = false; + boolean saveObbs = false; boolean saveShared = false; boolean doEverything = false; boolean allIncludesSystem = true; @@ -75,6 +77,10 @@ public final class Backup { saveApks = true; } else if ("-noapk".equals(arg)) { saveApks = false; + } else if ("-obb".equals(arg)) { + saveObbs = true; + } else if ("-noobb".equals(arg)) { + saveObbs = false; } else if ("-shared".equals(arg)) { saveShared = true; } else if ("-noshared".equals(arg)) { @@ -104,23 +110,37 @@ public final class Backup { return; } + ParcelFileDescriptor fd = null; try { - ParcelFileDescriptor fd = ParcelFileDescriptor.adoptFd(socketFd); + fd = ParcelFileDescriptor.adoptFd(socketFd); String[] packArray = new String[packages.size()]; - mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything, allIncludesSystem, - packages.toArray(packArray)); + mBackupManager.fullBackup(fd, saveApks, saveObbs, saveShared, doEverything, + allIncludesSystem, packages.toArray(packArray)); } catch (RemoteException e) { Log.e(TAG, "Unable to invoke backup manager for backup"); + } finally { + if (fd != null) { + try { + fd.close(); + } catch (IOException e) {} + } } } private void doFullRestore(int socketFd) { // No arguments to restore + ParcelFileDescriptor fd = null; try { - ParcelFileDescriptor fd = ParcelFileDescriptor.adoptFd(socketFd); + fd = ParcelFileDescriptor.adoptFd(socketFd); mBackupManager.fullRestore(fd); } catch (RemoteException e) { Log.e(TAG, "Unable to invoke backup manager for restore"); + } finally { + if (fd != null) { + try { + fd.close(); + } catch (IOException e) {} + } } } -- cgit v1.2.3-59-g8ed1b