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