-
Notifications
You must be signed in to change notification settings - Fork 29
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 #100 from Iterable/chore/MOB-372-remove-powermock
[MOB-372] Remove PowerMock from most tests
- Loading branch information
Showing
5 changed files
with
59 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
|
||
import org.json.JSONObject; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Created by David Truong [email protected] | ||
*/ | ||
|
@@ -64,8 +66,7 @@ PushRegistrationObject getDeviceToken() { | |
return null; | ||
} | ||
|
||
FirebaseInstanceId instanceID = FirebaseInstanceId.getInstance(); | ||
return new PushRegistrationObject(instanceID.getToken()); | ||
return new PushRegistrationObject(Util.getFirebaseToken()); | ||
|
||
} catch (Exception e) { | ||
IterableLogger.e(TAG, "Exception while retrieving the device token: check that firebase is added to the build dependencies", e); | ||
|
@@ -85,7 +86,7 @@ private void disableOldDeviceIfNeeded() { | |
final SharedPreferences sharedPref = applicationContext.getSharedPreferences(IterableConstants.PUSH_APP_ID, Context.MODE_PRIVATE); | ||
boolean migrationDone = sharedPref.getBoolean(IterableConstants.SHARED_PREFS_FCM_MIGRATION_DONE_KEY, false); | ||
if (!migrationDone) { | ||
String oldToken = FirebaseInstanceId.getInstance().getToken(gcmSenderId, IterableConstants.MESSAGING_PLATFORM_GOOGLE); | ||
String oldToken = Util.getFirebaseToken(gcmSenderId, IterableConstants.MESSAGING_PLATFORM_GOOGLE); | ||
|
||
// We disable the device on Iterable but keep the token | ||
if (oldToken != null) { | ||
|
@@ -104,16 +105,46 @@ public void onSuccess(JSONObject data) { | |
} | ||
|
||
static class Util { | ||
static UtilImpl instance = new UtilImpl(); | ||
|
||
static int getFirebaseResouceId(Context applicationContext) { | ||
return applicationContext.getResources().getIdentifier(IterableConstants.FIREBASE_RESOURCE_ID, IterableConstants.ANDROID_STRING, applicationContext.getPackageName()); | ||
return instance.getFirebaseResouceId(applicationContext); | ||
} | ||
|
||
static String getFirebaseToken() { | ||
return instance.getFirebaseToken(); | ||
} | ||
|
||
static String getFirebaseToken(String senderId, String platform) throws IOException { | ||
return instance.getFirebaseToken(senderId, platform); | ||
} | ||
|
||
static String getSenderId(Context applicationContext) { | ||
int resId = applicationContext.getResources().getIdentifier(IterableConstants.FIREBASE_SENDER_ID, IterableConstants.ANDROID_STRING, applicationContext.getPackageName()); | ||
if (resId != 0) { | ||
return applicationContext.getResources().getString(resId); | ||
} else { | ||
return null; | ||
return instance.getSenderId(applicationContext); | ||
} | ||
|
||
static class UtilImpl { | ||
int getFirebaseResouceId(Context applicationContext) { | ||
return applicationContext.getResources().getIdentifier(IterableConstants.FIREBASE_RESOURCE_ID, IterableConstants.ANDROID_STRING, applicationContext.getPackageName()); | ||
} | ||
|
||
String getFirebaseToken() { | ||
FirebaseInstanceId instanceID = FirebaseInstanceId.getInstance(); | ||
return instanceID.getToken(); | ||
} | ||
|
||
String getFirebaseToken(String senderId, String platform) throws IOException { | ||
FirebaseInstanceId instanceId = FirebaseInstanceId.getInstance(); | ||
return instanceId.getToken(senderId, platform); | ||
} | ||
|
||
String getSenderId(Context applicationContext) { | ||
int resId = applicationContext.getResources().getIdentifier(IterableConstants.FIREBASE_SENDER_ID, IterableConstants.ANDROID_STRING, applicationContext.getPackageName()); | ||
if (resId != 0) { | ||
return applicationContext.getResources().getString(resId); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
} | ||
|
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