Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate PackagerConnectionSettings.java to Kotlin #45800

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3693,13 +3693,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 com.facebook.common.logging.FLog
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers

public class PackagerConnectionSettings(private val appContext: Context) {
private val preferences: SharedPreferences =
appContext.applicationContext.getSharedPreferences(
"react_native_packager_connection", Context.MODE_PRIVATE)
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"
}
}
Loading