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

Commit ffc352b9 authored by Sunny Shao's avatar Sunny Shao
Browse files

Remove feature flag, unused lib and test cases

Fixes: 155949554
Test: make RunSettingsLibRoboTests -j56
Change-Id: I54a31aed503f7f058887720ab4fe01ca2f39ff93
parent 535e4abd
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -45,8 +45,6 @@ public class FeatureFlagUtils {
    /** @hide */
    /** @hide */
    public static final String SETTINGS_DO_NOT_RESTORE_PRESERVED =
    public static final String SETTINGS_DO_NOT_RESTORE_PRESERVED =
            "settings_do_not_restore_preserved";
            "settings_do_not_restore_preserved";
    /** @hide */
    public static final String SETTINGS_SCHEDULES_FLAG = "settings_schedules";


    private static final Map<String, String> DEFAULT_FLAGS;
    private static final Map<String, String> DEFAULT_FLAGS;


@@ -69,7 +67,6 @@ public class FeatureFlagUtils {
        DEFAULT_FLAGS.put(SETTINGS_DO_NOT_RESTORE_PRESERVED, "true");
        DEFAULT_FLAGS.put(SETTINGS_DO_NOT_RESTORE_PRESERVED, "true");


        DEFAULT_FLAGS.put("settings_tether_all_in_one", "false");
        DEFAULT_FLAGS.put("settings_tether_all_in_one", "false");
        DEFAULT_FLAGS.put(SETTINGS_SCHEDULES_FLAG, "false");
        DEFAULT_FLAGS.put("settings_contextual_home2", "true");
        DEFAULT_FLAGS.put("settings_contextual_home2", "true");
    }
    }


+0 −1
Original line number Original line Diff line number Diff line
@@ -50,7 +50,6 @@ java_defaults {
        "SettingsLibAdaptiveIcon",
        "SettingsLibAdaptiveIcon",
        "SettingsLibRadioButtonPreference",
        "SettingsLibRadioButtonPreference",
        "SettingsLibDisplayDensityUtils",
        "SettingsLibDisplayDensityUtils",
        "SettingsLibSchedulesProvider",
    ],
    ],
}
}


+0 −105
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 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.settingslib.schedulesprovider;

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

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class ScheduleInfoTest {
    private static final String TEST_TITLE = "Night Light";
    private static final String TEST_SUMMARY = "Night Light summary";
    private static final String TEST_EMPTY_SUMMARY = "";

    private final Context mContext = RuntimeEnvironment.application;

    @Test
    public void builder_usedValidArguments_isValid() {
        final PendingIntent pendingIntent = createTestPendingIntent(mContext);
        final ScheduleInfo info = createTestScheduleInfo(TEST_TITLE, TEST_SUMMARY, pendingIntent);

        assertThat(info).isNotNull();
        assertThat(info.isValid()).isTrue();
    }

    @Test
    public void builder_useEmptySummary_isInvalid() {
        final PendingIntent pendingIntent = createTestPendingIntent(mContext);
        final ScheduleInfo info = createTestScheduleInfo(TEST_TITLE, TEST_EMPTY_SUMMARY,
                pendingIntent);

        assertThat(info).isNotNull();
        assertThat(info.isValid()).isFalse();
    }

    @Test
    public void builder_pendingIntentIsNull_isInvalid() {
        final ScheduleInfo info = new ScheduleInfo.Builder()
                .setTitle(TEST_TITLE)
                .setSummary(TEST_SUMMARY)
                .build();

        assertThat(info).isNotNull();
        assertThat(info.isValid()).isFalse();
    }

    @Test
    public void getTitle_setValidTitle_shouldReturnSameCorrectTitle() {
        final PendingIntent pendingIntent = createTestPendingIntent(mContext);
        final ScheduleInfo info = createTestScheduleInfo(TEST_TITLE, TEST_SUMMARY, pendingIntent);

        assertThat(info.getTitle()).isEqualTo(TEST_TITLE);
    }

    @Test
    public void getSummary_setValidSummary_shouldReturnSameCorrectSummary() {
        final PendingIntent pendingIntent = createTestPendingIntent(mContext);
        final ScheduleInfo info = createTestScheduleInfo(TEST_TITLE, TEST_SUMMARY, pendingIntent);

        assertThat(info.getSummary()).isEqualTo(TEST_SUMMARY);
    }

    @Test
    public void getPendingIntent_setValidPendingIntent_shouldReturnSameCorrectIntent() {
        final PendingIntent pendingIntent = createTestPendingIntent(mContext);
        final ScheduleInfo info = createTestScheduleInfo(TEST_TITLE, TEST_SUMMARY, pendingIntent);

        assertThat(info.getPendingIntent()).isEqualTo(pendingIntent);
    }

    private static PendingIntent createTestPendingIntent(Context context) {
        final Intent intent = new Intent("android.settings.NIGHT_DISPLAY_SETTINGS").addCategory(
                Intent.CATEGORY_DEFAULT);
        return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
    }

    private static ScheduleInfo createTestScheduleInfo(String title, String summary,
            PendingIntent pendingIntent) {
        return new ScheduleInfo.Builder()
                .setTitle(title)
                .setSummary(summary)
                .setPendingIntent(pendingIntent)
                .build();
    }
}
+0 −174
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 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.settingslib.schedulesprovider;

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

