OSDN Git Service

Change action WIFI_DPP_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK to
authorArc Wang <arcwang@google.com>
Thu, 3 Jan 2019 10:09:06 +0000 (18:09 +0800)
committerArc Wang <arcwang@google.com>
Fri, 4 Jan 2019 01:59:40 +0000 (09:59 +0800)
PROCESS_WIFI_DPP_QR_CODE for more intuitive naming.

This change also caches the Wi-Fi DPP QR code in activity for
fragment to use.

Bug: 118794978
Test: manual test
Change-Id: I4bdb021883cb21ce7cc56edf656d1eee079359e5

AndroidManifest.xml
src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivity.java
tests/unit/src/com/android/settings/wifi/dpp/WifiDppConfiguratorActivityTest.java

index 871f609..0634ff1 100644 (file)
             <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"/>
+                <action android:name="android.settings.PROCESS_WIFI_DPP_QR_CODE"/>
                 <category android:name="android.intent.category.DEFAULT"/>
             </intent-filter>
         </activity>
index e89ebaa..c34bfd3 100644 (file)
@@ -44,7 +44,7 @@ import com.android.settings.R;
  * {@code WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY}
  * {@code WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID}
  *
- * For intent action {@code ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK}, specify Wi-Fi (DPP)
+ * For intent action {@code ACTION_PROCESS_WIFI_DPP_QR_CODE}, specify Wi-Fi (DPP)
  * QR code in {@code WifiDppUtils.EXTRA_QR_CODE}
  */
 public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
@@ -58,8 +58,8 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
             "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";
+    public static final String ACTION_PROCESS_WIFI_DPP_QR_CODE =
+            "android.settings.PROCESS_WIFI_DPP_QR_CODE";
 
     private FragmentManager mFragmentManager;
 
@@ -72,6 +72,9 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
     /** The information from Wi-Fi DPP QR code */
     private String mInformation;
 
+    /** The Wi-Fi DPP QR code from intent ACTION_PROCESS_WIFI_DPP_QR_CODE */
+    private WifiQrCode mWifiDppQrCode;
+
     @Override
     public int getMetricsCategory() {
         return MetricsProto.MetricsEvent.SETTINGS_WIFI_DPP_CONFIGURATOR;
@@ -115,8 +118,14 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
                     showQrCodeGeneratorFragment();
                 }
                 break;
-            case ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK:
-                showChooseSavedWifiNetworkFragment(/* addToBackStack */ false);
+            case ACTION_PROCESS_WIFI_DPP_QR_CODE:
+                String qrCode = intent.getStringExtra(WifiDppUtils.EXTRA_QR_CODE);
+                mWifiDppQrCode = getValidWiFiDppQrCodeOrNull(qrCode);
+                if (mWifiDppQrCode == null) {
+                    cancelActivity = true;
+                } else {
+                    showChooseSavedWifiNetworkFragment(/* addToBackStack */ false);
+                }
                 break;
             default:
                 cancelActivity = true;
@@ -199,6 +208,21 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
         fragmentTransaction.commit();
     }
 
+    private WifiQrCode getValidWiFiDppQrCodeOrNull(String qrCode) {
+        WifiQrCode wifiQrCode;
+        try {
+            wifiQrCode = new WifiQrCode(qrCode);
+        } catch(IllegalArgumentException e) {
+            return null;
+        }
+
+        if (WifiQrCode.SCHEME_DPP.equals(wifiQrCode.getScheme())) {
+            return wifiQrCode;
+        }
+
+        return null;
+    }
+
     @Override
     public WifiNetworkConfig getWifiNetworkConfig() {
         return mWifiNetworkConfig;
@@ -212,6 +236,10 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
         return mInformation;
     }
 
+    public WifiQrCode getWifiDppQrCode() {
+        return mWifiDppQrCode;
+    }
+
     @Override
     public boolean setWifiNetworkConfig(WifiNetworkConfig config) {
         if(!WifiNetworkConfig.isValidConfig(config)) {
@@ -223,7 +251,7 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
     }
 
     @Override
-    public boolean onNavigateUp(){
+    public boolean onNavigateUp() {
         Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
         if (fragment instanceof WifiDppQrCodeGeneratorFragment) {
             setResult(Activity.RESULT_CANCELED);
index 61033e9..8e64f5f 100644 (file)
@@ -38,6 +38,7 @@ public class WifiDppConfiguratorActivityTest {
         Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
         intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
         intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
+        intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
 
         mActivityRule.launchActivity(intent);
 
@@ -50,6 +51,7 @@ public class WifiDppConfiguratorActivityTest {
                 WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
         intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
         intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
+        intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
 
         mActivityRule.launchActivity(intent);
 
@@ -59,7 +61,10 @@ public class WifiDppConfiguratorActivityTest {
     @Test
     public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() {
         Intent intent = new Intent(
-                WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK);
+                WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
+        String qrCode = "DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD"
+               + "IgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;";
+        intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, qrCode);
 
         mActivityRule.launchActivity(intent);