Fix setup crash with sip:

This commit is contained in:
Margaux Clerc 2015-05-20 09:21:44 +02:00
parent 594d442abb
commit 4c92aa2ed6
7 changed files with 49 additions and 30 deletions

View file

@ -26,6 +26,7 @@
<string name="setup_linphone_account_hint">Enter your linphone.org username and password</string>
<string name="setup_general_account_hint">Enter your SIP account username, password and domain</string>
<string name="setup_username_hint">username</string>
<string name="button_sip_contacts">SIP</string>
<string name="tunnel_host"></string>
</resources>

View file

@ -313,7 +313,6 @@
<string name="button_ok">Okay</string>
<string name="button_back">Back</string>
<string name="button_all_contacts">All</string>
<string name="button_sip_contacts">SIP</string>
<string name="button_add_contact">New contact</string>
<string name="button_all_call">All</string>
<string name="button_missed_call">Missed</string>
@ -346,7 +345,7 @@
<string name="image_not_saved">Error, image not saved</string>
<string name="pref_linphone_friend_title">Friends</string>
<string name="pref_auto_accept_friends_title">New friends</string>
<string name="pref_auto_accept_friends_desc">utomatically accept new friend requests</string>
<string name="pref_auto_accept_friends_desc">Automatically accept new friend requests</string>
<string name="linphone_friend_new_request_title">Friend request</string>
<string name="linphone_friend_new_request_desc">wants to share it\'s presence status with you and be aware of yours.</string>
<string name="setup_ec_calibration">Echo canceller calibration in progress</string>

View file

@ -202,7 +202,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
contactsList.setVisibility(View.VISIBLE);
if (onlyDisplayLinphoneContacts) {
if (sipContactsCursor.getCount() == 0) {
if (sipContactsCursor != null && sipContactsCursor.getCount() == 0) {
noSipContact.setVisibility(View.VISIBLE);
contactsList.setVisibility(View.GONE);
} else {
@ -210,7 +210,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts(), sipContactsCursor));
}
} else {
if (allContactsCursor.getCount() == 0) {
if (allContactsCursor != null && allContactsCursor.getCount() == 0) {
noContact.setVisibility(View.VISIBLE);
contactsList.setVisibility(View.GONE);
} else {

View file

@ -83,9 +83,13 @@ public class ContactsManager {
return isContactPresenceDisabled;
}
public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
public void initializeContactManager(Context context, ContentResolver contentResolver){
this.context = context;
this.contentResolver = contentResolver;
}
public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
initializeContactManager(context,contentResolver);
Account newAccount = new Account(context.getString(R.string.sync_account_name), context.getString(R.string.sync_account_type));
AccountManager accountManager = (AccountManager) context.getSystemService(context.ACCOUNT_SERVICE);
accountManager.addAccountExplicitly(newAccount, null, null);
@ -342,7 +346,8 @@ public class ContactsManager {
if (sipUri.startsWith("sip:"))
sipUri = sipUri.substring(4);
if(LinphoneManager.getLcIfManagerNotDestroyedOrNull().getFriendList() != null && LinphoneManager.getLcIfManagerNotDestroyedOrNull().getFriendList().length > 0) {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if(lc != null && lc.getFriendList() != null && LinphoneManager.getLcIfManagerNotDestroyedOrNull().getFriendList().length > 0) {
for (LinphoneFriend friend : LinphoneManager.getLcIfManagerNotDestroyedOrNull().getFriendList()) {
if (friend.getAddress().equals(address)) {
return getContact(friend.getRefKey(), contentResolver);
@ -522,7 +527,7 @@ public class ContactsManager {
Thread sipContactsHandler = new Thread(new Runnable() {
@Override
public void run() {
if(sipContactCursor.getCount() > 0) {
if(sipContactCursor != null && sipContactCursor.getCount() > 0) {
for (int i = 0; i < sipContactCursor.getCount(); i++) {
Contact contact = Compatibility.getContact(contentResolver, sipContactCursor, i);
if (contact == null)

View file

@ -152,6 +152,8 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
if (getResources().getBoolean(R.bool.use_linphone_tag)) {
ContactsManager.getInstance().initializeSyncAccount(getApplicationContext(), getContentResolver());
} else {
ContactsManager.getInstance().initializeContactManager(getApplicationContext(), getContentResolver());
}
if(!LinphonePreferences.instance().isContactsMigrationDone()){

View file

@ -209,30 +209,34 @@ public class ApiFivePlus {
public static Contact getContact(ContentResolver cr, Cursor cursor, int position) {
try {
cursor.moveToFirst();
boolean success = cursor.move(position);
if (!success)
return null;
String id = cursor.getString(cursor.getColumnIndex(Data.CONTACT_ID));
String name = getContactDisplayName(cursor);
Uri thumbnail = getContactPictureUri(id);
Uri photo = getContactPhotoUri(id);
InputStream input = getContactPictureInputStream(cr, id);
if(cursor != null) {
cursor.moveToFirst();
boolean success = cursor.move(position);
if (!success)
return null;
Contact contact;
if (input == null) {
contact = new Contact(id, name);
}
else {
Bitmap bm = null;
try {
bm = BitmapFactory.decodeStream(input);
} catch (OutOfMemoryError oome) {}
contact = new Contact(id, name, photo, thumbnail, bm);
}
return contact;
String id = cursor.getString(cursor.getColumnIndex(Data.CONTACT_ID));
String name = getContactDisplayName(cursor);
Uri thumbnail = getContactPictureUri(id);
Uri photo = getContactPhotoUri(id);
InputStream input = getContactPictureInputStream(cr, id);
Contact contact;
if (input == null) {
contact = new Contact(id, name);
} else {
Bitmap bm = null;
try {
bm = BitmapFactory.decodeStream(input);
} catch (OutOfMemoryError oome) {
}
contact = new Contact(id, name, photo, thumbnail, bm);
}
return contact;
} else {
return null;
}
} catch (Exception e) {
}

View file

@ -305,6 +305,14 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
if (accountCreated)
return;
if(username.startsWith("sip:")) {
username = username.substring(4);
}
if(domain.startsWith("sip:")) {
domain = domain.substring(4);
}
String identity = "sip:" + username + "@" + domain;
try {
address = LinphoneCoreFactory.instance().createLinphoneAddress(identity);