Disable Moblie Data Slice in AP mode
When airplane mode is enabled, users should not be able to change the value of mobile data. Thus, when airplane mode is enabled, replace the Slice with a no-op slice explaining why it cannot be changed. Fixes: 119411534 Fixes: 126726036 Test: robotests Change-Id: I991fe05ad8f18004f77fbf1c87403de602d3a267
This commit is contained in:
@@ -10684,6 +10684,9 @@
|
||||
<!-- Title for the Volume dialog (settings panel) with all volume streams[CHAR LIMIT=50] -->
|
||||
<string name="volume_connectivity_panel_title">Volume</string>
|
||||
|
||||
<!-- Subtitle explaining that mobile data cannot be used while airplane mode is on [CHAR LIMIT=50] -->
|
||||
<string name="mobile_data_ap_mode_disabled">Unavailable during airplane mode</string>
|
||||
|
||||
<!-- UI debug setting: force desktop mode [CHAR LIMIT=50] -->
|
||||
<string name="force_desktop_mode">Force desktop mode</string>
|
||||
<!-- UI debug setting: force desktop mode summary [CHAR LIMIT=NONE] -->
|
||||
|
@@ -74,8 +74,27 @@ public class MobileDataSlice implements CustomSliceable {
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_network_cell);
|
||||
final String title = mContext.getText(R.string.mobile_data_settings_title).toString();
|
||||
final CharSequence summary = getSummary();
|
||||
@ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
|
||||
|
||||
// Return a Slice without the mobile data toggle when airplane mode is on.
|
||||
if (isAirplaneModeEnabled()) {
|
||||
final CharSequence summary = mContext.getText(R.string.mobile_data_ap_mode_disabled);
|
||||
// Intent does nothing, but we have to pass an intent to the Row.
|
||||
final PendingIntent intent = PendingIntent.getActivity(mContext, 0 /* requestCode */,
|
||||
new Intent(), 0 /* flags */);
|
||||
final SliceAction deadAction =
|
||||
SliceAction.create(intent, icon, ListBuilder.ICON_IMAGE, title);
|
||||
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(),
|
||||
ListBuilder.INFINITY)
|
||||
.setAccentColor(color)
|
||||
.addRow(new ListBuilder.RowBuilder()
|
||||
.setTitle(title)
|
||||
.setSubtitle(summary)
|
||||
.setPrimaryAction(deadAction));
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
final CharSequence summary = getSummary();
|
||||
final PendingIntent toggleAction = getBroadcastIntent(mContext);
|
||||
final PendingIntent primaryAction = getPrimaryAction();
|
||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon,
|
||||
@@ -101,11 +120,6 @@ public class MobileDataSlice implements CustomSliceable {
|
||||
|
||||
@Override
|
||||
public void onNotifyChange(Intent intent) {
|
||||
// Don't make a change if we are in Airplane Mode.
|
||||
if (isAirplaneModeEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean newState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE,
|
||||
isMobileDataEnabled());
|
||||
|
||||
|
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
@@ -162,4 +163,27 @@ public class MobileDataSliceTest {
|
||||
|
||||
assertThat(isMobileDataEnabled).isEqualTo(seed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void airplaneModeEnabled_slicePrimaryActionIsEmpty() {
|
||||
doReturn(true).when(mMobileDataSlice).isAirplaneModeEnabled();
|
||||
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
|
||||
final Slice mobileData = mMobileDataSlice.getSlice();
|
||||
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, mobileData);
|
||||
assertThat(metadata.getTitle())
|
||||
.isEqualTo(mContext.getString(R.string.mobile_data_settings_title));
|
||||
|
||||
assertThat(metadata.getSubtitle())
|
||||
.isEqualTo(mContext.getString(R.string.mobile_data_ap_mode_disabled));
|
||||
|
||||
final List<SliceAction> toggles = metadata.getToggles();
|
||||
assertThat(toggles).hasSize(0);
|
||||
|
||||
final SliceAction primaryAction = metadata.getPrimaryAction();
|
||||
final PendingIntent pendingIntent = primaryAction.getAction();
|
||||
final Intent actionIntent = pendingIntent.getIntent();
|
||||
|
||||
assertThat(actionIntent).isNull();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user