android 蓝牙之bluetooth_jni

本文分析了Android Bluetooth应用中的AdapterApp类,探讨了其在蓝牙进程启动时的角色,特别是如何加载libbluetooth_jni.so库的过程。从System.loadLibrary开始,追踪到库文件的实际路径,并介绍了libbluetooth_jni.so的生成和在Bluetooth应用中的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>&lt;application&gt;</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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值