public void setPushNotificationEnabled(boolean enable) {
    getConfig().setBool("app", "push_notification", enable);

    if (enable) {
      // Add push infos to exisiting proxy configs
      String regId = getPushNotificationRegistrationID();
      String appId = getString(R.string.push_sender_id);
      if (regId != null && getLc().getProxyConfigList().length > 0) {
        for (LinphoneProxyConfig lpc : getLc().getProxyConfigList()) {
          String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId;
          lpc.edit();
          lpc.setContactUriParameters(contactInfos);
          lpc.done();
          Log.d("Push notif infos added to proxy config");
        }
        getLc().refreshRegisters();
      }
    } else {
      if (getLc().getProxyConfigList().length > 0) {
        for (LinphoneProxyConfig lpc : getLc().getProxyConfigList()) {
          lpc.edit();
          lpc.setContactUriParameters(null);
          lpc.done();
          Log.d("Push notif infos removed from proxy config");
        }
        getLc().refreshRegisters();
      }
    }
  }
  public void setAccountProxy(int n, String proxy) {
    if (proxy == null || proxy.length() <= 0) {
      proxy = getAccountDomain(n);
    }

    if (!proxy.contains("sip:")) {
      proxy = "sip:" + proxy;
    }

    try {
      LinphoneAddress proxyAddr = LinphoneCoreFactory.instance().createLinphoneAddress(proxy);
      if (!proxy.contains("transport=")) {
        proxyAddr.setTransport(getAccountTransport(n));
      }

      LinphoneProxyConfig prxCfg = getProxyConfig(n);
      prxCfg.edit();
      prxCfg.setProxy(proxyAddr.asStringUriOnly());
      prxCfg.done();

      if (isAccountOutboundProxySet(n)) {
        setAccountOutboundProxyEnabled(n, true);
      }
    } catch (LinphoneCoreException e) {
      e.printStackTrace();
    }
  }
 public void setAvpfRRInterval(int n, String interval) {
   try {
     LinphoneProxyConfig prxCfg = getProxyConfig(n);
     prxCfg.edit();
     prxCfg.setAvpfRRInterval(Integer.parseInt(interval));
     prxCfg.done();
   } catch (NumberFormatException nfe) {
   }
 }
 public void setExpires(int n, String expire) {
   try {
     LinphoneProxyConfig prxCfg = getProxyConfig(n);
     prxCfg.edit();
     prxCfg.setExpires(Integer.parseInt(expire));
     prxCfg.done();
   } catch (NumberFormatException nfe) {
   }
 }
 public void setAccountDisplayName(int n, String displayName) {
   try {
     LinphoneProxyConfig prxCfg = getProxyConfig(n);
     LinphoneAddress addr =
         LinphoneCoreFactory.instance().createLinphoneAddress(prxCfg.getIdentity());
     addr.setDisplayName(displayName);
     prxCfg.edit();
     prxCfg.setIdentity(addr.asString());
     prxCfg.done();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public void setAccountOutboundProxyEnabled(int n, boolean enabled) {
   try {
     LinphoneProxyConfig prxCfg = getProxyConfig(n);
     prxCfg.edit();
     if (enabled) {
       String route = prxCfg.getProxy();
       prxCfg.setRoute(route);
     } else {
       prxCfg.setRoute(null);
     }
     prxCfg.done();
   } catch (LinphoneCoreException e) {
     e.printStackTrace();
   }
 }
  public void setAccountDomain(int n, String domain) {
    String identity = "sip:" + getAccountUsername(n) + "@" + domain;

    try {
      LinphoneAuthInfo authInfo = getClonedAuthInfo(n);
      authInfo.setDomain(domain);
      saveAuthInfo(authInfo);

      LinphoneProxyConfig prxCfg = getProxyConfig(n);
      prxCfg.edit();
      prxCfg.setIdentity(identity);
      prxCfg.done();
    } catch (LinphoneCoreException e) {
      e.printStackTrace();
    }
  }
  public void setAccountUsername(int n, String username) {
    String identity = "sip:" + username + "@" + getAccountDomain(n);
    LinphoneAuthInfo info =
        getClonedAuthInfo(
            n); // Get the auth info before editing the proxy config to ensure to get the correct
                // auth info
    try {
      LinphoneProxyConfig prxCfg = getProxyConfig(n);
      prxCfg.edit();
      prxCfg.setIdentity(identity);
      prxCfg.done();

      info.setUsername(username);
      saveAuthInfo(info);
    } catch (LinphoneCoreException e) {
      e.printStackTrace();
    }
  }
  public void setAccountEnabled(int n, boolean enabled) {
    LinphoneProxyConfig prxCfg = getProxyConfig(n);
    prxCfg.edit();
    prxCfg.enableRegister(enabled);
    prxCfg.done();

    // If default proxy config is disabled, try to set another one as default proxy
    if (!enabled && getLc().getDefaultProxyConfig().getIdentity().equals(prxCfg.getIdentity())) {
      int count = getLc().getProxyConfigList().length;
      if (count > 1) {
        for (int i = 0; i < count; i++) {
          if (isAccountEnabled(i)) {
            getLc().setDefaultProxyConfig(getProxyConfig(i));
            break;
          }
        }
      }
    }
  }
  public void setAccountTransport(int n, String transport) {
    LinphoneProxyConfig proxyConfig = getProxyConfig(n);

    if (proxyConfig != null && transport != null) {
      LinphoneAddress proxyAddr;
      try {
        proxyAddr = LinphoneCoreFactory.instance().createLinphoneAddress(proxyConfig.getProxy());
        int port = 0;
        if (transport.equals(getString(R.string.pref_transport_udp_key))) {
          proxyAddr.setTransport(TransportType.LinphoneTransportUdp);
        } else if (transport.equals(getString(R.string.pref_transport_tcp_key))) {
          proxyAddr.setTransport(TransportType.LinphoneTransportTcp);
        } else if (transport.equals(getString(R.string.pref_transport_tls_key))) {
          proxyAddr.setTransport(TransportType.LinphoneTransportTls);
          port = 5223;
        }

        /* 3G mobile firewall might block random TLS port, so we force use of 5223.
         * However we must NOT use this port when changing to TCP/UDP because otherwise
         * REGISTER (and everything actually) will fail...
         * */
        if ("sip.linphone.org".equals(proxyConfig.getDomain())) {
          proxyAddr.setPort(port);
        }

        LinphoneProxyConfig prxCfg = getProxyConfig(n);
        prxCfg.edit();
        prxCfg.setProxy(proxyAddr.asStringUriOnly());
        prxCfg.done();

        if (isAccountOutboundProxySet(n)) {
          setAccountOutboundProxyEnabled(n, true);
        }
      } catch (LinphoneCoreException e) {
        e.printStackTrace();
      }
    }
  }
 public void setReplacePlusByZeroZero(int n, boolean replace) {
   LinphoneProxyConfig prxCfg = getProxyConfig(n);
   prxCfg.edit();
   prxCfg.setDialEscapePlus(replace);
   prxCfg.done();
 }
 public void enableAvpf(int n, boolean enable) {
   LinphoneProxyConfig prxCfg = getProxyConfig(n);
   prxCfg.edit();
   prxCfg.enableAvpf(enable);
   prxCfg.done();
 }
 public void setPrefix(int n, String prefix) {
   LinphoneProxyConfig prxCfg = getProxyConfig(n);
   prxCfg.edit();
   prxCfg.setDialPrefix(prefix);
   prxCfg.done();
 }
 public void setAccountContactParameters(int n, String contactParams) {
   LinphoneProxyConfig prxCfg = getProxyConfig(n);
   prxCfg.edit();
   prxCfg.setContactUriParameters(contactParams);
   prxCfg.done();
 }