2 * Copyright (C) 2019 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.wifi.details;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.net.wifi.WifiManager;
22 import android.util.Log;
24 import androidx.preference.Preference;
26 import com.android.settings.core.BasePreferenceController;
27 import com.android.settings.wifi.dpp.WifiDppUtils;
29 import com.android.settingslib.wifi.AccessPoint;
32 * {@link AbstractPreferenceController} that launches Wi-Fi Easy Connect configurator flow
34 public class AddDevicePreferenceController extends BasePreferenceController {
36 private static final String TAG = "AddDevicePreferenceController";
38 private static final String KEY_ADD_DEVICE = "add_device_to_network";
40 private AccessPoint mAccessPoint;
41 private WifiManager mWifiManager;
43 public AddDevicePreferenceController(Context context) {
44 super(context, KEY_ADD_DEVICE);
46 mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
49 public AddDevicePreferenceController init(AccessPoint accessPoint) {
50 mAccessPoint = accessPoint;
56 public int getAvailabilityStatus() {
57 if (WifiDppUtils.isSupportConfiguratorQrCodeScanner(mContext, mAccessPoint)) {
60 return CONDITIONALLY_UNAVAILABLE;
65 public boolean handlePreferenceTreeClick(Preference preference) {
66 if (KEY_ADD_DEVICE.equals(preference.getKey())) {
67 WifiDppUtils.showLockScreen(mContext, () -> launchWifiDppConfiguratorQrCodeScanner());
68 return true; /* click is handled */
71 return false; /* click is not handled */
74 private void launchWifiDppConfiguratorQrCodeScanner() {
75 final Intent intent = WifiDppUtils.getConfiguratorQrCodeScannerIntentOrNull(mContext,
76 mWifiManager, mAccessPoint);
79 Log.e(TAG, "Launch Wi-Fi QR code scanner with a wrong Wi-Fi network!");
81 mContext.startActivity(intent);