Merge changes I236b1124,Iad16b06e into pi-dev

* changes:
  Add conformance test for preference controller constructor
  Remove duplicate framework classes/robotest compile stub
This commit is contained in:
TreeHugger Robot
2018-03-29 02:48:21 +00:00
committed by Android (Google) Code Review
10 changed files with 126 additions and 343 deletions

View File

@@ -1,44 +0,0 @@
/*
* Copyright (C) 2016 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.internal.app;
/**
* Fake controller to make robolectric test compile. This is necessary since
* ColorDisplayController is not part of Android's API.
*/
public class ColorDisplayController {
public static final int AUTO_MODE_DISABLED = 0;
public static final int AUTO_MODE_CUSTOM = 1;
public static final int AUTO_MODE_TWILIGHT = 2;
public static final int COLOR_MODE_NATURAL = 0;
public static final int COLOR_MODE_BOOSTED = 1;
public static final int COLOR_MODE_SATURATED = 2;
private int mColorMode;
public void setColorMode(int colorMode) {
mColorMode = colorMode;
}
public int getColorMode() {
return mColorMode;
}
public interface Callback {
}
}

View File

@@ -1,11 +0,0 @@
package com.android.internal.app;
/**
* A placeholder class to prevent ClassNotFound exceptions caused by lack of visibility.
*/
public class LocalePickerWithRegion {
public interface LocaleSelectedListener {
void onLocaleSelected(LocaleStore.LocaleInfo locale);
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (C) 2018 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 com.google.common.truth.Truth.assertWithMessage;
import android.content.Context;
import com.android.settings.core.codeinspection.CodeInspector;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
public class BasePreferenceControllerSignatureInspector extends CodeInspector {
private final List<String> grandfather;
public BasePreferenceControllerSignatureInspector(List<Class<?>> classes) {
super(classes);
grandfather = new ArrayList<>();
initializeGrandfatherList(grandfather,
"grandfather_invalid_base_preference_controller_constructor");
}
@Override
public void run() {
StringBuilder badClasses = new StringBuilder();
for (Class c : mClasses) {
if (!isConcreteSettingsClass(c)) {
// Not a Settings class, or is abstract, don't care.
continue;
}
if (!BasePreferenceController.class.isAssignableFrom(c)) {
// Not a BasePreferenceController, don't care.
continue;
}
final String className = c.getName();
if (grandfather.remove(className)) {
continue;
}
final Constructor[] constructors = c.getDeclaredConstructors();
if (constructors == null || constructors.length == 0) {
badClasses.append(c.getName()).append(",");
}
for (Constructor constructor : constructors) {
if (!hasValidConstructorSignature(constructor)) {
badClasses.append(className).append(",");
continue;
}
}
}
assertWithMessage("All BasePreferenceController (and subclasses) constructor must either"
+ "only take Context, or (Context, String). No other types are allowed")
.that(badClasses.toString())
.isEmpty();
assertWithMessage("Something in the grandfather list is no longer relevant. Please remove")
.that(grandfather)
.isEmpty();
}
private static boolean hasValidConstructorSignature(Constructor constructor) {
final Class[] parameterTypes = constructor.getParameterTypes();
if (parameterTypes.length == 1) {
return Context.class.isAssignableFrom(parameterTypes[0]);
} else if (parameterTypes.length == 2) {
return Context.class.isAssignableFrom(parameterTypes[0])
&& String.class.isAssignableFrom(parameterTypes[1]);
}
return false;
}
}

View File

@@ -18,6 +18,7 @@ package com.android.settings.core.codeinspection;
import static com.google.common.truth.Truth.assertThat;
import com.android.settings.core.BasePreferenceControllerSignatureInspector;
import com.android.settings.core.instrumentation.InstrumentableFragmentCodeInspector;
import com.android.settings.search.SearchIndexProviderCodeInspector;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -49,6 +50,11 @@ public class CodeInspectionTest {
new InstrumentableFragmentCodeInspector(mClasses).run();
}
@Test
public void runBasePreferenceControllerConstructorSignatureInspection() {
new BasePreferenceControllerSignatureInspector(mClasses).run();
}
@Ignore("b/73960706")
@Test
public void runSearchIndexProviderCodeInspection() {