• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.hotspot2;
18 
19 import android.content.Context;
20 import android.net.wifi.hotspot2.PasspointConfiguration;
21 
22 import com.android.org.conscrypt.TrustManagerImpl;
23 import com.android.server.wifi.Clock;
24 import com.android.server.wifi.SIMAccessor;
25 import com.android.server.wifi.WifiKeyStore;
26 import com.android.server.wifi.WifiMetrics;
27 import com.android.server.wifi.WifiNative;
28 
29 import java.security.KeyStore;
30 import java.security.NoSuchAlgorithmException;
31 
32 import javax.net.ssl.SSLContext;
33 
34 /**
35  * Factory class for creating Passpoint related objects. Useful for mocking object creations
36  * in the unit tests.
37  */
38 public class PasspointObjectFactory{
39     /**
40      * Create a PasspointEventHandler instance.
41      *
42      * @param wifiNative Instance of {@link WifiNative}
43      * @param callbacks Instance of {@link PasspointEventHandler.Callbacks}
44      * @return {@link PasspointEventHandler}
45      */
makePasspointEventHandler(WifiNative wifiNative, PasspointEventHandler.Callbacks callbacks)46     public PasspointEventHandler makePasspointEventHandler(WifiNative wifiNative,
47             PasspointEventHandler.Callbacks callbacks) {
48         return new PasspointEventHandler(wifiNative, callbacks);
49     }
50 
51     /**
52      * Create a PasspointProvider instance.
53      *
54      * @param keyStore Instance of {@link WifiKeyStore}
55      * @param config Configuration for the provider
56      * @param providerId Unique identifier for the provider
57      * @param packageName Package name of app adding/updating the {@code config}
58      * @return {@link PasspointProvider}
59      */
makePasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid, String packageName)60     public PasspointProvider makePasspointProvider(PasspointConfiguration config,
61             WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid,
62             String packageName) {
63         return new PasspointProvider(config, keyStore, simAccessor, providerId, creatorUid,
64                 packageName);
65     }
66 
67     /**
68      * Create a {@link PasspointConfigUserStoreData} instance.
69      *
70      * @param keyStore Instance of {@link WifiKeyStore}
71      * @param simAccessor Instance of {@link SIMAccessor}
72      * @param dataSource Passpoint configuration data source
73      * @return {@link PasspointConfigUserStoreData}
74      */
makePasspointConfigUserStoreData(WifiKeyStore keyStore, SIMAccessor simAccessor, PasspointConfigUserStoreData.DataSource dataSource)75     public PasspointConfigUserStoreData makePasspointConfigUserStoreData(WifiKeyStore keyStore,
76             SIMAccessor simAccessor, PasspointConfigUserStoreData.DataSource dataSource) {
77         return new PasspointConfigUserStoreData(keyStore, simAccessor, dataSource);
78     }
79 
80     /**
81      * Create a {@link PasspointConfigSharedStoreData} instance.
82      * @param dataSource Passpoint configuration data source
83      * @return {@link PasspointConfigSharedStoreData}
84      */
makePasspointConfigSharedStoreData( PasspointConfigSharedStoreData.DataSource dataSource)85     public PasspointConfigSharedStoreData makePasspointConfigSharedStoreData(
86             PasspointConfigSharedStoreData.DataSource dataSource) {
87         return new PasspointConfigSharedStoreData(dataSource);
88     }
89 
90     /**
91      * Create a AnqpCache instance.
92      *
93      * @param clock Instance of {@link Clock}
94      * @return {@link AnqpCache}
95      */
makeAnqpCache(Clock clock)96     public AnqpCache makeAnqpCache(Clock clock) {
97         return new AnqpCache(clock);
98     }
99 
100     /**
101      * Create an instance of {@link ANQPRequestManager}.
102      *
103      * @param handler Instance of {@link PasspointEventHandler}
104      * @param clock Instance of {@link Clock}
105      * @return {@link ANQPRequestManager}
106      */
makeANQPRequestManager(PasspointEventHandler handler, Clock clock)107     public ANQPRequestManager makeANQPRequestManager(PasspointEventHandler handler, Clock clock) {
108         return new ANQPRequestManager(handler, clock);
109     }
110 
111     /**
112      * Create an instance of {@link CertificateVerifier}.
113      *
114      * @return {@link CertificateVerifier}
115      */
makeCertificateVerifier()116     public CertificateVerifier makeCertificateVerifier() {
117         return new CertificateVerifier();
118     }
119 
120     /**
121      * Create an instance of {@link PasspointProvisioner}.
122      *
123      * @param context Instance of {@link Context}
124      * @param wifiNative Instance of {@link WifiNative}
125      * @param passpointManager Instance of {@link PasspointManager}
126      * @return {@link PasspointProvisioner}
127      */
makePasspointProvisioner(Context context, WifiNative wifiNative, PasspointManager passpointManager, WifiMetrics wifiMetrics)128     public PasspointProvisioner makePasspointProvisioner(Context context, WifiNative wifiNative,
129             PasspointManager passpointManager, WifiMetrics wifiMetrics) {
130         return new PasspointProvisioner(context, wifiNative, this, passpointManager, wifiMetrics);
131     }
132 
133     /**
134      * Create an instance of {@link OsuNetworkConnection}.
135      *
136      * @param context
137      * @return {@link OsuNetworkConnection}
138      */
makeOsuNetworkConnection(Context context)139     public OsuNetworkConnection makeOsuNetworkConnection(Context context) {
140         return new OsuNetworkConnection(context);
141     }
142 
143     /**
144      * Create an instance of {@link OsuServerConnection}.
145      *
146      * @return {@link OsuServerConnection}
147      */
makeOsuServerConnection()148     public OsuServerConnection makeOsuServerConnection() {
149         return new OsuServerConnection(null);
150     }
151 
152 
153     /**
154      * Create an instance of {@link WfaKeyStore}.
155      *
156      * @return WfaKeyStore {@link WfaKeyStore}
157      */
makeWfaKeyStore()158     public WfaKeyStore makeWfaKeyStore() {
159         return new WfaKeyStore();
160     }
161 
162     /**
163      * Create an instance of {@link SSLContext}.
164      *
165      * @param tlsVersion String indicate TLS version
166      * @return SSLContext an instance, corresponding to the TLS version
167      */
getSSLContext(String tlsVersion)168     public SSLContext getSSLContext(String tlsVersion) {
169         SSLContext tlsContext = null;
170         try {
171             tlsContext = SSLContext.getInstance(tlsVersion);
172         } catch (NoSuchAlgorithmException e) {
173             e.printStackTrace();
174         }
175         return tlsContext;
176     }
177 
178     /**
179      * Create an instance of {@link TrustManagerImpl}.
180      *
181      * @param ks KeyStore used to get root certs
182      * @return TrustManagerImpl an instance for delegating root cert validation
183      */
getTrustManagerImpl(KeyStore ks)184     public TrustManagerImpl getTrustManagerImpl(KeyStore ks) {
185         return new TrustManagerImpl(ks);
186     }
187 
188     /**
189      * Create an instance of {@link SystemInfo}.
190      *
191      * @param context Instance of {@link Context}
192      * @param wifiNative Instance of {@link WifiNative}
193      * @return {@Link Systeminfo} that is used for getting system related info.
194      */
getSystemInfo(Context context, WifiNative wifiNative)195     public SystemInfo getSystemInfo(Context context, WifiNative wifiNative) {
196         return SystemInfo.getInstance(context, wifiNative);
197     }
198 }
199