Skip to content

Commit

Permalink
Rewrite hook for force mount data
Browse files Browse the repository at this point in the history
The previous hook point is for startViaZygote(), but the logic in
ProcessList.java to determine whether a process is safe to apply
force mount is complex, and current implementation has already
caused issues. Change the hook point to PlatformCompat and force
return true for all sdk level, then we can let system server apply
the correct logic.

Vold app data isolation does not have sdk level check, so don't
touch it, unlink current code.
  • Loading branch information
aviraxp committed Oct 1, 2024
1 parent fcb89e7 commit 1de7239
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class HMAService(val pms: IPackageManager) : IHMAService.Stub() {
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
frameworkHooks.add(ZygoteArgsHook(this))
frameworkHooks.add(PlatformCompatHook(this))
}

frameworkHooks.forEach(IFrameworkHook::load)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package icu.nullptr.hidemyapplist.xposed.hook

import android.annotation.TargetApi
import android.content.pm.ApplicationInfo
import android.os.Build
import com.github.kyuubiran.ezxhelper.utils.findMethod
import com.github.kyuubiran.ezxhelper.utils.hookBefore
import de.robv.android.xposed.XC_MethodHook
import icu.nullptr.hidemyapplist.common.CommonUtils
import icu.nullptr.hidemyapplist.common.Constants.*
import icu.nullptr.hidemyapplist.xposed.HMAService
import icu.nullptr.hidemyapplist.xposed.logE
import icu.nullptr.hidemyapplist.xposed.logI

@TargetApi(Build.VERSION_CODES.S)
class ZygoteArgsHook(private val service: HMAService) : IFrameworkHook {
class PlatformCompatHook(private val service: HMAService) : IFrameworkHook {

companion object {
private const val TAG = "ZygoteArgsHook"
private const val TAG = "PlatformCompatHook"
private val sAppDataIsolationEnabled = CommonUtils.isAppDataIsolationEnabled
private val sVoldAppDataIsolationEnabled = CommonUtils.isVoldAppDataIsolationEnabled
}

private var hook: XC_MethodHook.Unhook? = null
Expand All @@ -26,19 +25,18 @@ class ZygoteArgsHook(private val service: HMAService) : IFrameworkHook {
if (!service.config.forceMountData) return
logI(TAG, "Load hook")
logI(TAG, "App data isolation enabled: $sAppDataIsolationEnabled")
logI(TAG, "Vold app data isolation enabled: $sVoldAppDataIsolationEnabled")
hook = findMethod("android.os.ZygoteProcess") {
name == "startViaZygote"
hook = findMethod("com.android.server.compat.PlatformCompat") {
name == "isChangeEnabled"
}.hookBefore { param ->
runCatching {
val uid = param.args[2] as Int
if (uid == UID_SYSTEM) return@hookBefore
val apps = service.pms.getPackagesForUid(uid) ?: return@hookBefore
val changeId = param.args[0] as Long
val appInfo = param.args[1] as ApplicationInfo
if (changeId.toInt() != 143937733) return@hookBefore
val apps = service.pms.getPackagesForUid(appInfo.uid) ?: return@hookBefore
for (app in apps) {
if (service.isHookEnabled(app)) {
if (sAppDataIsolationEnabled) param.args[20] = true // boolean bindMountAppsData
if (sVoldAppDataIsolationEnabled) param.args[21] = true // boolean bindMountAppStorageDirs
logI(TAG, "@startViaZygote force mount data: $uid $app")
if (sAppDataIsolationEnabled) param.result = true
logI(TAG, "@startViaZygote force mount data: ${appInfo.uid} $app")
return@hookBefore
}
}
Expand Down

0 comments on commit 1de7239

Please sign in to comment.