-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from Azure/feature/fcmv1
Adds support for FCM V1
- Loading branch information
Showing
22 changed files
with
503 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
NotificationHubs/src/com/windowsazure/messaging/FcmV1Credential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//---------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//---------------------------------------------------------------- | ||
|
||
package com.windowsazure.messaging; | ||
|
||
import java.util.AbstractMap.SimpleEntry; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* This class represents Azure Notification Hubs credentials for Firebase Messaging V1. | ||
*/ | ||
public final class FcmV1Credential extends PnsCredential { | ||
|
||
private String privateKey; | ||
private String projectId; | ||
private String clientEmail; | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Credential class. | ||
*/ | ||
public FcmV1Credential() { | ||
|
||
} | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Credential class. | ||
* @param privateKey The Private key from Firebase. | ||
* @param projectId The Project ID from Firebase. | ||
* @param clientEmail The Client Email from Firebase. | ||
*/ | ||
public FcmV1Credential(String privateKey, String projectId, String clientEmail) { | ||
super(); | ||
this.privateKey = privateKey; | ||
this.projectId = projectId; | ||
this.clientEmail = clientEmail; | ||
} | ||
|
||
/** | ||
* Gets the Private key for Firebase Messaging. | ||
* @return The Private key for Firebase Messaging. | ||
*/ | ||
public String getPrivateKey() { return privateKey; } | ||
|
||
/** | ||
* Sets the Private key for Firebase Messaging. | ||
* @param value The Private key for Firebase Messaging to set. | ||
*/ | ||
public void setPrivateKey(String value) { privateKey = value; } | ||
|
||
/** | ||
* Gets the Project ID for Firebase Messaging. | ||
* @return The Project ID for Firebase Messaging. | ||
*/ | ||
public String getProjectId() { return projectId; } | ||
|
||
/** | ||
* Sets the Project ID for Firebase Messaging. | ||
* @param value The Project ID for Firebase Messaging to set. | ||
*/ | ||
public void setProjectId(String value) { projectId = value; } | ||
|
||
/** | ||
* Gets the Client Email for Firebase Messaging. | ||
* @return The Client Email for Firebase Messaging. | ||
*/ | ||
public String getClientEmail() { return clientEmail; } | ||
|
||
/** | ||
* Sets the Client Email for Firebase Messaging. | ||
* @param value The Client Email for Firebase Messaging to set. | ||
*/ | ||
public void setClientEmail(String value) { clientEmail = value; } | ||
|
||
@Override | ||
public List<SimpleEntry<String, String>> getProperties() { | ||
ArrayList<SimpleEntry<String, String>> result = new ArrayList<>(); | ||
result.add(new SimpleEntry<>("PrivateKey", getPrivateKey())); | ||
result.add(new SimpleEntry<>("ProjectId", getProjectId())); | ||
result.add(new SimpleEntry<>("ClientEmail", getClientEmail())); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String getRootTagName() { | ||
return "FcmV1Credential"; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
NotificationHubs/src/com/windowsazure/messaging/FcmV1Installation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//---------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//---------------------------------------------------------------- | ||
|
||
package com.windowsazure.messaging; | ||
|
||
/** | ||
* This class represents a Firebase Cloud Messaging V1 installation. | ||
*/ | ||
public class FcmV1Installation extends Installation { | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Installation class. | ||
* | ||
* @param installationId The ID for the installation. | ||
*/ | ||
public FcmV1Installation(String installationId) { | ||
super(installationId, NotificationPlatform.FcmV1, null, (String[]) null); | ||
} | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Installation class. | ||
* | ||
* @param installationId The ID for the installation. | ||
* @param tags The tags for the installation. | ||
*/ | ||
public FcmV1Installation(String installationId, String... tags) { | ||
super(installationId, NotificationPlatform.FcmV1, null, tags); | ||
} | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Installation class. | ||
* | ||
* @param installationId The ID for the installation. | ||
*/ | ||
public FcmV1Installation(String installationId, String pushChannel) { | ||
super(installationId, NotificationPlatform.FcmV1, pushChannel, (String[]) null); | ||
} | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Installation class. | ||
* @param installationId The ID for the installation. | ||
* @param pushChannel The device specific push channel for the installation. | ||
* @param tags The tags for the installation. | ||
*/ | ||
public FcmV1Installation(String installationId, String pushChannel, String... tags) { | ||
super(installationId, NotificationPlatform.FcmV1, pushChannel, tags); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
NotificationHubs/src/com/windowsazure/messaging/FcmV1Notification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//---------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//---------------------------------------------------------------- | ||
|
||
package com.windowsazure.messaging; | ||
|
||
import org.apache.hc.core5.http.ContentType; | ||
|
||
/** | ||
* This class represents a notification to the Firebase Cloud Messaging V1 service. | ||
*/ | ||
public class FcmV1Notification extends Notification { | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Notification class. | ||
* @param body The JSON body for the Firebase Cloud Messaging V1 service. | ||
*/ | ||
public FcmV1Notification(String body) { | ||
this.body = body; | ||
this.contentType = ContentType.APPLICATION_JSON; | ||
this.headers.put("ServiceBusNotification-Format", "fcmv1"); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
NotificationHubs/src/com/windowsazure/messaging/FcmV1Registration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//---------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//---------------------------------------------------------------- | ||
|
||
package com.windowsazure.messaging; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Class representing a native registration for devices using FCM V1. | ||
*/ | ||
public class FcmV1Registration extends Registration { | ||
private static final String FCM_V1_NATIVE_REGISTRATION1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"><content type=\"application/xml\"><FcmV1RegistrationDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">"; | ||
private static final String FCM_V1_NATIVE_REGISTRATION2 = "<FcmV1RegistrationId>"; | ||
private static final String FCM_V1_NATIVE_REGISTRATION3 = "</FcmV1RegistrationId></FcmV1RegistrationDescription></content></entry>"; | ||
|
||
protected String fcmRegistrationId; | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Registration class. | ||
*/ | ||
public FcmV1Registration() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Registration with a registration ID and FCM registration ID. | ||
* @param registrationId The Azure Notification Hubs registration ID. | ||
* @param fcmRegistrationId The Firebase Cloud Messaging registration ID. | ||
*/ | ||
public FcmV1Registration(String registrationId, String fcmRegistrationId) { | ||
super(registrationId); | ||
this.fcmRegistrationId = fcmRegistrationId; | ||
} | ||
|
||
/** | ||
* Creates a new instance of the FcmV1Registration with a Firebase Cloud Messaging V1 registration ID. | ||
* @param fcmRegistrationId The Firebase Cloud Messaging V1 registration ID. | ||
*/ | ||
public FcmV1Registration(String fcmRegistrationId) { | ||
super(); | ||
this.fcmRegistrationId = fcmRegistrationId; | ||
} | ||
|
||
/** | ||
* Gets the Firebase Messaging registration ID. | ||
* @return The Firebase Messaging registration ID. | ||
*/ | ||
public String getFcmRegistrationId() { return fcmRegistrationId; } | ||
|
||
/** | ||
* Sets the Firebase Messaging registration ID. | ||
* @param value The Firebase Messaging registration ID to set. | ||
*/ | ||
public void setFcmRegistrationId(String value) { fcmRegistrationId = value; } | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (!super.equals(o)) return false; | ||
FcmV1Registration that = (FcmV1Registration) o; | ||
return Objects.equals(getFcmRegistrationId(), that.getFcmRegistrationId()); | ||
} | ||
|
||
/** | ||
* Gets the PNS handle for getting devices by channel. | ||
* @return The PNS handle for getting devices by channel. | ||
*/ | ||
@Override | ||
public String getPnsHandle() { return fcmRegistrationId; } | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), getFcmRegistrationId()); | ||
} | ||
|
||
@Override | ||
public String getXml() { | ||
return FCM_V1_NATIVE_REGISTRATION1 + | ||
getTagsXml() + | ||
FCM_V1_NATIVE_REGISTRATION2 + | ||
fcmRegistrationId + | ||
FCM_V1_NATIVE_REGISTRATION3; | ||
} | ||
|
||
} |
Oops, something went wrong.