1 /*
2  * Copyright (C) 2021 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.development;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Intent;
21 import android.os.Bundle;
22 
23 import androidx.fragment.app.FragmentTransaction;
24 
25 import com.android.settings.R;
26 import com.android.settings.wifi.dpp.WifiDppBaseActivity;
27 
28 /**
29  * To scan an ADB QR code to pair a device.
30  *
31  * To use intent action {@code ACTION_ADB_QR_CODE_SCANNER}.
32  */
33 public class AdbQrCodeActivity extends WifiDppBaseActivity {
34     private static final String TAG = "AdbQrCodeActivity";
35 
36     static final String TAG_FRAGMENT_ADB_QR_CODE_SCANNER = "adb_qr_code_scanner_fragment";
37 
38     public static final String ACTION_ADB_QR_CODE_SCANNER =
39             "android.settings.ADB_QR_CODE_SCANNER";
40 
41     @Override
getMetricsCategory()42     public int getMetricsCategory() {
43         return SettingsEnums.SETTINGS_ADB_WIRELESS;
44     }
45 
46     @Override
onCreate(Bundle icicle)47     protected void onCreate(Bundle icicle) {
48         super.onCreate(icicle);
49         AdbQrcodeScannerFragment fragment =
50                 (AdbQrcodeScannerFragment) mFragmentManager.findFragmentByTag(
51                         TAG_FRAGMENT_ADB_QR_CODE_SCANNER);
52 
53         if (fragment == null) {
54             fragment = new AdbQrcodeScannerFragment();
55         } else {
56             if (fragment.isVisible()) {
57                 return;
58             }
59 
60             // When the fragment in back stack but not on top of the stack, we can simply pop
61             // stack because current fragment transactions are arranged in an order
62             mFragmentManager.popBackStackImmediate();
63             return;
64         }
65         final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
66 
67         fragmentTransaction.replace(R.id.fragment_container, fragment,
68                 TAG_FRAGMENT_ADB_QR_CODE_SCANNER);
69         fragmentTransaction.commit();
70     }
71 
72     @Override
handleIntent(Intent intent)73     protected void handleIntent(Intent intent) {
74     }
75 }
76