android.util.Printer Java Examples

The following examples show how to use android.util.Printer. 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: LatinIME.java    From Android-Keyboard with Apache License 2.0 6 votes vote down vote up
@Override
protected void dump(final FileDescriptor fd, final PrintWriter fout, final String[] args) {
    super.dump(fd, fout, args);

    final Printer p = new PrintWriterPrinter(fout);
    p.println("LatinIME state :");
    p.println("  VersionCode = " + ApplicationUtils.getVersionCode(this));
    p.println("  VersionName = " + ApplicationUtils.getVersionName(this));
    final Keyboard keyboard = KeyboardSwitcher.getInstance().getKeyboard();
    final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
    p.println("  Keyboard mode = " + keyboardMode);
    final SettingsValues settingsValues = mSettings.getCurrent();
    p.println(settingsValues.dump());
    p.println(mDictionaryFacilitator.dump(this /* context */));
    // TODO: Dump all settings values
}
 
Example #2
Source File: SQLiteConnection.java    From sqlite-android with Apache License 2.0 6 votes vote down vote up
public void dump(Printer printer) {
    printer.println("  Prepared statement cache:");
    Map<String, PreparedStatement> cache = snapshot();
    if (!cache.isEmpty()) {
        int i = 0;
        for (Map.Entry<String, PreparedStatement> entry : cache.entrySet()) {
            PreparedStatement statement = entry.getValue();
            if (statement.mInCache) { // might be false due to a race with entryRemoved
                String sql = entry.getKey();
                printer.println("    " + i + ": statementPtr=0x"
                        + Long.toHexString(statement.mStatementPtr)
                        + ", numParameters=" + statement.mNumParameters
                        + ", type=" + statement.mType
                        + ", readOnly=" + statement.mReadOnly
                        + ", sql=\"" + trimSqlForDisplay(sql) + "\"");
            }
            i += 1;
        }
    } else {
        printer.println("    <none>");
    }
}
 
Example #3
Source File: CountryDetectorService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
@Override
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
    if (!DumpUtils.checkDumpPermission(mContext, TAG, fout)) return;
    if (!DEBUG) return;
    try {
        final Printer p = new PrintWriterPrinter(fout);
        p.println("CountryDetectorService state:");
        p.println("  Number of listeners=" + mReceivers.keySet().size());
        if (mCountryDetector == null) {
            p.println("  ComprehensiveCountryDetector not initialized");
        } else {
            p.println("  " + mCountryDetector.toString());
        }
    } catch (Exception e) {
        Slog.e(TAG, "Failed to dump CountryDetectorService: ", e);
    }
}
 
Example #4
Source File: TrustKit.java    From TrustKit-Android with MIT License 6 votes vote down vote up
/** Try to retrieve the Network Security Policy resource ID configured in the App's manifest.
 *
 * Somewhat convoluted as other means of getting the resource ID involve using private APIs.
 *
 * @param context
 * @return The resource ID for the XML file containing the configured Network Security Policy or
 * -1 if no policy was configured in the App's manifest or if we are not running on Android N.
 */
static private int getNetSecConfigResourceId(@NonNull Context context) {
    ApplicationInfo info = context.getApplicationInfo();

    // Dump the content of the ApplicationInfo, which contains the resource ID on Android N
    class NetSecConfigResIdRetriever implements Printer {
        private int netSecConfigResourceId = -1;
        private final String NETSEC_LINE_FORMAT = "networkSecurityConfigRes=0x";

        public void println(String x) {
            if (netSecConfigResourceId == -1) {
                // Attempt at parsing "networkSecurityConfigRes=0x1234"
                if (x.contains(NETSEC_LINE_FORMAT)) {
                    netSecConfigResourceId =
                            Integer.parseInt(x.substring(NETSEC_LINE_FORMAT.length()), 16);
                }
            }
        }

        private int getNetworkSecurityConfigResId() { return netSecConfigResourceId; }
    }

    NetSecConfigResIdRetriever retriever = new NetSecConfigResIdRetriever();
    info.dump(retriever, "");
    return retriever.getNetworkSecurityConfigResId();
}
 
Example #5
Source File: EditorInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Write debug output of this object.
 */
