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

Commit 58c0e6fb authored by Yalan Yiue's avatar Yalan Yiue Committed by Android (Google) Code Review
Browse files

Merge "Detect keyboard/touchpad connection with CoreStartable" into main

parents b8480739 fec792dd
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.dreams.AssistantAttentionMonitor
import com.android.systemui.dreams.DreamMonitor
import com.android.systemui.dreams.homecontrols.HomeControlsDreamStartable
import com.android.systemui.globalactions.GlobalActionsComponent
import com.android.systemui.inputdevice.oobe.KeyboardTouchpadOobeTutorialCoreStartable
import com.android.systemui.keyboard.KeyboardUI
import com.android.systemui.keyboard.PhysicalKeyboardCoreStartable
import com.android.systemui.keyguard.KeyguardViewConfigurator
@@ -255,6 +256,13 @@ abstract class SystemUICoreStartableModule {
    @ClassKey(StylusUsiPowerStartable::class)
    abstract fun bindStylusUsiPowerStartable(sysui: StylusUsiPowerStartable): CoreStartable

    @Binds
    @IntoMap
    @ClassKey(KeyboardTouchpadOobeTutorialCoreStartable::class)
    abstract fun bindOobeSchedulerCoreStartable(
        listener: KeyboardTouchpadOobeTutorialCoreStartable
    ): CoreStartable

    @Binds
    @IntoMap
    @ClassKey(PhysicalKeyboardCoreStartable::class)
+2 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ import com.android.systemui.statusbar.ui.binder.StatusBarViewBinderModule;
import com.android.systemui.statusbar.window.StatusBarWindowModule;
import com.android.systemui.telephony.data.repository.TelephonyRepositoryModule;
import com.android.systemui.temporarydisplay.dagger.TemporaryDisplayModule;
import com.android.systemui.touchpad.TouchpadModule;
import com.android.systemui.tuner.dagger.TunerModule;
import com.android.systemui.user.UserModule;
import com.android.systemui.user.domain.UserDomainLayerModule;
@@ -259,6 +260,7 @@ import javax.inject.Named;
        CommonSystemUIUnfoldModule.class,
        TelephonyRepositoryModule.class,
        TemporaryDisplayModule.class,
        TouchpadModule.class,
        TunerModule.class,
        UserDomainLayerModule.class,
        UserModule.class,
+2 −2
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ constructor(

    data class DeviceAdded(val deviceId: Int) : DeviceChange

    data object DeviceRemoved : DeviceChange
    data class DeviceRemoved(val deviceId: Int) : DeviceChange

    data object FreshStart : DeviceChange

@@ -72,7 +72,7 @@ constructor(

                        override fun onInputDeviceRemoved(deviceId: Int) {
                            connectedDevices = connectedDevices - deviceId
                            sendWithLogging(connectedDevices to DeviceRemoved)
                            sendWithLogging(connectedDevices to DeviceRemoved(deviceId))
                        }
                    }
                sendWithLogging(connectedDevices to FreshStart)
+37 −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.inputdevice.oobe

import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.inputdevice.oobe.domain.interactor.OobeTutorialSchedulerInteractor
import com.android.systemui.shared.Flags.newTouchpadGesturesTutorial
import dagger.Lazy
import javax.inject.Inject

/** A [CoreStartable] to launch a scheduler for keyboard and touchpad OOBE education */
@SysUISingleton
class KeyboardTouchpadOobeTutorialCoreStartable
@Inject
constructor(private val oobeTutorialSchedulerInteractor: Lazy<OobeTutorialSchedulerInteractor>) :
    CoreStartable {
    override fun start() {
        if (newTouchpadGesturesTutorial()) {
            oobeTutorialSchedulerInteractor.get().start()
        }
    }
}
+58 −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.inputdevice.oobe.domain.interactor

import android.content.Context
import android.content.Intent
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyboard.data.repository.KeyboardRepository
import com.android.systemui.touchpad.data.repository.TouchpadRepository
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/** When keyboards or touchpads are connected, schedule a tutorial after given time has elapsed */
@SysUISingleton
class OobeTutorialSchedulerInteractor
@Inject
constructor(
    @Application private val context: Context,
    @Application private val applicationScope: CoroutineScope,
    keyboardRepository: KeyboardRepository,
    touchpadRepository: TouchpadRepository
) {
    private val isAnyKeyboardConnected = keyboardRepository.isAnyKeyboardConnected
    private val isAnyTouchpadConnected = touchpadRepository.isAnyTouchpadConnected

    fun start() {
        applicationScope.launch { isAnyKeyboardConnected.collect { startOobe() } }
        applicationScope.launch { isAnyTouchpadConnected.collect { startOobe() } }
    }

    private fun startOobe() {
        val intent = Intent(TUTORIAL_ACTION)
        intent.addCategory(Intent.CATEGORY_DEFAULT)
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(intent)
    }

    companion object {
        const val TAG = "OobeSchedulerInteractor"
        const val TUTORIAL_ACTION = "com.android.systemui.action.TOUCHPAD_TUTORIAL"
    }
}
Loading