From 013cb91a69b0da5f1b0f8c66ddbdc972b3436447 Mon Sep 17 00:00:00 2001 From: Alice Kuo Date: Wed, 2 Jun 2021 10:34:56 +0800 Subject: Use finally block for Binder.restoreCallingIdentity 1. Use final for Binder.clearCallingIdentity() to protect not being overwritten. 2. Protect it in the finally block of the try statement to avoid missing restore the CallingIdentity as exception. Bug: 189819183 Test: Manual test Change-Id: I2dd4cfc1aacecb0b77fa4c82b48b24b284271779 Merged-In: I2dd4cfc1aacecb0b77fa4c82b48b24b284271779 --- .../core/java/com/android/server/BluetoothManagerService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java index 992ef2657a65..12a94e199624 100644 --- a/services/core/java/com/android/server/BluetoothManagerService.java +++ b/services/core/java/com/android/server/BluetoothManagerService.java @@ -601,8 +601,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } // waive WRITE_SECURE_SETTINGS permission check long callingIdentity = Binder.clearCallingIdentity(); - Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.BLUETOOTH_ON, value); - Binder.restoreCallingIdentity(callingIdentity); + try { + Settings.Global.putInt(mContext.getContentResolver(), + Settings.Global.BLUETOOTH_ON, value); + } finally { + Binder.restoreCallingIdentity(callingIdentity); + } } /** -- cgit v1.2.3-59-g8ed1b