Upgrading to new GAL registration API.
Change-Id: I67eaeb50ba8629a85d056da031e3b48ea7ab3858
This commit is contained in:
parent
8066a925b1
commit
32358f5516
|
@ -415,7 +415,9 @@
|
||||||
android:authorities="com.android.exchange.directory.provider"
|
android:authorities="com.android.exchange.directory.provider"
|
||||||
android:readPermission="android.permission.READ_CONTACTS"
|
android:readPermission="android.permission.READ_CONTACTS"
|
||||||
android:multiprocess="false"
|
android:multiprocess="false"
|
||||||
/>
|
>
|
||||||
|
<meta-data android:name="android.content.ContactDirectory" android:value="true"/>
|
||||||
|
</provider>
|
||||||
<!--EXCHANGE-REMOVE-SECTION-END-->
|
<!--EXCHANGE-REMOVE-SECTION-END-->
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
|
@ -103,21 +103,8 @@ public class EasAuthenticatorService extends Service {
|
||||||
ContentResolver.setSyncAutomatically(account, EmailContent.AUTHORITY, syncEmail);
|
ContentResolver.setSyncAutomatically(account, EmailContent.AUTHORITY, syncEmail);
|
||||||
|
|
||||||
// Register our GAL provider
|
// Register our GAL provider
|
||||||
ContentValues values = new ContentValues();
|
ContactsContract.Directory.notifyDirectoryChange(getContentResolver());
|
||||||
values.put(Directory.DIRECTORY_AUTHORITY,
|
|
||||||
ExchangeDirectoryProvider.EXCHANGE_GAL_AUTHORITY);
|
|
||||||
values.put(Directory.ACCOUNT_NAME, account.name);
|
|
||||||
values.put(Directory.ACCOUNT_TYPE, account.type);
|
|
||||||
values.put(Directory.PACKAGE_NAME, mContext.getPackageName());
|
|
||||||
if (VendorPolicyLoader.getInstance(EasAuthenticatorService.this)
|
|
||||||
.useAlternateExchangeStrings()) {
|
|
||||||
values.put(Directory.TYPE_RESOURCE_ID, R.string.exchange_name_alternate);
|
|
||||||
} else {
|
|
||||||
values.put(Directory.TYPE_RESOURCE_ID, R.string.exchange_name);
|
|
||||||
}
|
|
||||||
values.put(Directory.DISPLAY_NAME, account.name);
|
|
||||||
values.put(Directory.EXPORT_SUPPORT, Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY);
|
|
||||||
getContentResolver().insert(Directory.CONTENT_URI, values);
|
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
b.putString(AccountManager.KEY_ACCOUNT_NAME, options.getString(OPTIONS_USERNAME));
|
b.putString(AccountManager.KEY_ACCOUNT_NAME, options.getString(OPTIONS_USERNAME));
|
||||||
b.putString(AccountManager.KEY_ACCOUNT_TYPE, Email.EXCHANGE_ACCOUNT_MANAGER_TYPE);
|
b.putString(AccountManager.KEY_ACCOUNT_TYPE, Email.EXCHANGE_ACCOUNT_MANAGER_TYPE);
|
||||||
|
|
|
@ -16,12 +16,15 @@
|
||||||
|
|
||||||
package com.android.exchange.provider;
|
package com.android.exchange.provider;
|
||||||
|
|
||||||
|
import com.android.email.R;
|
||||||
|
import com.android.email.VendorPolicyLoader;
|
||||||
import com.android.email.mail.PackedString;
|
import com.android.email.mail.PackedString;
|
||||||
import com.android.email.provider.EmailContent.Account;
|
import com.android.email.provider.EmailContent.Account;
|
||||||
import com.android.exchange.EasSyncService;
|
import com.android.exchange.EasSyncService;
|
||||||
import com.android.exchange.SyncManager;
|
import com.android.exchange.SyncManager;
|
||||||
import com.android.exchange.provider.GalResult.GalData;
|
import com.android.exchange.provider.GalResult.GalData;
|
||||||
|
|
||||||
|
import android.accounts.AccountManager;
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.UriMatcher;
|
import android.content.UriMatcher;
|
||||||
|
@ -35,6 +38,7 @@ import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
|
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
|
||||||
import android.provider.ContactsContract.Contacts;
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.Contacts.Data;
|
import android.provider.ContactsContract.Contacts.Data;
|
||||||
|
import android.provider.ContactsContract.Directory;
|
||||||
import android.provider.ContactsContract.RawContacts;
|
import android.provider.ContactsContract.RawContacts;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
@ -51,16 +55,17 @@ public class ExchangeDirectoryProvider extends ContentProvider {
|
||||||
private static final int DEFAULT_CONTACT_ID = 1;
|
private static final int DEFAULT_CONTACT_ID = 1;
|
||||||
|
|
||||||
private static final int GAL_BASE = 0;
|
private static final int GAL_BASE = 0;
|
||||||
private static final int GAL_FILTER = GAL_BASE;
|
private static final int GAL_DIRECTORIES = GAL_BASE;
|
||||||
private static final int GAL_CONTACT = GAL_BASE + 1;
|
private static final int GAL_FILTER = GAL_BASE + 1;
|
||||||
private static final int GAL_CONTACT_WITH_ID = GAL_BASE + 2;
|
private static final int GAL_CONTACT = GAL_BASE + 2;
|
||||||
|
private static final int GAL_CONTACT_WITH_ID = GAL_BASE + 3;
|
||||||
|
|
||||||
private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
sURIMatcher.addURI(EXCHANGE_GAL_AUTHORITY, "directories", GAL_DIRECTORIES);
|
||||||
sURIMatcher.addURI(EXCHANGE_GAL_AUTHORITY, "contacts/filter/*", GAL_FILTER);
|
sURIMatcher.addURI(EXCHANGE_GAL_AUTHORITY, "contacts/filter/*", GAL_FILTER);
|
||||||
sURIMatcher.addURI(EXCHANGE_GAL_AUTHORITY, "contacts/lookup/*/entities",
|
sURIMatcher.addURI(EXCHANGE_GAL_AUTHORITY, "contacts/lookup/*/entities", GAL_CONTACT);
|
||||||
GAL_CONTACT);
|
|
||||||
sURIMatcher.addURI(EXCHANGE_GAL_AUTHORITY, "contacts/lookup/*/#/entities",
|
sURIMatcher.addURI(EXCHANGE_GAL_AUTHORITY, "contacts/lookup/*/#/entities",
|
||||||
GAL_CONTACT_WITH_ID);
|
GAL_CONTACT_WITH_ID);
|
||||||
}
|
}
|
||||||
|
@ -163,30 +168,66 @@ public class ExchangeDirectoryProvider extends ContentProvider {
|
||||||
@Override
|
@Override
|
||||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
||||||
String sortOrder) {
|
String sortOrder) {
|
||||||
String accountName = uri.getQueryParameter(RawContacts.ACCOUNT_NAME);
|
|
||||||
if (accountName == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Account account = SyncManager.getAccountByName(accountName);
|
|
||||||
if (account == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int match = sURIMatcher.match(uri);
|
int match = sURIMatcher.match(uri);
|
||||||
MatrixCursor cursor;
|
MatrixCursor cursor;
|
||||||
Object[] row;
|
Object[] row;
|
||||||
PackedString ps;
|
PackedString ps;
|
||||||
List<String> pathSegments = uri.getPathSegments();
|
|
||||||
String lookupKey;
|
String lookupKey;
|
||||||
|
|
||||||
switch (match) {
|
switch (match) {
|
||||||
|
case GAL_DIRECTORIES: {
|
||||||
|
// Assuming that GAL can be used with all exchange accounts
|
||||||
|
android.accounts.Account[] accounts = AccountManager.get(getContext())
|
||||||
|
.getAccountsByType(com.android.email.Email.EXCHANGE_ACCOUNT_MANAGER_TYPE);
|
||||||
|
cursor = new MatrixCursor(projection);
|
||||||
|
if (accounts != null) {
|
||||||
|
for (android.accounts.Account account : accounts) {
|
||||||
|
row = new Object[projection.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < projection.length; i++) {
|
||||||
|
String column = projection[i];
|
||||||
|
if (column.equals(Directory.ACCOUNT_NAME)) {
|
||||||
|
row[i] = account.name;
|
||||||
|
} else if (column.equals(Directory.ACCOUNT_TYPE)) {
|
||||||
|
row[i] = account.type;
|
||||||
|
} else if (column.equals(Directory.TYPE_RESOURCE_ID)) {
|
||||||
|
if (VendorPolicyLoader.getInstance(getContext())
|
||||||
|
.useAlternateExchangeStrings()) {
|
||||||
|
row[i] = R.string.exchange_name_alternate;
|
||||||
|
} else {
|
||||||
|
row[i] = R.string.exchange_name;
|
||||||
|
}
|
||||||
|
} else if (column.equals(Directory.DISPLAY_NAME)) {
|
||||||
|
row[i] = account.name;
|
||||||
|
} else if (column.equals(Directory.EXPORT_SUPPORT)) {
|
||||||
|
row[i] = Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY;
|
||||||
|
} else if (column.equals(Directory.SHORTCUT_SUPPORT)) {
|
||||||
|
row[i] = Directory.SHORTCUT_SUPPORT_FULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor.addRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
|
||||||
case GAL_FILTER: {
|
case GAL_FILTER: {
|
||||||
String filter = uri.getLastPathSegment();
|
String filter = uri.getLastPathSegment();
|
||||||
// We should have at least two characters before doing a GAL search
|
// We should have at least two characters before doing a GAL search
|
||||||
if (filter == null || filter.length() < 2) {
|
if (filter == null || filter.length() < 2) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String accountName = uri.getQueryParameter(RawContacts.ACCOUNT_NAME);
|
||||||
|
if (accountName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Account account = SyncManager.getAccountByName(accountName);
|
||||||
|
if (account == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
long callingId = Binder.clearCallingIdentity();
|
long callingId = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
// Get results from the Exchange account
|
// Get results from the Exchange account
|
||||||
|
@ -203,9 +244,15 @@ public class ExchangeDirectoryProvider extends ContentProvider {
|
||||||
|
|
||||||
case GAL_CONTACT:
|
case GAL_CONTACT:
|
||||||
case GAL_CONTACT_WITH_ID: {
|
case GAL_CONTACT_WITH_ID: {
|
||||||
|
String accountName = uri.getQueryParameter(RawContacts.ACCOUNT_NAME);
|
||||||
|
if (accountName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
GalProjection galProjection = new GalProjection(projection);
|
GalProjection galProjection = new GalProjection(projection);
|
||||||
cursor = new MatrixCursor(projection);
|
cursor = new MatrixCursor(projection);
|
||||||
// Handle the decomposition of the key into rows suitable for CP2
|
// Handle the decomposition of the key into rows suitable for CP2
|
||||||
|
List<String> pathSegments = uri.getPathSegments();
|
||||||
lookupKey = pathSegments.get(2);
|
lookupKey = pathSegments.get(2);
|
||||||
long contactId = (match == GAL_CONTACT_WITH_ID)
|
long contactId = (match == GAL_CONTACT_WITH_ID)
|
||||||
? Long.parseLong(pathSegments.get(3))
|
? Long.parseLong(pathSegments.get(3))
|
||||||
|
|
Loading…
Reference in New Issue