launching plugin activity when a plugin requests to go full screen.
Change-Id: Ib42bb08d01a75ca3a9c02085ee185396bb7b7378
This commit is contained in:
@@ -63,8 +63,11 @@ public class PluginManager {
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
|
private ArrayList<PackageInfo> mPackageInfoCache;
|
||||||
|
|
||||||
private PluginManager(Context context) {
|
private PluginManager(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mPackageInfoCache = new ArrayList<PackageInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized PluginManager getInstance(Context context) {
|
public static synchronized PluginManager getInstance(Context context) {
|
||||||
@@ -92,65 +95,94 @@ public class PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String[] getPluginDirectories() {
|
String[] getPluginDirectories() {
|
||||||
|
|
||||||
ArrayList<String> directories = new ArrayList<String>();
|
ArrayList<String> directories = new ArrayList<String>();
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
List<ResolveInfo> plugins = pm.queryIntentServices(new Intent(
|
List<ResolveInfo> plugins = pm.queryIntentServices(new Intent(
|
||||||
PLUGIN_ACTION), PackageManager.GET_SERVICES);
|
PLUGIN_ACTION), PackageManager.GET_SERVICES);
|
||||||
for (ResolveInfo info : plugins) {
|
|
||||||
ServiceInfo serviceInfo = info.serviceInfo;
|
synchronized(mPackageInfoCache) {
|
||||||
if (serviceInfo == null) {
|
|
||||||
Log.w(LOGTAG, "Ignore bad plugin");
|
// clear the list of existing packageInfo objects
|
||||||
continue;
|
mPackageInfoCache.clear();
|
||||||
}
|
|
||||||
PackageInfo pkgInfo;
|
for (ResolveInfo info : plugins) {
|
||||||
try {
|
ServiceInfo serviceInfo = info.serviceInfo;
|
||||||
pkgInfo = pm.getPackageInfo(serviceInfo.packageName,
|
if (serviceInfo == null) {
|
||||||
PackageManager.GET_PERMISSIONS
|
Log.w(LOGTAG, "Ignore bad plugin");
|
||||||
| PackageManager.GET_SIGNATURES);
|
continue;
|
||||||
} catch (NameNotFoundException e) {
|
}
|
||||||
Log.w(LOGTAG, "Cant find plugin: " + serviceInfo.packageName);
|
PackageInfo pkgInfo;
|
||||||
continue;
|
try {
|
||||||
}
|
pkgInfo = pm.getPackageInfo(serviceInfo.packageName,
|
||||||
if (pkgInfo == null) {
|
PackageManager.GET_PERMISSIONS
|
||||||
continue;
|
| PackageManager.GET_SIGNATURES);
|
||||||
}
|
} catch (NameNotFoundException e) {
|
||||||
String directory = pkgInfo.applicationInfo.dataDir + "/lib";
|
Log.w(LOGTAG, "Cant find plugin: " + serviceInfo.packageName);
|
||||||
if (directories.contains(directory)) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
if (pkgInfo == null) {
|
||||||
String permissions[] = pkgInfo.requestedPermissions;
|
continue;
|
||||||
if (permissions == null) {
|
}
|
||||||
continue;
|
String directory = pkgInfo.applicationInfo.dataDir + "/lib";
|
||||||
}
|
if (directories.contains(directory)) {
|
||||||
boolean permissionOk = false;
|
continue;
|
||||||
for (String permit : permissions) {
|
}
|
||||||
if (PLUGIN_PERMISSION.equals(permit)) {
|
String permissions[] = pkgInfo.requestedPermissions;
|
||||||
permissionOk = true;
|
if (permissions == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
boolean permissionOk = false;
|
||||||
|
for (String permit : permissions) {
|
||||||
|
if (PLUGIN_PERMISSION.equals(permit)) {
|
||||||
|
permissionOk = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!permissionOk) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Signature signatures[] = pkgInfo.signatures;
|
||||||
|
if (signatures == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
boolean signatureMatch = false;
|
||||||
|
for (Signature signature : signatures) {
|
||||||
|
// TODO: check signature against Google provided one
|
||||||
|
signatureMatch = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!signatureMatch) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mPackageInfoCache.add(pkgInfo);
|
||||||
|
directories.add(directory);
|
||||||
}
|
}
|
||||||
if (!permissionOk) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Signature signatures[] = pkgInfo.signatures;
|
|
||||||
if (signatures == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
boolean signatureMatch = false;
|
|
||||||
for (Signature signature : signatures) {
|
|
||||||
// TODO: check signature against Google provided one
|
|
||||||
signatureMatch = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!signatureMatch) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
directories.add(directory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return directories.toArray(new String[directories.size()]);
|
return directories.toArray(new String[directories.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getPluginsAPKName(String pluginLib) {
|
||||||
|
|
||||||
|
// basic error checking on input params
|
||||||
|
if (pluginLib == null || pluginLib.length() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// must be synchronized to ensure the consistency of the cache
|
||||||
|
synchronized(mPackageInfoCache) {
|
||||||
|
for (PackageInfo pkgInfo : mPackageInfoCache) {
|
||||||
|
if (pluginLib.startsWith(pkgInfo.applicationInfo.dataDir)) {
|
||||||
|
return pkgInfo.packageName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if no apk was found then return null
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String getPluginSharedDataDirectory() {
|
String getPluginSharedDataDirectory() {
|
||||||
return mContext.getDir("plugins", 0).getPath();
|
return mContext.getDir("plugins", 0).getPath();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package android.webkit;
|
package android.webkit;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.DrawFilter;
|
import android.graphics.DrawFilter;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
@@ -2091,17 +2092,44 @@ final class WebViewCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginWidget functions for creating SurfaceViews for the Surface drawing
|
// called by JNI. PluginWidget function to launch an activity and overlays
|
||||||
// model.
|
// the activity with the View provided by the plugin class.
|
||||||
private ViewManager.ChildView createSurface(String packageName, String className,
|
private void startFullScreenPluginActivity(String libName, String clsName, int npp) {
|
||||||
|
if (mWebView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String pkgName = PluginManager.getInstance(null).getPluginsAPKName(libName);
|
||||||
|
if (pkgName == null) {
|
||||||
|
Log.w(LOGTAG, "Unable to resolve " + libName + " to a plugin APK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent intent = new Intent("android.intent.webkit.PLUGIN");
|
||||||
|
intent.putExtra(PluginActivity.INTENT_EXTRA_PACKAGE_NAME, pkgName);
|
||||||
|
intent.putExtra(PluginActivity.INTENT_EXTRA_CLASS_NAME, clsName);
|
||||||
|
intent.putExtra(PluginActivity.INTENT_EXTRA_NPP_INSTANCE, npp);
|
||||||
|
mWebView.getContext().startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// called by JNI. PluginWidget functions for creating an embedded View for
|
||||||
|
// the surface drawing model.
|
||||||
|
private ViewManager.ChildView createSurface(String libName, String clsName,
|
||||||
int npp, int x, int y, int width, int height) {
|
int npp, int x, int y, int width, int height) {
|
||||||
if (mWebView == null) {
|
if (mWebView == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PluginStub stub = PluginUtil.getPluginStub(mWebView.getContext(), packageName, className);
|
|
||||||
|
String pkgName = PluginManager.getInstance(null).getPluginsAPKName(libName);
|
||||||
|
if (pkgName == null) {
|
||||||
|
Log.w(LOGTAG, "Unable to resolve " + libName + " to a plugin APK");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginStub stub =PluginUtil.getPluginStub(mWebView.getContext(),pkgName, clsName);
|
||||||
if (stub == null) {
|
if (stub == null) {
|
||||||
Log.e(LOGTAG, "Unable to find plugin class (" + className +
|
Log.e(LOGTAG, "Unable to find plugin class (" + clsName +
|
||||||
") in the apk (" + packageName + ")");
|
") in the apk (" + pkgName + ")");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user