Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new remote params #1076

Merged
merged 4 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ gen/

# Proguard folder generated by Eclipse
proguard/

# Examples

Examples/AndroidStudio/
Examples/OneSignalDemo/app/build/
OneSignalSDK/app/build/
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public void onCreate() {
OneSignal.setAppId(appId);
OneSignal.setAppContext(this);

OneSignal.unsubscribeWhenNotificationsAreDisabled(true);
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification);
OneSignal.pauseInAppMessages(true);
OneSignal.setLocationShared(false);

Log.d(Tag.DEBUG, Text.ONESIGNAL_SDK_INIT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public void onClick(View v) {
locationSharedSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
OneSignal.setLocationShared(isChecked);
// TODO remove element, was replaced by remote params
}
});
}
mikechoch marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,9 @@ public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) {
}

private void setupOneSignalSDK() {
boolean privacyConsent = true;
OneSignal.setRequiresUserPrivacyConsent(privacyConsent);

boolean isLocationShared = OneSignalPrefs.getCachedLocationSharedStatus(context);
OneSignal.setLocationShared(isLocationShared);

boolean isInAppMessagingPaused = OneSignalPrefs.getCachedInAppMessagingPausedStatus(context);
OneSignal.pauseInAppMessages(isInAppMessagingPaused);

Log.d(Tag.DEBUG, Text.PRIVACY_CONSENT_REQUIRED_SET + ": " + privacyConsent);

boolean isEmailCached = attemptSignIn(new EmailUpdateCallback() {
@Override
public void onSuccess() {
Expand Down Expand Up @@ -158,17 +150,7 @@ private void attemptEnterApplication() {
return;
}

((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
intentTo.mainActivity();
}
}, 1000);
}
});
((Activity) context).runOnUiThread(() -> new Handler().postDelayed(() -> intentTo.mainActivity(), 1000));
}

}
3 changes: 2 additions & 1 deletion OneSignalSDK/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.gradle
local.properties
Examples/OneSignalDemo/local.properties
.DS_Store
/build
/captures
*.gpg
/**/.idea
*.iml
*.iml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
*/

import android.content.Context;
import com.onesignal.OneSignal.NotificationOpenedHandler;
import com.onesignal.OneSignal.NotificationWillShowInForegroundHandler;

