Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afe9aed2 authored by Walter Jang's avatar Walter Jang
Browse files

Check if contact w/ phone # found before starting test intents

Bug 22407284

Change-Id: Ieb2ced79d32aae8358d4905dd6f8c4e1d170020d
parent 21bf61e6
Loading
Loading
Loading
Loading
+81 −51
Original line number Diff line number Diff line
@@ -276,13 +276,16 @@ public class AllIntentsActivity extends ListActivity
            }
            case EDIT_CONTACT: {
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
                    final Intent intent = new Intent(Intent.ACTION_EDIT, uri);
                    startActivity(intent);
                }
                break;
            }
            case EDIT_CONTACT_LOOKUP: {
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
                    final Uri lookupUri = Contacts.getLookupUri(getContentResolver(), uri);
                    final String lookupKey = lookupUri.getPathSegments().get(2);
@@ -290,31 +293,43 @@ public class AllIntentsActivity extends ListActivity
                            lookupKey);
                    final Intent intent = new Intent(Intent.ACTION_EDIT, lookupWithoutIdUri);
                    startActivity(intent);
                }
                break;
            }
            case EDIT_CONTACT_LOOKUP_ID: {
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
                    final Uri lookupUri = Contacts.getLookupUri(getContentResolver(), uri);
                    final Intent intent = new Intent(Intent.ACTION_EDIT, lookupUri);
                    startActivity(intent);
                }
                break;
            }
            case EDIT_RAW_CONTACT: {
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final long rawContactId = findArbitraryRawContactOfContact(contactId);
                final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
                    if (rawContactId != -1) {
                        final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
                                rawContactId);
                        final Intent intent = new Intent(Intent.ACTION_EDIT, uri);
                        startActivity(intent);
                    }
                }
                break;
            }
            case EDIT_LEGACY: {
                final Uri legacyContentUri = Uri.parse("content://contacts/people");
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final long rawContactId = findArbitraryRawContactOfContact(contactId);
                    if (rawContactId != -1) {
                        final Uri legacyContentUri = Uri.parse("content://contacts/people");
                        final Uri uri = ContentUris.withAppendedId(legacyContentUri, rawContactId);
                        final Intent intent = new Intent(Intent.ACTION_EDIT, uri);
                        startActivity(intent);
                    }
                }
                break;
            }
            case EDIT_NEW_CONTACT: {
@@ -323,9 +338,7 @@ public class AllIntentsActivity extends ListActivity
            }
            case EDIT_NEW_CONTACT_WITH_DATA: {
                Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);

                putDataExtra(intent);

                startActivity(intent);
                break;
            }
@@ -347,9 +360,11 @@ public class AllIntentsActivity extends ListActivity
            }
            case VIEW_CONTACT: {
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
                    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                }
                break;
            }
            case VIEW_CONTACT_WITHOUT_ID: {
@@ -358,6 +373,7 @@ public class AllIntentsActivity extends ListActivity
            }
            case VIEW_CONTACT_LOOKUP: {
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
                    final Uri lookupUri = Contacts.getLookupUri(getContentResolver(), uri);
                    final String lookupKey = lookupUri.getPathSegments().get(2);
@@ -365,31 +381,43 @@ public class AllIntentsActivity extends ListActivity
                            lookupKey);
                    final Intent intent = new Intent(Intent.ACTION_VIEW, lookupWithoutIdUri);
                    startActivity(intent);
                }
                break;
            }
            case VIEW_CONTACT_LOOKUP_ID: {
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
                    final Uri lookupUri = Contacts.getLookupUri(getContentResolver(), uri);
                    final Intent intent = new Intent(Intent.ACTION_VIEW, lookupUri);
                    startActivity(intent);
                }
                break;
            }
            case VIEW_RAW_CONTACT: {
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final long rawContactId = findArbitraryRawContactOfContact(contactId);
                final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
                    if (rawContactId != -1) {
                        final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
                                rawContactId);
                        final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        startActivity(intent);
                    }
                }
                break;
            }
            case VIEW_LEGACY: {
                final Uri legacyContentUri = Uri.parse("content://contacts/people");
                final long contactId = findArbitraryContactWithPhoneNumber();
                if (contactId != -1) {
                    final long rawContactId = findArbitraryRawContactOfContact(contactId);
                    if (rawContactId != -1) {
                        final Uri legacyContentUri = Uri.parse("content://contacts/people");
                        final Uri uri = ContentUris.withAppendedId(legacyContentUri, rawContactId);
                        final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        startActivity(intent);
                    }
                }
                break;
            }
            case QUICK_CONTACT_TESTS_ACTIVITY: {
@@ -436,7 +464,7 @@ public class AllIntentsActivity extends ListActivity
    private long findArbitraryContactWithPhoneNumber() {
        final Cursor cursor = getContentResolver().query(Contacts.CONTENT_URI,
                new String[] { Contacts._ID },
                Contacts.HAS_PHONE_NUMBER + "!=0 AND " + Contacts.STARRED + "!=0" ,
                Contacts.HAS_PHONE_NUMBER + "!=0",
                null, "RANDOM() LIMIT 1");
        try {
            if (cursor.moveToFirst()) {
@@ -445,7 +473,8 @@ public class AllIntentsActivity extends ListActivity
        } finally {
            cursor.close();
        }

        Toast.makeText(this, "Failed to find a contact with a phone number. Aborting.",
                Toast.LENGTH_SHORT).show();
        return -1;
    }

@@ -462,7 +491,8 @@ public class AllIntentsActivity extends ListActivity
        } finally {
            cursor.close();
        }

        Toast.makeText(this, "Failed to find a raw contact of contact with ID " + contactId +
                ". Aborting", Toast.LENGTH_SHORT).show();
        return -1;
    }