Search in sources :

Example 6 with MutableInt

use of android.util.MutableInt in project platform_frameworks_base by android.

the class IntentResolver method dumpMap.

boolean dumpMap(PrintWriter out, String titlePrefix, String title, String prefix, ArrayMap<String, F[]> map, String packageName, boolean printFilter, boolean collapseDuplicates) {
    final String eprefix = prefix + "  ";
    final String fprefix = prefix + "    ";
    final ArrayMap<Object, MutableInt> found = new ArrayMap<>();
    boolean printedSomething = false;
    Printer printer = null;
    for (int mapi = 0; mapi < map.size(); mapi++) {
        F[] a = map.valueAt(mapi);
        final int N = a.length;
        boolean printedHeader = false;
        F filter;
        if (collapseDuplicates && !printFilter) {
            found.clear();
            for (int i = 0; i < N && (filter = a[i]) != null; i++) {
                if (packageName != null && !isPackageForFilter(packageName, filter)) {
                    continue;
                }
                Object label = filterToLabel(filter);
                int index = found.indexOfKey(label);
                if (index < 0) {
                    found.put(label, new MutableInt(1));
                } else {
                    found.valueAt(index).value++;
                }
            }
            for (int i = 0; i < found.size(); i++) {
                if (title != null) {
                    out.print(titlePrefix);
                    out.println(title);
                    title = null;
                }
                if (!printedHeader) {
                    out.print(eprefix);
                    out.print(map.keyAt(mapi));
                    out.println(":");
                    printedHeader = true;
                }
                printedSomething = true;
                dumpFilterLabel(out, fprefix, found.keyAt(i), found.valueAt(i).value);
            }
        } else {
            for (int i = 0; i < N && (filter = a[i]) != null; i++) {
                if (packageName != null && !isPackageForFilter(packageName, filter)) {
                    continue;
                }
                if (title != null) {
                    out.print(titlePrefix);
                    out.println(title);
                    title = null;
                }
                if (!printedHeader) {
                    out.print(eprefix);
                    out.print(map.keyAt(mapi));
                    out.println(":");
                    printedHeader = true;
                }
                printedSomething = true;
                dumpFilter(out, fprefix, filter);
                if (printFilter) {
                    if (printer == null) {
                        printer = new PrintWriterPrinter(out);
                    }
                    filter.dump(printer, fprefix + "  ");
                }
            }
        }
    }
    return printedSomething;
}
Also used : PrintWriterPrinter(android.util.PrintWriterPrinter) MutableInt(android.util.MutableInt) ArrayMap(android.util.ArrayMap) PrintWriterPrinter(android.util.PrintWriterPrinter) LogPrinter(android.util.LogPrinter) Printer(android.util.Printer)

Example 7 with MutableInt

use of android.util.MutableInt in project android_frameworks_base by AOSPA.

the class IntentResolver method dumpMap.

boolean dumpMap(PrintWriter out, String titlePrefix, String title, String prefix, ArrayMap<String, F[]> map, String packageName, boolean printFilter, boolean collapseDuplicates) {
    final String eprefix = prefix + "  ";
    final String fprefix = prefix + "    ";
    final ArrayMap<Object, MutableInt> found = new ArrayMap<>();
    boolean printedSomething = false;
    Printer printer = null;
    for (int mapi = 0; mapi < map.size(); mapi++) {
        F[] a = map.valueAt(mapi);
        final int N = a.length;
        boolean printedHeader = false;
        F filter;
        if (collapseDuplicates && !printFilter) {
            found.clear();
            for (int i = 0; i < N && (filter = a[i]) != null; i++) {
                if (packageName != null && !isPackageForFilter(packageName, filter)) {
                    continue;
                }
                Object label = filterToLabel(filter);
                int index = found.indexOfKey(label);
                if (index < 0) {
                    found.put(label, new MutableInt(1));
                } else {
                    found.valueAt(index).value++;
                }
            }
            for (int i = 0; i < found.size(); i++) {
                if (title != null) {
                    out.print(titlePrefix);
                    out.println(title);
                    title = null;
                }
                if (!printedHeader) {
                    out.print(eprefix);
                    out.print(map.keyAt(mapi));
                    out.println(":");
                    printedHeader = true;
                }
                printedSomething = true;
                dumpFilterLabel(out, fprefix, found.keyAt(i), found.valueAt(i).value);
            }
        } else {
            for (int i = 0; i < N && (filter = a[i]) != null; i++) {
                if (packageName != null && !isPackageForFilter(packageName, filter)) {
                    continue;
                }
                if (title != null) {
                    out.print(titlePrefix);
                    out.println(title);
                    title = null;
                }
                if (!printedHeader) {
                    out.print(eprefix);
                    out.print(map.keyAt(mapi));
                    out.println(":");
                    printedHeader = true;
                }
                printedSomething = true;
                dumpFilter(out, fprefix, filter);
                if (printFilter) {
                    if (printer == null) {
                        printer = new PrintWriterPrinter(out);
                    }
                    filter.dump(printer, fprefix + "  ");
                }
            }
        }
    }
    return printedSomething;
}
Also used : PrintWriterPrinter(android.util.PrintWriterPrinter) MutableInt(android.util.MutableInt) ArrayMap(android.util.ArrayMap) PrintWriterPrinter(android.util.PrintWriterPrinter) LogPrinter(android.util.LogPrinter) Printer(android.util.Printer)