class DelayedConsentInitializationParameters {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static void initGoogleLocation() {
.addApi(LocationServices.API)
.addConnectionCallbacks(googleApiClientListener)
.addOnConnectionFailedListener(googleApiClientListener)
.setHandler(locationHandlerThread.mHandler)
.setHandler(getLocationHandlerThread().mHandler)
.build();

GMSLocationController.googleApiClient = new GoogleApiClientCompatProxy(googleApiClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void showUpdateGPSDialog() {
@Override
public void run() {
final Activity activity = ActivityLifecycleHandler.curActivity;
if (activity == null || OneSignal.mDisableGmsMissingPrompt)
if (activity == null || OneSignal.getDisableGMSMissingPrompt())
return;

// Load resource strings so a developer can customize this dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void init() {
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);

OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "HMSLocationController Huawei LocationServices requestLocationUpdates!");
huaweiFusedLocationProviderClient.requestLocationUpdates(locationRequest, this, locationHandlerThread.getLooper());
huaweiFusedLocationProviderClient.requestLocationUpdates(locationRequest, this, getLocationHandlerThread().getLooper());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ class LocationController {
private static boolean locationCoarse;

static final Object syncLock = new Object() {};
static LocationHandlerThread locationHandlerThread;

private static LocationHandlerThread locationHandlerThread;
static LocationHandlerThread getLocationHandlerThread() {
if (locationHandlerThread == null) {
jkasten2 marked this conversation as resolved.
Show resolved Hide resolved
synchronized (syncLock) {
if (locationHandlerThread == null)
locationHandlerThread = new LocationHandlerThread();
}
}
return locationHandlerThread;
}

static Thread fallbackFailThread;
static Context classContext;
static Location lastLocation;
Expand Down Expand Up @@ -100,7 +111,7 @@ void onAnswered(OneSignal.PromptActionResult result) {}
}

static boolean scheduleUpdate(Context context) {
if (!hasLocationPermission(context) || !OneSignal.shareLocation)
if (!hasLocationPermission(context) || !OneSignal.isLocationShared())
return false;

long lastTime = System.currentTimeMillis() - getLastLocationTime();
Expand Down Expand Up @@ -175,7 +186,7 @@ static void getLocation(Context context, boolean promptLocation, boolean fallbac
classContext = context;
locationHandlers.put(handler.getType(), handler);

if (!OneSignal.shareLocation) {
if (!OneSignal.isLocationShared()) {
sendAndClearPromptHandlers(promptLocation, OneSignal.PromptActionResult.ERROR);
fireFailedComplete();
return;
Expand Down Expand Up @@ -253,9 +264,6 @@ else if (permissionList.contains("android.permission.ACCESS_COARSE_LOCATION")) {
static void startGetLocation() {
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "LocationController startGetLocation with lastLocation: " + lastLocation);

if (locationHandlerThread == null)
locationHandlerThread = new LocationHandlerThread();

try {
if (isGooglePlayServicesAvailable()) {
GMSLocationController.startGetLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void clearOldestOverLimitStandard(Context context, int notifsToMakeRoomFo
}

// Clear the oldest based on the count in notifsToClear
for(Map.Entry<Long, Integer> mapData : activeNotifIds.entrySet()) {
for (Map.Entry<Long, Integer> mapData : activeNotifIds.entrySet()) {
OneSignal.cancelNotification(mapData.getValue());
if (--notifsToClear <= 0)
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class OSLogWrapper implements OSLogger {


public void verbose(@NonNull String message) {
OneSignal.Log(OneSignal.LOG_LEVEL.VERBOSE, message);
}
Expand All @@ -14,10 +13,20 @@ public void debug(@NonNull String message) {
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, message);
}

@Override
public void info(@NonNull String message) {
OneSignal.Log(OneSignal.LOG_LEVEL.INFO, message);
}

public void warning(@NonNull String message) {
OneSignal.Log(OneSignal.LOG_LEVEL.WARN, message);
}

@Override
public void error(@NonNull String message) {
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, message);
}

public void error(@NonNull String message, @Nullable Throwable throwable) {
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, message, throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ public interface OSLogger {

void debug(@NonNull String message);

void info(@NonNull String message);

void warning(@NonNull String message);

void error(@NonNull String message);

void error(@NonNull String message, @Nullable Throwable throwable);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.onesignal;

import com.onesignal.influence.OSTrackerFactory;

class OSRemoteParamController {

private OneSignalRemoteParams.Params remoteParams = null;

OSRemoteParamController() {
}

/**
* Save RemoteParams result of android_params request
*/
void saveRemoteParams(OneSignalRemoteParams.Params remoteParams,
OSTrackerFactory trackerFactory,
OSSharedPreferences preferences,
OSLogger logger) {
this.remoteParams = remoteParams;

OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_GT_FIREBASE_TRACKING_ENABLED,
remoteParams.firebaseAnalytics
);
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_RESTORE_TTL_FILTER,
remoteParams.restoreTTLFilter
);
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_CLEAR_GROUP_SUMMARY_CLICK,
remoteParams.clearGroupOnSummaryClick
);
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_RECEIVE_RECEIPTS_ENABLED,
remoteParams.receiveReceiptEnabled
);
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_UNSUBSCRIBE_WHEN_NOTIFICATIONS_DISABLED,
remoteParams.unsubscribeWhenNotificationsDisabled
);
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_DISABLE_GMS_MISSING_PROMPT,
remoteParams.disableGMSMissingPrompt
);
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
preferences.getOutcomesV2KeyName(),
remoteParams.influenceParams.outcomesV2ServiceEnabled
);

logger.debug("OneSignal saveInfluenceParams: " + remoteParams.influenceParams.toString());
trackerFactory.saveInfluenceParams(remoteParams.influenceParams);

saveLocationShared(remoteParams.locationShared);
OneSignal.setSharedLocation(remoteParams.locationShared);
savePrivacyConsentRequired(remoteParams.requiresUserPrivacyConsent);
}

boolean isRemoteParamsCallDone() {
return remoteParams != null;
}

OneSignalRemoteParams.Params getRemoteParams() {
return remoteParams;
}

void clearRemoteParams() {
remoteParams = null;
}

boolean getFirebaseAnalyticsEnabled() {
return OneSignalPrefs.getBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_GT_FIREBASE_TRACKING_ENABLED,
false);
}

boolean getClearGroupSummaryClick() {
return OneSignalPrefs.getBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_CLEAR_GROUP_SUMMARY_CLICK,
true);
}

boolean unsubscribeWhenNotificationsAreDisabled() {
return OneSignalPrefs.getBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_UNSUBSCRIBE_WHEN_NOTIFICATIONS_DISABLED,
true);
}

boolean isGMSMissingPromptDisable() {
return OneSignalPrefs.getBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_DISABLE_GMS_MISSING_PROMPT,
false);
}

boolean isLocationShared() {
return OneSignalPrefs.getBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_LOCATION_SHARED,
true);
}

void saveLocationShared(boolean shared) {
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_LOCATION_SHARED,
shared);
}

boolean isPrivacyConsentRequired() {
return OneSignalPrefs.getBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_REQUIRES_USER_PRIVACY_CONSENT,
true);
}


void savePrivacyConsentRequired(boolean required) {
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_OS_REQUIRES_USER_PRIVACY_CONSENT,
required);
}

boolean getSavedUserConsentStatus() {
return OneSignalPrefs.getBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_ONESIGNAL_USER_PROVIDED_CONSENT,
false);
}

void saveUserConsentStatus(boolean consent) {
OneSignalPrefs.saveBool(
OneSignalPrefs.PREFS_ONESIGNAL,
OneSignalPrefs.PREFS_ONESIGNAL_USER_PROVIDED_CONSENT,
consent);
}
}
Loading