Merge "Implement Wi-Fi DPP UI."
This commit is contained in:
committed by
Android (Google) Code Review
commit
db363a8026
@@ -3054,6 +3054,14 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".wifi.dpp.WifiDppEnrolleeActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER"/>
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".homepage.contextualcards.ContextualCardFeedbackDialog"
|
<activity android:name=".homepage.contextualcards.ContextualCardFeedbackDialog"
|
||||||
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" />
|
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert" />
|
||||||
<!-- This is the longest AndroidManifest.xml ever. -->
|
<!-- This is the longest AndroidManifest.xml ever. -->
|
||||||
|
@@ -44,8 +44,5 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"/>
|
android:layout_gravity="center"/>
|
||||||
|
|
||||||
<include layout="@layout/wifi_dpp_fragment_footer"
|
|
||||||
android:gravity="center|bottom"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@@ -2056,6 +2056,14 @@
|
|||||||
<string name="wifi_dpp_add_device_to_network">Add a device to this network</string>
|
<string name="wifi_dpp_add_device_to_network">Add a device to this network</string>
|
||||||
<!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=120] -->
|
<!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=120] -->
|
||||||
<string name="wifi_dpp_center_qr_code">Center the device\u2019s QR code below to add device to \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d</string>
|
<string name="wifi_dpp_center_qr_code">Center the device\u2019s QR code below to add device to \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d</string>
|
||||||
|
<!-- Title for the fragment to scan QR code [CHAR LIMIT=50] -->
|
||||||
|
<string name="wifi_dpp_scan_qr_code">Scan QR code</string>
|
||||||
|
<!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="wifi_dpp_scan_qr_code_join_network">Join \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d by scanning a QR code</string>
|
||||||
|
<!-- Title for the fragment to share Wi-Fi [CHAR LIMIT=50] -->
|
||||||
|
<string name="wifi_dpp_share_wifi">Share Wi\u2011Fi</string>
|
||||||
|
<!-- Hint for the user to use another device to scan QR code on screen to join Wi-Fi [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="wifi_dpp_scan_qr_code_with_another_device">Scan this QR code with another device to join \u201c<xliff:g id="ssid" example="OfficeWifi">%1$s</xliff:g>\u201d</string>
|
||||||
<!-- Label for the check box to share a network with other users on the same device -->
|
<!-- Label for the check box to share a network with other users on the same device -->
|
||||||
<string name="wifi_shared">Share with other device users</string>
|
<string name="wifi_shared">Share with other device users</string>
|
||||||
<!-- Hint for unchanged fields -->
|
<!-- Hint for unchanged fields -->
|
||||||
|
@@ -31,8 +31,26 @@ import com.android.internal.logging.nano.MetricsProto;
|
|||||||
import com.android.settings.core.InstrumentedActivity;
|
import com.android.settings.core.InstrumentedActivity;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To provision "other" device with specified Wi-Fi network.
|
||||||
|
*
|
||||||
|
* Uses different intents to specify different provisioning ways.
|
||||||
|
*
|
||||||
|
* For intent action {@code ACTION_CONFIGURATOR_QR_CODE_SCANNER} and
|
||||||
|
* {@code android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR}, specify the Wi-Fi network to be
|
||||||
|
* provisioned in:
|
||||||
|
*
|
||||||
|
* {@code WifiDppUtils.EXTRA_WIFI_SECURITY}
|
||||||
|
* {@code WifiDppUtils.EXTRA_WIFI_SSID}
|
||||||
|
* {@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)
|
||||||
|
* QR code in {@code WifiDppUtils.EXTRA_QR_CODE}
|
||||||
|
*/
|
||||||
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||||
WifiNetworkConfig.Retriever {
|
WifiNetworkConfig.Retriever,
|
||||||
|
WifiDppQrCodeGeneratorFragment.OnQrCodeGeneratorFragmentAddButtonClickedListener {
|
||||||
private static final String TAG = "WifiDppConfiguratorActivity";
|
private static final String TAG = "WifiDppConfiguratorActivity";
|
||||||
|
|
||||||
public static final String ACTION_CONFIGURATOR_QR_CODE_SCANNER =
|
public static final String ACTION_CONFIGURATOR_QR_CODE_SCANNER =
|
||||||
@@ -43,7 +61,6 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
"android.settings.WIFI_DPP_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK";
|
"android.settings.WIFI_DPP_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK";
|
||||||
|
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
private FragmentTransaction mFragmentTransaction;
|
|
||||||
|
|
||||||
/** The Wi-Fi network which will be configured */
|
/** The Wi-Fi network which will be configured */
|
||||||
private WifiNetworkConfig mWifiNetworkConfig;
|
private WifiNetworkConfig mWifiNetworkConfig;
|
||||||
@@ -57,12 +74,20 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.wifi_dpp_activity);
|
setContentView(R.layout.wifi_dpp_activity);
|
||||||
|
|
||||||
mFragmentManager = getSupportFragmentManager();
|
mFragmentManager = getSupportFragmentManager();
|
||||||
mFragmentTransaction = getSupportFragmentManager().beginTransaction();
|
|
||||||
|
|
||||||
Intent intent = getIntent();
|
handleIntent(getIntent());
|
||||||
|
|
||||||
|
ActionBar actionBar = getActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
|
actionBar.setElevation(0);
|
||||||
|
actionBar.setDisplayShowTitleEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleIntent(Intent intent) {
|
||||||
boolean cancelActivity = false;
|
boolean cancelActivity = false;
|
||||||
WifiNetworkConfig config;
|
WifiNetworkConfig config;
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
@@ -72,7 +97,7 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
cancelActivity = true;
|
cancelActivity = true;
|
||||||
} else {
|
} else {
|
||||||
mWifiNetworkConfig = config;
|
mWifiNetworkConfig = config;
|
||||||
addQrCodeScannerFragment(/* addToBackStack= */ false);
|
showQrCodeScannerFragment(/* addToBackStack= */ false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTION_CONFIGURATOR_QR_CODE_GENERATOR:
|
case ACTION_CONFIGURATOR_QR_CODE_GENERATOR:
|
||||||
@@ -81,11 +106,11 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
cancelActivity = true;
|
cancelActivity = true;
|
||||||
} else {
|
} else {
|
||||||
mWifiNetworkConfig = config;
|
mWifiNetworkConfig = config;
|
||||||
addQrCodeGeneratorFragment();
|
showQrCodeGeneratorFragment();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK:
|
case ACTION_CONFIGURATOR_CHOOSE_SAVED_WIFI_NETWORK:
|
||||||
addChooseSavedWifiNetworkFragment(/* addToBackStack */ false);
|
showChooseSavedWifiNetworkFragment(/* addToBackStack */ false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cancelActivity = true;
|
cancelActivity = true;
|
||||||
@@ -98,45 +123,55 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addQrCodeScannerFragment(boolean addToBackStack) {
|
private void showQrCodeScannerFragment(boolean addToBackStack) {
|
||||||
|
// Avoid to replace the same fragment during configuration change
|
||||||
|
if (mFragmentManager.findFragmentByTag(WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER) != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
|
WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
|
||||||
mFragmentTransaction.add(R.id.fragment_container, fragment);
|
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||||
|
|
||||||
|
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||||
|
WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||||
if (addToBackStack) {
|
if (addToBackStack) {
|
||||||
mFragmentTransaction.addToBackStack(/* name */ null);
|
fragmentTransaction.addToBackStack(/* name */ null);
|
||||||
}
|
}
|
||||||
mFragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showQrCodeGeneratorFragment() {
|
||||||
|
// Avoid to replace the same fragment during configuration change
|
||||||
|
if (mFragmentManager.findFragmentByTag(
|
||||||
|
WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR) != null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addQrCodeGeneratorFragment() {
|
|
||||||
WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
|
WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
|
||||||
mFragmentTransaction.add(R.id.fragment_container, fragment);
|
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||||
mFragmentTransaction.commit();
|
|
||||||
|
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||||
|
WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR);
|
||||||
|
fragmentTransaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addChooseSavedWifiNetworkFragment(boolean addToBackStack) {
|
private void showChooseSavedWifiNetworkFragment(boolean addToBackStack) {
|
||||||
ActionBar action = getActionBar();
|
// Avoid to replace the same fragment during configuration change
|
||||||
if (action != null) {
|
if (mFragmentManager.findFragmentByTag(
|
||||||
action.hide();
|
WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK) != null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiDppChooseSavedWifiNetworkFragment fragment =
|
WifiDppChooseSavedWifiNetworkFragment fragment =
|
||||||
new WifiDppChooseSavedWifiNetworkFragment();
|
new WifiDppChooseSavedWifiNetworkFragment();
|
||||||
mFragmentTransaction.add(R.id.fragment_container, fragment);
|
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||||
|
|
||||||
|
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||||
|
WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK);
|
||||||
if (addToBackStack) {
|
if (addToBackStack) {
|
||||||
mFragmentTransaction.addToBackStack(/* name */ null);
|
fragmentTransaction.addToBackStack(/* name */ null);
|
||||||
}
|
}
|
||||||
mFragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
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
|
@Override
|
||||||
@@ -153,4 +188,22 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onNavigateUp(){
|
||||||
|
Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
|
||||||
|
if (fragment instanceof WifiDppQrCodeGeneratorFragment) {
|
||||||
|
setResult(Activity.RESULT_CANCELED);
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
} else if (fragment instanceof WifiDppQrCodeScannerFragment) {
|
||||||
|
mFragmentManager.popBackStackImmediate();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onQrCodeGeneratorFragmentAddButtonClicked() {
|
||||||
|
showQrCodeScannerFragment(/* addToBackStack */ true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
106
src/com/android/settings/wifi/dpp/WifiDppEnrolleeActivity.java
Normal file
106
src/com/android/settings/wifi/dpp/WifiDppEnrolleeActivity.java
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.ActionBar;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
|
|
||||||
|
import com.android.settings.core.InstrumentedActivity;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To provision "this" device with specified Wi-Fi network.
|
||||||
|
*
|
||||||
|
* To use intent action {@code ACTION_ENROLLEE_QR_CODE_SCANNER}, specify the SSID string of the
|
||||||
|
* Wi-Fi network to be provisioned in {@code WifiDppUtils.EXTRA_QR_CODE}.
|
||||||
|
*/
|
||||||
|
public class WifiDppEnrolleeActivity extends InstrumentedActivity {
|
||||||
|
private static final String TAG = "WifiDppEnrolleeActivity";
|
||||||
|
|
||||||
|
public static final String ACTION_ENROLLEE_QR_CODE_SCANNER =
|
||||||
|
"android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER";
|
||||||
|
|
||||||
|
private FragmentManager mFragmentManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
//TODO:Should we use a new metrics category for Wi-Fi DPP?
|
||||||
|
return MetricsProto.MetricsEvent.WIFI_NETWORK_DETAILS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setContentView(R.layout.wifi_dpp_activity);
|
||||||
|
mFragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
|
handleIntent(getIntent());
|
||||||
|
|
||||||
|
ActionBar actionBar = getActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
|
actionBar.setElevation(0);
|
||||||
|
actionBar.setDisplayShowTitleEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleIntent(Intent intent) {
|
||||||
|
switch (intent.getAction()) {
|
||||||
|
case ACTION_ENROLLEE_QR_CODE_SCANNER:
|
||||||
|
String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);
|
||||||
|
showQrCodeScannerFragment(/* addToBackStack */ false, ssid);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log.e(TAG, "Launch with an invalid action");
|
||||||
|
setResult(Activity.RESULT_CANCELED);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showQrCodeScannerFragment(boolean addToBackStack, String ssid) {
|
||||||
|
// Avoid to replace the same fragment during configuration change
|
||||||
|
if (mFragmentManager.findFragmentByTag(WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER) != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment(ssid);
|
||||||
|
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||||
|
|
||||||
|
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||||
|
WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||||
|
if (addToBackStack) {
|
||||||
|
fragmentTransaction.addToBackStack(/* name */ null);
|
||||||
|
}
|
||||||
|
fragmentTransaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onNavigateUp(){
|
||||||
|
setResult(Activity.RESULT_CANCELED);
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -33,6 +33,10 @@ import com.android.settings.core.InstrumentedFragment;
|
|||||||
import com.android.settings.wifi.qrcode.QrDecorateView;
|
import com.android.settings.wifi.qrcode.QrDecorateView;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Should refine code to only initiate UI component in each child fragment.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There are below 4 fragments for Wi-Fi DPP UI flow, to reduce redundant code of UI components,
|
* There are below 4 fragments for Wi-Fi DPP UI flow, to reduce redundant code of UI components,
|
||||||
* this parent fragment instantiates all UI components and provides setting APIs for them.
|
* this parent fragment instantiates all UI components and provides setting APIs for them.
|
||||||
@@ -58,11 +62,9 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
|||||||
private ImageView mWifiApPictureView; //optional, for WifiDppAddDeviceFragment
|
private ImageView mWifiApPictureView; //optional, for WifiDppAddDeviceFragment
|
||||||
private TextView mChooseDifferentNetwork;//optional, for WifiDppAddDeviceFragment
|
private TextView mChooseDifferentNetwork;//optional, for WifiDppAddDeviceFragment
|
||||||
|
|
||||||
private Button mButtonLeft; //optional, for WifiDppQrCodeScannerFragment,
|
private Button mButtonLeft; //optional, for WifiDppChooseSavedWifiNetworkFragment,
|
||||||
// WifiDppChooseSavedWifiNetworkFragment,
|
|
||||||
// WifiDppAddDeviceFragment
|
// WifiDppAddDeviceFragment
|
||||||
private Button mButtonRight; //optional, for WifiDppQrCodeScannerFragment,
|
private Button mButtonRight; //optional, for WifiDppChooseSavedWifiNetworkFragment,
|
||||||
// WifiDppChooseSavedWifiNetworkFragment,
|
|
||||||
// WifiDppAddDeviceFragment
|
// WifiDppAddDeviceFragment
|
||||||
|
|
||||||
abstract protected int getLayout();
|
abstract protected int getLayout();
|
||||||
@@ -122,8 +124,7 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional, for WifiDppQrCodeScannerFragment,
|
* optional, for WifiDppChooseSavedWifiNetworkFragment,
|
||||||
* WifiDppChooseSavedWifiNetworkFragment,
|
|
||||||
* WifiDppAddDeviceFragment
|
* WifiDppAddDeviceFragment
|
||||||
*/
|
*/
|
||||||
protected void setLeftButtonText(String text) {
|
protected void setLeftButtonText(String text) {
|
||||||
@@ -133,8 +134,7 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional, for WifiDppQrCodeScannerFragment,
|
* optional, for WifiDppChooseSavedWifiNetworkFragment,
|
||||||
* WifiDppChooseSavedWifiNetworkFragment,
|
|
||||||
* WifiDppAddDeviceFragment
|
* WifiDppAddDeviceFragment
|
||||||
*/
|
*/
|
||||||
protected void setRightButtonText(String text) {
|
protected void setRightButtonText(String text) {
|
||||||
@@ -144,8 +144,7 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional, for WifiDppQrCodeScannerFragment,
|
* optional, for WifiDppChooseSavedWifiNetworkFragment,
|
||||||
* WifiDppChooseSavedWifiNetworkFragment,
|
|
||||||
* WifiDppAddDeviceFragment
|
* WifiDppAddDeviceFragment
|
||||||
*/
|
*/
|
||||||
protected void hideLeftButton() {
|
protected void hideLeftButton() {
|
||||||
@@ -155,8 +154,7 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional, for WifiDppQrCodeScannerFragment,
|
* optional, for WifiDppChooseSavedWifiNetworkFragment,
|
||||||
* WifiDppChooseSavedWifiNetworkFragment,
|
|
||||||
* WifiDppAddDeviceFragment
|
* WifiDppAddDeviceFragment
|
||||||
*/
|
*/
|
||||||
protected void hideRightButton() {
|
protected void hideRightButton() {
|
||||||
@@ -166,8 +164,7 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional, for WifiDppQrCodeScannerFragment,
|
* optional, for WifiDppChooseSavedWifiNetworkFragment,
|
||||||
* WifiDppChooseSavedWifiNetworkFragment,
|
|
||||||
* WifiDppAddDeviceFragment
|
* WifiDppAddDeviceFragment
|
||||||
*/
|
*/
|
||||||
protected void setLeftButtonOnClickListener(View.OnClickListener listener) {
|
protected void setLeftButtonOnClickListener(View.OnClickListener listener) {
|
||||||
@@ -177,8 +174,7 @@ public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* optional, for WifiDppQrCodeScannerFragment,
|
* optional, for WifiDppChooseSavedWifiNetworkFragment,
|
||||||
* WifiDppChooseSavedWifiNetworkFragment,
|
|
||||||
* WifiDppAddDeviceFragment
|
* WifiDppAddDeviceFragment
|
||||||
*/
|
*/
|
||||||
protected void setRightButtonOnClickListener(View.OnClickListener listener) {
|
protected void setRightButtonOnClickListener(View.OnClickListener listener) {
|
||||||
|
@@ -16,7 +16,12 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.dpp;
|
package com.android.settings.wifi.dpp;
|
||||||
|
|
||||||
|
import android.app.ActionBar;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
@@ -30,8 +35,64 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
|||||||
return R.layout.wifi_dpp_qrcode_generator_fragment;
|
return R.layout.wifi_dpp_qrcode_generator_fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Container Activity must implement this interface
|
||||||
|
public interface OnQrCodeGeneratorFragmentAddButtonClickedListener {
|
||||||
|
public void onQrCodeGeneratorFragmentAddButtonClicked();
|
||||||
|
}
|
||||||
|
OnQrCodeGeneratorFragmentAddButtonClickedListener mListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated (Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
WifiNetworkConfig wifiNetworkConfig = ((WifiNetworkConfig.Retriever) getActivity())
|
||||||
|
.getWifiNetworkConfig();
|
||||||
|
if (!WifiNetworkConfig.isValidConfig(wifiNetworkConfig)) {
|
||||||
|
throw new IllegalArgumentException("Invalid Wi-Fi network for configuring");
|
||||||
|
}
|
||||||
|
setTitle(getString(R.string.wifi_dpp_share_wifi));
|
||||||
|
setDescription(getString(R.string.wifi_dpp_scan_qr_code_with_another_device,
|
||||||
|
wifiNetworkConfig.getSsid()));
|
||||||
|
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
ActionBar actionBar = getActivity().getActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
actionBar.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
|
||||||
|
mListener = (OnQrCodeGeneratorFragmentAddButtonClickedListener) context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
mListener = null;
|
||||||
|
|
||||||
|
super.onDetach();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.next_label);
|
||||||
|
item.setIcon(R.drawable.ic_menu_add);
|
||||||
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||||
|
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem menuItem) {
|
||||||
|
switch (menuItem.getItemId()) {
|
||||||
|
case Menu.FIRST:
|
||||||
|
mListener.onQrCodeGeneratorFragmentAddButtonClicked();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(menuItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,12 +17,15 @@
|
|||||||
package com.android.settings.wifi.dpp;
|
package com.android.settings.wifi.dpp;
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.app.ActionBar;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Size;
|
import android.util.Size;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -38,15 +41,42 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
private SurfaceView mSurfaceView;
|
private SurfaceView mSurfaceView;
|
||||||
private QrDecorateView mDecorateView;
|
private QrDecorateView mDecorateView;
|
||||||
|
|
||||||
|
/** true if the fragment working for configurator, false enrollee*/
|
||||||
|
private final boolean mConfiguratorMode;
|
||||||
|
|
||||||
|
/** The SSID of the Wi-Fi network which the user specify to enroll */
|
||||||
|
private String mSsid;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getLayout() {
|
protected int getLayout() {
|
||||||
return R.layout.wifi_dpp_qrcode_scanner_fragment;
|
return R.layout.wifi_dpp_qrcode_scanner_fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configurator container activity of the fragment should create instance with this constructor.
|
||||||
|
*/
|
||||||
|
public WifiDppQrCodeScannerFragment() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
mConfiguratorMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
mConfiguratorMode = false;
|
||||||
|
mSsid = ssid;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
if (mConfiguratorMode) {
|
||||||
setTitle(getString(R.string.wifi_dpp_add_device_to_network));
|
setTitle(getString(R.string.wifi_dpp_add_device_to_network));
|
||||||
|
|
||||||
WifiNetworkConfig wifiNetworkConfig = ((WifiNetworkConfig.Retriever) getActivity())
|
WifiNetworkConfig wifiNetworkConfig = ((WifiNetworkConfig.Retriever) getActivity())
|
||||||
@@ -55,15 +85,16 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
throw new IllegalArgumentException("Invalid Wi-Fi network for configuring");
|
throw new IllegalArgumentException("Invalid Wi-Fi network for configuring");
|
||||||
}
|
}
|
||||||
setDescription(getString(R.string.wifi_dpp_center_qr_code, wifiNetworkConfig.getSsid()));
|
setDescription(getString(R.string.wifi_dpp_center_qr_code, wifiNetworkConfig.getSsid()));
|
||||||
|
} else {
|
||||||
|
setTitle(getString(R.string.wifi_dpp_scan_qr_code));
|
||||||
|
setDescription(getString(R.string.wifi_dpp_scan_qr_code_join_network, mSsid));
|
||||||
|
}
|
||||||
|
|
||||||
hideRightButton();
|
ActionBar actionBar = getActivity().getActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
setLeftButtonText(getString(android.R.string.cancel));
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
actionBar.show();
|
||||||
setLeftButtonOnClickListener((view) -> {
|
}
|
||||||
getActivity().setResult(Activity.RESULT_CANCELED);
|
|
||||||
getActivity().finish();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -78,6 +109,21 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
mDecorateView = (QrDecorateView) view.findViewById(R.id.decorate_view);
|
mDecorateView = (QrDecorateView) view.findViewById(R.id.decorate_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
SurfaceHolder surfaceHolder = mSurfaceView.getHolder();
|
||||||
|
surfaceHolder.removeCallback(this);
|
||||||
|
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
menu.removeItem(Menu.FIRST);
|
||||||
|
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(final SurfaceHolder holder) {
|
public void surfaceCreated(final SurfaceHolder holder) {
|
||||||
initCamera(holder);
|
initCamera(holder);
|
||||||
|
@@ -22,6 +22,27 @@ import android.content.Intent;
|
|||||||
* Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity
|
* Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity
|
||||||
*/
|
*/
|
||||||
public class WifiDppUtils {
|
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";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #TAG_FRAGMENT_QR_CODE_SCANNER
|
||||||
|
*/
|
||||||
|
public 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 =
|
||||||
|
"choose_saved_wifi_network_fragment";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #TAG_FRAGMENT_QR_CODE_SCANNER
|
||||||
|
*/
|
||||||
|
public static final String TAG_FRAGMENT_ADD_DEVICE = "add_device_fragment";
|
||||||
|
|
||||||
/** The data is from {@code com.android.settingslib.wifi.AccessPoint.securityToString} */
|
/** The data is from {@code com.android.settingslib.wifi.AccessPoint.securityToString} */
|
||||||
public static final String EXTRA_WIFI_SECURITY = "security";
|
public static final String EXTRA_WIFI_SECURITY = "security";
|
||||||
|
|
||||||
|
@@ -73,4 +73,12 @@ public class WifiDppConfiguratorActivityTest {
|
|||||||
|
|
||||||
assertThat(activity instanceof WifiNetworkConfig.Retriever).isEqualTo(true);
|
assertThat(activity instanceof WifiNetworkConfig.Retriever).isEqualTo(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testActivity_shouldImplementsQrCodeGeneratorFragmentCallback() {
|
||||||
|
WifiDppConfiguratorActivity activity = mActivityRule.getActivity();
|
||||||
|
|
||||||
|
assertThat(activity instanceof WifiDppQrCodeGeneratorFragment
|
||||||
|
.OnQrCodeGeneratorFragmentAddButtonClickedListener).isEqualTo(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
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;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class WifiDppQrCodeGeneratorFragmentTest {
|
||||||
|
@Rule
|
||||||
|
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
|
||||||
|
new ActivityTestRule<>(WifiDppConfiguratorActivity.class, true);
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void rotateScreen_shouldNotCrash() {
|
||||||
|
mActivityRule.getActivity().setRequestedOrientation(
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
|
mActivityRule.getActivity().setRequestedOrientation(
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
}
|
||||||
|
}
|
@@ -16,12 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.dpp;
|
package com.android.settings.wifi.dpp;
|
||||||
|
|
||||||
import static android.support.test.espresso.action.ViewActions.click;
|
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
|
||||||
import static android.support.test.espresso.Espresso.onView;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
|
Reference in New Issue
Block a user