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

Commit 2e1dec9d authored by Kanyinsola Fapohunda's avatar Kanyinsola Fapohunda Committed by Android (Google) Code Review
Browse files

Merge "Remove legacy flag for time feedback" into main

parents 227c77e5 9d036d26
Loading
Loading
Loading
Loading
+0 −52
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.settings.datetime;

import static android.provider.DeviceConfig.NAMESPACE_SYSTEM_TIME;

import android.provider.DeviceConfig;

import com.android.settings.flags.Flags;

/** A class to avoid duplication of launch-control logic for "time feedback" support. */
final class DateTimeLaunchUtils {
    /**
     * A {@link DeviceConfig} flag that influences whether the settings entries related to help and
     * feedback are supported on this device / for this user.
     */
    public static final String KEY_HELP_AND_FEEDBACK_FEATURE_SUPPORTED =
            "time_help_and_feedback_feature_supported";

    private DateTimeLaunchUtils() {}

    static boolean isFeedbackFeatureSupported() {
        // Support is determined according to:
        // 1) A build-time flag to determine release feature availability.
        // 2) A runtime / server-side flag to determine which devices / who gets to see the feature.
        //    This is launch control for limiting the feedback to droidfooding.
        return isFeedbackFeatureSupportedThisRelease() && isFeedbackFeatureSupportedOnThisDevice();
    }

    private static boolean isFeedbackFeatureSupportedThisRelease() {
        return Flags.datetimeFeedback();
    }

    private static boolean isFeedbackFeatureSupportedOnThisDevice() {
        boolean defaultIsSupported = false;
        return DeviceConfig.getBoolean(
                NAMESPACE_SYSTEM_TIME, KEY_HELP_AND_FEEDBACK_FEATURE_SUPPORTED, defaultIsSupported);
    }
}
+2 −5
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import androidx.annotation.NonNull;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags;
import com.android.settingslib.core.AbstractPreferenceController;

import java.util.ArrayList;
@@ -48,7 +49,7 @@ public class TimeFeedbackPreferenceCategoryController extends BasePreferenceCont
    @Override
    public int getAvailabilityStatus() {
        // Firstly, hide the category if it is not enabled by flags.
        if (!isTimeFeedbackFeatureEnabled()) {
        if (!Flags.datetimeFeedback()) {
            return UNSUPPORTED_ON_DEVICE;
        }

@@ -60,8 +61,4 @@ public class TimeFeedbackPreferenceCategoryController extends BasePreferenceCont
        }
        return UNSUPPORTED_ON_DEVICE;
    }

    protected boolean isTimeFeedbackFeatureEnabled() {
        return DateTimeLaunchUtils.isFeedbackFeatureSupported();
    }
}
+4 −6
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.flags.Flags;

import java.net.URISyntaxException;

