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

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

Merge "Add metrics for double tap power actions" into main

parents 74b7a28a 88be4363
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.gestures;

import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -25,6 +26,8 @@ import android.provider.Settings;
import androidx.annotation.NonNull;

import com.android.internal.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;

/** Common code for double tap power settings shared between controllers. */
final class DoubleTapPowerSettingsUtils {
@@ -91,6 +94,8 @@ final class DoubleTapPowerSettingsUtils {
     */
    public static boolean setDoubleTapPowerButtonGestureEnabled(
            @NonNull Context context, boolean enable) {
        getMetricsFeatureProvider().action(
                context, SettingsEnums.ACTION_DOUBLE_TAP_POWER_ENABLED, enable);
        return Settings.Secure.putInt(
                context.getContentResolver(),
                DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
@@ -121,6 +126,9 @@ final class DoubleTapPowerSettingsUtils {
     * @return {@code true} if the setting is updated.
     */
    public static boolean setDoubleTapPowerButtonForCameraLaunch(@NonNull Context context) {
        getMetricsFeatureProvider().action(
                context, SettingsEnums.ACTION_DOUBLE_TAP_POWER_BUTTON_BEHAVIOR,
                DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
        return Settings.Secure.putInt(
                context.getContentResolver(),
                DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
@@ -134,6 +142,9 @@ final class DoubleTapPowerSettingsUtils {
     * @return {@code true} if the setting is updated.
     */
    public static boolean setDoubleTapPowerButtonForWalletLaunch(@NonNull Context context) {
        getMetricsFeatureProvider().action(
                context, SettingsEnums.ACTION_DOUBLE_TAP_POWER_BUTTON_BEHAVIOR,
                DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
        return Settings.Secure.putInt(
                context.getContentResolver(),
                DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
@@ -160,4 +171,8 @@ final class DoubleTapPowerSettingsUtils {
        final ContentResolver resolver = context.getContentResolver();
        resolver.unregisterContentObserver(observer);
    }

    private static MetricsFeatureProvider getMetricsFeatureProvider() {
        return FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -23,10 +23,14 @@ import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.ON;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
@@ -35,6 +39,7 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.android.internal.R;
import com.android.settings.testutils.FakeFeatureFactory;

import org.junit.Before;
import org.junit.Test;
@@ -49,11 +54,14 @@ public class DoubleTapPowerSettingsUtilsTest {
    private Context mContext;
    private Resources mResources;

    private FakeFeatureFactory mFeatureFactory;

    @Before
    public void setUp() {
        mContext = spy(ApplicationProvider.getApplicationContext());
        mResources = mock(Resources.class);
        when(mContext.getResources()).thenReturn(mResources);
        mFeatureFactory = FakeFeatureFactory.setupForTest();
    }

    @Test
@@ -114,6 +122,8 @@ public class DoubleTapPowerSettingsUtilsTest {
                        Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
                        OFF))
                .isEqualTo(ON);
        verify(mFeatureFactory.metricsFeatureProvider).action(any(),
                eq(SettingsEnums.ACTION_DOUBLE_TAP_POWER_ENABLED), eq(true));
    }

    @Test
@@ -126,6 +136,8 @@ public class DoubleTapPowerSettingsUtilsTest {
                        Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
                        ON))
                .isEqualTo(OFF);
        verify(mFeatureFactory.metricsFeatureProvider).action(any(),
                eq(SettingsEnums.ACTION_DOUBLE_TAP_POWER_ENABLED), eq(false));
    }

    @Test
@@ -191,6 +203,9 @@ public class DoubleTapPowerSettingsUtilsTest {
                        Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
                        DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE))
                .isEqualTo(DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
        verify(mFeatureFactory.metricsFeatureProvider).action(any(),
                eq(SettingsEnums.ACTION_DOUBLE_TAP_POWER_BUTTON_BEHAVIOR),
                eq(DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE));
    }

    @Test
@@ -205,5 +220,8 @@ public class DoubleTapPowerSettingsUtilsTest {
                        Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
                        DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE))
                .isEqualTo(DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
        verify(mFeatureFactory.metricsFeatureProvider).action(any(),
                eq(SettingsEnums.ACTION_DOUBLE_TAP_POWER_BUTTON_BEHAVIOR),
                eq(DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE));
    }
}