diff --git a/service/src/com/android/server/connectivity/QosCallbackAgentConnection.java b/service/src/com/android/server/connectivity/QosCallbackAgentConnection.java index 534dbe7699..e682026aa8 100644 --- a/service/src/com/android/server/connectivity/QosCallbackAgentConnection.java +++ b/service/src/com/android/server/connectivity/QosCallbackAgentConnection.java @@ -30,6 +30,8 @@ import android.telephony.data.EpsBearerQosSessionAttributes; import android.telephony.data.NrQosSessionAttributes; import android.util.Log; +import com.android.modules.utils.build.SdkLevel; + import java.util.Objects; /** @@ -149,6 +151,7 @@ class QosCallbackAgentConnection implements IBinder.DeathRecipient { void sendEventEpsQosSessionAvailable(final QosSession session, final EpsBearerQosSessionAttributes attributes) { + if (!validateOrSendErrorAndUnregister()) return; try { if (DBG) log("sendEventEpsQosSessionAvailable: sending..."); mCallback.onQosEpsBearerSessionAvailable(session, attributes); @@ -159,6 +162,7 @@ class QosCallbackAgentConnection implements IBinder.DeathRecipient { void sendEventNrQosSessionAvailable(final QosSession session, final NrQosSessionAttributes attributes) { + if (!validateOrSendErrorAndUnregister()) return; try { if (DBG) log("sendEventNrQosSessionAvailable: sending..."); mCallback.onNrQosSessionAvailable(session, attributes); @@ -168,6 +172,7 @@ class QosCallbackAgentConnection implements IBinder.DeathRecipient { } void sendEventQosSessionLost(@NonNull final QosSession session) { + if (!validateOrSendErrorAndUnregister()) return; try { if (DBG) log("sendEventQosSessionLost: sending..."); mCallback.onQosSessionLost(session); @@ -185,6 +190,21 @@ class QosCallbackAgentConnection implements IBinder.DeathRecipient { } } + private boolean validateOrSendErrorAndUnregister() { + final int exceptionType = mFilter.validate(); + if (exceptionType != EX_TYPE_FILTER_NONE) { + log("validation fail before sending QosCallback."); + // Error callback is returned from Android T to prevent any disruption of application + // running on Android S. + if (SdkLevel.isAtLeastT()) { + sendEventQosCallbackError(exceptionType); + mQosCallbackTracker.unregisterCallback(mCallback); + } + return false; + } + return true; + } + private static void log(@NonNull final String msg) { Log.d(TAG, msg); }