import static org.robolectric.Shadows.shadowOf;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.util.ArrayList;

@RunWith(RobolectricTestRunner.class)
public class SchedulesProviderTest {
    private static final String INVALID_PACKAGE = "com.android.sunny";
    private static final String VALID_PACKAGE = "com.android.settings";
    private static final String INVALID_METHOD = "queryTestData";

    private final Context mContext = RuntimeEnvironment.application;

    private TestSchedulesProvider mProvider;

    @Before
    public void setUp() {
        mProvider = Robolectric.setupContentProvider(TestSchedulesProvider.class);
        shadowOf(mProvider).setCallingPackage(VALID_PACKAGE);
        mProvider.setScheduleInfos(TestSchedulesProvider.createOneValidScheduleInfo(mContext));
    }

    @Test
    public void call_invalidCallingPkg_returnNull() {
        shadowOf(mProvider).setCallingPackage(INVALID_PACKAGE);

        final Bundle bundle = mProvider.call(SchedulesProvider.METHOD_GENERATE_SCHEDULE_INFO_LIST,
                null /* arg */, null /* extras */);

        assertThat(bundle).isNull();
    }

    @Test
    public void call_invalidMethod_returnBundleWithoutScheduleInfoData() {
        final Bundle bundle = mProvider.call(INVALID_METHOD, null /* arg */, null /* extras */);

        assertThat(bundle).isNotNull();
        assertThat(bundle.containsKey(SchedulesProvider.BUNDLE_SCHEDULE_INFO_LIST)).isFalse();
    }

    @Test
    public void call_validMethod_returnScheduleInfoData() {
        final Bundle bundle = mProvider.call(SchedulesProvider.METHOD_GENERATE_SCHEDULE_INFO_LIST,
                null /* arg */, null /* extras */);

        assertThat(bundle).isNotNull();
        assertThat(bundle.containsKey(SchedulesProvider.BUNDLE_SCHEDULE_INFO_LIST)).isTrue();
        final ArrayList<ScheduleInfo> infos = bundle.getParcelableArrayList(
                SchedulesProvider.BUNDLE_SCHEDULE_INFO_LIST);
        assertThat(infos).hasSize(1);
    }

    @Test
    public void call_addTwoValidData_returnScheduleInfoData() {
        mProvider.setScheduleInfos(TestSchedulesProvider.createTwoValidScheduleInfos(mContext));
        final Bundle bundle = mProvider.call(SchedulesProvider.METHOD_GENERATE_SCHEDULE_INFO_LIST,
                null /* arg */, null /* extras */);

        assertThat(bundle).isNotNull();
        assertThat(bundle.containsKey(SchedulesProvider.BUNDLE_SCHEDULE_INFO_LIST)).isTrue();
        final ArrayList<ScheduleInfo> infos = bundle.getParcelableArrayList(
                SchedulesProvider.BUNDLE_SCHEDULE_INFO_LIST);
        assertThat(infos).hasSize(2);
    }

