aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/research/ResearchLogger.java
diff options
context:
space:
mode:
authorKurt Partridge <kep@google.com>2013-02-27 17:27:12 -0800
committerKurt Partridge <kep@google.com>2013-03-25 17:50:26 -0700
commit6d71d238e2e072802cb36a011a52f38f3efd9c40 (patch)
treeed9160b8651586e356c4b6f206fdfde19542d4f7 /java/src/com/android/inputmethod/research/ResearchLogger.java
parentfb658d6c531de8cfd55e4d36bffc9ccabc401f94 (diff)
downloadlatinime-6d71d238e2e072802cb36a011a52f38f3efd9c40.tar.gz
latinime-6d71d238e2e072802cb36a011a52f38f3efd9c40.tar.xz
latinime-6d71d238e2e072802cb36a011a52f38f3efd9c40.zip
[FileEncap18] Clean up uploading scheduling
- Move scheduling logic from ResearchLogger.java to UploaderService.java - Switch to a one-shot timer. Previously the uploader was scheduled on an inexact repeating schedule. It's better to reschedule the next upload after the current one is finished to reduce the chances of multiple uploads happening at the same time. - Avoid double-execution - Previously a scheduled upload might run right after an explicit one if they occured at the same time. This change reduces the chances of this. - Some method extraction and naming Change-Id: I9efda11be77d334c7f61bd40a36d65f0421ebde4
Diffstat (limited to 'java/src/com/android/inputmethod/research/ResearchLogger.java')
-rw-r--r--java/src/com/android/inputmethod/research/ResearchLogger.java31
1 files changed, 2 insertions, 29 deletions
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index a38a226f0..81b1a48af 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -20,16 +20,13 @@ import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOAR
import android.accounts.Account;
import android.accounts.AccountManager;
-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;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
@@ -74,22 +71,16 @@ import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.MotionEventReader.ReplayData;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
-import java.util.Locale;
import java.util.Random;
-import java.util.UUID;
/**
* Logs the use of the LatinIME keyboard.
@@ -254,7 +245,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
mUploadNowIntent = new Intent(mLatinIME, UploaderService.class);
mUploadNowIntent.putExtra(UploaderService.EXTRA_UPLOAD_UNCONDITIONALLY, true);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
- scheduleUploadingService(mLatinIME);
+ UploaderService.cancelAndRescheduleUploadingService(mLatinIME,
+ true /* needsRescheduling */);
}
mReplayer.setKeyboardSwitcher(keyboardSwitcher);
}
@@ -268,25 +260,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
ResearchSettings.writeResearchLastDirCleanupTime(mPrefs, now);
}
- /**
- * 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);
- }
-
public void mainKeyboardView_onAttachedToWindow(final MainKeyboardView mainKeyboardView) {
mMainKeyboardView = mainKeyboardView;
maybeShowSplashScreen();