Example 8 with MutableInt

use of android.util.MutableInt in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppStorageSettings method refreshGrantedUriPermissions.

private void refreshGrantedUriPermissions() {
    // Clear UI first (in case the activity has been resumed)
    removeUriPermissionsFromUi();
    // Gets all URI permissions from am.
    ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    List<UriPermission> perms = am.getGrantedUriPermissions(mAppEntry.info.packageName).getList();
    if (perms.isEmpty()) {
        mClearUriButton.setVisibility(View.GONE);
        return;
    }
    PackageManager pm = getActivity().getPackageManager();
    // Group number of URIs by app.
    Map<CharSequence, MutableInt> uriCounters = new TreeMap<>();
    for (UriPermission perm : perms) {
        String authority = perm.getUri().getAuthority();
        ProviderInfo provider = pm.resolveContentProvider(authority, 0);
        CharSequence app = provider.applicationInfo.loadLabel(pm);
        MutableInt count = uriCounters.get(app);
        if (count == null) {
            uriCounters.put(app, new MutableInt(1));
        } else {
            count.value++;
        }
    }
    // Dynamically add the preferences, one per app.
    int order = 0;
    for (Map.Entry<CharSequence, MutableInt> entry : uriCounters.entrySet()) {
        int numberResources = entry.getValue().value;
        Preference pref = new Preference(getPrefContext());
        pref.setTitle(entry.getKey());
        pref.setSummary(getPrefContext().getResources().getQuantityString(R.plurals.uri_permissions_text, numberResources, numberResources));
        pref.setSelectable(false);
        pref.setLayoutResource(R.layout.horizontal_preference);
        pref.setOrder(order);
        Log.v(TAG, "Adding preference '" + pref + "' at order " + order);
        mUri.addPreference(pref);
    }
    if (mAppsControlDisallowedBySystem) {
        mClearUriButton.setEnabled(false);
    }
    mClearUri.setOrder(order);
    mClearUriButton.setVisibility(View.VISIBLE);
}
Also used : ActivityManager(android.app.ActivityManager) TreeMap(java.util.TreeMap) PackageManager(android.content.pm.PackageManager) ProviderInfo(android.content.pm.ProviderInfo) Preference(android.support.v7.preference.Preference) MutableInt(android.util.MutableInt) UriPermission(android.content.UriPermission) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 9 with MutableInt

use of android.util.MutableInt in project android_frameworks_base by crdroidandroid.

the class SQLiteConnection method collectDbStats.

/**
     * Collects statistics about database connection memory usage.
     *
     * @param dbStatsList The list to populate.
     */
void collectDbStats(ArrayList<DbStats> dbStatsList) {
    // Get information about the main database.
    int lookaside = nativeGetDbLookaside(mConnectionPtr);
    long pageCount = 0;
    long pageSize = 0;
    try {
        pageCount = executeForLong("PRAGMA page_count;", null, null);
        pageSize = executeForLong("PRAGMA page_size;", null, null);
    } catch (SQLiteException ex) {
    // Ignore.
    }
    dbStatsList.add(getMainDbStatsUnsafe(lookaside, pageCount, pageSize));
    // Get information about attached databases.
    // We ignore the first row in the database list because it corresponds to
    // the main database which we have already described.
    CursorWindow window = new CursorWindow("collectDbStats");
    MutableBoolean exh = new MutableBoolean(false);
    MutableInt seen = new MutableInt(0);
    try {
        executeForCursorWindow("PRAGMA database_list;", null, window, 0, 0, false, null, exh, seen, null);
        for (int i = 1; i < window.getNumRows(); i++) {
            String name = window.getString(i, 1);
            String path = window.getString(i, 2);
            pageCount = 0;
            pageSize = 0;
            try {
                pageCount = executeForLong("PRAGMA " + name + ".page_count;", null, null);
                pageSize = executeForLong("PRAGMA " + name + ".page_size;", null, null);
            } catch (SQLiteException ex) {
            // Ignore.
            }
            String label = "  (attached) " + name;
            if (!path.isEmpty()) {
                label += ": " + path;
            }
            dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0));
        }
    } catch (SQLiteException ex) {
    // Ignore.
    } finally {
        window.close();
    }
}
Also used : MutableBoolean(android.util.MutableBoolean) MutableInt(android.util.MutableInt) CursorWindow(android.database.CursorWindow) DbStats(android.database.sqlite.SQLiteDebug.DbStats)

Aggregations

MutableInt (android.util.MutableInt)9 ArrayMap (android.util.ArrayMap)5 LogPrinter (android.util.LogPrinter)5 PrintWriterPrinter (android.util.PrintWriterPrinter)5 Printer (android.util.Printer)5 ActivityManager (android.app.ActivityManager)1 UriPermission (android.content.UriPermission)1 PackageManager (android.content.pm.PackageManager)1 ProviderInfo (android.content.pm.ProviderInfo)1 CursorWindow (android.database.CursorWindow)1 DbStats (android.database.sqlite.SQLiteDebug.DbStats)1 Preference (android.support.v7.preference.Preference)1 MutableBoolean (android.util.MutableBoolean)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1