🍭 v1.8.0版本的 MD5 值为:0229079aa4aa60e49c57f3c4c415ae2e

以下内容为反编译后的 LoginActivity.java 源代码,内容仅作参考


package im.pkahdfyclb.ui.activities;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.alibaba.fastjson.JSONObject;
import com.fm.openinstall.OpenInstall;
import com.serenegiant.uvccamera.BuildConfig;
import im.pkahdfyclb.messenger.AndroidUtilities;
import im.pkahdfyclb.messenger.ApplicationLoader;
import im.pkahdfyclb.messenger.ContactsController;
import im.pkahdfyclb.messenger.LocaleController;
import im.pkahdfyclb.messenger.MessagesController;
import im.pkahdfyclb.messenger.MessagesStorage;
import im.pkahdfyclb.messenger.NotificationCenter;
import im.pkahdfyclb.messenger.R;
import im.pkahdfyclb.messenger.UserConfig;
import im.pkahdfyclb.tgnet.ConnectionsManager;
import im.pkahdfyclb.tgnet.RequestDelegate;
import im.pkahdfyclb.tgnet.TLObject;
import im.pkahdfyclb.tgnet.TLRPC;
import im.pkahdfyclb.tgnet.TLRPCLogin;
import im.pkahdfyclb.ui.ExternalActionActivity;
import im.pkahdfyclb.ui.IndexActivity;
import im.pkahdfyclb.ui.LaunchActivity;
import im.pkahdfyclb.ui.actionbar.AlertDialog;
import im.pkahdfyclb.ui.actionbar.BaseFragment;
import im.pkahdfyclb.ui.components.AppTextView;
import im.pkahdfyclb.ui.components.LayoutHelper;
import im.pkahdfyclb.utils.DeviceUtils;
import im.pkahdfyclb.utils.FingerprintUtil;
import java.util.ArrayList;
import java.util.Locale;

