Skip to content

Commit

Permalink
[services] expose cached app freezer API
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Apr 6, 2022
1 parent 98aa959 commit 0dabad5
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;

import github.tornaco.android.thanos.core.app.start.StartRecord;
import github.tornaco.android.thanos.core.pm.Pkg;
import github.tornaco.android.thanos.core.process.ProcessRecord;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -96,8 +97,8 @@ public int getRunningAppsCount() {
}

@SneakyThrows
public ProcessRecord[] getRunningAppProcessForPackage(String pkgName) {
return server.getRunningAppProcessForPackage(pkgName);
public ProcessRecord[] getRunningAppProcessForPackage(Pkg pkg) {
return server.getRunningAppProcessForPackage(pkg);
}

@SneakyThrows
Expand Down Expand Up @@ -448,7 +449,7 @@ public void stopService(Intent intent) {

@SneakyThrows
public void killBackgroundProcesses(String packageName) {
server.killBackgroundProcesses(packageName);
server.killBackgroundProcesses(Pkg.systemUserPkg(packageName));
}

@SneakyThrows
Expand Down Expand Up @@ -511,6 +512,47 @@ public boolean checkGetContentProvider(String callerPkg, String name) {
return server.checkGetContentProvider(callerPkg, name);
}

// ******************************************************************
// CAF API
// https://source.android.com/devices/tech/perf/cached-apps-freezer
//
// ******************************************************************

@SneakyThrows
public boolean isCachedAppsFreezerSupported() {
return server.isCachedAppsFreezerSupported();
}

@SneakyThrows
public void freezeApp(String pkgName) {
server.freezeApp(Pkg.systemUserPkg(pkgName));
}

@SneakyThrows
public void freezeApp(Pkg pkg) {
server.freezeApp(pkg);
}

@SneakyThrows
public void freezeAppProcess(long pid) {
server.freezeAppProcess(pid);
}

@SneakyThrows
public void unfreezeApp(Pkg pkg) {
server.unfreezeApp(pkg);
}

@SneakyThrows
public void unfreezeApp(String pkgName) {
server.unfreezeApp(Pkg.systemUserPkg(pkgName));
}

@SneakyThrows
public void unfreezeAppProcess(long pid) {
server.unfreezeAppProcess(pid);
}

public IBinder asBinder() {
return server.asBinder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface IActivityManager {

int getRunningAppsCount();

ProcessRecord[] getRunningAppProcessForPackage(String pkgName);
ProcessRecord[] getRunningAppProcessForPackage(in Pkg pkg);
boolean isPackageRunning(String pkgName);

List<StartRecord> getStartRecordsByPackageName(String pkgName);
Expand Down Expand Up @@ -131,7 +131,7 @@ interface IActivityManager {
UserInfo getUserInfo(int userHandle);

void stopService(in Intent intent);
void killBackgroundProcesses(String packageName);
void killBackgroundProcesses(in Pkg pkg);

boolean isSmartStandByStopServiceEnabled();
void setSmartStandByStopServiceEnabled(boolean enable);
Expand Down Expand Up @@ -167,4 +167,15 @@ interface IActivityManager {
boolean checkGetContentProvider(String callerPkg, String name);

List<StartRecord> getAllStartRecordsForPackageSetWithRes(String pkgSetId, boolean allowed, boolean blocked);

// ******************************************************************
// CAF API
// https://source.android.com/devices/tech/perf/cached-apps-freezer
//
// ******************************************************************
boolean isCachedAppsFreezerSupported();
void freezeApp(in Pkg pkg);
void unfreezeApp(in Pkg pkg);
void freezeAppProcess(long pid);
void unfreezeAppProcess(long pid);
}
Loading

2 comments on commit 0dabad5

@Tornaco
Copy link
Owner Author

@Tornaco Tornaco commented on 0dabad5 Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under testing:

2022-03-30 17:47:56.612 1160-2287/system_process E/Thanox-Core: CachedAppOptimizer. Unable to freeze binder for 4320 com.topjohnwu.magisk
    util.XposedHelpers$InvocationTargetError: java.lang.RuntimeException: Unable to freeze/unfreeze binder
        at util.XposedHelpers.callStaticMethod(XposedHelpers.java:1390)
        at github.tornaco.android.thanos.services.automation.CachedAppOptimizer.freezeBinder(CachedAppOptimizer.kt:114)
        at github.tornaco.android.thanos.services.automation.CachedAppOptimizer.freezeProcessLocked(CachedAppOptimizer.kt:75)
        at github.tornaco.android.thanos.services.automation.CachedAppOptimizer.freezeProcess(CachedAppOptimizer.kt:40)
        at github.tornaco.android.thanos.services.app.ActivityManagerService.lambda$freezeApp$27$github-tornaco-android-thanos-services-app-ActivityManagerService(ActivityManagerService.java:1505)
        at github.tornaco.android.thanos.services.app.ActivityManagerService$$ExternalSyntheticLambda24.run(Unknown Source:4)
        at io.reactivex.internal.operators.completable.CompletableFromRunnable.subscribeActual(CompletableFromRunnable.java:35)
        at io.reactivex.Completable.subscribe(Completable.java:1635)
        at io.reactivex.internal.operators.completable.CompletableSubscribeOn$SubscribeOnObserver.run(CompletableSubscribeOn.java:64)
        at rx2.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:118)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: java.lang.RuntimeException: Unable to freeze/unfreeze binder
        at com.android.server.am.CachedAppOptimizer.freezeBinder(Native Method)
        at java.lang.reflect.Method.invoke(Native Method)
        at util.XposedHelpers.callStaticMethod(XposedHelpers.java:1382)
        at github.tornaco.android.thanos.services.automation.CachedAppOptimizer.freezeBinder(CachedAppOptimizer.kt:114) 
        at github.tornaco.android.thanos.services.automation.CachedAppOptimizer.freezeProcessLocked(CachedAppOptimizer.kt:75) 
        at github.tornaco.android.thanos.services.automation.CachedAppOptimizer.freezeProcess(CachedAppOptimizer.kt:40) 
        at github.tornaco.android.thanos.services.app.ActivityManagerService.lambda$freezeApp$27$github-tornaco-android-thanos-services-app-ActivityManagerService(ActivityManagerService.java:1505) 
        at github.tornaco.android.thanos.services.app.ActivityManagerService$$ExternalSyntheticLambda24.run(Unknown Source:4) 
        at io.reactivex.internal.operators.completable.CompletableFromRunnable.subscribeActual(CompletableFromRunnable.java:35) 
        at io.reactivex.Completable.subscribe(Completable.java:1635) 
        at io.reactivex.internal.operators.completable.CompletableSubscribeOn$SubscribeOnObserver.run(CompletableSubscribeOn.java:64) 
        at rx2.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:118) 
        at android.os.Handler.handleCallback(Handler.java:938) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 

@countrysideboy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哇,不明觉厉

Please sign in to comment.