mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
fix ActivityNotFoundException
This commit is contained in:
@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.material3.MaterialTheme.colorScheme
|
||||
@@ -111,7 +112,7 @@ fun ApplicationManage(){
|
||||
}
|
||||
if(VERSION.SDK_INT>=24&&(isDeviceOwner(myDpm)||isProfileOwner(myDpm))){
|
||||
AppManageItem(
|
||||
R.string.always_on_vpn,R.string.experimental_feature,{pkgName == myDpm.getAlwaysOnVpnPackage(myComponent)}) {b->
|
||||
R.string.always_on_vpn,R.string.place_holder,{pkgName == myDpm.getAlwaysOnVpnPackage(myComponent)}) {b->
|
||||
try {
|
||||
myDpm.setAlwaysOnVpnPackage(myComponent, pkgName, b)
|
||||
} catch(e: java.lang.UnsupportedOperationException) {
|
||||
@@ -171,7 +172,11 @@ fun ApplicationManage(){
|
||||
Text(text = "用户将无法清除应用的存储空间和缓存", style = bodyTextStyle)
|
||||
Text(text = "应用列表:")
|
||||
if(listText!=""){
|
||||
Text(text = listText, style = bodyTextStyle)
|
||||
SelectionContainer {
|
||||
Text(text = listText, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
@@ -277,7 +282,13 @@ fun ApplicationManage(){
|
||||
}
|
||||
var inited by remember{mutableStateOf(false)}
|
||||
if(!inited){refresh();inited=true}
|
||||
Text(text = if(list!=""){list}else{"无"}, style = bodyTextStyle)
|
||||
if(list!=""){
|
||||
SelectionContainer {
|
||||
Text(text = list, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = {
|
||||
@@ -317,7 +328,13 @@ fun ApplicationManage(){
|
||||
if(!inited){refresh();inited=true}
|
||||
Text(text = "跨资料微件", style = typography.titleLarge, color = titleColor)
|
||||
Text(text = "(跨资料桌面小部件提供者)", style = bodyTextStyle)
|
||||
Text(text = if(list!=""){list}else{"无"}, style = bodyTextStyle)
|
||||
if(list!=""){
|
||||
SelectionContainer {
|
||||
Text(text = list, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = {
|
||||
@@ -429,7 +446,13 @@ fun ApplicationManage(){
|
||||
if(getList!=null){ permittedAccessibility = getList }
|
||||
refreshList(); inited=true
|
||||
}
|
||||
Text(text = if(listText!=""){listText}else{"无"}, style = bodyTextStyle)
|
||||
if(listText!=""){
|
||||
SelectionContainer {
|
||||
Text(text = listText, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = { permittedAccessibility.add(pkgName); refreshList()},
|
||||
@@ -473,7 +496,13 @@ fun ApplicationManage(){
|
||||
if(getList!=null){ permittedIme = getList }
|
||||
refreshList();inited=true
|
||||
}
|
||||
Text(text = if(imeListText!=""){imeListText}else{"无"}, style = bodyTextStyle)
|
||||
if(imeListText!=""){
|
||||
SelectionContainer {
|
||||
Text(text = imeListText, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = { permittedIme.add(pkgName); refreshList() },
|
||||
@@ -518,7 +547,13 @@ fun ApplicationManage(){
|
||||
if(getList!=null){ keepUninstallPkg = getList }
|
||||
refresh(); inited=true
|
||||
}
|
||||
Text(text = if(listText==""){"无"}else{listText}, style = bodyTextStyle)
|
||||
if(listText!=""){
|
||||
SelectionContainer {
|
||||
Text(text = listText, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = {
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.material3.MaterialTheme.colorScheme
|
||||
@@ -36,7 +37,7 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun DeviceControl(){
|
||||
fun SystemManage(){
|
||||
val myContext = LocalContext.current
|
||||
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
|
||||
@@ -370,7 +371,13 @@ fun DeviceControl(){
|
||||
}
|
||||
refreshWhitelist()
|
||||
Text(text = "白名单应用", style = typography.titleLarge, color = titleColor)
|
||||
if(listText!=""){ Text(listText) }else{ Text(("无")) }
|
||||
if(listText!=""){
|
||||
SelectionContainer {
|
||||
Text(text = listText, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
OutlinedTextField(
|
||||
value = inputPkg,
|
||||
onValueChange = {inputPkg=it},
|
||||
|
||||
@@ -165,7 +165,7 @@ fun MyScaffold(){
|
||||
modifier = Modifier.padding(top = it.calculateTopPadding()).imePadding()
|
||||
){
|
||||
composable(route = "HomePage", content = { HomePage(navCtrl)})
|
||||
composable(route = "DeviceControl", content = { DeviceControl()})
|
||||
composable(route = "DeviceControl", content = { SystemManage()})
|
||||
composable(route = "ManagedProfile", content = {ManagedProfile()})
|
||||
composable(route = "Permissions", content = { DpmPermissions(navCtrl)})
|
||||
composable(route = "ApplicationManage", content = { ApplicationManage()})
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.binbin.androidowner
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.app.admin.DevicePolicyManager.*
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager.NameNotFoundException
|
||||
import android.os.Build.VERSION
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
@@ -96,15 +98,19 @@ fun ManagedProfile() {
|
||||
if(VERSION.SDK_INT>=24){CheckBoxItem("跳过加密",{skipEncrypt},{skipEncrypt=!skipEncrypt})}
|
||||
Button(
|
||||
onClick = {
|
||||
val intent = Intent(ACTION_PROVISION_MANAGED_PROFILE)
|
||||
if(VERSION.SDK_INT>=23){
|
||||
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,myComponent)
|
||||
}else{
|
||||
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,"com.binbin.androidowner")
|
||||
try {
|
||||
val intent = Intent(ACTION_PROVISION_MANAGED_PROFILE)
|
||||
if(VERSION.SDK_INT>=23){
|
||||
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,myComponent)
|
||||
}else{
|
||||
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,"com.binbin.androidowner")
|
||||
}
|
||||
if(VERSION.SDK_INT>=24){intent.putExtra(EXTRA_PROVISIONING_SKIP_ENCRYPTION,skipEncrypt)}
|
||||
if(VERSION.SDK_INT>=33){intent.putExtra(EXTRA_PROVISIONING_ALLOW_OFFLINE,true)}
|
||||
createManagedProfile.launch(intent)
|
||||
}catch(e:ActivityNotFoundException){
|
||||
Toast.makeText(myContext,"不支持",Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
if(VERSION.SDK_INT>=24){intent.putExtra(EXTRA_PROVISIONING_SKIP_ENCRYPTION,skipEncrypt)}
|
||||
if(VERSION.SDK_INT>=33){intent.putExtra(EXTRA_PROVISIONING_ALLOW_OFFLINE,true)}
|
||||
createManagedProfile.launch(intent)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme.colorScheme
|
||||
@@ -32,6 +33,7 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
@@ -114,7 +116,13 @@ fun Network(){
|
||||
RadioButtonItem("白名单",{selectedPolicyType==WIFI_SSID_POLICY_TYPE_ALLOWLIST},{selectedPolicyType=WIFI_SSID_POLICY_TYPE_ALLOWLIST})
|
||||
RadioButtonItem("黑名单",{selectedPolicyType==WIFI_SSID_POLICY_TYPE_DENYLIST},{selectedPolicyType=WIFI_SSID_POLICY_TYPE_DENYLIST})
|
||||
Text("SSID列表:")
|
||||
Text(text = if(ssidList!=""){ssidList}else{"无"}, style = bodyTextStyle)
|
||||
if(ssidList!=""){
|
||||
SelectionContainer {
|
||||
Text(text = ssidList, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
OutlinedTextField(
|
||||
value = inputSsid,
|
||||
label = { Text("SSID")},
|
||||
@@ -176,7 +184,7 @@ fun Network(){
|
||||
DevicePolicyManager.PRIVATE_DNS_SET_ERROR_FAILURE_SETTING to "失败"
|
||||
)
|
||||
var status by remember{mutableStateOf(dnsStatus[myDpm.getGlobalPrivateDnsMode(myComponent)])}
|
||||
Text(text = "状态:$status")
|
||||
Text(text = "当前状态:$status")
|
||||
Button(
|
||||
onClick = {
|
||||
val result = myDpm.setGlobalPrivateDnsModeOpportunistic(myComponent)
|
||||
@@ -199,6 +207,7 @@ fun Network(){
|
||||
)
|
||||
Button(
|
||||
onClick = {
|
||||
focusMgr.clearFocus()
|
||||
val result: Int
|
||||
try{
|
||||
result = myDpm.setGlobalPrivateDnsModeSpecifiedHost(myComponent,inputHost)
|
||||
@@ -647,7 +656,7 @@ fun Network(){
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(text = "这个功能没有被全面测试过", style = bodyTextStyle)
|
||||
Text(text = stringResource(id = R.string.developing), style = bodyTextStyle)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.padding(vertical = 30.dp))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.binbin.androidowner
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@@ -443,8 +444,12 @@ fun DeviceOwnerInfo(
|
||||
}
|
||||
|
||||
fun activateDeviceAdmin(inputContext:Context,inputComponent:ComponentName){
|
||||
val intent = Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, inputComponent)
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "在这里激活Android Owner")
|
||||
startActivity(inputContext,intent,null)
|
||||
try {
|
||||
val intent = Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, inputComponent)
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "在这里激活Android Owner")
|
||||
startActivity(inputContext,intent,null)
|
||||
}catch(e:ActivityNotFoundException){
|
||||
Toast.makeText(inputContext,"不支持",Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ fun AppSetting(navCtrl:NavHostController){
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
val bodyTextStyle = if(isWear){typography.bodyMedium}else{typography.bodyLarge}
|
||||
val titleColor = colorScheme.onPrimaryContainer
|
||||
val pkgInfo = myContext.packageManager.getPackageInfo(myContext.packageName,0)
|
||||
val verCode = pkgInfo.versionCode
|
||||
val verName = pkgInfo.versionName
|
||||
Column(modifier = sections()) {
|
||||
Row(modifier = Modifier.fillMaxWidth().padding(horizontal = 3.dp),horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(text = "Wear", style = typography.titleLarge, color = titleColor)
|
||||
@@ -59,6 +62,7 @@ fun AppSetting(navCtrl:NavHostController){
|
||||
modifier = Modifier.padding(start = 8.dp, end = 8.dp, bottom = 12.dp)
|
||||
) {
|
||||
Text(text = "关于", style = typography.headlineSmall, color = titleColor)
|
||||
Text(text = "Android owner v$verName ($verCode)", style = bodyTextStyle)
|
||||
Text(text = "使用安卓的Device admin、Device owner 、Profile owner,全方位掌控你的设备", style = bodyTextStyle)
|
||||
Spacer(Modifier.padding(vertical = 4.dp))
|
||||
Text(text = "这个应用只在AOSP和LineageOS上测试过,不确保每个功能都在其它系统可用,尤其是国内的魔改系统。", style = bodyTextStyle)
|
||||
|
||||
@@ -17,6 +17,7 @@ import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Checkbox
|
||||
@@ -35,13 +36,10 @@ import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.os.UserManagerCompat
|
||||
|
||||
|
||||
var affiliationID = mutableSetOf<String>()
|
||||
@Composable
|
||||
fun UserManage() {
|
||||
Column(
|
||||
modifier = Modifier.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
|
||||
val myContext = LocalContext.current
|
||||
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
|
||||
@@ -97,19 +95,8 @@ fun UserManage() {
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = {focusMgr.clearFocus()})
|
||||
)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(15.dp))
|
||||
.clickable(enabled = VERSION.SDK_INT >= 24 && isDeviceOwner(myDpm)) { useUid = !useUid }
|
||||
.padding(end = 12.dp)
|
||||
){
|
||||
Checkbox(
|
||||
checked = useUid,
|
||||
onCheckedChange = {useUid=it},
|
||||
enabled = VERSION.SDK_INT>=24&& isDeviceOwner(myDpm)
|
||||
)
|
||||
Text(text = "使用UID(不靠谱)",modifier = Modifier.padding(bottom = 2.dp), style = bodyTextStyle)
|
||||
if(VERSION.SDK_INT>=24&&isDeviceOwner(myDpm)){
|
||||
CheckBoxItem(text = "使用UID", checked = {useUid}, operation = {idInput=""; useUid = !useUid})
|
||||
}
|
||||
if(VERSION.SDK_INT>28){
|
||||
if(isProfileOwner(myDpm)&&myDpm.isAffiliatedUser){
|
||||
@@ -224,18 +211,6 @@ fun UserManage() {
|
||||
) {
|
||||
Text("创建(Owner)")
|
||||
}
|
||||
if(UserManager.supportsMultipleUsers()&&(VERSION.SDK_INT<34||(VERSION.SDK_INT>=34&&userManager.isAdminUser))){
|
||||
Button(
|
||||
onClick = {
|
||||
val intent = UserManager.createUserCreationIntent(userName,null,null,null)
|
||||
createUser.launch(intent)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text("创建(Intent)")
|
||||
}
|
||||
Text(text = "尽量用Device owner模式创建,Intent模式可能没有效果", style = bodyTextStyle)
|
||||
}
|
||||
if(newUserHandle!=null){ Text(text = "新用户的序列号:${userManager.getSerialNumberForUser(newUserHandle)}", style = bodyTextStyle) }
|
||||
}
|
||||
}
|
||||
@@ -259,7 +234,13 @@ fun UserManage() {
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = {focusMgr.clearFocus()})
|
||||
)
|
||||
Text(text = if(list==""){"无"}else{list}, style = bodyTextStyle)
|
||||
if(list!=""){
|
||||
SelectionContainer {
|
||||
Text(text = list, style = bodyTextStyle)
|
||||
}
|
||||
}else{
|
||||
Text(text = "无", style = bodyTextStyle)
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = { affiliationID.add(input); refresh() },
|
||||
@@ -371,7 +352,7 @@ private fun UserSessionMessage(text:String, textField:String, profileOwner:Boole
|
||||
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&profileOwner),
|
||||
modifier = if(isWear){Modifier.fillMaxWidth(0.48F)}else{Modifier.fillMaxWidth(0.65F)}
|
||||
modifier = Modifier.fillMaxWidth(if(isWear){0.49F}else{0.65F})
|
||||
) {
|
||||
Text("应用")
|
||||
}
|
||||
@@ -379,11 +360,11 @@ private fun UserSessionMessage(text:String, textField:String, profileOwner:Boole
|
||||
onClick = {
|
||||
focusMgr.clearFocus()
|
||||
setMsg(null)
|
||||
msg = if(get()==null){""}else{get().toString()}
|
||||
msg = get()?.toString() ?: ""
|
||||
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&profileOwner),
|
||||
modifier = Modifier.fillMaxWidth(0.92F)
|
||||
modifier = Modifier.fillMaxWidth(0.96F)
|
||||
) {
|
||||
Text("默认")
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
<string name="disable_bt_contact_share">禁止蓝牙分享联系人</string>
|
||||
<string name="user_manage">用户管理</string>
|
||||
<string name="setting">设置</string>
|
||||
<string name="always_on_vpn">VPN常开</string>
|
||||
<string name="always_on_vpn">VPN保持打开</string>
|
||||
<string name="experimental_feature">实验性功能</string>
|
||||
<string name="max_time_to_lock">屏幕超时</string>
|
||||
<string name="max_time_to_lock_desc">超时后锁屏(毫秒),0为由用户决定</string>
|
||||
|
||||
Reference in New Issue
Block a user