Skip to content

Commit a3b21d3

Browse files
committed
Adds new required params to FirebaseApp.init
* Added required values to setApplicationId, setApiKey, and setProjectId that is used with FirebaseOptions.Builder * Added static defaults, with the option to override later via remote params.
1 parent e14efeb commit a3b21d3

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalRemoteParams.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.onesignal;
22

33
import android.support.annotation.NonNull;
4+
import android.support.annotation.Nullable;
45

56
import org.json.JSONArray;
67
import org.json.JSONException;
@@ -10,6 +11,12 @@
1011

1112
class OneSignalRemoteParams {
1213

14+
static class FCMParams {
15+
@Nullable String projectId;
16+
@Nullable String appId;
17+
@Nullable String apiKey;
18+
}
19+
1320
static class OutcomesParams {
1421
//in minutes
1522
int indirectAttributionWindow = DEFAULT_INDIRECT_ATTRIBUTION_WINDOW;
@@ -29,6 +36,7 @@ static class Params {
2936
boolean clearGroupOnSummaryClick;
3037
boolean receiveReceiptEnabled;
3138
OutcomesParams outcomesParams;
39+
FCMParams fcmParams;
3240
}
3341

3442
interface CallBack {
@@ -44,6 +52,11 @@ interface CallBack {
4452
private static final String NOTIFICATION_ATTRIBUTION_PARAM = "notification_attribution";
4553
private static final String UNATTRIBUTED_PARAM = "unattributed";
4654

55+
private static final String FCM_PARENT_PARAM = "fcm";
56+
private static final String FCM_PROJECT_ID = "project_id";
57+
private static final String FCM_APP_ID = "app_id";
58+
private static final String FCM_API_KEY = "api_key";
59+
4760
private static final int INCREASE_BETWEEN_RETRIES = 10_000;
4861
private static final int MIN_WAIT_BETWEEN_RETRIES = 30_000;
4962
private static final int MAX_WAIT_BETWEEN_RETRIES = 90_000;
@@ -109,8 +122,8 @@ static private void processJson(String json, final @NonNull CallBack callBack) {
109122
googleProjectNumber = responseJson.optString("android_sender_id", null);
110123
clearGroupOnSummaryClick = responseJson.optBoolean("clear_group_on_summary_click", true);
111124
receiveReceiptEnabled = responseJson.optBoolean("receive_receipts_enable", false);
112-
outcomesParams = new OutcomesParams();
113125

126+
outcomesParams = new OutcomesParams();
114127
// Process outcomes params
115128
if (responseJson.has(OUTCOME_PARAM)) {
116129
JSONObject outcomes = responseJson.optJSONObject(OUTCOME_PARAM);
@@ -134,6 +147,14 @@ static private void processJson(String json, final @NonNull CallBack callBack) {
134147
outcomesParams.unattributedEnabled = unattributed.optBoolean(ENABLED_PARAM);
135148
}
136149
}
150+
151+
fcmParams = new FCMParams();
152+
if (responseJson.has(FCM_PARENT_PARAM)) {
153+
JSONObject fcm = responseJson.optJSONObject(FCM_PARENT_PARAM);
154+
fcmParams.apiKey = fcm.optString(FCM_API_KEY, null);
155+
fcmParams.appId = fcm.optString(FCM_APP_ID, null);
156+
fcmParams.projectId = fcm.optString(FCM_PROJECT_ID, null);
157+
}
137158
}};
138159

139160
callBack.complete(params);

OneSignalSDK/onesignal/src/main/java/com/onesignal/PushRegistratorFCM.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.content.ComponentName;
3131
import android.content.Context;
3232
import android.content.pm.PackageManager;
33+
import android.support.annotation.NonNull;
3334

3435
import com.google.firebase.FirebaseApp;
3536
import com.google.firebase.FirebaseOptions;
@@ -43,6 +44,10 @@
4344

4445
class PushRegistratorFCM extends PushRegistratorAbstractGoogle {
4546

47+
private static final String FCM_DEFAULT_PROJECT_ID = "onesignal-shared-public"; // project_info.project_id
48+
private static final String FCM_DEFAULT_APP_ID = "1:754795614042:android:c682b8144a8dd52bc1ad63"; // client.client_info.mobilesdk_app_id
49+
private static final String FCM_DEFAULT_API_KEY = "AIzaSyAnTLn5-_4Mc2a2P-dKUeE-aBtgyCrjlYU"; // client.api_key.current_key
50+
4651
private static final String FCM_APP_NAME = "ONESIGNAL_SDK_FCM_APP_NAME";
4752

4853
private FirebaseApp firebaseApp;
@@ -92,9 +97,28 @@ private void initFirebaseApp(String senderId) {
9297
FirebaseOptions firebaseOptions =
9398
new FirebaseOptions.Builder()
9499
.setGcmSenderId(senderId)
95-
.setApplicationId("OMIT_ID")
96-
.setApiKey("OMIT_KEY")
100+
.setApplicationId(getAppId())
101+
.setApiKey(getApiKey())
102+
.setProjectId(getProjectId())
97103
.build();
98104
firebaseApp = FirebaseApp.initializeApp(OneSignal.appContext, firebaseOptions, FCM_APP_NAME);
99105
}
106+
107+
private static @NonNull String getAppId() {
108+
if (OneSignal.remoteParams.fcmParams.appId != null)
109+
return OneSignal.remoteParams.fcmParams.appId;
110+
return FCM_DEFAULT_APP_ID;
111+
}
112+
113+
private static @NonNull String getApiKey() {
114+
if (OneSignal.remoteParams.fcmParams.apiKey != null)
115+
return OneSignal.remoteParams.fcmParams.apiKey;
116+
return FCM_DEFAULT_API_KEY;
117+
}
118+
119+
private static @NonNull String getProjectId() {
120+
if (OneSignal.remoteParams.fcmParams.projectId != null)
121+
return OneSignal.remoteParams.fcmParams.projectId;
122+
return FCM_DEFAULT_PROJECT_ID;
123+
}
100124
}

0 commit comments

Comments
 (0)