]> sigrok.org Git - sigrok-androidutils.git/blame - src/org/sigrok/androidutils/SigrokApplication.java
Include the device filter XML in the AAR
[sigrok-androidutils.git] / src / org / sigrok / androidutils / SigrokApplication.java
CommitLineData
711d21ce
MC
1/*
2 * This file is part of the sigrok-androidutils project.
3 *
4 * Copyright (C) 2016 Marcus Comstedt <marcus@mc.pp.se>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20package org.sigrok.androidutils;
21
22import android.app.Application;
23import android.content.Context;
24import android.content.pm.ApplicationInfo;
25import android.content.pm.PackageManager;
26import android.util.Log;
27
28public class SigrokApplication extends Application {
29
30 private static final String JNI_LIBS_RESOURCE_ID_META =
31 "org.sigrok.androidutils.jni_libs_resource_id";
f0d3cf4b
MC
32 private static final String DEVICE_FILTER_RESOURCE_ID_META =
33 "org.sigrok.androidutils.device_filter_resource_id";
711d21ce
MC
34
35 public SigrokApplication()
36 {
37 }
38
39 public static void initSigrok(Context context)
40 {
41 ApplicationInfo appInfo = context.getApplicationInfo();
42 Environment.initEnvironment(appInfo.sourceDir);
43 UsbHelper.setContext(context);
44 try {
45 appInfo = context.getPackageManager().
46 getApplicationInfo(context.getPackageName(),
47 PackageManager.GET_META_DATA);
48 } catch (PackageManager.NameNotFoundException exc) {
49 }
50 if (appInfo.metaData != null &&
51 appInfo.metaData.containsKey(JNI_LIBS_RESOURCE_ID_META)) {
52 int resId = appInfo.metaData.getInt(JNI_LIBS_RESOURCE_ID_META);
53 String[] libs = context.getResources().getStringArray(resId);
54 int numLibs = libs.length;
55 for (int i = 0; i < numLibs; i++) {
56 String libName = libs[i];
57 System.loadLibrary(libName);
58 }
59 }
60 }
61
f0d3cf4b
MC
62 public static UsbSupplicant createUsbSupplicant(Context context)
63 {
64 ApplicationInfo appInfo = context.getApplicationInfo();
65 try {
66 appInfo = context.getPackageManager().
67 getApplicationInfo(context.getPackageName(),
68 PackageManager.GET_META_DATA);
69 } catch (PackageManager.NameNotFoundException exc) {
70 }
71 if (appInfo.metaData != null &&
72 appInfo.metaData.containsKey(DEVICE_FILTER_RESOURCE_ID_META)) {
73 int resId = appInfo.metaData.getInt(DEVICE_FILTER_RESOURCE_ID_META);
74 return new UsbSupplicant(context, resId);
75 }
76 Log.e("SigrokApplication", "Can't create UsbSupplicant (resource ID missing)");
77 return null;
78 }
79
711d21ce
MC
80 @Override
81 public void onCreate()
82 {
83 super.onCreate();
84 initSigrok(getApplicationContext());
85 }
86}