blob: db8218b3e5a1f64000f2b3b6fb3ef3cc423b355f [file] [log] [blame]
Sunny Goyalae788a12019-04-24 17:11:24 -07001/**
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings.backup;
18
Mina Granicfdb9ac72025-04-02 15:00:32 +000019import android.app.AppGlobals;
Sunny Goyalae788a12019-04-24 17:11:24 -070020import android.app.backup.BackupAgentHelper;
Matías Hernández939189b2024-09-11 18:36:47 +020021import android.util.Log;
Sunny Goyalae788a12019-04-24 17:11:24 -070022
Mina Granicfdb9ac72025-04-02 15:00:32 +000023import com.android.settings.applications.appcompat.UserAspectRatioBackupHelper;
Mina Granicd9f9a412025-04-23 17:19:41 +000024import com.android.settings.applications.appcompat.UserAspectRatioManager;
Jacky Wang382f8452024-02-29 22:47:53 +080025import com.android.settings.flags.Flags;
XingHaiLu49cb0002023-11-14 14:17:30 +080026import com.android.settings.onboarding.OnboardingFeatureProvider;
27import com.android.settings.overlay.FeatureFactory;
Matías Hernández939189b2024-09-11 18:36:47 +020028import com.android.settings.shortcut.ShortcutsUpdater;
Jacky Wang006bf172024-02-29 11:10:53 +080029import com.android.settingslib.datastore.BackupRestoreStorageManager;
Sunny Goyalae788a12019-04-24 17:11:24 -070030
Jacky Wang382f8452024-02-29 22:47:53 +080031/** Backup agent for Settings APK */
Sunny Goyalae788a12019-04-24 17:11:24 -070032public class SettingsBackupHelper extends BackupAgentHelper {
Matías Hernández939189b2024-09-11 18:36:47 +020033 private static final String TAG = "SettingsBackupHelper";
34
XingHaiLu49cb0002023-11-14 14:17:30 +080035 public static final String SOUND_BACKUP_HELPER = "SoundSettingsBackup";
danielwbhuang44c25ed2024-07-24 18:02:10 +080036 public static final String ACCESSIBILITY_APPEARANCE_BACKUP_HELPER =
37 "AccessibilityAppearanceSettingsBackup";
Mina Granicfdb9ac72025-04-02 15:00:32 +000038 private static final String USER_ASPECT_RATIO_BACKUP_HELPER = "UserAspectRatioSettingsBackup";
Sunny Goyalae788a12019-04-24 17:11:24 -070039
40 @Override
41 public void onCreate() {
42 super.onCreate();
Jacky Wang006bf172024-02-29 11:10:53 +080043 BackupRestoreStorageManager.getInstance(this).addBackupAgentHelpers(this);
danielwbhuang44c25ed2024-07-24 18:02:10 +080044 OnboardingFeatureProvider onboardingFeatureProvider =
45 FeatureFactory.getFeatureFactory().getOnboardingFeatureProvider();
46
XingHaiLu49cb0002023-11-14 14:17:30 +080047 if (Flags.enableSoundBackup()) {
XingHaiLu49cb0002023-11-14 14:17:30 +080048 if (onboardingFeatureProvider != null) {
49 addHelper(SOUND_BACKUP_HELPER, onboardingFeatureProvider.
50 getSoundBackupHelper(this, this.getBackupRestoreEventLogger()));
51 }
52 }
danielwbhuang44c25ed2024-07-24 18:02:10 +080053
54 if (Flags.accessibilityAppearanceSettingsBackupEnabled()) {
55 if (onboardingFeatureProvider != null) {
56 addHelper(ACCESSIBILITY_APPEARANCE_BACKUP_HELPER,
57 onboardingFeatureProvider.getAccessibilityAppearanceBackupHelper(
58 this, this.getBackupRestoreEventLogger()));
59 }
60 }
Mina Granicfdb9ac72025-04-02 15:00:32 +000061
Mina Granicd9f9a412025-04-23 17:19:41 +000062 if (UserAspectRatioManager.isFeatureEnabled(getApplicationContext())) {
63 // Since the aconfig flag below is read-only, this class would not compile, and tests
64 // would fail to find the class, even if they are testing only code beyond the
65 // flag-guarded code.
66 final UserAspectRatioBackupHelper userAspectRatioBackupHelper =
67 new UserAspectRatioBackupHelper(this, AppGlobals.getPackageManager(),
68 getBackupRestoreEventLogger());
69 if (com.android.window.flags.Flags.backupAndRestoreForUserAspectRatioSettings()) {
70 addHelper(USER_ASPECT_RATIO_BACKUP_HELPER, userAspectRatioBackupHelper);
71 }
Mina Granicfdb9ac72025-04-02 15:00:32 +000072 }
Sunny Goyalae788a12019-04-24 17:11:24 -070073 }
74
75 @Override
76 public void onRestoreFinished() {
77 super.onRestoreFinished();
Jacky Wang006bf172024-02-29 11:10:53 +080078 BackupRestoreStorageManager.getInstance(this).onRestoreFinished();
Matías Hernández939189b2024-09-11 18:36:47 +020079 try {
80 ShortcutsUpdater.updatePinnedShortcuts(this);
81 } catch (Exception e) {
82 Log.e(TAG, "Error updating shortcuts after restoring backup", e);
83 }
Sunny Goyalae788a12019-04-24 17:11:24 -070084 }
Sunny Goyalae788a12019-04-24 17:11:24 -070085}