aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/research/ResearchLogger.java
diff options
context:
space:
mode:
authorKurt Partridge <kep@google.com>2012-08-04 23:26:35 -0700
committerKurt Partridge <kep@google.com>2012-08-07 20:04:55 -0700
commit7bc4bde41cc0aa7bc6d6f30b079e0f553c0c1fa6 (patch)
tree0e21d23990650fb247970c4188621bc224a4d0fd /java/src/com/android/inputmethod/research/ResearchLogger.java
parenta1ec8195d664a16d38e8ee7e18d1deb6b97fb3f7 (diff)
downloadlatinime-7bc4bde41cc0aa7bc6d6f30b079e0f553c0c1fa6.tar.gz
latinime-7bc4bde41cc0aa7bc6d6f30b079e0f553c0c1fa6.tar.xz
latinime-7bc4bde41cc0aa7bc6d6f30b079e0f553c0c1fa6.zip
ResearchLogging upload via service
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 Idf39453f6ccc70af63e7b2c912f61f2533339870 Bug: 6188932 Change-Id: Id5484f2b6349e316e828d5bdc0ed9ca92887d5b8
Diffstat (limited to 'java/src/com/android/inputmethod/research/ResearchLogger.java')
-rw-r--r--java/src/com/android/inputmethod/research/ResearchLogger.java50
1 files changed, 40 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index 3cad2d099..6279ba6ee 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) {
@@ -477,10 +506,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
@@ -490,10 +520,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;
}
@@ -731,10 +765,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
stop();
}
- private static final String[] EVENTKEYS_USER_FEEDBACK = {
- "UserFeedback", "FeedbackContents"
- };
-
// Regular logging methods
private static final String[] EVENTKEYS_MAINKEYBOARDVIEW_PROCESSMOTIONEVENT = {