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

Commit 55a51601 authored by Chris Göllner's avatar Chris Göllner
Browse files

Provide ScreenDecorations Executor via Dagger

This way the executor can be shared among multiple classes.

Test: PrivacyDotViewControllerTest.kt
Test: Build & Run
Flag: EXEMPT no behavior change
Bug: 362720432
Change-Id: I4df2f07915e410de52af06ab402b9a494ecf72e8
parent c736ec79
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -78,8 +78,8 @@ class PrivacyDotViewControllerTest : SysuiTestCase() {
            contentInsetsProvider,
            animationScheduler = mock<SystemStatusAnimationScheduler>(),
            shadeInteractor = null,
            uiExecutor = executor,
        )
            .also { it.setUiExecutor(executor) }

    @Test
    fun topMargin_topLeftView_basedOnSeascapeArea() {
+7 −10
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@ import com.android.systemui.statusbar.commandline.CommandRegistry;
import com.android.systemui.statusbar.events.PrivacyDotViewController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.concurrency.ThreadFactory;
import com.android.systemui.util.kotlin.JavaAdapter;
import com.android.systemui.util.settings.SecureSettings;

@@ -147,7 +146,6 @@ public class ScreenDecorations implements
    private CameraAvailabilityListener mCameraListener;
    private final UserTracker mUserTracker;
    private final PrivacyDotViewController mDotViewController;
    private final ThreadFactory mThreadFactory;
    private final DecorProviderFactory mDotFactory;
    private final FaceScanningProviderFactory mFaceScanningFactory;
    private final CameraProtectionLoader mCameraProtectionLoader;
@@ -172,7 +170,6 @@ public class ScreenDecorations implements
    private ViewCaptureAwareWindowManager mWindowManager;
    private int mRotation;
    private UserSettingObserver mColorInversionSetting;
    @Nullable
    private DelayableExecutor mExecutor;
    private Handler mHandler;
    boolean mPendingConfigChange;
@@ -327,27 +324,28 @@ public class ScreenDecorations implements
    }

    @Inject
    public ScreenDecorations(Context context,
    public ScreenDecorations(
            Context context,
            SecureSettings secureSettings,
            CommandRegistry commandRegistry,
            UserTracker userTracker,
            DisplayTracker displayTracker,
            PrivacyDotViewController dotViewController,
            ThreadFactory threadFactory,
            PrivacyDotDecorProviderFactory dotFactory,
            FaceScanningProviderFactory faceScanningFactory,
            ScreenDecorationsLogger logger,
            FacePropertyRepository facePropertyRepository,
            JavaAdapter javaAdapter,
            CameraProtectionLoader cameraProtectionLoader,
            ViewCaptureAwareWindowManager viewCaptureAwareWindowManager) {
            ViewCaptureAwareWindowManager viewCaptureAwareWindowManager,
            @ScreenDecorationsThread Handler handler,
            @ScreenDecorationsThread DelayableExecutor executor) {
        mContext = context;
        mSecureSettings = secureSettings;
        mCommandRegistry = commandRegistry;
        mUserTracker = userTracker;
        mDisplayTracker = displayTracker;
        mDotViewController = dotViewController;
        mThreadFactory = threadFactory;
        mDotFactory = dotFactory;
        mFaceScanningFactory = faceScanningFactory;
        mCameraProtectionLoader = cameraProtectionLoader;
@@ -356,6 +354,8 @@ public class ScreenDecorations implements
        mFacePropertyRepository = facePropertyRepository;
        mJavaAdapter = javaAdapter;
        mWindowManager = viewCaptureAwareWindowManager;
        mHandler = handler;
        mExecutor = executor;
    }

    private final ScreenDecorCommand.Callback mScreenDecorCommandCallback = (cmd, pw) -> {
@@ -403,10 +403,7 @@ public class ScreenDecorations implements
            Log.i(TAG, "ScreenDecorations is disabled");
            return;
        }
        mHandler = mThreadFactory.buildHandlerOnNewThread("ScreenDecorations");
        mExecutor = mThreadFactory.buildDelayableExecutorOnHandler(mHandler);
        mExecutor.execute(this::startOnScreenDecorationsThread);
        mDotViewController.setUiExecutor(mExecutor);
        mCommandRegistry.registerCommand(ScreenDecorCommand.SCREEN_DECOR_CMD_NAME,
                () -> new ScreenDecorCommand(mScreenDecorCommandCallback));
    }
+30 −0
Original line number Diff line number Diff line
@@ -17,16 +17,23 @@
package com.android.systemui

import android.content.Context
import android.os.Handler
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.decor.FaceScanningProviderFactory
import com.android.systemui.decor.FaceScanningProviderFactoryImpl
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener
import com.android.systemui.util.concurrency.DelayableExecutor
import com.android.systemui.util.concurrency.ThreadFactory
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap
import dagger.multibindings.IntoSet
import java.util.concurrent.Executor
import javax.inject.Qualifier

