diff --git a/ReactAndroid/src/main/java/com/facebook/react/MemoryPressureRouter.java b/ReactAndroid/src/main/java/com/facebook/react/MemoryPressureRouter.java index 940d9f101..e83d53f9a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/MemoryPressureRouter.java +++ b/ReactAndroid/src/main/java/com/facebook/react/MemoryPressureRouter.java @@ -2,60 +2,21 @@ package com.facebook.react; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; - -import android.annotation.TargetApi; -import android.app.Application; import android.content.ComponentCallbacks2; import android.content.Context; import android.content.res.Configuration; -import android.os.Build; - -import com.facebook.react.bridge.MemoryPressure; import com.facebook.react.bridge.MemoryPressureListener; - -import static android.content.ComponentCallbacks2.TRIM_MEMORY_BACKGROUND; -import static android.content.ComponentCallbacks2.TRIM_MEMORY_COMPLETE; -import static android.content.ComponentCallbacks2.TRIM_MEMORY_MODERATE; -import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL; -import static android.content.ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; /** * Translates and routes memory pressure events to the current catalyst instance. */ public class MemoryPressureRouter implements ComponentCallbacks2 { - // Trigger this by sending an intent to your activity with adb shell: - // am broadcast -a com.facebook.react.ACTION_TRIM_MEMORY_MODERATE - private static final String ACTION_TRIM_MEMORY_UI_HIDDEN = - "com.facebook.react.ACTION_TRIM_MEMORY_UI_HIDDEN"; - private static final String ACTION_TRIM_MEMORY_MODERATE = - "com.facebook.react.ACTION_TRIM_MEMORY_MODERATE"; - private static final String ACTION_TRIM_MEMORY_CRITICAL = - "com.facebook.react.ACTION_TRIM_MEMORY_CRITICAL"; - private final Set mListeners = Collections.synchronizedSet(new LinkedHashSet()); - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - public static boolean handleDebugIntent(Application application, String action) { - switch (action) { - case ACTION_TRIM_MEMORY_UI_HIDDEN: - simulateTrimMemory(application, ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN); - break; - case ACTION_TRIM_MEMORY_MODERATE: - simulateTrimMemory(application, TRIM_MEMORY_MODERATE); - break; - case ACTION_TRIM_MEMORY_CRITICAL: - simulateTrimMemory(application, TRIM_MEMORY_COMPLETE); - default: - return false; - } - - return true; - } - MemoryPressureRouter(Context context) { context.getApplicationContext().registerComponentCallbacks(this); } @@ -80,13 +41,7 @@ public class MemoryPressureRouter implements ComponentCallbacks2 { @Override public void onTrimMemory(int level) { - if (level >= TRIM_MEMORY_COMPLETE) { - dispatchMemoryPressure(MemoryPressure.CRITICAL); - } else if (level >= TRIM_MEMORY_BACKGROUND || level == TRIM_MEMORY_RUNNING_CRITICAL) { - dispatchMemoryPressure(MemoryPressure.MODERATE); - } else if (level == TRIM_MEMORY_UI_HIDDEN) { - dispatchMemoryPressure(MemoryPressure.UI_HIDDEN); - } + dispatchMemoryPressure(level); } @Override @@ -97,7 +52,7 @@ public class MemoryPressureRouter implements ComponentCallbacks2 { public void onLowMemory() { } - private void dispatchMemoryPressure(MemoryPressure level) { + private void dispatchMemoryPressure(int level) { // copy listeners array to avoid ConcurrentModificationException if any of the listeners remove // themselves in handleMemoryPressure() MemoryPressureListener[] listeners = @@ -106,8 +61,4 @@ public class MemoryPressureRouter implements ComponentCallbacks2 { listener.handleMemoryPressure(level); } } - - private static void simulateTrimMemory(Application application, int level) { - application.onTrimMemory(level); - } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java index d5290b8ea..cede3abbe 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java @@ -9,17 +9,8 @@ package com.facebook.react.bridge; -import javax.annotation.Nullable; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Collection; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicInteger; - import android.content.res.AssetManager; import android.util.Log; - import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; import com.facebook.jni.HybridData; @@ -33,6 +24,12 @@ import com.facebook.react.common.ReactConstants; import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.systrace.Systrace; import com.facebook.systrace.TraceListener; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicInteger; +import javax.annotation.Nullable; /** * This provides an implementation of the public CatalystInstance instance. It is public because @@ -396,11 +393,11 @@ public class CatalystInstanceImpl implements CatalystInstance { private native void jniHandleMemoryPressure(int level); @Override - public void handleMemoryPressure(MemoryPressure level) { + public void handleMemoryPressure(int level) { if (mDestroyed) { return; } - jniHandleMemoryPressure(level.ordinal()); + jniHandleMemoryPressure(level); } /** diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/MemoryPressureListener.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/MemoryPressureListener.java index e4640b96e..41c45d217 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/MemoryPressureListener.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/MemoryPressureListener.java @@ -10,6 +10,6 @@ public interface MemoryPressureListener { /** * Called when the system generates a memory warning. */ - void handleMemoryPressure(MemoryPressure level); + void handleMemoryPressure(int level); }