public void dump(Printer pw, String prefix) {
    pw.println(prefix + "inputType=0x" + Integer.toHexString(inputType)
            + " imeOptions=0x" + Integer.toHexString(imeOptions)
            + " privateImeOptions=" + privateImeOptions);
    pw.println(prefix + "actionLabel=" + actionLabel
            + " actionId=" + actionId);
    pw.println(prefix + "initialSelStart=" + initialSelStart
            + " initialSelEnd=" + initialSelEnd
            + " initialCapsMode=0x"
            + Integer.toHexString(initialCapsMode));
    pw.println(prefix + "hintText=" + hintText
            + " label=" + label);
    pw.println(prefix + "packageName=" + packageName
            + " fieldId=" + fieldId
            + " fieldName=" + fieldName);
    pw.println(prefix + "extras=" + extras);
    pw.println(prefix + "hintLocales=" + hintLocales);
    pw.println(prefix + "contentMimeTypes=" + Arrays.toString(contentMimeTypes));
}
 
Example #6
Source File: LatinIME.java    From hackerskeyboard with Apache License 2.0 6 votes vote down vote up
@Override
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
    super.dump(fd, fout, args);

    final Printer p = new PrintWriterPrinter(fout);
    p.println("LatinIME state :");
    p.println("  Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode());
    p.println("  mComposing=" + mComposing.toString());
    p.println("  mPredictionOnForMode=" + mPredictionOnForMode);
    p.println("  mCorrectionMode=" + mCorrectionMode);
    p.println("  mPredicting=" + mPredicting);
    p.println("  mAutoCorrectOn=" + mAutoCorrectOn);
    p.println("  mAutoSpace=" + mAutoSpace);
    p.println("  mCompletionOn=" + mCompletionOn);
    p.println("  TextEntryState.state=" + TextEntryState.getState());
    p.println("  mSoundOn=" + mSoundOn);
    p.println("  mVibrateOn=" + mVibrateOn);
    p.println("  mPopupOn=" + mPopupOn);
}
 
Example #7
Source File: LatinIME.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void dump(final FileDescriptor fd, final PrintWriter fout, final String[] args) {
    super.dump(fd, fout, args);

    final Printer p = new PrintWriterPrinter(fout);
    p.println("LatinIME state :");
    p.println("  VersionCode = " + ApplicationUtils.getVersionCode(this));
    p.println("  VersionName = " + ApplicationUtils.getVersionName(this));
    final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
    final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
    p.println("  Keyboard mode = " + keyboardMode);
    final SettingsValues settingsValues = mSettings.getCurrent();
    p.println(settingsValues.dump());
    p.println(mDictionaryFacilitator.dump(this /* context */));
    // TODO: Dump all settings values
}
 
Example #8
Source File: SQLiteConnection.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void dump(Printer printer) {
    printer.println("  Prepared statement cache:");
    Map<String, PreparedStatement> cache = snapshot();
    if (!cache.isEmpty()) {
        int i = 0;
        for (Map.Entry<String, PreparedStatement> entry : cache.entrySet()) {
            PreparedStatement statement = entry.getValue();
            if (statement.mInCache) { // might be false due to a race with entryRemoved
                String sql = entry.getKey();
                printer.println("    " + i + ": statementPtr=0x"
                        + Long.toHexString(statement.mStatementPtr)
                        + ", numParameters=" + statement.mNumParameters
                        + ", type=" + statement.mType
                        + ", readOnly=" + statement.mReadOnly
                        + ", sql=\"" + trimSqlForDisplay(sql) + "\"");
            }
            i += 1;
        }
    } else {
        printer.println("    <none>");
    }
}
 
Example #9
Source File: BlockDetectByPrinter.java    From imsdk-android with MIT License 6 votes vote down vote up
public static void start() {

        Looper.getMainLooper().setMessageLogging(new Printer() {

            private static final String START = ">>>>> Dispatching";
            private static final String END = "<<<<< Finished";

            @Override
            public void println(String x) {
                if (x.startsWith(START)) {
                    LogMonitor.getInstance().startMonitor();
                }
                if (x.startsWith(END)) {
                    LogMonitor.getInstance().removeMonitor();
                }
            }
        });

    }
 
Example #10
Source File: BlockDetectByPrinter.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
public static void start() {

        Looper.getMainLooper().setMessageLogging(new Printer() {

            private static final String START = ">>>>> Dispatching";
            private static final String END = "<<<<< Finished";

            @Override
            public void println(String x) {
                if (x.startsWith(START)) {
                    LogMonitor.getInstance().startMonitor();
                }
                if (x.startsWith(END)) {
                    LogMonitor.getInstance().removeMonitor();
                }
            }
        });

    }
 
