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

Commit 28cafbcb authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Create an atom to log the tutorial entry point" into main

parents 49b62ca0 00916979
Loading
Loading
Loading
Loading
+55 −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.tutorial

import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_ENTRY_POINT_CONTEXTUAL_EDU
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEYBOARD
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_TOUCHPAD
import com.android.systemui.shared.system.SysUiStatsLog
import javax.inject.Inject

class KeyboardTouchpadTutorialMetricsLogger @Inject constructor() {

    fun logPeripheralTutorialLaunched(entryPointExtra: String?, tutorialTypeExtra: String?) {
        val entryPoint =
            when (entryPointExtra) {
                INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER ->
                    SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__ENTRY_POINT__SCHEDULED
                INTENT_TUTORIAL_ENTRY_POINT_CONTEXTUAL_EDU ->
                    SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__ENTRY_POINT__CONTEXTUAL_EDU
                else -> SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__ENTRY_POINT__APP
            }

        val tutorialType =
            when (tutorialTypeExtra) {
                INTENT_TUTORIAL_TYPE_KEYBOARD ->
                    SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__TUTORIAL_TYPE__KEYBOARD
                INTENT_TUTORIAL_TYPE_TOUCHPAD ->
                    SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__TUTORIAL_TYPE__TOUCHPAD
                else -> SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__TUTORIAL_TYPE__BOTH
            }

        SysUiStatsLog.write(SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED, entryPoint, tutorialType)
    }

