Search in sources :

Example 51 with IndentingPrintWriter

use of com.android.internal.util.IndentingPrintWriter in project android_frameworks_base by ResurrectionRemix.

the class UsbService method dump.

@Override
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
    final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
    final long ident = Binder.clearCallingIdentity();
    try {
        if (args == null || args.length == 0 || "-a".equals(args[0])) {
            pw.println("USB Manager State:");
            pw.increaseIndent();
            if (mDeviceManager != null) {
                mDeviceManager.dump(pw);
            }
            if (mHostManager != null) {
                mHostManager.dump(pw);
            }
            if (mPortManager != null) {
                mPortManager.dump(pw);
            }
            mAlsaManager.dump(pw);
            synchronized (mLock) {
                for (int i = 0; i < mSettingsByUser.size(); i++) {
                    final int userId = mSettingsByUser.keyAt(i);
                    final UsbSettingsManager settings = mSettingsByUser.valueAt(i);
                    pw.println("Settings for user " + userId + ":");
                    pw.increaseIndent();
                    settings.dump(pw);
                    pw.decreaseIndent();
                }
            }
        } else if (args.length == 4 && "set-port-roles".equals(args[0])) {
            final String portId = args[1];
            final int powerRole;
            switch(args[2]) {
                case "source":
                    powerRole = UsbPort.POWER_ROLE_SOURCE;
                    break;
                case "sink":
                    powerRole = UsbPort.POWER_ROLE_SINK;
                    break;
                case "no-power":
                    powerRole = 0;
                    break;
                default:
                    pw.println("Invalid power role: " + args[2]);
                    return;
            }
            final int dataRole;
            switch(args[3]) {
                case "host":
                    dataRole = UsbPort.DATA_ROLE_HOST;
                    break;
                case "device":
                    dataRole = UsbPort.DATA_ROLE_DEVICE;
                    break;
                case "no-data":
                    dataRole = 0;
                    break;
                default:
                    pw.println("Invalid data role: " + args[3]);
                    return;
            }
            if (mPortManager != null) {
                mPortManager.setPortRoles(portId, powerRole, dataRole, pw);
                // Note: It might take some time for the side-effects of this operation
                // to be fully applied by the kernel since the driver may need to
                // renegotiate the USB port mode.  If this proves to be an issue
                // during debugging, it might be worth adding a sleep here before
                // dumping the new state.
                pw.println();
                mPortManager.dump(pw);
            }
        } else if (args.length == 3 && "add-port".equals(args[0])) {
            final String portId = args[1];
            final int supportedModes;
            switch(args[2]) {
                case "ufp":
                    supportedModes = UsbPort.MODE_UFP;
                    break;
                case "dfp":
                    supportedModes = UsbPort.MODE_DFP;
                    break;
                case "dual":
                    supportedModes = UsbPort.MODE_DUAL;
                    break;
                case "none":
                    supportedModes = 0;
                    break;
                default:
                    pw.println("Invalid mode: " + args[2]);
                    return;
            }
            if (mPortManager != null) {
                mPortManager.addSimulatedPort(portId, supportedModes, pw);
                pw.println();
                mPortManager.dump(pw);
            }
        } else if (args.length == 5 && "connect-port".equals(args[0])) {
            final String portId = args[1];
            final int mode;
            final boolean canChangeMode = args[2].endsWith("?");
            switch(canChangeMode ? removeLastChar(args[2]) : args[2]) {
                case "ufp":
                    mode = UsbPort.MODE_UFP;
                    break;
                case "dfp":
                    mode = UsbPort.MODE_DFP;
                    break;
                default:
                    pw.println("Invalid mode: " + args[2]);
                    return;
            }
            final int powerRole;
            final boolean canChangePowerRole = args[3].endsWith("?");
            switch(canChangePowerRole ? removeLastChar(args[3]) : args[3]) {
                case "source":
                    powerRole = UsbPort.POWER_ROLE_SOURCE;
                    break;
                case "sink":
                    powerRole = UsbPort.POWER_ROLE_SINK;
                    break;
                default:
                    pw.println("Invalid power role: " + args[3]);
                    return;
            }
            final int dataRole;
            final boolean canChangeDataRole = args[4].endsWith("?");
            switch(canChangeDataRole ? removeLastChar(args[4]) : args[4]) {
                case "host":
                    dataRole = UsbPort.DATA_ROLE_HOST;
                    break;
                case "device":
                    dataRole = UsbPort.DATA_ROLE_DEVICE;
                    break;
                default:
                    pw.println("Invalid data role: " + args[4]);
                    return;
            }
            if (mPortManager != null) {
                mPortManager.connectSimulatedPort(portId, mode, canChangeMode, powerRole, canChangePowerRole, dataRole, canChangeDataRole, pw);
                pw.println();
                mPortManager.dump(pw);
            }
        } else if (args.length == 2 && "disconnect-port".equals(args[0])) {
            final String portId = args[1];
            if (mPortManager != null) {
                mPortManager.disconnectSimulatedPort(portId, pw);
                pw.println();
                mPortManager.dump(pw);
            }
        } else if (args.length == 2 && "remove-port".equals(args[0])) {
            final String portId = args[1];
            if (mPortManager != null) {
                mPortManager.removeSimulatedPort(portId, pw);
                pw.println();
                mPortManager.dump(pw);
            }
        } else if (args.length == 1 && "reset".equals(args[0])) {
            if (mPortManager != null) {
                mPortManager.resetSimulation(pw);
                pw.println();
                mPortManager.dump(pw);
            }
        } else if (args.length == 1 && "ports".equals(args[0])) {
            if (mPortManager != null) {
                mPortManager.dump(pw);
            }
        } else {
            pw.println("Dump current USB state or issue command:");
            pw.println("  ports");
            pw.println("  set-port-roles <id> <source|sink|no-power> <host|device|no-data>");
            pw.println("  add-port <id> <ufp|dfp|dual|none>");
            pw.println("  connect-port <id> <ufp|dfp><?> <source|sink><?> <host|device><?>");
            pw.println("    (add ? suffix if mode, power role, or data role can be changed)");
            pw.println("  disconnect-port <id>");
            pw.println("  remove-port <id>");
            pw.println("  reset");
            pw.println();
            pw.println("Example USB type C port role switch:");
            pw.println("  dumpsys usb set-port-roles \"default\" source device");
            pw.println();
            pw.println("Example USB type C port simulation with full capabilities:");
            pw.println("  dumpsys usb add-port \"matrix\" dual");
            pw.println("  dumpsys usb connect-port \"matrix\" ufp? sink? device?");
            pw.println("  dumpsys usb ports");
            pw.println("  dumpsys usb disconnect-port \"matrix\"");
            pw.println("  dumpsys usb remove-port \"matrix\"");
            pw.println("  dumpsys usb reset");
            pw.println();
            pw.println("Example USB type C port where only power role can be changed:");
            pw.println("  dumpsys usb add-port \"matrix\" dual");
            pw.println("  dumpsys usb connect-port \"matrix\" dfp source? host");
            pw.println("  dumpsys usb reset");
            pw.println();
            pw.println("Example USB OTG port where id pin determines function:");
            pw.println("  dumpsys usb add-port \"matrix\" dual");
            pw.println("  dumpsys usb connect-port \"matrix\" dfp source host");
            pw.println("  dumpsys usb reset");
            pw.println();
            pw.println("Example USB device-only port:");
            pw.println("  dumpsys usb add-port \"matrix\" ufp");
            pw.println("  dumpsys usb connect-port \"matrix\" ufp sink device");
            pw.println("  dumpsys usb reset");
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 52 with IndentingPrintWriter

use of com.android.internal.util.IndentingPrintWriter in project android_frameworks_base by ResurrectionRemix.

the class UsageStatsService method dump.

/**
     * Called by the Binder stub.
     */
void dump(String[] args, PrintWriter pw) {
    synchronized (mLock) {
        IndentingPrintWriter idpw = new IndentingPrintWriter(pw, "  ");
        ArraySet<String> argSet = new ArraySet<>();
        argSet.addAll(Arrays.asList(args));
        final int userCount = mUserState.size();
        for (int i = 0; i < userCount; i++) {
            idpw.printPair("user", mUserState.keyAt(i));
            idpw.println();
            idpw.increaseIndent();
            if (argSet.contains("--checkin")) {
                mUserState.valueAt(i).checkin(idpw);
            } else {
                mUserState.valueAt(i).dump(idpw);
                idpw.println();
                if (args.length > 0) {
                    if ("history".equals(args[0])) {
                        mAppIdleHistory.dumpHistory(idpw, mUserState.keyAt(i));
                    } else if ("flush".equals(args[0])) {
                        UsageStatsService.this.flushToDiskLocked();
                        pw.println("Flushed stats to disk");
                    }
                }
            }
            mAppIdleHistory.dump(idpw, mUserState.keyAt(i));
            idpw.decreaseIndent();
        }
        pw.println();
        pw.println("Carrier privileged apps (have=" + mHaveCarrierPrivilegedApps + "): " + mCarrierPrivilegedApps);
        pw.println();
        pw.println("Settings:");
        pw.print("  mAppIdleDurationMillis=");
        TimeUtils.formatDuration(mAppIdleScreenThresholdMillis, pw);
        pw.println();
        pw.print("  mAppIdleWallclockThresholdMillis=");
        TimeUtils.formatDuration(mAppIdleWallclockThresholdMillis, pw);
        pw.println();
        pw.print("  mCheckIdleIntervalMillis=");
        TimeUtils.formatDuration(mCheckIdleIntervalMillis, pw);
        pw.println();
        pw.print("  mAppIdleParoleIntervalMillis=");
        TimeUtils.formatDuration(mAppIdleParoleIntervalMillis, pw);
        pw.println();
        pw.print("  mAppIdleParoleDurationMillis=");
        TimeUtils.formatDuration(mAppIdleParoleDurationMillis, pw);
        pw.println();
        pw.println();
        pw.print("mAppIdleEnabled=");
        pw.print(mAppIdleEnabled);
        pw.print(" mAppIdleTempParoled=");
        pw.print(mAppIdleTempParoled);
        pw.print(" mCharging=");
        pw.print(mCharging);
        pw.print(" mLastAppIdleParoledTime=");
        TimeUtils.formatDuration(mLastAppIdleParoledTime, pw);
        pw.println();
    }
}
Also used : ArraySet(android.util.ArraySet) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 53 with IndentingPrintWriter

use of com.android.internal.util.IndentingPrintWriter in project android_frameworks_base by crdroidandroid.

the class DiskInfo method toString.

@Override
public String toString() {
    final CharArrayWriter writer = new CharArrayWriter();
    dump(new IndentingPrintWriter(writer, "    ", 80));
    return writer.toString();
}
Also used : CharArrayWriter(java.io.CharArrayWriter) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 54 with IndentingPrintWriter

use of com.android.internal.util.IndentingPrintWriter in project android_frameworks_base by crdroidandroid.

the class VolumeInfo method toString.

@Override
public String toString() {
    final CharArrayWriter writer = new CharArrayWriter();
    dump(new IndentingPrintWriter(writer, "    ", 80));
    return writer.toString();
}
Also used : CharArrayWriter(java.io.CharArrayWriter) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 55 with IndentingPrintWriter

use of com.android.internal.util.IndentingPrintWriter in project android_frameworks_base by crdroidandroid.

the class NetworkPolicyManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
    mContext.enforceCallingOrSelfPermission(DUMP, TAG);
    final IndentingPrintWriter fout = new IndentingPrintWriter(writer, "  ");
    final ArraySet<String> argSet = new ArraySet<String>(args.length);
    for (String arg : args) {
        argSet.add(arg);
    }
    synchronized (mUidRulesFirstLock) {
        synchronized (mNetworkPoliciesSecondLock) {
            if (argSet.contains("--unsnooze")) {
                for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
                    mNetworkPolicy.valueAt(i).clearSnooze();
                }
                normalizePoliciesNL();
                updateNetworkEnabledNL();
                updateNetworkRulesNL();
                updateNotificationsNL();
                writePolicyAL();
                fout.println("Cleared snooze timestamps");
                return;
            }
            fout.print("System ready: ");
            fout.println(mSystemReady);
            fout.print("Restrict background: ");
            fout.println(mRestrictBackground);
            fout.print("Restrict power: ");
            fout.println(mRestrictPower);
            fout.print("Device idle: ");
            fout.println(mDeviceIdleMode);
            fout.println("Network policies:");
            fout.increaseIndent();
            for (int i = 0; i < mNetworkPolicy.size(); i++) {
                fout.println(mNetworkPolicy.valueAt(i).toString());
            }
            fout.decreaseIndent();
            fout.print("Metered ifaces: ");
            fout.println(String.valueOf(mMeteredIfaces));
            fout.println("Policy for UIDs:");
            fout.increaseIndent();
            int size = mUidPolicy.size();
            for (int i = 0; i < size; i++) {
                final int uid = mUidPolicy.keyAt(i);
                final int policy = mUidPolicy.valueAt(i);
                fout.print("UID=");
                fout.print(uid);
                fout.print(" policy=");
                fout.print(DebugUtils.flagsToString(NetworkPolicyManager.class, "POLICY_", policy));
                fout.println();
            }
            fout.decreaseIndent();
            size = mPowerSaveWhitelistExceptIdleAppIds.size();
            if (size > 0) {
                fout.println("Power save whitelist (except idle) app ids:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mPowerSaveWhitelistExceptIdleAppIds.keyAt(i));
                    fout.print(": ");
                    fout.print(mPowerSaveWhitelistExceptIdleAppIds.valueAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            size = mPowerSaveWhitelistAppIds.size();
            if (size > 0) {
                fout.println("Power save whitelist app ids:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mPowerSaveWhitelistAppIds.keyAt(i));
                    fout.print(": ");
                    fout.print(mPowerSaveWhitelistAppIds.valueAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            size = mRestrictBackgroundWhitelistUids.size();
            if (size > 0) {
                fout.println("Restrict background whitelist uids:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mRestrictBackgroundWhitelistUids.keyAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            size = mDefaultRestrictBackgroundWhitelistUids.size();
            if (size > 0) {
                fout.println("Default restrict background whitelist uids:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mDefaultRestrictBackgroundWhitelistUids.keyAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            size = mRestrictBackgroundWhitelistRevokedUids.size();
            if (size > 0) {
                fout.println("Default restrict background whitelist uids revoked by users:");
                fout.increaseIndent();
                for (int i = 0; i < size; i++) {
                    fout.print("UID=");
                    fout.print(mRestrictBackgroundWhitelistRevokedUids.keyAt(i));
                    fout.println();
                }
                fout.decreaseIndent();
            }
            final SparseBooleanArray knownUids = new SparseBooleanArray();
            collectKeys(mUidState, knownUids);
            collectKeys(mUidRules, knownUids);
            fout.println("Status for all known UIDs:");
            fout.increaseIndent();
            size = knownUids.size();
            for (int i = 0; i < size; i++) {
                final int uid = knownUids.keyAt(i);
                fout.print("UID=");
                fout.print(uid);
                final int state = mUidState.get(uid, ActivityManager.PROCESS_STATE_CACHED_EMPTY);
                fout.print(" state=");
                fout.print(state);
                if (state <= ActivityManager.PROCESS_STATE_TOP) {
                    fout.print(" (fg)");
                } else {
                    fout.print(state <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE ? " (fg svc)" : " (bg)");
                }
                final int uidRules = mUidRules.get(uid, RULE_NONE);
                fout.print(" rules=");
                fout.print(uidRulesToString(uidRules));
                fout.println();
            }
            fout.decreaseIndent();
            fout.println("Status for just UIDs with rules:");
            fout.increaseIndent();
            size = mUidRules.size();
            for (int i = 0; i < size; i++) {
                final int uid = mUidRules.keyAt(i);
                fout.print("UID=");
                fout.print(uid);
                final int uidRules = mUidRules.get(uid, RULE_NONE);
                fout.print(" rules=");
                fout.print(uidRulesToString(uidRules));
                fout.println();
            }
            fout.decreaseIndent();
        }
    }
}
Also used : ArraySet(android.util.ArraySet) NetworkPolicyManager(android.net.NetworkPolicyManager) INetworkPolicyManager(android.net.INetworkPolicyManager) SparseBooleanArray(android.util.SparseBooleanArray) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Aggregations

IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)126 CharArrayWriter (java.io.CharArrayWriter)21 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)10 ArrayList (java.util.ArrayList)10 ArraySet (android.util.ArraySet)9 HashSet (java.util.HashSet)7 PackageParser (android.content.pm.PackageParser)6 UserInfo (android.content.pm.UserInfo)6 ArrayMap (android.util.ArrayMap)6 SparseBooleanArray (android.util.SparseBooleanArray)6 Map (java.util.Map)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Point (android.graphics.Point)5 INetworkPolicyManager (android.net.INetworkPolicyManager)5 NetworkPolicyManager (android.net.NetworkPolicyManager)5 IBinder (android.os.IBinder)5 RemoteCallbackList (android.os.RemoteCallbackList)5 DiskInfo (android.os.storage.DiskInfo)5 VolumeInfo (android.os.storage.VolumeInfo)5 VolumeRecord (android.os.storage.VolumeRecord)5