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

Commit f3b47e95 authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Android (Google) Code Review
Browse files

Merge "Use unified Tethering Permission Check" into lmp-dev

parents f16b4940 edb47668
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -1402,6 +1402,20 @@ public class ConnectivityManager {
        return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    }

    /** {@hide */
    public static final void enforceTetherChangePermission(Context context) {
        if (context.getResources().getStringArray(
                com.android.internal.R.array.config_mobile_hotspot_provision_app).length == 2) {
            // Have a provisioning app - must only let system apps (which check this app)
            // turn on tethering
            context.enforceCallingOrSelfPermission(
                    android.Manifest.permission.CONNECTIVITY_INTERNAL, "ConnectivityService");
        } else {
            context.enforceCallingOrSelfPermission(
                    android.Manifest.permission.CHANGE_NETWORK_STATE, "ConnectivityService");
        }
    }

    /**
     * Get the set of tetherable, available interfaces.  This list is limited by
     * device configuration and current interface existence.
+3 −11
Original line number Diff line number Diff line
@@ -1357,13 +1357,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                "ConnectivityService");
    }

    // TODO Make this a special check when it goes public
    private void enforceTetherChangePermission() {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CHANGE_NETWORK_STATE,
                "ConnectivityService");
    }

    private void enforceTetherAccessPermission() {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_NETWORK_STATE,
@@ -2389,8 +2382,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {

    // javadoc from interface
    public int tether(String iface) {
        enforceTetherChangePermission();

        ConnectivityManager.enforceTetherChangePermission(mContext);
        if (isTetheringSupported()) {
            return mTethering.tether(iface);
        } else {
@@ -2400,7 +2392,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {

    // javadoc from interface
    public int untether(String iface) {
        enforceTetherChangePermission();
        ConnectivityManager.enforceTetherChangePermission(mContext);

        if (isTetheringSupported()) {
            return mTethering.untether(iface);
@@ -2449,7 +2441,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    }

    public int setUsbTethering(boolean enable) {
        enforceTetherChangePermission();
        ConnectivityManager.enforceTetherChangePermission(mContext);
        if (isTetheringSupported()) {
            return mTethering.setUsbTethering(enable);
        } else {