Snap for 5145130 from 41b06fd48e to qt-release

Change-Id: I32dcc216b27b3c57ab669551c86ef9e72d082ea6
This commit is contained in:
android-build-team Robot
2018-11-22 04:09:19 +00:00
48 changed files with 714 additions and 302 deletions

View File

@@ -1,18 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="4">
<issue
id="LintError"
severity="Error"
message="No `.class` files were found in project &quot;.&quot;, so none of the classfile based checks could be run. Does the project need to be built first?"
category="Lint"
priority="10"
summary="Lint Failure"
explanation="This issue type represents a problem running lint itself. Examples include failure to find bytecode for source files (which means certain detectors could not be run), parsing errors in lint configuration files, etc.&#xA;These errors are not errors in your own code, but they are shown to make it clear that some checks were not completed.">
<location
file="."/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
@@ -2553,7 +2541,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rXC/strings.xml"
line="2530"
line="2533"
column="168"/>
</issue>
@@ -2569,7 +2557,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rAU/strings.xml"
line="2531"
line="2534"
column="64"/>
</issue>
@@ -2585,7 +2573,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rCA/strings.xml"
line="2531"
line="2534"
column="64"/>
</issue>
@@ -2601,7 +2589,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rGB/strings.xml"
line="2531"
line="2534"
column="64"/>
</issue>
@@ -2617,7 +2605,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rIN/strings.xml"
line="2531"
line="2534"
column="64"/>
</issue>
@@ -2633,7 +2621,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/strings.xml"
line="5886"
line="5902"
column="36"/>
</issue>
@@ -2665,7 +2653,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
line="443"
line="448"
column="44"/>
</issue>
@@ -2681,7 +2669,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
line="449"
line="454"
column="44"/>
</issue>
@@ -2697,7 +2685,7 @@
errorLine2=" ^">
<location
file="res/values/styles.xml"
line="450"
line="455"
column="44"/>
</issue>
@@ -2761,7 +2749,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="91"
line="90"
column="47"/>
</issue>
@@ -2777,7 +2765,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="91"
line="90"
column="47"/>
</issue>
@@ -2793,7 +2781,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="97"
line="96"
column="40"/>
</issue>
@@ -2809,7 +2797,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="97"
line="96"
column="40"/>
</issue>
@@ -2825,7 +2813,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="160"
line="159"
column="45"/>
</issue>
@@ -2841,7 +2829,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="161"
line="160"
column="49"/>
</issue>
@@ -2857,7 +2845,7 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="169"
line="168"
column="45"/>
</issue>
@@ -2873,10 +2861,58 @@
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="170"
line="169"
column="49"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item name=&quot;batteryGoodColor&quot;>@color/battery_good_color_light&lt;/item>"
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="185"
column="39"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item name=&quot;batteryMaybeColor&quot;>@color/battery_maybe_color_light&lt;/item>"
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="186"
column="40"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" &lt;item name=&quot;batteryBadColor&quot;>@color/battery_bad_color_light&lt;/item>"
errorLine2=" ^">
<location
file="res/values/themes.xml"
line="187"
column="38"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"

View File

@@ -21,5 +21,5 @@
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M17.92,10.02C17.45,7.18 14.97,5 12,5C9.82,5 7.83,6.18 6.78,8.06C4.09,8.41 2,10.74 2,13.5C2,16.53 4.47,19 7.5,19h10c2.48,0 4.5,-2.02 4.5,-4.5C22,12.16 20.21,10.23 17.92,10.02zM17.5,17h-10C5.57,17 4,15.43 4,13.5c0,-1.89 1.54,-3.46 3.44,-3.49L8.08,10l0.26,-0.59C8.97,7.94 10.41,7 12,7c2.21,0 4,1.79 4,4v1h1.5c1.38,0 2.5,1.12 2.5,2.5S18.88,17 17.5,17zM14.09,11.09l1.41,1.41l-2.79,2.79L12,16l-0.71,-0.71L8.5,12.5l1.41,-1.41L11,12.17V9.5h2v2.67L14.09,11.09z"/>
android:pathData="M17.92,10.02C17.45,7.18 14.97,5 12,5C9.82,5 7.83,6.18 6.78,8.06C4.09,8.41 2,10.74 2,13.5C2,16.53 4.47,19 7.5,19h10c2.48,0 4.5,-2.02 4.5,-4.5C22,12.16 20.21,10.23 17.92,10.02zM17.5,17h-10C5.57,17 4,15.43 4,13.5c0,-1.89 1.54,-3.46 3.44,-3.49L8.08,10l0.26,-0.59C8.97,7.94 10.41,7 12,7c2.21,0 4,1.79 4,4v1h1.5c1.38,0 2.5,1.12 2.5,2.5S18.88,17 17.5,17zM9.91,14.41L8.5,13l2.79,-2.79L12,9.5l0.71,0.71L15.5,13l-1.41,1.41L13,13.33V16h-2v-2.67L9.91,14.41z"/>
</vector>

View File

@@ -180,6 +180,11 @@
<!-- action bar, needed for search bar icon tinting -->
<item name="android:actionBarTheme">@*android:style/ThemeOverlay.DeviceDefault.ActionBar.Accent</item>
<!-- For battery status icons in -->
<item name="batteryGoodColor">@color/battery_good_color_light</item>
<item name="batteryMaybeColor">@color/battery_maybe_color_light</item>
<item name="batteryBadColor">@color/battery_bad_color_light</item>
</style>
<style name="Theme.Settings.Home" parent="Theme.Settings.HomeBase">

View File

