blob: abbef702bd9f3e0eef0e21e0cc94ec87ba946eba [file] [log] [blame]
Jason Monk95f03c42015-02-11 13:28:26 -05001/*
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 */
16package com.android.settingslib;
17
Jason Monk95f03c42015-02-11 13:28:26 -050018import android.content.Context;
Jason Monk95f03c42015-02-11 13:28:26 -050019import android.os.SystemProperties;
Fan Zhang9c8d2fb2017-05-08 10:00:47 -070020import android.support.annotation.VisibleForTesting;
Chris Manton1ba0fa02015-09-01 13:56:46 -070021import android.telephony.CarrierConfigManager;
Jason Monk95f03c42015-02-11 13:28:26 -050022
23public class TetherUtil {
24
Fan Zhang9c8d2fb2017-05-08 10:00:47 -070025 @VisibleForTesting
26 static boolean isEntitlementCheckRequired(Context context) {
Chris Manton1ba0fa02015-09-01 13:56:46 -070027 final CarrierConfigManager configManager = (CarrierConfigManager) context
28 .getSystemService(Context.CARRIER_CONFIG_SERVICE);
Fan Zhang9c8d2fb2017-05-08 10:00:47 -070029 if (configManager == null || configManager.getConfig() == null) {
30 // return service default
31 return true;
32 }
Chris Manton1ba0fa02015-09-01 13:56:46 -070033 return configManager.getConfig().getBoolean(CarrierConfigManager
34 .KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL);
35 }
36
Jason Monk95f03c42015-02-11 13:28:26 -050037 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 Manton1ba0fa02015-09-01 13:56:46 -070046 // Check carrier config for entitlement checks
47 if (isEntitlementCheckRequired(context) == false) {
48 return false;
49 }
Jason Monk95f03c42015-02-11 13:28:26 -050050 return (provisionApp.length == 2);
51 }
Jason Monk95f03c42015-02-11 13:28:26 -050052}