Skip to content

Commit

Permalink
Revert "Revert "Migrate PackagerConnectionSettings.java to Kotlin (fa…
Browse files Browse the repository at this point in the history
…cebook#45800)""

This reverts commit c6a3f5b.
  • Loading branch information
zhongwuzw committed Aug 2, 2024
1 parent bf8ec52 commit abc88c7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 82 deletions.
12 changes: 6 additions & 6 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -3781,13 +3781,13 @@ public abstract class com/facebook/react/packagerconnection/NotificationOnlyHand
public final fun onRequest (Ljava/lang/Object;Lcom/facebook/react/packagerconnection/Responder;)V
}

public class com/facebook/react/packagerconnection/PackagerConnectionSettings {
public final class com/facebook/react/packagerconnection/PackagerConnectionSettings {
public fun <init> (Landroid/content/Context;)V
public fun getAdditionalOptionsForPackager ()Ljava/util/Map;
public fun getDebugServerHost ()Ljava/lang/String;
public fun getPackageName ()Ljava/lang/String;
public fun setAdditionalOptionForPackager (Ljava/lang/String;Ljava/lang/String;)V
public fun setDebugServerHost (Ljava/lang/String;)V
public final fun getAdditionalOptionsForPackager ()Ljava/util/Map;
public final fun getDebugServerHost ()Ljava/lang/String;
public final fun getPackageName ()Ljava/lang/String;
public final fun setAdditionalOptionForPackager (Ljava/lang/String;Ljava/lang/String;)V
public final fun setDebugServerHost (Ljava/lang/String;)V
}

public final class com/facebook/react/packagerconnection/ReconnectingWebSocket : okhttp3/WebSocketListener {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.packagerconnection

import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
import com.facebook.common.logging.FLog
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers

public class PackagerConnectionSettings(private val appContext: Context) {
private val preferences: SharedPreferences =
PreferenceManager.getDefaultSharedPreferences(appContext)
public val packageName: String = appContext.packageName
private val _additionalOptionsForPackager: MutableMap<String, String> = mutableMapOf()

public var debugServerHost: String
get() {
// Check host setting first. If empty try to detect emulator type and use default
// hostname for those
val hostFromSettings = preferences.getString(PREFS_DEBUG_SERVER_HOST_KEY, null)
if (hostFromSettings?.isNotEmpty() == true) {
return hostFromSettings
}
val host = AndroidInfoHelpers.getServerHost(appContext)
if (host == AndroidInfoHelpers.DEVICE_LOCALHOST) {
FLog.w(
TAG,
"You seem to be running on device. Run '${AndroidInfoHelpers.getAdbReverseTcpCommand(appContext)}' to forward the debug server's port to the device.")
}
return host
}
set(host) {
preferences.edit().putString(PREFS_DEBUG_SERVER_HOST_KEY, host).apply()
}

public fun setAdditionalOptionForPackager(key: String, value: String) {
_additionalOptionsForPackager[key] = value
}

public val additionalOptionsForPackager: Map<String, String>
get() = _additionalOptionsForPackager

private companion object {
private val TAG = PackagerConnectionSettings::class.java.simpleName
private const val PREFS_DEBUG_SERVER_HOST_KEY = "debug_http_host"
}
}

0 comments on commit abc88c7

Please sign in to comment.