1 /*
2  * Copyright (C) 2020 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 package com.android.settings.wifi.dpp;
17 
18 import android.content.Context;
19 import android.text.TextUtils;
20 
21 /**
22  * Extension of WifiQrCode to support ADB QR code format.
23  * It will be based on the ZXing format:
24  *
25  * WIFI:T:ADB;S:myname;P:mypassword;;
26  */
27 public class AdbQrCode extends WifiQrCode {
28     static final String SECURITY_ADB = "ADB";
29 
30     private WifiNetworkConfig mAdbConfig;
31 
AdbQrCode(String qrCode)32     public AdbQrCode(String qrCode) throws IllegalArgumentException {
33         super(qrCode);
34 
35         // Only accept the zxing format.
36         if (!WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG.equals(getScheme())) {
37             throw new IllegalArgumentException("DPP format not supported for ADB QR code");
38         }
39 
40         mAdbConfig = getWifiNetworkConfig();
41         if (!SECURITY_ADB.equals(mAdbConfig.getSecurity())) {
42             throw new IllegalArgumentException("Invalid security type");
43         }
44 
45         if (TextUtils.isEmpty(mAdbConfig.getSsid())) {
46             throw new IllegalArgumentException("Empty service name");
47         }
48 
49         if (TextUtils.isEmpty(mAdbConfig.getPreSharedKey())) {
50             throw new IllegalArgumentException("Empty password");
51         }
52     }
53 
getAdbNetworkConfig()54     public WifiNetworkConfig getAdbNetworkConfig() {
55         return mAdbConfig;
56     }
57 
58     /**
59      * Triggers a vibration to notify of a valid QR code.
60      *
61      * @param context The context to use
62      */
triggerVibrationForQrCodeRecognition(Context context)63     public static void triggerVibrationForQrCodeRecognition(Context context) {
64         WifiDppUtils.triggerVibrationForQrCodeRecognition(context);
65     }
66 }
67