Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3800: Mitigate indefinite crashes due to an initial crash or process death in low memory cases #3860

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
919ab2b
Add support for AABs, build flavors, and proguard.
BenHenning Sep 1, 2021
c31b07b
Merge branch 'develop' into add-bundles-proguard-build-flavors
BenHenning Sep 1, 2021
ceb1179
Lint & codeowner fixes.
BenHenning Sep 1, 2021
cbe5e76
Fix failures.
BenHenning Sep 1, 2021
d7945d5
Different attempt to fix bad develop reference in CI.
BenHenning Sep 1, 2021
366ab4d
Initial commit.
BenHenning Sep 1, 2021
c38b95c
Merge branch 'develop' into introduce-test-batching
BenHenning Sep 1, 2021
ac73dd6
Introduce infrastructure for batching.
BenHenning Sep 2, 2021
3aec233
Add bucketing strategy.
BenHenning Sep 2, 2021
650570b
Fix caching & stabilize builds.
BenHenning Sep 2, 2021
d66bb2c
Increase sharding & add randomization.
BenHenning Sep 2, 2021
3969a6d
Improving partitionin & readability.
BenHenning Sep 2, 2021
e7b2a0d
Add new tests & fix static analysis errors.
BenHenning Sep 2, 2021
d1da067
Fix script.
BenHenning Sep 2, 2021
fbb3838
Fix broken tests & test configuration.
BenHenning Sep 2, 2021
e9cb61b
Merge branch 'introduce-test-batching' into add-bundles-proguard-buil…
BenHenning Sep 2, 2021
601ff0a
Merge branch 'add-bundles-proguard-build-flavors' of github.com:oppia…
BenHenning Sep 2, 2021
6c91da9
Fix mistake from earlier commit.
BenHenning Sep 2, 2021
e3eb6f2
Try 10 max parallel actions instead.
BenHenning Sep 2, 2021
3ff775f
Merge branch 'introduce-test-batching' into add-bundles-proguard-buil…
BenHenning Sep 2, 2021
62576a1
Fix another error from an earlier commit.
BenHenning Sep 2, 2021
d4f4448
Merge branch 'introduce-test-batching' into add-bundles-proguard-buil…
BenHenning Sep 2, 2021
0644f70
Localisation updates from https://translatewiki.net.
translatewiki Sep 2, 2021
f2a412d
Fix mv command so it works on Linux & OSX.
BenHenning Sep 2, 2021
aa29739
Merge branch 'translatewiki-prs' into temp-branch-combine-prework-and…
BenHenning Sep 2, 2021
c8248ca
Introduce initial domain layer for translations.
BenHenning Sep 4, 2021
512f0b3
Initial app layer implementation for translations.
BenHenning Sep 8, 2021
6b8298d
Domain changes needed per downstream UI changes.
BenHenning Sep 8, 2021
2aa4470
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 8, 2021
014ac54
Add patterns & fixes.
BenHenning Sep 10, 2021
583a05c
Add needed domain changes for downstream branch.
BenHenning Sep 10, 2021
ceb66d9
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 10, 2021
b4915d1
Merge commit '0c98a6cc1688c3a96bed67246ebd429e79077479' into introduc…
BenHenning Sep 10, 2021
385ad6a
Merge branch 'introduce-test-batching' into add-bundles-proguard-buil…
BenHenning Sep 10, 2021
7160477
Merge branch 'develop' into add-bundles-proguard-build-flavors
BenHenning Sep 10, 2021
7b4b282
Introduce support for content localization.
BenHenning Sep 14, 2021
2f7dc24
Fix structures to work with parsing assumptions.
BenHenning Sep 14, 2021
3f92b84
Fix regex checks for translated strings.
BenHenning Sep 14, 2021
96f31ed
Merge branch 'develop' into fix-regex-checks-for-translated-strings
BenHenning Sep 14, 2021
99130f0
Lint-ish fix.
BenHenning Sep 14, 2021
b48cca6
Merge commit '92ce46b81b2183283e04c4d592fc8682338e1404' into add-bund…
BenHenning Sep 14, 2021
3fcc1e5
Merge branch 'add-bundles-proguard-build-flavors' into temp-branch-co…
BenHenning Sep 14, 2021
060c37e
Merge branch 'fix-regex-checks-for-translated-strings' into temp-bran…
BenHenning Sep 14, 2021
6d556fb
Fix failing regex checks.
BenHenning Sep 14, 2021
abb2164
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 14, 2021
4a266ba
Add check for nested res subdirectories.
BenHenning Sep 14, 2021
2ef0ea7
Add remaining regex patterns & fixes.
BenHenning Sep 15, 2021
3746880
Clean up locale infra.
BenHenning Sep 15, 2021
cb80423
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 15, 2021
fafe5c3
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 15, 2021
68f6c1d
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 15, 2021
1021a89
Merge commit '2d47a87b9020b95355e86e96254b1ad68f3843b2' into fix-rege…
BenHenning Sep 15, 2021
e58e422
Merge branch 'fix-regex-checks-for-translated-strings' into temp-bran…
BenHenning Sep 15, 2021
2ad1f41
Attempt to delete strings to force history.
BenHenning Sep 15, 2021
c0f8b45
Merge branch 'develop' into temp-branch-combine-prework-and-translations
BenHenning Sep 15, 2021
87f84a8
Merge branch 'temp-branch-combine-prework-and-translations' into loca…
BenHenning Sep 15, 2021
ebe2262
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 15, 2021
d863e20
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 15, 2021
b266b0c
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 15, 2021
b168091
Gate options behind compile-time flag.
BenHenning Sep 15, 2021
b1de8ed
Proguard fixes for Glide.
BenHenning Sep 15, 2021
f059838
Make AAB builds/runs manual-only targets.
BenHenning Sep 15, 2021
85e7574
Fix broken tests.
BenHenning Sep 15, 2021
7a9d952
Fix lint issues & add KDocs.
BenHenning Sep 16, 2021
4348fb1
Add 6/11 test suites (& placeholders for other 4).
BenHenning Sep 17, 2021
e8afb60
Add more test suites for domain layers.
BenHenning Sep 18, 2021
08a8219
Introduce wrapper & fake for bidi wrapping.
BenHenning Sep 20, 2021
0112762
Add remaining tests.
BenHenning Sep 20, 2021
2015e8e
Fix Gradle builds.
BenHenning Sep 21, 2021
2acb592
Lint fixes.
BenHenning Sep 21, 2021
0238557
Merge branch 'develop' into localization-part4-introduce-controller-a…
BenHenning Sep 21, 2021
826545a
Resolve remaining incomplete TODOs.
BenHenning Sep 21, 2021
703f770
Add new codeowners.
BenHenning Sep 21, 2021
2cc7c07
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 21, 2021
db3a3a8
Post-merge fixes.
BenHenning Sep 21, 2021
d667639
Fix most test targets (builds).
BenHenning Sep 21, 2021
267c6d6
Fix all remaining test builds.
BenHenning Sep 22, 2021
670c5e8
Fix all app layer tests.
BenHenning Sep 22, 2021
cccd1b4
Fix questions & profile issues.
BenHenning Sep 22, 2021
ee88628
Type specifier pattern & fixes.
BenHenning Sep 22, 2021
07b7823
Add missing KDocs.
BenHenning Sep 23, 2021
8ad41f3
Boilerplate & TODOs for needed tests.
BenHenning Sep 23, 2021
f876784
Add new needed test dep.
BenHenning Sep 23, 2021
180bd52
Add needed testing coverage.
BenHenning Sep 24, 2021
e879c04
Two fixes.
BenHenning Sep 24, 2021
326d5d9
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 24, 2021
86a50b7
Fix Gradle builds on branch.
BenHenning Sep 25, 2021
afb80e5
Resolve nearly all pending TODOs.
BenHenning Sep 25, 2021
970d561
Lint fixes.
BenHenning Sep 25, 2021
271fbd9
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 25, 2021
f17f479
Re-add method removed from merge.
BenHenning Sep 25, 2021
3b65ce3
Lint fixes.
BenHenning Sep 25, 2021
20e0d5e
Fix compute affected tests script.
BenHenning Sep 25, 2021
b7f63c3
Fix failures found on CI.
BenHenning Sep 26, 2021
3a85c49
Merge branch 'develop' into localization-part4-introduce-controller-a…
BenHenning Sep 26, 2021
0fa47f7
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 26, 2021
d37cdd2
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 26, 2021
74593a8
Fix remaining Gradle failures found in CI.
BenHenning Sep 26, 2021
5c37975
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 26, 2021
d7e39f9
Fix existing domain + app layer tests.
BenHenning Sep 27, 2021
51fb398
Merge branch 'develop' into localization-part4-introduce-controller-a…
BenHenning Sep 27, 2021
e66c24d
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 27, 2021
ce9446f
Post-merge fix.
BenHenning Sep 27, 2021
3de427e
Gradle Espresso test fix.
BenHenning Sep 27, 2021
d7cf31a
Merge branch 'develop' into localization-part4-introduce-controller-a…
BenHenning Sep 27, 2021
37e852f
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 27, 2021
dd11beb
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 27, 2021
c84b19e
Add missing KDocs, remove extra file, and other cleanups.
BenHenning Sep 27, 2021
a3c167b
Lint fixes.
BenHenning Sep 27, 2021
6c97de0
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 27, 2021
f240bf6
Fix CI & lint checks (except regex).
BenHenning Sep 27, 2021
eec5a9f
Deflake DataProviderTestMonitorTest.
BenHenning Sep 27, 2021
44f47b6
Address reviewer comments.
BenHenning Sep 27, 2021
085fa41
Merge branch 'develop' into localization-part5-introduce-app-string-t…
BenHenning Sep 27, 2021
2377ee5
Lint fixes.
BenHenning Sep 27, 2021
ec58dce
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 27, 2021
5a89f05
Fix affected tests from earlier changes.
BenHenning Sep 27, 2021
6748464
Fix remaining Gradle failures.
BenHenning Sep 28, 2021
700dfb1
Add placeholders for new needed tests.
BenHenning Sep 28, 2021
a1b0fb0
Fix broken tests.
BenHenning Sep 28, 2021
cb8b797
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 28, 2021
1e7c3c9
Add needed tests for new behaviors.
BenHenning Sep 29, 2021
b21525a
Fix Gradle build & mechanism change failures.
BenHenning Sep 29, 2021
171a1b8
Lint fixes.
BenHenning Sep 29, 2021
13ad6d5
Merge commit '3a0afb4eb8222d4ff3acd2e2e660b85911d35229' into localiza…
BenHenning Sep 29, 2021
0459300
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 29, 2021
c97b61a
Merge branch 'develop' into localization-part6-introduce-content-and-…
BenHenning Sep 29, 2021
4a3d53b
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 29, 2021
7af6cc1
Undo inadvertent change to Gradle jvmargs.
BenHenning Sep 29, 2021
d108d95
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 29, 2021
e20b742
Disable most tests on Espresso.
BenHenning Sep 29, 2021
8448350
Test fixes + make monitor Espresso-compatible.
BenHenning Sep 30, 2021
cd73e07
Fix broken tests.
BenHenning Sep 30, 2021
261adbb
Add exemptions & regex check tests.
BenHenning Sep 30, 2021
6d07512
Lint fixes.
BenHenning Sep 30, 2021
48ef103
Lint fixes.
BenHenning Sep 30, 2021
00bc30c
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 30, 2021
11bb929
Add new ratio input rule classifier.
BenHenning Sep 30, 2021
d99392c
Fix broken tests (per CI).
BenHenning Sep 30, 2021
69ff8e8
Merge branch 'localization-part7-add-gate-for-selecting-written-langu…
BenHenning Sep 30, 2021
8c7874a
Add mechanism to recover from crashes.
BenHenning Sep 30, 2021
6b735d8
Remove malformed TODO.
BenHenning Sep 30, 2021
612e17d
Merge branch 'develop' into localization-part6-introduce-content-and-…
BenHenning Oct 6, 2021
93e68ac
Merge branch 'develop' into localization-part6-introduce-content-and-…
BenHenning Oct 6, 2021
81ec28f
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Oct 6, 2021
9373da8
Merge branch 'develop' into localization-part7-add-gate-for-selecting…
BenHenning Oct 6, 2021
e405132
Merge branch 'localization-part7-add-gate-for-selecting-written-langu…
BenHenning Oct 6, 2021
8d5f5d9
Merge commit '5daaa9ec634a1c6c8356873d9971a0aaa9908abc' into localiza…
BenHenning Oct 7, 2021
49501e9
Merge branch 'localization-part8-add-support-for-new-ratio-classifier…
BenHenning Oct 7, 2021
83ad592
Merge branch 'develop' into localization-part9-add-mechanism-to-recov…
BenHenning Oct 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ class AppLanguageLocaleHandler @Inject constructor(
) {
private lateinit var displayLocale: OppiaLocale.DisplayLocale

/**
* Returns whether this handler's tracked locale has been initialized, that is, whether
* [initializeLocale] has been called.
*
* Once this method returns true, it's guaranteed to stay true for the lifetime of this class.
*/
fun isInitialized(): Boolean = ::displayLocale.isInitialized

/**
* Initializes this handler with the specified initial [OppiaLocale.DisplayLocale].
*
* This must be called before any other methods in this class, and it must only be called once for
* the lifetime of the application.
*/
fun initializeLocale(locale: OppiaLocale.DisplayLocale) {
check(!::displayLocale.isInitialized) {
check(!isInitialized()) {
"Expected to initialize the locale for the first time. If this is in a test, did you use" +
" InitializeDefaultLocaleRule?"
}
Expand Down Expand Up @@ -70,7 +78,7 @@ class AppLanguageLocaleHandler @Inject constructor(
}

private fun verifyDisplayLocaleIsInitialized() {
check(::displayLocale.isInitialized) {
check(isInitialized()) {
"Expected locale to be initialized. If this is in a test, did you remember to include" +
" InitializeDefaultLocaleRule?"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.translation
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import org.oppia.android.app.model.ProfileId
import org.oppia.android.domain.locale.LocaleController
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.data.AsyncResult
Expand All @@ -20,14 +21,46 @@ class AppLanguageWatcherMixin @Inject constructor(
private val activity: AppCompatActivity,
private val translationController: TranslationController,
private val appLanguageLocaleHandler: AppLanguageLocaleHandler,
private val localeController: LocaleController,
private val oppiaLogger: OppiaLogger,
private val activityRecreator: ActivityRecreator
) {
/**
* Initializes this mixin by starting language monitoring. This method should only ever be called
* once for the lifetime of the current activity.
*
* Note that this method will synchronously ensure that [AppLanguageLocaleHandler] is properly
* initialized if previous bootstrapping was lost (e.g. due to process death), so it must be
* called before interacting with the locale handler to avoid inadvertent crashes in such
* situations.
*/
fun initialize() {
if (!appLanguageLocaleHandler.isInitialized()) {
/* The handler might have been de-initialized since bootstrapping. This can generally happen
* in two cases:
* 1. Upon crash (later versions of Android will reopen the previous activity rather than
* starting from the launcher activity if the crash occurred with the app in the foreground)
* 2. Upon low-memory process death (the system will restore from a saved instance Bundle of
* the application's activity stack)
*
* In both cases, the locale will be lost & can't be determined until the controller provides
* the state. Since initialization happens during activity initialization, there's no way to
* pass data from a previous instance of the application. Thus, the application can either
* block the main thread on waiting for the data provider result (a strict mode violation that
* could theoretically cause an ANR) or default the locale and, in the event the default is
* wrong, restart the activity after the correct locale is retrieved. For the sake of avoiding
* potential ANRs (even at the potential of perceived jank due to activity recreations), the
* latter option is used here.
*/
oppiaLogger.e(
"AppLanguageWatcherMixin", "Restoring the display locale from de-initialization."
)
val defaultDisplayLocale = localeController.reconstituteDisplayLocale(
localeController.getLikelyDefaultAppStringLocaleContext()
)
appLanguageLocaleHandler.initializeLocale(defaultDisplayLocale)
}

// TODO(#52): Hook this up properly to profiles, and handle the non-profile activity cases.
val profileId = ProfileId.getDefaultInstance()
val appLanguageLocaleDataProvider = translationController.getAppLanguageLocale(profileId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,36 @@ class AppLanguageLocaleHandlerTest {
assertThat(locales[0].language).isEqualTo("en")
}

@Test
fun testIsInitialized_initialState_returnsFalse() {
val isInitialized = appLanguageLocaleHandler.isInitialized()

// initializeLocale() hasn't yet been called.
assertThat(isInitialized).isFalse()
}

@Test
fun testIsInitialized_afterInitialization_returnsTrue() {
setAppLanguage(ENGLISH)
appLanguageLocaleHandler.initializeLocale(retrieveAppLanguageLocale())

val isInitialized = appLanguageLocaleHandler.isInitialized()

// The handler should now (& hereafter) be initialized.
assertThat(isInitialized).isTrue()
}

@Test
fun testIsInitialized_afterInitialization_andUpdate_returnsTrue() {
appLanguageLocaleHandler.initializeLocale(computeNewAppLanguageLocale(ENGLISH))
appLanguageLocaleHandler.updateLocale(computeNewAppLanguageLocale(BRAZILIAN_PORTUGUESE))

val isInitialized = appLanguageLocaleHandler.isInitialized()

// Updating the locale should keep the handler initialized.
assertThat(isInitialized).isTrue()
}

private fun forceDefaultLocale(locale: Locale) {
context.applicationContext.resources.configuration.setLocale(locale)
Locale.setDefault(locale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class AppLanguageWatcherMixinTest {
// TODO(#1720): Similar to the above, also add a test to verify that multiple language changes
// does not result in multiple recreations for the same activity. It currently will in the test
// since two mixins are active, but that won't happen in reality.
// TODO(#1720): Similar to the above, also add 2 tests to verify that mixin initialization in
// cases when the locale isn't initialized (such as process death) prints an error & default
// initializes the locale handler.

@get:Rule
val initializeDefaultLocaleRule = InitializeDefaultLocaleRule()
Expand Down