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

Commit c1c708f9 authored by Fan Zhang's avatar Fan Zhang
Browse files

Ensure DashboardFragment shares pref controlls with search

Test: make RunSettingsRoboTests
Change-Id: I48be270d9706539925d00874bae29d46406ac491
Fix: 35812240
parent b00811da
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class BuildNumberPreferenceController extends PreferenceController
        super(context);
        mActivity = activity;
        mFragment = fragment;
        mUm = UserManager.get(context);
        mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
        if (lifecycle != null) {
            lifecycle.addObserver(this);
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ public class EmergencyBroadcastPreferenceController extends PreferenceController
    EmergencyBroadcastPreferenceController(Context context, AccountRestrictionHelper helper) {
        super(context);
        mHelper = helper;
        mUserManager = UserManager.get(context);
        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        mPm = mContext.getPackageManager();
        // Enable link to CMAS app settings depending on the value in config.xml.
        mCellBroadcastAppLinkEnabled = isCellBroadcastAppLinkEnabled();
+11 −0
Original line number Diff line number Diff line
com.android.settings.gestures.PickupGestureSettings
com.android.settings.language.LanguageAndInputSettings
com.android.settings.enterprise.EnterprisePrivacySettings
com.android.settings.gestures.DoubleTapScreenSettings
com.android.settings.applications.AdvancedAppSettings
com.android.settings.gestures.AssistGestureSettings
com.android.settings.fuelgauge.PowerUsageSummary
com.android.settings.gestures.SwipeToNotificationSettings
com.android.settings.inputmethod.InputMethodAndLanguageSettings
com.android.settings.gestures.DoubleTapPowerSettings
com.android.settings.gestures.DoubleTwistGestureSettings
 No newline at end of file
+4 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.settings.SettingsActivity;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.CategoryManager;
import com.android.settingslib.drawer.DashboardCategory;
@@ -62,7 +63,9 @@ import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;

@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH,
        sdk = TestConfig.SDK_VERSION,
        shadows = ShadowUserManager.class)
public class DashboardFeatureProviderImplTest {

    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.dashboard;

import android.app.Fragment;
import android.content.Context;

import com.android.settings.core.PreferenceController;
import com.android.settings.search.Indexable;
import com.android.settings.search2.DatabaseIndexingUtils;

import org.robolectric.RuntimeEnvironment;

import java.util.List;

public class DashboardFragmentSearchIndexProviderInspector {

    public static boolean isSharingPreferenceControllers(Class clazz) {
        final Context context = RuntimeEnvironment.application;
        final Fragment fragment;
        try {
            fragment = Fragment.instantiate(context, clazz.getName());
        } catch (Throwable e) {
            // Can't do much with exception, assume the test passed.
            return true;
        }
        if (!(fragment instanceof DashboardFragment)) {
            return true;
        }

        final Indexable.SearchIndexProvider provider =
                DatabaseIndexingUtils.getSearchIndexProvider(clazz);
        if (provider == null) {
            return true;
        }
        final List<PreferenceController> controllersFromSearchIndexProvider;
        final List<PreferenceController> controllersFromFragment;
        try {
            controllersFromSearchIndexProvider = provider.getPreferenceControllers(context);
        } catch (Throwable e) {
            // Can't do much with exception, assume the test passed.
            return true;
        }
        try {
            controllersFromFragment =
                    ((DashboardFragment) fragment).getPreferenceControllers(context);
        } catch (Throwable e) {
            // Can't do much with exception, assume the test passed.
            return true;
        }

        if (controllersFromFragment == controllersFromSearchIndexProvider) {
            return true;
        } else if (controllersFromFragment != null && controllersFromSearchIndexProvider != null) {
            return controllersFromFragment.size() == controllersFromSearchIndexProvider.size();
        } else {
            return false;
        }
    }
}
Loading