Skip to content

Commit

Permalink
Add UI to export cmd tool files
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Mar 21, 2021
1 parent cfd5a79 commit 87b60fd
Show file tree
Hide file tree
Showing 23 changed files with 416 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cmd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android.applicationVariants.all { variant ->

def outDir = new File(rootDir, "out")
def mappingPath = new File(outDir, "mapping").absolutePath
def dexPath = new File(outDir, "cmd").absolutePath
def dexPath = "${rootProject.rootDir.path}/manager/src/main/assets"
variant.assembleProvider.get().doLast {
if (variant.getBuildType().isMinifyEnabled()) {
copy {
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/main/java/rikka/shizuku/cmd/ShizukuCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static void main(String[] args) {
packageName = "com.android.shell";
} else {
packageName = System.getenv("SHIZUKU_APPLICATION_ID");
if (TextUtils.isEmpty(packageName)) {
if (TextUtils.isEmpty(packageName) || "PKG".equals(packageName)) {
abort("SHIZUKU_APPLICATION_ID is not set, set this environment variable to the id of current application (package name)");
}
}
Expand Down
5 changes: 4 additions & 1 deletion manager/aapt2-resources.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ color/material_teal_50#no_obfuscate
color/material_cyan_50#no_obfuscate
color/material_blue_50#no_obfuscate
color/material_blue_grey_50#no_obfuscate
color/material_deep_purple_50#no_obfuscate

color/material_orange_100#no_obfuscate
color/material_indigo_100#no_obfuscate
Expand All @@ -13,11 +14,13 @@ color/material_teal_100#no_obfuscate
color/material_cyan_100#no_obfuscate
color/material_blue_100#no_obfuscate
color/material_blue_grey_100#no_obfuscate
color/material_deep_purple_100#no_obfuscate

color/material_orange_600#no_obfuscate
color/material_indigo_600#no_obfuscate
color/material_blue_grey_600#no_obfuscate
color/material_teal_600#no_obfuscate
color/material_cyan_600#no_obfuscate
color/material_blue_600#no_obfuscate
color/material_blue_grey_600#no_obfuscate
color/material_blue_grey_600#no_obfuscate
color/material_deep_purple_600#no_obfuscate
3 changes: 3 additions & 0 deletions manager/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<activity
android:name=".management.ApplicationManagementActivity"
android:label="@string/home_app_management_title" />
<activity
android:name=".cmd.TerminalTutorialActivity"
android:label="@string/home_terminal_title" />
<activity
android:name=".settings.SettingsActivity"
android:label="@string/settings_title" />
Expand Down
10 changes: 3 additions & 7 deletions scripts/cmd.sh → manager/src/main/assets/shizuku
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ BASEDIR=$(dirname "$0")
DEX="$BASEDIR"/shizuku.dex

if [ ! -f "$DEX" ]; then
echo "Cannot find $DEX, please check post-install.sh"
echo "Cannot find $DEX, please check the tutorial in Shizuku app"
exit 1
fi

if [ ! -r "$DEX" ]; then
echo "Cannot read $DEX, please check post-install.sh"
exit 1
fi

export SHIZUKU_APPLICATION_ID=""
# Replace "PKG" with the application id of your terminal app
export SHIZUKU_APPLICATION_ID="PKG"
/system/bin/app_process -Djava.class.path="$DEX" /system/bin --nice-name=sui_wrapper rikka.shizuku.cmd.ShizukuCmd "$@"
7 changes: 7 additions & 0 deletions manager/src/main/java/moe/shizuku/manager/app/AppActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ abstract class AppActivity : MaterialActivity() {
}
}

override fun onSupportNavigateUp(): Boolean {
if (!super.onSupportNavigateUp()) {
finish()
}
return true
}

companion object {
private var sFontInitialized = false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package moe.shizuku.manager.cmd

import android.net.Uri
import android.os.Bundle
import android.provider.DocumentsContract
import androidx.activity.result.contract.ActivityResultContracts
import moe.shizuku.manager.R
import moe.shizuku.manager.app.AppBarActivity
import moe.shizuku.manager.databinding.TerminalTutorialActivityBinding
import moe.shizuku.manager.ktx.toHtml
import rikka.widget.borderview.BorderView

class TerminalTutorialActivity : AppBarActivity() {

private val openDocumentsTree = registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { tree: Uri? ->
if (tree == null) return@registerForActivityResult

val cr = contentResolver
val doc = DocumentsContract.buildDocumentUriUsingTree(tree, DocumentsContract.getTreeDocumentId(tree))
val child = DocumentsContract.buildChildDocumentsUriUsingTree(tree, DocumentsContract.getTreeDocumentId(tree))

cr.query(child, arrayOf(DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME), null, null, null)?.use {
while (it.moveToNext()) {
val id = it.getString(0)
val name = it.getString(1)
if (name == "shizuku" || name == "shizuku.dex") {
DocumentsContract.deleteDocument(cr, DocumentsContract.buildDocumentUriUsingTree(tree, id))
}
}
}

fun writeToDocument(name: String) {
DocumentsContract.createDocument(contentResolver, doc, "application/octet-stream", name)?.runCatching {
cr.openOutputStream(this)?.let { assets.open(name).copyTo(it) }
}
}

writeToDocument("shizuku")
writeToDocument("shizuku.dex")
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val binding = TerminalTutorialActivityBinding.inflate(layoutInflater)
setContentView(binding.root)

appBar?.setDisplayHomeAsUpEnabled(true)

binding.apply {
scrollView.borderVisibilityChangedListener = BorderView.OnBorderVisibilityChangedListener { top: Boolean, _: Boolean, _: Boolean, _: Boolean -> appBar?.setRaised(!top) }

val shizukuName = "<font face=\"monospace\">shizuku</font>"
val shizukuDexName = "<font face=\"monospace\">shizuku.dex</font>"

text1.text = getString(R.string.terminal_tutorial_1, shizukuName, shizukuDexName).toHtml()

text2.text = getString(R.string.terminal_tutorial_2, shizukuName).toHtml()
summary2.text = getString(
R.string.terminal_tutorial_2_description,
"Termux",
"<font face=\"monospace\">PKG</font>",
"<font face=\"monospace\">com.termux</font>",
"<font face=\"monospace\">com.termux</font>",
).toHtml()

text3.text = getString(
R.string.terminal_tutorial_3,
"<font face=\"monospace\">sh shizuku</font>",
).toHtml()
summary3.text = getString(R.string.terminal_tutorial_3_description,
shizukuName, "<font face=\"monospace\">PATH</font>"
).toHtml()

button1.setOnClickListener { openDocumentsTree.launch(null) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ abstract class HomeActivity : AppBarActivity() {

Shizuku.addBinderReceivedListenerSticky(binderReceivedListener)
Shizuku.addBinderDeadListener(binderDeadListener)

logd("onCreate")
}

override fun onResume() {
Expand Down
5 changes: 3 additions & 2 deletions manager/src/main/java/moe/shizuku/manager/home/HomeAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class HomeAdapter(private val homeModel: HomeViewModel, private val appsModel: A

clear()
addItem(ServerStatusViewHolder.CREATOR, status, 0)
addItem(ManageAppsViewHolder.CREATOR, Pair(status, grantedCount), 1)
addItem(ManageAppsViewHolder.CREATOR, status to grantedCount, 1)
addItem(TerminalViewHolder.CREATOR, status, 1)
if (Process.myUid() / 100000 == 0) {
val root = ShizukuSettings.getLastLaunchMode() == LaunchMethod.ROOT || isRooted()
val root = isRooted()
val rootRestart = running && status.uid == 0
when {
root && BuildUtils.atLeast30 -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package moe.shizuku.manager.home

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import moe.shizuku.manager.R
import moe.shizuku.manager.cmd.TerminalTutorialActivity
import moe.shizuku.manager.databinding.HomeTerminalBinding
import moe.shizuku.manager.model.ServiceStatus
import rikka.recyclerview.BaseViewHolder
import rikka.recyclerview.BaseViewHolder.Creator

class TerminalViewHolder(private val binding: HomeTerminalBinding) : BaseViewHolder<ServiceStatus>(binding.root), View.OnClickListener {

companion object {
val CREATOR = Creator<ServiceStatus> { inflater: LayoutInflater, parent: ViewGroup? -> TerminalViewHolder(HomeTerminalBinding.inflate(inflater, parent, false)) }
}

init {
itemView.setOnClickListener(this)
}

private inline val summary get() = binding.text2

override fun onBind() {
val context = itemView.context
if (!data.isRunning) {
itemView.isEnabled = false
summary.text = context.getString(R.string.home_status_service_not_running, context.getString(R.string.app_name))
} else {
itemView.isEnabled = true
summary.text = context.getString(R.string.home_terminal_description)
}
}

override fun onClick(v: View) {
v.context.startActivity(Intent(v.context, TerminalTutorialActivity::class.java))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ class ApplicationManagementActivity : AppBarActivity() {
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
} else if (item.itemId == R.id.action_view_apps) {
if (item.itemId == R.id.action_view_apps) {
CustomTabsHelper.launchUrlOrCopy(this, Helps.APPS.get())
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,4 @@ class SettingsActivity : AppBarFragmentActivity() {
.commit()
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ class StarterActivity : AppBarActivity() {
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
}
return super.onOptionsItemSelected(item)
}

companion object {

const val EXTRA_IS_ROOT = "$EXTRA.IS_ROOT"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M10,7H14V17H12V9H10V7M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4Z" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M9,7H13A2,2 0 0,1 15,9V11A2,2 0 0,1 13,13H11V15H15V17H11L9,17V13A2,2 0 0,1 11,11H13V9H9V7M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4Z" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M15,15A2,2 0 0,1 13,17H9V15H13V13H11V11H13V9H9V7H13A2,2 0 0,1 15,9V10.5A1.5,1.5 0 0,1 13.5,12A1.5,1.5 0 0,1 15,13.5V15M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4Z" />
</vector>
8 changes: 8 additions & 0 deletions manager/src/main/res/drawable/ic_terminal_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M20,19V7H4V19H20M20,3A2,2 0 0,1 22,5V19A2,2 0 0,1 20,21H4A2,2 0 0,1 2,19V5C2,3.89 2.9,3 4,3H20M13,17V15H18V17H13M9.58,13L5.57,9H8.4L11.7,12.3C12.09,12.69 12.09,13.33 11.7,13.72L8.42,17H5.59L9.58,13Z" />
</vector>
43 changes: 43 additions & 0 deletions manager/src/main/res/layout/home_terminal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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:gravity="center_vertical"
android:orientation="horizontal">

<moe.shizuku.manager.widget.MaterialCircleIconView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:importantForAccessibility="no"
android:src="@drawable/ic_terminal_24"
app:iconColorName="deep_purple" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:duplicateParentState="true"
android:orientation="vertical">

<TextView
android:id="@android:id/text1"
style="@style/CardTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:text="@string/home_terminal_title" />

<TextView
android:id="@android:id/text2"
style="@style/CardSummary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
tools:text="@string/home_terminal_description" />

</LinearLayout>

</LinearLayout>
Loading

0 comments on commit 87b60fd

Please sign in to comment.