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

Commit 4b054b7d authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Introduce ShadeDisplayAwareModule

This binds context, resources and layout inflater specific to the shade window.
A copy of the context is created (only when the new flag is enabled.

Those elements will be used in follow up cls.

Bug: 362719719
Bug: 374267505
Test: Presubmits - just introducing a flag guarded module not yet used
Flag:  com.android.systemui.shade_window_goes_around
Change-Id: I0c83c3c36168a189f45e8d2ad7288d87e7d5e796
parent d8d806e5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1521,6 +1521,13 @@ flag {
   }
}

flag {
  name: "shade_window_goes_around"
  namespace: "systemui"
  description: "Enables the shade window to move between displays"
  bug: "362719719"
}

flag {
   name: "media_projection_request_attribution_fix"
   namespace: "systemui"
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.shade

import android.content.Context
import android.content.res.Resources
import android.view.LayoutInflater
import android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
import com.android.systemui.Flags
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.res.R
import dagger.Module
import dagger.Provides

/**
 * Module responsible for managing display-specific components and resources for the notification
 * shade window.
 *
 * This isolation is crucial because when the window transitions between displays, its associated
 * context, resources, and display characteristics (like density and size) also change. If the shade
 * window shared the same context as the rest of the system UI, it could lead to inconsistencies and
 * errors due to incorrect display information.
 *
 * By using this dedicated module, we ensure the notification shade window always utilizes the
 * correct display context and resources, regardless of the display it's on.
 */
@Module
object ShadeDisplayAwareModule {

    /** Creates a new context for the shade window. */
    @Provides
    @ShadeDisplayAware
    @SysUISingleton
    fun provideShadeDisplayAwareContext(context: Context): Context {
        return if (Flags.shadeWindowGoesAround()) {
            context
                .createWindowContext(context.display, TYPE_APPLICATION_OVERLAY, /* options= */ null)
                .apply { setTheme(R.style.Theme_SystemUI) }
        } else {
            context
        }
    }

    @Provides
    @ShadeDisplayAware
    @SysUISingleton
    fun provideShadeDisplayAwareResources(@ShadeDisplayAware context: Context): Resources {
        return context.resources
    }

    @Provides
    @ShadeDisplayAware
    @SysUISingleton
    fun providesDisplayAwareLayoutInflater(@ShadeDisplayAware context: Context): LayoutInflater {
        return LayoutInflater.from(context)
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -49,7 +49,10 @@ import dagger.Provides
import javax.inject.Provider

/** Module for classes related to the notification shade. */
@Module(includes = [StartShadeModule::class, ShadeViewProviderModule::class])
@Module(
    includes =
        [StartShadeModule::class, ShadeViewProviderModule::class, ShadeDisplayAwareModule::class]
)
abstract class ShadeModule {
    companion object {
        @Provides