blob: 17f5f5e78571563501154af4d9538a1e26485e1f [file] [log] [blame]
Marcus Hagerottfac695a2016-08-24 17:02:40 -07001/*
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 */
16package com.android.contacts.common.model;
17
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070018import android.content.Context;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070019
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070020import com.android.contacts.common.Experiments;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070021import com.android.contacts.common.model.account.AccountWithDataSet;
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070022import com.android.contactsbind.ObjectFactory;
23import com.android.contactsbind.experiments.Flags;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070024
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070025import java.util.Collections;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070026import java.util.List;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070027
28/**
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070029 * Attempts to detect accounts for device contacts
Marcus Hagerottfac695a2016-08-24 17:02:40 -070030 */
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070031public abstract class DeviceLocalAccountLocator {
Marcus Hagerottfac695a2016-08-24 17:02:40 -070032
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070033 /**
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 Hagerottfac695a2016-08-24 17:02:40 -070045 };
46
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070047 public static DeviceLocalAccountLocator create(Context context,
Marcus Hagerottfac695a2016-08-24 17:02:40 -070048 List<AccountWithDataSet> knownAccounts) {
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070049 if (Flags.getInstance().getBoolean(Experiments.OEM_CP2_DEVICE_ACCOUNT_DETECTION_ENABLED)) {
50 return new Cp2DeviceLocalAccountLocator(context.getContentResolver(),
51 ObjectFactory.getDeviceLocalAccountTypeFactory(context), knownAccounts);
Marcus Hagerottfac695a2016-08-24 17:02:40 -070052 }
Marcus Hagerott7a756ab2016-11-01 18:16:02 -070053 return NULL_ONLY;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070054 }
55}