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

Commit ee0d554c authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Update workchain when wakelock uids updated

There are currently 2 ways to update the worksource with the caller uids
for appropriate attribution - Workchain and uids array in the WorkSource
object. The array approach has been deprecated, and is a hidden utility.
Workchain is the recommended way to do the attribution. A special hack
was created for Audio wakelocks to create wakelocks in async, and then
update the corresponding uids using updateWakelockUids API. This API
would then update the uids array inside the Worksource, and hence the
changing uids never get logged in the form of atoms.

Bug: 331304805
Flag: com.android.server.power.feature.flags.wakelock_attribution_via_workchain
Test: atest PowerManagerServiceTest

Change-Id: I4d1b8559c4293c35be5ba8d30957b5b48311c1ab
parent bac00a2e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1573,6 +1573,13 @@ java_aconfig_library {
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

java_aconfig_library {
    name: "power_flags_lib_host",
    aconfig_declarations: "power_flags",
    host_supported: true,
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
}

// Content
aconfig_declarations {
    name: "android.content.flags-aconfig",
+11 −0
Original line number Diff line number Diff line
@@ -4205,6 +4205,17 @@ public final class PowerManager {
            else mFlags &= ~UNIMPORTANT_FOR_LOGGING;
        }

        /** @hide */
        public void updateUids(int[] uids) {
            synchronized (mToken) {
                try {
                    mService.updateWakeLockUids(mToken, uids);
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                }
            }
        }

        @Override
        public String toString() {
            synchronized (mToken) {
+13 −4
Original line number Diff line number Diff line
@@ -5979,12 +5979,21 @@ public final class PowerManagerService extends SystemService

            if (uids != null) {
                ws = new WorkSource();
                // XXX should WorkSource have a way to set uids as an int[] instead of adding them
                // one at a time?
                if (mFeatureFlags.isWakelockAttributionViaWorkchainEnabled()) {
                    int callingUid = Binder.getCallingUid();
                    for (int uid : uids) {
                        WorkChain workChain = ws.createWorkChain();
                        workChain.addNode(uid, null);
                        workChain.addNode(callingUid, null);
                    }
                } else {
                    // XXX should WorkSource have a way to set uids as an int[] instead of
                    // adding them one at a time?
                    for (int uid : uids) {
                        ws.add(uid);
                    }
                }
            }
            updateWakeLockWorkSource(lock, ws, null);
        }

+12 −0
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ public class PowerManagerFlags {
    private final FlagState mMoveWscLoggingToNotifier =
            new FlagState(Flags.FLAG_MOVE_WSC_LOGGING_TO_NOTIFIER, Flags::moveWscLoggingToNotifier);

    private final FlagState mWakelockAttributionViaWorkchain =
            new FlagState(Flags.FLAG_WAKELOCK_ATTRIBUTION_VIA_WORKCHAIN,
                    Flags::wakelockAttributionViaWorkchain);

    /** Returns whether early-screen-timeout-detector is enabled on not. */
    public boolean isEarlyScreenTimeoutDetectorEnabled() {
        return mEarlyScreenTimeoutDetectorFlagState.isEnabled();
@@ -109,6 +113,13 @@ public class PowerManagerFlags {
        return mMoveWscLoggingToNotifier.isEnabled();
    }

    /**
     * @return Whether the wakelock attribution via workchain is enabled
     */
    public boolean isWakelockAttributionViaWorkchainEnabled() {
        return mWakelockAttributionViaWorkchain.isEnabled();
    }

    /**
     * dumps all flagstates
     * @param pw printWriter
@@ -120,6 +131,7 @@ public class PowerManagerFlags {
        pw.println(" " + mPerDisplayWakeByTouch);
        pw.println(" " + mFrameworkWakelockInfo);
        pw.println(" " + mMoveWscLoggingToNotifier);
        pw.println(" " + mWakelockAttributionViaWorkchain);
    }

    private static class FlagState {
+11 −0
Original line number Diff line number Diff line
@@ -22,6 +22,17 @@ flag {
    }
}

flag {
    name: "wakelock_attribution_via_workchain"
    namespace: "power"
    description: "Enables the attribution of wakelocks via WorkChain for updateWakelockUids"
    bug: "331304805"
    is_fixed_read_only: true
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "improve_wakelock_latency"
    namespace: "power"
Loading