Skip to content

Commit

Permalink
BKNDLSS-32464 Push notifications do not come if the app is closed (#11)
Browse files Browse the repository at this point in the history
* BKNDLSS-32464 Push notifications do not come if the app is closed

* Give a possibility of null values for appId and apiKey.

---------

Co-authored-by: oleg.vyalyh <[email protected]>
  • Loading branch information
oleg-vyalyh and vyalyh-oleg authored May 31, 2023
1 parent bb5a2e9 commit 92b8254
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 29 deletions.
2 changes: 1 addition & 1 deletion android-client-sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'com.android.library' version '7.4.0-beta02'
id 'com.android.library' version '7.4.1'
}

group 'com.backendless'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected void retrieveOSVersion()
public void init()
{
this.sharedPreferences = ((Context) getContext()).getSharedPreferences( PREFS_NAME, Context.MODE_PRIVATE );
this.restoreAuthKeysFromPreferences();
super.init();
}

Expand Down Expand Up @@ -156,18 +157,7 @@ private boolean restoreHeadersFromPreferences()
return false;
}

private synchronized AuthKeys getAuthKeys()
{
if( authKeys == null )
restoreAuthKeysFromPreferences();

if( authKeys == null && getCustomDomain() == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

return authKeys;
}

private boolean restoreAuthKeysFromPreferences()
protected boolean restoreAuthKeysFromPreferences()
{
if( sharedPreferences == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import com.backendless.Backendless;
import com.backendless.BackendlessInjector;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessFault;
Expand Down Expand Up @@ -51,6 +52,11 @@ public boolean onMessage( Context appContext, Intent msgIntent )

public BackendlessFCMService()
{
// will init the backendless sdk according to the current environment
// also calls initApp() if appId and apiKey were stored in prefs
if ( !Backendless.isInitialized() )
Log.w( TAG, "Backendless app wasn't initialized before or android app was reset." );

if( BackendlessFCMService.notificationIdGenerator == null )
BackendlessFCMService.notificationIdGenerator = new AtomicInteger( injector.getPrefs().getNotificationIdGeneratorInitValue() );
}
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ android.useAndroidX=true
android.nonTransitiveRClass=true
android.disableAutomaticComponentCreation=true

version.java-sdk-common = 7.0.2
version.java-client-sdk = 7.0.2
version.android-client-sdk = 7.0.2
version.java-sdk-common = 7.0.3
version.java-client-sdk = 7.0.3
version.android-client-sdk = 7.0.3
version.backendless-commons = 6.7.4.0
version.weborbclient = 5.2.0.8
version.io-socket-client = 2.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.backendless;

import com.backendless.exceptions.ExceptionMessage;

import java.util.UUID;
import java.util.prefs.Preferences;


class JavaBackendlessPrefs extends BackendlessPrefs
Expand Down Expand Up @@ -39,4 +42,28 @@ public void init()
{
super.init();
}

protected boolean restoreAuthKeysFromPreferences()
{
// At the moment, restoring the auth information in the Desktop/CodeRunner environment is not provided.
// I think the code should be like this:

/*
private final Preferences prefs = Preferences.userRoot().node( this.getClass().getName() );
if( prefs == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
String applicationId = prefs.get( Type.APPLICATION_ID_KEY.name64(), null );
String apiKey = prefs.get( Type.API_KEY.name64(), null );
if( applicationId != null && apiKey != null )
{
authKeys = new AuthKeys( applicationId, apiKey );
return true;
}
*/
return false;
}
}
23 changes: 13 additions & 10 deletions java-sdk-common/src/main/java/com/backendless/BackendlessPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ public abstract class BackendlessPrefs

abstract protected void retrieveOSVersion();

abstract protected boolean restoreAuthKeysFromPreferences();

protected synchronized AuthKeys getAuthKeys()
{
if( authKeys == null )
restoreAuthKeysFromPreferences();

// if( authKeys == null && getCustomDomain() == null )
// throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

return authKeys;
}

public void init()
{
this.retrieveDeviceId();
Expand Down Expand Up @@ -77,16 +90,6 @@ public synchronized HashMap<String, String> getHeaders()
return headers;
}

private synchronized AuthKeys getAuthKeys()
{
return authKeys;
}

boolean isAuthKeysExist()
{
return authKeys != null;
}

public void setUrl( String url )
{
this.url = url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import java.util.List;
import java.util.Map;

/**
* Created by oleg on 22.07.15.
*/

public class InvocationContext extends AbstractContext
{
private static ThreadLocal<InvocationContext> threadLocal = new InheritableThreadLocal<InvocationContext>(){
Expand Down

0 comments on commit 92b8254

Please sign in to comment.