diff options
Diffstat (limited to 'core/java')
24 files changed, 1062 insertions, 133 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 606d803..e38bbb3 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -4701,6 +4701,47 @@ public class Activity extends ContextThemeWrapper } /** + * Set a label to be used in the Recents task display. The activities of a task are traversed + * in order from the topmost activity to the bottommost. As soon as one activity returns a + * non-null Recents label the traversal is ended and that value will be used in + * {@link ActivityManager.RecentTaskInfo#activityLabel} + * + * @see ActivityManager#getRecentTasks + * + * @param recentsLabel The label to use in the RecentTaskInfo. + */ + public void setRecentsLabel(CharSequence recentsLabel) { + try { + ActivityManagerNative.getDefault().setRecentsLabel(mToken, recentsLabel); + } catch (RemoteException e) { + } + } + + /** + * Set an icon to be used in the Recents task display. The activities of a task are traversed + * in order from the topmost activity to the bottommost. As soon as one activity returns a + * non-null Recents icon the traversal is ended and that value will be used in + * {@link ActivityManager.RecentTaskInfo#activityIcon}. + * + * @see ActivityManager#getRecentTasks + * + * @param recentsIcon The Bitmap to use in the RecentTaskInfo. + */ + public void setRecentsIcon(Bitmap recentsIcon) { + final Bitmap scaledIcon; + if (recentsIcon != null) { + final int size = ActivityManager.getLauncherLargeIconSizeInner(this); + scaledIcon = Bitmap.createScaledBitmap(recentsIcon, size, size, true); + } else { + scaledIcon = null; + } + try { + ActivityManagerNative.getDefault().setRecentsIcon(mToken, scaledIcon); + } catch (RemoteException e) { + } + } + + /** * Sets the visibility of the progress bar in the title. * <p> * In order for the progress bar to be shown, the feature must be requested diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 0787ef1..d386eff 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -510,11 +510,23 @@ public class ActivityManager { public int stackId; /** - * The id the of the user the task was running as. + * The id of the user the task was running as. * @hide */ public int userId; + /** + * The label of the highest activity in the task stack to have set a label + * {@link Activity#setRecentsLabel}. + */ + public CharSequence activityLabel; + + /** + * The Bitmap icon of the highest activity in the task stack to set a Bitmap using + * {@link Activity#setRecentsIcon}. + */ + public Bitmap activityIcon; + public RecentTaskInfo() { } @@ -536,6 +548,14 @@ public class ActivityManager { ComponentName.writeToParcel(origActivity, dest); TextUtils.writeToParcel(description, dest, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); + TextUtils.writeToParcel(activityLabel, dest, + Parcelable.PARCELABLE_WRITE_RETURN_VALUE); + if (activityIcon == null) { + dest.writeInt(0); + } else { + dest.writeInt(1); + activityIcon.writeToParcel(dest, 0); + } dest.writeInt(stackId); dest.writeInt(userId); } @@ -550,6 +570,8 @@ public class ActivityManager { } origActivity = ComponentName.readFromParcel(source); description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); + activityLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); + activityIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null; stackId = source.readInt(); userId = source.readInt(); } @@ -1970,7 +1992,11 @@ public class ActivityManager { * @return dimensions of square icons in terms of pixels */ public int getLauncherLargeIconSize() { - final Resources res = mContext.getResources(); + return getLauncherLargeIconSizeInner(mContext); + } + + static int getLauncherLargeIconSizeInner(Context context) { + final Resources res = context.getResources(); final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); final int sw = res.getConfiguration().smallestScreenWidthDp; diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index 373a8a3..707a038 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -2128,6 +2128,25 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM reply.writeInt(isInLockTaskMode ? 1 : 0); return true; } + + case SET_RECENTS_LABEL_TRANSACTION: { + data.enforceInterface(IActivityManager.descriptor); + IBinder token = data.readStrongBinder(); + CharSequence recentsLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(data); + setRecentsLabel(token, recentsLabel); + reply.writeNoException(); + return true; + } + + case SET_RECENTS_ICON_TRANSACTION: { + data.enforceInterface(IActivityManager.descriptor); + IBinder token = data.readStrongBinder(); + Bitmap recentsIcon = data.readInt() != 0 + ? Bitmap.CREATOR.createFromParcel(data) : null; + setRecentsIcon(token, recentsIcon); + reply.writeNoException(); + return true; + } } return super.onTransact(code, data, reply, flags); @@ -4899,5 +4918,36 @@ class ActivityManagerProxy implements IActivityManager return isInLockTaskMode; } + public void setRecentsLabel(IBinder token, CharSequence recentsLabel) throws RemoteException + { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + data.writeInterfaceToken(IActivityManager.descriptor); + data.writeStrongBinder(token); + TextUtils.writeToParcel(recentsLabel, data, 0); + mRemote.transact(SET_RECENTS_LABEL_TRANSACTION, data, reply, IBinder.FLAG_ONEWAY); + reply.readException(); + data.recycle(); + reply.recycle(); + } + + public void setRecentsIcon(IBinder token, Bitmap recentsBitmap) throws RemoteException + { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + data.writeInterfaceToken(IActivityManager.descriptor); + data.writeStrongBinder(token); + if (recentsBitmap != null) { + data.writeInt(1); + recentsBitmap.writeToParcel(data, 0); + } else { + data.writeInt(0); + } + mRemote.transact(SET_RECENTS_ICON_TRANSACTION, data, reply, IBinder.FLAG_ONEWAY); + reply.readException(); + data.recycle(); + reply.recycle(); + } + private IBinder mRemote; } diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index cb06a42..3b56839 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -436,6 +436,12 @@ public interface IActivityManager extends IInterface { /** @hide */ public boolean isInLockTaskMode() throws RemoteException; + /** @hide */ + public void setRecentsLabel(IBinder token, CharSequence recentsLabel) throws RemoteException; + + /** @hide */ + public void setRecentsIcon(IBinder token, Bitmap recentsBitmap) throws RemoteException; + /* * Private non-Binder interfaces */ @@ -735,4 +741,6 @@ public interface IActivityManager extends IInterface { int START_LOCK_TASK_BY_TOKEN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+214; int STOP_LOCK_TASK_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+215; int IS_IN_LOCK_TASK_MODE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+216; + int SET_RECENTS_LABEL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+217; + int SET_RECENTS_ICON_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+218; } diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 2e8fbb6..13e74da 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -504,6 +504,13 @@ public class Notification implements Parcelable public static final String CATEGORY_SERVICE = "service"; /** + * Notification category: a specific, timely recommendation for a single thing. + * For example, a news app might want to recommend a news story it believes the user will + * want to read next. + */ + public static final String CATEGORY_RECOMMENDATION = "recommendation"; + + /** * Notification category: ongoing information about device or contextual status. */ public static final String CATEGORY_STATUS = "status"; diff --git a/core/java/android/hardware/hdmi/HdmiCec.java b/core/java/android/hardware/hdmi/HdmiCec.java new file mode 100644 index 0000000..c95431a --- /dev/null +++ b/core/java/android/hardware/hdmi/HdmiCec.java @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.hdmi; + +/** + * Defines constants and utility methods related to HDMI-CEC protocol. + */ +public final class HdmiCec { + + /** TV device type. */ + public static final int DEVICE_TV = 0; + + /** Recording device type. */ + public static final int DEVICE_RECORDER = 1; + + /** Device type reserved for future usage. */ + public static final int DEVICE_RESERVED = 2; + + /** Tuner device type. */ + public static final int DEVICE_TUNER = 3; + + /** Playback device type. */ + public static final int DEVICE_PLAYBACK = 4; + + /** Audio system device type. */ + public static final int DEVICE_AUDIO_SYSTEM = 5; + + // Value indicating the device is not an active source. + public static final int DEVICE_INACTIVE = -1; + + /** Logical address for TV */ + public static final int ADDR_TV = 0; + + /** Logical address for recorder 1 */ + public static final int ADDR_RECORDER_1 = 1; + + /** Logical address for recorder 2 */ + public static final int ADDR_RECORDER_2 = 2; + + /** Logical address for tuner 1 */ + public static final int ADDR_TUNER_1 = 3; + + /** Logical address for playback 1 */ + public static final int ADDR_PLAYBACK_1 = 4; + + /** Logical address for audio system */ + public static final int ADDR_AUDIO_SYSTEM = 5; + + /** Logical address for tuner 2 */ + public static final int ADDR_TUNER_2 = 6; + + /** Logical address for tuner 3 */ + public static final int ADDR_TUNER_3 = 7; + + /** Logical address for playback 2 */ + public static final int ADDR_PLAYBACK_2 = 8; + + /** Logical address for recorder 3 */ + public static final int ADDR_RECORDER_3 = 9; + + /** Logical address for tuner 4 */ + public static final int ADDR_TUNER_4 = 10; + + /** Logical address for playback 3 */ + public static final int ADDR_PLAYBACK_3 = 11; + + /** Logical address reserved for future usage */ + public static final int ADDR_RESERVED_1 = 12; + + /** Logical address reserved for future usage */ + public static final int ADDR_RESERVED_2 = 13; + + /** Logical address for TV other than the one assigned with {@link #ADDR_TV} */ + public static final int ADDR_FREE_USE = 14; + + /** Logical address for devices to which address cannot be allocated */ + public static final int ADDR_UNREGISTERED = 15; + + /** Logical address used in the destination address field for broadcast messages */ + public static final int ADDR_BROADCAST = 15; + + /** Logical address used to indicate it is not initialized or invalid. */ + public static final int ADDR_INVALID = -1; + + // TODO: Complete the list of CEC messages definition. + public static final int MESSAGE_ACTIVE_SOURCE = 0x9D; + + private static final int[] ADDRESS_TO_TYPE = { + DEVICE_TV, // ADDR_TV + DEVICE_RECORDER, // ADDR_RECORDER_1 + DEVICE_RECORDER, // ADDR_RECORDER_2 + DEVICE_TUNER, // ADDR_TUNER_1 + DEVICE_PLAYBACK, // ADDR_PLAYBACK_1 + DEVICE_AUDIO_SYSTEM, // ADDR_AUDIO_SYSTEM + DEVICE_TUNER, // ADDR_TUNER_2 + DEVICE_TUNER, // ADDR_TUNER_3 + DEVICE_PLAYBACK, // ADDR_PLAYBACK_2 + DEVICE_RECORDER, // ADDR_RECORDER_3 + DEVICE_TUNER, // ADDR_TUNER_4 + DEVICE_PLAYBACK, // ADDR_PLAYBACK_3 + }; + + private static final String[] DEFAULT_NAMES = { + "TV", + "Recorder_1", + "Recorder_2", + "Tuner_1", + "Playback_1", + "AudioSystem", + "Tuner_2", + "Tuner_3", + "Playback_2", + "Recorder_3", + "Tuner_4", + "Playback_3", + }; + + private HdmiCec() { } // Prevents instantiation. + + /** + * Check if the given type is valid. A valid type is one of the actual + * logical device types defined in the standard ({@link #DEVICE_TV}, + * {@link #DEVICE_PLAYBACK}, {@link #DEVICE_TUNER}, {@link #DEVICE_RECORDER}, + * and {@link #DEVICE_AUDIO_SYSTEM}). + * + * @param type device type + * @return true if the given type is valid + */ + public static boolean isValidType(int type) { + return (DEVICE_TV <= type && type <= DEVICE_AUDIO_SYSTEM) + && type != DEVICE_RESERVED; + } + + /** + * Check if the given logical address is valid. A logical address is valid + * if it is one allocated for an actual device which allows communication + * with other logical devices. + * + * @param address logical address + * @return true if the given address is valid + */ + public static boolean isValidAddress(int address) { + // TODO: We leave out the address 'free use(14)' for now. Check this later + // again to make sure it is a valid address for communication. + return (ADDR_TV <= address && address <= ADDR_PLAYBACK_3); + } + + /** + * Return the device type for the given logical address. + * + * @param address logical address + * @return device type for the given logical address; DEVICE_INACTIVE + * if the address is not valid. + */ + public static int getTypeFromAddress(int address) { + if (isValidAddress(address)) { + return ADDRESS_TO_TYPE[address]; + } + return DEVICE_INACTIVE; + } + + /** + * Return the default device name for a logical address. This is the name + * by which the logical device is known to others until a name is + * set explicitly using HdmiCecService.setOsdName. + * + * @param address logical address + * @return default device name; empty string if the address is not valid + */ + public static String getDefaultDeviceName(int address) { + if (isValidAddress(address)) { + return DEFAULT_NAMES[address]; + } + return ""; + } +} diff --git a/core/java/android/hardware/hdmi/HdmiCecMessage.aidl b/core/java/android/hardware/hdmi/HdmiCecMessage.aidl new file mode 100644 index 0000000..6687ba4 --- /dev/null +++ b/core/java/android/hardware/hdmi/HdmiCecMessage.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.hdmi; + +parcelable HdmiCecMessage; diff --git a/core/java/android/hardware/hdmi/HdmiCecMessage.java b/core/java/android/hardware/hdmi/HdmiCecMessage.java new file mode 100644 index 0000000..be94d97 --- /dev/null +++ b/core/java/android/hardware/hdmi/HdmiCecMessage.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.hdmi; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Arrays; + +/** + * A class to encapsulate HDMI-CEC message used for the devices connected via + * HDMI cable to communicate with one another. A message is defined by its + * source and destination address, command (or opcode), and optional parameters. + */ +public final class HdmiCecMessage implements Parcelable { + + private static final int MAX_MESSAGE_LENGTH = 16; + + private final int mSource; + private final int mDestination; + + private final int mOpcode; + private final byte[] mParams; + + /** + * Constructor. + */ + public HdmiCecMessage(int source, int destination, int opcode, byte[] params) { + mSource = source; + mDestination = destination; + mOpcode = opcode; + mParams = Arrays.copyOf(params, params.length); + } + + /** + * Return the source address field of the message. It is the logical address + * of the device which generated the message. + * + * @return source address + */ + public int getSource() { + return mSource; + } + + /** + * Return the destination address field of the message. It is the logical address + * of the device to which the message is sent. + * + * @return destination address + */ + public int getDestination() { + return mDestination; + } + + /** + * Return the opcode field of the message. It is the type of the message that + * tells the destination device what to do. + * + * @return opcode + */ + public int getOpcode() { + return mOpcode; + } + + /** + * Return the parameter field of the message. The contents of parameter varies + * from opcode to opcode, and is used together with opcode to describe + * the action for the destination device to take. + * + * @return parameter + */ + public byte[] getParams() { + return mParams; + } + + /** + * Describe the kinds of special objects contained in this Parcelable's + * marshalled representation. + */ + @Override + public int describeContents() { + return 0; + } + + /** + * Flatten this object in to a Parcel. + * + * @param dest The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. + * May be 0 or {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE}. + */ + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(mSource); + dest.writeInt(mDestination); + dest.writeInt(mOpcode); + dest.writeInt(mParams.length); + dest.writeByteArray(mParams); + } + + public static final Parcelable.Creator<HdmiCecMessage> CREATOR + = new Parcelable.Creator<HdmiCecMessage>() { + /** + * Rebuild a HdmiCecMessage previously stored with writeToParcel(). + * @param p HdmiCecMessage object to read the Rating from + * @return a new HdmiCecMessage created from the data in the parcel + */ + public HdmiCecMessage createFromParcel(Parcel p) { + int source = p.readInt(); + int destination = p.readInt(); + int opcode = p.readInt(); + byte[] params = new byte[p.readInt()]; + p.readByteArray(params); + return new HdmiCecMessage(source, destination, opcode, params); + } + public HdmiCecMessage[] newArray(int size) { + return new HdmiCecMessage[size]; + } + }; + + @Override + public String toString() { + StringBuffer s = new StringBuffer(); + s.append(String.format("src: %d dst: %d op: %2X params: ", mSource, mDestination, mOpcode)); + for (byte data : mParams) { + s.append(String.format("%02X ", data)); + } + return s.toString(); + } +} + diff --git a/core/java/android/hardware/hdmi/IHdmiCecListener.aidl b/core/java/android/hardware/hdmi/IHdmiCecListener.aidl new file mode 100644 index 0000000..d281ce6 --- /dev/null +++ b/core/java/android/hardware/hdmi/IHdmiCecListener.aidl @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.hdmi; + +import android.hardware.hdmi.HdmiCecMessage; + +/** + * Interface definition for HdmiCecService to do interprocess communcation. + * + * @hide + */ +oneway interface IHdmiCecListener { + void onMessageReceived(in HdmiCecMessage message); + void onCableStatusChanged(in boolean connected); +} diff --git a/core/java/android/hardware/hdmi/IHdmiCecService.aidl b/core/java/android/hardware/hdmi/IHdmiCecService.aidl new file mode 100644 index 0000000..6fefcf8 --- /dev/null +++ b/core/java/android/hardware/hdmi/IHdmiCecService.aidl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.hdmi; + +import android.hardware.hdmi.HdmiCecMessage; +import android.hardware.hdmi.IHdmiCecListener; +import android.os.IBinder; + +/** + * Binder interface that components running in the appplication process + * will use to enable HDMI-CEC protocol exchange with other devices. + * + * @hide + */ +interface IHdmiCecService { + IBinder allocateLogicalDevice(int type, IHdmiCecListener listener); + void removeServiceListener(IBinder b, IHdmiCecListener listener); + void setOsdName(IBinder b, String name); + void sendActiveSource(IBinder b); + void sendInactiveSource(IBinder b); + void sendImageViewOn(IBinder b); + void sendTextViewOn(IBinder b); + void sendGiveDevicePowerStatus(IBinder b, int address); + void sendMessage(IBinder b, in HdmiCecMessage message); +} + diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index b0d94d5..87beb95 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -155,6 +155,7 @@ public abstract class BatteryStats implements Parcelable { private static final String FOREGROUND_DATA = "fg"; private static final String WAKELOCK_DATA = "wl"; private static final String KERNEL_WAKELOCK_DATA = "kwl"; + private static final String WAKEUP_REASON_DATA = "wr"; private static final String NETWORK_DATA = "nt"; private static final String USER_ACTIVITY_DATA = "ua"; private static final String BATTERY_DATA = "bt"; @@ -201,6 +202,25 @@ public abstract class BatteryStats implements Parcelable { } /** + * State for keeping track of long counting information. + */ + public static abstract class LongCounter { + + /** + * Returns the count associated with this Counter for the + * selected type of statistics. + * + * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT + */ + public abstract long getCountLocked(int which); + + /** + * Temporary for debugging. + */ + public abstract void logState(Printer pw, String prefix); + } + + /** * State for keeping track of timing information. */ public static abstract class Timer { @@ -552,8 +572,8 @@ public abstract class BatteryStats implements Parcelable { // These states always appear directly in the first int token // of a delta change; they should be ones that change relatively // frequently. - public static final int STATE_WAKE_LOCK_FLAG = 1<<31; - public static final int STATE_SENSOR_ON_FLAG = 1<<30; + public static final int STATE_CPU_RUNNING_FLAG = 1<<31; + public static final int STATE_WAKE_LOCK_FLAG = 1<<30; public static final int STATE_GPS_ON_FLAG = 1<<29; public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; public static final int STATE_WIFI_SCAN_FLAG = 1<<27; @@ -562,9 +582,9 @@ public abstract class BatteryStats implements Parcelable { public static final int STATE_WIFI_RUNNING_FLAG = 1<<24; // These are on the lower bits used for the command; if they change // we need to write another int of data. - public static final int STATE_PHONE_SCANNING_FLAG = 1<<23; + public static final int STATE_SENSOR_ON_FLAG = 1<<23; public static final int STATE_AUDIO_ON_FLAG = 1<<22; - public static final int STATE_VIDEO_ON_FLAG = 1<<21; + public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; public static final int STATE_SCREEN_ON_FLAG = 1<<20; public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18; @@ -577,6 +597,7 @@ public abstract class BatteryStats implements Parcelable { public int states; + public static final int STATE2_VIDEO_ON_FLAG = 1<<0; public int states2; // The wake lock that was acquired at this point. @@ -653,6 +674,7 @@ public abstract class BatteryStats implements Parcelable { | ((((int)batteryVoltage)<<16)&0xffff0000); dest.writeInt(bat); dest.writeInt(states); + dest.writeInt(states2); if (wakelockTag != null) { wakelockTag.writeToParcel(dest, flags); } @@ -680,6 +702,7 @@ public abstract class BatteryStats implements Parcelable { batteryTemperature = (short)(bat2&0xffff); batteryVoltage = (char)((bat2>>16)&0xffff); states = src.readInt(); + states2 = src.readInt(); if ((bat&0x10000000) != 0) { wakelockTag = localWakelockTag; wakelockTag.readFromParcel(src); @@ -718,6 +741,7 @@ public abstract class BatteryStats implements Parcelable { batteryTemperature = 0; batteryVoltage = 0; states = 0; + states2 = 0; wakelockTag = null; wakeReasonTag = null; eventCode = EVENT_NONE; @@ -744,6 +768,7 @@ public abstract class BatteryStats implements Parcelable { batteryTemperature = o.batteryTemperature; batteryVoltage = o.batteryVoltage; states = o.states; + states2 = o.states2; if (o.wakelockTag != null) { wakelockTag = localWakelockTag; wakelockTag.setTo(o.wakelockTag); @@ -774,6 +799,7 @@ public abstract class BatteryStats implements Parcelable { && batteryTemperature == o.batteryTemperature && batteryVoltage == o.batteryVoltage && states == o.states + && states2 == o.states2 && currentTime == o.currentTime; } @@ -970,6 +996,15 @@ public abstract class BatteryStats implements Parcelable { public abstract int getMobileRadioActiveCount(int which); /** + * Returns the time in microseconds that is the difference between the mobile radio + * time we saw based on the elapsed timestamp when going down vs. the given time stamp + * from the radio. + * + * {@hide} + */ + public abstract long getMobileRadioActiveAdjustedTime(int which); + + /** * Returns the time in microseconds that the mobile network has been active * (in a high power state) but not being able to blame on an app. * @@ -1026,9 +1061,10 @@ public abstract class BatteryStats implements Parcelable { * {@hide} */ public abstract int getPhoneDataConnectionCount(int dataType, int which); - + public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] { + new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), @@ -1039,7 +1075,6 @@ public abstract class BatteryStats implements Parcelable { new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running", "Wr"), new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), - new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video", "v"), new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), @@ -1062,6 +1097,11 @@ public abstract class BatteryStats implements Parcelable { SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), }; + public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS + = new BitDescription[] { + new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), + }; + public static final String[] HISTORY_EVENT_NAMES = new String[] { "null", "proc", "fg", "top", "sync" }; @@ -1294,6 +1334,8 @@ public abstract class BatteryStats implements Parcelable { */ public abstract long computeRealtime(long curTime, int which); + public abstract Map<String, ? extends LongCounter> getWakeupReasonStats(); + public abstract Map<String, ? extends Timer> getKernelWakelockStats(); /** Returns the number of different speeds that the CPU can run at */ @@ -1554,7 +1596,8 @@ public abstract class BatteryStats implements Parcelable { wifiRunningTime / 1000, bluetoothOnTime / 1000, mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, fullWakeLockTimeTotal, partialWakeLockTimeTotal, - getInputEventCount(which), getMobileRadioActiveTime(rawRealtime, which)); + getInputEventCount(which), getMobileRadioActiveTime(rawRealtime, which), + getMobileRadioActiveAdjustedTime(which)); // Dump screen brightness stats Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; @@ -1626,16 +1669,22 @@ public abstract class BatteryStats implements Parcelable { } if (reqUid < 0) { - Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); + Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); if (kernelWakelocks.size() > 0) { - for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { + for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { sb.setLength(0); printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); - - dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(), + dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(), sb.toString()); } } + Map<String, ? extends LongCounter> wakeupReasons = getWakeupReasonStats(); + if (wakeupReasons.size() > 0) { + for (Map.Entry<String, ? extends LongCounter> ent : wakeupReasons.entrySet()) { + dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, + "\"" + ent.getKey() + "\"", ent.getValue().getCountLocked(which)); + } + } } BatteryStatsHelper helper = new BatteryStatsHelper(context); @@ -2111,6 +2160,18 @@ public abstract class BatteryStats implements Parcelable { pw.println(sb.toString()); } + final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); + if (mobileActiveAdjustedTime != 0) { + sb.setLength(0); + sb.append(prefix); + sb.append(" Mobile radio active adjusted time: "); + formatTimeMs(sb, mobileActiveAdjustedTime / 1000); + sb.append("("); + sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); + sb.append(")"); + pw.println(sb.toString()); + } + pw.print(prefix); pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); @@ -2346,24 +2407,49 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } } - } - if (timers.size() > 0) { - Collections.sort(timers, timerComparator); - pw.print(prefix); pw.println(" All partial wake locks:"); - for (int i=0; i<timers.size(); i++) { - TimerEntry timer = timers.get(i); - sb.setLength(0); - sb.append(" Wake lock "); - UserHandle.formatUid(sb, timer.mId); - sb.append(" "); - sb.append(timer.mName); - printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); - sb.append(" realtime"); - pw.println(sb.toString()); + if (timers.size() > 0) { + Collections.sort(timers, timerComparator); + pw.print(prefix); pw.println(" All partial wake locks:"); + for (int i=0; i<timers.size(); i++) { + TimerEntry timer = timers.get(i); + sb.setLength(0); + sb.append(" Wake lock "); + UserHandle.formatUid(sb, timer.mId); + sb.append(" "); + sb.append(timer.mName); + printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); + sb.append(" realtime"); + pw.println(sb.toString()); + } + timers.clear(); + pw.println(); + } + + Map<String, ? extends LongCounter> wakeupReasons = getWakeupReasonStats(); + if (wakeupReasons.size() > 0) { + pw.print(prefix); pw.println(" All wakeup reasons:"); + final ArrayList<TimerEntry> reasons = new ArrayList<TimerEntry>(); + for (Map.Entry<String, ? extends LongCounter> ent : wakeupReasons.entrySet()) { + BatteryStats.LongCounter counter = ent.getValue(); + reasons.add(new TimerEntry(ent.getKey(), 0, null, + ent.getValue().getCountLocked(which))); + } + Collections.sort(reasons, timerComparator); + for (int i=0; i<reasons.size(); i++) { + TimerEntry timer = reasons.get(i); + String linePrefix = ": "; + sb.setLength(0); + sb.append(prefix); + sb.append(" Wakeup reason "); + sb.append(timer.mName); + sb.append(": "); + formatTimeMs(sb, timer.mTime); + sb.append("realtime"); + pw.println(sb.toString()); + } + pw.println(); } - timers.clear(); - pw.println(); } for (int iu=0; iu<NU; iu++) { @@ -2772,6 +2858,7 @@ public abstract class BatteryStats implements Parcelable { public static class HistoryPrinter { int oldState = 0; + int oldState2 = 0; int oldLevel = -1; int oldStatus = -1; int oldHealth = -1; @@ -2780,7 +2867,8 @@ public abstract class BatteryStats implements Parcelable { int oldVolt = -1; long lastTime = -1; - public void printNextItem(PrintWriter pw, HistoryItem rec, long now, boolean checkin) { + public void printNextItem(PrintWriter pw, HistoryItem rec, long now, boolean checkin, + boolean verbose) { if (!checkin) { pw.print(" "); if (now >= 0) { @@ -2831,16 +2919,18 @@ public abstract class BatteryStats implements Parcelable { if (rec.batteryLevel < 10) pw.print("00"); else if (rec.batteryLevel < 100) pw.print("0"); pw.print(rec.batteryLevel); - pw.print(" "); - if (rec.states < 0) ; - else if (rec.states < 0x10) pw.print("0000000"); - else if (rec.states < 0x100) pw.print("000000"); - else if (rec.states < 0x1000) pw.print("00000"); - else if (rec.states < 0x10000) pw.print("0000"); - else if (rec.states < 0x100000) pw.print("000"); - else if (rec.states < 0x1000000) pw.print("00"); - else if (rec.states < 0x10000000) pw.print("0"); - pw.print(Integer.toHexString(rec.states)); + if (verbose) { + pw.print(" "); + if (rec.states < 0) ; + else if (rec.states < 0x10) pw.print("0000000"); + else if (rec.states < 0x100) pw.print("000000"); + else if (rec.states < 0x1000) pw.print("00000"); + else if (rec.states < 0x10000) pw.print("0000"); + else if (rec.states < 0x100000) pw.print("000"); + else if (rec.states < 0x1000000) pw.print("00"); + else if (rec.states < 0x10000000) pw.print("0"); + pw.print(Integer.toHexString(rec.states)); + } } else { if (oldLevel != rec.batteryLevel) { oldLevel = rec.batteryLevel; @@ -2934,6 +3024,8 @@ public abstract class BatteryStats implements Parcelable { } printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, HISTORY_STATE_DESCRIPTIONS, !checkin); + printBitDescriptions(pw, oldState2, rec.states2, null, + HISTORY_STATE2_DESCRIPTIONS, !checkin); if (rec.wakeReasonTag != null) { if (checkin) { pw.print(",Wr="); @@ -3010,6 +3102,7 @@ public abstract class BatteryStats implements Parcelable { public static final int DUMP_CHARGED_ONLY = 1<<1; public static final int DUMP_HISTORY_ONLY = 1<<2; public static final int DUMP_INCLUDE_HISTORY = 1<<3; + public static final int DUMP_VERBOSE = 1<<4; /** * Dumps a human-readable summary of the battery statistics to the given PrintWriter. @@ -3047,7 +3140,8 @@ public abstract class BatteryStats implements Parcelable { while (getNextHistoryLocked(rec)) { lastTime = rec.time; if (rec.time >= histStart) { - hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, false); + hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, false, + (flags&DUMP_VERBOSE) != 0); } } if (histStart >= 0) { @@ -3064,7 +3158,7 @@ public abstract class BatteryStats implements Parcelable { pw.println("Old battery History:"); HistoryPrinter hprinter = new HistoryPrinter(); while (getNextOldHistoryLocked(rec)) { - hprinter.printNextItem(pw, rec, now, false); + hprinter.printNextItem(pw, rec, now, false, (flags&DUMP_VERBOSE) != 0); } pw.println(); } finally { @@ -3150,7 +3244,7 @@ public abstract class BatteryStats implements Parcelable { if (rec.time >= histStart) { pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); pw.print(HISTORY_DATA); pw.print(','); - hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, true); + hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, true, false); } } if (histStart >= 0) { diff --git a/core/java/android/os/storage/IMountService.java b/core/java/android/os/storage/IMountService.java index b97734e..4180860 100644 --- a/core/java/android/os/storage/IMountService.java +++ b/core/java/android/os/storage/IMountService.java @@ -694,6 +694,36 @@ public interface IMountService extends IInterface { return _result; } + public String getPassword() throws RemoteException { + Parcel _data = Parcel.obtain(); + Parcel _reply = Parcel.obtain(); + String _result; + try { + _data.writeInterfaceToken(DESCRIPTOR); + mRemote.transact(Stub.TRANSACTION_getPassword, _data, _reply, 0); + _reply.readException(); + _result = _reply.readString(); + } finally { + _reply.recycle(); + _data.recycle(); + } + return _result; + } + + public void clearPassword() throws RemoteException { + Parcel _data = Parcel.obtain(); + Parcel _reply = Parcel.obtain(); + String _result; + try { + _data.writeInterfaceToken(DESCRIPTOR); + mRemote.transact(Stub.TRANSACTION_clearPassword, _data, _reply, 0); + _reply.readException(); + } finally { + _reply.recycle(); + _data.recycle(); + } + } + public StorageVolume[] getVolumeList() throws RemoteException { Parcel _data = Parcel.obtain(); Parcel _reply = Parcel.obtain(); @@ -846,7 +876,11 @@ public interface IMountService extends IInterface { static final int TRANSACTION_mkdirs = IBinder.FIRST_CALL_TRANSACTION + 34; - static final int TRANSACTION_getPasswordType = IBinder.FIRST_CALL_TRANSACTION + 36; + static final int TRANSACTION_getPasswordType = IBinder.FIRST_CALL_TRANSACTION + 35; + + static final int TRANSACTION_getPassword = IBinder.FIRST_CALL_TRANSACTION + 36; + + static final int TRANSACTION_clearPassword = IBinder.FIRST_CALL_TRANSACTION + 37; /** * Cast an IBinder object into an IMountService interface, generating a @@ -1208,6 +1242,19 @@ public interface IMountService extends IInterface { reply.writeInt(result); return true; } + case TRANSACTION_getPassword: { + data.enforceInterface(DESCRIPTOR); + String result = getPassword(); + reply.writeNoException(); + reply.writeString(result); + return true; + } + case TRANSACTION_clearPassword: { + data.enforceInterface(DESCRIPTOR); + clearPassword(); + reply.writeNoException(); + return true; + } } return super.onTransact(code, data, reply, flags); } @@ -1446,4 +1493,15 @@ public interface IMountService extends IInterface { * @return PasswordType */ public int getPasswordType() throws RemoteException; + + /** + * Get password from vold + * @return password or empty string + */ + public String getPassword() throws RemoteException; + + /** + * Securely clear password from vold + */ + public void clearPassword() throws RemoteException; } diff --git a/core/java/android/provider/SearchIndexableData.java b/core/java/android/provider/SearchIndexableData.java index 6381884..719dcea 100644 --- a/core/java/android/provider/SearchIndexableData.java +++ b/core/java/android/provider/SearchIndexableData.java @@ -21,15 +21,16 @@ import android.content.Context; import java.util.Locale; /** - * The Indexable data for Search. This abstract class defines the common parts for all search - * indexable data. + * The Indexable data for Search. + * + * This abstract class defines the common parts for all search indexable data. * * @hide */ public abstract class SearchIndexableData { /** - * The context for the data. Will usually allow to retrieve some resources. + * The context for the data. Will usually allow retrieving some resources. * * @see Context */ @@ -41,6 +42,11 @@ public abstract class SearchIndexableData { public Locale locale; /** + * Tells if the data will be included into the search results. This is application specific. + */ + public boolean enabled; + + /** * The rank for the data. This is application specific. */ public int rank; @@ -103,6 +109,7 @@ public abstract class SearchIndexableData { * Default constructor. */ public SearchIndexableData() { + enabled = true; } /** @@ -113,5 +120,6 @@ public abstract class SearchIndexableData { public SearchIndexableData(Context ctx) { context = ctx; locale = Locale.getDefault(); + enabled = true; } } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 1d6e998..a94a671 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -659,14 +659,14 @@ public final class ViewRootImpl implements ViewParent, mHandler.sendMessageAtFrontOfQueue(mHandler.obtainMessage(MSG_FLUSH_LAYER_UPDATES)); } - public void attachFunctor(int functor) { + public void attachFunctor(long functor) { //noinspection SimplifiableIfStatement if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) { mAttachInfo.mHardwareRenderer.attachFunctor(mAttachInfo, functor); } } - public void detachFunctor(int functor) { + public void detachFunctor(long functor) { mBlockResizeBuffer = true; if (mAttachInfo.mHardwareRenderer != null) { mAttachInfo.mHardwareRenderer.detachFunctor(functor); diff --git a/core/java/android/view/VolumePanel.java b/core/java/android/view/VolumePanel.java index 52f9c0b..b05225b 100644 --- a/core/java/android/view/VolumePanel.java +++ b/core/java/android/view/VolumePanel.java @@ -787,7 +787,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie return; } - mVibrator.vibrate(VIBRATE_DURATION); + mVibrator.vibrate(VIBRATE_DURATION, AudioManager.STREAM_SYSTEM); } protected void onRemoteVolumeChanged(int streamType, int flags) { diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl index 5ba5c57..32f700d 100644 --- a/core/java/com/android/internal/app/IBatteryStats.aidl +++ b/core/java/com/android/internal/app/IBatteryStats.aidl @@ -55,7 +55,7 @@ interface IBatteryStats { void noteScreenOff(); void noteInputEvent(); void noteUserActivity(int uid, int event); - void noteDataConnectionActive(int type, boolean active); + void noteDataConnectionActive(int type, boolean active, long timestampNs); void notePhoneOn(); void notePhoneOff(); void notePhoneSignalStrength(in SignalStrength signalStrength); diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 082f1a5..1d88533 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -87,7 +87,7 @@ public final class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version - private static final int VERSION = 99 + (USE_OLD_HISTORY ? 1000 : 0); + private static final int VERSION = 101 + (USE_OLD_HISTORY ? 1000 : 0); // Maximum number of items we will record in the history. private static final int MAX_HISTORY_ITEMS = 2000; @@ -191,7 +191,7 @@ public final class BatteryStatsImpl extends BatteryStats { long mHistoryBaseTime; boolean mHaveBatteryLevel = false; - boolean mRecordingHistory = true; + boolean mRecordingHistory = false; int mNumHistoryItems; static final int MAX_HISTORY_BUFFER = 128*1024; // 128KB @@ -200,6 +200,7 @@ public final class BatteryStatsImpl extends BatteryStats { final HistoryItem mHistoryLastWritten = new HistoryItem(); final HistoryItem mHistoryLastLastWritten = new HistoryItem(); final HistoryItem mHistoryReadTmp = new HistoryItem(); + final HistoryItem mHistoryAddTmp = new HistoryItem(); final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<HistoryTag, Integer>(); String[] mReadHistoryStrings; int[] mReadHistoryUids; @@ -209,7 +210,8 @@ public final class BatteryStatsImpl extends BatteryStats { int mHistoryBufferLastPos = -1; boolean mHistoryOverflow = false; long mLastHistoryElapsedRealtime = 0; - long mLastHistoryUptime = 0; + long mTrackRunningHistoryElapsedRealtime = 0; + long mTrackRunningHistoryUptime = 0; final HistoryItem mHistoryCur = new HistoryItem(); @@ -287,6 +289,7 @@ public final class BatteryStatsImpl extends BatteryStats { boolean mMobileRadioActive; StopwatchTimer mMobileRadioActiveTimer; StopwatchTimer mMobileRadioActivePerAppTimer; + LongSamplingCounter mMobileRadioActiveAdjustedTime; LongSamplingCounter mMobileRadioActiveUnknownTime; LongSamplingCounter mMobileRadioActiveUnknownCount; @@ -330,12 +333,21 @@ public final class BatteryStatsImpl extends BatteryStats { private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<String, SamplingTimer>(); - public Map<String, ? extends SamplingTimer> getKernelWakelockStats() { + public Map<String, ? extends Timer> getKernelWakelockStats() { return mKernelWakelockStats; } private static int sKernelWakelockUpdateVersion = 0; + String mLastWakeupReason = null; + long mLastWakeupUptimeMs = 0; + private final HashMap<String, LongSamplingCounter> mWakeupReasonStats = + new HashMap<String, LongSamplingCounter>(); + + public Map<String, ? extends LongCounter> getWakeupReasonStats() { + return mWakeupReasonStats; + } + private static final int[] PROC_WAKELOCKS_FORMAT = new int[] { Process.PROC_TAB_TERM|Process.PROC_OUT_STRING| // 0: name Process.PROC_QUOTES, @@ -719,7 +731,7 @@ public final class BatteryStatsImpl extends BatteryStats { } } - public static class LongSamplingCounter implements TimeBaseObs { + public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { final TimeBase mTimeBase; long mCount; long mLoadedCount; @@ -775,6 +787,14 @@ public final class BatteryStatsImpl extends BatteryStats { return val; } + @Override + public void logState(Printer pw, String prefix) { + pw.println(prefix + "mCount=" + mCount + + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount + + " mUnpluggedCount=" + mUnpluggedCount + + " mPluggedCount=" + mPluggedCount); + } + void addCountLocked(long count) { mCount += count; } @@ -1409,6 +1429,10 @@ public final class BatteryStatsImpl extends BatteryStats { return 0; } + long getLastUpdateTimeMs() { + return mUpdateTime; + } + void stopRunningLocked(long elapsedRealtimeMs) { // Ignore attempt to stop a timer that isn't running if (mNesting == 0) { @@ -1502,6 +1526,19 @@ public final class BatteryStatsImpl extends BatteryStats { } } + /* + * Get the wakeup reason counter, and create a new one if one + * doesn't already exist. + */ + public LongSamplingCounter getWakeupReasonCounterLocked(String name) { + LongSamplingCounter counter = mWakeupReasonStats.get(name); + if (counter == null) { + counter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); + mWakeupReasonStats.put(name, counter); + } + return counter; + } + private final Map<String, KernelWakelockStats> readKernelWakelockStats() { FileInputStream is; @@ -1759,6 +1796,10 @@ public final class BatteryStatsImpl extends BatteryStats { if (stateIntChanged) { firstToken |= DELTA_STATE_FLAG; } + final boolean state2IntChanged = cur.states2 != last.states2; + if (state2IntChanged) { + firstToken |= DELTA_STATE2_FLAG; + } if (cur.wakelockTag != null || cur.wakeReasonTag != null) { firstToken |= DELTA_WAKELOCK_FLAG; } @@ -1795,6 +1836,11 @@ public final class BatteryStatsImpl extends BatteryStats { + " batteryPlugType=" + cur.batteryPlugType + " states=0x" + Integer.toHexString(cur.states)); } + if (state2IntChanged) { + dest.writeInt(cur.states2); + if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" + + Integer.toHexString(cur.states2)); + } if (cur.wakelockTag != null || cur.wakeReasonTag != null) { int wakeLockIndex; int wakeReasonIndex; @@ -1917,6 +1963,12 @@ public final class BatteryStatsImpl extends BatteryStats { cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); } + if ((firstToken&DELTA_STATE2_FLAG) != 0) { + cur.states2 = src.readInt(); + if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" + + Integer.toHexString(cur.states2)); + } + if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { int indexes = src.readInt(); int wakeLockIndex = indexes&0xffff; @@ -1958,29 +2010,34 @@ public final class BatteryStatsImpl extends BatteryStats { } } - void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs) { + void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { if (!mHaveBatteryLevel || !mRecordingHistory) { return; } final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; - final int diffStates = mHistoryLastWritten.states^mHistoryCur.states; + final int diffStates = mHistoryLastWritten.states^cur.states; + final int diffStates2 = mHistoryLastWritten.states2^cur.states2; final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; + final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" + Integer.toHexString(diffStates) + " lastDiff=" - + Integer.toHexString(lastDiffStates)); + + Integer.toHexString(lastDiffStates) + " diff2=" + + Integer.toHexString(diffStates2) + " lastDiff2=" + + Integer.toHexString(lastDiffStates2)); if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 - && (mHistoryLastWritten.wakelockTag == null || mHistoryCur.wakelockTag == null) - && (mHistoryLastWritten.wakeReasonTag == null || mHistoryCur.wakeReasonTag == null) + && (diffStates2&lastDiffStates2) == 0 + && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) + && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE - || mHistoryCur.eventCode == HistoryItem.EVENT_NONE) - && mHistoryLastWritten.batteryLevel == mHistoryCur.batteryLevel - && mHistoryLastWritten.batteryStatus == mHistoryCur.batteryStatus - && mHistoryLastWritten.batteryHealth == mHistoryCur.batteryHealth - && mHistoryLastWritten.batteryPlugType == mHistoryCur.batteryPlugType - && mHistoryLastWritten.batteryTemperature == mHistoryCur.batteryTemperature - && mHistoryLastWritten.batteryVoltage == mHistoryCur.batteryVoltage) { + || cur.eventCode == HistoryItem.EVENT_NONE) + && mHistoryLastWritten.batteryLevel == cur.batteryLevel + && mHistoryLastWritten.batteryStatus == cur.batteryStatus + && mHistoryLastWritten.batteryHealth == cur.batteryHealth + && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType + && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature + && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { // We can merge this new change in with the last one. Merging is // allowed as long as only the states have changed, and within those states // as long as no bit has changed both between now and the last entry, as @@ -1994,23 +2051,23 @@ public final class BatteryStatsImpl extends BatteryStats { // Note that the condition above made sure that we aren't in a case where // both it and the current history item have a wakelock tag. if (mHistoryLastWritten.wakelockTag != null) { - mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; - mHistoryCur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); + cur.wakelockTag = cur.localWakelockTag; + cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); } // If the last written history had a wake reason tag, we need to retain it. // Note that the condition above made sure that we aren't in a case where // both it and the current history item have a wakelock tag. if (mHistoryLastWritten.wakeReasonTag != null) { - mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; - mHistoryCur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); + cur.wakeReasonTag = cur.localWakeReasonTag; + cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); } // If the last written history had an event, we need to retain it. // Note that the condition above made sure that we aren't in a case where // both it and the current history item have an event. if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { - mHistoryCur.eventCode = mHistoryLastWritten.eventCode; - mHistoryCur.eventTag = mHistoryCur.localEventTag; - mHistoryCur.eventTag.setTo(mHistoryLastWritten.eventTag); + cur.eventCode = mHistoryLastWritten.eventCode; + cur.eventTag = cur.localEventTag; + cur.eventTag.setTo(mHistoryLastWritten.eventTag); } mHistoryLastWritten.setTo(mHistoryLastLastWritten); } @@ -2019,8 +2076,8 @@ public final class BatteryStatsImpl extends BatteryStats { if (dataSize >= MAX_HISTORY_BUFFER) { if (!mHistoryOverflow) { mHistoryOverflow = true; - addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE); - addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW); + addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); + addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); return; } @@ -2028,43 +2085,64 @@ public final class BatteryStatsImpl extends BatteryStats { // record changes to the battery level and the most interesting states. // Once we've reached the maximum maximum number of items, we only // record changes to the battery level. - if (mHistoryLastWritten.batteryLevel == mHistoryCur.batteryLevel && + if (mHistoryLastWritten.batteryLevel == cur.batteryLevel && (dataSize >= MAX_MAX_HISTORY_BUFFER - || ((mHistoryLastWritten.states^mHistoryCur.states) + || ((mHistoryLastWritten.states^cur.states) & HistoryItem.MOST_INTERESTING_STATES) == 0)) { return; } - addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE); + addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); return; } - addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE); + addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); } - private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd) { + private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, + HistoryItem cur) { if (mIteratingHistory) { throw new IllegalStateException("Can't do this while iterating history!"); } mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); mHistoryLastLastWritten.setTo(mHistoryLastWritten); - mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, mHistoryCur); + mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); mLastHistoryElapsedRealtime = elapsedRealtimeMs; - mLastHistoryUptime = uptimeMs; - mHistoryCur.wakelockTag = null; - mHistoryCur.wakeReasonTag = null; - mHistoryCur.eventCode = HistoryItem.EVENT_NONE; - mHistoryCur.eventTag = null; + cur.wakelockTag = null; + cur.wakeReasonTag = null; + cur.eventCode = HistoryItem.EVENT_NONE; + cur.eventTag = null; if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos + " now " + mHistoryBuffer.dataPosition() + " size is now " + mHistoryBuffer.dataSize()); } int mChangedStates = 0; + int mChangedStates2 = 0; void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { - addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs); + if (mTrackRunningHistoryElapsedRealtime != 0) { + final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; + final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; + if (diffUptime < (diffElapsed-20)) { + final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); + mHistoryAddTmp.setTo(mHistoryLastWritten); + mHistoryAddTmp.wakelockTag = null; + mHistoryAddTmp.wakeReasonTag = null; + mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; + mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; + addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); + } + } + mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; + mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; + mTrackRunningHistoryUptime = uptimeMs; + addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); + } + + void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { + addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); if (!USE_OLD_HISTORY) { return; @@ -2080,25 +2158,28 @@ public final class BatteryStatsImpl extends BatteryStats { // into one record. if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) - && ((mHistoryEnd.states^mHistoryCur.states)&mChangedStates) == 0) { + && ((mHistoryEnd.states^cur.states)&mChangedStates) == 0 + && ((mHistoryEnd.states2^cur.states2)&mChangedStates2) == 0) { // If the current is the same as the one before, then we no // longer need the entry. if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) - && mHistoryLastEnd.sameNonEvent(mHistoryCur)) { + && mHistoryLastEnd.sameNonEvent(cur)) { mHistoryLastEnd.next = null; mHistoryEnd.next = mHistoryCache; mHistoryCache = mHistoryEnd; mHistoryEnd = mHistoryLastEnd; mHistoryLastEnd = null; } else { - mChangedStates |= mHistoryEnd.states^mHistoryCur.states; - mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, mHistoryCur); + mChangedStates |= mHistoryEnd.states^cur.states; + mChangedStates2 |= mHistoryEnd.states^cur.states2; + mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); } return; } mChangedStates = 0; + mChangedStates2 = 0; if (mNumHistoryItems == MAX_HISTORY_ITEMS || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { @@ -2111,9 +2192,9 @@ public final class BatteryStatsImpl extends BatteryStats { // Once we've reached the maximum maximum number of items, we only // record changes to the battery level. if (mHistoryEnd != null && mHistoryEnd.batteryLevel - == mHistoryCur.batteryLevel && + == cur.batteryLevel && (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS - || ((mHistoryEnd.states^mHistoryCur.states) + || ((mHistoryEnd.states^cur.states) & HistoryItem.MOST_INTERESTING_STATES) == 0)) { return; } @@ -2128,17 +2209,18 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryCur.eventTag = mHistoryCur.localEventTag; mHistoryCur.eventTag.string = name; mHistoryCur.eventTag.uid = uid; - addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs); + // XXX should be calling addHistoryRecordLocked()? + addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); } - void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd) { + void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { HistoryItem rec = mHistoryCache; if (rec != null) { mHistoryCache = rec.next; } else { rec = new HistoryItem(); } - rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, mHistoryCur); + rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); addHistoryRecordLocked(rec); } @@ -2168,7 +2250,8 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryBaseTime = 0; mLastHistoryElapsedRealtime = 0; - mLastHistoryUptime = 0; + mTrackRunningHistoryElapsedRealtime = 0; + mTrackRunningHistoryUptime = 0; mHistoryBuffer.setDataSize(0); mHistoryBuffer.setDataPosition(0); @@ -2284,6 +2367,7 @@ public final class BatteryStatsImpl extends BatteryStats { if (type == WAKE_TYPE_PARTIAL) { // Only care about partial wake locks, since full wake locks // will be canceled when the user puts the screen to sleep. + aggregateLastWakeupUptimeLocked(uptime); if (mWakeLockNesting == 0) { mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " @@ -2372,14 +2456,26 @@ public final class BatteryStatsImpl extends BatteryStats { } } - public void noteWakeupReasonLocked(int irq, String reason) { + void aggregateLastWakeupUptimeLocked(long uptimeMs) { + if (mLastWakeupReason != null) { + long deltaUptime = uptimeMs - mLastWakeupUptimeMs; + LongSamplingCounter timer = getWakeupReasonCounterLocked(mLastWakeupReason); + timer.addCountLocked(deltaUptime); + mLastWakeupReason = null; + } + } + + public void noteWakeupReasonLocked(String reason) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); - if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason irq #" + irq + "\"" + reason +"\": " + if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason reason \"" + reason +"\": " + Integer.toHexString(mHistoryCur.states)); + aggregateLastWakeupUptimeLocked(uptime); mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; mHistoryCur.wakeReasonTag.string = reason; - mHistoryCur.wakeReasonTag.uid = irq; + mHistoryCur.wakeReasonTag.uid = 0; + mLastWakeupReason = reason; + mLastWakeupUptimeMs = uptime; addHistoryRecordLocked(elapsedRealtime, uptime); } @@ -2670,13 +2766,28 @@ public final class BatteryStatsImpl extends BatteryStats { } } - public void noteDataConnectionActive(int type, boolean active) { + public void noteDataConnectionActive(int type, boolean active, long timestampNs) { if (ConnectivityManager.isNetworkTypeMobile(type)) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); if (mMobileRadioActive != active) { - if (active) mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; - else mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; + long realElapsedRealtimeMs; + if (active) { + realElapsedRealtimeMs = elapsedRealtime; + mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; + } else { + realElapsedRealtimeMs = timestampNs / (1000*1000); + long lastUpdateTimeMs = mMobileRadioActiveTimer.getLastUpdateTimeMs(); + if (realElapsedRealtimeMs < lastUpdateTimeMs) { + Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs + + " is before start time " + lastUpdateTimeMs); + realElapsedRealtimeMs = elapsedRealtime; + } else if (realElapsedRealtimeMs < elapsedRealtime) { + mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime + - realElapsedRealtimeMs); + } + mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; + } if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); @@ -2685,9 +2796,9 @@ public final class BatteryStatsImpl extends BatteryStats { mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); } else { - updateNetworkActivityLocked(NET_UPDATE_MOBILE, elapsedRealtime); - mMobileRadioActiveTimer.stopRunningLocked(elapsedRealtime); - mMobileRadioActivePerAppTimer.stopRunningLocked(elapsedRealtime); + mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); + mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); + updateNetworkActivityLocked(NET_UPDATE_MOBILE, realElapsedRealtimeMs); } } } @@ -2978,7 +3089,7 @@ public final class BatteryStatsImpl extends BatteryStats { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); if (!mVideoOn) { - mHistoryCur.states |= HistoryItem.STATE_VIDEO_ON_FLAG; + mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); @@ -2993,7 +3104,7 @@ public final class BatteryStatsImpl extends BatteryStats { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); if (mVideoOn) { - mHistoryCur.states &= ~HistoryItem.STATE_VIDEO_ON_FLAG; + mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(elapsedRealtime, uptime); @@ -3398,6 +3509,10 @@ public final class BatteryStatsImpl extends BatteryStats { return mMobileRadioActiveTimer.getCountLocked(which); } + @Override public long getMobileRadioActiveAdjustedTime(int which) { + return mMobileRadioActiveAdjustedTime.getCountLocked(which); + } + @Override public long getMobileRadioActiveUnknownTime(int which) { return mMobileRadioActiveUnknownTime.getCountLocked(which); } @@ -5458,6 +5573,7 @@ public final class BatteryStatsImpl extends BatteryStats { } mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase); mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase); + mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); mWifiOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase); @@ -5543,9 +5659,9 @@ public final class BatteryStatsImpl extends BatteryStats { PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); pw.println("Histories differ!"); pw.println("Old history:"); - (new HistoryPrinter()).printNextItem(pw, out, now, false); + (new HistoryPrinter()).printNextItem(pw, out, now, false, true); pw.println("New history:"); - (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, now, false); + (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, now, false, true); pw.flush(); } } @@ -5719,6 +5835,7 @@ public final class BatteryStatsImpl extends BatteryStats { } mMobileRadioActiveTimer.reset(false); mMobileRadioActivePerAppTimer.reset(false); + mMobileRadioActiveAdjustedTime.reset(false); mMobileRadioActiveUnknownTime.reset(false); mMobileRadioActiveUnknownCount.reset(false); mWifiOnTimer.reset(false); @@ -5744,7 +5861,14 @@ public final class BatteryStatsImpl extends BatteryStats { } mKernelWakelockStats.clear(); } - + + if (mWakeupReasonStats.size() > 0) { + for (LongSamplingCounter timer : mWakeupReasonStats.values()) { + mOnBatteryScreenOffTimeBase.remove(timer); + } + mWakeupReasonStats.clear(); + } + initDischarge(); clearHistoryLocked(); @@ -5828,9 +5952,10 @@ public final class BatteryStatsImpl extends BatteryStats { mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " + Integer.toHexString(mHistoryCur.states)); - mHistoryCur.currentTime = System.currentTimeMillis(); - addHistoryBufferLocked(mSecRealtime, mSecUptime, HistoryItem.CMD_CURRENT_TIME); - mHistoryCur.currentTime = 0; + if (reset) { + mRecordingHistory = true; + startRecordingHistory(mSecRealtime, mSecUptime, reset); + } addHistoryRecordLocked(mSecRealtime, mSecUptime); mDischargeCurrentLevel = mDischargeUnplugLevel = level; if (mScreenOn) { @@ -5843,9 +5968,6 @@ public final class BatteryStatsImpl extends BatteryStats { mDischargeAmountScreenOn = 0; mDischargeAmountScreenOff = 0; updateTimeBasesLocked(true, !mScreenOn, uptime, realtime); - if (reset) { - initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); - } } else { pullPendingStateUpdatesLocked(); mHistoryCur.batteryLevel = (byte)level; @@ -5868,6 +5990,18 @@ public final class BatteryStatsImpl extends BatteryStats { } } + private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, + boolean reset) { + mRecordingHistory = true; + mHistoryCur.currentTime = System.currentTimeMillis(); + addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, + mHistoryCur); + mHistoryCur.currentTime = 0; + if (reset) { + initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); + } + } + // This should probably be exposed in the API, though it's not critical private static final int BATTERY_PLUGGED_NONE = 0; @@ -5895,7 +6029,15 @@ public final class BatteryStatsImpl extends BatteryStats { } if (onBattery) { mDischargeCurrentLevel = level; - mRecordingHistory = true; + if (!mRecordingHistory) { + mRecordingHistory = true; + startRecordingHistory(elapsedRealtime, uptime, true); + } + } else if (level < 96) { + if (!mRecordingHistory) { + mRecordingHistory = true; + startRecordingHistory(elapsedRealtime, uptime, true); + } } if (onBattery != mOnBattery) { mHistoryCur.batteryLevel = (byte)level; @@ -6497,15 +6639,14 @@ public final class BatteryStatsImpl extends BatteryStats { } if (mHistoryBuffer.dataPosition() > 0) { + mRecordingHistory = true; final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); if (USE_OLD_HISTORY) { - addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START); + addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); } - addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START); - mHistoryCur.currentTime = System.currentTimeMillis(); - addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_CURRENT_TIME); - mHistoryCur.currentTime = 0; + addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); + startRecordingHistory(elapsedRealtime, uptime, false); } } @@ -6681,6 +6822,7 @@ public final class BatteryStatsImpl extends BatteryStats { mMobileRadioActive = false; mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); + mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); mWifiOn = false; @@ -6708,6 +6850,18 @@ public final class BatteryStatsImpl extends BatteryStats { } } + int NWR = in.readInt(); + if (NWR > 10000) { + Slog.w(TAG, "File corrupt: too many wakeup reasons " + NWR); + return; + } + for (int iwr = 0; iwr < NWR; iwr++) { + if (in.readInt() != 0) { + String reasonName = in.readString(); + getWakeupReasonCounterLocked(reasonName).readSummaryFromParcelLocked(in); + } + } + sNumSpeedSteps = in.readInt(); if (sNumSpeedSteps < 0 || sNumSpeedSteps > 100) { throw new BadParcelableException("Bad speed steps in data: " + sNumSpeedSteps); @@ -6915,6 +7069,7 @@ public final class BatteryStatsImpl extends BatteryStats { } mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); @@ -6933,7 +7088,19 @@ public final class BatteryStatsImpl extends BatteryStats { if (kwlt != null) { out.writeInt(1); out.writeString(ent.getKey()); - ent.getValue().writeSummaryFromParcelLocked(out, NOWREAL_SYS); + kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); + } else { + out.writeInt(0); + } + } + + out.writeInt(mWakeupReasonStats.size()); + for (Map.Entry<String, LongSamplingCounter> ent : mWakeupReasonStats.entrySet()) { + LongSamplingCounter counter = ent.getValue(); + if (counter != null) { + out.writeInt(1); + out.writeString(ent.getKey()); + counter.writeSummaryFromParcelLocked(out); } else { out.writeInt(0); } @@ -7171,6 +7338,7 @@ public final class BatteryStatsImpl extends BatteryStats { mMobileRadioActiveTimer = new StopwatchTimer(null, -400, null, mOnBatteryTimeBase, in); mMobileRadioActivePerAppTimer = new StopwatchTimer(null, -401, null, mOnBatteryTimeBase, in); + mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); mWifiOn = false; @@ -7205,12 +7373,22 @@ public final class BatteryStatsImpl extends BatteryStats { for (int ikw = 0; ikw < NKW; ikw++) { if (in.readInt() != 0) { String wakelockName = in.readString(); - in.readInt(); // Extra 0/1 written by Timer.writeTimerToParcel SamplingTimer kwlt = new SamplingTimer(mOnBatteryTimeBase, in); mKernelWakelockStats.put(wakelockName, kwlt); } } + mWakeupReasonStats.clear(); + int NWR = in.readInt(); + for (int iwr = 0; iwr < NWR; iwr++) { + if (in.readInt() != 0) { + String reasonName = in.readString(); + LongSamplingCounter counter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase, + in); + mWakeupReasonStats.put(reasonName, counter); + } + } + mPartialTimers.clear(); mFullTimers.clear(); mWindowTimers.clear(); @@ -7283,6 +7461,7 @@ public final class BatteryStatsImpl extends BatteryStats { } mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); + mMobileRadioActiveAdjustedTime.writeToParcel(out); mMobileRadioActiveUnknownTime.writeToParcel(out); mMobileRadioActiveUnknownCount.writeToParcel(out); mWifiOnTimer.writeToParcel(out, uSecRealtime); @@ -7313,7 +7492,18 @@ public final class BatteryStatsImpl extends BatteryStats { if (kwlt != null) { out.writeInt(1); out.writeString(ent.getKey()); - Timer.writeTimerToParcel(out, kwlt, uSecRealtime); + kwlt.writeToParcel(out, uSecRealtime); + } else { + out.writeInt(0); + } + } + out.writeInt(mWakeupReasonStats.size()); + for (Map.Entry<String, LongSamplingCounter> ent : mWakeupReasonStats.entrySet()) { + LongSamplingCounter counter = ent.getValue(); + if (counter != null) { + out.writeInt(1); + out.writeString(ent.getKey()); + counter.writeToParcel(out); } else { out.writeInt(0); } @@ -7383,6 +7573,8 @@ public final class BatteryStatsImpl extends BatteryStats { } pr.println("*** Mobile network active timer:"); mMobileRadioActiveTimer.logState(pr, " "); + pr.println("*** Mobile network active adjusted timer:"); + mMobileRadioActiveAdjustedTime.logState(pr, " "); pr.println("*** Wifi timer:"); mWifiOnTimer.logState(pr, " "); pr.println("*** WifiRunning timer:"); diff --git a/core/java/com/android/internal/widget/ILockSettings.aidl b/core/java/com/android/internal/widget/ILockSettings.aidl index 91056f1..9501f92 100644 --- a/core/java/com/android/internal/widget/ILockSettings.aidl +++ b/core/java/com/android/internal/widget/ILockSettings.aidl @@ -28,6 +28,7 @@ interface ILockSettings { boolean checkPattern(in String pattern, int userId); void setLockPassword(in String password, int userId); boolean checkPassword(in String password, int userId); + boolean checkVoldPassword(int userId); boolean havePattern(int userId); boolean havePassword(int userId); void removeUser(int userId); diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java index 2d79491..e5aaf7e 100644 --- a/core/java/com/android/internal/widget/LockPatternUtils.java +++ b/core/java/com/android/internal/widget/LockPatternUtils.java @@ -313,6 +313,20 @@ public class LockPatternUtils { } /** + * Check to see if vold already has the password. + * Note that this also clears vold's copy of the password. + * @return Whether the vold password matches or not. + */ + public boolean checkVoldPassword() { + final int userId = getCurrentOrCallingUserId(); + try { + return getLockSettings().checkVoldPassword(userId); + } catch (RemoteException re) { + return false; + } + } + + /** * Check to see if a password matches any of the passwords stored in the * password history. * diff --git a/core/java/com/android/internal/widget/RotarySelector.java b/core/java/com/android/internal/widget/RotarySelector.java index f856027..64ce918 100644 --- a/core/java/com/android/internal/widget/RotarySelector.java +++ b/core/java/com/android/internal/widget/RotarySelector.java @@ -24,6 +24,7 @@ import android.graphics.Paint; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; +import android.media.AudioManager; import android.os.UserHandle; import android.os.Vibrator; import android.provider.Settings; @@ -34,7 +35,9 @@ import android.view.View; import android.view.VelocityTracker; import android.view.ViewConfiguration; import android.view.animation.DecelerateInterpolator; + import static android.view.animation.AnimationUtils.currentAnimationTimeMillis; + import com.android.internal.R; @@ -676,7 +679,7 @@ public class RotarySelector extends View { mVibrator = (android.os.Vibrator) getContext() .getSystemService(Context.VIBRATOR_SERVICE); } - mVibrator.vibrate(duration); + mVibrator.vibrate(duration, AudioManager.STREAM_SYSTEM); } } diff --git a/core/java/com/android/internal/widget/SlidingTab.java b/core/java/com/android/internal/widget/SlidingTab.java index aebc4f6..deb0fd7 100644 --- a/core/java/com/android/internal/widget/SlidingTab.java +++ b/core/java/com/android/internal/widget/SlidingTab.java @@ -21,6 +21,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.media.AudioManager; import android.os.UserHandle; import android.os.Vibrator; import android.provider.Settings; @@ -821,7 +822,7 @@ public class SlidingTab extends ViewGroup { mVibrator = (android.os.Vibrator) getContext() .getSystemService(Context.VIBRATOR_SERVICE); } - mVibrator.vibrate(duration); + mVibrator.vibrate(duration, AudioManager.STREAM_SYSTEM); } } diff --git a/core/java/com/android/internal/widget/WaveView.java b/core/java/com/android/internal/widget/WaveView.java index 0c5993b..86f14b3 100644 --- a/core/java/com/android/internal/widget/WaveView.java +++ b/core/java/com/android/internal/widget/WaveView.java @@ -25,6 +25,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; +import android.media.AudioManager; import android.os.UserHandle; import android.os.Vibrator; import android.provider.Settings; @@ -582,7 +583,7 @@ public class WaveView extends View implements ValueAnimator.AnimatorUpdateListen mVibrator = (android.os.Vibrator) getContext() .getSystemService(Context.VIBRATOR_SERVICE); } - mVibrator.vibrate(duration); + mVibrator.vibrate(duration, AudioManager.STREAM_SYSTEM); } } diff --git a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java index 93ea5b3..772dc5f 100644 --- a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java +++ b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java @@ -30,6 +30,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.drawable.Drawable; +import android.media.AudioManager; import android.os.Bundle; import android.os.UserHandle; import android.os.Vibrator; @@ -564,7 +565,7 @@ public class GlowPadView extends View { mContext.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, 1, UserHandle.USER_CURRENT) != 0; if (mVibrator != null && hapticEnabled) { - mVibrator.vibrate(mVibrationDuration); + mVibrator.vibrate(mVibrationDuration, AudioManager.STREAM_SYSTEM); } } diff --git a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java index e22d1e8..4648f39 100644 --- a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java +++ b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java @@ -31,6 +31,7 @@ import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.RectF; import android.graphics.drawable.Drawable; +import android.media.AudioManager; import android.os.Bundle; import android.os.UserHandle; import android.os.Vibrator; @@ -599,7 +600,7 @@ public class MultiWaveView extends View { mContext.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, 1, UserHandle.USER_CURRENT) != 0; if (mVibrator != null && hapticEnabled) { - mVibrator.vibrate(mVibrationDuration); + mVibrator.vibrate(mVibrationDuration, AudioManager.STREAM_SYSTEM); } } |
