blob: bf52286245ce4ef17536fad5a5bc95a0817aa37e [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;
danielwbhuang2deed0e2025-08-14 15:52:31 +080026import com.android.settings.i18n.RegionalCustomizationFeatureProvider;
yyalanc2934df2025-09-02 08:22:51 +000027import com.android.settings.inputmethod.TouchpadThreeFingerTapLaunchingAppBackupHelper;
28import com.android.settings.inputmethod.TouchpadThreeFingerTapUtils;
XingHaiLu49cb0002023-11-14 14:17:30 +080029import com.android.settings.onboarding.OnboardingFeatureProvider;
30import com.android.settings.overlay.FeatureFactory;
Matías Hernández939189b2024-09-11 18:36:47 +020031import com.android.settings.shortcut.ShortcutsUpdater;
Jacky Wang006bf172024-02-29 11:10:53 +080032import com.android.settingslib.datastore.BackupRestoreStorageManager;
Sunny Goyalae788a12019-04-24 17:11:24 -070033
Jacky Wang382f8452024-02-29 22:47:53 +080034/** Backup agent for Settings APK */
Sunny Goyalae788a12019-04-24 17:11:24 -070035public class SettingsBackupHelper extends BackupAgentHelper {
Matías Hernández939189b2024-09-11 18:36:47 +020036 private static final String TAG = "SettingsBackupHelper";
37
XingHaiLu49cb0002023-11-14 14:17:30 +080038 public static final String SOUND_BACKUP_HELPER = "SoundSettingsBackup";
danielwbhuang44c25ed2024-07-24 18:02:10 +080039 public static final String ACCESSIBILITY_APPEARANCE_BACKUP_HELPER =
40 "AccessibilityAppearanceSettingsBackup";
danielwbhuang2deed0e2025-08-14 15:52:31 +080041 public static final String MOVEMENT_BACKUP_HELPER = "MovementSettingsBackup";
Mina Granicfdb9ac72025-04-02 15:00:32 +000042 private static final String USER_ASPECT_RATIO_BACKUP_HELPER = "UserAspectRatioSettingsBackup";
yyalanc2934df2025-09-02 08:22:51 +000043 private static final String TOUCHPAD_THREE_FINGER_TAP_LAUNCHING_APP_BACKUP_HELPER =
44 "TouchpadThreeFingerTapLaunchingAppBackup";
Sunny Goyalae788a12019-04-24 17:11:24 -070045
46 @Override
47 public void onCreate() {
48 super.onCreate();
Jacky Wang006bf172024-02-29 11:10:53 +080049 BackupRestoreStorageManager.getInstance(this).addBackupAgentHelpers(this);
danielwbhuang44c25ed2024-07-24 18:02:10 +080050 OnboardingFeatureProvider onboardingFeatureProvider =
51 FeatureFactory.getFeatureFactory().getOnboardingFeatureProvider();
danielwbhuang2deed0e2025-08-14 15:52:31 +080052 RegionalCustomizationFeatureProvider regionalCustomizationFeatureProvider =
53 FeatureFactory.getFeatureFactory().getRegionalCustomizationFeatureProvider();
danielwbhuang44c25ed2024-07-24 18:02:10 +080054
XingHaiLu49cb0002023-11-14 14:17:30 +080055 if (Flags.enableSoundBackup()) {
XingHaiLu49cb0002023-11-14 14:17:30 +080056 if (onboardingFeatureProvider != null) {
57 addHelper(SOUND_BACKUP_HELPER, onboardingFeatureProvider.
58 getSoundBackupHelper(this, this.getBackupRestoreEventLogger()));
59 }
60 }
danielwbhuang44c25ed2024-07-24 18:02:10 +080061
62 if (Flags.accessibilityAppearanceSettingsBackupEnabled()) {
63 if (onboardingFeatureProvider != null) {
64 addHelper(ACCESSIBILITY_APPEARANCE_BACKUP_HELPER,
65 onboardingFeatureProvider.getAccessibilityAppearanceBackupHelper(
66 this, this.getBackupRestoreEventLogger()));
67 }
68 }
Mina Granicfdb9ac72025-04-02 15:00:32 +000069
danielwbhuang2deed0e2025-08-14 15:52:31 +080070 if (Flags.movementSettingsBackupEnabled()) {
71 if (regionalCustomizationFeatureProvider != null) {
72 addHelper(MOVEMENT_BACKUP_HELPER,
73 regionalCustomizationFeatureProvider.getMovementBackupHelper(
74 this, this.getBackupRestoreEventLogger()));
75 }
76 }
77
Mina Granicd9f9a412025-04-23 17:19:41 +000078 if (UserAspectRatioManager.isFeatureEnabled(getApplicationContext())) {
79 // Since the aconfig flag below is read-only, this class would not compile, and tests
80 // would fail to find the class, even if they are testing only code beyond the
81 // flag-guarded code.
82 final UserAspectRatioBackupHelper userAspectRatioBackupHelper =
83 new UserAspectRatioBackupHelper(this, AppGlobals.getPackageManager(),
84 getBackupRestoreEventLogger());
85 if (com.android.window.flags.Flags.backupAndRestoreForUserAspectRatioSettings()) {
86 addHelper(USER_ASPECT_RATIO_BACKUP_HELPER, userAspectRatioBackupHelper);
87 }
Mina Granicfdb9ac72025-04-02 15:00:32 +000088 }
yyalanc2934df2025-09-02 08:22:51 +000089
90 if (Flags.threeFingerTapAppLaunch()) {
91 String key = TouchpadThreeFingerTapUtils.getFileToBackup();
92 final TouchpadThreeFingerTapLaunchingAppBackupHelper launchingAppBackupHelper =
93 new TouchpadThreeFingerTapLaunchingAppBackupHelper(this, key);
94 addHelper(
95 TOUCHPAD_THREE_FINGER_TAP_LAUNCHING_APP_BACKUP_HELPER,
96 launchingAppBackupHelper);
97 }
Sunny Goyalae788a12019-04-24 17:11:24 -070098 }
99
100 @Override
101 public void onRestoreFinished() {
102 super.onRestoreFinished();
Jacky Wang006bf172024-02-29 11:10:53 +0800103 BackupRestoreStorageManager.getInstance(this).onRestoreFinished();
Matías Hernández939189b2024-09-11 18:36:47 +0200104 try {
105 ShortcutsUpdater.updatePinnedShortcuts(this);
106 } catch (Exception e) {
107 Log.e(TAG, "Error updating shortcuts after restoring backup", e);
108 }
Sunny Goyalae788a12019-04-24 17:11:24 -0700109 }
Sunny Goyalae788a12019-04-24 17:11:24 -0700110}