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

Commit ace8d12f authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Use correct context, resources and configuration in notification package

Thanks to a linter that highlights non-annotated usages of resources, we realized several classes were not using the correct context.

Here:
- A few classes in the biometrics package were using ShadeDisplayAware context and resources, when they should have used the global one (for the default display), as they were tied to the finger print sensor (that at least for now, is only on the device)
- In a few other classes, @Application context and @Main resources have been used, as they are unrelated to the shade (and are not planning to move between displays)
- Many QS classes were not using the correct context. Now all those classes are either annotated with @ShadeDisplayAware, or @Main/@Application.

Generally, there shouldn't be not-annotated usages of context, resources, Layout inflator or Configuration{Repository|Interactor|State} after this cl.
There are 2 exceptions that are being clarified.

The expectation is that when the flag is off, there are no runtime changes (as the instances provided, even after these changes, will be exactly the same).

Bug: 362719719
Bug: 374267505
Test: presubmits + e2e tests
Flag: com.android.systemui.shade_window_goes_around
Change-Id: I93f202802fa65a2307e217c3add1e9f4eaee5de6
parent f2290c21
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import androidx.annotation.Nullable;

import com.android.internal.R;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.util.DeviceConfigProxy;
@@ -72,7 +73,7 @@ public class AssistantFeedbackController {
    /** Injected constructor */
    @Inject
    public AssistantFeedbackController(@Main Handler handler,
            Context context, DeviceConfigProxy proxy) {
            @Application Context context, DeviceConfigProxy proxy) {
        mHandler = handler;
        mContext = context;
        mDeviceConfigProxy = proxy;
+2 −1
Original line number Diff line number Diff line
@@ -18,13 +18,14 @@ package com.android.systemui.statusbar.notification

import android.content.Context
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.util.Utils
import javax.inject.Inject

@SysUISingleton
class NotificationSectionsFeatureManager
@Inject
constructor(val context: Context) {
constructor(@ShadeDisplayAware val context: Context) {

    fun isMediaControlsEnabled(): Boolean {
        return Utils.useQsMediaPlayer(context)
+14 −12
Original line number Diff line number Diff line
@@ -23,25 +23,27 @@ import android.content.pm.PackageManager
import android.service.notification.StatusBarNotification
import android.util.Log
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
import com.android.systemui.statusbar.phone.CentralSurfaces
import javax.inject.Inject

@SysUISingleton
class TargetSdkResolver @Inject constructor(
    private val context: Context
) {
class TargetSdkResolver @Inject constructor(@Application private val context: Context) {
    fun initialize(collection: CommonNotifCollection) {
        collection.addCollectionListener(object : NotifCollectionListener {
        collection.addCollectionListener(
            object : NotifCollectionListener {
                override fun onEntryBind(entry: NotificationEntry, sbn: StatusBarNotification) {
                    entry.targetSdk = resolveNotificationSdk(sbn)
                }
        })
            }
        )
    }

    private fun resolveNotificationSdk(sbn: StatusBarNotification): Int {
        val applicationInfo = getApplicationInfoFromExtras(sbn.notification)
        val applicationInfo =
            getApplicationInfoFromExtras(sbn.notification)
                ?: getApplicationInfoFromPackageManager(sbn)

        return applicationInfo?.targetSdkVersion ?: 0
@@ -50,7 +52,7 @@ class TargetSdkResolver @Inject constructor(
    private fun getApplicationInfoFromExtras(notification: Notification): ApplicationInfo? =
        notification.extras.getParcelable(
            Notification.EXTRA_BUILDER_APPLICATION_INFO,
                    ApplicationInfo::class.java
            ApplicationInfo::class.java,
        )

    private fun getApplicationInfoFromPackageManager(sbn: StatusBarNotification): ApplicationInfo? {
+3 −4
Original line number Diff line number Diff line
@@ -17,8 +17,9 @@
package com.android.systemui.statusbar.notification.collection.provider

import android.content.Context
import com.android.systemui.res.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.res.R
import com.android.systemui.shade.ShadeDisplayAware
import javax.inject.Inject

/**
@@ -31,9 +32,7 @@ import javax.inject.Inject
 * visibility when it invalidates, and we just store that state here.)
 */
@SysUISingleton
class SectionHeaderVisibilityProvider @Inject constructor(
    context: Context
) {
class SectionHeaderVisibilityProvider @Inject constructor(@ShadeDisplayAware context: Context) {
    val neverShowSectionHeaders =
        context.resources.getBoolean(R.bool.config_notification_never_show_section_headers)
    var sectionHeadersVisible = true
+12 −8
Original line number Diff line number Diff line
@@ -19,15 +19,16 @@ package com.android.systemui.statusbar.notification.collection.render
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.android.systemui.res.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.res.R
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.statusbar.notification.stack.MediaContainerView
import javax.inject.Inject

@SysUISingleton
class MediaContainerController @Inject constructor(
    private val layoutInflater: LayoutInflater
) : NodeController {
class MediaContainerController
@Inject
constructor(@ShadeDisplayAware private val layoutInflater: LayoutInflater) : NodeController {

    override val nodeLabel = "MediaContainer"
    var mediaContainerView: MediaContainerView? = null
@@ -42,11 +43,12 @@ class MediaContainerController @Inject constructor(
                parent.removeView(_view)
            }
        }
        val inflated = layoutInflater.inflate(
        val inflated =
            layoutInflater.inflate(
                R.layout.keyguard_media_container,
                parent,
                false /* attachToRoot */)
                as MediaContainerView
                false, /* attachToRoot */
            ) as MediaContainerView
        if (oldPos != -1) {
            parent.addView(inflated, oldPos)
        }
@@ -57,6 +59,8 @@ class MediaContainerController @Inject constructor(
        get() = mediaContainerView!!

    override fun offerToKeepInParentForAnimation(): Boolean = false

    override fun removeFromParentIfKeptForAnimation(): Boolean = false

    override fun resetKeepInParentForAnimation() {}
}
Loading