Skip to content

Commit

Permalink
Merge branch 'pascua28:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zelodev authored Oct 15, 2024
2 parents bd847ed + f6bdd5e commit 554c183
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 73 deletions.
16 changes: 14 additions & 2 deletions manager/src/main/java/moe/shizuku/manager/home/HomeAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package moe.shizuku.manager.home

import android.content.pm.PackageManager
import android.os.Build
import moe.shizuku.manager.application
import moe.shizuku.manager.management.AppsViewModel
import moe.shizuku.manager.utils.EnvironmentUtils
import moe.shizuku.manager.utils.UserHandleCompat
Expand All @@ -24,8 +26,9 @@ class HomeAdapter(private val homeModel: HomeViewModel, private val appsModel: A
private const val ID_START_ROOT = 3L
private const val ID_START_WADB = 4L
private const val ID_START_ADB = 5L
private const val ID_LEARN_MORE = 6L
private const val ID_ADB_PERMISSION_LIMITED = 7L
private const val ID_START_SYSTEM = 6L
private const val ID_LEARN_MORE = 7L
private const val ID_ADB_PERMISSION_LIMITED = 8L
}

override fun onCreateCreatorPool(): IndexCreatorPool {
Expand Down Expand Up @@ -54,6 +57,15 @@ class HomeAdapter(private val homeModel: HomeViewModel, private val appsModel: A
if (isPrimaryUser) {
val root = EnvironmentUtils.isRooted()
val rootRestart = running && status.uid == 0
val system : Boolean = try {
application.applicationContext.packageManager.getPackageInfo("com.sdet.fotaagent", 0)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}

if (system)
addItem(StartSystemViewHolder.CREATOR, rootRestart, ID_START_SYSTEM)

if (root) {
addItem(StartRootViewHolder.CREATOR, rootRestart, ID_START_ROOT)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package moe.shizuku.manager.home

import android.content.Intent
import android.text.method.LinkMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import moe.shizuku.manager.R
import moe.shizuku.manager.databinding.HomeItemContainerBinding
import moe.shizuku.manager.databinding.HomeStartSystemBinding
import moe.shizuku.manager.ktx.toHtml
import moe.shizuku.manager.starter.StarterActivity
import rikka.html.text.HtmlCompat
import rikka.recyclerview.BaseViewHolder
import rikka.recyclerview.BaseViewHolder.Creator

class StartSystemViewHolder(private val binding: HomeStartSystemBinding, system: View) :
BaseViewHolder<Boolean>(system) {

companion object {
val CREATOR = Creator<Boolean> { inflater: LayoutInflater, parent: ViewGroup? ->
val outer = HomeItemContainerBinding.inflate(inflater, parent, false)
val inner = HomeStartSystemBinding.inflate(inflater, outer.root, true)
StartSystemViewHolder(inner, outer.root)
}
}

private inline val start get() = binding.button1

private var alertDialog: AlertDialog? = null

init {
val listener = View.OnClickListener { v: View -> onStartClicked(v) }
start.setOnClickListener(listener)
binding.text1.movementMethod = LinkMovementMethod.getInstance()
}

private fun onStartClicked(v: View) {
val context = v.context
val intent = Intent(context, StarterActivity::class.java).apply {
putExtra(StarterActivity.EXTRA_IS_ROOT, false)
putExtra(StarterActivity.EXTRA_IS_SYSTEM, true)
}
context.startActivity(intent)
}

override fun onBind() {
start.isEnabled = true
if (data!!) {
start.visibility = View.GONE
} else {
start.visibility = View.VISIBLE
}

val sb = StringBuilder()
.append(
context.getString(
R.string.home_system_description
)
)

binding.text1.text = sb.toHtml(HtmlCompat.FROM_HTML_OPTION_TRIM_WHITESPACE)
}

override fun onRecycle() {
super.onRecycle()
alertDialog = null
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package moe.shizuku.manager.starter

import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.LiveData
Expand All @@ -22,12 +24,10 @@ import moe.shizuku.manager.adb.PreferenceAdbKeyStore
import moe.shizuku.manager.app.AppBarActivity
import moe.shizuku.manager.application
import moe.shizuku.manager.databinding.StarterActivityBinding
import moe.shizuku.manager.ktx.createDeviceProtectedStorageContextCompat
import rikka.lifecycle.Resource
import rikka.lifecycle.Status
import rikka.lifecycle.viewModels
import rikka.shizuku.Shizuku
import java.io.File
import java.net.ConnectException
import javax.net.ssl.SSLProtocolException

Expand All @@ -39,6 +39,7 @@ class StarterActivity : AppBarActivity() {
ViewModel(
this,
intent.getBooleanExtra(EXTRA_IS_ROOT, true),
intent.getBooleanExtra(EXTRA_IS_SYSTEM, false),
intent.getStringExtra(EXTRA_HOST),
intent.getIntExtra(EXTRA_PORT, 0)
)
Expand Down Expand Up @@ -99,13 +100,14 @@ class StarterActivity : AppBarActivity() {

companion object {

const val EXTRA_IS_SYSTEM = "$EXTRA.IS_SYSTEM"
const val EXTRA_IS_ROOT = "$EXTRA.IS_ROOT"
const val EXTRA_HOST = "$EXTRA.HOST"
const val EXTRA_PORT = "$EXTRA.PORT"
}
}

private class ViewModel(context: Context, root: Boolean, host: String?, port: Int) : androidx.lifecycle.ViewModel() {
private class ViewModel(context: Context, root: Boolean, isSystem: Boolean, host: String?, port: Int) : androidx.lifecycle.ViewModel() {

private val sb = StringBuilder()
private val _output = MutableLiveData<Resource<StringBuilder>>()
Expand All @@ -117,6 +119,8 @@ private class ViewModel(context: Context, root: Boolean, host: String?, port: In
if (root) {
//Starter.writeFiles(context)
startRoot()
} else if (isSystem) {
startSys()
} else {
startAdb(host!!, port)
}
Expand Down Expand Up @@ -168,6 +172,40 @@ private class ViewModel(context: Context, root: Boolean, host: String?, port: In
}
}

private fun startSys() {
sb.append("Starting with system...").append('\n').append('\n')
postResult()

GlobalScope.launch(Dispatchers.IO) {
val intent = Intent().apply {
setClassName("com.sdet.fotaagent", "com.sdet.fotaagent.Main")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
application.applicationContext.startActivity(intent)

val mIntent = Intent("com.sdet.fotaagent.intent.CP_FILE")
mIntent.putExtra("CP_FILE", "/data")
mIntent.putExtra("CP_LOC", "; " + application.applicationInfo.nativeLibraryDir
+ "/libshizuku.so" + "; am force-stop com.sdet.fotaagent")
try {
Thread.sleep(1000)
application.applicationContext.sendBroadcast(mIntent)
sb.append("Start system success!").append('\n').append('\n')
postResult()

sb.append("info: shizuku_starter exit with 0")
postResult()

return@launch
} catch (e: InterruptedException) {
e.printStackTrace()
sb.append("Start system failed!").append('\n')
postResult()
return@launch
}
}
}

private fun startAdb(host: String, port: Int) {
sb.append("Starting with wireless adb...").append('\n').append('\n')
postResult()
Expand Down
59 changes: 59 additions & 0 deletions manager/src/main/res/layout/home_start_system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="?homeCardStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">

<ImageView
android:id="@android:id/icon"
style="@style/CardIcon"
android:duplicateParentState="true"
android:importantForAccessibility="no"
android:src="@drawable/ic_root_24dp" />

<TextView
android:id="@android:id/title"
style="@style/CardTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/home_icon_padding"
android:layout_weight="1"
android:text="@string/home_system_title" />

</LinearLayout>

<TextView
android:id="@android:id/text1"
style="@style/CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
tools:text="@string/home_system_description" />

<com.google.android.material.button.MaterialButton
android:id="@android:id/button1"
style="@style/CardButton"
android:enabled="false"
android:text="@string/home_root_button_start"
app:icon="@drawable/ic_server_start_24dp" />

<com.google.android.material.button.MaterialButton
android:id="@android:id/button2"
style="@style/CardButton"
android:enabled="false"
android:text="@string/home_root_button_restart"
android:visibility="gone"
app:icon="@drawable/ic_server_restart"
tools:visibility="visible" />

</LinearLayout>
Loading

0 comments on commit 554c183

Please sign in to comment.