From 294b512ecaa98a6a8ef12285ad14e7a4091b5d57 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 19 Feb 2013 14:08:59 -0800 Subject: DO NOT MERGE - 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. (Cherrypicked) Change-Id: I471f6348abcccb7bf1e1710b7beda9f23de53e14 --- core/java/android/app/backup/BackupAgent.java | 1 + core/java/android/app/backup/FullBackup.java | 2 +- core/java/android/app/backup/IBackupManager.aidl | 7 +++- .../android/internal/backup/IObbBackupService.aidl | 45 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 core/java/com/android/internal/backup/IObbBackupService.aidl (limited to 'core/java') diff --git a/core/java/android/app/backup/BackupAgent.java b/core/java/android/app/backup/BackupAgent.java index 44aa06fecd74..342576553b61 100644 --- a/core/java/android/app/backup/BackupAgent.java +++ b/core/java/android/app/backup/BackupAgent.java @@ -472,6 +472,7 @@ public abstract class BackupAgent extends ContextWrapper { File efLocation = getExternalFilesDir(null); if (efLocation != null) { basePath = getExternalFilesDir(null).getCanonicalPath(); + mode = -1; // < 0 is a token to skip attempting a chmod() } } } else { diff --git a/core/java/android/app/backup/FullBackup.java b/core/java/android/app/backup/FullBackup.java index 2fe08f34b49e..cb0737e3ad72 100644 --- a/core/java/android/app/backup/FullBackup.java +++ b/core/java/android/app/backup/FullBackup.java @@ -89,7 +89,7 @@ public class FullBackup { * last modification time of the output file. if the {@code mode} parameter is * negative then this parameter will be ignored. * @param outFile Location within the filesystem to place the data. This must point - * to a location that is writeable by the caller, prefereably using an absolute path. + * to a location that is writeable by the caller, preferably using an absolute path. * @throws IOException */ static public void restoreFile(ParcelFileDescriptor data, diff --git a/core/java/android/app/backup/IBackupManager.aidl b/core/java/android/app/backup/IBackupManager.aidl index acdd0b54559a..bb4f5f160bbe 100644 --- a/core/java/android/app/backup/IBackupManager.aidl +++ b/core/java/android/app/backup/IBackupManager.aidl @@ -152,6 +152,8 @@ interface IBackupManager { * @param fd The file descriptor to which a 'tar' file stream is to be written * @param includeApks If true, the resulting tar stream will include the * application .apk files themselves as well as their data. + * @param includeObbs If true, the resulting tar stream will include any + * application expansion (OBB) files themselves belonging to each application. * @param includeShared If true, the resulting tar stream will include * the contents of the device's shared storage (SD card or equivalent). * @param allApps If true, the resulting tar stream will include all @@ -164,8 +166,9 @@ interface IBackupManager { * @param packageNames The package names of the apps whose data (and optionally .apk files) * are to be backed up. The allApps parameter supersedes this. */ - void fullBackup(in ParcelFileDescriptor fd, boolean includeApks, boolean includeShared, - boolean allApps, boolean allIncludesSystem, in String[] packageNames); + void fullBackup(in ParcelFileDescriptor fd, boolean includeApks, boolean includeObbs, + boolean includeShared, boolean allApps, boolean allIncludesSystem, + in String[] packageNames); /** * Restore device content from the data stream passed through the given socket. The diff --git a/core/java/com/android/internal/backup/IObbBackupService.aidl b/core/java/com/android/internal/backup/IObbBackupService.aidl new file mode 100644 index 000000000000..426dbc4009c5 --- /dev/null +++ b/core/java/com/android/internal/backup/IObbBackupService.aidl @@ -0,0 +1,45 @@ +/* + * Copyright 2013, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.backup; + +import android.app.backup.IBackupManager; +import android.os.ParcelFileDescriptor; + +/** + * Interface for the Backup Manager Service to communicate with a helper service that + * handles local (whole-file) backup & restore of OBB content on behalf of applications. + * This can't be done within the Backup Manager Service itself because of the restrictions + * on system-user access to external storage, and can't be left to the apps because even + * apps that do not have permission to access external storage in the usual way can still + * use OBBs. + * + * {@hide} + */ +oneway interface IObbBackupService { + /* + * Back up a package's OBB directory tree + */ + void backupObbs(in String packageName, in ParcelFileDescriptor data, + int token, in IBackupManager callbackBinder); + + /* + * Restore an OBB file for the given package from the incoming stream + */ + void restoreObbFile(in String pkgName, in ParcelFileDescriptor data, + long fileSize, int type, in String path, long mode, long mtime, + int token, in IBackupManager callbackBinder); +} -- cgit v1.2.3