Java Code Examples for org.telegram.tgnet.TLRPC#TL_account_sendConfirmPhoneCode

The following examples show how to use org.telegram.tgnet.TLRPC#TL_account_sendConfirmPhoneCode . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CancelAccountDeletionActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNextPressed() {
    if (getParentActivity() == null || nextPressed) {
        return;
    }
    TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
    boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    boolean allowCall = true;
    if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
        //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
        //boolean allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED;
        /*if (checkPermissions) {
            permissionsItems.clear();
            if (!allowCall) {
                permissionsItems.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (!allowSms) {
                permissionsItems.add(Manifest.permission.RECEIVE_SMS);
            }
            if (!permissionsItems.isEmpty()) {
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS)) {
                    preferences.edit().putBoolean("firstlogin", false).commit();
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    if (permissionsItems.size() == 2) {
                        builder.setMessage(LocaleController.getString("AllowReadCallAndSms", R.string.AllowReadCallAndSms));
                    } else if (!allowSms) {
                        builder.setMessage(LocaleController.getString("AllowReadSms", R.string.AllowReadSms));
                    } else {
                        builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall));
                    }
                    permissionsDialog = showDialog(builder.create());
                } else {
                    getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6);
                }
                return;
            }
        }*/
    }

    final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode();
    req.allow_flashcall = false;//simcardAvailable && allowCall;
    req.hash = hash;
    if (req.allow_flashcall) {
        try {
            @SuppressLint("HardwareIds") String number = tm.getLine1Number();
            if (!TextUtils.isEmpty(number)) {
                req.current_number = phone.contains(number) || number.contains(phone);
                if (!req.current_number) {
                    req.allow_flashcall = false;
                }
            } else {
                req.current_number = false;
            }
        } catch (Exception e) {
            req.allow_flashcall = false;
            FileLog.e(e);
        }
    }

    final Bundle params = new Bundle();
    params.putString("phone", phone);
    nextPressed = true;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
        @Override
        public void run(final TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    nextPressed = false;
                    if (error == null) {
                        fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
                    } else {
                        errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req);
                    }
                }
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 2
Source File: CancelAccountDeletionActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNextPressed() {
    if (getParentActivity() == null || nextPressed) {
        return;
    }
    TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
    boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    boolean allowCall = true;
    if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
        //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
        //boolean allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED;
        /*if (checkPermissions) {
            permissionsItems.clear();
            if (!allowCall) {
                permissionsItems.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (!allowSms) {
                permissionsItems.add(Manifest.permission.RECEIVE_SMS);
            }
            if (!permissionsItems.isEmpty()) {
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS)) {
                    preferences.edit().putBoolean("firstlogin", false).commit();
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    if (permissionsItems.size() == 2) {
                        builder.setMessage(LocaleController.getString("AllowReadCallAndSms", R.string.AllowReadCallAndSms));
                    } else if (!allowSms) {
                        builder.setMessage(LocaleController.getString("AllowReadSms", R.string.AllowReadSms));
                    } else {
                        builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall));
                    }
                    permissionsDialog = showDialog(builder.create());
                } else {
                    getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6);
                }
                return;
            }
        }*/
    }

    final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode();
    req.allow_flashcall = false;//simcardAvailable && allowCall;
    req.hash = hash;
    if (req.allow_flashcall) {
        try {
            @SuppressLint("HardwareIds") String number = tm.getLine1Number();
            if (!TextUtils.isEmpty(number)) {
                req.current_number = phone.contains(number) || number.contains(phone);
                if (!req.current_number) {
                    req.allow_flashcall = false;
                }
            } else {
                req.current_number = false;
            }
        } catch (Exception e) {
            req.allow_flashcall = false;
            FileLog.e(e);
        }
    }

    final Bundle params = new Bundle();
    params.putString("phone", phone);
    nextPressed = true;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
        @Override
        public void run(final TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    nextPressed = false;
                    if (error == null) {
                        fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
                    } else {
                        errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req);
                    }
                }
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 3
Source File: CancelAccountDeletionActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNextPressed() {
    if (getParentActivity() == null || nextPressed) {
        return;
    }
    TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
    boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    boolean allowCall = true;
    if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
        //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
        /*if (checkPermissions) {
            permissionsItems.clear();
            if (!allowCall) {
                permissionsItems.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (!permissionsItems.isEmpty()) {
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) {
                    preferences.edit().putBoolean("firstlogin", false).commit();
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall));
                    permissionsDialog = showDialog(builder.create());
                } else {
                    getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6);
                }
                return;
            }
        }*/
    }

    final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode();
    req.hash = hash;
    req.settings = new TLRPC.TL_codeSettings();
    req.settings.allow_flashcall = false;//simcardAvailable && allowCall;
    req.settings.allow_app_hash = ApplicationLoader.hasPlayServices;
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
    if (req.settings.allow_app_hash) {
        preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit();
    } else {
        preferences.edit().remove("sms_hash").commit();
    }
    if (req.settings.allow_flashcall) {
        try {
            @SuppressLint("HardwareIds") String number = tm.getLine1Number();
            if (!TextUtils.isEmpty(number)) {
                req.settings.current_number = PhoneNumberUtils.compare(phone, number);
                if (!req.settings.current_number) {
                    req.settings.allow_flashcall = false;
                }
            } else {
                req.settings.current_number = false;
            }
        } catch (Exception e) {
            req.settings.allow_flashcall = false;
            FileLog.e(e);
        }
    }

    final Bundle params = new Bundle();
    params.putString("phone", phone);
    nextPressed = true;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        nextPressed = false;
        if (error == null) {
            fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
        } else {
            errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req);
        }
    }), ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 4
Source File: CancelAccountDeletionActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNextPressed() {
    if (getParentActivity() == null || nextPressed) {
        return;
    }
    TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
    boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    boolean allowCall = true;
    if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
        //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
        /*if (checkPermissions) {
            permissionsItems.clear();
            if (!allowCall) {
                permissionsItems.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (!permissionsItems.isEmpty()) {
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) {
                    preferences.edit().putBoolean("firstlogin", false).commit();
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall));
                    permissionsDialog = showDialog(builder.create());
                } else {
                    getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6);
                }
                return;
            }
        }*/
    }

    final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode();
    req.hash = hash;
    req.settings = new TLRPC.TL_codeSettings();
    req.settings.allow_flashcall = false;//simcardAvailable && allowCall;
    req.settings.allow_app_hash = ApplicationLoader.hasPlayServices;
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
    if (req.settings.allow_app_hash) {
        preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit();
    } else {
        preferences.edit().remove("sms_hash").commit();
    }
    if (req.settings.allow_flashcall) {
        try {
            @SuppressLint("HardwareIds") String number = tm.getLine1Number();
            if (!TextUtils.isEmpty(number)) {
                req.settings.current_number = PhoneNumberUtils.compare(phone, number);
                if (!req.settings.current_number) {
                    req.settings.allow_flashcall = false;
                }
            } else {
                req.settings.current_number = false;
            }
        } catch (Exception e) {
            req.settings.allow_flashcall = false;
            FileLog.e(e);
        }
    }

    final Bundle params = new Bundle();
    params.putString("phone", phone);
    nextPressed = true;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        nextPressed = false;
        if (error == null) {
            fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
        } else {
            errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req);
        }
    }), ConnectionsManager.RequestFlagFailOnServerErrors);
}