Bug 1369650 - Fix lint: NewApi issues in WebAppActivity.java; r=maliu
authorTeng-pao Yu <osimpleo@gmail.com>
Tue, 16 May 2017 17:11:41 +0800
changeset 365682 02bae2b97fb34f761e90da864b7246443e820ce6
parent 365681 e80838b032bf04756aa6152b58b72e5ab8de7a3d
child 365683 d9d121ad03891d8814d863cee80d1b33109178f0
push id32080
push usercbook@mozilla.com
push dateFri, 23 Jun 2017 09:16:43 +0000
treeherdermozilla-central@3b468193c933 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaliu
bugs1369650
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1369650 - Fix lint: NewApi issues in WebAppActivity.java; r=maliu MozReview-Commit-ID: ERmh2IMTh0X
mobile/android/app/lint.xml
mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
--- a/mobile/android/app/lint.xml
+++ b/mobile/android/app/lint.xml
@@ -52,17 +52,16 @@
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/PrintHelper.java"/>
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/animation/PropertyAnimator.java"/>
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/RemotePresentationService.java"/>
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/db/SharedBrowserDatabaseProvider.java"/>
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/toolbar/TabCounter.java"/>
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/tabs/TabPanelBackButton.java"/>
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditText.java"/>
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java"/>
-        <ignore path="**/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java"/>
         <ignore path="**/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java"/>
         <ignore path="**/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioEffects.java"/>
         <ignore path="**/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java"/>
         <ignore path="src/main/res/values/styles.xml"/>
     </issue>
 
     <!-- We fixed all "Registered" lint errors. However the current gradle plugin has a bug where
          it ignores @SuppressLint annotations for this check. See CrashReporter class and
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -4,20 +4,22 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.webapps;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
+import android.annotation.TargetApi;
 import android.app.ActivityManager;
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.view.ActionMode;
 import android.support.v7.widget.Toolbar;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
@@ -113,46 +115,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;
         }
-        // The customisations defined in the manifest only work on Android API 21+
-        if (AppConstants.Versions.preLollipop) {
-            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);
 
-            updateStatusBarColor(color);
+            updateStatusBarColorV21(color);
             setTaskDescription(taskDescription);
 
         } catch (IOException | JSONException e) {
             Log.e(LOGTAG, "Failed to read manifest", e);
         }
     }
 
-    private void updateStatusBarColor(final Integer themeColor) {
+    @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));
         }
     }
 
     private Integer readColorFromManifest(JSONObject manifest) {