Implement the missing PreferenceControllerMixin interface
Change-Id: I0bb28cf9d2ec24629485a754778faddcbc8f9fdb Fixes: 68716631 Test: atest PreferenceControllerContractTest
This commit is contained in:
@@ -19,10 +19,11 @@ import android.support.v14.preference.SwitchPreference;
|
|||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
public class ShowOperatorNamePreferenceController extends AbstractPreferenceController
|
public class ShowOperatorNamePreferenceController extends AbstractPreferenceController
|
||||||
implements Preference.OnPreferenceChangeListener {
|
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String KEY_SHOW_OPERATOR_NAME = "show_operator_name";
|
private static final String KEY_SHOW_OPERATOR_NAME = "show_operator_name";
|
||||||
|
|
||||||
|
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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.core;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.fail;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.SearchIndexableResource;
|
||||||
|
import android.support.test.InstrumentationRegistry;
|
||||||
|
import android.support.test.filters.MediumTest;
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import android.util.ArraySet;
|
||||||
|
|
||||||
|
import com.android.settings.search.DatabaseIndexingUtils;
|
||||||
|
import com.android.settings.search.Indexable;
|
||||||
|
import com.android.settings.search.SearchIndexableResources;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@MediumTest
|
||||||
|
public class PreferenceControllerContractTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void controllersInSearchShouldImplementPreferenceControllerMixin() {
|
||||||
|
final Set<String> errorClasses = new ArraySet<>();
|
||||||
|
|
||||||
|
for (SearchIndexableResource page : SearchIndexableResources.values()) {
|
||||||
|
final Class<?> clazz = DatabaseIndexingUtils.getIndexableClass(page.className);
|
||||||
|
|
||||||
|
final Indexable.SearchIndexProvider provider =
|
||||||
|
DatabaseIndexingUtils.getSearchIndexProvider(clazz);
|
||||||
|
if (provider == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<AbstractPreferenceController> controllers =
|
||||||
|
provider.getPreferenceControllers(mContext);
|
||||||
|
if (controllers == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (AbstractPreferenceController controller : controllers) {
|
||||||
|
if (!(controller instanceof PreferenceControllerMixin)) {
|
||||||
|
errorClasses.add(controller.getClass().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!errorClasses.isEmpty()) {
|
||||||
|
final StringBuilder errorMessage = new StringBuilder()
|
||||||
|
.append("Each preference must implement PreferenceControllerMixin, ")
|
||||||
|
.append("the following classes don't:\n");
|
||||||
|
for (String c : errorClasses) {
|
||||||
|
errorMessage.append(c).append("\n");
|
||||||
|
}
|
||||||
|
fail(errorMessage.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings.core;
|
||||||
|
|
||||||
import static junit.framework.Assert.fail;
|
import static junit.framework.Assert.fail;
|
||||||
|
|
Reference in New Issue
Block a user