Clear calling identity when executing the callback

Callbacks need to be executed within Binder.clearCallingIdentity() since user code executed
in the callback should be with the calling pid/uid of the app, not the system.
Bug: 117795921
Test: Manually tested on eSIM operations

Change-Id: Ie50315e3fd287559ed516a24de09af6707c03d2f
This commit is contained in:
Jiashen Wang
2020-01-27 19:03:06 -08:00
parent ba702910aa
commit 86de2275b4

View File

@@ -20,6 +20,7 @@ import android.annotation.IntDef;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.content.Context; import android.content.Context;
import android.os.Binder;
import android.os.RemoteException; import android.os.RemoteException;
import android.service.euicc.EuiccProfileInfo; import android.service.euicc.EuiccProfileInfo;
import android.telephony.TelephonyFrameworkInitializer; import android.telephony.TelephonyFrameworkInitializer;
@@ -168,7 +169,12 @@ public class EuiccCardManager {
new IGetAllProfilesCallback.Stub() { new IGetAllProfilesCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, EuiccProfileInfo[] profiles) { public void onComplete(int resultCode, EuiccProfileInfo[] profiles) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, profiles)); executor.execute(() -> callback.onComplete(resultCode, profiles));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -192,7 +198,12 @@ public class EuiccCardManager {
new IGetProfileCallback.Stub() { new IGetProfileCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, EuiccProfileInfo profile) { public void onComplete(int resultCode, EuiccProfileInfo profile) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, profile)); executor.execute(() -> callback.onComplete(resultCode, profile));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -217,7 +228,12 @@ public class EuiccCardManager {
refresh, new IDisableProfileCallback.Stub() { refresh, new IDisableProfileCallback.Stub() {
@Override @Override
public void onComplete(int resultCode) { public void onComplete(int resultCode) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, null)); executor.execute(() -> callback.onComplete(resultCode, null));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -243,7 +259,12 @@ public class EuiccCardManager {
refresh, new ISwitchToProfileCallback.Stub() { refresh, new ISwitchToProfileCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, EuiccProfileInfo profile) { public void onComplete(int resultCode, EuiccProfileInfo profile) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, profile)); executor.execute(() -> callback.onComplete(resultCode, profile));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -268,7 +289,12 @@ public class EuiccCardManager {
nickname, new ISetNicknameCallback.Stub() { nickname, new ISetNicknameCallback.Stub() {
@Override @Override
public void onComplete(int resultCode) { public void onComplete(int resultCode) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, null)); executor.execute(() -> callback.onComplete(resultCode, null));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -292,7 +318,12 @@ public class EuiccCardManager {
new IDeleteProfileCallback.Stub() { new IDeleteProfileCallback.Stub() {
@Override @Override
public void onComplete(int resultCode) { public void onComplete(int resultCode) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, null)); executor.execute(() -> callback.onComplete(resultCode, null));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -317,7 +348,12 @@ public class EuiccCardManager {
new IResetMemoryCallback.Stub() { new IResetMemoryCallback.Stub() {
@Override @Override
public void onComplete(int resultCode) { public void onComplete(int resultCode) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, null)); executor.execute(() -> callback.onComplete(resultCode, null));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -340,7 +376,12 @@ public class EuiccCardManager {
new IGetDefaultSmdpAddressCallback.Stub() { new IGetDefaultSmdpAddressCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, String address) { public void onComplete(int resultCode, String address) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, address)); executor.execute(() -> callback.onComplete(resultCode, address));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -363,7 +404,12 @@ public class EuiccCardManager {
new IGetSmdsAddressCallback.Stub() { new IGetSmdsAddressCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, String address) { public void onComplete(int resultCode, String address) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, address)); executor.execute(() -> callback.onComplete(resultCode, address));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -388,7 +434,12 @@ public class EuiccCardManager {
new ISetDefaultSmdpAddressCallback.Stub() { new ISetDefaultSmdpAddressCallback.Stub() {
@Override @Override
public void onComplete(int resultCode) { public void onComplete(int resultCode) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, null)); executor.execute(() -> callback.onComplete(resultCode, null));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -411,7 +462,12 @@ public class EuiccCardManager {
new IGetRulesAuthTableCallback.Stub() { new IGetRulesAuthTableCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, EuiccRulesAuthTable rat) { public void onComplete(int resultCode, EuiccRulesAuthTable rat) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, rat)); executor.execute(() -> callback.onComplete(resultCode, rat));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -434,7 +490,12 @@ public class EuiccCardManager {
new IGetEuiccChallengeCallback.Stub() { new IGetEuiccChallengeCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, byte[] challenge) { public void onComplete(int resultCode, byte[] challenge) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, challenge)); executor.execute(() -> callback.onComplete(resultCode, challenge));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -457,7 +518,12 @@ public class EuiccCardManager {
new IGetEuiccInfo1Callback.Stub() { new IGetEuiccInfo1Callback.Stub() {
@Override @Override
public void onComplete(int resultCode, byte[] info) { public void onComplete(int resultCode, byte[] info) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, info)); executor.execute(() -> callback.onComplete(resultCode, info));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -480,7 +546,12 @@ public class EuiccCardManager {
new IGetEuiccInfo2Callback.Stub() { new IGetEuiccInfo2Callback.Stub() {
@Override @Override
public void onComplete(int resultCode, byte[] info) { public void onComplete(int resultCode, byte[] info) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, info)); executor.execute(() -> callback.onComplete(resultCode, info));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -522,7 +593,12 @@ public class EuiccCardManager {
new IAuthenticateServerCallback.Stub() { new IAuthenticateServerCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, byte[] response) { public void onComplete(int resultCode, byte[] response) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, response)); executor.execute(() -> callback.onComplete(resultCode, response));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -561,7 +637,12 @@ public class EuiccCardManager {
new IPrepareDownloadCallback.Stub() { new IPrepareDownloadCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, byte[] response) { public void onComplete(int resultCode, byte[] response) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, response)); executor.execute(() -> callback.onComplete(resultCode, response));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -589,7 +670,12 @@ public class EuiccCardManager {
new ILoadBoundProfilePackageCallback.Stub() { new ILoadBoundProfilePackageCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, byte[] response) { public void onComplete(int resultCode, byte[] response) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, response)); executor.execute(() -> callback.onComplete(resultCode, response));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -619,7 +705,12 @@ public class EuiccCardManager {
new ICancelSessionCallback.Stub() { new ICancelSessionCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, byte[] response) { public void onComplete(int resultCode, byte[] response) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, response)); executor.execute(() -> callback.onComplete(resultCode, response));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -643,7 +734,13 @@ public class EuiccCardManager {
new IListNotificationsCallback.Stub() { new IListNotificationsCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, EuiccNotification[] notifications) { public void onComplete(int resultCode, EuiccNotification[] notifications) {
executor.execute(() -> callback.onComplete(resultCode, notifications)); final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(
resultCode, notifications));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -667,7 +764,13 @@ public class EuiccCardManager {
events, new IRetrieveNotificationListCallback.Stub() { events, new IRetrieveNotificationListCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, EuiccNotification[] notifications) { public void onComplete(int resultCode, EuiccNotification[] notifications) {
executor.execute(() -> callback.onComplete(resultCode, notifications)); final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(
resultCode, notifications));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -691,7 +794,13 @@ public class EuiccCardManager {
seqNumber, new IRetrieveNotificationCallback.Stub() { seqNumber, new IRetrieveNotificationCallback.Stub() {
@Override @Override
public void onComplete(int resultCode, EuiccNotification notification) { public void onComplete(int resultCode, EuiccNotification notification) {
executor.execute(() -> callback.onComplete(resultCode, notification)); final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(
resultCode, notification));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -718,7 +827,12 @@ public class EuiccCardManager {
new IRemoveNotificationFromListCallback.Stub() { new IRemoveNotificationFromListCallback.Stub() {
@Override @Override
public void onComplete(int resultCode) { public void onComplete(int resultCode) {
final long token = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.onComplete(resultCode, null)); executor.execute(() -> callback.onComplete(resultCode, null));
} finally {
Binder.restoreCallingIdentity(token);
}
} }
}); });
} catch (RemoteException e) { } catch (RemoteException e) {