mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
@@ -67,11 +67,7 @@
|
||||
<receiver
|
||||
android:name=".PackageInstallerReceiver"
|
||||
android:description="@string/app_name"
|
||||
android:permission="android.permission.BIND_DEVICE_ADMIN"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.bintianqi.owndroid.PKG_INSTALL_RESULT"/>
|
||||
</intent-filter>
|
||||
android:permission="android.permission.BIND_DEVICE_ADMIN">
|
||||
</receiver>
|
||||
<provider
|
||||
android:name="rikka.shizuku.ShizukuProvider"
|
||||
|
||||
@@ -55,12 +55,10 @@ class MainActivity : ComponentActivity() {
|
||||
getCaCert = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
uriToStream(applicationContext,it.data?.data){stream->
|
||||
caCert = stream.readBytes()
|
||||
if(caCert.size>50000){ Toast.makeText(applicationContext, "太大了", Toast.LENGTH_SHORT).show(); caCert = byteArrayOf() }
|
||||
if(caCert.size>5000){ Toast.makeText(applicationContext, R.string.file_too_large, Toast.LENGTH_SHORT).show(); caCert = byteArrayOf() }
|
||||
}
|
||||
}
|
||||
createManagedProfile = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if(it.resultCode==Activity.RESULT_CANCELED){Toast.makeText(applicationContext, "用户已取消", Toast.LENGTH_SHORT).show()}
|
||||
}
|
||||
createManagedProfile = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
|
||||
addDeviceAdmin = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
val myDpm = applicationContext.getSystemService(DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
if(myDpm.isAdminActive(ComponentName(applicationContext, Receiver::class.java))){
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInstaller.*
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import com.bintianqi.owndroid.dpm.isDeviceOwner
|
||||
@@ -36,19 +37,20 @@ class Receiver : DeviceAdminReceiver() {
|
||||
|
||||
class PackageInstallerReceiver:BroadcastReceiver(){
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val toastText = when(intent.getIntExtra(EXTRA_STATUS,666)){
|
||||
STATUS_PENDING_USER_ACTION->"等待用户交互"
|
||||
STATUS_SUCCESS->context.getString(R.string.success)
|
||||
STATUS_FAILURE->context.getString(R.string.fail)
|
||||
STATUS_FAILURE_BLOCKED->"失败:被阻止"
|
||||
STATUS_FAILURE_ABORTED->"失败:被打断"
|
||||
STATUS_FAILURE_INVALID->"失败:无效"
|
||||
STATUS_FAILURE_CONFLICT->"失败:冲突"
|
||||
STATUS_FAILURE_STORAGE->"失败:空间不足"
|
||||
STATUS_FAILURE_INCOMPATIBLE->"失败:不兼容"
|
||||
STATUS_FAILURE_TIMEOUT->"失败:超时"
|
||||
else->context.getString(R.string.unknown)
|
||||
val toastText = when(intent.getIntExtra(EXTRA_STATUS,999)){
|
||||
STATUS_PENDING_USER_ACTION->R.string.status_pending_action
|
||||
STATUS_SUCCESS->R.string.success
|
||||
STATUS_FAILURE->R.string.fail
|
||||
STATUS_FAILURE_BLOCKED->R.string.status_fail_blocked
|
||||
STATUS_FAILURE_ABORTED->R.string.status_fail_aborted
|
||||
STATUS_FAILURE_INVALID->R.string.status_fail_invalid
|
||||
STATUS_FAILURE_CONFLICT->R.string.status_fail_conflict
|
||||
STATUS_FAILURE_STORAGE->R.string.status_fail_storage
|
||||
STATUS_FAILURE_INCOMPATIBLE->R.string.status_fail_incompatible
|
||||
STATUS_FAILURE_TIMEOUT->R.string.status_fail_timeout
|
||||
else->R.string.unknown
|
||||
}
|
||||
Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show()
|
||||
Log.e("OwnDroid", intent.getIntExtra(EXTRA_STATUS,999).toString())
|
||||
if(toastText!=999){Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show()}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,11 @@ fun uriToStream(
|
||||
try{
|
||||
val stream = context.contentResolver.openInputStream(uri)
|
||||
if(stream!=null) { operation(stream) }
|
||||
else{ Toast.makeText(context, "空的流", Toast.LENGTH_SHORT).show() }
|
||||
stream?.close()
|
||||
}
|
||||
catch(e: FileNotFoundException){ Toast.makeText(context, "文件不存在", Toast.LENGTH_SHORT).show() }
|
||||
catch(e: IOException){ Toast.makeText(context, "IO异常", Toast.LENGTH_SHORT).show() }
|
||||
}else{ Toast.makeText(context, "空URI", Toast.LENGTH_SHORT).show() }
|
||||
catch(e: FileNotFoundException){ Toast.makeText(context, R.string.file_not_exist, Toast.LENGTH_SHORT).show() }
|
||||
catch(e: IOException){ Toast.makeText(context, R.string.io_exception, Toast.LENGTH_SHORT).show() }
|
||||
}
|
||||
}
|
||||
|
||||
fun List<Any>.toText():String{
|
||||
|
||||
@@ -632,7 +632,11 @@ private fun PermittedAccessibility(pkgName: String){
|
||||
Button(
|
||||
onClick = {
|
||||
focusMgr.clearFocus()
|
||||
Toast.makeText(myContext, if(myDpm.setPermittedAccessibilityServices(myComponent, permittedAccessibility)){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(
|
||||
myContext,
|
||||
if(myDpm.setPermittedAccessibilityServices(myComponent, permittedAccessibility)){R.string.success}else{R.string.fail},
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
val getList = myDpm.getPermittedAccessibilityServices(myComponent)
|
||||
if(getList!=null){ permittedAccessibility = getList }
|
||||
listText = permittedAccessibility.toText()
|
||||
@@ -683,7 +687,11 @@ private fun PermittedIME(pkgName: String){
|
||||
Button(
|
||||
onClick = {
|
||||
focusMgr.clearFocus()
|
||||
Toast.makeText(myContext, if(myDpm.setPermittedInputMethods(myComponent, permittedIme)){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(
|
||||
myContext,
|
||||
if(myDpm.setPermittedInputMethods(myComponent, permittedIme)){R.string.success}else{R.string.fail},
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
val getList = myDpm.getPermittedInputMethods(myComponent)
|
||||
if(getList!=null){ permittedIme = getList }
|
||||
imeListText = permittedIme.toText()
|
||||
@@ -901,6 +909,7 @@ private fun installPackage(context: Context, inputStream: InputStream){
|
||||
session.fsync(out)
|
||||
inputStream.close()
|
||||
out.close()
|
||||
val pendingIntent = PendingIntent.getBroadcast(context, sessionId, Intent(context, PackageInstallerReceiver::class.java), PendingIntent.FLAG_IMMUTABLE).intentSender
|
||||
val intent = Intent(context, PackageInstallerReceiver::class.java)
|
||||
val pendingIntent = PendingIntent.getBroadcast(context, sessionId, intent, PendingIntent.FLAG_IMMUTABLE).intentSender
|
||||
session.commit(pendingIntent)
|
||||
}
|
||||
|
||||
@@ -792,7 +792,7 @@ private fun APN(){
|
||||
Button(
|
||||
onClick = {
|
||||
val success = myDpm.removeOverrideApn(myComponent,id)
|
||||
Toast.makeText(myContext, if(success){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(myContext, if(success){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
Modifier.fillMaxWidth(0.96F)
|
||||
){
|
||||
|
||||
@@ -282,7 +282,7 @@ private fun BugReport(){
|
||||
Button(
|
||||
onClick = {
|
||||
val result = myDpm.requestBugreport(myComponent)
|
||||
Toast.makeText(myContext, if(result){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(myContext, if(result){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
enabled = isDeviceOwner(myDpm)
|
||||
@@ -428,7 +428,7 @@ private fun NearbyStreamingPolicy(){
|
||||
Button(
|
||||
onClick = {
|
||||
myDpm.nearbyAppStreamingPolicy = appPolicy
|
||||
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
@@ -844,7 +844,7 @@ private fun SysUpdatePolicy(){
|
||||
else->null
|
||||
}
|
||||
myDpm.setSystemUpdatePolicy(myComponent,policy)
|
||||
Toast.makeText(myContext, "成功!", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(myContext, R.string.success, Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
|
||||
@@ -302,7 +302,7 @@ private fun CreateUser(){
|
||||
onClick = {
|
||||
newUserHandle=myDpm.createAndManageUser(myComponent,userName,myComponent,null,selectedFlag)
|
||||
focusMgr.clearFocus()
|
||||
Toast.makeText(myContext, if(newUserHandle!=null){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(myContext, if(newUserHandle!=null){R.string.success}else{R.string.fail}, Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
<string name="copy_command">复制代码</string>
|
||||
<string name="unknown_status">未知状态</string>
|
||||
<string name="copy">复制</string>
|
||||
<string name="file_too_large">文件太大了</string>
|
||||
<string name="file_not_exist">文件不存在</string>
|
||||
<string name="io_exception">IO异常</string>
|
||||
|
||||
<!--Permissions-->
|
||||
<string name="click_to_activate">点击以激活</string>
|
||||
@@ -277,6 +280,15 @@
|
||||
<string name="select_apk" tools:ignore="TypographyEllipsis">选择APK...</string>
|
||||
<string name="silent_install">静默安装</string>
|
||||
<string name="request_install">请求安装</string>
|
||||
<string name="app_installer_status">应用安装器:</string>
|
||||
<string name="status_pending_action">等待用户操作</string>
|
||||
<string name="status_fail_blocked">被阻止</string>
|
||||
<string name="status_fail_aborted">被打断</string>
|
||||
<string name="status_fail_invalid">无效APK</string>
|
||||
<string name="status_fail_conflict">冲突</string>
|
||||
<string name="status_fail_storage">空间不足</string>
|
||||
<string name="status_fail_incompatible">不兼容</string>
|
||||
<string name="status_fail_timeout">超时</string>
|
||||
|
||||
<!--UserRestriction-->
|
||||
<string name="user_restrict">用户限制</string>
|
||||
|
||||
@@ -46,6 +46,9 @@
|
||||
<string name="not_exist">Not exist</string>
|
||||
<string name="unknown_status">Unknown status</string>
|
||||
<string name="copy">Copy</string>
|
||||
<string name="file_too_large">File too large</string>
|
||||
<string name="file_not_exist">File not exist</string>
|
||||
<string name="io_exception">IO Exception</string>
|
||||
|
||||
<!--Permissions-->
|
||||
<string name="click_to_activate">Click to activate</string>
|
||||
@@ -291,6 +294,16 @@
|
||||
<string name="select_apk" tools:ignore="TypographyEllipsis">Select APK...</string>
|
||||
<string name="silent_install">Silent install</string>
|
||||
<string name="request_install">Request install</string>
|
||||
<!--App install session status-->
|
||||
<string name="app_installer_status">App installer:</string>
|
||||
<string name="status_pending_action">Pending user action</string>
|
||||
<string name="status_fail_blocked">Fail: blocked</string>
|
||||
<string name="status_fail_aborted">Fail: aborted</string>
|
||||
<string name="status_fail_invalid">Fail: invalid APK</string>
|
||||
<string name="status_fail_conflict">Fail: conflict</string>
|
||||
<string name="status_fail_storage">Fail: no space</string>
|
||||
<string name="status_fail_incompatible">Fail: incompatible</string>
|
||||
<string name="status_fail_timeout">Fail: timeout</string>
|
||||
|
||||
<!--UserRestriction-->
|
||||
<string name="user_restrict">User restriction</string>
|
||||
|
||||
Reference in New Issue
Block a user