Search in sources :

Example 86 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.

the class TrustManagerService method refreshAgentList.

void refreshAgentList(int userIdOrAll) {
    if (DEBUG)
        Slog.d(TAG, "refreshAgentList(" + userIdOrAll + ")");
    if (!mTrustAgentsCanRun) {
        return;
    }
    if (userIdOrAll != UserHandle.USER_ALL && userIdOrAll < UserHandle.USER_SYSTEM) {
        Log.e(TAG, "refreshAgentList(userId=" + userIdOrAll + "): Invalid user handle," + " must be USER_ALL or a specific user.", new Throwable("here"));
        userIdOrAll = UserHandle.USER_ALL;
    }
    PackageManager pm = mContext.getPackageManager();
    List<UserInfo> userInfos;
    if (userIdOrAll == UserHandle.USER_ALL) {
        userInfos = mUserManager.getUsers(true);
    } else {
        userInfos = new ArrayList<>();
        userInfos.add(mUserManager.getUserInfo(userIdOrAll));
    }
    LockPatternUtils lockPatternUtils = mLockPatternUtils;
    ArraySet<AgentInfo> obsoleteAgents = new ArraySet<>();
    obsoleteAgents.addAll(mActiveAgents);
    for (UserInfo userInfo : userInfos) {
        if (userInfo == null || userInfo.partial || !userInfo.isEnabled() || userInfo.guestToRemove)
            continue;
        if (!userInfo.supportsSwitchToByUser())
            continue;
        if (!StorageManager.isUserKeyUnlocked(userInfo.id))
            continue;
        if (!mActivityManager.isUserRunning(userInfo.id))
            continue;
        if (!lockPatternUtils.isSecure(userInfo.id))
            continue;
        if (!mStrongAuthTracker.canAgentsRunForUser(userInfo.id))
            continue;
        DevicePolicyManager dpm = lockPatternUtils.getDevicePolicyManager();
        int disabledFeatures = dpm.getKeyguardDisabledFeatures(null, userInfo.id);
        final boolean disableTrustAgents = (disabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS) != 0;
        List<ComponentName> enabledAgents = lockPatternUtils.getEnabledTrustAgents(userInfo.id);
        if (enabledAgents == null) {
            continue;
        }
        List<ResolveInfo> resolveInfos = resolveAllowedTrustAgents(pm, userInfo.id);
        for (ResolveInfo resolveInfo : resolveInfos) {
            ComponentName name = getComponentName(resolveInfo);
            if (!enabledAgents.contains(name))
                continue;
            if (disableTrustAgents) {
                List<PersistableBundle> config = dpm.getTrustAgentConfiguration(null, /* admin */
                name, userInfo.id);
                // Disable agent if no features are enabled.
                if (config == null || config.isEmpty())
                    continue;
            }
            AgentInfo agentInfo = new AgentInfo();
            agentInfo.component = name;
            agentInfo.userId = userInfo.id;
            if (!mActiveAgents.contains(agentInfo)) {
                agentInfo.label = resolveInfo.loadLabel(pm);
                agentInfo.icon = resolveInfo.loadIcon(pm);
                agentInfo.settings = getSettingsComponentName(pm, resolveInfo);
                agentInfo.agent = new TrustAgentWrapper(mContext, this, new Intent().setComponent(name), userInfo.getUserHandle());
                mActiveAgents.add(agentInfo);
            } else {
                obsoleteAgents.remove(agentInfo);
            }
        }
    }
    boolean trustMayHaveChanged = false;
    for (int i = 0; i < obsoleteAgents.size(); i++) {
        AgentInfo info = obsoleteAgents.valueAt(i);
        if (userIdOrAll == UserHandle.USER_ALL || userIdOrAll == info.userId) {
            if (info.agent.isManagingTrust()) {
                trustMayHaveChanged = true;
            }
            info.agent.destroy();
            mActiveAgents.remove(info);
        }
    }
    if (trustMayHaveChanged) {
        if (userIdOrAll == UserHandle.USER_ALL) {
            updateTrustAll();
        } else {
            updateTrust(userIdOrAll, 0);
        }
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ArraySet(android.util.ArraySet) LockPatternUtils(com.android.internal.widget.LockPatternUtils) UserInfo(android.content.pm.UserInfo) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) PersistableBundle(android.os.PersistableBundle) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 87 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.

the class WallpaperManagerService method isSetWallpaperAllowed.

@Override
public boolean isSetWallpaperAllowed(String callingPackage) {
    final PackageManager pm = mContext.getPackageManager();
    String[] uidPackages = pm.getPackagesForUid(Binder.getCallingUid());
    boolean uidMatchPackage = Arrays.asList(uidPackages).contains(callingPackage);
    if (!uidMatchPackage) {
        // callingPackage was faked.
        return false;
    }
    final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
    if (dpm.isDeviceOwnerApp(callingPackage) || dpm.isProfileOwnerApp(callingPackage)) {
        return true;
    }
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    return !um.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER);
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) UserManager(android.os.UserManager)

