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

Commit b0d80485 authored by Brad Hinegardner's avatar Brad Hinegardner
Browse files

Log custom lockscreen shortcuts

Bug: b/265434829
Test: KeyguardBottomAreaViewModelTest.kt
Change-Id: If686d441722eed24dd078949abaf881d3bf3c453
parent c7a54c4e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ import com.android.systemui.keyguard.data.quickaffordance.KeyguardDataQuickAffor
import com.android.systemui.keyguard.data.repository.KeyguardRepositoryModule;
import com.android.systemui.keyguard.domain.interactor.StartKeyguardTransitionModule;
import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceModule;
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLogger;
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLoggerImpl;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.shade.ShadeController;
@@ -64,6 +66,8 @@ import java.util.concurrent.Executor;
import dagger.Lazy;
import dagger.Module;
import dagger.Provides;
import kotlinx.coroutines.CoroutineDispatcher;
import kotlinx.coroutines.CoroutineScope;

/**
 * Dagger Module providing keyguard.
@@ -153,4 +157,10 @@ public class KeyguardModule {
    public ViewMediatorCallback providesViewMediatorCallback(KeyguardViewMediator viewMediator) {
        return viewMediator.getViewMediatorCallback();
    }

    /** */
    @Provides
    public KeyguardQuickAffordancesMetricsLogger providesKeyguardQuickAffordancesMetricsLogger() {
        return new KeyguardQuickAffordancesMetricsLoggerImpl();
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardPickerFlag
import com.android.systemui.keyguard.shared.model.KeyguardQuickAffordancePickerRepresentation
import com.android.systemui.keyguard.shared.model.KeyguardSlotPickerRepresentation
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLogger
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.settings.UserTracker
import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
@@ -68,6 +69,7 @@ constructor(
    private val featureFlags: FeatureFlags,
    private val repository: Lazy<KeyguardQuickAffordanceRepository>,
    private val launchAnimator: DialogLaunchAnimator,
    private val logger: KeyguardQuickAffordancesMetricsLogger,
    private val devicePolicyManager: DevicePolicyManager,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
) {
@@ -122,10 +124,12 @@ constructor(
     * @param configKey The configuration key corresponding to the [KeyguardQuickAffordanceModel] of
     *   the affordance that was clicked
     * @param expandable An optional [Expandable] for the activity- or dialog-launch animation
     * @param slotId The id of the lockscreen slot that the affordance is in
     */
    fun onQuickAffordanceTriggered(
        configKey: String,
        expandable: Expandable?,
        slotId: String,
    ) {
        @Suppress("UNCHECKED_CAST")
        val config =
@@ -139,6 +143,7 @@ constructor(
            Log.e(TAG, "Affordance config with key of \"$configKey\" not found!")
            return
        }
        logger.logOnShortcutTriggered(slotId, configKey)

        when (val result = config.onTriggered(expandable)) {
            is KeyguardQuickAffordanceConfig.OnTriggeredResult.StartActivity ->
@@ -191,6 +196,7 @@ constructor(
                affordanceIds = selections,
            )

        logger.logOnShortcutSelected(slotId, affordanceId)
        return true
    }

+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.keyguard.shared.quickaffordance

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.shared.system.SysUiStatsLog

interface KeyguardQuickAffordancesMetricsLogger {

    /**
     * Logs shortcut Triggered
     * @param slotId The id of the lockscreen slot that the affordance is in
     * @param affordanceId The id of the lockscreen affordance
     */
    fun logOnShortcutTriggered(slotId: String, affordanceId: String)

    /**
     * Logs shortcut Selected
     * @param slotId The id of the lockscreen slot that the affordance is in
     * @param affordanceId The id of the lockscreen affordance
     */
    fun logOnShortcutSelected(slotId: String, affordanceId: String)

}

@SysUISingleton
class KeyguardQuickAffordancesMetricsLoggerImpl : KeyguardQuickAffordancesMetricsLogger {

    override fun logOnShortcutTriggered(slotId: String, affordanceId: String) {
        SysUiStatsLog.write(
                SysUiStatsLog.LOCKSCREEN_SHORTCUT_TRIGGERED,
                slotId,
                affordanceId,
        )
    }

    override fun logOnShortcutSelected(slotId: String, affordanceId: String) {
        SysUiStatsLog.write(
                SysUiStatsLog.LOCKSCREEN_SHORTCUT_SELECTED,
                slotId,
                affordanceId,
        )
    }
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -502,6 +502,7 @@ object KeyguardBottomAreaViewBinder {
                    KeyguardQuickAffordanceViewModel.OnClickedParameters(
                        configKey = configKey,
                        expandable = Expandable.fromView(view),
                        slotId = viewModel.slotId,
                    )
                )
            }
@@ -568,6 +569,7 @@ object KeyguardBottomAreaViewBinder {
                    KeyguardQuickAffordanceViewModel.OnClickedParameters(
                        configKey = viewModel.configKey,
                        expandable = Expandable.fromView(view),
                        slotId = viewModel.slotId,
                    )
                )
            }
+10 −3
Original line number Diff line number Diff line
@@ -175,7 +175,8 @@ constructor(
                    areQuickAffordancesFullyOpaque,
                    selectedPreviewSlotId,
                ) { model, animateReveal, isFullyOpaque, selectedPreviewSlotId ->
                    val isSelected = selectedPreviewSlotId == position.toSlotId()
                    val slotId = position.toSlotId()
                    val isSelected = selectedPreviewSlotId == slotId
                    model.toViewModel(
                        animateReveal = !previewMode.isInPreviewMode && animateReveal,
                        isClickable = isFullyOpaque && !previewMode.isInPreviewMode,
@@ -187,7 +188,8 @@ constructor(
                            previewMode.isInPreviewMode &&
                                previewMode.shouldHighlightSelectedAffordance &&
                                !isSelected,
                        forceInactive = previewMode.isInPreviewMode
                        forceInactive = previewMode.isInPreviewMode,
                        slotId = slotId,
                    )
                }
                .distinctUntilChanged()
@@ -200,6 +202,7 @@ constructor(
        isSelected: Boolean,
        isDimmed: Boolean,
        forceInactive: Boolean,
        slotId: String,
    ): KeyguardQuickAffordanceViewModel {
        return when (this) {
            is KeyguardQuickAffordanceModel.Visible ->
@@ -212,6 +215,7 @@ constructor(
                        quickAffordanceInteractor.onQuickAffordanceTriggered(
                            configKey = parameters.configKey,
                            expandable = parameters.expandable,
                            slotId = parameters.slotId,
                        )
                    },
                    isClickable = isClickable,
@@ -219,8 +223,11 @@ constructor(
                    isSelected = isSelected,
                    useLongPress = quickAffordanceInteractor.useLongPress,
                    isDimmed = isDimmed,
                    slotId = slotId,
                )
            is KeyguardQuickAffordanceModel.Hidden -> KeyguardQuickAffordanceViewModel(
                slotId = slotId,
            )
            is KeyguardQuickAffordanceModel.Hidden -> KeyguardQuickAffordanceViewModel()
        }
    }

Loading