Skip to content

Commit

Permalink
Migrate PackagerConnectionSettings.java to Kotlin (facebook#45800)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#45800

convert PackagerConnectionSettings.java to PackagerConnectionSettings.kt

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D60296462

fbshipit-source-id: 77a4ef164cd3405c3b7c85ecb301ae6e1d965e57
  • Loading branch information
OmarBafagih authored and facebook-github-bot committed Aug 1, 2024
1 parent c8a1da4 commit ea78d68
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 ea78d68

Please sign in to comment.