Skip to content

Commit

Permalink
[Refactor] Use wakelocks in long-running tasks to keep the CPU awake
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Sep 11, 2023
1 parent b0c4d6f commit 065b99f
Show file tree
Hide file tree
Showing 22 changed files with 623 additions and 325 deletions.
1 change: 1 addition & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<lint>
<issue id="MissingTranslation" severity="ignore" />
<issue id="ImpliedQuantity" severity="ignore" />
<issue id="WakelockTimeout" severity="ignore" />

<issue id="LogConditional" severity="informational" />
<issue id="Registered" severity="informational" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
android:name="android.permission.UPDATE_DOMAIN_VERIFICATION_USER_SELECTION"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.termux.permission.RUN_COMMAND" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.PowerManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -48,6 +49,7 @@
import io.github.muntashirakon.AppManager.rules.compontents.ComponentUtils;
import io.github.muntashirakon.AppManager.types.ForegroundService;
import io.github.muntashirakon.AppManager.types.UserPackagePair;
import io.github.muntashirakon.AppManager.utils.CpuUtils;
import io.github.muntashirakon.AppManager.utils.NotificationUtils;
import io.github.muntashirakon.AppManager.utils.PackageUtils;
import io.github.muntashirakon.AppManager.utils.ThreadUtils;
Expand All @@ -72,6 +74,14 @@ public PackageInstallerService() {
private String mPackageName;
private QueuedProgressHandler mProgressHandler;
private NotificationInfo mNotificationInfo;
private PowerManager.WakeLock mWakeLock;

@Override
public void onCreate() {
super.onCreate();
mWakeLock = CpuUtils.getPartialWakeLock("installer");
mWakeLock.acquire();
}

@Override
public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
Expand Down Expand Up @@ -222,6 +232,9 @@ public void onDestroy() {
if (mProgressHandler != null) {
mProgressHandler.onDetach(this);
}
if (mWakeLock != null) {
mWakeLock.release();
}
super.onDestroy();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import io.github.muntashirakon.AppManager.self.SelfPermissions;
import io.github.muntashirakon.AppManager.ssaid.SsaidSettings;
import io.github.muntashirakon.AppManager.uri.UriManager;
import io.github.muntashirakon.AppManager.utils.ContextUtils;
import io.github.muntashirakon.AppManager.utils.DigestUtils;
import io.github.muntashirakon.AppManager.utils.KeyStoreUtils;
import io.github.muntashirakon.AppManager.utils.PackageUtils;
Expand All @@ -79,8 +78,6 @@ class RestoreOp implements Closeable {
static final String TAG = RestoreOp.class.getSimpleName();
private static final Object sLock = new Object();

@NonNull
private final Context mContext;
@NonNull
private final String mPackageName;
@NonNull
Expand Down Expand Up @@ -108,7 +105,6 @@ class RestoreOp implements Closeable {
RestoreOp(@NonNull String packageName, @NonNull MetadataManager metadataManager,
@NonNull BackupFlags requestedFlags, @NonNull BackupFiles.BackupFile backupFile,
int userId) throws BackupException {
mContext = ContextUtils.getContext();
mPackageName = packageName;
mRequestedFlags = requestedFlags;
mBackupFile = backupFile;
Expand Down Expand Up @@ -721,7 +717,7 @@ private void restoreRules() throws BackupException {
} catch (IOException e) {
throw new BackupException("Could not get decrypted rules file", e);
}
try (RulesImporter importer = new RulesImporter(mContext, Arrays.asList(RuleType.values()), new int[]{mUserId})) {
try (RulesImporter importer = new RulesImporter(Arrays.asList(RuleType.values()), new int[]{mUserId})) {
importer.addRulesFromPath(rulesFile);
importer.setPackagesToImport(Collections.singletonList(mPackageName));
importer.applyRules(true);
Expand Down
Loading

0 comments on commit 065b99f

Please sign in to comment.