How Android Bluetooth Profiles are enabled & Services activated ?

How Android Bluetooth profiles are enabled ?

Ans:

Check packages/apps/Bluetooth/res/values/config.xml

<resources>
16    <bool name="profile_supported_a2dp">true</bool>
30</resources>

If you want to disable the above profile, change from "true" to "false"
Check related lxr

The above flags are used during initialisation as below, in file, 
packages/apps/Bluetooth/src/com/android/bluetooth/btservice/Config.java
Resource flag to indicate whether profile is supported or not.
private static final int[]  PROFILE_SERVICES_FLAG = {
        R.bool.profile_supported_hs_hfp,
        R.bool.profile_supported_a2dp,
        R.bool.profile_supported_a2dp_sink,
        R.bool.profile_supported_hid,
        R.bool.profile_supported_hdp,
        R.bool.profile_supported_pan,
        R.bool.profile_supported_gatt,
        R.bool.profile_supported_map,
        R.bool.profile_supported_hfpclient,
        R.bool.profile_supported_avrcp_controller,
    };

Supported Profile services are defined at,
    private static final Class[] PROFILE_SERVICES = {
        HeadsetService.class,
        A2dpService.class,
        A2dpSinkService.class,
        HidService.class,
        HealthService.class,
        PanService.class,
        GattService.class,
        BluetoothMapService.class,
        HeadsetClientService.class,
        AvrcpControllerService.class,
    };
Now inside init, it checks resources (from packages/apps/Bluetooth/res/values/config.xml ) flag and adds a profile if its supported as below,
           boolean supported = resources.getBoolean(PROFILE_SERVICES_FLAG[i]);
            if (supported) {
                Log.d(TAG, "Adding " + PROFILE_SERVICES[i].getSimpleName());
                profiles.add(PROFILE_SERVICES[i]);
            }
Refer to Link for more details.

How Profile Services are started ?

As mentioned above, the declaration of profile services, is done, now the profile service actually gets started from
packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterService.java

void processStart() {
Class[] supportedProfileServices = Config.getSupportedProfiles(); [ This is called to Link ]
mJniCallbacks.init(mBondStateMachine,mRemoteDevices); [ This calls the JNI calls for the particular profile service ]

  //Start profile services
      if (!mProfilesStarted && supportedProfileServices.length >) {
            //Startup all profile services
            setProfileServiceState(supportedProfileServices,BluetoothAdapter.STATE_ON);
        }else {
            debugLog("processStart() - Profile Services alreay started");
            mAdapterStateMachine.sendMessage(mAdapterStateMachine.obtainMessage(AdapterState.STARTED));
        }
 The above functions calls to starts the profile services, Call to setProfileServiceState goes to
file packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterService.java

private void setProfileServiceState(Class[] services, int state) {
        for (int i=; i <services.length;i++) {
            String serviceName = services[i].getName();
            Integer serviceState = mProfileServicesState.get(serviceName);
            if(serviceState != null && serviceState != expectedCurrentState) {
                debugLog("setProfileServiceState() - Unable to "
                    + (state == BluetoothAdapter.STATE_OFF ? "start" : "stop" )
                    + " service " + serviceName
                    + ". Invalid state: " + serviceState);
                continue;
            }

            debugLog("setProfileServiceState() - "
                + (state == BluetoothAdapter.STATE_OFF ? "Stopping" : "Starting")
                + " service " + serviceName);

            mProfileServicesState.put(serviceName,pendingState);
            Intent intent = new Intent(this,services[i]);
            intent.putExtra(EXTRA_ACTION,ACTION_SERVICE_STATE_CHANGED);
            intent.putExtra(BluetoothAdapter.EXTRA_STATE,state);
            startService(intent);
        }
}
 
Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply