Merge "[Provider Model] Airplane mode slice design change" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c30cd79f35
@@ -12582,8 +12582,10 @@
|
||||
<string name="view_airplane_safe_networks">View airplane mode networks</string>
|
||||
<!-- Text of message for viewing the networks that are available in airplane mode. [CHAR LIMIT=60] -->
|
||||
<string name="viewing_airplane_mode_networks">Viewing airplane mode networks</string>
|
||||
<!-- Label text to turn off airplane mode. [CHAR LIMIT=40] -->
|
||||
<string name="turn_off_airplane_mode">Turn off airplane mode</string>
|
||||
<!-- Slice title text for turning on networks (e.g. Wi-Fi). [CHAR LIMIT=40] -->
|
||||
<string name="turn_on_networks">Turn on networks</string>
|
||||
<!-- Slice title text for turning off networks (e.g. Wi-Fi). [CHAR LIMIT=40] -->
|
||||
<string name="turn_off_networks">Turn off networks</string>
|
||||
<!-- Title for interrupting the voice call alert. [CHAR_LIMIT=NONE] -->
|
||||
<string name="reset_your_internet_title">Reset your internet?</string>
|
||||
<!-- Description for interrupting the voice call alert. [CHAR_LIMIT=NONE] -->
|
||||
|
@@ -23,6 +23,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
@@ -33,6 +34,7 @@ import androidx.slice.Slice;
|
||||
import androidx.slice.builders.ListBuilder;
|
||||
import androidx.slice.builders.ListBuilder.RowBuilder;
|
||||
import androidx.slice.builders.SliceAction;
|
||||
import androidx.slice.core.SliceHints;
|
||||
|
||||
import com.android.settings.AirplaneModeEnabler;
|
||||
import com.android.settings.R;
|
||||
@@ -41,7 +43,6 @@ import com.android.settings.slices.CustomSliceRegistry;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
import com.android.settings.slices.SliceBackgroundWorker;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
import com.android.settingslib.WirelessUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -49,7 +50,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
/**
|
||||
* {@link CustomSliceable} for airplane-safe networks, used by generic clients.
|
||||
*/
|
||||
// TODO(b/173413889): Need to update the slice to Button style.
|
||||
public class AirplaneSafeNetworksSlice implements CustomSliceable,
|
||||
AirplaneModeEnabler.OnAirplaneModeChangedListener {
|
||||
|
||||
@@ -60,26 +60,29 @@ public class AirplaneSafeNetworksSlice implements CustomSliceable,
|
||||
/**
|
||||
* Annotation for different action of the slice.
|
||||
*
|
||||
* {@code VIEW_AIRPLANE_SAFE_NETWORKS} for action of turning on Wi-Fi.
|
||||
* {@code TURN_OFF_AIRPLANE_MODE} for action of turning off Airplane Mode.
|
||||
* {@code TURN_ON_NETWORKS} for action of turning on Wi-Fi networks.
|
||||
* {@code TURN_OFF_NETWORKS} for action of turning off Wi-Fi networks.
|
||||
*/
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef(value = {
|
||||
Action.VIEW_AIRPLANE_SAFE_NETWORKS,
|
||||
Action.TURN_OFF_AIRPLANE_MODE,
|
||||
Action.TURN_ON_NETWORKS,
|
||||
Action.TURN_OFF_NETWORKS,
|
||||
})
|
||||
public @interface Action {
|
||||
int VIEW_AIRPLANE_SAFE_NETWORKS = 1;
|
||||
int TURN_OFF_AIRPLANE_MODE = 2;
|
||||
int TURN_ON_NETWORKS = 1;
|
||||
int TURN_OFF_NETWORKS = 2;
|
||||
}
|
||||
|
||||
private final Context mContext;
|
||||
private final AirplaneModeEnabler mAirplaneModeEnabler;
|
||||
private final WifiManager mWifiManager;
|
||||
|
||||
private boolean mIsAirplaneModeOn;
|
||||
|
||||
public AirplaneSafeNetworksSlice(Context context) {
|
||||
mContext = context;
|
||||
mAirplaneModeEnabler = new AirplaneModeEnabler(context, this);
|
||||
mIsAirplaneModeOn = mAirplaneModeEnabler.isAirplaneModeOn();
|
||||
mWifiManager = mContext.getSystemService(WifiManager.class);
|
||||
}
|
||||
|
||||
@@ -89,15 +92,14 @@ public class AirplaneSafeNetworksSlice implements CustomSliceable,
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
if (!WirelessUtils.isAirplaneModeOn(mContext)) {
|
||||
return null;
|
||||
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY);
|
||||
if (mIsAirplaneModeOn) {
|
||||
listBuilder.addRow(new RowBuilder()
|
||||
.setTitle(getTitle())
|
||||
.addEndItem(getEndIcon(), SliceHints.ICON_IMAGE)
|
||||
.setPrimaryAction(getSliceAction()));
|
||||
}
|
||||
|
||||
return new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.addRow(new RowBuilder()
|
||||
.setTitle(getTitle())
|
||||
.setPrimaryAction(getSliceAction()))
|
||||
.build();
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,21 +110,22 @@ public class AirplaneSafeNetworksSlice implements CustomSliceable,
|
||||
@Override
|
||||
public void onNotifyChange(Intent intent) {
|
||||
final int action = intent.getIntExtra(ACTION_INTENT_EXTRA, 0);
|
||||
if (action == Action.VIEW_AIRPLANE_SAFE_NETWORKS) {
|
||||
if (action == Action.TURN_ON_NETWORKS) {
|
||||
if (!mWifiManager.isWifiEnabled()) {
|
||||
logd("Action: turn on WiFi");
|
||||
logd("Action: turn on Wi-Fi networks");
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
}
|
||||
} else if (action == Action.TURN_OFF_AIRPLANE_MODE) {
|
||||
if (WirelessUtils.isAirplaneModeOn(mContext)) {
|
||||
logd("Action: turn off Airplane mode");
|
||||
mAirplaneModeEnabler.setAirplaneMode(false);
|
||||
} else if (action == Action.TURN_OFF_NETWORKS) {
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
logd("Action: turn off Wi-Fi networks");
|
||||
mWifiManager.setWifiEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
||||
mIsAirplaneModeOn = isAirplaneModeOn;
|
||||
final AirplaneSafeNetworksWorker worker = SliceBackgroundWorker.getInstance(getUri());
|
||||
if (worker != null) {
|
||||
worker.updateSlice();
|
||||
@@ -140,15 +143,26 @@ public class AirplaneSafeNetworksSlice implements CustomSliceable,
|
||||
@Action
|
||||
private int getAction() {
|
||||
return mWifiManager.isWifiEnabled()
|
||||
? Action.TURN_OFF_AIRPLANE_MODE
|
||||
: Action.VIEW_AIRPLANE_SAFE_NETWORKS;
|
||||
? Action.TURN_OFF_NETWORKS
|
||||
: Action.TURN_ON_NETWORKS;
|
||||
}
|
||||
|
||||
private String getTitle() {
|
||||
return mContext.getText(
|
||||
(getAction() == Action.VIEW_AIRPLANE_SAFE_NETWORKS)
|
||||
? R.string.view_airplane_safe_networks
|
||||
: R.string.turn_off_airplane_mode).toString();
|
||||
(getAction() == Action.TURN_ON_NETWORKS)
|
||||
? R.string.turn_on_networks
|
||||
: R.string.turn_off_networks).toString();
|
||||
}
|
||||
|
||||
private IconCompat getEndIcon() {
|
||||
final Drawable drawable = mContext.getDrawable(
|
||||
(getAction() == Action.TURN_ON_NETWORKS) ? R.drawable.ic_airplane_safe_networks_24dp
|
||||
: R.drawable.ic_airplanemode_active);
|
||||
if (drawable == null) {
|
||||
return Utils.createIconWithDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
drawable.setTintList(Utils.getColorAttr(mContext, android.R.attr.colorAccent));
|
||||
return Utils.createIconWithDrawable(drawable);
|
||||
}
|
||||
|
||||
private SliceAction getSliceAction() {
|
||||
@@ -156,8 +170,7 @@ public class AirplaneSafeNetworksSlice implements CustomSliceable,
|
||||
0 /* requestCode */, getIntent(),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
final IconCompat icon = Utils.createIconWithDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
return SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.ACTION_WITH_LABEL,
|
||||
getTitle());
|
||||
return SliceAction.create(pendingIntent, icon, ListBuilder.ACTION_WITH_LABEL, getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -34,7 +34,6 @@ import androidx.slice.widget.SliceLiveData;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.AirplaneModeRule;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -50,8 +49,6 @@ public class AirplaneSafeNetworksSliceTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMocks = MockitoJUnit.rule();
|
||||
@Rule
|
||||
public AirplaneModeRule mAirplaneModeRule = new AirplaneModeRule();
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
@@ -67,18 +64,18 @@ public class AirplaneSafeNetworksSliceTest {
|
||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||
|
||||
mAirplaneSafeNetworksSlice = new AirplaneSafeNetworksSlice(mContext);
|
||||
mAirplaneSafeNetworksSlice.onAirplaneModeChanged(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_airplaneModeOff_shouldBeNull() {
|
||||
mAirplaneModeRule.setAirplaneMode(false);
|
||||
public void getSlice_airplaneModeOff_shouldBeNotNull() {
|
||||
mAirplaneSafeNetworksSlice.onAirplaneModeChanged(false);
|
||||
|
||||
assertThat(mAirplaneSafeNetworksSlice.getSlice()).isNull();
|
||||
assertThat(mAirplaneSafeNetworksSlice.getSlice()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_wifiDisabled_shouldShowViewAirplaneSafeNetworks() {
|
||||
mAirplaneModeRule.setAirplaneMode(true);
|
||||
public void getSlice_wifiDisabled_shouldShowTurnOnNetworks() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
|
||||
final Slice slice = mAirplaneSafeNetworksSlice.getSlice();
|
||||
@@ -87,12 +84,11 @@ public class AirplaneSafeNetworksSliceTest {
|
||||
final SliceItem sliceTitle =
|
||||
SliceMetadata.from(mContext, slice).getListContent().getHeader().getTitleItem();
|
||||
assertThat(sliceTitle.getText()).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "view_airplane_safe_networks"));
|
||||
ResourcesUtils.getResourcesString(mContext, "turn_on_networks"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_wifiEnabled_shouldShowTurnOffAirplaneMode() {
|
||||
mAirplaneModeRule.setAirplaneMode(true);
|
||||
public void getSlice_wifiEnabled_shouldShowTurnOffNetworks() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
|
||||
final Slice slice = mAirplaneSafeNetworksSlice.getSlice();
|
||||
@@ -101,12 +97,11 @@ public class AirplaneSafeNetworksSliceTest {
|
||||
final SliceItem sliceTitle =
|
||||
SliceMetadata.from(mContext, slice).getListContent().getHeader().getTitleItem();
|
||||
assertThat(sliceTitle.getText()).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "turn_off_airplane_mode"));
|
||||
ResourcesUtils.getResourcesString(mContext, "turn_off_networks"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_viewAirplaneSafeNetworks_shouldSetWifiEnabled() {
|
||||
mAirplaneModeRule.setAirplaneMode(true);
|
||||
public void onNotifyChange_turnOnNetworks_shouldSetWifiEnabled() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
Intent intent = mAirplaneSafeNetworksSlice.getIntent();
|
||||
|
||||
@@ -116,13 +111,12 @@ public class AirplaneSafeNetworksSliceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_turnOffAirplaneMode_shouldSetAirplaneModeOff() {
|
||||
mAirplaneModeRule.setAirplaneMode(true);
|
||||
public void onNotifyChange_turnOffNetworks_shouldSetWifiDisabled() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
Intent intent = mAirplaneSafeNetworksSlice.getIntent();
|
||||
|
||||
mAirplaneSafeNetworksSlice.onNotifyChange(intent);
|
||||
|
||||
assertThat(mAirplaneModeRule.isAirplaneModeOn()).isFalse();
|
||||
verify(mWifiManager).setWifiEnabled(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user