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

Commit 15bc8358 authored by Danesh M's avatar Danesh M Committed by Gerrit Code Review
Browse files

NetworkPolicyManager : Process low power mode change on background thread

Since PowerManagerService runs in the same process, the callbacks occur on
the invocation thread. updateRulesForGlobalChangeLocked can take quite long
to process which in turns blocks the system processes background thread queue
and delays things like switching to/from power saver mode.

Address this by processing the action on our background thread via the handler,
and to not queue up multiple calls.

CYNGNOS-786

Change-Id: Ibbcae795f0138a1e1836f0df92f905178d34b684
(cherry picked from commit 8ff13dea)
parent 2a6dc128
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -247,6 +247,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
    private static final int MSG_RESTRICT_BACKGROUND_CHANGED = 6;
    private static final int MSG_ADVISE_PERSIST_THRESHOLD = 7;
    private static final int MSG_SCREEN_ON_CHANGED = 8;
    private static final int MSG_PROCESS_LOW_POWER_CHANGED = 9;

    private final Context mContext;
    private final IActivityManager mActivityManager;
@@ -437,13 +438,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
            mPowerManagerInternal.registerLowPowerModeObserver(
                    new PowerManagerInternal.LowPowerModeListener() {
                @Override
                public void onLowPowerModeChanged(boolean enabled) {
                    synchronized (mRulesLock) {
                        if (mRestrictPower != enabled) {
                            mRestrictPower = enabled;
                            updateRulesForGlobalChangeLocked(true);
                        }
                    }
                public void onLowPowerModeChanged(final boolean enabled) {
                    mHandler.removeMessages(MSG_PROCESS_LOW_POWER_CHANGED);
                    Message msg = Message.obtain(mHandler, MSG_PROCESS_LOW_POWER_CHANGED, enabled);
                    mHandler.sendMessage(msg);
                }
            });
            mRestrictPower = mPowerManagerInternal.getLowPowerModeEnabled();
@@ -2432,6 +2430,16 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                    updateScreenOn();
                    return true;
                }
                case MSG_PROCESS_LOW_POWER_CHANGED: {
                    boolean enabled = (Boolean) msg.obj;
                    synchronized (mRulesLock) {
                        if (mRestrictPower != enabled) {
                            mRestrictPower = enabled;
                            updateRulesForGlobalChangeLocked(true);
                        }
                    }
                    return true;
                }
                default: {
                    return false;
                }