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

Commit fef14575 authored by Tetiana Meronyk's avatar Tetiana Meronyk
Browse files

Move UserWakeupStore initialization to happen before it is used

Before this change there was a case in which UserWakeupStore was called before it was initialised which caused NPE.

With this change it is initialized before any calls can happen.

Bug: 332990374
Test: atest AlarmManagerServiceTest

Change-Id: I122eaf9a7f6dac17f808a7267e6f37292ffe91e4
parent 43e10749
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -1795,6 +1795,10 @@ public class AlarmManagerService extends SystemService {

        mUseFrozenStateToDropListenerAlarms = Flags.useFrozenStateToDropListenerAlarms();
        mStartUserBeforeScheduledAlarms = Flags.startUserBeforeScheduledAlarms();
        if (mStartUserBeforeScheduledAlarms) {
            mUserWakeupStore = new UserWakeupStore();
            mUserWakeupStore.init();
        }
        if (mUseFrozenStateToDropListenerAlarms) {
            final ActivityManager.UidFrozenStateChangedCallback callback = (uids, frozenStates) -> {
                final int size = frozenStates.length;
@@ -1913,10 +1917,6 @@ public class AlarmManagerService extends SystemService {
                Slog.w(TAG, "Failed to open alarm driver. Falling back to a handler.");
            }
        }
        if (mStartUserBeforeScheduledAlarms) {
            mUserWakeupStore = new UserWakeupStore();
            mUserWakeupStore.init();
        }
        publishLocalService(AlarmManagerInternal.class, new LocalService());
        publishBinderService(Context.ALARM_SERVICE, mService);
    }
@@ -3863,7 +3863,7 @@ public class AlarmManagerService extends SystemService {
        long nextNonWakeup = 0;
        if (mAlarmStore.size() > 0) {
            long firstWakeup = mAlarmStore.getNextWakeupDeliveryTime();
            if (mStartUserBeforeScheduledAlarms) {
            if (mStartUserBeforeScheduledAlarms && mUserWakeupStore != null) {
                final long firstUserWakeup = mUserWakeupStore.getNextWakeupTime();
                if (firstUserWakeup >= 0 && firstUserWakeup < firstWakeup) {
                    firstWakeup = firstUserWakeup;