• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.wifi.factory;
18 
19 import android.content.Context;
20 import android.net.TetheringManager;
21 import android.net.wifi.WifiManager;
22 import android.util.Log;
23 
24 import androidx.annotation.NonNull;
25 import androidx.annotation.Nullable;
26 import androidx.lifecycle.ViewModelProvider;
27 import androidx.lifecycle.ViewModelStoreOwner;
28 
29 import com.android.settings.wifi.details.WifiNetworkDetailsViewModel;
30 import com.android.settings.wifi.dpp.WifiDppQrCodeGeneratorFragment;
31 import com.android.settings.wifi.repository.SharedConnectivityRepository;
32 import com.android.settings.wifi.repository.WifiHotspotRepository;
33 import com.android.settings.wifi.tether.WifiHotspotSecurityViewModel;
34 import com.android.settings.wifi.tether.WifiHotspotSpeedViewModel;
35 import com.android.settings.wifi.tether.WifiTetherViewModel;
36 
37 import org.jetbrains.annotations.NotNull;
38 
39 /**
40  * Wi-Fi Feature Provider
41  */
42 public class WifiFeatureProvider {
43     private static final String TAG = "WifiFeatureProvider";
44 
45     private final Context mAppContext;
46     private WifiManager mWifiManager;
47     private TetheringManager mTetheringManager;
48     private WifiVerboseLogging mWifiVerboseLogging;
49     private WifiHotspotRepository mWifiHotspotRepository;
50     private SharedConnectivityRepository mSharedConnectivityRepository;
51 
WifiFeatureProvider(@onNull Context appContext)52     public WifiFeatureProvider(@NonNull Context appContext) {
53         mAppContext = appContext;
54     }
55 
56     /**
57      * Gets WifiManager
58      */
getWifiManager()59     public WifiManager getWifiManager() {
60         if (mWifiManager == null) {
61             mWifiManager = mAppContext.getSystemService(WifiManager.class);
62         }
63         return mWifiManager;
64     }
65 
66     /**
67      * Gets TetheringManager
68      */
getTetheringManager()69     public TetheringManager getTetheringManager() {
70         if (mTetheringManager == null) {
71             mTetheringManager = mAppContext.getSystemService(TetheringManager.class);
72             verboseLog(TAG, "getTetheringManager():" + mTetheringManager);
73         }
74         return mTetheringManager;
75     }
76 
77     /**
78      * Gets WifiVerboseLogging
79      */
getWifiVerboseLogging()80     public WifiVerboseLogging getWifiVerboseLogging() {
81         if (mWifiVerboseLogging == null) {
82             mWifiVerboseLogging = new WifiVerboseLogging(mAppContext, getWifiManager());
83         }
84         return mWifiVerboseLogging;
85     }
86 
87     /**
88      * Gets WifiHotspotRepository
89      */
getWifiHotspotRepository()90     public WifiHotspotRepository getWifiHotspotRepository() {
91         if (mWifiHotspotRepository == null) {
92             mWifiHotspotRepository = new WifiHotspotRepository(mAppContext, getWifiManager(),
93                     getTetheringManager());
94             verboseLog(TAG, "getWifiHotspotRepository():" + mWifiHotspotRepository);
95         }
96         return mWifiHotspotRepository;
97     }
98 
99     /**
100      * Gets SharedConnectivityRepository
101      */
getSharedConnectivityRepository()102     public SharedConnectivityRepository getSharedConnectivityRepository() {
103         if (mSharedConnectivityRepository == null) {
104             mSharedConnectivityRepository = new SharedConnectivityRepository(mAppContext);
105             verboseLog(TAG, "getSharedConnectivityRepository():" + mSharedConnectivityRepository);
106         }
107         return mSharedConnectivityRepository;
108     }
109 
110     /**
111      * Gets WifiTetherViewModel
112      */
getWifiTetherViewModel(@otNull ViewModelStoreOwner owner)113     public WifiTetherViewModel getWifiTetherViewModel(@NotNull ViewModelStoreOwner owner) {
114         return new ViewModelProvider(owner).get(WifiTetherViewModel.class);
115     }
116 
117     /**
118      * Gets WifiHotspotSecurityViewModel
119      */
getWifiHotspotSecurityViewModel( @otNull ViewModelStoreOwner owner)120     public WifiHotspotSecurityViewModel getWifiHotspotSecurityViewModel(
121             @NotNull ViewModelStoreOwner owner) {
122         WifiHotspotSecurityViewModel viewModel =
123                 new ViewModelProvider(owner).get(WifiHotspotSecurityViewModel.class);
124         verboseLog(TAG, "getWifiHotspotSecurityViewModel():" + viewModel);
125         return viewModel;
126     }
127 
128     /**
129      * Gets WifiHotspotSpeedViewModel
130      */
getWifiHotspotSpeedViewModel( @otNull ViewModelStoreOwner owner)131     public WifiHotspotSpeedViewModel getWifiHotspotSpeedViewModel(
132             @NotNull ViewModelStoreOwner owner) {
133         WifiHotspotSpeedViewModel viewModel =
134                 new ViewModelProvider(owner).get(WifiHotspotSpeedViewModel.class);
135         verboseLog(TAG, "getWifiHotspotSpeedViewModel():" + viewModel);
136         return viewModel;
137     }
138 
139     /**
140      * Gets WifiNetworkDetailsViewModel
141      */
getWifiNetworkDetailsViewModel( @otNull ViewModelStoreOwner owner)142     public WifiNetworkDetailsViewModel getWifiNetworkDetailsViewModel(
143             @NotNull ViewModelStoreOwner owner) {
144         WifiNetworkDetailsViewModel viewModel =
145                 new ViewModelProvider(owner).get(WifiNetworkDetailsViewModel.class);
146         verboseLog(TAG, "getWifiNetworkDetailsViewModel():" + viewModel);
147         return viewModel;
148     }
149 
150     /**
151      * Gets an instance of WifiDppQrCodeGeneratorFragment
152      */
getWifiDppQrCodeGeneratorFragment()153     public WifiDppQrCodeGeneratorFragment getWifiDppQrCodeGeneratorFragment() {
154         WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
155         verboseLog(TAG, "getWifiDppQrCodeGeneratorFragment():" + fragment);
156         return fragment;
157     }
158 
159     /**
160      * Send a {@link Log#VERBOSE} log message.
161      *
162      * @param tag Used to identify the source of a log message.  It usually identifies
163      *            the class or activity where the log call occurs.
164      * @param msg The message you would like logged.
165      */
verboseLog(@ullable String tag, @NonNull String msg)166     public void verboseLog(@Nullable String tag, @NonNull String msg) {
167         getWifiVerboseLogging().log(tag, msg);
168     }
169 }
170 
171