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

Commit 7e9f4eb2 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Track client requests through location manager.

This fixes a problem where applications could ask the location
manager to do very heavy-weight things (like...  say... update
location every minute), which would get accounted against the
system instead of the application because ultimately it is the
system making the heavy calls (wake locks, etc).

To solve this, we introduce a new class WorkSource representing
the source of some work.  Wake locks and Wifi locks allow you
to set the source to use (but only if you are system code and thus
can get the permission to do so), which is what will be reported
to the battery stats until the actual caller.

For the initial implementation, the location manager keeps track
of all clients requesting periodic updates, and tells its providers
about them as a WorkSource param when setting their min update time.
The network location provider uses this to set the source on the
wake and wifi locks it acquires, when doing work because of the
update period.

This should also be used elsewhere, such as in the GPS provider,
but this is a good start.

Change-Id: I2b6ffafad9e90ecf15d7c502e2db675fd52ae3cf
parent cc5494c9
Loading
Loading
Loading
Loading
+160 −0
Original line number Diff line number Diff line
@@ -84326,6 +84326,8 @@
>
<parameter name="uid" type="int">
</parameter>
<parameter name="ws" type="android.os.WorkSource">
</parameter>
</method>
<method name="onDisable"
 return="void"
@@ -84455,6 +84457,8 @@
>
<parameter name="uid" type="int">
</parameter>
<parameter name="ws" type="android.os.WorkSource">
</parameter>
</method>
<method name="onRequiresCell"
 return="boolean"
@@ -84516,6 +84520,8 @@
>
<parameter name="minTime" type="long">
</parameter>
<parameter name="ws" type="android.os.WorkSource">
</parameter>
</method>
<method name="onSupportsAltitude"
 return="boolean"
@@ -101636,6 +101642,19 @@
<parameter name="refCounted" type="boolean">
</parameter>
</method>
<method name="setWorkSource"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="ws" type="android.os.WorkSource">
</parameter>
</method>
</class>
</package>
<package name="android.opengl"
@@ -128447,6 +128466,19 @@
<parameter name="value" type="boolean">
</parameter>
</method>
<method name="setWorkSource"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="ws" type="android.os.WorkSource">
</parameter>
</method>
</class>
<class name="Process"
 extends="java.lang.Object"
@@ -129595,6 +129627,134 @@
</parameter>
</method>
</class>
<class name="WorkSource"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<implements name="android.os.Parcelable">
</implements>
<constructor name="WorkSource"
 type="android.os.WorkSource"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</constructor>
<constructor name="WorkSource"
 type="android.os.WorkSource"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="orig" type="android.os.WorkSource">
</parameter>
</constructor>
<method name="add"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="other" type="android.os.WorkSource">
</parameter>
</method>
<method name="clear"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="describeContents"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="diff"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="other" type="android.os.WorkSource">
</parameter>
</method>
<method name="remove"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="other" type="android.os.WorkSource">
</parameter>
</method>
<method name="set"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="other" type="android.os.WorkSource">
</parameter>
</method>
<method name="writeToParcel"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="dest" type="android.os.Parcel">
</parameter>
<parameter name="flags" type="int">
</parameter>
</method>
<field name="CREATOR"
 type="android.os.Parcelable.Creator"
 transient="false"
 volatile="false"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
</package>
<package name="android.os.storage"
>
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public class PowerCommand extends Svc.Command {
                            = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
                    try {
                        IBinder lock = new Binder();
                        pm.acquireWakeLock(PowerManager.FULL_WAKE_LOCK, lock, "svc power");
                        pm.acquireWakeLock(PowerManager.FULL_WAKE_LOCK, lock, "svc power", null);
                        pm.setStayOnSetting(val);
                        pm.releaseWakeLock(lock, 0);
                    }
+4 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.WorkSource;
import android.provider.Settings;
import android.text.format.DateUtils;
import android.text.format.Time;
@@ -126,8 +127,8 @@ public class SyncManager implements OnAccountsUpdateListener {

    private static final int INITIALIZATION_UNBIND_DELAY_MS = 5000;

    private static final String SYNC_WAKE_LOCK = "SyncManagerSyncWakeLock";
    private static final String HANDLE_SYNC_ALARM_WAKE_LOCK = "SyncManagerHandleSyncAlarmWakeLock";
    private static final String SYNC_WAKE_LOCK = "*sync*";
    private static final String HANDLE_SYNC_ALARM_WAKE_LOCK = "SyncManagerHandleSyncAlarm";

    private Context mContext;

@@ -1695,6 +1696,7 @@ public class SyncManager implements OnAccountsUpdateListener {
                Log.v(TAG, "runStateIdle: setting mActiveSyncContext to " + mActiveSyncContext);
            }
            mSyncStorageEngine.setActiveSync(mActiveSyncContext);
            mSyncWakeLock.setWorkSource(new WorkSource(syncAdapterInfo.uid));
            if (!activeSyncContext.bindToSyncAdapter(syncAdapterInfo)) {
                Log.e(TAG, "Bind attempt failed to " + syncAdapterInfo);
                mActiveSyncContext.close();
+3 −0
Original line number Diff line number Diff line
@@ -404,6 +404,7 @@ public abstract class BatteryStats implements Parcelable {
        
        public static final byte CMD_UPDATE = 0;
        public static final byte CMD_START = 1;
        public static final byte CMD_OVERFLOW = 2;
        
        public byte cmd;
        
@@ -1703,6 +1704,8 @@ public abstract class BatteryStats implements Parcelable {
                pw.print(" ");
                if (rec.cmd == HistoryItem.CMD_START) {
                    pw.println(" START");
                } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
                    pw.println(" *OVERFLOW*");
                } else {
                    if (rec.batteryLevel < 10) pw.print("00");
                    else if (rec.batteryLevel < 100) pw.print("0");
+4 −1
Original line number Diff line number Diff line
@@ -17,10 +17,13 @@

package android.os;

import android.os.WorkSource;

/** @hide */
interface IPowerManager
{
    void acquireWakeLock(int flags, IBinder lock, String tag);
    void acquireWakeLock(int flags, IBinder lock, String tag, in WorkSource ws);
    void updateWakeLockWorkSource(IBinder lock, in WorkSource ws);
    void goToSleep(long time);
    void goToSleepWithReason(long time, int reason);
    void releaseWakeLock(IBinder lock, int flags);
Loading