Make registration ID optionally extended.
This commit is contained in:
parent
2db44a1578
commit
7b1a37bd91
1 changed files with 9 additions and 2 deletions
|
@ -38,11 +38,18 @@ public class KeyHelper {
|
|||
* Generate a registration ID. Clients should only do this once,
|
||||
* at install time.
|
||||
*
|
||||
* @param extendedRange By default (false), the generated registration
|
||||
* ID is sized to require the minimal possible protobuf
|
||||
* encoding overhead. Specify true if the caller needs
|
||||
* the full range of MAX_INT at the cost of slightly
|
||||
* higher encoding overhead.
|
||||
* @return the generated registration ID.
|
||||
*/
|
||||
public static int generateRegistrationId() {
|
||||
public static int generateRegistrationId(boolean extendedRange) {
|
||||
try {
|
||||
return SecureRandom.getInstance("SHA1PRNG").nextInt(16380) + 1;
|
||||
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
|
||||
if (extendedRange) return secureRandom.nextInt(Integer.MAX_VALUE - 1) + 1;
|
||||
else return secureRandom.nextInt(16380) + 1;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue