Skip to content

Commit 1484195

Browse files
work around root issue
Signed-off-by: androidacy-user <[email protected]>
1 parent 4e0a620 commit 1484195

File tree

5 files changed

+30
-50
lines changed

5 files changed

+30
-50
lines changed

app/proguard-rules.pro

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Uncomment this to preserve the line number information for
1616
# debugging stack traces.
17-
# -keepattributes SourceFile,LineNumberTable,Signature
17+
-keepattributes SourceFile,LineNumberTable,Signature
1818
-printmapping mapping.txt
1919

2020
# Optimisations
@@ -194,9 +194,7 @@
194194
}
195195

196196
-keepclassmembers class org.apache.commons.compress.archivers.zip.* { *; }
197-
198-
-keep,includedescriptorclasses class net.sqlcipher.** { *; }
199-
-keep,includedescriptorclasses interface net.sqlcipher.** { *; }
197+
#-keep class com.fox2code.mmm.installer.InstallerInitializer { *; }
200198

201199
# dontwarn
202200
-dontwarn android.os.SystemProperties
@@ -210,4 +208,4 @@
210208
-dontwarn rikka.core.util.ResourceUtils
211209
-dontwarn io.sentry.compose.viewhierarchy.ComposeViewHierarchyExporter
212210
-dontwarn org.commonmark.ext.gfm.strikethrough.Strikethrough
213-
-dontwarn pl.droidsonroids.gif.GifDrawable
211+
-dontwarn pl.droidsonroids.gif.GifDrawable

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
android:value="false" />
193193
<meta-data
194194
android:name="io.sentry.dsn"
195-
android:value="https://[email protected]/77" /> <!-- enable view hierarchy for crashes -->
195+
android:value="https://[email protected]/7" /> <!-- enable view hierarchy for crashes -->
196196
<meta-data
197197
android:name="io.sentry.attach-view-hierarchy"
198198
android:value="true" /> <!-- Sane value, but feel free to lower it -->
@@ -213,4 +213,4 @@
213213
android:value="0.2" />
214214
</application>
215215

216-
</manifest>
216+
</manifest>

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

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,20 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
130130
fun requestNewToken(): String {
131131
val deviceId = generateDeviceId()
132132
val resp = doHttpGet(
133-
"https://" + host + "/auth/register?device_id=" + deviceId + "&client_id=" + BuildConfig.ANDROIDACY_CLIENT_ID,
133+
"https://" + host + "/auth/register?fmt=json&device_id=" + deviceId + "&client_id=" + BuildConfig.ANDROIDACY_CLIENT_ID,
134134
false
135135
)
136-
// response is JSON
137-
val jsonObject = JSONObject(String(resp))
138-
val token = jsonObject.getString("token")
136+
var token: String
137+
try {
138+
val jsonObject = JSONObject(String(resp))
139+
token = jsonObject.getString("token")
140+
} catch (e: JSONException) {
141+
if (String(resp).count() == 64) {
142+
token = String(resp)
143+
} else {
144+
return ""
145+
}
146+
}
139147
// Save the token to the shared preferences
140148
val editor = getSharedPreferences("androidacy")!!.edit()
141149
editor.putString("pref_androidacy_api_token", token)
@@ -217,37 +225,8 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
217225
Timber.i("Token is null, requesting new one...")
218226
try {
219227
Timber.i("Requesting new token...")
220-
// POST json request to https://production-api.androidacy.com/auth/register
221228
token = requestNewToken()
222229
// Parse token
223-
try {
224-
val jsonObject = JSONObject(token!!)
225-
// log last four of token, replacing the rest with asterisks
226-
token = jsonObject.getString("token")
227-
val tempToken = token!!
228-
Timber.d(
229-
"Token: %s",
230-
tempToken.substring(0, tempToken.length - 4)
231-
.replace(".".toRegex(), "*") + tempToken.substring(
232-
tempToken.length - 4
233-
)
234-
)
235-
memberLevel = jsonObject.getString("role")
236-
Timber.d("Member level: %s", memberLevel)
237-
} catch (e: JSONException) {
238-
Timber.e(e, "Failed to parse token: %s", token)
239-
// Show a toast
240-
val mainLooper = Looper.getMainLooper()
241-
val handler = Handler(mainLooper)
242-
handler.post {
243-
Toast.makeText(
244-
INSTANCE,
245-
R.string.androidacy_failed_to_parse_token,
246-
Toast.LENGTH_LONG
247-
).show()
248-
}
249-
return false
250-
}
251230
// Ensure token is valid
252231
if (!isValidToken(token)) {
253232
Timber.e("Failed to validate token")
@@ -541,4 +520,4 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
541520
}
542521
}
543522
}
544-
}
523+
}

app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class InstallerInitializer : Shell.Initializer() {
3838
const val ERROR_NO_PATH = 1
3939
const val ERROR_NO_SU = 2
4040
const val ERROR_OTHER = 3
41+
private var tries = 0
4142

42-
@JvmStatic
4343
val errorNotification: NotificationType?
4444
get() {
4545
val hasRoot = Shell.isAppGrantedRoot()
@@ -56,7 +56,6 @@ class InstallerInitializer : Shell.Initializer() {
5656
return NotificationType.NO_ROOT
5757
}
5858

59-
@JvmStatic
6059
fun peekMagiskPath(): String? {
6160
return mgskPth
6261
}
@@ -74,23 +73,18 @@ class InstallerInitializer : Shell.Initializer() {
7473
*
7574
* For read/write only "/data/adb/modules" should be used
7675
*/
77-
@JvmStatic
7876
fun peekModulesPath(): String? {
7977
return if (mgskPth == null) null else "$mgskPth/.magisk/modules"
8078
}
8179

82-
@JvmStatic
8380
fun peekMagiskVersion(): Int {
8481
return mgskVerCode
8582
}
8683

87-
@JvmStatic
8884
fun peekHasRamdisk(): Boolean {
8985
return hsRmdsk
9086
}
9187

92-
@JvmStatic
93-
@JvmOverloads
9488
fun tryGetMagiskPathAsync(callback: Callback, forceCheck: Boolean = false) {
9589
val mgskPth = mgskPth
9690
val thread: Thread = object : Thread("Magisk GetPath Thread") {
@@ -135,6 +129,7 @@ class InstallerInitializer : Shell.Initializer() {
135129
var hsRmdsk = hsRmdsk
136130
if (mgskPth != null && !forceCheck) return mgskPth
137131
val output = ArrayList<String>()
132+
try {
138133
if (!Shell.cmd(
139134
"if grep ' / ' /proc/mounts | grep -q '/dev/root' &> /dev/null; " +
140135
"then echo true; else echo false; fi", "magisk -V", "magisk --path"
@@ -168,6 +163,14 @@ class InstallerInitializer : Shell.Initializer() {
168163
}
169164
Companion.mgskVerCode = mgskVerCode
170165
return mgskPth
166+
} catch (ignored: Exception) {
167+
if (tries < 5) {
168+
tries++
169+
return tryGetMagiskPath(true)
170+
} else {
171+
return null
172+
}
173+
}
171174
}
172175
}
173-
}
176+
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ buildscript {
2424

2525
// NOTE: Do not place your application dependencies here; they belong
2626
// in the individual module build.gradle files
27-
classpath("io.sentry:sentry-android-gradle-plugin:3.7.0")
27+
classpath("io.sentry:sentry-android-gradle-plugin:3.11.0")
2828
classpath("org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:2.7.1")
2929
}
3030
}

0 commit comments

Comments
 (0)