[Provider Model] Internet Panel - Airplane mode is on
- Add "Airplane mode is on" to sub-title - Set the header layout to CENTER_HORIZONTAL if it's no icon - Hide "Settings" button - Screenshot https://screenshot.googleplex.com/6m5dFVZu7ar4nKW Bug: 178717651 Test: manual test atest InternetConnectivityPanelTest \ PanelFragmentTest \ ProviderModelSliceTest Change-Id: I899a817fd99415e9cad608aa4deac1e45365696a
This commit is contained in:
@@ -48,11 +48,13 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/header_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/header_title"
|
android:id="@+id/header_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -68,7 +70,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"/>
|
android:maxLines="1"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@@ -26,7 +26,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -87,9 +86,6 @@ public class ProviderModelSlice extends WifiSlice {
|
|||||||
final ListBuilder listBuilder = mHelper.createListBuilder(getUri());
|
final ListBuilder listBuilder = mHelper.createListBuilder(getUri());
|
||||||
if (mHelper.isAirplaneModeEnabled() && !mWifiManager.isWifiEnabled()) {
|
if (mHelper.isAirplaneModeEnabled() && !mWifiManager.isWifiEnabled()) {
|
||||||
log("Airplane mode is enabled.");
|
log("Airplane mode is enabled.");
|
||||||
listBuilder.setHeader(mHelper.createHeader(Settings.ACTION_AIRPLANE_MODE_SETTINGS));
|
|
||||||
listBuilder.addGridRow(mHelper.createMessageGridRow(R.string.condition_airplane_title,
|
|
||||||
Settings.ACTION_AIRPLANE_MODE_SETTINGS));
|
|
||||||
return listBuilder.build();
|
return listBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,10 +191,14 @@ public class ProviderModelSlice extends WifiSlice {
|
|||||||
MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState,
|
MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState,
|
||||||
false /* disableOtherSubscriptions */);
|
false /* disableOtherSubscriptions */);
|
||||||
}
|
}
|
||||||
doCarrierNetworkAction(isToggleAction, newState);
|
|
||||||
|
final boolean isDataEnabled =
|
||||||
|
isToggleAction ? newState : MobileNetworkUtils.isMobileDataEnabled(mContext);
|
||||||
|
doCarrierNetworkAction(isToggleAction, isDataEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doCarrierNetworkAction(boolean isToggleAction, boolean isDataEnabled) {
|
@VisibleForTesting
|
||||||
|
void doCarrierNetworkAction(boolean isToggleAction, boolean isDataEnabled) {
|
||||||
final NetworkProviderWorker worker = getWorker();
|
final NetworkProviderWorker worker = getWorker();
|
||||||
if (worker == null) {
|
if (worker == null) {
|
||||||
return;
|
return;
|
||||||
@@ -209,7 +209,7 @@ public class ProviderModelSlice extends WifiSlice {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MobileNetworkUtils.isMobileDataEnabled(mContext)) {
|
if (isDataEnabled) {
|
||||||
worker.connectCarrierNetwork();
|
worker.connectCarrierNetwork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.panel;
|
|||||||
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||||
|
|
||||||
|
import static com.android.settings.network.InternetUpdater.INTERNET_APM;
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
|
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
|
||||||
import static com.android.settings.network.NetworkProviderSettings.ACTION_NETWORK_PROVIDER_SETTINGS;
|
import static com.android.settings.network.NetworkProviderSettings.ACTION_NETWORK_PROVIDER_SETTINGS;
|
||||||
|
|
||||||
@@ -83,6 +84,9 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
mInternetUpdater.onPause();
|
mInternetUpdater.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a string for the title of the Panel.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getTitle() {
|
public CharSequence getTitle() {
|
||||||
if (mIsProviderModelEnabled) {
|
if (mIsProviderModelEnabled) {
|
||||||
@@ -93,10 +97,21 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
return mContext.getText(R.string.internet_connectivity_panel_title);
|
return mContext.getText(R.string.internet_connectivity_panel_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a string for the subtitle of the Panel.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public CharSequence getSubTitle() {
|
||||||
|
if (mIsProviderModelEnabled && mInternetType == INTERNET_APM) {
|
||||||
|
return mContext.getText(R.string.condition_airplane_title);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Uri> getSlices() {
|
public List<Uri> getSlices() {
|
||||||
final List<Uri> uris = new ArrayList<>();
|
final List<Uri> uris = new ArrayList<>();
|
||||||
if (Utils.isProviderModelEnabled(mContext)) {
|
if (mIsProviderModelEnabled) {
|
||||||
uris.add(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
|
uris.add(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
|
||||||
uris.add(CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
|
uris.add(CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
|
||||||
} else {
|
} else {
|
||||||
@@ -109,18 +124,21 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Intent getSeeMoreIntent() {
|
public Intent getSeeMoreIntent() {
|
||||||
return new Intent(Utils.isProviderModelEnabled(mContext)
|
return new Intent(mIsProviderModelEnabled
|
||||||
? ACTION_NETWORK_PROVIDER_SETTINGS : Settings.ACTION_WIRELESS_SETTINGS)
|
? ACTION_NETWORK_PROVIDER_SETTINGS : Settings.ACTION_WIRELESS_SETTINGS)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCustomizedButtonUsed() {
|
public boolean isCustomizedButtonUsed() {
|
||||||
return Utils.isProviderModelEnabled(mContext);
|
return mIsProviderModelEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getCustomizedButtonTitle() {
|
public CharSequence getCustomizedButtonTitle() {
|
||||||
|
if (mInternetType == INTERNET_APM) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return mContext.getText(R.string.settings_button);
|
return mContext.getText(R.string.settings_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,18 +163,35 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
|||||||
* @param internetType the internet type
|
* @param internetType the internet type
|
||||||
*/
|
*/
|
||||||
public void onInternetTypeChanged(@InternetUpdater.InternetType int internetType) {
|
public void onInternetTypeChanged(@InternetUpdater.InternetType int internetType) {
|
||||||
final boolean needRefresh = internetType != mInternetType
|
if (internetType == mInternetType) {
|
||||||
&& (internetType == INTERNET_APM_NETWORKS
|
return;
|
||||||
|| mInternetType == INTERNET_APM_NETWORKS);
|
|
||||||
mInternetType = internetType;
|
|
||||||
if (needRefresh) {
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh() {
|
final boolean changeToApm = (internetType == INTERNET_APM);
|
||||||
|
final boolean changeFromApm = (mInternetType == INTERNET_APM);
|
||||||
|
final boolean changeWithApmNetworks =
|
||||||
|
(internetType == INTERNET_APM_NETWORKS || mInternetType == INTERNET_APM_NETWORKS);
|
||||||
|
mInternetType = internetType;
|
||||||
|
|
||||||
if (mCallback != null) {
|
if (mCallback != null) {
|
||||||
|
if (changeToApm) {
|
||||||
|
// The internet type is changed to the airplane mode.
|
||||||
|
// Title: Internet
|
||||||
|
// Sub-Title: Airplane mode is on
|
||||||
|
// Settings button: Hide
|
||||||
|
mCallback.onHeaderChanged();
|
||||||
|
mCallback.onCustomizedButtonStateChanged();
|
||||||
|
} else if (changeFromApm) {
|
||||||
|
// The internet type is changed from the airplane mode.
|
||||||
|
// Title: Internet
|
||||||
|
// Settings button: Show
|
||||||
|
mCallback.onTitleChanged();
|
||||||
|
mCallback.onCustomizedButtonStateChanged();
|
||||||
|
} else if (changeWithApmNetworks) {
|
||||||
|
// The internet type is changed with the airplane mode networks.
|
||||||
|
// Title: Airplane mode networks / Internet
|
||||||
mCallback.onTitleChanged();
|
mCallback.onTitleChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -26,6 +26,7 @@ import android.net.Uri;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -94,6 +95,7 @@ public class PanelFragment extends Fragment {
|
|||||||
private LinearLayout mPanelHeader;
|
private LinearLayout mPanelHeader;
|
||||||
private ImageView mTitleIcon;
|
private ImageView mTitleIcon;
|
||||||
private LinearLayout mTitleGroup;
|
private LinearLayout mTitleGroup;
|
||||||
|
private LinearLayout mHeaderLayout;
|
||||||
private TextView mHeaderTitle;
|
private TextView mHeaderTitle;
|
||||||
private TextView mHeaderSubtitle;
|
private TextView mHeaderSubtitle;
|
||||||
private int mMaxHeight;
|
private int mMaxHeight;
|
||||||
@@ -202,6 +204,7 @@ public class PanelFragment extends Fragment {
|
|||||||
mPanelHeader = mLayoutView.findViewById(R.id.panel_header);
|
mPanelHeader = mLayoutView.findViewById(R.id.panel_header);
|
||||||
mTitleIcon = mLayoutView.findViewById(R.id.title_icon);
|
mTitleIcon = mLayoutView.findViewById(R.id.title_icon);
|
||||||
mTitleGroup = mLayoutView.findViewById(R.id.title_group);
|
mTitleGroup = mLayoutView.findViewById(R.id.title_group);
|
||||||
|
mHeaderLayout = mLayoutView.findViewById(R.id.header_layout);
|
||||||
mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
|
mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
|
||||||
mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
|
mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
|
||||||
mFooterDivider = mLayoutView.findViewById(R.id.footer_divider);
|
mFooterDivider = mLayoutView.findViewById(R.id.footer_divider);
|
||||||
@@ -239,13 +242,12 @@ public class PanelFragment extends Fragment {
|
|||||||
|
|
||||||
final IconCompat icon = mPanel.getIcon();
|
final IconCompat icon = mPanel.getIcon();
|
||||||
final CharSequence title = mPanel.getTitle();
|
final CharSequence title = mPanel.getTitle();
|
||||||
|
final CharSequence subtitle = mPanel.getSubTitle();
|
||||||
|
|
||||||
if (icon != null) {
|
if (icon != null || (subtitle != null && subtitle.length() > 0)) {
|
||||||
enablePanelHeader(icon, title);
|
enablePanelHeader(icon, title, subtitle);
|
||||||
} else {
|
} else {
|
||||||
mTitleView.setVisibility(View.VISIBLE);
|
enableTitle(title);
|
||||||
mPanelHeader.setVisibility(View.GONE);
|
|
||||||
mTitleView.setText(title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mFooterDivider.setVisibility(View.GONE);
|
mFooterDivider.setVisibility(View.GONE);
|
||||||
@@ -254,13 +256,7 @@ public class PanelFragment extends Fragment {
|
|||||||
mDoneButton.setOnClickListener(getCloseListener());
|
mDoneButton.setOnClickListener(getCloseListener());
|
||||||
|
|
||||||
if (mPanel.isCustomizedButtonUsed()) {
|
if (mPanel.isCustomizedButtonUsed()) {
|
||||||
final CharSequence customTitle = mPanel.getCustomizedButtonTitle();
|
enableCustomizedButton();
|
||||||
if (TextUtils.isEmpty(customTitle)) {
|
|
||||||
mSeeMoreButton.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
mSeeMoreButton.setVisibility(View.VISIBLE);
|
|
||||||
mSeeMoreButton.setText(customTitle);
|
|
||||||
}
|
|
||||||
} else if (mPanel.getSeeMoreIntent() == null) {
|
} else if (mPanel.getSeeMoreIntent() == null) {
|
||||||
// If getSeeMoreIntent() is null hide the mSeeMoreButton.
|
// If getSeeMoreIntent() is null hide the mSeeMoreButton.
|
||||||
mSeeMoreButton.setVisibility(View.GONE);
|
mSeeMoreButton.setVisibility(View.GONE);
|
||||||
@@ -275,14 +271,16 @@ public class PanelFragment extends Fragment {
|
|||||||
0 /* value */);
|
0 /* value */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enablePanelHeader(IconCompat icon, CharSequence title) {
|
private void enablePanelHeader(IconCompat icon, CharSequence title, CharSequence subtitle) {
|
||||||
mTitleView.setVisibility(View.GONE);
|
mTitleView.setVisibility(View.GONE);
|
||||||
mPanelHeader.setVisibility(View.VISIBLE);
|
mPanelHeader.setVisibility(View.VISIBLE);
|
||||||
mPanelHeader.setAccessibilityPaneTitle(title);
|
mPanelHeader.setAccessibilityPaneTitle(title);
|
||||||
mHeaderTitle.setText(title);
|
mHeaderTitle.setText(title);
|
||||||
mHeaderSubtitle.setText(mPanel.getSubTitle());
|
mHeaderSubtitle.setText(subtitle);
|
||||||
|
mHeaderSubtitle.setAccessibilityPaneTitle(subtitle);
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
mTitleGroup.setVisibility(View.VISIBLE);
|
mTitleGroup.setVisibility(View.VISIBLE);
|
||||||
|
mHeaderLayout.setGravity(Gravity.LEFT);
|
||||||
mTitleIcon.setImageIcon(icon.toIcon(getContext()));
|
mTitleIcon.setImageIcon(icon.toIcon(getContext()));
|
||||||
if (mPanel.getHeaderIconIntent() != null) {
|
if (mPanel.getHeaderIconIntent() != null) {
|
||||||
mTitleIcon.setOnClickListener(getHeaderIconListener());
|
mTitleIcon.setOnClickListener(getHeaderIconListener());
|
||||||
@@ -295,6 +293,24 @@ public class PanelFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mTitleGroup.setVisibility(View.GONE);
|
mTitleGroup.setVisibility(View.GONE);
|
||||||
|
mHeaderLayout.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableTitle(CharSequence title) {
|
||||||
|
mPanelHeader.setVisibility(View.GONE);
|
||||||
|
mTitleView.setVisibility(View.VISIBLE);
|
||||||
|
mTitleView.setAccessibilityPaneTitle(title);
|
||||||
|
mTitleView.setText(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableCustomizedButton() {
|
||||||
|
final CharSequence customTitle = mPanel.getCustomizedButtonTitle();
|
||||||
|
if (TextUtils.isEmpty(customTitle)) {
|
||||||
|
mSeeMoreButton.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
mSeeMoreButton.setVisibility(View.VISIBLE);
|
||||||
|
mSeeMoreButton.setText(customTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,24 +503,14 @@ public class PanelFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCustomizedButtonStateChanged() {
|
public void onCustomizedButtonStateChanged() {
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
ThreadUtils.postOnMainThread(() -> {
|
||||||
mSeeMoreButton.setVisibility(
|
enableCustomizedButton();
|
||||||
mPanel.isCustomizedButtonUsed() ? View.VISIBLE : View.GONE);
|
|
||||||
mSeeMoreButton.setText(mPanel.getCustomizedButtonTitle());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHeaderChanged() {
|
public void onHeaderChanged() {
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
ThreadUtils.postOnMainThread(() -> {
|
||||||
final IconCompat icon = mPanel.getIcon();
|
enablePanelHeader(mPanel.getIcon(), mPanel.getTitle(), mPanel.getSubTitle());
|
||||||
if (icon != null) {
|
|
||||||
mTitleIcon.setImageIcon(icon.toIcon(getContext()));
|
|
||||||
mTitleGroup.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
mTitleGroup.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
mHeaderTitle.setText(mPanel.getTitle());
|
|
||||||
mHeaderSubtitle.setText(mPanel.getSubTitle());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,7 +523,7 @@ public class PanelFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onTitleChanged() {
|
public void onTitleChanged() {
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
ThreadUtils.postOnMainThread(() -> {
|
||||||
mTitleView.setText(mPanel.getTitle());
|
enableTitle(mPanel.getTitle());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.panel;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.SystemProperties;
|
|
||||||
|
|
||||||
import com.android.settings.network.AirplaneModePreferenceController;
|
|
||||||
import com.android.settings.slices.CustomSliceRegistry;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
|
|
||||||
public class InternetConnectivityPanelTest {
|
|
||||||
|
|
||||||
private InternetConnectivityPanel mPanel;
|
|
||||||
private static final String SETTINGS_PROVIDER_MODEL =
|
|
||||||
"persist.sys.fflag.override.settings_provider_model";
|
|
||||||
private boolean mSettingsProviderModelState;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mPanel = InternetConnectivityPanel.create(RuntimeEnvironment.application);
|
|
||||||
mSettingsProviderModelState = SystemProperties.getBoolean(SETTINGS_PROVIDER_MODEL, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
SystemProperties.set(SETTINGS_PROVIDER_MODEL,
|
|
||||||
mSettingsProviderModelState ? "true" : "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSlices_providerModelDisabled_containsNecessarySlices() {
|
|
||||||
SystemProperties.set(SETTINGS_PROVIDER_MODEL, "false");
|
|
||||||
final List<Uri> uris = mPanel.getSlices();
|
|
||||||
|
|
||||||
assertThat(uris).containsExactly(
|
|
||||||
AirplaneModePreferenceController.SLICE_URI,
|
|
||||||
CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
|
|
||||||
CustomSliceRegistry.WIFI_SLICE_URI);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSlices_providerModelEnabled_containsNecessarySlices() {
|
|
||||||
SystemProperties.set(SETTINGS_PROVIDER_MODEL, "true");
|
|
||||||
final List<Uri> uris = mPanel.getSlices();
|
|
||||||
|
|
||||||
assertThat(uris).containsExactly(
|
|
||||||
CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
|
|
||||||
CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSeeMoreIntent_notNull() {
|
|
||||||
assertThat(mPanel.getSeeMoreIntent()).isNotNull();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -25,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
|||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.eq;
|
import static org.mockito.Mockito.eq;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -387,35 +386,34 @@ public class ProviderModelSliceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onNotifyChange_intentToggleActionOn_shouldSetCarrierNetworkEnabledTrue() {
|
public void doCarrierNetworkAction_toggleActionSetDataEnabled_setCarrierNetworkEnabledTrue() {
|
||||||
when(mMockProviderModelSlice.defaultSubscriptionIsUsable(anyInt())).thenReturn(true);
|
mMockProviderModelSlice.doCarrierNetworkAction(true /* isToggleAction */,
|
||||||
Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
|
true /* isDataEnabled */);
|
||||||
intent.putExtra(EXTRA_TOGGLE_STATE, true);
|
|
||||||
|
|
||||||
mMockProviderModelSlice.onNotifyChange(intent);
|
|
||||||
|
|
||||||
verify(mMockNetworkProviderWorker).setCarrierNetworkEnabled(true);
|
verify(mMockNetworkProviderWorker).setCarrierNetworkEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onNotifyChange_intentToggleActionOff_shouldSetCarrierNetworkEnabledFalse() {
|
public void doCarrierNetworkAction_toggleActionSetDataDisabled_setCarrierNetworkEnabledFalse() {
|
||||||
when(mMockProviderModelSlice.defaultSubscriptionIsUsable(anyInt())).thenReturn(true);
|
mMockProviderModelSlice.doCarrierNetworkAction(true /* isToggleAction */,
|
||||||
Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
|
false /* isDataEnabled */);
|
||||||
intent.putExtra(EXTRA_TOGGLE_STATE, false);
|
|
||||||
|
|
||||||
mMockProviderModelSlice.onNotifyChange(intent);
|
|
||||||
|
|
||||||
verify(mMockNetworkProviderWorker).setCarrierNetworkEnabled(false);
|
verify(mMockNetworkProviderWorker).setCarrierNetworkEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onNotifyChange_intentPrimaryAction_shouldConnectCarrierNetwork() {
|
public void doCarrierNetworkAction_primaryActionAndDataEnabled_connectCarrierNetwork() {
|
||||||
when(mMockProviderModelSlice.defaultSubscriptionIsUsable(anyInt())).thenReturn(true);
|
mMockProviderModelSlice.doCarrierNetworkAction(false /* isToggleAction */,
|
||||||
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
|
true /* isDataEnabled */);
|
||||||
Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
|
|
||||||
|
|
||||||
mMockProviderModelSlice.onNotifyChange(intent);
|
|
||||||
|
|
||||||
verify(mMockNetworkProviderWorker).connectCarrierNetwork();
|
verify(mMockNetworkProviderWorker).connectCarrierNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void doCarrierNetworkAction_primaryActionAndDataDisabled_notConnectCarrierNetwork() {
|
||||||
|
mMockProviderModelSlice.doCarrierNetworkAction(false /* isToggleAction */,
|
||||||
|
false /* isDataEnabled */);
|
||||||
|
|
||||||
|
verify(mMockNetworkProviderWorker, never()).connectCarrierNetwork();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,9 @@ package com.android.settings.panel;
|
|||||||
|
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_APM;
|
import static com.android.settings.network.InternetUpdater.INTERNET_APM;
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
|
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
|
||||||
|
import static com.android.settings.network.InternetUpdater.INTERNET_CELLULAR;
|
||||||
|
import static com.android.settings.network.InternetUpdater.INTERNET_ETHERNET;
|
||||||
|
import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -26,10 +29,13 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
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.network.AirplaneModePreferenceController;
|
||||||
|
import com.android.settings.slices.CustomSliceRegistry;
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
import com.android.settings.testutils.ResourcesUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -40,6 +46,8 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class InternetConnectivityPanelTest {
|
public class InternetConnectivityPanelTest {
|
||||||
|
|
||||||
@@ -47,6 +55,10 @@ public class InternetConnectivityPanelTest {
|
|||||||
ApplicationProvider.getApplicationContext(), "provider_internet_settings");
|
ApplicationProvider.getApplicationContext(), "provider_internet_settings");
|
||||||
public static final String TITLE_APM_NETWORKS = ResourcesUtils.getResourcesString(
|
public static final String TITLE_APM_NETWORKS = ResourcesUtils.getResourcesString(
|
||||||
ApplicationProvider.getApplicationContext(), "airplane_mode_network_panel_title");
|
ApplicationProvider.getApplicationContext(), "airplane_mode_network_panel_title");
|
||||||
|
public static final String SUBTITLE_APM_IS_ON = ResourcesUtils.getResourcesString(
|
||||||
|
ApplicationProvider.getApplicationContext(), "condition_airplane_title");
|
||||||
|
public static final String BUTTON_SETTINGS = ResourcesUtils.getResourcesString(
|
||||||
|
ApplicationProvider.getApplicationContext(), "settings_button");
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final MockitoRule mMocks = MockitoJUnit.rule();
|
public final MockitoRule mMocks = MockitoJUnit.rule();
|
||||||
@@ -66,30 +78,147 @@ public class InternetConnectivityPanelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTitle_internetTypeChangedFromApmToApmNetworks_verifyTitleChanged() {
|
public void getTitle_internetApmNetworks_shouldBeApmNetworks() {
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
|
||||||
|
assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getTitle_notInternetApmNetworks_shouldBeInternet() {
|
||||||
mPanel.onInternetTypeChanged(INTERNET_APM);
|
mPanel.onInternetTypeChanged(INTERNET_APM);
|
||||||
|
|
||||||
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
|
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_WIFI);
|
||||||
|
|
||||||
|
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
|
||||||
|
|
||||||
|
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
|
||||||
|
|
||||||
|
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSubTitle_internetApm_shouldBeApmIsOn() {
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM);
|
||||||
|
|
||||||
|
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_APM_IS_ON);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSubTitle_notinternetApm_shouldBeNull() {
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
|
||||||
|
assertThat(mPanel.getSubTitle()).isNull();
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_WIFI);
|
||||||
|
|
||||||
|
assertThat(mPanel.getSubTitle()).isNull();
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
|
||||||
|
|
||||||
|
assertThat(mPanel.getSubTitle()).isNull();
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
|
||||||
|
|
||||||
|
assertThat(mPanel.getSubTitle()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getCustomizedButtonTitle_internetApm_shouldBeNull() {
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM);
|
||||||
|
|
||||||
|
assertThat(mPanel.getCustomizedButtonTitle()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getCustomizedButtonTitle_notInternetApm_shouldBeSettings() {
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
|
||||||
|
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_WIFI);
|
||||||
|
|
||||||
|
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
|
||||||
|
|
||||||
|
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
|
||||||
|
|
||||||
|
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSlices_providerModelDisabled_containsNecessarySlices() {
|
||||||
|
mPanel.mIsProviderModelEnabled = false;
|
||||||
|
final List<Uri> uris = mPanel.getSlices();
|
||||||
|
|
||||||
|
assertThat(uris).containsExactly(
|
||||||
|
AirplaneModePreferenceController.SLICE_URI,
|
||||||
|
CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
|
||||||
|
CustomSliceRegistry.WIFI_SLICE_URI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSlices_providerModelEnabled_containsNecessarySlices() {
|
||||||
|
final List<Uri> uris = mPanel.getSlices();
|
||||||
|
|
||||||
|
assertThat(uris).containsExactly(
|
||||||
|
CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
|
||||||
|
CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSeeMoreIntent_notNull() {
|
||||||
|
assertThat(mPanel.getSeeMoreIntent()).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onInternetTypeChanged_internetTypeChangedToApm_changeHeaderAndHideSettings() {
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
clearInvocations(mPanelContentCallback);
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM);
|
||||||
|
|
||||||
|
verify(mPanelContentCallback).onHeaderChanged();
|
||||||
|
verify(mPanelContentCallback).onCustomizedButtonStateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onInternetTypeChanged_internetTypeChangedFomApm_changeTitleAndShowSettings() {
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM);
|
||||||
|
clearInvocations(mPanelContentCallback);
|
||||||
|
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
|
||||||
|
verify(mPanelContentCallback).onTitleChanged();
|
||||||
|
verify(mPanelContentCallback).onCustomizedButtonStateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onInternetTypeChanged_internetTypeChangedToApmNetworks_changeTitle() {
|
||||||
|
mPanel.onInternetTypeChanged(INTERNET_WIFI);
|
||||||
clearInvocations(mPanelContentCallback);
|
clearInvocations(mPanelContentCallback);
|
||||||
|
|
||||||
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
|
||||||
assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
|
|
||||||
verify(mPanelContentCallback).onTitleChanged();
|
verify(mPanelContentCallback).onTitleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTitle_internetTypeChangedFromApmNetworksToApm_verifyTitleChanged() {
|
public void onInternetTypeChanged_internetTypeChangedFromApmNetworks_changeTitle() {
|
||||||
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
|
||||||
assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
|
|
||||||
|
|
||||||
clearInvocations(mPanelContentCallback);
|
clearInvocations(mPanelContentCallback);
|
||||||
|
|
||||||
mPanel.onInternetTypeChanged(INTERNET_APM);
|
mPanel.onInternetTypeChanged(INTERNET_WIFI);
|
||||||
|
|
||||||
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
|
|
||||||
verify(mPanelContentCallback).onTitleChanged();
|
verify(mPanelContentCallback).onTitleChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user