Search in sources :

Example 56 with FastPrintWriter

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

the class ActiveServices method serviceTimeout.

void serviceTimeout(ProcessRecord proc) {
    String anrMessage = null;
    synchronized (mAm) {
        if (proc.executingServices.size() == 0 || proc.thread == null) {
            return;
        }
        final long now = SystemClock.uptimeMillis();
        final long maxTime = now - (proc.execServicesFg ? SERVICE_TIMEOUT : SERVICE_BACKGROUND_TIMEOUT);
        ServiceRecord timeout = null;
        long nextTime = 0;
        for (int i = proc.executingServices.size() - 1; i >= 0; i--) {
            ServiceRecord sr = proc.executingServices.valueAt(i);
            if (sr.executingStart < maxTime) {
                timeout = sr;
                break;
            }
            if (sr.executingStart > nextTime) {
                nextTime = sr.executingStart;
            }
        }
        if (timeout != null && mAm.mLruProcesses.contains(proc)) {
            Slog.w(TAG, "Timeout executing service: " + timeout);
            StringWriter sw = new StringWriter();
            PrintWriter pw = new FastPrintWriter(sw, false, 1024);
            pw.println(timeout);
            timeout.dump(pw, "    ");
            pw.close();
            mLastAnrDump = sw.toString();
            mAm.mHandler.removeCallbacks(mLastAnrDumpClearer);
            mAm.mHandler.postDelayed(mLastAnrDumpClearer, LAST_ANR_LIFETIME_DURATION_MSECS);
            anrMessage = "executing service " + timeout.shortName;
        } else {
            Message msg = mAm.mHandler.obtainMessage(ActivityManagerService.SERVICE_TIMEOUT_MSG);
            msg.obj = proc;
            mAm.mHandler.sendMessageAtTime(msg, proc.execServicesFg ? (nextTime + SERVICE_TIMEOUT) : (nextTime + SERVICE_BACKGROUND_TIMEOUT));
        }
    }
    if (anrMessage != null) {
        mAm.mAppErrors.appNotResponding(proc, null, null, false, anrMessage);
    }
}
Also used : StringWriter(java.io.StringWriter) Message(android.os.Message) FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 57 with FastPrintWriter

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

the class Log method getStackTraceString.

/**
     * Handy function to get a loggable stack trace from a Throwable
     * @param tr An exception to log
     */
