AI 143748: Fix issue #1743326 (More battery stats)

Adds stats for:
  - Number of raw user events that have happened in the system.
  - Number of times user activity has been reported, dividied by UID and type of activity.
  - Duration of screen brightness levels in 4 buckets.
  - Per-UID tracking of who has turned on Wifi and how long we can attribute it being on because of them.
  BUG=1743326

Automated import of CL 143748
This commit is contained in:
Dianne Hackborn
2009-03-31 12:11:48 -07:00
committed by The Android Open Source Project
parent 3f46f0a0cd
commit 65c8e11a31
9 changed files with 623 additions and 80 deletions

View File

@@ -47,6 +47,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.provider.Settings;
import android.util.Log;
@@ -167,6 +168,11 @@ public class WifiService extends IWifiManager.Stub {
private char[] mScanResultBuffer;
private boolean mNeedReconfig;
/*
* Last UID that asked to enable WIFI.
*/
private int mLastEnableUid = Process.myUid();
/**
* Number of allowed radio frequency channels in various regulatory domains.
* This list is sufficient for 802.11b/g networks (2.4GHz range).
@@ -239,7 +245,7 @@ public class WifiService extends IWifiManager.Stub {
},
new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
setWifiEnabledBlocking(wifiEnabled, false);
setWifiEnabledBlocking(wifiEnabled, false, Process.myUid());
}
/**
@@ -455,7 +461,8 @@ public class WifiService extends IWifiManager.Stub {
synchronized (mWifiHandler) {
sWakeLock.acquire();
sendEnableMessage(enable, true);
mLastEnableUid = Binder.getCallingUid();
sendEnableMessage(enable, true, Binder.getCallingUid());
}
return true;
@@ -465,10 +472,11 @@ public class WifiService extends IWifiManager.Stub {
* Enables/disables Wi-Fi synchronously.
* @param enable {@code true} to turn Wi-Fi on, {@code false} to turn it off.
* @param persist {@code true} if the setting should be persisted.
* @param uid The UID of the process making the request.
* @return {@code true} if the operation succeeds (or if the existing state
* is the same as the requested state)
*/
private boolean setWifiEnabledBlocking(boolean enable, boolean persist) {
private boolean setWifiEnabledBlocking(boolean enable, boolean persist, int uid) {
final int eventualWifiState = enable ? WIFI_STATE_ENABLED : WIFI_STATE_DISABLED;
if (mWifiState == eventualWifiState) {
@@ -478,18 +486,18 @@ public class WifiService extends IWifiManager.Stub {
return false;
}
setWifiEnabledState(enable ? WIFI_STATE_ENABLING : WIFI_STATE_DISABLING);
setWifiEnabledState(enable ? WIFI_STATE_ENABLING : WIFI_STATE_DISABLING, uid);
if (enable) {
if (!WifiNative.loadDriver()) {
Log.e(TAG, "Failed to load Wi-Fi driver.");
setWifiEnabledState(WIFI_STATE_UNKNOWN);
setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
return false;
}
if (!WifiNative.startSupplicant()) {
WifiNative.unloadDriver();
Log.e(TAG, "Failed to start supplicant daemon.");
setWifiEnabledState(WIFI_STATE_UNKNOWN);
setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
return false;
}
registerForBroadcasts();
@@ -503,7 +511,7 @@ public class WifiService extends IWifiManager.Stub {
boolean failedToStopSupplicantOrUnloadDriver = false;
if (!WifiNative.stopSupplicant()) {
Log.e(TAG, "Failed to stop supplicant daemon.");
setWifiEnabledState(WIFI_STATE_UNKNOWN);
setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
failedToStopSupplicantOrUnloadDriver = true;
}
@@ -513,7 +521,7 @@ public class WifiService extends IWifiManager.Stub {
if (!WifiNative.unloadDriver()) {
Log.e(TAG, "Failed to unload Wi-Fi driver.");
if (!failedToStopSupplicantOrUnloadDriver) {
setWifiEnabledState(WIFI_STATE_UNKNOWN);
setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
failedToStopSupplicantOrUnloadDriver = true;
}
}
@@ -527,7 +535,7 @@ public class WifiService extends IWifiManager.Stub {
if (persist) {
persistWifiEnabled(enable);
}
setWifiEnabledState(eventualWifiState);
setWifiEnabledState(eventualWifiState, uid);
/*
* Initialize the hidden networks state and the number of allowed
@@ -541,15 +549,15 @@ public class WifiService extends IWifiManager.Stub {
return true;
}
private void setWifiEnabledState(int wifiState) {
private void setWifiEnabledState(int wifiState, int uid) {
final int previousWifiState = mWifiState;
long ident = Binder.clearCallingIdentity();
try {
if (wifiState == WIFI_STATE_ENABLED) {
mBatteryStats.noteWifiOn();
mBatteryStats.noteWifiOn(uid);
} else if (wifiState == WIFI_STATE_DISABLED) {
mBatteryStats.noteWifiOff();
mBatteryStats.noteWifiOff(uid);
}
} catch (RemoteException e) {
} finally {
@@ -1571,10 +1579,10 @@ public class WifiService extends IWifiManager.Stub {
}
};
private void sendEnableMessage(boolean enable, boolean persist) {
private void sendEnableMessage(boolean enable, boolean persist, int uid) {
Message msg = Message.obtain(mWifiHandler,
(enable ? MESSAGE_ENABLE_WIFI : MESSAGE_DISABLE_WIFI),
(persist ? 1 : 0), 0);
(persist ? 1 : 0), uid);
msg.sendToTarget();
}
@@ -1602,7 +1610,7 @@ public class WifiService extends IWifiManager.Stub {
if (wifiShouldBeEnabled) {
if (wifiShouldBeStarted) {
sWakeLock.acquire();
sendEnableMessage(true, false);
sendEnableMessage(true, false, mLastEnableUid);
sWakeLock.acquire();
sendStartMessage(strongestLockMode == WifiManager.WIFI_MODE_SCAN_ONLY);
} else {
@@ -1626,7 +1634,7 @@ public class WifiService extends IWifiManager.Stub {
}
} else {
sWakeLock.acquire();
sendEnableMessage(false, false);
sendEnableMessage(false, false, mLastEnableUid);
}
}
}
@@ -1671,7 +1679,7 @@ public class WifiService extends IWifiManager.Stub {
switch (msg.what) {
case MESSAGE_ENABLE_WIFI:
setWifiEnabledBlocking(true, msg.arg1 == 1);
setWifiEnabledBlocking(true, msg.arg1 == 1, msg.arg2);
sWakeLock.release();
break;
@@ -1684,7 +1692,7 @@ public class WifiService extends IWifiManager.Stub {
case MESSAGE_DISABLE_WIFI:
// a non-zero msg.arg1 value means the "enabled" setting
// should be persisted
setWifiEnabledBlocking(false, msg.arg1 == 1);
setWifiEnabledBlocking(false, msg.arg1 == 1, msg.arg2);
sWakeLock.release();
break;