android.util.ArraySet#remove ( )源码实例Demo

下面列出了android.util.ArraySet#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: JobStore.java
public boolean remove(JobStatus job) {
    final int uid = job.getUid();
    final ArraySet<JobStatus> jobs = mJobs.get(uid);
    final int sourceUid = job.getSourceUid();
    final ArraySet<JobStatus> jobsForSourceUid = mJobsPerSourceUid.get(sourceUid);
    final boolean didRemove = jobs != null && jobs.remove(job);
    final boolean sourceRemove = jobsForSourceUid != null && jobsForSourceUid.remove(job);
    if (didRemove != sourceRemove) {
        Slog.wtf(TAG, "Job presence mismatch; caller=" + didRemove
                + " source=" + sourceRemove);
    }
    if (didRemove || sourceRemove) {
        // no more jobs for this uid?  let the now-empty set objects be GC'd.
        if (jobs != null && jobs.size() == 0) {
            mJobs.remove(uid);
        }
        if (jobsForSourceUid != null && jobsForSourceUid.size() == 0) {
            mJobsPerSourceUid.remove(sourceUid);
        }
        return true;
    }
    return false;
}
 
public void systemReady() {
    mAppOps = mContext.getSystemService(AppOpsManager.class);

    synchronized (mSessions) {
        readSessionsLocked();

        reconcileStagesLocked(StorageManager.UUID_PRIVATE_INTERNAL, false /*isInstant*/);
        reconcileStagesLocked(StorageManager.UUID_PRIVATE_INTERNAL, true /*isInstant*/);

        final ArraySet<File> unclaimedIcons = newArraySet(
                mSessionsDir.listFiles());

        // Ignore stages and icons claimed by active sessions
        for (int i = 0; i < mSessions.size(); i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            unclaimedIcons.remove(buildAppIconFile(session.sessionId));
        }

        // Clean up orphaned icons
        for (File icon : unclaimedIcons) {
            Slog.w(TAG, "Deleting orphan icon " + icon);
            icon.delete();
        }
    }
}
 
@GuardedBy("mSessions")
private void reconcileStagesLocked(String volumeUuid, boolean isEphemeral) {
    final File stagingDir = buildStagingDir(volumeUuid, isEphemeral);
    final ArraySet<File> unclaimedStages = newArraySet(
            stagingDir.listFiles(sStageFilter));

    // Ignore stages claimed by active sessions
    for (int i = 0; i < mSessions.size(); i++) {
        final PackageInstallerSession session = mSessions.valueAt(i);
        unclaimedStages.remove(session.stageDir);
    }

    // Clean up orphaned staging directories
    for (File stage : unclaimedStages) {
        Slog.w(TAG, "Deleting orphan stage " + stage);
        synchronized (mPm.mInstallLock) {
            mPm.removeCodePathLI(stage);
        }
    }
}
 
源代码4 项目: android_9.0.0_r45   文件: ManagedServices.java
protected void setPackageOrComponentEnabled(String pkgOrComponent, int userId,
        boolean isPrimary, boolean enabled) {
    Slog.i(TAG,
            (enabled ? " Allowing " : "Disallowing ") + mConfig.caption + " " + pkgOrComponent);
    ArrayMap<Boolean, ArraySet<String>> allowedByType = mApproved.get(userId);
    if (allowedByType == null) {
        allowedByType = new ArrayMap<>();
        mApproved.put(userId, allowedByType);
    }
    ArraySet<String> approved = allowedByType.get(isPrimary);
    if (approved == null) {
        approved = new ArraySet<>();
        allowedByType.put(isPrimary, approved);
    }
    String approvedItem = getApprovedValue(pkgOrComponent);

    if (approvedItem != null) {
        if (enabled) {
            approved.add(approvedItem);
        } else {
            approved.remove(approvedItem);
        }
    }

    rebindServices(false);
}
 
源代码5 项目: android_9.0.0_r45   文件: AutofillManager.java
/**
 * Remove a value from a set.
 *
 * @param set           The set or null (== empty set)
 * @param valueToRemove The value to remove
 *
 * @return The set without the removed value. {@code null} if set was null, or is empty
 *         after removal.
 */
// TODO: move to Helper as static method
@Nullable
private <T> ArraySet<T> removeFromSet(@Nullable ArraySet<T> set, T valueToRemove) {
    if (set == null) {
        return null;
    }

    set.remove(valueToRemove);

    if (set.isEmpty()) {
        return null;
    }

    return set;
}
 
源代码6 项目: android_9.0.0_r45   文件: SliceFullAccessList.java
public void removeGrant(String pkg, int userId) {
    ArraySet<String> pkgs = mFullAccessPkgs.get(userId, null);
    if (pkgs == null) {
        pkgs = new ArraySet<>();
        mFullAccessPkgs.put(userId, pkgs);
    }
    pkgs.remove(pkg);
}
 
源代码7 项目: android_9.0.0_r45   文件: PrintAttributes.java
/**
 * Get the Id of all predefined media sizes beside the {@link #UNKNOWN_PORTRAIT} and
 * {@link #UNKNOWN_LANDSCAPE}.
 *
 * @return List of all predefined media sizes
 *
 * @hide
 */
public static @NonNull ArraySet<MediaSize> getAllPredefinedSizes() {
    ArraySet<MediaSize> definedMediaSizes = new ArraySet<>(sIdToMediaSizeMap.values());

    definedMediaSizes.remove(UNKNOWN_PORTRAIT);
    definedMediaSizes.remove(UNKNOWN_LANDSCAPE);

    return definedMediaSizes;
}
 
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;
}