package com.example.appwindowmanagerdemo1;
import android.provider.Settings;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import java.util.Collections;
import java.util.List;
import android.accessibilityservice.GestureDescription;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.media.AudioManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import java.util.ArrayDeque;
import java.util.Deque;
/*Draft java code by "Lazarus Android Module Wizard" [7/14/2020 16:47:51]*/
/*https://github.com/jmpessoa/lazandroidmodulewizard*/
/*jControl LAMW template*/
// ref. https://stackoverflow.com/questions/22057625/prevent-ussd-dialog-and-read-ussd-response
// ref. http://habrahabr.ru/post/234425/
public class jUSSDService extends AccessibilityService {
private Path path;
private GestureDescription.Builder builder;
private GestureDescription.StrokeDescription strokeDescription;
private GestureResultCallback gestureResultCallback;
private GestureDescription gestureDescription;
private long pascalObj = 0; //Pascal Object
private Controls controls = null; //Java/Pascal [events] Interface ...
/*.*/public static String TAG
= jUSSDService.
class.
getSimpleName();
//GUIDELINE: please, preferentially, init all yours params names with "_", ex: int _flag, String _hello ...
/*.*/public jUSSDService() {
//super();
}
public jUSSDService(Controls _ctrls, long _Self) { //Add more others news "_xxx" params if needed!
//super(_ctrls.activity);
context = _ctrls.activity;
pascalObj = _Self;
controls = _ctrls;
}
private String processUSSDText
(List
<CharSequence
> eventText
) { for (CharSequence s : eventText) {
// Return text if text is the expected ussd response
if( true ) {
return text;
}
}
return null;
}
private String toString
(AccessibilityEvent event
) { str += "eventtype: " + AccessibilityEvent.eventTypeToString(event.getEventType());
str += "\nsource: " + event.getSource();
str += "\npackagename: " + event.getPackageName();
str += "\nclassname: " + event.getClassName();
return str;
}
//public static void
public void logNodeHeirarchy(AccessibilityNodeInfo nodeInfo, int depth) {
//if nodeInfo.getText() = "Home" {
// //currentNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
// }
if (nodeInfo == null) return;
for (int i = 0; i < depth; ++i) {
logString += " ";
}
logString += "Text: " + nodeInfo.getText() + " " + " Content-Description: " + nodeInfo.getContentDescription();
Log.v("Meu", logString);
Intent intent = new Intent("org.lamw.action.USSDService");
intent.putExtra("message",logString ); //text
sendBroadcast(intent);
for (int i = 0; i < nodeInfo.getChildCount(); ++i) {
logNodeHeirarchy(nodeInfo.getChild(i), depth + 1);
}
}
@Override
/*.*/public void onAccessibilityEvent(AccessibilityEvent event) {
//Log.d(TAG, "onAccessibilityEvent");
AccessibilityNodeInfo source = event.getSource();
if (source == null) {
return;}
if (event.getEventType()==AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED){
if (source.getPackageName()!=null) {
if (!source.getPackageName().equals("com.sec.android.app.launcher")) {
if (!source.getPackageName().equals("com.example.appwindowmanagerdemo1")) {
Intent intent = new Intent("org.lamw.action.USSDService");
intent.putExtra("message","Package:"+source.getPackageName() ); //text
sendBroadcast(intent);
AccessibilityNodeInfo currentNode=getRootInActiveWindow();
if (currentNode!=null) {
logNodeHeirarchy(currentNode, 0);
}
}
}
}
}
return;
}
@Override
/*.*/public void onInterrupt() {
//
}
@Override
protected void onServiceConnected() {
super.onServiceConnected();
// pag1();
// com.uieaser.atextwidget class android.widget.TextView id name R.id.textViewMain parent android.widget.RelativeLayout(R.id.RelativeLayout1)
//Log.d(TAG, "onServiceConnected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.flags = AccessibilityServiceInfo.DEFAULT;
info.packageNames = null;
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
setServiceInfo(info);
}
public void jFree() {
//free local objects...
}
//write others [public] methods code here......
//GUIDELINE: please, preferentially, init all yours params names with "_", ex: int _flag, String _hello ...
//Method to start the service
public void Start() {
//Explicit intents explicitly define the component which should be called by the Android system,
//by using the Java class as identifier
//Create an intent for a specific component.
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
controls.activity. startActivity(intent);
}
public void pag1() {
if (path == null) {
path = new Path();
path.moveTo(513, 1963);
path.lineTo(513, 1963);
}
if (builder == null)
builder = new GestureDescription.Builder();
if (strokeDescription == null) {
strokeDescription = new GestureDescription.StrokeDescription(path, 0, 1);
builder.addStroke(strokeDescription);
}
if (gestureResultCallback == null)
gestureResultCallback = new GestureResultCallback() {
@Override
public void onCompleted(GestureDescription gestureDescription) {
pag1();
}
@Override
public void onCancelled(GestureDescription gestureDescription) {
super.onCancelled(gestureDescription);
}
};
if (gestureDescription == null)
gestureDescription = builder.build();
dispatchGesture(gestureDescription, gestureResultCallback, null);
}
public void Stop() {
controls.activity.stopService(new Intent(controls.activity,jUSSDService.class));
}
}