Expose MANAGED_PROVISIONING_DPC_DOWNLOADED via DevicePolicyManager

Expose Settings.Secure.MANAGED_PROVISIONING_DPC_DOWNLOADED by adding
getter & setter methods in DevicePolicyManager.

Bug: 212679631

Test: android.devicepolicy.cts.DevicePolicyManagerTest
Change-Id: I9c8c69ec494fcbf82965308b76f6e27e5184ba4d
This commit is contained in:
Elis Elliott
2022-01-18 16:46:51 +00:00
parent 4994547596
commit d603ad7916
4 changed files with 70 additions and 0 deletions

View File

@@ -1071,6 +1071,7 @@ package android.app.admin {
method public boolean isDeviceManaged();
method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isDeviceProvisioned();
method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean isDeviceProvisioningConfigApplied();
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean isDpcDownloaded();
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS}) public boolean isManagedKiosk();
method public boolean isSecondaryLockscreenEnabled(@NonNull android.os.UserHandle);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS}) public boolean isUnattendedManagedKiosk();
@@ -1083,6 +1084,7 @@ package android.app.admin {
method @RequiresPermission(android.Manifest.permission.SEND_LOST_MODE_LOCATION_UPDATES) public void sendLostModeLocationUpdate(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
method @Deprecated @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) public boolean setActiveProfileOwner(@NonNull android.content.ComponentName, String) throws java.lang.IllegalArgumentException;
method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public void setDeviceProvisioningConfigApplied();
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void setDpcDownloaded(boolean);
method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_MANAGEMENT_RESOURCES) public void setDrawables(@NonNull java.util.Set<android.app.admin.DevicePolicyDrawableResource>);
method @Deprecated @RequiresPermission(value=android.Manifest.permission.GRANT_PROFILE_OWNER_DEVICE_IDS_ACCESS, conditional=true) public void setProfileOwnerCanAccessDeviceIds(@NonNull android.content.ComponentName);
method public void setSecondaryLockscreenEnabled(@NonNull android.content.ComponentName, boolean);

View File

@@ -15334,4 +15334,45 @@ public class DevicePolicyManager {
}
return ParcelableResource.loadDefaultString(defaultStringLoader);
}
/**
* Returns a boolean for whether the DPC has been downloaded during provisioning.
*
* <p>If true is returned, then any attempts to begin setup again should result in factory reset
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
public boolean isDpcDownloaded() {
throwIfParentInstance("isDpcDownloaded");
if (mService != null) {
try {
return mService.isDpcDownloaded();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
return false;
}
/**
* Use to indicate that the DPC has or has not been downloaded during provisioning.
*
* @param downloaded {@code true} if the dpc has been downloaded during provisioning. false otherwise.
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
public void setDpcDownloaded(boolean downloaded) {
throwIfParentInstance("setDpcDownloaded");
if (mService != null) {
try {
mService.setDpcDownloaded(downloaded);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
}

View File

@@ -554,6 +554,9 @@ interface IDevicePolicyManager {
void resetDrawables(in String[] drawableIds);
ParcelableResource getDrawable(String drawableId, String drawableStyle, String drawableSource);
boolean isDpcDownloaded();
void setDpcDownloaded(boolean downloaded);
void setStrings(in List<DevicePolicyStringResource> strings);
void resetStrings(in String[] stringIds);
ParcelableResource getString(String stringId);

View File

@@ -134,6 +134,7 @@ import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPR
import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_1;
import static android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK;
import static android.provider.Settings.Global.PRIVATE_DNS_SPECIFIER;
import static android.provider.Settings.Secure.MANAGED_PROVISIONING_DPC_DOWNLOADED;
import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
import static android.provider.Telephony.Carriers.DPC_URI;
import static android.provider.Telephony.Carriers.ENFORCE_KEY;
@@ -222,6 +223,7 @@ import android.compat.annotation.EnabledSince;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.IIntentReceiver;
@@ -18656,4 +18658,26 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
mContext.sendBroadcastAsUser(intent, user);
}
}
public boolean isDpcDownloaded() {
Preconditions.checkCallAuthorization(hasCallingOrSelfPermission(
android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS));
ContentResolver cr = mContext.getContentResolver();
return mInjector.binderWithCleanCallingIdentity(() -> Settings.Secure.getIntForUser(
cr, MANAGED_PROVISIONING_DPC_DOWNLOADED,
/* def= */ 0, /* userHandle= */ cr.getUserId())
== 1);
}
public void setDpcDownloaded(boolean downloaded) {
Preconditions.checkCallAuthorization(hasCallingOrSelfPermission(
android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS));
int setTo = downloaded ? 1 : 0;
mInjector.binderWithCleanCallingIdentity(() -> Settings.Secure.putInt(
mContext.getContentResolver(), MANAGED_PROVISIONING_DPC_DOWNLOADED, setTo));
}
}