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