1

I'm doing some task with the accessibility service. All works great, but I need to remove the configuration of my xml and run the service from the onServiConnected configuration method and here is where I have the problem.

I can see in the log that onServiceConnected work when I enable the service in my phone, but it doesn't work with the package name like where I run the configuration in the access_xml_config.

Then, that I want to do is have same functionality that I have from the access_xml_config but in the onServiceConnected method.

My method:

@Override
    @SuppressLint("NewApi")
    public void onServiceConnected() {
        super.onServiceConnected();
        Log.i(TAG, "onServiceConnected AccessibilityService");
        AccessibilityServiceInfo info = new AccessibilityServiceInfo();
        info.flags = AccessibilityServiceInfo.DEFAULT;
        info.getCanRetrieveWindowContent();
        info.notificationTimeout = 100;
        info.feedbackType = AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
        info.feedbackType = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
        info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
        info.feedbackType = AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
        info.packageNames = new String[]{"com.android.incallui"};
        this.setServiceInfo(info);

    }

Manifest

 <service android:name=".VsAccessibilityCallScreenService"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
            <intent-filter>
                <action android:name= "android.accessibilityservice.AccessibilityService" />
            </intent-filter>

This is my access_xml_config:

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:packageNames="com.android.incallui"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFlags="flagDefault|flagReportViewIds|flagIncludeNotImportantViews|flagRetrieveInteractiveWindows"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
android:description="@string/app_name"
    />
S.P.
  • 2,274
  • 4
  • 26
  • 57

2 Answers2

1

you using in wrong way bits/integer flags assigment :)

    info.feedbackType = AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
    info.feedbackType = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
    info.feedbackType = AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;

each next line is overriding previous one

so for your case it should be:

    info.feedbackType = 
      AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS
    | AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
    | AccessibilityServiceInfo.FEEDBACK_GENERIC
    | AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS; 

in short:

&   -  bitwise and
|   -  bitwise or
^   -  bitwise xor
~   -  bitwise not
<< -  bitwise shift left
>>  -  bitwise shift right

good start:

Community
  • 1
  • 1
ceph3us
  • 7,326
  • 3
  • 36
  • 43
-2

I found the anwser... using getServiceInfo();

@Override
    @SuppressLint("NewApi")
    public void onServiceConnected() {
        super.onServiceConnected();
        Log.i(TAG, "onServiceConnected AccessibilityService");
        accessibilityServiceInfo info;
        clientconfig = VsClientConfig.getInstance();
        info = getServiceInfo();
        info.packageNames = new String[]{"your.package.name"};
        setServiceInfo(info);

    }
S.P.
  • 2,274
  • 4
  • 26
  • 57