下面列出了android.util.ArraySet#valueAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Adjusts the wallpaper windows if the input display has a pending wallpaper layout or one of
* the opening apps should be a wallpaper target.
*/
void adjustWallpaperWindowsForAppTransitionIfNeeded(DisplayContent dc,
ArraySet<AppWindowToken> openingApps) {
boolean adjust = false;
if ((dc.pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
adjust = true;
} else {
for (int i = openingApps.size() - 1; i >= 0; --i) {
final AppWindowToken token = openingApps.valueAt(i);
if (token.windowsCanBeWallpaperTarget()) {
adjust = true;
break;
}
}
}
if (adjust) {
adjustWallpaperWindows(dc);
}
}
private AppWindowToken lookForHighestTokenWithFilter(ArraySet<AppWindowToken> array1,
ArraySet<AppWindowToken> array2, Predicate<AppWindowToken> filter) {
final int array1count = array1.size();
final int count = array1count + array2.size();
int bestPrefixOrderIndex = Integer.MIN_VALUE;
AppWindowToken bestToken = null;
for (int i = 0; i < count; i++) {
final AppWindowToken wtoken = i < array1count
? array1.valueAt(i)
: array2.valueAt(i - array1count);
final int prefixOrderIndex = wtoken.getPrefixOrderIndex();
if (filter.test(wtoken) && prefixOrderIndex > bestPrefixOrderIndex) {
bestPrefixOrderIndex = prefixOrderIndex;
bestToken = wtoken;
}
}
return bestToken;
}
/**
* Finds the top app in a list of apps, using its {@link AppWindowToken#getPrefixOrderIndex} to
* compare z-order.
*
* @param apps The list of apps to search.
* @param ignoreHidden If set to true, ignores apps that are {@link AppWindowToken#isHidden}.
* @return The top {@link AppWindowToken}.
*/
private AppWindowToken getTopApp(ArraySet<AppWindowToken> apps, boolean ignoreHidden) {
int topPrefixOrderIndex = Integer.MIN_VALUE;
AppWindowToken topApp = null;
for (int i = apps.size() - 1; i >= 0; i--) {
final AppWindowToken app = apps.valueAt(i);
if (ignoreHidden && app.isHidden()) {
continue;
}
final int prefixOrderIndex = app.getPrefixOrderIndex();
if (prefixOrderIndex > topPrefixOrderIndex) {
topPrefixOrderIndex = prefixOrderIndex;
topApp = app;
}
}
return topApp;
}
private void trimApprovedListsAccordingToInstalledServices() {
int N = mApproved.size();
for (int i = 0 ; i < N; i++) {
final int userId = mApproved.keyAt(i);
final ArrayMap<Boolean, ArraySet<String>> approvedByType = mApproved.valueAt(i);
int M = approvedByType.size();
for (int j = 0; j < M; j++) {
final ArraySet<String> approved = approvedByType.valueAt(j);
int P = approved.size();
for (int k = P - 1; k >= 0; k--) {
final String approvedPackageOrComponent = approved.valueAt(k);
if (!isValidEntry(approvedPackageOrComponent, userId)){
approved.removeAt(k);
Slog.v(TAG, "Removing " + approvedPackageOrComponent
+ " from approved list; no matching services found");
} else {
if (DEBUG) {
Slog.v(TAG, "Keeping " + approvedPackageOrComponent
+ " on approved list; matching services found");
}
}
}
}
}
}
private boolean removeUninstalledItemsFromApprovedLists(int uninstalledUserId, String pkg) {
boolean removed = false;
final ArrayMap<Boolean, ArraySet<String>> approvedByType = mApproved.get(uninstalledUserId);
if (approvedByType != null) {
int M = approvedByType.size();
for (int j = 0; j < M; j++) {
final ArraySet<String> approved = approvedByType.valueAt(j);
int O = approved.size();
for (int k = O - 1; k >= 0; k--) {
final String packageOrComponent = approved.valueAt(k);
final String packageName = getPackageName(packageOrComponent);
if (TextUtils.equals(pkg, packageName)) {
approved.removeAt(k);
if (DEBUG) {
Slog.v(TAG, "Removing " + packageOrComponent
+ " from approved list; uninstalled");
}
}
}
}
}
return removed;
}
private void notifyOpActiveChanged(ArraySet<ActiveCallback> callbacks,
int code, int uid, String packageName, boolean active) {
// There are components watching for mode changes such as window manager
// and location manager which are in our process. The callbacks in these
// components may require permissions our remote caller does not have.
final long identity = Binder.clearCallingIdentity();
try {
final int callbackCount = callbacks.size();
for (int i = 0; i < callbackCount; i++) {
final ActiveCallback callback = callbacks.valueAt(i);
try {
callback.mCallback.opActiveChanged(code, uid, packageName, active);
} catch (RemoteException e) {
/* do nothing */
}
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
/**
* @return true if {@param apps} contains an activity in the docked stack, false otherwise.
*/
private boolean containsAppInDockedStack(ArraySet<AppWindowToken> apps) {
for (int i = apps.size() - 1; i >= 0; i--) {
final AppWindowToken token = apps.valueAt(i);
if (token.getTask() != null && token.inSplitScreenPrimaryWindowingMode()) {
return true;
}
}
return false;
}
void snapshotTasks(ArraySet<Task> tasks) {
for (int i = tasks.size() - 1; i >= 0; i--) {
final Task task = tasks.valueAt(i);
final int mode = getSnapshotMode(task);
final TaskSnapshot snapshot;
switch (mode) {
case SNAPSHOT_MODE_NONE:
continue;
case SNAPSHOT_MODE_APP_THEME:
snapshot = drawAppThemeSnapshot(task);
break;
case SNAPSHOT_MODE_REAL:
snapshot = snapshotTask(task);
break;
default:
snapshot = null;
break;
}
if (snapshot != null) {
final GraphicBuffer buffer = snapshot.getSnapshot();
if (buffer.getWidth() == 0 || buffer.getHeight() == 0) {
buffer.destroy();
Slog.e(TAG, "Invalid task snapshot dimensions " + buffer.getWidth() + "x"
+ buffer.getHeight());
} else {
mCache.putSnapshot(task, snapshot);
mPersister.persistSnapshot(task.mTaskId, task.mUserId, snapshot);
if (task.getController() != null) {
task.getController().reportSnapshotChanged(snapshot);
}
}
}
}
}
private boolean containsVoiceInteraction(ArraySet<AppWindowToken> apps) {
for (int i = apps.size() - 1; i >= 0; i--) {
if (apps.valueAt(i).mVoiceInteraction) {
return true;
}
}
return false;
}
public JobStatus get(int uid, int jobId) {
ArraySet<JobStatus> jobs = mJobs.get(uid);
if (jobs != null) {
for (int i = jobs.size() - 1; i >= 0; i--) {
JobStatus job = jobs.valueAt(i);
if (job.getJobId() == jobId) {
return job;
}
}
}
return null;
}
public int countJobsForUid(int uid) {
int total = 0;
ArraySet<JobStatus> jobs = mJobs.get(uid);
if (jobs != null) {
for (int i = jobs.size() - 1; i >= 0; i--) {
JobStatus job = jobs.valueAt(i);
if (job.getUid() == job.getSourceUid()) {
total++;
}
}
}
return total;
}
public void forEachJob(@Nullable Predicate<JobStatus> filterPredicate,
Consumer<JobStatus> functor) {
for (int uidIndex = mJobs.size() - 1; uidIndex >= 0; uidIndex--) {
ArraySet<JobStatus> jobs = mJobs.valueAt(uidIndex);
if (jobs != null) {
for (int i = jobs.size() - 1; i >= 0; i--) {
final JobStatus jobStatus = jobs.valueAt(i);
if ((filterPredicate == null) || filterPredicate.test(jobStatus)) {
functor.accept(jobStatus);
}
}
}
}
}
/**
* Any fragments that were removed because they have been postponed should have their views
* made invisible by setting their transition alpha to 0.
*
* @param fragments The fragments that were added during operation execution. Only the ones
* that are no longer added will have their transition alpha changed.
*/
private void makeRemovedFragmentsInvisible(ArraySet<Fragment> fragments) {
final int numAdded = fragments.size();
for (int i = 0; i < numAdded; i++) {
final Fragment fragment = fragments.valueAt(i);
if (!fragment.mAdded) {
final View view = fragment.getView();
view.setTransitionAlpha(0f);
}
}
}
private void evalForegroundWatchers(int op, SparseArray<ArraySet<ModeCallback>> watchers,
SparseBooleanArray which) {
boolean curValue = which.get(op, false);
ArraySet<ModeCallback> callbacks = watchers.get(op);
if (callbacks != null) {
for (int cbi = callbacks.size() - 1; !curValue && cbi >= 0; cbi--) {
if ((callbacks.valueAt(cbi).mFlags
& AppOpsManager.WATCH_FOREGROUND_CHANGES) != 0) {
hasForegroundWatchers = true;
curValue = true;
}
}
}
which.put(op, curValue);
}
private void notifyOpChanged(ArraySet<ModeCallback> callbacks, int code,
int uid, String packageName) {
for (int i = 0; i < callbacks.size(); i++) {
final ModeCallback callback = callbacks.valueAt(i);
notifyOpChanged(callback, code, uid, packageName);
}
}
private static HashMap<ModeCallback, ArrayList<ChangeRec>> addCallbacks(
HashMap<ModeCallback, ArrayList<ChangeRec>> callbacks,
int op, int uid, String packageName, ArraySet<ModeCallback> cbs) {
if (cbs == null) {
return callbacks;
}
if (callbacks == null) {
callbacks = new HashMap<>();
}
boolean duplicate = false;
final int N = cbs.size();
for (int i=0; i<N; i++) {
ModeCallback cb = cbs.valueAt(i);
ArrayList<ChangeRec> reports = callbacks.get(cb);
if (reports == null) {
reports = new ArrayList<>();
callbacks.put(cb, reports);
} else {
final int reportCount = reports.size();
for (int j = 0; j < reportCount; j++) {
ChangeRec report = reports.get(j);
if (report.op == op && report.pkg.equals(packageName)) {
duplicate = true;
break;
}
}
}
if (!duplicate) {
reports.add(new ChangeRec(op, uid, packageName));
}
}
return callbacks;
}
private void commitUidPendingStateLocked(UidState uidState) {
final boolean lastForeground = uidState.state <= UID_STATE_LAST_NON_RESTRICTED;
final boolean nowForeground = uidState.pendingState <= UID_STATE_LAST_NON_RESTRICTED;
uidState.state = uidState.pendingState;
uidState.pendingStateCommitTime = 0;
if (uidState.hasForegroundWatchers && lastForeground != nowForeground) {
for (int fgi = uidState.foregroundOps.size() - 1; fgi >= 0; fgi--) {
if (!uidState.foregroundOps.valueAt(fgi)) {
continue;
}
final int code = uidState.foregroundOps.keyAt(fgi);
final ArraySet<ModeCallback> callbacks = mOpModeWatchers.get(code);
if (callbacks != null) {
for (int cbi = callbacks.size() - 1; cbi >= 0; cbi--) {
final ModeCallback callback = callbacks.valueAt(cbi);
if ((callback.mFlags & AppOpsManager.WATCH_FOREGROUND_CHANGES) == 0
|| !callback.isWatchingUid(uidState.uid)) {
continue;
}
boolean doAllPackages = uidState.opModes != null
&& uidState.opModes.get(code) == AppOpsManager.MODE_FOREGROUND;
if (uidState.pkgOps != null) {
for (int pkgi = uidState.pkgOps.size() - 1; pkgi >= 0; pkgi--) {
final Op op = uidState.pkgOps.valueAt(pkgi).get(code);
if (doAllPackages || (op != null
&& op.mode == AppOpsManager.MODE_FOREGROUND)) {
mHandler.sendMessage(PooledLambda.obtainMessage(
AppOpsService::notifyOpChanged,
this, callback, code, uidState.uid,
uidState.pkgOps.keyAt(pkgi)));
}
}
}
}
}
}
}
}
int collectFlags() {
int flags = 0;
for (int i=apps.size()-1; i>=0; i--) {
final ArraySet<ConnectionRecord> connections = apps.valueAt(i).connections;
for (int j=connections.size()-1; j>=0; j--) {
flags |= connections.valueAt(j).flags;
}
}
return flags;
}
private Diff diff(ZenModeConfig to) {
final Diff d = new Diff();
if (to == null) {
return d.addLine("config", "delete");
}
if (user != to.user) {
d.addLine("user", user, to.user);
}
if (allowAlarms != to.allowAlarms) {
d.addLine("allowAlarms", allowAlarms, to.allowAlarms);
}
if (allowMedia != to.allowMedia) {
d.addLine("allowMedia", allowMedia, to.allowMedia);
}
if (allowSystem != to.allowSystem) {
d.addLine("allowSystem", allowSystem, to.allowSystem);
}
if (allowCalls != to.allowCalls) {
d.addLine("allowCalls", allowCalls, to.allowCalls);
}
if (allowReminders != to.allowReminders) {
d.addLine("allowReminders", allowReminders, to.allowReminders);
}
if (allowEvents != to.allowEvents) {
d.addLine("allowEvents", allowEvents, to.allowEvents);
}
if (allowRepeatCallers != to.allowRepeatCallers) {
d.addLine("allowRepeatCallers", allowRepeatCallers, to.allowRepeatCallers);
}
if (allowMessages != to.allowMessages) {
d.addLine("allowMessages", allowMessages, to.allowMessages);
}
if (allowCallsFrom != to.allowCallsFrom) {
d.addLine("allowCallsFrom", allowCallsFrom, to.allowCallsFrom);
}
if (allowMessagesFrom != to.allowMessagesFrom) {
d.addLine("allowMessagesFrom", allowMessagesFrom, to.allowMessagesFrom);
}
if (suppressedVisualEffects != to.suppressedVisualEffects) {
d.addLine("suppressedVisualEffects", suppressedVisualEffects,
to.suppressedVisualEffects);
}
final ArraySet<String> allRules = new ArraySet<>();
addKeys(allRules, automaticRules);
addKeys(allRules, to.automaticRules);
final int N = allRules.size();
for (int i = 0; i < N; i++) {
final String rule = allRules.valueAt(i);
final ZenRule fromRule = automaticRules != null ? automaticRules.get(rule) : null;
final ZenRule toRule = to.automaticRules != null ? to.automaticRules.get(rule) : null;
ZenRule.appendDiff(d, "automaticRule[" + rule + "]", fromRule, toRule);
}
ZenRule.appendDiff(d, "manualRule", manualRule, to.manualRule);
if (areChannelsBypassingDnd != to.areChannelsBypassingDnd) {
d.addLine("areChannelsBypassingDnd", areChannelsBypassingDnd,
to.areChannelsBypassingDnd);
}
return d;
}
@Override
public void onBootPhase(int phase) {
if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
LocalServices.getService(ActivityManagerInternal.class)
.registerScreenObserver(this);
mNotificationManager = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
synchronized (mLock) {
Looper looper = Looper.getMainLooper();
Handler handler = new Handler(looper);
ArrayList<EnabledComponentChangeListener> listeners = new ArrayList<>();
listeners.add(this);
mComponentObserver = EnabledComponentsObserver.build(mContext, handler,
Settings.Secure.ENABLED_VR_LISTENERS, looper,
android.Manifest.permission.BIND_VR_LISTENER_SERVICE,
VrListenerService.SERVICE_INTERFACE, mLock, listeners);
mComponentObserver.rebuildAll();
}
//TODO: something more robust than picking the first one
ArraySet<ComponentName> defaultVrComponents =
SystemConfig.getInstance().getDefaultVrComponents();
if (defaultVrComponents.size() > 0) {
mDefaultVrService = defaultVrComponents.valueAt(0);
} else {
Slog.i(TAG, "No default vr listener service found.");
}
DisplayManager dm =
(DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
mVr2dDisplay = new Vr2dDisplay(
dm,
LocalServices.getService(ActivityManagerInternal.class),
LocalServices.getService(WindowManagerInternal.class),
mVrManager);
mVr2dDisplay.init(getContext(), mBootsToVr);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
getContext().registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_USER_UNLOCKED.equals(intent.getAction())) {
VrManagerService.this.setUserUnlocked();
}
}
}, intentFilter);
}
}