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

Commit cda31b48 authored by Karthik Parsha's avatar Karthik Parsha Committed by Giulio Cervera
Browse files

DynamicMemoryManagerService: Use Wakelock to Prevent Suspend.

Use Wakelock to prevent Suspend from being attempted during PageMigration.
parent ca33a1da
Loading
Loading
Loading
Loading
+38 −15
Original line number Diff line number Diff line
@@ -64,7 +64,8 @@ class DynamicMemoryManagerService {
        "com.android.server.DMMService.action.DPD_START";
    private static final String ACTION_DPD_STOP =
        "com.android.server.DMMService.action.DPD_STOP";

    private PowerManager.WakeLock mWakeLock = null;
    private final static String WAKELOCK_NAME = "DynamicMemoryManagerServiceLock";
    private final boolean DEBUG = false;

    public DynamicMemoryManagerService(Context context) {
@@ -83,7 +84,8 @@ class DynamicMemoryManagerService {
                mStopPendingIntent = PendingIntent.getBroadcast(mContext, 0, mStopIntent, 0);
                mStartAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
                mStopAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);

                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_NAME);
                Log.w(TAG, "DynamicMemoryManager Service Initialized");
        }
        else
@@ -290,6 +292,14 @@ class DynamicMemoryManagerService {

    private int enableUnstableMemory(boolean flag) {
        Log.w(TAG, "Enable Unstable Memory : " + flag);
        synchronized (mWakeLock) {
            try {
                mWakeLock.acquire();
                if (DEBUG) Log.w(TAG, "Wakelock " + WAKELOCK_NAME + " Acquired");
            }
            catch (Exception e) {
                Log.e(TAG, "Unable to Acquired Wakelock: " + WAKELOCK_NAME);
            }
            if (flag) {
                if(mState == DMM_MEM_STATE.DISABLED) {
                    if(Power.SetUnstableMemoryState(flag) < 0)
@@ -305,6 +315,19 @@ class DynamicMemoryManagerService {
                            mState = DMM_MEM_STATE.DISABLED;
                }
            }
            try {
                if (mWakeLock.isHeld()) {
                    mWakeLock.release();
                    if (DEBUG) Log.w(TAG, "Wakelock " + WAKELOCK_NAME + " Released");
                }
                else {
                    Log.e(TAG, "Error: Attempring to release unheld Wakelock: " + WAKELOCK_NAME);
                }
            }
            catch (Exception e) {
                Log.e(TAG, "Unable to release Wakelock: " + WAKELOCK_NAME);
            }
        }
        return 0;
    }
}