use of android.util.SparseArray in project android_frameworks_base by ResurrectionRemix.
the class ProcessStats method dumpCheckinLocked.
public void dumpCheckinLocked(PrintWriter pw, String reqPackage) {
final long now = SystemClock.uptimeMillis();
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
pw.println("vers,5");
pw.print("period,");
pw.print(mTimePeriodStartClockStr);
pw.print(",");
pw.print(mTimePeriodStartRealtime);
pw.print(",");
pw.print(mRunning ? SystemClock.elapsedRealtime() : mTimePeriodEndRealtime);
boolean partial = true;
if ((mFlags & FLAG_SHUTDOWN) != 0) {
pw.print(",shutdown");
partial = false;
}
if ((mFlags & FLAG_SYSPROPS) != 0) {
pw.print(",sysprops");
partial = false;
}
if ((mFlags & FLAG_COMPLETE) != 0) {
pw.print(",complete");
partial = false;
}
if (partial) {
pw.print(",partial");
}
if (mHasSwappedOutPss) {
pw.print(",swapped-out-pss");
}
pw.println();
pw.print("config,");
pw.println(mRuntime);
for (int ip = 0; ip < pkgMap.size(); ip++) {
final String pkgName = pkgMap.keyAt(ip);
if (reqPackage != null && !reqPackage.equals(pkgName)) {
continue;
}
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
final int uid = uids.keyAt(iu);
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
for (int iv = 0; iv < vpkgs.size(); iv++) {
final int vers = vpkgs.keyAt(iv);
final PackageState pkgState = vpkgs.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
final int NSRVS = pkgState.mServices.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState proc = pkgState.mProcesses.valueAt(iproc);
proc.dumpPackageProcCheckin(pw, pkgName, uid, vers, pkgState.mProcesses.keyAt(iproc), now);
}
for (int isvc = 0; isvc < NSRVS; isvc++) {
final String serviceName = DumpUtils.collapseString(pkgName, pkgState.mServices.keyAt(isvc));
final ServiceState svc = pkgState.mServices.valueAt(isvc);
svc.dumpTimesCheckin(pw, pkgName, uid, vers, serviceName, now);
}
}
}
}
ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
for (int ip = 0; ip < procMap.size(); ip++) {
String procName = procMap.keyAt(ip);
SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
final int uid = uids.keyAt(iu);
final ProcessState procState = uids.valueAt(iu);
procState.dumpProcCheckin(pw, procName, uid, now);
}
}
pw.print("total");
DumpUtils.dumpAdjTimesCheckin(pw, ",", mMemFactorDurations, mMemFactor, mStartTime, now);
pw.println();
final int sysMemUsageCount = mSysMemUsage.getKeyCount();
if (sysMemUsageCount > 0) {
pw.print("sysmemusage");
for (int i = 0; i < sysMemUsageCount; i++) {
final int key = mSysMemUsage.getKeyAt(i);
final int type = SparseMappingTable.getIdFromKey(key);
pw.print(",");
DumpUtils.printProcStateTag(pw, type);
for (int j = SYS_MEM_USAGE_SAMPLE_COUNT; j < SYS_MEM_USAGE_COUNT; j++) {
if (j > SYS_MEM_USAGE_CACHED_MINIMUM) {
pw.print(":");
}
pw.print(mSysMemUsage.getValue(key, j));
}
}
}
pw.println();
TotalMemoryUseCollection totalMem = new TotalMemoryUseCollection(ALL_SCREEN_ADJ, ALL_MEM_ADJ);
computeTotalMemoryUse(totalMem, now);
pw.print("weights,");
pw.print(totalMem.totalTime);
pw.print(",");
pw.print(totalMem.sysMemCachedWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
pw.print(",");
pw.print(totalMem.sysMemFreeWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
pw.print(",");
pw.print(totalMem.sysMemZRamWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
pw.print(",");
pw.print(totalMem.sysMemKernelWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
pw.print(",");
pw.print(totalMem.sysMemNativeWeight);
pw.print(":");
pw.print(totalMem.sysMemSamples);
for (int i = 0; i < STATE_COUNT; i++) {
pw.print(",");
pw.print(totalMem.processStateWeight[i]);
pw.print(":");
pw.print(totalMem.processStateSamples[i]);
}
pw.println();
final int NPAGETYPES = mPageTypeLabels.size();
for (int i = 0; i < NPAGETYPES; i++) {
pw.print("availablepages,");
pw.print(mPageTypeLabels.get(i));
pw.print(",");
pw.print(mPageTypeZones.get(i));
pw.print(",");
final int[] sizes = mPageTypeSizes.get(i);
final int N = sizes == null ? 0 : sizes.length;
for (int j = 0; j < N; j++) {
if (j != 0) {
pw.print(",");
}
pw.print(sizes[j]);
}
pw.println();
}
}
use of android.util.SparseArray in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DataUsageList method bindStats.
/**
* Bind the given {@link NetworkStats}, or {@code null} to clear list.
*/
public void bindStats(NetworkStats stats, int[] restrictedUids) {
ArrayList<AppItem> items = new ArrayList<>();
long largest = 0;
final int currentUserId = ActivityManager.getCurrentUser();
UserManager userManager = UserManager.get(getContext());
final List<UserHandle> profiles = userManager.getUserProfiles();
final SparseArray<AppItem> knownItems = new SparseArray<AppItem>();
PackageManager pm = getContext().getPackageManager();
ApplicationInfo ai = null;
try {
ai = pm.getApplicationInfo("com.android.dialer", PackageManager.GET_ACTIVITIES);
} catch (Exception e) {
Log.d(TAG, "get dialer getApplicationInfo failed " + e);
}
NetworkStats.Entry entry = null;
final int size = stats != null ? stats.size() : 0;
for (int i = 0; i < size; i++) {
entry = stats.getValues(i, entry);
// Decide how to collapse items together
final int uid = entry.uid;
final int collapseKey;
final int category;
final int userId = UserHandle.getUserId(uid);
if (UserHandle.isApp(uid)) {
if (profiles.contains(new UserHandle(userId))) {
if (userId != currentUserId) {
// Add to a managed user item.
final int managedKey = UidDetailProvider.buildKeyForUser(userId);
largest = accumulate(managedKey, knownItems, entry, AppItem.CATEGORY_USER, items, largest);
}
// Add to app item.
collapseKey = uid;
category = AppItem.CATEGORY_APP;
} else {
// If it is a removed user add it to the removed users' key
final UserInfo info = userManager.getUserInfo(userId);
if (info == null) {
collapseKey = UID_REMOVED;
category = AppItem.CATEGORY_APP;
} else {
// Add to other user item.
collapseKey = UidDetailProvider.buildKeyForUser(userId);
category = AppItem.CATEGORY_USER;
}
}
} else if (uid == UID_REMOVED || uid == UID_TETHERING) {
collapseKey = uid;
category = AppItem.CATEGORY_APP;
} else if ((ai != null) && (uid == ai.uid) && getContext().getResources().getBoolean(com.android.internal.R.bool.config_video_call_datausage_enable)) {
collapseKey = uid;
category = AppItem.CATEGORY_APP;
} else {
collapseKey = android.os.Process.SYSTEM_UID;
category = AppItem.CATEGORY_APP;
}
largest = accumulate(collapseKey, knownItems, entry, category, items, largest);
}
final int restrictedUidsMax = restrictedUids.length;
for (int i = 0; i < restrictedUidsMax; ++i) {
final int uid = restrictedUids[i];
// Only splice in restricted state for current user or managed users
if (!profiles.contains(new UserHandle(UserHandle.getUserId(uid)))) {
continue;
}
AppItem item = knownItems.get(uid);
if (item == null) {
item = new AppItem(uid);
item.total = -1;
items.add(item);
knownItems.put(item.key, item);
}
item.restricted = true;
}
Collections.sort(items);
mApps.removeAll();
for (int i = 0; i < items.size(); i++) {
final int percentTotal = largest != 0 ? (int) (items.get(i).total * 100 / largest) : 0;
AppDataUsagePreference preference = new AppDataUsagePreference(getContext(), items.get(i), percentTotal, mUidDetailProvider);
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
AppDataUsagePreference pref = (AppDataUsagePreference) preference;
AppItem item = pref.getItem();
startAppDataUsage(item);
return true;
}
});
mApps.addPreference(preference);
}
}
use of android.util.SparseArray in project UltimateAndroid by cymcsg.
the class FixedGridLayoutManager method fillGrid.
private void fillGrid(int direction, int emptyLeft, int emptyTop, RecyclerView.Recycler recycler) {
if (mFirstVisiblePosition < 0)
mFirstVisiblePosition = 0;
if (mFirstVisiblePosition >= getItemCount())
mFirstVisiblePosition = (getItemCount() - 1);
/*
* First, we will detach all existing views from the layout.
* detachView() is a lightweight operation that we can use to
* quickly reorder views without a full add/remove.
*/
SparseArray<View> viewCache = new SparseArray<View>(getChildCount());
int startLeftOffset = getPaddingLeft() + emptyLeft;
int startTopOffset = getPaddingTop() + emptyTop;
if (getChildCount() != 0) {
final View topView = getChildAt(0);
startLeftOffset = getDecoratedLeft(topView);
startTopOffset = getDecoratedTop(topView);
switch(direction) {
case DIRECTION_START:
startLeftOffset -= mDecoratedChildWidth;
break;
case DIRECTION_END:
startLeftOffset += mDecoratedChildWidth;
break;
case DIRECTION_UP:
startTopOffset -= mDecoratedChildHeight;
break;
case DIRECTION_DOWN:
startTopOffset += mDecoratedChildHeight;
break;
}
//Cache all views by their existing position, before updating counts
for (int i = 0; i < getChildCount(); i++) {
int position = positionOfIndex(i);
final View child = getChildAt(i);
viewCache.put(position, child);
}
// Views we still need will be added back at the proper index.
for (int i = 0; i < viewCache.size(); i++) {
detachView(viewCache.valueAt(i));
}
}
/*
* Next, we advance the visible position based on the fill direction.
* DIRECTION_NONE doesn't advance the position in any direction.
*/
switch(direction) {
case DIRECTION_START:
mFirstVisiblePosition--;
break;
case DIRECTION_END:
mFirstVisiblePosition++;
break;
case DIRECTION_UP:
mFirstVisiblePosition -= getTotalColumnCount();
break;
case DIRECTION_DOWN:
mFirstVisiblePosition += getTotalColumnCount();
break;
}
/*
* Next, we supply the grid of items that are deemed visible.
* If these items were previously there, they will simple be
* re-attached. New views that must be created are obtained
* from the Recycler and added.
*/
int leftOffset = startLeftOffset;
int topOffset = startTopOffset;
for (int i = 0; i < getVisibleChildCount(); i++) {
int nextPosition = positionOfIndex(i);
if (nextPosition >= getItemCount()) {
//Item space beyond the data set, don't attempt to add a view
continue;
}
//Layout this position
View view = viewCache.get(nextPosition);
if (view == null) {
/*
* The Recycler will give us either a newly constructed view,
* or a recycled view it has on-hand. In either case, the
* view will already be fully bound to the data by the
* adapter for us.
*/
view = recycler.getViewForPosition(nextPosition);
addView(view);
/*
* It is prudent to measure/layout each new view we
* receive from the Recycler. We don't have to do
* this for views we are just re-arranging.
*/
measureChildWithMargins(view, 0, 0);
layoutDecorated(view, leftOffset, topOffset, leftOffset + mDecoratedChildWidth, topOffset + mDecoratedChildHeight);
} else {
//Re-attach the cached view at its new index
attachView(view);
viewCache.remove(nextPosition);
}
if (i % mVisibleColumnCount == (mVisibleColumnCount - 1)) {
leftOffset = startLeftOffset;
topOffset += mDecoratedChildHeight;
//If we wrapped without setting the column count, we've reached it
} else {
leftOffset += mDecoratedChildWidth;
}
}
/*
* Finally, we ask the Recycler to scrap and store any views
* that we did not re-attach. These are views that are not currently
* necessary because they are no longer visible.
*/
for (int i = 0; i < viewCache.size(); i++) {
recycler.recycleView(viewCache.valueAt(i));
}
}
use of android.util.SparseArray in project Douya by DreaminginCodeZH.
the class TabViewPagerAdapter method saveState.
@Override
public Parcelable saveState() {
Bundle state = new Bundle();
for (int i = 0; i < mViews.length; ++i) {
SparseArray<Parcelable> hierarchyState = new SparseArray<>();
mViews[i].saveHierarchyState(hierarchyState);
state.putSparseParcelableArray(makeHierarchyStateKey(i), hierarchyState);
}
return state;
}
use of android.util.SparseArray in project HomeMirror by HannahMitt.
the class MoodModule method createCameraSource.
/**
* Creates and starts the camera. Note that this uses a higher resolution in comparison
* to other detection examples to enable the barcode detector to detect small barcodes
* at long distances.
*/
private void createCameraSource() {
Context context = mContextWeakReference.get();
FaceDetector detector = new FaceDetector.Builder(context).setClassificationType(FaceDetector.ALL_CLASSIFICATIONS).build();
detector.setProcessor(new Detector.Processor<Face>() {
@Override
public void release() {
}
@Override
public void receiveDetections(final Detector.Detections<Face> detections) {
final SparseArray<Face> detectedItems = detections.getDetectedItems();
if (detectedItems.size() != 0) {
final int key = detectedItems.keyAt(0);
final Face face = detectedItems.get(key);
final float isSmilingProbability = face.getIsSmilingProbability();
String feedback = getFeedbackForSmileProbability(isSmilingProbability);
mCallBacks.onShouldGivePositiveAffirmation(feedback);
}
}
});
if (!detector.isOperational()) {
// Note: The first time that an app using face API is installed on a device, GMS will
// download a native library to the device in order to do detection. Usually this
// completes before the app is run for the first time. But if that download has not yet
// completed, then the above call will not detect any faces.
//
// isOperational() can be used to check if the required native library is currently
// available. The detector will automatically become operational once the library
// download completes on device.
Log.w(TAG, "Face detector dependencies are not yet available.");
}
try {
mCameraSource = new CameraSource.Builder(context, detector).setRequestedPreviewSize(640, 480).setFacing(CameraSource.CAMERA_FACING_FRONT).setRequestedFps(30.0f).build();
mCameraSource.start();
} catch (IOException | RuntimeException e) {
Log.e(TAG, "Something went horribly wrong, with your face.", e);
}
}
Aggregations