public class LoginActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
    public TextView backupIpAddressLog;
    private AppTextView tvTips;

    @Override
    public boolean onFragmentCreate() {
        NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.getBackupIpStatus);
        return super.onFragmentCreate();
    }

    private boolean checkPermission() {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission("android.permission.READ_PHONE_STATE") != 0) {
            getParentActivity().requestPermissions(new String[]{"android.permission.READ_PHONE_STATE"}, 6);
            return false;
        }
        return true;
    }

    @Override
    public View createView(Context context) {
        this.fragmentView = LayoutInflater.from(context).inflate(R.layout.activity_login_layout, (ViewGroup) null);
        this.actionBar.setAddToContainer(false);
        this.tvTips = (AppTextView) this.fragmentView.findViewById(R.id.tvTips);
        TextView textView = new TextView(context);
        this.backupIpAddressLog = textView;
        textView.setTextColor(getParentActivity().getResources().getColor(R.color.black));
        this.backupIpAddressLog.setTextSize(1, 10.0f);
        ((FrameLayout) this.fragmentView).addView(this.backupIpAddressLog, LayoutHelper.createFrame(-1, -1, 16, 160, 16, 16));
        login2();
        return this.fragmentView;
    }

    @Override
    public void onRequestPermissionsResultFragment(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResultFragment(requestCode, permissions, grantResults);
        if (requestCode == 6 && grantResults != null && grantResults[0] == 0) {
            login();
        }
    }

    private void login() {
        TLRPCLogin.TL_auth_SignAuto req = new TLRPCLogin.TL_auth_SignAuto();
        req.company_tag = "Guang";
        req.dev_uuid = DeviceUtils.getDeviceId(getParentActivity());
        ConnectionsManager.getInstance(this.currentAccount).bindRequestToGuid(ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                LoginActivity.this.lambda$login$1$LoginActivity(tLObject, tL_error);
            }
        }, 10), this.classGuid);
    }

    public void lambda$login$1$LoginActivity(final TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                LoginActivity.this.lambda$null$0$LoginActivity(error, response);
            }
        });
    }

    public void lambda$null$0$LoginActivity(TLRPC.TL_error error, TLObject response) {
        if (error == null) {
            if (!(response instanceof TLRPC.TL_auth_authorizationSignUpRequired) && (response instanceof TLRPC.TL_auth_authorization)) {
                OpenInstall.reportRegister();
                onAuthSuccess((TLRPC.TL_auth_authorization) response);
                return;
            }
            return;
        }
        parseError(error, "");
    }

    private void login2() {
        String oldFingerprint = DeviceUtils.getDeviceId(getParentActivity());
        final String newFingerprint = FingerprintUtil.getDeviceId(getParentActivity());
        TLRPCLogin.TL_auth_SignAuto2 req = new TLRPCLogin.TL_auth_SignAuto2();
        req.company_tag = "Guang";
        req.device_old = oldFingerprint;
        req.device_new = newFingerprint;
        ConnectionsManager.getInstance(this.currentAccount).bindRequestToGuid(ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                LoginActivity.this.lambda$login2$3$LoginActivity(newFingerprint, tLObject, tL_error);
            }
        }, 10), this.classGuid);
    }

    public void lambda$login2$3$LoginActivity(final String newFingerprint, final TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                LoginActivity.this.lambda$null$2$LoginActivity(error, response, newFingerprint);
            }
        });
    }

    public void lambda$null$2$LoginActivity(TLRPC.TL_error error, TLObject response, String newFingerprint) {
        if (error == null) {
            if (!(response instanceof TLRPC.TL_auth_authorizationSignUpRequired) && (response instanceof TLRPC.TL_auth_authorization)) {
                OpenInstall.reportRegister();
                Log.e(BuildConfig.BUILD_TYPE, "response" + JSONObject.toJSONString(response));
                onAuthSuccess((TLRPC.TL_auth_authorization) response);
                SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("deviceConfig", 0);
                sharedPreferences.edit().putString("device_fingerprint", newFingerprint).commit();
                return;
            }
            return;
        }
        parseError(error, "");
    }

    @Override
    public void onFragmentDestroy() {
        super.onFragmentDestroy();
        getConnectionsManager().cancelRequestsForGuid(this.classGuid);
    }

    protected void onAuthSuccess(TLRPC.TL_auth_authorization res) {
        ConnectionsManager.getInstance(this.currentAccount).setUserId(res.user.id);
        UserConfig.getInstance(this.currentAccount).clearConfig();
        MessagesController.getInstance(this.currentAccount).cleanup();
        UserConfig.getInstance(this.currentAccount).syncContacts = false;
        UserConfig.getInstance(this.currentAccount).setCurrentUser(res.user);
        UserConfig.getInstance(this.currentAccount).saveConfig(true);
        MessagesStorage.getInstance(this.currentAccount).cleanup(true);
        ArrayList<TLRPC.User> users = new ArrayList<>();
        users.add(res.user);
        MessagesStorage.getInstance(this.currentAccount).putUsersAndChats(users, null, true, true);
        MessagesController.getInstance(this.currentAccount).putUser(res.user, false);
        ContactsController.getInstance(this.currentAccount).checkAppAccount();
        MessagesController.getInstance(this.currentAccount).checkProxyInfo(true);
        ConnectionsManager.getInstance(this.currentAccount).updateDcSettings();
        if (getParentActivity() instanceof LaunchActivity) {
            presentFragment(new IndexActivity(), true);
            NotificationCenter.getInstance(this.currentAccount).postNotificationName(NotificationCenter.mainUserInfoChanged, new Object[0]);
        } else if (getParentActivity() instanceof ExternalActionActivity) {
            ((ExternalActionActivity) getParentActivity()).onFinishLogin();
        }
    }

    protected void parseError(TLRPC.TL_error error, String extra) {
        if (error != null && !TextUtils.isEmpty(error.text)) {
            if (error.text.contains("PHONE_NUMBER_INVALID")) {
                needShowInvalidAlert(extra, false);
                return;
            }
            if (error.text.contains("PHONE_PASSWORD_FLOOD")) {
                needShowAlert(LocaleController.getString(R.string.FloodWait));
                return;
            }
            if (error.text.contains("PHONE_NUMBER_FLOOD")) {
                needShowAlert(LocaleController.getString(R.string.PhoneNumberFlood));
                return;
            }
            if (error.text.contains("PHONE_NUMBER_BANNED") || error.text.contains("ACCOUNT_RESTRICTED")) {
                needShowInvalidAlert(extra, true);
                return;
            }
            if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
                needShowAlert(LocaleController.getString("InvalidCode", R.string.InvalidCode));
                return;
            }
            if (error.text.contains("PHONE_CODE_EXPIRED")) {
                needShowAlert(LocaleController.getString("VerificationcodeExpired", R.string.VerificationcodeExpired));
                return;
            }
            if (error.text.startsWith("FLOOD_WAIT")) {
                needShowAlert(LocaleController.getString(R.string.FloodWait));
                return;
            }
            if (error.text.startsWith("CODE_VERIFY_LIMIT")) {
                needShowAlert(LocaleController.getString(R.string.CODE_VERIFY_LIMIT));
                return;
            }
            if (error.text.startsWith("CODE_INVALID")) {
                needShowAlert(LocaleController.getString(R.string.InvalidCode));
                return;
            }
            if (error.text.startsWith("PASSWORD_ERROR")) {
                needShowAlert(LocaleController.getString(R.string.LoginPwdError));
                return;
            }
            if (error.text.startsWith("PHONE_NOT_SIGNUP") || error.text.startsWith("USERNAME_NOT_EXIST")) {
                needShowAlert(LocaleController.getString(R.string.UserNotRegistered));
                return;
            }
            if (error.text.startsWith("PHONE_NUMBER_OCCUPIED")) {
                needShowAlert(LocaleController.getString(R.string.UsernameAlreadyExists));
                return;
            }
            if (error.text.startsWith("CURRENT_PWD_ERR")) {
                needShowAlert(LocaleController.getString(R.string.OldPwdError));
                return;
            }
            if (error.text.startsWith("NOTEQUAL_TAG")) {
                needShowAlert(LocaleController.getString(R.string.LoginPwdError));
                return;
            }
            if (error.text.startsWith("PASSWORD_INVALID")) {
                needShowAlert(LocaleController.getString(R.string.PasswordDoNotMatch));
                return;
            }
            if (error.text.startsWith("PASSWORD_MANY")) {
                needShowAlert(LocaleController.getString(R.string.PWdErrorMany));
                return;
            }
            if (error.text.startsWith("USERNAME_INVALID")) {
                needShowAlert(LocaleController.getString(R.string.UsernameInvalid));
                return;
            }
            if (error.text.startsWith("USERNAME_OCCUPIED")) {
                needShowAlert(LocaleController.getString(R.string.UsernameInUse));
                return;
            }
            needShowAlert(LocaleController.getString(R.string.OperationFailedPleaseTryAgain) + "\n" + error.text);
        }
    }

    protected void needShowInvalidAlert(final String phoneNumber, final boolean banned) {
        if (getParentActivity() == null) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString(R.string.AppName));
        if (banned) {
            builder.setMessage(LocaleController.getString(R.string.BannedPhoneNumber));
        } else {
            builder.setMessage(LocaleController.getString(R.string.InvalidPhoneNumber));
        }
        builder.setNeutralButton(LocaleController.getString(R.string.BotHelp), new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                LoginActivity.this.lambda$needShowInvalidAlert$4$LoginActivity(banned, phoneNumber, dialogInterface, i);
            }
        });
        builder.setPositiveButton(LocaleController.getString(R.string.OK), null);
        showDialog(builder.create());
    }

    public void lambda$needShowInvalidAlert$4$LoginActivity(boolean banned, String phoneNumber, DialogInterface dialog, int which) {
        try {
            PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
            String version = String.format(Locale.US, "%s (%d)", pInfo.versionName, Integer.valueOf(pInfo.versionCode));
            Intent mailer = new Intent("android.intent.action.SEND");
            mailer.setType("message/rfc822");
            mailer.putExtra("android.intent.extra.EMAIL", new String[]{"login@stel.com"});
            if (banned) {
                mailer.putExtra("android.intent.extra.SUBJECT", "Banned phone number: " + phoneNumber);
                mailer.putExtra("android.intent.extra.TEXT", "I'm trying to use my mobile phone number: " + phoneNumber + "\nBut pkahdfyclb says it's banned. Please help.\n\nApp version: " + version + "\nOS version: SDK " + Build.VERSION.SDK_INT + "\nDevice Name: " + Build.MANUFACTURER + Build.MODEL + "\nLocale: " + Locale.getDefault());
            } else {
                mailer.putExtra("android.intent.extra.SUBJECT", "Invalid phone number: " + phoneNumber);
                mailer.putExtra("android.intent.extra.TEXT", "I'm trying to use my mobile phone number: " + phoneNumber + "\nBut pkahdfyclb says it's invalid. Please help.\n\nApp version: " + version + "\nOS version: SDK " + Build.VERSION.SDK_INT + "\nDevice Name: " + Build.MANUFACTURER + Build.MODEL + "\nLocale: " + Locale.getDefault());
            }
            getParentActivity().startActivity(Intent.createChooser(mailer, "Send email..."));
        } catch (Exception e) {
            needShowAlert(LocaleController.getString(R.string.NoMailInstalled));
        }
    }

    protected void needShowAlert(String text) {
        if (text == null || getParentActivity() == null) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString(R.string.AppName));
        builder.setMessage(text);
        builder.setPositiveButton(LocaleController.getString(R.string.OK), null);
        showDialog(builder.create());
    }

    @Override
    public void didReceivedNotification(int id, int account, Object... args) {
        if (id == NotificationCenter.getBackupIpStatus) {
            Log.e(BuildConfig.BUILD_TYPE, "args==" + ((String) args[0]));
            if (this.backupIpAddressLog != null && getParentActivity() != null) {
                this.backupIpAddressLog.setText(((String) args[0]) + "(" + AndroidUtilities.getVersionName(getParentActivity()) + ")");
            }
        }
    }
}