com.google.android.collect.Sets Java Examples

The following examples show how to use com.google.android.collect.Sets. 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: RecentTasks.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
void onPackagesSuspendedChanged(String[] packages, boolean suspended, int userId) {
    final Set<String> packageNames = Sets.newHashSet(packages);
    for (int i = mTasks.size() - 1; i >= 0; --i) {
        final TaskRecord tr = mTasks.get(i);
        if (tr.realActivity != null
                && packageNames.contains(tr.realActivity.getPackageName())
                && tr.userId == userId
                && tr.realActivitySuspended != suspended) {
           tr.realActivitySuspended = suspended;
           if (suspended) {
               mService.mStackSupervisor.removeTaskByIdLocked(tr.taskId, false,
                       REMOVE_FROM_RECENTS, "suspended-package");
           }
           notifyTaskPersisterLocked(tr, false);
        }
    }
}
 
Example #2
Source File: ChooseTypeAndAccountActivity.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Return a set of account types specified by the intent as well as supported by the
 * AccountManager.
 */
private Set<String> getReleventAccountTypes(final Intent intent) {
  // An account type is relevant iff it is allowed by the caller and supported by the account
  // manager.
  Set<String> setOfRelevantAccountTypes = null;
  final String[] allowedAccountTypes =
          intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
    AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
    Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
    for (AuthenticatorDescription desc : descs) {
        supportedAccountTypes.add(desc.type);
    }
    if (allowedAccountTypes != null) {
        setOfRelevantAccountTypes = Sets.newHashSet(allowedAccountTypes);
        setOfRelevantAccountTypes.retainAll(supportedAccountTypes);
    } else {
        setOfRelevantAccountTypes = supportedAccountTypes;
  }
  return setOfRelevantAccountTypes;
}
 
Example #3
Source File: ChooseTypeAndAccountActivity.java    From Android-AccountChooser with Apache License 2.0 6 votes vote down vote up
/**
 * Return a set of account types speficied by the intent as well as supported by the
 * AccountManager.
 */
private Set<String> getReleventAccountTypes(final Intent intent) {
  // An account type is relevant iff it is allowed by the caller and supported by the account
  // manager.
  Set<String> setOfRelevantAccountTypes = null;
  final String[] allowedAccountTypes =
          intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
  if (allowedAccountTypes != null) {
      setOfRelevantAccountTypes = Sets.newHashSet(allowedAccountTypes);
      AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
      Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
      for (AuthenticatorDescription desc : descs) {
          supportedAccountTypes.add(desc.type);
      }
      setOfRelevantAccountTypes.retainAll(supportedAccountTypes);
  }
  return setOfRelevantAccountTypes;
}
 
Example #4
Source File: ConversationFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
  switch (item.getItemId()) {
    case R.id.action_info:        handleDisplayDetails(messageRecord);                         return true;
    case R.id.action_delete:      handleDeleteMessages(Sets.newHashSet(messageRecord));        return true;
    case R.id.action_copy:        handleCopyMessage(Sets.newHashSet(messageRecord));           return true;
    case R.id.action_reply:       handleReplyMessage(messageRecord);                           return true;
    case R.id.action_multiselect: handleEnterMultiSelect(messageRecord);                       return true;
    case R.id.action_forward:     handleForwardMessage(messageRecord);                         return true;
    case R.id.action_download:    handleSaveAttachment((MediaMmsMessageRecord) messageRecord); return true;
    default:                                                                                   return false;
  }
}
 
