Merge "API to get the device manager role holder package name"

This commit is contained in:
Antoan Angelov
2022-02-09 20:15:11 +00:00
committed by Android (Google) Code Review
2 changed files with 37 additions and 0 deletions

View File

@@ -7362,6 +7362,7 @@ package android.app.admin {
method public int getCurrentFailedPasswordAttempts();
method @Nullable public java.util.List<java.lang.String> getDelegatePackages(@NonNull android.content.ComponentName, @NonNull String);
method @NonNull public java.util.List<java.lang.String> getDelegatedScopes(@Nullable android.content.ComponentName, @NonNull String);
method @Nullable public String getDeviceManagerRoleHolderPackageName();
method public CharSequence getDeviceOwnerLockScreenInfo();
method @Nullable public android.graphics.drawable.Drawable getDrawable(@NonNull String, @NonNull String, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);
method @Nullable public android.graphics.drawable.Drawable getDrawable(@NonNull String, @NonNull String, @NonNull String, @NonNull java.util.concurrent.Callable<android.graphics.drawable.Drawable>);

View File

@@ -15635,4 +15635,40 @@ public class DevicePolicyManager {
}
}
}
/**
* Returns the package name of the device manager role holder.
*
* <p>If the device manager role holder is not configured for this device, returns {@code null}.
*/
@Nullable
public String getDeviceManagerRoleHolderPackageName() {
String deviceManagerConfig =
mContext.getString(com.android.internal.R.string.config_deviceManager);
return extractPackageNameFromDeviceManagerConfig(deviceManagerConfig);
}
/**
* Retrieves the package name for a given {@code deviceManagerConfig}.
*
* <p>Valid configs look like:
* <ul>
* <li>{@code com.package.name}</li>
* <li>{@code com.package.name:<SHA256 checksum>}</li>
* </ul>
*
* <p>If the supplied {@code deviceManagerConfig} is {@code null} or empty, returns
* {@code null}.
*/
@Nullable
private String extractPackageNameFromDeviceManagerConfig(
@Nullable String deviceManagerConfig) {
if (TextUtils.isEmpty(deviceManagerConfig)) {
return null;
}
if (deviceManagerConfig.contains(":")) {
return deviceManagerConfig.split(":")[0];
}
return deviceManagerConfig;
}
}