Bug 1243585 - Move Intent constants into UploadService. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 19 Apr 2016 08:49:07 -0700
changeset 357483 8d7c612e5740b87aa3339951381efff6e448e799
parent 357482 fffde0e08abb1e12c33effc93f336b29c8b323a8
child 357484 8732a360b28366b840a60d9f7463835f54684093
push id16806
push usermichael.l.comella@gmail.com
push dateFri, 29 Apr 2016 00:52:31 +0000
reviewerssebastian
bugs1243585
milestone49.0a1
Bug 1243585 - Move Intent constants into UploadService. r=sebastian I'm thinking it's better to have constants with the classes they're most closely associated with rather than one giant constants file because it becomes hard to find anything in a large constants file. MozReview-Commit-ID: D3SCkW3vbRM
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryConstants.java
mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -4080,23 +4080,23 @@ public class BrowserApp extends GeckoApp
         }
 
         final SharedPreferences sharedPrefs = GeckoSharedPrefs.forProfileName(context, profile.getName());
         final int seq = sharedPrefs.getInt(TelemetryConstants.PREF_SEQ_COUNT, 1);
 
         // We store synchronously before sending the Intent to ensure this sequence number will not be re-used.
         sharedPrefs.edit().putInt(TelemetryConstants.PREF_SEQ_COUNT, seq + 1).commit();
 
-        final Intent i = new Intent(TelemetryConstants.ACTION_UPLOAD_CORE);
+        final Intent i = new Intent(TelemetryUploadService.ACTION_UPLOAD_CORE);
         i.setClass(context, TelemetryUploadService.class);
