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

Commit 30c33e09 authored by Andrei Stingaceanu's avatar Andrei Stingaceanu Committed by Android (Google) Code Review
Browse files

Merge "RestrictedLockUtils - introduce check for suspended apps"

parents a74cce60 44af4828
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.UserInfo;
import android.graphics.Color;
@@ -226,6 +227,26 @@ public class RestrictedLockUtils {
        return null;
    }

    /**
     * Check if an application is suspended.
     *
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} if the application is not suspended.
     */
    public static EnforcedAdmin checkIfApplicationIsSuspended(Context context, String packageName,
            int userId) {
        IPackageManager ipm = AppGlobals.getPackageManager();
        try {
            ApplicationInfo ai = ipm.getApplicationInfo(packageName, 0, userId);
            if (ai != null && ((ai.flags & ApplicationInfo.FLAG_SUSPENDED) != 0)) {
                return getProfileOrDeviceOwnerOnCallingUser(context);
            }
        } catch (RemoteException e) {
            // Nothing to do
        }
        return null;
    }

    /**
     * Check if account management for a specific type of account is disabled by admin.
     * Only a profile or device owner can disable account management. So, we check if account