Skip to content

Commit

Permalink
fix(anr): add patch for rn-device-info that removes install-referrer …
Browse files Browse the repository at this point in the history
…init (#259)
  • Loading branch information
ice-orion authored Jan 24, 2024
1 parent f3d4f71 commit 4911dbe
Showing 1 changed file with 165 additions and 0 deletions.
165 changes: 165 additions & 0 deletions patches/react-native-device-info+10.3.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
diff --git a/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java b/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
index b01e9d2..935507e 100644
--- a/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
+++ b/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
@@ -72,7 +72,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
private final DeviceIdResolver deviceIdResolver;
private BroadcastReceiver receiver;
private BroadcastReceiver headphoneConnectionReceiver;
- private RNInstallReferrerClient installReferrerClient;

private double mLastBatteryLevel = -1;
private String mLastBatteryState = "";
@@ -86,7 +85,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
super(reactContext);
this.deviceTypeResolver = new DeviceTypeResolver(reactContext);
this.deviceIdResolver = new DeviceIdResolver(reactContext);
- this.installReferrerClient = new RNInstallReferrerClient(reactContext.getBaseContext());
}

@Override
@@ -639,14 +637,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
@ReactMethod
public void getAvailableLocationProviders(Promise p) { p.resolve(getAvailableLocationProvidersSync()); }

- @ReactMethod(isBlockingSynchronousMethod = true)
- public String getInstallReferrerSync() {
- SharedPreferences sharedPref = getRNDISharedPreferences(getReactApplicationContext());
- return sharedPref.getString("installReferrer", Build.UNKNOWN);
- }
- @ReactMethod
- public void getInstallReferrer(Promise p) { p.resolve(getInstallReferrerSync()); }
-
private PackageInfo getPackageInfo() throws Exception {
return getReactApplicationContext().getPackageManager().getPackageInfo(getReactApplicationContext().getPackageName(), 0);
}
diff --git a/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNInstallReferrerClient.java b/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNInstallReferrerClient.java
deleted file mode 100644
index d02152b..0000000
--- a/node_modules/react-native-device-info/android/src/main/java/com/learnium/RNDeviceInfo/RNInstallReferrerClient.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package com.learnium.RNDeviceInfo;
-
-import android.content.SharedPreferences;
-import android.content.Context;
-import android.util.Log;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-
-public class RNInstallReferrerClient {
- private static Class<?> InstallReferrerClientClazz;
- private static Class<?> InstallReferrerStateListenerClazz;
- private static Class<?> ReferrerDetailsClazz;
-
- static {
- try {
- InstallReferrerClientClazz = Class.forName("com.android.installreferrer.api.InstallReferrerClient");
- InstallReferrerStateListenerClazz = Class.forName("com.android.installreferrer.api.InstallReferrerStateListener");
- ReferrerDetailsClazz = Class.forName("com.android.installreferrer.api.ReferrerDetails");
- } catch (Exception e) {
- System.err.println("RNInstallReferrerClient exception. 'installreferrer' APIs are unavailable.");
- }
- }
-
- private final SharedPreferences sharedPreferences;
- private Object mReferrerClient;
- private Object installReferrerStateListener;
-
- // From InstallReferrerClient.InstallReferrerResponse
- private static final int R_RESPONSE_OK = 0;
- private static final int R_RESPONSE_SERVICE_UNAVAILABLE = 1;
- private static final int R_RESPONSE_FEATURE_NOT_SUPPORTED = 2;
-
- RNInstallReferrerClient(Context context) {
- sharedPreferences = context.getSharedPreferences("react-native-device-info", Context.MODE_PRIVATE);
-
- if (InstallReferrerClientClazz == null || InstallReferrerStateListenerClazz == null || ReferrerDetailsClazz == null) {
- return;
- }
-
- try {
- // Build the InstallReferrerClient instance.
- Method newBuilderMethod = InstallReferrerClientClazz.getMethod("newBuilder", Context.class);
- Object builder = newBuilderMethod.invoke(null, context);
- Method buildMethod = builder.getClass().getMethod("build");
- mReferrerClient = buildMethod.invoke(builder);
-
- // Create the InstallReferrerStateListener instance using a Proxy.
- installReferrerStateListener = Proxy.newProxyInstance(
- InstallReferrerStateListenerClazz.getClassLoader(),
- new Class[]{InstallReferrerStateListenerClazz},
- new InstallReferrerStateListenerProxy());
-
- // Call startConnection on the client instance.
- Method startConnectionMethod = InstallReferrerClientClazz.getMethod("startConnection", InstallReferrerStateListenerClazz);
- startConnectionMethod.invoke(mReferrerClient, installReferrerStateListener);
- } catch (Exception e) {
- System.err.println("RNInstallReferrerClient exception. getInstallReferrer will be unavailable: " + e.getMessage());
- e.printStackTrace(System.err);
- }
- }
-
- private class InstallReferrerStateListenerProxy implements InvocationHandler {
- @Override
- public Object invoke(Object o, Method method, Object[] args) throws Throwable {
- String methodName = method.getName();
- try {
- if (methodName.equals("onInstallReferrerSetupFinished") && args != null && args[0] instanceof Integer) {
- onInstallReferrerSetupFinished((Integer) args[0]);
- } else if (methodName.equals("onInstallReferrerServiceDisconnected")) {
- onInstallReferrerServiceDisconnected();
- }
- } catch (Exception e) {
- throw new RuntimeException("unexpected invocation exception: " + e.getMessage());
- }
-
- return null;
- }
-
- public void onInstallReferrerSetupFinished(int responseCode) {
- switch (responseCode) {
- case R_RESPONSE_OK:
- // Connection established
- try {
- //if (BuildConfig.DEBUG)
- Log.d("InstallReferrerState", "OK");
- Method getInstallReferrerMethod = InstallReferrerClientClazz.getMethod("getInstallReferrer");
- Object response = getInstallReferrerMethod.invoke(mReferrerClient);
- Method getInstallReferrerMethod2 = ReferrerDetailsClazz.getMethod("getInstallReferrer");
- String referrer = (String) getInstallReferrerMethod2.invoke(response);
- SharedPreferences.Editor editor = sharedPreferences.edit();
- editor.putString("installReferrer", referrer);
- editor.apply();
-
- Method endConnectionMethod = InstallReferrerClientClazz.getMethod("endConnection");
- endConnectionMethod.invoke(mReferrerClient);
- } catch (Exception e) {
- System.err.println("RNInstallReferrerClient exception. getInstallReferrer will be unavailable: " + e.getMessage());
- e.printStackTrace(System.err);
- }
- break;
- case R_RESPONSE_FEATURE_NOT_SUPPORTED:
- //if (BuildConfig.DEBUG)
- Log.d("InstallReferrerState", "FEATURE_NOT_SUPPORTED");
- // API not available on the current Play Store app
- break;
- case R_RESPONSE_SERVICE_UNAVAILABLE:
- //if (BuildConfig.DEBUG)
- Log.d("InstallReferrerState", "SERVICE_UNAVAILABLE");
- // Connection could not be established
- break;
- }
- }
-
- public void onInstallReferrerServiceDisconnected() {
- // Documentation indicates the InstallReferrer connection will be maintained
- // So there is really nothing to do here
- //if (BuildConfig.DEBUG)
- Log.d("RNInstallReferrerClient", "InstallReferrerService disconnected");
- }
- }
-}

0 comments on commit 4911dbe

Please sign in to comment.