1/*
2 * Copyright (C) 2009 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
17package android.content;
18
19import android.accounts.Account;
20import android.content.ComponentName;
21import android.content.SyncInfo;
22import android.content.ISyncStatusObserver;
23import android.content.SyncAdapterType;
24import android.content.SyncRequest;
25import android.content.SyncStatusInfo;
26import android.content.PeriodicSync;
27import android.net.Uri;
28import android.os.Bundle;
29import android.database.IContentObserver;
30
31/**
32 * @hide
33 */
34interface IContentService {
35    void unregisterContentObserver(IContentObserver observer);
36
37    /**
38     * Register a content observer tied to a specific user's view of the provider.
39     * @param userHandle the user whose view of the provider is to be observed.  May be
40     *     the calling user without requiring any permission, otherwise the caller needs to
41     *     hold the INTERACT_ACROSS_USERS_FULL permission.  Pseudousers USER_ALL and
42     *     USER_CURRENT are properly handled.
43     */
44    void registerContentObserver(in Uri uri, boolean notifyForDescendants,
45            IContentObserver observer, int userHandle);
46
47    /**
48     * Notify observers of a particular user's view of the provider.
49     * @param userHandle the user whose view of the provider is to be notified.  May be
50     *     the calling user without requiring any permission, otherwise the caller needs to
51     *     hold the INTERACT_ACROSS_USERS_FULL permission.  Pseudousers USER_ALL
52     *     USER_CURRENT are properly interpreted.
53     */
54    void notifyChange(in Uri uri, IContentObserver observer,
55            boolean observerWantsSelfNotifications, boolean syncToNetwork,
56            int userHandle);
57
58    void requestSync(in Account account, String authority, in Bundle extras);
59    /**
60     * Start a sync given a request.
61     */
62    void sync(in SyncRequest request);
63    void syncAsUser(in SyncRequest request, int userId);
64    void cancelSync(in Account account, String authority, in ComponentName cname);
65    void cancelSyncAsUser(in Account account, String authority, in ComponentName cname, int userId);
66
67    /** Cancel a sync, providing information about the sync to be cancelled. */
68     void cancelRequest(in SyncRequest request);
69
70    /**
71     * Check if the provider should be synced when a network tickle is received
72     * @param providerName the provider whose setting we are querying
73     * @return true if the provider should be synced when a network tickle is received
74     */
75    boolean getSyncAutomatically(in Account account, String providerName);
76    boolean getSyncAutomaticallyAsUser(in Account account, String providerName, int userId);
77
78    /**
79     * Set whether or not the provider is synced when it receives a network tickle.
80     *
81     * @param providerName the provider whose behavior is being controlled
82     * @param sync true if the provider should be synced when tickles are received for it
83     */
84    void setSyncAutomatically(in Account account, String providerName, boolean sync);
85    void setSyncAutomaticallyAsUser(in Account account, String providerName, boolean sync,
86            int userId);
87
88    /**
89     * Get a list of periodic operations for a specified authority, or service.
90     * @param account account for authority, must be null if cname is non-null.
91     * @param providerName name of provider, must be null if cname is non-null.
92     * @param cname component to identify sync service, must be null if account/providerName are
93     * non-null.
94     */
95    List<PeriodicSync> getPeriodicSyncs(in Account account, String providerName,
96        in ComponentName cname);
97
98    /**
99     * Set whether or not the provider is to be synced on a periodic basis.
100     *
101     * @param providerName the provider whose behavior is being controlled
102     * @param pollFrequency the period that a sync should be performed, in seconds. If this is
103     * zero or less then no periodic syncs will be performed.
104     */
105    void addPeriodicSync(in Account account, String providerName, in Bundle extras,
106      long pollFrequency);
107
108    /**
109     * Set whether or not the provider is to be synced on a periodic basis.
110     *
111     * @param providerName the provider whose behavior is being controlled
112     * @param pollFrequency the period that a sync should be performed, in seconds. If this is
113     * zero or less then no periodic syncs will be performed.
114     */
115    void removePeriodicSync(in Account account, String providerName, in Bundle extras);
116
117    /**
118     * Check if this account/provider is syncable.
119     * @return >0 if it is syncable, 0 if not, and <0 if the state isn't known yet.
120     */
121    int getIsSyncable(in Account account, String providerName);
122    int getIsSyncableAsUser(in Account account, String providerName, int userId);
123
124    /**
125     * Set whether this account/provider is syncable.
126     * @param syncable, >0 denotes syncable, 0 means not syncable, <0 means unknown
127     */
128    void setIsSyncable(in Account account, String providerName, int syncable);
129
130    void setMasterSyncAutomatically(boolean flag);
131    void setMasterSyncAutomaticallyAsUser(boolean flag, int userId);
132
133    boolean getMasterSyncAutomatically();
134    boolean getMasterSyncAutomaticallyAsUser(int userId);
135
136    List<SyncInfo> getCurrentSyncs();
137    List<SyncInfo> getCurrentSyncsAsUser(int userId);
138
139    /**
140     * Returns the types of the SyncAdapters that are registered with the system.
141     * @return Returns the types of the SyncAdapters that are registered with the system.
142     */
143    SyncAdapterType[] getSyncAdapterTypes();
144    SyncAdapterType[] getSyncAdapterTypesAsUser(int userId);
145
146    /**
147     * Returns true if there is currently a operation for the given account/authority or service
148     * actively being processed.
149     * @param account account for authority, must be null if cname is non-null.
150     * @param providerName name of provider, must be null if cname is non-null.
151     * @param cname component to identify sync service, must be null if account/providerName are
152     * non-null.
153     */
154    boolean isSyncActive(in Account account, String authority, in ComponentName cname);
155
156    /**
157     * Returns the status that matches the authority. If there are multiples accounts for
158     * the authority, the one with the latest "lastSuccessTime" status is returned.
159     * @param account account for authority, must be null if cname is non-null.
160     * @param providerName name of provider, must be null if cname is non-null.
161     * @param cname component to identify sync service, must be null if account/providerName are
162     * non-null.
163     */
164    SyncStatusInfo getSyncStatus(in Account account, String authority, in ComponentName cname);
165    SyncStatusInfo getSyncStatusAsUser(in Account account, String authority, in ComponentName cname,
166            int userId);
167
168    /**
169     * Return true if the pending status is true of any matching authorities.
170     * @param account account for authority, must be null if cname is non-null.
171     * @param providerName name of provider, must be null if cname is non-null.
172     * @param cname component to identify sync service, must be null if account/providerName are
173     * non-null.
174     */
175    boolean isSyncPending(in Account account, String authority, in ComponentName cname);
176    boolean isSyncPendingAsUser(in Account account, String authority, in ComponentName cname,
177            int userId);
178
179    void addStatusChangeListener(int mask, ISyncStatusObserver callback);
180
181    void removeStatusChangeListener(ISyncStatusObserver callback);
182}
183