public static String getStackTraceString(Throwable tr) {
    if (tr == null) {
        return "";
    }
    // This is to reduce the amount of log spew that apps do in the non-error
    // condition of the network being unavailable.
    Throwable t = tr;
    while (t != null) {
        if (t instanceof UnknownHostException) {
            return "";
        }
        t = t.getCause();
    }
    StringWriter sw = new StringWriter();
    PrintWriter pw = new FastPrintWriter(sw, false, 256);
    tr.printStackTrace(pw);
    pw.flush();
    return sw.toString();
}
Also used : UnknownHostException(java.net.UnknownHostException) StringWriter(java.io.StringWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 58 with FastPrintWriter

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

the class ProcessCpuTracker method printCurrentLoad.

public final String printCurrentLoad() {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new FastPrintWriter(sw, false, 128);
    pw.print("Load: ");
    pw.print(mLoad1);
    pw.print(" / ");
    pw.print(mLoad5);
    pw.print(" / ");
    pw.println(mLoad15);
    pw.flush();
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 59 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by AOSPA.

the class ActivityThread method handleDumpService.

private void handleDumpService(DumpComponentInfo info) {
    final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
    try {
        Service s = mServices.get(info.token);
        if (s != null) {
            PrintWriter pw = new FastPrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
            s.dump(info.fd.getFileDescriptor(), pw, info.args);
            pw.flush();
        }
    } finally {
        IoUtils.closeQuietly(info.fd);
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
Also used : StrictMode(android.os.StrictMode) FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 60 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by AOSPA.

the class IntentResolver method buildResolveList.

private void buildResolveList(Intent intent, FastImmutableArraySet<String> categories, boolean debug, boolean defaultOnly, String resolvedType, String scheme, F[] src, List<R> dest, int userId) {
    final String action = intent.getAction();
    final Uri data = intent.getData();
    final String packageName = intent.getPackage();
    final boolean excludingStopped = intent.isExcludingStopped();
    final Printer logPrinter;
    final PrintWriter logPrintWriter;
    if (debug) {
        logPrinter = new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM);
        logPrintWriter = new FastPrintWriter(logPrinter);
    } else {
        logPrinter = null;
        logPrintWriter = null;
    }
    final int N = src != null ? src.length : 0;
    boolean hasNonDefaults = false;
    int i;
    F filter;
    for (i = 0; i < N && (filter = src[i]) != null; i++) {
        int match;
        if (debug)
            Slog.v(TAG, "Matching against filter " + filter);
        if (excludingStopped && isFilterStopped(filter, userId)) {
            if (debug) {
                Slog.v(TAG, "  Filter's target is stopped; skipping");
            }
            continue;
        }
        // Is delivery being limited to filters owned by a particular package?
        if (packageName != null && !isPackageForFilter(packageName, filter)) {
            if (debug) {
                Slog.v(TAG, "  Filter is not from package " + packageName + "; skipping");
            }
            continue;
        }
        // Are we verified ?
        if (filter.getAutoVerify()) {
            if (localVerificationLOGV || debug) {
                Slog.v(TAG, "  Filter verified: " + isFilterVerified(filter));
                int authorities = filter.countDataAuthorities();
                for (int z = 0; z < authorities; z++) {
                    Slog.v(TAG, "   " + filter.getDataAuthority(z).getHost());
                }
            }
        }
        // Do we already have this one?
        if (!allowFilterResult(filter, dest)) {
            if (debug) {
                Slog.v(TAG, "  Filter's target already added");
            }
            continue;
        }
        match = filter.match(action, resolvedType, scheme, data, categories, TAG);
        if (match >= 0) {
            if (debug)
                Slog.v(TAG, "  Filter matched!  match=0x" + Integer.toHexString(match) + " hasDefault=" + filter.hasCategory(Intent.CATEGORY_DEFAULT));
            if (!defaultOnly || filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
                final R oneResult = newResult(filter, match, userId);
                if (oneResult != null) {
                    dest.add(oneResult);
                    if (debug) {
                        dumpFilter(logPrintWriter, "    ", filter);
                        logPrintWriter.flush();
                        filter.dump(logPrinter, "    ");
                    }
                }
            } else {
                hasNonDefaults = true;
            }
        } else {
            if (debug) {
                String reason;
                switch(match) {
                    case IntentFilter.NO_MATCH_ACTION:
                        reason = "action";
                        break;
                    case IntentFilter.NO_MATCH_CATEGORY:
                        reason = "category";
                        break;
                    case IntentFilter.NO_MATCH_DATA:
                        reason = "data";
                        break;
                    case IntentFilter.NO_MATCH_TYPE:
                        reason = "type";
                        break;
                    default:
                        reason = "unknown reason";
                        break;
                }
                Slog.v(TAG, "  Filter did not match: " + reason);
            }
        }
    }
    if (debug && hasNonDefaults) {
        if (dest.size() == 0) {
            Slog.v(TAG, "resolveIntent failed: found match, but none with CATEGORY_DEFAULT");
        } else if (dest.size() > 1) {
            Slog.v(TAG, "resolveIntent: multiple matches, only some with CATEGORY_DEFAULT");
        }
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriterPrinter(android.util.PrintWriterPrinter) LogPrinter(android.util.LogPrinter) Printer(android.util.Printer) Uri(android.net.Uri) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) LogPrinter(android.util.LogPrinter)

Aggregations

FastPrintWriter (com.android.internal.util.FastPrintWriter)128 PrintWriter (java.io.PrintWriter)122 FileOutputStream (java.io.FileOutputStream)61 StringWriter (java.io.StringWriter)34 LogWriter (android.util.LogWriter)24 StrictMode (android.os.StrictMode)17 IOException (java.io.IOException)16 FileNotFoundException (java.io.FileNotFoundException)12 Date (java.util.Date)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Uri (android.net.Uri)7 Message (android.os.Message)7 ArrayMap (android.util.ArrayMap)7 PrintWriterPrinter (android.util.PrintWriterPrinter)7 SimpleDateFormat (java.text.SimpleDateFormat)7 NotFoundException (android.content.res.Resources.NotFoundException)5 Point (android.graphics.Point)5 LogPrinter (android.util.LogPrinter)5 Printer (android.util.Printer)5