@Qualifier annotation class ScreenDecorationsThread

@Module
interface ScreenDecorationsModule {
@@ -41,6 +48,12 @@ interface ScreenDecorationsModule {
    @IntoSet
    fun bindScreenDecorationsConfigListener(impl: ScreenDecorations): ConfigurationListener

    @Binds
    @ScreenDecorationsThread
    fun screenDecorationsExecutor(
        @ScreenDecorationsThread delayableExecutor: DelayableExecutor
    ): Executor

    companion object {
        @Provides
        @SysUISingleton
@@ -50,5 +63,22 @@ interface ScreenDecorationsModule {
        ): FaceScanningProviderFactory {
            return creator.create(context)
        }

        @Provides
        @SysUISingleton
        @ScreenDecorationsThread
        fun screenDecorationsHandler(threadFactory: ThreadFactory): Handler {
            return threadFactory.buildHandlerOnNewThread("ScreenDecorations")
        }

        @Provides
        @SysUISingleton
        @ScreenDecorationsThread
        fun screenDecorationsDelayableExecutor(
            @ScreenDecorationsThread handler: Handler,
            threadFactory: ThreadFactory,
        ): DelayableExecutor {
            return threadFactory.buildDelayableExecutorOnHandler(handler)
        }
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package com.android.systemui.statusbar.data

import com.android.systemui.statusbar.data.repository.KeyguardStatusBarRepositoryModule
import com.android.systemui.statusbar.data.repository.PrivacyDotViewControllerStoreModule
import com.android.systemui.statusbar.data.repository.RemoteInputRepositoryModule
import com.android.systemui.statusbar.data.repository.StatusBarConfigurationControllerModule
import com.android.systemui.statusbar.data.repository.StatusBarContentInsetsProviderStoreModule
@@ -28,7 +27,6 @@ import dagger.Module
    includes =
        [
            KeyguardStatusBarRepositoryModule::class,
            PrivacyDotViewControllerStoreModule::class,
            RemoteInputRepositoryModule::class,
            StatusBarConfigurationControllerModule::class,
            StatusBarContentInsetsProviderStoreModule::class,
+4 −17
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@ import android.view.View
import android.widget.FrameLayout
import androidx.core.animation.Animator
import com.android.app.animation.Interpolators
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.internal.annotations.GuardedBy
import com.android.systemui.ScreenDecorationsThread
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
@@ -53,7 +55,6 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import java.util.concurrent.Executor
import kotlinx.coroutines.CoroutineScope
import com.android.app.tracing.coroutines.launchTraced as launch

/**
 * Understands how to keep the persistent privacy dot in the corner of the screen in
@@ -81,10 +82,6 @@ interface PrivacyDotViewController {

    var showingListener: ShowingListener?

    fun setUiExecutor(e: DelayableExecutor)

    fun getUiExecutor(): DelayableExecutor?

    @UiThread fun setNewRotation(rot: Int)

    @UiThread fun hideDotView(dot: View, animate: Boolean)
@@ -117,6 +114,7 @@ constructor(
    @Assisted private val contentInsetsProvider: StatusBarContentInsetsProvider,
    private val animationScheduler: SystemStatusAnimationScheduler,
    shadeInteractor: ShadeInteractor?,
    @ScreenDecorationsThread val uiExecutor: DelayableExecutor,
) : PrivacyDotViewController {
    private lateinit var tl: View
    private lateinit var tr: View
@@ -136,9 +134,6 @@ constructor(
    private val lock = Object()
    private var cancelRunnable: Runnable? = null

    // Privacy dots are created in ScreenDecoration's UiThread, which is not the main thread
    private var uiExecutor: DelayableExecutor? = null

    private val views: Sequence<View>
        get() = if (!this::tl.isInitialized) sequenceOf() else sequenceOf(tl, tr, br, bl)

@@ -155,7 +150,7 @@ constructor(
    private val configurationListener =
        object : ConfigurationController.ConfigurationListener {
            override fun onLayoutDirectionChanged(isRtl: Boolean) {
                uiExecutor?.execute {
                uiExecutor.execute {
                    // If rtl changed, hide all dots until the next state resolves
                    setCornerVisibilities(View.INVISIBLE)

@@ -198,14 +193,6 @@ constructor(
        stateController.removeCallback(statusBarStateListener)
    }

    override fun setUiExecutor(e: DelayableExecutor) {
        uiExecutor = e
    }

    override fun getUiExecutor(): DelayableExecutor? {
        return uiExecutor
    }

    @UiThread
    override fun setNewRotation(rot: Int) {
        dlog("updateRotation: $rot")
Loading