</provider>
<activity
- android:name=".wifi.dpp.WifiDppConfiguratorActivity"/>
+ android:name=".wifi.dpp.WifiDppConfiguratorActivity">
+ <intent-filter>
+ <action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER"/>
+ <action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR"/>
+ <action android:name="android.settings.WIFI_DPP_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
<activity android:name=".homepage.contextualcards.ContextualCardFeedbackDialog"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" />
import android.app.ActionBar;
import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.android.settings.core.InstrumentedActivity;
import com.android.settings.R;
-public class WifiDppConfiguratorActivity extends InstrumentedActivity {
+public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
+ WifiNetworkConfig.Retriever {
private static final String TAG = "WifiDppConfiguratorActivity";
+ public 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 =
+ "android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR";
+ public static final String ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK =
+ "android.settings.WIFI_DPP_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK";
+
private FragmentManager mFragmentManager;
private FragmentTransaction mFragmentTransaction;
- public static final String EXTRA_LAUNCH_MODE =
- "com.android.settings.wifi.dpp.EXTRA_LAUNCH_MODE";
- public static final String EXTRA_SSID = "com.android.settings.wifi.dpp.EXTRA_SSID";
-
- public enum LaunchMode {
- LAUNCH_MODE_QR_CODE_SCANNER(1),
- LAUNCH_MODE_QR_CODE_GENERATOR(2),
- LAUNCH_MODE_CHOOSE_SAVED_WIFI_NETWORK(3),
- LAUNCH_MODE_NOT_DEFINED(-1);
-
- private int mMode;
-
- LaunchMode(int mode) {
- this.mMode = mode;
- }
-
- public int getMode() {
- return mMode;
- }
- }
+ /** The Wi-Fi network which will be configured */
+ private WifiNetworkConfig mWifiNetworkConfig;
@Override
public int getMetricsCategory() {
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = getSupportFragmentManager().beginTransaction();
- final int launchMode = getIntent().getIntExtra(EXTRA_LAUNCH_MODE,
- LaunchMode.LAUNCH_MODE_NOT_DEFINED.getMode());
- if (launchMode == LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode()) {
- addQrCodeScannerFragment();
- } else if (launchMode == LaunchMode.LAUNCH_MODE_QR_CODE_GENERATOR.getMode()) {
- addQrCodeGeneratorFragment();
- } else if (launchMode == LaunchMode.LAUNCH_MODE_CHOOSE_SAVED_WIFI_NETWORK.getMode()) {
- addChooseSavedWifiNetworkFragment();
- } else {
- Log.e(TAG, "Launch with an invalid mode extra");
+ Intent intent = getIntent();
+ boolean cancelActivity = false;
+ WifiNetworkConfig config;
+ switch (intent.getAction()) {
+ case ACTION_CONFIGURATOR_QR_CODE_SCANNER:
+ config = WifiNetworkConfig.getValidConfigOrNull(intent);
+ if (config == null) {
+ cancelActivity = true;
+ } else {
+ mWifiNetworkConfig = config;
+ addQrCodeScannerFragment(/* addToBackStack= */ false);
+ }
+ break;
+ case ACTION_CONFIGURATOR_QR_CODE_GENERATOR:
+ config = WifiNetworkConfig.getValidConfigOrNull(intent);
+ if (config == null) {
+ cancelActivity = true;
+ } else {
+ mWifiNetworkConfig = config;
+ addQrCodeGeneratorFragment();
+ }
+ break;
+ case ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK:
+ addChooseSavedWifiNetworkFragment(/* addToBackStack */ false);
+ break;
+ default:
+ cancelActivity = true;
+ Log.e(TAG, "Launch with an invalid action");
+ }
+
+ if (cancelActivity) {
setResult(Activity.RESULT_CANCELED);
finish();
}
}
- private void addQrCodeScannerFragment() {
- final WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
+ private void addQrCodeScannerFragment(boolean addToBackStack) {
+ WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
mFragmentTransaction.add(R.id.fragment_container, fragment);
- mFragmentTransaction.addToBackStack(/* name */ null);
+ if (addToBackStack) {
+ mFragmentTransaction.addToBackStack(/* name */ null);
+ }
mFragmentTransaction.commit();
}
private void addQrCodeGeneratorFragment() {
- final WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
+ WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
mFragmentTransaction.add(R.id.fragment_container, fragment);
- mFragmentTransaction.addToBackStack(/* name */ null);
mFragmentTransaction.commit();
}
- private void addChooseSavedWifiNetworkFragment() {
- final ActionBar action = getActionBar();
+ private void addChooseSavedWifiNetworkFragment(boolean addToBackStack) {
+ ActionBar action = getActionBar();
if (action != null) {
action.hide();
}
WifiDppChooseSavedWifiNetworkFragment fragment =
new WifiDppChooseSavedWifiNetworkFragment();
mFragmentTransaction.add(R.id.fragment_container, fragment);
- mFragmentTransaction.addToBackStack(/* name */ null);
+ if (addToBackStack) {
+ mFragmentTransaction.addToBackStack(/* name */ null);
+ }
mFragmentTransaction.commit();
}
@Override
protected void onStop() {
- final Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
+ Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
if (fragment != null) {
// Remove it to prevent stacking multiple fragments after screen rotated.
mFragmentManager.beginTransaction().remove(fragment).commit();
super.onStop();
}
+
+ @Override
+ public WifiNetworkConfig getWifiNetworkConfig() {
+ return mWifiNetworkConfig;
+ }
+
+ @Override
+ public boolean setWifiNetworkConfig(WifiNetworkConfig config) {
+ if(!WifiNetworkConfig.isValidConfig(config)) {
+ return false;
+ } else {
+ mWifiNetworkConfig = new WifiNetworkConfig(config);
+ return true;
+ }
+ }
}
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.core.InstrumentedFragment;
+import com.android.settings.wifi.qrcode.QrDecorateView;
import com.android.settings.R;
/**
private TextView mDescription;
private SurfaceView mPreviewView; //optional, for WifiDppQrCodeScannerFragment
- private ImageView mDecorateViiew; //optional, for WifiDppQrCodeScannerFragment
+ private QrDecorateView mDecorateViiew; //optional, for WifiDppQrCodeScannerFragment
private TextView mErrorMessage; //optional, for WifiDppQrCodeScannerFragment
private ImageView mBarcodeView; //optional, for WifiDppQrCodeGeneratorFragment
setTitle(getString(R.string.wifi_dpp_add_device_to_network));
- String ssid = null;
- final Intent intent = getActivity().getIntent();
- if (intent != null) {
- ssid = intent.getStringExtra(WifiDppConfiguratorActivity.EXTRA_SSID);
+ WifiNetworkConfig wifiNetworkConfig = ((WifiNetworkConfig.Retriever) getActivity())
+ .getWifiNetworkConfig();
+ if (!WifiNetworkConfig.isValidConfig(wifiNetworkConfig)) {
+ throw new IllegalArgumentException("Invalid Wi-Fi network for configuring");
}
- if (TextUtils.isEmpty(ssid)) {
- throw new IllegalArgumentException("Invalid SSID");
- }
- setDescription(getString(R.string.wifi_dpp_center_qr_code, ssid));
+ setDescription(getString(R.string.wifi_dpp_center_qr_code, wifiNetworkConfig.getSsid()));
hideRightButton();
--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.dpp;
+
+import android.content.Intent;
+
+/**
+ * Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity
+ */
+public class WifiDppUtils {
+ /** The data is from {@code com.android.settingslib.wifi.AccessPoint.securityToString} */
+ public static final String EXTRA_WIFI_SECURITY = "security";
+
+ /** The data corresponding to {@code WifiConfiguration} SSID */
+ public static final String EXTRA_WIFI_SSID = "ssid";
+
+ /** The data corresponding to {@code WifiConfiguration} preSharedKey */
+ public 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";
+
+ /**
+ * Acceptable QR code string may be a standard W-Fi DPP bootstrapping information or the Wi-Fi
+ * Network config format described in
+ * https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11
+ *
+ * Wi-Fi Network config format example:
+ *
+ * WIFI:T:WPA;S:mynetwork;P:mypass;;
+ *
+ * parameter Example Description
+ * T WPA Authentication type; can be WEP or WPA, or 'nopass' for no password. Or,
+ * omit for no password.
+ * S mynetwork Network SSID. Required. Enclose in double quotes if it is an ASCII name,
+ * but could be interpreted as hex (i.e. "ABCD")
+ * P mypass Password, ignored if T is "nopass" (in which case it may be omitted).
+ * Enclose in double quotes if it is an ASCII name, but could be interpreted as
+ * hex (i.e. "ABCD")
+ * H true Optional. True if the network SSID is hidden.
+ */
+ public static final String EXTRA_QR_CODE = "qrCode";
+}
--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi.dpp;
+
+import android.content.Intent;
+import android.text.TextUtils;
+
+/**
+ * Contains the Wi-Fi Network config parameters described in
+ * https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11
+ *
+ * Checks below members of {@code WifiDppUtils} for more information.
+ * EXTRA_WIFI_SECURITY / EXTRA_WIFI_SSID / EXTRA_WIFI_PRE_SHARED_KEY / EXTRA_WIFI_HIDDEN_SSID /
+ * EXTRA_QR_CODE
+ */
+public class WifiNetworkConfig {
+ private String mSecurity;
+ private String mSsid;
+ private String mPreSharedKey;
+ private boolean mHiddenSsid;
+
+ private WifiNetworkConfig(String security, String ssid, String preSharedKey,
+ boolean hiddenSsid) {
+ mSecurity = security;
+ mSsid = ssid;
+ mPreSharedKey = preSharedKey;
+ mHiddenSsid = hiddenSsid;
+ }
+
+ public WifiNetworkConfig(WifiNetworkConfig config) {
+ mSecurity = new String(config.mSecurity);
+ mSsid = new String(config.mSsid);
+ mPreSharedKey = new String(config.mPreSharedKey);
+ mHiddenSsid = config.mHiddenSsid;
+ }
+
+ /**
+ * Wi-Fi DPP activities should implement this interface for fragments to retrieve the
+ * WifiNetworkConfig for configuration
+ */
+ public interface Retriever {
+ public WifiNetworkConfig getWifiNetworkConfig();
+ public boolean setWifiNetworkConfig(WifiNetworkConfig config);
+ }
+
+ /**
+ * Retrieve WifiNetworkConfig from below 2 intents
+ *
+ * android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR
+ * android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER
+ */
+ public static WifiNetworkConfig getValidConfigOrNull(Intent intent) {
+ String security = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SECURITY);
+ String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);
+ String preSharedKey = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY);
+ boolean hiddenSsid = intent.getBooleanExtra(WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID, false);
+
+ if (!isValidConfig(security, ssid, hiddenSsid)) {
+ return null;
+ }
+
+ if (ssid == null) {
+ ssid = "";
+ }
+
+ return new WifiNetworkConfig(security, ssid, preSharedKey, hiddenSsid);
+ }
+
+ public static boolean isValidConfig(WifiNetworkConfig config) {
+ if (config == null) {
+ return false;
+ } else {
+ return isValidConfig(config.mSecurity, config.mSsid, config.mHiddenSsid);
+ }
+ }
+
+ public static boolean isValidConfig(String security, String ssid, boolean hiddenSsid) {
+ if (TextUtils.isEmpty(security)) {
+ return false;
+ }
+
+ if (!hiddenSsid && TextUtils.isEmpty(ssid)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public String getSecurity() {
+ return new String(mSecurity);
+ }
+
+ public String getSsid() {
+ return new String(mSsid);
+ }
+
+ public String getPreSharedKey() {
+ return new String(mPreSharedKey);
+ }
+
+ public boolean getHiddenSsid() {
+ return mHiddenSsid;
+ }
+}
new ActivityTestRule<>(WifiDppConfiguratorActivity.class);
@Test
- public void launchActivity_modeQrCodeScanner_shouldNotAutoFinish() {
- Intent intent = new Intent();
- intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
- WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode());
+ public void launchActivity_qrCodeScanner_shouldNotAutoFinish() {
+ Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
+ intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
+ intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
+
mActivityRule.launchActivity(intent);
assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(false);
}
@Test
- public void launchActivity_modeQrCodeGenerator_shouldNotAutoFinish() {
- Intent intent = new Intent();
- intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
- WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_GENERATOR.getMode());
+ public void launchActivity_qrCodeGenerator_shouldNotAutoFinish() {
+ Intent intent = new Intent(
+ WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
+ intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
+ intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
+
mActivityRule.launchActivity(intent);
assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(false);
}
@Test
- public void launchActivity_modeChooseSavedWifiNetwork_shouldNotAutoFinish() {
- Intent intent = new Intent();
- intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
- WifiDppConfiguratorActivity.LaunchMode
- .LAUNCH_MODE_CHOOSE_SAVED_WIFI_NETWORK.getMode());
+ public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() {
+ Intent intent = new Intent(
+ WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK);
+
mActivityRule.launchActivity(intent);
assertThat(mActivityRule.getActivity().isFinishing()).isEqualTo(false);
}
@Test
- public void launchActivity_noLaunchMode_shouldFinishActivityWithResultCodeCanceled() {
- // If we do not specify launch mode, the activity will finish itself right away
- Intent intent = new Intent();
- mActivityRule.launchActivity(intent);
+ public void testActivity_shouldImplementsWifiNetworkConfigRetriever() {
+ WifiDppConfiguratorActivity activity = mActivityRule.getActivity();
- assertThat(mActivityRule.getActivityResult().getResultCode()).
- isEqualTo(Activity.RESULT_CANCELED);
+ assertThat(activity instanceof WifiNetworkConfig.Retriever).isEqualTo(true);
}
}
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
+import com.android.settings.R;
+
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@Before
public void setUp() {
- Intent intent = new Intent();
- intent.putExtra(WifiDppConfiguratorActivity.EXTRA_LAUNCH_MODE,
- WifiDppConfiguratorActivity.LaunchMode.LAUNCH_MODE_QR_CODE_SCANNER.getMode());
+ Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
+ intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
+ intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
mActivityRule.launchActivity(intent);
}
@Test
- public void leftButton_shouldFinishActivityWithResultCodeCanceled() {
- onView(withText("Cancel")).perform(click());
-
- assertThat(mActivityRule.getActivityResult().getResultCode()).
- isEqualTo(Activity.RESULT_CANCELED);
- }
-
- @Test
public void rotateScreen_shouldNotCrash() {
mActivityRule.getActivity().setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);