1bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling/*
2bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * Copyright (C) 2016 The Android Open Source Project
3bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling *
4bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * Licensed under the Apache License, Version 2.0 (the "License");
5bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * you may not use this file except in compliance with the License.
6bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * You may obtain a copy of the License at
7bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling *
8bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling *      http://www.apache.org/licenses/LICENSE-2.0
9bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling *
10bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * Unless required by applicable law or agreed to in writing, software
11bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * distributed under the License is distributed on an "AS IS" BASIS,
12bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * See the License for the specific language governing permissions and
14bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling * limitations under the License.
15bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling */
16bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling
17bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Lingpackage com.android.settings.testutils.shadow;
18bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling
19771848dde0d2960b8ec7d359090ba5106d6bb727Doris Lingimport android.accounts.Account;
20bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Lingimport android.content.ContentResolver;
21bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Lingimport android.content.SyncAdapterType;
22bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling
234f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritzeimport android.database.Cursor;
244f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritzeimport android.database.MatrixCursor;
254f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritzeimport android.net.Uri;
264f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritzeimport android.provider.SearchIndexablesContract;
27bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Lingimport org.robolectric.annotation.Implementation;
28bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Lingimport org.robolectric.annotation.Implements;
2922a39c2b93bc66db71238274a7683d329232d124James Lemieuximport org.robolectric.annotation.Resetter;
30bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling
314f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritzeimport static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
324f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze
33771848dde0d2960b8ec7d359090ba5106d6bb727Doris Lingimport java.util.HashMap;
34771848dde0d2960b8ec7d359090ba5106d6bb727Doris Lingimport java.util.Map;
35771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
36bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling@Implements(ContentResolver.class)
37bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Lingpublic class ShadowContentResolver {
38bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling
39771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    private static SyncAdapterType[] sSyncAdapterTypes = new SyncAdapterType[0];
40771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    private static Map<String, Integer> sSyncable = new HashMap<>();
41771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    private static Map<String, Boolean> sSyncAutomatically = new HashMap<>();
42771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    private static Map<Integer, Boolean> sMasterSyncAutomatically = new HashMap<>();
43771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
44bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling    @Implementation
45bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling    public static SyncAdapterType[] getSyncAdapterTypesAsUser(int userId) {
46771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        return sSyncAdapterTypes;
47bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling    }
484f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze
494f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze    @Implementation
504f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze    public final Cursor query(Uri uri, String[] projection, String selection,
514f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze            String[] selectionArgs, String sortOrder) {
524f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze        MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
534f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze        MatrixCursor.RowBuilder builder = cursor.newRow()
544f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze                .add(SearchIndexablesContract.NonIndexableKey.COLUMN_KEY_VALUE, "");
554f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze        return cursor;
564f198813ed0d513ddb1461315bae1c881904ebf0Matthew Fritze    }
57771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
58771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    @Implementation
59771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    public static int getIsSyncableAsUser(Account account, String authority, int userId) {
60771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        return sSyncable.containsKey(authority) ? sSyncable.get(authority) : 1;
61771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    }
62771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
63771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    @Implementation
64771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    public static boolean getSyncAutomaticallyAsUser(Account account, String authority,
65771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling            int userId) {
66771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        return sSyncAutomatically.containsKey(authority) ? sSyncAutomatically.get(authority) : true;
67771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    }
68771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
69771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    @Implementation
70771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    public static boolean getMasterSyncAutomaticallyAsUser(int userId) {
71771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        return sMasterSyncAutomatically.containsKey(userId)
72771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling                ? sMasterSyncAutomatically.get(userId) : true;
73771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    }
74771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
75771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    public static void setSyncAdapterTypes(SyncAdapterType[] syncAdapterTypes) {
76771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        sSyncAdapterTypes = syncAdapterTypes;
77771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    }
78771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
79771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    public static void setSyncable(String authority, int syncable) {
80771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        sSyncable.put(authority, syncable);
81771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    }
82771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
83771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    public static void setSyncAutomatically(String authority, boolean syncAutomatically) {
84771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        sSyncAutomatically.put(authority, syncAutomatically);
85771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    }
86771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
87771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    public static void setMasterSyncAutomatically(int userId, boolean syncAutomatically) {
88771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        sMasterSyncAutomatically.put(userId, syncAutomatically);
89771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    }
90771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling
91771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    public static void reset() {
92771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        sSyncable.clear();
93771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        sSyncAutomatically.clear();
94771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        sMasterSyncAutomatically.clear();
95771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling        sSyncAdapterTypes = new SyncAdapterType[0];
96771848dde0d2960b8ec7d359090ba5106d6bb727Doris Ling    }
97bfac31b517e1fa2f217fe932192ecd0c57b33525Doris Ling}
98