导航菜单

页面标题

页面副标题

Delta Chat v1.58.3 - BackupTransferActivity.java 源代码

正在查看: Delta Chat v1.58.3 应用的 BackupTransferActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.thoughtcrime.securesms.qr;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.BaseActionBarActivity;
import org.thoughtcrime.securesms.ConversationListActivity;
import org.thoughtcrime.securesms.LogViewActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.service.GenericForegroundService;
import org.thoughtcrime.securesms.service.NotificationController;
import org.thoughtcrime.securesms.util.Util;

public class BackupTransferActivity extends BaseActionBarActivity {
    public static final String QR_CODE = "qr_code";
    private static final String TAG = "BackupTransferActivity";
    public static final String TRANSFER_MODE = "transfer_mode";
    NotificationController notificationController;
    private TransferMode transferMode = TransferMode.RECEIVER_SCAN_QR;
    private TransferState transferState = TransferState.TRANSFER_UNKNOWN;
    private boolean notificationControllerClosed = false;
    public boolean warnAboutCopiedQrCodeOnAbort = false;

    public enum TransferState {
        TRANSFER_UNKNOWN,
        TRANSFER_ERROR,
        TRANSFER_SUCCESS
    }

    public enum TransferMode {
        INVALID(0),
        SENDER_SHOW_QR(1),
        RECEIVER_SCAN_QR(2);

        private final int i;

        TransferMode(int i) {
            this.i = i;
        }

        public int getInt() {
            return this.i;
        }

        public static TransferMode fromInt(int i) {
            return values()[i];
        }
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        TransferMode fromInt = TransferMode.fromInt(getIntent().getIntExtra(TRANSFER_MODE, TransferMode.INVALID.getInt()));
        this.transferMode = fromInt;
        if (fromInt == TransferMode.INVALID) {
            throw new RuntimeException("bad transfer mode");
        }
        DcHelper.getAccounts(this).stopIo();
        String string = getString(this.transferMode == TransferMode.RECEIVER_SCAN_QR ? R.string.multidevice_receiver_title : R.string.multidevice_title);
        this.notificationController = GenericForegroundService.startForegroundTask(this, string);
        setContentView(R.layout.backup_provider_activity);
        int i = AnonymousClass1.$SwitchMap$org$thoughtcrime$securesms$qr$BackupTransferActivity$TransferMode[this.transferMode.ordinal()];
        if (i == 1) {
            initFragment(android.R.id.content, new BackupProviderFragment(), bundle);
        } else if (i == 2) {
            initFragment(android.R.id.content, new BackupReceiverFragment(), bundle);
        }
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        supportActionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
        supportActionBar.setTitle(string);
    }

    protected void onDestroy() {
        super.onDestroy();
        if (!this.notificationControllerClosed) {
            this.notificationController.close();
        }
        DcHelper.getAccounts(this).startIo();
    }

    public boolean onPrepareOptionsMenu(Menu menu) {
        menu.clear();
        getMenuInflater().inflate(R.menu.backup_transfer_menu, menu);
        return super.onPrepareOptionsMenu(menu);
    }

