-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract PackagerConnectionSettings to ensure easier reusability of Pa…
…ckagerConnection module Reviewed By: cwdick Differential Revision: D4689535 fbshipit-source-id: f698837f407a03bf91521cc5e921c66f5755e6e0
- Loading branch information
1 parent
50ff716
commit 60142ad
Showing
8 changed files
with
132 additions
and
65 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
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
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
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
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
59 changes: 59 additions & 0 deletions
59
...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,59 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.packagerconnection; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
import android.text.TextUtils; | ||
|
||
import com.facebook.common.logging.FLog; | ||
import com.facebook.infer.annotation.Assertions; | ||
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers; | ||
|
||
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; | ||
|
||
public PackagerConnectionSettings(Context applicationContext) { | ||
mPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext); | ||
mPackageName = applicationContext.getPackageName(); | ||
} | ||
|
||
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(); | ||
|
||
if (host.equals(AndroidInfoHelpers.DEVICE_LOCALHOST)) { | ||
FLog.w( | ||
TAG, | ||
"You seem to be running on device. Run 'adb reverse tcp:8081 tcp:8081' " + | ||
"to forward the debug server's port to the device."); | ||
} | ||
|
||
return host; | ||
} | ||
|
||
public @Nullable String getPackageName() { | ||
return mPackageName; | ||
} | ||
} |
Oops, something went wrong.