Bug 1416169 - Part 1 - Silence StaticFieldLeak linter. r=snorp
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 11 Mar 2018 13:06:25 +0100
changeset 464076 1a1f19183f38eabb73d25522da0754cfbc98c569
parent 464075 c909f553340c334a5f94df6cc4e3f6f2c096bbcf
child 464077 6b1099c4b838cda680f18aa4ddd83cdb325bc64f
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1416169
milestone61.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 1416169 - Part 1 - Silence StaticFieldLeak linter. r=snorp In practice we've already been using the application context anyway, but this way makes it more explicit. With that out of the way, we can also silence the linter here, since the Static- FieldLeak check is only really relevant when holding onto non-Application contexts. MozReview-Commit-ID: CYOs8MPnlcN
mobile/android/base/java/org/mozilla/gecko/media/AudioFocusAgent.java
--- a/mobile/android/base/java/org/mozilla/gecko/media/AudioFocusAgent.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/AudioFocusAgent.java
@@ -1,24 +1,27 @@
 package org.mozilla.gecko.media;
 
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.GeckoAppShell;
 
+import android.annotation.SuppressLint;
 import android.content.Context;
 import android.content.Intent;
 import android.media.AudioManager;
 import android.media.AudioManager.OnAudioFocusChangeListener;
 import android.support.annotation.VisibleForTesting;
 import android.util.Log;
 
 public class AudioFocusAgent {
     private static final String LOGTAG = "AudioFocusAgent";
 
+    // We're referencing the *application* context, so this is in fact okay.
+    @SuppressLint("StaticFieldLeak")
     private static Context mContext;
     private AudioManager mAudioManager;
     private OnAudioFocusChangeListener mAfChangeListener;
 
     public enum State {
         OWN_FOCUS,
         LOST_FOCUS,
         LOST_FOCUS_TRANSIENT,
@@ -45,17 +48,17 @@ public class AudioFocusAgent {
         AudioFocusAgent.getInstance().abandonAudioFocusIfNeeded();
     }
 
     public synchronized void attachToContext(Context context) {
         if (isAttachedToContext()) {
             return;
         }
 
-        mContext = context;
+        mContext = context.getApplicationContext();
         mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
 
         mAfChangeListener = new OnAudioFocusChangeListener() {
             public void onAudioFocusChange(int focusChange) {
                 switch (focusChange) {
                     case AudioManager.AUDIOFOCUS_LOSS:
                         Log.d(LOGTAG, "onAudioFocusChange, AUDIOFOCUS_LOSS");
                         mAudioFocusState = State.LOST_FOCUS;
@@ -93,16 +96,18 @@ public class AudioFocusAgent {
     }
 
     @RobocopTarget
     public static AudioFocusAgent getInstance() {
         return AudioFocusAgent.SingletonHolder.INSTANCE;
     }
 
     private static class SingletonHolder {
+        // We're referencing the *application* context, so this is in fact okay.
+        @SuppressLint("StaticFieldLeak")
         private static final AudioFocusAgent INSTANCE = new AudioFocusAgent();
     }
 
     private static boolean isAttachedToContext() {
         return (mContext != null);
     }
 
     private void notifyObservers(String topic, String data) {