Merge "[Wi-Fi DPP] Add a parent class for WifiDppConfiguratorActivity and WifiDppEnrolleeActivity"

This commit is contained in:
TreeHugger Robot
2019-07-09 11:15:28 +00:00
committed by Android (Google) Code Review
3 changed files with 57 additions and 47 deletions

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.wifi.dpp;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.core.InstrumentedActivity;
abstract class WifiDppBaseActivity extends InstrumentedActivity {
protected FragmentManager mFragmentManager;
protected abstract void handleIntent(Intent intent);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wifi_dpp_activity);
mFragmentManager = getSupportFragmentManager();
if (savedInstanceState == null) {
handleIntent(getIntent());
}
}
@Override
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
resid = SetupWizardUtils.getTheme(getIntent());
theme.applyStyle(R.style.SetupWizardPartnerResource, /* force */ true);
super.onApplyThemeResource(theme, resid, first);
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.wifi.dpp;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
@@ -29,12 +28,9 @@ import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.core.InstrumentedActivity;
import java.util.List; import java.util.List;
@@ -55,7 +51,7 @@ import java.util.List;
* For intent action {@link Settings#ACTION_PROCESS_WIFI_EASY_CONNECT_URI}, specify Wi-Fi * For intent action {@link Settings#ACTION_PROCESS_WIFI_EASY_CONNECT_URI}, specify Wi-Fi
* Easy Connect bootstrapping information string in Intent's data URI. * Easy Connect bootstrapping information string in Intent's data URI.
*/ */
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements
WifiNetworkConfig.Retriever, WifiNetworkConfig.Retriever,
WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener, WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener,
WifiDppAddDeviceFragment.OnClickChooseDifferentNetworkListener, WifiDppAddDeviceFragment.OnClickChooseDifferentNetworkListener,
@@ -77,8 +73,6 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
private static final String KEY_WIFI_NETWORK_ID = "key_wifi_network_id"; private static final String KEY_WIFI_NETWORK_ID = "key_wifi_network_id";
private static final String KEY_IS_HOTSPOT = "key_is_hotspot"; private static final String KEY_IS_HOTSPOT = "key_is_hotspot";
private FragmentManager mFragmentManager;
/** The Wi-Fi network which will be configured */ /** The Wi-Fi network which will be configured */
private WifiNetworkConfig mWifiNetworkConfig; private WifiNetworkConfig mWifiNetworkConfig;
@@ -93,20 +87,10 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
return SettingsEnums.SETTINGS_WIFI_DPP_CONFIGURATOR; return SettingsEnums.SETTINGS_WIFI_DPP_CONFIGURATOR;
} }
@Override
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
resid = SetupWizardUtils.getTheme(getIntent());
theme.applyStyle(R.style.SetupWizardPartnerResource, /* force */ true);
super.onApplyThemeResource(theme, resid, first);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.wifi_dpp_activity);
mFragmentManager = getSupportFragmentManager();
if (savedInstanceState != null) { if (savedInstanceState != null) {
String qrCode = savedInstanceState.getString(KEY_QR_CODE); String qrCode = savedInstanceState.getString(KEY_QR_CODE);
@@ -121,12 +105,11 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
mWifiNetworkConfig = WifiNetworkConfig.getValidConfigOrNull(security, ssid, mWifiNetworkConfig = WifiNetworkConfig.getValidConfigOrNull(security, ssid,
preSharedKey, hiddenSsid, networkId, isHotspot); preSharedKey, hiddenSsid, networkId, isHotspot);
} else {
handleIntent(getIntent());
} }
} }
private void handleIntent(Intent intent) { @Override
protected void handleIntent(Intent intent) {
boolean cancelActivity = false; boolean cancelActivity = false;
WifiNetworkConfig config; WifiNetworkConfig config;
switch (intent.getAction()) { switch (intent.getAction()) {

View File

@@ -18,17 +18,12 @@ package com.android.settings.wifi.dpp;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log; import android.util.Log;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.core.InstrumentedActivity;
/** /**
* To provision "this" device with specified Wi-Fi network. * To provision "this" device with specified Wi-Fi network.
@@ -36,40 +31,20 @@ import com.android.settings.core.InstrumentedActivity;
* To use intent action {@code ACTION_ENROLLEE_QR_CODE_SCANNER}, specify the SSID string of the * 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_WIFI_SSID}. * Wi-Fi network to be provisioned in {@code WifiDppUtils.EXTRA_WIFI_SSID}.
*/ */
public class WifiDppEnrolleeActivity extends InstrumentedActivity implements public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements
WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener { WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener {
private static final String TAG = "WifiDppEnrolleeActivity"; private static final String TAG = "WifiDppEnrolleeActivity";
public static final String ACTION_ENROLLEE_QR_CODE_SCANNER = public static final String ACTION_ENROLLEE_QR_CODE_SCANNER =
"android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER"; "android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER";
private FragmentManager mFragmentManager;
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
return SettingsEnums.SETTINGS_WIFI_DPP_ENROLLEE; return SettingsEnums.SETTINGS_WIFI_DPP_ENROLLEE;
} }
@Override @Override
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { protected void handleIntent(Intent intent) {
resid = SetupWizardUtils.getTheme(getIntent());
theme.applyStyle(R.style.SetupWizardPartnerResource, /* force */ true);
super.onApplyThemeResource(theme, resid, first);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wifi_dpp_activity);
mFragmentManager = getSupportFragmentManager();
if (savedInstanceState == null) {
handleIntent(getIntent());
}
}
private void handleIntent(Intent intent) {
switch (intent.getAction()) { switch (intent.getAction()) {
case ACTION_ENROLLEE_QR_CODE_SCANNER: case ACTION_ENROLLEE_QR_CODE_SCANNER:
String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID); String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);