Bug 1079874 - Define device configuration in inflated resources. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 01 Jun 2016 14:49:29 -0700
changeset 374118 3c604117f07eb6b62f31bfff4f1d057e492bc414
parent 373911 4b66897490ab2ab196c44ad9485dd529fe96441c
child 522558 232f6127e79f3649ac6672fc03fab3f62bb3eadb
push id19937
push usermichael.l.comella@gmail.com
push dateWed, 01 Jun 2016 21:50:30 +0000
reviewerssebastian
bugs1079874
milestone49.0a1
Bug 1079874 - Define device configuration in inflated resources. r=sebastian See the added code comments for motivations. Note that this is a speculative patch - I was unable to reproduce the crash and thus do not know if it fixes it, however, I did test that the appropriate toolbar configuration is created on vanilla Android for phone & tablet. MozReview-Commit-ID: 2v1Ix8X68LH
mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
mobile/android/base/resources/values-large/bool.xml
mobile/android/base/resources/values/bool.xml
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
@@ -156,18 +156,19 @@ public abstract class BrowserToolbar ext
     /**
      * Returns a Drawable overlaid with the theme's bitmap.
      */
     protected Drawable getLWTDefaultStateSetDrawable() {
         return getTheme().getDrawable(this);
     }
 
     public static BrowserToolbar create(final Context context, final AttributeSet attrs) {
+        final boolean isLargeResource = context.getResources().getBoolean(R.bool.is_large_resource);
         final BrowserToolbar toolbar;
-        if (HardwareUtils.isTablet()) {
+        if (isLargeResource) {
             toolbar = new BrowserToolbarTablet(context, attrs);
         } else {
             toolbar = new BrowserToolbarPhone(context, attrs);
         }
         return toolbar;
     }
 
     protected BrowserToolbar(final Context context, final AttributeSet attrs) {
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/values-large/bool.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ This Source Code Form is subject to the terms of the Mozilla Public
+  ~ License, v. 2.0. If a copy of the MPL was not distributed with this
+  ~ file, you can obtain one at http://mozilla.org/MPL/2.0/.
+  -->
+
+<resources>
+    <!-- See definition in values/ for explanation. -->
+    <bool name="is_large_resource">true</bool>
+</resources>
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/values/bool.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ This Source Code Form is subject to the terms of the Mozilla Public
+  ~ License, v. 2.0. If a copy of the MPL was not distributed with this
+  ~ file, you can obtain one at http://mozilla.org/MPL/2.0/.
+  -->
+
+<resources>
+    <!-- Some devices use resources based on configuration (e.g. large, xlarge) that are inconsistent
+         with the configuration retrieved by HardwareUtils (e.g. some custom ROMs allow the user to
+         choose a phone or tablet version of the UI even though the hardware stays the same). This
+         can cause crashes when we branch on the value returned by HardwareUtils.
+
+         In order to work around this, we define the resource size in resources with the expectation that
+         we branch on that value, rather than HardwareUtils, so our code is consistent with the used resources.
+         See bug 1277379 for a initiative to move all of the HardwareUtils code over. -->
+    <bool name="is_large_resource">false</bool>
+</resources>