diff options
author | 2012-08-04 23:26:35 -0700 | |
---|---|---|
committer | 2012-08-17 21:44:08 -0700 | |
commit | baf1f0bd616ca1fc3b53ad832012f498b3601afb (patch) | |
tree | 8d39064b3cf271c87054c7d693982468a51435e9 /java/src/com/android/inputmethod/research/ResearchLogger.java | |
parent | c58f5d904bceab9b33840a7de4e3de4323b2126b (diff) | |
download | latinime-baf1f0bd616ca1fc3b53ad832012f498b3601afb.tar.gz latinime-baf1f0bd616ca1fc3b53ad832012f498b3601afb.tar.xz latinime-baf1f0bd616ca1fc3b53ad832012f498b3601afb.zip |
ResearchLogging upload via service
DO NOT MERGE
Upload using an intent service rather than just a thread. More robust in case the keyboard
is closed and the upload hasn't finished yet.
multi-project commit with I40db74fb780e01364609339764e150f0291d3f9b
Bug: 6188932
Change-Id: Ie980d38a713d15c01083d41bd73f0602ec75dd16
Diffstat (limited to 'java/src/com/android/inputmethod/research/ResearchLogger.java')
-rw-r--r-- | java/src/com/android/inputmethod/research/ResearchLogger.java | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java index bd62ca35e..814a12673 100644 --- a/java/src/com/android/inputmethod/research/ResearchLogger.java +++ b/java/src/com/android/inputmethod/research/ResearchLogger.java @@ -18,11 +18,14 @@ package com.android.inputmethod.research; import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET; +import android.app.AlarmManager; import android.app.AlertDialog; import android.app.Dialog; +import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; +import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.pm.PackageInfo; @@ -133,7 +136,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private KeyboardSwitcher mKeyboardSwitcher; private InputMethodService mInputMethodService; private final Statistics mStatistics; - private ResearchLogUploader mResearchLogUploader; + + private Intent mUploadIntent; + private PendingIntent mUploadPendingIntent; private LogUnit mCurrentLogUnit = new LogUnit(); @@ -176,11 +181,34 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang e.apply(); } } - mResearchLogUploader = new ResearchLogUploader(ims, mFilesDir); - mResearchLogUploader.start(); mKeyboardSwitcher = keyboardSwitcher; mInputMethodService = ims; mPrefs = prefs; + mUploadIntent = new Intent(mInputMethodService, UploaderService.class); + mUploadPendingIntent = PendingIntent.getService(mInputMethodService, 0, mUploadIntent, 0); + + if (ProductionFlag.IS_EXPERIMENTAL) { + scheduleUploadingService(mInputMethodService); + } + } + + /** + * Arrange for the UploaderService to be run on a regular basis. + * + * Any existing scheduled invocation of UploaderService is removed and rescheduled. This may + * cause problems if this method is called often and frequent updates are required, but since + * the user will likely be sleeping at some point, if the interval is less that the expected + * sleep duration and this method is not called during that time, the service should be invoked + * at some point. + */ + public static void scheduleUploadingService(Context context) { + final Intent intent = new Intent(context, UploaderService.class); + final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); + final AlarmManager manager = + (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + manager.cancel(pendingIntent); + manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, + UploaderService.RUN_INTERVAL, UploaderService.RUN_INTERVAL, pendingIntent); } private void cleanupLoggingDir(final File dir, final long time) { @@ -257,6 +285,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang final Editor e = mPrefs.edit(); e.putBoolean(PREF_RESEARCH_HAS_SEEN_SPLASH, true); e.apply(); + restart(); } private void setLoggingAllowed(boolean enableLogging) { @@ -479,10 +508,11 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang if (mFeedbackLogBuffer == null) { return; } - if (!includeHistory) { + if (includeHistory) { + commitCurrentLogUnit(); + } else { mFeedbackLogBuffer.clear(); } - commitCurrentLogUnit(); final LogUnit feedbackLogUnit = new LogUnit(); final Object[] values = { feedbackContents @@ -492,10 +522,14 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang mFeedbackLogBuffer.shiftIn(feedbackLogUnit); publishLogBuffer(mFeedbackLogBuffer, mFeedbackLog, true /* isIncludingPrivateData */); mFeedbackLog.close(); - mResearchLogUploader.uploadAfterCompletion(mFeedbackLog, null); + uploadNow(); mFeedbackLog = new ResearchLog(createLogFile(mFilesDir)); } + public void uploadNow() { + mInputMethodService.startService(mUploadIntent); + } + public void onLeavingSendFeedbackDialog() { mInFeedbackDialog = false; } |