From ca9a81be6d88a684b0566da0b2fb76743d6c02be Mon Sep 17 00:00:00 2001 From: "Kyeongkab.Nam" Date: Tue, 23 Nov 2021 10:30:19 +0900 Subject: Fix permission error of binding to TvInputService Bind to the TvInputService even if TvInputService calls addHardwareInput(), addHdmiInput(), or removeHardwareInput(). Bug: 207301256 Test: manual Change-Id: I91cdf49f9ff1af240b5d87cec02e95ae305cf46f --- .../android/server/tv/TvInputManagerService.java | 43 +++++++++++++++------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java index b9ceec15c9ab..2f54f302af6c 100755 --- a/services/core/java/com/android/server/tv/TvInputManagerService.java +++ b/services/core/java/com/android/server/tv/TvInputManagerService.java @@ -2985,32 +2985,47 @@ public final class TvInputManagerService extends SystemService { public void addHardwareInput(int deviceId, TvInputInfo inputInfo) { ensureHardwarePermission(); ensureValidInput(inputInfo); - synchronized (mLock) { - mTvInputHardwareManager.addHardwareInput(deviceId, inputInfo); - addHardwareInputLocked(inputInfo); + final long identity = Binder.clearCallingIdentity(); + try { + synchronized (mLock) { + mTvInputHardwareManager.addHardwareInput(deviceId, inputInfo); + addHardwareInputLocked(inputInfo); + } + } finally { + Binder.restoreCallingIdentity(identity); } } public void addHdmiInput(int id, TvInputInfo inputInfo) { ensureHardwarePermission(); ensureValidInput(inputInfo); - synchronized (mLock) { - mTvInputHardwareManager.addHdmiInput(id, inputInfo); - addHardwareInputLocked(inputInfo); + final long identity = Binder.clearCallingIdentity(); + try { + synchronized (mLock) { + mTvInputHardwareManager.addHdmiInput(id, inputInfo); + addHardwareInputLocked(inputInfo); + } + } finally { + Binder.restoreCallingIdentity(identity); } } public void removeHardwareInput(String inputId) { ensureHardwarePermission(); - synchronized (mLock) { - ServiceState serviceState = getServiceStateLocked(mComponent, mUserId); - boolean removed = serviceState.hardwareInputMap.remove(inputId) != null; - if (removed) { - buildTvInputListLocked(mUserId, null); - mTvInputHardwareManager.removeHardwareInput(inputId); - } else { - Slog.e(TAG, "failed to remove input " + inputId); + final long identity = Binder.clearCallingIdentity(); + try { + synchronized (mLock) { + ServiceState serviceState = getServiceStateLocked(mComponent, mUserId); + boolean removed = serviceState.hardwareInputMap.remove(inputId) != null; + if (removed) { + buildTvInputListLocked(mUserId, null); + mTvInputHardwareManager.removeHardwareInput(inputId); + } else { + Slog.e(TAG, "failed to remove input " + inputId); + } } + } finally { + Binder.restoreCallingIdentity(identity); } } } -- cgit v1.2.3-59-g8ed1b