Merge "Cache application info." into jb-dev

This commit is contained in:
Jean Chalard 2012-05-25 04:07:36 -07:00 committed by Android (Google) Code Review
commit 7707e0459f
2 changed files with 17 additions and 4 deletions

View file

@ -667,9 +667,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead"); Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead");
} }
mTargetApplicationInfo = null; mTargetApplicationInfo =
TargetApplicationGetter.getCachedApplicationInfo(editorInfo.packageName);
if (null == mTargetApplicationInfo) {
new TargetApplicationGetter(this /* context */, this /* listener */) new TargetApplicationGetter(this /* context */, this /* listener */)
.execute(editorInfo.packageName); .execute(editorInfo.packageName);
}
LatinImeLogger.onStartInputView(editorInfo); LatinImeLogger.onStartInputView(editorInfo);
// In landscape mode, this method gets called without the input view being created. // In landscape mode, this method gets called without the input view being created.

View file

@ -20,9 +20,19 @@ import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.util.LruCache;
public class TargetApplicationGetter extends AsyncTask<String, Void, ApplicationInfo> { public class TargetApplicationGetter extends AsyncTask<String, Void, ApplicationInfo> {
private static final int MAX_CACHE_ENTRIES = 64; // arbitrary
private static LruCache<String, ApplicationInfo> sCache =
new LruCache<String, ApplicationInfo>(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 interface OnTargetApplicationKnownListener {
public void onTargetApplicationKnown(final ApplicationInfo info); public void onTargetApplicationKnown(final ApplicationInfo info);
} }
@ -38,12 +48,12 @@ public class TargetApplicationGetter extends AsyncTask<String, Void, Application
@Override @Override
protected ApplicationInfo doInBackground(final String... packageName) { protected ApplicationInfo doInBackground(final String... packageName) {
// TODO: cache app info. Wipe the cache when new packages are installed.
final PackageManager pm = mContext.getPackageManager(); final PackageManager pm = mContext.getPackageManager();
mContext = null; // Bazooka-powered anti-leak device mContext = null; // Bazooka-powered anti-leak device
try { try {
final ApplicationInfo targetAppInfo = final ApplicationInfo targetAppInfo =
pm.getApplicationInfo(packageName[0], 0 /* flags */); pm.getApplicationInfo(packageName[0], 0 /* flags */);
sCache.put(packageName[0], targetAppInfo);
return targetAppInfo; return targetAppInfo;
} catch (android.content.pm.PackageManager.NameNotFoundException e) { } catch (android.content.pm.PackageManager.NameNotFoundException e) {
return null; return null;