Add DevicePolicyManager.setBackupServiceEnabled as hidden API.
BUG=28628532
Change-Id: I48c3423734e54b6a4d70e58d50c98c3e17790e0d
(based on a820252460)
This commit is contained in:
@@ -6493,4 +6493,35 @@ public class DevicePolicyManager {
|
|||||||
throw new SecurityException(functionName + " cannot be called on the parent instance");
|
throw new SecurityException(functionName + " cannot be called on the parent instance");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
* Enable backup service.
|
||||||
|
* <p>This includes all backup and restore mechanisms.
|
||||||
|
* Setting this to {@code false} will make backup service no-op or return empty results.
|
||||||
|
*
|
||||||
|
* <p>There must be only one user on the device, managed by the device owner.
|
||||||
|
* Otherwise a {@link SecurityException} will be thrown.
|
||||||
|
*
|
||||||
|
* <p>Backup service is off by default when device owner is present.
|
||||||
|
*/
|
||||||
|
public void setBackupServiceEnabled(@NonNull ComponentName admin, boolean enabled) {
|
||||||
|
try {
|
||||||
|
mService.setBackupServiceEnabled(admin, enabled);
|
||||||
|
} catch (RemoteException re) {
|
||||||
|
throw re.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
* @return {@code true} if backup service is enabled, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isBackupServiceEnabled(@NonNull ComponentName admin) {
|
||||||
|
try {
|
||||||
|
return mService.isBackupServiceEnabled(admin);
|
||||||
|
} catch (RemoteException re) {
|
||||||
|
throw re.rethrowFromSystemServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -305,4 +305,7 @@ interface IDevicePolicyManager {
|
|||||||
boolean isDeviceProvisioned();
|
boolean isDeviceProvisioned();
|
||||||
boolean isDeviceProvisioningConfigApplied();
|
boolean isDeviceProvisioningConfigApplied();
|
||||||
void setDeviceProvisioningConfigApplied();
|
void setDeviceProvisioningConfigApplied();
|
||||||
|
|
||||||
|
void setBackupServiceEnabled(in ComponentName admin, boolean enabled);
|
||||||
|
boolean isBackupServiceEnabled(in ComponentName admin);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -497,9 +497,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
|||||||
new MonitoringCertNotificationTask().execute(userId);
|
new MonitoringCertNotificationTask().execute(userId);
|
||||||
}
|
}
|
||||||
if (Intent.ACTION_USER_ADDED.equals(action)) {
|
if (Intent.ACTION_USER_ADDED.equals(action)) {
|
||||||
disableSecurityLoggingIfNotCompliant();
|
disableDeviceOwnerManagedSingleUserFeaturesIfNeeded();
|
||||||
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
|
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
|
||||||
disableSecurityLoggingIfNotCompliant();
|
disableDeviceOwnerManagedSingleUserFeaturesIfNeeded();
|
||||||
removeUserData(userHandle);
|
removeUserData(userHandle);
|
||||||
} else if (Intent.ACTION_USER_STARTED.equals(action)) {
|
} else if (Intent.ACTION_USER_STARTED.equals(action)) {
|
||||||
synchronized (DevicePolicyManagerService.this) {
|
synchronized (DevicePolicyManagerService.this) {
|
||||||
@@ -1712,7 +1712,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
|||||||
if (mOwners.hasDeviceOwner()) {
|
if (mOwners.hasDeviceOwner()) {
|
||||||
mInjector.systemPropertiesSet(PROPERTY_DEVICE_OWNER_PRESENT, "true");
|
mInjector.systemPropertiesSet(PROPERTY_DEVICE_OWNER_PRESENT, "true");
|
||||||
Slog.i(LOG_TAG, "Set ro.device_owner property to true");
|
Slog.i(LOG_TAG, "Set ro.device_owner property to true");
|
||||||
disableSecurityLoggingIfNotCompliant();
|
disableDeviceOwnerManagedSingleUserFeaturesIfNeeded();
|
||||||
if (mInjector.securityLogGetLoggingEnabledProperty()) {
|
if (mInjector.securityLogGetLoggingEnabledProperty()) {
|
||||||
mSecurityLogMonitor.start();
|
mSecurityLogMonitor.start();
|
||||||
}
|
}
|
||||||
@@ -5930,7 +5930,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
|||||||
mOwners.clearDeviceOwner();
|
mOwners.clearDeviceOwner();
|
||||||
mOwners.writeDeviceOwner();
|
mOwners.writeDeviceOwner();
|
||||||
updateDeviceOwnerLocked();
|
updateDeviceOwnerLocked();
|
||||||
disableSecurityLoggingIfNotCompliant();
|
disableDeviceOwnerManagedSingleUserFeaturesIfNeeded();
|
||||||
try {
|
try {
|
||||||
// Reactivate backup service.
|
// Reactivate backup service.
|
||||||
mInjector.getIBackupManager().setBackupServiceActive(UserHandle.USER_SYSTEM, true);
|
mInjector.getIBackupManager().setBackupServiceActive(UserHandle.USER_SYSTEM, true);
|
||||||
@@ -8904,10 +8904,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void disableSecurityLoggingIfNotCompliant() {
|
private synchronized void disableDeviceOwnerManagedSingleUserFeaturesIfNeeded() {
|
||||||
if (!isDeviceOwnerManagedSingleUserDevice()) {
|
if (!isDeviceOwnerManagedSingleUserDevice()) {
|
||||||
mInjector.securityLogSetLoggingEnabledProperty(false);
|
mInjector.securityLogSetLoggingEnabledProperty(false);
|
||||||
Slog.w(LOG_TAG, "Security logging turned off as it's no longer a single user device.");
|
Slog.w(LOG_TAG, "Security logging turned off as it's no longer a single user device.");
|
||||||
|
setBackupServiceEnabledInternal(false);
|
||||||
|
Slog.w(LOG_TAG, "Backup is off as it's a managed device that has more that one user.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9208,4 +9210,46 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBackupServiceEnabled(ComponentName admin, boolean enabled) {
|
||||||
|
Preconditions.checkNotNull(admin);
|
||||||
|
if (!mHasFeature) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ensureDeviceOwnerManagingSingleUser(admin);
|
||||||
|
setBackupServiceEnabledInternal(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setBackupServiceEnabledInternal(boolean enabled) {
|
||||||
|
long ident = mInjector.binderClearCallingIdentity();
|
||||||
|
try {
|
||||||
|
IBackupManager ibm = mInjector.getIBackupManager();
|
||||||
|
if (ibm != null) {
|
||||||
|
ibm.setBackupServiceActive(UserHandle.USER_SYSTEM, enabled);
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Failed " + (enabled ? "" : "de") + "activating backup service.", e);
|
||||||
|
} finally {
|
||||||
|
mInjector.binderRestoreCallingIdentity(ident);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBackupServiceEnabled(ComponentName admin) {
|
||||||
|
Preconditions.checkNotNull(admin);
|
||||||
|
if (!mHasFeature) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
synchronized (this) {
|
||||||
|
getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
|
||||||
|
try {
|
||||||
|
IBackupManager ibm = mInjector.getIBackupManager();
|
||||||
|
return ibm != null && ibm.isBackupServiceActive(UserHandle.USER_SYSTEM);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw new IllegalStateException("Failed requesting backup service state.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user