android 蓝牙之bluetooth_jni
通过阅读该篇文章,你可以知道bluetooth_jni
到底是什么?
什么时候加载?
从何处来?
从代码层层剖析,清楚明白。如有不正确的请指正,非常感谢。
AdapterApp分析
Bluetooth.apk里面有个AdapterApp.java,该类继承自android.app.Application, Application类的解释如下:
/**
* Base class for maintaining global application state. You can provide your own
* implementation by creating a subclass and specifying the fully-qualified name
* of this subclass as the <code>"android:name"</code> attribute in your
* AndroidManifest.xml's <code><application></code> tag. The Application
* class, or your subclass of the Application class, is instantiated before any
* other class when the process for your application/package is created.
**/
由这解释可以可以看出,继承自Application的子类需要在AndroidManifest.xml里注册,然后子类便会在你进程的其它所有类create之前实例化。
也就是说,在蓝牙进程启动时,AdapterApp类是第一个跑起来的可见类。
public class AdapterApp extends Application {
private static final String TAG = "BluetoothAdapterApp";
private static final boolean DBG = false;
//For Debugging only
private static int sRefCount=0;
static {
if (DBG) Log.d(TAG,"Loading JNI Library");
System.loadLibrary("bluetooth_jni");
}
public AdapterApp() {
super();
if (DBG) {
synchronized (AdapterApp.class) {
sRefCount++;
Log.d(TAG, "REFCOUNT: Constructed "+ this + " Instance Count = " + sRefCount);
}
}
}
@Override
public void onCreate() {
super.onCreate();
if (DBG) Log.d