Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aaa20ad1 authored by Jeremy Klein's avatar Jeremy Klein
Browse files

Remove several TetherUtil functions which are no longer needed.

Slowly chipping away at TetherUtil to clean up this code.
This CL also adds an admin check to
ConnectivityService.isTetheringSupported to get parity with the
TetherUtil function before removing it.

Change-Id: Ibe7c5c9fb420d57e5458f77dad30e8a1e751a3e2
parent 57218cbb
Loading
Loading
Loading
Loading
+0 −30
Original line number Diff line number Diff line
@@ -15,40 +15,19 @@
 */
package com.android.settingslib;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.SystemProperties;
import android.os.UserManager;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;

public class TetherUtil {

    // Extras used for communicating with the TetherService.
    public static final String EXTRA_ADD_TETHER_TYPE = "extraAddTetherType";
    public static final String EXTRA_REM_TETHER_TYPE = "extraRemTetherType";
    public static final String EXTRA_SET_ALARM = "extraSetAlarm";
    /**
     * Tells the service to run a provision check now.
     */
    public static final String EXTRA_RUN_PROVISION = "extraRunProvision";

    public static boolean setWifiTethering(boolean enable, Context context) {
        final WifiManager wifiManager =
                (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        return wifiManager.setWifiApEnabled(null, enable);
    }

    public static boolean isWifiTetherEnabled(Context context) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        return wifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED;
    }

    private static boolean isEntitlementCheckRequired(Context context) {
        final CarrierConfigManager configManager = (CarrierConfigManager) context
             .getSystemService(Context.CARRIER_CONFIG_SERVICE);
@@ -71,13 +50,4 @@ public class TetherUtil {
        }
        return (provisionApp.length == 2);
    }

    public static boolean isTetheringSupported(Context context) {
        final ConnectivityManager cm =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        final boolean isAdminUser =
                UserManager.get(context).isUserAdmin(ActivityManager.getCurrentUser());
        return isAdminUser && cm.isTetheringSupported();
    }

}
+0 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ public interface HotspotController {
    void addCallback(Callback callback);
    void removeCallback(Callback callback);
    boolean isHotspotEnabled();
    boolean isHotspotSupported();
    void setHotspotEnabled(boolean enabled);
    boolean isTetheringAllowed();

+0 −7
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;

import com.android.settingslib.TetherUtil;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -97,11 +95,6 @@ public class HotspotControllerImpl implements HotspotController {
        return mHotspotState == WifiManager.WIFI_AP_STATE_ENABLED;
    }

    @Override
    public boolean isHotspotSupported() {
        return TetherUtil.isTetheringSupported(mContext);
    }

    @Override
    public boolean isTetheringAllowed() {
        return !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING,
+5 −1
Original line number Diff line number Diff line
@@ -2670,18 +2670,21 @@ public class ConnectivityService extends IConnectivityManager.Stub
    // if ro.tether.denied = true we default to no tethering
    // gservices could set the secure setting to 1 though to enable it on a build where it
    // had previously been turned off.
    @Override
    public boolean isTetheringSupported() {
        enforceTetherAccessPermission();
        int defaultVal = (SystemProperties.get("ro.tether.denied").equals("true") ? 0 : 1);
        boolean tetherEnabledInSettings = (Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.TETHER_SUPPORTED, defaultVal) != 0)
                && !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
        return tetherEnabledInSettings && ((mTethering.getTetherableUsbRegexs().length != 0 ||
        return tetherEnabledInSettings && mUserManager.isAdminUser() &&
                ((mTethering.getTetherableUsbRegexs().length != 0 ||
                mTethering.getTetherableWifiRegexs().length != 0 ||
                mTethering.getTetherableBluetoothRegexs().length != 0) &&
                mTethering.getUpstreamIfaceTypes().length != 0);
    }

    @Override
    public void startTethering(int type, ResultReceiver receiver,
            boolean showProvisioningUi) {
        ConnectivityManager.enforceTetherChangePermission(mContext);
@@ -2692,6 +2695,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        mTethering.startTethering(type, receiver, showProvisioningUi);
    }

    @Override
    public void stopTethering(int type) {
        ConnectivityManager.enforceTetherChangePermission(mContext);
        mTethering.stopTethering(type);