乐健体育 v3.9.1版本的 MD5 值为:87ae8a64955cdd0e43f3559ee8984d75
以下内容为反编译后的 ContactAccessorImpl.java 源代码,内容仅作参考
package io.dcloud.feature.contacts;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
import android.provider.ContactsContract;
import android.util.Base64;
import android.util.Log;
import com.google.android.exoplayer2.text.ttml.TtmlNode;
import com.google.android.gms.common.internal.AccountType;
import com.taobao.weex.bridge.WXBridgeManager;
import com.taobao.weex.common.Constants;
import com.taobao.weex.el.parse.Operators;
import com.taobao.weex.utils.WXUtils;
import io.dcloud.common.adapter.util.DeviceInfo;
import io.dcloud.common.adapter.util.Logger;
import io.dcloud.common.util.JSONUtil;
import io.dcloud.feature.contacts.ContactAccessor;
import io.dcloud.feature.oauth.BaseOAuthService;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ContactAccessorImpl extends ContactAccessor {
private static final String EMAIL_REGEXP = ".+@.+\\.+.+";
private static final long MAX_PHOTO_SIZE = 1048576;
private static final String Tag = "contacts";
private static final Map<String, String> dbMap;
static {
HashMap hashMap = new HashMap();
dbMap = hashMap;
hashMap.put("id", "raw_contact_id");
hashMap.put("displayName", "display_name");
hashMap.put("name", "data1");
hashMap.put("name.formatted", "data1");
hashMap.put("name.familyName", "data3");
hashMap.put("name.givenName", "data2");
hashMap.put("name.middleName", "data5");
hashMap.put("name.honorificPrefix", "data4");
hashMap.put("name.honorificSuffix", "data6");
hashMap.put(BaseOAuthService.KEY_NICKNAME, "data1");
hashMap.put("phoneNumbers", "data1");
hashMap.put("phoneNumbers.value", "data1");
hashMap.put("emails", "data1");
hashMap.put("emails.value", "data1");
hashMap.put("addresses", "data1");
hashMap.put("addresses.formatted", "data1");
hashMap.put("addresses.streetAddress", "data4");
hashMap.put("addresses.locality", "data7");
hashMap.put("addresses.region", "data8");
hashMap.put("addresses.postalCode", "data9");
hashMap.put("addresses.country", "data10");
hashMap.put("ims", "data1");
hashMap.put("ims.value", "data1");
hashMap.put("organizations", "data1");
hashMap.put("organizations.name", "data1");
hashMap.put("organizations.department", "data5");
hashMap.put("organizations.title", "data4");
hashMap.put("birthday", "vnd.android.cursor.item/contact_event");
hashMap.put("note", "data1");
hashMap.put("photos.value", "vnd.android.cursor.item/photo");
hashMap.put("urls", "data1");
hashMap.put("urls.value", "data1");
}
public ContactAccessorImpl(Context context) {
this.mApp = context;
}
private JSONObject addressQuery(Cursor cursor) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("id", cursor.getString(cursor.getColumnIndex("_id")));
jSONObject.put("pref", false);
jSONObject.put("type", getAddressType(cursor.getInt(cursor.getColumnIndex("data2"))));
jSONObject.put("formatted", cursor.getString(cursor.getColumnIndex("data1")));
jSONObject.put("streetAddress", cursor.getString(cursor.getColumnIndex("data4")));
jSONObject.put("locality", cursor.getString(cursor.getColumnIndex("data7")));
jSONObject.put(TtmlNode.TAG_REGION, cursor.getString(cursor.getColumnIndex("data8")));
jSONObject.put("postalCode", cursor.getString(cursor.getColumnIndex("data9")));
jSONObject.put("country", cursor.getString(cursor.getColumnIndex("data10")));
} catch (JSONException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
}
return jSONObject;
}
private ContactAccessor.WhereOptions buildIdClause(ArrayList<String> arrayList) {
ContactAccessor.WhereOptions whereOptions = new ContactAccessor.WhereOptions();
Iterator<String> it = arrayList.iterator();
StringBuffer stringBuffer = new StringBuffer(Operators.BRACKET_START_STR);
while (it.hasNext()) {
stringBuffer.append("'" + it.next() + "'");
if (it.hasNext()) {
stringBuffer.append(",");
}
}
stringBuffer.append(Operators.BRACKET_END_STR);
whereOptions.setSelection("raw_contact_id IN " + stringBuffer.toString());
whereOptions.setSelectionArgs(null);
return whereOptions;
}
private ContactAccessor.WhereOptions buildWhereClause(JSONArray jSONArray) {
int length;
Map<String, String> map;
ContactAccessor.WhereOptions whereOptions = new ContactAccessor.WhereOptions();
if (jSONArray != null && (length = jSONArray.length()) > 0) {
StringBuffer stringBuffer = new StringBuffer();
ArrayList arrayList = new ArrayList();
boolean z = false;
for (int i2 = 0; i2 < length; i2++) {
JSONObject jSONObject = JSONUtil.getJSONObject(jSONArray, i2);
String string = JSONUtil.getString(jSONObject, "field");
String formatLogic = formatLogic(JSONUtil.getString(jSONObject, "logic"));
String string2 = JSONUtil.getString(jSONObject, "value");
if (string != null) {
if (dbMap.containsKey(string) && string2 != null && !string2.equals("")) {
String replace = string2.replace(Operators.CONDITION_IF, '_').replace('*', WXUtils.PERCENT);
stringBuffer.append(Operators.BRACKET_START_STR + map.get(string) + " LIKE ? )");
if (i2 != length - 1) {
stringBuffer.append(Operators.SPACE_STR + formatLogic + Operators.SPACE_STR);
}
arrayList.add(replace);
z = true;
}
}
}
if (z) {
whereOptions.setSelection(stringBuffer.toString());
String[] strArr = new String[arrayList.size()];
arrayList.toArray(strArr);
whereOptions.setSelectionArgs(strArr);
}
}
return whereOptions;
}
private boolean createNewContact(JSONObject jSONObject, Account account) {
ArrayList<ContentProviderOperation> arrayList = new ArrayList<>();
ArrayList arrayList2 = new ArrayList();
if (account != null) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue("account_type", account.type).withValue("account_name", account.name).build());
} else {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue("aggregation_mode", 3).build());
}
arrayList2.add(jSONObject);
JSONObject optJSONObject = jSONObject.optJSONObject("name");
String jsonString = getJsonString(jSONObject, "displayName");
if (jsonString != null || optJSONObject != null) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/name").withValue("data1", jsonString).withValue("data3", getJsonString(optJSONObject, "familyName")).withValue("data5", getJsonString(optJSONObject, "middleName")).withValue("data2", getJsonString(optJSONObject, "givenName")).withValue("data4", getJsonString(optJSONObject, "honorificPrefix")).withValue("data6", getJsonString(optJSONObject, "honorificSuffix")).build());
arrayList2.add(optJSONObject);
}
try {
JSONArray jSONArray = jSONObject.getJSONArray("phoneNumbers");
if (jSONArray != null) {
for (int i2 = 0; i2 < jSONArray.length(); i2++) {
insertPhone(arrayList, (JSONObject) jSONArray.get(i2));
}
}
} catch (JSONException unused) {
Log.d("ContactsAccessor", "Could not get phone numbers");
}
try {
JSONArray jSONArray2 = jSONObject.getJSONArray("emails");
if (jSONArray2 != null) {
for (int i3 = 0; i3 < jSONArray2.length(); i3++) {
JSONObject jSONObject2 = (JSONObject) jSONArray2.get(i3);
insertEmail(arrayList, jSONObject2);
arrayList2.add(jSONObject2);
}
}
} catch (JSONException unused2) {
Log.d("ContactsAccessor", "Could not get emails");
}
try {
JSONArray jSONArray3 = jSONObject.getJSONArray("addresses");
if (jSONArray3 != null) {
for (int i4 = 0; i4 < jSONArray3.length(); i4++) {
JSONObject jSONObject3 = (JSONObject) jSONArray3.get(i4);
insertAddress(arrayList, jSONObject3);
arrayList2.add(jSONObject3);
}
}
} catch (JSONException unused3) {
Log.d("ContactsAccessor", "Could not get addresses");
}
try {
JSONArray jSONArray4 = jSONObject.getJSONArray("organizations");
if (jSONArray4 != null) {
for (int i5 = 0; i5 < jSONArray4.length(); i5++) {
JSONObject jSONObject4 = (JSONObject) jSONArray4.get(i5);
insertOrganization(arrayList, jSONObject4);
arrayList2.add(jSONObject4);
}
}
} catch (JSONException unused4) {
Log.d("ContactsAccessor", "Could not get organizations");
}
try {
JSONArray jSONArray5 = jSONObject.getJSONArray("ims");
if (jSONArray5 != null) {
for (int i6 = 0; i6 < jSONArray5.length(); i6++) {
JSONObject jSONObject5 = (JSONObject) jSONArray5.get(i6);
insertIm(arrayList, jSONObject5);
arrayList2.add(jSONObject5);
}
}
} catch (JSONException unused5) {
Log.d("ContactsAccessor", "Could not get emails");
}
try {
JSONArray jSONArray6 = jSONObject.getJSONArray("websites");
if (jSONArray6 != null) {
for (int i7 = 0; i7 < jSONArray6.length(); i7++) {
JSONObject jSONObject6 = (JSONObject) jSONArray6.get(i7);
insertWebsite(arrayList, jSONObject6);
arrayList2.add(jSONObject6);
}
}
} catch (JSONException unused6) {
Log.d("ContactsAccessor", "Could not get websites");
}
try {
JSONArray jSONArray7 = jSONObject.getJSONArray("photos");
if (jSONArray7 != null) {
for (int i8 = 0; i8 < jSONArray7.length(); i8++) {
JSONObject jSONObject7 = (JSONObject) jSONArray7.get(i8);
insertPhoto(arrayList, jSONObject7);
arrayList2.add(jSONObject7);
}
}
} catch (JSONException unused7) {
Log.d("ContactsAccessor", "Could not get photos");
}
String jsonString2 = getJsonString(jSONObject, "birthday");
if (jsonString2 != null) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/contact_event").withValue("data2", 3).withValue("data1", jsonString2).build());
}
String jsonString3 = getJsonString(jSONObject, "note");
if (jsonString3 != null) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/note").withValue("data1", jsonString3).build());
}
String jsonString4 = getJsonString(jSONObject, BaseOAuthService.KEY_NICKNAME);
if (jsonString4 != null) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/nickname").withValue("data1", jsonString4).build());
}
try {
ContentProviderResult[] applyBatch = this.mApp.getContentResolver().applyBatch("com.android.contacts", arrayList);
if (applyBatch.length >= 0) {
for (int i9 = 0; i9 < arrayList2.size(); i9++) {
String lastPathSegment = applyBatch[i9].uri.getLastPathSegment();
JSONObject jSONObject8 = (JSONObject) arrayList2.get(i9);
if (jSONObject8 != null) {
jSONObject8.put("id", lastPathSegment);
}
}
}
return true;
} catch (OperationApplicationException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
return false;
} catch (RemoteException e3) {
Log.e("ContactsAccessor", e3.getMessage(), e3);
return false;
} catch (JSONException e4) {
Logger.e(e4.getMessage());
return false;
}
}
private JSONObject emailQuery(Cursor cursor) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("id", cursor.getString(cursor.getColumnIndex("_id")));
jSONObject.put("pref", false);
jSONObject.put("value", cursor.getString(cursor.getColumnIndex("data1")));
jSONObject.put("type", getContactType(cursor.getInt(cursor.getColumnIndex("data2"))));
} catch (JSONException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
}
return jSONObject;
}
private String formatLogic(String str) {
String lowerCase = str != null ? str.toLowerCase(Locale.ENGLISH) : "or";
return (lowerCase.equals("not") || lowerCase.equals("and")) ? lowerCase : "or";
}
private int getAddressType(String str) {
if (str != null) {
Locale locale = Locale.ENGLISH;
if ("work".equals(str.toLowerCase(locale))) {
return 2;
}
if (!"other".equals(str.toLowerCase(locale)) && "home".equals(str.toLowerCase(locale))) {
return 1;
}
}
return 3;
}
private String getAddressType(int i2) {
return i2 != 1 ? i2 != 2 ? "other" : "work" : "home";
}
private int getContactType(String str) {
if (str != null) {
Locale locale = Locale.ENGLISH;
if ("home".equals(str.toLowerCase(locale))) {
return 1;
}
if ("work".equals(str.toLowerCase(locale))) {
return 2;
}
if ("other".equals(str.toLowerCase(locale))) {
return 3;
}
if ("mobile".equals(str.toLowerCase(locale))) {
return 4;
}
if ("custom".equals(str.toLowerCase(locale))) {
return 0;
}
}
return 3;
}
private String getContactType(int i2) {
return i2 != 0 ? i2 != 1 ? i2 != 2 ? i2 != 4 ? "other" : "mobile" : "work" : "home" : "custom";
}
private int getOrgType(String str) {
if (str != null) {
Locale locale = Locale.ENGLISH;
if ("work".equals(str.toLowerCase(locale))) {
return 1;
}
if (!"other".equals(str.toLowerCase(locale)) && "custom".equals(str.toLowerCase(locale))) {
return 0;
}
}
return 2;
}
private String getOrgType(int i2) {
return i2 != 0 ? i2 != 1 ? "other" : "work" : "custom";
}
private InputStream getPathFromUri(String str) throws IOException {
if (str.startsWith("content:")) {
return this.mApp.getContentResolver().openInputStream(Uri.parse(str));
} else if (!str.startsWith("http:") && !str.startsWith("file:")) {
return this.mView.obtainFrameView().obtainApp().obtainResInStream(this.mView.obtainFullUrl(), str);
} else {
return new URL(str).openStream();
}
}
private int getPhoneType(String str) {
Locale locale = Locale.ENGLISH;
if ("home".equals(str.toLowerCase(locale))) {
return 1;
}
if ("mobile".equals(str.toLowerCase(locale))) {
return 2;
}
if ("work".equals(str.toLowerCase(locale))) {
return 3;
}
if ("work fax".equals(str.toLowerCase(locale))) {
return 4;
}
if ("home fax".equals(str.toLowerCase(locale))) {
return 5;
}
if ("fax".equals(str.toLowerCase(locale))) {
return 4;
}
if ("pager".equals(str.toLowerCase(locale))) {
return 6;
}
if ("other".equals(str.toLowerCase(locale))) {
return 7;
}
if ("car".equals(str.toLowerCase(locale))) {
return 9;
}
if ("company main".equals(str.toLowerCase(locale))) {
return 10;
}
if ("isdn".equals(str.toLowerCase(locale))) {
return 11;
}
if ("main".equals(str.toLowerCase(locale))) {
return 12;
}
if ("other fax".equals(str.toLowerCase(locale))) {
return 13;
}
if ("radio".equals(str.toLowerCase(locale))) {
return 14;
}
if ("telex".equals(str.toLowerCase(locale))) {
return 15;
}
if ("work mobile".equals(str.toLowerCase(locale))) {
return 17;
}
if ("work pager".equals(str.toLowerCase(locale))) {
return 18;
}
if ("assistant".equals(str.toLowerCase(locale))) {
return 19;
}
if ("mms".equals(str.toLowerCase(locale))) {
return 20;
}
if (WXBridgeManager.METHOD_CALLBACK.equals(str.toLowerCase(locale))) {
return 8;
}
if ("tty ttd".equals(str.toLowerCase(locale))) {
return 16;
}
return "custom".equals(str.toLowerCase(locale)) ? 0 : 7;
}
private String getPhoneType(int i2) {
switch (i2) {
case 0:
return "custom";
case 1:
return "home";
case 2:
return "mobile";
case 3:
return "work";
case 4:
return "work fax";
case 5:
return "home fax";
case 6:
return "pager";
case 7:
case 12:
default:
return "other";
case 8:
return WXBridgeManager.METHOD_CALLBACK;
case 9:
return "car";
case 10:
return "company main";
case 11:
return "isdn";
case 13:
return "other fax";
case 14:
return "radio";
case 15:
return "telex";
case 16:
return "tty tdd";
case 17:
return "work mobile";
case 18:
return "work pager";
case 19:
return "assistant";
case 20:
return "mms";
}
}
private byte[] getPhotoBytes(String str) {
int indexOf = str.indexOf(";base64,");
if (indexOf > 0) {
String substring = str.substring(indexOf + 8);
if (DeviceInfo.sDeviceSdkVer >= 8) {
return Base64.decode(substring, 2);
}
return io.dcloud.common.util.Base64.decode2bytes(substring);
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
long j2 = 0;
try {
InputStream pathFromUri = getPathFromUri(str);
if (pathFromUri != null) {
byte[] bArr = new byte[8192];
while (true) {
int read = pathFromUri.read(bArr, 0, 8192);
if (read == -1 || j2 > 1048576) {
break;
}
byteArrayOutputStream.write(bArr, 0, read);
j2 += read;
}
pathFromUri.close();
byteArrayOutputStream.flush();
}
} catch (FileNotFoundException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
} catch (IOException e3) {
Log.e("ContactsAccessor", e3.getMessage(), e3);
}
return byteArrayOutputStream.toByteArray();
}
private JSONObject imQuery(Cursor cursor) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("id", cursor.getString(cursor.getColumnIndex("_id")));
jSONObject.put("pref", false);
jSONObject.put("value", cursor.getString(cursor.getColumnIndex("data1")));
jSONObject.put("type", getContactType(cursor.getInt(cursor.getColumnIndex("data2"))));
} catch (JSONException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
}
return jSONObject;
}
private void insertAddress(ArrayList<ContentProviderOperation> arrayList, JSONObject jSONObject) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/postal-address_v2").withValue("data2", Integer.valueOf(getAddressType(getJsonString(jSONObject, "type")))).withValue("data1", getJsonString(jSONObject, "formatted")).withValue("data4", getJsonString(jSONObject, "streetAddress")).withValue("data7", getJsonString(jSONObject, "locality")).withValue("data8", getJsonString(jSONObject, TtmlNode.TAG_REGION)).withValue("data9", getJsonString(jSONObject, "postalCode")).withValue("data10", getJsonString(jSONObject, "country")).build());
}
private void insertEmail(ArrayList<ContentProviderOperation> arrayList, JSONObject jSONObject) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/email_v2").withValue("data1", getJsonString(jSONObject, "value")).withValue("data2", Integer.valueOf(getPhoneType(getJsonString(jSONObject, "type")))).build());
}
private void insertIm(ArrayList<ContentProviderOperation> arrayList, JSONObject jSONObject) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/im").withValue("data1", getJsonString(jSONObject, "value")).withValue("data2", Integer.valueOf(getContactType(getJsonString(jSONObject, "type")))).build());
}
private void insertOrganization(ArrayList<ContentProviderOperation> arrayList, JSONObject jSONObject) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/organization").withValue("data2", Integer.valueOf(getOrgType(getJsonString(jSONObject, "type")))).withValue("data5", getJsonString(jSONObject, "department")).withValue("data1", getJsonString(jSONObject, "name")).withValue("data4", getJsonString(jSONObject, "title")).build());
}
private void insertPhone(ArrayList<ContentProviderOperation> arrayList, JSONObject jSONObject) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/phone_v2").withValue("data1", getJsonString(jSONObject, "value")).withValue("data2", Integer.valueOf(getPhoneType(getJsonString(jSONObject, "type")))).build());
}
private void insertPhoto(ArrayList<ContentProviderOperation> arrayList, JSONObject jSONObject) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("is_super_primary", 1).withValue("mimetype", "vnd.android.cursor.item/photo").withValue("data15", getPhotoBytes(getJsonString(jSONObject, "value"))).build());
}
private void insertWebsite(ArrayList<ContentProviderOperation> arrayList, JSONObject jSONObject) {
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference("raw_contact_id", 0).withValue("mimetype", "vnd.android.cursor.item/website").withValue("data1", getJsonString(jSONObject, "value")).withValue("data2", Integer.valueOf(getContactType(getJsonString(jSONObject, "type")))).build());
}
private boolean isSearchAll(JSONArray jSONArray) {
if (jSONArray.length() == 1) {
try {
if (Operators.MUL.equals(jSONArray.getString(0))) {
return true;
}
} catch (JSONException unused) {
}
}
return false;
}
private boolean modifyContact(JSONObject jSONObject, Account account, String str) {
String str2;
String str3;
String str4;
String str5;
ContactAccessorImpl contactAccessorImpl;
String str6;
String str7;
String str8;
String str9;
JSONArray optJSONArray;
String str10;
byte[] photoBytes;
JSONArray optJSONArray2;
JSONArray jSONArray;
String str11;
String str12;
JSONArray optJSONArray3;
JSONArray jSONArray2;
String str13;
String jsonString;
JSONObject jSONObject2;
String str14 = "vnd.android.cursor.item/postal-address_v2";
String str15 = "vnd.android.cursor.item/photo";
String str16 = "vnd.android.cursor.item/organization";
String str17 = "type";
ArrayList<ContentProviderOperation> arrayList = new ArrayList<>();
if (account != null) {
str2 = "raw_contact_id=? and mimetype=?";
str3 = "raw_contact_id";
str4 = "mimetype";
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.RawContacts.CONTENT_URI).withValue("account_type", account.type).withValue("account_name", account.name).build());
} else {
str2 = "raw_contact_id=? and mimetype=?";
str3 = "raw_contact_id";
str4 = "mimetype";
}
try {
jsonString = getJsonString(jSONObject, "displayName");
jSONObject2 = jSONObject.getJSONObject("name");
str5 = "name";
} catch (JSONException unused) {
str5 = "name";
}
try {
ContentProviderOperation.Builder withSelection = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/name"});
withSelection.withValue("data1", jsonString);
withSelection.withValue("data3", getJsonString(jSONObject2, "familyName"));
withSelection.withValue("data5", getJsonString(jSONObject2, "middleName"));
withSelection.withValue("data2", getJsonString(jSONObject2, "givenName"));
withSelection.withValue("data4", getJsonString(jSONObject2, "honorificPrefix"));
withSelection.withValue("data6", getJsonString(jSONObject2, "honorificSuffix"));
arrayList.add(withSelection.build());
} catch (JSONException unused2) {
Log.d("ContactsAccessor", "Could not get name");
String str18 = "data5";
String str19 = str2;
String str20 = "data1";
String str21 = str3;
char c = 2;
String str22 = "data2";
String str23 = str4;
modifyContactOption(arrayList, jSONObject.optJSONArray("phoneNumbers"), str, "vnd.android.cursor.item/phone_v2", "data1", "data2");
modifyContactOption(arrayList, jSONObject.optJSONArray("emails"), str, "vnd.android.cursor.item/email_v2", "data1", "data2");
modifyContactOption(arrayList, jSONObject.optJSONArray("ims"), str, "vnd.android.cursor.item/im", "data1", "data2");
modifyContactOption(arrayList, jSONObject.optJSONArray("websites"), str, "vnd.android.cursor.item/website", "data1", "data2");
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str19, new String[]{String.valueOf(str), "vnd.android.cursor.item/postal-address_v2"}).build());
optJSONArray3 = jSONObject.optJSONArray("addresses");
if (optJSONArray3 != null) {
}
contactAccessorImpl = this;
str6 = str17;
str7 = str22;
str8 = str20;
str9 = "ContactsAccessor";
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str19, new String[]{String.valueOf(str), str16}).build());
optJSONArray2 = jSONObject.optJSONArray("organizations");
if (optJSONArray2 != null) {
}
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str19, new String[]{String.valueOf(str), str15}).build());
optJSONArray = jSONObject.optJSONArray("photos");
if (optJSONArray != null) {
}
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/note"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "note")).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/nickname"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, BaseOAuthService.KEY_NICKNAME)).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=? AND data2=?", new String[]{str, "vnd.android.cursor.item/contact_event", "3"}).withValue(str7, 3).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "birthday")).build());
contactAccessorImpl.mApp.getContentResolver().applyBatch("com.android.contacts", arrayList);
return true;
}
String str182 = "data5";
String str192 = str2;
String str202 = "data1";
String str212 = str3;
char c2 = 2;
String str222 = "data2";
String str232 = str4;
modifyContactOption(arrayList, jSONObject.optJSONArray("phoneNumbers"), str, "vnd.android.cursor.item/phone_v2", "data1", "data2");
modifyContactOption(arrayList, jSONObject.optJSONArray("emails"), str, "vnd.android.cursor.item/email_v2", "data1", "data2");
modifyContactOption(arrayList, jSONObject.optJSONArray("ims"), str, "vnd.android.cursor.item/im", "data1", "data2");
modifyContactOption(arrayList, jSONObject.optJSONArray("websites"), str, "vnd.android.cursor.item/website", "data1", "data2");
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), "vnd.android.cursor.item/postal-address_v2"}).build());
optJSONArray3 = jSONObject.optJSONArray("addresses");
if (optJSONArray3 != null) {
int i2 = 0;
while (i2 < optJSONArray3.length()) {
JSONObject optJSONObject = optJSONArray3.optJSONObject(i2);
if (optJSONObject != null) {
ContentValues contentValues = new ContentValues();
contentValues.put(str212, str);
contentValues.put(str232, str14);
contactAccessorImpl = this;
str6 = str17;
try {
str7 = str222;
} catch (Exception unused3) {
str7 = str222;
str8 = str202;
str9 = "ContactsAccessor";
Log.d(str9, "Could not get addresses");
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), str16}).build());
optJSONArray2 = jSONObject.optJSONArray("organizations");
if (optJSONArray2 != null) {
}
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), str15}).build());
optJSONArray = jSONObject.optJSONArray("photos");
if (optJSONArray != null) {
}
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/note"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "note")).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/nickname"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, BaseOAuthService.KEY_NICKNAME)).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=? AND data2=?", new String[]{str, "vnd.android.cursor.item/contact_event", "3"}).withValue(str7, 3).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "birthday")).build());
contactAccessorImpl.mApp.getContentResolver().applyBatch("com.android.contacts", arrayList);
return true;
}
try {
contentValues.put(str7, Integer.valueOf(contactAccessorImpl.getAddressType(contactAccessorImpl.getJsonString(optJSONObject, str6))));
jSONArray2 = optJSONArray3;
str8 = str202;
try {
contentValues.put(str8, contactAccessorImpl.getJsonString(optJSONObject, "formatted"));
contentValues.put("data4", contactAccessorImpl.getJsonString(optJSONObject, "streetAddress"));
str13 = str14;
contentValues.put("data7", contactAccessorImpl.getJsonString(optJSONObject, "locality"));
contentValues.put("data8", contactAccessorImpl.getJsonString(optJSONObject, TtmlNode.TAG_REGION));
contentValues.put("data9", contactAccessorImpl.getJsonString(optJSONObject, "postalCode"));
contentValues.put("data10", contactAccessorImpl.getJsonString(optJSONObject, "country"));
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValues(contentValues).build());
} catch (Exception unused4) {
str9 = "ContactsAccessor";
Log.d(str9, "Could not get addresses");
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), str16}).build());
optJSONArray2 = jSONObject.optJSONArray("organizations");
if (optJSONArray2 != null) {
}
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), str15}).build());
optJSONArray = jSONObject.optJSONArray("photos");
if (optJSONArray != null) {
}
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/note"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "note")).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/nickname"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, BaseOAuthService.KEY_NICKNAME)).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=? AND data2=?", new String[]{str, "vnd.android.cursor.item/contact_event", "3"}).withValue(str7, 3).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "birthday")).build());
contactAccessorImpl.mApp.getContentResolver().applyBatch("com.android.contacts", arrayList);
return true;
}
} catch (Exception unused5) {
str8 = str202;
str9 = "ContactsAccessor";
Log.d(str9, "Could not get addresses");
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), str16}).build());
optJSONArray2 = jSONObject.optJSONArray("organizations");
if (optJSONArray2 != null) {
}
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), str15}).build());
optJSONArray = jSONObject.optJSONArray("photos");
if (optJSONArray != null) {
}
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/note"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "note")).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/nickname"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, BaseOAuthService.KEY_NICKNAME)).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=? AND data2=?", new String[]{str, "vnd.android.cursor.item/contact_event", "3"}).withValue(str7, 3).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "birthday")).build());
contactAccessorImpl.mApp.getContentResolver().applyBatch("com.android.contacts", arrayList);
return true;
}
} else {
jSONArray2 = optJSONArray3;
str6 = str17;
str7 = str222;
str8 = str202;
str13 = str14;
}
i2++;
str202 = str8;
str17 = str6;
str14 = str13;
c2 = 2;
optJSONArray3 = jSONArray2;
str222 = str7;
}
}
contactAccessorImpl = this;
str6 = str17;
str7 = str222;
str8 = str202;
str9 = "ContactsAccessor";
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), str16}).build());
optJSONArray2 = jSONObject.optJSONArray("organizations");
if (optJSONArray2 != null) {
int i3 = 0;
while (i3 < optJSONArray2.length()) {
JSONObject optJSONObject2 = optJSONArray2.optJSONObject(i3);
if (optJSONObject2 != null) {
ContentValues contentValues2 = new ContentValues();
contentValues2.put(str212, str);
jSONArray = optJSONArray2;
String str24 = str16;
contentValues2.put(str232, str24);
str16 = str24;
contentValues2.put(str7, Integer.valueOf(contactAccessorImpl.getOrgType(contactAccessorImpl.getJsonString(optJSONObject2, str6))));
str11 = str6;
String str25 = str182;
contentValues2.put(str25, contactAccessorImpl.getJsonString(optJSONObject2, "department"));
str182 = str25;
str12 = str5;
contentValues2.put(str8, contactAccessorImpl.getJsonString(optJSONObject2, str12));
contentValues2.put("data4", contactAccessorImpl.getJsonString(optJSONObject2, "title"));
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValues(contentValues2).build());
} else {
jSONArray = optJSONArray2;
str11 = str6;
str12 = str5;
}
i3++;
str5 = str12;
str6 = str11;
optJSONArray2 = jSONArray;
}
}
try {
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection(str192, new String[]{String.valueOf(str), str15}).build());
optJSONArray = jSONObject.optJSONArray("photos");
if (optJSONArray != null) {
int i4 = 0;
while (i4 < optJSONArray.length()) {
JSONObject optJSONObject3 = optJSONArray.optJSONObject(i4);
if (optJSONObject3 == null || (photoBytes = contactAccessorImpl.getPhotoBytes(contactAccessorImpl.getJsonString(optJSONObject3, "value"))) == null) {
str10 = str15;
} else {
ContentValues contentValues3 = new ContentValues();
contentValues3.put(str212, str);
str10 = str15;
contentValues3.put(str232, str10);
contentValues3.put("is_super_primary", (Integer) 1);
contentValues3.put("data15", photoBytes);
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValues(contentValues3).build());
}
i4++;
str15 = str10;
}
}
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/note"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "note")).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=?", new String[]{str, "vnd.android.cursor.item/nickname"}).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, BaseOAuthService.KEY_NICKNAME)).build());
arrayList.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? AND mimetype=? AND data2=?", new String[]{str, "vnd.android.cursor.item/contact_event", "3"}).withValue(str7, 3).withValue(str8, contactAccessorImpl.getJsonString(jSONObject, "birthday")).build());
} catch (Exception unused6) {
Log.d(str9, "Could not get photos");
}
try {
contactAccessorImpl.mApp.getContentResolver().applyBatch("com.android.contacts", arrayList);
return true;
} catch (OperationApplicationException e2) {
Log.e(str9, e2.getMessage(), e2);
Log.e(str9, Log.getStackTraceString(e2), e2);
return false;
} catch (RemoteException e3) {
Log.e(str9, e3.getMessage(), e3);
Log.e(str9, Log.getStackTraceString(e3), e3);
return false;
}
}
private void modifyContactOption(ArrayList<ContentProviderOperation> arrayList, JSONArray jSONArray, String str, String str2, String str3, String str4) {
arrayList.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).withSelection("raw_contact_id=? and mimetype=?", new String[]{String.valueOf(str), str2}).build());
if (jSONArray != null) {
for (int i2 = 0; i2 < jSONArray.length(); i2++) {
JSONObject optJSONObject = jSONArray.optJSONObject(i2);
if (optJSONObject != null) {
ContentValues contentValues = new ContentValues();
contentValues.put("raw_contact_id", str);
contentValues.put("mimetype", str2);
contentValues.put(str3, getJsonString(optJSONObject, "value"));
contentValues.put(str4, Integer.valueOf(getContactType(getJsonString(optJSONObject, "type"))));
arrayList.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValues(contentValues).build());
}
}
}
}
private JSONObject nameQuery(Cursor cursor) {
JSONObject jSONObject = new JSONObject();
try {
String string = cursor.getString(cursor.getColumnIndex("data3"));
String string2 = cursor.getString(cursor.getColumnIndex("data2"));
String string3 = cursor.getString(cursor.getColumnIndex("data5"));
String string4 = cursor.getString(cursor.getColumnIndex("data4"));
String string5 = cursor.getString(cursor.getColumnIndex("data6"));
StringBuffer stringBuffer = new StringBuffer("");
if (string4 != null) {
stringBuffer.append(string4 + Operators.SPACE_STR);
}
if (string2 != null) {
stringBuffer.append(string2 + Operators.SPACE_STR);
}
if (string3 != null) {
stringBuffer.append(string3 + Operators.SPACE_STR);
}
if (string != null) {
stringBuffer.append(string + Operators.SPACE_STR);
}
if (string5 != null) {
stringBuffer.append(string5 + Operators.SPACE_STR);
}
jSONObject.put("familyName", string);
jSONObject.put("givenName", string2);
jSONObject.put("middleName", string3);
jSONObject.put("honorificPrefix", string4);
jSONObject.put("honorificSuffix", string5);
jSONObject.put("formatted", stringBuffer);
} catch (JSONException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
}
return jSONObject;
}
private JSONObject organizationQuery(Cursor cursor) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("id", cursor.getString(cursor.getColumnIndex("_id")));
jSONObject.put("pref", false);
jSONObject.put("type", getOrgType(cursor.getInt(cursor.getColumnIndex("data2"))));
jSONObject.put("department", cursor.getString(cursor.getColumnIndex("data5")));
jSONObject.put("name", cursor.getString(cursor.getColumnIndex("data1")));
jSONObject.put("title", cursor.getString(cursor.getColumnIndex("data4")));
} catch (JSONException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
}
return jSONObject;
}
private JSONObject phoneQuery(Cursor cursor) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("id", cursor.getString(cursor.getColumnIndex("_id")));
jSONObject.put("pref", false);
jSONObject.put("value", cursor.getString(cursor.getColumnIndex("data1")));
jSONObject.put("type", getPhoneType(cursor.getInt(cursor.getColumnIndex("data2"))));
} catch (JSONException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
} catch (Exception e3) {
Log.e("ContactsAccessor", e3.getMessage(), e3);
}
return jSONObject;
}
private JSONObject photoQuery(Cursor cursor, long j2) {
byte[] bArr;
String str;
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("id", cursor.getString(cursor.getColumnIndex("_id")));
jSONObject.put("pref", false);
jSONObject.put("type", "url");
InputStream openContactPhotoInputStream = ContactsContract.Contacts.openContactPhotoInputStream(this.mApp.getContentResolver(), ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, j2));
try {
openContactPhotoInputStream.read(new byte[openContactPhotoInputStream.available()]);
str = "data:image/png;base64," + Base64.encodeToString(bArr, 2);
} catch (Exception e2) {
e2.printStackTrace();
}
jSONObject.put("value", str);
} catch (JSONException e3) {
Log.e("ContactsAccessor", e3.getMessage(), e3);
}
return jSONObject;
}
private JSONObject populateContact(HashMap<String, Boolean> hashMap, JSONObject jSONObject, JSONArray jSONArray, JSONArray jSONArray2, JSONArray jSONArray3, JSONArray jSONArray4, JSONArray jSONArray5, JSONArray jSONArray6, JSONArray jSONArray7) {
try {
if (jSONArray3.length() > 0 || isRequired("phoneNumbers", hashMap)) {
jSONObject.put("phoneNumbers", jSONArray3);
}
if (jSONArray4.length() > 0 || isRequired("emails", hashMap)) {
jSONObject.put("emails", jSONArray4);
}
if (jSONArray2.length() > 0 || isRequired("addresses", hashMap)) {
jSONObject.put("addresses", jSONArray2);
}
if (jSONArray5.length() > 0 || isRequired("ims", hashMap)) {
jSONObject.put("ims", jSONArray5);
}
if (jSONArray.length() > 0 || isRequired("organizations", hashMap)) {
jSONObject.put("organizations", jSONArray);
}
if (jSONArray6.length() > 0 || isRequired("urls", hashMap)) {
jSONObject.put("urls", jSONArray6);
}
if (jSONArray7.length() > 0 || isRequired("photos", hashMap)) {
jSONObject.put("photos", jSONArray7);
}
} catch (JSONException e2) {
Log.e("ContactsAccessor", "e.getMessage()==" + e2.getMessage(), e2);
}
return jSONObject;
}
private org.json.JSONArray populateContactArray(int r34, java.util.HashMap<java.lang.String, java.lang.Boolean> r35, android.database.Cursor r36) {
throw new UnsupportedOperationException("Method not decompiled: io.dcloud.feature.contacts.ContactAccessorImpl.populateContactArray(int, java.util.HashMap, android.database.Cursor):org.json.JSONArray");
}
private JSONObject urlQuery(Cursor cursor) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("id", cursor.getString(cursor.getColumnIndex("_id")));
jSONObject.put("pref", false);
jSONObject.put("value", cursor.getString(cursor.getColumnIndex("data1")));
jSONObject.put("type", getContactType(cursor.getInt(cursor.getColumnIndex("data2"))));
} catch (JSONException e2) {
Log.e("ContactsAccessor", e2.getMessage(), e2);
}
return jSONObject;
}
@Override
public boolean remove(String str) {
ArrayList<ContentProviderOperation> arrayList = new ArrayList<>();
arrayList.add(ContentProviderOperation.newDelete(ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, Long.parseLong(str))).build());
try {
return this.mApp.getContentResolver().applyBatch("com.android.contacts", arrayList).length > 0;
} catch (Exception unused) {
return false;
}
}
@Override
public boolean save(JSONObject jSONObject) {
Account[] accounts = AccountManager.get(this.mApp).getAccounts();
Account account = null;
if (accounts.length == 1) {
account = accounts[0];
} else if (accounts.length > 1) {
int length = accounts.length;
int i2 = 0;
while (true) {
if (i2 >= length) {
break;
}
Account account2 = accounts[i2];
if (account2.type.contains("eas") && account2.name.matches(EMAIL_REGEXP)) {
account = account2;
break;
}
i2++;
}
if (account == null) {
int length2 = accounts.length;
int i3 = 0;
while (true) {
if (i3 >= length2) {
break;
}
Account account3 = accounts[i3];
if (account3.type.contains(AccountType.GOOGLE) && account3.name.matches(EMAIL_REGEXP)) {
account = account3;
break;
}
i3++;
}
}
if (account == null) {
int length3 = accounts.length;
int i4 = 0;
while (true) {
if (i4 >= length3) {
break;
}
Account account4 = accounts[i4];
if (account4.name.matches(EMAIL_REGEXP)) {
account = account4;
break;
}
i4++;
}
}
if (account == null) {
account = accounts[0];
}
}
String jsonString = getJsonString(jSONObject, "id");
if (jsonString != null && !BaseOAuthService.NULL.equals(jsonString)) {
return modifyContact(jSONObject, account, jsonString);
}
return createNewContact(jSONObject, account);
}
@Override
public JSONArray search(JSONArray jSONArray, JSONObject jSONObject) {
JSONArray jSONArray2;
String[] selectionArgs;
String str;
int i2 = Integer.MAX_VALUE;
boolean z = true;
if (jSONObject != null) {
jSONArray2 = JSONUtil.getJSONArray(jSONObject, Constants.Name.FILTER);
if (!jSONObject.optBoolean("multiple", true)) {
i2 = 1;
}
} else {
jSONArray2 = null;
}
if (jSONArray2 != null && jSONArray2.length() != 0 && (jSONArray2.length() != 1 || !jSONArray2.optJSONObject(0).isNull("field"))) {
z = false;
}
if (z) {
str = null;
selectionArgs = null;
} else {
ContactAccessor.WhereOptions buildWhereClause = buildWhereClause(jSONArray2);
String selection = buildWhereClause.getSelection();
selectionArgs = buildWhereClause.getSelectionArgs();
str = selection;
}
Cursor query = this.mApp.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[]{"raw_contact_id"}, str, selectionArgs, "raw_contact_id ASC");
ArrayList<String> arrayList = new ArrayList<>();
while (query.moveToNext()) {
arrayList.add(query.getString(query.getColumnIndex("raw_contact_id")));
}
query.close();
if (arrayList.size() == 0) {
return new JSONArray();
}
ContactAccessor.WhereOptions buildIdClause = buildIdClause(arrayList);
return populateContactArray(i2, buildPopulationSet(jSONArray), this.mApp.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, buildIdClause.getSelection(), buildIdClause.getSelectionArgs(), "raw_contact_id ASC"));
}
}