Chromium Code Reviews| 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..e365c94f150bf1ae30e1789418d2e78905975a0b 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. |
| @@ -27,14 +29,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) |
| + throw new RuntimeException("got null Context in DeviceDisplayInfo constructor"); |
| + mWinManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
| } |
| /** |
| @@ -154,7 +159,10 @@ 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; |
| } |
| /** |
| @@ -181,18 +189,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(); |
|
jdduke (slow)
2015/06/16 15:01:28
So the "default" Display can vary per WindowManage
gsennton
2015/06/17 11:40:36
AFAICT this is indeed the case, e.g. using WebView
gsennton
2015/06/25 13:59:58
I should clarify this (my comment above is not ent
|
| } |
| @@ -205,13 +201,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); |
| - |
| } |