]> sigrok.org Git - sigrok-androidutils.git/commitdiff
Include the device filter XML in the AAR
authorMarcus Comstedt <redacted>
Wed, 7 Dec 2016 20:24:47 +0000 (21:24 +0100)
committerUwe Hermann <redacted>
Fri, 16 Dec 2016 18:22:52 +0000 (19:22 +0100)
Also add a convenience method for creating a UsbSupplicant from it.

AndroidManifest.xml.in
build.xml
src/org/sigrok/androidutils/SigrokApplication.java

index 1256ec425f447c3e71d8acd430e147c690853bb6..e6b25f63b3be76d5c60fd354d1311beb8bf50f3e 100644 (file)
@@ -29,6 +29,7 @@
 
     <application>
        <meta-data android:name="org.sigrok.androidutils.jni_libs_resource_id" android:resource="@array/sigrok_androidutils_jni_libs"/>
+       <meta-data android:name="org.sigrok.androidutils.device_filter_resource_id" android:resource="@xml/sigrok_androidutils_device_filter"/>
     </application>
 
 </manifest>
index 04496cd7361c19a9594aea37479b6b3e61f09d05..e4af70ab6147fd7b79309e71841051dafda30416 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -95,6 +95,7 @@
 </resources>]]></concat>
         <mergemapper to="res/values/sigrok_androidutils_jni_libs.xml" />
       </mappedresources>
+      <zipfileset file="device_filter.xml" fullpath="res/xml/sigrok_androidutils_device_filter.xml"/>
     </zip>
   </target>
 
index 5a68792a1580c27351a1bcf201c80e555b2cfdc3..8406693571a16874c7cc9f609b13b6ea6f41ef7b 100644 (file)
@@ -29,6 +29,8 @@ public class SigrokApplication extends Application {
 
        private static final String JNI_LIBS_RESOURCE_ID_META =
            "org.sigrok.androidutils.jni_libs_resource_id";
+       private static final String DEVICE_FILTER_RESOURCE_ID_META =
+           "org.sigrok.androidutils.device_filter_resource_id";
 
        public SigrokApplication()
        {
@@ -57,6 +59,24 @@ public class SigrokApplication extends Application {
                }
        }
 
+       public static UsbSupplicant createUsbSupplicant(Context context)
+       {
+               ApplicationInfo appInfo = context.getApplicationInfo();
+               try {
+                       appInfo = context.getPackageManager().
+                               getApplicationInfo(context.getPackageName(),
+                               PackageManager.GET_META_DATA);
+               } catch (PackageManager.NameNotFoundException exc) {
+               }
+               if (appInfo.metaData != null &&
+                               appInfo.metaData.containsKey(DEVICE_FILTER_RESOURCE_ID_META)) {
+                       int resId = appInfo.metaData.getInt(DEVICE_FILTER_RESOURCE_ID_META);
+                       return new UsbSupplicant(context, resId);
+               }
+               Log.e("SigrokApplication", "Can't create UsbSupplicant (resource ID missing)");
+               return null;
+       }
+
        @Override
        public void onCreate()
        {