Java Code Examples for android.util.ArraySet#contains()

The following examples show how to use android.util.ArraySet#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskSnapshotPersister.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
void write() {
    final ArraySet<Integer> newPersistedTaskIds;
    synchronized (mLock) {
        newPersistedTaskIds = new ArraySet<>(mPersistedTaskIdsSinceLastRemoveObsolete);
    }
    for (int userId : mRunningUserIds) {
        final File dir = getDirectory(userId);
        final String[] files = dir.list();
        if (files == null) {
            continue;
        }
        for (String file : files) {
            final int taskId = getTaskId(file);
            if (!mPersistentTaskIds.contains(taskId)
                    && !newPersistedTaskIds.contains(taskId)) {
                new File(dir, file).delete();
            }
        }
    }
}
 
Example 2
Source File: ActiveServices.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void updateServiceConnectionActivitiesLocked(ProcessRecord clientProc) {
    ArraySet<ProcessRecord> updatedProcesses = null;
    for (int i = 0; i < clientProc.connections.size(); i++) {
        final ConnectionRecord conn = clientProc.connections.valueAt(i);
        final ProcessRecord proc = conn.binding.service.app;
        if (proc == null || proc == clientProc) {
            continue;
        } else if (updatedProcesses == null) {
            updatedProcesses = new ArraySet<>();
        } else if (updatedProcesses.contains(proc)) {
            continue;
        }
        updatedProcesses.add(proc);
        updateServiceClientActivitiesLocked(proc, null, false);
    }
}
 
Example 3
Source File: PermissionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Determines whether a package is whitelisted for a particular privapp permission.
 *
 * <p>Does NOT check whether the package is a privapp, just whether it's whitelisted.
 *
 * <p>This handles parent/child apps.
 */
private boolean hasPrivappWhitelistEntry(String perm, PackageParser.Package pkg) {
    ArraySet<String> wlPermissions = null;
    if (pkg.isVendor()) {
        wlPermissions =
                SystemConfig.getInstance().getVendorPrivAppPermissions(pkg.packageName);
    } else if (pkg.isProduct()) {
        wlPermissions =
                SystemConfig.getInstance().getProductPrivAppPermissions(pkg.packageName);
    } else {
        wlPermissions = SystemConfig.getInstance().getPrivAppPermissions(pkg.packageName);
    }
    // Let's check if this package is whitelisted...
    boolean whitelisted = wlPermissions != null && wlPermissions.contains(perm);
    // If it's not, we'll also tail-recurse to the parent.
    return whitelisted ||
            pkg.parentPackage != null && hasPrivappWhitelistEntry(perm, pkg.parentPackage);
}
 
