From ea86b1d11cb91622b9b19d5901e823a031c6ceac Mon Sep 17 00:00:00 2001 From: Yixiao Luo Date: Tue, 28 Jun 2022 14:03:01 -0700 Subject: [PATCH] Add explicit error when called by sharee for related functions List of functions: tune() cancelTuning() scan() cancelScanning() getFrontendStatus() getFrontendStatusReadiness() connectFrontendToCiCam() disconnectFrontendToCiCam() getCurrentFrontendHardwareInfo() removeOutputPid() setMaxNumberOfFrontends() Bug: 202983530 Test: cts Change-Id: I5d1062c238829f5f00bab67415dc13f3afbc330a --- media/java/android/media/tv/tuner/Tuner.java | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/media/java/android/media/tv/tuner/Tuner.java b/media/java/android/media/tv/tuner/Tuner.java index 13f7ee6e8c8be..bbb4d1fa76bc6 100644 --- a/media/java/android/media/tv/tuner/Tuner.java +++ b/media/java/android/media/tv/tuner/Tuner.java @@ -1161,6 +1161,10 @@ public class Tuner implements AutoCloseable { public int tune(@NonNull FrontendSettings settings) { mFrontendLock.lock(); try { + if (mFeOwnerTuner != null) { + Log.d(TAG, "Operation cannot be done by sharee of tuner"); + return RESULT_INVALID_STATE; + } final int type = settings.getType(); if (mFrontendHandle != null && type != mFrontendType) { Log.e(TAG, "Frontend was opened with type " + mFrontendType @@ -1204,6 +1208,10 @@ public class Tuner implements AutoCloseable { public int cancelTuning() { mFrontendLock.lock(); try { + if (mFeOwnerTuner != null) { + Log.d(TAG, "Operation cannot be done by sharee of tuner"); + return RESULT_INVALID_STATE; + } return nativeStopTune(); } finally { mFrontendLock.unlock(); @@ -1237,6 +1245,10 @@ public class Tuner implements AutoCloseable { mFrontendLock.lock(); try { + if (mFeOwnerTuner != null) { + Log.d(TAG, "Operation cannot be done by sharee of tuner"); + return RESULT_INVALID_STATE; + } synchronized (mScanCallbackLock) { // Scan can be called again for blink scan if scanCallback and executor are same as //before. @@ -1287,6 +1299,10 @@ public class Tuner implements AutoCloseable { public int cancelScanning() { mFrontendLock.lock(); try { + if (mFeOwnerTuner != null) { + Log.d(TAG, "Operation cannot be done by sharee of tuner"); + return RESULT_INVALID_STATE; + } synchronized (mScanCallbackLock) { FrameworkStatsLog.write(FrameworkStatsLog.TV_TUNER_STATE_CHANGED, mUserId, FrameworkStatsLog.TV_TUNER_STATE_CHANGED__STATE__SCAN_STOPPED); @@ -1377,6 +1393,9 @@ public class Tuner implements AutoCloseable { if (mFrontend == null) { throw new IllegalStateException("frontend is not initialized"); } + if (mFeOwnerTuner != null) { + throw new IllegalStateException("Operation cannot be done by sharee of tuner"); + } return nativeGetFrontendStatus(statusTypes); } finally { mFrontendLock.unlock(); @@ -1480,6 +1499,10 @@ public class Tuner implements AutoCloseable { mFrontendCiCamLock.lock(); mFrontendLock.lock(); try { + if (mFeOwnerTuner != null) { + Log.d(TAG, "Operation cannot be done by sharee of tuner"); + return RESULT_INVALID_STATE; + } if (TunerVersionChecker.checkHigherOrEqualVersionTo( TunerVersionChecker.TUNER_VERSION_1_1, "linkFrontendToCiCam")) { @@ -1543,6 +1566,10 @@ public class Tuner implements AutoCloseable { public int disconnectFrontendToCiCam(int ciCamId) { acquireTRMSLock("disconnectFrontendToCiCam()"); try { + if (mFeOwnerTuner != null) { + Log.d(TAG, "Operation cannot be done by sharee of tuner"); + return RESULT_INVALID_STATE; + } if (TunerVersionChecker.checkHigherOrEqualVersionTo( TunerVersionChecker.TUNER_VERSION_1_1, "unlinkFrontendToCiCam")) { @@ -1591,6 +1618,10 @@ public class Tuner implements AutoCloseable { if (mFrontend == null) { throw new IllegalStateException("frontend is not initialized"); } + if (mFeOwnerTuner != null) { + Log.d(TAG, "Operation cannot be done by sharee of tuner"); + return RESULT_INVALID_STATE; + } return nativeRemoveOutputPid(pid); } finally { mFrontendLock.unlock(); @@ -1621,6 +1652,9 @@ public class Tuner implements AutoCloseable { if (mFrontend == null) { throw new IllegalStateException("frontend is not initialized"); } + if (mFeOwnerTuner != null) { + throw new IllegalStateException("Operation cannot be done by sharee of tuner"); + } FrontendStatusReadiness[] readiness = nativeGetFrontendStatusReadiness(statusTypes); if (readiness == null) { return Collections.EMPTY_LIST; @@ -1697,6 +1731,9 @@ public class Tuner implements AutoCloseable { if (mFrontend == null) { throw new IllegalStateException("frontend is not initialized"); } + if (mFeOwnerTuner != null) { + throw new IllegalStateException("Operation cannot be done by sharee of tuner"); + } return nativeGetFrontendHardwareInfo(); } finally { mFrontendLock.unlock(); @@ -1726,6 +1763,10 @@ public class Tuner implements AutoCloseable { if (maxNumber < 0) { return RESULT_INVALID_ARGUMENT; } + if (mFeOwnerTuner != null) { + Log.d(TAG, "Operation cannot be done by sharee of tuner"); + return RESULT_INVALID_STATE; + } int res = nativeSetMaxNumberOfFrontends(frontendType, maxNumber); if (res == RESULT_SUCCESS) { if (!mTunerResourceManager.setMaxNumberOfFrontends(frontendType, maxNumber)) {