    fun logPeripheralTutorialLaunchedFromSettings() {
        val entryPoint = SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__ENTRY_POINT__SETTINGS
        val tutorialType = SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED__TUTORIAL_TYPE__TOUCHPAD
        SysUiStatsLog.write(SysUiStatsLog.PERIPHERAL_TUTORIAL_LAUNCHED, entryPoint, tutorialType)
    }
}
+10 −7
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSched
import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSchedulerInteractor.Companion.TAG
import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSchedulerInteractor.TutorialType
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_ENTRY_POINT_KEY
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_BOTH
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEY
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEYBOARD
@@ -48,7 +50,7 @@ constructor(
    @Background private val backgroundScope: CoroutineScope,
    @Application private val context: Context,
    private val tutorialSchedulerInteractor: TutorialSchedulerInteractor,
    private val notificationManager: NotificationManager
    private val notificationManager: NotificationManager,
) {
    fun start() {
        backgroundScope.launch {
@@ -68,7 +70,7 @@ constructor(
        val extras = Bundle()
        extras.putString(
            Notification.EXTRA_SUBSTITUTE_APP_NAME,
            context.getString(com.android.internal.R.string.android_system_label)
            context.getString(com.android.internal.R.string.android_system_label),
        )

        val info = getNotificationInfo(tutorialType)!!
@@ -91,7 +93,7 @@ constructor(
            NotificationChannel(
                CHANNEL_ID,
                context.getString(com.android.internal.R.string.android_system_label),
                NotificationManager.IMPORTANCE_DEFAULT
                NotificationManager.IMPORTANCE_DEFAULT,
            )
        notificationManager.createNotificationChannel(channel)
    }
@@ -100,13 +102,14 @@ constructor(
        val intent =
            Intent(context, KeyboardTouchpadTutorialActivity::class.java).apply {
                putExtra(INTENT_TUTORIAL_TYPE_KEY, tutorialType)
                putExtra(INTENT_TUTORIAL_ENTRY_POINT_KEY, INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER)
                flags = Intent.FLAG_ACTIVITY_NEW_TASK
            }
        return PendingIntent.getActivity(
            context,
            /* requestCode= */ 0,
            intent,
            PendingIntent.FLAG_IMMUTABLE
            PendingIntent.FLAG_IMMUTABLE,
        )
    }

@@ -118,13 +121,13 @@ constructor(
                NotificationInfo(
                    context.getString(R.string.launch_keyboard_tutorial_notification_title),
                    context.getString(R.string.launch_keyboard_tutorial_notification_content),
                    INTENT_TUTORIAL_TYPE_KEYBOARD
                    INTENT_TUTORIAL_TYPE_KEYBOARD,
                )
            TutorialType.TOUCHPAD ->
                NotificationInfo(
                    context.getString(R.string.launch_touchpad_tutorial_notification_title),
                    context.getString(R.string.launch_touchpad_tutorial_notification_content),
                    INTENT_TUTORIAL_TYPE_TOUCHPAD
                    INTENT_TUTORIAL_TYPE_TOUCHPAD,
                )
            TutorialType.BOTH ->
                NotificationInfo(
@@ -134,7 +137,7 @@ constructor(
                    context.getString(
                        R.string.launch_keyboard_touchpad_tutorial_notification_content
                    ),
                    INTENT_TUTORIAL_TYPE_BOTH
                    INTENT_TUTORIAL_TYPE_BOTH,
                )
            TutorialType.NONE -> null
        }
+10 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import androidx.lifecycle.lifecycleScope
import com.android.compose.theme.PlatformTheme
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger.TutorialContext
import com.android.systemui.inputdevice.tutorial.KeyboardTouchpadTutorialMetricsLogger
import com.android.systemui.inputdevice.tutorial.TouchpadTutorialScreensProvider
import com.android.systemui.inputdevice.tutorial.ui.composable.ActionKeyTutorialScreen
import com.android.systemui.inputdevice.tutorial.ui.viewmodel.KeyboardTouchpadTutorialViewModel
@@ -51,6 +52,7 @@ constructor(
    private val viewModelFactoryAssistedProvider: ViewModelFactoryAssistedProvider,
    private val touchpadTutorialScreensProvider: Optional<TouchpadTutorialScreensProvider>,
    private val logger: InputDeviceTutorialLogger,
    private val metricsLogger: KeyboardTouchpadTutorialMetricsLogger,
) : ComponentActivity() {

    companion object {
@@ -58,6 +60,9 @@ constructor(
        const val INTENT_TUTORIAL_TYPE_TOUCHPAD = "touchpad"
        const val INTENT_TUTORIAL_TYPE_KEYBOARD = "keyboard"
        const val INTENT_TUTORIAL_TYPE_BOTH = "both"
        const val INTENT_TUTORIAL_ENTRY_POINT_KEY = "entry_point"
        const val INTENT_TUTORIAL_ENTRY_POINT_SCHEDULER = "scheduler"
        const val INTENT_TUTORIAL_ENTRY_POINT_CONTEXTUAL_EDU = "contextual_edu"
    }

    private val vm by
@@ -86,6 +91,10 @@ constructor(
            PlatformTheme { KeyboardTouchpadTutorialContainer(vm, touchpadTutorialScreensProvider) }
        }
        if (savedInstanceState == null) {
            metricsLogger.logPeripheralTutorialLaunched(
                intent.getStringExtra(INTENT_TUTORIAL_ENTRY_POINT_KEY),
                intent.getStringExtra(INTENT_TUTORIAL_TYPE_KEY),
            )
            logger.logOpenTutorial(TutorialContext.KEYBOARD_TOUCHPAD_TUTORIAL)
        }
    }
@@ -109,7 +118,7 @@ fun KeyboardTouchpadTutorialContainer(
        ACTION_KEY ->
            ActionKeyTutorialScreen(
                onDoneButtonClicked = vm::onDoneButtonClicked,
                onBack = vm::onBack
                onBack = vm::onBack,
            )
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.compose.theme.PlatformTheme
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger.TutorialContext
import com.android.systemui.inputdevice.tutorial.KeyboardTouchpadTutorialMetricsLogger
import com.android.systemui.touchpad.tutorial.ui.composable.BackGestureTutorialScreen
import com.android.systemui.touchpad.tutorial.ui.composable.HomeGestureTutorialScreen
import com.android.systemui.touchpad.tutorial.ui.composable.RecentAppsGestureTutorialScreen
@@ -45,6 +46,7 @@ class TouchpadTutorialActivity
constructor(
    private val viewModelFactory: TouchpadTutorialViewModel.Factory,
    private val logger: InputDeviceTutorialLogger,
    private val metricsLogger: KeyboardTouchpadTutorialMetricsLogger,
) : ComponentActivity() {

    private val vm by viewModels<TouchpadTutorialViewModel>(factoryProducer = { viewModelFactory })
@@ -57,6 +59,7 @@ constructor(
        }
        // required to handle 3+ fingers on touchpad
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
        metricsLogger.logPeripheralTutorialLaunchedFromSettings()
        logger.logOpenTutorial(TutorialContext.TOUCHPAD_TUTORIAL)
    }

@@ -85,7 +88,7 @@ fun TouchpadTutorialScreen(vm: TouchpadTutorialViewModel, closeTutorial: () -> U
                onBackTutorialClicked = { vm.goTo(BACK_GESTURE) },
                onHomeTutorialClicked = { vm.goTo(HOME_GESTURE) },
                onRecentAppsTutorialClicked = { vm.goTo(RECENT_APPS_GESTURE) },
                onDoneButtonClicked = closeTutorial
                onDoneButtonClicked = closeTutorial,
            )
        BACK_GESTURE ->
            BackGestureTutorialScreen(