mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-03 14:00:07 +01:00
[TF][KILL] GMS SMS Receiver
(cherry picked from commit cebab00b23fc87cc7a993511fedee644c4981c2e)
This commit is contained in:
parent
c72c70c46e
commit
fd30c76096
@ -246,14 +246,6 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".SmsReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".CallReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PHONE_STATE"/>
|
||||
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This is the source code of Telegram for Android v. 5.x.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2018.
|
||||
*/
|
||||
|
||||
package org.telegram.messenger;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.google.android.gms.auth.api.phone.SmsRetriever;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SmsReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String message = "";
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
String hash = preferences.getString("sms_hash", null);
|
||||
if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
|
||||
if (!AndroidUtilities.isWaitingForSms()) {
|
||||
return;
|
||||
}
|
||||
Bundle bundle = intent.getExtras();
|
||||
message = (String) bundle.get(SmsRetriever.EXTRA_SMS_MESSAGE);
|
||||
}
|
||||
if (TextUtils.isEmpty(message)) {
|
||||
return;
|
||||
}
|
||||
Pattern pattern = Pattern.compile("[0-9\\-]+");
|
||||
final Matcher matcher = pattern.matcher(message);
|
||||
if (matcher.find()) {
|
||||
String code = matcher.group(0).replace("-", "");
|
||||
if (code.length() >= 3) {
|
||||
if (preferences != null && hash != null) {
|
||||
preferences.edit().putString("sms_hash_code", hash + "|" + code).commit();
|
||||
}
|
||||
AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, code));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user