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

@@ -0,0 +1,31 @@
com.android.settings.applications.appinfo.AppActionButtonPreferenceController
com.android.settings.applications.appinfo.AppBatteryPreferenceController
com.android.settings.applications.appinfo.AppDataUsagePreferenceController
com.android.settings.applications.appinfo.AppHeaderViewPreferenceController
com.android.settings.applications.appinfo.AppInstallerInfoPreferenceController
com.android.settings.applications.appinfo.AppMemoryPreferenceController
com.android.settings.applications.appinfo.AppNotificationPreferenceController
com.android.settings.applications.appinfo.AppOpenByDefaultPreferenceController
com.android.settings.applications.appinfo.AppPermissionPreferenceController
com.android.settings.applications.appinfo.AppStoragePreferenceController
com.android.settings.applications.appinfo.AppVersionPreferenceController
com.android.settings.applications.appinfo.DrawOverlayDetailPreferenceController
com.android.settings.applications.appinfo.ExternalSourceDetailPreferenceController
com.android.settings.applications.appinfo.InstantAppButtonsPreferenceController
com.android.settings.applications.appinfo.InstantAppDomainsPreferenceController
com.android.settings.applications.appinfo.PictureInPictureDetailPreferenceController
com.android.settings.applications.appinfo.WriteSystemSettingsPreferenceController
com.android.settings.bluetooth.BluetoothDeviceNamePreferenceController
com.android.settings.bluetooth.BluetoothDeviceRenamePreferenceController
com.android.settings.bluetooth.BluetoothSwitchPreferenceController
com.android.settings.connecteddevice.ConnectedDeviceGroupController
com.android.settings.connecteddevice.SavedDeviceGroupController
com.android.settings.datausage.DataUsageSummaryPreferenceController
com.android.settings.datetime.timezone.TimeZoneInfoPreferenceController
com.android.settings.fuelgauge.RestrictAppPreferenceController
com.android.settings.fuelgauge.batterysaver.AutoBatterySeekBarPreferenceController
com.android.settings.fuelgauge.batterysaver.BatterySaverButtonPreferenceController
com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController
com.android.settings.security.VisiblePatternProfilePreferenceController
com.android.settings.security.screenlock.LockScreenPreferenceController
com.android.settings.wifi.details.WifiMeteredPreferenceController

View File

@@ -1,49 +0,0 @@
/*
* 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 android.app.admin;
import android.annotation.NonNull;
/**
* Stub implementation of framework's PasswordMetrics for Robolectric tests. Otherwise Robolectric
* is throwing ClassNotFoundError.
*
* TODO: Remove this class when Robolectric supports O
*/
public class PasswordMetrics {
// Maximum allowed number of repeated or ordered characters in a sequence before we'll
// consider it a complex PIN/password.
public static final int MAX_ALLOWED_SEQUENCE = 3;
public int length = 0;
public int letters = 0;
public int upperCase = 0;
public int lowerCase = 0;
public int numeric = 0;
public int symbols = 0;
public int nonLetter = 0;
public static int maxLengthSequence(@NonNull String string) {
// Stub implementation
return 1;
}
public static PasswordMetrics computeForPassword(@NonNull String password) {
return new PasswordMetrics();
}
}

View File

@@ -1,54 +0,0 @@
/*
* 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 android.bluetooth;
/**
* A placeholder class to prevent ClassNotFound exceptions caused by lack of visibility.
*/
public class BluetoothCodecConfig {
public static final int SAMPLE_RATE_NONE = 0;
public static final int SAMPLE_RATE_48000 = 0x1 << 1;
public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000;
public static final int SOURCE_CODEC_TYPE_AAC = 1;
public static final int CODEC_PRIORITY_DEFAULT = 0;
public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000;
public static final int BITS_PER_SAMPLE_NONE = 0;
public static final int CHANNEL_MODE_NONE = 0;
public static final int BITS_PER_SAMPLE_24 = 0x1 << 1;
public static final int CHANNEL_MODE_STEREO = 0x1 << 1;
public int getSampleRate() {
return 0;
}
public int getCodecType() {
return 0;
}
public int getBitsPerSample() {
return 0;
}
public int getChannelMode() {
return 0;
}
public long getCodecSpecific1() {
return 0;
}
}

View File

