1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/* 2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project 3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License"); 5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License. 6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at 7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * http://www.apache.org/licenses/LICENSE-2.0 9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software 11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS, 12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and 14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License. 15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.datamodel.data; 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.ContentValues; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.res.Resources; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.database.Cursor; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.graphics.Color; 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.os.Parcel; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.os.Parcelable; 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.support.v7.mms.MmsManager; 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.telephony.SubscriptionInfo; 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.text.TextUtils; 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.ex.chips.RecipientEntry; 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.Factory; 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.R; 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.DatabaseHelper; 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.DatabaseHelper.ParticipantColumns; 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.datamodel.DatabaseWrapper; 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.sms.MmsSmsUtils; 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.Assert; 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.PhoneUtils; 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.util.TextUtil; 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/** 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * A class that encapsulates all of the data for a specific participant in a conversation. 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class ParticipantData implements Parcelable { 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // We always use -1 as default/invalid sub id although system may give us anything negative 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int DEFAULT_SELF_SUB_ID = MmsManager.DEFAULT_SUB_ID; 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // This needs to be something apart from valid or DEFAULT_SELF_SUB_ID 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int OTHER_THAN_SELF_SUB_ID = DEFAULT_SELF_SUB_ID - 1; 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Active slot ids are non-negative. Using -1 to designate to inactive self participants. 51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INVALID_SLOT_ID = -1; 52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // TODO: may make sense to move this to common place? 54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final long PARTICIPANT_CONTACT_ID_NOT_RESOLVED = -1; 55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final long PARTICIPANT_CONTACT_ID_NOT_FOUND = -2; 56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static class ParticipantsQuery { 58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final String[] PROJECTION = new String[] { 59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns._ID, 60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.SUB_ID, 61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.SIM_SLOT_ID, 62d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.NORMALIZED_DESTINATION, 63d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.SEND_DESTINATION, 64d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.DISPLAY_DESTINATION, 65d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.FULL_NAME, 66d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.FIRST_NAME, 67d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.PROFILE_PHOTO_URI, 68d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.CONTACT_ID, 69d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.LOOKUP_KEY, 70d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.BLOCKED, 71d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.SUBSCRIPTION_COLOR, 72d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.SUBSCRIPTION_NAME, 73d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns.CONTACT_DESTINATION, 74d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }; 75d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 76d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_ID = 0; 77d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_SUB_ID = 1; 78d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_SIM_SLOT_ID = 2; 79d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_NORMALIZED_DESTINATION = 3; 80d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_SEND_DESTINATION = 4; 81d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_DISPLAY_DESTINATION = 5; 82d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_FULL_NAME = 6; 83d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_FIRST_NAME = 7; 84d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_PROFILE_PHOTO_URI = 8; 85d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_CONTACT_ID = 9; 86d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_LOOKUP_KEY = 10; 87d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_BLOCKED = 11; 88d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_SUBSCRIPTION_COLOR = 12; 89d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_SUBSCRIPTION_NAME = 13; 90d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final int INDEX_CONTACT_DESTINATION = 14; 91d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 92d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 93d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 94d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @return The MMS unknown sender participant entity 95d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 96d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static String getUnknownSenderDestination() { 97d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // This is a hard coded string rather than a localized one because we don't want it to 98d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // change when you change locale. 99d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return "\u02BCUNKNOWN_SENDER!\u02BC"; 100d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 101d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 102d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mParticipantId; 103d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private int mSubId; 104d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private int mSlotId; 105d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mNormalizedDestination; 106d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mSendDestination; 107d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mDisplayDestination; 108d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mContactDestination; 109d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mFullName; 110d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mFirstName; 111d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mProfilePhotoUri; 112d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private long mContactId; 113d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mLookupKey; 114d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private int mSubscriptionColor; 115d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private String mSubscriptionName; 116d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private boolean mIsEmailAddress; 117d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private boolean mBlocked; 118d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 119d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Don't call constructor directly 120d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private ParticipantData() { 121d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 122d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 123d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static ParticipantData getFromCursor(final Cursor cursor) { 124d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ParticipantData pd = new ParticipantData(); 125d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mParticipantId = cursor.getString(ParticipantsQuery.INDEX_ID); 126d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubId = cursor.getInt(ParticipantsQuery.INDEX_SUB_ID); 127d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSlotId = cursor.getInt(ParticipantsQuery.INDEX_SIM_SLOT_ID); 128d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mNormalizedDestination = cursor.getString( 129d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantsQuery.INDEX_NORMALIZED_DESTINATION); 130d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSendDestination = cursor.getString(ParticipantsQuery.INDEX_SEND_DESTINATION); 131d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mDisplayDestination = cursor.getString(ParticipantsQuery.INDEX_DISPLAY_DESTINATION); 132d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mContactDestination = cursor.getString(ParticipantsQuery.INDEX_CONTACT_DESTINATION); 133d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mFullName = cursor.getString(ParticipantsQuery.INDEX_FULL_NAME); 134d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mFirstName = cursor.getString(ParticipantsQuery.INDEX_FIRST_NAME); 135d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mProfilePhotoUri = cursor.getString(ParticipantsQuery.INDEX_PROFILE_PHOTO_URI); 136d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mContactId = cursor.getLong(ParticipantsQuery.INDEX_CONTACT_ID); 137d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mLookupKey = cursor.getString(ParticipantsQuery.INDEX_LOOKUP_KEY); 138d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mIsEmailAddress = MmsSmsUtils.isEmailAddress(pd.mSendDestination); 139d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mBlocked = cursor.getInt(ParticipantsQuery.INDEX_BLOCKED) != 0; 140d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubscriptionColor = cursor.getInt(ParticipantsQuery.INDEX_SUBSCRIPTION_COLOR); 141d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubscriptionName = cursor.getString(ParticipantsQuery.INDEX_SUBSCRIPTION_NAME); 142d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.maybeSetupUnknownSender(); 143d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return pd; 144d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 145d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 146d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static ParticipantData getFromId(final DatabaseWrapper dbWrapper, 147d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String participantId) { 148d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Cursor cursor = null; 149d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd try { 150d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd cursor = dbWrapper.query(DatabaseHelper.PARTICIPANTS_TABLE, 151d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantsQuery.PROJECTION, 152d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd ParticipantColumns._ID + " =?", 153d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd new String[] { participantId }, null, null, null); 154d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 155d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (cursor.moveToFirst()) { 156d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return ParticipantData.getFromCursor(cursor); 157d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } else { 158d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return null; 159d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 160d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } finally { 161d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (cursor != null) { 162d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd cursor.close(); 163d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 164d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 165d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 166d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 167d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static ParticipantData getFromRecipientEntry(final RecipientEntry recipientEntry) { 168d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ParticipantData pd = new ParticipantData(); 169d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mParticipantId = null; 170d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubId = OTHER_THAN_SELF_SUB_ID; 171d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSlotId = INVALID_SLOT_ID; 172d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSendDestination = TextUtil.replaceUnicodeDigits(recipientEntry.getDestination()); 173d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mIsEmailAddress = MmsSmsUtils.isEmailAddress(pd.mSendDestination); 174d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mNormalizedDestination = pd.mIsEmailAddress ? 175d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSendDestination : 176d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PhoneUtils.getDefault().getCanonicalBySystemLocale(pd.mSendDestination); 177d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mDisplayDestination = pd.mIsEmailAddress ? 178d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mNormalizedDestination : 179d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PhoneUtils.getDefault().formatForDisplay(pd.mNormalizedDestination); 180d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mFullName = recipientEntry.getDisplayName(); 181d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mFirstName = null; 182d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mProfilePhotoUri = (recipientEntry.getPhotoThumbnailUri() == null) ? null : 183d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd recipientEntry.getPhotoThumbnailUri().toString(); 184d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mContactId = recipientEntry.getContactId(); 185d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (pd.mContactId < 0) { 186d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // ParticipantData only supports real contact ids (>=0) based on faith that the contacts 187d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // provider will continue to only use non-negative ids. The UI uses contactId < 0 for 188d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // special handling. We convert those to 'not resolved' 189d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mContactId = PARTICIPANT_CONTACT_ID_NOT_RESOLVED; 190d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 191d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mLookupKey = recipientEntry.getLookupKey(); 192d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mBlocked = false; 193d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubscriptionColor = Color.TRANSPARENT; 194d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubscriptionName = null; 195d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.maybeSetupUnknownSender(); 196d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return pd; 197d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 198d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 199d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Shared code for getFromRawPhoneBySystemLocale and getFromRawPhoneBySimLocale 200d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private static ParticipantData getFromRawPhone(final String phoneNumber) { 201d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.isTrue(phoneNumber != null); 202d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ParticipantData pd = new ParticipantData(); 203d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mParticipantId = null; 204d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubId = OTHER_THAN_SELF_SUB_ID; 205d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSlotId = INVALID_SLOT_ID; 206d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSendDestination = TextUtil.replaceUnicodeDigits(phoneNumber); 207d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mIsEmailAddress = MmsSmsUtils.isEmailAddress(pd.mSendDestination); 208d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mFullName = null; 209d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mFirstName = null; 210d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mProfilePhotoUri = null; 211d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mContactId = PARTICIPANT_CONTACT_ID_NOT_RESOLVED; 212d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mLookupKey = null; 213d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mBlocked = false; 214d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubscriptionColor = Color.TRANSPARENT; 215d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubscriptionName = null; 216d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return pd; 217d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 218d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 219d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 220d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Get an instance from a raw phone number and using system locale to normalize it. 221d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 222d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Use this when creating a participant that is for displaying UI and not associated 223d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * with a specific SIM. For example, when creating a conversation using user entered 224d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * phone number. 225d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 226d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @param phoneNumber The raw phone number 227d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @return instance 228d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 229d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static ParticipantData getFromRawPhoneBySystemLocale(final String phoneNumber) { 230d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ParticipantData pd = getFromRawPhone(phoneNumber); 231d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mNormalizedDestination = pd.mIsEmailAddress ? 232d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSendDestination : 233d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PhoneUtils.getDefault().getCanonicalBySystemLocale(pd.mSendDestination); 234d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mDisplayDestination = pd.mIsEmailAddress ? 235d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mNormalizedDestination : 236d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PhoneUtils.getDefault().formatForDisplay(pd.mNormalizedDestination); 237d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.maybeSetupUnknownSender(); 238d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return pd; 239d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 240d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 241d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 242d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Get an instance from a raw phone number and using SIM or system locale to normalize it. 243d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 244d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Use this when creating a participant that is associated with a specific SIM. For example, 245d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * the sender of a received message or the recipient of a sending message that is already 246d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * targeted at a specific SIM. 247d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 248d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @param phoneNumber The raw phone number 249d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @return instance 250d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 251d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static ParticipantData getFromRawPhoneBySimLocale( 252d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String phoneNumber, final int subId) { 253d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ParticipantData pd = getFromRawPhone(phoneNumber); 254d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mNormalizedDestination = pd.mIsEmailAddress ? 255d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSendDestination : 256d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PhoneUtils.get(subId).getCanonicalBySimLocale(pd.mSendDestination); 257d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mDisplayDestination = pd.mIsEmailAddress ? 258d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mNormalizedDestination : 259d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PhoneUtils.getDefault().formatForDisplay(pd.mNormalizedDestination); 260d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.maybeSetupUnknownSender(); 261d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return pd; 262d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 263d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 264d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static ParticipantData getSelfParticipant(final int subId) { 265d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.isTrue(subId != OTHER_THAN_SELF_SUB_ID); 266d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ParticipantData pd = new ParticipantData(); 267d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mParticipantId = null; 268d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubId = subId; 269d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSlotId = INVALID_SLOT_ID; 270d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mIsEmailAddress = false; 271d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSendDestination = null; 272d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mNormalizedDestination = null; 273d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mDisplayDestination = null; 274d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mFullName = null; 275d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mFirstName = null; 276d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mProfilePhotoUri = null; 277d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mContactId = PARTICIPANT_CONTACT_ID_NOT_RESOLVED; 278d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mLookupKey = null; 279d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mBlocked = false; 280d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubscriptionColor = Color.TRANSPARENT; 281d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd pd.mSubscriptionName = null; 282d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return pd; 283d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 284d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 285d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private void maybeSetupUnknownSender() { 286d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (isUnknownSender()) { 287d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Because your locale may change, we setup the display string for the unknown sender 288d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // on the fly rather than relying on the version in the database. 289d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final Resources resources = Factory.get().getApplicationContext().getResources(); 290d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mDisplayDestination = resources.getString(R.string.unknown_sender); 291d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mFullName = mDisplayDestination; 292d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 293d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 294d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 295d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getNormalizedDestination() { 296d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mNormalizedDestination; 297d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 298d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 299d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getSendDestination() { 300d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mSendDestination; 301d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 302d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 303d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getDisplayDestination() { 304d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mDisplayDestination; 305d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 306d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 307d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getContactDestination() { 308d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mContactDestination; 309d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 310d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 311d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getFullName() { 312d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mFullName; 313d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 314d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 315d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getFirstName() { 316d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mFirstName; 317d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 318d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 319d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getDisplayName(final boolean preferFullName) { 320d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (preferFullName) { 321d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Prefer full name over first name 322d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (!TextUtils.isEmpty(mFullName)) { 323d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mFullName; 324d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 325d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (!TextUtils.isEmpty(mFirstName)) { 326d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mFirstName; 327d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 328d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } else { 329d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Prefer first name over full name 330d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (!TextUtils.isEmpty(mFirstName)) { 331d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mFirstName; 332d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 333d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (!TextUtils.isEmpty(mFullName)) { 334d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mFullName; 335d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 336d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 337d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 338d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Fallback to the display destination 339d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (!TextUtils.isEmpty(mDisplayDestination)) { 340d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mDisplayDestination; 341d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 342d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 343d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return Factory.get().getApplicationContext().getResources().getString( 344d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd R.string.unknown_sender); 345d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 346d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 347d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getProfilePhotoUri() { 348d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mProfilePhotoUri; 349d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 350d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 351d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public long getContactId() { 352d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mContactId; 353d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 354d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 355d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getLookupKey() { 356d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mLookupKey; 357d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 358d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 359d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean updatePhoneNumberForSelfIfChanged() { 360d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String phoneNumber = 361d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PhoneUtils.get(mSubId).getCanonicalForSelf(true/*allowOverride*/); 362d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd boolean changed = false; 363d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (isSelf() && !TextUtils.equals(phoneNumber, mNormalizedDestination)) { 364d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mNormalizedDestination = phoneNumber; 365d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSendDestination = phoneNumber; 366d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mDisplayDestination = mIsEmailAddress ? 367d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd phoneNumber : 368d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd PhoneUtils.getDefault().formatForDisplay(phoneNumber); 369d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd changed = true; 370d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 371d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return changed; 372d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 373d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 374d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean updateSubscriptionInfoForSelfIfChanged(final SubscriptionInfo subscriptionInfo) { 375d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd boolean changed = false; 376d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (isSelf()) { 377d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (subscriptionInfo == null) { 378d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // The subscription is inactive. Check if the participant is still active. 379d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (isActiveSubscription()) { 380d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSlotId = INVALID_SLOT_ID; 381d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSubscriptionColor = Color.TRANSPARENT; 382d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSubscriptionName = ""; 383d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd changed = true; 384d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 385d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } else { 386d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int slotId = subscriptionInfo.getSimSlotIndex(); 387d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final int color = subscriptionInfo.getIconTint(); 388d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final CharSequence name = subscriptionInfo.getDisplayName(); 389d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (mSlotId != slotId || mSubscriptionColor != color || mSubscriptionName != name) { 390d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSlotId = slotId; 391d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSubscriptionColor = color; 392d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSubscriptionName = name.toString(); 393d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd changed = true; 394d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 395d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 396d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 397d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return changed; 398d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 399d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 400d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void setFullName(final String fullName) { 401d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mFullName = fullName; 402d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 403d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 404d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void setFirstName(final String firstName) { 405d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mFirstName = firstName; 406d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 407d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 408d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void setProfilePhotoUri(final String profilePhotoUri) { 409d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mProfilePhotoUri = profilePhotoUri; 410d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 411d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 412d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void setContactId(final long contactId) { 413d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mContactId = contactId; 414d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 415d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 416d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void setLookupKey(final String lookupKey) { 417d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mLookupKey = lookupKey; 418d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 419d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 420d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void setSendDestination(final String destination) { 421d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSendDestination = destination; 422d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 423d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 424d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void setContactDestination(final String destination) { 425d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mContactDestination = destination; 426d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 427d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 428d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public int getSubId() { 429d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mSubId; 430d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 431d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 432d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 433d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * @return whether this sub is active. Note that {@link ParticipantData#DEFAULT_SELF_SUB_ID} is 434d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * is considered as active if there is any active SIM. 435d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 436d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean isActiveSubscription() { 437d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mSlotId != INVALID_SLOT_ID; 438d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 439d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 440d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean isDefaultSelf() { 441d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mSubId == ParticipantData.DEFAULT_SELF_SUB_ID; 442d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 443d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 444d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public int getSlotId() { 445d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mSlotId; 446d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 447d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 448d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd /** 449d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Slot IDs in the subscription manager is zero-based, but we want to show it 450d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * as 1-based in UI. 451d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 452d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public int getDisplaySlotId() { 453d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return getSlotId() + 1; 454d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 455d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 456d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public int getSubscriptionColor() { 457d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.isTrue(isActiveSubscription()); 458d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd // Force the alpha channel to 0xff to ensure the returned color is solid. 459d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mSubscriptionColor | 0xff000000; 460d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 461d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 462d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getSubscriptionName() { 463d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd Assert.isTrue(isActiveSubscription()); 464d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mSubscriptionName; 465d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 466d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 467d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public String getId() { 468d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mParticipantId; 469d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 470d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 471d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean isSelf() { 472d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return (mSubId != OTHER_THAN_SELF_SUB_ID); 473d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 474d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 475d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean isEmail() { 476d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mIsEmailAddress; 477d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 478d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 479d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean isContactIdResolved() { 480d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return (mContactId != PARTICIPANT_CONTACT_ID_NOT_RESOLVED); 481d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 482d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 483d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean isBlocked() { 484d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return mBlocked; 485d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 486d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 487d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public boolean isUnknownSender() { 488d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final String unknownSender = ParticipantData.getUnknownSenderDestination(); 489d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return (TextUtils.equals(mSendDestination, unknownSender)); 490d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 491d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 492d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public ContentValues toContentValues() { 493d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final ContentValues values = new ContentValues(); 494d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.SUB_ID, mSubId); 495d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.SIM_SLOT_ID, mSlotId); 496d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(DatabaseHelper.ParticipantColumns.SEND_DESTINATION, mSendDestination); 497d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 498d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (!isUnknownSender()) { 499d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(DatabaseHelper.ParticipantColumns.DISPLAY_DESTINATION, mDisplayDestination); 500d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(DatabaseHelper.ParticipantColumns.NORMALIZED_DESTINATION, 501d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mNormalizedDestination); 502d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.FULL_NAME, mFullName); 503d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.FIRST_NAME, mFirstName); 504d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 505d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 506d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.PROFILE_PHOTO_URI, mProfilePhotoUri); 507d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.CONTACT_ID, mContactId); 508d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.LOOKUP_KEY, mLookupKey); 509d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.BLOCKED, mBlocked); 510d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.SUBSCRIPTION_COLOR, mSubscriptionColor); 511d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd values.put(ParticipantColumns.SUBSCRIPTION_NAME, mSubscriptionName); 512d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return values; 513d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 514d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 515d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public ParticipantData(final Parcel in) { 516d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mParticipantId = in.readString(); 517d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSubId = in.readInt(); 518d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSlotId = in.readInt(); 519d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mNormalizedDestination = in.readString(); 520d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSendDestination = in.readString(); 521d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mDisplayDestination = in.readString(); 522d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mFullName = in.readString(); 523d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mFirstName = in.readString(); 524d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mProfilePhotoUri = in.readString(); 525d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mContactId = in.readLong(); 526d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mLookupKey = in.readString(); 527d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mIsEmailAddress = in.readInt() != 0; 528d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mBlocked = in.readInt() != 0; 529d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSubscriptionColor = in.readInt(); 530d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mSubscriptionName = in.readString(); 531d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 532d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 533d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 534d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public int describeContents() { 535d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return 0; 536d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 537d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 538d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 539d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public void writeToParcel(final Parcel dest, final int flags) { 540d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mParticipantId); 541d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeInt(mSubId); 542d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeInt(mSlotId); 543d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mNormalizedDestination); 544d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mSendDestination); 545d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mDisplayDestination); 546d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mFullName); 547d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mFirstName); 548d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mProfilePhotoUri); 549d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeLong(mContactId); 550d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mLookupKey); 551d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeInt(mIsEmailAddress ? 1 : 0); 552d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeInt(mBlocked ? 1 : 0); 553d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeInt(mSubscriptionColor); 554d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd dest.writeString(mSubscriptionName); 555d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 556d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 557d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public static final Parcelable.Creator<ParticipantData> CREATOR 558d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd = new Parcelable.Creator<ParticipantData>() { 559d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 560d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public ParticipantData createFromParcel(final Parcel in) { 561d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new ParticipantData(in); 562d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 563d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 564d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 565d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public ParticipantData[] newArray(final int size) { 566d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd return new ParticipantData[size]; 567d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 568d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd }; 569d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd} 570