diff options
| author | 2021-12-20 06:50:01 +0000 | |
|---|---|---|
| committer | 2021-12-20 06:50:01 +0000 | |
| commit | 6560e43b0604b441fb91babc516788aa2be073fa (patch) | |
| tree | 8300b1d5edba394c1b5f60777c1260b9bb194e02 | |
| parent | 4c44a2f18a80329aba7445a4277d31c450f4d308 (diff) | |
| parent | 765cd84bb81fe3a542c508e345b736901ee695dc (diff) | |
Merge "Add app-locales backup helper to SystemBackupAgent."
| -rw-r--r-- | services/core/java/com/android/server/backup/AppSpecificLocalesBackupHelper.java | 90 | ||||
| -rw-r--r-- | services/core/java/com/android/server/backup/SystemBackupAgent.java | 4 |
2 files changed, 93 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/backup/AppSpecificLocalesBackupHelper.java b/services/core/java/com/android/server/backup/AppSpecificLocalesBackupHelper.java new file mode 100644 index 000000000000..1726da2ff05d --- /dev/null +++ b/services/core/java/com/android/server/backup/AppSpecificLocalesBackupHelper.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2021 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.server.backup; + +import android.annotation.NonNull; +import android.annotation.UserIdInt; +import android.app.backup.BlobBackupHelper; +import android.util.Slog; + +import com.android.server.LocalServices; +import com.android.server.locales.LocaleManagerInternal; + +/** + * Helper for backing up app-specific locales. + * <p> + * This helper is used in {@link com.android.server.backup.SystemBackupAgent} + */ +public class AppSpecificLocalesBackupHelper extends BlobBackupHelper { + private static final String TAG = "AppLocalesBackupHelper"; // must be < 23 chars + private static final boolean DEBUG = false; + + // Current version of the blob schema + private static final int BLOB_VERSION = 1; + + // Key under which the payload blob is stored + private static final String KEY_APP_LOCALES = "app_locales"; + + private final @UserIdInt int mUserId; + + private final @NonNull LocaleManagerInternal mLocaleManagerInternal; + + public AppSpecificLocalesBackupHelper(int userId) { + super(BLOB_VERSION, KEY_APP_LOCALES); + mUserId = userId; + mLocaleManagerInternal = LocalServices.getService(LocaleManagerInternal.class); + } + + @Override + protected byte[] getBackupPayload(String key) { + if (DEBUG) { + Slog.d(TAG, "Handling backup of " + key); + } + + byte[] newPayload = null; + if (KEY_APP_LOCALES.equals(key)) { + try { + newPayload = mLocaleManagerInternal.getBackupPayload(mUserId); + } catch (Exception e) { + // Treat as no data + Slog.e(TAG, "Couldn't communicate with locale manager", e); + newPayload = null; + } + } else { + Slog.w(TAG, "Unexpected backup key " + key); + } + return newPayload; + } + + @Override + protected void applyRestoredPayload(String key, byte[] payload) { + if (DEBUG) { + Slog.d(TAG, "Handling restore of " + key); + } + + if (KEY_APP_LOCALES.equals(key)) { + try { + mLocaleManagerInternal.stageAndApplyRestoredPayload(payload, mUserId); + } catch (Exception e) { + Slog.e(TAG, "Couldn't communicate with locale manager", e); + } + } else { + Slog.w(TAG, "Unexpected restore key " + key); + } + } + +} diff --git a/services/core/java/com/android/server/backup/SystemBackupAgent.java b/services/core/java/com/android/server/backup/SystemBackupAgent.java index fa1820456fb9..d39d2d1eefb7 100644 --- a/services/core/java/com/android/server/backup/SystemBackupAgent.java +++ b/services/core/java/com/android/server/backup/SystemBackupAgent.java @@ -57,6 +57,7 @@ public class SystemBackupAgent extends BackupAgentHelper { private static final String ACCOUNT_MANAGER_HELPER = "account_manager"; private static final String SLICES_HELPER = "slices"; private static final String PEOPLE_HELPER = "people"; + private static final String APP_LOCALES_HELPER = "app_locales"; // These paths must match what the WallpaperManagerService uses. The leaf *_FILENAME // are also used in the full-backup file format, so must not change unless steps are @@ -83,7 +84,7 @@ public class SystemBackupAgent extends BackupAgentHelper { private static final String WALLPAPER_IMAGE_KEY = WallpaperBackupHelper.WALLPAPER_IMAGE_KEY; private static final Set<String> sEligibleForMultiUser = Sets.newArraySet( - PERMISSION_HELPER, NOTIFICATION_HELPER, SYNC_SETTINGS_HELPER); + PERMISSION_HELPER, NOTIFICATION_HELPER, SYNC_SETTINGS_HELPER, APP_LOCALES_HELPER); private int mUserId = UserHandle.USER_SYSTEM; @@ -102,6 +103,7 @@ public class SystemBackupAgent extends BackupAgentHelper { addHelper(ACCOUNT_MANAGER_HELPER, new AccountManagerBackupHelper()); addHelper(SLICES_HELPER, new SliceBackupHelper(this)); addHelper(PEOPLE_HELPER, new PeopleBackupHelper(mUserId)); + addHelper(APP_LOCALES_HELPER, new AppSpecificLocalesBackupHelper(mUserId)); } @Override |