Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

插件的服务需要无障碍权限的话,需要在哪边manifest注册?以及使用时判断权限的context该用哪个? #1226

Closed
mintz1chen opened this issue Aug 18, 2023 · 1 comment

Comments

@mintz1chen
Copy link

mintz1chen commented Aug 18, 2023

你好,我的项目demo有一个Service是需要用到android.permission.BIND_ACCESSIBILITY_SERVICE。在使用shadow的框架移植项目demo的时候发现有几个疑问:
1、如果这个Service直接在插件的manifest注册的话,宿主安装之后,系统无障碍设置页的已安装的服务里面是找不到这个服务的,导致无法开启
2、如果这个Service不在插件的manifest注册的话,比如在host或者introduce-shadow-lib里面注册,在系统设置页是能找到这个服务了,但是这样的话Service相关的代码是否就都需要挪到这个lib或者host里面?
3、Service在插件的manifest注册时,单独跑插件可以正常使用这个服务,但是如果在introduce-shadow-lib里面注册跟插件service一样包名路径的服务,给host开了无障碍权限,实际上并不能使用。
插件里面判断无障碍权限的方法如下:

public static boolean isAccessibilitySettingsOn(Context mContext) {
        int accessibilityEnabled = 0;
        final String service = mContext.getPackageName() + "/" + RCAccessibilityService.class.getCanonicalName();
        try {
            accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(),
                    Settings.Secure.ACCESSIBILITY_ENABLED);
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
        }
        TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
        if (accessibilityEnabled == 1) {
            String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(),
                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
            if (settingValue != null) {
                mStringColonSplitter.setString(settingValue);
                while (mStringColonSplitter.hasNext()) {
                    String accessibilityService = mStringColonSplitter.next();
                    if (accessibilityService.equalsIgnoreCase(service)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

想咨询一下像这种场景,这个服务应该放在哪里?

@mintz1chen
Copy link
Author

最后我是通过在host建个lib工程,然后在host-lib的manifest里面注册个壳子服务,服务里面利用callback来传回调内容给插件,注意弄好白名单,插件也要compileOnly这个host-lib这样子

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant