Make Settings robotest work with tot Robolectric

Bug: 116278591
Test: make -j RunSettingsRoboTests
Change-Id: I32cb2fcf6094675f79d2fc24702ef6298a9691e4
This commit is contained in:
Fan Zhang
2018-10-11 15:37:36 -07:00
parent dd3feeb155
commit cdf284b732
140 changed files with 706 additions and 823 deletions

View File

@@ -23,7 +23,6 @@ public class AppLocationPermissionPreferenceController extends
@Override
public boolean isAvailable() {
return Settings.Global.getInt(mContext.getContentResolver(),
android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED, 1)
== 1;
Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED, 1) == 1;
}
}

View File

@@ -37,6 +37,7 @@ public class CarrierPreferenceController extends BasePreferenceController {
public CarrierPreferenceController(Context context, String key) {
super(context, key);
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
mCarrierConfigManager = new CarrierConfigManager(context);
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}

View File

@@ -59,6 +59,7 @@ public class MobileDataPreferenceController extends TogglePreferenceController
public MobileDataPreferenceController(Context context, String key) {
super(context, key);
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

View File

@@ -82,7 +82,7 @@ public class MobileNetworkUtils {
* Returns true if Wifi calling is enabled for at least one phone.
*/
public static boolean isWifiCallingEnabled(Context context) {
int phoneCount = TelephonyManager.from(context).getPhoneCount();
int phoneCount = context.getSystemService(TelephonyManager.class).getPhoneCount();
for (int i = 0; i < phoneCount; i++) {
if (isWifiCallingEnabled(context, i)) {
return true;
@@ -218,7 +218,7 @@ public class MobileNetworkUtils {
*/
public static void setMobileDataEnabled(Context context, int subId, boolean enabled,
boolean disableOtherSubscriptions) {
final TelephonyManager telephonyManager = TelephonyManager.from(context)
final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(subId);
final SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
@@ -230,7 +230,7 @@ public class MobileNetworkUtils {
if (subInfoList != null) {
for (SubscriptionInfo subInfo : subInfoList) {
if (subInfo.getSubscriptionId() != subId) {
TelephonyManager.from(context).createForSubscriptionId(
context.getSystemService(TelephonyManager.class).createForSubscriptionId(
subInfo.getSubscriptionId()).setDataEnabled(false);
}
}
@@ -245,7 +245,7 @@ public class MobileNetworkUtils {
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
return false;
}
final TelephonyManager telephonyManager = TelephonyManager.from(context)
final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(subId);
final PersistableBundle carrierConfig = context.getSystemService(
CarrierConfigManager.class).getConfigForSubId(subId);
@@ -307,7 +307,7 @@ public class MobileNetworkUtils {
}
private static boolean isGsmBasicOptions(Context context, int subId) {
final TelephonyManager telephonyManager = TelephonyManager.from(context)
final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(subId);
final PersistableBundle carrierConfig = context.getSystemService(
CarrierConfigManager.class).getConfigForSubId(subId);
@@ -329,7 +329,7 @@ public class MobileNetworkUtils {
* settings
*/
public static boolean isWorldMode(Context context, int subId) {
final TelephonyManager telephonyManager = TelephonyManager.from(context)
final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
.createForSubscriptionId(subId);
boolean worldModeOn = false;
final String configString = context.getString(R.string.config_world_mode);
@@ -392,7 +392,7 @@ public class MobileNetworkUtils {
Context con = context.createPackageContext("com.android.systemui", 0);
int id = con.getResources().getIdentifier("config_show4GForLTE",
"bool", "com.android.systemui");
return con.getResources().getBoolean(id);
return con.getResources().getBoolean(id);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "NameNotFoundException for show4GFotLTE");
return false;
@@ -404,7 +404,7 @@ public class MobileNetworkUtils {
*/
public static boolean isTdscdmaSupported(Context context, int subId) {
return isTdscdmaSupported(context,
TelephonyManager.from(context).createForSubscriptionId(subId));
context.getSystemService(TelephonyManager.class).createForSubscriptionId(subId));
}
//TODO(b/117651939): move it to telephony

View File

@@ -59,6 +59,7 @@ public class RoamingPreferenceController extends TogglePreferenceController impl
public RoamingPreferenceController(Context context, String key) {
super(context, key);
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;

View File

@@ -22,6 +22,7 @@ import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.preference.Preference;
@@ -48,6 +49,7 @@ public abstract class CdmaBasePreferenceController extends BasePreferenceControl
public CdmaBasePreferenceController(Context context, String key) {
super(context, key);
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
}

View File

@@ -28,7 +28,6 @@ import android.os.UserManager;
import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -83,24 +82,6 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
return true;
}
// finds the preference recursively and removes it from its parent
private void findAndRemovePreference(PreferenceGroup prefGroup, String key) {
final int preferenceCount = prefGroup.getPreferenceCount();
for (int i = preferenceCount - 1; i >= 0; i--) {
final Preference preference = prefGroup.getPreference(i);
final String curKey = preference.getKey();
if (curKey != null && curKey.equals(key)) {
mPreference = preference;
prefGroup.removePreference(preference);
}
if (preference instanceof PreferenceGroup) {
findAndRemovePreference((PreferenceGroup) preference, key);
}
}
}
protected void onResume(NotificationBackend.AppRow appRow,
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
RestrictedLockUtils.EnforcedAdmin admin) {

View File

@@ -226,7 +226,7 @@ class SliceDataConverter {
SliceBuilderUtils.getPreferenceController(mContext, xmlSlice);
// Only add pre-approved Slices available on the device.
if (controller.isAvailable() && controller.isSliceable()) {
if (controller.isSliceable() && controller.isAvailable()) {
xmlSliceData.add(xmlSlice);
}
}

View File

@@ -66,12 +66,11 @@ class SlicesIndexer implements Runnable {
return;
}
SQLiteDatabase database = mHelper.getWritableDatabase();
final SQLiteDatabase database = mHelper.getWritableDatabase();
long startTime = System.currentTimeMillis();
database.beginTransaction();
try {
long startTime = System.currentTimeMillis();
database.beginTransaction();
mHelper.reconstruct(mHelper.getWritableDatabase());
List<SliceData> indexData = getSliceData();
insertSliceData(database, indexData);
@@ -85,6 +84,7 @@ class SlicesIndexer implements Runnable {
} finally {
database.endTransaction();
}
database.close();
}
@VisibleForTesting

View File

@@ -68,7 +68,7 @@ public class WifiWakeupPreferenceController extends AbstractPreferenceController
@Override
public boolean isAvailable() {
return true;
return true;
}
@Override
@@ -108,8 +108,8 @@ public class WifiWakeupPreferenceController extends AbstractPreferenceController
final SwitchPreference enableWifiWakeup = (SwitchPreference) preference;
enableWifiWakeup.setChecked(getWifiWakeupEnabled()
&& getWifiScanningEnabled()
&& mLocationManager.isLocationEnabled());
&& getWifiScanningEnabled()
&& mLocationManager.isLocationEnabled());
if (!mLocationManager.isLocationEnabled()) {
preference.setSummary(getNoLocationSummary());
} else {
@@ -117,7 +117,8 @@ public class WifiWakeupPreferenceController extends AbstractPreferenceController
}
}
@VisibleForTesting CharSequence getNoLocationSummary() {
@VisibleForTesting
CharSequence getNoLocationSummary() {
AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo("link", null);
CharSequence locationText = mContext.getText(R.string.wifi_wakeup_summary_no_location);
return AnnotationSpan.linkify(locationText, linkInfo);