Example #11
Source File: BlockTask.java    From ArgusAPM with Apache License 2.0 6 votes vote down vote up
@Override
public void start() {
    super.start();
    if (!mBlockThread.isAlive()) { //防止多次调用
        mBlockThread.start();
        mHandler = new Handler(mBlockThread.getLooper());
        Looper.getMainLooper().setMessageLogging(new Printer() {

            private static final String START = ">>>>> Dispatching";
            private static final String END = "<<<<< Finished";

            @Override
            public void println(String x) {
                if (x.startsWith(START)) {
                    startMonitor();
                }
                if (x.startsWith(END)) {
                    removeMonitor();
                }
            }
        });
    }
}
 
Example #12
Source File: ApplicationErrorReport.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Dump the report to a Printer.
 */
public void dump(Printer pw, String prefix) {
    pw.println(prefix + "type: " + type);
    pw.println(prefix + "packageName: " + packageName);
    pw.println(prefix + "installerPackageName: " + installerPackageName);
    pw.println(prefix + "processName: " + processName);
    pw.println(prefix + "time: " + time);
    pw.println(prefix + "systemApp: " + systemApp);

    switch (type) {
        case TYPE_CRASH:
            crashInfo.dump(pw, prefix);
            break;
        case TYPE_ANR:
            anrInfo.dump(pw, prefix);
            break;
        case TYPE_BATTERY:
            batteryInfo.dump(pw, prefix);
            break;
        case TYPE_RUNNING_SERVICE:
            runningServiceInfo.dump(pw, prefix);
            break;
    }
}
 
Example #13
Source File: LatinIME.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void dump(final FileDescriptor fd, final PrintWriter fout, final String[] args) {
    super.dump(fd, fout, args);

    final Printer p = new PrintWriterPrinter(fout);
    p.println("LatinIME state :");
    p.println("  VersionCode = " + ApplicationUtils.getVersionCode(this));
    p.println("  VersionName = " + ApplicationUtils.getVersionName(this));
    final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
    final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
    p.println("  Keyboard mode = " + keyboardMode);
    final SettingsValues settingsValues = mSettings.getCurrent();
    p.println(settingsValues.dump());
    p.println(mDictionaryFacilitator.dump(this /* context */));
    // TODO: Dump all settings values
}
 
Example #14
Source File: BlockDetectByPrinter.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
public static void start() {

        Looper.getMainLooper().setMessageLogging(new Printer() {

            private static final String START = ">>>>> Dispatching";
            private static final String END = "<<<<< Finished";

            @Override
            public void println(String x) {
                if (x.startsWith(START)) {
                    LogMonitor.getInstance().startMonitor();
                }
                if (x.startsWith(END)) {
                    LogMonitor.getInstance().removeMonitor();
                }
            }
        });

    }
 
Example #15
Source File: PackageItemInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
protected void dumpFront(Printer pw, String prefix) {
    if (name != null) {
        pw.println(prefix + "name=" + name);
    }
    pw.println(prefix + "packageName=" + packageName);
    if (labelRes != 0 || nonLocalizedLabel != null || icon != 0 || banner != 0) {
        pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)
                + " nonLocalizedLabel=" + nonLocalizedLabel
                + " icon=0x" + Integer.toHexString(icon)
                + " banner=0x" + Integer.toHexString(banner));
    }
}
 
Example #16
Source File: ResolveInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @hide */
public void dump(Printer pw, String prefix, int dumpFlags) {
    if (filter != null) {
        pw.println(prefix + "Filter:");
        filter.dump(pw, prefix + "  ");
    }
    pw.println(prefix + "priority=" + priority
            + " preferredOrder=" + preferredOrder
            + " match=0x" + Integer.toHexString(match)
            + " specificIndex=" + specificIndex
            + " isDefault=" + isDefault);
    if (resolvePackageName != null) {
        pw.println(prefix + "resolvePackageName=" + resolvePackageName);
    }
    if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {
        pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)
                + " nonLocalizedLabel=" + nonLocalizedLabel
                + " icon=0x" + Integer.toHexString(icon));
    }
    if (activityInfo != null) {
        pw.println(prefix + "ActivityInfo:");
        activityInfo.dump(pw, prefix + "  ", dumpFlags);
    } else if (serviceInfo != null) {
        pw.println(prefix + "ServiceInfo:");
        serviceInfo.dump(pw, prefix + "  ", dumpFlags);
    } else if (providerInfo != null) {
        pw.println(prefix + "ProviderInfo:");
        providerInfo.dump(pw, prefix + "  ", dumpFlags);
    }
}
 
