1. 程式人生 > >16 展訊Sprd設定-電池-獲取模擬輔助服務列表介面

16 展訊Sprd設定-電池-獲取模擬輔助服務列表介面

1. 前言

後臺管理中,尤其是bing-service型別啟動中,有些服務是不建議攔截的,比如模擬輔助功能

2. 獲取可用模擬輔助元件列表

    private List<ComponentName> mEnabledAccessibilityServiceList = new ArrayList<>();

    public boolean isEnabledAccessibilityService(ComponentName comp) {
        return mEnabledAccessibilityServiceList.contains(comp);
    }

    /**
     * @get the set of enabled accessibility services.
     */
    private void getEnabledServiceList() {
        try {
            final String enabledServicesSetting = Settings.Secure.getStringForUser(
                    mContext.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
                    UserHandle.myUserId());

            Slog.d(TAG, "enabledServicesSetting:" + enabledServicesSetting);
            if (enabledServicesSetting == null) {
                return;
            }
            mEnabledAccessibilityServiceList.clear();

            final TextUtils.SimpleStringSplitter colonSplitter = sStringColonSplitter;
            colonSplitter.setString(enabledServicesSetting);

            while (colonSplitter.hasNext()) {
                final String componentNameString = colonSplitter.next();
                final ComponentName enabledService = ComponentName.unflattenFromString(
                        componentNameString);
                if (enabledService != null) {
                    mEnabledAccessibilityServiceList.add(enabledService);
                }
            }
        } catch (Exception e){}

        if (DEBUG) {
            for (int i = 0, count = mEnabledAccessibilityServiceList.size(); i < count; ++i) {
                Slog.d(TAG, "Enabled AccessibilityService : " + mEnabledAccessibilityServiceList.get(i));
            }
        }
    }

3. 獲取已安裝的模擬輔助元件列表

    private List<ComponentName> mInstalledAccessibilityServiceList = new ArrayList<>();

    public boolean isInstalledAccessibilityService(ComponentName comp) {
        return mInstalledAccessibilityServiceList.contains(comp);
    }

    private void loadInstalledAccessibilityServiceList () {

        AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(mContext);

        try {
            List<AccessibilityServiceInfo> installedServices =
                    accessibilityManager.getInstalledAccessibilityServiceList();

            mInstalledAccessibilityServiceList.clear();
            for (int i = 0, count = installedServices.size(); i < count; ++i) {
                AccessibilityServiceInfo info = installedServices.get(i);

                ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
                ComponentName componentName = new ComponentName(serviceInfo.packageName,
                        serviceInfo.name);

                mInstalledAccessibilityServiceList.add(componentName);
            }
        } catch (Exception e) {}

        if (DEBUG) {
            for (int i = 0, count = mInstalledAccessibilityServiceList.size(); i < count; ++i) {
                Slog.d(TAG, "Installed Accessibility Service: " + mInstalledAccessibilityServiceList.get(i));
            }
        }
    }