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

Commit 8817a6a8 authored by beatricemarch's avatar beatricemarch Committed by Beatrice Marchegiani
Browse files

Enable SystemBackupAgent to integrate with metrics.

Pass a logger instance to BackupHelpers in SystemBackupAgent.

Bug: 296844513
Test: atest -v SystemBackupAgentTest; manual: override flag value, add log events to some helpers in the SystemBackupAgent, check that the correct agent logs are printed in the backup dumpsys.

Change-Id: I2d14d49516849f4c992e8180baf4c3d431326a26
parent efdc1c87
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 android.app.backup;

import android.os.ParcelFileDescriptor;

/**
 * Utility class for writing BackupHelpers with added logging capabilities.
 * Used for passing a logger object to Helper in key shared backup agents
 *
 * @hide
 */
public abstract class BackupHelperWithLogger implements BackupHelper {
    private BackupRestoreEventLogger mLogger;
    private boolean mIsLoggerSet = false;

    public abstract void writeNewStateDescription(ParcelFileDescriptor newState);

    public abstract void restoreEntity(BackupDataInputStream data);

    public abstract void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState);

    /**
     * Gets the logger so that the backuphelper can log success/error for each datatype handled
     */
    public BackupRestoreEventLogger getLogger() {
        return mLogger;
    }

    /**
     * Allow the shared backup agent to pass a logger to each of its backup helper
     */
    public void setLogger(BackupRestoreEventLogger logger) {
        mLogger = logger;
        mIsLoggerSet = true;
    }

    /**
     * Allow the helper to check if its shared backup agent has passed a logger
     */
    public boolean isLoggerSet() {
        return mIsLoggerSet;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ import java.util.zip.InflaterInputStream;
 *
 * @hide
 */
public abstract class BlobBackupHelper implements BackupHelper {
public abstract class BlobBackupHelper extends BackupHelperWithLogger {
    private static final String TAG = "BlobBackupHelper";
    private static final boolean DEBUG = false;

+2 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.accounts.AccountManager;
import android.app.backup.BackupDataInputStream;
import android.app.backup.BackupDataOutput;
import android.app.backup.BackupHelper;
import android.app.backup.BackupHelperWithLogger;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SyncAdapterType;
@@ -56,7 +57,7 @@ import java.util.Set;
 * sync settings are backed up as a JSON object containing all the necessary information for
 * restoring the sync settings later.
 */
public class AccountSyncSettingsBackupHelper implements BackupHelper {
public class AccountSyncSettingsBackupHelper extends BackupHelperWithLogger {

    private static final String TAG = "AccountSyncSettingsBackupHelper";
    private static final boolean DEBUG = false;
+9 −0
Original line number Diff line number Diff line
@@ -9,6 +9,15 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "enable_metrics_system_backup_agents"
    namespace: "backup"
    description: "Enable SystemBackupAgent to collect B&R agent metrics by passing an instance of "
            "the logger to each BackupHelper."
    bug: "296844513"
    is_fixed_read_only: true
}

flag {
    name: "enable_max_size_writes_to_pipes"
    namespace: "onboarding"
+1 −0
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ java_library_static {
        "com_android_wm_shell_flags_lib",
        "com.android.server.utils_aconfig-java",
        "service-jobscheduler-deviceidle.flags-aconfig-java",
        "backup_flags_lib",
        "policy_flags_lib",
    ],
    javac_shard_size: 50,
Loading