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

Commit cab6c9bc authored by lucaslin's avatar lucaslin Committed by Lucas Lin
Browse files

Use [clear|restore]CallingIdentity instead of withCleanCallingIdentity

ConnectivityService is going to be a part of mainline module, to
prevent using @hide method - withCleanCallingIdentity(), use
clearCallingIdentity() & restoreCallingIdentity() instead.

Bug: 170598012
Test: FrameworksNetTests & CtsNetTestCasesLatestSdk
      & TetheringIntegrationTests
Change-Id: I20f45af4a4044844a171b09269981451a9d7cdb4
parent a2c355cc
Loading
Loading
Loading
Loading
+22 −14
Original line number Original line Diff line number Diff line
@@ -1705,16 +1705,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
            return newNc;
            return newNc;
        }
        }


        Binder.withCleanCallingIdentity(
        final long token = Binder.clearCallingIdentity();
                () -> {
        try {
            if (!mLocationPermissionChecker.checkLocationPermission(
            if (!mLocationPermissionChecker.checkLocationPermission(
                    callerPkgName, null /* featureId */, callerUid, null /* message */)) {
                    callerPkgName, null /* featureId */, callerUid, null /* message */)) {
                // Caller does not have the requisite location permissions. Reset the
                // Caller does not have the requisite location permissions. Reset the
                // owner's UID in the NetworkCapabilities.
                // owner's UID in the NetworkCapabilities.
                newNc.setOwnerUid(INVALID_UID);
                newNc.setOwnerUid(INVALID_UID);
            }
            }
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        }
        );


        return newNc;
        return newNc;
    }
    }
@@ -3871,8 +3872,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
                new CaptivePortal(new CaptivePortalImpl(network).asBinder()));
                new CaptivePortal(new CaptivePortalImpl(network).asBinder()));
        appIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
        appIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);


        Binder.withCleanCallingIdentity(() ->
        final long token = Binder.clearCallingIdentity();
                mContext.startActivityAsUser(appIntent, UserHandle.CURRENT));
        try {
            mContext.startActivityAsUser(appIntent, UserHandle.CURRENT);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }
    }


    private class CaptivePortalImpl extends ICaptivePortal.Stub {
    private class CaptivePortalImpl extends ICaptivePortal.Stub {
@@ -7759,10 +7764,13 @@ public class ConnectivityService extends IConnectivityManager.Stub


        final int userId = UserHandle.getCallingUserId();
        final int userId = UserHandle.getCallingUserId();


        Binder.withCleanCallingIdentity(() -> {
        final long token = Binder.clearCallingIdentity();
        try {
            final IpMemoryStore ipMemoryStore = IpMemoryStore.getMemoryStore(mContext);
            final IpMemoryStore ipMemoryStore = IpMemoryStore.getMemoryStore(mContext);
            ipMemoryStore.factoryReset();
            ipMemoryStore.factoryReset();
        });
        } finally {
            Binder.restoreCallingIdentity(token);
        }


        // Turn airplane mode off
        // Turn airplane mode off
        setAirplaneMode(false);
        setAirplaneMode(false);
+23 −18
Original line number Original line Diff line number Diff line
@@ -107,8 +107,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {


        String ifacePrefix = isTun ? TEST_TUN_PREFIX : TEST_TAP_PREFIX;
        String ifacePrefix = isTun ? TEST_TUN_PREFIX : TEST_TAP_PREFIX;
        String iface = ifacePrefix + sTestTunIndex.getAndIncrement();
        String iface = ifacePrefix + sTestTunIndex.getAndIncrement();
        return Binder.withCleanCallingIdentity(
        final long token = Binder.clearCallingIdentity();
                () -> {
        try {
        try {
            ParcelFileDescriptor tunIntf =
            ParcelFileDescriptor tunIntf =
                    ParcelFileDescriptor.adoptFd(jniCreateTunTap(isTun, iface));
                    ParcelFileDescriptor.adoptFd(jniCreateTunTap(isTun, iface));
@@ -122,8 +121,9 @@ class TestNetworkService extends ITestNetworkManager.Stub {
            return new TestNetworkInterface(tunIntf, iface);
            return new TestNetworkInterface(tunIntf, iface);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        }
                });
    }
    }


    /**
    /**
@@ -317,7 +317,12 @@ class TestNetworkService extends ITestNetworkManager.Stub {


        try {
        try {
            // This requires NETWORK_STACK privileges.
            // This requires NETWORK_STACK privileges.
            Binder.withCleanCallingIdentity(() -> mNMS.setInterfaceUp(iface));
            final long token = Binder.clearCallingIdentity();
            try {
                mNMS.setInterfaceUp(iface);
            } finally {
                Binder.restoreCallingIdentity(token);
            }


            // Synchronize all accesses to mTestNetworkTracker to prevent the case where:
            // Synchronize all accesses to mTestNetworkTracker to prevent the case where:
            // 1. TestNetworkAgent successfully binds to death of binder
            // 1. TestNetworkAgent successfully binds to death of binder