Search in sources :

Example 46 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class AppsQueryHelper method queryApps.

/**
     * Return a List of all packages that satisfy a specified criteria.
     * @param flags search flags. Use any combination of {@link #GET_NON_LAUNCHABLE_APPS},
     * {@link #GET_APPS_WITH_INTERACT_ACROSS_USERS_PERM} or {@link #GET_IMES}.
     * @param systemAppsOnly if true, only system apps will be returned
     * @param user user, whose apps are queried
     */
public List<String> queryApps(int flags, boolean systemAppsOnly, UserHandle user) {
    boolean nonLaunchableApps = (flags & GET_NON_LAUNCHABLE_APPS) > 0;
    boolean interactAcrossUsers = (flags & GET_APPS_WITH_INTERACT_ACROSS_USERS_PERM) > 0;
    boolean imes = (flags & GET_IMES) > 0;
    boolean requiredForSystemUser = (flags & GET_REQUIRED_FOR_SYSTEM_USER) > 0;
    if (mAllApps == null) {
        mAllApps = getAllApps(user.getIdentifier());
    }
    List<String> result = new ArrayList<>();
    if (flags == 0) {
        final int allAppsSize = mAllApps.size();
        for (int i = 0; i < allAppsSize; i++) {
            final ApplicationInfo appInfo = mAllApps.get(i);
            if (systemAppsOnly && !appInfo.isSystemApp()) {
                continue;
            }
            result.add(appInfo.packageName);
        }
        return result;
    }
    if (nonLaunchableApps) {
        Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
        final List<ResolveInfo> resolveInfos = queryIntentActivitiesAsUser(intent, user.getIdentifier());
        ArraySet<String> appsWithLaunchers = new ArraySet<>();
        final int resolveInfosSize = resolveInfos.size();
        for (int i = 0; i < resolveInfosSize; i++) {
            appsWithLaunchers.add(resolveInfos.get(i).activityInfo.packageName);
        }
        final int allAppsSize = mAllApps.size();
        for (int i = 0; i < allAppsSize; i++) {
            final ApplicationInfo appInfo = mAllApps.get(i);
            if (systemAppsOnly && !appInfo.isSystemApp()) {
                continue;
            }
            final String packageName = appInfo.packageName;
            if (!appsWithLaunchers.contains(packageName)) {
                result.add(packageName);
            }
        }
    }
    if (interactAcrossUsers) {
        final List<PackageInfo> packagesHoldingPermissions = getPackagesHoldingPermission(Manifest.permission.INTERACT_ACROSS_USERS, user.getIdentifier());
        final int packagesHoldingPermissionsSize = packagesHoldingPermissions.size();
        for (int i = 0; i < packagesHoldingPermissionsSize; i++) {
            PackageInfo packageInfo = packagesHoldingPermissions.get(i);
            if (systemAppsOnly && !packageInfo.applicationInfo.isSystemApp()) {
                continue;
            }
            if (!result.contains(packageInfo.packageName)) {
                result.add(packageInfo.packageName);
            }
        }
    }
    if (imes) {
        final List<ResolveInfo> resolveInfos = queryIntentServicesAsUser(new Intent(InputMethod.SERVICE_INTERFACE), user.getIdentifier());
        final int resolveInfosSize = resolveInfos.size();
        for (int i = 0; i < resolveInfosSize; i++) {
            ServiceInfo serviceInfo = resolveInfos.get(i).serviceInfo;
            if (systemAppsOnly && !serviceInfo.applicationInfo.isSystemApp()) {
                continue;
            }
            if (!result.contains(serviceInfo.packageName)) {
                result.add(serviceInfo.packageName);
            }
        }
    }
    if (requiredForSystemUser) {
        final int allAppsSize = mAllApps.size();
        for (int i = 0; i < allAppsSize; i++) {
            final ApplicationInfo appInfo = mAllApps.get(i);
            if (systemAppsOnly && !appInfo.isSystemApp()) {
                continue;
            }
            if (appInfo.isRequiredForSystemUser()) {
                result.add(appInfo.packageName);
            }
        }
    }
    return result;
}
Also used : ArraySet(android.util.ArraySet) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 47 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class ResourceCertificateSource method ensureInitialized.

private void ensureInitialized() {
    synchronized (mLock) {
        if (mCertificates != null) {
            return;
        }
        Set<X509Certificate> certificates = new ArraySet<X509Certificate>();
        Collection<? extends Certificate> certs;
        InputStream in = null;
        try {
            CertificateFactory factory = CertificateFactory.getInstance("X.509");
            in = mContext.getResources().openRawResource(mResourceId);
            certs = factory.generateCertificates(in);
        } catch (CertificateException e) {
            throw new RuntimeException("Failed to load trust anchors from id " + mResourceId, e);
        } finally {
            IoUtils.closeQuietly(in);
        }
        TrustedCertificateIndex indexLocal = new TrustedCertificateIndex();
        for (Certificate cert : certs) {
            certificates.add((X509Certificate) cert);
            indexLocal.index((X509Certificate) cert);
        }
        mCertificates = certificates;
        mIndex = indexLocal;
        mContext = null;
    }
}
Also used : ArraySet(android.util.ArraySet) InputStream(java.io.InputStream) TrustedCertificateIndex(com.android.org.conscrypt.TrustedCertificateIndex) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 48 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class XmlConfigSource method parsePinSet.

