am 7707e045: Merge "Cache application info." into jb-dev

* commit '7707e0459ff54edc701f7f84dd222861c62445c7':
  Cache application info.
main
Jean Chalard 2012-05-25 04:09:10 -07:00 committed by Android Git Automerger
commit d45e334f5a
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 =
new TargetApplicationGetter(this /* context */, this /* listener */) TargetApplicationGetter.getCachedApplicationInfo(editorInfo.packageName);
.execute(editorInfo.packageName); if (null == mTargetApplicationInfo) {
new TargetApplicationGetter(this /* context */, this /* listener */)
.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;