Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a283fc95 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Add new API to retrieve a dumpsys of a single package."

parents 4d3adce0 cbfd23ee
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -16,8 +16,7 @@

package com.android.commands.pm;

import com.android.internal.content.PackageHelper;

import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.content.ComponentName;
import android.content.pm.ApplicationInfo;
@@ -46,6 +45,7 @@ import android.os.UserHandle;
import android.os.UserManager;

import java.io.File;
import java.io.FileDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.security.InvalidAlgorithmParameterException;
@@ -59,6 +59,8 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import com.android.internal.content.PackageHelper;

public final class Pm {
    IPackageManager mPm;
    IUserManager mUm;
@@ -105,6 +107,11 @@ public final class Pm {
            return;
        }

        if ("dump".equals(op)) {
            runDump();
            return;
        }

        if ("install".equals(op)) {
            runInstall();
            return;
@@ -672,6 +679,15 @@ public final class Pm {
        displayPackageFilePath(pkg);
    }

    private void runDump() {
        String pkg = nextArg();
        if (pkg == null) {
            System.err.println("Error: no package specified");
            return;
        }
        ActivityManager.dumpPackageStateStatic(FileDescriptor.out, pkg);
    }

    class PackageInstallObserver extends IPackageInstallObserver.Stub {
        boolean finished;
        int result;
@@ -1456,6 +1472,7 @@ public final class Pm {
        System.err.println("       pm list libraries");
        System.err.println("       pm list users");
        System.err.println("       pm path PACKAGE");
        System.err.println("       pm dump PACKAGE");
        System.err.println("       pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f]");
        System.err.println("                  [--algo <algorithm name> --key <key-in-hex> --iv <IV-in-hex>]");
        System.err.println("                  [--originating-uri <URI>] [--referrer <URI>] PATH");
@@ -1506,6 +1523,8 @@ public final class Pm {
        System.err.println("");
        System.err.println("pm path: print the path to the .apk of the given PACKAGE.");
        System.err.println("");
        System.err.println("pm dump: print system state associated w ith the given PACKAGE.");
        System.err.println("");
        System.err.println("pm install: installs a package to the system.  Options:");
        System.err.println("    -l: install the package with FORWARD_LOCK.");
        System.err.println("    -r: reinstall an exisiting app, keeping its data.");
+56 −1
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package android.app;

import android.os.IBinder;
import com.android.internal.app.IUsageStats;
import com.android.internal.os.PkgUsageStats;
import com.android.internal.os.TransferPipe;
import com.android.internal.util.MemInfoReader;

import android.content.ComponentName;
@@ -49,6 +51,9 @@ import android.util.Log;
import android.util.Slog;
import android.view.Display;

import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -1709,7 +1714,7 @@ public class ActivityManager {
        public ComponentName importanceReasonComponent;
        
        /**
         * When {@link importanceReasonPid} is non-0, this is the importance
         * When {@link #importanceReasonPid} is non-0, this is the importance
         * of the other pid. @hide
         */
        public int importanceReasonImportance;
@@ -2181,4 +2186,54 @@ public class ActivityManager {
            return false;
        }
    }

    /**
     * Perform a system dump of various state associated with the given application
     * package name.  This call blocks while the dump is being performed, so should
     * not be done on a UI thread.  The data will be written to the given file
     * descriptor as text.  An application must hold the
     * {@link android.Manifest.permission#DUMP} permission to make this call.
     * @param fd The file descriptor that the dump should be written to.
     * @param packageName The name of the package that is to be dumped.
     */
    public void dumpPackageState(FileDescriptor fd, String packageName) {
        dumpPackageStateStatic(fd, packageName);
    }

    /**
     * @hide
     */
    public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
        FileOutputStream fout = new FileOutputStream(fd);
        PrintWriter pw = new PrintWriter(fout);
        dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { "package", packageName});
        pw.println();
        dumpService(pw, fd, "package", new String[] { packageName});
        pw.println();
        dumpService(pw, fd, "batteryinfo", new String[] { packageName});
        pw.flush();
    }

    private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
        pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
        IBinder service = ServiceManager.checkService(name);
        if (service == null) {
            pw.println("  (Service not found)");
            return;
        }
        TransferPipe tp = null;
        try {
            pw.flush();
            tp = new TransferPipe();
            tp.setBufferPrefix("  ");
            service.dump(tp.getWriteFd().getFileDescriptor(), args);
            tp.go(fd);
        } catch (Throwable e) {
            if (tp != null) {
                tp.kill();
            }
            pw.println("Failure dumping service:");
            e.printStackTrace(pw);
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -2279,7 +2279,7 @@ public abstract class BatteryStats implements Parcelable {
     * @param pw a Printer to receive the dump output.
     */
    @SuppressWarnings("unused")
    public void dumpLocked(PrintWriter pw, boolean isUnpluggedOnly) {
    public void dumpLocked(PrintWriter pw, boolean isUnpluggedOnly, int reqUid) {
        prepareForDumpLocked();

        long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
@@ -2336,11 +2336,11 @@ public abstract class BatteryStats implements Parcelable {
            pw.println("Statistics since last charge:");
            pw.println("  System starts: " + getStartCount()
                    + ", currently on battery: " + getIsOnBattery());
            dumpLocked(pw, "", STATS_SINCE_CHARGED, -1);
            dumpLocked(pw, "", STATS_SINCE_CHARGED, reqUid);
            pw.println("");
        }
        pw.println("Statistics since last unplugged:");
        dumpLocked(pw, "", STATS_SINCE_UNPLUGGED, -1);
        dumpLocked(pw, "", STATS_SINCE_UNPLUGGED, reqUid);
    }
    
    @SuppressWarnings("unused")
+2 −2
Original line number Diff line number Diff line
@@ -6038,7 +6038,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        updateNetworkActivityLocked();
    }

    public void dumpLocked(PrintWriter pw, boolean isUnpluggedOnly) {
    public void dumpLocked(PrintWriter pw, boolean isUnpluggedOnly, int reqUid) {
        if (DEBUG) {
            Printer pr = new PrintWriterPrinter(pw);
            pr.println("*** Screen timer:");
@@ -6068,6 +6068,6 @@ public final class BatteryStatsImpl extends BatteryStats {
            pr.println("*** Bluetooth timer:");
            mBluetoothOnTimer.logState(pr, "  ");
        }
        super.dumpLocked(pw, isUnpluggedOnly);
        super.dumpLocked(pw, isUnpluggedOnly, reqUid);
    }
}
+8 −8
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.server.am;
package com.android.internal.os;

import java.io.FileDescriptor;
import java.io.FileInputStream;
@@ -32,7 +32,7 @@ import android.util.Slog;
/**
 * Helper for transferring data through a pipe from a client app.
 */
final class TransferPipe implements Runnable {
public final class TransferPipe implements Runnable {
    static final String TAG = "TransferPipe";
    static final boolean DEBUG = false;

@@ -53,7 +53,7 @@ final class TransferPipe implements Runnable {
                String[] args) throws RemoteException;
    }

    TransferPipe() throws IOException {
    public TransferPipe() throws IOException {
        mThread = new Thread(this, "TransferPipe");
        mFds = ParcelFileDescriptor.createPipe();
    }
@@ -62,11 +62,11 @@ final class TransferPipe implements Runnable {
        return mFds[0];
    }

    ParcelFileDescriptor getWriteFd() {
    public ParcelFileDescriptor getWriteFd() {
        return mFds[1];
    }

    void setBufferPrefix(String prefix) {
    public void setBufferPrefix(String prefix) {
        mBufferPrefix = prefix;
    }

@@ -120,11 +120,11 @@ final class TransferPipe implements Runnable {
        }
    }

    void go(FileDescriptor out) throws IOException {
    public void go(FileDescriptor out) throws IOException {
        go(out, DEFAULT_TIMEOUT);
    }

    void go(FileDescriptor out, long timeout) throws IOException {
    public void go(FileDescriptor out, long timeout) throws IOException {
        try {
            synchronized (this) {
                mOutFd = out;
@@ -173,7 +173,7 @@ final class TransferPipe implements Runnable {
        }
    }

    void kill() {
    public void kill() {
        closeFd(0);
        closeFd(1);
    }
Loading