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

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

Merge "Connect to network while clicking open or saved networks on slice"

parents 877a9a05 da2ca2f0
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2591,6 +2591,12 @@
            </intent-filter>
        </activity>

        <activity
            android:name=".wifi.slice.ConnectToWifiHandler"
            android:theme="@android:style/Theme.NoDisplay"
            android:excludeFromRecents="true"
            android:exported="false" />

        <activity android:name=".sim.SimDialogActivity"
                android:theme="@style/Theme.AlertDialog"
                android:label="@string/sim_settings_title"
+18 −18
Original line number Diff line number Diff line
@@ -562,24 +562,24 @@ public class WifiSettings extends RestrictedSettingsFragment
             * Bypass dialog and connect to unsecured networks, or previously connected saved
             * networks, or Passpoint provided networks.
             */
            WifiConfiguration config = mSelectedAccessPoint.getConfig();
            if (mSelectedAccessPoint.isOsuProvider()) {
            switch (WifiUtils.getConnectingType(mSelectedAccessPoint)) {
                case WifiUtils.CONNECT_TYPE_OSU_PROVISION:
                    mSelectedAccessPoint.startOsuProvisioning();
                    mClickedConnect = true;
            } else if ((mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
                    (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
                    break;

                case WifiUtils.CONNECT_TYPE_OPEN_NETWORK:
                    mSelectedAccessPoint.generateOpenNetworkConfig();
                    connect(mSelectedAccessPoint.getConfig(), mSelectedAccessPoint.isSaved());
            } else if (mSelectedAccessPoint.isSaved() && config != null
                    && config.getNetworkSelectionStatus() != null
                    && config.getNetworkSelectionStatus().getHasEverConnected()) {
                connect(config, true /* isSavedNetwork */);
            } else if (mSelectedAccessPoint.isPasspoint()) {
                // Access point provided by an installed Passpoint provider, connect using
                // the associated config.
                connect(config, true /* isSavedNetwork */);
            } else {
                    break;

                case WifiUtils.CONNECT_TYPE_SAVED_NETWORK:
                    connect(mSelectedAccessPoint.getConfig(), true /* isSavedNetwork */);
                    break;

                default:
                    showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
                    break;
            }
        } else if (preference == mAddPreference) {
            onAddNetworkPressed();
+29 −0
Original line number Diff line number Diff line
@@ -253,4 +253,33 @@ public class WifiUtils {

        return AccessPoint.SECURITY_NONE;
    }


    public static final int CONNECT_TYPE_OTHERS = 0;
    public static final int CONNECT_TYPE_OPEN_NETWORK = 1;
    public static final int CONNECT_TYPE_SAVED_NETWORK = 2;
    public static final int CONNECT_TYPE_OSU_PROVISION = 3;

    /**
     * Gets the connecting type of {@link AccessPoint}.
     */
    public static int getConnectingType(AccessPoint accessPoint) {
        final WifiConfiguration config = accessPoint.getConfig();
        if (accessPoint.isOsuProvider()) {
            return CONNECT_TYPE_OSU_PROVISION;
        } else if ((accessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
                (accessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
            return CONNECT_TYPE_OPEN_NETWORK;
        } else if (accessPoint.isSaved() && config != null
                && config.getNetworkSelectionStatus() != null
                && config.getNetworkSelectionStatus().getHasEverConnected()) {
            return CONNECT_TYPE_SAVED_NETWORK;
        } else if (accessPoint.isPasspoint()) {
            // Access point provided by an installed Passpoint provider, connect using
            // the associated config.
            return CONNECT_TYPE_SAVED_NETWORK;
        } else {
            return CONNECT_TYPE_OTHERS;
        }
    }
}
+63 −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.slice;

import android.app.Activity;
import android.net.wifi.WifiManager;
import android.os.Bundle;

import androidx.annotation.VisibleForTesting;

import com.android.settings.wifi.WifiDialogActivity;
import com.android.settings.wifi.WifiUtils;
import com.android.settingslib.wifi.AccessPoint;

/**
 * This activity helps connect to the Wi-Fi network which is open or saved
 */
public class ConnectToWifiHandler extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final Bundle accessPointState = getIntent().getBundleExtra(
                WifiDialogActivity.KEY_ACCESS_POINT_STATE);

        if (accessPointState != null) {
            connect(new AccessPoint(this, accessPointState));
        }
        finish();
    }

    @VisibleForTesting
    void connect(AccessPoint accessPoint) {
        switch (WifiUtils.getConnectingType(accessPoint)) {
            case WifiUtils.CONNECT_TYPE_OSU_PROVISION:
                accessPoint.startOsuProvisioning();
                break;

            case WifiUtils.CONNECT_TYPE_OPEN_NETWORK:
                accessPoint.generateOpenNetworkConfig();

            case WifiUtils.CONNECT_TYPE_SAVED_NETWORK:
                final WifiManager wifiManager = getSystemService(WifiManager.class);
                wifiManager.connect(accessPoint.getConfig(), null /* listener */);
                break;
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settings.slices.SliceBuilderUtils;
import com.android.settings.wifi.WifiDialogActivity;
import com.android.settings.wifi.WifiSettings;
import com.android.settings.wifi.WifiUtils;
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.WifiTracker;
@@ -176,6 +177,9 @@ public class WifiSlice implements CustomSliceable {
                    .setArguments(extras)
                    .setSourceMetricsCategory(SettingsEnums.WIFI)
                    .toIntent();
        } else if (WifiUtils.getConnectingType(accessPoint) != WifiUtils.CONNECT_TYPE_OTHERS) {
            intent = new Intent(mContext, ConnectToWifiHandler.class);
            intent.putExtra(WifiDialogActivity.KEY_ACCESS_POINT_STATE, extras);
        } else {
            intent = new Intent(mContext, WifiDialogActivity.class);
            intent.putExtra(WifiDialogActivity.KEY_ACCESS_POINT_STATE, extras);
Loading