@@ -94,8 +94,7 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
void finishIfAccountMissing() {
final Context context = getContext();
final UserManager um = context.getSystemService(UserManager.class);
final AccountManager accountManager = (AccountManager) context.getSystemService(
AccountManager.class);
final AccountManager accountManager = context.getSystemService(AccountManager.class);
for (UserHandle userHandle : um.getUserProfiles()) {
for (Account account : accountManager.getAccountsAsUser(userHandle.getIdentifier())) {
if (account.equals(mAccount)) {

View File

@@ -24,7 +24,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
@@ -37,9 +36,7 @@ public class LayoutPreference extends Preference {
private final View.OnClickListener mClickListener = v -> performClick(v);
private boolean mAllowDividerAbove;
private boolean mAllowDividerBelow;
@VisibleForTesting
View mRootView;
private View mRootView;
public LayoutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -116,4 +113,11 @@ public class LayoutPreference extends Preference {
return mRootView.findViewById(id);
}
public void setAllowDividerBelow(boolean allowed) {
mAllowDividerBelow = allowed;
}
public boolean isAllowDividerBelow() {
return mAllowDividerBelow;
}
}

View File

@@ -128,7 +128,7 @@ public class ImeiInfoDialogController {
private SubscriptionInfo getSubscriptionInfo(Context context, int slotId) {
final List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(context)
.getActiveSubscriptionInfoList();
if (subscriptionInfoList == null) {
if (subscriptionInfoList == null || subscriptionInfoList.isEmpty()) {
return null;
}

View File

@@ -26,6 +26,7 @@ import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting;
import com.android.settings.Utils;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -115,6 +116,6 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER);
}
}
BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
}
}

View File

@@ -21,6 +21,7 @@ import static android.provider.SettingsSlicesContract.KEY_WIFI;
import android.annotation.Nullable;
import com.android.settings.homepage.contextualcards.deviceinfo.BatterySlice;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import com.android.settings.homepage.contextualcards.slices.ConnectedDeviceSlice;
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
import com.android.settings.intelligence.ContextualCardProto.ContextualCard;
@@ -61,11 +62,18 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
.setCardName(LowStorageSlice.PATH_LOW_STORAGE)
.setCardCategory(ContextualCard.Category.IMPORTANT)
.build();
final ContextualCard batteryFixCard =
ContextualCard.newBuilder()
.setSliceUri(BatteryFixSlice.BATTERY_FIX_URI.toString())
.setCardName(BatteryFixSlice.PATH_BATTERY_FIX)
.setCardCategory(ContextualCard.Category.IMPORTANT)
.build();
final ContextualCardList cards = ContextualCardList.newBuilder()
.addCard(wifiCard)
.addCard(batteryInfoCard)
.addCard(connectedDeviceCard)
.addCard(lowStorageCard)
.addCard(batteryFixCard)
.build();
return cards;

View File

@@ -131,7 +131,7 @@ public class DeviceInfoSlice implements CustomSliceable {
SubscriptionInfo getFirstSubscriptionInfo() {
final List<SubscriptionInfo> subscriptionInfoList =
mSubscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfoList == null) {
if (subscriptionInfoList == null || subscriptionInfoList.isEmpty()) {
return null;
}
return subscriptionInfoList.get(0);

View File

@@ -0,0 +1,224 @@
/*
* 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.homepage.contextualcards.slices;
import static android.content.Context.MODE_PRIVATE;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
import androidx.slice.builders.ListBuilder;
import androidx.slice.builders.ListBuilder.RowBuilder;
import androidx.slice.builders.SliceAction;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.R;
import com.android.settings.SubSettings;
import com.android.settings.Utils;
import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.slices.CustomSliceable;
import com.android.settings.slices.SettingsSliceProvider;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settings.slices.SliceBuilderUtils;
import com.android.settingslib.utils.ThreadUtils;
import java.util.List;
public class BatteryFixSlice implements CustomSliceable {
/**
* Unique name of Battery Fix Slice.
*/
public static final String PATH_BATTERY_FIX = "battery_fix";
/**
* Uri for Battery Fix Slice.
*/
public static final Uri BATTERY_FIX_URI = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendPath(PATH_BATTERY_FIX)
.build();
@VisibleForTesting
static final String PREFS = "battery_fix_prefs";
@VisibleForTesting
static final String KEY_CURRENT_TIPS_TYPE = "current_tip_type";
private static final String TAG = "BatteryFixSlice";
private final Context mContext;
public BatteryFixSlice(Context context) {
mContext = context;
}
@Override
public Uri getUri() {
return BATTERY_FIX_URI;
}
/**
* Return a Slice bound to {@link #BATTERY_FIX_URI}.
*/
@Override
public Slice getSlice() {
IconCompat icon;
SliceAction primaryAction;
Slice slice = null;
// TipType.SUMMARY is battery good
if (readBatteryTipAvailabilityCache(mContext) == BatteryTip.TipType.SUMMARY) {
return null;
}
final List<BatteryTip> batteryTips = SliceBackgroundWorker.getInstance(mContext,
this).getResults();
if (batteryTips != null) {
for (BatteryTip batteryTip : batteryTips) {
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
icon = IconCompat.createWithResource(mContext, batteryTip.getIconId());
primaryAction = new SliceAction(getPrimaryAction(),
icon,
batteryTip.getTitle(mContext));
slice = new ListBuilder(mContext, BATTERY_FIX_URI, ListBuilder.INFINITY)
.setAccentColor(Utils.getColorAccentDefaultColor(mContext))
.addRow(new RowBuilder()
.setTitle(batteryTip.getTitle(mContext))
.setSubtitle(batteryTip.getSummary(mContext))
.setPrimaryAction(primaryAction)
.addEndItem(icon, ListBuilder.ICON_IMAGE))
.build();
break;
}
}
} else {
icon = IconCompat.createWithResource(mContext,
R.drawable.ic_battery_status_good_24dp);
final String title = mContext.getString(R.string.power_usage_summary_title);
primaryAction = new SliceAction(getPrimaryAction(), icon, title);
slice = new ListBuilder(mContext, BATTERY_FIX_URI, ListBuilder.INFINITY)
.setAccentColor(Utils.getColorAccentDefaultColor(mContext))
.addRow(new RowBuilder()
.setTitle(title)
.setPrimaryAction(primaryAction)
.addEndItem(icon, ListBuilder.ICON_IMAGE))
.build();
}
return slice;
}
@Override
public Intent getIntent() {
final String screenTitle = mContext.getText(R.string.power_usage_summary_title)
.toString();
final Uri contentUri = new Uri.Builder().appendPath(PATH_BATTERY_FIX).build();
return SliceBuilderUtils.buildSearchResultPageIntent(mContext,
PowerUsageSummary.class.getName(), PATH_BATTERY_FIX,
screenTitle,
MetricsProto.MetricsEvent.SLICE)
.setClassName(mContext.getPackageName(), SubSettings.class.getName())
.setData(contentUri);
}
@Override
public void onNotifyChange(Intent intent) {
}
@Override
public Class getBackgroundWorkerClass() {
return BatteryTipWorker.class;
}
private PendingIntent getPrimaryAction() {
final Intent intent = getIntent();
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
}
// TODO(b/114807643): we should find a better way to get current battery tip type quickly
// Now we save battery tip type to shared preference when battery level changes
public static void updateBatteryTipAvailabilityCache(Context context) {
ThreadUtils.postOnBackgroundThread(() -> {
refreshBatteryTips(context);
});
}
@VisibleForTesting
static int readBatteryTipAvailabilityCache(Context context) {
final SharedPreferences prefs = context.getSharedPreferences(PREFS, MODE_PRIVATE);
return prefs.getInt(KEY_CURRENT_TIPS_TYPE, BatteryTip.TipType.SUMMARY);
}
@WorkerThread
private static List<BatteryTip> refreshBatteryTips(Context context) {
final BatteryStatsHelperLoader statsLoader = new BatteryStatsHelperLoader(context);
final BatteryStatsHelper statsHelper = statsLoader.loadInBackground();
final BatteryTipLoader loader = new BatteryTipLoader(context, statsHelper);
final List<BatteryTip> batteryTips = loader.loadInBackground();
for (BatteryTip batteryTip : batteryTips) {
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
SharedPreferences.Editor editor = context.getSharedPreferences(PREFS,
MODE_PRIVATE).edit();
editor.putInt(KEY_CURRENT_TIPS_TYPE, batteryTip.getType());
editor.apply();
break;
}
}
return batteryTips;
}
public static class BatteryTipWorker extends SliceBackgroundWorker<BatteryTip> {
private final Context mContext;
public BatteryTipWorker(Context context, Uri uri) {
super(context, uri);
mContext = context;
}
@Override
protected void onSlicePinned() {
ThreadUtils.postOnBackgroundThread(() -> {
final List<BatteryTip> batteryTips = refreshBatteryTips(mContext);
updateResults(batteryTips);
});
}
@Override
protected void onSliceUnpinned() {
}
@Override
public void close() {
}
}
}

View File

@@ -17,6 +17,10 @@
package com.android.settings.network.telephony;
import android.content.Context;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
@@ -62,10 +66,31 @@ public class CarrierPreferenceController extends BasePreferenceController {
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (getPreferenceKey().equals(preference.getKey())) {
//TODO(b/117651939): start carrier settings activity
final Intent carrierSettingsIntent = getCarrierSettingsActivityIntent(mSubId);
if (carrierSettingsIntent != null) {
mContext.startActivity(carrierSettingsIntent);
}
return true;
}
return false;
}
private Intent getCarrierSettingsActivityIntent(int subId) {
final PersistableBundle config = mCarrierConfigManager.getConfigForSubId(subId);
final ComponentName cn = ComponentName.unflattenFromString(
config == null ? "" : config.getString(
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
"" /* default value */));
if (cn == null) return null;
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PackageManager pm = mContext.getPackageManager();
final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0 /* flags */);
return resolveInfo != null ? intent : null;
}
}

