1

如何检查是否有任何应用程序使用可访问性权限(BIND_ACCESSIBILITY_SERVICE),或者请求相同的应用程序名称以及是否授予它们?

要检测以下应用程序正在使用辅助功能权限:

  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

已经尝试过以下代码,该代码不适用于上述应用程序,不显示 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;
            }
    }

谢谢

4

2 回答 2

0

检查可访问性是否打开/关闭

(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
        }
    } }
于 2021-11-01T13:47:56.753 回答
0

对于一般权限(<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.")
    }
}

但是,对于无障碍服务,您可能需要查询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.")
}
于 2021-02-09T11:15:45.843 回答