Loading packages/SettingsLib/DataStore/src/com/android/settingslib/datastore/BackupRestoreStorageManager.kt +35 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settingslib.datastore import android.app.Application import android.app.backup.BackupAgentHelper import android.app.backup.BackupManager import android.content.Context import android.util.Log Loading @@ -42,6 +43,35 @@ class BackupRestoreStorageManager private constructor(private val application: A BackupManager.dataChanged(application.packageName) } /** * Adds all the registered [BackupRestoreStorage] as the helpers of given [BackupAgentHelper]. * * @see BackupAgentHelper.addHelper */ fun addBackupAgentHelpers(backupAgentHelper: BackupAgentHelper) { for ((keyPrefix, storage) in storages) { backupAgentHelper.addHelper(keyPrefix, storage) } } /** * Callback when restore finished. * * The observers of the storages will be notified. */ fun onRestoreFinished() { for (storage in storages.values) { storage.notifyRestoreFinished() } } private fun BackupRestoreStorage.notifyRestoreFinished() { when (this) { is KeyedObservable<*> -> notifyChange(ChangeReason.RESTORE) is Observable -> notifyChange(ChangeReason.RESTORE) } } /** * Adds a list of storages. * Loading Loading @@ -78,6 +108,11 @@ class BackupRestoreStorageManager private constructor(private val application: A } } /** Removes all the storages. */ fun removeAll() { for ((name, _) in storages) remove(name) } /** Removes storage with given name. */ fun remove(name: String): BackupRestoreStorage? { val storage = storages.remove(name) Loading packages/SettingsLib/DataStore/src/com/android/settingslib/datastore/ObservableBackupRestoreStorage.kt 0 → 100644 +25 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.settingslib.datastore /** * A [BackupRestoreStorage] that implements [Observable]. * * This class provides the [Observable] implementations on top of [DataObservable] by delegation. */ abstract class ObservableBackupRestoreStorage : BackupRestoreStorage(), Observable by DataObservable() Loading
packages/SettingsLib/DataStore/src/com/android/settingslib/datastore/BackupRestoreStorageManager.kt +35 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settingslib.datastore import android.app.Application import android.app.backup.BackupAgentHelper import android.app.backup.BackupManager import android.content.Context import android.util.Log Loading @@ -42,6 +43,35 @@ class BackupRestoreStorageManager private constructor(private val application: A BackupManager.dataChanged(application.packageName) } /** * Adds all the registered [BackupRestoreStorage] as the helpers of given [BackupAgentHelper]. * * @see BackupAgentHelper.addHelper */ fun addBackupAgentHelpers(backupAgentHelper: BackupAgentHelper) { for ((keyPrefix, storage) in storages) { backupAgentHelper.addHelper(keyPrefix, storage) } } /** * Callback when restore finished. * * The observers of the storages will be notified. */ fun onRestoreFinished() { for (storage in storages.values) { storage.notifyRestoreFinished() } } private fun BackupRestoreStorage.notifyRestoreFinished() { when (this) { is KeyedObservable<*> -> notifyChange(ChangeReason.RESTORE) is Observable -> notifyChange(ChangeReason.RESTORE) } } /** * Adds a list of storages. * Loading Loading @@ -78,6 +108,11 @@ class BackupRestoreStorageManager private constructor(private val application: A } } /** Removes all the storages. */ fun removeAll() { for ((name, _) in storages) remove(name) } /** Removes storage with given name. */ fun remove(name: String): BackupRestoreStorage? { val storage = storages.remove(name) Loading
packages/SettingsLib/DataStore/src/com/android/settingslib/datastore/ObservableBackupRestoreStorage.kt 0 → 100644 +25 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 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.settingslib.datastore /** * A [BackupRestoreStorage] that implements [Observable]. * * This class provides the [Observable] implementations on top of [DataObservable] by delegation. */ abstract class ObservableBackupRestoreStorage : BackupRestoreStorage(), Observable by DataObservable()