    @Test
    public void call_addTwoValidDataAndOneInvalidData_returnTwoScheduleInfoData() {
        mProvider.setScheduleInfos(
                TestSchedulesProvider.createTwoValidAndOneInvalidScheduleInfo(mContext));
        final Bundle bundle = mProvider.call(SchedulesProvider.METHOD_GENERATE_SCHEDULE_INFO_LIST,
                null /* arg */, null /* extras */);

        assertThat(bundle).isNotNull();
        assertThat(bundle.containsKey(SchedulesProvider.BUNDLE_SCHEDULE_INFO_LIST)).isTrue();
        final ArrayList<ScheduleInfo> infos = bundle.getParcelableArrayList(
                SchedulesProvider.BUNDLE_SCHEDULE_INFO_LIST);
        assertThat(infos).hasSize(2);
    }

    private static class TestSchedulesProvider extends SchedulesProvider {
        private ArrayList<ScheduleInfo> mScheduleInfos = new ArrayList<>();

        @Override
        public ArrayList<ScheduleInfo> getScheduleInfoList() {
            return mScheduleInfos;
        }

        void setScheduleInfos(ArrayList<ScheduleInfo> scheduleInfos) {
            mScheduleInfos = scheduleInfos;
        }

        private static ArrayList<ScheduleInfo> createOneValidScheduleInfo(Context context) {
            final ArrayList<ScheduleInfo> scheduleInfos = new ArrayList<>();

            final ScheduleInfo info = new ScheduleInfo.Builder().setTitle("Night Light").setSummary(
                    "This a sunny test").setPendingIntent(createTestPendingIntent(context,
                    "android.settings.NIGHT_DISPLAY_SETTINGS")).build();
            scheduleInfos.add(info);

            return scheduleInfos;
        }

        private static ArrayList<ScheduleInfo> createTwoValidScheduleInfos(Context context) {
            final ArrayList<ScheduleInfo> scheduleInfos = new ArrayList<>();
            ScheduleInfo info = new ScheduleInfo.Builder().setTitle("Night Light").setSummary(
                    "This a sunny test").setPendingIntent(createTestPendingIntent(context,
                    "android.settings.NIGHT_DISPLAY_SETTINGS")).build();
            scheduleInfos.add(info);

            info = new ScheduleInfo.Builder().setTitle("Display").setSummary(
                    "Display summary").setPendingIntent(
                    createTestPendingIntent(context, "android.settings.DISPLAY_SETTINGS")).build();
            scheduleInfos.add(info);

            return scheduleInfos;
        }

        private static ArrayList<ScheduleInfo> createTwoValidAndOneInvalidScheduleInfo(
                Context context) {
            final ArrayList<ScheduleInfo> scheduleInfos = new ArrayList<>();
            ScheduleInfo info = new ScheduleInfo.Builder().setTitle("Night Light").setSummary(
                    "This a sunny test").setPendingIntent(createTestPendingIntent(context,
                    "android.settings.NIGHT_DISPLAY_SETTINGS")).build();
            scheduleInfos.add(info);

            info = new ScheduleInfo.Builder().setTitle("Display").setSummary(
                    "Display summary").setPendingIntent(
                    createTestPendingIntent(context, "android.settings.DISPLAY_SETTINGS")).build();
            scheduleInfos.add(info);

            info = new ScheduleInfo.Builder().setTitle("").setSummary(
                    "Display summary").setPendingIntent(
                    createTestPendingIntent(context, "android.settings.DISPLAY_SETTINGS")).build();
            scheduleInfos.add(info);

            return scheduleInfos;
        }

        private static PendingIntent createTestPendingIntent(Context context, String action) {
            final Intent intent = new Intent(action).addCategory(Intent.CATEGORY_DEFAULT);
            return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
        }
    }
}