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

Commit 498204fc authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Replace GlobalConfig with Main for ShadeDisplayAwareDetector

From now on we're accepting all classes annotated with @Main, as there are legit reasons to have the "default display" class also for shade classes.

Bug: 362719719
Bug: 374267505
Test: presubmits
Flag: com.android.systemui.shade_window_goes_around
Change-Id: Iea3894f57c81c8b1f3dbc5bdf083ea64c2419075
parent 79079b80
Loading
Loading
Loading
Loading
+3 −6
Original line number Original line Diff line number Diff line
@@ -59,9 +59,9 @@ class ShadeDisplayAwareDetector : Detector(), SourceCodeScanner {
        private const val INJECT_ANNOTATION = "javax.inject.Inject"
        private const val INJECT_ANNOTATION = "javax.inject.Inject"
        private const val APPLICATION_ANNOTATION =
        private const val APPLICATION_ANNOTATION =
            "com.android.systemui.dagger.qualifiers.Application"
            "com.android.systemui.dagger.qualifiers.Application"
        private const val GLOBAL_CONFIG_ANNOTATION = "com.android.systemui.common.ui.GlobalConfig"
        private const val SHADE_DISPLAY_AWARE_ANNOTATION =
        private const val SHADE_DISPLAY_AWARE_ANNOTATION =
            "com.android.systemui.shade.ShadeDisplayAware"
            "com.android.systemui.shade.ShadeDisplayAware"
        private const val MAIN_ANNOTATION = "com.android.systemui.dagger.qualifiers.Main"


        private const val CONTEXT = "android.content.Context"
        private const val CONTEXT = "android.content.Context"
        private const val WINDOW_MANAGER = "android.view.WindowManager"
        private const val WINDOW_MANAGER = "android.view.WindowManager"
@@ -108,13 +108,10 @@ class ShadeDisplayAwareDetector : Detector(), SourceCodeScanner {


            // check if the parameter is a context-dependent class relevant to shade
            // check if the parameter is a context-dependent class relevant to shade
            if (className !in CONTEXT_DEPENDENT_SHADE_CLASSES) return false
            if (className !in CONTEXT_DEPENDENT_SHADE_CLASSES) return false
            // check if it has @ShadeDisplayAware
            if (hasAnnotation(SHADE_DISPLAY_AWARE_ANNOTATION) || hasAnnotation(MAIN_ANNOTATION))
            if (hasAnnotation(SHADE_DISPLAY_AWARE_ANNOTATION)) return false
                return false
            // check if its a @Application-annotated Context
            // check if its a @Application-annotated Context
            if (className == CONTEXT && hasAnnotation(APPLICATION_ANNOTATION)) return false
            if (className == CONTEXT && hasAnnotation(APPLICATION_ANNOTATION)) return false
            // check if its a @GlobalConfig-annotated ConfigurationState, ConfigurationController
            // or ConfigurationInteractor
            if (className in CONFIG_CLASSES && hasAnnotation(GLOBAL_CONFIG_ANNOTATION)) return false


            return true
            return true
        }
        }
+7 −7
Original line number Original line Diff line number Diff line
@@ -73,12 +73,12 @@ class ShadeDisplayAwareDetectorTest : SystemUILintDetectorTest() {
            )
            )
            .indented()
            .indented()


    private val globalConfigStub: TestFile =
    private val mainStub: TestFile =
        kotlin(
        kotlin(
                """
                """
                package com.android.systemui.common.ui
                package com.android.systemui.dagger.qualifiers


                @Retention(AnnotationRetention.RUNTIME) annotation class GlobalConfig
                @Retention(AnnotationRetention.RUNTIME) annotation class Main
                """
                """
            )
            )
            .indented()
            .indented()
@@ -119,7 +119,7 @@ class ShadeDisplayAwareDetectorTest : SystemUILintDetectorTest() {
            qsContext,
            qsContext,
            shadeDisplayAwareStub,
            shadeDisplayAwareStub,
            applicationStub,
            applicationStub,
            globalConfigStub,
            mainStub,
            configStateStub,
            configStateStub,
            configControllerStub,
            configControllerStub,
            configInteractorStub,
            configInteractorStub,
@@ -308,7 +308,7 @@ class ShadeDisplayAwareDetectorTest : SystemUILintDetectorTest() {
    }
    }


    @Test
    @Test
    fun injectedConstructor_inRelevantPackage_withGlobalConfigAnnotatedConfigurationClass() {
    fun injectedConstructor_inRelevantPackage_withMainAnnotatedConfigurationClass() {
        lint()
        lint()
            .files(
            .files(
                TestFiles.kotlin(
                TestFiles.kotlin(
@@ -317,11 +317,11 @@ class ShadeDisplayAwareDetectorTest : SystemUILintDetectorTest() {


                        import javax.inject.Inject
                        import javax.inject.Inject
                        import com.android.systemui.common.ui.ConfigurationState
                        import com.android.systemui.common.ui.ConfigurationState
                        import com.android.systemui.common.ui.GlobalConfig
                        import com.android.systemui.dagger.qualifiers.Main


                        class ExampleClass
                        class ExampleClass
                            @Inject
                            @Inject
                            constructor(@GlobalConfig private val configState: ConfigurationState)
                            constructor(@Main private val configState: ConfigurationState)
                    """
                    """
                        .trimIndent()
                        .trimIndent()
                ),
                ),
+3 −4
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


package com.android.systemui.keyboard.docking.ui.viewmodel
package com.android.systemui.keyboard.docking.ui.viewmodel


import android.annotation.SuppressLint
import android.content.Context
import android.content.Context
import android.view.Surface
import android.view.Surface
import android.view.WindowManager
import android.view.WindowManager
@@ -37,10 +36,10 @@ import kotlinx.coroutines.flow.asStateFlow
class KeyboardDockingIndicationViewModel
class KeyboardDockingIndicationViewModel
@Inject
@Inject
constructor(
constructor(
    @SuppressLint("ShadeDisplayAwareContextChecker") @Main private val windowManager: WindowManager,
    @Main private val windowManager: WindowManager,
    @SuppressLint("ShadeDisplayAwareContextChecker") @Main private val context: Context,
    @Main private val context: Context,
    keyboardDockingIndicationInteractor: KeyboardDockingIndicationInteractor,
    keyboardDockingIndicationInteractor: KeyboardDockingIndicationInteractor,
    @SuppressLint("ShadeDisplayAwareContextChecker") @Main configurationInteractor: ConfigurationInteractor,
    @Main configurationInteractor: ConfigurationInteractor,
    @Background private val backgroundScope: CoroutineScope,
    @Background private val backgroundScope: CoroutineScope,
) {
) {