Example 88 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.

the class ContactsInternal method maybeStartManagedQuickContact.

/**
     * If the URI in {@code intent} is of a corp contact, launch quick contact on the managed
     * profile.
     *
     * @return the URI in {@code intent} is of a corp contact thus launched on the managed profile.
     */
private static boolean maybeStartManagedQuickContact(Context context, Intent originalIntent) {
    final Uri uri = originalIntent.getData();
    // Decompose into an ID and a lookup key.
    final List<String> pathSegments = uri.getPathSegments();
    final boolean isContactIdIgnored = pathSegments.size() < 4;
    final long contactId = isContactIdIgnored ? //contact id will be ignored
    ContactsContract.Contacts.ENTERPRISE_CONTACT_ID_BASE : ContentUris.parseId(uri);
    final String lookupKey = pathSegments.get(2);
    final String directoryIdStr = uri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY);
    final long directoryId = (directoryIdStr == null) ? ContactsContract.Directory.ENTERPRISE_DIRECTORY_ID_BASE : Long.parseLong(directoryIdStr);
    // See if it has a corp lookupkey.
    if (TextUtils.isEmpty(lookupKey) || !lookupKey.startsWith(ContactsContract.Contacts.ENTERPRISE_CONTACT_LOOKUP_PREFIX)) {
        // It's not a corp lookup key.
        return false;
    }
    if (!ContactsContract.Contacts.isEnterpriseContactId(contactId)) {
        throw new IllegalArgumentException("Invalid enterprise contact id: " + contactId);
    }
    if (!ContactsContract.Directory.isEnterpriseDirectoryId(directoryId)) {
        throw new IllegalArgumentException("Invalid enterprise directory id: " + directoryId);
    }
    // Launch Quick Contact on the managed profile, if the policy allows.
    final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
    final String actualLookupKey = lookupKey.substring(ContactsContract.Contacts.ENTERPRISE_CONTACT_LOOKUP_PREFIX.length());
    final long actualContactId = (contactId - ContactsContract.Contacts.ENTERPRISE_CONTACT_ID_BASE);
    final long actualDirectoryId = (directoryId - ContactsContract.Directory.ENTERPRISE_DIRECTORY_ID_BASE);
    dpm.startManagedQuickContact(actualLookupKey, actualContactId, isContactIdIgnored, actualDirectoryId, originalIntent);
    return true;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) Uri(android.net.Uri)

Example 89 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by AOSPA.

the class ContactsInternal method maybeStartManagedQuickContact.

/**
     * If the URI in {@code intent} is of a corp contact, launch quick contact on the managed
     * profile.
     *
     * @return the URI in {@code intent} is of a corp contact thus launched on the managed profile.
     */
