From e358ae77053a2a59f55f1f76f4efe183769da9b7 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Mon, 18 Nov 2024 11:41:31 +1100 Subject: [PATCH 1/4] Fixing crashes and ANRs seen in 1.20.4 (and older) --- .../org/thoughtcrime/securesms/ShareActivity.java | 11 ++++++++++- .../conversation/v2/ConversationViewModel.kt | 8 +++++--- .../messagerequests/MessageRequestsActivity.kt | 4 ++-- .../securesms/preferences/ClearAllDataDialog.kt | 13 ++++++++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ShareActivity.java b/app/src/main/java/org/thoughtcrime/securesms/ShareActivity.java index 3b939bf647..c2c3b38b29 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ShareActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ShareActivity.java @@ -82,6 +82,8 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity private String mimeType; private boolean isPassingAlongMedia; + private ResolveMediaTask resolveTask; + @Override protected void onCreate(Bundle icicle, boolean ready) { if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) { @@ -190,7 +192,8 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity } else { contactsFragment.getView().setVisibility(View.GONE); progressWheel.setVisibility(View.VISIBLE); - new ResolveMediaTask(context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, streamExtra); + resolveTask = new ResolveMediaTask(context); + resolveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, streamExtra); } } @@ -262,6 +265,12 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity public void onContactDeselected(String number) { } + @Override + protected void onDestroy() { + super.onDestroy(); + if (resolveTask != null) resolveTask.cancel(true); + } + @SuppressLint("StaticFieldLeak") private class ResolveMediaTask extends AsyncTask { private final Context context; diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt index 5ecddd2147..32e1dcff41 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt @@ -169,9 +169,11 @@ class ConversationViewModel( communityWriteAccessJob = viewModelScope.launch { OpenGroupManager.getCommunitiesWriteAccessFlow() .map { - if(openGroup?.groupId != null) - it[openGroup?.groupId] - else null + withContext(Dispatchers.Default) { + if (openGroup?.groupId != null) + it[openGroup?.groupId] + else null + } } .filterNotNull() .collect{ diff --git a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt index e27345afc7..d75c5b7978 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt @@ -37,7 +37,7 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat private val viewModel: MessageRequestsViewModel by viewModels() private val adapter: MessageRequestsAdapter by lazy { - MessageRequestsAdapter(context = this, cursor = threadDb.unapprovedConversationList, listener = this) + MessageRequestsAdapter(context = this, cursor = null, listener = this) } override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) { @@ -114,7 +114,7 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat } private fun updateEmptyState() { - val threadCount = (binding.recyclerView.adapter as MessageRequestsAdapter).itemCount + val threadCount = adapter.itemCount binding.emptyStateContainer.isVisible = threadCount == 0 binding.clearAllMessageRequestsButton.isVisible = threadCount != 0 } diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt index 98ad62dcb3..80f45b1db3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/ClearAllDataDialog.kt @@ -127,7 +127,7 @@ class ClearAllDataDialog : DialogFragment() { ApplicationContext.getInstance(context).clearAllDataAndRestart().let { success -> withContext(Main) { if (success) { - dismiss() + dismissAllowingStateLoss() } else { Toast.makeText(ApplicationContext.getInstance(requireContext()), R.string.errorUnknown, Toast.LENGTH_LONG).show() } @@ -161,8 +161,15 @@ class ClearAllDataDialog : DialogFragment() { } else if (deletionResultMap.values.all { it }) { // ..otherwise if the network data deletion was successful proceed to delete the local data as well. - ApplicationContext.getInstance(context).clearAllDataAndRestart() - withContext(Main) { dismiss() } + ApplicationContext.getInstance(context).clearAllDataAndRestart().let { success -> + withContext(Main) { + if (success) { + dismissAllowingStateLoss() + } else { + Toast.makeText(ApplicationContext.getInstance(requireContext()), R.string.errorUnknown, Toast.LENGTH_LONG).show() + } + } + } } } } From 120659120c5ff5c6bb3ceeab3fc69182e501d2d4 Mon Sep 17 00:00:00 2001 From: SessionHero01 <180888785+SessionHero01@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:43:45 +1100 Subject: [PATCH 2/4] Check if columns exist before migration --- .../database/helpers/SQLCipherOpenHelper.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index 5bc8c58ba4..1eae623dad 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -630,8 +630,17 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { } if (oldVersion < lokiV47) { - db.execSQL(SmsDatabase.ADD_IS_DELETED_COLUMN); - db.execSQL(MmsDatabase.ADD_IS_DELETED_COLUMN); + // Ideally we shouldn't need to check if the column exists, but somehow we get + // "duplicated column" from play store crashes. + // If you are keen you can investigate + // deep into this but for now, we will just check if the column exists before adding it. + if (!columnExists(db, SmsDatabase.TABLE_NAME, SmsDatabase.IS_DELETED)) { + db.execSQL(SmsDatabase.ADD_IS_DELETED_COLUMN); + } + + if (!columnExists(db, MmsDatabase.TABLE_NAME, MmsDatabase.IS_DELETED)) { + db.execSQL(MmsDatabase.ADD_IS_DELETED_COLUMN); + } } db.setTransactionSuccessful(); From 4d0db2ac6ebea90c2b3dfb4e36d8bf3645f8a718 Mon Sep 17 00:00:00 2001 From: SessionHero01 <180888785+SessionHero01@users.noreply.github.com> Date: Mon, 18 Nov 2024 00:45:52 +0000 Subject: [PATCH 3/4] Update script to take non-existence build folder into account --- scripts/build-and-release.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/build-and-release.py b/scripts/build-and-release.py index ff4100a591..c1941343e6 100755 --- a/scripts/build-and-release.py +++ b/scripts/build-and-release.py @@ -40,7 +40,7 @@ class BuildCredentials: self.key_password = credentials['key_password'] def build_releases(project_root: str, flavor: str, credentials_property_prefix: str, credentials: BuildCredentials, huawei: bool=False) -> BuildResult: - (keystore_fd, keystore_file) = tempfile.mkstemp(prefix='keystore_', suffix='.jks', dir=os.path.join(project_root, 'build')) + (keystore_fd, keystore_file) = tempfile.mkstemp(prefix='keystore_', suffix='.jks', dir=build_dir) try: with os.fdopen(keystore_fd, 'wb') as f: f.write(base64.b64decode(credentials.keystore_b64)) @@ -82,8 +82,9 @@ def build_releases(project_root: str, flavor: str, credentials_property_prefix: project_root = os.path.dirname(sys.path[0]) +build_dir = os.path.join(project_root, 'build') credentials_file_path = os.path.join(project_root, 'release-creds.toml') -fdroid_repo_path = os.path.join(project_root, 'build/fdroidrepo') +fdroid_repo_path = os.path.join(build_dir, 'fdroidrepo') def detect_android_sdk() -> str: sdk_dir = os.environ.get('ANDROID_HOME') @@ -102,11 +103,11 @@ def update_fdroid(build: BuildResult, fdroid_workspace: str, creds: BuildCredent # Check if there's a git repo at the fdroid repo path by running git status try: subprocess.check_call(f'git -C {fdroid_repo_path} status', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - subprocess.check_call(f'git fetch', shell=True, cwd=fdroid_workspace) + subprocess.check_call(f'git fetch --depth=1', shell=True, cwd=fdroid_workspace) print(f'Found fdroid git repo at {fdroid_repo_path}') except subprocess.CalledProcessError: print(f'No fdroid git repo found at {fdroid_repo_path}. Cloning using gh.') - subprocess.run(f'gh repo clone session-foundation/session-fdroid {fdroid_repo_path} -- --depth=1', shell=True, check=True) + subprocess.run(f'gh repo clone session-foundation/session-fdroid {fdroid_repo_path} -- -b master --depth=1', shell=True, check=True) # Create a branch for the release print(f'Creating a branch for the fdroid release: {build.version_name}') @@ -162,7 +163,7 @@ def update_fdroid(build: BuildResult, fdroid_workspace: str, creds: BuildCredent with open(metadata_file, 'w') as file: file.write(metadata_contents) - [keystore_fd, keystore_path] = tempfile.mkstemp(prefix='fdroid_keystore_', suffix='.p12', dir=os.path.join(project_root, 'build')) + [keystore_fd, keystore_path] = tempfile.mkstemp(prefix='fdroid_keystore_', suffix='.p12', dir=build_dir) config_file_path = os.path.join(fdroid_workspace, 'config.yml') try: @@ -207,6 +208,7 @@ def update_fdroid(build: BuildResult, fdroid_workspace: str, creds: BuildCredent subprocess.run(f'''\ gh pr create --base master \ --title "Release {build.version_name}" \ + -R session-foundation/session-fdroid \ --body "This is an automated release preparation for Release {build.version_name}. Human beings are still required to approve and merge this PR."\ ''', shell=True, check=True, cwd=fdroid_workspace) @@ -224,6 +226,9 @@ if not os.path.isfile(credentials_file_path): with open(credentials_file_path, 'rb') as f: credentials = tomllib.load(f) +# Make sure build folder exists +if not os.path.isdir(build_dir): + os.makedirs(build_dir) print("Building play releases...") play_build_result = build_releases( From d447371a11a88fa38f9e3fcdf645883b638c68a1 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Mon, 18 Nov 2024 11:49:07 +1100 Subject: [PATCH 4/4] 1.20.5 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 20cda8b583..030bac589f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ configurations.forEach { it.exclude module: "commons-logging" } -def canonicalVersionCode = 386 -def canonicalVersionName = "1.20.4" +def canonicalVersionCode = 387 +def canonicalVersionName = "1.20.5" def postFixSize = 10 def abiPostFix = ['armeabi-v7a' : 1,