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

Commit 7998fbc6 authored by Sooraj Sasindran's avatar Sooraj Sasindran
Browse files

Do not use hidden withCleanCallingIdentity

Do not use hidden withCleanCallingIdentity

Bug: 140908357
Test: Build
Merged-In: Ic6cbd587c009df973d4602ff21e5b8a9c27293ff
Change-Id: Ic6cbd587c009df973d4602ff21e5b8a9c27293ff
parent b1c57994
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.RemoteException;
import android.os.SystemProperties;

import java.io.PrintWriter;
import java.util.function.Supplier;

/**
 * This class provides various util functions
@@ -74,6 +75,42 @@ public final class TelephonyUtils {
        throw new IllegalStateException("Missing ComponentInfo!");
    }

    /**
     * Convenience method for running the provided action enclosed in
     * {@link Binder#clearCallingIdentity}/{@link Binder#restoreCallingIdentity}
     *
     * Any exception thrown by the given action will need to be handled by caller.
     *
     */
    public static void runWithCleanCallingIdentity(
            @NonNull Runnable action) {
        long callingIdentity = Binder.clearCallingIdentity();
        try {
            action.run();
        } finally {
            Binder.restoreCallingIdentity(callingIdentity);
        }
    }


    /**
     * Convenience method for running the provided action enclosed in
     * {@link Binder#clearCallingIdentity}/{@link Binder#restoreCallingIdentity} and return
     * the result.
     *
     * Any exception thrown by the given action will need to be handled by caller.
     *
     */
    public static <T> T runWithCleanCallingIdentity(
            @NonNull Supplier<T> action) {
        long callingIdentity = Binder.clearCallingIdentity();
        try {
            return action.get();
        } finally {
            Binder.restoreCallingIdentity(callingIdentity);
        }
    }

    /**
     * Filter values in bundle to only basic types.
     */
+7 −3
Original line number Diff line number Diff line
@@ -163,9 +163,13 @@ public class ImsMmTelManager implements RegistrationManager {
            public void onCapabilitiesStatusChanged(int config) {
                if (mLocalCallback == null) return;

                Binder.withCleanCallingIdentity(() ->
                long callingIdentity = Binder.clearCallingIdentity();
                try {
                    mExecutor.execute(() -> mLocalCallback.onCapabilitiesStatusChanged(
                                new MmTelFeature.MmTelCapabilities(config))));
                            new MmTelFeature.MmTelCapabilities(config)));
                } finally {
                    restoreCallingIdentity(callingIdentity);
                }
            }

            @Override
+7 −3
Original line number Diff line number Diff line
@@ -75,9 +75,13 @@ public class ImsRcsManager implements RegistrationManager {
            public void onCapabilitiesStatusChanged(int config) {
                if (mLocalCallback == null) return;

                Binder.withCleanCallingIdentity(() ->
                long callingIdentity = Binder.clearCallingIdentity();
                try {
                    mExecutor.execute(() -> mLocalCallback.onAvailabilityChanged(
                                new RcsFeature.RcsImsCapabilities(config))));
                            new RcsFeature.RcsImsCapabilities(config)));
                } finally {
                    restoreCallingIdentity(callingIdentity);
                }
            }

            @Override
+14 −7
Original line number Diff line number Diff line
@@ -791,17 +791,24 @@ public class ProvisioningManager {

            @Override
            public final void onIntConfigChanged(int item, int value) {
                Binder.withCleanCallingIdentity(() ->
                long callingIdentity = Binder.clearCallingIdentity();
                try {
                    mExecutor.execute(() ->
                                mLocalConfigurationCallback.onProvisioningIntChanged(item, value)));
                            mLocalConfigurationCallback.onProvisioningIntChanged(item, value));
                } finally {
                    restoreCallingIdentity(callingIdentity);
                }
            }

            @Override
            public final void onStringConfigChanged(int item, String value) {
                Binder.withCleanCallingIdentity(() ->
                long callingIdentity = Binder.clearCallingIdentity();
                try {
                    mExecutor.execute(() ->
                                mLocalConfigurationCallback.onProvisioningStringChanged(item,
                                        value)));
                            mLocalConfigurationCallback.onProvisioningStringChanged(item, value));
                } finally {
                    restoreCallingIdentity(callingIdentity);
                }
            }

            private void setExecutor(Executor executor) {
+13 −6
Original line number Diff line number Diff line
@@ -251,15 +251,22 @@ public class RcsUceAdapter {
        IRcsUceControllerCallback internalCallback = new IRcsUceControllerCallback.Stub() {
            @Override
            public void onCapabilitiesReceived(List<RcsContactUceCapability> contactCapabilities) {
                Binder.withCleanCallingIdentity(() ->
                long callingIdentity = Binder.clearCallingIdentity();
                try {
                    executor.execute(() ->
                                c.onCapabilitiesReceived(contactCapabilities)));
                            c.onCapabilitiesReceived(contactCapabilities));
                } finally {
                    restoreCallingIdentity(callingIdentity);
                }
            }
            @Override
            public void onError(int errorCode) {
                Binder.withCleanCallingIdentity(() ->
                        executor.execute(() ->
                                c.onError(errorCode)));
                long callingIdentity = Binder.clearCallingIdentity();
                try {
                    executor.execute(() -> c.onError(errorCode));
                } finally {
                    restoreCallingIdentity(callingIdentity);
                }
            }
        };

Loading