Is there a GCM registrationId pattern?
Asked Answered
P

2

7
/**
 * @author Sebastien Lorber <i>([email protected])</i>
 */
public enum EnumDeviceType {

    ANDROID {
        @Override
        public boolean validateDeviceIdentifier(String deviceIdentifier) {
            Preconditions.checkArgument( !Strings.isNullOrEmpty(deviceIdentifier) );
            return ANDROID_REGISTRATION_ID_PATTERN.matcher(deviceIdentifier).matches();
        }
    },
    IOS {
        @Override
        public boolean validateDeviceIdentifier(String deviceIdentifier) {
            Preconditions.checkArgument( !Strings.isNullOrEmpty(deviceIdentifier) );
            return IOS_DEVICE_TOKEN_PATTERN.matcher(deviceIdentifier).matches();
        }
    },
    ;

    // TODO how do we validate registration Ids
    public static final Pattern ANDROID_REGISTRATION_ID_PATTERN = Pattern.compile(".*");
    // IOS device token is a 64 HEX string
    public static final Pattern IOS_DEVICE_TOKEN_PATTERN = Pattern.compile("[a-fA-F0-9]{64,64}");


    public abstract boolean validateDeviceIdentifier(String deviceIdentifier);


    public boolean isIos() {
        return IOS.equals(this);
    }

    public boolean isAndroid() {
        return ANDROID.equals(this);
    }


}

Is there any known pattern for the GCM registrationId i can use to validate on application that the registrationId has a correct shape? I would just like to know which range of chars it has, which is the minimum and maximum size for exemple... or any other information...

Pliocene answered 13/9, 2012 at 9:50 Comment(0)
R
16

The documentation doesn't specify any pattern, therefore any valid string is allowed. The format may change in the future; please do not validate this input against any pattern, as this may cause your app to break if this happens.

As with the "registration_id" field, the upper bound on size is the max size for a cookie, which is 4K (4096 bytes).

Ranie answered 19/9, 2012 at 20:27 Comment(0)
H
17

I hasn't seen any official information about format of GCM registrationId, but I've analyzed our database of such IDs and can make following conclusions:

  • in most cases length of a registrationID equals 162 symbols, but can be variations to 119 symbols, maybe other lengths too;
  • it consists only from this chars: [0-9a-zA-Z\-\_]*
  • every regID contains one or both of "delimiters": - (minus) or _ (underline)
Hanako answered 13/9, 2012 at 11:15 Comment(2)
GCM3 returns registrationId's with other chars ex. ':'Sensate
I get two kind lengths in my database. most 162 symbols and some 140 symbols.Uncouth
R
16

The documentation doesn't specify any pattern, therefore any valid string is allowed. The format may change in the future; please do not validate this input against any pattern, as this may cause your app to break if this happens.

As with the "registration_id" field, the upper bound on size is the max size for a cookie, which is 4K (4096 bytes).

Ranie answered 19/9, 2012 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.