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

Commit ae5ef2ef authored by Sarp Misoglu's avatar Sarp Misoglu Committed by Android (Google) Code Review
Browse files

Merge "Add BackupTransport#getBackupManagerMonitor"

parents 4dffd5e7 f7fbe355
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
@@ -1123,18 +1122,4 @@ public class BackupManager {
            });
        }
    }

    private class BackupManagerMonitorWrapper extends IBackupManagerMonitor.Stub {
        final BackupManagerMonitor mMonitor;

        BackupManagerMonitorWrapper(BackupManagerMonitor monitor) {
            mMonitor = monitor;
        }

        @Override
        public void onEvent(final Bundle event) throws RemoteException {
            mMonitor.onEvent(event);
        }
    }

}
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.Bundle;
import android.os.RemoteException;

/**
 * Wrapper around {@link BackupManagerMonitor} that helps with IPC between the caller of backup
 * APIs and the backup service.
 *
 * The caller implements {@link BackupManagerMonitor} and passes it into framework APIs that run on
 * the caller's process. Those framework APIs will then wrap it around this class when doing the
 * actual IPC.
 */
class BackupManagerMonitorWrapper extends IBackupManagerMonitor.Stub {
    private final BackupManagerMonitor mMonitor;

    BackupManagerMonitorWrapper(BackupManagerMonitor monitor) {
        mMonitor = monitor;
    }

    @Override
    public void onEvent(final Bundle event) throws RemoteException {
        mMonitor.onEvent(event);
    }
}
+24 −0
Original line number Diff line number Diff line
@@ -655,6 +655,20 @@ public class BackupTransport {
        return 0;
    }

    /**
     * Ask the transport for a {@link IBackupManagerMonitor} instance which will be used by the
     * framework to report logging events back to the transport.
     *
     * <p>Backups requested from outside the framework may pass in a monitor with the request,
     * however backups initiated by the framework will call this method to retrieve one.
     *
     * @hide
     */
    @Nullable
    public BackupManagerMonitor getBackupManagerMonitor() {
        return null;
    }

    /**
     * Bridge between the actual IBackupTransport implementation and the stable API.  If the
     * binder interface needs to change, we use this layer to translate so that we can
@@ -952,5 +966,15 @@ public class BackupTransport {
                callback.onOperationCompleteWithStatus(BackupTransport.TRANSPORT_ERROR);
            }
        }

        @Override
        public void getBackupManagerMonitor(AndroidFuture<IBackupManagerMonitor> resultFuture) {
            try {
                BackupManagerMonitor result = BackupTransport.this.getBackupManagerMonitor();
                resultFuture.complete(new BackupManagerMonitorWrapper(result));
            } catch (RuntimeException e) {
                resultFuture.cancel(/* mayInterruptIfRunning */ true);
            }
        }
    }
}
+0 −14
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
@@ -393,17 +392,4 @@ public class RestoreSession {
                    mHandler.obtainMessage(MSG_RESTORE_FINISHED, error, 0));
        }
    }

    private class BackupManagerMonitorWrapper extends IBackupManagerMonitor.Stub {
        final BackupManagerMonitor mMonitor;

        BackupManagerMonitorWrapper(BackupManagerMonitor monitor) {
            mMonitor = monitor;
        }

        @Override
        public void onEvent(final Bundle event) throws RemoteException {
            mMonitor.onEvent(event);
        }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.backup;

import android.app.backup.IBackupManagerMonitor;
import android.app.backup.RestoreDescription;
import android.app.backup.RestoreSet;
import android.content.Intent;
@@ -400,4 +401,13 @@ oneway interface IBackupTransport {
     * <p>For supported flags see {@link android.app.backup.BackupAgent}.
     */
    void getTransportFlags(in AndroidFuture<int> resultFuture);

    /**
     * Ask the transport for a {@link IBackupManagerMonitor} instance which will be used by the
     * framework to report logging events back to the transport.
     *
     * Backups requested from outside the framework may pass in a monitor with the request,
     * however backups initiated by the framework will call this method to retrieve one.
     */
    void getBackupManagerMonitor(in AndroidFuture<IBackupManagerMonitor> resultFuture);
}
Loading