简体   繁体   中英

How to Check other apps are using accessibility (BIND_ACCESSIBILITY_SERVICE) permission or not in Android

how to check is there any app using accessibility permission(BIND_ACCESSIBILITY_SERVICE), or the name of applications which requested for the same along with its granted or not to them?

To detect that below apps are using accessibility permission:

  1. https://play.google.com/store/apps/details?id=you.in.spark.access.dots&hl=en_IN&gl=US
  2. https://play.google.com/store/apps/details?id=com.oddlyspaced.burnermedia.burnerguard&hl=en_IN&gl=US
  3. https://play.google.com/store/apps/details?id=com.lastpass.lpandroid&hl=en_IN&gl=US

Already Tried Below code which is not working for above apps, not showing any entry for Access Dot app and BurnerGuard app, while showing entry for Last pass but not affecting on change of permission:

List<PackageInfo> allpackages = getPackageManager().getInstalledPackages(PackageManager.GET_PERMISSIONS);
    for(int i =0;i<allpackages.size();i++){
        PackageInfo pi = allpackages.get(i);
        if (pi.requestedPermissions == null) {
            // No permissions are requested in the AndroidManifest
            continue;
        }
        String[] requestedPermissions = pi.requestedPermissions;
        int[] requestPermissionFlags;
        for(int j=0;j<requestedPermissions.length;j++){
            String reqParm = requestedPermissions[j];
            int status = pi.requestedPermissionsFlags[j] & PackageInfo.REQUESTED_PERMISSION_GRANTED;
            
            try {
                PermissionInfo permissionInfo = getPackageManager().getPermissionInfo(reqParm,0);
      
                if(permissionInfo.name.equals("android.permission.BIND_ACCESSIBILITY_SERVICE")) {
                    if(status!=0) {
                        Log.i("accessibility", "Package Name :: " + pi.packageName + "    permission name :: " + permissionInfo.name + " Permission Granted " );
                    } else {
                        Log.i("accessibility", "Package Name :: " + pi.packageName + "    permission name :: " + permissionInfo.name + " Permission Requested " );
                    }
                }
            } catch (PackageManager.NameNotFoundException e) {
                //Log.e("accessibility", "Unknown permission: ");
                continue;
            }
    }

Thanks

For permissions in general (those declared with <uses-permission> in the manifest), this should give you the information you want:

// Iterate over all installed packages and include information about their permissions
packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS).forEach { pkg ->
    // Find out if the current package has declared BIND_ACCESSIBILITY_SERVICE in its manifest..
    val index = pkg.requestedPermissions?.indexOf(Manifest.permission.BIND_ACCESSIBILITY_SERVICE) ?: -1
    if (index != -1) {
        // ..it has, so log whether the permission has been granted.
        val flags = pkg.requestedPermissionFlags[index]
        val grantStatus = if ((flags and PackageManager.PERMISSION_GRANTED) == PackageManager.PERMISSION_GRANTED) "granted" else "not granted"
        Log.d("Foo", "Package ${pkg.packageName} wants BIND_ACCESSIBILITY_SERVICE, and it is currently $grantStatus.")
    }
}

However, for accessibility services you may need to query the AccessibilityManager instead:

val accessibilityManager = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
val installedServices = accessibilityManager.installedAccessibilityServiceList
val enabledServices = accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK)
installedServices.forEach { installed ->
    val svcInfo = installed.resolveInfo.serviceInfo
    val appLabel = packageManager.getApplicationLabel(packageManager.getApplicationInfo(svcInfo.packageName, 0))
    val state = if (enabledServices.any { it.resolveInfo.serviceInfo.packageName == svcInfo.packageName && it.resolveInfo.serviceInfo.name == svcInfo.name && svcInfo.permission == Manifest.permission.BIND_ACCESSIBILITY_SERVICE)) {
        "enabled"
    } else {
        "installed but currently disabled"
    }
    Log.d("Foo", "Service ${svcInfo.name} belonging to $appLabel is $state.")
}

to check accessibility is on/off

(requireActivity().getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager).apply {
    installedAccessibilityServiceList.forEach { installedService ->
        installedService.resolveInfo.serviceInfo.apply {
            if (getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK).any { it.resolveInfo.serviceInfo.packageName == packageName && it.resolveInfo.serviceInfo.name == name && permission == Manifest.permission.BIND_ACCESSIBILITY_SERVICE && it.resolveInfo.serviceInfo.packageName == requireActivity().packageName })
                isAccessibilityEnabled = true
        }
    } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM