Java Code Examples for com.android.internal.util.ArrayUtils#contains()
The following examples show how to use
com.android.internal.util.ArrayUtils#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: AppOpsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public boolean hasRestriction(int restriction, String packageName, int userId) { if (perUserRestrictions == null) { return false; } boolean[] restrictions = perUserRestrictions.get(userId); if (restrictions == null) { return false; } if (!restrictions[restriction]) { return false; } if (perUserExcludedPackages == null) { return true; } String[] perUserExclusions = perUserExcludedPackages.get(userId); if (perUserExclusions == null) { return true; } return !ArrayUtils.contains(perUserExclusions, packageName); }
Example 2
Source File: KeySyncTask.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Returns {@code true} if a sync is pending. * @param recoveryAgentUid uid of the recovery agent. */ private boolean shouldCreateSnapshot(int recoveryAgentUid) { int[] types = mRecoverableKeyStoreDb.getRecoverySecretTypes(mUserId, recoveryAgentUid); if (!ArrayUtils.contains(types, KeyChainProtectionParams.TYPE_LOCKSCREEN)) { // Only lockscreen type is supported. // We will need to pass extra argument to KeySyncTask to support custom pass phrase. return false; } if (mCredentialUpdated) { // Sync credential if at least one snapshot was created. if (mRecoverableKeyStoreDb.getSnapshotVersion(mUserId, recoveryAgentUid) != null) { mRecoverableKeyStoreDb.setShouldCreateSnapshot(mUserId, recoveryAgentUid, true); return true; } } return mRecoverableKeyStoreDb.getShouldCreateSnapshot(mUserId, recoveryAgentUid); }
Example 3
Source File: ClipData.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Finds all applicable MIME types for a given URI. * * @param resolver ContentResolver used to get information about the URI. * @param uri The URI. * @return Returns an array of MIME types. */ private static String[] getMimeTypes(ContentResolver resolver, Uri uri) { String[] mimeTypes = null; if (SCHEME_CONTENT.equals(uri.getScheme())) { String realType = resolver.getType(uri); mimeTypes = resolver.getStreamTypes(uri, "*/*"); if (realType != null) { if (mimeTypes == null) { mimeTypes = new String[] { realType }; } else if (!ArrayUtils.contains(mimeTypes, realType)) { String[] tmp = new String[mimeTypes.length + 1]; tmp[0] = realType; System.arraycopy(mimeTypes, 0, tmp, 1, mimeTypes.length); mimeTypes = tmp; } } } if (mimeTypes == null) { mimeTypes = MIMETYPES_TEXT_URILIST; } return mimeTypes; }
Example 4
Source File: AppStateTracker.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @return whether force-app-standby is effective for a UID package-name. */ private boolean isRestricted(int uid, @NonNull String packageName, boolean useTempWhitelistToo, boolean exemptOnBatterySaver) { if (isUidActive(uid)) { return false; } synchronized (mLock) { // Whitelisted? final int appId = UserHandle.getAppId(uid); if (ArrayUtils.contains(mPowerWhitelistedAllAppIds, appId)) { return false; } if (useTempWhitelistToo && ArrayUtils.contains(mTempWhitelistedAppIds, appId)) { return false; } if (mForcedAppStandbyEnabled && isRunAnyRestrictedLocked(uid, packageName)) { return true; } if (exemptOnBatterySaver) { return false; } final int userId = UserHandle.getUserId(uid); if (mExemptedPackages.contains(userId, packageName)) { return false; } return mForceAllAppsStandby; } }
Example 5
Source File: SyncStorageEngine.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
boolean isAccountValid(Account account, int userId) { Account[] accountsForUser = mAccountsCache.get(userId); if (accountsForUser == null) { accountsForUser = mAccountManager.getAccountsAsUser(userId); mAccountsCache.put(userId, accountsForUser); } return ArrayUtils.contains(accountsForUser, account); }
Example 6
Source File: LockSettingsService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void setStringUnchecked(String key, int userId, String value) { Preconditions.checkArgument(userId != USER_FRP, "cannot store lock settings for FRP user"); mStorage.writeKeyValue(key, value, userId); if (ArrayUtils.contains(SETTINGS_TO_BACKUP, key)) { BackupManager.dataChanged("com.android.providers.settings"); } }
Example 7
Source File: PackageUserState.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Test if the given component is considered enabled. */ public boolean isEnabled(ComponentInfo componentInfo, int flags) { if ((flags & MATCH_DISABLED_COMPONENTS) != 0) { return true; } // First check if the overall package is disabled; if the package is // enabled then fall through to check specific component switch (this.enabled) { case COMPONENT_ENABLED_STATE_DISABLED: case COMPONENT_ENABLED_STATE_DISABLED_USER: return false; case COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED: if ((flags & MATCH_DISABLED_UNTIL_USED_COMPONENTS) == 0) { return false; } case COMPONENT_ENABLED_STATE_DEFAULT: if (!componentInfo.applicationInfo.enabled) { return false; } case COMPONENT_ENABLED_STATE_ENABLED: break; } // Check if component has explicit state before falling through to // the manifest default if (ArrayUtils.contains(this.enabledComponents, componentInfo.name)) { return true; } if (ArrayUtils.contains(this.disabledComponents, componentInfo.name)) { return false; } return componentInfo.enabled; }
Example 8
Source File: NetworkTemplate.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Examine the given template and normalize if it refers to a "merged" * mobile subscriber. We pick the "lowest" merged subscriber as the primary * for key purposes, and expand the template to match all other merged * subscribers. * <p> * For example, given an incoming template matching B, and the currently * active merge set [A,B], we'd return a new template that primarily matches * A, but also matches B. */ public static NetworkTemplate normalize(NetworkTemplate template, String[] merged) { if (template.isMatchRuleMobile() && ArrayUtils.contains(merged, template.mSubscriberId)) { // Requested template subscriber is part of the merge group; return // a template that matches all merged subscribers. return new NetworkTemplate(template.mMatchRule, merged[0], merged, template.mNetworkId); } else { return template; } }
Example 9
Source File: PackageUserState.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Test if the given component is considered enabled. */ public boolean isEnabled(ComponentInfo componentInfo, int flags) { if ((flags & MATCH_DISABLED_COMPONENTS) != 0) { return true; } // First check if the overall package is disabled; if the package is // enabled then fall through to check specific component switch (this.enabled) { case COMPONENT_ENABLED_STATE_DISABLED: case COMPONENT_ENABLED_STATE_DISABLED_USER: return false; case COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED: if ((flags & MATCH_DISABLED_UNTIL_USED_COMPONENTS) == 0) { return false; } case COMPONENT_ENABLED_STATE_DEFAULT: if (!componentInfo.applicationInfo.enabled) { return false; } case COMPONENT_ENABLED_STATE_ENABLED: break; } // Check if component has explicit state before falling through to // the manifest default if (ArrayUtils.contains(this.enabledComponents, componentInfo.name)) { return true; } if (ArrayUtils.contains(this.disabledComponents, componentInfo.name)) { return false; } return componentInfo.enabled; }
Example 10
Source File: PackageUserState.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Test if the given component is considered enabled. */ public boolean isEnabled(ComponentInfo componentInfo, int flags) { if ((flags & MATCH_DISABLED_COMPONENTS) != 0) { return true; } // First check if the overall package is disabled; if the package is // enabled then fall through to check specific component switch (this.enabled) { case COMPONENT_ENABLED_STATE_DISABLED: case COMPONENT_ENABLED_STATE_DISABLED_USER: return false; case COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED: if ((flags & MATCH_DISABLED_UNTIL_USED_COMPONENTS) == 0) { return false; } case COMPONENT_ENABLED_STATE_DEFAULT: if (!componentInfo.applicationInfo.enabled) { return false; } case COMPONENT_ENABLED_STATE_ENABLED: break; } // Check if component has explicit state before falling through to // the manifest default if (ArrayUtils.contains(this.enabledComponents, componentInfo.name)) { return true; } if (ArrayUtils.contains(this.disabledComponents, componentInfo.name)) { return false; } return componentInfo.enabled; }
Example 11
Source File: PackageUserState.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Test if the given component is considered enabled. */ public boolean isEnabled(ComponentInfo componentInfo, int flags) { if ((flags & MATCH_DISABLED_COMPONENTS) != 0) { return true; } // First check if the overall package is disabled; if the package is // enabled then fall through to check specific component switch (this.enabled) { case COMPONENT_ENABLED_STATE_DISABLED: case COMPONENT_ENABLED_STATE_DISABLED_USER: return false; case COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED: if ((flags & MATCH_DISABLED_UNTIL_USED_COMPONENTS) == 0) { return false; } case COMPONENT_ENABLED_STATE_DEFAULT: if (!componentInfo.applicationInfo.enabled) { return false; } case COMPONENT_ENABLED_STATE_ENABLED: break; } // Check if component has explicit state before falling through to // the manifest default if (ArrayUtils.contains(this.enabledComponents, componentInfo.name)) { return true; } if (ArrayUtils.contains(this.disabledComponents, componentInfo.name)) { return false; } return componentInfo.enabled; }
Example 12
Source File: PackageUserState.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Test if the given component is considered enabled. */ public boolean isEnabled(ComponentInfo componentInfo, int flags) { if ((flags & MATCH_DISABLED_COMPONENTS) != 0) { return true; } // First check if the overall package is disabled; if the package is // enabled then fall through to check specific component switch (this.enabled) { case COMPONENT_ENABLED_STATE_DISABLED: case COMPONENT_ENABLED_STATE_DISABLED_USER: return false; case COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED: if ((flags & MATCH_DISABLED_UNTIL_USED_COMPONENTS) == 0) { return false; } case COMPONENT_ENABLED_STATE_DEFAULT: if (!componentInfo.applicationInfo.enabled) { return false; } case COMPONENT_ENABLED_STATE_ENABLED: break; } // Check if component has explicit state before falling through to // the manifest default if (ArrayUtils.contains(this.enabledComponents, componentInfo.name)) { return true; } if (ArrayUtils.contains(this.disabledComponents, componentInfo.name)) { return false; } return componentInfo.enabled; }
Example 13
Source File: PackageUserState.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Test if the given component is considered enabled. */ public boolean isEnabled(ComponentInfo componentInfo, int flags) { if ((flags & MATCH_DISABLED_COMPONENTS) != 0) { return true; } // First check if the overall package is disabled; if the package is // enabled then fall through to check specific component switch (this.enabled) { case COMPONENT_ENABLED_STATE_DISABLED: case COMPONENT_ENABLED_STATE_DISABLED_USER: return false; case COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED: if ((flags & MATCH_DISABLED_UNTIL_USED_COMPONENTS) == 0) { return false; } case COMPONENT_ENABLED_STATE_DEFAULT: if (!componentInfo.applicationInfo.enabled) { return false; } case COMPONENT_ENABLED_STATE_ENABLED: break; } // Check if component has explicit state before falling through to // the manifest default if (ArrayUtils.contains(this.enabledComponents, componentInfo.name)) { return true; } if (ArrayUtils.contains(this.disabledComponents, componentInfo.name)) { return false; } return componentInfo.enabled; }
Example 14
Source File: PackageSharedLibraryUpdater.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static boolean isLibraryPresent(ArrayList<String> usesLibraries, ArrayList<String> usesOptionalLibraries, String apacheHttpLegacy) { return ArrayUtils.contains(usesLibraries, apacheHttpLegacy) || ArrayUtils.contains(usesOptionalLibraries, apacheHttpLegacy); }
Example 15
Source File: AppStateTracker.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * @param uid the uid to check for * @return whether a UID is in the user defined power-save whitelist or not. */ public boolean isUidPowerSaveUserWhitelisted(int uid) { synchronized (mLock) { return ArrayUtils.contains(mPowerWhitelistedUserAppIds, UserHandle.getAppId(uid)); } }
Example 16
Source File: InstantAppRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private void writeUninstalledInstantAppMetadata( @NonNull InstantAppInfo instantApp, @UserIdInt int userId) { File appDir = getInstantApplicationDir(instantApp.getPackageName(), userId); if (!appDir.exists() && !appDir.mkdirs()) { return; } File metadataFile = new File(appDir, INSTANT_APP_METADATA_FILE); AtomicFile destination = new AtomicFile(metadataFile); FileOutputStream out = null; try { out = destination.startWrite(); XmlSerializer serializer = Xml.newSerializer(); serializer.setOutput(out, StandardCharsets.UTF_8.name()); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.startDocument(null, true); serializer.startTag(null, TAG_PACKAGE); serializer.attribute(null, ATTR_LABEL, instantApp.loadLabel( mService.mContext.getPackageManager()).toString()); serializer.startTag(null, TAG_PERMISSIONS); for (String permission : instantApp.getRequestedPermissions()) { serializer.startTag(null, TAG_PERMISSION); serializer.attribute(null, ATTR_NAME, permission); if (ArrayUtils.contains(instantApp.getGrantedPermissions(), permission)) { serializer.attribute(null, ATTR_GRANTED, String.valueOf(true)); } serializer.endTag(null, TAG_PERMISSION); } serializer.endTag(null, TAG_PERMISSIONS); serializer.endTag(null, TAG_PACKAGE); serializer.endDocument(); destination.finishWrite(out); } catch (Throwable t) { Slog.wtf(LOG_TAG, "Failed to write instant state, restoring backup", t); destination.failWrite(out); } finally { IoUtils.closeQuietly(out); } }
Example 17
Source File: NetworkStatsService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Inspect all current {@link NetworkState} to derive mapping from {@code * iface} to {@link NetworkStatsHistory}. When multiple {@link NetworkInfo} * are active on a single {@code iface}, they are combined under a single * {@link NetworkIdentitySet}. */ @GuardedBy("mStatsLock") private void updateIfacesLocked(Network[] defaultNetworks, NetworkState[] states) { if (!mSystemReady) return; if (LOGV) Slog.v(TAG, "updateIfacesLocked()"); // take one last stats snapshot before updating iface mapping. this // isn't perfect, since the kernel may already be counting traffic from // the updated network. // poll, but only persist network stats to keep codepath fast. UID stats // will be persisted during next alarm poll event. performPollLocked(FLAG_PERSIST_NETWORK); // Rebuild active interfaces based on connected networks mActiveIfaces.clear(); mActiveUidIfaces.clear(); if (defaultNetworks != null) { // Caller is ConnectivityService. Update the list of default networks. mDefaultNetworks = defaultNetworks; } final ArraySet<String> mobileIfaces = new ArraySet<>(); for (NetworkState state : states) { if (state.networkInfo.isConnected()) { final boolean isMobile = isNetworkTypeMobile(state.networkInfo.getType()); final boolean isDefault = ArrayUtils.contains(mDefaultNetworks, state.network); final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state, isDefault); // Traffic occurring on the base interface is always counted for // both total usage and UID details. final String baseIface = state.linkProperties.getInterfaceName(); if (baseIface != null) { findOrCreateNetworkIdentitySet(mActiveIfaces, baseIface).add(ident); findOrCreateNetworkIdentitySet(mActiveUidIfaces, baseIface).add(ident); // Build a separate virtual interface for VT (Video Telephony) data usage. // Only do this when IMS is not metered, but VT is metered. // If IMS is metered, then the IMS network usage has already included VT usage. // VT is considered always metered in framework's layer. If VT is not metered // per carrier's policy, modem will report 0 usage for VT calls. if (state.networkCapabilities.hasCapability( NetworkCapabilities.NET_CAPABILITY_IMS) && !ident.getMetered()) { // Copy the identify from IMS one but mark it as metered. NetworkIdentity vtIdent = new NetworkIdentity(ident.getType(), ident.getSubType(), ident.getSubscriberId(), ident.getNetworkId(), ident.getRoaming(), true /* metered */, true /* onDefaultNetwork */); findOrCreateNetworkIdentitySet(mActiveIfaces, VT_INTERFACE).add(vtIdent); findOrCreateNetworkIdentitySet(mActiveUidIfaces, VT_INTERFACE).add(vtIdent); } if (isMobile) { mobileIfaces.add(baseIface); } } // Traffic occurring on stacked interfaces is usually clatd, // which is already accounted against its final egress interface // by the kernel. Thus, we only need to collect stacked // interface stats at the UID level. final List<LinkProperties> stackedLinks = state.linkProperties.getStackedLinks(); for (LinkProperties stackedLink : stackedLinks) { final String stackedIface = stackedLink.getInterfaceName(); if (stackedIface != null) { findOrCreateNetworkIdentitySet(mActiveUidIfaces, stackedIface).add(ident); if (isMobile) { mobileIfaces.add(stackedIface); } NetworkStatsFactory.noteStackedIface(stackedIface, baseIface); } } } } mMobileIfaces = mobileIfaces.toArray(new String[mobileIfaces.size()]); }
Example 18
Source File: UserController.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
boolean isCurrentProfile(int userId) { synchronized (mLock) { return ArrayUtils.contains(mCurrentProfileIds, userId); } }
Example 19
Source File: ContentService.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
@Override protected synchronized void dump(FileDescriptor fd, PrintWriter pw_, String[] args) { if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw_)) return; final IndentingPrintWriter pw = new IndentingPrintWriter(pw_, " "); final boolean dumpAll = ArrayUtils.contains(args, "-a"); // This makes it so that future permission checks will be in the context of this // process rather than the caller's process. We will restore this before returning. final long identityToken = clearCallingIdentity(); try { if (mSyncManager == null) { pw.println("No SyncManager created! (Disk full?)"); } else { mSyncManager.dump(fd, pw, dumpAll); } pw.println(); pw.println("Observer tree:"); synchronized (mRootNode) { int[] counts = new int[2]; final SparseIntArray pidCounts = new SparseIntArray(); mRootNode.dumpLocked(fd, pw, args, "", " ", counts, pidCounts); pw.println(); ArrayList<Integer> sorted = new ArrayList<Integer>(); for (int i=0; i<pidCounts.size(); i++) { sorted.add(pidCounts.keyAt(i)); } Collections.sort(sorted, new Comparator<Integer>() { @Override public int compare(Integer lhs, Integer rhs) { int lc = pidCounts.get(lhs); int rc = pidCounts.get(rhs); if (lc < rc) { return 1; } else if (lc > rc) { return -1; } return 0; } }); for (int i=0; i<sorted.size(); i++) { int pid = sorted.get(i); pw.print(" pid "); pw.print(pid); pw.print(": "); pw.print(pidCounts.get(pid)); pw.println(" observers"); } pw.println(); pw.print(" Total number of nodes: "); pw.println(counts[0]); pw.print(" Total number of observers: "); pw.println(counts[1]); } synchronized (mCache) { pw.println(); pw.println("Cached content:"); pw.increaseIndent(); for (int i = 0; i < mCache.size(); i++) { pw.println("User " + mCache.keyAt(i) + ":"); pw.increaseIndent(); pw.println(mCache.valueAt(i)); pw.decreaseIndent(); } pw.decreaseIndent(); } } finally { restoreCallingIdentity(identityToken); } }
Example 20
Source File: SliceItem.java From android_9.0.0_r45 with Apache License 2.0 | 2 votes |
/** * @param hint The hint to check for * @return true if this item contains the given hint */ public boolean hasHint(@Slice.SliceHint String hint) { return ArrayUtils.contains(mHints, hint); }