Java Code Examples for com.android.internal.util.DumpUtils#checkDumpAndUsageStatsPermission()

The following examples show how to use com.android.internal.util.DumpUtils#checkDumpAndUsageStatsPermission() . 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: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
protected synchronized void dump(FileDescriptor fd, PrintWriter pw_, String[] args) {
    if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw_)) return;
    final IndentingPrintWriter pw = new IndentingPrintWriter(pw_, "  ");

    final boolean dumpAll = ArrayUtils.contains(args, "-a");

    // This makes it so that future permission checks will be in the context of this
    // process rather than the caller's process. We will restore this before returning.
    final long identityToken = clearCallingIdentity();
    try {
        if (mSyncManager == null) {
            pw.println("No SyncManager created!  (Disk full?)");
        } else {
            mSyncManager.dump(fd, pw, dumpAll);
        }
        pw.println();
        pw.println("Observer tree:");
        synchronized (mRootNode) {
            int[] counts = new int[2];
            final SparseIntArray pidCounts = new SparseIntArray();
            mRootNode.dumpLocked(fd, pw, args, "", "  ", counts, pidCounts);
            pw.println();
            ArrayList<Integer> sorted = new ArrayList<Integer>();
            for (int i=0; i<pidCounts.size(); i++) {
                sorted.add(pidCounts.keyAt(i));
            }
            Collections.sort(sorted, new Comparator<Integer>() {
                @Override
                public int compare(Integer lhs, Integer rhs) {
                    int lc = pidCounts.get(lhs);
                    int rc = pidCounts.get(rhs);
                    if (lc < rc) {
                        return 1;
                    } else if (lc > rc) {
                        return -1;
                    }
                    return 0;
                }

            });
            for (int i=0; i<sorted.size(); i++) {
                int pid = sorted.get(i);
                pw.print("  pid "); pw.print(pid); pw.print(": ");
                pw.print(pidCounts.get(pid)); pw.println(" observers");
            }
            pw.println();
            pw.print(" Total number of nodes: "); pw.println(counts[0]);
            pw.print(" Total number of observers: "); pw.println(counts[1]);
        }

        synchronized (mCache) {
            pw.println();
            pw.println("Cached content:");
            pw.increaseIndent();
            for (int i = 0; i < mCache.size(); i++) {
                pw.println("User " + mCache.keyAt(i) + ":");
                pw.increaseIndent();
                pw.println(mCache.valueAt(i));
                pw.decreaseIndent();
            }
            pw.decreaseIndent();
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
 
Example 2
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
protected synchronized void dump(FileDescriptor fd, PrintWriter pw_, String[] args) {
    if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw_)) return;
    final IndentingPrintWriter pw = new IndentingPrintWriter(pw_, "  ");

    final boolean dumpAll = ArrayUtils.contains(args, "-a");

    // This makes it so that future permission checks will be in the context of this
    // process rather than the caller's process. We will restore this before returning.
    final long identityToken = clearCallingIdentity();
    try {
        if (mSyncManager == null) {
            pw.println("SyncManager not available yet");
        } else {
            mSyncManager.dump(fd, pw, dumpAll);
        }
        pw.println();
        pw.println("Observer tree:");
        synchronized (mRootNode) {
            int[] counts = new int[2];
            final SparseIntArray pidCounts = new SparseIntArray();
            mRootNode.dumpLocked(fd, pw, args, "", "  ", counts, pidCounts);
            pw.println();
            ArrayList<Integer> sorted = new ArrayList<Integer>();
            for (int i=0; i<pidCounts.size(); i++) {
                sorted.add(pidCounts.keyAt(i));
            }
            Collections.sort(sorted, new Comparator<Integer>() {
                @Override
                public int compare(Integer lhs, Integer rhs) {
                    int lc = pidCounts.get(lhs);
                    int rc = pidCounts.get(rhs);
                    if (lc < rc) {
                        return 1;
                    } else if (lc > rc) {
                        return -1;
                    }
                    return 0;
                }

            });
            for (int i=0; i<sorted.size(); i++) {
                int pid = sorted.get(i);
                pw.print("  pid "); pw.print(pid); pw.print(": ");
                pw.print(pidCounts.get(pid)); pw.println(" observers");
            }
            pw.println();
            pw.print(" Total number of nodes: "); pw.println(counts[0]);
            pw.print(" Total number of observers: "); pw.println(counts[1]);

            sObserverDeathDispatcher.dump(pw, " ");
        }
        synchronized (sObserverLeakDetectedUid) {
            pw.println();
            pw.print("Observer leaking UIDs: ");
            pw.println(sObserverLeakDetectedUid.toString());
        }

        synchronized (mCache) {
            pw.println();
            pw.println("Cached content:");
            pw.increaseIndent();
            for (int i = 0; i < mCache.size(); i++) {
                pw.println("User " + mCache.keyAt(i) + ":");
                pw.increaseIndent();
                pw.println(mCache.valueAt(i));
                pw.decreaseIndent();
            }
            pw.decreaseIndent();
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
 
Example 3
Source File: JobSchedulerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * "dumpsys" infrastructure
 */
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (!DumpUtils.checkDumpAndUsageStatsPermission(getContext(), TAG, pw)) return;

    int filterUid = -1;
    boolean proto = false;
    if (!ArrayUtils.isEmpty(args)) {
        int opti = 0;
        while (opti < args.length) {
            String arg = args[opti];
            if ("-h".equals(arg)) {
                dumpHelp(pw);
                return;
            } else if ("-a".equals(arg)) {
                // Ignore, we always dump all.
            } else if ("--proto".equals(arg)) {
                proto = true;
            } else if (arg.length() > 0 && arg.charAt(0) == '-') {
                pw.println("Unknown option: " + arg);
                return;
            } else {
                break;
            }
            opti++;
        }
        if (opti < args.length) {
            String pkg = args[opti];
            try {
                filterUid = getContext().getPackageManager().getPackageUid(pkg,
                        PackageManager.MATCH_ANY_USER);
            } catch (NameNotFoundException ignored) {
                pw.println("Invalid package: " + pkg);
                return;
            }
        }
    }

    final long identityToken = Binder.clearCallingIdentity();
    try {
        if (proto) {
            JobSchedulerService.this.dumpInternalProto(fd, filterUid);
        } else {
            JobSchedulerService.this.dumpInternal(new IndentingPrintWriter(pw, "  "),
                    filterUid);
        }
    } finally {
        Binder.restoreCallingIdentity(identityToken);
    }
}
 
Example 4
Source File: ContentService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
protected synchronized void dump(FileDescriptor fd, PrintWriter pw_, String[] args) {
    if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw_)) return;
    final IndentingPrintWriter pw = new IndentingPrintWriter(pw_, "  ");

    final boolean dumpAll = ArrayUtils.contains(args, "-a");

    // This makes it so that future permission checks will be in the context of this
    // process rather than the caller's process. We will restore this before returning.
    final long identityToken = clearCallingIdentity();
    try {
        if (mSyncManager == null) {
            pw.println("SyncManager not available yet");
        } else {
            mSyncManager.dump(fd, pw, dumpAll);
        }
        pw.println();
        pw.println("Observer tree:");
        synchronized (mRootNode) {
            int[] counts = new int[2];
            final SparseIntArray pidCounts = new SparseIntArray();
            mRootNode.dumpLocked(fd, pw, args, "", "  ", counts, pidCounts);
            pw.println();
            ArrayList<Integer> sorted = new ArrayList<Integer>();
            for (int i=0; i<pidCounts.size(); i++) {
                sorted.add(pidCounts.keyAt(i));
            }
            Collections.sort(sorted, new Comparator<Integer>() {
                @Override
                public int compare(Integer lhs, Integer rhs) {
                    int lc = pidCounts.get(lhs);
                    int rc = pidCounts.get(rhs);
                    if (lc < rc) {
                        return 1;
                    } else if (lc > rc) {
                        return -1;
                    }
                    return 0;
                }

            });
            for (int i=0; i<sorted.size(); i++) {
                int pid = sorted.get(i);
                pw.print("  pid "); pw.print(pid); pw.print(": ");
                pw.print(pidCounts.get(pid)); pw.println(" observers");
            }
            pw.println();
            pw.print(" Total number of nodes: "); pw.println(counts[0]);
            pw.print(" Total number of observers: "); pw.println(counts[1]);
        }

        synchronized (mCache) {
            pw.println();
            pw.println("Cached content:");
            pw.increaseIndent();
            for (int i = 0; i < mCache.size(); i++) {
                pw.println("User " + mCache.keyAt(i) + ":");
                pw.increaseIndent();
                pw.println(mCache.valueAt(i));
                pw.decreaseIndent();
            }
            pw.decreaseIndent();
        }
    } finally {
        restoreCallingIdentity(identityToken);
    }
}
 
Example 5
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw)) return;
    dumpNoCheck(fd, pw, args);
}