Connect to network while clicking open or saved networks on slice
Test: make RunSettingsRoboTests -j Fixes: 121342770 Change-Id: I0ffb925628dd271d054f990b9b176eb10372e6a3
This commit is contained in:
@@ -2591,6 +2591,12 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".wifi.slice.ConnectToWifiHandler"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<activity android:name=".sim.SimDialogActivity"
|
<activity android:name=".sim.SimDialogActivity"
|
||||||
android:theme="@style/Theme.AlertDialog"
|
android:theme="@style/Theme.AlertDialog"
|
||||||
android:label="@string/sim_settings_title"
|
android:label="@string/sim_settings_title"
|
||||||
|
@@ -562,24 +562,24 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
* Bypass dialog and connect to unsecured networks, or previously connected saved
|
* Bypass dialog and connect to unsecured networks, or previously connected saved
|
||||||
* networks, or Passpoint provided networks.
|
* networks, or Passpoint provided networks.
|
||||||
*/
|
*/
|
||||||
WifiConfiguration config = mSelectedAccessPoint.getConfig();
|
switch (WifiUtils.getConnectingType(mSelectedAccessPoint)) {
|
||||||
if (mSelectedAccessPoint.isOsuProvider()) {
|
case WifiUtils.CONNECT_TYPE_OSU_PROVISION:
|
||||||
mSelectedAccessPoint.startOsuProvisioning();
|
mSelectedAccessPoint.startOsuProvisioning();
|
||||||
mClickedConnect = true;
|
mClickedConnect = true;
|
||||||
} else if ((mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
|
break;
|
||||||
(mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
|
|
||||||
mSelectedAccessPoint.generateOpenNetworkConfig();
|
case WifiUtils.CONNECT_TYPE_OPEN_NETWORK:
|
||||||
connect(mSelectedAccessPoint.getConfig(), mSelectedAccessPoint.isSaved());
|
mSelectedAccessPoint.generateOpenNetworkConfig();
|
||||||
} else if (mSelectedAccessPoint.isSaved() && config != null
|
connect(mSelectedAccessPoint.getConfig(), mSelectedAccessPoint.isSaved());
|
||||||
&& config.getNetworkSelectionStatus() != null
|
break;
|
||||||
&& config.getNetworkSelectionStatus().getHasEverConnected()) {
|
|
||||||
connect(config, true /* isSavedNetwork */);
|
case WifiUtils.CONNECT_TYPE_SAVED_NETWORK:
|
||||||
} else if (mSelectedAccessPoint.isPasspoint()) {
|
connect(mSelectedAccessPoint.getConfig(), true /* isSavedNetwork */);
|
||||||
// Access point provided by an installed Passpoint provider, connect using
|
break;
|
||||||
// the associated config.
|
|
||||||
connect(config, true /* isSavedNetwork */);
|
default:
|
||||||
} else {
|
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
|
||||||
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
|
break;
|
||||||
}
|
}
|
||||||
} else if (preference == mAddPreference) {
|
} else if (preference == mAddPreference) {
|
||||||
onAddNetworkPressed();
|
onAddNetworkPressed();
|
||||||
|
@@ -253,4 +253,33 @@ public class WifiUtils {
|
|||||||
|
|
||||||
return AccessPoint.SECURITY_NONE;
|
return AccessPoint.SECURITY_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final int CONNECT_TYPE_OTHERS = 0;
|
||||||
|
public static final int CONNECT_TYPE_OPEN_NETWORK = 1;
|
||||||
|
public static final int CONNECT_TYPE_SAVED_NETWORK = 2;
|
||||||
|
public static final int CONNECT_TYPE_OSU_PROVISION = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the connecting type of {@link AccessPoint}.
|
||||||
|
*/
|
||||||
|
public static int getConnectingType(AccessPoint accessPoint) {
|
||||||
|
final WifiConfiguration config = accessPoint.getConfig();
|
||||||
|
if (accessPoint.isOsuProvider()) {
|
||||||
|
return CONNECT_TYPE_OSU_PROVISION;
|
||||||
|
} else if ((accessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
|
||||||
|
(accessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
|
||||||
|
return CONNECT_TYPE_OPEN_NETWORK;
|
||||||
|
} else if (accessPoint.isSaved() && config != null
|
||||||
|
&& config.getNetworkSelectionStatus() != null
|
||||||
|
&& config.getNetworkSelectionStatus().getHasEverConnected()) {
|
||||||
|
return CONNECT_TYPE_SAVED_NETWORK;
|
||||||
|
} else if (accessPoint.isPasspoint()) {
|
||||||
|
// Access point provided by an installed Passpoint provider, connect using
|
||||||
|
// the associated config.
|
||||||
|
return CONNECT_TYPE_SAVED_NETWORK;
|
||||||
|
} else {
|
||||||
|
return CONNECT_TYPE_OTHERS;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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.wifi.slice;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import com.android.settings.wifi.WifiDialogActivity;
|
||||||
|
import com.android.settings.wifi.WifiUtils;
|
||||||
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This activity helps connect to the Wi-Fi network which is open or saved
|
||||||
|
*/
|
||||||
|
public class ConnectToWifiHandler extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
final Bundle accessPointState = getIntent().getBundleExtra(
|
||||||
|
WifiDialogActivity.KEY_ACCESS_POINT_STATE);
|
||||||
|
|
||||||
|
if (accessPointState != null) {
|
||||||
|
connect(new AccessPoint(this, accessPointState));
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void connect(AccessPoint accessPoint) {
|
||||||
|
switch (WifiUtils.getConnectingType(accessPoint)) {
|
||||||
|
case WifiUtils.CONNECT_TYPE_OSU_PROVISION:
|
||||||
|
accessPoint.startOsuProvisioning();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WifiUtils.CONNECT_TYPE_OPEN_NETWORK:
|
||||||
|
accessPoint.generateOpenNetworkConfig();
|
||||||
|
|
||||||
|
case WifiUtils.CONNECT_TYPE_SAVED_NETWORK:
|
||||||
|
final WifiManager wifiManager = getSystemService(WifiManager.class);
|
||||||
|
wifiManager.connect(accessPoint.getConfig(), null /* listener */);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -48,6 +48,7 @@ import com.android.settings.slices.SliceBackgroundWorker;
|
|||||||
import com.android.settings.slices.SliceBuilderUtils;
|
import com.android.settings.slices.SliceBuilderUtils;
|
||||||
import com.android.settings.wifi.WifiDialogActivity;
|
import com.android.settings.wifi.WifiDialogActivity;
|
||||||
import com.android.settings.wifi.WifiSettings;
|
import com.android.settings.wifi.WifiSettings;
|
||||||
|
import com.android.settings.wifi.WifiUtils;
|
||||||
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
|
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
|
||||||
import com.android.settingslib.wifi.AccessPoint;
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
import com.android.settingslib.wifi.WifiTracker;
|
import com.android.settingslib.wifi.WifiTracker;
|
||||||
@@ -176,6 +177,9 @@ public class WifiSlice implements CustomSliceable {
|
|||||||
.setArguments(extras)
|
.setArguments(extras)
|
||||||
.setSourceMetricsCategory(SettingsEnums.WIFI)
|
.setSourceMetricsCategory(SettingsEnums.WIFI)
|
||||||
.toIntent();
|
.toIntent();
|
||||||
|
} else if (WifiUtils.getConnectingType(accessPoint) != WifiUtils.CONNECT_TYPE_OTHERS) {
|
||||||
|
intent = new Intent(mContext, ConnectToWifiHandler.class);
|
||||||
|
intent.putExtra(WifiDialogActivity.KEY_ACCESS_POINT_STATE, extras);
|
||||||
} else {
|
} else {
|
||||||
intent = new Intent(mContext, WifiDialogActivity.class);
|
intent = new Intent(mContext, WifiDialogActivity.class);
|
||||||
intent.putExtra(WifiDialogActivity.KEY_ACCESS_POINT_STATE, extras);
|
intent.putExtra(WifiDialogActivity.KEY_ACCESS_POINT_STATE, extras);
|
||||||
|
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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.wifi.slice;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.net.wifi.WifiConfiguration.NetworkSelectionStatus;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
||||||
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {
|
||||||
|
ShadowConnectivityManager.class,
|
||||||
|
ShadowWifiManager.class,
|
||||||
|
})
|
||||||
|
public class ConnectToWifiHandlerTest {
|
||||||
|
|
||||||
|
private static final String AP1_SSID = "\"ap1\"";
|
||||||
|
private ConnectToWifiHandler mHandler;
|
||||||
|
private WifiConfiguration mWifiConfig;
|
||||||
|
@Mock
|
||||||
|
private AccessPoint mAccessPoint;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mHandler = Robolectric.setupActivity(ConnectToWifiHandler.class);
|
||||||
|
mWifiConfig = new WifiConfiguration();
|
||||||
|
mWifiConfig.SSID = AP1_SSID;
|
||||||
|
doReturn(mWifiConfig).when(mAccessPoint).getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void connect_shouldConnectToUnsavedOpenNetwork() {
|
||||||
|
when(mAccessPoint.isSaved()).thenReturn(false);
|
||||||
|
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_NONE);
|
||||||
|
|
||||||
|
mHandler.connect(mAccessPoint);
|
||||||
|
|
||||||
|
assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void connect_shouldStartOsuProvisioning() {
|
||||||
|
when(mAccessPoint.isSaved()).thenReturn(false);
|
||||||
|
when(mAccessPoint.isOsuProvider()).thenReturn(true);
|
||||||
|
|
||||||
|
mHandler.connect(mAccessPoint);
|
||||||
|
|
||||||
|
verify(mAccessPoint).startOsuProvisioning();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void connect_shouldConnectWithPasspointProvider() {
|
||||||
|
when(mAccessPoint.isSaved()).thenReturn(false);
|
||||||
|
when(mAccessPoint.isPasspoint()).thenReturn(true);
|
||||||
|
|
||||||
|
mHandler.connect(mAccessPoint);
|
||||||
|
|
||||||
|
assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void connect_shouldConnectToSavedSecuredNetwork() {
|
||||||
|
when(mAccessPoint.isSaved()).thenReturn(true);
|
||||||
|
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK);
|
||||||
|
final NetworkSelectionStatus status = new NetworkSelectionStatus();
|
||||||
|
status.setHasEverConnected(true);
|
||||||
|
mWifiConfig.setNetworkSelectionStatus(status);
|
||||||
|
|
||||||
|
mHandler.connect(mAccessPoint);
|
||||||
|
|
||||||
|
assertThat(ShadowWifiManager.get().savedWifiConfig.SSID).isEqualTo(AP1_SSID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void connect_shouldNotConnectToUnsavedSecuredNetwork() {
|
||||||
|
when(mAccessPoint.isSaved()).thenReturn(false);
|
||||||
|
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK);
|
||||||
|
|
||||||
|
mHandler.connect(mAccessPoint);
|
||||||
|
|
||||||
|
assertThat(ShadowWifiManager.get().savedWifiConfig).isNull();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user