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

Commit d8d280f6 authored by Anton Potapov's avatar Anton Potapov
Browse files

Migrate secondary non-critical functionality from QSTileImpl

This includes:
- analytics tracking
- logging
- filtering false touches

Test: atest QSTileAnalyticsTest QSTileLoggerTest
Bug: 299908705
Change-Id: I98fb31c7d91f503782f63ef3cb1975ae1c4933d7
parent 4fdea46e
Loading
Loading
Loading
Loading
+36 −4
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import com.android.systemui.log.LogcatEchoTrackerProd;
import com.android.systemui.log.table.TableLogBuffer;
import com.android.systemui.log.table.TableLogBufferFactory;
import com.android.systemui.qs.QSFragmentLegacy;
import com.android.systemui.qs.pipeline.shared.QSPipelineFlagsRepository;
import com.android.systemui.qs.pipeline.shared.TileSpec;
import com.android.systemui.statusbar.notification.NotifPipelineFlags;
import com.android.systemui.util.Compile;
import com.android.systemui.util.wakelock.WakeLockLog;
@@ -37,6 +39,9 @@ import com.android.systemui.util.wakelock.WakeLockLog;
import dagger.Module;
import dagger.Provides;

import java.util.HashMap;
import java.util.Map;

/**
 * Dagger module for providing instances of {@link LogBuffer}.
 */
@@ -173,9 +178,36 @@ public class LogModule {
    @Provides
    @SysUISingleton
    @QSLog
    public static LogBuffer provideQuickSettingsLogBuffer(LogBufferFactory factory) {
    public static LogBuffer provideQuickSettingsLogBuffer(
            LogBufferFactory factory,
            QSPipelineFlagsRepository flags
    ) {
        if (flags.getPipelineTilesEnabled()) {
            // we use
            return factory.create("QSLog", 450 /* maxSize */, false /* systrace */);
        } else {
            return factory.create("QSLog", 700 /* maxSize */, false /* systrace */);
        }
    }

    /**
     * Provides a logging buffer for all logs related to Quick Settings tiles. This LogBuffer is
     * unique for each tile.
     * go/qs-tile-refactor
     */
    @Provides
    @QSTilesDefaultLog
    public static LogBuffer provideQuickSettingsTilesLogBuffer(LogBufferFactory factory) {
        return factory.create("QSTileLog", 25 /* maxSize */, false /* systrace */);
    }

    @Provides
    @QSTilesLogBuffers
    public static Map<TileSpec, LogBuffer> provideQuickSettingsTilesLogBufferCache() {
        final Map<TileSpec, LogBuffer> buffers = new HashMap<>();
        // Add chatty buffers here
        return buffers;
    }

    /** Provides a logging buffer for logs related to Quick Settings configuration. */
    @Provides
+28 −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.log.dagger

import javax.inject.Qualifier

/**
 * A default [com.android.systemui.log.LogBuffer] for QS tiles messages. It's used exclusively in
 * [com.android.systemui.qs.tiles.base.logging.QSTileLogger]. If you need to increase it for you
 * tile, add one to the map provided by the [QSTilesLogBuffers]
 */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class QSTilesDefaultLog
+30 −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.log.dagger

import javax.inject.Qualifier

/**
 * Provides a map with custom [com.android.systemui.log.LogBuffer] for QS tiles messages. Add
 * buffers to it when the tile needs to be more verbose and the default buffer provided by
 * [QSTilesDefaultLog] is not enough.
 *
 * This is not a multibinding. Add new logs directly to [LogModule]
 */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class QSTilesLogBuffers
+36 −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.log.dagger;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import com.android.systemui.log.LogBuffer;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Qualifier;

/**
 * A {@link LogBuffer} for QS tiles messages. It's used exclusively in
 * {@link com.android.systemui.qs.tiles.base.logging.QSTileLogger}
 */
@Qualifier
@Documented
@Retention(RUNTIME)
public @interface QSTilesVerboseLog {
}
+52 −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.qs.tiles.base.analytics

import com.android.internal.logging.UiEventLogger
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.qs.QSEvent
import com.android.systemui.qs.tiles.viewmodel.QSTileConfig
import com.android.systemui.qs.tiles.viewmodel.QSTileUserAction
import javax.inject.Inject

/** Tracks QS tiles analytic events to [UiEventLogger]. */
@SysUISingleton
class QSTileAnalytics
@Inject
constructor(
    private val uiEventLogger: UiEventLogger,
) {

    fun trackUserAction(config: QSTileConfig, action: QSTileUserAction) {
        logAction(config, action)
    }

    private fun logAction(config: QSTileConfig, action: QSTileUserAction) {
        uiEventLogger.logWithInstanceId(
            action.getQSEvent(),
            0,
            config.metricsSpec,
            config.instanceId,
        )
    }

    private fun QSTileUserAction.getQSEvent(): QSEvent =
        when (this) {
            is QSTileUserAction.Click -> QSEvent.QS_ACTION_CLICK
            is QSTileUserAction.LongClick -> QSEvent.QS_ACTION_LONG_PRESS
        }
}
Loading