From 1b1243d61fd682d804e61de6a1eccbf0e8ba78b2 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 25 May 2012 18:19:19 +0900 Subject: [PATCH] Cache application info. Bug: 6537051 Change-Id: Ieca891235df0d697bdeb0510651b703654fdef38 --- java/src/com/android/inputmethod/latin/LatinIME.java | 9 ++++++--- .../inputmethod/latin/TargetApplicationGetter.java | 12 +++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 44aab3395..c58549497 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -667,9 +667,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead"); } - mTargetApplicationInfo = null; - new TargetApplicationGetter(this /* context */, this /* listener */) - .execute(editorInfo.packageName); + mTargetApplicationInfo = + TargetApplicationGetter.getCachedApplicationInfo(editorInfo.packageName); + if (null == mTargetApplicationInfo) { + new TargetApplicationGetter(this /* context */, this /* listener */) + .execute(editorInfo.packageName); + } LatinImeLogger.onStartInputView(editorInfo); // In landscape mode, this method gets called without the input view being created. diff --git a/java/src/com/android/inputmethod/latin/TargetApplicationGetter.java b/java/src/com/android/inputmethod/latin/TargetApplicationGetter.java index 109f23f4c..46300b479 100644 --- a/java/src/com/android/inputmethod/latin/TargetApplicationGetter.java +++ b/java/src/com/android/inputmethod/latin/TargetApplicationGetter.java @@ -20,9 +20,19 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.AsyncTask; +import android.util.LruCache; public class TargetApplicationGetter extends AsyncTask { + private static final int MAX_CACHE_ENTRIES = 64; // arbitrary + private static LruCache sCache = + new LruCache(MAX_CACHE_ENTRIES); + + public static ApplicationInfo getCachedApplicationInfo(final String packageName) { + return sCache.get(packageName); + } + // TODO: Wipe the cache when new packages are installed. + public interface OnTargetApplicationKnownListener { public void onTargetApplicationKnown(final ApplicationInfo info); } @@ -38,12 +48,12 @@ public class TargetApplicationGetter extends AsyncTask