@@ -1,36 +0,0 @@
/*
* 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 android.content.om;
import android.os.IBinder;
import java.util.List;
public interface IOverlayManager {
OverlayInfo getOverlayInfo(String packageName, int userId);
List getOverlayInfosForTarget(String targetPackageName, int userId);
boolean setEnabled(String packageName, boolean enabled, int userId);
boolean setEnabledExclusiveInCategory(String packageName, int userId);
class Stub {
public static IOverlayManager asInterface(IBinder b) {
return null;
}
}
}

View File

@@ -1,130 +0,0 @@
package android.net;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Objects;
/**
* Holds metadata about a discovered network scorer/recommendation application.
*
* TODO: delete this class once robolectric supports Android O
*/
public final class NetworkScorerAppData implements Parcelable {
/** UID of the scorer app. */
public final int packageUid;
private final ComponentName mRecommendationService;
/** User visible label in Settings for the recommendation service. */
private final String mRecommendationServiceLabel;
/**
* The {@link ComponentName} of the Activity to start before enabling the "connect to open
* wifi networks automatically" feature.
*/
private final ComponentName mEnableUseOpenWifiActivity;
/**
* The {@link android.app.NotificationChannel} ID used by {@link #mRecommendationService} to
* post open network notifications.
*/
private final String mNetworkAvailableNotificationChannelId;
public NetworkScorerAppData(int packageUid, ComponentName recommendationServiceComp,
String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity,
String networkAvailableNotificationChannelId) {
this.packageUid = packageUid;
this.mRecommendationService = recommendationServiceComp;
this.mRecommendationServiceLabel = recommendationServiceLabel;
this.mEnableUseOpenWifiActivity = enableUseOpenWifiActivity;
this.mNetworkAvailableNotificationChannelId = networkAvailableNotificationChannelId;
}
protected NetworkScorerAppData(Parcel in) {
packageUid = in.readInt();
mRecommendationService = ComponentName.readFromParcel(in);
mRecommendationServiceLabel = in.readString();
mEnableUseOpenWifiActivity = ComponentName.readFromParcel(in);
mNetworkAvailableNotificationChannelId = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(packageUid);
ComponentName.writeToParcel(mRecommendationService, dest);
dest.writeString(mRecommendationServiceLabel);
ComponentName.writeToParcel(mEnableUseOpenWifiActivity, dest);
dest.writeString(mNetworkAvailableNotificationChannelId);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<NetworkScorerAppData> CREATOR =
new Creator<NetworkScorerAppData>() {
@Override
public NetworkScorerAppData createFromParcel(Parcel in) {
return new NetworkScorerAppData(in);
}
@Override
public NetworkScorerAppData[] newArray(int size) {
return new NetworkScorerAppData[size];
}
};
public String getRecommendationServicePackageName() {
return mRecommendationService.getPackageName();
}
public ComponentName getRecommendationServiceComponent() {
return mRecommendationService;
}
@Nullable
public ComponentName getEnableUseOpenWifiActivity() {
return mEnableUseOpenWifiActivity;
}
@Nullable
public String getRecommendationServiceLabel() {
return mRecommendationServiceLabel;
}
@Nullable
public String getNetworkAvailableNotificationChannelId() {
return mNetworkAvailableNotificationChannelId;
}
@Override
public String toString() {
return "NetworkScorerAppData{" +
"packageUid=" + packageUid +
", mRecommendationService=" + mRecommendationService +
", mRecommendationServiceLabel=" + mRecommendationServiceLabel +
", mEnableUseOpenWifiActivity=" + mEnableUseOpenWifiActivity +
", mNetworkAvailableNotificationChannelId=" +
mNetworkAvailableNotificationChannelId +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NetworkScorerAppData that = (NetworkScorerAppData) o;
return packageUid == that.packageUid &&
Objects.equals(mRecommendationService, that.mRecommendationService) &&
Objects.equals(mRecommendationServiceLabel, that.mRecommendationServiceLabel) &&
Objects.equals(mEnableUseOpenWifiActivity, that.mEnableUseOpenWifiActivity) &&
Objects.equals(mNetworkAvailableNotificationChannelId,
that.mNetworkAvailableNotificationChannelId);
}
@Override
public int hashCode() {
return Objects.hash(packageUid, mRecommendationService, mRecommendationServiceLabel,
mEnableUseOpenWifiActivity, mNetworkAvailableNotificationChannelId);
}
}

View File

@@ -1,19 +0,0 @@
package android.print;
import android.annotation.NonNull;
import android.content.Context;
import android.content.Loader;
import android.printservice.PrintServiceInfo;
import com.android.internal.util.Preconditions;
import java.util.List;
/**
* A placeholder class to prevent ClassNotFound exceptions caused by lack of visibility.
*/
public class PrintServicesLoader extends Loader<List<PrintServiceInfo>> {
public PrintServicesLoader(@NonNull PrintManager printManager, @NonNull Context context,
int selectionFlags) {
super(Preconditions.checkNotNull(context));
}
}

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