Do not use hidden withCleanCallingIdentity
Do not use hidden withCleanCallingIdentity Bug: 140908357 Test: Build Change-Id: Ic6cbd587c009df973d4602ff21e5b8a9c27293ff
This commit is contained in:
@@ -161,9 +161,13 @@ public class ImsMmTelManager implements RegistrationManager {
|
||||
public void onCapabilitiesStatusChanged(int config) {
|
||||
if (mLocalCallback == null) return;
|
||||
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
mExecutor.execute(() -> mLocalCallback.onCapabilitiesStatusChanged(
|
||||
new MmTelFeature.MmTelCapabilities(config))));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() -> mLocalCallback.onCapabilitiesStatusChanged(
|
||||
new MmTelFeature.MmTelCapabilities(config)));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,9 +67,13 @@ public class ImsRcsManager implements RegistrationManager {
|
||||
public void onCapabilitiesStatusChanged(int config) {
|
||||
if (mLocalCallback == null) return;
|
||||
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
mExecutor.execute(() -> mLocalCallback.onAvailabilityChanged(
|
||||
new RcsFeature.RcsImsCapabilities(config))));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() -> mLocalCallback.onAvailabilityChanged(
|
||||
new RcsFeature.RcsImsCapabilities(config)));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -136,17 +136,24 @@ public class ProvisioningManager {
|
||||
|
||||
@Override
|
||||
public final void onIntConfigChanged(int item, int value) {
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
mExecutor.execute(() ->
|
||||
mLocalConfigurationCallback.onProvisioningIntChanged(item, value)));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() ->
|
||||
mLocalConfigurationCallback.onProvisioningIntChanged(item, value));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onStringConfigChanged(int item, String value) {
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
mExecutor.execute(() ->
|
||||
mLocalConfigurationCallback.onProvisioningStringChanged(item,
|
||||
value)));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() ->
|
||||
mLocalConfigurationCallback.onProvisioningStringChanged(item, value));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
private void setExecutor(Executor executor) {
|
||||
|
||||
@@ -245,15 +245,22 @@ public class RcsUceAdapter {
|
||||
IRcsUceControllerCallback internalCallback = new IRcsUceControllerCallback.Stub() {
|
||||
@Override
|
||||
public void onCapabilitiesReceived(List<RcsContactUceCapability> contactCapabilities) {
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
executor.execute(() ->
|
||||
c.onCapabilitiesReceived(contactCapabilities)));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
executor.execute(() ->
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -110,42 +110,63 @@ public interface RegistrationManager {
|
||||
public void onRegistered(int imsRadioTech) {
|
||||
if (mLocalCallback == null) return;
|
||||
|
||||
Binder.withCleanCallingIdentity(() -> mExecutor.execute(() ->
|
||||
mLocalCallback.onRegistered(getAccessType(imsRadioTech))));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() ->
|
||||
mLocalCallback.onRegistered(getAccessType(imsRadioTech)));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegistering(int imsRadioTech) {
|
||||
if (mLocalCallback == null) return;
|
||||
|
||||
Binder.withCleanCallingIdentity(() -> mExecutor.execute(() ->
|
||||
mLocalCallback.onRegistering(getAccessType(imsRadioTech))));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() ->
|
||||
mLocalCallback.onRegistering(getAccessType(imsRadioTech)));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeregistered(ImsReasonInfo info) {
|
||||
if (mLocalCallback == null) return;
|
||||
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
mExecutor.execute(() -> mLocalCallback.onUnregistered(info)));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() -> mLocalCallback.onUnregistered(info));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTechnologyChangeFailed(int imsRadioTech, ImsReasonInfo info) {
|
||||
if (mLocalCallback == null) return;
|
||||
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
mExecutor.execute(() -> mLocalCallback.onTechnologyChangeFailed(
|
||||
getAccessType(imsRadioTech), info)));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() -> mLocalCallback.onTechnologyChangeFailed(
|
||||
getAccessType(imsRadioTech), info));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscriberAssociatedUriChanged(Uri[] uris) {
|
||||
if (mLocalCallback == null) return;
|
||||
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
mExecutor.execute(() ->
|
||||
mLocalCallback.onSubscriberAssociatedUriChanged(uris)));
|
||||
long callingIdentity = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() -> mLocalCallback.onSubscriberAssociatedUriChanged(uris));
|
||||
} finally {
|
||||
restoreCallingIdentity(callingIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
private void setExecutor(Executor executor) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.annotation.NonNull;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.os.RemoteException;
|
||||
import android.telephony.ims.RcsContactUceCapability;
|
||||
import android.telephony.ims.aidl.IImsCapabilityCallback;
|
||||
@@ -33,7 +32,7 @@ import android.telephony.ims.stub.RcsPresenceExchangeImplBase;
|
||||
import android.telephony.ims.stub.RcsSipOptionsImplBase;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.util.FunctionalUtils;
|
||||
import com.android.internal.telephony.util.TelephonyUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -43,6 +42,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Base implementation of the RcsFeature APIs. Any ImsService wishing to support RCS should extend
|
||||
@@ -150,13 +150,13 @@ public class RcsFeature extends ImsFeature {
|
||||
|
||||
// Call the methods with a clean calling identity on the executor and wait indefinitely for
|
||||
// the future to return.
|
||||
private void executeMethodAsync(FunctionalUtils.ThrowingRunnable r, String errorLogName)
|
||||
private void executeMethodAsync(Runnable r, String errorLogName)
|
||||
throws RemoteException {
|
||||
// call with a clean calling identity on the executor and wait indefinitely for the
|
||||
// future to return.
|
||||
try {
|
||||
CompletableFuture.runAsync(
|
||||
() -> Binder.withCleanCallingIdentity(r), mExecutor).join();
|
||||
() -> TelephonyUtils.runWithCleanCallingIdentity(r), mExecutor).join();
|
||||
} catch (CancellationException | CompletionException e) {
|
||||
Log.w(LOG_TAG, "RcsFeatureBinder - " + errorLogName + " exception: "
|
||||
+ e.getMessage());
|
||||
@@ -164,12 +164,12 @@ public class RcsFeature extends ImsFeature {
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T executeMethodAsyncForResult(FunctionalUtils.ThrowingSupplier<T> r,
|
||||
private <T> T executeMethodAsyncForResult(Supplier<T> r,
|
||||
String errorLogName) throws RemoteException {
|
||||
// call with a clean calling identity on the executor and wait indefinitely for the
|
||||
// future to return.
|
||||
CompletableFuture<T> future = CompletableFuture.supplyAsync(
|
||||
() -> Binder.withCleanCallingIdentity(r), mExecutor);
|
||||
() -> TelephonyUtils.runWithCleanCallingIdentity(r), mExecutor);
|
||||
try {
|
||||
return future.get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.os.RemoteException;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* This class provides various util functions
|
||||
@@ -71,4 +72,40 @@ public final class TelephonyUtils {
|
||||
if (resolveInfo.providerInfo != null) return resolveInfo.providerInfo;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user