Search in sources :

Example 16 with DeviceAdminInfo

use of android.app.admin.DeviceAdminInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceAdminSettings method addDeviceAdminBroadcastReceiversForProfile.

/**
     * Add a profile's device admins that are receivers of
     * {@code DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED} to the internal collection if they
     * haven't been added yet.
     *
     * @param alreadyAddedComponents the set of active admin component names. Receivers of
     *            {@code DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED} whose component is in this
     *            set are not added to the internal collection again.
     * @param profileId the identifier of the profile
     */
private void addDeviceAdminBroadcastReceiversForProfile(Collection<ComponentName> alreadyAddedComponents, final int profileId) {
    final PackageManager pm = getActivity().getPackageManager();
    List<ResolveInfo> enabledForProfile = pm.queryBroadcastReceiversAsUser(new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED), PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, profileId);
    if (enabledForProfile == null) {
        enabledForProfile = Collections.emptyList();
    }
    final int n = enabledForProfile.size();
    for (int i = 0; i < n; ++i) {
        ResolveInfo resolveInfo = enabledForProfile.get(i);
        ComponentName riComponentName = new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
        if (alreadyAddedComponents == null || !alreadyAddedComponents.contains(riComponentName)) {
            DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(resolveInfo.activityInfo);
            // add only visible ones (note: active admins are added regardless of visibility)
            if (deviceAdminInfo != null && deviceAdminInfo.isVisible()) {
                if (!deviceAdminInfo.getActivityInfo().applicationInfo.isInternal()) {
                    continue;
                }
                DeviceAdminListItem item = new DeviceAdminListItem();
                item.info = deviceAdminInfo;
                item.name = deviceAdminInfo.loadLabel(pm).toString();
                // Active ones already added.
                item.active = false;
                mAdmins.add(item);
            }
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) DeviceAdminInfo(android.app.admin.DeviceAdminInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Aggregations

DeviceAdminInfo (android.app.admin.DeviceAdminInfo)16 IOException (java.io.IOException)9 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)9 ParcelableString (com.android.internal.util.ParcelableString)6 ActivityInfo (android.content.pm.ActivityInfo)5 RemoteException (android.os.RemoteException)5 Intent (android.content.Intent)4 JournaledFile (com.android.internal.util.JournaledFile)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 XmlPullParser (org.xmlpull.v1.XmlPullParser)4 ComponentName (android.content.ComponentName)3 PackageManager (android.content.pm.PackageManager)3 ResolveInfo (android.content.pm.ResolveInfo)3 IPackageManager (android.content.pm.IPackageManager)2 Activity (android.app.Activity)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 PackageInfo (android.content.pm.PackageInfo)1