Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | package com.android.contacts.common.model; |
| 17 | |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 18 | import android.content.Context; |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 19 | |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 20 | import com.android.contacts.common.Experiments; |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 21 | import com.android.contacts.common.model.account.AccountWithDataSet; |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 22 | import com.android.contactsbind.ObjectFactory; |
| 23 | import com.android.contactsbind.experiments.Flags; |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 24 | |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 25 | import java.util.Collections; |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 26 | import java.util.List; |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 29 | * Attempts to detect accounts for device contacts |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 30 | */ |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 31 | public abstract class DeviceLocalAccountLocator { |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 32 | |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Returns a list of device local accounts |
| 35 | */ |
| 36 | public abstract List<AccountWithDataSet> getDeviceLocalAccounts(); |
| 37 | |
| 38 | // This works on Nexus and AOSP because the local device account is the null account but most |
| 39 | // OEMs have a special account name and type for their device account. |
| 40 | public static final DeviceLocalAccountLocator NULL_ONLY = new DeviceLocalAccountLocator() { |
| 41 | @Override |
| 42 | public List<AccountWithDataSet> getDeviceLocalAccounts() { |
| 43 | return Collections.singletonList(AccountWithDataSet.getNullAccount()); |
| 44 | } |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 47 | public static DeviceLocalAccountLocator create(Context context, |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 48 | List<AccountWithDataSet> knownAccounts) { |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 49 | if (Flags.getInstance().getBoolean(Experiments.OEM_CP2_DEVICE_ACCOUNT_DETECTION_ENABLED)) { |
| 50 | return new Cp2DeviceLocalAccountLocator(context.getContentResolver(), |
| 51 | ObjectFactory.getDeviceLocalAccountTypeFactory(context), knownAccounts); |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 52 | } |
Marcus Hagerott | 7a756ab | 2016-11-01 18:16:02 -0700 | [diff] [blame] | 53 | return NULL_ONLY; |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 54 | } |
| 55 | } |