Skip to content

Commit 2a83b20

Browse files
committed
Simplyfy housekeeping determinision
1 parent c6d7a00 commit 2a83b20

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

com.unity.mobile.notifications/Runtime/Android/Plugins/com/unity/androidnotifications/UnityNotificationBackgroundThread.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ public void run(Context context, Set<String> notificationIds) {
7777
}
7878
}
7979

80+
private static final int TASKS_FOR_HOUSEKEEPING = 50;
8081
private LinkedTransferQueue<Task> mTasks = new LinkedTransferQueue();
81-
private int mSentNotificationsSinceHousekeeping = 0;
82-
private int mOtherTasksSinceHousekeeping;
82+
private int mTasksSinceHousekeeping = TASKS_FOR_HOUSEKEEPING; // we want hoursekeeping at the start
8383

8484
public UnityNotificationBackgroundThread() {
85-
// force housekeeping
86-
mOtherTasksSinceHousekeeping = 2;
8785
enqueueHousekeeping();
8886
}
8987

@@ -111,6 +109,10 @@ public void run() {
111109
try {
112110
Task task = mTasks.take();
113111
executeTask(context, task, notificationIds);
112+
if (!(task instanceof HousekeepingTask))
113+
++mTasksSinceHousekeeping;
114+
if (mTasks.size() == 0)
115+
enqueueHousekeeping();
114116
} catch (InterruptedException e) {
115117
if (mTasks.isEmpty())
116118
break;
@@ -120,31 +122,17 @@ public void run() {
120122

121123
private void executeTask(Context context, Task task, Set<String> notificationIds) {
122124
try {
123-
ScheduleNotificationTask scheduleTask = null;
124-
if (task instanceof ScheduleNotificationTask)
125-
scheduleTask = (ScheduleNotificationTask)task;
126-
127125
task.run(context, notificationIds);
128-
129-
if (scheduleTask != null)
130-
++mSentNotificationsSinceHousekeeping;
131-
else
132-
++mOtherTasksSinceHousekeeping;
133-
if ((mSentNotificationsSinceHousekeeping + mOtherTasksSinceHousekeeping) >= 50) {
134-
enqueueHousekeeping();
135-
}
136126
} catch (Exception e) {
137127
Log.e(TAG_UNITY, "Exception executing notification task", e);
138128
}
139129
}
140130

141131
private void performHousekeeping(Context context, Set<String> notificationIds) {
142132
// don't do housekeeping if last task we did was housekeeping (other=1)
143-
boolean performHousekeeping = mSentNotificationsSinceHousekeeping > 0 && mOtherTasksSinceHousekeeping > 1;
144-
mSentNotificationsSinceHousekeeping = 0;
145-
mOtherTasksSinceHousekeeping = 0;
146-
if (!performHousekeeping)
147-
return;
148-
UnityNotificationManager.performNotificationHousekeeping(context, notificationIds);
133+
boolean performHousekeeping = mTasksSinceHousekeeping >= TASKS_FOR_HOUSEKEEPING;
134+
mTasksSinceHousekeeping = 0;
135+
if (performHousekeeping)
136+
UnityNotificationManager.performNotificationHousekeeping(context, notificationIds);
149137
}
150138
}

0 commit comments

Comments
 (0)