Skip to content

Commit

Permalink
Removed broken code and permissions checks, optimized UI (104)
Browse files Browse the repository at this point in the history
  • Loading branch information
cioccarellia committed Sep 4, 2024
1 parent 0f68346 commit 8d84273
Show file tree
Hide file tree
Showing 21 changed files with 301 additions and 699 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.andreacioccarelli.impactor"
minSdkVersion 16
targetSdkVersion 35
versionCode 102
versionName "5.9.10"
versionCode 104
versionName "5.9.11"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
Expand Down Expand Up @@ -43,7 +43,6 @@ dependencies {
implementation 'androidx.browser:browser:1.6.0'

implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation 'com.afollestad:assent:0.2.5'
implementation 'com.jrummyapps:android-shell:1.0.1'
implementation 'com.github.GrenderG:Toasty:1.4.2'
implementation 'com.jaredrummler:android-device-names:2.1.1'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
android:roundIcon="@mipmap/ic_launcher"
android:label="@string/AppName"
android:supportsRtl="true"
android:name=".App"
android:theme="@style/Impactor">

<meta-data
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/andreacioccarelli/impactor/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.andreacioccarelli.impactor

import android.app.Application
import com.jaredrummler.android.device.DeviceName

class App : Application() {

override fun onCreate() {
super.onCreate()

DeviceName.init(this)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.andreacioccarelli.impactor.base

import android.content.Context
import android.os.Vibrator
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.andreacioccarelli.impactor.tools.AssetsProvider
import com.andreacioccarelli.impactor.tools.CodeExecutor
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.jrummyapps.android.shell.Shell
import es.dmoral.toasty.Toasty
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

open class ImpactorActivity : AppCompatActivity() {

fun vibrate(time: Int) {
try {
val v = baseContext.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
v.vibrate(time.toLong())
} catch (ignored: Exception) {}
}


var root = false
var busybox = false

fun refreshRootLogic(
i1: ImageView,
i2: ImageView,
c1: TextView,
c2: TextView,
fab: FloatingActionButton
) {
CoroutineScope(Dispatchers.IO).launch {
root = false
busybox = CodeExecutor().checkBusyBox()

try {
root = Shell.SU.available()
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
Toasty.error(this@ImpactorActivity, "Error raised while checking root", 1).show()
}
}

AssetsProvider.init(root, busybox, i1, i2, c1, c2, fab)
}
}


}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ package com.andreacioccarelli.impactor.tools

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Build
import android.widget.ImageView
import android.widget.TextView
import com.andreacioccarelli.impactor.R
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.jaredrummler.android.device.DeviceName
import com.jrummyapps.android.shell.Shell
import com.jrummyapps.android.shell.ShellExitCode
import es.dmoral.toasty.Toasty
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.random.Random

@SuppressLint("SetTextI18n")
class AssetsProvider : ShellExitCode {
Expand All @@ -26,6 +31,7 @@ class AssetsProvider : ShellExitCode {
v.setImageResource(R.drawable.hw_info_red)
}


private fun s1(v: ImageView) {
v.setImageResource(R.drawable.check_ok)
}
Expand All @@ -34,50 +40,62 @@ class AssetsProvider : ShellExitCode {
v.setImageResource(R.drawable.hw_info_green)
}

fun init(ir: Boolean, i1: ImageView, i2: ImageView, c1: TextView, c2: TextView) {
if (ir) {
s1(i1)
s2(i2)
c1.text = "Root access has been detected, Impactor ready to go"
c2.text = "Device: " + DeviceName.getDeviceName() + "\nAndroid Version: " + Build.VERSION.RELEASE + "\nBusybox: " + if (CodeExecutor().checkBusyBox()) "Installed" else "Not installed"
} else {
err_ck1(i1)
err_ck2(i2)
c1.text = "Root access not installed or not allowed"
c2.text = "Device: " + DeviceName.getDeviceName() + "\nAndroid Version: " + Build.VERSION.RELEASE + "\nRoot: Not available"
}

private fun l1(v: ImageView) {
v.setImageResource(R.drawable.loading)
}

private fun l2(v: ImageView) {
v.setImageResource(R.drawable.loading)
}

fun init(ctx: Context, i1: ImageView, i2: ImageView, c1: TextView, c2: TextView) {
fun init(
ir: Boolean,
bb: Boolean,
i1: ImageView,
i2: ImageView,
c1: TextView,
c2: TextView,
fab: FloatingActionButton
) {
CoroutineScope(Dispatchers.Main).launch {
l1(i1)
l2(i2)

CoroutineScope(Dispatchers.IO).launch {
var root = false
val busybox = CodeExecutor().checkBusyBox()

try {
root = Shell.SU.available()
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
Toasty.error(ctx, "Error raised while checking root", 1).show()
}
}
if (ir) {
s1(i1)
s2(i2)
c1.text = "Root access has been detected.\nImpactor ready to go"

withContext(Dispatchers.Main) {
if (root) {
s1(i1)
s2(i2)
c1.text = "Root access has been detected, Impactor ready to go"
c2.text = "Device: " + DeviceName.getDeviceName() + "\nAndroid Version: " + Build.VERSION.RELEASE + "\nBusybox: " + if (busybox) "Installed" else "Not installed"
} else {
err_ck1(i1)
err_ck2(i2)
c1.text = "Root access not installed or not allowed"
c2.text = "Device: " + DeviceName.getDeviceName() + "\nAndroid Version: " + Build.VERSION.RELEASE + "\nRoot: Not available"
}
fab.show()
// fab.backgroundTintList = ColorStateList.valueOf(Color.parseColor("#00E676"))
} else {
// Non-root detection is very fast.
// Delaying result display for a fraction of a second to make it feel like the app is
// doing something for users who don't have root access, and which probably downloaded the app without knowing anything,
// so they don't leave 1 star reviews complaining that the app is broken.
// Yes, I know, it's horrible, but it's not the worse thing about this
// class by a wide margin, and it's either that or I start cursing people out
delay(100L + Random.nextInt(50, 300))

err_ck1(i1)
err_ck2(i2)
c1.text = "Root access not installed or not allowed"
fab.hide()
}

PreferenceBuilder(ctx, PreferenceBuilder.DefaultFilename).putBoolean("root", root)

c2.text =
"Device: " + DeviceName.getDeviceName() +
"\nAndroid Version: " + Build.VERSION.RELEASE + " (SDK ${Build.VERSION.SDK_INT})" +
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {Build.VERSION.BASE_OS + ")"} else {")"} +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
" (security patch ${Build.VERSION.SECURITY_PATCH})"
} else {
""
} +
"\nBusybox: " + if (bb) "Installed" else "Not installed"
}
}
}
Expand Down
Loading

0 comments on commit 8d84273

Please sign in to comment.