forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Migrate PackagerConnectionSettings.java to Kotlin (fa…
…cebook#45800)"" This reverts commit c6a3f5b.
- Loading branch information
Showing
3 changed files
with
59 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 0 additions & 76 deletions
76
...droid/src/main/java/com/facebook/react/packagerconnection/PackagerConnectionSettings.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...Android/src/main/java/com/facebook/react/packagerconnection/PackagerConnectionSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |