Call restoreCallingIdentity in finally block
Bug: 20822416
Change-Id: Ideadd8093408defe761288ecb9c728637555f351
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index 63e9e49..6bfef57 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -308,13 +308,16 @@
// Broadcast an intent indicating the phone account which was registered.
long token = Binder.clearCallingIdentity();
- Intent intent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED);
- intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,
- account.getAccountHandle());
- Log.i(this, "Sending phone-account intent as user");
- mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
- PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION);
- Binder.restoreCallingIdentity(token);
+ try {
+ Intent intent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED);
+ intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,
+ account.getAccountHandle());
+ Log.i(this, "Sending phone-account intent as user");
+ mContext.sendBroadcastAsUser(intent, UserHandle.ALL,
+ PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
} catch (Exception e) {
Log.e(this, e, "registerPhoneAccount %s", account);
throw e;
@@ -743,11 +746,14 @@
synchronized (mLock) {
final UserHandle userHandle = Binder.getCallingUserHandle();
long token = Binder.clearCallingIdentity();
- final Intent intent = new Intent(Intent.ACTION_CALL, handle);
- intent.putExtras(extras);
- new UserCallIntentProcessor(mContext, userHandle).processIntent(intent,
- callingPackage);
- Binder.restoreCallingIdentity(token);
+ try {
+ final Intent intent = new Intent(Intent.ACTION_CALL, handle);
+ intent.putExtras(extras);
+ new UserCallIntentProcessor(mContext, userHandle).processIntent(intent,
+ callingPackage);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
}