Skip to content

Commit

Permalink
Release 14.9.0 (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Mar 21, 2023
1 parent 1c50da9 commit 13f5276
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 13 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Cordova Plugin Changelog

## Version 14.9.0 - March 21, 2023
Minor release that adds a new Android config flag `com.urbanairship.android.disable_user_notifications_on_system_opt_out` that will disable user notifications on Airship if not enabled at the system level during app start. Apps can set this to `always` to always do this check, or `once` to apply a one time disable on Airship.

This new flag is useful for preventing a notification permission prompt if the app previously enabled Airship user notifications on plugin 14.2.0 or older on a Android 33+ device. Most apps should use `once` value in order for Airship to still be able to send user notifications if the end user ops back in through system settings instead of through the app without the App needing to enable user notification on Airship again.

### Changes
- Added new config flag on Android to disable user notifications on startup.
- Fixed enableUserNotifications on Android to hand back the actual result of the prompt instead of always `true`.

## Version 14.8.0 - March 10, 2023
Minor release updating Android SDK to 16.9.0 and iOS SDK to 16.11.2.

Expand Down
2 changes: 1 addition & 1 deletion urbanairship-accengage-cordova/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "urbanairship-accengage-cordova",
"version": "14.8.0",
"version": "14.9.0",
"description": "Urban Airship-Accengage Cordova plugin",
"cordova": {
"id": "urbanairship-accengage-cordova",
Expand Down
6 changes: 3 additions & 3 deletions urbanairship-accengage-cordova/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="urbanairship-accengage-cordova"
version="14.8.0"
version="14.9.0"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">

Expand All @@ -16,13 +16,13 @@
<engine name="cordova" version=">=9.0.1"/>
</engines>

<dependency id="urbanairship-cordova" version="14.8.0"/>
<dependency id="urbanairship-cordova" version="14.9.0"/>

<!-- ios -->
<platform name="ios">

<config-file target="*-Info.plist" parent="UACordovaPluginVersion">
<string>14.8.0</string>
<string>14.9.0</string>
</config-file>

<!-- Airship Accengage Module -->
Expand Down
2 changes: 1 addition & 1 deletion urbanairship-cordova/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "urbanairship-cordova",
"version": "14.8.0",
"version": "14.9.0",
"description": "Urban Airship Cordova plugin",
"cordova": {
"id": "urbanairship-cordova",
Expand Down
6 changes: 3 additions & 3 deletions urbanairship-cordova/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin id="urbanairship-cordova"
version="14.8.0"
version="14.9.0"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">

Expand Down Expand Up @@ -40,7 +40,7 @@
<config-file parent="/manifest/application" target="AndroidManifest.xml">
<meta-data
android:name="com.urbanairship.cordova.version"
android:value="14.8.0"/>
android:value="14.9.0"/>

<meta-data
android:name="com.urbanairship.autopilot"
Expand Down Expand Up @@ -145,7 +145,7 @@
</config-file>

<config-file target="*-Info.plist" parent="UACordovaPluginVersion">
<string>14.8.0</string>
<string>14.9.0</string>
</config-file>

<config-file parent="/widget" target="config.xml">
Expand Down
18 changes: 18 additions & 0 deletions urbanairship-cordova/src/android/CordovaAutopilot.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.XmlRes;
import androidx.core.app.NotificationManagerCompat;

import com.urbanairship.AirshipConfigOptions;
import com.urbanairship.Autopilot;
Expand Down Expand Up @@ -60,6 +61,23 @@ public void onAirshipReady(@NonNull UAirship airship) {
final Context context = UAirship.getApplicationContext();
final PluginManager pluginManager = PluginManager.shared(context);

PluginManager.NotificationsOptedOutFlag optOutFlag = pluginManager.getDisableNotificationsOnOptOut();
if (optOutFlag != null) {
if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) {
switch(optOutFlag) {
case ONCE:
if (!pluginManager.getProcessedNotificationOptOutFlag()) {
airship.getPushManager().setUserNotificationsEnabled(false);
}
break;
case ALWAYS:
airship.getPushManager().setUserNotificationsEnabled(false);
break;
}
}
pluginManager.editConfig().setProcessedNotificationsOptedOutFlag(true).apply();
}

if (pluginManager.getEnablePushOnLaunch()) {
airship.getPushManager().setUserNotificationsEnabled(true);
}
Expand Down
46 changes: 46 additions & 0 deletions urbanairship-cordova/src/android/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package com.urbanairship.cordova;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
Expand Down Expand Up @@ -31,13 +32,19 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
* Plugin manager.
*/
public class PluginManager {

enum NotificationsOptedOutFlag {
ALWAYS,
ONCE
}

/**
* Interface when a new event is received.
*/
Expand All @@ -55,6 +62,10 @@ public interface Listener {
private static final String DEVELOPMENT_LOG_LEVEL = "com.urbanairship.development_log_level";
private static final String IN_PRODUCTION = "com.urbanairship.in_production";
private static final String ENABLE_PUSH_ONLAUNCH = "com.urbanairship.enable_push_onlaunch";

private static final String DISABLE_ANDROID_NOTIFICATIONS_ON_OPT_OUT = "com.urbanairship.android.disable_user_notifications_on_system_opt_out";
private static final String PROCESSED_NOTIFICATIONS_OPTED_OUT_FLAG = "com.urbanairship.PROCESSED_NOTIFICATIONS_OPTED_OUT_FLAG";

private static final String NOTIFICATION_ICON = "com.urbanairship.notification_icon";
private static final String NOTIFICATION_LARGE_ICON = "com.urbanairship.notification_large_icon";
private static final String NOTIFICATION_ACCENT_COLOR = "com.urbanairship.notification_accent_color";
Expand All @@ -66,6 +77,7 @@ public interface Listener {
private static final String INITIAL_CONFIG_URL = "com.urbanairship.initial_config_url";

private static final String NOTIFICATION_OPT_IN_STATUS_EVENT_PREFERENCES_KEY = "com.urbanairship.notification_opt_in_status_preferences";

private static final String DEFAULT_NOTIFICATION_CHANNEL_ID = "com.urbanairship.default_notification_channel_id";
private static final String FOREGROUND_NOTIFICATIONS = "com.urbanairship.foreground_notifications";

Expand Down Expand Up @@ -326,6 +338,7 @@ public void setListener(@Nullable Listener listener) {
*
* @return The airship config if available, or null if the plugin is not configured.
*/
@SuppressLint("RestrictedApi")
@Nullable
public AirshipConfigOptions getAirshipConfig() {
if (configOptions != null) {
Expand Down Expand Up @@ -379,6 +392,29 @@ public boolean getEnablePushOnLaunch() {
return getConfigBoolean(ENABLE_PUSH_ONLAUNCH, false);
}

@Nullable
public NotificationsOptedOutFlag getDisableNotificationsOnOptOut() {
String disableNotifications = getConfigString(DISABLE_ANDROID_NOTIFICATIONS_ON_OPT_OUT, null);
if (UAStringUtil.isEmpty(disableNotifications)) {
return null;
}

switch (disableNotifications.toLowerCase(Locale.ROOT).trim()) {
case "once":
return NotificationsOptedOutFlag.ONCE;
case "always":
return NotificationsOptedOutFlag.ALWAYS;
default:
PluginLogger.error("Invalid value for %s: %s", DISABLE_ANDROID_NOTIFICATIONS_ON_OPT_OUT, disableNotifications);
}

return null;
}

boolean getProcessedNotificationOptOutFlag() {
return sharedPreferences.getBoolean(PROCESSED_NOTIFICATIONS_OPTED_OUT_FLAG, false);
}

/**
* Gets the auto launch message center option.
*
Expand Down Expand Up @@ -493,6 +529,8 @@ private int getConfigColor(@NonNull String key, @ColorInt int defaultColor) {
return defaultColor;
}



/**
* Gets a resource value from the config.
*
Expand Down Expand Up @@ -534,6 +572,8 @@ private String getConfigValue(@NonNull String key) {
return sharedPreferences.getString(key, defaultConfigValues.get(key));
}



/**
* Helper method to notify the listener of the event.
*
Expand Down Expand Up @@ -671,6 +711,12 @@ public ConfigEditor setForegroundNotificationsEnabled(boolean allow) {
return this;
}

@NonNull
public ConfigEditor setProcessedNotificationsOptedOutFlag(boolean optedNotificationsOut) {
editor.putBoolean(PROCESSED_NOTIFICATIONS_OPTED_OUT_FLAG, optedNotificationsOut);
return this;
}

/**
* Sets the cloud site.
*
Expand Down
16 changes: 14 additions & 2 deletions urbanairship-cordova/src/android/UAirshipPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.util.Consumer;

import com.urbanairship.Autopilot;
import com.urbanairship.PendingResult;
Expand All @@ -42,6 +43,9 @@
import com.urbanairship.messagecenter.Inbox;
import com.urbanairship.messagecenter.Message;
import com.urbanairship.messagecenter.MessageCenter;
import com.urbanairship.permission.Permission;
import com.urbanairship.permission.PermissionRequestResult;
import com.urbanairship.permission.PermissionStatus;
import com.urbanairship.preferencecenter.PreferenceCenter;
import com.urbanairship.push.PushMessage;
import com.urbanairship.reactive.Observable;
Expand Down Expand Up @@ -476,8 +480,16 @@ private void isUserNotificationsEnabled(@NonNull JSONArray data, @NonNull Callba
* @param callbackContext The callback context.
*/
private void enableUserNotifications(@NonNull JSONArray data, @NonNull CallbackContext callbackContext) {
UAirship.shared().getPushManager().setUserNotificationsEnabled(true);
callbackContext.success(1);
UAirship.shared().getPermissionsManager().requestPermission(
Permission.DISPLAY_NOTIFICATIONS,
true,
permissionRequestResult -> {
if (permissionRequestResult.getPermissionStatus() == PermissionStatus.GRANTED) {
callbackContext.success(1);
} else {
callbackContext.success(0);
}
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion urbanairship-hms-cordova/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "urbanairship-hms-cordova",
"version": "14.8.0",
"version": "14.9.0",
"description": "Urban Airship HMS Cordova plugin",
"cordova": {
"id": "urbanairship-hms-cordova",
Expand Down
4 changes: 2 additions & 2 deletions urbanairship-hms-cordova/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="urbanairship-hms-cordova"
version="14.8.0"
version="14.9.0"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">

Expand All @@ -15,7 +15,7 @@
<engine name="cordova" version=">=9.0.1"/>
</engines>

<dependency id="urbanairship-cordova" version="14.8.0"/>
<dependency id="urbanairship-cordova" version="14.9.0"/>

<!-- android -->
<platform name="android">
Expand Down

0 comments on commit 13f5276

Please sign in to comment.