Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92f5b2e3 authored by Roman Birg's avatar Roman Birg
Browse files

Don't block wake locks for required always-on system apps



If an app is marked as "allow-in-power-save" (loaded in as part of
SystemConfig), then this app is not susceptible to battery saving
optimizations and is required to be active for the system to function properly.

If an app is in this list (only com.google.android.gms for now), it will
now not block the wake lock from happening.

Ticket: CYNGNOS-1258

Change-Id: Ia8bf9266489719f101114f334fbf205aee314d15
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 23c63190
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -17,14 +17,18 @@
package com.android.server.power;

import android.app.ActivityManager;
import android.os.IDeviceIdleController;
import android.os.ServiceManager;
import android.util.SparseIntArray;

import com.android.internal.app.IAppOpsService;
import com.android.internal.app.IBatteryStats;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.ArrayUtils;
import com.android.server.EventLogTags;
import com.android.server.LocalServices;
import com.android.server.ServiceThread;
import com.android.server.SystemConfig;
import com.android.server.SystemService;
import com.android.server.am.BatteryStatsService;
import com.android.server.lights.Light;
@@ -3292,13 +3296,22 @@ public final class PowerManagerService extends SystemService
                if (mAppOps != null &&
                        mAppOps.checkOperation(AppOpsManager.OP_WAKE_LOCK, uid, packageName)
                                != AppOpsManager.MODE_ALLOWED) {

                    // If this app is whitelisted as "allow-in-power-save" then always allow!
                    // Current impl only looks at system-loaded ones, if we want to also include
                    // user apps which have been manually set, we would use IDeviceIdleController
                    if (!SystemConfig.getInstance().getAllowInPowerSave().contains(packageName)) {
                        Slog.d(TAG, "acquireWakeLock: ignoring request from " + packageName);
                        // For (ignore) accounting purposes
                        mAppOps.noteOperation(AppOpsManager.OP_WAKE_LOCK, uid, packageName);
                        // silent return
                        return;
                    } else {
                        Slog.d(TAG, "wake lock requested to be ignored but " + packageName
                                + " is marked to opt-out of all power save restrictions.");
                    }
                }
            } catch (RemoteException e) {
            } catch (RemoteException ignored) {
            }

            final long ident = Binder.clearCallingIdentity();