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

Commit fac4ddbd authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Work around buggy DMAgent.

They're targeting new API level, but they aren't handling the new
constants.

Bug: 27785116
Change-Id: I8391294d963c86af1f948b91c7d1de6b7f44f66a
parent c9b329ed
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -4868,10 +4868,24 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        // we start using it for different purposes.
        ensureCallerPackage(callerPackage);

        final ApplicationInfo ai;
        try {
            ai = mContext.getPackageManager().getApplicationInfo(callerPackage, 0);
        } catch (NameNotFoundException e) {
            throw new SecurityException(e);
        }

        boolean legacyApp = false;
        if (ai.targetSdkVersion <= Build.VERSION_CODES.M) {
            legacyApp = true;
        } else if ("com.google.android.apps.enterprise.dmagent".equals(ai.packageName)
                && ai.versionCode == 697) {
            // TODO: remove this once a new prebuilt is dropped
            legacyApp = true;
        }

        final int rawStatus = getEncryptionStatus();
        if ((rawStatus == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER)
                && (callerPackage != null)
                && (getTargetSdk(callerPackage, userHandle) <= VERSION_CODES.M)) {
        if ((rawStatus == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER) && legacyApp) {
            return DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE;
        }
        return rawStatus;