@@ -476,8 +476,11 @@ jboolean IPCBridge::ExecTransact_Replace(jboolean *res, JNIEnv *env, jobject obj
476476 if (*res == JNI_FALSE) {
477477 uint64_t caller_id = BinderCaller::GetId ();
478478 if (caller_id != 0 ) {
479+ // LOGV("Caller {} rejected by bridge service.", caller_id);
479480 g_last_failed_id.store (caller_id, std::memory_order_relaxed);
480481 }
482+ } else {
483+ g_last_failed_id.store (~0 , std::memory_order_relaxed);
481484 }
482485 return true ; // Return true to indicate we handled the call.
483486 }
@@ -486,21 +489,18 @@ jboolean IPCBridge::ExecTransact_Replace(jboolean *res, JNIEnv *env, jobject obj
486489
487490jboolean JNICALL IPCBridge::CallBooleanMethodV_Hook (JNIEnv *env, jobject obj, jmethodID methodId,
488491 va_list args) {
489- uint64_t current_caller_id = BinderCaller::GetId ();
490- if (current_caller_id != 0 ) {
491- uint64_t last_failed = g_last_failed_id.load (std::memory_order_relaxed);
492- // If this caller is the one that just failed,
493- // skip interception and go straight to the original function.
494- if (current_caller_id == last_failed) {
492+ // Check if the method being called is the one we want to intercept: Binder.execTransact()
493+ if (methodId == GetInstance ().exec_transact_backup_method_id_ ) {
494+ uint64_t current_caller_id = BinderCaller::GetId ();
495+
496+ if (current_caller_id != 0 &&
497+ current_caller_id == g_last_failed_id.load (std::memory_order_relaxed)) {
498+ // If this caller is the one that just failed,
499+ // skip interception and go straight to the original function.
500+ // LOGV("Skip caller {} for bridge service.", current_caller_id);
495501 return GetInstance ().call_boolean_method_v_backup_ (env, obj, methodId, args);
496- } else if (last_failed != ~0 ) {
497- // Consume the failed state by resetting it, so the next call is not skipped.
498- g_last_failed_id.store (~0 , std::memory_order_relaxed);
499502 }
500- }
501503
502- // Check if the method being called is the one we want to intercept: Binder.execTransact()
503- if (methodId == GetInstance ().exec_transact_backup_method_id_ ) {
504504 jboolean res = false ;
505505 // Attempt to handle the transaction with our replacement logic.
506506 if (ExecTransact_Replace (&res, env, obj, args)) {
0 commit comments