Example #17
Source File: LatinIME.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
@Override
protected void dump(final FileDescriptor fd, final PrintWriter fout, final String[] args) {
    super.dump(fd, fout, args);

    final Printer p = new PrintWriterPrinter(fout);
    p.println("LatinIME state :");
    p.println("  VersionCode = " + ApplicationUtils.getVersionCode(this));
    p.println("  VersionName = " + ApplicationUtils.getVersionName(this));
    final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
    final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
    p.println("  Keyboard mode = " + keyboardMode);
}
 
Example #18
Source File: SQLiteDatabase.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
private void dump(Printer printer, boolean verbose) {
    synchronized (mLock) {
        if (mConnectionPoolLocked != null) {
            printer.println("");
            mConnectionPoolLocked.dump(printer, verbose);
        }
    }
}
 
Example #19
Source File: ComponentInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
protected void dumpFront(Printer pw, String prefix) {
    super.dumpFront(pw, prefix);
    if (processName != null && !packageName.equals(processName)) {
        pw.println(prefix + "processName=" + processName);
    }
    if (splitName != null) {
        pw.println(prefix + "splitName=" + splitName);
    }
    pw.println(prefix + "enabled=" + enabled + " exported=" + exported
            + " directBootAware=" + directBootAware);
    if (descriptionRes != 0) {
        pw.println(prefix + "description=" + descriptionRes);
    }
}
 
Example #20
Source File: ProviderInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @hide */
public void dump(Printer pw, String prefix, int dumpFlags) {
    super.dumpFront(pw, prefix);
    pw.println(prefix + "authority=" + authority);
    pw.println(prefix + "flags=0x" + Integer.toHexString(flags));
    super.dumpBack(pw, prefix, dumpFlags);
}
 
Example #21
Source File: ApplicationErrorReport.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Dump a BatteryInfo instance to a Printer.
 */
public void dump(Printer pw, String prefix) {
    pw.println(prefix + "usagePercent: " + usagePercent);
    pw.println(prefix + "durationMicros: " + durationMicros);
    pw.println(prefix + "usageDetails: " + usageDetails);
    pw.println(prefix + "checkinDetails: " + checkinDetails);
}
 
Example #22
Source File: MessageQueue.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void dump(Printer pw, String prefix, Handler h) {
    synchronized (this) {
        long now = SystemClock.uptimeMillis();
        int n = 0;
        for (Message msg = mMessages; msg != null; msg = msg.next) {
            if (h == null || h == msg.target) {
                pw.println(prefix + "Message " + n + ": " + msg.toString(now));
            }
            n++;
        }
        pw.println(prefix + "(Total messages: " + n + ", polling=" + isPollingLocked()
                + ", quitting=" + mQuitting + ")");
    }
}
 
Example #23
Source File: StrictMode.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** Dump a ViolationInfo instance to a Printer. */
public void dump(Printer pw, String prefix) {
    pw.println(prefix + "stackTrace: " + getStackTrace());
    pw.println(prefix + "policy: " + mPolicy);
    if (durationMillis != -1) {
        pw.println(prefix + "durationMillis: " + durationMillis);
    }
    if (numInstances != -1) {
        pw.println(prefix + "numInstances: " + numInstances);
    }
    if (violationNumThisLoop != 0) {
        pw.println(prefix + "violationNumThisLoop: " + violationNumThisLoop);
    }
    if (numAnimationsRunning != 0) {
        pw.println(prefix + "numAnimationsRunning: " + numAnimationsRunning);
    }
    pw.println(prefix + "violationUptimeMillis: " + violationUptimeMillis);
    if (broadcastIntentAction != null) {
        pw.println(prefix + "broadcastIntentAction: " + broadcastIntentAction);
    }
    if (tags != null) {
        int index = 0;
        for (String tag : tags) {
            pw.println(prefix + "tag[" + (index++) + "]: " + tag);
        }
    }
}
 
