1 /*
2  * Copyright (C) 2015 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.settingslib;
17 
18 import android.content.Context;
19 import android.net.wifi.WifiManager;
20 import android.os.SystemProperties;
21 import android.telephony.CarrierConfigManager;
22 
23 public class TetherUtil {
24 
setWifiTethering(boolean enable, Context context)25     public static boolean setWifiTethering(boolean enable, Context context) {
26         final WifiManager wifiManager =
27                 (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
28         return wifiManager.setWifiApEnabled(null, enable);
29     }
30 
isEntitlementCheckRequired(Context context)31     private static boolean isEntitlementCheckRequired(Context context) {
32         final CarrierConfigManager configManager = (CarrierConfigManager) context
33              .getSystemService(Context.CARRIER_CONFIG_SERVICE);
34         return configManager.getConfig().getBoolean(CarrierConfigManager
35              .KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL);
36     }
37 
isProvisioningNeeded(Context context)38     public static boolean isProvisioningNeeded(Context context) {
39         // Keep in sync with other usage of config_mobile_hotspot_provision_app.
40         // ConnectivityManager#enforceTetherChangePermission
41         String[] provisionApp = context.getResources().getStringArray(
42                 com.android.internal.R.array.config_mobile_hotspot_provision_app);
43         if (SystemProperties.getBoolean("net.tethering.noprovisioning", false)
44                 || provisionApp == null) {
45             return false;
46         }
47         // Check carrier config for entitlement checks
48         if (isEntitlementCheckRequired(context) == false) {
49             return false;
50         }
51         return (provisionApp.length == 2);
52     }
53 }
54