Refactor WifiSlice to CustomSliceManager
Modify the WifiSliceCode to follow the pattern for Slices that do not match existing UI components. Test: robotests Bug: 80263568 Change-Id: Id69e019608777282f4b64ff945e8c30c97aaf577
This commit is contained in:
committed by
Matt Fritze
parent
3df19f92b0
commit
7f0a30226a
@@ -20,6 +20,8 @@ import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import com.android.settings.wifi.WifiSlice;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -36,7 +38,7 @@ public class CustomSliceManager {
|
||||
private final Context mContext;
|
||||
|
||||
public CustomSliceManager(Context context) {
|
||||
mContext = context;
|
||||
mContext = context.getApplicationContext();
|
||||
mUriMap = new ArrayMap<>();
|
||||
addSlices();
|
||||
}
|
||||
@@ -84,5 +86,6 @@ public class CustomSliceManager {
|
||||
}
|
||||
|
||||
private void addSlices() {
|
||||
mUriMap.put(WifiSlice.WIFI_URI, WifiSlice.class);
|
||||
}
|
||||
}
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.slices;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
@@ -56,33 +57,53 @@ public interface CustomSliceable {
|
||||
/**
|
||||
* @return an complete instance of the {@link Slice}.
|
||||
*/
|
||||
Slice getSlice(Context context);
|
||||
Slice getSlice();
|
||||
|
||||
/**
|
||||
* @return a {@link android.content.ContentResolver#SCHEME_CONTENT content} {@link Uri} which
|
||||
* backs the {@link Slice} returned by {@link #getSlice(Context)}.
|
||||
* backs the {@link Slice} returned by {@link #getSlice()}.
|
||||
*/
|
||||
Uri getUri();
|
||||
|
||||
/**
|
||||
* Handles the actions sent by the {@link Intent intents} bound to the {@link Slice} returned by
|
||||
* {@link #getSlice(Context)}.
|
||||
* {@link #getSlice()}.
|
||||
*
|
||||
* @param intent which has the action taken on a {@link Slice}.
|
||||
*/
|
||||
void onNotifyChange(Intent intent);
|
||||
|
||||
/**
|
||||
* @return an {@link Intent} to the source of the Slice data.
|
||||
*/
|
||||
Intent getIntent();
|
||||
|
||||
/**
|
||||
* Settings Slices which can represent components that are updatable by the framework should
|
||||
* listen to changes matched to the {@link IntentFilter} returned here.
|
||||
*
|
||||
* @return an {@link IntentFilter} for updates related to the {@link Slice} returned by
|
||||
* {@link #getSlice(Context)}.
|
||||
* {@link #getSlice()}.
|
||||
*/
|
||||
default IntentFilter getIntentFilter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardize the intents returned to indicate actions by the Slice.
|
||||
* <p>
|
||||
* The {@link PendingIntent} is linked to {@link SliceBroadcastReceiver} where the Intent
|
||||
* Action is found by {@code getUri().toString()}.
|
||||
*
|
||||
* @return a {@link PendingIntent} linked to {@link SliceBroadcastReceiver}.
|
||||
*/
|
||||
default PendingIntent getBroadcastIntent(Context context) {
|
||||
final Intent intent = new Intent(getUri().toString());
|
||||
intent.setClass(context, SliceBroadcastReceiver.class);
|
||||
return PendingIntent.getBroadcast(context, 0 /* requestCode */, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an instance of a {@link CustomSliceable} which has a {@link Context}-only constructor.
|
||||
*/
|
||||
|
@@ -39,7 +39,8 @@ import com.android.settings.location.LocationSliceBuilder;
|
||||
import com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper;
|
||||
import com.android.settings.notification.ZenModeSliceBuilder;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.wifi.WifiSliceBuilder;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.wifi.WifiSlice;
|
||||
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
|
||||
import com.android.settingslib.SliceBroadcastRelay;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
@@ -166,11 +167,7 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
if (WifiSliceBuilder.WIFI_URI.equals(sliceUri)) {
|
||||
registerIntentToUri(WifiSliceBuilder.INTENT_FILTER, sliceUri);
|
||||
mRegisteredUris.add(sliceUri);
|
||||
return;
|
||||
} else if (ZenModeSliceBuilder.ZEN_MODE_URI.equals(sliceUri)) {
|
||||
if (ZenModeSliceBuilder.ZEN_MODE_URI.equals(sliceUri)) {
|
||||
registerIntentToUri(ZenModeSliceBuilder.INTENT_FILTER, sliceUri);
|
||||
return;
|
||||
} else if (BluetoothSliceBuilder.BLUETOOTH_URI.equals(sliceUri)) {
|
||||
@@ -217,7 +214,7 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
if (mCustomSliceManager.isValidUri(sliceUri)) {
|
||||
final CustomSliceable sliceable = mCustomSliceManager.getSliceableFromUri(
|
||||
sliceUri);
|
||||
return sliceable.getSlice(getContext());
|
||||
return sliceable.getSlice();
|
||||
}
|
||||
|
||||
if (WifiCallingSliceHelper.WIFI_CALLING_URI.equals(sliceUri)) {
|
||||
@@ -225,8 +222,6 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
.getSlicesFeatureProvider()
|
||||
.getNewWifiCallingSliceHelper(getContext())
|
||||
.createWifiCallingSlice(sliceUri);
|
||||
} else if (WifiSliceBuilder.WIFI_URI.equals(sliceUri)) {
|
||||
return WifiSliceBuilder.getSlice(getContext());
|
||||
} else if (ZenModeSliceBuilder.ZEN_MODE_URI.equals(sliceUri)) {
|
||||
return ZenModeSliceBuilder.getSlice(getContext());
|
||||
} else if (BluetoothSliceBuilder.BLUETOOTH_URI.equals(sliceUri)) {
|
||||
@@ -402,7 +397,7 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
|
||||
private List<Uri> getSpecialCasePlatformUris() {
|
||||
return Arrays.asList(
|
||||
WifiSliceBuilder.WIFI_URI,
|
||||
WifiSlice.WIFI_URI,
|
||||
BluetoothSliceBuilder.BLUETOOTH_URI,
|
||||
LocationSliceBuilder.LOCATION_URI
|
||||
);
|
||||
|
@@ -26,7 +26,6 @@ import static com.android.settings.slices.SettingsSliceProvider.ACTION_SLIDER_CH
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_TOGGLE_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_PLATFORM_DEFINED;
|
||||
import static com.android.settings.wifi.WifiSliceBuilder.ACTION_WIFI_SLICE_CHANGED;
|
||||
import static com.android.settings.wifi.calling.WifiCallingSliceHelper.ACTION_WIFI_CALLING_CHANGED;
|
||||
import static com.android.settings.wifi.calling.WifiCallingSliceHelper
|
||||
.ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED;
|
||||
@@ -54,7 +53,6 @@ import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.flashlight.FlashlightSliceBuilder;
|
||||
import com.android.settings.notification.ZenModeSliceBuilder;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.wifi.WifiSliceBuilder;
|
||||
|
||||
/**
|
||||
* Responds to actions performed on slices and notifies slices of updates in state changes.
|
||||
@@ -91,9 +89,6 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
case ACTION_BLUETOOTH_SLICE_CHANGED:
|
||||
BluetoothSliceBuilder.handleUriChange(context, intent);
|
||||
break;
|
||||
case ACTION_WIFI_SLICE_CHANGED:
|
||||
WifiSliceBuilder.handleUriChange(context, intent);
|
||||
break;
|
||||
case ACTION_WIFI_CALLING_CHANGED:
|
||||
FeatureFactory.getFactory(context)
|
||||
.getSlicesFeatureProvider()
|
||||
|
@@ -16,6 +16,7 @@ package com.android.settings.slices;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
@@ -24,7 +25,8 @@ import android.util.Log;
|
||||
import com.android.settings.bluetooth.BluetoothSliceBuilder;
|
||||
import com.android.settings.location.LocationSliceBuilder;
|
||||
import com.android.settings.notification.ZenModeSliceBuilder;
|
||||
import com.android.settings.wifi.WifiSliceBuilder;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.wifi.WifiSlice;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@@ -50,23 +52,28 @@ public class SliceDeepLinkSpringBoard extends Activity {
|
||||
if (ACTION_VIEW_SLICE.equals(intent.getAction())) {
|
||||
// This shouldn't matter since the slice is shown instead of the device
|
||||
// index caring about the launch uri.
|
||||
final Uri slice = Uri.parse(intent.getStringExtra(EXTRA_SLICE));
|
||||
final Intent launchIntent;
|
||||
final Uri sliceUri = Uri.parse(intent.getStringExtra(EXTRA_SLICE));
|
||||
Intent launchIntent;
|
||||
|
||||
// TODO (b/80263568) Avoid duplicating this list of Slice Uris.
|
||||
if (WifiSliceBuilder.WIFI_URI.equals(slice)) {
|
||||
launchIntent = WifiSliceBuilder.getIntent(this /* context */);
|
||||
} else if (ZenModeSliceBuilder.ZEN_MODE_URI.equals(slice)) {
|
||||
final CustomSliceManager customSliceManager = FeatureFactory.getFactory(this)
|
||||
.getSlicesFeatureProvider().getCustomSliceManager(this);
|
||||
if (customSliceManager.isValidUri(sliceUri)) {
|
||||
final CustomSliceable sliceable =
|
||||
customSliceManager.getSliceableFromUri(sliceUri);
|
||||
launchIntent = sliceable.getIntent();
|
||||
} else if (ZenModeSliceBuilder.ZEN_MODE_URI.equals(sliceUri)) {
|
||||
launchIntent = ZenModeSliceBuilder.getIntent(this /* context */);
|
||||
} else if (BluetoothSliceBuilder.BLUETOOTH_URI.equals(slice)) {
|
||||
} else if (BluetoothSliceBuilder.BLUETOOTH_URI.equals(sliceUri)) {
|
||||
launchIntent = BluetoothSliceBuilder.getIntent(this /* context */);
|
||||
} else if (LocationSliceBuilder.LOCATION_URI.equals(slice)) {
|
||||
} else if (LocationSliceBuilder.LOCATION_URI.equals(sliceUri)) {
|
||||
launchIntent = LocationSliceBuilder.getIntent(this /* context */);
|
||||
} else {
|
||||
final SlicesDatabaseAccessor slicesDatabaseAccessor =
|
||||
new SlicesDatabaseAccessor(this /* context */);
|
||||
// Sadly have to block here because we don't know where to go.
|
||||
final SliceData sliceData = slicesDatabaseAccessor.getSliceDataFromUri(slice);
|
||||
final SliceData sliceData =
|
||||
slicesDatabaseAccessor.getSliceDataFromUri(sliceUri);
|
||||
launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData);
|
||||
}
|
||||
|
||||
|
@@ -36,6 +36,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
import com.android.settings.slices.SliceBuilderUtils;
|
||||
|
||||
@@ -48,7 +49,7 @@ import androidx.slice.builders.SliceAction;
|
||||
/**
|
||||
* Utility class to build a Wifi Slice, and handle all associated actions.
|
||||
*/
|
||||
public class WifiSliceBuilder {
|
||||
public class WifiSlice implements CustomSliceable {
|
||||
|
||||
/**
|
||||
* Backing Uri for the Wifi Slice.
|
||||
@@ -60,41 +61,43 @@ public class WifiSliceBuilder {
|
||||
.appendPath(KEY_WIFI)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Action notifying a change on the Wifi Slice.
|
||||
*/
|
||||
public static final String ACTION_WIFI_SLICE_CHANGED =
|
||||
"com.android.settings.wifi.action.WIFI_CHANGED";
|
||||
private final Context mContext;
|
||||
|
||||
public static final IntentFilter INTENT_FILTER = new IntentFilter();
|
||||
|
||||
static {
|
||||
INTENT_FILTER.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
INTENT_FILTER.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
public WifiSlice(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
private WifiSliceBuilder() {
|
||||
@Override
|
||||
public Uri getUri() {
|
||||
return WIFI_URI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntentFilter getIntentFilter() {
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Wifi Slice bound to {@link #WIFI_URI}.
|
||||
* <p>
|
||||
* Note that you should register a listener for {@link #INTENT_FILTER} to get changes for Wifi.
|
||||
*/
|
||||
public static Slice getSlice(Context context) {
|
||||
final boolean isWifiEnabled = isWifiEnabled(context);
|
||||
final IconCompat icon = IconCompat.createWithResource(context,
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
final boolean isWifiEnabled = isWifiEnabled();
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_settings_wireless);
|
||||
final String title = context.getString(R.string.wifi_settings);
|
||||
final CharSequence summary = getSummary(context);
|
||||
@ColorInt final int color = Utils.getColorAccentDefaultColor(context);
|
||||
final PendingIntent toggleAction = getBroadcastIntent(context);
|
||||
final PendingIntent primaryAction = getPrimaryAction(context);
|
||||
final String title = mContext.getString(R.string.wifi_settings);
|
||||
final CharSequence summary = getSummary();
|
||||
@ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
|
||||
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
||||
final PendingIntent primaryAction = getPrimaryAction();
|
||||
final SliceAction primarySliceAction = new SliceAction(primaryAction, icon, title);
|
||||
final SliceAction toggleSliceAction = new SliceAction(toggleAction, null /* actionTitle */,
|
||||
isWifiEnabled);
|
||||
|
||||
return new ListBuilder(context, WIFI_URI, ListBuilder.INFINITY)
|
||||
return new ListBuilder(mContext, WIFI_URI, ListBuilder.INFINITY)
|
||||
.setAccentColor(color)
|
||||
.addRow(new RowBuilder()
|
||||
.setTitle(title)
|
||||
@@ -108,8 +111,9 @@ public class WifiSliceBuilder {
|
||||
* Update the current wifi status to the boolean value keyed by
|
||||
* {@link android.app.slice.Slice#EXTRA_TOGGLE_STATE} on {@param intent}.
|
||||
*/
|
||||
public static void handleUriChange(Context context, Intent intent) {
|
||||
final WifiManager wifiManager = context.getSystemService(WifiManager.class);
|
||||
@Override
|
||||
public void onNotifyChange(Intent intent) {
|
||||
final WifiManager wifiManager = mContext.getSystemService(WifiManager.class);
|
||||
final boolean newState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
|
||||
wifiManager.isWifiEnabled());
|
||||
wifiManager.setWifiEnabled(newState);
|
||||
@@ -118,20 +122,21 @@ public class WifiSliceBuilder {
|
||||
// handle it.
|
||||
}
|
||||
|
||||
public static Intent getIntent(Context context) {
|
||||
final String screenTitle = context.getText(R.string.wifi_settings).toString();
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
final String screenTitle = mContext.getText(R.string.wifi_settings).toString();
|
||||
final Uri contentUri = new Uri.Builder().appendPath(KEY_WIFI).build();
|
||||
final Intent intent = SliceBuilderUtils.buildSearchResultPageIntent(context,
|
||||
final Intent intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext,
|
||||
WifiSettings.class.getName(), KEY_WIFI, screenTitle,
|
||||
MetricsEvent.DIALOG_WIFI_AP_EDIT)
|
||||
.setClassName(context.getPackageName(), SubSettings.class.getName())
|
||||
.setClassName(mContext.getPackageName(), SubSettings.class.getName())
|
||||
.setData(contentUri);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
private static boolean isWifiEnabled(Context context) {
|
||||
final WifiManager wifiManager = context.getSystemService(WifiManager.class);
|
||||
private boolean isWifiEnabled() {
|
||||
final WifiManager wifiManager = mContext.getSystemService(WifiManager.class);
|
||||
|
||||
switch (wifiManager.getWifiState()) {
|
||||
case WifiManager.WIFI_STATE_ENABLED:
|
||||
@@ -145,38 +150,31 @@ public class WifiSliceBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private static CharSequence getSummary(Context context) {
|
||||
final WifiManager wifiManager = context.getSystemService(WifiManager.class);
|
||||
private CharSequence getSummary() {
|
||||
final WifiManager wifiManager = mContext.getSystemService(WifiManager.class);
|
||||
|
||||
switch (wifiManager.getWifiState()) {
|
||||
case WifiManager.WIFI_STATE_ENABLED:
|
||||
final String ssid = WifiInfo.removeDoubleQuotes(wifiManager.getConnectionInfo()
|
||||
.getSSID());
|
||||
if (TextUtils.equals(ssid, WifiSsid.NONE)) {
|
||||
return context.getText(R.string.disconnected);
|
||||
return mContext.getText(R.string.disconnected);
|
||||
}
|
||||
return ssid;
|
||||
case WifiManager.WIFI_STATE_ENABLING:
|
||||
return context.getText(R.string.disconnected);
|
||||
return mContext.getText(R.string.disconnected);
|
||||
case WifiManager.WIFI_STATE_DISABLED:
|
||||
case WifiManager.WIFI_STATE_DISABLING:
|
||||
return context.getText(R.string.switch_off_text);
|
||||
return mContext.getText(R.string.switch_off_text);
|
||||
case WifiManager.WIFI_STATE_UNKNOWN:
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static PendingIntent getPrimaryAction(Context context) {
|
||||
final Intent intent = getIntent(context);
|
||||
return PendingIntent.getActivity(context, 0 /* requestCode */,
|
||||
private PendingIntent getPrimaryAction() {
|
||||
final Intent intent = getIntent();
|
||||
return PendingIntent.getActivity(mContext, 0 /* requestCode */,
|
||||
intent, 0 /* flags */);
|
||||
}
|
||||
|
||||
private static PendingIntent getBroadcastIntent(Context context) {
|
||||
final Intent intent = new Intent(ACTION_WIFI_SLICE_CHANGED);
|
||||
intent.setClass(context, SliceBroadcastReceiver.class);
|
||||
return PendingIntent.getBroadcast(context, 0 /* requestCode */, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
}
|
||||
}
|
@@ -84,8 +84,9 @@ public class Enhanced4gLteSliceHelperTest {
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mSlicesFeatureProvider = mFeatureFactory.getSlicesFeatureProvider();
|
||||
|
||||
CustomSliceManager manager = new CustomSliceManager(mContext);
|
||||
when(mSlicesFeatureProvider.getCustomSliceManager(any(Context.class)))
|
||||
.thenReturn(new CustomSliceManager(mContext));
|
||||
.thenReturn(manager);
|
||||
|
||||
//setup for SettingsSliceProvider tests
|
||||
mProvider = spy(new SettingsSliceProvider());
|
||||
|
@@ -45,7 +45,7 @@ import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeToggleController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||
import com.android.settings.wifi.WifiSliceBuilder;
|
||||
import com.android.settings.wifi.WifiSlice;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -94,7 +94,7 @@ public class SettingsSliceProviderTest {
|
||||
private SliceManager mManager;
|
||||
|
||||
private static final List<Uri> SPECIAL_CASE_PLATFORM_URIS = Arrays.asList(
|
||||
WifiSliceBuilder.WIFI_URI,
|
||||
WifiSlice.WIFI_URI,
|
||||
BluetoothSliceBuilder.BLUETOOTH_URI,
|
||||
LocationSliceBuilder.LOCATION_URI
|
||||
);
|
||||
@@ -448,9 +448,9 @@ public class SettingsSliceProviderTest {
|
||||
|
||||
@Test
|
||||
public void bindSlice_wifiSlice_returnsWifiSlice() {
|
||||
final Slice wifiSlice = mProvider.onBindSlice(WifiSliceBuilder.WIFI_URI);
|
||||
final Slice wifiSlice = mProvider.onBindSlice(WifiSlice.WIFI_URI);
|
||||
|
||||
assertThat(wifiSlice.getUri()).isEqualTo(WifiSliceBuilder.WIFI_URI);
|
||||
assertThat(wifiSlice.getUri()).isEqualTo(WifiSlice.WIFI_URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -85,8 +85,9 @@ public class SliceBroadcastReceiverTest {
|
||||
mSearchFeatureProvider = new SearchFeatureProviderImpl();
|
||||
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mFakeFeatureFactory.searchFeatureProvider = mSearchFeatureProvider;
|
||||
CustomSliceManager manager = new CustomSliceManager(mContext);
|
||||
when(mFakeFeatureFactory.slicesFeatureProvider.getCustomSliceManager(any()))
|
||||
.thenReturn(new CustomSliceManager(mContext));
|
||||
.thenReturn(manager);
|
||||
mLoggingNameArgumentCatpor = ArgumentCaptor.forClass(Pair.class);
|
||||
mLoggingValueArgumentCatpor = ArgumentCaptor.forClass(Pair.class);
|
||||
}
|
||||
|
@@ -112,10 +112,14 @@ public class SpecialCaseSliceManagerTest {
|
||||
|
||||
static boolean backingData = false;
|
||||
|
||||
public FakeSliceable(Context context) {}
|
||||
final Context mContext;
|
||||
|
||||
public FakeSliceable(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice getSlice(Context context) {
|
||||
public Slice getSlice() {
|
||||
return SLICE;
|
||||
}
|
||||
|
||||
@@ -133,5 +137,10 @@ public class SpecialCaseSliceManagerTest {
|
||||
public IntentFilter getIntentFilter() {
|
||||
return new IntentFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -47,10 +47,12 @@ import androidx.slice.core.SliceAction;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class WifiSliceBuilderTest {
|
||||
public class WifiSliceTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private WifiSlice mWifiSlice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
@@ -62,11 +64,13 @@ public class WifiSliceBuilderTest {
|
||||
|
||||
// Set-up specs for SliceMetadata.
|
||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||
|
||||
mWifiSlice = new WifiSlice(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiSlice_correctSliceContent() {
|
||||
final Slice wifiSlice = WifiSliceBuilder.getSlice(mContext);
|
||||
final Slice wifiSlice = mWifiSlice.getSlice();
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
|
||||
|
||||
final List<SliceAction> toggles = metadata.getToggles();
|
||||
@@ -83,11 +87,11 @@ public class WifiSliceBuilderTest {
|
||||
|
||||
@Test
|
||||
public void handleUriChange_updatesWifi() {
|
||||
final Intent intent = new Intent(WifiSliceBuilder.ACTION_WIFI_SLICE_CHANGED);
|
||||
final Intent intent = mWifiSlice.getIntent();
|
||||
intent.putExtra(android.app.slice.Slice.EXTRA_TOGGLE_STATE, true);
|
||||
final WifiManager wifiManager = mContext.getSystemService(WifiManager.class);
|
||||
|
||||
WifiSliceBuilder.handleUriChange(mContext, intent);
|
||||
mWifiSlice.onNotifyChange(intent);
|
||||
|
||||
assertThat(wifiManager.getWifiState()).isEqualTo(WifiManager.WIFI_STATE_ENABLED);
|
||||
}
|
@@ -99,8 +99,9 @@ public class WifiCallingSliceHelperTest {
|
||||
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mSlicesFeatureProvider = mFeatureFactory.getSlicesFeatureProvider();
|
||||
CustomSliceManager manager = new CustomSliceManager(mContext);
|
||||
when(mSlicesFeatureProvider.getCustomSliceManager(any(Context.class)))
|
||||
.thenReturn(new CustomSliceManager(mContext));
|
||||
.thenReturn(manager);
|
||||
|
||||
// Prevent crash in SliceMetadata.
|
||||
Resources resources = spy(mContext.getResources());
|
||||
|
@@ -29,7 +29,7 @@ import android.support.test.runner.AndroidJUnit4;
|
||||
import com.android.settings.bluetooth.BluetoothSliceBuilder;
|
||||
import com.android.settings.location.LocationSliceBuilder;
|
||||
import com.android.settings.notification.ZenModeSliceBuilder;
|
||||
import com.android.settings.wifi.WifiSliceBuilder;
|
||||
import com.android.settings.wifi.WifiSlice;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -57,7 +57,7 @@ public class SliceDeepLinkSpringBoardTest {
|
||||
@Test
|
||||
@Presubmit
|
||||
public void launchesDeepLinkIntent_wifiSlice_shouldNotCrash() {
|
||||
final Intent deepLinkIntent = getSpringboardIntent(WifiSliceBuilder.WIFI_URI.toString());
|
||||
final Intent deepLinkIntent = getSpringboardIntent(WifiSlice.WIFI_URI.toString());
|
||||
|
||||
mContext.startActivity(deepLinkIntent);
|
||||
}
|
||||
|
Reference in New Issue
Block a user