private PinSet parsePinSet(XmlResourceParser parser) throws IOException, XmlPullParserException, ParserException {
    String expirationDate = parser.getAttributeValue(null, "expiration");
    long expirationTimestampMilis = Long.MAX_VALUE;
    if (expirationDate != null) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            sdf.setLenient(false);
            Date date = sdf.parse(expirationDate);
            if (date == null) {
                throw new ParserException(parser, "Invalid expiration date in pin-set");
            }
            expirationTimestampMilis = date.getTime();
        } catch (ParseException e) {
            throw new ParserException(parser, "Invalid expiration date in pin-set", e);
        }
    }
    int outerDepth = parser.getDepth();
    Set<Pin> pins = new ArraySet<>();
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        String tagName = parser.getName();
        if (tagName.equals("pin")) {
            pins.add(parsePin(parser));
        } else {
            XmlUtils.skipCurrentTag(parser);
        }
    }
    return new PinSet(pins, expirationTimestampMilis);
}
Also used : XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ArraySet(android.util.ArraySet) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 49 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class NotificationController method updateNotifications.

/**
     * Update notifications for the given print jobs, remove all other notifications.
     *
     * @param printJobs The print job that we want to create notifications for.
     */
private void updateNotifications(List<PrintJobInfo> printJobs) {
    ArraySet<PrintJobId> removedPrintJobs = new ArraySet<>(mNotifications);
    final int numPrintJobs = printJobs.size();
    // Create summary notification
    if (numPrintJobs > 1) {
        createStackedNotification(printJobs);
    } else {
        mNotificationManager.cancel(PRINT_JOB_NOTIFICATION_SUMMARY, 0);
    }
    // Create per print job notification
    for (int i = 0; i < numPrintJobs; i++) {
        PrintJobInfo printJob = printJobs.get(i);
        PrintJobId printJobId = printJob.getId();
        removedPrintJobs.remove(printJobId);
        mNotifications.add(printJobId);
        createSimpleNotification(printJob);
    }
    // Remove notifications for print jobs that do not exist anymore
    final int numRemovedPrintJobs = removedPrintJobs.size();
    for (int i = 0; i < numRemovedPrintJobs; i++) {
        PrintJobId removedPrintJob = removedPrintJobs.valueAt(i);
        mNotificationManager.cancel(removedPrintJob.flattenToString(), 0);
        mNotifications.remove(removedPrintJob);
    }
}
Also used : ArraySet(android.util.ArraySet) PrintJobId(android.print.PrintJobId) PrintJobInfo(android.print.PrintJobInfo)

Example 50 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class CastControllerImpl method getCastDevices.

@Override
public Set<CastDevice> getCastDevices() {
    final ArraySet<CastDevice> devices = new ArraySet<CastDevice>();
    synchronized (mProjectionLock) {
        if (mProjection != null) {
            final CastDevice device = new CastDevice();
            device.id = mProjection.getPackageName();
            device.name = getAppName(mProjection.getPackageName());
            device.description = mContext.getString(R.string.quick_settings_casting);
            device.state = CastDevice.STATE_CONNECTED;
            device.tag = mProjection;
            devices.add(device);
            return devices;
        }
    }
    synchronized (mRoutes) {
        for (RouteInfo route : mRoutes.values()) {
            final CastDevice device = new CastDevice();
            device.id = route.getTag().toString();
            final CharSequence name = route.getName(mContext);
            device.name = name != null ? name.toString() : null;
            final CharSequence description = route.getDescription();
            device.description = description != null ? description.toString() : null;
            device.state = route.isConnecting() ? CastDevice.STATE_CONNECTING : route.isSelected() ? CastDevice.STATE_CONNECTED : CastDevice.STATE_DISCONNECTED;
            device.tag = route;
            devices.add(device);
        }
    }
    return devices;
}
Also used : ArraySet(android.util.ArraySet) RouteInfo(android.media.MediaRouter.RouteInfo)

Aggregations

ArraySet (android.util.ArraySet)521 PublicKey (java.security.PublicKey)94 ArrayList (java.util.ArrayList)87 ComponentName (android.content.ComponentName)82 ArrayMap (android.util.ArrayMap)73 Pair (android.util.Pair)47 RemoteException (android.os.RemoteException)43 ResolveInfo (android.content.pm.ResolveInfo)39 Intent (android.content.Intent)38 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)35 File (java.io.File)33 SSLContext (javax.net.ssl.SSLContext)32 IOException (java.io.IOException)31 PackageManager (android.content.pm.PackageManager)29 UserInfo (android.content.pm.UserInfo)28 ApplicationInfo (android.content.pm.ApplicationInfo)24 Point (android.graphics.Point)24 X509Certificate (java.security.cert.X509Certificate)20 PackageInfo (android.content.pm.PackageInfo)19 Test (org.junit.Test)19