@@ -47,7 +48,6 @@ public class TimeFeedbackPreferenceController

    private final PackageManager mPackageManager;
    private final String mIntentUri;
    private final int mAvailabilityStatus;

    public TimeFeedbackPreferenceController(Context context, String preferenceKey) {
        this(context, context.getPackageManager(), preferenceKey, context.getResources().getString(
@@ -60,7 +60,6 @@ public class TimeFeedbackPreferenceController
        super(context, preferenceKey);
        mPackageManager = packageManager;
        mIntentUri = intentUri;
        mAvailabilityStatus = TextUtils.isEmpty(mIntentUri) ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
    }

    /**
@@ -75,13 +74,12 @@ public class TimeFeedbackPreferenceController

    @Override
    public int getAvailabilityStatus() {
        if (!DateTimeLaunchUtils.isFeedbackFeatureSupported()) {
        if (!Flags.datetimeFeedback() || TextUtils.isEmpty(mIntentUri)) {
            return UNSUPPORTED_ON_DEVICE;
        }
        if (!isTimeFeedbackTargetAvailable()) {
        } else if (!isTimeFeedbackTargetAvailable()) {
            return CONDITIONALLY_UNAVAILABLE;
        }
        return mAvailabilityStatus;
        return AVAILABLE;
    }

    @Override
+14 −31
Original line number Diff line number Diff line
@@ -24,45 +24,51 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;

import com.android.settings.flags.Flags;
import com.android.settingslib.core.AbstractPreferenceController;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class TimeFeedbackPreferenceCategoryControllerTest {

    private TestTimeFeedbackPreferenceCategoryController mController;
    private TimeFeedbackPreferenceCategoryController mController;
    @Mock private AbstractPreferenceController mChildController;

    @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        Context context = RuntimeEnvironment.getApplication();

        mController = new TestTimeFeedbackPreferenceCategoryController(context, "test_key");
        mController = new TimeFeedbackPreferenceCategoryController(context, "test_key");
        mController.addChildController(mChildController);
    }

    @Test
    @DisableFlags({Flags.FLAG_DATETIME_FEEDBACK})
    public void getAvailabilityStatus_featureEnabledPrimary() {
        mController.setTimeFeedbackFeatureEnabled(false);

        when(mChildController.isAvailable()).thenReturn(true);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @Test
    @EnableFlags({Flags.FLAG_DATETIME_FEEDBACK})
    public void getAvailabilityStatus_childControllerSecondary() {
        mController.setTimeFeedbackFeatureEnabled(true);

        when(mChildController.isAvailable()).thenReturn(false);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
@@ -71,27 +77,4 @@ public class TimeFeedbackPreferenceCategoryControllerTest {

        assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
    }

    /**
     * Extend class under test to change {@link #isTimeFeedbackFeatureEnabled} to not call
     * {@link DateTimeLaunchUtils} because that's non-trivial to fake.
     */
    private static class TestTimeFeedbackPreferenceCategoryController
            extends TimeFeedbackPreferenceCategoryController {

        private boolean mTimeFeedbackFeatureEnabled;

        TestTimeFeedbackPreferenceCategoryController(Context context, String preferenceKey) {
            super(context, preferenceKey);
        }

        void setTimeFeedbackFeatureEnabled(boolean value) {
            this.mTimeFeedbackFeatureEnabled = value;
        }

        @Override
        protected boolean isTimeFeedbackFeatureEnabled() {
            return mTimeFeedbackFeatureEnabled;
        }
    }
}
+12 −7
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.settings.datetime;

import static android.provider.DeviceConfig.NAMESPACE_SYSTEM_TIME;

import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
@@ -38,9 +36,9 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.DeviceConfig;

import androidx.preference.Preference;

@@ -82,6 +80,7 @@ public class TimeFeedbackPreferenceControllerTest {
    }

    @Test
    @EnableFlags({Flags.FLAG_DATETIME_FEEDBACK})
    public void emptyIntentUri_controllerNotAvailable() {
        String emptyIntentUri = "";
        TimeFeedbackPreferenceController controller =
@@ -90,11 +89,18 @@ public class TimeFeedbackPreferenceControllerTest {
        assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @Test
    @DisableFlags({Flags.FLAG_DATETIME_FEEDBACK})
    public void datetimeFeedbackDisabled_controllerNotAvailable() {
        TimeFeedbackPreferenceController controller =
                new TimeFeedbackPreferenceController(
                        mContext, mContext.getPackageManager(), "test_key", TEST_INTENT_URI);
        assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @Test
    @EnableFlags({Flags.FLAG_DATETIME_FEEDBACK})
    public void validIntentUri_targetHandlerNotFound_returnsConditionallyUnavailable() {
        DeviceConfig.setProperty(NAMESPACE_SYSTEM_TIME,
                DateTimeLaunchUtils.KEY_HELP_AND_FEEDBACK_FEATURE_SUPPORTED, "true", true);
        when(mMockPackageManager.resolveActivity(any(), anyInt())).thenReturn(null);

        TimeFeedbackPreferenceController controller =
@@ -107,8 +113,6 @@ public class TimeFeedbackPreferenceControllerTest {
    @Test
    @EnableFlags({Flags.FLAG_DATETIME_FEEDBACK})
    public void validIntentUri_targetHandlerAvailable_returnsAvailable() {
        DeviceConfig.setProperty(NAMESPACE_SYSTEM_TIME,
                DateTimeLaunchUtils.KEY_HELP_AND_FEEDBACK_FEATURE_SUPPORTED, "true", true);
        when(mMockPackageManager.resolveActivity(any(), anyInt())).thenReturn(
                createDummyResolveInfo());

@@ -120,6 +124,7 @@ public class TimeFeedbackPreferenceControllerTest {
    }

    @Test
    @EnableFlags({Flags.FLAG_DATETIME_FEEDBACK})
    public void clickPreference() {
        Preference preference = new Preference(mContext);