Skip to content

Commit

Permalink
💥 remove deprecated function, prepare new protocol support
Browse files Browse the repository at this point in the history
  • Loading branch information
Szzrain committed Mar 25, 2024
1 parent 6df75fb commit 61787e3
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 88 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
minSdk 26
//noinspection ExpiredTargetSdkVersion
targetSdk 28
versionCode 38
versionName "v0.6.0"
versionCode 39
versionName "v0.6.1-dev"
buildConfigField "String", "DOCUMENTS_AUTHORITY", "\"com.sealdice.dice.authorities\""
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
Expand Down
83 changes: 78 additions & 5 deletions app/src/main/java/com/sealdice/dice/DebugActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Build
import android.os.Bundle
import android.view.MenuItem
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -18,9 +19,17 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader

class DebugActivity : AppCompatActivity() {
private var processBuilder: ProcessBuilder = ProcessBuilder("sh").redirectErrorStream(true)
private lateinit var process: Process
private var shellLogs = ""
private var isInit = false
private lateinit var outputStream : java.io.OutputStream
private var isRunning = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_debug)
Expand Down Expand Up @@ -50,7 +59,71 @@ class DebugActivity : AppCompatActivity() {
startActivity(intent)
}
}
findViewById<Button>(R.id.DEBUG_button_force_output_data).setOnClickListener{
findViewById<Button>(R.id.DEBUG_button_exec).setOnClickListener {
val command = findViewById<EditText>(R.id.DEBUG_edittext_command).text.toString()
if (!isInit) {
processBuilder.directory(File(this.filesDir.absolutePath))
// processBuilder.environment()["LD_LIBRARY_PATH"] = this.filesDir.absolutePath + "/sealdice/lagrange/openssl-1.1"
// processBuilder.environment()["CLR_OPENSSL_VERSION_OVERRIDE"] = "1.1"

GlobalScope.launch(context = Dispatchers.IO) {
isRunning = true
process = processBuilder.start()
outputStream = process.outputStream
outputStream.write(command.toByteArray())
outputStream.write("\n".toByteArray())
outputStream.flush()
val data = process.inputStream
val ir = BufferedReader(InputStreamReader(data))
while (isRunning) {
var line: String?
try {
line = ir.readLine()
} catch (e: Exception) {
break
}
while (line != null && isRunning) {
shellLogs += line
shellLogs += "\n"
try {
line = ir.readLine()
} catch (e: Exception) {
break
}
}
Thread.sleep(1000)
}
}
} else {
outputStream.write(command.toByteArray())
outputStream.write("\n".toByteArray())
outputStream.flush()
}
}
findViewById<Button>(R.id.DEBUG_button_get_current_dir).setOnClickListener {
val alertDialogBuilder = AlertDialog.Builder(
this, R.style.Theme_Mshell_DialogOverlay
)
alertDialogBuilder.setTitle("当前目录")
alertDialogBuilder.setMessage(this.filesDir.absolutePath)
alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int ->
}
alertDialogBuilder.create().show()
}
findViewById<Button>(R.id.DEBUG_button_console).setOnClickListener {
val alertDialogBuilder = AlertDialog.Builder(
this, R.style.Theme_Mshell_DialogOverlay
)
alertDialogBuilder.setTitle("DEBUG:Console")
alertDialogBuilder.setMessage(shellLogs)
alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int ->
}
alertDialogBuilder.create().show()
}
findViewById<Button>(R.id.DEBUG_button_remove_log).setOnClickListener {
shellLogs = ""
}
findViewById<Button>(R.id.DEBUG_button_force_output_data).setOnClickListener {
val builder: AlertDialog.Builder = AlertDialog.Builder(this, R.style.Theme_Mshell_DialogOverlay)
builder.setCancelable(false) // if you want user to wait for some process to finish,
builder.setView(R.layout.layout_loading_dialog)
Expand Down Expand Up @@ -90,25 +163,25 @@ class DebugActivity : AppCompatActivity() {
for (service in manager.getRunningServices(Int.MAX_VALUE)) {
text += service.service.className + "\n"
}
val alertDialogBuilder = androidx.appcompat.app.AlertDialog.Builder(
val alertDialogBuilder = AlertDialog.Builder(
this, R.style.Theme_Mshell_DialogOverlay
)
alertDialogBuilder.setTitle("DEBUG:Running Services")
alertDialogBuilder.setMessage(text)
alertDialogBuilder.setPositiveButton("确定") { _: android.content.DialogInterface, _: Int ->
alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int ->
}
alertDialogBuilder.create().show()
}
findViewById<Button>(R.id.DEBUG_crash).setOnClickListener {
throw Exception("DEBUG:Crash")
}
findViewById<Button>(R.id.DEBUG_button_info).setOnClickListener {
val alertDialogBuilder = androidx.appcompat.app.AlertDialog.Builder(
val alertDialogBuilder = AlertDialog.Builder(
this, R.style.Theme_Mshell_DialogOverlay
)
alertDialogBuilder.setTitle("DEBUG:Info")
alertDialogBuilder.setMessage("Version:"+BuildConfig.VERSION_NAME+"\nBuild:"+BuildConfig.VERSION_CODE+"\nPackage:"+packageName)
alertDialogBuilder.setPositiveButton("确定") { _: android.content.DialogInterface, _: Int ->
alertDialogBuilder.setPositiveButton("确定") { _: DialogInterface, _: Int ->
}
alertDialogBuilder.create().show()
}
Expand Down
53 changes: 3 additions & 50 deletions app/src/main/java/com/sealdice/dice/FirstFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import com.sealdice.dice.databinding.FragmentFirstBinding
import com.sealdice.dice.utils.Utils
import com.sealdice.dice.utils.ViewModelMain
import kotlinx.coroutines.*
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import kotlin.system.exitProcess


Expand Down Expand Up @@ -70,7 +72,7 @@ class FirstFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
val versionName = BuildConfig.VERSION_NAME
val packageName = BuildConfig.APPLICATION_ID
val sharedPreferences = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val nightModeFlags = context?.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
val isNightMode = nightModeFlags == Configuration.UI_MODE_NIGHT_YES
binding.buttonThird.setOnClickListener {
Expand Down Expand Up @@ -111,54 +113,6 @@ class FirstFragment : Fragment() {
}
alertDialogBuilder?.create()?.show()
}
binding.buttonDeviceJson.setOnClickListener {
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder?.setTitle("提示")
alertDialogBuilder?.setMessage("此操作将会生成本机的设备信息用于账号登录,点击“确定”后将申请一些权限,请全部授权否则无法正常工作,如不想使用此功能请删除sealdice文件夹内的my_device.json")
alertDialogBuilder?.setNegativeButton("取消") {_: DialogInterface, _: Int ->}
alertDialogBuilder?.setPositiveButton("确定") {_: DialogInterface, _: Int ->
val permissions = arrayOf(
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
val permissionList = ArrayList<String>()
for (permission in permissions) {
if (ContextCompat.checkSelfPermission(
requireContext(),
permission
) != PackageManager.PERMISSION_GRANTED
) {
permissionList.add(permission)
}
}
if (permissionList.isNotEmpty()) {
ActivityCompat.requestPermissions(
requireActivity(),
permissionList.toTypedArray(),
1
)
}
File(FileWrite.getPrivateFileDir(requireContext())+"sealdice/my_device.json").writeText(DeviceInfo(context).deviceInfo.toString())
val alertDialogBuilder2 = context?.let { it1 ->
AlertDialog.Builder(
it1, R.style.Theme_Mshell_DialogOverlay
)
}
alertDialogBuilder2?.setTitle("提示")
alertDialogBuilder2?.setMessage("已生成my_device.json")
alertDialogBuilder2?.setPositiveButton("确定") {_: DialogInterface, _: Int ->
}
alertDialogBuilder2?.create()?.show()
}
alertDialogBuilder?.create()?.show()
}
binding.buttonReset.setOnClickListener {
val alertDialogBuilder = context?.let { it1 ->
AlertDialog.Builder(
Expand Down Expand Up @@ -214,7 +168,6 @@ class FirstFragment : Fragment() {
binding.buttonThird.visibility = View.VISIBLE
binding.buttonConsole.visibility = View.VISIBLE
binding.buttonFirst.visibility = View.GONE
binding.buttonDeviceJson.visibility = View.GONE
if (Build.VERSION.SDK_INT >= 28) {
val permissionState =
context?.let { it1 -> ContextCompat.checkSelfPermission(it1, Manifest.permission.FOREGROUND_SERVICE) }
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/sealdice/dice/ProcessService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ class ProcessService : LifecycleService(){
} else {
processBuilder.environment()["PATH"] = "${this.filesDir.absolutePath}/sealdice"
}
process = processBuilder.start()
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
processBuilder.environment()["LD_LIBRARY_PATH"] = this.filesDir.absolutePath + sharedPreferences.getString("ld_library_path", "/sealdice/lagrange/openssl-1.1")
processBuilder.environment()["CLR_OPENSSL_VERSION_OVERRIDE"] = "1.1"
process = processBuilder.start()
val args = sharedPreferences.getString("launch_args", "")
val cmd = "cd sealdice&&./sealdice-core $args"
GlobalScope.launch(context = Dispatchers.IO) {
Expand Down
65 changes: 62 additions & 3 deletions app/src/main/res/layout/activity_debug.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
Expand All @@ -17,6 +17,65 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="@+id/DEBUG_edittext_command"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="450dp"
android:autofillHints="请输入要执行的指令"
android:hint="@string/exec_command_hint"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:inputType="text" />

<Button
android:id="@+id/DEBUG_button_exec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="500dp"
android:background="?attr/seal_buttonColor"
android:text="执行指令"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/DEBUG_button_get_current_dir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="560dp"
android:background="?attr/seal_buttonColor"
android:text="获取当前目录"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/DEBUG_button_console"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="500dp"
android:background="?attr/seal_buttonColor"
android:text="显示日志"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.154"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/DEBUG_button_remove_log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="500dp"
android:background="?attr/seal_buttonColor"
android:text="清除日志"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.845"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/DEBUG_button_abis"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -94,7 +153,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="500dp"
android:layout_marginTop="650dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@mipmap/ic_launcher"
Expand Down
18 changes: 5 additions & 13 deletions app/src/main/res/layout/fragment_first.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="com.sealdice.dice.BuildConfig" />
</data>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
Expand All @@ -24,6 +24,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_second" />


<Button
android:id="@+id/button_first"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -56,16 +57,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_device_json"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="345dp"
android:background="?attr/seal_buttonColor"
android:text="生成设备信息"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_third"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -124,6 +115,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button_exit"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
<string name="review">问题反馈</string>
<string name="repo">项目地址</string>
<string name="action_manual">使用手册</string>
<string name="exec_command_hint"><![CDATA[cd sealdice&&./sealdice]]></string>
</resources>
8 changes: 4 additions & 4 deletions app/src/main/res/xml/backup_rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
See https://developer.android.com/about/versions/12/backup-restore
-->
<full-backup-content>
<!--
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="device.xml"/>
-->

<!-- <include domain="sharedpref" path="."/>-->
<!-- <exclude domain="sharedpref" path="device.xml"/>-->

</full-backup-content>
Loading

0 comments on commit 61787e3

Please sign in to comment.