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

Commit 5ed5e86c authored by arangelov's avatar arangelov
Browse files

API to get the device manager role holder package name

Test: atest cts/DevicePolicyManagerTest.java
Fixes: 218515670
Change-Id: Ia4f92d422334cf6069fe87008416f73d06ab80d0
parent aa77a5d0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7334,6 +7334,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>);
+36 −0
Original line number Diff line number Diff line
@@ -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;
    }
}