Fix "adb backup -shared"
An accidental side-effect of introducing the XML content file and its domain semantic checking was that the shared-storage domain got dropped on the floor. Now the mechanism understands what it means again. Bug 29999884 Change-Id: I22b99c96869683d1a92430f237dda54b170b8f60
This commit is contained in:
@@ -21,6 +21,8 @@ import android.content.pm.PackageManager;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.StorageVolume;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.text.TextUtils;
|
||||
@@ -223,8 +225,12 @@ public class FullBackup {
|
||||
|
||||
final int mFullBackupContent;
|
||||
final PackageManager mPackageManager;
|
||||
final StorageManager mStorageManager;
|
||||
final String mPackageName;
|
||||
|
||||
// lazy initialized, only when needed
|
||||
private StorageVolume[] mVolumes = null;
|
||||
|
||||
/**
|
||||
* Parse out the semantic domains into the correct physical location.
|
||||
*/
|
||||
@@ -260,16 +266,41 @@ public class FullBackup {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (domainToken.startsWith(FullBackup.SHARED_PREFIX)) {
|
||||
return sharedDomainToPath(domainToken);
|
||||
}
|
||||
// Not a supported location
|
||||
Log.i(TAG, "Unrecognized domain " + domainToken);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, "Error reading directory for domain: " + domainToken);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String sharedDomainToPath(String domain) throws IOException {
|
||||
// already known to start with SHARED_PREFIX, so we just look after that
|
||||
final String volume = domain.substring(FullBackup.SHARED_PREFIX.length());
|
||||
final StorageVolume[] volumes = getVolumeList();
|
||||
final int volNum = Integer.parseInt(volume);
|
||||
if (volNum < mVolumes.length) {
|
||||
return volumes[volNum].getPathFile().getCanonicalPath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private StorageVolume[] getVolumeList() {
|
||||
if (mStorageManager != null) {
|
||||
if (mVolumes == null) {
|
||||
mVolumes = mStorageManager.getVolumeList();
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Unable to access Storage Manager");
|
||||
}
|
||||
return mVolumes;
|
||||
}
|
||||
|
||||
/**
|
||||
* A map of domain -> list of canonical file names in that domain that are to be included.
|
||||
* We keep track of the domain so that we can go through the file system in order later on.
|
||||
@@ -283,6 +314,7 @@ public class FullBackup {
|
||||
|
||||
BackupScheme(Context context) {
|
||||
mFullBackupContent = context.getApplicationInfo().fullBackupContent;
|
||||
mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
|
||||
mPackageManager = context.getPackageManager();
|
||||
mPackageName = context.getPackageName();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user