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

--HG--
extra : rebase_source : 37611c82f84ba011c763554c6793bef63c093faa
This commit is contained in:
Michael Comella 2016-04-19 08:49:07 -07:00
Родитель cf8a4c46d6
Коммит 27f4871f75
3 изменённых файлов: 23 добавлений и 23 удалений

Просмотреть файл

@ -3952,13 +3952,13 @@ public class BrowserApp extends GeckoApp
// 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);
}

Просмотреть файл

@ -15,13 +15,6 @@ public class TelemetryConstants {
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";
}

Просмотреть файл

@ -39,6 +39,13 @@ 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() {
@ -80,17 +87,17 @@ public class TelemetryUploadService extends BackgroundService {
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);
}
@ -143,24 +150,24 @@ public class TelemetryUploadService extends BackgroundService {
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;
}