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

Commit 3b1b4995 authored by Stanley Tng's avatar Stanley Tng Committed by android-build-merger
Browse files

Merge "Clear caller identity while checking Tether Change permission"

am: 6c2e52b6

Change-Id: Ia314dea6724273100d27d9b703c6144563612b97
parents 562e1439 6c2e52b6
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.");