Snap for 5828070 from 318be48d07 to qt-qpr1-release

Change-Id: I2742ee18bbb4269d33a1f4ccf85963ac9b7d1c80
This commit is contained in:
android-build-team Robot
2019-08-24 23:01:46 +00:00
7 changed files with 153 additions and 13 deletions

View File

@@ -135,7 +135,10 @@ public class ApnEditor extends SettingsPreferenceFragment
private int mBearerInitialVal = 0;
private String mMvnoTypeStr;
private String mMvnoMatchDataStr;
private String[] mReadOnlyApnTypes;
@VisibleForTesting
String[] mReadOnlyApnTypes;
@VisibleForTesting
String[] mDefaultApnTypes;
private String[] mReadOnlyApnFields;
private boolean mReadOnlyApn;
private Uri mCarrierUri;
@@ -189,7 +192,8 @@ public class ApnEditor extends SettingsPreferenceFragment
private static final int MMSPROXY_INDEX = 12;
private static final int MMSPORT_INDEX = 13;
private static final int AUTH_TYPE_INDEX = 14;
private static final int TYPE_INDEX = 15;
@VisibleForTesting
static final int TYPE_INDEX = 15;
private static final int PROTOCOL_INDEX = 16;
@VisibleForTesting
static final int CARRIER_ENABLED_INDEX = 17;
@@ -250,12 +254,17 @@ public class ApnEditor extends SettingsPreferenceFragment
mReadOnlyApnTypes = b.getStringArray(
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
if (!ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
for (String apnType : mReadOnlyApnTypes) {
Log.d(TAG, "onCreate: read only APN type: " + apnType);
}
Log.d(TAG,
"onCreate: read only APN type: " + Arrays.toString(mReadOnlyApnTypes));
}
mReadOnlyApnFields = b.getStringArray(
CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY);
mDefaultApnTypes = b.getStringArray(
CarrierConfigManager.KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY);
if (!ArrayUtils.isEmpty(mDefaultApnTypes)) {
Log.d(TAG, "onCreate: default apn types: " + Arrays.toString(mDefaultApnTypes));
}
}
}
@@ -1150,17 +1159,24 @@ public class ApnEditor extends SettingsPreferenceFragment
return sNotSet.equals(value) ? null : value;
}
private String getUserEnteredApnType() {
@VisibleForTesting
String getUserEnteredApnType() {
// if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY"
// but if user enter empty type, map it just for default
String userEnteredApnType = mApnType.getText();
if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim();
if ((TextUtils.isEmpty(userEnteredApnType)
|| PhoneConstants.APN_TYPE_ALL.equals(userEnteredApnType))
&& !ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
String[] apnTypeList = PhoneConstants.APN_TYPES;
if (TextUtils.isEmpty(userEnteredApnType) && !ArrayUtils.isEmpty(mDefaultApnTypes)) {
apnTypeList = mDefaultApnTypes;
}
StringBuilder editableApnTypes = new StringBuilder();
List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes);
boolean first = true;
for (String apnType : PhoneConstants.APN_TYPES) {
for (String apnType : apnTypeList) {
// add APN type if it is not read-only and is not wild-cardable
if (!readOnlyApnTypes.contains(apnType)
&& !apnType.equals(PhoneConstants.APN_TYPE_IA)

View File

@@ -390,7 +390,7 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
WifiDppUtils.getSecurityString(wifiConfiguration),
wifiConfiguration.getPrintableSsid(),
wifiConfiguration.preSharedKey,
/* hiddenSsid */ false,
wifiConfiguration.hiddenSSID,
wifiConfiguration.networkId,
/* isHotspot */ false);
}

View File

@@ -172,22 +172,25 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
// Adds all Wi-Fi networks in QR code to the set of configured networks and
// connects to it if it's reachable.
boolean hasReachableWifiNetwork = false;
boolean hasHiddenOrReachableWifiNetwork = false;
for (WifiConfiguration qrCodeWifiConfiguration : qrCodeWifiConfigurations) {
final int id = wifiManager.addNetwork(qrCodeWifiConfiguration);
if (id == -1) {
continue;
}
wifiManager.enableNetwork(id, /* attemptConnect */ false);
if (isReachableWifiNetwork(qrCodeWifiConfiguration)) {
hasReachableWifiNetwork = true;
// WifiTracker only contains a hidden SSID Wi-Fi network if it's saved.
// We can't check if a hidden SSID Wi-Fi network is reachable in advance.
if (qrCodeWifiConfiguration.hiddenSSID ||
isReachableWifiNetwork(qrCodeWifiConfiguration)) {
hasHiddenOrReachableWifiNetwork = true;
mEnrolleeWifiConfiguration = qrCodeWifiConfiguration;
wifiManager.connect(id,
/* listener */ WifiDppQrCodeScannerFragment.this);
}
}
if (hasReachableWifiNetwork == false) {
if (!hasHiddenOrReachableWifiNetwork) {
showErrorMessageAndRestartCamera(
R.string.wifi_dpp_check_connection_try_again);
return;

View File

@@ -296,6 +296,7 @@ public class WifiDppUtils {
if (!TextUtils.isEmpty(preSharedKey)) {
intent.putExtra(EXTRA_WIFI_PRE_SHARED_KEY, preSharedKey);
}
intent.putExtra(EXTRA_WIFI_HIDDEN_SSID, wifiConfiguration.hiddenSSID);
}
/**

View File

@@ -220,7 +220,7 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
}
final WifiNetworkConfig networkConfig = WifiNetworkConfig.getValidConfigOrNull(
selectedAccessPoint.getSecurityString(/* concise */ true),
wifiConfig.getPrintableSsid(), wifiConfig.preSharedKey, /* hiddenSsid */ false,
wifiConfig.getPrintableSsid(), wifiConfig.preSharedKey, wifiConfig.hiddenSSID,
wifiConfig.networkId, /* isHotspot */ false);
if (mOnChooseNetworkListener != null) {
mOnChooseNetworkListener.onChooseNetwork(networkConfig);

View File

@@ -463,6 +463,43 @@ public class ApnEditorTest {
verify(mApnEditorUT).finish();
}
@Test
public void getUserEnteredApnType_emptyApnType_shouldReturnDefault() {
// case 1
// GIVEN read only APN types with DUN
String[] readOnlyApnTypes = {"dun"};
mApnEditorUT.mReadOnlyApnTypes = readOnlyApnTypes;
// GIVEN read specificApnTypeForEmptyInput with DEFAULT,DUN
String[] defaultApnTypes = {"default", "dun"};
mApnEditorUT.mDefaultApnTypes = defaultApnTypes;
// Input empty in TYPE
final FakeApnData apnData = new FakeApnData(APN_DATA);
apnData.mData[ApnEditor.TYPE_INDEX] = "";
mApnEditorUT.mApnData = apnData;
mApnEditorUT.fillUI(true /* firstTime */);
// THEN APN type should be default
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
// case 2
// GIVEN read only APN types with DUN
String[] readOnlyApnTypesCase2 = {"dun"};
mApnEditorUT.mReadOnlyApnTypes = readOnlyApnTypesCase2;
// GIVEN read specificApnTypeForEmptyInput with DEFAULT
String[] defaultApnTypesCase2 = {"default"};
mApnEditorUT.mDefaultApnTypes = defaultApnTypesCase2;
// Input empty in TYPE
final FakeApnData apnDataCase2 = new FakeApnData(APN_DATA);
apnDataCase2.mData[ApnEditor.TYPE_INDEX] = "";
mApnEditorUT.mApnData = apnDataCase2;
mApnEditorUT.fillUI(true /* firstTime */);
// THEN APN type should be default
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
}
private void initCursor() {
doReturn(2).when(mCursor).getColumnCount();
doReturn(2).when(mCursor).getInt(CURSOR_INTEGER_INDEX);

View File

@@ -0,0 +1,83 @@
/*
* 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.dpp;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiManager;
import com.android.settingslib.wifi.AccessPoint;
import java.util.BitSet;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
public class WifiDppUtilsTest {
@Mock
private WifiManager mWifiManager;
@Mock
private AccessPoint mAccessPoint;
@Mock
private WifiConfiguration mWifiConfiguration;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.WIFI_SERVICE, mWifiManager);
}
@Test
public void getConfiguratorQrCodeScannerIntentOrNull_hiddenSsidNetwork_hasHiddenSsidExtra() {
when(mWifiManager.isEasyConnectSupported()).thenReturn(true);
when(mAccessPoint.isPasspoint()).thenReturn(false);
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK);
when(mAccessPoint.getConfig()).thenReturn(mWifiConfiguration);
mWifiConfiguration.SSID = "GuestNetwork";
mWifiConfiguration.allowedKeyManagement = new BitSet();
mWifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
mWifiConfiguration.hiddenSSID = true;
Intent intent = WifiDppUtils
.getConfiguratorQrCodeScannerIntentOrNull(mContext, mWifiManager, mAccessPoint);
assertThat(intent.getBooleanExtra(WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID, false))
.isEqualTo(true);
}
}