Skip to content

Commit cacc570

Browse files
committed
Merge branch 'master' into try-osx11-agent
2 parents 6b6ec61 + 46d18a7 commit cacc570

23 files changed

+1258
-516
lines changed

.buginfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
system: jira
2+
server: jira.unity3d.com
3+
project: MNB
4+
issuetype: Bug
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb7d100a40edf48f99686ea68a90ff4c, type: 3}
13+
m_Name: Not shown in foreground
14+
m_EditorClassIdentifier:
15+
ButtonName: Not shown in foreground
16+
Channel: default_channel
17+
FireInSeconds: 10
18+
NotificationID: 0
19+
Title: Not in foreground
20+
Text: This notifications should not appear when app is in foreground
21+
SmallIcon:
22+
LargeIcon:
23+
NotificationStyle: 0
24+
Color: {r: 0, g: 0, b: 0, a: 1}
25+
Number: -1
26+
ShouldAutoCancel: 0
27+
UsesStopWatch: 0
28+
Group:
29+
GroupSummary: 0
30+
GroupAlertBehaviours: 0
31+
SortKey:
32+
IntentData:
33+
ShowTimestamp: 0
34+
RepeatInterval: 0
35+
ShowInForeground: 0

TestProjects/com.unity.mobile-notifications-sample/Assets/Resources/AndroidNotifications/Not shown in foreground.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TestProjects/com.unity.mobile-notifications-sample/Assets/Scripts/AndroidTest.cs

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class AndroidTest : MonoBehaviour
2323
private Button ButtonModifyExplicitID;
2424
private Button ButtonCancelExplicitID;
2525
private Button ButtonCheckStatusExplicitID;
26+
private AndroidNotificationTemplate[] AndroidNotificationsTemplates;
2627

2728
public int notificationExplicitID
2829
{
@@ -107,6 +108,32 @@ private void HandleLastNotificationIntent()
107108
}
108109
}
109110

111+
private AndroidNotification parseNotificationTemplate(AndroidNotificationTemplate template)
112+
{
113+
AndroidNotification newNotification = new AndroidNotification()
114+
{
115+
Title = template.Title,
116+
Text = template.Text,
117+
118+
SmallIcon = template.SmallIcon,
119+
LargeIcon = template.LargeIcon,
120+
Style = template.NotificationStyle,
121+
FireTime = System.DateTime.Now.AddSeconds(template.FireInSeconds),
122+
Color = template.Color,
123+
Number = template.Number,
124+
ShouldAutoCancel = template.ShouldAutoCancel,
125+
UsesStopwatch = template.UsesStopWatch,
126+
Group = template.Group,
127+
GroupSummary = template.GroupSummary,
128+
SortKey = template.SortKey,
129+
IntentData = template.IntentData,
130+
ShowTimestamp = template.ShowTimestamp,
131+
RepeatInterval = TimeSpan.FromSeconds(template.RepeatInterval),
132+
//ShowInForeground = template.ShowInForeground
133+
};
134+
return newNotification;
135+
}
136+
110137
private void InstantiateAllTestButtons()
111138
{
112139
m_groups = new Dictionary<string, OrderedDictionary>();
@@ -123,39 +150,16 @@ private void InstantiateAllTestButtons()
123150
m_groups["Modify"]["Modify pending Explicit notification"] = new Action(() => { ModifyExplicitNotification(); });
124151
m_groups["Modify"]["Cancel pending Explicit notification"] = new Action(() => { CancelExplicitNotification(); });
125152
m_groups["Modify"]["Check status of Explicit notification"] = new Action(() => { CheckStatusOfExplicitNotification (); });
126-
127-
153+
AndroidNotificationsTemplates = Resources.LoadAll<AndroidNotificationTemplate>("AndroidNotifications");
128154
m_groups["Send"] = new OrderedDictionary();
129-
foreach (AndroidNotificationTemplate template in Resources.LoadAll("AndroidNotifications", typeof(AndroidNotificationTemplate)))
155+
foreach (AndroidNotificationTemplate template in AndroidNotificationsTemplates)
130156
{
131157
if (template == null) continue;
132-
m_groups["Send"][$"[{template.FireInSeconds}s] {template.ButtonName}"] = new Action(() => {
133-
SendNotification(
134-
new AndroidNotification()
135-
{
136-
Title = template.Title,
137-
Text = template.Text,
138-
139-
SmallIcon = template.SmallIcon,
140-
LargeIcon = template.LargeIcon,
141-
Style = template.NotificationStyle,
142-
FireTime = System.DateTime.Now.AddSeconds(template.FireInSeconds),
143-
Color = template.Color,
144-
Number = template.Number,
145-
ShouldAutoCancel = template.ShouldAutoCancel,
146-
UsesStopwatch = template.UsesStopWatch,
147-
Group = template.Group,
148-
GroupSummary = template.GroupSummary,
149-
SortKey = template.SortKey,
150-
IntentData = template.IntentData,
151-
ShowTimestamp = template.ShowTimestamp,
152-
RepeatInterval = TimeSpan.FromSeconds(template.RepeatInterval)
153-
},
154-
template.Channel, template.NotificationID
155-
);
158+
m_groups["Send"][$"[{template.FireInSeconds}s] {template.ButtonName}"] = new Action(() =>
159+
{
160+
SendNotification(parseNotificationTemplate(template), template.Channel, template.NotificationID);
156161
});
157162
}
158-
159163
m_groups["Cancellation"] = new OrderedDictionary();
160164
m_groups["Cancellation"]["Cancel all notifications"] = new Action(() => { CancelAllNotifications(); });
161165
m_groups["Cancellation"]["Cancel pending notifications"] = new Action(() => { CancelPendingNotifications(); });
@@ -208,7 +212,8 @@ private void InstantiateAllTestButtons()
208212
AndroidNotificationCenter.OpenNotificationSettings("secondary_channel");
209213
});
210214
m_groups["Channels"]["Delete All Channels"] = new Action(() => { DeleteAllChannels(); });
211-
215+
m_groups["Custom sequences"] = new OrderedDictionary();
216+
m_groups["Custom sequences"]["Run custom sequence"] = new Action(() => { StartCoroutine(RunCustomSequence()); });
212217
foreach (KeyValuePair<string, OrderedDictionary> group in m_groups)
213218
{
214219
// Instantiate group
@@ -287,6 +292,7 @@ public void SendNotification(AndroidNotification notification, string channel =
287292
}
288293
if (notificationID != 0)
289294
{
295+
notification.Text = "ID: " + notificationID + " " + notification.Text;
290296
AndroidNotificationCenter.SendNotificationWithExplicitID(notification, channel, notificationID);
291297
notificationExplicitID = notificationID;
292298
}
@@ -353,6 +359,25 @@ public void ScrollLogsToBottom()
353359
m_gameObjectReferences.LogsScrollRect.verticalNormalizedPosition = 0f;
354360
}
355361

362+
IEnumerator RunCustomSequence()
363+
{
364+
AndroidNotificationTemplate ant = AndroidNotificationsTemplates[4];
365+
SendNotification(parseNotificationTemplate(ant), ant.Channel, 15);
366+
SendNotification(parseNotificationTemplate(ant), ant.Channel, 20);
367+
SendNotification(parseNotificationTemplate(ant), ant.Channel, 28);
368+
SendNotification(parseNotificationTemplate(ant), ant.Channel, 14);
369+
yield return new WaitForSeconds(ant.FireInSeconds+5);
370+
AndroidNotificationCenter.CancelNotification(15);
371+
yield return new WaitForSeconds(5);
372+
AndroidNotificationCenter.CancelDisplayedNotification(20);
373+
yield return new WaitForSeconds(5);
374+
SendNotification(parseNotificationTemplate(ant), ant.Channel, 99);
375+
SendNotification(parseNotificationTemplate(ant), ant.Channel, 99);
376+
yield return new WaitForSeconds(ant.FireInSeconds-1);
377+
SendNotification(parseNotificationTemplate(ant), ant.Channel, 99);
378+
SendNotification(parseNotificationTemplate(ant), ant.Channel, 99);
379+
}
380+
356381
#endif
357382
}
358383
}

