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 "Migrate PackagerConnectionSettings.java to Kotlin (facebook#4…
- Loading branch information
Showing
3 changed files
with
82 additions
and
59 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: 76 additions & 0 deletions
76
...droid/src/main/java/com/facebook/react/packagerconnection/PackagerConnectionSettings.java
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,76 @@ | ||
/* | ||
* 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 android.preference.PreferenceManager; | ||
import android.text.TextUtils; | ||
import androidx.annotation.Nullable; | ||
import com.facebook.common.logging.FLog; | ||
import com.facebook.infer.annotation.Assertions; | ||
import com.facebook.infer.annotation.Nullsafe; | ||
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Nullsafe(Nullsafe.Mode.LOCAL) | ||
public class PackagerConnectionSettings { | ||
private static final String TAG = PackagerConnectionSettings.class.getSimpleName(); | ||
private static final String PREFS_DEBUG_SERVER_HOST_KEY = "debug_http_host"; | ||
|
||
private final SharedPreferences mPreferences; | ||
private final String mPackageName; | ||
private final Context mAppContext; | ||
private final Map<String, String> mAdditionalOptionsForPackager = new HashMap<>(); | ||
|
||
public PackagerConnectionSettings(Context applicationContext) { | ||
mPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext); | ||
mPackageName = applicationContext.getPackageName(); | ||
mAppContext = applicationContext; | ||
} | ||
|
||
public String getDebugServerHost() { | ||
// Check host setting first. If empty try to detect emulator type and use default | ||
// hostname for those | ||
String hostFromSettings = mPreferences.getString(PREFS_DEBUG_SERVER_HOST_KEY, null); | ||
|
||
if (!TextUtils.isEmpty(hostFromSettings)) { | ||
return Assertions.assertNotNull(hostFromSettings); | ||
} | ||
|
||
String host = AndroidInfoHelpers.getServerHost(mAppContext); | ||
|
||
if (host.equals(AndroidInfoHelpers.DEVICE_LOCALHOST)) { | ||
FLog.w( | ||
TAG, | ||
"You seem to be running on device. Run '" | ||
+ AndroidInfoHelpers.getAdbReverseTcpCommand(mAppContext) | ||
+ "' " | ||
+ "to forward the debug server's port to the device."); | ||
} | ||
|
||
return host; | ||
} | ||
|
||
public void setDebugServerHost(String host) { | ||
mPreferences.edit().putString(PREFS_DEBUG_SERVER_HOST_KEY, host).apply(); | ||
} | ||
|
||
public @Nullable String getPackageName() { | ||
return mPackageName; | ||
} | ||
|
||
public void setAdditionalOptionForPackager(String key, String value) { | ||
mAdditionalOptionsForPackager.put(key, value); | ||
} | ||
|
||
public Map<String, String> getAdditionalOptionsForPackager() { | ||
return mAdditionalOptionsForPackager; | ||
} | ||
} |
53 changes: 0 additions & 53 deletions
53
...Android/src/main/java/com/facebook/react/packagerconnection/PackagerConnectionSettings.kt
This file was deleted.
Oops, something went wrong.