-        i.putExtra(TelemetryConstants.EXTRA_DEFAULT_SEARCH_ENGINE, (defaultEngine == null) ? null : defaultEngine.getIdentifier());
-        i.putExtra(TelemetryConstants.EXTRA_DOC_ID, UUID.randomUUID().toString());
-        i.putExtra(TelemetryConstants.EXTRA_PROFILE_NAME, profile.getName());
-        i.putExtra(TelemetryConstants.EXTRA_PROFILE_PATH, profile.getDir().getAbsolutePath());
-        i.putExtra(TelemetryConstants.EXTRA_SEQ, seq);
+        i.putExtra(TelemetryUploadService.EXTRA_DEFAULT_SEARCH_ENGINE, (defaultEngine == null) ? null : defaultEngine.getIdentifier());
+        i.putExtra(TelemetryUploadService.EXTRA_DOC_ID, UUID.randomUUID().toString());
+        i.putExtra(TelemetryUploadService.EXTRA_PROFILE_NAME, profile.getName());
+        i.putExtra(TelemetryUploadService.EXTRA_PROFILE_PATH, profile.getDir().getAbsolutePath());
+        i.putExtra(TelemetryUploadService.EXTRA_SEQ, seq);
         context.startService(i);
     }
 
     private static class UploadTelemetryCallback implements SearchEngineManager.SearchEngineCallback {
         private final WeakReference<BrowserApp> activityWeakReference;
 
         public UploadTelemetryCallback(final BrowserApp activity) {
             this.activityWeakReference = new WeakReference<>(activity);
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryConstants.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryConstants.java
@@ -10,18 +10,11 @@ public class TelemetryConstants {
 
     // Change these two values to enable upload in developer builds.
     public static final boolean UPLOAD_ENABLED = AppConstants.MOZILLA_OFFICIAL; // Disabled for developer builds.
     public static final String DEFAULT_SERVER_URL = "https://incoming.telemetry.mozilla.org";
 
     public static final String USER_AGENT =
             "Firefox-Android-Telemetry/" + AppConstants.MOZ_APP_VERSION + " (" + AppConstants.MOZ_APP_UA_NAME + ")";
 
-    public static final String ACTION_UPLOAD_CORE = "uploadCore";
-    public static final String EXTRA_DEFAULT_SEARCH_ENGINE = "defaultSearchEngine";
-    public static final String EXTRA_DOC_ID = "docId";
-    public static final String EXTRA_PROFILE_NAME = "geckoProfileName";
-    public static final String EXTRA_PROFILE_PATH = "geckoProfilePath";
-    public static final String EXTRA_SEQ = "seq";
-
     public static final String PREF_SERVER_URL = "telemetry-serverUrl";
     public static final String PREF_SEQ_COUNT = "telemetry-seqCount";
 }
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryUploadService.java
@@ -34,16 +34,23 @@ import java.security.GeneralSecurityExce
  *
  * Note that we'll fail to upload if the network is off or background uploads are disabled but the caller is still
  * expected to increment the sequence number.
  */
 public class TelemetryUploadService extends BackgroundService {
     private static final String LOGTAG = StringUtils.safeSubstring("Gecko" + TelemetryUploadService.class.getSimpleName(), 0, 23);
     private static final String WORKER_THREAD_NAME = LOGTAG + "Worker";
 
+    public static final String ACTION_UPLOAD_CORE = "uploadCore";
+    public static final String EXTRA_DEFAULT_SEARCH_ENGINE = "defaultSearchEngine";
+    public static final String EXTRA_DOC_ID = "docId";
+    public static final String EXTRA_PROFILE_NAME = "geckoProfileName";
+    public static final String EXTRA_PROFILE_PATH = "geckoProfilePath";
+    public static final String EXTRA_SEQ = "seq";
+
     private static final int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
 
     public TelemetryUploadService() {
         super(WORKER_THREAD_NAME);
 
         // Intent redelivery can fail hard (e.g. we OOM as we try to upload, the Intent gets redelivered, repeat) so for
         // simplicity, we avoid it for now. In the unlikely event that Android kills our upload service, we'll thus fail
         // to upload the document with a specific sequence number. Furthermore, we never attempt to re-upload it.
@@ -75,27 +82,27 @@ public class TelemetryUploadService exte
             return;
         }
 
         if (!isIntentValid(intent)) {
             Log.w(LOGTAG, "Received invalid Intent; returning");
             return;
         }
 
-        if (!TelemetryConstants.ACTION_UPLOAD_CORE.equals(intent.getAction())) {
+        if (!ACTION_UPLOAD_CORE.equals(intent.getAction())) {
             Log.w(LOGTAG, "Unknown action: " + intent.getAction() + ". Returning");
             return;
         }
 
-        final String defaultSearchEngine = intent.getStringExtra(TelemetryConstants.EXTRA_DEFAULT_SEARCH_ENGINE);
-        final String docId = intent.getStringExtra(TelemetryConstants.EXTRA_DOC_ID);
-        final int seq = intent.getIntExtra(TelemetryConstants.EXTRA_SEQ, -1);
+        final String defaultSearchEngine = intent.getStringExtra(EXTRA_DEFAULT_SEARCH_ENGINE);
+        final String docId = intent.getStringExtra(EXTRA_DOC_ID);
+        final int seq = intent.getIntExtra(EXTRA_SEQ, -1);
 
-        final String profileName = intent.getStringExtra(TelemetryConstants.EXTRA_PROFILE_NAME);
-        final String profilePath = intent.getStringExtra(TelemetryConstants.EXTRA_PROFILE_PATH);
+        final String profileName = intent.getStringExtra(EXTRA_PROFILE_NAME);
+        final String profilePath = intent.getStringExtra(EXTRA_PROFILE_PATH);
 
         uploadCorePing(docId, seq, profileName, profilePath, defaultSearchEngine);
     }
 
     /**
      * Determines if the telemetry upload feature is enabled via the application configuration. Prefer to use
      * {@link #isUploadEnabledByProfileConfig(Context, GeckoProfile)} if the profile is available as it takes into
      * account more information.
@@ -138,34 +145,34 @@ public class TelemetryUploadService exte
 
     private boolean isIntentValid(final Intent intent) {
         // Intent can be null. Bug 1025937.
         if (intent == null) {
             Log.d(LOGTAG, "Received null intent");
             return false;
         }
 
-        if (intent.getStringExtra(TelemetryConstants.EXTRA_DOC_ID) == null) {
+        if (intent.getStringExtra(EXTRA_DOC_ID) == null) {
             Log.d(LOGTAG, "Received invalid doc ID in Intent");
             return false;
         }
 
-        if (!intent.hasExtra(TelemetryConstants.EXTRA_SEQ)) {
+        if (!intent.hasExtra(EXTRA_SEQ)) {
             Log.d(LOGTAG, "Received Intent without sequence number");
             return false;
         }
 
-        if (intent.getStringExtra(TelemetryConstants.EXTRA_PROFILE_NAME) == null) {
+        if (intent.getStringExtra(EXTRA_PROFILE_NAME) == null) {
             Log.d(LOGTAG, "Received invalid profile name in Intent");
             return false;
         }
 
         // GeckoProfile can use the name to get the path so this isn't strictly necessary.
         // However, getting the path requires parsing an ini file so we optimize by including it here.
-        if (intent.getStringExtra(TelemetryConstants.EXTRA_PROFILE_PATH) == null) {
+        if (intent.getStringExtra(EXTRA_PROFILE_PATH) == null) {
             Log.d(LOGTAG, "Received invalid profile path in Intent");
             return false;
         }
 
         return true;
     }
 
     @WorkerThread