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.content.pm.UserInfo;
22 import android.net.Uri;
23 import android.os.UserHandle;
24 import android.os.UserManager;
25 import android.provider.ContactsContract.CommonDataKinds.Phone;
26 
27 import java.util.List;
28 
29 public final class DevicePolicyUtils {
isBluetoothWorkContactSharingDisabled(Context context)30     private static boolean isBluetoothWorkContactSharingDisabled(Context context) {
31         final DevicePolicyManager dpm = (DevicePolicyManager) context
32                 .getSystemService(Context.DEVICE_POLICY_SERVICE);
33         final UserManager userManager = (UserManager) context
34                 .getSystemService(Context.USER_SERVICE);
35         final int myUserId = UserHandle.myUserId();
36         final List<UserInfo> userInfoList = userManager.getProfiles(myUserId);
37 
38         // Check each user.
39         for (UserInfo ui : userInfoList) {
40             if (!ui.isManagedProfile()) {
41                 continue; // Not a managed user.
42             }
43             return dpm.getBluetoothContactSharingDisabled(new UserHandle(ui.id));
44         }
45         // No managed profile, so this feature is disabled
46         return true;
47     }
48 
49     // Now we support getBluetoothContactSharingDisabled() for managed profile only
50     // TODO: Make primary profile can also support getBluetoothContactSharingDisabled()
getEnterprisePhoneUri(Context context)51     public static Uri getEnterprisePhoneUri(Context context) {
52         return isBluetoothWorkContactSharingDisabled(context) ? Phone.CONTENT_URI
53                 : Phone.ENTERPRISE_CONTENT_URI;
54     }
55 }
56