Example #5
Source File: RecentsAnimationController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public TaskSnapshot screenshotTask(int taskId) {
    if (DEBUG_RECENTS_ANIMATIONS) Slog.d(TAG, "screenshotTask(" + taskId + "):"
            + " mCanceled=" + mCanceled);
    final long token = Binder.clearCallingIdentity();
    try {
        synchronized (mService.getWindowManagerLock()) {
            if (mCanceled) {
                return null;
            }
            for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
                final TaskAnimationAdapter adapter = mPendingAnimations.get(i);
                final Task task = adapter.mTask;
                if (task.mTaskId == taskId) {
                    final TaskSnapshotController snapshotController =
                            mService.mTaskSnapshotController;
                    final ArraySet<Task> tasks = Sets.newArraySet(task);
                    snapshotController.snapshotTasks(tasks);
                    snapshotController.addSkipClosingAppSnapshotTasks(tasks);
                    return snapshotController.getSnapshot(taskId, 0 /* userId */,
                            false /* restoreFromDisk */, false /* reducedResolution */);
                }
            }
            return null;
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example #6
Source File: UserRestrictionsUtils.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static Set<String> newSetWithUniqueCheck(String[] strings) {
    final Set<String> ret = Sets.newArraySet(strings);

    // Make sure there's no overlap.
    Preconditions.checkState(ret.size() == strings.length);
    return ret;
}
 
Example #7
Source File: UriPermission.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void addReadOwner(UriPermissionOwner owner) {
    if (mReadOwners == null) {
        mReadOwners = Sets.newArraySet();
        ownedModeFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
        updateModeFlags();
    }
    if (mReadOwners.add(owner)) {
        owner.addReadPermission(this);
    }
}
 
Example #8
Source File: UriPermission.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void addWriteOwner(UriPermissionOwner owner) {
    if (mWriteOwners == null) {
        mWriteOwners = Sets.newArraySet();
        ownedModeFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
        updateModeFlags();
    }
    if (mWriteOwners.add(owner)) {
        owner.addWritePermission(this);
    }
}
 
Example #9
Source File: TaskSnapshotController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Called when the visibility of an app changes outside of the regular app transition flow.
 */
void notifyAppVisibilityChanged(AppWindowToken appWindowToken, boolean visible) {
    if (!visible) {
        handleClosingApps(Sets.newArraySet(appWindowToken));
    }
}
 
Example #10
Source File: NetworkStatsRecorder.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Record any delta that occurred since last {@link NetworkStats} snapshot,
 * using the given {@link Map} to identify network interfaces. First
 * snapshot is considered bootstrap, and is not counted as delta.
 *
 * @param vpnArray Optional info about the currently active VPN, if any. This is used to
 *                 redistribute traffic from the VPN app to the underlying responsible apps.
 *                 This should always be set to null if the provided snapshot is aggregated
 *                 across all UIDs (e.g. contains UID_ALL buckets), regardless of VPN state.
 */
public void recordSnapshotLocked(NetworkStats snapshot,
        Map<String, NetworkIdentitySet> ifaceIdent, @Nullable VpnInfo[] vpnArray,
        long currentTimeMillis) {
    final HashSet<String> unknownIfaces = Sets.newHashSet();

    // skip recording when snapshot missing
    if (snapshot == null) return;

    // assume first snapshot is bootstrap and don't record
    if (mLastSnapshot == null) {
        mLastSnapshot = snapshot;
        return;
    }

    final NetworkStatsCollection complete = mComplete != null ? mComplete.get() : null;

    final NetworkStats delta = NetworkStats.subtract(
            snapshot, mLastSnapshot, mObserver, mCookie);
    final long end = currentTimeMillis;
    final long start = end - delta.getElapsedRealtime();

    if (vpnArray != null) {
        for (VpnInfo info : vpnArray) {
            delta.migrateTun(info.ownerUid, info.vpnIface, info.primaryUnderlyingIface);
        }
    }

    NetworkStats.Entry entry = null;
    for (int i = 0; i < delta.size(); i++) {
        entry = delta.getValues(i, entry);

        // As a last-ditch sanity check, report any negative values and
        // clamp them so recording below doesn't croak.
        if (entry.isNegative()) {
            if (mObserver != null) {
                mObserver.foundNonMonotonic(delta, i, mCookie);
            }
            entry.rxBytes = Math.max(entry.rxBytes, 0);
            entry.rxPackets = Math.max(entry.rxPackets, 0);
            entry.txBytes = Math.max(entry.txBytes, 0);
            entry.txPackets = Math.max(entry.txPackets, 0);
            entry.operations = Math.max(entry.operations, 0);
        }

        final NetworkIdentitySet ident = ifaceIdent.get(entry.iface);
        if (ident == null) {
            unknownIfaces.add(entry.iface);
            continue;
        }

        // skip when no delta occurred
        if (entry.isEmpty()) continue;

        // only record tag data when requested
        if ((entry.tag == TAG_NONE) != mOnlyTags) {
            if (mPending != null) {
                mPending.recordData(ident, entry.uid, entry.set, entry.tag, start, end, entry);
            }

            // also record against boot stats when present
            if (mSinceBoot != null) {
                mSinceBoot.recordData(ident, entry.uid, entry.set, entry.tag, start, end, entry);
            }

            // also record against complete dataset when present
            if (complete != null) {
                complete.recordData(ident, entry.uid, entry.set, entry.tag, start, end, entry);
            }
        }
    }

    mLastSnapshot = snapshot;

    if (LOGV && unknownIfaces.size() > 0) {
        Slog.w(TAG, "unknown interfaces " + unknownIfaces + ", ignoring those stats");
    }
}
 
Example #11
Source File: UriPermissionOwner.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public void addReadPermission(UriPermission perm) {
    if (mReadPerms == null) {
        mReadPerms = Sets.newArraySet();
    }
    mReadPerms.add(perm);
}
 
Example #12
Source File: UriPermissionOwner.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public void addWritePermission(UriPermission perm) {
    if (mWritePerms == null) {
        mWritePerms = Sets.newArraySet();
    }
    mWritePerms.add(perm);
}