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(); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.status, container, false); statusText = (TextView) view.findViewById(R.id.status_text); statusLed = (ImageView) view.findViewById(R.id.status_led); mListener = new LinphoneCoreListenerBase() { @Override public void registrationState( final LinphoneCore lc, final LinphoneProxyConfig proxy, final LinphoneCore.RegistrationState state, String smessage) { if (!isAttached || !RedfoxService.isReady()) { return; } if (lc.getProxyConfigList() == null) { statusLed.setImageResource(R.drawable.led_disconnected); statusText.setText(getString(R.string.no_account)); } else { statusLed.setVisibility(View.VISIBLE); } if (lc.getDefaultProxyConfig() != null && lc.getDefaultProxyConfig().equals(proxy)) { statusLed.setImageResource(getStatusIconResource(state, true)); statusText.setText(getStatusIconText(state)); } else if (lc.getDefaultProxyConfig() == null) { statusLed.setImageResource(getStatusIconResource(state, true)); statusText.setText(getStatusIconText(state)); } try { statusText.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { lc.refreshRegisters(); } }); } catch (IllegalStateException ise) { } } }; LinphoneCore lc = RedfoxManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { lc.addListener(mListener); LinphoneProxyConfig lpc = lc.getDefaultProxyConfig(); if (lpc != null) { mListener.registrationState(lc, lpc, lpc.getState(), null); } } return view; }
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 int getDefaultAccountIndex() { LinphoneProxyConfig defaultPrxCfg = getLc().getDefaultProxyConfig(); if (defaultPrxCfg == null) return -1; LinphoneProxyConfig[] prxCfgs = getLc().getProxyConfigList(); for (int i = 0; i < prxCfgs.length; i++) { if (defaultPrxCfg.getIdentity().equals(prxCfgs[i].getIdentity())) { return i; } } return -1; }
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(); } }
private LinphoneAuthInfo getAuthInfo(int n) { LinphoneProxyConfig prxCfg = getProxyConfig(n); try { LinphoneAddress addr = LinphoneCoreFactory.instance().createLinphoneAddress(prxCfg.getIdentity()); LinphoneAuthInfo authInfo = getLc().findAuthInfo(addr.getUserName(), null, addr.getDomain()); return authInfo; } catch (LinphoneCoreException e) { e.printStackTrace(); } return null; }
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 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 TransportType getAccountTransport(int n) { TransportType transport = null; LinphoneProxyConfig proxyConfig = getProxyConfig(n); if (proxyConfig != null) { LinphoneAddress proxyAddr; try { proxyAddr = LinphoneCoreFactory.instance().createLinphoneAddress(proxyConfig.getProxy()); transport = proxyAddr.getTransport(); } catch (LinphoneCoreException e) { e.printStackTrace(); } } return transport; }
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 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 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(); } } }
/** * Creates a new account * * @throws LinphoneCoreException */ public void saveNewAccount() throws LinphoneCoreException { if (tempUsername == null || tempUsername.length() < 1 || tempDomain == null || tempDomain.length() < 1) { Log.w("Skipping account save: username or domain not provided"); return; } String identity = "sip:" + tempUsername + "@" + tempDomain; String proxy = "sip:"; if (tempProxy == null) { proxy += tempDomain; } else { if (!tempProxy.startsWith("sip:") && !tempProxy.startsWith("<sip:") && !tempProxy.startsWith("sips:") && !tempProxy.startsWith("<sips:")) { proxy += tempProxy; } else { proxy = tempProxy; } } LinphoneAddress proxyAddr = LinphoneCoreFactory.instance().createLinphoneAddress(proxy); LinphoneAddress identityAddr = LinphoneCoreFactory.instance().createLinphoneAddress(identity); if (tempDisplayName != null) { identityAddr.setDisplayName(tempDisplayName); } if (tempTransport != null) { proxyAddr.setTransport(tempTransport); } String route = tempOutboundProxy ? proxyAddr.asStringUriOnly() : null; LinphoneProxyConfig prxCfg = lc.createProxyConfig( identityAddr.asString(), proxyAddr.asStringUriOnly(), route, tempEnabled); if (tempContactsParams != null) prxCfg.setContactUriParameters(tempContactsParams); if (tempExpire != null) { try { prxCfg.setExpires(Integer.parseInt(tempExpire)); } catch (NumberFormatException nfe) { } } prxCfg.enableAvpf(tempAvpfEnabled); prxCfg.setAvpfRRInterval(tempAvpfRRInterval); prxCfg.enableQualityReporting(tempQualityReportingEnabled); prxCfg.setQualityReportingCollector(tempQualityReportingCollector); prxCfg.setQualityReportingInterval(tempQualityReportingInterval); if (tempRealm != null) prxCfg.setRealm(tempRealm); LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance() .createAuthInfo(tempUsername, tempUserId, tempPassword, null, null, tempDomain); lc.addProxyConfig(prxCfg); lc.addAuthInfo(authInfo); if (!tempNoDefault && LinphonePreferences.instance().getAccountCount() == 1) lc.setDefaultProxyConfig(prxCfg); }
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(); }
// Added by me public void createGroupChat(String groupName, String[] groupMembers, int groupSize) { // Intent intent = new Intent(this, ChatActivity.class); // intent.putExtra("GroupName", groupName); // intent.putExtra("GroupMembers", groupMembers); // intent.putExtra("GroupSize", groupSize); // intent.putExtra("ChatType", 1); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { LinphoneChatRoom chatRoom = null; chatRoom = lc.getOrCreateGroupChatRoom(groupName, groupMembers, groupSize, 0, 0); if (chatRoom != null) { LinphoneAddress la = chatRoom.getPeerAddress(); String sipUri = la.asStringUriOnly(); String displayName = la.getDisplayName(); String addrStr = la.asString(); // intent.putExtra("SipUri", sipUri); // intent.putExtra("DisplayName", displayName); LinphoneProxyConfig pc = lc.getDefaultProxyConfig(); String identity = pc.getIdentity(); String id = ""; try { la = LinphoneCoreFactory.instance().createLinphoneAddress(identity); id = la.getUserName(); } catch (LinphoneCoreException e) { Log.e("Cannot display chat", e); // return; } String message = id + " created group " + groupName; LinphoneChatMessage msg = chatRoom.createLinphoneGroupChatMessage(message); chatRoom.sendGroupChatMessage(msg); // chatRoom.sendGroupMessage(message); onMessageSent(sipUri, message); goToChatList(); /*String toDisplay = "Display Name: " + displayName; toDisplay += "\nSIP URI: " + sipUri; toDisplay += "\nGroup Name: " + chatRoom.getGroupName(); toDisplay += "\nGroup Address: " + addrStr; displayCustomToast(toDisplay, Toast.LENGTH_SHORT);*/ } // LinphoneProxyConfig pc = lc.getDefaultProxyConfig(); // String identity = pc.getIdentity(); // displayCustomToast("I am: " + identity, Toast.LENGTH_SHORT); } /*startOrientationSensor(); startActivityForResult(intent, CHAT_ACTIVITY); LinphoneService.instance().resetMessageNotifCount(); LinphoneService.instance().removeMessageNotification(); displayMissedChats(getChatStorage().getUnreadMessageCount());*/ }
private void displayContact(LayoutInflater inflater, View view) { AvatarWithShadow contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture); if (contact.getPhotoUri() != null) { InputStream input = Compatibility.getContactPictureInputStream( LinphoneActivity.instance().getContentResolver(), contact.getID()); contactPicture.setImageBitmap(BitmapFactory.decodeStream(input)); } else { contactPicture.setImageResource(R.drawable.unknown_small); } TextView contactName = (TextView) view.findViewById(R.id.contactName); contactName.setText(contact.getName()); TableLayout controls = (TableLayout) view.findViewById(R.id.controls); controls.removeAllViews(); for (String numberOrAddress : contact.getNumerosOrAddresses()) { View v = inflater.inflate(R.layout.contact_control_row, null); String displayednumberOrAddress = numberOrAddress; if (numberOrAddress.startsWith("sip:")) { displayednumberOrAddress = displayednumberOrAddress.replace("sip:", ""); } TextView tv = (TextView) v.findViewById(R.id.numeroOrAddress); tv.setText(displayednumberOrAddress); tv.setSelected(true); if (!displayChatAddressOnly) { v.findViewById(R.id.dial).setOnClickListener(dialListener); v.findViewById(R.id.dial).setTag(displayednumberOrAddress); } else { v.findViewById(R.id.dial).setVisibility(View.GONE); } v.findViewById(R.id.start_chat).setOnClickListener(chatListener); LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig(); if (lpc != null) { if (!displayednumberOrAddress.startsWith("sip:")) { numberOrAddress = "sip:" + displayednumberOrAddress; } String tag = numberOrAddress; if (!numberOrAddress.contains("@")) { tag = numberOrAddress + "@" + lpc.getDomain(); } v.findViewById(R.id.start_chat).setTag(tag); } else { v.findViewById(R.id.start_chat).setTag(numberOrAddress); } final String finalNumberOrAddress = numberOrAddress; ImageView friend = (ImageView) v.findViewById(R.id.addFriend); if (getResources().getBoolean(R.bool.enable_linphone_friends) && !displayChatAddressOnly) { friend.setVisibility(View.VISIBLE); boolean isAlreadyAFriend = LinphoneManager.getLc().findFriendByAddress(finalNumberOrAddress) != null; if (!isAlreadyAFriend) { friend.setImageResource(R.drawable.friend_add); friend.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (LinphoneActivity.instance().newFriend(contact, finalNumberOrAddress)) { displayContact(ContactFragment.this.inflater, ContactFragment.this.view); } } }); } else { friend.setImageResource(R.drawable.friend_remove); friend.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (LinphoneActivity.instance().removeFriend(contact, finalNumberOrAddress)) { displayContact(ContactFragment.this.inflater, ContactFragment.this.view); } } }); } } if (getResources().getBoolean(R.bool.disable_chat)) { v.findViewById(R.id.start_chat).setVisibility(View.GONE); } controls.addView(v); } }