Example 4
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Remove dangling bitmap files for a package.
 *
 * Note this method must be called with the lock held after calling
 * {@link ShortcutBitmapSaver#waitForAllSavesLocked()} to make sure there's no pending bitmap
 * saves are going on.
 */
private void cleanupDanglingBitmapFilesLocked(@UserIdInt int userId, @NonNull ShortcutUser user,
        @NonNull String packageName, @NonNull File path) {
    final ArraySet<String> usedFiles =
            user.getPackageShortcuts(packageName).getUsedBitmapFiles();

    for (File child : path.listFiles()) {
        if (!child.isFile()) {
            continue;
        }
        final String name = child.getName();
        if (!usedFiles.contains(name)) {
            if (DEBUG) {
                Slog.d(TAG, "Removing dangling bitmap file: " + child.getAbsolutePath());
            }
            child.delete();
        }
    }
}
 
Example 5
Source File: AlarmManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Re-orders the alarm batches based on newly evaluated send times based on the current
 * app-standby buckets
 * @param targetPackages [Package, User] pairs for which alarms need to be re-evaluated,
 *                       null indicates all
 * @return True if there was any reordering done to the current list.
 */
boolean reorderAlarmsBasedOnStandbyBuckets(ArraySet<Pair<String, Integer>> targetPackages) {
    final long start = mStatLogger.getTime();
    final ArrayList<Alarm> rescheduledAlarms = new ArrayList<>();

    for (int batchIndex = mAlarmBatches.size() - 1; batchIndex >= 0; batchIndex--) {
        final Batch batch = mAlarmBatches.get(batchIndex);
        for (int alarmIndex = batch.size() - 1; alarmIndex >= 0; alarmIndex--) {
            final Alarm alarm = batch.get(alarmIndex);
            final Pair<String, Integer> packageUser =
                    Pair.create(alarm.sourcePackage, UserHandle.getUserId(alarm.creatorUid));
            if (targetPackages != null && !targetPackages.contains(packageUser)) {
                continue;
            }
            if (adjustDeliveryTimeBasedOnStandbyBucketLocked(alarm)) {
                batch.remove(alarm);
                rescheduledAlarms.add(alarm);
            }
        }
        if (batch.size() == 0) {
            mAlarmBatches.remove(batchIndex);
        }
    }
    for (int i = 0; i < rescheduledAlarms.size(); i++) {
        final Alarm a = rescheduledAlarms.get(i);
        insertAndBatchAlarmLocked(a);
    }

    mStatLogger.logDurationStat(Stats.REORDER_ALARMS_FOR_STANDBY, start);
    return rescheduledAlarms.size() > 0;
}
 
Example 6
Source File: PinnerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Update the currently pinned files.
 * Specifically, this only updates pinning for the apps that need to be pinned.
 * The other files pinned in onStart will not need to be updated.
 */
public void update(ArraySet<String> updatedPackages, boolean force) {
    int currentUser = ActivityManager.getCurrentUser();
    for (int i = mPinKeys.size() - 1; i >= 0; i--) {
        int key = mPinKeys.valueAt(i);
        ApplicationInfo info = getInfoForKey(key, currentUser);
        if (info != null && updatedPackages.contains(info.packageName)) {
            Slog.i(TAG, "Updating pinned files for " + info.packageName + " force=" + force);
            sendPinAppMessage(key, currentUser, force);
        }
    }
}
 
Example 7
Source File: ManagedServices.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
protected boolean isPackageOrComponentAllowed(String pkgOrComponent, int userId) {
    ArrayMap<Boolean, ArraySet<String>> allowedByType =
            mApproved.getOrDefault(userId, new ArrayMap<>());
    for (int i = 0; i < allowedByType.size(); i++) {
        ArraySet<String> allowed = allowedByType.valueAt(i);
        if (allowed.contains(pkgOrComponent)) {
            return true;
        }
    }
    return false;
}
 
Example 8
Source File: ZenModeConditions.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void evaluateConfig(ZenModeConfig config, ComponentName trigger,
        boolean processSubscriptions) {
    if (config == null) return;
    if (config.manualRule != null && config.manualRule.condition != null
            && !config.manualRule.isTrueOrUnknown()) {
        if (DEBUG) Log.d(TAG, "evaluateConfig: clearing manual rule");
        config.manualRule = null;
    }
    final ArraySet<Uri> current = new ArraySet<>();
    evaluateRule(config.manualRule, current, null, processSubscriptions);
    for (ZenRule automaticRule : config.automaticRules.values()) {
        evaluateRule(automaticRule, current, trigger, processSubscriptions);
        updateSnoozing(automaticRule);
    }

    synchronized (mSubscriptions) {
        final int N = mSubscriptions.size();
        for (int i = N - 1; i >= 0; i--) {
            final Uri id = mSubscriptions.keyAt(i);
            final ComponentName component = mSubscriptions.valueAt(i);
            if (processSubscriptions) {
                if (!current.contains(id)) {
                    mConditionProviders.unsubscribeIfNecessary(component, id);
                    mSubscriptions.removeAt(i);
                }
            }
        }
    }
    mFirstEvaluation = false;
}
 
Example 9
Source File: KeySetManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * addScannedPackageLPw directly modifies the package metadata in  pm.Settings
 * at a point of no-return.  We need to make sure that the scanned package does
 * not contain bad keyset meta-data that could generate an incorrect
 * PackageSetting. Verify that there is a signing keyset, there are no issues
 * with null objects, and the upgrade and defined keysets match.
 *
 * Returns true if the package can safely be added to the keyset metadata.
 */
public void assertScannedPackageValid(PackageParser.Package pkg)
        throws PackageManagerException {
    if (pkg == null || pkg.packageName == null) {
        throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                "Passed invalid package to keyset validation.");
    }
    ArraySet<PublicKey> signingKeys = pkg.mSigningDetails.publicKeys;
    if (signingKeys == null || !(signingKeys.size() > 0) || signingKeys.contains(null)) {
        throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                "Package has invalid signing-key-set.");
    }
    ArrayMap<String, ArraySet<PublicKey>> definedMapping = pkg.mKeySetMapping;
    if (definedMapping != null) {
        if (definedMapping.containsKey(null) || definedMapping.containsValue(null)) {
            throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                    "Package has null defined key set.");
        }
        int defMapSize = definedMapping.size();
        for (int i = 0; i < defMapSize; i++) {
            if (!(definedMapping.valueAt(i).size() > 0)
                    || definedMapping.valueAt(i).contains(null)) {
                throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                        "Package has null/no public keys for defined key-sets.");
            }
        }
    }
    ArraySet<String> upgradeAliases = pkg.mUpgradeKeySets;
    if (upgradeAliases != null) {
        if (definedMapping == null || !(definedMapping.keySet().containsAll(upgradeAliases))) {
            throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                    "Package has upgrade-key-sets without corresponding definitions.");
        }
    }
}
 
