1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.bluetooth.util; 18 19 import android.app.admin.DevicePolicyManager; 20 import android.content.Context; 21 import android.net.Uri; 22 import android.os.UserHandle; 23 import android.os.UserManager; 24 import android.provider.ContactsContract.CommonDataKinds.Phone; 25 26 import java.util.List; 27 28 public final class DevicePolicyUtils { isBluetoothWorkContactSharingDisabled(Context context)29 private static boolean isBluetoothWorkContactSharingDisabled(Context context) { 30 final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); 31 final UserManager userManager = context.getSystemService(UserManager.class); 32 final List<UserHandle> userHandleList = userManager.getAllProfiles(); 33 34 // Check each user. 35 for (UserHandle uh : userHandleList) { 36 if (!userManager.isManagedProfile(uh.getIdentifier())) { 37 continue; // Not a managed user. 38 } 39 return dpm.getBluetoothContactSharingDisabled(uh); 40 } 41 // No managed profile, so this feature is disabled 42 return true; 43 } 44 45 /** 46 * Returns a URI to query all phones on the device. If a managed profile exists and the policy 47 * allows, it will be a URI that supports the managed profile. 48 */ 49 // TODO: Make primary profile can also support getBluetoothContactSharingDisabled() getEnterprisePhoneUri(Context context)50 public static Uri getEnterprisePhoneUri(Context context) { 51 return isBluetoothWorkContactSharingDisabled(context) 52 ? Phone.CONTENT_URI 53 : Phone.ENTERPRISE_CONTENT_URI; 54 } 55 } 56