Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6bc44a07 authored by Garvit Narang's avatar Garvit Narang
Browse files

Add a wear backup helper

This adds a backup helper for Wear to use in system server along with an
internal interface to communicate the info.

Bug: 380505272
Test: manually confirm backup succesfull
Flag: EXEMPT trivial
Change-Id: Iaf2e8c24dd232911c1294e46b57f95e00b8e32f9
parent e579b0d6
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public class SystemBackupAgent extends BackupAgentHelper {
    private static final String SYSTEM_GENDER_HELPER = "system_gender";
    private static final String DISPLAY_HELPER = "display";
    private static final String INPUT_HELPER = "input";
    private static final String WEAR_BACKUP_HELPER = "wear";

    // 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
@@ -113,7 +114,7 @@ public class SystemBackupAgent extends BackupAgentHelper {
    private static final Set<String> sEligibleHelpersForNonSystemUser =
            SetUtils.union(sEligibleHelpersForProfileUser,
                    Sets.newArraySet(ACCOUNT_MANAGER_HELPER, USAGE_STATS_HELPER, PREFERRED_HELPER,
                            SHORTCUT_MANAGER_HELPER, INPUT_HELPER));
                            SHORTCUT_MANAGER_HELPER, INPUT_HELPER, WEAR_BACKUP_HELPER));

    private int mUserId = UserHandle.USER_SYSTEM;
    private boolean mIsProfileUser = false;
@@ -153,6 +154,11 @@ public class SystemBackupAgent extends BackupAgentHelper {
        if (com.android.hardware.input.Flags.enableBackupAndRestoreForInputGestures()) {
            addHelperIfEligibleForUser(INPUT_HELPER, new InputBackupHelper(mUserId));
        }

        // Add Wear helper only if the device is a watch
        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
            addHelperIfEligibleForUser(WEAR_BACKUP_HELPER, new WearBackupHelper());
        }
    }

    @Override
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright 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
 *
 *      https://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.Nullable;
import android.app.backup.BlobBackupHelper;

import com.android.server.LocalServices;

/** A {@link android.app.backup.BlobBackupHelper} for Wear */
public class WearBackupHelper extends BlobBackupHelper {

    private static final int BLOB_VERSION = 1;
    private static final String KEY_WEAR_BACKUP = "wear";
    @Nullable private final WearBackupInternal mWearBackupInternal;

    public WearBackupHelper() {
        super(BLOB_VERSION, KEY_WEAR_BACKUP);
        mWearBackupInternal = LocalServices.getService(WearBackupInternal.class);
    }

    @Override
    protected byte[] getBackupPayload(String key) {
        return KEY_WEAR_BACKUP.equals(key) && mWearBackupInternal != null
                ? mWearBackupInternal.getBackupPayload(getLogger())
                : null;
    }

    @Override
    protected void applyRestoredPayload(String key, byte[] payload) {
        if (KEY_WEAR_BACKUP.equals(key) && mWearBackupInternal != null) {
            mWearBackupInternal.applyRestoredPayload(payload);
        }
    }
}
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright 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
 *
 *      https://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.app.backup.BackupRestoreEventLogger;

import com.android.internal.annotations.Keep;

/** A local service internal for Wear OS handle backup/restore */
@Keep
public interface WearBackupInternal {

    /** Gets the backup payload */
    byte[] getBackupPayload(BackupRestoreEventLogger logger);

    /** Applies the restored payload */
    void applyRestoredPayload(byte[] payload);
}