use of android.util.ArraySet in project android_frameworks_base by AOSPA.
the class ProcessStats method collectProcessesLocked.
public ArrayList<ProcessState> collectProcessesLocked(int[] screenStates, int[] memStates, int[] procStates, int[] sortProcStates, long now, String reqPackage, boolean activeOnly) {
final ArraySet<ProcessState> foundProcs = new ArraySet<ProcessState>();
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
for (int ip = 0; ip < pkgMap.size(); ip++) {
final String pkgName = pkgMap.keyAt(ip);
final SparseArray<SparseArray<PackageState>> procs = pkgMap.valueAt(ip);
for (int iu = 0; iu < procs.size(); iu++) {
final SparseArray<PackageState> vpkgs = procs.valueAt(iu);
final int NVERS = vpkgs.size();
for (int iv = 0; iv < NVERS; iv++) {
final PackageState state = vpkgs.valueAt(iv);
final int NPROCS = state.mProcesses.size();
final boolean pkgMatch = reqPackage == null || reqPackage.equals(pkgName);
for (int iproc = 0; iproc < NPROCS; iproc++) {
final ProcessState proc = state.mProcesses.valueAt(iproc);
if (!pkgMatch && !reqPackage.equals(proc.getName())) {
continue;
}
if (activeOnly && !proc.isInUse()) {
continue;
}
foundProcs.add(proc.getCommonProcess());
}
}
}
}
ArrayList<ProcessState> outProcs = new ArrayList<ProcessState>(foundProcs.size());
for (int i = 0; i < foundProcs.size(); i++) {
ProcessState proc = foundProcs.valueAt(i);
if (proc.computeProcessTimeLocked(screenStates, memStates, procStates, now) > 0) {
outProcs.add(proc);
if (procStates != sortProcStates) {
proc.computeProcessTimeLocked(screenStates, memStates, sortProcStates, now);
}
}
}
Collections.sort(outProcs, ProcessState.COMPARATOR);
return outProcs;
}
use of android.util.ArraySet in project android_frameworks_base by AOSPA.
the class TransformState method setClippingDeactivated.
public static void setClippingDeactivated(final View transformedView, boolean deactivated) {
if (!(transformedView.getParent() instanceof ViewGroup)) {
return;
}
ViewGroup view = (ViewGroup) transformedView.getParent();
while (true) {
ArraySet<View> clipSet = (ArraySet<View>) view.getTag(CLIP_CLIPPING_SET);
if (clipSet == null) {
clipSet = new ArraySet<>();
view.setTag(CLIP_CLIPPING_SET, clipSet);
}
Boolean clipChildren = (Boolean) view.getTag(CLIP_CHILDREN_TAG);
if (clipChildren == null) {
clipChildren = view.getClipChildren();
view.setTag(CLIP_CHILDREN_TAG, clipChildren);
}
Boolean clipToPadding = (Boolean) view.getTag(CLIP_TO_PADDING);
if (clipToPadding == null) {
clipToPadding = view.getClipToPadding();
view.setTag(CLIP_TO_PADDING, clipToPadding);
}
ExpandableNotificationRow row = view instanceof ExpandableNotificationRow ? (ExpandableNotificationRow) view : null;
if (!deactivated) {
clipSet.remove(transformedView);
if (clipSet.isEmpty()) {
view.setClipChildren(clipChildren);
view.setClipToPadding(clipToPadding);
view.setTag(CLIP_CLIPPING_SET, null);
if (row != null) {
row.setClipToActualHeight(true);
}
}
} else {
clipSet.add(transformedView);
view.setClipChildren(false);
view.setClipToPadding(false);
if (row != null && row.isChildInGroup()) {
// We still want to clip to the parent's height
row.setClipToActualHeight(false);
}
}
if (row != null && !row.isChildInGroup()) {
return;
}
final ViewParent parent = view.getParent();
if (parent instanceof ViewGroup) {
view = (ViewGroup) parent;
} else {
return;
}
}
}
use of android.util.ArraySet in project android_frameworks_base by AOSPA.
the class TaskStack method computeComponentsRemoved.
/**
* Computes the components of tasks in this stack that have been removed as a result of a change
* in the specified package.
*/
public ArraySet<ComponentName> computeComponentsRemoved(String packageName, int userId) {
// Identify all the tasks that should be removed as a result of the package being removed.
// Using a set to ensure that we callback once per unique component.
SystemServicesProxy ssp = Recents.getSystemServices();
ArraySet<ComponentName> existingComponents = new ArraySet<>();
ArraySet<ComponentName> removedComponents = new ArraySet<>();
ArrayList<Task.TaskKey> taskKeys = getTaskKeys();
int taskKeyCount = taskKeys.size();
for (int i = 0; i < taskKeyCount; i++) {
Task.TaskKey t = taskKeys.get(i);
// Skip if this doesn't apply to the current user
if (t.userId != userId)
continue;
ComponentName cn = t.getComponent();
if (cn.getPackageName().equals(packageName)) {
if (existingComponents.contains(cn)) {
// If we know that the component still exists in the package, then skip
continue;
}
if (ssp.getActivityInfo(cn, userId) != null) {
existingComponents.add(cn);
} else {
removedComponents.add(cn);
}
}
}
return removedComponents;
}
use of android.util.ArraySet in project android_frameworks_base by AOSPA.
the class NetworkPolicyManagerService method updateNetworkRulesNL.
/**
* Examine all connected {@link NetworkState}, looking for
* {@link NetworkPolicy} that need to be enforced. When matches found, set
* remaining quota based on usage cycle and historical stats.
*/
void updateNetworkRulesNL() {
if (LOGV)
Slog.v(TAG, "updateNetworkRulesNL()");
final NetworkState[] states;
try {
states = mConnManager.getAllNetworkState();
} catch (RemoteException e) {
// ignored; service lives in system_server
return;
}
// First, generate identities of all connected networks so we can
// quickly compare them against all defined policies below.
final ArrayList<Pair<String, NetworkIdentity>> connIdents = new ArrayList<>(states.length);
final ArraySet<String> connIfaces = new ArraySet<String>(states.length);
for (NetworkState state : states) {
if (state.networkInfo != null && state.networkInfo.isConnected()) {
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
final String baseIface = state.linkProperties.getInterfaceName();
if (baseIface != null) {
connIdents.add(Pair.create(baseIface, ident));
}
// Stacked interfaces are considered to have same identity as
// their parent network.
final List<LinkProperties> stackedLinks = state.linkProperties.getStackedLinks();
for (LinkProperties stackedLink : stackedLinks) {
final String stackedIface = stackedLink.getInterfaceName();
if (stackedIface != null) {
connIdents.add(Pair.create(stackedIface, ident));
}
}
}
}
// Apply policies against all connected interfaces found above
mNetworkRules.clear();
final ArrayList<String> ifaceList = Lists.newArrayList();
for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
final NetworkPolicy policy = mNetworkPolicy.valueAt(i);
ifaceList.clear();
for (int j = connIdents.size() - 1; j >= 0; j--) {
final Pair<String, NetworkIdentity> ident = connIdents.get(j);
if (policy.template.matches(ident.second)) {
ifaceList.add(ident.first);
}
}
if (ifaceList.size() > 0) {
final String[] ifaces = ifaceList.toArray(new String[ifaceList.size()]);
mNetworkRules.put(policy, ifaces);
}
}
long lowestRule = Long.MAX_VALUE;
final ArraySet<String> newMeteredIfaces = new ArraySet<String>(states.length);
// apply each policy that we found ifaces for; compute remaining data
// based on current cycle and historical stats, and push to kernel.
final long currentTime = currentTimeMillis();
for (int i = mNetworkRules.size() - 1; i >= 0; i--) {
final NetworkPolicy policy = mNetworkRules.keyAt(i);
final String[] ifaces = mNetworkRules.valueAt(i);
final long start;
final long totalBytes;
if (policy.hasCycle()) {
start = computeLastCycleBoundary(currentTime, policy);
totalBytes = getTotalBytes(policy.template, start, currentTime);
} else {
start = Long.MAX_VALUE;
totalBytes = 0;
}
if (LOGD) {
Slog.d(TAG, "applying policy " + policy + " to ifaces " + Arrays.toString(ifaces));
}
final boolean hasWarning = policy.warningBytes != LIMIT_DISABLED;
final boolean hasLimit = policy.limitBytes != LIMIT_DISABLED;
if (hasLimit || policy.metered) {
final long quotaBytes;
if (!hasLimit) {
// metered network, but no policy limit; we still need to
// restrict apps, so push really high quota.
quotaBytes = Long.MAX_VALUE;
} else if (policy.lastLimitSnooze >= start) {
// snoozing past quota, but we still need to restrict apps,
// so push really high quota.
quotaBytes = Long.MAX_VALUE;
} else {
// remaining "quota" bytes are based on total usage in
// current cycle. kernel doesn't like 0-byte rules, so we
// set 1-byte quota and disable the radio later.
quotaBytes = Math.max(1, policy.limitBytes - totalBytes);
}
if (ifaces.length > 1) {
// TODO: switch to shared quota once NMS supports
Slog.w(TAG, "shared quota unsupported; generating rule for each iface");
}
for (String iface : ifaces) {
// long quotaBytes split up into two ints to fit in message
mHandler.obtainMessage(MSG_UPDATE_INTERFACE_QUOTA, (int) (quotaBytes >> 32), (int) (quotaBytes & 0xFFFFFFFF), iface).sendToTarget();
newMeteredIfaces.add(iface);
}
}
// keep track of lowest warning or limit of active policies
if (hasWarning && policy.warningBytes < lowestRule) {
lowestRule = policy.warningBytes;
}
if (hasLimit && policy.limitBytes < lowestRule) {
lowestRule = policy.limitBytes;
}
}
for (int i = connIfaces.size() - 1; i >= 0; i--) {
String iface = connIfaces.valueAt(i);
// long quotaBytes split up into two ints to fit in message
mHandler.obtainMessage(MSG_UPDATE_INTERFACE_QUOTA, (int) (Long.MAX_VALUE >> 32), (int) (Long.MAX_VALUE & 0xFFFFFFFF), iface).sendToTarget();
newMeteredIfaces.add(iface);
}
mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget();
// remove quota on any trailing interfaces
for (int i = mMeteredIfaces.size() - 1; i >= 0; i--) {
final String iface = mMeteredIfaces.valueAt(i);
if (!newMeteredIfaces.contains(iface)) {
mHandler.obtainMessage(MSG_REMOVE_INTERFACE_QUOTA, iface).sendToTarget();
}
}
mMeteredIfaces = newMeteredIfaces;
final String[] meteredIfaces = mMeteredIfaces.toArray(new String[mMeteredIfaces.size()]);
mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget();
}
use of android.util.ArraySet in project android_frameworks_base by AOSPA.
the class NetworkPolicyManagerService method dump.
@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
mContext.enforceCallingOrSelfPermission(DUMP, TAG);
final IndentingPrintWriter fout = new IndentingPrintWriter(writer, " ");
final ArraySet<String> argSet = new ArraySet<String>(args.length);
for (String arg : args) {
argSet.add(arg);
}
synchronized (mUidRulesFirstLock) {
synchronized (mNetworkPoliciesSecondLock) {
if (argSet.contains("--unsnooze")) {
for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
mNetworkPolicy.valueAt(i).clearSnooze();
}
normalizePoliciesNL();
updateNetworkEnabledNL();
updateNetworkRulesNL();
updateNotificationsNL();
writePolicyAL();
fout.println("Cleared snooze timestamps");
return;
}
fout.print("System ready: ");
fout.println(mSystemReady);
fout.print("Restrict background: ");
fout.println(mRestrictBackground);
fout.print("Restrict power: ");
fout.println(mRestrictPower);
fout.print("Device idle: ");
fout.println(mDeviceIdleMode);
fout.println("Network policies:");
fout.increaseIndent();
for (int i = 0; i < mNetworkPolicy.size(); i++) {
fout.println(mNetworkPolicy.valueAt(i).toString());
}
fout.decreaseIndent();
fout.print("Metered ifaces: ");
fout.println(String.valueOf(mMeteredIfaces));
fout.println("Policy for UIDs:");
fout.increaseIndent();
int size = mUidPolicy.size();
for (int i = 0; i < size; i++) {
final int uid = mUidPolicy.keyAt(i);
final int policy = mUidPolicy.valueAt(i);
fout.print("UID=");
fout.print(uid);
fout.print(" policy=");
fout.print(DebugUtils.flagsToString(NetworkPolicyManager.class, "POLICY_", policy));
fout.println();
}
fout.decreaseIndent();
size = mPowerSaveWhitelistExceptIdleAppIds.size();
if (size > 0) {
fout.println("Power save whitelist (except idle) app ids:");
fout.increaseIndent();
for (int i = 0; i < size; i++) {
fout.print("UID=");
fout.print(mPowerSaveWhitelistExceptIdleAppIds.keyAt(i));
fout.print(": ");
fout.print(mPowerSaveWhitelistExceptIdleAppIds.valueAt(i));
fout.println();
}
fout.decreaseIndent();
}
size = mPowerSaveWhitelistAppIds.size();
if (size > 0) {
fout.println("Power save whitelist app ids:");
fout.increaseIndent();
for (int i = 0; i < size; i++) {
fout.print("UID=");
fout.print(mPowerSaveWhitelistAppIds.keyAt(i));
fout.print(": ");
fout.print(mPowerSaveWhitelistAppIds.valueAt(i));
fout.println();
}
fout.decreaseIndent();
}
size = mRestrictBackgroundWhitelistUids.size();
if (size > 0) {
fout.println("Restrict background whitelist uids:");
fout.increaseIndent();
for (int i = 0; i < size; i++) {
fout.print("UID=");
fout.print(mRestrictBackgroundWhitelistUids.keyAt(i));
fout.println();
}
fout.decreaseIndent();
}
size = mDefaultRestrictBackgroundWhitelistUids.size();
if (size > 0) {
fout.println("Default restrict background whitelist uids:");
fout.increaseIndent();
for (int i = 0; i < size; i++) {
fout.print("UID=");
fout.print(mDefaultRestrictBackgroundWhitelistUids.keyAt(i));
fout.println();
}
fout.decreaseIndent();
}
size = mRestrictBackgroundWhitelistRevokedUids.size();
if (size > 0) {
fout.println("Default restrict background whitelist uids revoked by users:");
fout.increaseIndent();
for (int i = 0; i < size; i++) {
fout.print("UID=");
fout.print(mRestrictBackgroundWhitelistRevokedUids.keyAt(i));
fout.println();
}
fout.decreaseIndent();
}
final SparseBooleanArray knownUids = new SparseBooleanArray();
collectKeys(mUidState, knownUids);
collectKeys(mUidRules, knownUids);
fout.println("Status for all known UIDs:");
fout.increaseIndent();
size = knownUids.size();
for (int i = 0; i < size; i++) {
final int uid = knownUids.keyAt(i);
fout.print("UID=");
fout.print(uid);
final int state = mUidState.get(uid, ActivityManager.PROCESS_STATE_CACHED_EMPTY);
fout.print(" state=");
fout.print(state);
if (state <= ActivityManager.PROCESS_STATE_TOP) {
fout.print(" (fg)");
} else {
fout.print(state <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE ? " (fg svc)" : " (bg)");
}
final int uidRules = mUidRules.get(uid, RULE_NONE);
fout.print(" rules=");
fout.print(uidRulesToString(uidRules));
fout.println();
}
fout.decreaseIndent();
fout.println("Status for just UIDs with rules:");
fout.increaseIndent();
size = mUidRules.size();
for (int i = 0; i < size; i++) {
final int uid = mUidRules.keyAt(i);
fout.print("UID=");
fout.print(uid);
final int uidRules = mUidRules.get(uid, RULE_NONE);
fout.print(" rules=");
fout.print(uidRulesToString(uidRules));
fout.println();
}
fout.decreaseIndent();
}
}
}
Aggregations