• 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.server.wifi.Clock;
23 import com.android.server.wifi.WifiCarrierInfoManager;
24 import com.android.server.wifi.WifiInjector;
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.KeyStoreException;
31 import java.security.NoSuchAlgorithmException;
32 
33 import javax.net.ssl.SSLContext;
34 import javax.net.ssl.TrustManagerFactory;
35 
36 /**
37  * Factory class for creating Passpoint related objects. Useful for mocking object creations
38  * in the unit tests.
39  */
40 public class PasspointObjectFactory{
41     /**
42      * Create a PasspointEventHandler instance.
43      *
44      * @param wifiNative Instance of {@link WifiNative}
45      * @param callbacks Instance of {@link PasspointEventHandler.Callbacks}
46      * @return {@link PasspointEventHandler}
47      */
makePasspointEventHandler(WifiInjector wifiInjector, PasspointEventHandler.Callbacks callbacks)48     public PasspointEventHandler makePasspointEventHandler(WifiInjector wifiInjector,
49             PasspointEventHandler.Callbacks callbacks) {
50         return new PasspointEventHandler(wifiInjector, callbacks);
51     }
52 
53     /**
54      * Create a PasspointProvider instance.
55      *
56      * @param config Configuration for the provider
57      * @param keyStore Instance of {@link WifiKeyStore}
58      * @param wifiCarrierInfoManager Instance of {@link WifiCarrierInfoManager}
59      * @param providerId Unique identifier for the provider
60      * @param creatorUid Creator UID
61      * @param packageName Package name of app adding/updating the {@code config}
62      * @param isFromSuggestion True if originated from a suggestion
63      * @param clock Instance of {@link Clock}
64      * @return {@link PasspointProvider}
65      */
makePasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, WifiCarrierInfoManager wifiCarrierInfoManager, long providerId, int creatorUid, String packageName, boolean isFromSuggestion, Clock clock)66     public PasspointProvider makePasspointProvider(PasspointConfiguration config,
67             WifiKeyStore keyStore, WifiCarrierInfoManager wifiCarrierInfoManager, long providerId,
68             int creatorUid, String packageName, boolean isFromSuggestion, Clock clock) {
69         return new PasspointProvider(config, keyStore, wifiCarrierInfoManager, providerId,
70                 creatorUid, packageName, isFromSuggestion, clock);
71     }
72 
73     /**
74      * Create a {@link PasspointConfigUserStoreData} instance.
75      *
76      * @param keyStore Instance of {@link WifiKeyStore}
77      * @param wifiCarrierInfoManager Instance of {@link WifiCarrierInfoManager}
78      * @param dataSource Passpoint configuration data source
79      * @param clock Instance of {@link Clock}
80      * @return {@link PasspointConfigUserStoreData}
81      */
makePasspointConfigUserStoreData(WifiKeyStore keyStore, WifiCarrierInfoManager wifiCarrierInfoManager, PasspointConfigUserStoreData.DataSource dataSource, Clock clock)82     public PasspointConfigUserStoreData makePasspointConfigUserStoreData(WifiKeyStore keyStore,
83             WifiCarrierInfoManager wifiCarrierInfoManager,
84             PasspointConfigUserStoreData.DataSource dataSource, Clock clock) {
85         return new PasspointConfigUserStoreData(keyStore, wifiCarrierInfoManager, dataSource,
86                 clock);
87     }
88 
89     /**
90      * Create a {@link PasspointConfigSharedStoreData} instance.
91      * @param dataSource Passpoint configuration data source
92      * @return {@link PasspointConfigSharedStoreData}
93      */
makePasspointConfigSharedStoreData( PasspointConfigSharedStoreData.DataSource dataSource)94     public PasspointConfigSharedStoreData makePasspointConfigSharedStoreData(
95             PasspointConfigSharedStoreData.DataSource dataSource) {
96         return new PasspointConfigSharedStoreData(dataSource);
97     }
98 
99     /**
100      * Create a AnqpCache instance.
101      *
102      * @param clock Instance of {@link Clock}
103      * @return {@link AnqpCache}
104      */
makeAnqpCache(Clock clock)105     public AnqpCache makeAnqpCache(Clock clock) {
106         return new AnqpCache(clock);
107     }
108 
109     /**
110      * Create an instance of {@link ANQPRequestManager}.
111      *
112      * @param handler Instance of {@link PasspointEventHandler}
113      * @param clock Instance of {@link Clock}
114      * @return {@link ANQPRequestManager}
115      */
makeANQPRequestManager(PasspointEventHandler handler, Clock clock)116     public ANQPRequestManager makeANQPRequestManager(PasspointEventHandler handler, Clock clock) {
117         return new ANQPRequestManager(handler, clock);
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 TrustManagerFactory}.
180      *
181      * @param ks KeyStore used to get root certs
182      * @return TrustManagerFactory an instance for root cert validation
183      */
getTrustManagerFactory(KeyStore ks)184     public TrustManagerFactory getTrustManagerFactory(KeyStore ks) {
185         try {
186             TrustManagerFactory trustManagerFactory = TrustManagerFactory
187                     .getInstance(TrustManagerFactory.getDefaultAlgorithm());
188             trustManagerFactory.init(ks);
189             return trustManagerFactory;
190         } catch (NoSuchAlgorithmException | KeyStoreException e) {
191             return null;
192         }
193     }
194 
195     /**
196      * Create an instance of {@link SystemInfo}.
197      *
198      * @param context Instance of {@link Context}
199      * @param wifiNative Instance of {@link WifiNative}
200      * @return {@Link Systeminfo} that is used for getting system related info.
201      */
getSystemInfo(Context context, WifiNative wifiNative)202     public SystemInfo getSystemInfo(Context context, WifiNative wifiNative) {
203         return SystemInfo.getInstance(context, wifiNative);
204     }
205 }
206