Index: ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java |
diff --git a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java |
index da8e0262a1f9e202086b5d4095cc61b47555dd48..15ba5809f9299be9c7381e055737bbaa4e514fe7 100644 |
--- a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java |
+++ b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java |
@@ -17,6 +17,8 @@ import android.view.WindowManager; |
import org.chromium.base.CalledByNative; |
import org.chromium.base.JNINamespace; |
+import java.lang.ref.WeakReference; |
+ |
/** |
* This class facilitates access to android information typically only |
* available using the Java SDK, including {@link Display} properties. |
@@ -26,15 +28,17 @@ import org.chromium.base.JNINamespace; |
*/ |
@JNINamespace("gfx") |
public class DeviceDisplayInfo { |
- |
- private final Context mAppContext; |
+ private final WeakReference<Context> mContextRef; |
private final WindowManager mWinManager; |
private Point mTempPoint = new Point(); |
private DisplayMetrics mTempMetrics = new DisplayMetrics(); |
- private DeviceDisplayInfo(Context context) { |
- mAppContext = context.getApplicationContext(); |
- mWinManager = (WindowManager) mAppContext.getSystemService(Context.WINDOW_SERVICE); |
+ private DeviceDisplayInfo(WeakReference<Context> contextRef) { |
+ mContextRef = contextRef; |
+ Context context = mContextRef.get(); |
+ if (context == null) |
boliu
2015/07/15 06:38:47
Pass a strong ref in constructor, then this can't
gsennton
2015/07/15 19:26:21
Unless the incoming context is null because we ret
boliu
2015/07/16 14:36:56
You can check for null before passing it into Devi
gsennton
2015/10/20 13:27:12
Right, will check this in WindowAndroid::UpdateDev
boliu
2015/10/20 15:07:22
"use the default DeviceDisplayInfo" sounds wrong,
|
+ throw new RuntimeException("got null Context in DeviceDisplayInfo constructor"); |
+ mWinManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
} |
/** |
@@ -154,7 +158,9 @@ public class DeviceDisplayInfo { |
*/ |
@CalledByNative |
private int getSmallestDIPWidth() { |
- return mAppContext.getResources().getConfiguration().smallestScreenWidthDp; |
+ Context context = mContextRef.get(); |
+ if (context == null) throw new RuntimeException("null context in getSmallestDIPWidth!!!"); |
+ return context.getResources().getConfiguration().smallestScreenWidthDp; |
boliu
2015/07/15 06:38:47
I wonder if this can ever change. Maybe it's ok to
jdduke (slow)
2015/07/15 16:03:07
+1. It might also be worth investigating why this
gsennton
2015/07/15 19:26:21
Right, going ahead and storing the value in the co
boliu
2015/07/16 14:36:56
You no longer need to keep mContextRef in this cla
gsennton
2015/10/20 13:27:12
will remove mContextRef
Regarding getSmallestDIPW
|
} |
/** |
@@ -181,18 +187,6 @@ public class DeviceDisplayInfo { |
return 0; |
} |
- /** |
- * Inform the native implementation to update its cached representation of |
- * the DeviceDisplayInfo values. |
- */ |
- public void updateNativeSharedDisplayInfo() { |
- nativeUpdateSharedDeviceDisplayInfo( |
- getDisplayHeight(), getDisplayWidth(), |
- getPhysicalDisplayHeight(), getPhysicalDisplayWidth(), |
- getBitsPerPixel(), getBitsPerComponent(), |
- getDIPScale(), getSmallestDIPWidth(), getRotationDegrees()); |
- } |
- |
private Display getDisplay() { |
return mWinManager.getDefaultDisplay(); |
} |
@@ -205,13 +199,6 @@ public class DeviceDisplayInfo { |
*/ |
@CalledByNative |
public static DeviceDisplayInfo create(Context context) { |
- return new DeviceDisplayInfo(context); |
+ return new DeviceDisplayInfo(new WeakReference<Context>(context)); |
} |
- |
- private native void nativeUpdateSharedDeviceDisplayInfo( |
- int displayHeight, int displayWidth, |
- int physicalDisplayHeight, int physicalDisplayWidth, |
- int bitsPerPixel, int bitsPerComponent, double dipScale, |
- int smallestDIPWidth, int rotationDegrees); |
- |
} |