Skip to content

Commit

Permalink
Fix ANDROID_ID segment for inspector device ID
Browse files Browse the repository at this point in the history
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
  • Loading branch information
huntie authored and facebook-github-bot committed Jun 5, 2024
1 parent f71d7d7 commit a1e8118
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ public final class com/facebook/react/devsupport/DefaultDevSupportManagerFactory

public class com/facebook/react/devsupport/DevServerHelper {
public static final field RELOAD_APP_EXTRA_JS_PROXY Ljava/lang/String;
public fun <init> (Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;Ljava/lang/String;Lcom/facebook/react/packagerconnection/PackagerConnectionSettings;)V
public fun <init> (Lcom/facebook/react/modules/debug/interfaces/DeveloperSettings;Landroid/content/Context;Lcom/facebook/react/packagerconnection/PackagerConnectionSettings;)V
public fun closeInspectorConnection ()V
public fun closePackagerConnection ()V
public fun disableDebugger ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

package com.facebook.react.devsupport;

import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.Settings;
import android.provider.Settings.Secure;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
Expand Down Expand Up @@ -104,14 +105,15 @@ public String typeID() {
private final OkHttpClient mClient;
private final BundleDownloader mBundleDownloader;
private final PackagerStatusCheck mPackagerStatusCheck;
private final Context mApplicationContext;
private final String mPackageName;

private @Nullable JSPackagerClient mPackagerClient;
private @Nullable IInspectorPackagerConnection mInspectorPackagerConnection;

public DevServerHelper(
DeveloperSettings developerSettings,
String packageName,
Context applicationContext,
PackagerConnectionSettings packagerConnectionSettings) {
mSettings = developerSettings;
mPackagerConnectionSettings = packagerConnectionSettings;
Expand All @@ -123,7 +125,8 @@ public DevServerHelper(
.build();
mBundleDownloader = new BundleDownloader(mClient);
mPackagerStatusCheck = new PackagerStatusCheck(mClient);
mPackageName = packageName;
mApplicationContext = applicationContext;
mPackageName = applicationContext.getPackageName();
}

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

String rawDeviceId =
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ public DevSupportManagerBase(
mDevSettings = new DevInternalSettings(applicationContext, this::reloadSettings);
mDevServerHelper =
new DevServerHelper(
mDevSettings,
mApplicationContext.getPackageName(),
mDevSettings.getPackagerConnectionSettings());
mDevSettings, mApplicationContext, mDevSettings.getPackagerConnectionSettings());
mBundleDownloadListener = devBundleDownloadListener;

// Prepare shake gesture detector (will be started/stopped from #reload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public void onInternalSettingsChanged() {}
});
mDevServerHelper =
new DevServerHelper(
mDevSettings,
applicationContext.getPackageName(),
mDevSettings.getPackagerConnectionSettings());
mDevSettings, applicationContext, mDevSettings.getPackagerConnectionSettings());
}

@Override
Expand Down

0 comments on commit a1e8118

Please sign in to comment.