am 68b3e4e7: Merge changes I2ded3d0a,I27ad9dfb

* commit '68b3e4e7d3ad6d242915d7c087664be5889cfe9b':
  Little cleanups
  Clean up initialization ordering
main
Kurt Partridge 2013-03-06 07:09:52 -08:00 committed by Android Git Automerger
commit 837e1f7fe7
1 changed files with 27 additions and 35 deletions

View File

@ -236,43 +236,41 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
public void init(final LatinIME latinIME, final KeyboardSwitcher keyboardSwitcher, public void init(final LatinIME latinIME, final KeyboardSwitcher keyboardSwitcher,
final Suggest suggest) { final Suggest suggest) {
assert latinIME != null; assert latinIME != null;
if (latinIME == null) { mLatinIME = latinIME;
Log.w(TAG, "IMS is null; logging is off");
} else {
mFilesDir = latinIME.getFilesDir(); mFilesDir = latinIME.getFilesDir();
if (mFilesDir == null || !mFilesDir.exists()) { if (mFilesDir == null || !mFilesDir.exists()) {
Log.w(TAG, "IME storage directory does not exist."); Log.w(TAG, "IME storage directory does not exist. Cannot start logging.");
return;
} }
} mPrefs = PreferenceManager.getDefaultSharedPreferences(latinIME);
mSuggest = suggest; mPrefs.registerOnSharedPreferenceChangeListener(this);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIME);
if (prefs != null) {
sIsLogging = ResearchSettings.readResearchLoggerEnabledFlag(prefs);
prefs.registerOnSharedPreferenceChangeListener(this);
final long lastCleanupTime = prefs.getLong(PREF_LAST_CLEANUP_TIME, 0L); // Initialize fields from preferences
final long now = System.currentTimeMillis(); sIsLogging = ResearchSettings.readResearchLoggerEnabledFlag(mPrefs);
if (lastCleanupTime + DURATION_BETWEEN_DIR_CLEANUP_IN_MS < now) {
final long timeHorizon = now - MAX_LOGFILE_AGE_IN_MS; // Initialize fields from resources
cleanupLoggingDir(mFilesDir, timeHorizon);
Editor e = prefs.edit();
e.putLong(PREF_LAST_CLEANUP_TIME, now);
e.apply();
}
}
final Resources res = latinIME.getResources(); final Resources res = latinIME.getResources();
sAccountType = res.getString(R.string.research_account_type); sAccountType = res.getString(R.string.research_account_type);
sAllowedAccountDomain = res.getString(R.string.research_allowed_account_domain); sAllowedAccountDomain = res.getString(R.string.research_allowed_account_domain);
mLatinIME = latinIME;
mPrefs = prefs; // Cleanup logging directory
// TODO: Move this and other file-related components to separate file.
final long lastCleanupTime = mPrefs.getLong(PREF_LAST_CLEANUP_TIME, 0L);
final long now = System.currentTimeMillis();
if (now - lastCleanupTime > DURATION_BETWEEN_DIR_CLEANUP_IN_MS) {
final long timeHorizon = now - MAX_LOGFILE_AGE_IN_MS;
cleanupLoggingDir(mFilesDir, timeHorizon);
mPrefs.edit().putLong(PREF_LAST_CLEANUP_TIME, now).apply();
}
// Initialize external services
mUploadIntent = new Intent(mLatinIME, UploaderService.class); mUploadIntent = new Intent(mLatinIME, UploaderService.class);
mUploadNowIntent = new Intent(mLatinIME, UploaderService.class); mUploadNowIntent = new Intent(mLatinIME, UploaderService.class);
mUploadNowIntent.putExtra(UploaderService.EXTRA_UPLOAD_UNCONDITIONALLY, true); mUploadNowIntent.putExtra(UploaderService.EXTRA_UPLOAD_UNCONDITIONALLY, true);
mReplayer.setKeyboardSwitcher(keyboardSwitcher);
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
scheduleUploadingService(mLatinIME); scheduleUploadingService(mLatinIME);
} }
mReplayer.setKeyboardSwitcher(keyboardSwitcher);
} }
/** /**
@ -453,10 +451,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
// Log.w(TAG, "not in usability mode; not logging"); // Log.w(TAG, "not in usability mode; not logging");
return; return;
} }
if (mFilesDir == null || !mFilesDir.exists()) {
Log.w(TAG, "IME storage directory does not exist. Cannot start logging.");
return;
}
if (mMainLogBuffer == null) { if (mMainLogBuffer == null) {
mMainResearchLog = new ResearchLog(createLogFile(mFilesDir), mLatinIME); mMainResearchLog = new ResearchLog(createLogFile(mFilesDir), mLatinIME);
final int numWordsToIgnore = new Random().nextInt(NUMBER_OF_WORDS_BETWEEN_SAMPLES + 1); final int numWordsToIgnore = new Random().nextInt(NUMBER_OF_WORDS_BETWEEN_SAMPLES + 1);
@ -560,7 +554,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
if (key == null || prefs == null) { if (key == null || prefs == null) {
return; return;
} }
@ -582,7 +576,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
presentFeedbackDialog(latinIME); presentFeedbackDialog(latinIME);
} }
public void presentFeedbackDialog(LatinIME latinIME) { public void presentFeedbackDialog(final LatinIME latinIME) {
if (isMakingUserRecording()) { if (isMakingUserRecording()) {
saveRecording(); saveRecording();
} }
@ -814,9 +808,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
if (mPrefs == null) { if (mPrefs == null) {
return; return;
} }
final Editor e = mPrefs.edit(); mPrefs.edit().putString(PREF_RESEARCH_SAVED_CHANNEL, channelName).apply();
e.putString(PREF_RESEARCH_SAVED_CHANNEL, channelName);
e.apply();
} }
} }