From: Andrei Popescu Date: Tue, 9 Feb 2010 16:59:58 +0000 (+0000) Subject: Implement navigator.isApplicationInstalled() API X-Git-Tag: android-x86-2.2~126 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=30995e7cef0a0d5f9c7228d504076e0c158fa8b7;p=android-x86%2Fpackages-apps-Browser.git Implement navigator.isApplicationInstalled() API This CL contains the comminication with the package manager. Fix b: 2371005 --- diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 53e506a..22ac914 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -128,8 +128,11 @@ import java.net.URLEncoder; import java.text.ParseException; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -339,6 +342,12 @@ public class BrowserActivity extends Activity // if it is replacing, refreshPlugins() when adding return; } + + if (sGoogleApps.contains(packageName)) { + BrowserActivity.this.packageChanged(packageName, + Intent.ACTION_PACKAGE_ADDED.equals(action)); + } + PackageManager pm = BrowserActivity.this.getPackageManager(); PackageInfo pkgInfo = null; try { @@ -431,6 +440,8 @@ public class BrowserActivity extends Activity if (jsFlags.trim().length() != 0) { mTabControl.getCurrentWebView().setJsFlags(jsFlags); } + // Work out which packages are installed on the system. + getInstalledPackages(); } /** @@ -3804,6 +3815,54 @@ public class BrowserActivity extends Activity } } + private void packageChanged(String packageName, boolean wasAdded) { + WebView w = mTabControl.getCurrentWebView(); + if (w == null) { + return; + } + + if (wasAdded) { + w.addPackageName(packageName); + } else { + w.removePackageName(packageName); + } + } + + private void addPackageNames(Set packageNames) { + WebView w = mTabControl.getCurrentWebView(); + if (w == null) { + return; + } + + w.addPackageNames(packageNames); + } + + private void getInstalledPackages() { + AsyncTask > task = + new AsyncTask >() { + protected Set doInBackground(Void... unused) { + Set installedPackages = new HashSet(); + PackageManager pm = BrowserActivity.this.getPackageManager(); + if (pm != null) { + List packages = pm.getInstalledPackages(0); + for (PackageInfo p : packages) { + if (BrowserActivity.this.sGoogleApps.contains(p.packageName)) { + installedPackages.add(p.packageName); + } + } + } + + return installedPackages; + } + + // Executes on the UI thread + protected void onPostExecute(Set installedPackages) { + addPackageNames(installedPackages); + } + }; + task.execute(); + } + final static int LOCK_ICON_UNSECURE = 0; final static int LOCK_ICON_SECURE = 1; final static int LOCK_ICON_MIXED = 2; @@ -3970,6 +4029,14 @@ public class BrowserActivity extends Activity // the video progress view private View mVideoProgressView; + // The Google packages we monitor for the navigator.isApplicationInstalled() + // API. Add as needed. + private static Set sGoogleApps; + static { + sGoogleApps = new HashSet(); + sGoogleApps.add("com.google.android.youtube"); + } + /** * A UrlData class to abstract how the content will be set to WebView. * This base class uses loadUrl to show the content.