Skip to content

Commit

Permalink
Revert "Migrate PackagerConnectionSettings.java to Kotlin (facebook#4…
Browse files Browse the repository at this point in the history
…5800)"

This reverts commit ea78d68.
  • Loading branch information
zhongwuzw committed Aug 2, 2024
1 parent d22c3f1 commit c6a3f5b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 59 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 final class com/facebook/react/packagerconnection/PackagerConnectionSettings {
public class com/facebook/react/packagerconnection/PackagerConnectionSettings {
public fun <init> (Landroid/content/Context;)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 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 class com/facebook/react/packagerconnection/ReconnectingWebSocket : okhttp3/WebSocketListener {
Expand Down
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;
}
}

This file was deleted.

0 comments on commit c6a3f5b

Please sign in to comment.