简体   繁体   English

如何在 Android 中检查其他应用程序是否使用辅助功能(BIND_ACCESSIBILITY_SERVICE)权限

[英]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?如何检查是否有任何应用程序使用可访问权限(BIND_ACCESSIBILITY_SERVICE),或者请求相同的应用程序的名称以及是否授予它们?

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 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 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 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:已经尝试过以下代码,该代码不适用于上述应用程序,不显示 Access Dot 应用程序和 BurnerGuard 应用程序的任何条目,同时显示 Last pass 的条目但不影响权限更改:

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:对于一般权限(在清单中使用<uses-permission>声明的权限),这应该为您提供所需的信息:

// 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:但是,对于无障碍服务,您可能需要查询AccessibilityManager

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
        }
    } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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