From ec0b5af0492b88c9ed973ba3e961cd723f0f532a Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 07:03:44 -0700 Subject: [PATCH] Back out "Kotlinify OkHttpCallUtil" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Changelog: [Internal] There seems to be a weird problem with OkHttpCallUtil: * D55707704 works in fbsource but breaks the CircleCI build with > using 'dispatcher(): Dispatcher' is an error. moved to val * D55744165 fixes the CircleCI build but breaks in fbsource with > cannot access 'dispatcher': it is package-private in 'OkHttpClient' Not sure what's the real fix to migrate `OkHttpCallUtil` to Koltin but at this point is probably safer to backout the original migration! 😥 Differential Revision: D55745345 --- .../ReactAndroid/api/ReactAndroid.api | 5 ++- .../react/common/network/OkHttpCallUtil.java | 36 +++++++++++++++++++ .../react/common/network/OkHttpCallUtil.kt | 32 ----------------- 3 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.java delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 004d1e44d7b34d..00819defed36f3 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1936,9 +1936,8 @@ public final class com/facebook/react/common/mapbuffer/WritableMapBuffer : com/f public final fun put (IZ)Lcom/facebook/react/common/mapbuffer/WritableMapBuffer; } -public final class com/facebook/react/common/network/OkHttpCallUtil { - public static final field INSTANCE Lcom/facebook/react/common/network/OkHttpCallUtil; - public static final fun cancelTag (Lokhttp3/OkHttpClient;Ljava/lang/Object;)V +public class com/facebook/react/common/network/OkHttpCallUtil { + public static fun cancelTag (Lokhttp3/OkHttpClient;Ljava/lang/Object;)V } public class com/facebook/react/config/ReactFeatureFlags { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.java new file mode 100644 index 00000000000000..a71f7113dc0e9f --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.common.network; + +import com.facebook.infer.annotation.Nullsafe; +import okhttp3.Call; +import okhttp3.OkHttpClient; + +/** + * Helper class that provides the necessary methods for canceling queued and running OkHttp calls + */ +@Nullsafe(Nullsafe.Mode.LOCAL) +public class OkHttpCallUtil { + + private OkHttpCallUtil() {} + + public static void cancelTag(OkHttpClient client, Object tag) { + for (Call call : client.dispatcher().queuedCalls()) { + if (tag.equals(call.request().tag())) { + call.cancel(); + return; + } + } + for (Call call : client.dispatcher().runningCalls()) { + if (tag.equals(call.request().tag())) { + call.cancel(); + return; + } + } + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.kt deleted file mode 100644 index 0bd4a0f112383e..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.common.network - -import okhttp3.OkHttpClient - -/** - * Helper class that provides the necessary methods for canceling queued and running OkHttp calls - */ -public object OkHttpCallUtil { - - @JvmStatic - public fun cancelTag(client: OkHttpClient, tag: Any) { - for (call in client.dispatcher().queuedCalls()) { - if (tag == call.request().tag()) { - call.cancel() - return - } - } - for (call in client.dispatcher().runningCalls()) { - if (tag == call.request().tag()) { - call.cancel() - return - } - } - } -}