1 /* 2 * Copyright (C) 2021 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.settings.enterprise; 18 19 import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED; 20 21 import android.app.admin.DevicePolicyManager; 22 import android.content.Context; 23 24 /** Factory for creating the privacy settings preference for a managed device. */ 25 public class PrivacySettingsPreferenceFactory { 26 27 /** 28 * Determines which preference to use in the Privacy Settings based off of the type of managed 29 * device. 30 */ createPrivacySettingsPreference(Context context)31 public static PrivacySettingsPreference createPrivacySettingsPreference(Context context) { 32 if (isFinancedDevice(context)) { 33 return createPrivacySettingsFinancedPreference(context); 34 } else { 35 return createPrivacySettingsEnterprisePreference(context); 36 } 37 } 38 createPrivacySettingsEnterprisePreference( Context context)39 private static PrivacySettingsEnterprisePreference createPrivacySettingsEnterprisePreference( 40 Context context) { 41 return new PrivacySettingsEnterprisePreference(context); 42 } 43 createPrivacySettingsFinancedPreference( Context context)44 private static PrivacySettingsFinancedPreference createPrivacySettingsFinancedPreference( 45 Context context) { 46 return new PrivacySettingsFinancedPreference(context); 47 } 48 isFinancedDevice(Context context)49 private static boolean isFinancedDevice(Context context) { 50 final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class); 51 return dpm.isDeviceManaged() && dpm.getDeviceOwnerType( 52 dpm.getDeviceOwnerComponentOnAnyUser()) == DEVICE_OWNER_TYPE_FINANCED; 53 } 54 } 55