From 8a135ab0b1f8487437a25b72275f8c50b4811389 Mon Sep 17 00:00:00 2001 From: hyongbai Date: Thu, 28 Mar 2019 14:23:43 +0800 Subject: [PATCH] #plugin##provider# support getType --- .../injector/provider/ProviderInjector.groovy | 3 +- .../loader/p/PluginProviderClient.java | 68 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/replugin-plugin-gradle/src/main/groovy/com/qihoo360/replugin/gradle/plugin/injector/provider/ProviderInjector.groovy b/replugin-plugin-gradle/src/main/groovy/com/qihoo360/replugin/gradle/plugin/injector/provider/ProviderInjector.groovy index c71694cf..aed10d6b 100644 --- a/replugin-plugin-gradle/src/main/groovy/com/qihoo360/replugin/gradle/plugin/injector/provider/ProviderInjector.groovy +++ b/replugin-plugin-gradle/src/main/groovy/com/qihoo360/replugin/gradle/plugin/injector/provider/ProviderInjector.groovy @@ -36,13 +36,14 @@ public class ProviderInjector extends BaseInjector { 'bulkInsert', 'delete', 'update', - /// 以下方法 replugin 暂未支持,导致字节码修改失败。 + /// 以下方法 replugin plugin lib 暂未支持,导致字节码修改失败。 // 'openInputStream', // 'openOutputStream', // 'openFileDescriptor', // 'registerContentObserver', // 'acquireContentProviderClient', // 'notifyChange', +// 'toCalledUri', ] // 表达式编辑器 diff --git a/replugin-plugin-library/replugin-plugin-lib/src/main/java/com/qihoo360/replugin/loader/p/PluginProviderClient.java b/replugin-plugin-library/replugin-plugin-lib/src/main/java/com/qihoo360/replugin/loader/p/PluginProviderClient.java index 2453fc4b..51c8915a 100644 --- a/replugin-plugin-library/replugin-plugin-lib/src/main/java/com/qihoo360/replugin/loader/p/PluginProviderClient.java +++ b/replugin-plugin-library/replugin-plugin-lib/src/main/java/com/qihoo360/replugin/loader/p/PluginProviderClient.java @@ -19,6 +19,7 @@ import android.annotation.TargetApi; import android.content.ContentValues; import android.content.Context; +import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Build; @@ -196,6 +197,34 @@ public static int update(Context c, Uri uri, ContentValues values, String select return -1; } + /** + * 调用插件里的Provider + * + * @see android.content.ContentResolver#getType(Uri) + */ + public static String getType(Context c, Uri uri) { + if (c == null) { + return null; + } + + if (!RePluginFramework.mHostInitialized) { + return c.getContentResolver().getType(uri); + } + + try { + Object obj = ProxyRePluginProviderClientVar.getType.call(null, c, uri); + if (obj != null) { + return (String) obj; + } + } catch (Exception e) { + if (LogDebug.LOG) { + e.printStackTrace(); + } + } + + return null; + } + public static class ProxyRePluginProviderClientVar { private static MethodInvoker query; @@ -210,6 +239,30 @@ public static class ProxyRePluginProviderClientVar { private static MethodInvoker update; + private static MethodInvoker getType; + + private static MethodInvoker openInputStream; + + private static MethodInvoker openOutputStream; + + private static MethodInvoker openOutputStream2; + + private static MethodInvoker openFileDescriptor; + + private static MethodInvoker openFileDescriptor2; + + private static MethodInvoker registerContentObserver; + + private static MethodInvoker acquireContentProviderClient; + + private static MethodInvoker notifyChange; + + private static MethodInvoker notifyChange2; + + private static MethodInvoker toCalledUri; + + private static MethodInvoker toCalledUri2; + public static void initLocked(final ClassLoader classLoader) { // String rePluginProviderClient = "com.qihoo360.loader2.mgr.PluginProviderClient"; @@ -223,6 +276,21 @@ public static void initLocked(final ClassLoader classLoader) { bulkInsert = new MethodInvoker(classLoader, rePluginProviderClient, "bulkInsert", new Class[]{Context.class, Uri.class, ContentValues[].class}); delete = new MethodInvoker(classLoader, rePluginProviderClient, "delete", new Class[]{Context.class, Uri.class, String.class, String[].class}); update = new MethodInvoker(classLoader, rePluginProviderClient, "update", new Class[]{Context.class, Uri.class, ContentValues.class, String.class, String[].class}); + // new supported + getType = new MethodInvoker(classLoader, rePluginProviderClient, "getType", new Class[]{Context.class, Uri.class}); + openInputStream = new MethodInvoker(classLoader, rePluginProviderClient, "openInputStream", new Class[]{Context.class, Uri.class}); + openOutputStream = new MethodInvoker(classLoader, rePluginProviderClient, "openOutputStream", new Class[]{Context.class, Uri.class}); + openOutputStream2 = new MethodInvoker(classLoader, rePluginProviderClient, "openOutputStream", new Class[]{Context.class, Uri.class, String.class}); + openFileDescriptor = new MethodInvoker(classLoader, rePluginProviderClient, "openFileDescriptor", new Class[]{Context.class, Uri.class, String.class}); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + openFileDescriptor2 = new MethodInvoker(classLoader, rePluginProviderClient, "openFileDescriptor", new Class[]{Context.class, Uri.class, String.class, CancellationSignal.class}); + } + registerContentObserver = new MethodInvoker(classLoader, rePluginProviderClient, "registerContentObserver", new Class[]{Context.class, Uri.class, Boolean.class, ContentObserver.class}); + acquireContentProviderClient = new MethodInvoker(classLoader, rePluginProviderClient, "acquireContentProviderClient", new Class[]{Context.class, String.class}); + notifyChange = new MethodInvoker(classLoader, rePluginProviderClient, "notifyChange", new Class[]{Context.class, Uri.class, ContentObserver.class}); + notifyChange2 = new MethodInvoker(classLoader, rePluginProviderClient, "notifyChange", new Class[]{Context.class, Uri.class, ContentObserver.class, Boolean.class}); + toCalledUri = new MethodInvoker(classLoader, rePluginProviderClient, "toCalledUri", new Class[]{Context.class, Uri.class}); + toCalledUri2 = new MethodInvoker(classLoader, rePluginProviderClient, "toCalledUri", new Class[]{Context.class, String.class, Uri.class, Integer.class}); } } }