1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.settings.wifi.dpp; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Intent; 21 import android.util.Log; 22 23 import androidx.fragment.app.FragmentTransaction; 24 25 import com.android.settings.R; 26 27 /** 28 * To provision "this" device with specified Wi-Fi network. 29 * 30 * To use intent action {@code ACTION_ENROLLEE_QR_CODE_SCANNER}, specify the SSID string of the 31 * Wi-Fi network to be provisioned in {@code WifiDppUtils.EXTRA_WIFI_SSID}. 32 */ 33 public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements 34 WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener { 35 private static final String TAG = "WifiDppEnrolleeActivity"; 36 37 static final String ACTION_ENROLLEE_QR_CODE_SCANNER = 38 "android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER"; 39 40 @Override getMetricsCategory()41 public int getMetricsCategory() { 42 return SettingsEnums.SETTINGS_WIFI_DPP_ENROLLEE; 43 } 44 45 @Override handleIntent(Intent intent)46 protected void handleIntent(Intent intent) { 47 String action = intent != null ? intent.getAction() : null; 48 if (action == null) { 49 finish(); 50 return; 51 } 52 53 switch (action) { 54 case ACTION_ENROLLEE_QR_CODE_SCANNER: 55 String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID); 56 showQrCodeScannerFragment(ssid); 57 break; 58 default: 59 Log.e(TAG, "Launch with an invalid action"); 60 finish(); 61 } 62 } 63 showQrCodeScannerFragment(String ssid)64 private void showQrCodeScannerFragment(String ssid) { 65 WifiDppQrCodeScannerFragment fragment = 66 (WifiDppQrCodeScannerFragment) mFragmentManager.findFragmentByTag( 67 WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER); 68 69 if (fragment == null) { 70 fragment = new WifiDppQrCodeScannerFragment(ssid); 71 } else { 72 if (fragment.isVisible()) { 73 return; 74 } 75 76 // When the fragment in back stack but not on top of the stack, we can simply pop 77 // stack because current fragment transactions are arranged in an order 78 mFragmentManager.popBackStackImmediate(); 79 return; 80 } 81 final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); 82 83 fragmentTransaction.replace(R.id.fragment_container, fragment, 84 WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER); 85 fragmentTransaction.commit(); 86 } 87 88 @Override onScanWifiDppSuccess(WifiQrCode wifiQrCode)89 public void onScanWifiDppSuccess(WifiQrCode wifiQrCode) { 90 // Do nothing 91 } 92 } 93