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

Commit 1ebccf53 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix problems with determining when to kill apps for wake usage.

Also improve debug printing of various times.

Change-Id: Ifcc288fd1bcbf44c069875ba97925b9e7ffe9a48
parent a8d9291d
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import java.util.Map;
import android.util.Log;
import android.util.Printer;
import android.util.SparseArray;
import android.util.TimeUtils;

/**
 * A class providing access to battery usage statistics, including information on
@@ -1576,8 +1577,10 @@ public abstract class BatteryStats implements Parcelable {
                            Uid.Proc.ExcessiveWake ew = ps.getExcessiveWake(e);
                            if (ew != null) {
                                pw.print(prefix); pw.print("      * Killed for wake lock use: ");
                                        pw.print(ew.usedTime); pw.print("ms over ");
                                        pw.print(ew.overTime); pw.print("ms (");
                                        TimeUtils.formatDuration(ew.usedTime, pw);
                                        pw.print(" over ");
                                        TimeUtils.formatDuration(ew.overTime, pw);
                                        pw.print(" (");
                                        pw.print((ew.usedTime*100)/ew.overTime);
                                        pw.println("%)");
                            }
+2 −1
Original line number Diff line number Diff line
@@ -192,10 +192,11 @@ public class Looper {
        pw.println(prefix + "mQueue=" + ((mQueue != null) ? mQueue : "(null"));
        if (mQueue != null) {
            synchronized (mQueue) {
                long now = SystemClock.uptimeMillis();
                Message msg = mQueue.mMessages;
                int n = 0;
                while (msg != null) {
                    pw.println(prefix + "  Message " + n + ": " + msg);
                    pw.println(prefix + "  Message " + n + ": " + msg.toString(now));
                    n++;
                    msg = msg.next;
                }
+6 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.os;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.TimeUtils;

/**
 * 
@@ -366,13 +367,17 @@ public final class Message implements Parcelable {
    }

    public String toString() {
        return toString(SystemClock.uptimeMillis());
    }

    String toString(long now) {
        StringBuilder   b = new StringBuilder();
        
        b.append("{ what=");
        b.append(what);

        b.append(" when=");
        b.append(when);
        TimeUtils.formatDuration(when-now, b);

        if (arg1 != 0) {
            b.append(" arg1=");
+125 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.TimeZone;
import java.util.Date;

@@ -130,4 +131,128 @@ public class TimeUtils {
    public static String getTimeZoneDatabaseVersion() {
        return ZoneInfoDB.getVersion();
    }

    private static final int SECONDS_PER_MINUTE = 60;
    private static final int SECONDS_PER_HOUR = 60 * 60;
    private static final int SECONDS_PER_DAY = 24 * 60 * 60;

    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long duration, StringBuilder builder) {
        if (duration == 0) {
            builder.append("0");
            return;
        }
        if (duration > 0) {
            builder.append("+");
        } else {
            builder.append("-");
            duration = -duration;
        }

        int millis = (int)(duration%1000);
        int seconds = (int) Math.floor(duration / 1000);
        int days = 0, hours = 0, minutes = 0;

        if (seconds > SECONDS_PER_DAY) {
            days = seconds / SECONDS_PER_DAY;
            seconds -= days * SECONDS_PER_DAY;
        }
        if (seconds > SECONDS_PER_HOUR) {
            hours = seconds / SECONDS_PER_HOUR;
            seconds -= hours * SECONDS_PER_HOUR;
        }
        if (seconds > SECONDS_PER_MINUTE) {
            minutes = seconds / SECONDS_PER_MINUTE;
            seconds -= minutes * SECONDS_PER_MINUTE;
        }

        boolean doall = false;
        if (days > 0) {
            builder.append(days);
            builder.append('d');
            doall = true;
        }
        if (doall || hours > 0) {
            builder.append(hours);
            builder.append('h');
            doall = true;
        }
        if (doall || minutes > 0) {
            builder.append(minutes);
            builder.append('m');
            doall = true;
        }
        if (doall || seconds > 0) {
            builder.append(seconds);
            builder.append('s');
            doall = true;
        }
        builder.append(millis);
        builder.append("ms");
    }

    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long duration, PrintWriter pw) {
        if (duration == 0) {
            pw.print("0");
            return;
        }
        if (duration > 0) {
            pw.print("+");
        } else {
            pw.print("-");
            duration = -duration;
        }

        int millis = (int)(duration%1000);
        int seconds = (int) Math.floor(duration / 1000);
        int days = 0, hours = 0, minutes = 0;

        if (seconds > SECONDS_PER_DAY) {
            days = seconds / SECONDS_PER_DAY;
            seconds -= days * SECONDS_PER_DAY;
        }
        if (seconds > SECONDS_PER_HOUR) {
            hours = seconds / SECONDS_PER_HOUR;
            seconds -= hours * SECONDS_PER_HOUR;
        }
        if (seconds > SECONDS_PER_MINUTE) {
            minutes = seconds / SECONDS_PER_MINUTE;
            seconds -= minutes * SECONDS_PER_MINUTE;
        }

        boolean doall = false;
        if (days > 0) {
            pw.print(days);
            pw.print('d');
            doall = true;
        }
        if (doall || hours > 0) {
            pw.print(hours);
            pw.print('h');
            doall = true;
        }
        if (doall || minutes > 0) {
            pw.print(minutes);
            pw.print('m');
            doall = true;
        }
        if (doall || seconds > 0) {
            pw.print(seconds);
            pw.print('s');
            doall = true;
        }
        pw.print(millis);
        pw.print("ms");
    }


    /** @hide Just for debugging; not internationalized. */
    public static void formatDuration(long time, long now, PrintWriter pw) {
        if (time == 0) {
            pw.print("--");
            return;
        }
        formatDuration(time-now, pw);
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -18,17 +18,31 @@ package com.android.internal.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.Toast;

public class PlatLogoActivity extends Activity {
    Toast mToast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        mToast = Toast.makeText(this, "Zombie art by Jack Larson", Toast.LENGTH_SHORT);

        ImageView content = new ImageView(this);
        content.setImageResource(com.android.internal.R.drawable.platlogo);
        content.setScaleType(ImageView.ScaleType.FIT_CENTER);
        
        setContentView(content);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_UP) {
            mToast.show();
        }
        return super.dispatchTouchEvent(ev);
    }
}
Loading