Example #24
Source File: Handler.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public final void dump(Printer pw, String prefix) {
    pw.println(prefix + this + " @ " + SystemClock.uptimeMillis());
    if (mLooper == null) {
        pw.println(prefix + "looper uninitialized");
    } else {
        mLooper.dump(pw, prefix + "  ");
    }
}
 
Example #25
Source File: Handler.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @hide
 */
public final void dumpMine(Printer pw, String prefix) {
    pw.println(prefix + this + " @ " + SystemClock.uptimeMillis());
    if (mLooper == null) {
        pw.println(prefix + "looper uninitialized");
    } else {
        mLooper.dump(pw, prefix + "  ", this);
    }
}
 
Example #26
Source File: SQLiteDebug.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Dumps detailed information about all databases used by the process.
 * @param printer The printer for dumping database state.
 * @param args Command-line arguments supplied to dumpsys dbinfo
 */
public static void dump(Printer printer, String[] args) {
    boolean verbose = false;
    for (String arg : args) {
        if (arg.equals("-v")) {
            verbose = true;
        }
    }

    SQLiteDatabase.dumpAll(printer, verbose);
}
 
Example #27
Source File: SQLiteDatabase.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void dump(Printer printer, boolean verbose) {
    synchronized (mLock) {
        if (mConnectionPoolLocked != null) {
            printer.println("");
            mConnectionPoolLocked.dump(printer, verbose);
        }
    }
}
 
Example #28
Source File: SQLiteConnection.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Dumps debugging information about this connection, in the case where the
 * caller might not actually own the connection.
 *
 * This function is written so that it may be called by a thread that does not
 * own the connection.  We need to be very careful because the connection state is
 * not synchronized.
 *
 * At worst, the method may return stale or slightly wrong data, however
 * it should not crash.  This is ok as it is only used for diagnostic purposes.
 *
 * @param printer The printer to receive the dump, not null.
 * @param verbose True to dump more verbose information.
 */
void dumpUnsafe(Printer printer, boolean verbose) {
    printer.println("Connection #" + mConnectionId + ":");
    if (verbose) {
        printer.println("  connectionPtr: 0x" + Long.toHexString(mConnectionPtr));
    }
    printer.println("  isPrimaryConnection: " + mIsPrimaryConnection);
    printer.println("  onlyAllowReadOnlyOperations: " + mOnlyAllowReadOnlyOperations);

    mRecentOperations.dump(printer, verbose);

    if (verbose) {
        mPreparedStatementCache.dump(printer);
    }
}
 
Example #29
Source File: SQLiteConnection.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void dump(Printer printer, boolean verbose) {
    synchronized (mOperations) {
        printer.println("  Most recently executed operations:");
        int index = mIndex;
        Operation operation = mOperations[index];
        if (operation != null) {
            // Note: SimpleDateFormat is not thread-safe, cannot be compile-time created,
            // and is relatively expensive to create during preloading. This method is only
            // used when dumping a connection, which is a rare (mainly error) case.
            SimpleDateFormat opDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            int n = 0;
            do {
                StringBuilder msg = new StringBuilder();
                msg.append("    ").append(n).append(": [");
                String formattedStartTime = opDF.format(new Date(operation.mStartWallTime));
                msg.append(formattedStartTime);
                msg.append("] ");
                operation.describe(msg, verbose);
                printer.println(msg.toString());

                if (index > 0) {
                    index -= 1;
                } else {
                    index = MAX_RECENT_OPERATIONS - 1;
                }
                n += 1;
                operation = mOperations[index];
            } while (operation != null && n < MAX_RECENT_OPERATIONS);
        } else {
            printer.println("    <none>");
        }
    }
}
 
Example #30
Source File: ApplicationErrorReport.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Dump a CrashInfo instance to a Printer.
 */
public void dump(Printer pw, String prefix) {
    pw.println(prefix + "exceptionClassName: " + exceptionClassName);
    pw.println(prefix + "exceptionMessage: " + exceptionMessage);
    pw.println(prefix + "throwFileName: " + throwFileName);
    pw.println(prefix + "throwClassName: " + throwClassName);
    pw.println(prefix + "throwMethodName: " + throwMethodName);
    pw.println(prefix + "throwLineNumber: " + throwLineNumber);
    pw.println(prefix + "stackTrace: " + stackTrace);
}