private static boolean maybeStartManagedQuickContact(Context context, Intent originalIntent) {
    final Uri uri = originalIntent.getData();
    // Decompose into an ID and a lookup key.
    final List<String> pathSegments = uri.getPathSegments();
    final boolean isContactIdIgnored = pathSegments.size() < 4;
    final long contactId = isContactIdIgnored ? //contact id will be ignored
    ContactsContract.Contacts.ENTERPRISE_CONTACT_ID_BASE : ContentUris.parseId(uri);
    final String lookupKey = pathSegments.get(2);
    final String directoryIdStr = uri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY);
    final long directoryId = (directoryIdStr == null) ? ContactsContract.Directory.ENTERPRISE_DIRECTORY_ID_BASE : Long.parseLong(directoryIdStr);
    // See if it has a corp lookupkey.
    if (TextUtils.isEmpty(lookupKey) || !lookupKey.startsWith(ContactsContract.Contacts.ENTERPRISE_CONTACT_LOOKUP_PREFIX)) {
        // It's not a corp lookup key.
        return false;
    }
    if (!ContactsContract.Contacts.isEnterpriseContactId(contactId)) {
        throw new IllegalArgumentException("Invalid enterprise contact id: " + contactId);
    }
    if (!ContactsContract.Directory.isEnterpriseDirectoryId(directoryId)) {
        throw new IllegalArgumentException("Invalid enterprise directory id: " + directoryId);
    }
    // Launch Quick Contact on the managed profile, if the policy allows.
    final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
    final String actualLookupKey = lookupKey.substring(ContactsContract.Contacts.ENTERPRISE_CONTACT_LOOKUP_PREFIX.length());
    final long actualContactId = (contactId - ContactsContract.Contacts.ENTERPRISE_CONTACT_ID_BASE);
    final long actualDirectoryId = (directoryId - ContactsContract.Directory.ENTERPRISE_DIRECTORY_ID_BASE);
    dpm.startManagedQuickContact(actualLookupKey, actualContactId, isContactIdIgnored, actualDirectoryId, originalIntent);
    return true;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) Uri(android.net.Uri)

Example 90 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project bitcoin-wallet by bitcoin-wallet.

the class ReportIssueDialogFragment method appendDeviceInfo.

private static void appendDeviceInfo(final Appendable report, final Context context) throws IOException {
    final Resources res = context.getResources();
    final android.content.res.Configuration config = res.getConfiguration();
    final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    report.append("Device Model: " + Build.MODEL + "\n");
    report.append("Android Version: " + Build.VERSION.RELEASE + "\n");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        report.append("Android security patch level: ").append(Build.VERSION.SECURITY_PATCH).append("\n");
    report.append("ABIs: ").append(Joiner.on(", ").skipNulls().join(Strings.emptyToNull(Build.CPU_ABI), Strings.emptyToNull(Build.CPU_ABI2))).append("\n");
    report.append("Board: " + Build.BOARD + "\n");
    report.append("Brand: " + Build.BRAND + "\n");
    report.append("Device: " + Build.DEVICE + "\n");
    report.append("Display: " + Build.DISPLAY + "\n");
    report.append("Finger Print: " + Build.FINGERPRINT + "\n");
    report.append("Host: " + Build.HOST + "\n");
    report.append("ID: " + Build.ID + "\n");
    report.append("Product: " + Build.PRODUCT + "\n");
    report.append("Tags: " + Build.TAGS + "\n");
    report.append("Time: " + Build.TIME + "\n");
    report.append("Type: " + Build.TYPE + "\n");
    report.append("User: " + Build.USER + "\n");
    report.append("Configuration: " + config + "\n");
    report.append("Screen Layout: size " + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK) + " long " + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_LONG_MASK) + "\n");
    report.append("Display Metrics: " + res.getDisplayMetrics() + "\n");
    report.append("Memory Class: " + activityManager.getMemoryClass() + "/" + activityManager.getLargeMemoryClass() + (activityManager.isLowRamDevice() ? " (low RAM device)" : "") + "\n");
    report.append("Storage Encryption Status: " + devicePolicyManager.getStorageEncryptionStatus() + "\n");
    report.append("Bluetooth MAC: " + bluetoothMac() + "\n");
    report.append("Runtime: ").append(System.getProperty("java.vm.name")).append(" ").append(System.getProperty("java.vm.version")).append("\n");
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) Resources(android.content.res.Resources) ActivityManager(android.app.ActivityManager)

Aggregations

DevicePolicyManager (android.app.admin.DevicePolicyManager)159 ComponentName (android.content.ComponentName)45 UserManager (android.os.UserManager)29 UserInfo (android.content.pm.UserInfo)25 RemoteException (android.os.RemoteException)24 LockPatternUtils (com.android.internal.widget.LockPatternUtils)19 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)14 PersistableBundle (android.os.PersistableBundle)8 PendingIntent (android.app.PendingIntent)6 IBinder (android.os.IBinder)6 UserHandle (android.os.UserHandle)6 IPackageManager (android.content.pm.IPackageManager)5 Uri (android.net.Uri)5 VrManagerInternal (com.android.server.vr.VrManagerInternal)5 ResolveInfo (android.content.pm.ResolveInfo)4 Point (android.graphics.Point)4 Binder (android.os.Binder)4 KeyStore (android.security.KeyStore)4 ArraySet (android.util.ArraySet)4