View File

@@ -20,10 +20,13 @@ import android.content.Context;
import android.net.Uri;
import android.util.ArrayMap;
import androidx.annotation.VisibleForTesting;
import com.android.settings.homepage.contextualcards.deviceinfo.BatterySlice;
import com.android.settings.homepage.contextualcards.deviceinfo.DataUsageSlice;
import com.android.settings.homepage.contextualcards.deviceinfo.DeviceInfoSlice;
import com.android.settings.homepage.contextualcards.deviceinfo.StorageSlice;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import com.android.settings.homepage.contextualcards.slices.ConnectedDeviceSlice;
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
import com.android.settings.wifi.WifiSlice;
@@ -34,13 +37,11 @@ import java.util.WeakHashMap;
/**
* Manages custom {@link androidx.slice.Slice Slices}, which are all Slices not backed by
* preferences.
* <p>
* By default, all Slices in Settings should be built by a
* </p>
*/
public class CustomSliceManager {
protected final Map<Uri, Class<? extends CustomSliceable>> mUriMap;
@VisibleForTesting
final Map<Uri, Class<? extends CustomSliceable>> mUriMap;
private final Context mContext;
private final Map<Uri, CustomSliceable> mSliceableCache;
@@ -107,5 +108,6 @@ public class CustomSliceManager {
mUriMap.put(BatterySlice.BATTERY_CARD_URI, BatterySlice.class);
mUriMap.put(ConnectedDeviceSlice.CONNECTED_DEVICE_URI, ConnectedDeviceSlice.class);
mUriMap.put(LowStorageSlice.LOW_STORAGE_URI, LowStorageSlice.class);
mUriMap.put(BatteryFixSlice.BATTERY_FIX_URI, BatteryFixSlice.class);
}
}

View File

@@ -238,6 +238,7 @@ public class EntityHeaderController {
pref.setOrder(-1000);
pref.setSelectable(false);
pref.setKey(PREF_KEY_APP_HEADER);
pref.setAllowDividerBelow(true);
return pref;
}

View File

