Merge pull request #2067 from vector-im/feature/contact_crash

Android 6: App crash when read Contact permission is granted (#2064)
This commit is contained in:
Benoit Marty 2020-09-08 08:46:27 +02:00 committed by GitHub
commit 3755d866b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 3 deletions

View file

@ -26,6 +26,7 @@ Bugfix 🐛:
- Login with Matrix-Id | Autodiscovery fails if identity server is invalid and Homeserver ok (#2027)
- Support for image compression on Android 10
- Verification popup won't show
- Android 6: App crash when read Contact permission is granted (#2064)
Translations 🗣:
- The SDK is now using SAS string translations from [Weblate Matrix-doc project](https://translate.riot.im/projects/matrix-doc/) (#1909)

View file

@ -84,6 +84,7 @@ import im.vector.app.receivers.DebugReceiver
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import org.matrix.android.sdk.api.extensions.tryThis
import org.matrix.android.sdk.api.failure.GlobalError
import timber.log.Timber
import kotlin.system.measureTimeMillis
@ -345,6 +346,28 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
}
}
private val postResumeScheduledActions = mutableListOf<() -> Unit>()
/**
* Schedule action to be done in the next call of onPostResume()
* It fixes bug observed on Android 6 (API 23)
*/
protected fun doOnPostResume(action: () -> Unit) {
synchronized(postResumeScheduledActions) {
postResumeScheduledActions.add(action)
}
}
override fun onPostResume() {
super.onPostResume()
synchronized(postResumeScheduledActions) {
postResumeScheduledActions.forEach {
tryThis { it.invoke() }
}
postResumeScheduledActions.clear()
}
}
override fun onPause() {
super.onPause()
Timber.i("onPause Activity ${this.javaClass.simpleName}")

View file

@ -113,7 +113,7 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
if (allGranted(grantResults)) {
if (requestCode == PERMISSION_REQUEST_CODE_READ_CONTACTS) {
addFragmentToBackstack(R.id.container, ContactsBookFragment::class.java)
doOnPostResume { addFragmentToBackstack(R.id.container, ContactsBookFragment::class.java) }
}
}
}

View file

@ -45,9 +45,9 @@ import im.vector.app.features.userdirectory.UserDirectoryFragment
import im.vector.app.features.userdirectory.UserDirectorySharedAction
import im.vector.app.features.userdirectory.UserDirectorySharedActionViewModel
import im.vector.app.features.userdirectory.UserDirectoryViewModel
import org.matrix.android.sdk.api.failure.Failure
import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.activity.*
import org.matrix.android.sdk.api.failure.Failure
import java.net.HttpURLConnection
import javax.inject.Inject
@ -114,7 +114,7 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() {
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
if (allGranted(grantResults)) {
if (requestCode == PERMISSION_REQUEST_CODE_READ_CONTACTS) {
addFragmentToBackstack(R.id.container, ContactsBookFragment::class.java)
doOnPostResume { addFragmentToBackstack(R.id.container, ContactsBookFragment::class.java) }
}
}
}