Merge changes from topic "launch_wifi_details-sc-aosp" into sc-v2-dev-plus-aosp
* changes: Refactor InternetIconInjector to SettingsLib [Provider Model] Cherry-pick from ag/15243691, ag/15287619, ag/15287620 and ag/15270751 [ProviderModel] Cherry-pick from master ag/15207286, ag/15216391 and ag/15205988
This commit is contained in:
@@ -20,10 +20,13 @@ import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_
|
||||
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.getMaxNetworkSelectionDisableReason;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.NetworkSelectionStatus;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -36,6 +39,23 @@ public class WifiUtils {
|
||||
|
||||
private static final int INVALID_RSSI = -127;
|
||||
|
||||
/**
|
||||
* The intent action shows network details settings to allow configuration of Wi-Fi.
|
||||
* <p>
|
||||
* In some cases, a matching Activity may not exist, so ensure you
|
||||
* safeguard against this.
|
||||
* <p>
|
||||
* Input: The calling package should put the chosen
|
||||
* com.android.wifitrackerlib.WifiEntry#getKey() to a string extra in the request bundle into
|
||||
* the {@link #KEY_CHOSEN_WIFIENTRY_KEY}.
|
||||
* <p>
|
||||
* Output: Nothing.
|
||||
*/
|
||||
public static final String ACTION_WIFI_DETAILS_SETTINGS =
|
||||
"android.settings.WIFI_DETAILS_SETTINGS";
|
||||
public static final String KEY_CHOSEN_WIFIENTRY_KEY = "key_chosen_wifientry_key";
|
||||
public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
|
||||
|
||||
static final int[] WIFI_PIE = {
|
||||
com.android.internal.R.drawable.ic_wifi_signal_0,
|
||||
com.android.internal.R.drawable.ic_wifi_signal_1,
|
||||
@@ -275,7 +295,42 @@ public class WifiUtils {
|
||||
return noInternet ? NO_INTERNET_WIFI_PIE[level] : WIFI_PIE[level];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper the {@link #getInternetIconResource} for testing compatibility.
|
||||
*/
|
||||
public static class InternetIconInjector {
|
||||
|
||||
protected final Context mContext;
|
||||
|
||||
public InternetIconInjector(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Internet icon for a given RSSI level.
|
||||
*
|
||||
* @param noInternet True if a connected Wi-Fi network cannot access the Internet
|
||||
* @param level The number of bars to show (0-4)
|
||||
*/
|
||||
public Drawable getIcon(boolean noInternet, int level) {
|
||||
return mContext.getDrawable(WifiUtils.getInternetIconResource(level, noInternet));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMeteredOverridden(WifiConfiguration config) {
|
||||
return config.meteredOverride != WifiConfiguration.METERED_OVERRIDE_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Intent for Wi-Fi network details settings.
|
||||
*
|
||||
* @param key The Wi-Fi entry key
|
||||
*/
|
||||
public static Intent getWifiDetailsSettingsIntent(String key) {
|
||||
final Intent intent = new Intent(ACTION_WIFI_DETAILS_SETTINGS);
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(KEY_CHOSEN_WIFIENTRY_KEY, key);
|
||||
intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, bundle);
|
||||
return intent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,12 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.NetworkKey;
|
||||
import android.net.RssiCurve;
|
||||
import android.net.ScoredNetwork;
|
||||
@@ -36,6 +39,8 @@ import android.os.SystemClock;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settingslib.R;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -44,7 +49,6 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
@@ -69,7 +73,7 @@ public class WifiUtilsTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,6 +152,32 @@ public class WifiUtilsTest {
|
||||
assertThat(WifiUtils.isMeteredOverridden(mWifiConfig)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiDetailsSettingsIntent_returnsCorrectValues() {
|
||||
final String key = "test_key";
|
||||
|
||||
final Intent intent = WifiUtils.getWifiDetailsSettingsIntent(key);
|
||||
|
||||
assertThat(intent.getAction()).isEqualTo(WifiUtils.ACTION_WIFI_DETAILS_SETTINGS);
|
||||
final Bundle bundle = intent.getBundleExtra(WifiUtils.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||
assertThat(bundle.getString(WifiUtils.KEY_CHOSEN_WIFIENTRY_KEY)).isEqualTo(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInternetIconInjector_getIcon_returnsCorrectValues() {
|
||||
WifiUtils.InternetIconInjector iconInjector = new WifiUtils.InternetIconInjector(mContext);
|
||||
|
||||
for (int level = 0; level <= 4; level++) {
|
||||
iconInjector.getIcon(false /* noInternet */, level);
|
||||
verify(mContext).getDrawable(
|
||||
WifiUtils.getInternetIconResource(level, false /* noInternet */));
|
||||
|
||||
iconInjector.getIcon(true /* noInternet */, level);
|
||||
verify(mContext).getDrawable(
|
||||
WifiUtils.getInternetIconResource(level, true /* noInternet */));
|
||||
}
|
||||
}
|
||||
|
||||
private static ArrayList<ScanResult> buildScanResultCache() {
|
||||
ArrayList<ScanResult> scanResults = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
@@ -27,15 +27,16 @@
|
||||
android:layout_width="match_parent"
|
||||
style="@style/Widget.SliceView.Panel"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/internet_dialog_title"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="32dp"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:fontFamily="google-sans"
|
||||
android:textSize="24sp"/>
|
||||
@@ -44,7 +45,8 @@
|
||||
android:id="@+id/internet_dialog_subtitle"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:fontFamily="google-sans"
|
||||
@@ -56,296 +58,309 @@
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/internet_list"
|
||||
<ProgressBar
|
||||
android:id="@+id/wifi_searching_progress"
|
||||
android:indeterminate="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:minHeight="1dp"
|
||||
android:maxHeight="1dp"
|
||||
style="@*android:style/Widget.Material.ProgressBar.Horizontal"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/mobile_network_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="88dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginRight="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginLeft="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
||||
android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:clickable="false"
|
||||
android:layout_gravity="center_vertical|start">
|
||||
<ImageView
|
||||
android:id="@+id/signal_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/mobile_network_list"
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start|center_vertical">
|
||||
<TextView
|
||||
android:id="@+id/mobile_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
<TextView
|
||||
android:id="@+id/mobile_summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp">
|
||||
<Switch
|
||||
android:id="@+id/mobile_toggle"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:track="@drawable/settingslib_track_selector"
|
||||
android:thumb="@drawable/settingslib_thumb_selector"
|
||||
android:theme="@style/MainSwitch.Settingslib"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/wifi_searching_progress"
|
||||
android:indeterminate="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="1dp"
|
||||
android:maxHeight="1dp"
|
||||
style="@*android:style/Widget.Material.ProgressBar.Horizontal"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/turn_on_wifi_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginRight="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginLeft="@dimen/settingslib_switchbar_margin"
|
||||
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
||||
android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:text="@string/turn_on_wifi"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start|center_vertical"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
<Switch
|
||||
android:id="@+id/wifi_toggle"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:track="@drawable/settingslib_track_selector"
|
||||
android:thumb="@drawable/settingslib_thumb_selector"
|
||||
android:theme="@style/MainSwitch.Settingslib"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/wifi_connected_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:visibility="gone"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginRight="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginLeft="@dimen/settingslib_switchbar_margin"
|
||||
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
||||
android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:clickable="false"
|
||||
android:layout_gravity="center_vertical|start">
|
||||
<ImageView
|
||||
android:id="@+id/wifi_connected_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_weight="3"
|
||||
android:id="@+id/wifi_connected_list"
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="72dp"
|
||||
android:gravity="start|center_vertical">
|
||||
<TextView
|
||||
android:id="@+id/wifi_connected_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
<TextView
|
||||
android:id="@+id/wifi_connected_summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginRight="5dp"
|
||||
android:clickable="false"
|
||||
android:gravity="center">
|
||||
<ImageView
|
||||
android:id="@+id/wifi_settings_icon"
|
||||
android:src="@drawable/ic_settings_24dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="wrap_content"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/wifi_list_layout"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:overScrollMode="never"
|
||||
android:nestedScrollingEnabled="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/see_all_layout"
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
||||
android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:clickable="false"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:layout_marginStart="16dp">
|
||||
<ImageView
|
||||
android:id="@+id/arrow_forward"
|
||||
android:src="@drawable/ic_arrow_forward"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/scroll_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:id="@+id/internet_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
</FrameLayout>
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp">
|
||||
<TextView
|
||||
android:text="@string/see_all_networks"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start|center_vertical"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</FrameLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/mobile_network_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="88dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginRight="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginLeft="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:paddingStart="19dp"
|
||||
android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
|
||||
|
||||
</LinearLayout>
|
||||
<FrameLayout
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:clickable="false"
|
||||
android:layout_gravity="center_vertical|start">
|
||||
<ImageView
|
||||
android:id="@+id/signal_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
</FrameLayout>
|
||||
|
||||
<Space
|
||||
android:id="@+id/space"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="28dp"
|
||||
android:visibility="gone"/>
|
||||
<LinearLayout
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/mobile_network_list"
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start|center_vertical">
|
||||
<TextView
|
||||
android:id="@+id/mobile_title"
|
||||
android:layout_marginLeft="17dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
<TextView
|
||||
android:id="@+id/mobile_summary"
|
||||
android:layout_marginLeft="17dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginBottom="25dp"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal">
|
||||
<Button
|
||||
style="@*android:style/Widget.DeviceDefault.Button.Borderless.Colored"
|
||||
android:id="@+id/done"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:layout_gravity="end"
|
||||
android:background="@drawable/internet_dialog_footer_background"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:text="@string/inline_done_button"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</LinearLayout>
|
||||
<FrameLayout
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="end|center_vertical">
|
||||
<Switch
|
||||
android:id="@+id/mobile_toggle"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:track="@drawable/settingslib_track_selector"
|
||||
android:thumb="@drawable/settingslib_thumb_selector"
|
||||
android:theme="@style/MainSwitch.Settingslib"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/turn_on_wifi_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginRight="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginLeft="@dimen/settingslib_switchbar_margin"
|
||||
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
||||
android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:text="@string/turn_on_wifi"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start|center_vertical"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
<Switch
|
||||
android:id="@+id/wifi_toggle"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:track="@drawable/settingslib_track_selector"
|
||||
android:thumb="@drawable/settingslib_thumb_selector"
|
||||
android:theme="@style/MainSwitch.Settingslib"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/wifi_connected_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="72dp"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:visibility="gone"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginRight="@dimen/settingslib_switchbar_margin"
|
||||
android:layout_marginLeft="@dimen/settingslib_switchbar_margin"
|
||||
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
||||
android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:clickable="false"
|
||||
android:layout_gravity="center_vertical|start">
|
||||
<ImageView
|
||||
android:id="@+id/wifi_connected_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_weight="3"
|
||||
android:id="@+id/wifi_connected_list"
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="72dp"
|
||||
android:gravity="start|center_vertical">
|
||||
<TextView
|
||||
android:id="@+id/wifi_connected_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
<TextView
|
||||
android:id="@+id/wifi_connected_summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginRight="5dp"
|
||||
android:clickable="false"
|
||||
android:gravity="center">
|
||||
<ImageView
|
||||
android:id="@+id/wifi_settings_icon"
|
||||
android:src="@drawable/ic_settings_24dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="wrap_content"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/wifi_list_layout"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:overScrollMode="never"
|
||||
android:nestedScrollingEnabled="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/see_all_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="@dimen/settingslib_switchbar_padding_left"
|
||||
android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:clickable="false"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:layout_marginStart="16dp">
|
||||
<ImageView
|
||||
android:id="@+id/arrow_forward"
|
||||
android:src="@drawable/ic_arrow_forward"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp">
|
||||
<TextView
|
||||
android:text="@string/see_all_networks"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="start|center_vertical"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:id="@+id/space"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="28dp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginBottom="25dp"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal">
|
||||
<Button
|
||||
style="@*android:style/Widget.DeviceDefault.Button.Borderless.Colored"
|
||||
android:id="@+id/done"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:layout_gravity="end"
|
||||
android:background="@drawable/internet_dialog_footer_background"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:text="@string/inline_done_button"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="google-sans"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -53,6 +53,7 @@ import com.android.systemui.qs.logging.QSLogger;
|
||||
import com.android.systemui.qs.tileimpl.QSTileImpl;
|
||||
import com.android.systemui.qs.tiles.dialog.InternetDialogFactory;
|
||||
import com.android.systemui.statusbar.policy.NetworkController;
|
||||
import com.android.systemui.statusbar.policy.NetworkController.AccessPointController;
|
||||
import com.android.systemui.statusbar.policy.NetworkController.IconState;
|
||||
import com.android.systemui.statusbar.policy.NetworkController.MobileDataIndicators;
|
||||
import com.android.systemui.statusbar.policy.NetworkController.SignalCallback;
|
||||
@@ -69,6 +70,7 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
private static final Intent WIFI_SETTINGS = new Intent(Settings.ACTION_WIFI_SETTINGS);
|
||||
|
||||
protected final NetworkController mController;
|
||||
private final AccessPointController mAccessPointController;
|
||||
private final DataUsageController mDataController;
|
||||
// The last updated tile state, 0: mobile, 1: wifi, 2: ethernet.
|
||||
private int mLastTileState = -1;
|
||||
@@ -88,6 +90,7 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
ActivityStarter activityStarter,
|
||||
QSLogger qsLogger,
|
||||
NetworkController networkController,
|
||||
AccessPointController accessPointController,
|
||||
InternetDialogFactory internetDialogFactory
|
||||
) {
|
||||
super(host, backgroundLooper, mainHandler, falsingManager, metricsLogger,
|
||||
@@ -95,6 +98,7 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
mInternetDialogFactory = internetDialogFactory;
|
||||
mHandler = mainHandler;
|
||||
mController = networkController;
|
||||
mAccessPointController = accessPointController;
|
||||
mDataController = mController.getMobileDataController();
|
||||
mController.observe(getLifecycle(), mSignalCallback);
|
||||
}
|
||||
@@ -118,9 +122,8 @@ public class InternetTile extends QSTileImpl<SignalState> {
|
||||
|
||||
@Override
|
||||
protected void handleClick(@Nullable View view) {
|
||||
mHandler.post(() -> {
|
||||
mInternetDialogFactory.create(true);
|
||||
});
|
||||
boolean canConfigMobileData = mAccessPointController.canConfigMobileData();
|
||||
mHandler.post(() -> mInternetDialogFactory.create(true, canConfigMobileData));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -174,10 +174,7 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
||||
Html.fromHtml(wifiEntry.getSummary(false), Html.FROM_HTML_MODE_LEGACY));
|
||||
|
||||
mWifiListLayout.setOnClickListener(v -> {
|
||||
if (!isOpenNetwork(security)) {
|
||||
// Popup Wi-Fi password dialog condition:
|
||||
// 1. The access point is a non-open network.
|
||||
// 2. The Wi-Fi connection is not connected with this access point.
|
||||
if (wifiEntry.shouldEditBeforeConnect()) {
|
||||
final Intent intent = new Intent(ACTION_WIFI_DIALOG);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package com.android.systemui.qs.tiles.dialog;
|
||||
|
||||
import static android.view.WindowInsets.Type.navigationBars;
|
||||
import static android.view.WindowInsets.Type.statusBars;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
|
||||
|
||||
import static com.android.systemui.Prefs.Key.QS_HAS_TURNED_OFF_MOBILE_DATA;
|
||||
|
||||
@@ -56,6 +55,10 @@ import android.widget.Space;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.internal.logging.UiEvent;
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.settingslib.Utils;
|
||||
@@ -68,10 +71,6 @@ import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Dialog for showing mobile network, connected Wi-Fi network and Wi-Fi networks.
|
||||
*/
|
||||
@@ -127,6 +126,7 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
private int mListMaxHeight;
|
||||
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
private boolean mIsProgressBarVisible;
|
||||
private boolean mCanConfigMobileData;
|
||||
|
||||
private final ViewTreeObserver.OnGlobalLayoutListener mInternetListLayoutListener = () -> {
|
||||
// Set max height for list
|
||||
@@ -138,7 +138,7 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
};
|
||||
|
||||
public InternetDialog(Context context, InternetDialogFactory internetDialogFactory,
|
||||
InternetDialogController internetDialogController,
|
||||
InternetDialogController internetDialogController, boolean canConfigMobileData,
|
||||
boolean aboveStatusBar, UiEventLogger uiEventLogger, @Main Handler handler) {
|
||||
super(context, R.style.Theme_SystemUI_Dialog_Internet);
|
||||
if (DEBUG) {
|
||||
@@ -152,6 +152,7 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
mDefaultDataSubId = mInternetDialogController.getDefaultDataSubscriptionId();
|
||||
mTelephonyManager = mInternetDialogController.getTelephonyManager();
|
||||
mWifiManager = mInternetDialogController.getWifiManager();
|
||||
mCanConfigMobileData = canConfigMobileData;
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(mContext) {
|
||||
@Override
|
||||
@@ -166,7 +167,6 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
if (!aboveStatusBar) {
|
||||
getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
|
||||
}
|
||||
show();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,16 +179,19 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
mDialogView = LayoutInflater.from(mContext).inflate(R.layout.internet_connectivity_dialog,
|
||||
null);
|
||||
final Window window = getWindow();
|
||||
final WindowManager.LayoutParams lp = window.getAttributes();
|
||||
lp.gravity = Gravity.BOTTOM;
|
||||
lp.setFitInsetsTypes(statusBars() | navigationBars());
|
||||
lp.setFitInsetsSides(WindowInsets.Side.all());
|
||||
lp.setFitInsetsIgnoringVisibility(true);
|
||||
window.setAttributes(lp);
|
||||
final WindowManager.LayoutParams layoutParams = window.getAttributes();
|
||||
layoutParams.gravity = Gravity.BOTTOM;
|
||||
// Move down the dialog to overlay the navigation bar.
|
||||
layoutParams.setFitInsetsTypes(
|
||||
layoutParams.getFitInsetsTypes() & ~WindowInsets.Type.navigationBars());
|
||||
layoutParams.setFitInsetsSides(WindowInsets.Side.all());
|
||||
layoutParams.setFitInsetsIgnoringVisibility(true);
|
||||
window.setAttributes(layoutParams);
|
||||
window.setContentView(mDialogView);
|
||||
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
window.setWindowAnimations(R.style.Animation_InternetDialog);
|
||||
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
window.addFlags(FLAG_LAYOUT_NO_LIMITS);
|
||||
|
||||
mInternetDialogTitle = mDialogView.requireViewById(R.id.internet_dialog_title);
|
||||
mInternetDialogSubTitle = mDialogView.requireViewById(R.id.internet_dialog_subtitle);
|
||||
@@ -297,9 +300,7 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
isChecked, false);
|
||||
}
|
||||
});
|
||||
mConnectedWifListLayout.setOnClickListener(v -> {
|
||||
// TODO(b/191475923): Need to launch the detailed page of Wi-Fi entry.
|
||||
});
|
||||
mConnectedWifListLayout.setOnClickListener(v -> onClickConnectedWifi());
|
||||
mSeeAllLayout.setOnClickListener(v -> onClickSeeMoreButton());
|
||||
mWiFiToggle.setOnCheckedChangeListener(
|
||||
(buttonView, isChecked) -> {
|
||||
@@ -318,8 +319,13 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
mMobileDataToggle.setChecked(mInternetDialogController.isMobileDataEnabled());
|
||||
mMobileNetworkLayout.setVisibility(View.VISIBLE);
|
||||
mMobileTitleText.setText(getMobileNetworkTitle());
|
||||
mMobileSummaryText.setText(
|
||||
Html.fromHtml(getMobileNetworkSummary(), Html.FROM_HTML_MODE_LEGACY));
|
||||
if (!TextUtils.isEmpty(getMobileNetworkSummary())) {
|
||||
mMobileSummaryText.setText(
|
||||
Html.fromHtml(getMobileNetworkSummary(), Html.FROM_HTML_MODE_LEGACY));
|
||||
mMobileSummaryText.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mMobileSummaryText.setVisibility(View.GONE);
|
||||
}
|
||||
mSignalIcon.setImageDrawable(getSignalStrengthDrawable());
|
||||
int titleColor = isCellularNetwork ? mContext.getColor(
|
||||
R.color.connected_network_primary_color) : Utils.getColorAttrDefaultColor(
|
||||
@@ -330,6 +336,8 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
mMobileTitleText.setTextColor(titleColor);
|
||||
mMobileSummaryText.setTextColor(summaryColor);
|
||||
mMobileNetworkLayout.setBackground(isCellularNetwork ? mBackgroundOn : null);
|
||||
|
||||
mMobileDataToggle.setVisibility(mCanConfigMobileData ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,6 +361,10 @@ public class InternetDialog extends SystemUIDialog implements
|
||||
mConnectedWifListLayout.setBackground(mBackgroundOn);
|
||||
}
|
||||
|
||||
void onClickConnectedWifi() {
|
||||
mInternetDialogController.launchWifiNetworkDetailsSetting();
|
||||
}
|
||||
|
||||
void onClickSeeMoreButton() {
|
||||
mInternetDialogController.launchNetworkSetting();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.AccessNetworkConstants;
|
||||
import android.telephony.NetworkRegistrationInfo;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SignalStrength;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
@@ -48,6 +50,10 @@ import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback;
|
||||
@@ -56,6 +62,7 @@ import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.graph.SignalDrawable;
|
||||
import com.android.settingslib.mobile.MobileMappings;
|
||||
import com.android.settingslib.net.SignalStrengthUtil;
|
||||
import com.android.settingslib.wifi.WifiUtils;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
@@ -78,10 +85,6 @@ import java.util.stream.Stream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
NetworkController.AccessPointController.AccessPointCallback {
|
||||
|
||||
@@ -104,7 +107,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
private Context mContext;
|
||||
private ActivityStarter mActivityStarter;
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@@ -115,16 +117,19 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
private MobileMappings.Config mConfig = null;
|
||||
private Executor mExecutor;
|
||||
private AccessPointController mAccessPointController;
|
||||
private IntentFilter mWifiStateFilter;
|
||||
private IntentFilter mConnectionStateFilter;
|
||||
private InternetDialogCallback mCallback;
|
||||
private List<WifiEntry> mWifiEntry;
|
||||
private WifiEntry mConnectedEntry;
|
||||
private UiEventLogger mUiEventLogger;
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
private GlobalSettings mGlobalSettings;
|
||||
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
@VisibleForTesting
|
||||
protected ActivityStarter mActivityStarter;
|
||||
@VisibleForTesting
|
||||
protected WifiEntry mConnectedEntry;
|
||||
@VisibleForTesting
|
||||
protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener;
|
||||
@VisibleForTesting
|
||||
@@ -168,8 +173,10 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
mSubscriptionManager = subscriptionManager;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mKeyguardUpdateMonitor = keyguardUpdateMonitor;
|
||||
mWifiStateFilter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
mWifiStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
mConnectionStateFilter = new IntentFilter();
|
||||
mConnectionStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
mConnectionStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
mConnectionStateFilter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
|
||||
mUiEventLogger = uiEventLogger;
|
||||
mActivityStarter = starter;
|
||||
mAccessPointController = accessPointController;
|
||||
@@ -183,12 +190,16 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
mCallback = callback;
|
||||
mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateCallback);
|
||||
mAccessPointController.addAccessPointCallback(this);
|
||||
mBroadcastDispatcher.registerReceiver(mWifiStateReceiver, mWifiStateFilter, mExecutor);
|
||||
mBroadcastDispatcher.registerReceiver(mConnectionStateReceiver, mConnectionStateFilter,
|
||||
mExecutor);
|
||||
// Listen the subscription changes
|
||||
mOnSubscriptionsChangedListener = new InternetOnSubscriptionChangedListener();
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
|
||||
mOnSubscriptionsChangedListener);
|
||||
mDefaultDataSubId = getDefaultDataSubscriptionId();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Init, SubId: " + mDefaultDataSubId);
|
||||
}
|
||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId);
|
||||
mInternetTelephonyCallback = new InternetTelephonyCallback();
|
||||
mTelephonyManager.registerTelephonyCallback(mExecutor, mInternetTelephonyCallback);
|
||||
@@ -203,7 +214,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onStop");
|
||||
}
|
||||
mBroadcastDispatcher.unregisterReceiver(mWifiStateReceiver);
|
||||
mBroadcastDispatcher.unregisterReceiver(mConnectionStateReceiver);
|
||||
mTelephonyManager.unregisterTelephonyCallback(mInternetTelephonyCallback);
|
||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(
|
||||
mOnSubscriptionsChangedListener);
|
||||
@@ -226,6 +237,17 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
return new Intent(ACTION_NETWORK_PROVIDER_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
|
||||
protected Intent getWifiDetailsSettingsIntent() {
|
||||
String key = mConnectedEntry == null ? null : mConnectedEntry.getKey();
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "connected entry's key is empty");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return WifiUtils.getWifiDetailsSettingsIntent(key);
|
||||
}
|
||||
|
||||
CharSequence getDialogTitleText() {
|
||||
if (isAirplaneModeEnabled()) {
|
||||
return mContext.getText(R.string.airplane_mode);
|
||||
@@ -533,6 +555,14 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
mActivityStarter.postStartActivityDismissingKeyguard(getSettingsIntent(), 0);
|
||||
}
|
||||
|
||||
void launchWifiNetworkDetailsSetting() {
|
||||
Intent intent = getWifiDetailsSettingsIntent();
|
||||
if (intent != null) {
|
||||
mCallback.dismissDialog();
|
||||
mActivityStarter.postStartActivityDismissingKeyguard(intent, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void connectCarrierNetwork() {
|
||||
final MergedCarrierEntry mergedCarrierEntry =
|
||||
mAccessPointController.getMergedCarrierEntry();
|
||||
@@ -626,13 +656,12 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
}
|
||||
|
||||
boolean isDataStateInService() {
|
||||
if (mTelephonyManager == null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "TelephonyManager is null, can not detect mobile state.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return mTelephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED;
|
||||
final ServiceState serviceState = mTelephonyManager.getServiceState();
|
||||
NetworkRegistrationInfo regInfo =
|
||||
(serviceState == null) ? null : serviceState.getNetworkRegistrationInfo(
|
||||
NetworkRegistrationInfo.DOMAIN_PS,
|
||||
AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
|
||||
return (regInfo == null) ? false : regInfo.isRegistered();
|
||||
}
|
||||
|
||||
boolean isVoiceStateInService() {
|
||||
@@ -793,15 +822,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
|
||||
@Override
|
||||
public void onSubscriptionsChanged() {
|
||||
mDefaultDataSubId = getDefaultDataSubscriptionId();
|
||||
if (SubscriptionManager.isUsableSubscriptionId(mDefaultDataSubId)) {
|
||||
mTelephonyManager.unregisterTelephonyCallback(mInternetTelephonyCallback);
|
||||
|
||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId);
|
||||
mTelephonyManager.registerTelephonyCallback(mHandler::post,
|
||||
mInternetTelephonyCallback);
|
||||
mCallback.onSubscriptionsChanged(mDefaultDataSubId);
|
||||
}
|
||||
updateListener();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -817,13 +838,46 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
||||
}
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mWifiStateReceiver = new BroadcastReceiver() {
|
||||
private final BroadcastReceiver mConnectionStateReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mCallback.onWifiStateReceived(context, intent);
|
||||
final String action = intent.getAction();
|
||||
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)
|
||||
|| action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
||||
mCallback.onWifiStateReceived(context, intent);
|
||||
}
|
||||
|
||||
if (action.equals(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED");
|
||||
}
|
||||
updateListener();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void updateListener() {
|
||||
int defaultDataSubId = getDefaultDataSubscriptionId();
|
||||
if (mDefaultDataSubId == getDefaultDataSubscriptionId()) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "DDS: no change");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
mDefaultDataSubId = defaultDataSubId;
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "DDS: defaultDataSubId:" + mDefaultDataSubId);
|
||||
}
|
||||
if (SubscriptionManager.isUsableSubscriptionId(mDefaultDataSubId)) {
|
||||
mTelephonyManager.unregisterTelephonyCallback(mInternetTelephonyCallback);
|
||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mDefaultDataSubId);
|
||||
mTelephonyManager.registerTelephonyCallback(mHandler::post,
|
||||
mInternetTelephonyCallback);
|
||||
mCallback.onSubscriptionsChanged(mDefaultDataSubId);
|
||||
}
|
||||
}
|
||||
|
||||
interface InternetDialogCallback {
|
||||
|
||||
void onRefreshCarrierInfo();
|
||||
|
||||
@@ -41,15 +41,16 @@ class InternetDialogFactory @Inject constructor(
|
||||
}
|
||||
|
||||
/** Creates a [InternetDialog]. */
|
||||
fun create(aboveStatusBar: Boolean) {
|
||||
fun create(aboveStatusBar: Boolean, canConfigMobileData: Boolean) {
|
||||
if (internetDialog != null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "InternetDialog is showing, do not create it twice.")
|
||||
}
|
||||
return
|
||||
} else {
|
||||
internetDialog = InternetDialog(context, this, internetDialogController, aboveStatusBar,
|
||||
uiEventLogger, handler)
|
||||
internetDialog = InternetDialog(context, this, internetDialogController,
|
||||
canConfigMobileData, aboveStatusBar, uiEventLogger, handler)
|
||||
internetDialog?.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +119,11 @@ public class AccessPointControllerImpl
|
||||
new UserHandle(mCurrentUser));
|
||||
}
|
||||
|
||||
public boolean canConfigMobileData() {
|
||||
return !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,
|
||||
UserHandle.of(mCurrentUser));
|
||||
}
|
||||
|
||||
public void onUserSwitched(int newUserId) {
|
||||
mCurrentUser = newUserId;
|
||||
}
|
||||
|
||||
@@ -228,6 +228,7 @@ public interface NetworkController extends CallbackController<SignalCallback>, D
|
||||
int getIcon(WifiEntry ap);
|
||||
boolean connect(WifiEntry ap);
|
||||
boolean canConfigWifi();
|
||||
boolean canConfigMobileData();
|
||||
|
||||
public interface AccessPointCallback {
|
||||
void onAccessPointsChanged(List<WifiEntry> accessPoints);
|
||||
|
||||
@@ -793,7 +793,8 @@ public class NetworkControllerImpl extends BroadcastReceiver
|
||||
mReceiverHandler.post(this::handleConfigurationChanged);
|
||||
break;
|
||||
case Settings.Panel.ACTION_INTERNET_CONNECTIVITY:
|
||||
mMainHandler.post(() -> mInternetDialogFactory.create(true));
|
||||
boolean canConfigMobileData = mAccessPoints.canConfigMobileData();
|
||||
mMainHandler.post(() -> mInternetDialogFactory.create(true, canConfigMobileData));
|
||||
break;
|
||||
default:
|
||||
int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,
|
||||
|
||||
@@ -3,11 +3,16 @@ package com.android.systemui.qs.tiles.dialog;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
@@ -20,6 +25,9 @@ import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
@@ -33,9 +41,6 @@ import com.android.systemui.util.settings.GlobalSettings;
|
||||
import com.android.systemui.util.time.FakeSystemClock;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -68,13 +73,15 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private Handler mHandler;
|
||||
@Mock
|
||||
private ActivityStarter mActivityStarter;
|
||||
@Mock
|
||||
private GlobalSettings mGlobalSettings;
|
||||
@Mock
|
||||
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
@Mock
|
||||
private NetworkController.AccessPointController mAccessPointController;
|
||||
@Mock
|
||||
private WifiEntry mWifiEntryConnected = mock(WifiEntry.class);
|
||||
private WifiEntry mConnectedEntry;
|
||||
@Mock
|
||||
private WifiInfo mWifiInfo;
|
||||
@Mock
|
||||
@@ -94,6 +101,8 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
|
||||
mInternetDialogController.mOnSubscriptionsChangedListener);
|
||||
mInternetDialogController.onStart(mCallback);
|
||||
mInternetDialogController.mActivityStarter = mActivityStarter;
|
||||
mInternetDialogController.mConnectedEntry = mConnectedEntry;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,7 +197,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void getConnectedWifiTitle_withNoConnectedEntry_returnNull() {
|
||||
mInternetDialogController.setConnectedWifiEntry(null);
|
||||
mInternetDialogController.mConnectedEntry = null;
|
||||
|
||||
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(),
|
||||
""));
|
||||
@@ -196,8 +205,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void getConnectedWifiTitle_withConnectedEntry_returnTitle() {
|
||||
mInternetDialogController.setConnectedWifiEntry(mWifiEntryConnected);
|
||||
when(mWifiEntryConnected.getTitle()).thenReturn(CONNECTED_TITLE);
|
||||
when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE);
|
||||
|
||||
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(),
|
||||
CONNECTED_TITLE));
|
||||
@@ -205,7 +213,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void getConnectedWifiSummary_withNoConnectedEntry_returnNull() {
|
||||
mInternetDialogController.setConnectedWifiEntry(null);
|
||||
mInternetDialogController.mConnectedEntry = null;
|
||||
|
||||
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(),
|
||||
""));
|
||||
@@ -213,13 +221,52 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void getConnectedWifiSummary_withConnectedEntry_returnSummary() {
|
||||
mInternetDialogController.setConnectedWifiEntry(mWifiEntryConnected);
|
||||
when(mWifiEntryConnected.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
|
||||
when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
|
||||
|
||||
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(),
|
||||
CONNECTED_SUMMARY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiDetailsSettingsIntent_withNoConnectedEntry_returnNull() {
|
||||
mInternetDialogController.mConnectedEntry = null;
|
||||
|
||||
assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiDetailsSettingsIntent_withNoConnectedEntryKey_returnNull() {
|
||||
when(mConnectedEntry.getKey()).thenReturn(null);
|
||||
|
||||
assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiDetailsSettingsIntent_withConnectedEntryKey_returnIntent() {
|
||||
when(mConnectedEntry.getKey()).thenReturn("test_key");
|
||||
|
||||
assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWifiNetworkDetailsSetting_withNoConnectedEntry_doNothing() {
|
||||
mInternetDialogController.mConnectedEntry = null;
|
||||
|
||||
mInternetDialogController.launchWifiNetworkDetailsSetting();
|
||||
|
||||
verify(mActivityStarter, never())
|
||||
.postStartActivityDismissingKeyguard(any(Intent.class), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWifiNetworkDetailsSetting_withConnectedEntryKey_startActivity() {
|
||||
when(mConnectedEntry.getKey()).thenReturn("test_key");
|
||||
|
||||
mInternetDialogController.launchWifiNetworkDetailsSetting();
|
||||
|
||||
verify(mActivityStarter).postStartActivityDismissingKeyguard(any(Intent.class), anyInt());
|
||||
}
|
||||
|
||||
private String getResourcesString(String name) {
|
||||
return mContext.getResources().getString(getResourcesId(name));
|
||||
}
|
||||
@@ -231,7 +278,6 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
|
||||
private class MockInternetDialogController extends InternetDialogController {
|
||||
|
||||
private WifiEntry mConnectedEntry;
|
||||
private GlobalSettings mGlobalSettings;
|
||||
private boolean mIsAirplaneModeOn;
|
||||
|
||||
@@ -256,14 +302,5 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
||||
public void setAirplaneModeEnabled(boolean enabled) {
|
||||
mIsAirplaneModeOn = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
WifiEntry getConnectedWifiEntry() {
|
||||
return mConnectedEntry;
|
||||
}
|
||||
|
||||
public void setConnectedWifiEntry(WifiEntry connectedEntry) {
|
||||
mConnectedEntry = connectedEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,8 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mInternetDialog = new MockInternetDialog(mContext, mInternetDialogFactory,
|
||||
mInternetDialogController, true, mUiEventLogger, mHandler);
|
||||
mInternetDialogController, true, true, mUiEventLogger, mHandler);
|
||||
mInternetDialog.show();
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
when(mMockWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
|
||||
@@ -177,10 +178,10 @@ public class InternetDialogTest extends SysuiTestCase {
|
||||
private String mConnectedWifiSummary;
|
||||
|
||||
MockInternetDialog(Context context, InternetDialogFactory internetDialogFactory,
|
||||
InternetDialogController internetDialogController,
|
||||
InternetDialogController internetDialogController, boolean canConfigMobileData,
|
||||
boolean aboveStatusBar, UiEventLogger uiEventLogger, @Main Handler handler) {
|
||||
super(context, internetDialogFactory, internetDialogController, aboveStatusBar,
|
||||
uiEventLogger, handler);
|
||||
super(context, internetDialogFactory, internetDialogController, canConfigMobileData,
|
||||
aboveStatusBar, uiEventLogger, handler);
|
||||
mAdapter = mInternetAdapter;
|
||||
mWifiManager = mMockWifiManager;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user