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

Commit c141d08b authored by Lenka Trochtova's avatar Lenka Trochtova
Browse files

New management API for making backups mandatory.

Let the device owner make backups with a chosen backup
transport mandatory.

BUG: 64012357
Test: make RunFrameworksServicesRoboTests
Test: manually together with the corresponding GmsCore change.
Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases --test
com.android.cts.devicepolicy.DeviceOwnerTest#testGetAndSetMandatoryBackupTransport
Test: cts-tradefed run cts -m CtsBackupHostTestCase --test
android.cts.backup.BackupDeviceOwnerHostSideTest#testMandatoryBackupTransport

Change-Id: I9bfae5799beae3459659e697813b75a9b508ae55
parent 4fe35999
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6403,6 +6403,7 @@ package android.app.admin {
    method public int getLockTaskFeatures(android.content.ComponentName);
    method public java.lang.String[] getLockTaskPackages(android.content.ComponentName);
    method public java.lang.CharSequence getLongSupportMessage(android.content.ComponentName);
    method public android.content.ComponentName getMandatoryBackupTransport();
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public int getOrganizationColor(android.content.ComponentName);
@@ -6502,6 +6503,7 @@ package android.app.admin {
    method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException;
    method public void setLogoutEnabled(android.content.ComponentName, boolean);
    method public void setLongSupportMessage(android.content.ComponentName, java.lang.CharSequence);
    method public void setMandatoryBackupTransport(android.content.ComponentName, android.content.ComponentName);
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
+44 −0
Original line number Diff line number Diff line
@@ -8633,6 +8633,13 @@ public class DevicePolicyManager {
     *
     * <p> Backup service is off by default when device owner is present.
     *
     * <p> If backups are made mandatory by specifying a non-null mandatory backup transport using
     * the {@link DevicePolicyManager#setMandatoryBackupTransport} method, the backup service is
     * automatically enabled.
     *
     * <p> If the backup service is disabled using this method after the mandatory backup transport
     * has been set, the mandatory backup transport is cleared.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param enabled {@code true} to enable the backup service, {@code false} to disable it.
     * @throws SecurityException if {@code admin} is not a device owner.
@@ -8663,6 +8670,43 @@ public class DevicePolicyManager {
        }
    }

    /**
     * Makes backups mandatory and enforces the usage of the specified backup transport.
     *
     * <p>When a {@code null} backup transport is specified, backups are made optional again.
     * <p>Only device owner can call this method.
     * <p>If backups were disabled and a non-null backup transport {@link ComponentName} is
     * specified, backups will be enabled.
     *
     * @param admin admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param backupTransportComponent The backup transport layer to be used for mandatory backups.
     * @throws SecurityException if {@code admin} is not a device owner.
     */
    public void setMandatoryBackupTransport(
            @NonNull ComponentName admin, @Nullable ComponentName backupTransportComponent) {
        try {
            mService.setMandatoryBackupTransport(admin, backupTransportComponent);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the backup transport which has to be used for backups if backups are mandatory or
     * {@code null} if backups are not mandatory.
     *
     * @return a {@link ComponentName} of the backup transport layer to be used if backups are
     *         mandatory or {@code null} if backups are not mandatory.
     */
    public ComponentName getMandatoryBackupTransport() {
        try {
            return mService.getMandatoryBackupTransport();
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }


    /**
     * Called by a device owner to control the network logging feature.
     *
+2 −0
Original line number Diff line number Diff line
@@ -359,6 +359,8 @@ interface IDevicePolicyManager {

    void setBackupServiceEnabled(in ComponentName admin, boolean enabled);
    boolean isBackupServiceEnabled(in ComponentName admin);
    void setMandatoryBackupTransport(in ComponentName admin, in ComponentName backupTransportComponent);
    ComponentName getMandatoryBackupTransport();

    void setNetworkLoggingEnabled(in ComponentName admin, boolean enabled);
    boolean isNetworkLoggingEnabled(in ComponentName admin);
+2 −1
Original line number Diff line number Diff line
@@ -294,7 +294,8 @@ interface IBackupManager {
     *
     * @param transport ComponentName of the service hosting the transport. This is different from
     *                  the transport's name that is returned by {@link BackupTransport#name()}.
     * @param listener A listener object to get a callback on the transport being selected.
     * @param listener A listener object to get a callback on the transport being selected. It may
     *                 be {@code null}.
     *
     * @hide
     */
+25 −0
Original line number Diff line number Diff line
package com.android.server.backup;

import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;

import com.android.internal.annotations.VisibleForTesting;

/**
 * A helper class to decouple this service from {@link DevicePolicyManager} in order to improve
 * testability.
 */
@VisibleForTesting
public class BackupPolicyEnforcer {
    private DevicePolicyManager mDevicePolicyManager;

    public BackupPolicyEnforcer(Context context) {
        mDevicePolicyManager =
                (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    }

    public ComponentName getMandatoryBackupTransport() {
        return mDevicePolicyManager.getMandatoryBackupTransport();
    }
}
Loading