Merge "Protobufferize PowerManager dumpsys"

This commit is contained in:
Netta Peterbursky
2017-02-24 21:36:14 +00:00
committed by Android (Google) Code Review
13 changed files with 1135 additions and 29 deletions

View File

@@ -18,8 +18,10 @@ package android.os;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.LooperProto;
import android.util.Log;
import android.util.Printer;
import android.util.proto.ProtoOutputStream;
/**
* Class used to run a message loop for a thread. Threads by default do
@@ -289,6 +291,16 @@ public final class Looper {
mQueue.dump(pw, prefix + " ");
}
/** @hide */
public void writeToProto(ProtoOutputStream proto, long fieldId) {
final long looperToken = proto.start(fieldId);
proto.write(LooperProto.THREAD_NAME, mThread.getName());
proto.write(LooperProto.THREAD_ID, mThread.getId());
proto.write(LooperProto.IDENTITY_HASH_CODE, System.identityHashCode(this));
mQueue.writeToProto(proto, LooperProto.QUEUE);
proto.end(looperToken);
}
@Override
public String toString() {
return "Looper (" + mThread.getName() + ", tid " + mThread.getId()

View File

@@ -16,13 +16,15 @@
package android.os;
import android.os.MessageProto;
import android.util.TimeUtils;
import android.util.proto.ProtoOutputStream;
/**
*
*
* Defines a message containing a description and arbitrary data object that can be
* sent to a {@link Handler}. This object contains two extra int fields and an
* extra object field that allow you to not do allocations in many cases.
* extra object field that allow you to not do allocations in many cases.
*
* <p class="note">While the constructor of Message is public, the best way to get
* one of these is to call {@link #obtain Message.obtain()} or one of the
@@ -31,7 +33,7 @@ import android.util.TimeUtils;
*/
public final class Message implements Parcelable {
/**
* User-defined message code so that the recipient can identify
* User-defined message code so that the recipient can identify
* what this message is about. Each {@link Handler} has its own name-space
* for message codes, so you do not need to worry about yours conflicting
* with other handlers.
@@ -43,7 +45,7 @@ public final class Message implements Parcelable {
* {@link #setData(Bundle) setData()} if you only need to store a
* few integer values.
*/
public int arg1;
public int arg1;
/**
* arg1 and arg2 are lower-cost alternatives to using
@@ -58,7 +60,7 @@ public final class Message implements Parcelable {
* be non-null if it contains a Parcelable of a framework class (not one
* implemented by the application). For other data transfer use
* {@link #setData}.
*
*
* <p>Note that Parcelable objects here are not supported prior to
* the {@link android.os.Build.VERSION_CODES#FROYO} release.
*/
@@ -97,13 +99,13 @@ public final class Message implements Parcelable {
/*package*/ int flags;
/*package*/ long when;
/*package*/ Bundle data;
/*package*/ Handler target;
/*package*/ Runnable callback;
// sometimes we store linked lists of these things
/*package*/ Message next;
@@ -216,9 +218,9 @@ public final class Message implements Parcelable {
}
/**
* Same as {@link #obtain()}, but sets the values of the <em>target</em>, <em>what</em>,
* Same as {@link #obtain()}, but sets the values of the <em>target</em>, <em>what</em>,
* <em>arg1</em>, and <em>arg2</em> members.
*
*
* @param h The <em>target</em> value to set.
* @param what The <em>what</em> value to set.
* @param arg1 The <em>arg1</em> value to set.
@@ -236,9 +238,9 @@ public final class Message implements Parcelable {
}
/**
* Same as {@link #obtain()}, but sets the values of the <em>target</em>, <em>what</em>,
* Same as {@link #obtain()}, but sets the values of the <em>target</em>, <em>what</em>,
* <em>arg1</em>, <em>arg2</em>, and <em>obj</em> members.
*
*
* @param h The <em>target</em> value to set.
* @param what The <em>what</em> value to set.
* @param arg1 The <em>arg1</em> value to set.
@@ -246,7 +248,7 @@ public final class Message implements Parcelable {
* @param obj The <em>obj</em> value to set.
* @return A Message object from the global pool.
*/
public static Message obtain(Handler h, int what,
public static Message obtain(Handler h, int what,
int arg1, int arg2, Object obj) {
Message m = obtain();
m.target = h;
@@ -339,7 +341,7 @@ public final class Message implements Parcelable {
public long getWhen() {
return when;
}
public void setTarget(Handler target) {
this.target = target;
}
@@ -367,8 +369,8 @@ public final class Message implements Parcelable {
public Runnable getCallback() {
return callback;
}
/**
/**
* Obtains a Bundle of arbitrary data associated with this
* event, lazily creating it if necessary. Set this value by calling
* {@link #setData(Bundle)}. Note that when transferring data across
@@ -383,11 +385,11 @@ public final class Message implements Parcelable {
if (data == null) {
data = new Bundle();
}
return data;
}
/**
/**
* Like getData(), but does not lazily create the Bundle. A null
* is returned if the Bundle does not already exist. See
* {@link #getData} for further information on this.
@@ -401,7 +403,7 @@ public final class Message implements Parcelable {
/**
* Sets a Bundle of arbitrary data values. Use arg1 and arg2 members
* as a lower cost way to send a few simple integer values, if you can.
* @see #getData()
* @see #getData()
* @see #peekData()
*/
public void setData(Bundle data) {
@@ -520,6 +522,37 @@ public final class Message implements Parcelable {
return b.toString();
}
void writeToProto(ProtoOutputStream proto, long fieldId) {
final long messageToken = proto.start(fieldId);
proto.write(MessageProto.WHEN, when);
if (target != null) {
if (callback != null) {
proto.write(MessageProto.CALLBACK, callback.getClass().getName());
} else {
proto.write(MessageProto.WHAT, what);
}
if (arg1 != 0) {
proto.write(MessageProto.ARG1, arg1);
}
if (arg2 != 0) {
proto.write(MessageProto.ARG2, arg2);
}
if (obj != null) {
proto.write(MessageProto.OBJ, obj.toString());
}
proto.write(MessageProto.TARGET, target.getClass().getName());
} else {
proto.write(MessageProto.BARRIER, arg1);
}
proto.end(messageToken);
}
public static final Parcelable.Creator<Message> CREATOR
= new Parcelable.Creator<Message>() {
public Message createFromParcel(Parcel source) {
@@ -527,12 +560,12 @@ public final class Message implements Parcelable {
msg.readFromParcel(source);
return msg;
}
public Message[] newArray(int size) {
return new Message[size];
}
};
public int describeContents() {
return 0;
}

View File

@@ -18,9 +18,11 @@ package android.os;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.os.MessageQueueProto;
import android.util.Log;
import android.util.Printer;
import android.util.SparseArray;
import android.util.proto.ProtoOutputStream;
import java.io.FileDescriptor;
import java.lang.annotation.Retention;
@@ -31,7 +33,7 @@ import java.util.ArrayList;
* Low-level class holding the list of messages to be dispatched by a
* {@link Looper}. Messages are not added directly to a MessageQueue,
* but rather through {@link Handler} objects associated with the Looper.
*
*
* <p>You can retrieve the MessageQueue for the current thread with
* {@link Looper#myQueue() Looper.myQueue()}.
*/
@@ -770,6 +772,18 @@ public final class MessageQueue {
}
}
void writeToProto(ProtoOutputStream proto, long fieldId) {
final long messageQueueToken = proto.start(fieldId);
synchronized (this) {
for (Message msg = mMessages; msg != null; msg = msg.next) {
msg.writeToProto(proto, MessageQueueProto.MESSAGES);
}
proto.write(MessageQueueProto.IS_POLLING_LOCKED, isPollingLocked());
proto.write(MessageQueueProto.IS_QUITTING, mQuitting);
}
proto.end(messageQueueToken);
}
/**
* Callback interface for discovering when a thread is going to block
* waiting for more messages.

View File

@@ -1,6 +1,8 @@
package android.os;
import android.os.WorkSourceProto;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import java.util.Arrays;
@@ -296,7 +298,7 @@ public class WorkSource implements Parcelable {
break;
}
if (mUids[i] == uid) {
int diff = mNames[i].compareTo(name);
int diff = mNames[i].compareTo(name);
if (diff > 0) {
break;
}
@@ -692,6 +694,20 @@ public class WorkSource implements Parcelable {
return result.toString();
}
/** @hide */
public void writeToProto(ProtoOutputStream proto, long fieldId) {
final long workSourceToken = proto.start(fieldId);
for (int i = 0; i < mNum; i++) {
final long contentProto = proto.start(WorkSourceProto.WORK_SOURCE_CONTENTS);
proto.write(WorkSourceProto.WorkSourceContentProto.UID, mUids[i]);
if (mNames != null) {
proto.write(WorkSourceProto.WorkSourceContentProto.NAME, mNames[i]);
}
proto.end(contentProto);
}
proto.end(workSourceToken);
}
public static final Parcelable.Creator<WorkSource> CREATOR
= new Parcelable.Creator<WorkSource>() {
public WorkSource createFromParcel(Parcel in) {