TestProjects/com.unity.mobile-notifications-sample/Assets/Scripts/ScriptableObjects/AndroidNotificationTemplate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class AndroidNotificationTemplate : ScriptableObject
3636
[TextArea] public string IntentData = "";
3737
public bool ShowTimestamp = false;
3838
public long RepeatInterval;
39+
public bool ShowInForeground = true;
3940
#endif
4041
}
4142
}

com.unity.mobile.notifications/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this package will be documented in this file.
44

5+
## [2.0.2] - 2022-05-13
6+
7+
### Changes & Improvements:
8+
- [Android] - AndroidNotificationCenter.CheckScheduledNotificationStatus now works on devices with all API levels
9+
10+
### Fixes:
11+
- [Android] [issue 186](https://github.com/Unity-Technologies/com.unity.mobile.notifications/issues/186) Mitigate OutOfMemory errors causing application crash
12+
- [Android] [issue 188](https://github.com/Unity-Technologies/com.unity.mobile.notifications/issues/188) Fix unguarded API usage from level 23
13+
514
## [2.0.1] - 2022-04-15
615

716
### Fixes:

com.unity.mobile.notifications/Runtime/Android/AndroidNotification.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,21 @@ public DateTime CustomTimestamp
177177
}
178178
}
179179

180+
/// <summary>
181+
/// Set this notification to be shown when app is in the foreground (default: true).
182+
/// </summary>
183+
public bool ShowInForeground
184+
{
185+
get => !m_SilentInForeground;
186+
set => m_SilentInForeground = !value;
187+
}
188+
180189
internal bool ShowCustomTimestamp { get; set; }
181190

182191
private Color m_Color;
183192
private TimeSpan m_RepeatInterval;
184193
private DateTime m_CustomTimestamp;
194+
private bool m_SilentInForeground;
185195

186196
/// <summary>
187197
/// Create a notification struct with all optional fields set to default values.
@@ -212,6 +222,7 @@ public AndroidNotification(string title, string text, DateTime fireTime)
212222
m_RepeatInterval = (-1L).ToTimeSpan();
213223
m_Color = new Color(0, 0, 0, 0);
214224
m_CustomTimestamp = (-1L).ToDatetime();
225+
m_SilentInForeground = false;
215226
}
216227

217228
/// <summary>

com.unity.mobile.notifications/Runtime/Android/AndroidNotificationCallback.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23

34
namespace Unity.Notifications.Android
@@ -8,6 +9,17 @@ public NotificationCallback() : base("com.unity.androidnotifications.Notificatio
89
{
910
}
1011

12+
public override AndroidJavaObject Invoke(string methodName, AndroidJavaObject[] args)
13+
{
14+
if (methodName.Equals("onSentNotification", StringComparison.InvariantCulture) && args != null && args.Length == 1)
15+
{
16+
onSentNotification(args[0]);
17+
return null;
18+
}
19+
20+
return base.Invoke(methodName, args);
21+
}
22+
1123
public void onSentNotification(AndroidJavaObject notification)
1224
{
1325
AndroidReceivedNotificationMainThreadDispatcher.GetInstance().EnqueueReceivedNotification(notification);

0 commit comments

Comments
 (0)