Merge "Track USB data link in batterystats" into pi-dev

am: 3787f73198

Change-Id: Id0d95a1516a21d9c7e9739a1237558f47f3d2e9c
This commit is contained in:
Mike Ma
2018-03-27 21:43:23 +00:00
committed by android-build-merger
5 changed files with 70 additions and 3 deletions

View File

@@ -1585,6 +1585,7 @@ public abstract class BatteryStats implements Parcelable {
public static final int STATE2_CAMERA_FLAG = 1<<21;
public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
public static final int STATE2_CELLULAR_HIGH_TX_POWER_FLAG = 1 << 19;
public static final int STATE2_USB_DATA_LINK_FLAG = 1 << 18;
public static final int MOST_INTERESTING_STATES2 =
STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
@@ -2363,8 +2364,7 @@ public abstract class BatteryStats implements Parcelable {
SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
};
public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
= new BitDescription[] {
public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS = new BitDescription[] {
new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
@@ -2375,6 +2375,7 @@ public abstract class BatteryStats implements Parcelable {
new String[] { "off", "light", "full", "???" },
new String[] { "off", "light", "full", "???" }),
new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
new BitDescription(HistoryItem.STATE2_USB_DATA_LINK_FLAG, "usb_data", "Ud"),
new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,

View File

@@ -93,6 +93,7 @@ interface IBatteryStats {
void noteVibratorOff(int uid);
void noteGpsChanged(in WorkSource oldSource, in WorkSource newSource);
void noteGpsSignalQuality(int signalLevel);
void noteUsbConnectionState(boolean connected);
void noteScreenState(int state);
void noteScreenBrightness(int brightness);
void noteUserActivity(int uid, int event);

View File

@@ -767,6 +767,8 @@ public class BatteryStatsImpl extends BatteryStats {
int mCameraOnNesting;
StopwatchTimer mCameraOnTimer;
int mUsbDataState; // 0: unknown, 1: disconnected, 2: connected
int mGpsSignalQualityBin = -1;
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
protected final StopwatchTimer[] mGpsSignalQualityTimer =
@@ -5240,6 +5242,19 @@ public class BatteryStatsImpl extends BatteryStats {
}
}
public void noteUsbConnectionStateLocked(boolean connected) {
int newState = connected ? 2 : 1;
if (mUsbDataState != newState) {
mUsbDataState = newState;
if (connected) {
mHistoryCur.states2 |= HistoryItem.STATE2_USB_DATA_LINK_FLAG;
} else {
mHistoryCur.states2 &= ~HistoryItem.STATE2_USB_DATA_LINK_FLAG;
}
addHistoryRecordLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis());
}
}
void stopAllPhoneSignalStrengthTimersLocked(int except) {
final long elapsedRealtime = mClocks.elapsedRealtime();
for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {

View File

@@ -4229,6 +4229,16 @@
android:exported="false">
</receiver>
<receiver android:name="com.android.server.am.BatteryStatsService$UsbConnectionReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_STATE" />
</intent-filter>
</receiver>
<service android:name="android.hardware.location.GeofenceHardwareService"
android:permission="android.permission.LOCATION_HARDWARE"
android:exported="false" />

View File

@@ -18,9 +18,13 @@ package com.android.server.am;
import android.app.ActivityManager;
import android.bluetooth.BluetoothActivityEnergyInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.hardware.usb.UsbManager;
import android.net.wifi.WifiActivityEnergyInfo;
import android.os.PowerManager.ServiceType;
import android.os.PowerSaveState;
@@ -34,6 +38,7 @@ import android.os.ParcelFileDescriptor;
import android.os.ParcelFormatException;
import android.os.PowerManagerInternal;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -70,7 +75,6 @@ import java.nio.CharBuffer;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
@@ -684,6 +688,13 @@ public final class BatteryStatsService extends IBatteryStats.Stub
}
}
public void noteUsbConnectionState(boolean connected) {
enforceCallingPermission();
synchronized (mStats) {
mStats.noteUsbConnectionStateLocked(connected);
}
}
public void notePhoneSignalStrength(SignalStrength signalStrength) {
enforceCallingPermission();
synchronized (mStats) {
@@ -1116,6 +1127,35 @@ public final class BatteryStatsService extends IBatteryStats.Stub
Binder.getCallingPid(), Binder.getCallingUid(), null);
}
public final static class UsbConnectionReceiver extends BroadcastReceiver {
private static final String TAG = UsbConnectionReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
final Intent usbState = context.registerReceiver(null, new IntentFilter(UsbManager.ACTION_USB_STATE));
if (usbState != null) {
handleUsbState(usbState);
}
} else if (UsbManager.ACTION_USB_STATE.equals(action)) {
handleUsbState(intent);
}
}
private void handleUsbState(Intent intent) {
IBatteryStats bs = getService();
if (bs == null) {
Slog.w(TAG, "Could not access batterystats");
return;
}
boolean connected = intent.getExtras().getBoolean(UsbManager.USB_CONNECTED);
try {
bs.noteUsbConnectionState(connected);
} catch (RemoteException e) {
Slog.w(TAG, "Could not access batterystats: ", e);
}
}
}
final class WakeupReasonThread extends Thread {
private static final int MAX_REASON_SIZE = 512;
private CharsetDecoder mDecoder;