From d1fc3684ef0cc756fbd17c715768c47a6d53a67f Mon Sep 17 00:00:00 2001 From: Paul Cartier Date: Fri, 7 Feb 2020 17:03:59 +0100 Subject: [PATCH] update push notification parameters - remove set_network_reachable: sdk will not register if push are allowed - uses push_notification_allowed instead of refkey in proxy config --- Classes/LinphoneAppDelegate.m | 19 ----------------- Classes/LinphoneCoreSettingsStore.m | 10 ++++----- Classes/LinphoneManager.m | 27 ++++++++++++++++++------ Resources/assistant_linphone_create.rc | 1 - Resources/assistant_linphone_existing.rc | 1 - TestsUI/LinphoneTestCase.m | 2 +- 6 files changed, 25 insertions(+), 35 deletions(-) diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 535c60bd4..c8702338a 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -320,25 +320,6 @@ LOGI(@"%@", NSStringFromSelector(_cmd)); LinphoneManager.instance.conf = TRUE; linphone_core_terminate_all_calls(LC); - - // !!! Will be removed after push notification job finished - // destroyLinphoneCore automatically unregister proxies but if we are using - // remote push notifications, we want to continue receiving them - if (LinphoneManager.instance.pushNotificationToken != nil) { - // trick me! setting network reachable to false will avoid sending unregister - const MSList *proxies = linphone_core_get_proxy_config_list(LC); - BOOL pushNotifEnabled = NO; - while (proxies) { - const char *refkey = linphone_proxy_config_get_ref_key(proxies->data); - pushNotifEnabled = pushNotifEnabled || (refkey && strcmp(refkey, "push_notification") == 0); - proxies = proxies->next; - } - // but we only want to hack if at least one proxy config uses remote push.. - if (pushNotifEnabled) { - linphone_core_set_network_reachable(LC, FALSE); - } - } - [LinphoneManager.instance destroyLinphoneCore]; } diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 4b0e60206..2e1e8e343 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -175,11 +175,9 @@ proxy = proxies->data; // root section { - const char *refkey = linphone_proxy_config_get_ref_key(proxy); - if (refkey) { - BOOL pushEnabled = (strcmp(refkey, "push_notification") == 0); - [self setBool:pushEnabled forKey:@"account_pushnotification_preference"]; - } + BOOL pushEnabled = linphone_proxy_config_is_push_notification_allowed(proxy); + [self setBool:pushEnabled forKey:@"account_pushnotification_preference"]; + const LinphoneAddress *identity_addr = linphone_proxy_config_get_identity_address(proxy); const char *server_addr = linphone_proxy_config_get_server_addr(proxy); LinphoneAddress *proxy_addr = linphone_core_interpret_url(LC, server_addr); @@ -584,7 +582,7 @@ } // use empty string "" instead of NULL to avoid being overwritten by default proxy config values - linphone_proxy_config_set_ref_key(proxyCfg, pushnotification ? "push_notification" : "no_push_notification"); + linphone_proxy_config_set_push_notification_allowed(proxyCfg, pushnotification); [LinphoneManager.instance configurePushTokenForProxyConfig:proxyCfg]; linphone_proxy_config_enable_register(proxyCfg, is_enabled); diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 55efddb3a..21c011a1f 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -449,6 +449,22 @@ static int check_should_migrate_images(void *data, int argc, char **argv, char * } [self lpConfigSetBool:TRUE forKey:@"lime_migration_done"]; } + + if ([self lpConfigBoolForKey:@"push_notification_migration_done"] == FALSE) { + const MSList *proxies = linphone_core_get_proxy_config_list(LC); + bool_t pushEnabled; + while (proxies) { + const char *refkey = linphone_proxy_config_get_ref_key(proxies->data); + if (refkey) { + pushEnabled = (strcmp(refkey, "push_notification") == 0); + } else { + pushEnabled = true; + } + linphone_proxy_config_set_push_notification_allowed(proxies->data, pushEnabled); + proxies = proxies->next; + } + [self lpConfigSetBool:TRUE forKey:@"push_notification_migration_done"]; + } } - (void)migrationPerAccount { @@ -473,7 +489,7 @@ static int check_should_migrate_images(void *data, int argc, char **argv, char * [self lpConfigSetBool:NO forKey:@"pushnotification_preference"]; const MSList *proxies = linphone_core_get_proxy_config_list(LC); while (proxies) { - linphone_proxy_config_set_ref_key(proxies->data, "push_notification"); + linphone_proxy_config_set_push_notification_allowed(proxies->data, true); [self configurePushTokenForProxyConfig:proxies->data]; proxies = proxies->next; } @@ -2078,8 +2094,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { // handle proxy config if any if (proxyCfg) { - const char *refkey = proxyCfg ? linphone_proxy_config_get_ref_key(proxyCfg) : NULL; - BOOL pushNotifEnabled = (refkey && strcmp(refkey, "push_notification") == 0); + BOOL pushNotifEnabled = linphone_proxy_config_is_push_notification_allowed(proxyCfg); if ([LinphoneManager.instance lpConfigBoolForKey:@"backgroundmode_preference"] || pushNotifEnabled) { if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { // For registration register @@ -2133,8 +2148,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { LOGI(@"Entering [%s] bg mode", shouldEnterBgMode ? "normal" : "lite"); if (!shouldEnterBgMode && floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) { - const char *refkey = proxyCfg ? linphone_proxy_config_get_ref_key(proxyCfg) : NULL; - BOOL pushNotifEnabled = (refkey && strcmp(refkey, "push_notification") == 0); + BOOL pushNotifEnabled = linphone_proxy_config_is_push_notification_allowed(proxyCfg); if (pushNotifEnabled) { LOGI(@"Keeping lc core to handle push"); return YES; @@ -2529,8 +2543,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { linphone_proxy_config_edit(proxyCfg); NSData *tokenData = _pushNotificationToken; - const char *refkey = linphone_proxy_config_get_ref_key(proxyCfg); - BOOL pushNotifEnabled = (refkey && strcmp(refkey, "push_notification") == 0); + BOOL pushNotifEnabled = linphone_proxy_config_is_push_notification_allowed(proxyCfg); if (tokenData != nil && pushNotifEnabled) { const unsigned char *tokenBuffer = [tokenData bytes]; NSMutableString *tokenString = [NSMutableString stringWithCapacity:[tokenData length] * 2]; diff --git a/Resources/assistant_linphone_create.rc b/Resources/assistant_linphone_create.rc index a970646ce..08ed436cd 100644 --- a/Resources/assistant_linphone_create.rc +++ b/Resources/assistant_linphone_create.rc @@ -12,7 +12,6 @@ sip:?@sip.linphone.org <sip:sip.linphone.org;transport=tls> 1 - push_notification sip.linphone.org nat_policy_default_values diff --git a/Resources/assistant_linphone_existing.rc b/Resources/assistant_linphone_existing.rc index 95aadffa5..f6c18d860 100644 --- a/Resources/assistant_linphone_existing.rc +++ b/Resources/assistant_linphone_existing.rc @@ -12,7 +12,6 @@ sip:?@sip.linphone.org <sip:sip.linphone.org;transport=tls> 1 - push_notification sip.linphone.org nat_policy_default_values diff --git a/TestsUI/LinphoneTestCase.m b/TestsUI/LinphoneTestCase.m index 05fffaa79..b1ca25fa0 100644 --- a/TestsUI/LinphoneTestCase.m +++ b/TestsUI/LinphoneTestCase.m @@ -142,7 +142,7 @@ linphone_proxy_config_set_identity_address(testProxy, testAddr); linphone_proxy_config_set_server_addr(testProxy, [self accountProxyRoute].UTF8String); linphone_proxy_config_set_route(testProxy, [self accountProxyRoute].UTF8String); - linphone_proxy_config_set_ref_key(testProxy, "push_notification"); + linphone_proxy_config_set_push_notification_allowed(testProxy, true); LinphoneAuthInfo *testAuth = linphone_auth_info_new(linphone_address_get_username(testAddr), NULL, linphone_address_get_username(testAddr), NULL, NULL,