Example 10
Source File: EnabledComponentsObserver.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether a given component is present and enabled for the given user.
 *
 * @param component the component to check.
 * @param userId the user ID for the component to check.
 * @return {@code true} if present and enabled.
 */
public int isValid(ComponentName component, int userId) {
    synchronized (mLock) {
        ArraySet<ComponentName> installedComponents = mInstalledSet.get(userId);
        if (installedComponents == null || !installedComponents.contains(component)) {
            return NOT_INSTALLED;
        }
        ArraySet<ComponentName> validComponents = mEnabledSet.get(userId);
        if (validComponents == null || !validComponents.contains(component)) {
            return DISABLED;
        }
        return NO_ERROR;
    }
}
 
Example 11
Source File: RemoteAnimationDefinition.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the remote animation for a specific transition.
 *
 * @param transition The transition type. Must be one of WindowManager.TRANSIT_* values.
 * @param activityTypes The set of activity types of activities that are involved in the
 *                      transition. Will be used for filtering.
 * @return The remote animation adapter for the specified transition.
 */
public @Nullable RemoteAnimationAdapter getAdapter(@TransitionType int transition,
        ArraySet<Integer> activityTypes) {
    final RemoteAnimationAdapterEntry entry = mTransitionAnimationMap.get(transition);
    if (entry == null) {
        return null;
    }
    if (entry.activityTypeFilter == ACTIVITY_TYPE_UNDEFINED
            || activityTypes.contains(entry.activityTypeFilter)) {
        return entry.adapter;
    } else {
        return null;
    }
}
 
Example 12
Source File: WindowSurfacePlacer.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private int maybeUpdateTransitToWallpaper(int transit, boolean openingAppHasWallpaper,
        boolean closingAppHasWallpaper) {
    // Given no app transition pass it through instead of a wallpaper transition.
    // Never convert the crashing transition.
    // Never update the transition for the wallpaper if we are just docking from recents
    if (transit == TRANSIT_NONE || transit == TRANSIT_CRASHING_ACTIVITY_CLOSE
            || transit == TRANSIT_DOCK_TASK_FROM_RECENTS) {
        return transit;
    }

    // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper
    final WindowState wallpaperTarget = mWallpaperControllerLocked.getWallpaperTarget();
    final WindowState oldWallpaper = mWallpaperControllerLocked.isWallpaperTargetAnimating()
            ? null : wallpaperTarget;
    final ArraySet<AppWindowToken> openingApps = mService.mOpeningApps;
    final ArraySet<AppWindowToken> closingApps = mService.mClosingApps;
    final AppWindowToken topOpeningApp = getTopApp(mService.mOpeningApps,
            false /* ignoreHidden */);
    final AppWindowToken topClosingApp = getTopApp(mService.mClosingApps,
            true /* ignoreHidden */);

    boolean openingCanBeWallpaperTarget = canBeWallpaperTarget(openingApps);
    if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
            "New wallpaper target=" + wallpaperTarget
                    + ", oldWallpaper=" + oldWallpaper
                    + ", openingApps=" + openingApps
                    + ", closingApps=" + closingApps);

    if (openingCanBeWallpaperTarget && transit == TRANSIT_KEYGUARD_GOING_AWAY) {
        transit = TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
        if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
                "New transit: " + AppTransition.appTransitionToString(transit));
    }
    // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic
    // relies on the fact that we always execute a Keyguard transition after preparing one.
    else if (!isKeyguardGoingAwayTransit(transit)) {
        if (closingAppHasWallpaper && openingAppHasWallpaper) {
            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Wallpaper animation!");
            switch (transit) {
                case TRANSIT_ACTIVITY_OPEN:
                case TRANSIT_TASK_OPEN:
                case TRANSIT_TASK_TO_FRONT:
                    transit = TRANSIT_WALLPAPER_INTRA_OPEN;
                    break;
                case TRANSIT_ACTIVITY_CLOSE:
                case TRANSIT_TASK_CLOSE:
                case TRANSIT_TASK_TO_BACK:
                    transit = TRANSIT_WALLPAPER_INTRA_CLOSE;
                    break;
            }
            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
                    "New transit: " + AppTransition.appTransitionToString(transit));
        } else if (oldWallpaper != null && !mService.mOpeningApps.isEmpty()
                && !openingApps.contains(oldWallpaper.mAppToken)
                && closingApps.contains(oldWallpaper.mAppToken)
                && topClosingApp == oldWallpaper.mAppToken) {
            // We are transitioning from an activity with a wallpaper to one without.
            transit = TRANSIT_WALLPAPER_CLOSE;
            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "New transit away from wallpaper: "
                    + AppTransition.appTransitionToString(transit));
        } else if (wallpaperTarget != null && wallpaperTarget.isVisibleLw()
                && openingApps.contains(wallpaperTarget.mAppToken)
                && topOpeningApp == wallpaperTarget.mAppToken
                && transit != TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE) {
            // We are transitioning from an activity without
            // a wallpaper to now showing the wallpaper
            transit = TRANSIT_WALLPAPER_OPEN;
            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "New transit into wallpaper: "
                    + AppTransition.appTransitionToString(transit));
        }
    }
    return transit;
}
 
