Fix null pointer exception

This commit is contained in:
Sylvain Berfini 2016-06-02 15:50:48 +02:00
parent b894516ab5
commit cfb430bfb1

View file

@ -977,30 +977,35 @@ public class LinphonePreferences {
public void setPushNotificationEnabled(boolean enable) { public void setPushNotificationEnabled(boolean enable) {
getConfig().setBool("app", "push_notification", enable); getConfig().setBool("app", "push_notification", enable);
LinphoneCore lc = getLc();
if (lc == null) {
return;
}
if (enable) { if (enable) {
// Add push infos to exisiting proxy configs // Add push infos to exisiting proxy configs
String regId = getPushNotificationRegistrationID(); String regId = getPushNotificationRegistrationID();
String appId = getString(R.string.push_sender_id); String appId = getString(R.string.push_sender_id);
if (regId != null && getLc().getProxyConfigList().length > 0) { if (regId != null && lc.getProxyConfigList().length > 0) {
for (LinphoneProxyConfig lpc : getLc().getProxyConfigList()) { for (LinphoneProxyConfig lpc : lc.getProxyConfigList()) {
String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId; String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId;
lpc.edit(); lpc.edit();
lpc.setContactUriParameters(contactInfos); lpc.setContactUriParameters(contactInfos);
lpc.done(); lpc.done();
Log.d("Push notif infos added to proxy config"); Log.d("Push notif infos added to proxy config");
} }
getLc().refreshRegisters(); lc.refreshRegisters();
} }
} else { } else {
if (getLc().getProxyConfigList().length > 0) { if (lc.getProxyConfigList().length > 0) {
for (LinphoneProxyConfig lpc : getLc().getProxyConfigList()) { for (LinphoneProxyConfig lpc : lc.getProxyConfigList()) {
lpc.edit(); lpc.edit();
lpc.setContactUriParameters(null); lpc.setContactUriParameters(null);
lpc.done(); lpc.done();
Log.d("Push notif infos removed from proxy config"); Log.d("Push notif infos removed from proxy config");
} }
getLc().refreshRegisters(); lc.refreshRegisters();
} }
} }
} }