Skip to content

Commit a9122f5

Browse files
fix ze crashes
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 3fe42f6 commit a9122f5

5 files changed

Lines changed: 37 additions & 45 deletions

File tree

app/src/main/java/com/fox2code/mmm/MainActivity.kt

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,15 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
130130
// check if this build has expired
131131
val buildTime = Timestamp(BuildConfig.BUILD_TIME)
132132
// if the build time is more than 30 days ago, throw an exception
133-
check(ts.time < buildTime.time) { "This build has expired. Please download a stable build or update to the latest version." }
133+
if (BuildConfig.DEBUG) {
134+
check(ts.time < buildTime.time) { getString(R.string.build_expired) }
135+
} else {
136+
// non-debug builds expire after 1 year but only show a toast
137+
val ts2 = Timestamp(System.currentTimeMillis() - 365L * 24 * 60 * 60 * 1000)
138+
if (ts2.time > buildTime.time) {
139+
Toast.makeText(this, R.string.build_expired, Toast.LENGTH_LONG).show()
140+
}
141+
}
134142
setContentView(R.layout.activity_main)
135143
this.setTitle(R.string.app_name)
136144
// set window flags to ignore status bar
@@ -245,6 +253,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
245253
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
246254
finish()
247255
}
256+
248257
R.id.online_menu_item -> {
249258
TrackHelper.track().event("view_list", "online_modules")
250259
.with(MainApplication.INSTANCE!!.tracker)
@@ -262,6 +271,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
262271
searchView.setQuery("", false)
263272
searchView.clearFocus()
264273
}
274+
265275
R.id.installed_menu_item -> {
266276
TrackHelper.track().event("view_list", "installed_modules")
267277
.with(MainApplication.INSTANCE!!.tracker)
@@ -377,13 +387,11 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
377387
RepoManager.getINSTANCE().update { value: Double ->
378388
runOnUiThread(if (max == 0) Runnable {
379389
progressIndicator.setProgressCompat(
380-
(value * PRECISION).toInt(),
381-
true
390+
(value * PRECISION).toInt(), true
382391
)
383392
} else Runnable {
384393
progressIndicator.setProgressCompat(
385-
(value * PRECISION * 0.75f).toInt(),
386-
true
394+
(value * PRECISION * 0.75f).toInt(), true
387395
)
388396
})
389397
}
@@ -597,8 +605,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
597605
RepoManager.getINSTANCE().update { value: Double ->
598606
runOnUiThread {
599607
progressIndicator!!.setProgressCompat(
600-
(value * PRECISION).toInt(),
601-
true
608+
(value * PRECISION).toInt(), true
602609
)
603610
}
604611
}
@@ -639,13 +646,11 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
639646
RepoManager.getINSTANCE().update { value: Double ->
640647
runOnUiThread(if (max == 0) Runnable {
641648
progressIndicator!!.setProgressCompat(
642-
(value * PRECISION).toInt(),
643-
true
649+
(value * PRECISION).toInt(), true
644650
)
645651
} else Runnable {
646652
progressIndicator!!.setProgressCompat(
647-
(value * PRECISION * 0.75f).toInt(),
648-
true
653+
(value * PRECISION * 0.75f).toInt(), true
649654
)
650655
})
651656
}
@@ -716,8 +721,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
716721
Timber.i("Query submit: %s on online list", query)
717722
Thread({
718723
moduleViewListBuilderOnline.applyTo(
719-
moduleListOnline!!,
720-
moduleViewAdapterOnline!!
724+
moduleListOnline!!, moduleViewAdapterOnline!!
721725
)
722726
}, "Query update thread").start()
723727
}
@@ -739,8 +743,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
739743
Timber.i("Query submit: %s on online list", query)
740744
Thread({
741745
moduleViewListBuilderOnline.applyTo(
742-
moduleListOnline!!,
743-
moduleViewAdapterOnline!!
746+
moduleListOnline!!, moduleViewAdapterOnline!!
744747
)
745748
}, "Query update thread").start()
746749
}
@@ -759,8 +762,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
759762
if (moduleViewListBuilderOnline.setQueryChange(null)) {
760763
Thread({
761764
moduleViewListBuilderOnline.applyTo(
762-
moduleListOnline!!,
763-
moduleViewAdapterOnline!!
765+
moduleListOnline!!, moduleViewAdapterOnline!!
764766
)
765767
}, "Query update thread").start()
766768
}
@@ -789,9 +791,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
789791
}
790792
i++
791793
}
792-
if (AndroidacyRepoData.getInstance()
793-
.isEnabled && AndroidacyRepoData.getInstance().memberLevel == null
794-
) {
794+
if (AndroidacyRepoData.getInstance().isEnabled && AndroidacyRepoData.getInstance().memberLevel == null) {
795795
Timber.d("Member level is null, waiting for it to be initialized")
796796
i = 0
797797
while (AndroidacyRepoData.getInstance().memberLevel == null && i < 20) {
@@ -804,14 +804,10 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
804804
}
805805
}
806806
// if it's still null, but it's enabled, throw an error
807-
if (AndroidacyRepoData.getInstance()
808-
.isEnabled && AndroidacyRepoData.getInstance().memberLevel == null
809-
) {
807+
if (AndroidacyRepoData.getInstance().isEnabled && AndroidacyRepoData.getInstance().memberLevel == null) {
810808
Timber.e("AndroidacyRepoData is enabled, but member level is null")
811809
}
812-
if (AndroidacyRepoData.getInstance() != null && AndroidacyRepoData.getInstance()
813-
.isEnabled && AndroidacyRepoData.getInstance().memberLevel == "Guest"
814-
) {
810+
if (AndroidacyRepoData.getInstance() != null && AndroidacyRepoData.getInstance().isEnabled && AndroidacyRepoData.getInstance().memberLevel == "Guest") {
815811
runtimeUtils!!.showUpgradeSnackbar(this, this)
816812
} else {
817813
if (!AndroidacyRepoData.getInstance().isEnabled) {
@@ -825,9 +821,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
825821
Timber.i("Unknown error, not showing upgrade snackbar 1")
826822
}
827823
}
828-
} else if (AndroidacyRepoData.getInstance()
829-
.isEnabled && AndroidacyRepoData.getInstance().memberLevel == "Guest"
830-
) {
824+
} else if (AndroidacyRepoData.getInstance().isEnabled && AndroidacyRepoData.getInstance().memberLevel == "Guest") {
831825
runtimeUtils!!.showUpgradeSnackbar(this, this)
832826
} else {
833827
if (!AndroidacyRepoData.getInstance().isEnabled) {
@@ -853,6 +847,7 @@ class MainActivity : FoxActivity(), OnRefreshListener, SearchView.OnQueryTextLis
853847
}
854848

855849
private const val PRECISION = 10000
850+
856851
@JvmField
857852
var doSetupNowRunning = true
858853
var doSetupRestarting = false

app/src/main/java/com/fox2code/mmm/MainApplication.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class MainApplication : FoxApplication(), Configuration.Provider {
8787
private var markwonThemeContext: FoxThemeWrapper? = null
8888
@JvmField
8989
var markwon: Markwon? = null
90-
private var existingKey: ByteArray? = byteArrayOf(0)
90+
private var existingKey: ByteArray? = null
9191
@JvmField
9292
var tracker: Tracker? = null
9393
private var makingNewKey = false
@@ -450,7 +450,7 @@ class MainApplication : FoxApplication(), Configuration.Provider {
450450
}
451451
}
452452
// attempt to read the existingKey property
453-
if (existingKey != null) {
453+
if (existingKey != null && existingKey!!.isNotEmpty()) {
454454
return existingKey as ByteArray
455455
}
456456
// check if we have a key already
@@ -563,14 +563,17 @@ class MainApplication : FoxApplication(), Configuration.Provider {
563563
).apply()
564564
Timber.d("Saved the encrypted key in shared preferences.")
565565
makingNewKey = false
566+
Timber.d("Returning the new key. Key length: %d", realmKey.size)
566567
return realmKey // pass to a realm configuration via encryptionKey()
567568
}
568569

569570
// Access the encrypted key in the keystore, decrypt it with the secret,
570571
// and use it to open and read from the realm again
571572
fun getExistingKey(): ByteArray {
573+
Timber.v("Getting existing key.")
572574
// attempt to read the existingKey property
573575
if (existingKey != null) {
576+
Timber.v("Existing key found in memory.")
574577
return existingKey as ByteArray
575578
}
576579
// open a connection to the android keystore

app/src/main/java/com/fox2code/mmm/utils/io/PropUtils.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ enum class PropUtils {
127127
).use { bufferedReader ->
128128
var line: String
129129
var lineNum = 0
130-
while (bufferedReader.readLine().also { line = it } != null) {
130+
val iterator = bufferedReader.lineSequence().iterator()
131+
while (iterator.hasNext()) {
132+
line = iterator.next()
131133
if (lineNum == 0 && line.startsWith("\u0000")) {
132134
while (line.startsWith("\u0000")) line = line.substring(1)
133135
}

app/src/main/res/layout/activity_setup.xml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -282,28 +282,18 @@
282282
android:layout_height="wrap_content"
283283
android:layout_marginHorizontal="4dp"
284284
android:layout_marginVertical="12dp"
285-
android:text="@string/other_section"
285+
android:text="@string/eula_agree_v2_headline"
286286
android:textAppearance="@android:style/TextAppearance.Material.Headline" />
287287

288-
<com.google.android.material.materialswitch.MaterialSwitch
288+
<com.google.android.material.checkbox.MaterialCheckBox
289289
android:layout_width="match_parent"
290290
android:layout_height="wrap_content"
291291
android:checked="false"
292292
android:id="@+id/setup_agree_eula"
293293
android:layout_marginHorizontal="2dp"
294294
android:layout_marginVertical="4dp"
295-
android:text="@string/eula_sum"
296-
android:textAppearance="@android:style/TextAppearance.Material.Small"
297-
android:drawableStart="@drawable/baseline_library_add_check_24"
298-
android:drawablePadding="8dp" />
299-
300-
<com.google.android.material.textview.MaterialTextView
301-
android:layout_width="match_parent"
302-
android:layout_height="wrap_content"
303-
android:autoLink="web"
304-
android:textColorLink="@color/blue"
305295
android:text="@string/eula_agree_v2"
306-
android:textAppearance="@android:style/TextAppearance.Material.Small" />
296+
android:textAppearance="@style/TextAppearance.Material3.LabelSmall" />
307297

308298
</LinearLayout>
309299

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,6 @@
429429
<string name="upgrade_now">Upgrade</string>
430430
<string name="crash_details_suggestion">The stacktrace may be found below. However, we <b>strongly</b> recommend you to use the feedback form below to submit feedback instead. This way, instead of manually copying the stacktrace, it will send it to us automatically. It also is deobfuscated that way and additional details are reported automatically.</string>
431431
<string name="reinstall_warning">Most modules should be uninstalled, then reinstalled cleanly. For this reason, AMM does not support reinstalling modules while they are installed on the device.</string>
432+
<string name="build_expired">This build has expired. Please update to the latest version.</string>
433+
<string name="eula_agree_v2_headline">EULA and Terms</string>
432434
</resources>

0 commit comments

Comments
 (0)