Jason Monk | 95f03c4 | 2015-02-11 13:28:26 -0500 | [diff] [blame] | 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 | |
Jason Monk | 95f03c4 | 2015-02-11 13:28:26 -0500 | [diff] [blame] | 18 | import android.content.Context; |
Jason Monk | 95f03c4 | 2015-02-11 13:28:26 -0500 | [diff] [blame] | 19 | import android.os.SystemProperties; |
Fan Zhang | 9c8d2fb | 2017-05-08 10:00:47 -0700 | [diff] [blame] | 20 | import android.support.annotation.VisibleForTesting; |
Chris Manton | 1ba0fa0 | 2015-09-01 13:56:46 -0700 | [diff] [blame] | 21 | import android.telephony.CarrierConfigManager; |
Jason Monk | 95f03c4 | 2015-02-11 13:28:26 -0500 | [diff] [blame] | 22 | |
| 23 | public class TetherUtil { |
| 24 | |
Fan Zhang | 9c8d2fb | 2017-05-08 10:00:47 -0700 | [diff] [blame] | 25 | @VisibleForTesting |
| 26 | static boolean isEntitlementCheckRequired(Context context) { |
Chris Manton | 1ba0fa0 | 2015-09-01 13:56:46 -0700 | [diff] [blame] | 27 | final CarrierConfigManager configManager = (CarrierConfigManager) context |
| 28 | .getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Fan Zhang | 9c8d2fb | 2017-05-08 10:00:47 -0700 | [diff] [blame] | 29 | if (configManager == null || configManager.getConfig() == null) { |
| 30 | // return service default |
| 31 | return true; |
| 32 | } |
Chris Manton | 1ba0fa0 | 2015-09-01 13:56:46 -0700 | [diff] [blame] | 33 | return configManager.getConfig().getBoolean(CarrierConfigManager |
| 34 | .KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL); |
| 35 | } |
| 36 | |
Jason Monk | 95f03c4 | 2015-02-11 13:28:26 -0500 | [diff] [blame] | 37 | public static boolean isProvisioningNeeded(Context context) { |
| 38 | // Keep in sync with other usage of config_mobile_hotspot_provision_app. |
| 39 | // ConnectivityManager#enforceTetherChangePermission |
| 40 | String[] provisionApp = context.getResources().getStringArray( |
| 41 | com.android.internal.R.array.config_mobile_hotspot_provision_app); |
| 42 | if (SystemProperties.getBoolean("net.tethering.noprovisioning", false) |
| 43 | || provisionApp == null) { |
| 44 | return false; |
| 45 | } |
Chris Manton | 1ba0fa0 | 2015-09-01 13:56:46 -0700 | [diff] [blame] | 46 | // Check carrier config for entitlement checks |
| 47 | if (isEntitlementCheckRequired(context) == false) { |
| 48 | return false; |
| 49 | } |
Jason Monk | 95f03c4 | 2015-02-11 13:28:26 -0500 | [diff] [blame] | 50 | return (provisionApp.length == 2); |
| 51 | } |
Jason Monk | 95f03c4 | 2015-02-11 13:28:26 -0500 | [diff] [blame] | 52 | } |