Skip to content

Commit a1e8118

Browse files
huntiefacebook-github-bot
authored andcommitted
Fix ANDROID_ID segment for inspector device ID
Summary: Fixes a bug where page IDs would collide for multiple connected Android devices running the same React Native app. The `Secure.ANDROID_ID` key (not value!) was being substituted in the ID string (pre-hashing) — now this segment is fixed. Changelog: [Android][Changed] - Update constructor signature of `DevServerHelper` Reviewed By: hoxyq Differential Revision: D58134323 fbshipit-source-id: 859e2758108e266167205a777bb6a6e87ca0573b
1 parent f71d7d7 commit a1e8118

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ public final class com/facebook/react/devsupport/DefaultDevSupportManagerFactory
20672067

20682068
public class com/facebook/react/devsupport/DevServerHelper {
20692069
public static final field RELOAD_APP_EXTRA_JS_PROXY Ljava/lang/String;
2070-
public fun <init> (Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;Ljava/lang/String;Lcom/facebook/react/packagerconnection/PackagerConnectionSettings;)V
2070+
public fun <init> (Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;Landroid/content/Context;Lcom/facebook/react/packagerconnection/PackagerConnectionSettings;)V
20712071
public fun closeInspectorConnection ()V
20722072
public fun closePackagerConnection ()V
20732073
public fun disableDebugger ()V

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
package com.facebook.react.devsupport;
99

10+
import android.content.Context;
1011
import android.net.Uri;
1112
import android.os.AsyncTask;
12-
import android.provider.Settings;
13+
import android.provider.Settings.Secure;
1314
import androidx.annotation.NonNull;
1415
import androidx.annotation.Nullable;
1516
import com.facebook.common.logging.FLog;
@@ -104,14 +105,15 @@ public String typeID() {
104105
private final OkHttpClient mClient;
105106
private final BundleDownloader mBundleDownloader;
106107
private final PackagerStatusCheck mPackagerStatusCheck;
108+
private final Context mApplicationContext;
107109
private final String mPackageName;
108110

109111
private @Nullable JSPackagerClient mPackagerClient;
110112
private @Nullable IInspectorPackagerConnection mInspectorPackagerConnection;
111113

112114
public DevServerHelper(
113115
DeveloperSettings developerSettings,
114-
String packageName,
116+
Context applicationContext,
115117
PackagerConnectionSettings packagerConnectionSettings) {
116118
mSettings = developerSettings;
117119
mPackagerConnectionSettings = packagerConnectionSettings;
@@ -123,7 +125,8 @@ public DevServerHelper(
123125
.build();
124126
mBundleDownloader = new BundleDownloader(mClient);
125127
mPackagerStatusCheck = new PackagerStatusCheck(mClient);
126-
mPackageName = packageName;
128+
mApplicationContext = applicationContext;
129+
mPackageName = applicationContext.getPackageName();
127130
}
128131

129132
public void openPackagerConnection(
@@ -301,7 +304,8 @@ private String getInspectorDeviceId() {
301304
// * randomly generated when the user first sets up the device and should remain constant for
302305
// the lifetime of the user's device (API level < 26).
303306
// [Source: Android docs]
304-
String androidId = Settings.Secure.ANDROID_ID;
307+
String androidId =
308+
Secure.getString(mApplicationContext.getContentResolver(), Secure.ANDROID_ID);
305309

306310
String rawDeviceId =
307311
String.format(

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ public DevSupportManagerBase(
143143
mDevSettings = new DevInternalSettings(applicationContext, this::reloadSettings);
144144
mDevServerHelper =
145145
new DevServerHelper(
146-
mDevSettings,
147-
mApplicationContext.getPackageName(),
148-
mDevSettings.getPackagerConnectionSettings());
146+
mDevSettings, mApplicationContext, mDevSettings.getPackagerConnectionSettings());
149147
mBundleDownloadListener = devBundleDownloadListener;
150148

151149
// Prepare shake gesture detector (will be started/stopped from #reload)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/PerftestDevSupportManager.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public void onInternalSettingsChanged() {}
2929
});
3030
mDevServerHelper =
3131
new DevServerHelper(
32-
mDevSettings,
33-
applicationContext.getPackageName(),
34-
mDevSettings.getPackagerConnectionSettings());
32+
mDevSettings, applicationContext, mDevSettings.getPackagerConnectionSettings());
3533
}
3634

3735
@Override

0 commit comments

Comments
 (0)