Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d9f680fc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 4cafc50e 91c3146b
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}
+3 −20
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.settings.wifi.dpp;

import android.app.settings.SettingsEnums;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
@@ -29,12 +28,9 @@ import android.util.Log;

import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.android.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.core.InstrumentedActivity;

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
 * Easy Connect bootstrapping information string in Intent's data URI.
 */
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements
        WifiNetworkConfig.Retriever,
        WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener,
        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_IS_HOTSPOT = "key_is_hotspot";

    private FragmentManager mFragmentManager;

    /** The Wi-Fi network which will be configured */
    private WifiNetworkConfig mWifiNetworkConfig;

@@ -93,20 +87,10 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
        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
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.wifi_dpp_activity);
        mFragmentManager = getSupportFragmentManager();

        if (savedInstanceState != null) {
            String qrCode = savedInstanceState.getString(KEY_QR_CODE);

@@ -121,12 +105,11 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements

            mWifiNetworkConfig = WifiNetworkConfig.getValidConfigOrNull(security, ssid,
                    preSharedKey, hiddenSsid, networkId, isHotspot);
        } else {
            handleIntent(getIntent());
        }
    }

    private void handleIntent(Intent intent) {
    @Override
    protected void handleIntent(Intent intent) {
        boolean cancelActivity = false;
        WifiNetworkConfig config;
        switch (intent.getAction()) {
+2 −27
Original line number Diff line number Diff line
@@ -18,17 +18,12 @@ package com.android.settings.wifi.dpp;

import android.app.settings.SettingsEnums;
import android.content.Intent;
import android.content.res.Resources;
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.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.core.InstrumentedActivity;

/**
 * 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
 * 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 {
    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() {
        return SettingsEnums.SETTINGS_WIFI_DPP_ENROLLEE;
    }

    @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
    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) {
    protected void handleIntent(Intent intent) {
        switch (intent.getAction()) {
            case ACTION_ENROLLEE_QR_CODE_SCANNER:
                String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);