-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ee4d48
commit 09dba49
Showing
8 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
package nep.timeline.cirno.entity; | ||
|
||
import android.os.IBinder; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class AppState { | ||
private final AppRecord parent; | ||
private boolean visible = false; | ||
private final Set<IBinder> activities = new HashSet<>(); | ||
|
||
public AppState(AppRecord appRecord) { | ||
this.parent = appRecord; | ||
} | ||
|
||
public synchronized boolean setVisible(boolean value) { | ||
if (visible == value) | ||
return false; | ||
visible = value; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 25 additions & 6 deletions
31
app/src/main/java/nep/timeline/cirno/services/FreezerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
package nep.timeline.cirno.services; | ||
|
||
import nep.timeline.cirno.utils.RWUtils; | ||
import nep.timeline.cirno.entity.AppRecord; | ||
import nep.timeline.cirno.entity.ProcessRecord; | ||
import nep.timeline.cirno.utils.FrozenRW; | ||
|
||
public class FreezerService { | ||
public static final String cgroupV2 = "/sys/fs/cgroup/"; | ||
public static void freezer(AppRecord appRecord) { | ||
if (appRecord.isFrozen() || appRecord.isSystem() || appRecord.getAppState().isVisible()) | ||
return; | ||
|
||
public static void frozen(int uid, int pid) { | ||
RWUtils.writeFrozen(cgroupV2 + "/uid_" + uid + "/pid_" + pid + "/cgroup.freeze", 1); | ||
for (ProcessRecord processRecord : appRecord.getProcessRecords()) { | ||
if (processRecord.isDeathProcess() || processRecord.isFrozen()) | ||
continue; | ||
|
||
FrozenRW.frozen(processRecord.getRunningUid(), processRecord.getPid()); | ||
processRecord.setFrozen(true); | ||
} | ||
} | ||
|
||
public static void thaw(int uid, int pid) { | ||
RWUtils.writeFrozen(cgroupV2 + "/uid_" + uid + "/pid_" + pid + "/cgroup.freeze", 0); | ||
|
||
public static void thaw(AppRecord appRecord) { | ||
if (!appRecord.isFrozen() || appRecord.isSystem()) | ||
return; | ||
|
||
for (ProcessRecord processRecord : appRecord.getProcessRecords()) { | ||
if (processRecord.isDeathProcess() || !processRecord.isFrozen()) | ||
continue; | ||
|
||
FrozenRW.thaw(processRecord.getRunningUid(), processRecord.getPid()); | ||
processRecord.setFrozen(false); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/nep/timeline/cirno/threads/FreezerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package nep.timeline.cirno.threads; | ||
|
||
import android.os.Handler; | ||
import android.os.Message; | ||
|
||
import nep.timeline.cirno.entity.AppRecord; | ||
|
||
public class FreezerHandler { | ||
public static final Handler handler = new FreezerMessageHandler(Handlers.makeLooper("Freezer")); | ||
|
||
public static void removeAppMessage(AppRecord appRecord) { | ||
if (handler.hasMessages(0, appRecord)) | ||
handler.removeMessages(0, appRecord); | ||
} | ||
|
||
public static void sendFreezeMessage(AppRecord appRecord, long delay) { | ||
if (handler.hasMessages(0, appRecord)) | ||
return; | ||
|
||
sendFreezeMessageIgnoreMessages(appRecord, delay); | ||
} | ||
|
||
public static void sendFreezeMessageIgnoreMessages(AppRecord appRecord, long delay) { | ||
removeAppMessage(appRecord); | ||
|
||
Message obtain = handler.obtainMessage(0, appRecord); | ||
if (delay < 1) | ||
handler.sendMessage(obtain); | ||
else | ||
handler.sendMessageDelayed(obtain, delay); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/nep/timeline/cirno/threads/FreezerMessageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nep.timeline.cirno.threads; | ||
|
||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.os.Message; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import nep.timeline.cirno.entity.AppRecord; | ||
import nep.timeline.cirno.log.Log; | ||
import nep.timeline.cirno.services.FreezerService; | ||
|
||
public class FreezerMessageHandler extends Handler { | ||
public FreezerMessageHandler(Looper looper) { | ||
super(looper); | ||
} | ||
|
||
@Override | ||
public void handleMessage(@NonNull Message message) { | ||
super.handleMessage(message); | ||
try { | ||
FreezerService.freezer((AppRecord) message.obj); | ||
} catch (Throwable th) { | ||
Log.e("Freezer", th); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nep.timeline.cirno.utils; | ||
|
||
public class FrozenRW { | ||
public static final String cgroupV2 = "/sys/fs/cgroup/"; | ||
|
||
public static void frozen(int uid, int pid) { | ||
RWUtils.writeFrozen(cgroupV2 + "/uid_" + uid + "/pid_" + pid + "/cgroup.freeze", 1); | ||
} | ||
|
||
public static void thaw(int uid, int pid) { | ||
RWUtils.writeFrozen(cgroupV2 + "/uid_" + uid + "/pid_" + pid + "/cgroup.freeze", 0); | ||
} | ||
} |