Skip to content

Commit 2ff680b

Browse files
code cleanup
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent b5a9803 commit 2ff680b

170 files changed

Lines changed: 812 additions & 602 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class AppUpdateManager private constructor() {
5454
}
5555
val deviceId = AndroidacyRepoData.generateDeviceId()
5656
val clientId = BuildConfig.ANDROIDACY_CLIENT_ID
57-
val url = "https://production-api.androidacy.com/amm/updates/check?appVersionCode=${BuildConfig.VERSION_CODE}&token=$token&device_id=$deviceId&client_id=$clientId"
57+
val url =
58+
"https://production-api.androidacy.com/amm/updates/check?appVersionCode=${BuildConfig.VERSION_CODE}&token=$token&device_id=$deviceId&client_id=$clientId"
5859
val response = doHttpGet(url, false)
5960
// convert response to string
6061
val responseString = String(response, Charsets.UTF_8)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,21 @@ class MainApplication : FoxApplication(), Configuration.Provider {
8181

8282
@JvmField
8383
var modulesHaveUpdates = false
84+
8485
@JvmField
8586
var updateModuleCount = 0
87+
8688
@JvmField
8789
var updateModules: List<String> = ArrayList()
8890

8991
@StyleRes
9092
private var managerThemeResId = R.style.Theme_MagiskModuleManager
9193
private var markwonThemeContext: FoxThemeWrapper? = null
94+
9295
@JvmField
9396
var markwon: Markwon? = null
9497
private var existingKey: ByteArray? = null
98+
9599
@JvmField
96100
var tracker: Tracker? = null
97101
private var makingNewKey = false
@@ -697,6 +701,7 @@ class MainApplication : FoxApplication(), Configuration.Provider {
697701
@JvmField
698702
val isWrapped = !FoxProcessExt.isRootLoader()
699703
private val callers = ArrayList<String>()
704+
700705
@JvmField
701706
var o = false
702707
private var SHOWCASE_MODE_TRUE: String? = null
@@ -858,6 +863,7 @@ class MainApplication : FoxApplication(), Configuration.Provider {
858863
val isBlurEnabled: Boolean
859864
get() = getSharedPreferences("mmm")!!
860865
.getBoolean("pref_enable_blur", false)
866+
861867
@JvmStatic
862868
val isDeveloper: Boolean
863869
get() {
@@ -872,6 +878,7 @@ class MainApplication : FoxApplication(), Configuration.Provider {
872878
"mmm"
873879
)!!
874880
.getBoolean("pref_use_magisk_install_command", false) && isDeveloper
881+
875882
@JvmStatic
876883
val isBackgroundUpdateCheckEnabled: Boolean
877884
get() {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* Copyright (c) 2023 to present Androidacy and contributors. Names, logos, icons, and the Androidacy name are all trademarks of Androidacy and may not be used without license. See LICENSE for more information.
33
*/
44

5-
@file:Suppress("KotlinConstantConditions", "UNINITIALIZED_ENUM_COMPANION_WARNING",
5+
@file:Suppress(
6+
"KotlinConstantConditions", "UNINITIALIZED_ENUM_COMPANION_WARNING",
67
"ktConcatNullable", "BlockingMethodInNonBlockingContext", "UnusedEquals"
78
)
89

@@ -51,6 +52,7 @@ enum class NotificationType constructor(
5152
return !BuildConfig.DEBUG
5253
}
5354
},
55+
5456
@JvmStatic
5557
SHOWCASE_MODE(
5658
R.string.showcase_mode, R.drawable.ic_baseline_lock_24,
@@ -60,6 +62,7 @@ enum class NotificationType constructor(
6062
return !MainApplication.isShowcaseMode
6163
}
6264
},
65+
6366
@JvmStatic
6467
NO_MAGISK(
6568
R.string.fail_magisk_missing,
@@ -74,6 +77,7 @@ enum class NotificationType constructor(
7477
return InstallerInitializer.errorNotification !== this
7578
}
7679
},
80+
7781
@JvmStatic
7882
NO_ROOT(R.string.fail_root_magisk, R.drawable.ic_baseline_numbers_24) {
7983
override fun shouldRemove(): Boolean {
@@ -85,6 +89,7 @@ enum class NotificationType constructor(
8589
return InstallerInitializer.errorNotification !== this
8690
}
8791
},
92+
8893
@JvmStatic
8994
MAGISK_OUTDATED(
9095
R.string.magisk_outdated,
@@ -101,18 +106,21 @@ enum class NotificationType constructor(
101106
Constants.MAGISK_VER_CODE_INSTALL_COMMAND
102107
}
103108
},
109+
104110
@JvmStatic
105111
NO_INTERNET(R.string.fail_internet, R.drawable.ic_baseline_cloud_off_24) {
106112
override fun shouldRemove(): Boolean {
107113
return RepoManager.getINSTANCE()!!.hasConnectivity()
108114
}
109115
},
116+
110117
@JvmStatic
111118
REPO_UPDATE_FAILED(R.string.repo_update_failed, R.drawable.ic_baseline_cloud_off_24) {
112119
override fun shouldRemove(): Boolean {
113120
return RepoManager.getINSTANCE()!!.isLastUpdateSuccess
114121
}
115122
},
123+
116124
@JvmStatic
117125
NEED_CAPTCHA_ANDROIDACY(
118126
R.string.androidacy_need_captcha,
@@ -128,12 +136,14 @@ enum class NotificationType constructor(
128136
|| !Http.needCaptchaAndroidacy())
129137
}
130138
},
139+
131140
@JvmStatic
132141
NO_WEB_VIEW(R.string.no_web_view, R.drawable.ic_baseline_android_24) {
133142
override fun shouldRemove(): Boolean {
134143
return Http.hasWebView()
135144
}
136145
},
146+
137147
@JvmStatic
138148
UPDATE_AVAILABLE(
139149
R.string.app_update_available,
@@ -152,6 +162,7 @@ enum class NotificationType constructor(
152162
return !AppUpdateManager.appUpdateManager.peekShouldUpdate()
153163
}
154164
},
165+
155166
@JvmStatic
156167
INSTALL_FROM_STORAGE(
157168
R.string.install_from_storage,

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import java.util.Objects
4242
class SetupActivity : FoxActivity(), LanguageActivity {
4343
private var cachedTheme = 0
4444
private var realmDatabasesCreated = false
45+
4546
@SuppressLint("ApplySharedPref", "RestrictedApi")
4647
override fun onCreate(savedInstanceState: Bundle?) {
4748
super.onCreate(savedInstanceState)
@@ -77,8 +78,10 @@ class SetupActivity : FoxActivity(), LanguageActivity {
7778
assert((Objects.requireNonNull<Any>(view.findViewById(R.id.setup_crash_reporting)) as MaterialSwitch).isChecked == BuildConfig.DEFAULT_ENABLE_CRASH_REPORTING)
7879
}
7980
// Repos are a little harder, as the enabled_repos build config is an arraylist
80-
val andRepoView = Objects.requireNonNull<Any>(view.findViewById(R.id.setup_androidacy_repo)) as MaterialSwitch
81-
val magiskAltRepoView = Objects.requireNonNull<Any>(view.findViewById(R.id.setup_magisk_alt_repo)) as MaterialSwitch
81+
val andRepoView =
82+
Objects.requireNonNull<Any>(view.findViewById(R.id.setup_androidacy_repo)) as MaterialSwitch
83+
val magiskAltRepoView =
84+
Objects.requireNonNull<Any>(view.findViewById(R.id.setup_magisk_alt_repo)) as MaterialSwitch
8285
andRepoView.isChecked = BuildConfig.ENABLED_REPOS.contains("androidacy_repo")
8386
magiskAltRepoView.isChecked = BuildConfig.ENABLED_REPOS.contains("magisk_alt_repo")
8487
// On debug builds, log when a switch is toggled
@@ -242,8 +245,10 @@ class SetupActivity : FoxActivity(), LanguageActivity {
242245
}
243246
realm.executeTransactionAsync { r: Realm ->
244247
Timber.d("Realm transaction started")
245-
r.where(ReposList::class.java).equalTo("id", "androidacy_repo").findFirst()!!.isEnabled = androidacyRepo
246-
r.where(ReposList::class.java).equalTo("id", "magisk_alt_repo").findFirst()!!.isEnabled = magiskAltRepo
248+
r.where(ReposList::class.java).equalTo("id", "androidacy_repo")
249+
.findFirst()!!.isEnabled = androidacyRepo
250+
r.where(ReposList::class.java).equalTo("id", "magisk_alt_repo")
251+
.findFirst()!!.isEnabled = magiskAltRepo
247252
Timber.d("Realm transaction committing")
248253
// commit the changes
249254
r.commitTransaction()

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import java.util.Objects
3333
class UpdateActivity : FoxActivity() {
3434
private var chgWv: WebView? = null
3535
private var url: String = String()
36+
3637
@SuppressLint("RestrictedApi", "SetJavaScriptEnabled")
3738
override fun onCreate(savedInstanceState: Bundle?) {
3839
super.onCreate(savedInstanceState)
@@ -128,6 +129,7 @@ class UpdateActivity : FoxActivity() {
128129
ACTIONS.CHECK -> {
129130
checkForUpdate()
130131
}
132+
131133
ACTIONS.DOWNLOAD -> {
132134
try {
133135
downloadUpdate()
@@ -142,6 +144,7 @@ class UpdateActivity : FoxActivity() {
142144
}
143145
}
144146
}
147+
145148
ACTIONS.INSTALL -> {
146149
// ensure path was passed and points to a file within our cache directory. replace .. and url encoded characters
147150
val path =
@@ -233,7 +236,8 @@ class UpdateActivity : FoxActivity() {
233236
Timber.w("Invalid token, not checking for updates")
234237
token = AndroidacyRepoData.instance.requestNewToken()
235238
}
236-
url = "https://production-api.androidacy.com/amm/updates/check?appVersionCode=${BuildConfig.VERSION_CODE}&token=$token&device_id=$deviceId&client_id=$clientId"
239+
url =
240+
"https://production-api.androidacy.com/amm/updates/check?appVersionCode=${BuildConfig.VERSION_CODE}&token=$token&device_id=$deviceId&client_id=$clientId"
237241
runOnUiThread {
238242
// set status text to no update available
239243
statusTextView.setText(R.string.no_update_available)
@@ -280,15 +284,19 @@ class UpdateActivity : FoxActivity() {
280284
}
281285
val deviceId = AndroidacyRepoData.generateDeviceId()
282286
val clientId = BuildConfig.ANDROIDACY_CLIENT_ID
283-
url = "https://production-api.androidacy.com/amm/updates/check?appVersionCode=${BuildConfig.VERSION_CODE}&token=$token&device_id=$deviceId&client_id=$clientId"
287+
url =
288+
"https://production-api.androidacy.com/amm/updates/check?appVersionCode=${BuildConfig.VERSION_CODE}&token=$token&device_id=$deviceId&client_id=$clientId"
284289
runOnUiThread {
285290
val changelogWebView = chgWv!!
286291
changelogWebView.loadUrl(url.replace("updates/check", "changelog"))
287292
}
288293
// get the download url
289294
var downloadUrl = url.replace("check", "download")
290295
// append arch to download url. coerce anything like arm64-* or aarch64-* to arm64 and anything like arm-* or armeabi-* to arm
291-
downloadUrl += if (Build.SUPPORTED_ABIS[0].contains("arm64") || Build.SUPPORTED_ABIS[0].contains("aarch64")) {
296+
downloadUrl += if (Build.SUPPORTED_ABIS[0].contains("arm64") || Build.SUPPORTED_ABIS[0].contains(
297+
"aarch64"
298+
)
299+
) {
292300
"&arch=arm64"
293301
} else if (Build.SUPPORTED_ABIS[0].contains("arm") || Build.SUPPORTED_ABIS[0].contains("armeabi")) {
294302
"&arch=arm"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ enum class XHooks {
7070

7171
@Keep
7272
fun getXRepo(url: String?): XRepo {
73-
return RepoManager.iNSTANCE_UNSAFE?.get(url) ?: throw NullPointerException("Repo not found!")
73+
return RepoManager.iNSTANCE_UNSAFE?.get(url)
74+
?: throw NullPointerException("Repo not found!")
7475
}
7576

7677
@get:Keep

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ import java.io.IOException
6060
*/
6161
class AndroidacyActivity : FoxActivity() {
6262
private var moduleFile: File? = null
63+
6364
@JvmField
6465
var webView: WebView? = null
6566
var webViewNote: TextView? = null
6667
private var androidacyWebAPI: AndroidacyWebAPI? = null
6768
var progressIndicator: LinearProgressIndicator? = null
69+
6870
@JvmField
6971
var backOnResume = false
7072
var downloadMode = false
73+
7174
@SuppressLint(
7275
"SetJavaScriptEnabled",
7376
"JavascriptInterface",
@@ -469,7 +472,8 @@ class AndroidacyActivity : FoxActivity() {
469472
module = doHttpGet(
470473
url!!, ({ downloaded: Int, total: Int, _: Boolean ->
471474
progressIndicator!!.setProgressCompat(
472-
downloaded * 100 / total, true)
475+
downloaded * 100 / total, true
476+
)
473477

474478
} as Http.ProgressListener?)!!)
475479
FileOutputStream(moduleFile).use { fileOutputStream -> fileOutputStream.write(module) }

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
5050
private val clientID = BuildConfig.ANDROIDACY_CLIENT_ID
5151
private val testMode: Boolean
5252
private val host: String
53+
5354
@JvmField
5455
var userInfo = arrayOf(arrayOf("role", null), arrayOf("permissions", null))
56+
5557
@JvmField
5658
var memberLevel: String? = null
5759

@@ -154,7 +156,8 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
154156
// If it's a 400, the app is probably outdated. Show a snackbar suggesting user update app and webview
155157
if (connection.responseCode == 400) {
156158
// Show a dialog using androidacy_update_needed string
157-
INSTANCE?.let { MaterialAlertDialogBuilder(it) }!!.setTitle(R.string.androidacy_update_needed)
159+
INSTANCE?.let { MaterialAlertDialogBuilder(it) }!!
160+
.setTitle(R.string.androidacy_update_needed)
158161
.setMessage(
159162
R.string.androidacy_update_needed_message
160163
)
@@ -179,7 +182,8 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
179182
androidacyBlockade = time + 30000L
180183
try {
181184
if (token == null) {
182-
token = getSharedPreferences("androidacy")?.getString("pref_androidacy_api_token", null)
185+
token =
186+
getSharedPreferences("androidacy")?.getString("pref_androidacy_api_token", null)
183187
if (token != null && !isValidToken(token)) {
184188
Timber.i("Token expired or invalid, requesting new one...")
185189
token = null
@@ -459,10 +463,12 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
459463

460464
companion object {
461465
private var ANDROIDACY_DEVICE_ID: String? = null
462-
var token = getSharedPreferences("androidacy")!!.getString("pref_androidacy_api_token", null)
466+
var token =
467+
getSharedPreferences("androidacy")!!.getString("pref_androidacy_api_token", null)
463468

464469
init {
465-
@Suppress("LocalVariableName") val OK_HTTP_URL_BUILDER: Builder = Builder().scheme("https")
470+
@Suppress("LocalVariableName") val OK_HTTP_URL_BUILDER: Builder =
471+
Builder().scheme("https")
466472
// Using HttpUrl.Builder.host(String) crash the app
467473
OK_HTTP_URL_BUILDER.host("production-api.androidacy.com")
468474
OK_HTTP_URL_BUILDER.build()

app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class BackgroundUpdateChecker(context: Context, workerParams: WorkerParameters)
5757
private const val NOTIFICATION_ID_ONGOING = 2
5858
private const val NOTIFICATION_CHANNEL_ID_ONGOING = "mmm_background_update"
5959
private const val NOTIFICATION_ID_APP = 3
60+
6061
@SuppressLint("RestrictedApi")
6162
private fun postNotificationForAppUpdate(context: Context) {
6263
// create the notification channel if not already created
@@ -415,7 +416,9 @@ class BackgroundUpdateChecker(context: Context, workerParams: WorkerParameters)
415416
// schedule periodic check for updates every 6 hours (6 * 60 * 60 = 21600) and not on low battery
416417
Timber.d("Scheduling periodic background check")
417418
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
418-
"background_checker", ExistingPeriodicWorkPolicy.UPDATE, PeriodicWorkRequest.Builder(
419+
"background_checker",
420+
ExistingPeriodicWorkPolicy.UPDATE,
421+
PeriodicWorkRequest.Builder(
419422
BackgroundUpdateChecker::class.java, 21600, TimeUnit.SECONDS
420423
).setConstraints(
421424
Constraints.Builder().setRequiresBatteryNotLow(true).build()

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class InstallerActivity : FoxActivity() {
8080
private var canceled = false
8181
private var warnReboot = false
8282
private var wakeLock: WakeLock? = null
83+
8384
@SuppressLint("RestrictedApi")
8485
override fun onCreate(savedInstanceState: Bundle?) {
8586
warnReboot = false
@@ -211,7 +212,8 @@ class InstallerActivity : FoxActivity() {
211212
)
212213
)
213214
if (urlMode) {
214-
rawModule = Http.doHttpGet(target
215+
rawModule = Http.doHttpGet(
216+
target
215217
) ProgressListener@{ progress: Int, max: Int, _: Boolean ->
216218
if (max <= 0 && prgInd!!.isIndeterminate) return@ProgressListener
217219
runOnUiThread {
@@ -642,10 +644,10 @@ class InstallerActivity : FoxActivity() {
642644
builder.setTitle(R.string.install_terminal_reboot_now)
643645
.setMessage(R.string.install_terminal_reboot_now_message)
644646
.setCancelable(false).setIcon(
645-
R.drawable.ic_reboot_24
646-
).setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int ->
647-
Shell.cmd(rbtCmd).submit()
648-
}
647+
R.drawable.ic_reboot_24
648+
).setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int ->
649+
Shell.cmd(rbtCmd).submit()
650+
}
649651
.setNegativeButton(R.string.no) { x: DialogInterface, _: Int -> x.dismiss() }
650652
.show()
651653
} else {

0 commit comments

Comments
 (0)