am e79d504c: Merge "Cancel interval alarm for dictionary decaying in onDestroy."

* commit 'e79d504cf521e6dd516f0d15eb29f9e61be3e85d':
  Cancel interval alarm for dictionary decaying in onDestroy.
main
Keisuke Kuroyanagi 2014-12-03 02:38:09 +00:00 committed by Android Git Automerger
commit a0c82bdc25
3 changed files with 32 additions and 8 deletions

View File

@ -731,6 +731,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
unregisterReceiver(mDictionaryPackInstallReceiver); unregisterReceiver(mDictionaryPackInstallReceiver);
unregisterReceiver(mDictionaryDumpBroadcastReceiver); unregisterReceiver(mDictionaryDumpBroadcastReceiver);
mStatsUtilsManager.onDestroy(); mStatsUtilsManager.onDestroy();
DictionaryDecayBroadcastReciever.cancelIntervalAlarmForDictionaryDecaying(this);
super.onDestroy(); super.onDestroy();
} }

View File

@ -43,17 +43,40 @@ public class DictionaryDecayBroadcastReciever extends BroadcastReceiver {
/** /**
* Interval to update for decaying dictionaries. * Interval to update for decaying dictionaries.
*/ */
/* package */ static final long DICTIONARY_DECAY_INTERVAL = TimeUnit.MINUTES.toMillis(60); static final long DICTIONARY_DECAY_INTERVAL_IN_MILLIS = TimeUnit.MINUTES.toMillis(60);
public static void setUpIntervalAlarmForDictionaryDecaying(Context context) { private static PendingIntent getPendingIntentForDictionaryDecay(final Context context) {
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
final Intent updateIntent = new Intent(DICTIONARY_DECAY_INTENT_ACTION); final Intent updateIntent = new Intent(DICTIONARY_DECAY_INTENT_ACTION);
updateIntent.setClass(context, DictionaryDecayBroadcastReciever.class); updateIntent.setClass(context, DictionaryDecayBroadcastReciever.class);
final long alarmTime = System.currentTimeMillis() + DICTIONARY_DECAY_INTERVAL; return PendingIntent.getBroadcast(context, 0 /* requestCode */,
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0 /* requestCode */,
updateIntent, PendingIntent.FLAG_CANCEL_CURRENT); updateIntent, PendingIntent.FLAG_CANCEL_CURRENT);
if (null != alarmManager) alarmManager.setInexactRepeating(AlarmManager.RTC, }
alarmTime, DICTIONARY_DECAY_INTERVAL, pendingIntent);
/**
* Set up interval alarm for dynamic dictionaries.
*/
public static void setUpIntervalAlarmForDictionaryDecaying(final Context context) {
final AlarmManager alarmManager =
(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
if (null == alarmManager) {
return;
}
final long alarmTriggerTimeInMillis =
System.currentTimeMillis() + DICTIONARY_DECAY_INTERVAL_IN_MILLIS;
alarmManager.setInexactRepeating(AlarmManager.RTC, alarmTriggerTimeInMillis,
DICTIONARY_DECAY_INTERVAL_IN_MILLIS, getPendingIntentForDictionaryDecay(context));
}
/**
* Cancel interval alarm that has been set up.
*/
public static void cancelIntervalAlarmForDictionaryDecaying(final Context context) {
final AlarmManager alarmManager =
(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
if (null == alarmManager) {
return;
}
alarmManager.cancel(getPendingIntentForDictionaryDecay(context));
} }
@Override @Override

View File

@ -74,7 +74,7 @@ public class PersonalizationHelper {
private static int sCurrentTimestampForTesting = 0; private static int sCurrentTimestampForTesting = 0;
public static void currentTimeChangedForTesting(final int currentTimestamp) { public static void currentTimeChangedForTesting(final int currentTimestamp) {
if (TimeUnit.MILLISECONDS.toSeconds( if (TimeUnit.MILLISECONDS.toSeconds(
DictionaryDecayBroadcastReciever.DICTIONARY_DECAY_INTERVAL) DictionaryDecayBroadcastReciever.DICTIONARY_DECAY_INTERVAL_IN_MILLIS)
< currentTimestamp - sCurrentTimestampForTesting) { < currentTimestamp - sCurrentTimestampForTesting) {
runGCOnAllOpenedUserHistoryDictionaries(); runGCOnAllOpenedUserHistoryDictionaries();
runGCOnAllOpenedPersonalizationDictionaries(); runGCOnAllOpenedPersonalizationDictionaries();