@@ -111,13 +111,60 @@ public boolean isInitialized() {
111111 return senderIds != null || getCurrentRegistrationId () != null ;
112112 }
113113
114- /**
115- * Unregister from GCM.
116- */
114+ @ Override
115+ public boolean isManifestSetup () {
116+ Context context = Leanplum .getContext ();
117+ if (context == null ) {
118+ return false ;
119+ }
120+ // We don't want to check if manifest is setup in Release build.
121+ if (!BuildConfig .DEBUG ) {
122+ return true ;
123+ }
124+ try {
125+ boolean hasPermissions = LeanplumManifestHelper .checkPermission (LeanplumManifestHelper .RECEIVE_PERMISSION , false , true )
126+ && (LeanplumManifestHelper .checkPermission (context .getPackageName () + ".gcm.permission.C2D_MESSAGE" , true , false )
127+ || LeanplumManifestHelper .checkPermission (context .getPackageName () + ".permission.C2D_MESSAGE" , true , true ));
128+
129+ boolean hasGcmReceiver = LeanplumManifestHelper .checkComponent (
130+ LeanplumManifestHelper .ApplicationComponent .RECEIVER , LeanplumManifestHelper .GCM_RECEIVER ,
131+ true , LeanplumManifestHelper .SEND_PERMISSION , Arrays .asList (LeanplumManifestHelper .RECEIVE_ACTION ,
132+ LeanplumManifestHelper .REGISTRATION_ACTION ), context .getPackageName ());
133+ boolean hasPushReceiver = LeanplumManifestHelper .checkComponent (LeanplumManifestHelper .ApplicationComponent .RECEIVER ,
134+ LeanplumPushReceiver .class .getName (), false , null ,
135+ Collections .singletonList (LeanplumManifestHelper .PUSH_LISTENER_SERVICE_FILTER ), null );
136+
137+ boolean hasReceivers = hasGcmReceiver && hasPushReceiver ;
138+
139+ boolean hasPushListenerService = LeanplumManifestHelper .checkComponent (
140+ LeanplumManifestHelper .ApplicationComponent .SERVICE ,
141+ LeanplumPushListenerService .class .getName (), false , null ,
142+ Collections .singletonList (LeanplumManifestHelper .RECEIVE_ACTION ), null );
143+ boolean hasInstanceIdService = LeanplumManifestHelper .checkComponent (
144+ LeanplumManifestHelper .ApplicationComponent .SERVICE ,
145+ LeanplumPushInstanceIDService .class .getName (), false , null ,
146+ Collections .singletonList (LeanplumManifestHelper .INSTANCE_ID_ACTION ), null );
147+ boolean hasRegistrationService = LeanplumManifestHelper .checkComponent (
148+ LeanplumManifestHelper .ApplicationComponent .SERVICE ,
149+ LeanplumPushRegistrationService .class .getName (), false , null , null , null );
150+
151+ boolean hasServices = hasPushListenerService && hasInstanceIdService && hasRegistrationService ;
152+
153+ if (hasPermissions && hasReceivers && hasServices ) {
154+ Log .i ("Google Cloud Messaging is setup correctly." );
155+ return true ;
156+ }
157+ } catch (Throwable t ) {
158+ Util .handleException (t );
159+ }
160+ Log .i ("Failed to setup Google Cloud Messaging, check your manifest configuration." );
161+ return false ;
162+ }
163+
117164 public void unregister () {
118165 try {
119166 InstanceID .getInstance (Leanplum .getContext ()).deleteInstanceID ();
120- Log .i ("Application was unregistred from GCM." );
167+ Log .i ("Application was unregistered from GCM." );
121168 } catch (Exception e ) {
122169 Log .e ("Failed to unregister from GCM." );
123170 }
0 commit comments