diff options
9 files changed, 176 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSystemUIModule.java index 1ef3a950ba0d..11b42a8eafd6 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/ReferenceSystemUIModule.java @@ -36,7 +36,8 @@ import com.android.systemui.dock.DockManager; import com.android.systemui.dock.DockManagerImpl; import com.android.systemui.doze.DozeHost; import com.android.systemui.education.dagger.ContextualEducationModule; -import com.android.systemui.effects.dagger.TopLevelWindowEffectsModule; +import com.android.systemui.topwindoweffects.dagger.SqueezeEffectRepositoryModule; +import com.android.systemui.topwindoweffects.dagger.TopLevelWindowEffectsModule; import com.android.systemui.emergency.EmergencyGestureModule; import com.android.systemui.inputdevice.tutorial.KeyboardTouchpadTutorialModule; import com.android.systemui.keyboard.shortcut.ShortcutHelperModule; @@ -161,6 +162,7 @@ import javax.inject.Named; StatusBarPhoneModule.class, SystemActionsModule.class, ShadeModule.class, + SqueezeEffectRepositoryModule.class, StartCentralSurfacesModule.class, SceneContainerFrameworkModule.class, SysUICoroutinesModule.class, diff --git a/packages/SystemUI/src/com/android/systemui/effects/TopLevelWindowEffects.kt b/packages/SystemUI/src/com/android/systemui/topwindoweffects/TopLevelWindowEffects.kt index dac2d572e400..7dc6fa8e9f70 100644 --- a/packages/SystemUI/src/com/android/systemui/effects/TopLevelWindowEffects.kt +++ b/packages/SystemUI/src/com/android/systemui/topwindoweffects/TopLevelWindowEffects.kt @@ -14,24 +14,46 @@ * limitations under the License. */ -package com.android.systemui.effects; +package com.android.systemui.topwindoweffects; import android.content.Context import android.graphics.PixelFormat import android.view.Gravity import android.view.WindowInsets import android.view.WindowManager +import com.android.app.viewcapture.ViewCaptureAwareWindowManager import com.android.systemui.CoreStartable import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application +import com.android.systemui.topwindoweffects.domain.interactor.SqueezeEffectInteractor +import com.android.systemui.topwindoweffects.ui.compose.EffectsWindowRoot +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.launch import javax.inject.Inject @SysUISingleton class TopLevelWindowEffects @Inject constructor( - @Application private val context: Context + @Application private val context: Context, + @Application private val applicationScope: CoroutineScope, + private val windowManager: ViewCaptureAwareWindowManager, + private val squeezeEffectInteractor: SqueezeEffectInteractor ) : CoreStartable { - override fun start() { + override fun start() { + applicationScope.launch { + var root: EffectsWindowRoot? = null + squeezeEffectInteractor.isSqueezeEffectEnabled.collectLatest { enabled -> + // TODO: move window ops to a separate UI thread + if (enabled && root == null) { + root = EffectsWindowRoot(context) + root?.let { windowManager.addView(it, getWindowManagerLayoutParams()) } + } else if (root?.isAttachedToWindow == true) { + windowManager.removeView(root) + root = null + } + } + } } private fun getWindowManagerLayoutParams(): WindowManager.LayoutParams { diff --git a/packages/SystemUI/src/com/android/systemui/topwindoweffects/dagger/SqueezeEffectRepositoryModule.kt b/packages/SystemUI/src/com/android/systemui/topwindoweffects/dagger/SqueezeEffectRepositoryModule.kt new file mode 100644 index 000000000000..5a2af9228771 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/topwindoweffects/dagger/SqueezeEffectRepositoryModule.kt @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2025 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.topwindoweffects.dagger + +import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepository +import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepositoryImpl +import dagger.Binds +import dagger.Module + +@Module +interface SqueezeEffectRepositoryModule { + + @Binds + fun squeezeEffectRepository( + squeezeEffectRepositoryImpl: SqueezeEffectRepositoryImpl + ) : SqueezeEffectRepository +}
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/effects/dagger/TopLevelWindowEffectsModule.kt b/packages/SystemUI/src/com/android/systemui/topwindoweffects/dagger/TopLevelWindowEffectsModule.kt index 70c4636e25c5..6fbfedc94774 100644 --- a/packages/SystemUI/src/com/android/systemui/effects/dagger/TopLevelWindowEffectsModule.kt +++ b/packages/SystemUI/src/com/android/systemui/topwindoweffects/dagger/TopLevelWindowEffectsModule.kt @@ -14,10 +14,10 @@ * limitations under the License. */ -package com.android.systemui.effects.dagger +package com.android.systemui.topwindoweffects.dagger import com.android.systemui.CoreStartable -import com.android.systemui.effects.TopLevelWindowEffects +import com.android.systemui.topwindoweffects.TopLevelWindowEffects import dagger.Binds import dagger.Module import dagger.multibindings.ClassKey diff --git a/packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepository.kt b/packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepository.kt new file mode 100644 index 000000000000..9e0b25633d5f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepository.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2025 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.topwindoweffects.data.repository + +import kotlinx.coroutines.flow.Flow + +interface SqueezeEffectRepository { + val isSqueezeEffectEnabled: Flow<Boolean> +}
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryImpl.kt new file mode 100644 index 000000000000..9e0feed35016 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/topwindoweffects/data/repository/SqueezeEffectRepositoryImpl.kt @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2025 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.topwindoweffects.data.repository + +import android.database.ContentObserver +import android.os.Handler +import android.provider.Settings.Global.POWER_BUTTON_LONG_PRESS +import com.android.internal.R +import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.shared.Flags +import com.android.systemui.util.settings.GlobalSettings +import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import javax.inject.Inject +import kotlin.coroutines.CoroutineContext + +@SysUISingleton +class SqueezeEffectRepositoryImpl @Inject constructor( + @Background private val bgHandler: Handler?, + @Background private val bgCoroutineContext: CoroutineContext, + private val globalSettings: GlobalSettings +) : SqueezeEffectRepository { + + override val isSqueezeEffectEnabled: Flow<Boolean> = conflatedCallbackFlow { + val observer = object : ContentObserver(bgHandler) { + override fun onChange(selfChange: Boolean) { + trySendWithFailureLogging(squeezeEffectEnabled, TAG, + "updated isSqueezeEffectEnabled") + } + } + trySendWithFailureLogging(squeezeEffectEnabled, TAG, "init isSqueezeEffectEnabled") + globalSettings.registerContentObserverAsync(POWER_BUTTON_LONG_PRESS, observer) + awaitClose { globalSettings.unregisterContentObserverAsync(observer) } + }.flowOn(bgCoroutineContext) + + private val squeezeEffectEnabled + get() = Flags.enableLppSqueezeEffect() && globalSettings.getInt( + POWER_BUTTON_LONG_PRESS, R.integer.config_longPressOnPowerBehavior + ) == 5 // 5 corresponds to launch assistant in config_longPressOnPowerBehavior + + companion object { + private const val TAG = "SqueezeEffectRepository" + } +}
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/topwindoweffects/domain/interactor/SqueezeEffectInteractor.kt b/packages/SystemUI/src/com/android/systemui/topwindoweffects/domain/interactor/SqueezeEffectInteractor.kt new file mode 100644 index 000000000000..879fde769aee --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/topwindoweffects/domain/interactor/SqueezeEffectInteractor.kt @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2025 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.topwindoweffects.domain.interactor + +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.topwindoweffects.data.repository.SqueezeEffectRepository +import javax.inject.Inject + +@SysUISingleton +class SqueezeEffectInteractor @Inject constructor( + squeezeEffectRepository: SqueezeEffectRepository +) { + val isSqueezeEffectEnabled = squeezeEffectRepository.isSqueezeEffectEnabled +}
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/effects/ui/compose/EffectsWindowRoot.kt b/packages/SystemUI/src/com/android/systemui/topwindoweffects/ui/compose/EffectsWindowRoot.kt index b7a370b3c162..0826917c5cb5 100644 --- a/packages/SystemUI/src/com/android/systemui/effects/ui/compose/EffectsWindowRoot.kt +++ b/packages/SystemUI/src/com/android/systemui/topwindoweffects/ui/compose/EffectsWindowRoot.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.effects.ui.compose +package com.android.systemui.topwindoweffects.ui.compose import android.content.Context import android.util.AttributeSet diff --git a/packages/SystemUI/src/com/android/systemui/effects/ui/compose/SqueezeEffect.kt b/packages/SystemUI/src/com/android/systemui/topwindoweffects/ui/compose/SqueezeEffect.kt index 0502f3514423..124724000aaf 100644 --- a/packages/SystemUI/src/com/android/systemui/effects/ui/compose/SqueezeEffect.kt +++ b/packages/SystemUI/src/com/android/systemui/topwindoweffects/ui/compose/SqueezeEffect.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.systemui.effects.ui.compose +package com.android.systemui.topwindoweffects.ui.compose import androidx.compose.runtime.Composable |