Skip to content

Commit

Permalink
fix known bugs
Browse files Browse the repository at this point in the history
Signed-off-by: androidacy-user <[email protected]>
  • Loading branch information
androidacy-user committed Nov 6, 2023
1 parent b6a496e commit dac8489
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 57 deletions.
18 changes: 9 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,15 @@ configurations {
dependencies {
// UI
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.activity:activity-ktx:1.7.2")
implementation("androidx.activity:activity-ktx:1.8.0")
implementation("androidx.emoji2:emoji2:1.4.0")
implementation("androidx.emoji2:emoji2-views-helper:1.4.0")
implementation("androidx.preference:preference-ktx:1.2.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.recyclerview:recyclerview:1.3.1")
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("androidx.webkit:webkit:1.8.0")
implementation("com.google.android.material:material:1.9.0")
implementation("com.google.android.material:material:1.10.0")

implementation("com.mikepenz:aboutlibraries:10.9.1")

Expand Down Expand Up @@ -405,11 +405,11 @@ dependencies {
implementation("androidx.security:security-crypto:1.1.0-alpha06")

// some utils
implementation("commons-io:commons-io:2.14.0")
implementation("commons-io:commons-io:2.15.0")
implementation("org.apache.commons:commons-compress:1.24.0")

// analytics
implementation("ly.count.android:sdk:23.8.2")
implementation("ly.count.android:sdk:23.8.4")

// annotations
implementation("org.jetbrains:annotations-java5:24.0.1")
Expand All @@ -418,19 +418,19 @@ dependencies {
debugImplementation("com.squareup.leakcanary:leakcanary-android:2.12")

// desugaring
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")

// yes
implementation("com.github.fingerprintjs:fingerprint-android:2.0.2")

// room
implementation("androidx.room:room-runtime:2.5.2")
implementation("androidx.room:room-runtime:2.6.0")

// To use Kotlin Symbol Processing (KSP)
ksp("androidx.room:room-compiler:2.5.2")
ksp("androidx.room:room-compiler:2.6.0")

// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:2.5.2")
implementation("androidx.room:room-ktx:2.6.0")

implementation("pl.droidsonroids.gif:android-gif-drawable:1.2.28")

Expand Down
34 changes: 8 additions & 26 deletions app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {

@SuppressLint("SdCardPath")
val getContent = this.registerForActivityResult(
ActivityResultContracts.GetContent()
ActivityResultContracts.GetContent(),
) { uri: Uri? ->
if (uri == null) {
Timber.d("invalid uri received")
Expand Down Expand Up @@ -157,46 +157,28 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
)
return@registerForActivityResult
}
// check if the file is a zip by reading the first 4 bytes
val bytes = ByteArray(4)
inputStream.read(bytes, 0, 4)
if (!(bytes[0] == 0x50.toByte() && bytes[1] == 0x4B.toByte() && bytes[2] == 0x03.toByte() && bytes[3] == 0x04.toByte())) {
Toast.makeText(
this@MainActivity, R.string.file_picker_not_zip, Toast.LENGTH_SHORT
).show()
Timber.e(
"File is not a zip! Expected 0x504B0304, got %02X%02X%02X%02X",
bytes[0],
bytes[1],
bytes[2],
bytes[3]
)
run {
outputStream = FileOutputStream(destination)
Files.copy(inputStream, outputStream as FileOutputStream)
if (MainApplication.forceDebugLogging) Timber.i("File saved at %s", destination)
success = true
callback?.onReceived(
destination,
uri,
IntentHelper.RESPONSE_ERROR
IntentHelper.RESPONSE_FILE
)
return@registerForActivityResult
}
outputStream = FileOutputStream(destination)
Files.copy(inputStream, outputStream)
if (MainApplication.forceDebugLogging) Timber.i("File saved at %s", destination)
success = true
} catch (e: Exception) {
Timber.e(e)
Toast.makeText(
this@MainActivity, R.string.file_picker_failure, Toast.LENGTH_SHORT
).show()
callback?.onReceived(destination, uri, IntentHelper.RESPONSE_ERROR)
} finally {
Files.closeSilently(inputStream)
Files.closeSilently(outputStream)
if (!success && destination?.exists() == true && !destination!!.delete()) Timber.e("Failed to delete artifact!")
}
callback?.onReceived(
destination,
uri,
if (success) IntentHelper.RESPONSE_FILE else IntentHelper.RESPONSE_ERROR
)
}

init {
Expand Down
20 changes: 14 additions & 6 deletions app/src/main/kotlin/com/fox2code/mmm/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
BuildConfig.DEBUG || getPreferences("mmm")?.getBoolean(
"pref_force_debug_logging",
false
) ?: false
) ?: BuildConfig.DEBUG

// Warning! Locales that don't exist will crash the app
// Anything that is commented out is supported but the translation is not complete to at least 60%
Expand Down Expand Up @@ -641,7 +641,7 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
}

fun shouldPreventReboot(): Boolean {
return getPreferences("mmm")!!.getBoolean("pref_prevent_reboot", true)
return getPreferences("mmm")!!.getBoolean("pref_prevent_reboot", false)
}

val isShowIncompatibleModules: Boolean
Expand Down Expand Up @@ -738,17 +738,25 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
}

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
lastActivity = activity as AppCompatActivity
activity.setTheme(managerThemeResId)
try {
lastActivity = activity as AppCompatActivity
activity.setTheme(managerThemeResId)
} catch (e: Exception) {
Timber.e(e, "Failed to set theme")
}
}

override fun onActivityStarted(activity: Activity) {
if (analyticsAllowed()) Countly.sharedInstance().onStart(activity)
}

override fun onActivityResumed(activity: Activity) {
lastActivity = activity as AppCompatActivity
activity.setTheme(managerThemeResId)
try {
lastActivity = activity as AppCompatActivity
activity.setTheme(managerThemeResId)
} catch (e: Exception) {
Timber.e(e, "Failed to set theme")
}
}

override fun onActivityPaused(activity: Activity) {
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/kotlin/com/fox2code/mmm/module/ActionButtonType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.text.Spanned
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.DrawableRes
import com.fox2code.mmm.BuildConfig
import com.fox2code.mmm.MainApplication
import com.fox2code.mmm.MainApplication.Companion.INSTANCE
import com.fox2code.mmm.MainApplication.Companion.isShowcaseMode
Expand Down Expand Up @@ -159,14 +160,16 @@ enum class ActionButtonType {
})
// if text is reinstall, we need to uninstall first - warn the user but don't proceed
if (moduleHolder.moduleInfo != null && moduleHolder.repoModule == null && button.text == button.context.getString(R.string.reinstall)) {
val builder = MaterialAlertDialogBuilder(button.context)
builder.setTitle(R.string.reinstall)
.setMessage(R.string.reinstall_warning_v2)
.setCancelable(true)
// ok button that does nothing
.setPositiveButton(R.string.ok, null)
.show()
return
if (!BuildConfig.DEBUG) {
val builder = MaterialAlertDialogBuilder(button.context)
builder.setTitle(R.string.reinstall)
.setMessage(R.string.reinstall_warning_v2)
.setCancelable(true)
// ok button that does nothing
.setPositiveButton(R.string.ok, null)
.show()
return
}
}
// prefer repomodule if possible
var updateZipUrl = ""
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/fox2code/mmm/utils/IntentHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ enum class IntentHelper {;
}
MainActivity.INSTANCE?.callback = callback
MainActivity.INSTANCE?.destination = destination
MainActivity.INSTANCE?.getContent?.launch("*/*")
// select zip file
MainActivity.INSTANCE?.getContent?.launch("application/zip")
}
}
}
10 changes: 4 additions & 6 deletions app/src/main/kotlin/com/fox2code/mmm/utils/io/net/Http.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ enum class Http {;
*
* Note: DNS Cache is stored in user data.
*/
private class FallBackDNS(context: Context, parent: Dns, vararg fallbacks: String?) : Dns {
private class FallBackDNS(parent: Dns, vararg fallbacks: String?) : Dns {
private val parent: Dns
private val sharedPreferences: SharedPreferences
private val sharedPreferences: SharedPreferences = MainApplication.getPreferences("mmm_dns")!!
private val fallbacks: HashSet<String>
private val fallbackCache: HashMap<String, List<InetAddress>>

init {
sharedPreferences = MainApplication.getPreferences("mmm_dns")!!
this.parent = parent
this.fallbacks =
HashSet(listOf(*fallbacks)).toString().replaceAfter("]", "").replace("[", "")
Expand Down Expand Up @@ -291,11 +290,11 @@ enum class Http {;
}
// User-Agent format was agreed on telegram
androidacyUA = if (hasWebView) {
WebSettings.getDefaultUserAgent(mainApplication)
.replace("wv", "") + " AMMM/" + BuildConfig.VERSION_CODE
WebSettings.getDefaultUserAgent(mainApplication).replaceFirst("(; )?wv".toRegex(), "").replaceFirst(" Version/[^ ]*".toRegex(), "") + " AMM/" + BuildConfig.VERSION_CODE
} else {
"Mozilla/5.0 (Linux; Android " + Build.VERSION.RELEASE + "; " + Build.DEVICE + ")" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Mobile Safari/537.36" + " AMMM/" + BuildConfig.VERSION_CODE
}
Timber.i("User-Agent: %s", androidacyUA)
httpclientBuilder.addInterceptor(Interceptor { chain: Interceptor.Chain? ->
val request: Request.Builder = chain!!.request().newBuilder()
request.header("Upgrade-Insecure-Requests", "1")
Expand Down Expand Up @@ -383,7 +382,6 @@ enum class Http {;
}
// Fallback DNS cache responses in case request fail but already succeeded once in the past
fallbackDNS = FallBackDNS(
mainApplication,
dns,
"github.com",
"api.github.com",
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/security_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<SwitchPreferenceCompat
android:widgetLayout="@layout/preference_material_switch"
app:defaultValue="true"
app:defaultValue="false"
app:icon="@drawable/ic_reboot_24"
app:key="pref_prevent_reboot"
app:singleLineTitle="false"
Expand Down

0 comments on commit dac8489

Please sign in to comment.