Example 13
Source File: CalendarTracker.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public CheckEventResult checkEvent(EventInfo filter, long time) {
    final Uri.Builder uriBuilder = Instances.CONTENT_URI.buildUpon();
    ContentUris.appendId(uriBuilder, time);
    ContentUris.appendId(uriBuilder, time + EVENT_CHECK_LOOKAHEAD);
    final Uri uri = uriBuilder.build();
    final Cursor cursor = mUserContext.getContentResolver().query(uri, INSTANCE_PROJECTION,
            null, null, INSTANCE_ORDER_BY);
    final CheckEventResult result = new CheckEventResult();
    result.recheckAt = time + EVENT_CHECK_LOOKAHEAD;
    try {
        final ArraySet<Long> primaryCalendars = getPrimaryCalendars();
        while (cursor != null && cursor.moveToNext()) {
            final long begin = cursor.getLong(0);
            final long end = cursor.getLong(1);
            final String title = cursor.getString(2);
            final boolean calendarVisible = cursor.getInt(3) == 1;
            final int eventId = cursor.getInt(4);
            final String name = cursor.getString(5);
            final String owner = cursor.getString(6);
            final long calendarId = cursor.getLong(7);
            final int availability = cursor.getInt(8);
            final boolean calendarPrimary = primaryCalendars.contains(calendarId);
            if (DEBUG) Log.d(TAG, String.format(
                    "%s %s-%s v=%s a=%s eid=%s n=%s o=%s cid=%s p=%s",
                    title,
                    new Date(begin), new Date(end), calendarVisible,
                    availabilityToString(availability), eventId, name, owner, calendarId,
                    calendarPrimary));
            final boolean meetsTime = time >= begin && time < end;
            final boolean meetsCalendar = calendarVisible && calendarPrimary
                    && (filter.calendar == null || Objects.equals(filter.calendar, owner)
                    || Objects.equals(filter.calendar, name));
            final boolean meetsAvailability = availability != Instances.AVAILABILITY_FREE;
            if (meetsCalendar && meetsAvailability) {
                if (DEBUG) Log.d(TAG, "  MEETS CALENDAR & AVAILABILITY");
                final boolean meetsAttendee = meetsAttendee(filter, eventId, owner);
                if (meetsAttendee) {
                    if (DEBUG) Log.d(TAG, "    MEETS ATTENDEE");
                    if (meetsTime) {
                        if (DEBUG) Log.d(TAG, "      MEETS TIME");
                        result.inEvent = true;
                    }
                    if (begin > time && begin < result.recheckAt) {
                        result.recheckAt = begin;
                    } else if (end > time && end < result.recheckAt) {
                        result.recheckAt = end;
                    }
                }
            }
        }
    } catch (Exception e) {
        Slog.w(TAG, "error reading calendar", e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return result;
}
 
Example 14
Source File: ShortcutLauncher.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Return true if the given shortcut is pinned by this launcher.<code></code>
 */
public boolean hasPinned(ShortcutInfo shortcut) {
    final ArraySet<String> pinned =
            getPinnedShortcutIds(shortcut.getPackage(), shortcut.getUserId());
    return (pinned != null) && pinned.contains(shortcut.getId());
}
 
Example 15
Source File: ShortcutLauncher.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Pin the given shortcuts, replacing the current pinned ones.
 */
public void pinShortcuts(@UserIdInt int packageUserId,
        @NonNull String packageName, @NonNull List<String> ids, boolean forPinRequest) {
    final ShortcutPackage packageShortcuts =
            mShortcutUser.getPackageShortcutsIfExists(packageName);
    if (packageShortcuts == null) {
        return; // No need to instantiate.
    }

    final PackageWithUser pu = PackageWithUser.of(packageUserId, packageName);

    final int idSize = ids.size();
    if (idSize == 0) {
        mPinnedShortcuts.remove(pu);
    } else {
        final ArraySet<String> prevSet = mPinnedShortcuts.get(pu);

        // Actually pin shortcuts.
        // This logic here is to make sure a launcher cannot pin a shortcut that is floating
        // (i.e. not dynamic nor manifest but is pinned) and pinned by another launcher.
        // In this case, technically the shortcut doesn't exist to this launcher, so it can't
        // pin it.
        // (Maybe unnecessarily strict...)

        final ArraySet<String> newSet = new ArraySet<>();

        for (int i = 0; i < idSize; i++) {
            final String id = ids.get(i);
            final ShortcutInfo si = packageShortcuts.findShortcutById(id);
            if (si == null) {
                continue;
            }
            if (si.isDynamic()
                    || si.isManifestShortcut()
                    || (prevSet != null && prevSet.contains(id))
                    || forPinRequest) {
                newSet.add(id);
            }
        }
        mPinnedShortcuts.put(pu, newSet);
    }
    packageShortcuts.refreshPinnedFlags();
}
 
Example 16
Source File: BackgroundDexOptService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private int optimizePackages(PackageManagerService pm, ArraySet<String> pkgs,
        long lowStorageThreshold, boolean is_for_primary_dex,
        ArraySet<String> failedPackageNames) {
    ArraySet<String> updatedPackages = new ArraySet<>();
    Set<String> unusedPackages = pm.getUnusedPackages(mDowngradeUnusedAppsThresholdInMillis);
    // Only downgrade apps when space is low on device.
    // Threshold is selected above the lowStorageThreshold so that we can pro-actively clean
    // up disk before user hits the actual lowStorageThreshold.
    final long lowStorageThresholdForDowngrade = LOW_THRESHOLD_MULTIPLIER_FOR_DOWNGRADE *
            lowStorageThreshold;
    boolean shouldDowngrade = shouldDowngrade(lowStorageThresholdForDowngrade);
    for (String pkg : pkgs) {
        int abort_code = abortIdleOptimizations(lowStorageThreshold);
        if (abort_code == OPTIMIZE_ABORT_BY_JOB_SCHEDULER) {
            return abort_code;
        }

        synchronized (failedPackageNames) {
            if (failedPackageNames.contains(pkg)) {
                // Skip previously failing package
                continue;
            }
        }

        int reason;
        boolean downgrade;
        // Downgrade unused packages.
        if (unusedPackages.contains(pkg) && shouldDowngrade) {
            // This applies for system apps or if packages location is not a directory, i.e.
            // monolithic install.
            if (is_for_primary_dex && !pm.canHaveOatDir(pkg)) {
                // For apps that don't have the oat directory, instead of downgrading,
                // remove their compiler artifacts from dalvik cache.
                pm.deleteOatArtifactsOfPackage(pkg);
                continue;
            } else {
                reason = PackageManagerService.REASON_INACTIVE_PACKAGE_DOWNGRADE;
                downgrade = true;
            }
        } else if (abort_code != OPTIMIZE_ABORT_NO_SPACE_LEFT) {
            reason = PackageManagerService.REASON_BACKGROUND_DEXOPT;
            downgrade = false;
        } else {
            // can't dexopt because of low space.
            continue;
        }

        synchronized (failedPackageNames) {
            // Conservatively add package to the list of failing ones in case
            // performDexOpt never returns.
            failedPackageNames.add(pkg);
        }

        // Optimize package if needed. Note that there can be no race between
        // concurrent jobs because PackageDexOptimizer.performDexOpt is synchronized.
        boolean success;
        int dexoptFlags =
                DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES |
                DexoptOptions.DEXOPT_BOOT_COMPLETE |
                (downgrade ? DexoptOptions.DEXOPT_DOWNGRADE : 0) |
                DexoptOptions.DEXOPT_IDLE_BACKGROUND_JOB;
        if (is_for_primary_dex) {
            int result = pm.performDexOptWithStatus(new DexoptOptions(pkg, reason,
                    dexoptFlags));
            success = result != PackageDexOptimizer.DEX_OPT_FAILED;
            if (result == PackageDexOptimizer.DEX_OPT_PERFORMED) {
                updatedPackages.add(pkg);
            }
        } else {
            success = pm.performDexOpt(new DexoptOptions(pkg,
                    reason, dexoptFlags | DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX));
        }
        if (success) {
            // Dexopt succeeded, remove package from the list of failing ones.
            synchronized (failedPackageNames) {
                failedPackageNames.remove(pkg);
            }
        }
    }
    notifyPinService(updatedPackages);
    return OPTIMIZE_PROCESSED;
}
 
Example 17
Source File: PermissionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private int checkUidPermission(String permName, PackageParser.Package pkg, int uid,
        int callingUid) {
    final int callingUserId = UserHandle.getUserId(callingUid);
    final boolean isCallerInstantApp =
            mPackageManagerInt.getInstantAppPackageName(callingUid) != null;
    final boolean isUidInstantApp =
            mPackageManagerInt.getInstantAppPackageName(uid) != null;
    final int userId = UserHandle.getUserId(uid);
    if (!mUserManagerInt.exists(userId)) {
        return PackageManager.PERMISSION_DENIED;
    }

    if (pkg != null) {
        if (pkg.mSharedUserId != null) {
            if (isCallerInstantApp) {
                return PackageManager.PERMISSION_DENIED;
            }
        } else if (mPackageManagerInt.filterAppAccess(pkg, callingUid, callingUserId)) {
            return PackageManager.PERMISSION_DENIED;
        }
        final PermissionsState permissionsState =
                ((PackageSetting) pkg.mExtras).getPermissionsState();
        if (permissionsState.hasPermission(permName, userId)) {
            if (isUidInstantApp) {
                if (mSettings.isPermissionInstant(permName)) {
                    return PackageManager.PERMISSION_GRANTED;
                }
            } else {
                return PackageManager.PERMISSION_GRANTED;
            }
        }
        // Special case: ACCESS_FINE_LOCATION permission includes ACCESS_COARSE_LOCATION
        if (Manifest.permission.ACCESS_COARSE_LOCATION.equals(permName) && permissionsState
                .hasPermission(Manifest.permission.ACCESS_FINE_LOCATION, userId)) {
            return PackageManager.PERMISSION_GRANTED;
        }
    } else {
        ArraySet<String> perms = mSystemPermissions.get(uid);
        if (perms != null) {
            if (perms.contains(permName)) {
                return PackageManager.PERMISSION_GRANTED;
            }
            if (Manifest.permission.ACCESS_COARSE_LOCATION.equals(permName) && perms
                    .contains(Manifest.permission.ACCESS_FINE_LOCATION)) {
                return PackageManager.PERMISSION_GRANTED;
            }
        }
    }
    return PackageManager.PERMISSION_DENIED;
}
 
Example 18
Source File: SliceFullAccessList.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public boolean hasFullAccess(String pkg, int userId) {
    ArraySet<String> pkgs = mFullAccessPkgs.get(userId, null);
    return pkgs != null && pkgs.contains(pkg);
}
 
Example 19
Source File: JobStore.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public boolean contains(JobStatus job) {
    final int uid = job.getUid();
    ArraySet<JobStatus> jobs = mJobs.get(uid);
    return jobs != null && jobs.contains(job);
}
 
Example 20
Source File: AutofillManager.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Check if set is null or value is in set.
 *
 * @param set   The set or null (== empty set)
 * @param value The value that might be in the set
 *
 * @return {@code true} iff set is not empty and value is in set
 */
// TODO: move to Helper as static method
private <T> boolean isInSet(@Nullable ArraySet<T> set, T value) {
    return set != null && set.contains(value);
}