aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/SystemBroadcastReceiver.java
diff options
context:
space:
mode:
authorJatin Matani <jatinm@google.com>2015-07-13 10:34:03 -0700
committerJatin Matani <jatinm@google.com>2015-07-13 10:40:26 -0700
commit80c9bfbd280d6ca519af201a2dc4f93bb3ab63b1 (patch)
treedac73f877b51df06f1e8715c45e05761694e7f85 /java/src/com/android/inputmethod/latin/SystemBroadcastReceiver.java
parentb4b19735182767df88f3a196a94c4a943423e72b (diff)
parent9cd60fe1bb67cec755c1cee6d541272e64129072 (diff)
downloadlatinime-80c9bfbd280d6ca519af201a2dc4f93bb3ab63b1.tar.gz
latinime-80c9bfbd280d6ca519af201a2dc4f93bb3ab63b1.tar.xz
latinime-80c9bfbd280d6ca519af201a2dc4f93bb3ab63b1.zip
resolved conflicts for merge of 9cd60fe1 to mnc-dr-dev
Change-Id: I8c7e0f48dad8eff174df4ffdebeeb9467fd799a0
Diffstat (limited to 'java/src/com/android/inputmethod/latin/SystemBroadcastReceiver.java')
-rw-r--r--java/src/com/android/inputmethod/latin/SystemBroadcastReceiver.java39
1 files changed, 36 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/SystemBroadcastReceiver.java b/java/src/com/android/inputmethod/latin/SystemBroadcastReceiver.java
index 0d081e0d2..90221512f 100644
--- a/java/src/com/android/inputmethod/latin/SystemBroadcastReceiver.java
+++ b/java/src/com/android/inputmethod/latin/SystemBroadcastReceiver.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.latin;
+import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -23,14 +24,15 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.database.Cursor;
import android.os.Process;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
-import com.android.inputmethod.dictionarypack.CommonPreferences;
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
+import com.android.inputmethod.dictionarypack.DownloadManagerWrapper;
import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.setup.SetupActivity;
@@ -75,7 +77,12 @@ public final class SystemBroadcastReceiver extends BroadcastReceiver {
final InputMethodSubtype[] additionalSubtypes = richImm.getAdditionalSubtypes();
richImm.setAdditionalInputMethodSubtypes(additionalSubtypes);
toggleAppIcon(context);
- downloadLatestDictionaries(context);
+
+ // Remove all the previously scheduled downloads. This will also makes sure
+ // that any erroneously stuck downloads will get cleared. (b/21797386)
+ removeOldDownloads(context);
+ // b/21797386
+ // downloadLatestDictionaries(context);
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
Log.i(TAG, "Boot has been completed");
toggleAppIcon(context);
@@ -103,13 +110,39 @@ public final class SystemBroadcastReceiver extends BroadcastReceiver {
}
}
+ private void removeOldDownloads(Context context) {
+ try {
+ Log.i(TAG, "Removing the old downloads in progress of the previous keyboard version.");
+ final DownloadManagerWrapper downloadManagerWrapper = new DownloadManagerWrapper(
+ context);
+ final DownloadManager.Query q = new DownloadManager.Query();
+ // Query all the download statuses except the succeeded ones.
+ q.setFilterByStatus(DownloadManager.STATUS_FAILED
+ | DownloadManager.STATUS_PAUSED
+ | DownloadManager.STATUS_PENDING
+ | DownloadManager.STATUS_RUNNING);
+ final Cursor c = downloadManagerWrapper.query(q);
+ if (c != null) {
+ for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
+ final long downloadId = c
+ .getLong(c.getColumnIndex(DownloadManager.COLUMN_ID));
+ downloadManagerWrapper.remove(downloadId);
+ Log.i(TAG, "Removed the download with Id: " + downloadId);
+ }
+ c.close();
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Exception while removing old downloads.");
+ }
+ }
+
private void downloadLatestDictionaries(Context context) {
final Intent updateIntent = new Intent(
DictionaryPackConstants.INIT_AND_UPDATE_NOW_INTENT_ACTION);
context.sendBroadcast(updateIntent);
}
- private static void toggleAppIcon(final Context context) {
+ public static void toggleAppIcon(final Context context) {
final int appInfoFlags = context.getApplicationInfo().flags;
final boolean isSystemApp = (appInfoFlags & ApplicationInfo.FLAG_SYSTEM) > 0;
if (Log.isLoggable(TAG, Log.INFO)) {