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

Commit e7ff0951 authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Android (Google) Code Review
Browse files

Merge "New log buffer for debugging WakeLocks" into udc-dev

parents 923de0c4 7eda3bbc
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -24,16 +24,13 @@ class BroadcastSender @Inject constructor(
    @Background private val bgExecutor: Executor
) {

    private val WAKE_LOCK_TAG = "SysUI:BroadcastSender"
    private val WAKE_LOCK_SEND_REASON = "sendInBackground"

    /**
     * Sends broadcast via [Context.sendBroadcast] on background thread to avoid blocking
     * synchronous binder call.
     */
    @AnyThread
    fun sendBroadcast(intent: Intent) {
        sendInBackground {
        sendInBackground("$intent") {
            context.sendBroadcast(intent)
        }
    }
@@ -44,7 +41,7 @@ class BroadcastSender @Inject constructor(
     */
    @AnyThread
    fun sendBroadcast(intent: Intent, receiverPermission: String?) {
        sendInBackground {
        sendInBackground("$intent") {
            context.sendBroadcast(intent, receiverPermission)
        }
    }
@@ -55,7 +52,7 @@ class BroadcastSender @Inject constructor(
     */
    @AnyThread
    fun sendBroadcastAsUser(intent: Intent, userHandle: UserHandle) {
        sendInBackground {
        sendInBackground("$intent") {
            context.sendBroadcastAsUser(intent, userHandle)
        }
    }
@@ -66,7 +63,7 @@ class BroadcastSender @Inject constructor(
     */
    @AnyThread
    fun sendBroadcastAsUser(intent: Intent, userHandle: UserHandle, receiverPermission: String?) {
        sendInBackground {
        sendInBackground("$intent") {
            context.sendBroadcastAsUser(intent, userHandle, receiverPermission)
        }
    }
@@ -82,7 +79,7 @@ class BroadcastSender @Inject constructor(
        receiverPermission: String?,
        options: Bundle?
    ) {
        sendInBackground {
        sendInBackground("$intent") {
            context.sendBroadcastAsUser(intent, userHandle, receiverPermission, options)
        }
    }
@@ -98,7 +95,7 @@ class BroadcastSender @Inject constructor(
        receiverPermission: String?,
        appOp: Int
    ) {
        sendInBackground {
        sendInBackground("$intent") {
            context.sendBroadcastAsUser(intent, userHandle, receiverPermission, appOp)
        }
    }
@@ -108,7 +105,7 @@ class BroadcastSender @Inject constructor(
     */
    @AnyThread
    fun closeSystemDialogs() {
        sendInBackground {
        sendInBackground("closeSystemDialogs") {
            context.closeSystemDialogs()
        }
    }
@@ -116,17 +113,21 @@ class BroadcastSender @Inject constructor(
    /**
     * Dispatches parameter on background executor while holding a wakelock.
     */
    private fun sendInBackground(callable: () -> Unit) {
    private fun sendInBackground(reason: String, callable: () -> Unit) {
        val broadcastWakelock = wakeLockBuilder.setTag(WAKE_LOCK_TAG)
                                .setMaxTimeout(5000)
                                .build()
        broadcastWakelock.acquire(WAKE_LOCK_SEND_REASON)
        broadcastWakelock.acquire(reason)
        bgExecutor.execute {
            try {
                callable.invoke()
            } finally {
                broadcastWakelock.release(WAKE_LOCK_SEND_REASON)
                broadcastWakelock.release(reason)
            }
        }
    }

    companion object {
        private const val WAKE_LOCK_TAG = "SysUI:BroadcastSender"
    }
}
 No newline at end of file
+5 −2
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import com.android.systemui.statusbar.policy.NextAlarmController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.util.wakelock.SettableWakeLock;
import com.android.systemui.util.wakelock.WakeLock;
import com.android.systemui.util.wakelock.WakeLockLogger;

import java.util.Date;
import java.util.Locale;
@@ -148,6 +149,8 @@ public class KeyguardSliceProvider extends SliceProvider implements
    private int mStatusBarState;
    private boolean mMediaIsVisible;
    private SystemUIAppComponentFactory.ContextAvailableCallback mContextAvailableCallback;
    @Inject
    WakeLockLogger mWakeLockLogger;

    /**
     * Receiver responsible for time ticking and updating the date format.
@@ -305,8 +308,8 @@ public class KeyguardSliceProvider extends SliceProvider implements
    @Override
    public boolean onCreateSliceProvider() {
        mContextAvailableCallback.onContextAvailable(getContext());
        mMediaWakeLock = new SettableWakeLock(WakeLock.createPartial(getContext(), "media"),
                "media");
        mMediaWakeLock = new SettableWakeLock(
                WakeLock.createPartial(getContext(), mWakeLockLogger, "media"), "media");
        synchronized (KeyguardSliceProvider.sInstanceLock) {
            KeyguardSliceProvider oldInstance = KeyguardSliceProvider.sInstance;
            if (oldInstance != null) {
+9 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.plugins.log.LogcatEchoTrackerDebug;
import com.android.systemui.plugins.log.LogcatEchoTrackerProd;
import com.android.systemui.statusbar.notification.NotifPipelineFlags;
import com.android.systemui.util.Compile;
import com.android.systemui.util.wakelock.WakeLockLog;

import dagger.Module;
import dagger.Provides;
@@ -168,6 +169,14 @@ public class LogModule {
                false /* systrace */);
    }

    /** Provides a logging buffer for {@link com.android.systemui.broadcast.BroadcastSender} */
    @Provides
    @SysUISingleton
    @WakeLockLog
    public static LogBuffer provideWakeLockLog(LogBufferFactory factory) {
        return factory.create("WakeLockLog", 500 /* maxSize */, false /* systrace */);
    }

    /** Provides a logging buffer for all logs related to Toasts shown by SystemUI. */
    @Provides
    @SysUISingleton
+4 −2
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public class DelayedWakeLock implements WakeLock {
     */
    public static class Builder {
        private final Context mContext;
        private final WakeLockLogger mLogger;
        private String mTag;
        private Handler mHandler;

@@ -69,8 +70,9 @@ public class DelayedWakeLock implements WakeLock {
         * Constructor for DelayedWakeLock.Builder
         */
        @Inject
        public Builder(Context context) {
        public Builder(Context context, WakeLockLogger logger) {
            mContext = context;
            mLogger = logger;
        }

        /**
@@ -95,7 +97,7 @@ public class DelayedWakeLock implements WakeLock {
         * Build the DelayedWakeLock.
         */
        public DelayedWakeLock build() {
            return new DelayedWakeLock(mHandler, WakeLock.createPartial(mContext, mTag));
            return new DelayedWakeLock(mHandler, WakeLock.createPartial(mContext, mLogger, mTag));
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public class KeepAwakeAnimationListener extends AnimatorListenerAdapter
    public KeepAwakeAnimationListener(Context context) {
        Assert.isMainThread();
        if (sWakeLock == null) {
            sWakeLock = WakeLock.createPartial(context, "animation");
            sWakeLock = WakeLock.createPartial(context, null, "animation");
        }
    }

Loading