From 9d807400cef3aa86f67205ff551c8331e32a2050 Mon Sep 17 00:00:00 2001 From: harshanl Date: Wed, 18 Nov 2015 14:38:18 +0530 Subject: [PATCH] Added GCM failure handling logic --- .../mobile/impl/android/gcm/GCMService.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java index 57c79f7a9..1ee07387c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/gcm/GCMService.java @@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.gcm; import com.google.android.gcm.server.Message; +import com.google.android.gcm.server.MulticastResult; +import com.google.android.gcm.server.Result; import com.google.android.gcm.server.Sender; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -61,7 +63,10 @@ public class GCMService { Message message = new Message.Builder().timeToLive(seconds).delayWhileIdle(false).addData("data", messageData).build(); try { - sender.send(message, getGCMToken(device.getProperties()), 5); + Result result = sender.send(message, getGCMToken(device.getProperties()), 5); + if (result.getErrorCodeName() != null) { + log.error("Unable to send notification via GCM : " + result.getErrorCodeName()); + } } catch (IOException e) { log.error("Exception occurred while sending the GCM notification.",e); } @@ -73,7 +78,16 @@ public class GCMService { Message message = new Message.Builder().timeToLive(seconds).delayWhileIdle(false).addData("data", messageData).build(); try { - sender.send(message, getGCMTokens(devices), 5); + MulticastResult result = sender.send(message, getGCMTokens(devices), 5); + if (result.getFailure() == 1) { + List resultList = result.getResults(); + if (resultList != null && resultList.size() > 0) { + Result error = resultList.get(0); + log.error("Unable to send notification via GCM : " + error.getErrorCodeName()); + } else { + log.error("Unable to send notification via GCM."); + } + } } catch (IOException e) { log.error("Exception occurred while sending the GCM notification.",e); }