mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
fix unable to uninstall app in Dhizuku mode
fix unable to push CI builds to Telegram
This commit is contained in:
17
app/src/main/java/android/content/pm/IPackageInstaller.java
Normal file
17
app/src/main/java/android/content/pm/IPackageInstaller.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package android.content.pm;
|
||||
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.IInterface;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
@Keep
|
||||
public interface IPackageInstaller extends IInterface {
|
||||
@Keep
|
||||
abstract class Stub extends Binder implements IPackageInstaller {
|
||||
public static IPackageInstaller asInterface(IBinder obj) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class InstallAppActivity: FragmentActivity() {
|
||||
)
|
||||
fd?.close()
|
||||
withContext(Dispatchers.Main) {
|
||||
status = "waiting"
|
||||
status = "pending"
|
||||
apkInfoText = "${context.getString(R.string.package_name)}: ${apkInfo.packageName}\n"
|
||||
apkInfoText += "${context.getString(R.string.version_name)}: ${apkInfo.versionName}\n"
|
||||
apkInfoText += "${context.getString(R.string.version_code)}: ${apkInfo.versionCode}"
|
||||
@@ -79,7 +79,7 @@ class InstallAppActivity: FragmentActivity() {
|
||||
},
|
||||
text = {
|
||||
Column {
|
||||
AnimatedVisibility(status != "waiting") {
|
||||
AnimatedVisibility(status != "pending") {
|
||||
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
Text(text = apkInfoText, modifier = Modifier.padding(top = 4.dp))
|
||||
|
||||
@@ -942,7 +942,7 @@ private fun UninstallApp(pkgName: String) {
|
||||
onClick = {
|
||||
val intent = Intent(context, PackageInstallerReceiver::class.java)
|
||||
val intentSender = PendingIntent.getBroadcast(context, 8, intent, PendingIntent.FLAG_IMMUTABLE).intentSender
|
||||
val pkgInstaller = context.packageManager.packageInstaller
|
||||
val pkgInstaller = context.getPI()
|
||||
pkgInstaller.uninstall(pkgName, intentSender)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.app.admin.SystemUpdatePolicy
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.IPackageInstaller
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.os.Build.VERSION
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
@@ -86,7 +87,7 @@ fun installPackage(context: Context, inputStream: InputStream) {
|
||||
}
|
||||
|
||||
@SuppressLint("PrivateApi")
|
||||
fun binderWrapperDevicePolicyManager(appContext: Context): DevicePolicyManager? {
|
||||
private fun binderWrapperDevicePolicyManager(appContext: Context): DevicePolicyManager? {
|
||||
try {
|
||||
val context = appContext.createPackageContext(Dhizuku.getOwnerComponent().packageName, Context.CONTEXT_IGNORE_SECURITY)
|
||||
val manager = context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
@@ -105,6 +106,40 @@ fun binderWrapperDevicePolicyManager(appContext: Context): DevicePolicyManager?
|
||||
return null
|
||||
}
|
||||
|
||||
@SuppressLint("PrivateApi")
|
||||
private fun binderWrapperPackageInstaller(appContext: Context): PackageInstaller? {
|
||||
try {
|
||||
val context = appContext.createPackageContext(Dhizuku.getOwnerComponent().packageName, Context.CONTEXT_IGNORE_SECURITY)
|
||||
val installer = context.packageManager.packageInstaller
|
||||
val field = installer.javaClass.getDeclaredField("mInstaller")
|
||||
field.isAccessible = true
|
||||
val oldInterface = field[installer] as IPackageInstaller
|
||||
if (oldInterface is DhizukuBinderWrapper) return installer
|
||||
val oldBinder = oldInterface.asBinder()
|
||||
val newBinder = binderWrapper(oldBinder)
|
||||
val newInterface = IPackageInstaller.Stub.asInterface(newBinder)
|
||||
field[installer] = newInterface
|
||||
return installer
|
||||
} catch (e: Exception) {
|
||||
dhizukuErrorStatus.value = 1
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun Context.getPI(): PackageInstaller {
|
||||
val sharedPref = this.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
if(sharedPref.getBoolean("dhizuku", false)) {
|
||||
if (!Dhizuku.isPermissionGranted()) {
|
||||
dhizukuErrorStatus.value = 2
|
||||
backToHomeStateFlow.value = true
|
||||
return this.packageManager.packageInstaller
|
||||
}
|
||||
return binderWrapperPackageInstaller(this) ?: this.packageManager.packageInstaller
|
||||
} else {
|
||||
return this.packageManager.packageInstaller
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getDPM(): DevicePolicyManager {
|
||||
val sharedPref = this.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
if(sharedPref.getBoolean("dhizuku", false)) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
@@ -101,7 +102,7 @@ private fun Home(navCtrl: NavHostController) {
|
||||
Text(
|
||||
text = stringResource(R.string.work_profile),
|
||||
style = typography.headlineLarge,
|
||||
modifier = Modifier.padding(top = 8.dp, bottom = 5.dp, start = 15.dp)
|
||||
modifier = Modifier.padding(top = 8.dp, bottom = 5.dp).offset(x = (-8).dp)
|
||||
)
|
||||
if(VERSION.SDK_INT >= 30 && context.isProfileOwner && dpm.isManagedProfile(receiver)) {
|
||||
SubPageItem(R.string.org_owned_work_profile, "", R.drawable.corporate_fare_fill0) { navCtrl.navigate("OrgOwnedWorkProfile") }
|
||||
|
||||
@@ -327,6 +327,7 @@ private fun DeviceOwner() {
|
||||
val context = LocalContext.current
|
||||
val dpm = context.getDPM()
|
||||
var deactivateDialog by remember { mutableStateOf(false) }
|
||||
var resetPolicy by remember { mutableStateOf(true) }
|
||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {
|
||||
Spacer(Modifier.padding(vertical = 10.dp))
|
||||
Text(text = stringResource(R.string.device_owner), style = typography.headlineLarge)
|
||||
@@ -357,7 +358,8 @@ private fun DeviceOwner() {
|
||||
text = {
|
||||
Column {
|
||||
if(sharedPref.getBoolean("dhizuku", false)) Text(stringResource(R.string.dhizuku_will_be_deactivated))
|
||||
Text(stringResource(R.string.will_reset_policy))
|
||||
Spacer(Modifier.padding(vertical = 4.dp))
|
||||
CheckBoxItem(text = R.string.reset_device_policy, checked = resetPolicy, operation = { resetPolicy = it })
|
||||
}
|
||||
},
|
||||
onDismissRequest = { deactivateDialog = false },
|
||||
@@ -372,7 +374,7 @@ private fun DeviceOwner() {
|
||||
TextButton(
|
||||
onClick = {
|
||||
coroutine.launch {
|
||||
context.resetDevicePolicy()
|
||||
if(resetPolicy) context.resetDevicePolicy()
|
||||
dpm.clearDeviceOwnerApp(context.dpcPackageName)
|
||||
if(sharedPref.getBoolean("dhizuku", false)) {
|
||||
if (!Dhizuku.init(context)) {
|
||||
|
||||
Reference in New Issue
Block a user