@@ -51,24 +51,22 @@ class NotificationChannelManager {
51
51
// Can't create a channel with the id 'miscellaneous' as an exception is thrown.
52
52
// Using it results in the notification not being displayed.
53
53
// private static final String DEFAULT_CHANNEL_ID = "miscellaneous"; // NotificationChannel.DEFAULT_CHANNEL_ID;
54
-
54
+
55
55
private static final String DEFAULT_CHANNEL_ID = "fcm_fallback_notification_channel" ;
56
+ private static final String RESTORE_CHANNEL_ID = "restored_OS_notifications" ;
56
57
57
- static String createNotificationChannel (Context context , JSONObject jsonPayload ) {
58
+ static String createNotificationChannel (NotificationGenerationJob notifJob ) {
58
59
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O )
59
60
return DEFAULT_CHANNEL_ID ;
60
61
61
- //// To test with additional data
62
- // JSONObject customJson = null;
63
- // try {
64
- // customJson = new JSONObject(jsonPayload.optString("custom"));
65
- // } catch (JSONException e) {
66
- // e.printStackTrace();
67
- // }
68
- // jsonPayload = customJson.optJSONObject("a");
69
-
62
+ Context context = notifJob .context ;
63
+ JSONObject jsonPayload = notifJob .jsonPayload ;
64
+
70
65
NotificationManager notificationManager =
71
- (NotificationManager )context .getSystemService (Context .NOTIFICATION_SERVICE );
66
+ (NotificationManager )context .getSystemService (Context .NOTIFICATION_SERVICE );
67
+
68
+ if (notifJob .restoring )
69
+ return createRestoreChannel (notificationManager );
72
70
73
71
// Allow channels created outside the SDK
74
72
if (jsonPayload .has ("oth_chnl" )) {
@@ -100,7 +98,7 @@ private static String createChannel(Context context, NotificationManager notific
100
98
JSONObject channelPayload = null ;
101
99
if (objChannelPayload instanceof String )
102
100
channelPayload = new JSONObject ((String )objChannelPayload );
103
- else if ( objChannelPayload instanceof JSONObject )
101
+ else
104
102
channelPayload = (JSONObject )objChannelPayload ;
105
103
106
104
String channel_id = channelPayload .optString ("id" , DEFAULT_CHANNEL_ID );
@@ -128,21 +126,21 @@ else if (objChannelPayload instanceof JSONObject)
128
126
notificationManager .createNotificationChannelGroup (new NotificationChannelGroup (group_id , group_name ));
129
127
channel .setGroup (group_id );
130
128
}
131
-
132
- channel .enableLights (payload .optInt ("led" , 1 ) == 1 );
129
+
133
130
if (payload .has ("ledc" )) {
134
131
BigInteger ledColor = new BigInteger (payload .optString ("ledc" ), 16 );
135
132
channel .setLightColor (ledColor .intValue ());
136
133
}
134
+ channel .enableLights (payload .optInt ("led" , 1 ) == 1 );
137
135
138
- channel .enableVibration (payload .optInt ("vib" , 1 ) == 1 );
139
136
if (payload .has ("vib_pt" )) {
140
137
JSONArray json_vib_array = payload .optJSONArray ("vib_pt" );
141
138
long [] long_array = new long [json_vib_array .length ()];
142
139
for (int i = 0 ; i < json_vib_array .length (); i ++)
143
140
long_array [i ] = json_vib_array .optLong (i );
144
141
channel .setVibrationPattern (long_array );
145
142
}
143
+ channel .enableVibration (payload .optInt ("vib" , 1 ) == 1 );
146
144
147
145
if (payload .has ("sound" )) {
148
146
// Sound will only play if Importance is set to High or Urgent
@@ -157,7 +155,7 @@ else if ("null".equals(sound) || "nil".equals(sound))
157
155
// Setting sound to null makes it 'None' in the Settings.
158
156
// Otherwise not calling setSound makes it the default notification sound.
159
157
160
- channel .setLockscreenVisibility (payload .optInt ("vis" , Notification .VISIBILITY_PUBLIC ));
158
+ channel .setLockscreenVisibility (payload .optInt ("vis" , Notification .VISIBILITY_PRIVATE ));
161
159
channel .setShowBadge (payload .optInt ("bdg" , 1 ) == 1 );
162
160
channel .setBypassDnd (payload .optInt ("bdnd" , 0 ) == 1 );
163
161
@@ -177,6 +175,17 @@ private static String createDefaultChannel(NotificationManager notificationManag
177
175
178
176
return DEFAULT_CHANNEL_ID ;
179
177
}
178
+
179
+ @ RequiresApi (api = Build .VERSION_CODES .O )
180
+ private static String createRestoreChannel (NotificationManager notificationManager ) {
181
+ NotificationChannel channel = new NotificationChannel (RESTORE_CHANNEL_ID ,
182
+ "Restored" ,
183
+ NotificationManager .IMPORTANCE_LOW );
184
+
185
+ notificationManager .createNotificationChannel (channel );
186
+
187
+ return RESTORE_CHANNEL_ID ;
188
+ }
180
189
181
190
static void processChannelList (Context context , JSONObject payload ) {
182
191
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O )
0 commit comments