Loading core/java/android/app/backup/BackupAgent.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -403,7 +403,7 @@ public abstract class BackupAgent extends ContextWrapper { public void onFullBackup(FullBackupDataOutput data) throws IOException { public void onFullBackup(FullBackupDataOutput data) throws IOException { FullBackup.BackupScheme backupScheme = FullBackup.getBackupScheme(this, FullBackup.BackupScheme backupScheme = FullBackup.getBackupScheme(this, mOperationType); mOperationType); if (!isDeviceToDeviceMigration() && !backupScheme.isFullBackupContentEnabled()) { if (!backupScheme.isFullBackupEnabled(data.getTransportFlags())) { return; return; } } Loading Loading @@ -911,7 +911,7 @@ public abstract class BackupAgent extends ContextWrapper { } } FullBackup.BackupScheme bs = FullBackup.getBackupScheme(this, mOperationType); FullBackup.BackupScheme bs = FullBackup.getBackupScheme(this, mOperationType); if (!bs.isFullBackupContentEnabled()) { if (!bs.isFullRestoreEnabled()) { if (Log.isLoggable(FullBackup.TAG_XML_PARSER, Log.VERBOSE)) { if (Log.isLoggable(FullBackup.TAG_XML_PARSER, Log.VERBOSE)) { Log.v(FullBackup.TAG_XML_PARSER, Log.v(FullBackup.TAG_XML_PARSER, "onRestoreFile \"" + destination.getCanonicalPath() "onRestoreFile \"" + destination.getCanonicalPath() Loading core/java/android/app/backup/FullBackup.java +69 −1 Original line number Original line Diff line number Diff line Loading @@ -99,6 +99,8 @@ public class FullBackup { public static final String FLAG_REQUIRED_DEVICE_TO_DEVICE_TRANSFER = "deviceToDeviceTransfer"; public static final String FLAG_REQUIRED_DEVICE_TO_DEVICE_TRANSFER = "deviceToDeviceTransfer"; public static final String FLAG_REQUIRED_FAKE_CLIENT_SIDE_ENCRYPTION = public static final String FLAG_REQUIRED_FAKE_CLIENT_SIDE_ENCRYPTION = "fakeClientSideEncryption"; "fakeClientSideEncryption"; private static final String FLAG_DISABLE_IF_NO_ENCRYPTION_CAPABILITIES = "disableIfNoEncryptionCapabilities"; /** /** * When this change is enabled, include / exclude rules specified via * When this change is enabled, include / exclude rules specified via Loading Loading @@ -307,6 +309,10 @@ public class FullBackup { // lazy initialized, only when needed // lazy initialized, only when needed private StorageVolume[] mVolumes = null; private StorageVolume[] mVolumes = null; // Properties the transport must have (e.g. encryption) for the operation to go ahead. @Nullable private Integer mRequiredTransportFlags; @Nullable private Boolean mIsUsingNewScheme; /** /** * Parse out the semantic domains into the correct physical location. * Parse out the semantic domains into the correct physical location. */ */ Loading Loading @@ -453,6 +459,35 @@ public class FullBackup { } } } } boolean isFullBackupEnabled(int transportFlags) { try { if (isUsingNewScheme()) { int requiredTransportFlags = getRequiredTransportFlags(); // All bits that are set in requiredTransportFlags must be set in // transportFlags. return (transportFlags & requiredTransportFlags) == requiredTransportFlags; } } catch (IOException | XmlPullParserException e) { Slog.w(TAG, "Failed to interpret the backup scheme: " + e); return false; } return isFullBackupContentEnabled(); } boolean isFullRestoreEnabled() { try { if (isUsingNewScheme()) { return true; } } catch (IOException | XmlPullParserException e) { Slog.w(TAG, "Failed to interpret the backup scheme: " + e); return false; } return isFullBackupContentEnabled(); } boolean isFullBackupContentEnabled() { boolean isFullBackupContentEnabled() { if (mFullBackupContent < 0) { if (mFullBackupContent < 0) { // android:fullBackupContent="false", bail. // android:fullBackupContent="false", bail. Loading Loading @@ -491,10 +526,30 @@ public class FullBackup { return mExcludes; return mExcludes; } } private synchronized int getRequiredTransportFlags() throws IOException, XmlPullParserException { if (mRequiredTransportFlags == null) { maybeParseBackupSchemeLocked(); } return mRequiredTransportFlags; } private synchronized boolean isUsingNewScheme() throws IOException, XmlPullParserException { if (mIsUsingNewScheme == null) { maybeParseBackupSchemeLocked(); } return mIsUsingNewScheme; } private void maybeParseBackupSchemeLocked() throws IOException, XmlPullParserException { private void maybeParseBackupSchemeLocked() throws IOException, XmlPullParserException { // This not being null is how we know that we've tried to parse the xml already. // This not being null is how we know that we've tried to parse the xml already. mIncludes = new ArrayMap<String, Set<PathWithRequiredFlags>>(); mIncludes = new ArrayMap<String, Set<PathWithRequiredFlags>>(); mExcludes = new ArraySet<PathWithRequiredFlags>(); mExcludes = new ArraySet<PathWithRequiredFlags>(); mRequiredTransportFlags = 0; mIsUsingNewScheme = false; if (mFullBackupContent == 0 && mDataExtractionRules == 0) { if (mFullBackupContent == 0 && mDataExtractionRules == 0) { // No scheme specified via either new or legacy config, will copy everything. // No scheme specified via either new or legacy config, will copy everything. Loading Loading @@ -535,12 +590,14 @@ public class FullBackup { } } if (!mExcludes.isEmpty() || !mIncludes.isEmpty()) { if (!mExcludes.isEmpty() || !mIncludes.isEmpty()) { // Found configuration in the new config, we will use it. // Found configuration in the new config, we will use it. mIsUsingNewScheme = true; return; return; } } } } if (operationType == OperationType.MIGRATION if (operationType == OperationType.MIGRATION && CompatChanges.isChangeEnabled(IGNORE_FULL_BACKUP_CONTENT_IN_D2D)) { && CompatChanges.isChangeEnabled(IGNORE_FULL_BACKUP_CONTENT_IN_D2D)) { mIsUsingNewScheme = true; return; return; } } Loading Loading @@ -584,13 +641,24 @@ public class FullBackup { continue; continue; } } // TODO(b/180523028): Parse required attributes for rules (e.g. encryption). parseRequiredTransportFlags(parser, configSection); parseRules(parser, excludes, includes, Optional.of(0), configSection); parseRules(parser, excludes, includes, Optional.of(0), configSection); } } logParsingResults(excludes, includes); logParsingResults(excludes, includes); } } private void parseRequiredTransportFlags(XmlPullParser parser, @ConfigSection String configSection) { if (ConfigSection.CLOUD_BACKUP.equals(configSection)) { String encryptionAttribute = parser.getAttributeValue(/* namespace */ null, FLAG_DISABLE_IF_NO_ENCRYPTION_CAPABILITIES); if ("true".equals(encryptionAttribute)) { mRequiredTransportFlags = BackupAgent.FLAG_CLIENT_SIDE_ENCRYPTION_ENABLED; } } } @VisibleForTesting @VisibleForTesting public void parseBackupSchemeFromXmlLocked(XmlPullParser parser, public void parseBackupSchemeFromXmlLocked(XmlPullParser parser, Set<PathWithRequiredFlags> excludes, Set<PathWithRequiredFlags> excludes, Loading packages/LocalTransport/src/com/android/localtransport/LocalTransport.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -165,6 +165,9 @@ public class LocalTransport extends BackupTransport { if (mParameters.isDeviceTransfer()) { if (mParameters.isDeviceTransfer()) { flags |= BackupAgent.FLAG_DEVICE_TO_DEVICE_TRANSFER; flags |= BackupAgent.FLAG_DEVICE_TO_DEVICE_TRANSFER; } } if (mParameters.isEncrypted()) { flags |= BackupAgent.FLAG_CLIENT_SIDE_ENCRYPTION_ENABLED; } return flags; return flags; } } Loading packages/LocalTransport/src/com/android/localtransport/LocalTransportParameters.java +7 −0 Original line number Original line Diff line number Diff line Loading @@ -28,10 +28,12 @@ public class LocalTransportParameters extends KeyValueSettingObserver { private static final String KEY_FAKE_ENCRYPTION_FLAG = "fake_encryption_flag"; private static final String KEY_FAKE_ENCRYPTION_FLAG = "fake_encryption_flag"; private static final String KEY_NON_INCREMENTAL_ONLY = "non_incremental_only"; private static final String KEY_NON_INCREMENTAL_ONLY = "non_incremental_only"; private static final String KEY_IS_DEVICE_TRANSFER = "is_device_transfer"; private static final String KEY_IS_DEVICE_TRANSFER = "is_device_transfer"; private static final String KEY_IS_ENCRYPTED = "is_encrypted"; private boolean mFakeEncryptionFlag; private boolean mFakeEncryptionFlag; private boolean mIsNonIncrementalOnly; private boolean mIsNonIncrementalOnly; private boolean mIsDeviceTransfer; private boolean mIsDeviceTransfer; private boolean mIsEncrypted; public LocalTransportParameters(Handler handler, ContentResolver resolver) { public LocalTransportParameters(Handler handler, ContentResolver resolver) { super(handler, resolver, Settings.Secure.getUriFor(SETTING)); super(handler, resolver, Settings.Secure.getUriFor(SETTING)); Loading @@ -49,6 +51,10 @@ public class LocalTransportParameters extends KeyValueSettingObserver { return mIsDeviceTransfer; return mIsDeviceTransfer; } } boolean isEncrypted() { return mIsEncrypted; } public String getSettingValue(ContentResolver resolver) { public String getSettingValue(ContentResolver resolver) { return Settings.Secure.getString(resolver, SETTING); return Settings.Secure.getString(resolver, SETTING); } } Loading @@ -57,5 +63,6 @@ public class LocalTransportParameters extends KeyValueSettingObserver { mFakeEncryptionFlag = parser.getBoolean(KEY_FAKE_ENCRYPTION_FLAG, false); mFakeEncryptionFlag = parser.getBoolean(KEY_FAKE_ENCRYPTION_FLAG, false); mIsNonIncrementalOnly = parser.getBoolean(KEY_NON_INCREMENTAL_ONLY, false); mIsNonIncrementalOnly = parser.getBoolean(KEY_NON_INCREMENTAL_ONLY, false); mIsDeviceTransfer = parser.getBoolean(KEY_IS_DEVICE_TRANSFER, false); mIsDeviceTransfer = parser.getBoolean(KEY_IS_DEVICE_TRANSFER, false); mIsEncrypted = parser.getBoolean(KEY_IS_ENCRYPTED, false); } } } } Loading
core/java/android/app/backup/BackupAgent.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -403,7 +403,7 @@ public abstract class BackupAgent extends ContextWrapper { public void onFullBackup(FullBackupDataOutput data) throws IOException { public void onFullBackup(FullBackupDataOutput data) throws IOException { FullBackup.BackupScheme backupScheme = FullBackup.getBackupScheme(this, FullBackup.BackupScheme backupScheme = FullBackup.getBackupScheme(this, mOperationType); mOperationType); if (!isDeviceToDeviceMigration() && !backupScheme.isFullBackupContentEnabled()) { if (!backupScheme.isFullBackupEnabled(data.getTransportFlags())) { return; return; } } Loading Loading @@ -911,7 +911,7 @@ public abstract class BackupAgent extends ContextWrapper { } } FullBackup.BackupScheme bs = FullBackup.getBackupScheme(this, mOperationType); FullBackup.BackupScheme bs = FullBackup.getBackupScheme(this, mOperationType); if (!bs.isFullBackupContentEnabled()) { if (!bs.isFullRestoreEnabled()) { if (Log.isLoggable(FullBackup.TAG_XML_PARSER, Log.VERBOSE)) { if (Log.isLoggable(FullBackup.TAG_XML_PARSER, Log.VERBOSE)) { Log.v(FullBackup.TAG_XML_PARSER, Log.v(FullBackup.TAG_XML_PARSER, "onRestoreFile \"" + destination.getCanonicalPath() "onRestoreFile \"" + destination.getCanonicalPath() Loading
core/java/android/app/backup/FullBackup.java +69 −1 Original line number Original line Diff line number Diff line Loading @@ -99,6 +99,8 @@ public class FullBackup { public static final String FLAG_REQUIRED_DEVICE_TO_DEVICE_TRANSFER = "deviceToDeviceTransfer"; public static final String FLAG_REQUIRED_DEVICE_TO_DEVICE_TRANSFER = "deviceToDeviceTransfer"; public static final String FLAG_REQUIRED_FAKE_CLIENT_SIDE_ENCRYPTION = public static final String FLAG_REQUIRED_FAKE_CLIENT_SIDE_ENCRYPTION = "fakeClientSideEncryption"; "fakeClientSideEncryption"; private static final String FLAG_DISABLE_IF_NO_ENCRYPTION_CAPABILITIES = "disableIfNoEncryptionCapabilities"; /** /** * When this change is enabled, include / exclude rules specified via * When this change is enabled, include / exclude rules specified via Loading Loading @@ -307,6 +309,10 @@ public class FullBackup { // lazy initialized, only when needed // lazy initialized, only when needed private StorageVolume[] mVolumes = null; private StorageVolume[] mVolumes = null; // Properties the transport must have (e.g. encryption) for the operation to go ahead. @Nullable private Integer mRequiredTransportFlags; @Nullable private Boolean mIsUsingNewScheme; /** /** * Parse out the semantic domains into the correct physical location. * Parse out the semantic domains into the correct physical location. */ */ Loading Loading @@ -453,6 +459,35 @@ public class FullBackup { } } } } boolean isFullBackupEnabled(int transportFlags) { try { if (isUsingNewScheme()) { int requiredTransportFlags = getRequiredTransportFlags(); // All bits that are set in requiredTransportFlags must be set in // transportFlags. return (transportFlags & requiredTransportFlags) == requiredTransportFlags; } } catch (IOException | XmlPullParserException e) { Slog.w(TAG, "Failed to interpret the backup scheme: " + e); return false; } return isFullBackupContentEnabled(); } boolean isFullRestoreEnabled() { try { if (isUsingNewScheme()) { return true; } } catch (IOException | XmlPullParserException e) { Slog.w(TAG, "Failed to interpret the backup scheme: " + e); return false; } return isFullBackupContentEnabled(); } boolean isFullBackupContentEnabled() { boolean isFullBackupContentEnabled() { if (mFullBackupContent < 0) { if (mFullBackupContent < 0) { // android:fullBackupContent="false", bail. // android:fullBackupContent="false", bail. Loading Loading @@ -491,10 +526,30 @@ public class FullBackup { return mExcludes; return mExcludes; } } private synchronized int getRequiredTransportFlags() throws IOException, XmlPullParserException { if (mRequiredTransportFlags == null) { maybeParseBackupSchemeLocked(); } return mRequiredTransportFlags; } private synchronized boolean isUsingNewScheme() throws IOException, XmlPullParserException { if (mIsUsingNewScheme == null) { maybeParseBackupSchemeLocked(); } return mIsUsingNewScheme; } private void maybeParseBackupSchemeLocked() throws IOException, XmlPullParserException { private void maybeParseBackupSchemeLocked() throws IOException, XmlPullParserException { // This not being null is how we know that we've tried to parse the xml already. // This not being null is how we know that we've tried to parse the xml already. mIncludes = new ArrayMap<String, Set<PathWithRequiredFlags>>(); mIncludes = new ArrayMap<String, Set<PathWithRequiredFlags>>(); mExcludes = new ArraySet<PathWithRequiredFlags>(); mExcludes = new ArraySet<PathWithRequiredFlags>(); mRequiredTransportFlags = 0; mIsUsingNewScheme = false; if (mFullBackupContent == 0 && mDataExtractionRules == 0) { if (mFullBackupContent == 0 && mDataExtractionRules == 0) { // No scheme specified via either new or legacy config, will copy everything. // No scheme specified via either new or legacy config, will copy everything. Loading Loading @@ -535,12 +590,14 @@ public class FullBackup { } } if (!mExcludes.isEmpty() || !mIncludes.isEmpty()) { if (!mExcludes.isEmpty() || !mIncludes.isEmpty()) { // Found configuration in the new config, we will use it. // Found configuration in the new config, we will use it. mIsUsingNewScheme = true; return; return; } } } } if (operationType == OperationType.MIGRATION if (operationType == OperationType.MIGRATION && CompatChanges.isChangeEnabled(IGNORE_FULL_BACKUP_CONTENT_IN_D2D)) { && CompatChanges.isChangeEnabled(IGNORE_FULL_BACKUP_CONTENT_IN_D2D)) { mIsUsingNewScheme = true; return; return; } } Loading Loading @@ -584,13 +641,24 @@ public class FullBackup { continue; continue; } } // TODO(b/180523028): Parse required attributes for rules (e.g. encryption). parseRequiredTransportFlags(parser, configSection); parseRules(parser, excludes, includes, Optional.of(0), configSection); parseRules(parser, excludes, includes, Optional.of(0), configSection); } } logParsingResults(excludes, includes); logParsingResults(excludes, includes); } } private void parseRequiredTransportFlags(XmlPullParser parser, @ConfigSection String configSection) { if (ConfigSection.CLOUD_BACKUP.equals(configSection)) { String encryptionAttribute = parser.getAttributeValue(/* namespace */ null, FLAG_DISABLE_IF_NO_ENCRYPTION_CAPABILITIES); if ("true".equals(encryptionAttribute)) { mRequiredTransportFlags = BackupAgent.FLAG_CLIENT_SIDE_ENCRYPTION_ENABLED; } } } @VisibleForTesting @VisibleForTesting public void parseBackupSchemeFromXmlLocked(XmlPullParser parser, public void parseBackupSchemeFromXmlLocked(XmlPullParser parser, Set<PathWithRequiredFlags> excludes, Set<PathWithRequiredFlags> excludes, Loading
packages/LocalTransport/src/com/android/localtransport/LocalTransport.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -165,6 +165,9 @@ public class LocalTransport extends BackupTransport { if (mParameters.isDeviceTransfer()) { if (mParameters.isDeviceTransfer()) { flags |= BackupAgent.FLAG_DEVICE_TO_DEVICE_TRANSFER; flags |= BackupAgent.FLAG_DEVICE_TO_DEVICE_TRANSFER; } } if (mParameters.isEncrypted()) { flags |= BackupAgent.FLAG_CLIENT_SIDE_ENCRYPTION_ENABLED; } return flags; return flags; } } Loading
packages/LocalTransport/src/com/android/localtransport/LocalTransportParameters.java +7 −0 Original line number Original line Diff line number Diff line Loading @@ -28,10 +28,12 @@ public class LocalTransportParameters extends KeyValueSettingObserver { private static final String KEY_FAKE_ENCRYPTION_FLAG = "fake_encryption_flag"; private static final String KEY_FAKE_ENCRYPTION_FLAG = "fake_encryption_flag"; private static final String KEY_NON_INCREMENTAL_ONLY = "non_incremental_only"; private static final String KEY_NON_INCREMENTAL_ONLY = "non_incremental_only"; private static final String KEY_IS_DEVICE_TRANSFER = "is_device_transfer"; private static final String KEY_IS_DEVICE_TRANSFER = "is_device_transfer"; private static final String KEY_IS_ENCRYPTED = "is_encrypted"; private boolean mFakeEncryptionFlag; private boolean mFakeEncryptionFlag; private boolean mIsNonIncrementalOnly; private boolean mIsNonIncrementalOnly; private boolean mIsDeviceTransfer; private boolean mIsDeviceTransfer; private boolean mIsEncrypted; public LocalTransportParameters(Handler handler, ContentResolver resolver) { public LocalTransportParameters(Handler handler, ContentResolver resolver) { super(handler, resolver, Settings.Secure.getUriFor(SETTING)); super(handler, resolver, Settings.Secure.getUriFor(SETTING)); Loading @@ -49,6 +51,10 @@ public class LocalTransportParameters extends KeyValueSettingObserver { return mIsDeviceTransfer; return mIsDeviceTransfer; } } boolean isEncrypted() { return mIsEncrypted; } public String getSettingValue(ContentResolver resolver) { public String getSettingValue(ContentResolver resolver) { return Settings.Secure.getString(resolver, SETTING); return Settings.Secure.getString(resolver, SETTING); } } Loading @@ -57,5 +63,6 @@ public class LocalTransportParameters extends KeyValueSettingObserver { mFakeEncryptionFlag = parser.getBoolean(KEY_FAKE_ENCRYPTION_FLAG, false); mFakeEncryptionFlag = parser.getBoolean(KEY_FAKE_ENCRYPTION_FLAG, false); mIsNonIncrementalOnly = parser.getBoolean(KEY_NON_INCREMENTAL_ONLY, false); mIsNonIncrementalOnly = parser.getBoolean(KEY_NON_INCREMENTAL_ONLY, false); mIsDeviceTransfer = parser.getBoolean(KEY_IS_DEVICE_TRANSFER, false); mIsDeviceTransfer = parser.getBoolean(KEY_IS_DEVICE_TRANSFER, false); mIsEncrypted = parser.getBoolean(KEY_IS_ENCRYPTED, false); } } } }