    public void onBackPressed() {
        finishOrAskToFinish();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        super.onOptionsItemSelected(menuItem);
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finishOrAskToFinish();
            return true;
        }
        if (itemId == R.id.troubleshooting) {
            DcHelper.openHelp(this, "#multiclient");
            return true;
        }
        if (itemId != R.id.view_log_button) {
            return false;
        }
        startActivity(new Intent((Context) this, (Class<?>) LogViewActivity.class));
        return true;
    }

    public void setTransferState(TransferState transferState) {
        this.transferState = transferState;
    }

    public void setTransferError(String str) {
        if (this.transferState != TransferState.TRANSFER_ERROR) {
            this.transferState = TransferState.TRANSFER_ERROR;
            String lastError = DcHelper.getContext(this).getLastError();
            if (lastError.isEmpty()) {
                lastError = "<last error not set>";
            }
            if (!str.isEmpty()) {
                str = str + ": ";
            }
            new AlertDialog.Builder(this).setMessage(str + lastError).setPositiveButton(android.R.string.ok, (DialogInterface.OnClickListener) null).setCancelable(false).show();
        }
    }

    static class AnonymousClass1 {
        static final int[] $SwitchMap$org$thoughtcrime$securesms$qr$BackupTransferActivity$TransferMode;
        static final int[] $SwitchMap$org$thoughtcrime$securesms$qr$BackupTransferActivity$TransferState;

        static {
            int[] iArr = new int[TransferState.values().length];
            $SwitchMap$org$thoughtcrime$securesms$qr$BackupTransferActivity$TransferState = iArr;
            try {
                iArr[TransferState.TRANSFER_ERROR.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$org$thoughtcrime$securesms$qr$BackupTransferActivity$TransferState[TransferState.TRANSFER_SUCCESS.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            int[] iArr2 = new int[TransferMode.values().length];
            $SwitchMap$org$thoughtcrime$securesms$qr$BackupTransferActivity$TransferMode = iArr2;
            try {
                iArr2[TransferMode.SENDER_SHOW_QR.ordinal()] = 1;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$org$thoughtcrime$securesms$qr$BackupTransferActivity$TransferMode[TransferMode.RECEIVER_SCAN_QR.ordinal()] = 2;
            } catch (NoSuchFieldError unused4) {
            }
        }
    }

    private void finishOrAskToFinish() {
        int i = AnonymousClass1.$SwitchMap$org$thoughtcrime$securesms$qr$BackupTransferActivity$TransferState[this.transferState.ordinal()];
        if (i == 1 || i == 2) {
            doFinish();
            return;
        }
        String string = getString(R.string.multidevice_abort);
        if (this.warnAboutCopiedQrCodeOnAbort) {
            string = string + "\n\n" + getString(R.string.multidevice_abort_will_invalidate_copied_qr);
        }
        new AlertDialog.Builder(this).setMessage(string).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i2) {
                BackupTransferActivity.this.m1585x41c68456(dialogInterface, i2);
            }
        }).setNegativeButton(R.string.cancel, (DialogInterface.OnClickListener) null).show();
    }

    void m1585x41c68456(DialogInterface dialogInterface, int i) {
        doFinish();
    }

    public void doFinish() {
        this.notificationController.close();
        this.notificationControllerClosed = true;
        if (this.transferMode == TransferMode.RECEIVER_SCAN_QR && this.transferState == TransferState.TRANSFER_SUCCESS) {
            startActivity(new Intent(getApplicationContext(), (Class<?>) ConversationListActivity.class));
        } else if (this.transferMode == TransferMode.SENDER_SHOW_QR) {
            startActivity(new Intent(getApplicationContext(), (Class<?>) ConversationListActivity.class));
            startActivity(new Intent((Context) this, (Class<?>) ApplicationPreferencesActivity.class));
            overridePendingTransition(0, 0);
        }
        finish();
    }

    public static void appendSSID(final Activity activity, final TextView textView) {
        if (textView == null || Build.VERSION.SDK_INT < 23) {
            return;
        }
        new Thread(new Runnable() {
            @Override
            public final void run() {
                BackupTransferActivity.lambda$appendSSID$2(activity, textView);
            }
        }).start();
    }

    static void lambda$appendSSID$2(Activity activity, final TextView textView) {
        try {
            WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService("wifi");
            if (wifiManager.isWifiEnabled()) {
                final String ssid = wifiManager.getConnectionInfo().getSSID();
                Log.i(TAG, "wifi ssid: " + ssid);
                if (ssid.equals("<unknown ssid>")) {
                    return;
                }
                Util.runOnMain(new Runnable() {
                    @Override
                    public final void run() {
                        r0.setText(((Object) textView.getText()) + " (" + ssid + ")");
                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}