diff --git a/project/Libraries/DroidPlugin/AndroidManifest.xml b/project/Libraries/DroidPlugin/AndroidManifest.xml index 24e549c..cc143ec 100644 --- a/project/Libraries/DroidPlugin/AndroidManifest.xml +++ b/project/Libraries/DroidPlugin/AndroidManifest.xml @@ -187,6 +187,10 @@ android:name=".PluginManagerService" android:label="@string/service_name_plugin_manager_service" /> + + = 18) { + return bundle.getBinder(key); + } else { + if(getIBinder != null) { + try { + return (IBinder) getIBinder.invoke(bundle, key); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + } + + public static void putBinder(Bundle bundle, String key, IBinder value) { + if (Build.VERSION.SDK_INT >= 18) { + bundle.putBinder(key, value); + } else { + if(putIBinder != null) { + try { + putIBinder.invoke(bundle, key, value); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + +} diff --git a/project/Libraries/DroidPlugin/src/com/morgoo/helper/compat/ContentProviderCompat.java b/project/Libraries/DroidPlugin/src/com/morgoo/helper/compat/ContentProviderCompat.java new file mode 100644 index 0000000..e9fc7ca --- /dev/null +++ b/project/Libraries/DroidPlugin/src/com/morgoo/helper/compat/ContentProviderCompat.java @@ -0,0 +1,86 @@ +package com.morgoo.helper.compat; + +import android.content.ContentProviderClient; +import android.content.Context; +import android.net.Uri; +import android.os.Build; +import android.os.Build.VERSION; +import android.os.Bundle; +import android.os.RemoteException; +import android.os.SystemClock; + +/** + * @author Lody + */ +public class ContentProviderCompat { + + public static Bundle call(Context context, Uri uri, String method, String arg, Bundle extras) { + if (VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { + return context.getContentResolver().call(uri, method, arg, extras); + } + ContentProviderClient client = crazyAcquireContentProvider(context, uri); + Bundle res = null; + try { + res = client.call(method, arg, extras); + } catch (RemoteException e) { + e.printStackTrace(); + } finally { + releaseQuietly(client); + } + return res; + } + + + private static ContentProviderClient acquireContentProviderClient(Context context, Uri uri) { + if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + return context.getContentResolver().acquireUnstableContentProviderClient(uri); + } + return context.getContentResolver().acquireContentProviderClient(uri); + } + + public static ContentProviderClient crazyAcquireContentProvider(Context context, Uri uri) { + ContentProviderClient client = acquireContentProviderClient(context, uri); + if (client == null) { + int retry = 0; + while (retry < 5 && client == null) { + SystemClock.sleep(100); + retry++; + client = acquireContentProviderClient(context, uri); + } + } + return client; + } + + public static ContentProviderClient crazyAcquireContentProvider(Context context, String name) { + ContentProviderClient client = acquireContentProviderClient(context, name); + if (client == null) { + int retry = 0; + while (retry < 5 && client == null) { + SystemClock.sleep(100); + retry++; + client = acquireContentProviderClient(context, name); + } + } + return client; + } + + private static ContentProviderClient acquireContentProviderClient(Context context, String name) { + if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + return context.getContentResolver().acquireUnstableContentProviderClient(name); + } + return context.getContentResolver().acquireContentProviderClient(name); + } + + public static void releaseQuietly(ContentProviderClient client) { + if (client != null) { + try { + if (VERSION.SDK_INT >= Build.VERSION_CODES.N) { + client.close(); + } else { + client.release(); + } + } catch (Exception ignored) { + } + } + } +} \ No newline at end of file diff --git a/project/TestPlugin/AndroidManifest.xml b/project/TestPlugin/AndroidManifest.xml index 543dc19..634c598 100644 --- a/project/TestPlugin/AndroidManifest.xml +++ b/project/TestPlugin/AndroidManifest.xml @@ -3,7 +3,7 @@ package="com.example.TestPlugin" android:versionCode="1" android:versionName="1.0"> - +