| Sunny Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 1 | /** |
| 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 | |
| 17 | package com.android.settings.backup; |
| 18 | |
| Mina Granic | fdb9ac7 | 2025-04-02 15:00:32 +0000 | [diff] [blame] | 19 | import android.app.AppGlobals; |
| Sunny Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 20 | import android.app.backup.BackupAgentHelper; |
| Matías Hernández | 939189b | 2024-09-11 18:36:47 +0200 | [diff] [blame] | 21 | import android.util.Log; |
| Sunny Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 22 | |
| Mina Granic | fdb9ac7 | 2025-04-02 15:00:32 +0000 | [diff] [blame] | 23 | import com.android.settings.applications.appcompat.UserAspectRatioBackupHelper; |
| Mina Granic | d9f9a41 | 2025-04-23 17:19:41 +0000 | [diff] [blame] | 24 | import com.android.settings.applications.appcompat.UserAspectRatioManager; |
| Jacky Wang | 382f845 | 2024-02-29 22:47:53 +0800 | [diff] [blame] | 25 | import com.android.settings.flags.Flags; |
| danielwbhuang | 2deed0e | 2025-08-14 15:52:31 +0800 | [diff] [blame] | 26 | import com.android.settings.i18n.RegionalCustomizationFeatureProvider; |
| yyalan | c2934df | 2025-09-02 08:22:51 +0000 | [diff] [blame] | 27 | import com.android.settings.inputmethod.TouchpadThreeFingerTapLaunchingAppBackupHelper; |
| 28 | import com.android.settings.inputmethod.TouchpadThreeFingerTapUtils; |
| XingHaiLu | 49cb000 | 2023-11-14 14:17:30 +0800 | [diff] [blame] | 29 | import com.android.settings.onboarding.OnboardingFeatureProvider; |
| 30 | import com.android.settings.overlay.FeatureFactory; |
| Matías Hernández | 939189b | 2024-09-11 18:36:47 +0200 | [diff] [blame] | 31 | import com.android.settings.shortcut.ShortcutsUpdater; |
| Jacky Wang | 006bf17 | 2024-02-29 11:10:53 +0800 | [diff] [blame] | 32 | import com.android.settingslib.datastore.BackupRestoreStorageManager; |
| Sunny Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 33 | |
| Jacky Wang | 382f845 | 2024-02-29 22:47:53 +0800 | [diff] [blame] | 34 | /** Backup agent for Settings APK */ |
| Sunny Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 35 | public class SettingsBackupHelper extends BackupAgentHelper { |
| Matías Hernández | 939189b | 2024-09-11 18:36:47 +0200 | [diff] [blame] | 36 | private static final String TAG = "SettingsBackupHelper"; |
| 37 | |
| XingHaiLu | 49cb000 | 2023-11-14 14:17:30 +0800 | [diff] [blame] | 38 | public static final String SOUND_BACKUP_HELPER = "SoundSettingsBackup"; |
| danielwbhuang | 44c25ed | 2024-07-24 18:02:10 +0800 | [diff] [blame] | 39 | public static final String ACCESSIBILITY_APPEARANCE_BACKUP_HELPER = |
| 40 | "AccessibilityAppearanceSettingsBackup"; |
| danielwbhuang | 2deed0e | 2025-08-14 15:52:31 +0800 | [diff] [blame] | 41 | public static final String MOVEMENT_BACKUP_HELPER = "MovementSettingsBackup"; |
| Mina Granic | fdb9ac7 | 2025-04-02 15:00:32 +0000 | [diff] [blame] | 42 | private static final String USER_ASPECT_RATIO_BACKUP_HELPER = "UserAspectRatioSettingsBackup"; |
| yyalan | c2934df | 2025-09-02 08:22:51 +0000 | [diff] [blame] | 43 | private static final String TOUCHPAD_THREE_FINGER_TAP_LAUNCHING_APP_BACKUP_HELPER = |
| 44 | "TouchpadThreeFingerTapLaunchingAppBackup"; |
| Sunny Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 45 | |
| 46 | @Override |
| 47 | public void onCreate() { |
| 48 | super.onCreate(); |
| Jacky Wang | 006bf17 | 2024-02-29 11:10:53 +0800 | [diff] [blame] | 49 | BackupRestoreStorageManager.getInstance(this).addBackupAgentHelpers(this); |
| danielwbhuang | 44c25ed | 2024-07-24 18:02:10 +0800 | [diff] [blame] | 50 | OnboardingFeatureProvider onboardingFeatureProvider = |
| 51 | FeatureFactory.getFeatureFactory().getOnboardingFeatureProvider(); |
| danielwbhuang | 2deed0e | 2025-08-14 15:52:31 +0800 | [diff] [blame] | 52 | RegionalCustomizationFeatureProvider regionalCustomizationFeatureProvider = |
| 53 | FeatureFactory.getFeatureFactory().getRegionalCustomizationFeatureProvider(); |
| danielwbhuang | 44c25ed | 2024-07-24 18:02:10 +0800 | [diff] [blame] | 54 | |
| XingHaiLu | 49cb000 | 2023-11-14 14:17:30 +0800 | [diff] [blame] | 55 | if (Flags.enableSoundBackup()) { |
| XingHaiLu | 49cb000 | 2023-11-14 14:17:30 +0800 | [diff] [blame] | 56 | if (onboardingFeatureProvider != null) { |
| 57 | addHelper(SOUND_BACKUP_HELPER, onboardingFeatureProvider. |
| 58 | getSoundBackupHelper(this, this.getBackupRestoreEventLogger())); |
| 59 | } |
| 60 | } |
| danielwbhuang | 44c25ed | 2024-07-24 18:02:10 +0800 | [diff] [blame] | 61 | |
| 62 | if (Flags.accessibilityAppearanceSettingsBackupEnabled()) { |
| 63 | if (onboardingFeatureProvider != null) { |
| 64 | addHelper(ACCESSIBILITY_APPEARANCE_BACKUP_HELPER, |
| 65 | onboardingFeatureProvider.getAccessibilityAppearanceBackupHelper( |
| 66 | this, this.getBackupRestoreEventLogger())); |
| 67 | } |
| 68 | } |
| Mina Granic | fdb9ac7 | 2025-04-02 15:00:32 +0000 | [diff] [blame] | 69 | |
| danielwbhuang | 2deed0e | 2025-08-14 15:52:31 +0800 | [diff] [blame] | 70 | if (Flags.movementSettingsBackupEnabled()) { |
| 71 | if (regionalCustomizationFeatureProvider != null) { |
| 72 | addHelper(MOVEMENT_BACKUP_HELPER, |
| 73 | regionalCustomizationFeatureProvider.getMovementBackupHelper( |
| 74 | this, this.getBackupRestoreEventLogger())); |
| 75 | } |
| 76 | } |
| 77 | |
| Mina Granic | d9f9a41 | 2025-04-23 17:19:41 +0000 | [diff] [blame] | 78 | 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 Granic | fdb9ac7 | 2025-04-02 15:00:32 +0000 | [diff] [blame] | 88 | } |
| yyalan | c2934df | 2025-09-02 08:22:51 +0000 | [diff] [blame] | 89 | |
| 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 Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void onRestoreFinished() { |
| 102 | super.onRestoreFinished(); |
| Jacky Wang | 006bf17 | 2024-02-29 11:10:53 +0800 | [diff] [blame] | 103 | BackupRestoreStorageManager.getInstance(this).onRestoreFinished(); |
| Matías Hernández | 939189b | 2024-09-11 18:36:47 +0200 | [diff] [blame] | 104 | try { |
| 105 | ShortcutsUpdater.updatePinnedShortcuts(this); |
| 106 | } catch (Exception e) { |
| 107 | Log.e(TAG, "Error updating shortcuts after restoring backup", e); |
| 108 | } |
| Sunny Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 109 | } |
| Sunny Goyal | ae788a1 | 2019-04-24 17:11:24 -0700 | [diff] [blame] | 110 | } |