2 * This file is part of the sigrok-androidutils project.
4 * Copyright (C) 2016 Marcus Comstedt <marcus@mc.pp.se>
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.
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.
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/>.
20 package org.sigrok.androidutils;
22 import android.app.Application;
23 import android.content.Context;
24 import android.content.pm.ApplicationInfo;
25 import android.content.pm.PackageManager;
26 import android.util.Log;
28 public class SigrokApplication extends Application {
30 private static final String JNI_LIBS_RESOURCE_ID_META =
31 "org.sigrok.androidutils.jni_libs_resource_id";
32 private static final String DEVICE_FILTER_RESOURCE_ID_META =
33 "org.sigrok.androidutils.device_filter_resource_id";
35 public SigrokApplication()
39 public static void initSigrok(Context context)
41 ApplicationInfo appInfo = context.getApplicationInfo();
42 Environment.initEnvironment(appInfo.sourceDir);
43 UsbHelper.setContext(context);
45 appInfo = context.getPackageManager().
46 getApplicationInfo(context.getPackageName(),
47 PackageManager.GET_META_DATA);
48 } catch (PackageManager.NameNotFoundException exc) {
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);
62 public static UsbSupplicant createUsbSupplicant(Context context)
64 ApplicationInfo appInfo = context.getApplicationInfo();
66 appInfo = context.getPackageManager().
67 getApplicationInfo(context.getPackageName(),
68 PackageManager.GET_META_DATA);
69 } catch (PackageManager.NameNotFoundException exc) {
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);
76 Log.e("SigrokApplication", "Can't create UsbSupplicant (resource ID missing)");
81 public void onCreate()
84 initSigrok(getApplicationContext());