Skip to content

Commit

Permalink
fix: loss root after reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
bmax committed Jan 18, 2024
1 parent 159875c commit 86e7698
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/me/bmax/apatch/services/RootServices.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.bmax.apatch.services;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
Expand All @@ -19,7 +18,6 @@
import java.util.List;

import me.bmax.apatch.IAPRootService;
import me.bmax.apatch.Natives;
import rikka.parcelablelist.ParcelableListSlice;

public class RootServices extends RootService {
Expand All @@ -32,6 +30,7 @@ public ParcelableListSlice<PackageInfo> getPackages(int flags) {
Log.i(TAG, "getPackages: " + list.size());
return new ParcelableListSlice<>(list);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import me.bmax.apatch.util.HanziToPinyin
import me.bmax.apatch.util.PkgConfig
import java.text.Collator
import java.util.*
import kotlin.collections.HashMap
import kotlin.concurrent.thread
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

Expand Down Expand Up @@ -121,7 +123,12 @@ class SuperUserViewModel : ViewModel() {
val uids = Natives.suUids().toList()
Log.d(TAG, "all allows: ${uids}")

val configs: HashMap<String, PkgConfig.Config> = PkgConfig.configs
var configs: HashMap<String, PkgConfig.Config> = HashMap()
thread {
Natives.su()
configs = PkgConfig.readConfigs()
}.join()

Log.d(TAG, "all configs: ${configs}")

apps = allPackages.list.map { it ->
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/me/bmax/apatch/util/PkgConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ object PkgConfig {

private val CSV_HEADER = "pkg,exclude,allow,uid,to_uid,sctx"

val configs: HashMap<String, Config> = readConfigs()

@Immutable
@Parcelize
@Keep
Expand All @@ -46,26 +44,30 @@ object PkgConfig {
}
}

private fun readConfigs(): HashMap<String,Config> {
public fun readConfigs(): HashMap<String,Config> {
val configs = HashMap<String,Config>()
val file = File(APApplication.PACKAGE_CONFIG_FILE)
if(file.exists()) {
file.readLines().drop(1).filter { !it.isEmpty() }.forEach {
Log.d(TAG, it)
val p = Config.fromLine(it)
configs[p.pkg] = p
if(! p.isDefault()) {
configs[p.pkg] = p
}
}
}
return configs
}

private fun writeConfigs() {
private fun writeConfigs(configs: HashMap<String,Config> ) {
val file = File(APApplication.PACKAGE_CONFIG_FILE)
if(!file.parentFile.exists()) file.parentFile.mkdirs()
val writer = FileWriter(file, false)
writer.write(CSV_HEADER + '\n')
configs.values.forEach {
writer.write(it.toLine() + '\n')
if(!it.isDefault()) {
writer.write(it.toLine() + '\n')
}
}
writer.flush()
writer.close()
Expand All @@ -75,9 +77,10 @@ object PkgConfig {
mutex.withLock {
thread {
Natives.su()
val configs = readConfigs()
Log.d(TAG, "change config: " + config)
configs[config.pkg] = config
writeConfigs()
writeConfigs(configs)
}.join()
}
}
Expand Down

0 comments on commit 86e7698

Please sign in to comment.