[Wi-Fi DPP] Refine code
Remove unused code. Rename some variables and methods for better readability. Fix typos. Reduce unnecessary variable scope and method scope. Simplify some code logic. Bug: 120645817 Test: atest com.android.settings.wifi.dpp Change-Id: I8f30b3e445f25ada927e995befee1783d2270b91
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.settings.wifi.dpp;
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.net.wifi.EasyConnectStatusCallback;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
@@ -28,7 +27,6 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@@ -36,8 +34,6 @@ import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* After getting Wi-Fi network information and(or) QR code, this fragment config a device to connect
|
||||
* to the Wi-Fi network.
|
||||
@@ -51,7 +47,7 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
private int mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_FAILURE_NONE;
|
||||
|
||||
// Key for Bundle usage
|
||||
private static final String KEY_LATEST_ERROR_CODE = "key_latest_error_code";
|
||||
private static final String KEY_LATEST_STATUS_CODE = "key_latest_status_code";
|
||||
|
||||
private class EasyConnectConfiguratorStatusCallback extends EasyConnectStatusCallback {
|
||||
@Override
|
||||
@@ -80,7 +76,7 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
private void showSuccessUi(boolean isConfigurationChange) {
|
||||
setHeaderIconImageResource(R.drawable.ic_devices_check_circle_green_32dp);
|
||||
setHeaderTitle(R.string.wifi_dpp_wifi_shared_with_device);
|
||||
setProgressBarShown(isGoingInitiator());
|
||||
setProgressBarShown(isEasyConnectHandshaking());
|
||||
mSummary.setVisibility(View.INVISIBLE);
|
||||
mWifiApPictureView.setImageResource(R.drawable.wifi_dpp_success);
|
||||
mChooseDifferentNetwork.setVisibility(View.INVISIBLE);
|
||||
@@ -170,12 +166,12 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
mLeftButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
if (isGoingInitiator()) {
|
||||
if (isEasyConnectHandshaking()) {
|
||||
mSummary.setText(R.string.wifi_dpp_sharing_wifi_with_this_device);
|
||||
}
|
||||
|
||||
setProgressBarShown(isGoingInitiator());
|
||||
mRightButton.setVisibility(isGoingInitiator() ? View.INVISIBLE : View.VISIBLE);
|
||||
setProgressBarShown(isEasyConnectHandshaking());
|
||||
mRightButton.setVisibility(isEasyConnectHandshaking() ? View.INVISIBLE : View.VISIBLE);
|
||||
|
||||
if (!isConfigurationChange) {
|
||||
mLatestStatusCode = code;
|
||||
@@ -205,7 +201,7 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mLatestStatusCode = savedInstanceState.getInt(KEY_LATEST_ERROR_CODE);
|
||||
mLatestStatusCode = savedInstanceState.getInt(KEY_LATEST_STATUS_CODE);
|
||||
}
|
||||
|
||||
final WifiDppInitiatorViewModel model =
|
||||
@@ -214,7 +210,7 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
model.getStatusCode().observe(this, statusCode -> {
|
||||
// After configuration change, observe callback will be triggered,
|
||||
// do nothing for this case if a handshake does not end
|
||||
if (model.isGoingInitiator()) {
|
||||
if (model.isWifiDppHandshaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -272,8 +268,9 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
if (mLatestStatusCode == WifiDppUtils.EASY_CONNECT_EVENT_SUCCESS) {
|
||||
showSuccessUi(/* isConfigurationChange */ true);
|
||||
} else if (mLatestStatusCode == WifiDppUtils.EASY_CONNECT_EVENT_FAILURE_NONE) {
|
||||
setProgressBarShown(isGoingInitiator());
|
||||
mRightButton.setVisibility(isGoingInitiator() ? View.INVISIBLE : View.VISIBLE);
|
||||
setProgressBarShown(isEasyConnectHandshaking());
|
||||
mRightButton.setVisibility(isEasyConnectHandshaking() ?
|
||||
View.INVISIBLE : View.VISIBLE);
|
||||
} else {
|
||||
showErrorUi(mLatestStatusCode, /* isConfigurationChange */ true);
|
||||
}
|
||||
@@ -282,7 +279,7 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(KEY_LATEST_ERROR_CODE, mLatestStatusCode);
|
||||
outState.putInt(KEY_LATEST_STATUS_CODE, mLatestStatusCode);
|
||||
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
@@ -310,9 +307,9 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnClickChooseDifferentNetworkListener {
|
||||
public void onClickChooseDifferentNetwork();
|
||||
void onClickChooseDifferentNetwork();
|
||||
}
|
||||
OnClickChooseDifferentNetworkListener mClickChooseDifferentNetworkListener;
|
||||
private OnClickChooseDifferentNetworkListener mClickChooseDifferentNetworkListener;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
@@ -329,34 +326,21 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
}
|
||||
|
||||
// Check is Easy Connect handshaking or not
|
||||
private boolean isGoingInitiator() {
|
||||
private boolean isEasyConnectHandshaking() {
|
||||
final WifiDppInitiatorViewModel model =
|
||||
ViewModelProviders.of(this).get(WifiDppInitiatorViewModel.class);
|
||||
|
||||
return model.isGoingInitiator();
|
||||
return model.isWifiDppHandshaking();
|
||||
}
|
||||
|
||||
private void updateSummary() {
|
||||
if (isGoingInitiator()) {
|
||||
if (isEasyConnectHandshaking()) {
|
||||
mSummary.setText(R.string.wifi_dpp_sharing_wifi_with_this_device);
|
||||
} else {
|
||||
mSummary.setText(getString(R.string.wifi_dpp_add_device_to_wifi, getSsid()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This fragment will change UI display and text messages for events. To improve Talkback user
|
||||
* experienience, using this method to focus on a right component and announce a changed text
|
||||
* after an UI changing event.
|
||||
*
|
||||
* @param focusView The UI component which will be focused
|
||||
* @param announceView The UI component's text will be talked
|
||||
*/
|
||||
private void changeFocusAndAnnounceChange(View focusView, View announceView) {
|
||||
focusView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
|
||||
announceView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFooterAvailable() {
|
||||
return true;
|
||||
|
@@ -22,8 +22,6 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.ListView;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
@@ -37,8 +35,6 @@ import com.android.settings.R;
|
||||
public class WifiDppChooseSavedWifiNetworkFragment extends WifiDppQrCodeBaseFragment {
|
||||
private static final String TAG_FRAGMENT_WIFI_NETWORK_LIST = "wifi_network_list_fragment";
|
||||
|
||||
private ListView mSavedWifiNetworkList;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SETTINGS_WIFI_DPP_CONFIGURATOR;
|
||||
@@ -48,8 +44,8 @@ public class WifiDppChooseSavedWifiNetworkFragment extends WifiDppQrCodeBaseFrag
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
/** Embeded WifiNetworkListFragment as child fragment within
|
||||
* WifiDppChooseSavedWifiNetworkFragment. */
|
||||
// Embedded WifiNetworkListFragment as child fragment within
|
||||
// WifiDppChooseSavedWifiNetworkFragment.
|
||||
final FragmentManager fragmentManager = getChildFragmentManager();
|
||||
final WifiNetworkListFragment fragment = new WifiNetworkListFragment();
|
||||
final Bundle args = getArguments();
|
||||
|
@@ -27,7 +27,6 @@ import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -59,9 +58,9 @@ public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements
|
||||
|
||||
private static final String TAG = "WifiDppConfiguratorActivity";
|
||||
|
||||
public static final String ACTION_CONFIGURATOR_QR_CODE_SCANNER =
|
||||
static final String ACTION_CONFIGURATOR_QR_CODE_SCANNER =
|
||||
"android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER";
|
||||
public static final String ACTION_CONFIGURATOR_QR_CODE_GENERATOR =
|
||||
static final String ACTION_CONFIGURATOR_QR_CODE_GENERATOR =
|
||||
"android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR";
|
||||
|
||||
// Key for Bundle usage
|
||||
@@ -274,7 +273,7 @@ public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements
|
||||
return mWifiNetworkConfig;
|
||||
}
|
||||
|
||||
public WifiQrCode getWifiDppQrCode() {
|
||||
WifiQrCode getWifiDppQrCode() {
|
||||
return mWifiDppQrCode;
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,6 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -35,7 +34,7 @@ public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements
|
||||
WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener {
|
||||
private static final String TAG = "WifiDppEnrolleeActivity";
|
||||
|
||||
public static final String ACTION_ENROLLEE_QR_CODE_SCANNER =
|
||||
static final String ACTION_ENROLLEE_QR_CODE_SCANNER =
|
||||
"android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER";
|
||||
|
||||
@Override
|
||||
@@ -48,7 +47,7 @@ public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements
|
||||
switch (intent.getAction()) {
|
||||
case ACTION_ENROLLEE_QR_CODE_SCANNER:
|
||||
String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);
|
||||
showQrCodeScannerFragment(/* addToBackStack */ false, ssid);
|
||||
showQrCodeScannerFragment(ssid);
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG, "Launch with an invalid action");
|
||||
@@ -56,7 +55,7 @@ public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
private void showQrCodeScannerFragment(boolean addToBackStack, String ssid) {
|
||||
private void showQrCodeScannerFragment(String ssid) {
|
||||
WifiDppQrCodeScannerFragment fragment =
|
||||
(WifiDppQrCodeScannerFragment) mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||
@@ -77,9 +76,6 @@ public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||
if (addToBackStack) {
|
||||
fragmentTransaction.addToBackStack(/* name */ null);
|
||||
}
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
|
@@ -26,13 +26,13 @@ import androidx.lifecycle.AndroidViewModel;
|
||||
public class WifiDppInitiatorViewModel extends AndroidViewModel {
|
||||
private MutableLiveData<Integer> mEnrolleeSuccessNetworkId;
|
||||
private MutableLiveData<Integer> mStatusCode;
|
||||
private boolean mIsGoingInitiator;
|
||||
private boolean mIsWifiDppHandshaking;
|
||||
|
||||
public WifiDppInitiatorViewModel(Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
public MutableLiveData<Integer> getEnrolleeSuccessNetworkId() {
|
||||
MutableLiveData<Integer> getEnrolleeSuccessNetworkId() {
|
||||
if (mEnrolleeSuccessNetworkId == null) {
|
||||
mEnrolleeSuccessNetworkId = new MutableLiveData<>();
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class WifiDppInitiatorViewModel extends AndroidViewModel {
|
||||
return mEnrolleeSuccessNetworkId;
|
||||
}
|
||||
|
||||
public MutableLiveData<Integer> getStatusCode() {
|
||||
MutableLiveData<Integer> getStatusCode() {
|
||||
if (mStatusCode == null) {
|
||||
mStatusCode = new MutableLiveData<>();
|
||||
}
|
||||
@@ -48,12 +48,12 @@ public class WifiDppInitiatorViewModel extends AndroidViewModel {
|
||||
return mStatusCode;
|
||||
}
|
||||
|
||||
public boolean isGoingInitiator() {
|
||||
return mIsGoingInitiator;
|
||||
boolean isWifiDppHandshaking() {
|
||||
return mIsWifiDppHandshaking;
|
||||
}
|
||||
|
||||
public void startEasyConnectAsConfiguratorInitiator(String qrCode, int networkId) {
|
||||
mIsGoingInitiator = true;
|
||||
void startEasyConnectAsConfiguratorInitiator(String qrCode, int networkId) {
|
||||
mIsWifiDppHandshaking = true;
|
||||
final WifiManager wifiManager = getApplication().getSystemService(WifiManager.class);
|
||||
|
||||
wifiManager.startEasyConnectAsConfiguratorInitiator(qrCode, networkId,
|
||||
@@ -61,8 +61,8 @@ public class WifiDppInitiatorViewModel extends AndroidViewModel {
|
||||
new EasyConnectDelegateCallback());
|
||||
}
|
||||
|
||||
public void startEasyConnectAsEnrolleeInitiator(String qrCode) {
|
||||
mIsGoingInitiator = true;
|
||||
void startEasyConnectAsEnrolleeInitiator(String qrCode) {
|
||||
mIsWifiDppHandshaking = true;
|
||||
final WifiManager wifiManager = getApplication().getSystemService(WifiManager.class);
|
||||
|
||||
wifiManager.startEasyConnectAsEnrolleeInitiator(qrCode, getApplication().getMainExecutor(),
|
||||
@@ -72,19 +72,19 @@ public class WifiDppInitiatorViewModel extends AndroidViewModel {
|
||||
private class EasyConnectDelegateCallback extends EasyConnectStatusCallback {
|
||||
@Override
|
||||
public void onEnrolleeSuccess(int newNetworkId) {
|
||||
mIsGoingInitiator = false;
|
||||
mIsWifiDppHandshaking = false;
|
||||
mEnrolleeSuccessNetworkId.setValue(newNetworkId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfiguratorSuccess(int code) {
|
||||
mIsGoingInitiator = false;
|
||||
mIsWifiDppHandshaking = false;
|
||||
mStatusCode.setValue(WifiDppUtils.EASY_CONNECT_EVENT_SUCCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int code) {
|
||||
mIsGoingInitiator = false;
|
||||
mIsWifiDppHandshaking = false;
|
||||
mStatusCode.setValue(code);
|
||||
}
|
||||
|
||||
|
@@ -19,8 +19,8 @@ package com.android.settings.wifi.dpp;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
@@ -42,8 +42,9 @@ import com.google.android.setupdesign.GlifLayout;
|
||||
* {@code WifiDppAddDeviceFragment}
|
||||
*/
|
||||
public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
||||
private static final String TAG = "WifiDppQrCodeBaseFragment";
|
||||
|
||||
private GlifLayout mGlifLayout;
|
||||
private ImageView mHeaderIcon;
|
||||
protected TextView mSummary;
|
||||
protected FooterButton mLeftButton;
|
||||
protected FooterButton mRightButton;
|
||||
@@ -53,13 +54,9 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mGlifLayout = (GlifLayout) view;
|
||||
|
||||
mHeaderIcon = view.findViewById(android.R.id.icon);
|
||||
mSummary = view.findViewById(android.R.id.summary);
|
||||
|
||||
if (isFooterAvailable()) {
|
||||
FooterBarMixin FooterBarMixin = ((GlifLayout) view).getMixin(FooterBarMixin.class);
|
||||
|
||||
mLeftButton = new FooterButton.Builder(getContext())
|
||||
.setButtonType(FooterButton.ButtonType.CANCEL)
|
||||
.setTheme(R.style.SudGlifButton_Secondary)
|
||||
@@ -87,6 +84,7 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
||||
try {
|
||||
buttonIcon = getContext().getDrawable(iconResId);
|
||||
} catch (Resources.NotFoundException exception) {
|
||||
Log.e(TAG, "Resource does not exist: " + iconResId);
|
||||
}
|
||||
return buttonIcon;
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.wifi.dpp;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
@@ -44,7 +43,6 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
||||
private static final String TAG = "WifiDppQrCodeGeneratorFragment";
|
||||
|
||||
private ImageView mQrCodeView;
|
||||
private TextView mPasswordView;
|
||||
private String mQrCode;
|
||||
|
||||
@Override
|
||||
@@ -56,7 +54,7 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
// setTitle for Talkback
|
||||
// setTitle for TalkBack
|
||||
final WifiNetworkConfig wifiNetworkConfig = getWifiNetworkConfigFromHostActivity();
|
||||
if (wifiNetworkConfig.isHotspot()) {
|
||||
getActivity().setTitle(R.string.wifi_dpp_share_hotspot);
|
||||
@@ -96,21 +94,21 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
||||
}
|
||||
|
||||
final String password = wifiNetworkConfig.getPreSharedKey();
|
||||
mPasswordView = view.findViewById(R.id.password);
|
||||
TextView passwordView = view.findViewById(R.id.password);
|
||||
if (TextUtils.isEmpty(password)) {
|
||||
mSummary.setText(getString(
|
||||
R.string.wifi_dpp_scan_open_network_qr_code_with_another_device,
|
||||
wifiNetworkConfig.getSsid()));
|
||||
|
||||
mPasswordView.setVisibility(View.GONE);
|
||||
passwordView.setVisibility(View.GONE);
|
||||
} else {
|
||||
mSummary.setText(getString(R.string.wifi_dpp_scan_qr_code_with_another_device,
|
||||
wifiNetworkConfig.getSsid()));
|
||||
|
||||
if (wifiNetworkConfig.isHotspot()) {
|
||||
mPasswordView.setText(getString(R.string.wifi_dpp_hotspot_password, password));
|
||||
passwordView.setText(getString(R.string.wifi_dpp_hotspot_password, password));
|
||||
} else {
|
||||
mPasswordView.setText(getString(R.string.wifi_dpp_wifi_password, password));
|
||||
passwordView.setText(getString(R.string.wifi_dpp_wifi_password, password));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,11 +123,11 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
||||
final Bitmap bmp = QrCodeGenerator.encodeQrCode(mQrCode, qrcodeSize);
|
||||
mQrCodeView.setImageBitmap(bmp);
|
||||
} catch (WriterException e) {
|
||||
Log.e(TAG, "Error generatting QR code bitmap " + e);
|
||||
Log.e(TAG, "Error generating QR code bitmap " + e);
|
||||
}
|
||||
}
|
||||
|
||||
WifiNetworkConfig getWifiNetworkConfigFromHostActivity() {
|
||||
private WifiNetworkConfig getWifiNetworkConfigFromHostActivity() {
|
||||
final WifiNetworkConfig wifiNetworkConfig = ((WifiNetworkConfig.Retriever) getActivity())
|
||||
.getWifiNetworkConfig();
|
||||
if (!WifiNetworkConfig.isValidConfig(wifiNetworkConfig)) {
|
||||
|
@@ -19,7 +19,6 @@ package com.android.settings.wifi.dpp;
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Rect;
|
||||
@@ -57,7 +56,6 @@ import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.WifiTracker;
|
||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment implements
|
||||
@@ -201,7 +199,6 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -246,7 +243,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
model.getEnrolleeSuccessNetworkId().observe(this, networkId -> {
|
||||
// After configuration change, observe callback will be triggered,
|
||||
// do nothing for this case if a handshake does not end
|
||||
if (model.isGoingInitiator()) {
|
||||
if (model.isWifiDppHandshaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -256,7 +253,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
model.getStatusCode().observe(this, statusCode -> {
|
||||
// After configuration change, observe callback will be triggered,
|
||||
// do nothing for this case if a handshake does not end
|
||||
if (model.isGoingInitiator()) {
|
||||
if (model.isWifiDppHandshaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -279,7 +276,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (!isGoingInitiator()) {
|
||||
if (!isWifiDppHandshaking()) {
|
||||
restartCamera();
|
||||
}
|
||||
}
|
||||
@@ -295,9 +292,9 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnScanWifiDppSuccessListener {
|
||||
public void onScanWifiDppSuccess(WifiQrCode wifiQrCode);
|
||||
void onScanWifiDppSuccess(WifiQrCode wifiQrCode);
|
||||
}
|
||||
OnScanWifiDppSuccessListener mScanWifiDppSuccessListener;
|
||||
private OnScanWifiDppSuccessListener mScanWifiDppSuccessListener;
|
||||
|
||||
/**
|
||||
* Configurator container activity of the fragment should create instance with this constructor.
|
||||
@@ -312,7 +309,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
* Enrollee container activity of the fragment should create instance with this constructor and
|
||||
* specify the SSID string of the WI-Fi network to be provisioned.
|
||||
*/
|
||||
public WifiDppQrCodeScannerFragment(String ssid) {
|
||||
WifiDppQrCodeScannerFragment(String ssid) {
|
||||
super();
|
||||
|
||||
mIsConfiguratorMode = false;
|
||||
@@ -326,7 +323,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
mWifiTracker = WifiTrackerFactory.create(getActivity(), /* wifiListener */ this,
|
||||
getSettingsLifecycle(), /* includeSaved */ false, /* includeScans */ true);
|
||||
|
||||
// setTitle for Talkback
|
||||
// setTitle for TalkBack
|
||||
if (mIsConfiguratorMode) {
|
||||
getActivity().setTitle(R.string.wifi_dpp_add_device_to_network);
|
||||
} else {
|
||||
@@ -359,12 +356,12 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mTextureView = (TextureView) view.findViewById(R.id.preview_view);
|
||||
mTextureView = view.findViewById(R.id.preview_view);
|
||||
mTextureView.setSurfaceTextureListener(this);
|
||||
|
||||
mDecorateView = (QrDecorateView) view.findViewById(R.id.decorate_view);
|
||||
mDecorateView = view.findViewById(R.id.decorate_view);
|
||||
|
||||
setProgressBarShown(isGoingInitiator());
|
||||
setProgressBarShown(isWifiDppHandshaking());
|
||||
|
||||
if (mIsConfiguratorMode) {
|
||||
setHeaderTitle(R.string.wifi_dpp_add_device_to_network);
|
||||
@@ -490,7 +487,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
if (mCamera == null) {
|
||||
mCamera = new QrCamera(getContext(), this);
|
||||
|
||||
if (isGoingInitiator()) {
|
||||
if (isWifiDppHandshaking()) {
|
||||
if (mDecorateView != null) {
|
||||
mDecorateView.setFocused(true);
|
||||
}
|
||||
@@ -561,7 +558,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
public void onFailure(int code) {
|
||||
Log.d(TAG, "EasyConnectEnrolleeStatusCallback.onFailure " + code);
|
||||
|
||||
int errorMessageResId = 0;
|
||||
int errorMessageResId;
|
||||
switch (code) {
|
||||
case EasyConnectStatusCallback.EASY_CONNECT_EVENT_FAILURE_INVALID_URI:
|
||||
errorMessageResId = R.string.wifi_dpp_qr_code_is_not_valid_format;
|
||||
@@ -648,11 +645,11 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
}
|
||||
|
||||
// Check is Easy Connect handshaking or not
|
||||
private boolean isGoingInitiator() {
|
||||
private boolean isWifiDppHandshaking() {
|
||||
final WifiDppInitiatorViewModel model =
|
||||
ViewModelProviders.of(this).get(WifiDppInitiatorViewModel.class);
|
||||
|
||||
return model.isGoingInitiator();
|
||||
return model.isWifiDppHandshaking();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,7 +674,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
}
|
||||
|
||||
private void updateEnrolleeSummary() {
|
||||
if (isGoingInitiator()) {
|
||||
if (isWifiDppHandshaking()) {
|
||||
mSummary.setText(R.string.wifi_dpp_connecting);
|
||||
} else {
|
||||
String description;
|
||||
|
@@ -29,7 +29,6 @@ import android.os.Looper;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
import android.text.TextUtils;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
@@ -48,62 +47,62 @@ public class WifiDppUtils {
|
||||
/**
|
||||
* The fragment tag specified to FragmentManager for container activities to manage fragments.
|
||||
*/
|
||||
public static final String TAG_FRAGMENT_QR_CODE_SCANNER = "qr_code_scanner_fragment";
|
||||
static final String TAG_FRAGMENT_QR_CODE_SCANNER = "qr_code_scanner_fragment";
|
||||
|
||||
/**
|
||||
* @see #TAG_FRAGMENT_QR_CODE_SCANNER
|
||||
*/
|
||||
public static final String TAG_FRAGMENT_QR_CODE_GENERATOR = "qr_code_generator_fragment";
|
||||
static final String TAG_FRAGMENT_QR_CODE_GENERATOR = "qr_code_generator_fragment";
|
||||
|
||||
/**
|
||||
* @see #TAG_FRAGMENT_QR_CODE_SCANNER
|
||||
*/
|
||||
public static final String TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK =
|
||||
static final String TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK =
|
||||
"choose_saved_wifi_network_fragment";
|
||||
|
||||
/**
|
||||
* @see #TAG_FRAGMENT_QR_CODE_SCANNER
|
||||
*/
|
||||
public static final String TAG_FRAGMENT_ADD_DEVICE = "add_device_fragment";
|
||||
static final String TAG_FRAGMENT_ADD_DEVICE = "add_device_fragment";
|
||||
|
||||
/** The data is from {@code com.android.settingslib.wifi.AccessPoint.securityToString} */
|
||||
public static final String EXTRA_WIFI_SECURITY = "security";
|
||||
static final String EXTRA_WIFI_SECURITY = "security";
|
||||
|
||||
/** The data corresponding to {@code WifiConfiguration} SSID */
|
||||
public static final String EXTRA_WIFI_SSID = "ssid";
|
||||
static final String EXTRA_WIFI_SSID = "ssid";
|
||||
|
||||
/** The data corresponding to {@code WifiConfiguration} preSharedKey */
|
||||
public static final String EXTRA_WIFI_PRE_SHARED_KEY = "preSharedKey";
|
||||
static final String EXTRA_WIFI_PRE_SHARED_KEY = "preSharedKey";
|
||||
|
||||
/** The data corresponding to {@code WifiConfiguration} hiddenSSID */
|
||||
public static final String EXTRA_WIFI_HIDDEN_SSID = "hiddenSsid";
|
||||
static final String EXTRA_WIFI_HIDDEN_SSID = "hiddenSsid";
|
||||
|
||||
/** The data corresponding to {@code WifiConfiguration} networkId */
|
||||
public static final String EXTRA_WIFI_NETWORK_ID = "networkId";
|
||||
static final String EXTRA_WIFI_NETWORK_ID = "networkId";
|
||||
|
||||
/** The data to recognize if it's a Wi-Fi hotspot for configuration */
|
||||
public static final String EXTRA_IS_HOTSPOT = "isHotspot";
|
||||
static final String EXTRA_IS_HOTSPOT = "isHotspot";
|
||||
|
||||
/** Used by {@link android.provider.Settings#ACTION_PROCESS_WIFI_EASY_CONNECT_URI} to
|
||||
* indicate test mode UI should be shown. Test UI does not make API calls. Value is a boolean.*/
|
||||
public static final String EXTRA_TEST = "test";
|
||||
static final String EXTRA_TEST = "test";
|
||||
|
||||
/**
|
||||
* Default status code for Easy Connect
|
||||
*/
|
||||
public static final int EASY_CONNECT_EVENT_FAILURE_NONE = 0;
|
||||
static final int EASY_CONNECT_EVENT_FAILURE_NONE = 0;
|
||||
|
||||
/**
|
||||
* Success status code for Easy Connect.
|
||||
*/
|
||||
public static final int EASY_CONNECT_EVENT_SUCCESS = 1;
|
||||
static final int EASY_CONNECT_EVENT_SUCCESS = 1;
|
||||
|
||||
private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3);
|
||||
|
||||
/**
|
||||
* Returns whether the device support WiFi DPP.
|
||||
*/
|
||||
public static boolean isWifiDppEnabled(Context context) {
|
||||
static boolean isWifiDppEnabled(Context context) {
|
||||
final WifiManager manager = context.getSystemService(WifiManager.class);
|
||||
return manager.isEasyConnectSupported();
|
||||
}
|
||||
@@ -130,10 +129,10 @@ public class WifiDppUtils {
|
||||
|
||||
private static String getPresharedKey(WifiManager wifiManager,
|
||||
WifiConfiguration wifiConfiguration) {
|
||||
final List<WifiConfiguration> privilegedWifiConfiguratios =
|
||||
final List<WifiConfiguration> privilegedWifiConfigurations =
|
||||
wifiManager.getPrivilegedConfiguredNetworks();
|
||||
|
||||
for (WifiConfiguration privilegedWifiConfiguration : privilegedWifiConfiguratios) {
|
||||
for (WifiConfiguration privilegedWifiConfiguration : privilegedWifiConfigurations) {
|
||||
if (privilegedWifiConfiguration.networkId == wifiConfiguration.networkId) {
|
||||
// WEP uses a shared key hence the AuthAlgorithm.SHARED is used
|
||||
// to identify it.
|
||||
|
@@ -81,7 +81,7 @@ public class WifiNetworkConfig {
|
||||
* WifiNetworkConfig for configuration
|
||||
*/
|
||||
public interface Retriever {
|
||||
public WifiNetworkConfig getWifiNetworkConfig();
|
||||
WifiNetworkConfig getWifiNetworkConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ public class WifiNetworkConfig {
|
||||
* android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR
|
||||
* android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER
|
||||
*/
|
||||
public static WifiNetworkConfig getValidConfigOrNull(Intent intent) {
|
||||
static WifiNetworkConfig getValidConfigOrNull(Intent intent) {
|
||||
final String security = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SECURITY);
|
||||
final String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);
|
||||
final String preSharedKey = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY);
|
||||
@@ -103,7 +103,7 @@ public class WifiNetworkConfig {
|
||||
return getValidConfigOrNull(security, ssid, preSharedKey, hiddenSsid, networkId, isHotspot);
|
||||
}
|
||||
|
||||
public static WifiNetworkConfig getValidConfigOrNull(String security, String ssid,
|
||||
static WifiNetworkConfig getValidConfigOrNull(String security, String ssid,
|
||||
String preSharedKey, boolean hiddenSsid, int networkId, boolean isHotspot) {
|
||||
if (!isValidConfig(security, ssid, preSharedKey, hiddenSsid)) {
|
||||
return null;
|
||||
@@ -113,7 +113,7 @@ public class WifiNetworkConfig {
|
||||
isHotspot);
|
||||
}
|
||||
|
||||
public static boolean isValidConfig(WifiNetworkConfig config) {
|
||||
static boolean isValidConfig(WifiNetworkConfig config) {
|
||||
if (config == null) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -122,7 +122,7 @@ public class WifiNetworkConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValidConfig(String security, String ssid, String preSharedKey,
|
||||
static boolean isValidConfig(String security, String ssid, String preSharedKey,
|
||||
boolean hiddenSsid) {
|
||||
if (!TextUtils.isEmpty(security) && !SECURITY_NO_PASSWORD.equals(security)) {
|
||||
if (TextUtils.isEmpty(preSharedKey)) {
|
||||
@@ -162,9 +162,9 @@ public class WifiNetworkConfig {
|
||||
* Construct a barcode string for WiFi network login.
|
||||
* See https://en.wikipedia.org/wiki/QR_code#WiFi_network_login
|
||||
*/
|
||||
public String getQrCode() {
|
||||
String getQrCode() {
|
||||
final String empty = "";
|
||||
String barcode = new StringBuilder("WIFI:")
|
||||
return new StringBuilder("WIFI:")
|
||||
.append("S:")
|
||||
.append(escapeSpecialCharacters(mSsid))
|
||||
.append(";")
|
||||
@@ -179,7 +179,6 @@ public class WifiNetworkConfig {
|
||||
.append(mHiddenSsid)
|
||||
.append(";;")
|
||||
.toString();
|
||||
return barcode;
|
||||
}
|
||||
|
||||
public String getSecurity() {
|
||||
@@ -233,9 +232,6 @@ public class WifiNetworkConfig {
|
||||
/**
|
||||
* This is a simplified method from {@code WifiConfigController.getConfig()}
|
||||
*
|
||||
* TODO (b/129021867): WifiConfiguration is a deprecated class, should replace it with
|
||||
* {@code android.net.wifi.WifiNetworkSuggestion}
|
||||
*
|
||||
* @return When it's a open network, returns 2 WifiConfiguration in the List, the 1st is
|
||||
* open network and the 2nd is enhanced open network. Returns 1 WifiConfiguration in the
|
||||
* List for all other supported Wi-Fi securities.
|
||||
|
@@ -40,7 +40,6 @@ import com.android.settingslib.wifi.WifiSavedConfigUtils;
|
||||
import com.android.settingslib.wifi.WifiTracker;
|
||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -51,7 +50,7 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
private static final String WIFI_CONFIG_KEY = "wifi_config_key";
|
||||
private static final String PREF_KEY_ACCESS_POINTS = "access_points";
|
||||
|
||||
static final int ADD_NETWORK_REQUEST = 1;
|
||||
private static final int ADD_NETWORK_REQUEST = 1;
|
||||
|
||||
private PreferenceCategory mAccessPointsPreferenceCategory;
|
||||
private AccessPointPreference.UserBadgeCache mUserBadgeCache;
|
||||
@@ -67,10 +66,9 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnChooseNetworkListener {
|
||||
public void onChooseNetwork(WifiNetworkConfig wifiNetworkConfig);
|
||||
void onChooseNetwork(WifiNetworkConfig wifiNetworkConfig);
|
||||
}
|
||||
|
||||
OnChooseNetworkListener mOnChooseNetworkListener;
|
||||
private OnChooseNetworkListener mOnChooseNetworkListener;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
@@ -139,8 +137,7 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.wifi_dpp_network_list);
|
||||
|
||||
mAccessPointsPreferenceCategory = (PreferenceCategory) findPreference(
|
||||
PREF_KEY_ACCESS_POINTS);
|
||||
mAccessPointsPreferenceCategory = findPreference(PREF_KEY_ACCESS_POINTS);
|
||||
|
||||
mFakeNetworkPreference = new Preference(getPrefContext());
|
||||
mFakeNetworkPreference.setIcon(R.drawable.ic_wifi_signal_0);
|
||||
@@ -254,12 +251,8 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
private boolean isValidForDppConfiguration(AccessPoint accessPoint) {
|
||||
final int security = accessPoint.getSecurity();
|
||||
|
||||
// DPP 1.0 only support SAE and PSK.
|
||||
if (!(security == AccessPoint.SECURITY_PSK || security == AccessPoint.SECURITY_SAE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
// DPP 1.0 only support PSK and SAE.
|
||||
return security == AccessPoint.SECURITY_PSK || security == AccessPoint.SECURITY_SAE;
|
||||
}
|
||||
|
||||
private void launchAddNetworkFragment() {
|
||||
|
@@ -48,26 +48,26 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
*/
|
||||
public class WifiQrCode {
|
||||
public static final String SCHEME_DPP = "DPP";
|
||||
public static final String SCHEME_ZXING_WIFI_NETWORK_CONFIG = "WIFI";
|
||||
public static final String PREFIX_DPP = "DPP:";
|
||||
public static final String PREFIX_ZXING_WIFI_NETWORK_CONFIG = "WIFI:";
|
||||
static final String SCHEME_DPP = "DPP";
|
||||
static final String SCHEME_ZXING_WIFI_NETWORK_CONFIG = "WIFI";
|
||||
static final String PREFIX_DPP = "DPP:";
|
||||
static final String PREFIX_ZXING_WIFI_NETWORK_CONFIG = "WIFI:";
|
||||
|
||||
public static final String PREFIX_DPP_PUBLIC_KEY = "K:";
|
||||
public static final String PREFIX_DPP_INFORMATION = "I:";
|
||||
static final String PREFIX_DPP_PUBLIC_KEY = "K:";
|
||||
static final String PREFIX_DPP_INFORMATION = "I:";
|
||||
|
||||
public static final String PREFIX_ZXING_SECURITY = "T:";
|
||||
public static final String PREFIX_ZXING_SSID = "S:";
|
||||
public static final String PREFIX_ZXING_PASSWORD = "P:";
|
||||
public static final String PREFIX_ZXING_HIDDEN_SSID = "H:";
|
||||
static final String PREFIX_ZXING_SECURITY = "T:";
|
||||
static final String PREFIX_ZXING_SSID = "S:";
|
||||
static final String PREFIX_ZXING_PASSWORD = "P:";
|
||||
static final String PREFIX_ZXING_HIDDEN_SSID = "H:";
|
||||
|
||||
public static final String DELIMITER_QR_CODE = ";";
|
||||
static final String DELIMITER_QR_CODE = ";";
|
||||
|
||||
// Ignores password if security is SECURITY_NO_PASSWORD or absent
|
||||
public static final String SECURITY_NO_PASSWORD = "nopass"; //open network or OWE
|
||||
public static final String SECURITY_WEP = "WEP";
|
||||
public static final String SECURITY_WPA_PSK = "WPA";
|
||||
public static final String SECURITY_SAE = "SAE";
|
||||
static final String SECURITY_NO_PASSWORD = "nopass"; //open network or OWE
|
||||
static final String SECURITY_WEP = "WEP";
|
||||
static final String SECURITY_WPA_PSK = "WPA";
|
||||
static final String SECURITY_SAE = "SAE";
|
||||
|
||||
private String mQrCode;
|
||||
|
||||
@@ -104,7 +104,7 @@ public class WifiQrCode {
|
||||
|
||||
/** Parses Wi-Fi DPP QR code string */
|
||||
private void parseWifiDppQrCode(String qrCode) throws IllegalArgumentException {
|
||||
List keyValueList = getKeyValueList(qrCode, PREFIX_DPP, DELIMITER_QR_CODE);
|
||||
List<String> keyValueList = getKeyValueList(qrCode, PREFIX_DPP, DELIMITER_QR_CODE);
|
||||
|
||||
String publicKey = getValueOrNull(keyValueList, PREFIX_DPP_PUBLIC_KEY);
|
||||
if (TextUtils.isEmpty(publicKey)) {
|
||||
@@ -117,7 +117,7 @@ public class WifiQrCode {
|
||||
|
||||
/** Parses ZXing reader library's Wi-Fi Network config format */
|
||||
private void parseZxingWifiQrCode(String qrCode) throws IllegalArgumentException {
|
||||
List keyValueList = getKeyValueList(qrCode, PREFIX_ZXING_WIFI_NETWORK_CONFIG,
|
||||
List<String> keyValueList = getKeyValueList(qrCode, PREFIX_ZXING_WIFI_NETWORK_CONFIG,
|
||||
DELIMITER_QR_CODE);
|
||||
|
||||
String security = getValueOrNull(keyValueList, PREFIX_ZXING_SECURITY);
|
||||
@@ -155,8 +155,7 @@ public class WifiQrCode {
|
||||
// Should not treat \delimiter as a delimiter
|
||||
String regex = "(?<!\\\\)" + Pattern.quote(delimiter);
|
||||
|
||||
List<String> result = Arrays.asList(keyValueString.split(regex));
|
||||
return result;
|
||||
return Arrays.asList(keyValueString.split(regex));
|
||||
}
|
||||
|
||||
private String getValueOrNull(List<String> keyValueList, String prefix) {
|
||||
@@ -195,7 +194,7 @@ public class WifiQrCode {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getQrCode() {
|
||||
String getQrCode() {
|
||||
return mQrCode;
|
||||
}
|
||||
|
||||
@@ -221,7 +220,7 @@ public class WifiQrCode {
|
||||
}
|
||||
|
||||
/** Available when {@code getScheme()} returns SCHEME_ZXING_WIFI_NETWORK_CONFIG */
|
||||
public WifiNetworkConfig getWifiNetworkConfig() {
|
||||
WifiNetworkConfig getWifiNetworkConfig() {
|
||||
if (mWifiNetworkConfig == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -229,7 +228,7 @@ public class WifiQrCode {
|
||||
return new WifiNetworkConfig(mWifiNetworkConfig);
|
||||
}
|
||||
|
||||
public static WifiQrCode getValidWifiDppQrCodeOrNull(String qrCode) {
|
||||
static WifiQrCode getValidWifiDppQrCodeOrNull(String qrCode) {
|
||||
WifiQrCode wifiQrCode;
|
||||
try {
|
||||
wifiQrCode = new WifiQrCode(qrCode);
|
||||
|
@@ -68,9 +68,9 @@ public class QrCamera extends Handler {
|
||||
* size is 1920x1440, MAX_RATIO_DIFF 0.1 could allow picture size of 720x480 or 352x288 or
|
||||
* 176x44 but not 1920x1080.
|
||||
*/
|
||||
private static double MAX_RATIO_DIFF = 0.1;
|
||||
private static final double MAX_RATIO_DIFF = 0.1;
|
||||
|
||||
private static long AUTOFOCUS_INTERVAL_MS = 1500L;
|
||||
private static final long AUTOFOCUS_INTERVAL_MS = 1500L;
|
||||
|
||||
private static Map<DecodeHintType, List<BarcodeFormat>> HINTS = new ArrayMap<>();
|
||||
private static List<BarcodeFormat> FORMATS = new ArrayList<>();
|
||||
@@ -217,7 +217,7 @@ public class QrCamera extends Handler {
|
||||
final int rotateDegrees = (mCameraOrientation - degrees + 360) % 360;
|
||||
mCamera.setDisplayOrientation(rotateDegrees);
|
||||
mCamera.startPreview();
|
||||
if (mParameters.getFocusMode() == Parameters.FOCUS_MODE_AUTO) {
|
||||
if (Parameters.FOCUS_MODE_AUTO.equals(mParameters.getFocusMode())) {
|
||||
mCamera.autoFocus(/* Camera.AutoFocusCallback */ null);
|
||||
sendMessageDelayed(obtainMessage(MSG_AUTO_FOCUS), AUTOFOCUS_INTERVAL_MS);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ public class QrCamera extends Handler {
|
||||
final Semaphore imageGot = new Semaphore(0);
|
||||
while (true) {
|
||||
// This loop will try to capture preview image continuously until a valid QR Code
|
||||
// decoded. The caller can also call {@link #stop()} to inturrupts scanning loop.
|
||||
// decoded. The caller can also call {@link #stop()} to interrupts scanning loop.
|
||||
mCamera.setOneShotPreviewCallback(
|
||||
(imageData, camera) -> {
|
||||
mImage = getFrameImage(imageData);
|
||||
@@ -300,7 +300,7 @@ public class QrCamera extends Handler {
|
||||
return false;
|
||||
}
|
||||
setCameraParameter();
|
||||
setTransformationMatrix(mScannerCallback.getViewSize());
|
||||
setTransformationMatrix();
|
||||
if (!startPreview()) {
|
||||
Log.e(TAG, "Error to init Camera");
|
||||
mCamera = null;
|
||||
@@ -317,13 +317,10 @@ public class QrCamera extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
/** Set transfom matrix to crop and center the preview picture */
|
||||
private void setTransformationMatrix(Size viewSize) {
|
||||
// Check aspect ratio, can only handle square view.
|
||||
final int viewRatio = (int)getRatio(viewSize.getWidth(), viewSize.getHeight());
|
||||
|
||||
/** Set transform matrix to crop and center the preview picture */
|
||||
private void setTransformationMatrix() {
|
||||
final boolean isPortrait = mContext.get().getResources().getConfiguration().orientation
|
||||
== Configuration.ORIENTATION_PORTRAIT ? true : false;
|
||||
== Configuration.ORIENTATION_PORTRAIT;
|
||||
|
||||
final int previewWidth = isPortrait ? mPreviewSize.getWidth() : mPreviewSize.getHeight();
|
||||
final int previewHeight = isPortrait ? mPreviewSize.getHeight() : mPreviewSize.getWidth();
|
||||
@@ -357,7 +354,7 @@ public class QrCamera extends Handler {
|
||||
switch (msg.what) {
|
||||
case MSG_AUTO_FOCUS:
|
||||
// Calling autoFocus(null) will only trigger the camera to focus once. In order
|
||||
// to make the camera continuously auto focus during scanning, need to periodly
|
||||
// to make the camera continuously auto focus during scanning, need to periodically
|
||||
// trigger it.
|
||||
mCamera.autoFocus(/* Camera.AutoFocusCallback */ null);
|
||||
sendMessageDelayed(obtainMessage(MSG_AUTO_FOCUS), AUTOFOCUS_INTERVAL_MS);
|
||||
|
@@ -107,8 +107,6 @@ public class WifiNetworkListFragmentTest {
|
||||
intent.setData(Uri.parse(uriString));
|
||||
mActivityRule.launchActivity(intent);
|
||||
|
||||
verify(mWifiTracker).getManager();
|
||||
|
||||
List<Fragment> fragments =
|
||||
mActivityRule.getActivity().getSupportFragmentManager().getFragments();
|
||||
assertThat(fragments.size()).isEqualTo(1);
|
||||
|
Reference in New Issue
Block a user