-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bongtrop
committed
Aug 3, 2023
1 parent
df93162
commit dc910cb
Showing
57 changed files
with
2,434 additions
and
251 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package cc.ggez.ezhz | ||
|
||
import android.Manifest | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.annotation.RequiresApi | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.content.ContextCompat | ||
import com.topjohnwu.superuser.Shell | ||
import java.io.FileOutputStream | ||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.io.OutputStream | ||
|
||
|
||
class SplashActivity : AppCompatActivity() { | ||
companion object { | ||
init { | ||
Shell.enableVerboseLogging = true | ||
} | ||
} | ||
|
||
private lateinit var requestPermissionLauncher: ActivityResultLauncher<String> | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { | ||
if (it) { | ||
startMain() | ||
} else { | ||
val builder: AlertDialog.Builder = AlertDialog.Builder(this) | ||
builder.setTitle("Notification Permission Required") | ||
builder.setMessage("For foreground service, notification permission is required.") | ||
builder.setPositiveButton("OK") { _, _ -> | ||
startMain() | ||
} | ||
|
||
val dialog: AlertDialog = builder.create() | ||
dialog.show() | ||
} | ||
} | ||
if (ContextCompat.checkSelfPermission( | ||
this, | ||
Manifest.permission.POST_NOTIFICATIONS, | ||
) != PackageManager.PERMISSION_GRANTED && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU | ||
) { | ||
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) | ||
} else { | ||
startMain() | ||
} | ||
|
||
} | ||
|
||
private fun startMain() { | ||
Shell.getShell { shell -> | ||
if (!shell.isRoot) { | ||
val builder: AlertDialog.Builder = AlertDialog.Builder(this) | ||
builder.setTitle("Root Required") | ||
builder.setMessage("Please root your device and grant su permission first.") | ||
builder.setPositiveButton("Exit") { _, _ -> | ||
finish() | ||
} | ||
|
||
val dialog: AlertDialog = builder.create() | ||
dialog.show() | ||
return@getShell | ||
} | ||
|
||
copyAssets() | ||
|
||
val intent = Intent(this, MainActivity::class.java) | ||
startActivity(intent) | ||
finish() | ||
} | ||
} | ||
|
||
@Throws(IOException::class) | ||
private fun copyFile(`in`: InputStream, out: OutputStream) { | ||
val buffer = ByteArray(1024) | ||
var read: Int | ||
while (`in`.read(buffer).also { read = it } != -1) { | ||
out.write(buffer, 0, read) | ||
} | ||
} | ||
|
||
private fun copyAssets() { | ||
val assetManager = assets | ||
var files: Array<String>? = null | ||
val abi = Build.SUPPORTED_ABIS[0] | ||
val arch = if (abi.matches("armeabi-v7a|arm64-v8a".toRegex())) "armeabi-v7a" else "x86" | ||
|
||
files = assetManager.list(arch) | ||
|
||
if (files != null) { | ||
for (file in files) { | ||
try { | ||
val inFile = assetManager.open("${arch}/$file") | ||
val outFile = FileOutputStream("${filesDir.absolutePath}/${file}") | ||
copyFile(inFile, outFile) | ||
inFile.close() | ||
outFile.flush() | ||
outFile.close() | ||
} catch (e: IOException) { | ||
Log.e("tag", "Failed to copy asset file: $file", e) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.