Loading android/app/src/com/android/bluetooth/hfp/AtPhonebook.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.telephony.PhoneNumberUtils; import android.util.Log; import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.Utils; import com.android.bluetooth.util.DevicePolicyUtils; import java.util.HashMap; import java.util.HashMap; Loading Loading @@ -429,7 +430,8 @@ public class AtPhonebook { pbr.typeColumn = -1; pbr.typeColumn = -1; pbr.nameColumn = -1; pbr.nameColumn = -1; } else { } else { pbr.cursor = mContentResolver.query(Phone.ENTERPRISE_CONTENT_URI, PHONES_PROJECTION, final Uri phoneContentUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); pbr.cursor = mContentResolver.query(phoneContentUri, PHONES_PROJECTION, where, null, Phone.NUMBER + " LIMIT " + MAX_PHONEBOOK_SIZE); where, null, Phone.NUMBER + " LIMIT " + MAX_PHONEBOOK_SIZE); if (pbr.cursor == null) return false; if (pbr.cursor == null) return false; Loading android/app/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java +6 −9 Original line number Original line Diff line number Diff line Loading @@ -67,6 +67,7 @@ import javax.obex.Operation; import javax.obex.ResponseCodes; import javax.obex.ResponseCodes; import com.android.bluetooth.Utils; import com.android.bluetooth.Utils; import com.android.bluetooth.util.DevicePolicyUtils; public class BluetoothPbapVcardManager { public class BluetoothPbapVcardManager { private static final String TAG = "BluetoothPbapVcardManager"; private static final String TAG = "BluetoothPbapVcardManager"; Loading Loading @@ -161,7 +162,7 @@ public class BluetoothPbapVcardManager { } } public final int getContactsSize() { public final int getContactsSize() { final Uri myUri = getPhoneUri(); final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); Cursor contactCursor = null; Cursor contactCursor = null; try { try { contactCursor = mResolver.query(myUri, new String[] {Phone.CONTACT_ID}, contactCursor = mResolver.query(myUri, new String[] {Phone.CONTACT_ID}, Loading Loading @@ -258,7 +259,7 @@ public class BluetoothPbapVcardManager { nameList.add(ownerName); nameList.add(ownerName); //End enhancement //End enhancement final Uri myUri = getPhoneUri(); final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); Cursor contactCursor = null; Cursor contactCursor = null; try { try { contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE, contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE, Loading Loading @@ -295,7 +296,7 @@ public class BluetoothPbapVcardManager { String[] projection = null; String[] projection = null; if (TextUtils.isEmpty(phoneNumber)) { if (TextUtils.isEmpty(phoneNumber)) { uri = getPhoneUri(); uri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); projection = PHONES_CONTACTS_PROJECTION; projection = PHONES_CONTACTS_PROJECTION; } else { } else { uri = Uri.withAppendedPath(getPhoneLookupFilterUri(), uri = Uri.withAppendedPath(getPhoneLookupFilterUri(), Loading Loading @@ -412,7 +413,7 @@ public class BluetoothPbapVcardManager { Phone.CONTACT_ID Phone.CONTACT_ID }); }); final Uri myUri = getPhoneUri(); final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); Cursor contactCursor = null; Cursor contactCursor = null; try { try { contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE, contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE, Loading Loading @@ -454,7 +455,7 @@ public class BluetoothPbapVcardManager { Log.e(TAG, "Internal error: offset is not correct."); Log.e(TAG, "Internal error: offset is not correct."); return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } } final Uri myUri = getPhoneUri(); final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); Cursor contactCursor = null; Cursor contactCursor = null; try { try { contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, Loading Loading @@ -812,10 +813,6 @@ public class BluetoothPbapVcardManager { } } } } private static final Uri getPhoneUri() { return Phone.ENTERPRISE_CONTENT_URI; } private static final Uri getPhoneLookupFilterUri() { private static final Uri getPhoneLookupFilterUri() { return PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI; return PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI; } } Loading android/app/src/com/android/bluetooth/util/DevicePolicyUtils.java 0 → 100644 +55 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package com.android.bluetooth.util; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.content.pm.UserInfo; import android.net.Uri; import android.os.UserHandle; import android.os.UserManager; import android.provider.ContactsContract.CommonDataKinds.Phone; import java.util.List; public final class DevicePolicyUtils { private static boolean isBluetoothWorkContactSharingDisabled(Context context) { final DevicePolicyManager dpm = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); final UserManager userManager = (UserManager) context .getSystemService(Context.USER_SERVICE); final int myUserId = UserHandle.myUserId(); final List<UserInfo> userInfoList = userManager.getProfiles(myUserId); // Check each user. for (UserInfo ui : userInfoList) { if (!ui.isManagedProfile()) { continue; // Not a managed user. } return dpm.getBluetoothContactSharingDisabled(new UserHandle(ui.id)); } // No managed profile, so this feature is disabled return true; } // Now we support getBluetoothContactSharingDisabled() for managed profile only // TODO: Make primary profile can also support getBluetoothContactSharingDisabled() public static Uri getEnterprisePhoneUri(Context context) { return isBluetoothWorkContactSharingDisabled(context) ? Phone.CONTENT_URI : Phone.ENTERPRISE_CONTENT_URI; } } Loading
android/app/src/com/android/bluetooth/hfp/AtPhonebook.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.telephony.PhoneNumberUtils; import android.util.Log; import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.Utils; import com.android.bluetooth.util.DevicePolicyUtils; import java.util.HashMap; import java.util.HashMap; Loading Loading @@ -429,7 +430,8 @@ public class AtPhonebook { pbr.typeColumn = -1; pbr.typeColumn = -1; pbr.nameColumn = -1; pbr.nameColumn = -1; } else { } else { pbr.cursor = mContentResolver.query(Phone.ENTERPRISE_CONTENT_URI, PHONES_PROJECTION, final Uri phoneContentUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); pbr.cursor = mContentResolver.query(phoneContentUri, PHONES_PROJECTION, where, null, Phone.NUMBER + " LIMIT " + MAX_PHONEBOOK_SIZE); where, null, Phone.NUMBER + " LIMIT " + MAX_PHONEBOOK_SIZE); if (pbr.cursor == null) return false; if (pbr.cursor == null) return false; Loading
android/app/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java +6 −9 Original line number Original line Diff line number Diff line Loading @@ -67,6 +67,7 @@ import javax.obex.Operation; import javax.obex.ResponseCodes; import javax.obex.ResponseCodes; import com.android.bluetooth.Utils; import com.android.bluetooth.Utils; import com.android.bluetooth.util.DevicePolicyUtils; public class BluetoothPbapVcardManager { public class BluetoothPbapVcardManager { private static final String TAG = "BluetoothPbapVcardManager"; private static final String TAG = "BluetoothPbapVcardManager"; Loading Loading @@ -161,7 +162,7 @@ public class BluetoothPbapVcardManager { } } public final int getContactsSize() { public final int getContactsSize() { final Uri myUri = getPhoneUri(); final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); Cursor contactCursor = null; Cursor contactCursor = null; try { try { contactCursor = mResolver.query(myUri, new String[] {Phone.CONTACT_ID}, contactCursor = mResolver.query(myUri, new String[] {Phone.CONTACT_ID}, Loading Loading @@ -258,7 +259,7 @@ public class BluetoothPbapVcardManager { nameList.add(ownerName); nameList.add(ownerName); //End enhancement //End enhancement final Uri myUri = getPhoneUri(); final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); Cursor contactCursor = null; Cursor contactCursor = null; try { try { contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE, contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE, Loading Loading @@ -295,7 +296,7 @@ public class BluetoothPbapVcardManager { String[] projection = null; String[] projection = null; if (TextUtils.isEmpty(phoneNumber)) { if (TextUtils.isEmpty(phoneNumber)) { uri = getPhoneUri(); uri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); projection = PHONES_CONTACTS_PROJECTION; projection = PHONES_CONTACTS_PROJECTION; } else { } else { uri = Uri.withAppendedPath(getPhoneLookupFilterUri(), uri = Uri.withAppendedPath(getPhoneLookupFilterUri(), Loading Loading @@ -412,7 +413,7 @@ public class BluetoothPbapVcardManager { Phone.CONTACT_ID Phone.CONTACT_ID }); }); final Uri myUri = getPhoneUri(); final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); Cursor contactCursor = null; Cursor contactCursor = null; try { try { contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE, contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, CLAUSE_ONLY_VISIBLE, Loading Loading @@ -454,7 +455,7 @@ public class BluetoothPbapVcardManager { Log.e(TAG, "Internal error: offset is not correct."); Log.e(TAG, "Internal error: offset is not correct."); return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; return ResponseCodes.OBEX_HTTP_INTERNAL_ERROR; } } final Uri myUri = getPhoneUri(); final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); Cursor contactCursor = null; Cursor contactCursor = null; try { try { contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, Loading Loading @@ -812,10 +813,6 @@ public class BluetoothPbapVcardManager { } } } } private static final Uri getPhoneUri() { return Phone.ENTERPRISE_CONTENT_URI; } private static final Uri getPhoneLookupFilterUri() { private static final Uri getPhoneLookupFilterUri() { return PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI; return PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI; } } Loading
android/app/src/com/android/bluetooth/util/DevicePolicyUtils.java 0 → 100644 +55 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package com.android.bluetooth.util; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.content.pm.UserInfo; import android.net.Uri; import android.os.UserHandle; import android.os.UserManager; import android.provider.ContactsContract.CommonDataKinds.Phone; import java.util.List; public final class DevicePolicyUtils { private static boolean isBluetoothWorkContactSharingDisabled(Context context) { final DevicePolicyManager dpm = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); final UserManager userManager = (UserManager) context .getSystemService(Context.USER_SERVICE); final int myUserId = UserHandle.myUserId(); final List<UserInfo> userInfoList = userManager.getProfiles(myUserId); // Check each user. for (UserInfo ui : userInfoList) { if (!ui.isManagedProfile()) { continue; // Not a managed user. } return dpm.getBluetoothContactSharingDisabled(new UserHandle(ui.id)); } // No managed profile, so this feature is disabled return true; } // Now we support getBluetoothContactSharingDisabled() for managed profile only // TODO: Make primary profile can also support getBluetoothContactSharingDisabled() public static Uri getEnterprisePhoneUri(Context context) { return isBluetoothWorkContactSharingDisabled(context) ? Phone.CONTENT_URI : Phone.ENTERPRISE_CONTENT_URI; } }