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

Commit 6c2e52b6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Clear caller identity while checking Tether Change permission"

parents cb762626 5a3b4326
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.net.LinkAddress;
import android.net.NetworkUtils;
import android.os.Handler;
import android.os.IBinder;
import android.os.Binder;
import android.os.INetworkManagementService;
import android.os.Message;
import android.os.ServiceManager;
@@ -324,10 +325,19 @@ public class PanService extends ProfileService {

    void setBluetoothTethering(boolean value) {
        if(DBG) Log.d(TAG, "setBluetoothTethering: " + value +", mTetherOn: " + mTetherOn);
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        final Context context = getBaseContext();
        String pkgName = context.getOpPackageName();

        // Clear caller identity temporarily so enforceTetherChangePermission UID checks work
        // correctly
        final long identityToken = Binder.clearCallingIdentity();
        try {
            ConnectivityManager.enforceTetherChangePermission(context, pkgName);
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        } finally {
            Binder.restoreCallingIdentity(identityToken);
        }

        UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
        if (um.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
            throw new SecurityException("DISALLOW_CONFIG_TETHERING is enabled for this user.");