@@ -298,18 +298,30 @@ public class QrCamera extends Handler {
}
}
/** Get best preview size from the list of camera supported preview sizes. Compares the
* preview size and aspect ratio to choose the best one. */
private Size getBestPreviewSize(Camera.Parameters parameters) {
final double minRatioDiffPercent = 0.1;
final Size windowSize = mScannerCallback.getViewSize();
final double winRatio = getRatio(windowSize.getWidth(), windowSize.getHeight());
double bestChoiceRatio = 0;
Size bestChoice = new Size(0, 0);
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width <= windowSize.getWidth() && size.height <= windowSize.getHeight()) {
double ratio = getRatio(size.width, size.height);
if (size.height * size.width > bestChoice.getWidth() * bestChoice.getHeight()
&& (Math.abs(bestChoiceRatio - winRatio) / winRatio > minRatioDiffPercent
|| Math.abs(ratio - winRatio) / winRatio <= minRatioDiffPercent)) {
bestChoice = new Size(size.width, size.height);
break;
bestChoiceRatio = getRatio(size.width, size.height);
}
}
return bestChoice;
}
private double getRatio(double x, double y) {
return (x < y) ? x / y : y / x;
}
@VisibleForTesting
protected void decodeImage(BinaryBitmap image) {
Result qrCode = null;

View File

@@ -166,11 +166,11 @@ public class AccessibilityHearingAidPreferenceControllerTest {
mPreferenceController.setPreference(mHearingAidPreference);
//not call registerReceiver()
mPreferenceController.onResume();
verify(mContext, never()).registerReceiver((BroadcastReceiver) any(), (IntentFilter) any());
verify(mContext, never()).registerReceiver(any(), any());
//not call unregisterReceiver()
mPreferenceController.onPause();
verify(mContext, never()).unregisterReceiver((BroadcastReceiver) any());
verify(mContext, never()).unregisterReceiver(any());
}
private void setupBluetoothEnvironment() {
@@ -185,9 +185,9 @@ public class AccessibilityHearingAidPreferenceControllerTest {
private void setupHearingAidEnvironment() {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
mShadowBluetoothAdapter.enable();
mBluetoothAdapter.enable();
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME);

View File

@@ -166,11 +166,11 @@ public class AccountDetailDashboardFragmentTest {
public void onResume_accountMissing_shouldFinish() {
ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class));
ShadowAccountManager acctMgr = Shadow.extract(
ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class));
userManager.addProfile(new UserInfo(1, null, 0));
acctMgr.addAccountForUser(1, new Account("test@test.com", "com.test"));
userManager.addUserProfile(new UserHandle(1));
accountManager.addAccountForUser(1, new Account("test@test.com", "com.test"));
mFragment.finishIfAccountMissing();
verify(mFragment).finish();
@@ -180,11 +180,11 @@ public class AccountDetailDashboardFragmentTest {
public void onResume_accountPresentOneProfile_shouldNotFinish() {
ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class));
ShadowAccountManager acctMgr = Shadow.extract(
ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class));
userManager.addProfile(new UserInfo(1, null, 0));
acctMgr.addAccountForUser(1, mFragment.mAccount);
userManager.addUserProfile(new UserHandle(1));
accountManager.addAccountForUser(1, mFragment.mAccount);
mFragment.finishIfAccountMissing();
verify(mFragment, never()).finish();
@@ -194,13 +194,13 @@ public class AccountDetailDashboardFragmentTest {
public void onResume_accountPresentTwoProfiles_shouldNotFinish() {
ShadowUserManager userManager = Shadow.extract(
mContext.getSystemService(UserManager.class));
ShadowAccountManager acctMgr = Shadow.extract(
ShadowAccountManager accountManager = Shadow.extract(
mContext.getSystemService(AccountManager.class));
userManager.addProfile(new UserInfo(1, null, 0));
userManager.addProfile(new UserInfo(2, null, 0));
acctMgr.addAccountForUser(1, new Account("test@test.com", "com.test"));
acctMgr.addAccountForUser(2, mFragment.mAccount);
userManager.addUserProfile(new UserHandle(1));
userManager.addUserProfile(new UserHandle(2));
accountManager.addAccountForUser(1, new Account("test@test.com", "com.test"));
accountManager.addAccountForUser(2, mFragment.mAccount);
mFragment.finishIfAccountMissing();
verify(mFragment, never()).finish();

View File

@@ -40,6 +40,7 @@ import android.os.Bundle;
import android.widget.ImageView;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -99,7 +100,11 @@ public class AvatarViewMixinTest {
}
@Test
@Config(qualifiers = "mcc999")
@Config(qualifiers = "mcc999",
shadows = {
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void onStart_useMockAvatarViewMixin_shouldBeExecuted() {
final AvatarViewMixin mockAvatar = spy(new AvatarViewMixin(mActivity, mImageView));
@@ -141,8 +146,7 @@ public class AvatarViewMixinTest {
@Test
public void callWithGetAccountAvatarMethod_useDummyData_shouldReturnAccountNameAndAvatar() {
final ShadowContentResolver shadowContentResolver = Shadow.extract(
mContext.getContentResolver());
final ContentResolver contentResolver = mContext.getContentResolver();
final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(
DUMMY_AUTHORITY).build();
final ContentProvider mockContentProvider = mock(ContentProvider.class);
@@ -156,8 +160,7 @@ public class AvatarViewMixinTest {
doReturn(bundle).when(mockContentProvider).call(anyString(), anyString(),
any(Bundle.class));
final Bundle expectBundle = shadowContentResolver.call(uri, METHOD_GET_ACCOUNT_AVATAR,
null /* arg */, null /* extras */);
contentResolver.call(uri, METHOD_GET_ACCOUNT_AVATAR, null /* arg */, null /* extras */);
final Object object = bundle.getParcelable("account_avatar");
assertThat(object instanceof Bitmap).isTrue();

View File

@@ -83,4 +83,11 @@ public class LayoutPreferenceTest {
assertThat(mPreference.findViewById(R.id.button1).isEnabled()).isFalse();
assertThat(mPreference.findViewById(R.id.button2).isEnabled()).isTrue();
}
@Test
public void allowDividerBelow_shouldSaveCorrectDividerStatus() {
mPreference.setAllowDividerBelow(true);
assertThat(mPreference.isAllowDividerBelow()).isTrue();
}
}

View File

@@ -37,7 +37,6 @@ import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -23,7 +23,6 @@ import static org.robolectric.RuntimeEnvironment.application;
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.view.View;
import android.widget.Button;
@@ -36,8 +35,6 @@ import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.Shadows;
import org.robolectric.android.controller.ActivityController;
@@ -49,20 +46,14 @@ import org.robolectric.shadows.ShadowKeyguardManager;
@Config(shadows = {ShadowLockPatternUtils.class, ShadowUserManager.class})
public class FingerprintSuggestionActivityTest {
@Mock
private UserInfo mUserInfo;
private ActivityController<FingerprintSuggestionActivity> mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
final Intent intent = new Intent();
mController = Robolectric.buildActivity(FingerprintSuggestionActivity.class, intent);
ShadowUserManager.getShadow().setUserInfo(0, mUserInfo);
}
@Test

View File

@@ -23,7 +23,6 @@ import static org.robolectric.RuntimeEnvironment.application;
import android.app.KeyguardManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.view.View;
import android.widget.Button;
@@ -43,8 +42,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.Shadows;
import org.robolectric.android.controller.ActivityController;
@@ -62,15 +59,10 @@ import org.robolectric.shadows.ShadowKeyguardManager;
})
public class SetupFingerprintEnrollIntroductionTest {
@Mock
private UserInfo mUserInfo;
private ActivityController<SetupFingerprintEnrollIntroduction> mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Shadows.shadowOf(application.getPackageManager())
.setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);
@@ -78,8 +70,6 @@ public class SetupFingerprintEnrollIntroductionTest {
final Intent intent = new Intent();
mController = Robolectric.buildActivity(SetupFingerprintEnrollIntroduction.class, intent);
ShadowUserManager.getShadow().setUserInfo(0, mUserInfo);
}
@After

View File

@@ -15,7 +15,7 @@
*/
package com.android.settings.bluetooth;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -64,7 +64,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
private Context mContext;
private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater;
private Collection<CachedBluetoothDevice> mCachedDevices;
private ShadowAudioManager mShadowAudioManager;
private AudioManager mAudioManager;
private BluetoothDevicePreference mPreference;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager;
@@ -73,14 +73,13 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mShadowAudioManager = ShadowAudioManager.getShadow();
mContext = RuntimeEnvironment.application;
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter.setEnabled(true);
mContext = RuntimeEnvironment.application;
mShadowCachedBluetoothDeviceManager = Shadow.extract(
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
mCachedDevices =
new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
mCachedDevices = new ArrayList<>();
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
doReturn(mContext).when(mDashboardFragment).getContext();
@@ -96,7 +95,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onAudioModeChanged_hfpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -109,7 +108,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onAudioModeChanged_hfpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -122,7 +121,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onAudioModeChanged_a2dpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -135,7 +134,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -148,7 +147,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -161,7 +160,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -174,7 +173,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -187,7 +186,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -201,7 +200,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_addPreference()
{
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
@@ -214,7 +213,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);

View File

@@ -18,8 +18,8 @@ package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -72,8 +72,8 @@ public class BluetoothDeviceRenamePreferenceControllerTest {
mContext = spy(RuntimeEnvironment.application);
mPreference = new Preference(mContext);
mPreference.setKey(PREF_KEY);
mBluetoothAdapter = ShadowBluetoothAdapter.getDefaultAdapter();
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mController = spy(new BluetoothDeviceRenamePreferenceController(mContext, PREF_KEY));
mController.setFragment(mFragment);

View File

@@ -66,7 +66,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
private Context mContext;
private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
private Collection<CachedBluetoothDevice> mCachedDevices;
private ShadowAudioManager mShadowAudioManager;
private AudioManager mAudioManager;
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager;
@@ -74,15 +74,14 @@ public class ConnectedBluetoothDeviceUpdaterTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mShadowAudioManager = ShadowAudioManager.getShadow();
mContext = RuntimeEnvironment.application;
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
mShadowBluetoothAdapter.setEnabled(true);
mContext = RuntimeEnvironment.application;
mShadowCachedBluetoothDeviceManager = Shadow.extract(
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
doReturn(mContext).when(mDashboardFragment).getContext();
mCachedDevices =
new ArrayList<CachedBluetoothDevice>(new ArrayList<CachedBluetoothDevice>());
mCachedDevices = new ArrayList<>();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
@@ -95,7 +94,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onAudioModeChanged_hfpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -108,7 +107,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onAudioModeChanged_hfpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -121,7 +120,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -134,7 +133,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onAudioModeChanged_a2dpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -147,7 +146,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -160,7 +159,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
@@ -173,7 +172,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -186,7 +185,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
@@ -200,7 +199,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_inCall_removePreference()
{
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);
@@ -214,7 +213,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
@Test
public void onProfileConnectionStateChanged_hearingAidDeviceConnected_notInCall_removePreference
() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true);

View File

@@ -23,6 +23,7 @@ import static org.mockito.Mockito.spy;
import android.content.ContentResolver;
import android.content.Context;
import android.nfc.NfcAdapter;
import android.provider.Settings;
import com.android.settings.R;
@@ -60,7 +61,7 @@ public class AdvancedConnectedDeviceControllerTest {
mContentResolver = mContext.getContentResolver();
mNfcController = new NfcPreferenceController(mContext,
NfcPreferenceController.KEY_TOGGLE_NFC);
mShadowNfcAdapter = Shadows.shadowOf(ShadowNfcAdapter.getNfcAdapter(mContext));
mShadowNfcAdapter = Shadows.shadowOf(NfcAdapter.getNfcAdapter(mContext));
}
@Test
@@ -68,8 +69,7 @@ public class AdvancedConnectedDeviceControllerTest {
AdvancedConnectedDeviceController controller =
new AdvancedConnectedDeviceController(mContext, KEY);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
AVAILABLE);
assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test

View File

@@ -56,10 +56,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {
ShadowAudioManager.class,
ShadowBluetoothUtils.class}
)
@Config(shadows = {ShadowAudioManager.class, ShadowBluetoothUtils.class})
public class AvailableMediaDeviceGroupControllerTest {
private static final String PREFERENCE_KEY_1 = "pref_key_1";
@@ -84,7 +81,7 @@ public class AvailableMediaDeviceGroupControllerTest {
private Preference mPreference;
private AvailableMediaDeviceGroupController mAvailableMediaDeviceGroupController;
private LocalBluetoothManager mLocalBluetoothManager;
private ShadowAudioManager mShadowAudioManager;
private AudioManager mAudioManager;
@Before
public void setUp() {
@@ -101,7 +98,7 @@ public class AvailableMediaDeviceGroupControllerTest {
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
mShadowAudioManager = ShadowAudioManager.getShadow();
mAudioManager = mContext.getSystemService(AudioManager.class);
doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager();
mAvailableMediaDeviceGroupController = new AvailableMediaDeviceGroupController(mContext);
@@ -184,7 +181,7 @@ public class AvailableMediaDeviceGroupControllerTest {
@Test
public void setTitle_inCallState_showCallStateTitle() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAvailableMediaDeviceGroupController.onAudioModeChanged();
assertThat(mPreferenceGroup.getTitle()).isEqualTo(
@@ -193,7 +190,7 @@ public class AvailableMediaDeviceGroupControllerTest {
@Test
public void setTitle_notInCallState_showMediaStateTitle() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAvailableMediaDeviceGroupController.onAudioModeChanged();
assertThat(mPreferenceGroup.getTitle()).isEqualTo(

View File

@@ -365,6 +365,8 @@ public class DashboardFeatureProviderImplTest {
@Test
public void openTileIntent_profileSelectionDialog_shouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
@@ -379,6 +381,8 @@ public class DashboardFeatureProviderImplTest {
@Test
public void openTileIntent_profileSelectionDialog_explicitMetadataShouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_ALL);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>();
@@ -394,6 +398,8 @@ public class DashboardFeatureProviderImplTest {
@Test
public void openTileIntent_profileSelectionDialog_shouldNotShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_PRIMARY);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>();

View File

@@ -16,7 +16,6 @@
package com.android.settings.development;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static com.google.common.truth.Truth.assertThat;
@@ -34,7 +33,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
@RunWith(SettingsRobolectricTestRunner.class)
public final class CbrsDataSwitchPreferenceControllerTest {

View File

@@ -41,6 +41,7 @@ import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -82,6 +83,7 @@ public class DevelopmentTilePreferenceControllerTest {
}
@Test
@Ignore("b/119829673")
public void display_hasTileService_shouldDisplay() {
final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE)
.setPackage(mContext.getPackageName());

View File

@@ -155,6 +155,7 @@ public class ActionDisabledByAdminDialogHelperTest {
dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
dpmShadow.setIsAdminActiveAsUser(true);
userManagerShadow.addProfile(new UserInfo(123, null, 0));
userManagerShadow.addUserProfile(new UserHandle(123));
ShadowProcess.setMyUid(Process.SYSTEM_UID);
mHelper.setAdminSupportDetails(mActivity, view, admin);

View File

@@ -33,6 +33,7 @@ import android.os.BatteryManager;
import android.os.PowerManager;
import com.android.settings.Utils;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -42,6 +43,11 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
@RunWith(SettingsRobolectricTestRunner.class)
public class BatteryBroadcastReceiverTest {
@@ -74,6 +80,10 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testOnReceive_batteryLevelChanged_dataUpdated() {
mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
@@ -85,6 +95,10 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testOnReceive_powerSaveModeChanged_listenerInvoked() {
mBatteryBroadcastReceiver.onReceive(mContext,
new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
@@ -93,6 +107,10 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
final String batteryStatus =
@@ -108,6 +126,10 @@ public class BatteryBroadcastReceiverTest {
}
@Test
@Config(shadows = {
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
BatteryFixSliceTest.ShadowBatteryTipLoader.class
})
public void testRegister_updateBatteryStatus() {
doReturn(mChargingIntent).when(mContext).registerReceiver(any(), any());

View File

@@ -19,8 +19,8 @@ package com.android.settings.fuelgauge.batterytip;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -45,9 +45,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowJobScheduler;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -85,9 +83,8 @@ public class AnomalyCleanupJobServiceTest {
public void scheduleCleanUp() {
AnomalyCleanupJobService.scheduleCleanUp(mContext);
ShadowJobScheduler shadowJobScheduler =
Shadows.shadowOf(mContext.getSystemService(JobScheduler.class));
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
JobScheduler jobScheduler = mContext.getSystemService(JobScheduler.class);
List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
assertEquals(1, pendingJobs.size());
JobInfo pendingJob = pendingJobs.get(0);
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_clean_up);

View File

@@ -45,8 +45,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowJobScheduler;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -82,9 +80,8 @@ public class AnomalyConfigJobServiceTest {
public void testScheduleConfigUpdate() {
AnomalyConfigJobService.scheduleConfigUpdate(mContext);
ShadowJobScheduler shadowJobScheduler =
Shadows.shadowOf(mContext.getSystemService(JobScheduler.class));
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
JobScheduler jobScheduler = mContext.getSystemService(JobScheduler.class);
List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
assertEquals(1, pendingJobs.size());
JobInfo pendingJob = pendingJobs.get(0);
assertThat(pendingJob.getId()).isEqualTo(R.integer.job_anomaly_config_update);

View File

@@ -22,12 +22,12 @@ import static android.os.StatsDimensionsValue.TUPLE_VALUE_TYPE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
@@ -67,10 +67,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.android.controller.ServiceController;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowJobScheduler;
import java.util.ArrayList;
import java.util.List;
@@ -129,9 +127,8 @@ public class AnomalyDetectionJobServiceTest {
public void scheduleCleanUp() {
AnomalyDetectionJobService.scheduleAnomalyDetection(application, new Intent());
ShadowJobScheduler shadowJobScheduler =
Shadows.shadowOf(application.getSystemService(JobScheduler.class));
List<JobInfo> pendingJobs = shadowJobScheduler.getAllPendingJobs();
JobScheduler jobScheduler = application.getSystemService(JobScheduler.class);
List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
assertThat(pendingJobs).hasSize(1);
JobInfo pendingJob = pendingJobs.get(0);

View File

@@ -0,0 +1,130 @@
/*
* 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.homepage.contextualcards.slices;
import static android.content.Context.MODE_PRIVATE;
import static com.android.settings.homepage.contextualcards.slices.BatteryFixSlice.KEY_CURRENT_TIPS_TYPE;
import static com.android.settings.homepage.contextualcards.slices.BatteryFixSlice.PREFS;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.slice.SliceProvider;
import androidx.slice.widget.SliceLiveData;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
import com.android.settings.fuelgauge.batterytip.BatteryTipLoader;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
public class BatteryFixSliceTest {
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
}
@After
public void tearDown() {
ShadowBatteryTipLoader.reset();
}
@Test
public void readBatteryTipfromPref_readCorrectValue() {
int target = 111;
final SharedPreferences.Editor editor = mContext.getSharedPreferences(PREFS,
MODE_PRIVATE).edit();
editor.putInt(KEY_CURRENT_TIPS_TYPE, target);
editor.commit();
assertThat(BatteryFixSlice.readBatteryTipAvailabilityCache(mContext)).isEqualTo(target);
}
@Test
@Config(shadows = {
ShadowBatteryStatsHelperLoader.class,
ShadowBatteryTipLoader.class
})
public void updateBatteryTipAvailabilityCache_writeCorrectValue() {
final List<BatteryTip> tips = new ArrayList<>();
tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false, ""));
tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
assertThat(BatteryFixSlice.readBatteryTipAvailabilityCache(mContext)).isEqualTo(
BatteryTip.TipType.BATTERY_SAVER);
}
@Implements(BatteryStatsHelperLoader.class)
public static class ShadowBatteryStatsHelperLoader {
@Implementation
protected BatteryStatsHelper loadInBackground() {
return null;
}
}
@Implements(BatteryTipLoader.class)
public static class ShadowBatteryTipLoader {
private static List<BatteryTip> sBatteryTips = new ArrayList<>();
@Resetter
public static void reset() {
sBatteryTips = new ArrayList<>();
}
@Implementation
protected List<BatteryTip> loadInBackground() {
return sBatteryTips;
}
public static void setBatteryTips(List<BatteryTip> tips) {
sBatteryTips = tips;
}
}
}

View File

@@ -21,10 +21,18 @@ import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_U
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
@@ -38,12 +46,15 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.ArgumentCaptor;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class CarrierPreferenceControllerTest {
private static final int SUB_ID = 2;
private static final String CARRIER_SETTINGS_COMPONENT = "packageName/className";
@Mock
private TelephonyManager mTelephonyManager;
@@ -106,4 +117,55 @@ public class CarrierPreferenceControllerTest {
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void handlePreferenceClick_activityFound_openCarrierSettingActivity() {
final PersistableBundle bundle = new PersistableBundle();
bundle.putString(
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
CARRIER_SETTINGS_COMPONENT);
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
PackageManager pm = Mockito.mock(PackageManager.class);
doReturn(pm).when(mContext).getPackageManager();
doReturn(new ResolveInfo()).when(pm).resolveActivity(any(Intent.class), anyInt());
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
verify(mContext).startActivity(captor.capture());
final Intent intent = captor.getValue();
assertThat(intent.getComponent()).isEqualTo(
ComponentName.unflattenFromString(CARRIER_SETTINGS_COMPONENT));
}
@Test
public void handlePreferenceClick_activityNotFound_DoNothing() {
final PersistableBundle bundle = new PersistableBundle();
bundle.putString(
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
CARRIER_SETTINGS_COMPONENT);
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
PackageManager pm = Mockito.mock(PackageManager.class);
doReturn(pm).when(mContext).getPackageManager();
doReturn(null).when(pm).resolveActivity(any(Intent.class), anyInt());
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
verify(mContext, never()).startActivity(captor.capture());
}
@Test
public void handlePreferenceClick_activityNotConfigured_DoNothing() {
final PersistableBundle bundle = new PersistableBundle();
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
PackageManager pm = Mockito.mock(PackageManager.class);
doReturn(pm).when(mContext).getPackageManager();
doReturn(new ResolveInfo()).when(pm).resolveActivity(any(Intent.class), anyInt());
mController.handlePreferenceTreeClick(mPreference);
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
verify(mContext, never()).startActivity(captor.capture());
}
}

View File

@@ -79,8 +79,8 @@ public class Enhanced4gLtePreferenceControllerTest {
mPreference = new RestrictedSwitchPreference(mContext);
mController = new Enhanced4gLtePreferenceController(mContext, "roaming");
mController.mImsManager = mImsManager;
mController.init(SUB_ID);
mController.mImsManager = mImsManager;
mPreference.setKey(mController.getPreferenceKey());
}

View File

@@ -38,6 +38,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.util.FeatureFlagUtils;
import androidx.preference.ListPreference;
@@ -107,8 +108,8 @@ public class AudioOutputSwitchPreferenceControllerTest {
private Context mContext;
private PreferenceScreen mScreen;
private ListPreference mPreference;
private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager;
private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice;
@@ -126,8 +127,8 @@ public class AudioOutputSwitchPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowAudioManager = ShadowAudioManager.getShadow();
mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -168,7 +169,6 @@ public class AudioOutputSwitchPreferenceControllerTest {
@After
public void tearDown() {
mShadowAudioManager.reset();
ShadowBluetoothUtils.reset();
}

View File

@@ -99,8 +99,8 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
private Context mContext;
private PreferenceScreen mScreen;
private ListPreference mPreference;
private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager;
private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice;
@@ -117,8 +117,8 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowAudioManager = ShadowAudioManager.getShadow();
mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -163,7 +163,6 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
@After
public void tearDown() {
mShadowAudioManager.reset();
ShadowBluetoothUtils.reset();
}
@@ -173,7 +172,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void setActiveBluetoothDevice_btDeviceWithHisyncId_shouldSetBtDeviceActive() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
@@ -188,7 +187,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void setActiveBluetoothDevice_btDeviceWithoutHisyncId_shouldSetBtDeviceActive() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -203,7 +202,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void setActiveBluetoothDevice_setNull_shouldSetNullToBothProfiles() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(null);
@@ -217,7 +216,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void setActiveBluetoothDevice_inNormalMode_shouldNotSetActiveDeviceToHeadsetProfile() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -245,7 +244,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_oneHeadsetsAvailableAndActivated_shouldSetDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -266,7 +265,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_moreThanOneHfpBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
List<BluetoothDevice> connectedDevices = new ArrayList<>(2);
connectedDevices.add(mBluetoothDevice);
@@ -288,7 +287,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_withAvailableDevicesWiredHeadsetActivated_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
@@ -308,7 +307,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_noAvailableHeadsetBtDevices_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
List<BluetoothDevice> emptyDeviceList = new ArrayList<>();
when(mHeadsetProfile.getConnectedDevices()).thenReturn(emptyDeviceList);
@@ -326,7 +325,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -350,7 +349,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -378,7 +377,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -411,7 +410,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -443,7 +442,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
*/
@Test
public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);

View File

@@ -100,8 +100,8 @@ public class MediaOutputPreferenceControllerTest {
private Context mContext;
private PreferenceScreen mScreen;
private ListPreference mPreference;
private AudioManager mAudioManager;
private ShadowAudioManager mShadowAudioManager;
private ShadowMediaRouter mShadowMediaRouter;
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothDevice mBluetoothDevice;
@@ -118,8 +118,8 @@ public class MediaOutputPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mShadowAudioManager = ShadowAudioManager.getShadow();
mShadowMediaRouter = ShadowMediaRouter.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
@@ -164,7 +164,6 @@ public class MediaOutputPreferenceControllerTest {
@After
public void tearDown() {
mShadowAudioManager.reset();
ShadowBluetoothUtils.reset();
}
@@ -174,7 +173,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void setActiveBluetoothDevice_btDeviceWithHisyncId_shouldSetBtDeviceActive() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
mController.setActiveBluetoothDevice(mLeftBluetoothHapDevice);
@@ -189,7 +188,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void setActiveBluetoothDevice_btDeviceWithoutHisyncId_shouldSetBtDeviceActive() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -204,7 +203,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void setActiveBluetoothDevice_setNull_shouldSetNullToBothProfiles() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.setActiveBluetoothDevice(null);
@@ -218,7 +217,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void setActiveBluetoothDevice_duringACall_shouldNotSetActiveDeviceToA2dpProfile() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.setActiveBluetoothDevice(mBluetoothDevice);
@@ -246,7 +245,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_duringACall_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.updateState(mPreference);
@@ -262,7 +261,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_noAvailableA2dpBtDevices_shouldDisableAndSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
List<BluetoothDevice> emptyDeviceList = new ArrayList<>();
when(mA2dpProfile.getConnectedDevices()).thenReturn(emptyDeviceList);
@@ -296,7 +295,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_oneA2dpBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -316,7 +315,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_moreThanOneA2DpBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -337,7 +336,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_a2dpDevicesAvailableWiredHeadsetIsActivated_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
@@ -359,7 +358,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_a2dpDevicesAvailableCurrentDeviceActivated_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
@@ -379,7 +378,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_oneHapBtDeviceAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -403,7 +402,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_moreThanOneHapBtDevicesAreAvailable_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
@@ -431,7 +430,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_hapBtDeviceWithSameId_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -464,7 +463,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_hapBtDeviceWithSameIdButDifferentOrder_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
@@ -496,7 +495,7 @@ public class MediaOutputPreferenceControllerTest {
*/
@Test
public void updateState_hapBtDeviceWithDifferentId_shouldSetActivatedDeviceName() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);

View File

@@ -30,7 +30,7 @@ import java.util.List;
import java.util.Map;
@Implements(AccountManager.class)
public class ShadowAccountManager{
public class ShadowAccountManager {
private static final Map<String, AuthenticatorDescription> sAuthenticators = new HashMap<>();
private static final Map<Integer, List<Account>> sAccountsByUserId = new HashMap<>();

View File

@@ -101,11 +101,6 @@ public class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManag
}
}
@Resetter
public void reset() {
mDeviceCallbacks.clear();
}
public void setBluetoothScoOn(boolean bluetoothScoOn) {
mBluetoothScoOn = bluetoothScoOn;
}

View File

@@ -1,60 +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.settings.testutils.shadow;
import libcore.icu.TimeZoneNames;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.util.ReflectionHelpers;
import java.util.Locale;
import java.util.TimeZone;
/**
* System.logI used by ZoneStringsCache.create is a method new in API 24 and not available in
* Robolectric's 6.0 jar. Create a shadow which removes that log call.
*/
@Implements(value = TimeZoneNames.class, isInAndroidSdk = false)
public class ShadowLibcoreTimeZoneNames {
private static final String[] availableTimeZoneIds = TimeZone.getAvailableIDs();
@Implements(value = TimeZoneNames.ZoneStringsCache.class, isInAndroidSdk = false)
public static class ShadowZoneStringsCache {
@RealObject
private TimeZoneNames.ZoneStringsCache mRealObject;
@Implementation
public String[][] create(Locale locale) {
// Set up the 2D array used to hold the names. The first column contains the Olson ids.
String[][] result = new String[availableTimeZoneIds.length][5];
for (int i = 0; i < availableTimeZoneIds.length; ++i) {
result[i][0] = availableTimeZoneIds[i];
}
ReflectionHelpers.callInstanceMethod(TimeZoneNames.class,
mRealObject, "fillZoneStrings",
ReflectionHelpers.ClassParameter.from(String.class, locale.toLanguageTag()),
ReflectionHelpers.ClassParameter.from(String[][].class, result));
return result;
}
}
}

View File

@@ -21,12 +21,10 @@ import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager.EnforcingUser;
import android.util.SparseArray;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
import org.robolectric.shadow.api.Shadow;
import java.util.ArrayList;
@@ -40,7 +38,6 @@ import java.util.Set;
@Implements(value = UserManager.class)
public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
private SparseArray<UserInfo> mUserInfos = new SparseArray<>();
private final List<String> mRestrictions = new ArrayList<>();
private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>();
private final List<UserInfo> mUserProfileInfos = new ArrayList<>();
@@ -49,15 +46,6 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
private int[] profileIdsForUser = new int[0];
private boolean mUserSwitchEnabled;
public void setUserInfo(int userHandle, UserInfo userInfo) {
mUserInfos.put(userHandle, userInfo);
}
@Implementation
protected UserInfo getUserInfo(int userHandle) {
return mUserInfos.get(userHandle);
}
public void addProfile(UserInfo userInfo) {
mUserProfileInfos.add(userInfo);
}
@@ -76,16 +64,6 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
return ids;
}
@Implementation
public List<UserHandle> getUserProfiles() {
int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
List<UserHandle> result = new ArrayList<>(userIds.length);
for (int userId : userIds) {
result.add(UserHandle.of(userId));
}
return result;
}
@Implementation
protected int getCredentialOwnerProfile(@UserIdInt int userHandle) {
return userHandle;

View File

@@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.pm.UserInfo;
import android.provider.Settings.Global;
import androidx.preference.PreferenceScreen;
@@ -32,7 +31,6 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.RestrictedSwitchPreference;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,7 +38,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {ShadowUserManager.class})
@@ -49,7 +46,6 @@ public class AddUserWhenLockedPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock(answer = RETURNS_DEEP_STUBS)
private UserInfo mUserInfo;
private Context mContext;
private ShadowUserManager mUserManager;
@@ -65,8 +61,7 @@ public class AddUserWhenLockedPreferenceControllerTest {
@Test
public void displayPref_NotAdmin_shouldNotDisplay() {
mUserManager.setUserInfo(0, mUserInfo);
when(mUserInfo.isAdmin()).thenReturn(false);
mUserManager.setIsAdminUser(false);
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
when(mScreen.findPreference(preference.getKey())).thenReturn(preference);

View File

@@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
@@ -40,9 +39,7 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,18 +47,14 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = {ShadowUserManager.class})
public class EditUserInfoControllerTest {
@Mock
private Fragment mFragment;
@Mock
private LayoutInflater mInflater;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private UserInfo mUserInfo;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private View mDialogContent;
@Mock
private EditText mUserName;
@@ -70,7 +63,6 @@ public class EditUserInfoControllerTest {
@Mock
private Drawable mCurrentIcon;
private ShadowUserManager mUserManager;
private FragmentActivity mActivity;
private TestEditUserInfoController mController;
@@ -92,8 +84,6 @@ public class EditUserInfoControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mUserManager = ShadowUserManager.getShadow();
mUserManager.setUserInfo(0, mUserInfo);
mActivity = spy(ActivityController.of(new FragmentActivity()).get());
when(mFragment.getActivity()).thenReturn(mActivity);
when(mActivity.getLayoutInflater()).thenReturn(mInflater);

View File

@@ -96,11 +96,12 @@ public class EntityHeaderControllerTest {
}
@Test
public void testBuildView_withContext_shouldBuildPreference() {
public void testBuildView_withContext_shouldBuildPreferenceAllowedBelowDivider() {
mController = EntityHeaderController.newInstance(mActivity, mFragment, null);
Preference preference = mController.done(mActivity, mShadowContext);
assertThat(preference instanceof LayoutPreference).isTrue();
assertThat(((LayoutPreference)preference).isAllowDividerBelow()).isTrue();
}
@Test

View File

@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@@ -56,14 +57,14 @@ public class SavedAccessPointsPreferenceControllerTest {
private PreferenceCategory mPreferenceCategory;
private Context mContext;
private ShadowWifiManager mWifiManager;
private WifiManager mWifiManager;
private SavedAccessPointsPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mWifiManager = ShadowWifiManager.get();
mWifiManager = mContext.getSystemService(WifiManager.class);
mController = spy(new SavedAccessPointsPreferenceController(mContext, "test_key"));
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))