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

Commit c8b4c7f1 authored by Trung Lam's avatar Trung Lam Committed by Android (Google) Code Review
Browse files

Merge "Added PeopleBackupHelper and skeleton backup/restore methods on PeopleServiceInternal."

parents 49f7e6bf d7cf8f29
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.app.backup.BlobBackupHelper;
import android.util.Slog;

import com.android.server.LocalServices;
import com.android.server.people.PeopleServiceInternal;

class PeopleBackupHelper extends BlobBackupHelper {

    private static final String TAG = PeopleBackupHelper.class.getSimpleName();
    private static final boolean DEBUG = false;

    // Current schema of the backup state blob.
    private static final int STATE_VERSION = 1;

    // Key under which conversation infos state blob is committed to backup.
    private static final String KEY_CONVERSATIONS = "people_conversation_infos";

    private final int mUserId;

    PeopleBackupHelper(int userId) {
        super(STATE_VERSION, KEY_CONVERSATIONS);
        mUserId = userId;
    }

    @Override
    protected byte[] getBackupPayload(String key) {
        if (!KEY_CONVERSATIONS.equals(key)) {
            Slog.w(TAG, "Unexpected backup key " + key);
            return new byte[0];
        }
        PeopleServiceInternal ps = LocalServices.getService(PeopleServiceInternal.class);
        if (DEBUG) {
            Slog.d(TAG, "Handling backup of " + key);
        }
        return ps.backupConversationInfos(mUserId);
    }

    @Override
    protected void applyRestoredPayload(String key, byte[] payload) {
        if (!KEY_CONVERSATIONS.equals(key)) {
            Slog.w(TAG, "Unexpected restore key " + key);
            return;
        }
        PeopleServiceInternal ps = LocalServices.getService(PeopleServiceInternal.class);
        if (DEBUG) {
            Slog.d(TAG, "Handling restore of " + key);
        }
        ps.restoreConversationInfos(mUserId, key, payload);
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public class SystemBackupAgent extends BackupAgentHelper {
    private static final String SHORTCUT_MANAGER_HELPER = "shortcut_manager";
    private static final String ACCOUNT_MANAGER_HELPER = "account_manager";
    private static final String SLICES_HELPER = "slices";
    private static final String PEOPLE_HELPER = "people";

    // 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
@@ -99,6 +100,7 @@ public class SystemBackupAgent extends BackupAgentHelper {
        addHelper(SHORTCUT_MANAGER_HELPER, new ShortcutBackupHelper());
        addHelper(ACCOUNT_MANAGER_HELPER, new AccountManagerBackupHelper());
        addHelper(SLICES_HELPER, new SliceBackupHelper(this));
        addHelper(PEOPLE_HELPER, new PeopleBackupHelper(mUserId));
    }

    @Override
+17 −1
Original line number Diff line number Diff line
@@ -16,9 +16,25 @@

package com.android.server.people;

import android.annotation.NonNull;
import android.service.appprediction.IPredictionService;

/**
 * @hide Only for use within the system server.
 */
public abstract class PeopleServiceInternal extends IPredictionService.Stub {}
public abstract class PeopleServiceInternal extends IPredictionService.Stub {

    /**
     * The number conversation infos will be dynamic, based on the currently installed apps on the
     * device. All of which should be combined into a single blob to be backed up.
     */
    public abstract byte[] backupConversationInfos(@NonNull int userId);

    /**
     * Multiple conversation infos may exist in the restore payload, child classes are required to
     * manage the restoration based on how individual conversation infos were originally combined
     * during backup.
     */
    public abstract void restoreConversationInfos(@NonNull int userId, @NonNull String key,
            @NonNull byte[] payload);
}
+9 −0
Original line number Diff line number Diff line
@@ -137,5 +137,14 @@ public class PeopleService extends SystemService {
                Slog.e(TAG, "Failed to calling callback" + e);
            }
        }

        @Override
        public byte[] backupConversationInfos(int userId) {
            return new byte[0];
        }

        @Override
        public void restoreConversationInfos(int userId, String key, byte[] payload) {
        }
    }
}