androidandroid-serviceandroid-bluetoothaidl

Android 12 breaks AIDL/IPC with runtime permissions on IPC APK


Pre-Android 12 I could create proprietary Bluetooth health device driver service APKs and exchange info with them from a main application via AIDL. The driver APKs have no UI and launch nothing when installed. Though these APKs used Bluetooth and BLE all runtime permissions could be given from the primary application. These APKs could be installed and uninstalled without changing any code in the primary application (no action from the user, either).

With Android 12, that is no longer true. These service APKs are useless without the primary application yet Android 12 is requiring runtime permissions from these UI-less and launch-less services.

Does anyone know how to work around this issue or why Android even did this? Defeats the entire purpose of creating plugin drivers! Is there a way to give the permissions from the primary application to the installed driver? The driver does not crash due to no runtime bluetooth permissions until the application tries to use it.


Solution

  • I've faced similar problem also on pre-12. My apk-lib-plugin-aidl app needed some other perms and I've ended with one and only Activity (not set as launcher!) with transparent, or just black, background, which was just running runtime perm dialogs in onResume. didn't even care about result, besides finish()ing Activity. I've also added two methods for AIDL checking perms and running this Activity

        override fun openGrantPermissionsActivity() {
            Log.i(LOG_TAG, "openGrantPermissionsActivity")
            val intent = Intent(this@AidlService, PermissionActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or
                    Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
            startActivity(intent)
        }
    
        override fun checkPermissions(): Boolean {
            val permissionsOk = Utils.checkPermission(
                this@AidlService, PermissionActivity.RECORD_AUDIO_PERM
            )
            Log.i(LOG_TAG, "checkPermissions are ok:$permissionsOk")
            return permissionsOk
        }
    

    would be great to "share" any permission granted to "my app" with other apps, but afaik thats not possible