mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
fix leaving Delta Chat during backup transfer
this fixes leaving Delta Chat during backup transfer by removing other activities that would abort BackupTransfer by getting called with onNewIntent() otherwise. moreover, the permantent notification is removed more reliably and possible crashes in the permantent notification closing (races ...) are catched. see code + comments for details.
This commit is contained in:
@@ -144,6 +144,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
Intent intent = new Intent(this, BackupTransferActivity.class);
|
||||
intent.putExtra(BackupTransferActivity.TRANSFER_MODE, BackupTransferActivity.TransferMode.SENDER_SHOW_QR.getInt());
|
||||
startActivity(intent);
|
||||
overridePendingTransition(0, 0); // let the activity appear in the same way as the other pages (which are mostly fragments)
|
||||
finishAffinity(); // see comment (**2) in BackupTransferActivity.doFinish()
|
||||
}
|
||||
|
||||
public static class ApplicationPreferenceFragment extends CorrectedPreferenceFragment implements DcEventCenter.DcEventDelegate {
|
||||
|
||||
@@ -14,6 +14,7 @@ import androidx.annotation.NonNull;
|
||||
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;
|
||||
@@ -56,6 +57,7 @@ public class BackupTransferActivity extends BaseActionBarActivity {
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
NotificationController notificationController;
|
||||
private boolean notificationControllerClosed = false;
|
||||
public boolean warnAboutCopiedQrCodeOnAbort = false;
|
||||
|
||||
@Override
|
||||
@@ -93,12 +95,12 @@ public class BackupTransferActivity extends BaseActionBarActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (isFinishing()) {
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (!notificationControllerClosed) {
|
||||
notificationController.close();
|
||||
DcHelper.getAccounts(this).startIo();
|
||||
}
|
||||
DcHelper.getAccounts(this).startIo();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,8 +168,25 @@ public class BackupTransferActivity extends BaseActionBarActivity {
|
||||
}
|
||||
|
||||
public void doFinish() {
|
||||
// the permanent notification will prevent other activities to be started and kill BackupTransferActivity;
|
||||
// close it before starting other activities
|
||||
notificationController.close();
|
||||
notificationControllerClosed = true;
|
||||
|
||||
if (transferMode == TransferMode.RECEIVER_SCAN_QR && transferState == TransferState.TRANSFER_SUCCESS) {
|
||||
startActivity(new Intent(getApplicationContext(), ConversationListActivity.class));
|
||||
} else if (transferMode == TransferMode.SENDER_SHOW_QR) {
|
||||
// restart the activities that were removed when BackupTransferActivity was started at (**2)
|
||||
// (we removed the activity backstack as otherwise a tap on the Delta Chat icon on the home screen would
|
||||
// call onNewIntent() which cannot be aborted and will kill BackupTransferActivity.
|
||||
// if all activities are removed, onCreate() will be called and that can be aborted, so that
|
||||
// a tap in the home icon just opens BackupTransferActivity.
|
||||
// (the user can leave Delta Chat during backup transfer :)
|
||||
// a proper fix would maybe to not rely onNewIntent() at all - but that would require more refactorings
|
||||
// and needs lots if testing in complicated areas (share ...))
|
||||
startActivity(new Intent(getApplicationContext(), ConversationListActivity.class));
|
||||
startActivity(new Intent(this, ApplicationPreferencesActivity.class));
|
||||
overridePendingTransition(0, 0);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -58,8 +58,12 @@ public final class NotificationController {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
GenericForegroundService.stopForegroundTask(context, id);
|
||||
context.unbindService(serviceConnection);
|
||||
try {
|
||||
GenericForegroundService.stopForegroundTask(context, id);
|
||||
context.unbindService(serviceConnection);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setIndeterminateProgress() {
|
||||
|
||||
Reference in New Issue
Block a user