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

Commit 67e155d1 authored by Darrell Shi's avatar Darrell Shi
Browse files

Log UI event on tap clock complication

Bug: 284028343
Bug: 284028011
Test: atest DreamHomeControlsComplicationTest
Test: atest DreamClockTimeComplicationTest
Change-Id: I6bddf2de86654dc62f10fca029a3e6d4d13a1a75
parent c74dc994
Loading
Loading
Loading
Loading
+32 −2
Original line number Diff line number Diff line
@@ -21,11 +21,13 @@ import static com.android.systemui.complication.dagger.RegisteredComplicationsMo

import android.view.View;

import com.android.internal.logging.UiEventLogger;
import com.android.systemui.CoreStartable;
import com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent;
import com.android.systemui.dagger.qualifiers.SystemUser;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.shared.condition.Monitor;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.condition.ConditionalCoreStartable;

import javax.inject.Inject;
@@ -94,11 +96,14 @@ public class DreamClockTimeComplication implements Complication {
        private final ComplicationLayoutParams mLayoutParams;

        @Inject
        DreamClockTimeViewHolder(@Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
        DreamClockTimeViewHolder(
                @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
                @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
                        ComplicationLayoutParams layoutParams) {
                        ComplicationLayoutParams layoutParams,
                DreamClockTimeViewController viewController) {
            mView = view;
            mLayoutParams = layoutParams;
            viewController.init();
        }

        @Override
@@ -111,4 +116,29 @@ public class DreamClockTimeComplication implements Complication {
            return mLayoutParams;
        }
    }

    static class DreamClockTimeViewController extends ViewController<View> {
        private final UiEventLogger mUiEventLogger;

        @Inject
        DreamClockTimeViewController(
                @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
                UiEventLogger uiEventLogger) {
            super(view);

            mUiEventLogger = uiEventLogger;
        }

        @Override
        protected void onViewAttached() {
            mView.setOnClickListener(this::onClick);
        }

        @Override
        protected void onViewDetached() {}

        private void onClick(View v) {
            mUiEventLogger.log(DreamOverlayUiEvent.DREAM_CLOCK_TAPPED);
        }
    }
}
+1 −20
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.CoreStartable;
import com.android.systemui.animation.ActivityLaunchAnimator;
@@ -201,23 +199,6 @@ public class DreamHomeControlsComplication implements Complication {

        private final UiEventLogger mUiEventLogger;

        @VisibleForTesting
        public enum DreamOverlayEvent implements UiEventLogger.UiEventEnum {
            @UiEvent(doc = "The home controls on the screensaver has been tapped.")
            DREAM_HOME_CONTROLS_TAPPED(1212);

            private final int mId;

            DreamOverlayEvent(int id) {
                mId = id;
            }

            @Override
            public int getId() {
                return mId;
            }
        }

        @Inject
        DreamHomeControlsChipViewController(
                @Named(DREAM_HOME_CONTROLS_CHIP_VIEW) ImageView view,
@@ -246,7 +227,7 @@ public class DreamHomeControlsComplication implements Complication {
        private void onClickHomeControls(View v) {
            if (DEBUG) Log.d(TAG, "home controls complication tapped");

            mUiEventLogger.log(DreamOverlayEvent.DREAM_HOME_CONTROLS_TAPPED);
            mUiEventLogger.log(DreamOverlayUiEvent.DREAM_HOME_CONTROLS_TAPPED);

            final Intent intent = new Intent(mContext, ControlsActivity.class)
                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
+32 −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.complication

import com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger.UiEventEnum

/** UI log events for the dream overlay. */
enum class DreamOverlayUiEvent(private val mId: Int) : UiEventEnum {
    @UiEvent(doc = "The home controls on the screensaver has been tapped.")
    DREAM_HOME_CONTROLS_TAPPED(1212),
    @UiEvent(doc = "The clock on the screensaver has been tapped") DREAM_CLOCK_TAPPED(1440),
    @UiEvent(doc = "The weather on the screensaver has been tapped") DREAM_WEATHER_TAPPED(1441);

    override fun getId(): Int {
        return mId
    }
}
+24 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.view.View;

import androidx.test.filters.SmallTest;

import com.android.internal.logging.UiEventLogger;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent;
import com.android.systemui.condition.SelfExecutingMonitor;
@@ -37,6 +38,7 @@ import com.android.systemui.shared.condition.Monitor;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@@ -72,6 +74,12 @@ public class DreamClockTimeComplicationTest extends SysuiTestCase {
    @Mock
    private ComplicationLayoutParams mLayoutParams;

    @Mock
    private DreamClockTimeComplication.DreamClockTimeViewController mViewController;

    @Mock
    private UiEventLogger mUiEventLogger;

    private Monitor mMonitor;

    @Before
@@ -127,8 +135,23 @@ public class DreamClockTimeComplicationTest extends SysuiTestCase {
    @Test
    public void testComplicationViewHolderContentAccessors() {
        final DreamClockTimeComplication.DreamClockTimeViewHolder viewHolder =
                new DreamClockTimeComplication.DreamClockTimeViewHolder(mView, mLayoutParams);
                new DreamClockTimeComplication.DreamClockTimeViewHolder(mView, mLayoutParams,
                        mViewController);
        assertThat(viewHolder.getView()).isEqualTo(mView);
        assertThat(viewHolder.getLayoutParams()).isEqualTo(mLayoutParams);
    }

    @Test
    public void testClick_logUiEvent() {
        final DreamClockTimeComplication.DreamClockTimeViewController controller =
                new DreamClockTimeComplication.DreamClockTimeViewController(mView, mUiEventLogger);
        controller.onViewAttached();

        final ArgumentCaptor<View.OnClickListener> clickListenerCaptor =
                ArgumentCaptor.forClass(View.OnClickListener.class);
        verify(mView).setOnClickListener(clickListenerCaptor.capture());

        clickListenerCaptor.getValue().onClick(mView);
        verify(mUiEventLogger).log(DreamOverlayUiEvent.DREAM_CLOCK_TAPPED);
    }
}
+1 −3
Original line number Diff line number Diff line
@@ -234,9 +234,7 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase {
        verify(mHomeControlsView).setOnClickListener(clickListenerCaptor.capture());

        clickListenerCaptor.getValue().onClick(mHomeControlsView);
        verify(mUiEventLogger).log(
                DreamHomeControlsComplication.DreamHomeControlsChipViewController
                        .DreamOverlayEvent.DREAM_HOME_CONTROLS_TAPPED);
        verify(mUiEventLogger).log(DreamOverlayUiEvent.DREAM_HOME_CONTROLS_TAPPED);
    }

    private void setHaveFavorites(boolean value) {