Bug 1369817 - Clean up webapp manifest handling r=daleharvey draft
authorJames Willcox <snorp@snorp.net>
Tue, 08 Aug 2017 11:26:50 -0500
changeset 644219 9e9e8377c5877efcd3b635ec4f9925c0c19c99f5
parent 644218 f827a96eda9896d75ebe2d22ad248bdc84b453c2
child 644220 e020bd9b6b1e07d46837a1da3f53103799c7b009
child 644365 c764ee83a419097fb78511685392f61fede78bd7
child 644378 854ea8e4467525739f8ec875e43d7c04114271a8
child 644917 664ecda76cc0343b68fc89d01f666fcecd81b815
push id73351
push userbmo:snorp@snorp.net
push dateThu, 10 Aug 2017 17:15:02 +0000
reviewersdaleharvey
bugs1369817
milestone57.0a1
Bug 1369817 - Clean up webapp manifest handling r=daleharvey MozReview-Commit-ID: 4ImLBrlGzBc
mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -120,50 +120,51 @@ public class WebAppActivity extends AppC
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
 
         outState.putParcelable(SAVED_INTENT, getIntent());
     }
 
     private void loadManifest(String manifestPath) {
-        if (AppConstants.Versions.feature21Plus) {
-            loadManifestV21(manifestPath);
-        }
-    }
-
-    // The customisations defined in the manifest only work on Android API 21+
-    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
-    private void loadManifestV21(String manifestPath) {
         if (TextUtils.isEmpty(manifestPath)) {
             Log.e(LOGTAG, "Missing manifest");
             return;
         }
 
         try {
             final File manifestFile = new File(manifestPath);
             final JSONObject manifest = FileUtils.readJSONObjectFromFile(manifestFile);
             final JSONObject manifestField = manifest.getJSONObject("manifest");
-            final Integer color = readColorFromManifest(manifestField);
-            final String name = readNameFromManifest(manifestField);
-            final Bitmap icon = readIconFromManifest(manifest);
-            mScope = readScopeFromManifest(manifest, manifestPath);
-            final ActivityManager.TaskDescription taskDescription = (color == null)
-                    ? new ActivityManager.TaskDescription(name, icon)
-                    : new ActivityManager.TaskDescription(name, icon, color);
 
-            updateStatusBarColorV21(color);
-            setTaskDescription(taskDescription);
+            if (AppConstants.Versions.feature21Plus) {
+                loadManifestV21(manifest, manifestField);
+            }
 
             updateScreenOrientation(manifestField);
         } catch (IOException | JSONException e) {
             Log.e(LOGTAG, "Failed to read manifest", e);
         }
     }
 
+    // The customisations defined in the manifest only work on Android API 21+
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+    private void loadManifestV21(JSONObject manifest, JSONObject manifestField) {
+        final Integer color = readColorFromManifest(manifestField);
+        final String name = readNameFromManifest(manifestField);
+        final Bitmap icon = readIconFromManifest(manifest);
+        mScope = readScopeFromManifest(manifest);
+        final ActivityManager.TaskDescription taskDescription = (color == null)
+            ? new ActivityManager.TaskDescription(name, icon)
+            : new ActivityManager.TaskDescription(name, icon, color);
+
+        updateStatusBarColorV21(color);
+        setTaskDescription(taskDescription);
+    }
+
     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
     private void updateStatusBarColorV21(final Integer themeColor) {
         if (themeColor != null) {
             final Window window = getWindow();
             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
             window.setStatusBarColor(ColorUtil.darken(themeColor, 0.25));
         }
     }
@@ -208,17 +209,17 @@ public class WebAppActivity extends AppC
         final LoadFaviconResult loadIconResult = FaviconDecoder
             .decodeDataURI(this, iconStr);
         if (loadIconResult == null) {
             return null;
         }
         return loadIconResult.getBestBitmap(GeckoAppShell.getPreferredIconSize());
     }
 
-    private Uri readScopeFromManifest(JSONObject manifest, String manifestPath) {
+    private Uri readScopeFromManifest(JSONObject manifest) {
         final String scopeStr = manifest.optString("scope", null);
         if (scopeStr == null) {
             return null;
         }
 
         Uri res = Uri.parse(scopeStr);
         if (res.isRelative()) {
             // TODO: Handle this more correctly.