Bug 1263390 - Post: Fix new "Registered" lint errors. r?mcomella draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 20 Apr 2016 10:18:33 +0200
changeset 354200 437f897e5702a1a9514bd740815d00f39f8a9aef
parent 354199 73ca60c33ad616471d81948bc0a1a7e76d770593
child 354201 32b18c74899d050a3c7e966555063b4cfae8cd1f
push id15990
push users.kaspari@gmail.com
push dateWed, 20 Apr 2016 09:05:12 +0000
reviewersmcomella
bugs1263390, 204846
milestone48.0a1
Bug 1263390 - Post: Fix new "Registered" lint errors. r?mcomella * GeckoActivity, LocaleAwareAppCompatActivity, LocaleAwareFragmentActivity, LocaleAwareActivity: Those activities are never instantiated directly. Make them abstract. * CrashReporter: This activity is only registered if MOZ_CRASHREPORTER is set. Supress warning. Unfortunately I had to downgrade this lint check from "error" to "warning" because the current gradle plugin doesn't recognize the SupressLint annotation for the "Registered" check: https://code.google.com/p/android/issues/detail?id=204846 MozReview-Commit-ID: Hy56pZB8ZdB
mobile/android/app/lint.xml
mobile/android/base/java/org/mozilla/gecko/CrashReporter.java
mobile/android/base/java/org/mozilla/gecko/GeckoActivity.java
mobile/android/base/java/org/mozilla/gecko/Locales.java
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountWebFlowActivity.java
--- a/mobile/android/app/lint.xml
+++ b/mobile/android/app/lint.xml
@@ -30,16 +30,21 @@
     <issue id="NewApi" severity="warning" />
     <issue id="OnClick" severity="warning" />
     <issue id="ReferenceType" severity="warning" />
     <issue id="ResourceAsColor" severity="warning" />
     <issue id="ResourceType" severity="warning" />
     <issue id="ValidFragment" severity="warning" />
     <issue id="WrongConstant" severity="warning" />
 
+    <!-- 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
+         https://code.google.com/p/android/issues/detail?id=204846 -->
+    <issue id="Registered" severity="warning" />
+
     <!-- WHEN YOU FIX A LINT WARNING, ADD IT TO THIS LIST.
 
          We want all lint warnings to be fatal errors.
          This is the list of checks that we've explicitly
          set as errors. Ideally, once we have no more warnings,
          we switch to the `warningsAsErrors` lint option
          (bug 1253737) rather than listing everything explicitly. -->
     <issue id="AaptCrash" severity="error" />
@@ -139,17 +144,16 @@
     <issue id="ParcelCreator" severity="error" />
     <issue id="Performance" severity="error" />
     <issue id="Proguard" severity="error" />
     <issue id="ProguardSplit" severity="error" />
     <issue id="PropertyEscape" severity="error" />
     <issue id="ProtectedPermissions" severity="error" />
     <issue id="PxUsage" severity="error" />
     <issue id="Range" severity="error" />
-    <issue id="Registered" severity="error" />
     <issue id="RelativeOverlap" severity="error" />
     <issue id="RequiredSize" severity="error" />
     <issue id="ResAuto" severity="error" />
     <issue id="ResourceCycle" severity="error" />
     <issue id="ResourceName" severity="error" />
     <issue id="ResourceType" severity="error" />
     <issue id="RtlCompat" severity="error" />
     <issue id="RtlEnabled" severity="error" />
--- a/mobile/android/base/java/org/mozilla/gecko/CrashReporter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/CrashReporter.java
@@ -18,32 +18,34 @@ import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.nio.channels.Channels;
 import java.nio.channels.FileChannel;
 import java.util.zip.GZIPOutputStream;
 
 import org.mozilla.gecko.AppConstants.Versions;
 
+import android.annotation.SuppressLint;
 import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.support.v7.app.AppCompatActivity;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
 import android.widget.CheckBox;
 import android.widget.CompoundButton;
 import android.widget.EditText;
 
+@SuppressLint("Registered") // This activity is only registered in the manifest if MOZ_CRASHREPORTER is set
 public class CrashReporter extends AppCompatActivity
 {
     private static final String LOGTAG = "GeckoCrashReporter";
 
     private static final String PASSED_MINI_DUMP_KEY = "minidumpPath";
     private static final String MINI_DUMP_PATH_KEY = "upload_file_minidump";
     private static final String PAGE_URL_KEY = "URL";
     private static final String NOTES_KEY = "Notes";
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoActivity.java
@@ -3,17 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.content.ComponentName;
 import android.content.Intent;
 import android.support.v7.app.AppCompatActivity;
 
-public class GeckoActivity extends AppCompatActivity implements GeckoActivityStatus {
+public abstract class GeckoActivity extends AppCompatActivity implements GeckoActivityStatus {
     // has this activity recently started another Gecko activity?
     private boolean mGeckoActivityOpened;
 
     /**
      * Display any resources that show strings or encompass locale-specific
      * representations.
      *
      * onLocaleReady must always be called on the UI thread.
--- a/mobile/android/base/java/org/mozilla/gecko/Locales.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Locales.java
@@ -43,33 +43,33 @@ public class Locales {
         StrictMode.allowThreadDiskWrites();
         try {
             localeManager.getAndApplyPersistedLocale(context);
         } finally {
             StrictMode.setThreadPolicy(savedPolicy);
         }
     }
 
-    public static class LocaleAwareAppCompatActivity extends AppCompatActivity {
+    public static abstract class LocaleAwareAppCompatActivity extends AppCompatActivity {
         @Override
         protected void onCreate(Bundle savedInstanceState) {
             Locales.initializeLocale(getApplicationContext());
             super.onCreate(savedInstanceState);
         }
 
     }
-    public static class LocaleAwareFragmentActivity extends FragmentActivity {
+    public static abstract class LocaleAwareFragmentActivity extends FragmentActivity {
         @Override
         protected void onCreate(Bundle savedInstanceState) {
             Locales.initializeLocale(getApplicationContext());
             super.onCreate(savedInstanceState);
         }
     }
 
-    public static class LocaleAwareActivity extends Activity {
+    public static abstract class LocaleAwareActivity extends Activity {
         @Override
         protected void onCreate(Bundle savedInstanceState) {
             Locales.initializeLocale(getApplicationContext());
             super.onCreate(savedInstanceState);
         }
     }
 
     /**
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountWebFlowActivity.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/activities/FxAccountWebFlowActivity.java
@@ -9,17 +9,17 @@ import android.os.Bundle;
 import org.mozilla.gecko.Locales;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.fxa.FxAccountConstants;
 import org.mozilla.gecko.sync.setup.activities.ActivityUtils;
 
 /**
  * Activity which shows the status activity or passes through to web flow.
  */
-public class FxAccountWebFlowActivity extends FxAccountAbstractActivity {
+public abstract class FxAccountWebFlowActivity extends FxAccountAbstractActivity {
     protected static final String LOG_TAG = FxAccountWebFlowActivity.class.getSimpleName();
 
     protected static final String ABOUT_ACCOUNTS = "about:accounts";
 
     public static final String EXTRA_ENDPOINT = "entrypoint";
 
     protected static final String[] EXTRAS_TO_PASSTHROUGH = new String[] {
             EXTRA_ENDPOINT,