Search in sources :

Example 36 with FastPrintWriter

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

the class PackageManagerService method logCriticalInfo.

static void logCriticalInfo(int priority, String msg) {
    Slog.println(priority, TAG, msg);
    EventLogTags.writePmCriticalInfo(msg);
    try {
        File fname = getSettingsProblemFile();
        FileOutputStream out = new FileOutputStream(fname, true);
        PrintWriter pw = new FastPrintWriter(out);
        SimpleDateFormat formatter = new SimpleDateFormat();
        String dateString = formatter.format(new Date(System.currentTimeMillis()));
        pw.println(dateString + ": " + msg);
        pw.close();
        FileUtils.setPermissions(fname.toString(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IROTH, -1, -1);
    } catch (java.io.IOException e) {
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) PackageParser.isApkFile(android.content.pm.PackageParser.isApkFile) File(java.io.File) DexFile(dalvik.system.DexFile) StrictJarFile(android.util.jar.StrictJarFile) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 37 with FastPrintWriter

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

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 38 with FastPrintWriter

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

the class ActivityManagerService method stopBinderTrackingAndDump.

public boolean stopBinderTrackingAndDump(ParcelFileDescriptor fd) throws RemoteException {
    try {
        synchronized (this) {
            mBinderTransactionTrackingEnabled = false;
            // permission (same as profileControl).
            if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER) != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires permission " + android.Manifest.permission.SET_ACTIVITY_WATCHER);
            }
            if (fd == null) {
                throw new IllegalArgumentException("null fd");
            }
            PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd.getFileDescriptor()));
            pw.println("Binder transaction traces for all processes.\n");
            for (ProcessRecord process : mLruProcesses) {
                if (!processSanityChecksLocked(process)) {
                    continue;
                }
                pw.println("Traces for process: " + process.processName);
                pw.flush();
                try {
                    TransferPipe tp = new TransferPipe();
                    try {
                        process.thread.stopBinderTrackingAndDump(tp.getWriteFd().getFileDescriptor());
                        tp.go(fd.getFileDescriptor());
                    } finally {
                        tp.kill();
                    }
                } catch (IOException e) {
                    pw.println("Failure while dumping IPC traces from " + process + ".  Exception: " + e);
                    pw.flush();
                } catch (RemoteException e) {
                    pw.println("Got a RemoteException while dumping IPC traces from " + process + ".  Exception: " + e);
                    pw.flush();
                }
            }
            fd = null;
            return true;
        }
    } finally {
        if (fd != null) {
            try {
                fd.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RemoteException(android.os.RemoteException) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) TransferPipe(com.android.internal.os.TransferPipe)

Example 39 with FastPrintWriter

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

the class TransactionTracker method writeTracesToFile.

public void writeTracesToFile(ParcelFileDescriptor fd) {
    if (mTraces.isEmpty()) {
        return;
    }
    PrintWriter pw = new FastPrintWriter(new FileOutputStream(fd.getFileDescriptor()));
    synchronized (this) {
        for (String trace : mTraces.keySet()) {
            pw.println("Count: " + mTraces.get(trace));
            pw.println("Trace: " + trace);
            pw.println();
        }
    }
    pw.flush();
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 40 with FastPrintWriter

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

the class StrictMode method readAndHandleBinderCallViolations.

/**
     * Called from Parcel.readException() when the exception is EX_STRICT_MODE_VIOLATIONS,
     * we here read back all the encoded violations.
     */
/* package */
static void readAndHandleBinderCallViolations(Parcel p) {
    // Our own stack trace to append
    StringWriter sw = new StringWriter();
    sw.append("# via Binder call with stack:\n");
    PrintWriter pw = new FastPrintWriter(sw, false, 256);
    new LogStackTrace().printStackTrace(pw);
    pw.flush();
    String ourStack = sw.toString();
    final int policyMask = getThreadPolicyMask();
    final boolean currentlyGathering = (policyMask & PENALTY_GATHER) != 0;
    final int size = p.readInt();
    for (int i = 0; i < size; i++) {
        final ViolationInfo info = new ViolationInfo(p, !currentlyGathering);
        info.crashInfo.appendStackTrace(ourStack);
        BlockGuard.Policy policy = BlockGuard.getThreadPolicy();
        if (policy instanceof AndroidBlockGuardPolicy) {
            ((AndroidBlockGuardPolicy) policy).handleViolationWithTimingAttempt(info);
        }
    }
}
Also used : StringWriter(java.io.StringWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) BlockGuard(dalvik.system.BlockGuard) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

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