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

Commit ac8d23d9 authored by Ruslan Tkhakokhov's avatar Ruslan Tkhakokhov Committed by Android (Google) Code Review
Browse files

Merge "Pass operation type via BackupManagerMonitor#onEvent" into udc-dev

parents 22480bc5 97853abf
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -207,6 +207,12 @@ oneway interface IBackupAgent {
    void getLoggerResults(
            in AndroidFuture<List<BackupRestoreEventLogger.DataTypeResult>> resultsFuture);

    /**
    * Provides the operation type (backup or restore) the agent is created for. See
    * {@link android.app.backup.BackupAnnotations.OperationType}.
    */
    void getOperationType(in AndroidFuture<int> operationTypeFuture);

    /**
     * Clears the logs accumulated by the BackupAgent during a backup or restore operation.
     */
+6 −0
Original line number Diff line number Diff line
@@ -1352,6 +1352,12 @@ public abstract class BackupAgent extends ContextWrapper {
            }
        }

        @Override
        public void getOperationType(
                AndroidFuture<Integer> in) {
            in.complete(mLogger == null ? OperationType.UNKNOWN : mLogger.getOperationType());
        }

        @Override
        public void clearBackupRestoreEventLogger() {
            final long ident = Binder.clearCallingIdentity();
+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.app.backup;

import android.annotation.SystemApi;
import android.app.backup.BackupAnnotations.OperationType;
import android.os.Bundle;

/**
@@ -136,6 +137,13 @@ public class BackupManagerMonitor {
  public static final String EXTRA_LOG_AGENT_LOGGING_RESULTS =
          "android.app.backup.extra.LOG_AGENT_LOGGING_RESULTS";

  /**
   * The operation type this log is associated with. See {@link OperationType}.
   *
   * @hide
   */
  public static final String EXTRA_LOG_OPERATION_TYPE = "android.app.backup.extra.OPERATION_TYPE";

  // TODO complete this list with all log messages. And document properly.
  public static final int LOG_EVENT_ID_FULL_BACKUP_CANCEL = 4;
  public static final int LOG_EVENT_ID_ILLEGAL_KEY = 5;
+3 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.app.IActivityManager;
import android.app.IBackupAgent;
import android.app.PendingIntent;
import android.app.backup.BackupAgent;
import android.app.backup.BackupAnnotations;
import android.app.backup.BackupAnnotations.BackupDestination;
import android.app.backup.BackupManager;
import android.app.backup.BackupManagerMonitor;
@@ -3066,7 +3067,8 @@ public class UserBackupManagerService {
                    /* caller */ "BMS.reportDelayedRestoreResult");

            IBackupManagerMonitor monitor = transportClient.getBackupManagerMonitor();
            BackupManagerMonitorUtils.sendAgentLoggingResults(monitor, packageInfo, results);
            BackupManagerMonitorUtils.sendAgentLoggingResults(monitor, packageInfo, results,
                    BackupAnnotations.OperationType.RESTORE);
        } catch (NameNotFoundException | TransportNotAvailableException
                | TransportNotRegisteredException | RemoteException e) {
            Slog.w(TAG, "Failed to send delayed restore logs: " + e);
+10 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.backup.utils;

import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_AGENT_LOGGING_RESULTS;
import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_EVENT_PACKAGE_NAME;
import static android.app.backup.BackupManagerMonitor.EXTRA_LOG_OPERATION_TYPE;
import static android.app.backup.BackupManagerMonitor.LOG_EVENT_CATEGORY_AGENT;
import static android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_AGENT_LOGGING_RESULTS;

@@ -27,6 +28,7 @@ import static com.android.server.backup.BackupManagerService.TAG;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.IBackupAgent;
import android.app.backup.BackupAnnotations.OperationType;
import android.app.backup.BackupManagerMonitor;
import android.app.backup.BackupRestoreEventLogger.DataTypeResult;
import android.app.backup.IBackupManagerMonitor;
@@ -122,9 +124,13 @@ public class BackupManagerMonitorUtils {
        try {
            AndroidFuture<List<DataTypeResult>> resultsFuture =
                    new AndroidFuture<>();
            AndroidFuture<Integer> operationTypeFuture = new AndroidFuture<>();
            agent.getLoggerResults(resultsFuture);
            agent.getOperationType(operationTypeFuture);
            return sendAgentLoggingResults(monitor, pkg,
                    resultsFuture.get(AGENT_LOGGER_RESULTS_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
                    resultsFuture.get(AGENT_LOGGER_RESULTS_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS),
                    operationTypeFuture.get(AGENT_LOGGER_RESULTS_TIMEOUT_MILLIS,
                            TimeUnit.MILLISECONDS));
        } catch (TimeoutException e) {
            Slog.w(TAG, "Timeout while waiting to retrieve logging results from agent", e);
        } catch (Exception e) {
@@ -134,10 +140,12 @@ public class BackupManagerMonitorUtils {
    }

    public static IBackupManagerMonitor sendAgentLoggingResults(
            @NonNull IBackupManagerMonitor monitor, PackageInfo pkg, List<DataTypeResult> results) {
            @NonNull IBackupManagerMonitor monitor, PackageInfo pkg, List<DataTypeResult> results,
            @OperationType int operationType) {
        Bundle loggerResultsBundle = new Bundle();
        loggerResultsBundle.putParcelableList(
                EXTRA_LOG_AGENT_LOGGING_RESULTS, results);
        loggerResultsBundle.putInt(EXTRA_LOG_OPERATION_TYPE, operationType);
        return monitorEvent(
                monitor,
                LOG_EVENT_ID_AGENT_LOGGING_RESULTS,
Loading