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
This commit is contained in:
Alice Kuo
2021-06-02 10:34:56 +08:00
parent 65db2bd3b3
commit 013cb91a69

View File

@@ -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);
}
}
/**