Skip to content

Commit 2ac5488

Browse files
coadometa-codesync[bot]
authored andcommitted
Fix: loading bundle using debug_http_host preferences (#54687)
Summary: In #54139 I have removed checking shared preferences for `debug_http_host`. The diff reverts this removal because it is used for changing the bundle source before the app starts. ## Changelog: [ANDROID][FIXED] - revert removal of checking shared preferences for `debug_http_host`. Pull Request resolved: #54687 Test Plan: I have run the `rn-tester` app and swapped a default prefs file on Android emulator located in: `/data/data/com.facebook.react.uiapp/shared_prefs/com.facebook.react.uiapp_preferences.xml` with one that had updated port in `debug_http_host` setting to `8082`: ```xml <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <map> <boolean name="fps_debug" value="true" /> <string name="debug_http_host">10.0.2.2:8082</string> <boolean name="inspector_debug" value="true" /> </map> ``` Then, I have run the app and checked if the bundle is loaded from the Metro instance invoked using `yarn start --port 8082`. Reviewed By: cortinico Differential Revision: D87869540 Pulled By: coado fbshipit-source-id: 9a76990b097ad7ff24cbbc5202ca935053de23e5
1 parent f0cbc93 commit 2ac5488

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/PackagerConnectionSettings.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
@file:Suppress("DEPRECATION") // PreferenceManager should be migrated to androidx
9+
810
package com.facebook.react.packagerconnection
911

1012
import android.content.Context
13+
import android.content.SharedPreferences
14+
import android.preference.PreferenceManager
1115
import com.facebook.common.logging.FLog
1216
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers
1317

1418
public open class PackagerConnectionSettings(private val appContext: Context) {
19+
private val preferences: SharedPreferences =
20+
PreferenceManager.getDefaultSharedPreferences(appContext)
1521
public val packageName: String = appContext.packageName
1622
private val _additionalOptionsForPackager: MutableMap<String, String> = mutableMapOf()
1723
private var _packagerOptionsUpdater: (Map<String, String>) -> Map<String, String> = { it }
@@ -24,6 +30,12 @@ public open class PackagerConnectionSettings(private val appContext: Context) {
2430
cachedHost?.let {
2531
return it
2632
}
33+
34+
val hostFromSettings = preferences.getString(PREFS_DEBUG_SERVER_HOST_KEY, null)
35+
if (!hostFromSettings.isNullOrEmpty()) {
36+
return hostFromSettings
37+
}
38+
2739
val host = AndroidInfoHelpers.getServerHost(appContext)
2840
if (host == AndroidInfoHelpers.DEVICE_LOCALHOST) {
2941
FLog.w(
@@ -63,5 +75,6 @@ public open class PackagerConnectionSettings(private val appContext: Context) {
6375

6476
private companion object {
6577
private val TAG = PackagerConnectionSettings::class.java.simpleName
78+
private const val PREFS_DEBUG_SERVER_HOST_KEY = "debug_http_host"
6679
}
6780
}

0 commit comments

Comments
 (0)