1 /*
2  * Copyright (C) 2022 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.server.wifi.hal;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.util.Log;
22 
23 /**
24  * Wrapper around a WifiP2pIface.
25  * May be initialized using a HIDL or AIDL WifiP2pIface.
26  */
27 public class WifiP2pIface implements WifiHal.WifiInterface {
28     private static final String TAG = "WifiP2pIface";
29     private final IWifiP2pIface mWifiP2pIface;
30 
WifiP2pIface(@onNull android.hardware.wifi.V1_0.IWifiP2pIface p2pIface)31     public WifiP2pIface(@NonNull android.hardware.wifi.V1_0.IWifiP2pIface p2pIface) {
32         mWifiP2pIface = createWifiP2pIfaceHidlImplMockable(p2pIface);
33     }
34 
WifiP2pIface(@onNull android.hardware.wifi.IWifiP2pIface p2pIface)35     public WifiP2pIface(@NonNull android.hardware.wifi.IWifiP2pIface p2pIface) {
36         mWifiP2pIface = createWifiP2pIfaceAidlImplMockable(p2pIface);
37     }
38 
createWifiP2pIfaceHidlImplMockable( android.hardware.wifi.V1_0.IWifiP2pIface p2pIface)39     protected WifiP2pIfaceHidlImpl createWifiP2pIfaceHidlImplMockable(
40             android.hardware.wifi.V1_0.IWifiP2pIface p2pIface) {
41         return new WifiP2pIfaceHidlImpl(p2pIface);
42     }
43 
createWifiP2pIfaceAidlImplMockable( android.hardware.wifi.IWifiP2pIface p2pIface)44     protected WifiP2pIfaceAidlImpl createWifiP2pIfaceAidlImplMockable(
45             android.hardware.wifi.IWifiP2pIface p2pIface) {
46         return new WifiP2pIfaceAidlImpl(p2pIface);
47     }
48 
handleNullIface(String methodStr)49     private void handleNullIface(String methodStr) {
50         Log.wtf(TAG, "Cannot call " + methodStr + " because mWifiP2pIface is null");
51     }
52 
53     /**
54      * See comments for {@link IWifiP2pIface#getName()}
55      */
56     @Override
57     @Nullable
getName()58     public String getName() {
59         final String methodStr = "getName";
60         if (mWifiP2pIface == null) {
61             handleNullIface(methodStr);
62             return null;
63         }
64         return mWifiP2pIface.getName();
65     }
66 }
67