Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac9385ef authored by Fred Quintana's avatar Fred Quintana
Browse files

- clean up the sync settings names to:

   (get|set)SyncAutomatically
   (get|set)MasterSyncAutomatically
- change SYNC_EXTRAS_FORCE to SYNC_EXTRAS_MANUAL to mace clear that
  this overrides the .*SyncAutomatically settings
- make ContentResolver methods that call the sync controls methods
  in IContentService so that SDK users can use them
- rename startSync to requestSync to reinforce the fact that a sync
  is not immediately or always started when this method is called
- add an Account parameter to all the sync settings and control methods
- change the sync control methods to take a String authority rather than a Uri uri
parent f86a58ff
Loading
Loading
Loading
Loading
+241 −4
Original line number Diff line number Diff line
@@ -29249,6 +29249,21 @@
<parameter name="name" type="java.lang.String">
</parameter>
</method>
<method name="addStatusChangeListener"
 return="java.lang.Object"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="mask" type="int">
</parameter>
<parameter name="callback" type="android.content.SyncStatusObserver">
</parameter>
</method>
<method name="applyBatch"
 return="android.content.ContentProviderResult[]"
 abstract="false"
@@ -29290,12 +29305,27 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="uri" type="android.net.Uri">
</parameter>
</method>
<method name="cancelSync"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="account" type="android.accounts.Account">
</parameter>
<parameter name="authority" type="java.lang.String">
</parameter>
</method>
<method name="delete"
 return="int"
 abstract="false"
@@ -29313,6 +29343,43 @@
<parameter name="selectionArgs" type="java.lang.String[]">
</parameter>
</method>
<method name="getMasterSyncAutomatically"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getSyncAdapterTypes"
 return="android.content.SyncAdapterType[]"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getSyncAutomatically"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="account" type="android.accounts.Account">
</parameter>
<parameter name="authority" type="java.lang.String">
</parameter>
</method>
<method name="getType"
 return="java.lang.String"
 abstract="false"
@@ -29341,6 +29408,36 @@
<parameter name="values" type="android.content.ContentValues">
</parameter>
</method>
<method name="isSyncActive"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="account" type="android.accounts.Account">
</parameter>
<parameter name="authority" type="java.lang.String">
</parameter>
</method>
<method name="isSyncPending"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="account" type="android.accounts.Account">
</parameter>
<parameter name="authority" type="java.lang.String">
</parameter>
</method>
<method name="notifyChange"
 return="void"
 abstract="false"
@@ -29513,6 +29610,66 @@
<parameter name="observer" type="android.database.ContentObserver">
</parameter>
</method>
<method name="removeStatusChangeListener"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="handle" type="java.lang.Object">
</parameter>
</method>
<method name="requestSync"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="account" type="android.accounts.Account">
</parameter>
<parameter name="authority" type="java.lang.String">
</parameter>
<parameter name="extras" type="android.os.Bundle">
</parameter>
</method>
<method name="setMasterSyncAutomatically"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="sync" type="boolean">
</parameter>
</method>
<method name="setSyncAutomatically"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="account" type="android.accounts.Account">
</parameter>
<parameter name="authority" type="java.lang.String">
</parameter>
<parameter name="sync" type="boolean">
</parameter>
</method>
<method name="startSync"
 return="void"
 abstract="false"
@@ -29520,7 +29677,7 @@
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="uri" type="android.net.Uri">
@@ -29635,7 +29792,7 @@
 value="&quot;account&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
</field>
@@ -29662,6 +29819,17 @@
>
</field>
<field name="SYNC_EXTRAS_FORCE"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;force&quot;"
 static="true"
 final="true"
 deprecated="deprecated"
 visibility="public"
>
</field>
<field name="SYNC_EXTRAS_MANUAL"
 type="java.lang.String"
 transient="false"
 volatile="false"
@@ -37903,6 +38071,8 @@
 deprecated="not deprecated"
 visibility="public"
>
<implements name="android.os.Parcelable">
</implements>
<constructor name="SyncAdapterType"
 type="android.content.SyncAdapterType"
 static="false"
@@ -37915,6 +38085,52 @@
<parameter name="accountType" type="java.lang.String">
</parameter>
</constructor>
<constructor name="SyncAdapterType"
 type="android.content.SyncAdapterType"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="source" type="android.os.Parcel">
</parameter>
</constructor>
<method name="describeContents"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="writeToParcel"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="dest" type="android.os.Parcel">
</parameter>
<parameter name="flags" type="int">
</parameter>
</method>
<field name="CREATOR"
 type="android.os.Parcelable.Creator"
 transient="false"
 volatile="false"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="accountType"
 type="java.lang.String"
 transient="false"
@@ -37936,6 +38152,27 @@
>
</field>
</class>
<interface name="SyncStatusObserver"
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="onStatusChanged"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="which" type="int">
</parameter>
</method>
</interface>
<class name="UriMatcher"
 extends="java.lang.Object"
 abstract="false"
@@ -117418,7 +117655,7 @@
>
<parameter name="uri" type="android.net.Uri">
</parameter>
<parameter name="account" type="java.lang.String">
<parameter name="accountName" type="java.lang.String">
</parameter>
<parameter name="authority" type="java.lang.String">
</parameter>
+2 −1
Original line number Diff line number Diff line
@@ -141,7 +141,8 @@ public abstract class AbstractSyncableContentProvider extends SyncableContentPro
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            if (!upgradeDatabase(db, oldVersion, newVersion)) {
                mSyncState.discardSyncData(db, null /* all accounts */);
                getContext().getContentResolver().startSync(mContentUri, new Bundle());
                ContentResolver.requestSync(null /* all accounts */,
                        mContentUri.getAuthority(), new Bundle());
            }
        }

+245 −4
Original line number Diff line number Diff line
@@ -48,9 +48,18 @@ import java.util.ArrayList;
 * This class provides applications access to the content model.
 */
public abstract class ContentResolver {
    public final static String SYNC_EXTRAS_ACCOUNT = "account";
    /**
     * @deprecated instead use
     * {@link #requestSync(android.accounts.Account, String, android.os.Bundle)}
     */
    public static final String SYNC_EXTRAS_ACCOUNT = "account";
    public static final String SYNC_EXTRAS_EXPEDITED = "expedited";
    /**
     * @deprecated instead use
     * {@link #SYNC_EXTRAS_MANUAL}
     */
    public static final String SYNC_EXTRAS_FORCE = "force";
    public static final String SYNC_EXTRAS_MANUAL = "force";
    public static final String SYNC_EXTRAS_UPLOAD = "upload";
    public static final String SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS = "deletions_override";
    public static final String SYNC_EXTRAS_DISCARD_LOCAL_DELETIONS = "discard_deletions";
@@ -91,6 +100,34 @@ public abstract class ContentResolver {
     */
    public static final String CURSOR_DIR_BASE_TYPE = "vnd.android.cursor.dir";

    /** @hide */
    public static final int SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS = 1;
    /** @hide */
    public static final int SYNC_ERROR_AUTHENTICATION = 2;
    /** @hide */
    public static final int SYNC_ERROR_IO = 3;
    /** @hide */
    public static final int SYNC_ERROR_PARSE = 4;
    /** @hide */
    public static final int SYNC_ERROR_CONFLICT = 5;
    /** @hide */
    public static final int SYNC_ERROR_TOO_MANY_DELETIONS = 6;
    /** @hide */
    public static final int SYNC_ERROR_TOO_MANY_RETRIES = 7;
    /** @hide */
    public static final int SYNC_ERROR_INTERNAL = 8;

    /** @hide */
    public static final int SYNC_OBSERVER_TYPE_SETTINGS = 1<<0;
    /** @hide */
    public static final int SYNC_OBSERVER_TYPE_PENDING = 1<<1;
    /** @hide */
    public static final int SYNC_OBSERVER_TYPE_ACTIVE = 1<<2;
    /** @hide */
    public static final int SYNC_OBSERVER_TYPE_STATUS = 1<<3;
    /** @hide */
    public static final int SYNC_OBSERVER_TYPE_ALL = 0x7fffffff;

    public ContentResolver(Context context) {
        mContext = context;
    }
@@ -829,11 +866,42 @@ public abstract class ContentResolver {
     *
     * @param uri the uri of the provider to sync or null to sync all providers.
     * @param extras any extras to pass to the SyncAdapter.
     * @deprecated instead use
     * {@link #requestSync(android.accounts.Account, String, android.os.Bundle)}
     */
    public void startSync(Uri uri, Bundle extras) {
        Account account = null;
        if (extras != null) {
            String accountName = extras.getString(SYNC_EXTRAS_ACCOUNT);
            if (!TextUtils.isEmpty(accountName)) {
                account = new Account(accountName, "com.google.GAIA");
            }
            extras.remove(SYNC_EXTRAS_ACCOUNT);
        }
        requestSync(account, uri != null ? uri.getAuthority() : null, extras);
    }

    /**
     * Start an asynchronous sync operation. If you want to monitor the progress
     * of the sync you may register a SyncObserver. Only values of the following
     * types may be used in the extras bundle:
     * <ul>
     * <li>Integer</li>
     * <li>Long</li>
     * <li>Boolean</li>
     * <li>Float</li>
     * <li>Double</li>
     * <li>String</li>
     * </ul>
     *
     * @param account which account should be synced
     * @param authority which authority should be synced
     * @param extras any extras to pass to the SyncAdapter.
     */
    public static void requestSync(Account account, String authority, Bundle extras) {
        validateSyncExtrasBundle(extras);
        try {
            getContentService().startSync(uri, extras);
            getContentService().requestSync(account, authority, extras);
        } catch (RemoteException e) {
        }
    }
@@ -874,13 +942,186 @@ public abstract class ContentResolver {
        }
    }

    /**
     * Cancel any active or pending syncs that match the Uri. If the uri is null then
     * all syncs will be canceled.
     *
     * @param uri the uri of the provider to sync or null to sync all providers.
     * @deprecated instead use {@link #cancelSync(android.accounts.Account, String)}
     */
    public void cancelSync(Uri uri) {
        cancelSync(null /* all accounts */, uri != null ? uri.getAuthority() : null);
    }

    /**
     * Cancel any active or pending syncs that match account and authority. The account and
     * authority can each independently be set to null, which means that syncs with any account
     * or authority, respectively, will match.
     *
     * @param account filters the syncs that match by this account
     * @param authority filters the syncs that match by this authority
     */
    public static void cancelSync(Account account, String authority) {
        try {
            getContentService().cancelSync(account, authority);
        } catch (RemoteException e) {
        }
    }

    /**
     * Get information about the SyncAdapters that are known to the system.
     * @return an array of SyncAdapters that have registered with the system
     */
    public static SyncAdapterType[] getSyncAdapterTypes() {
        try {
            return getContentService().getSyncAdapterTypes();
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * Check if the provider should be synced when a network tickle is received
     *
     * @param account the account whose setting we are querying
     * @param authority the provider whose setting we are querying
     * @return true if the provider should be synced when a network tickle is received
     */
    public static boolean getSyncAutomatically(Account account, String authority) {
        try {
            return getContentService().getSyncAutomatically(account, authority);
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * Set whether or not the provider is synced when it receives a network tickle.
     *
     * @param account the account whose setting we are querying
     * @param authority the provider whose behavior is being controlled
     * @param sync true if the provider should be synced when tickles are received for it
     */
    public static void setSyncAutomatically(Account account, String authority, boolean sync) {
        try {
            getContentService().setSyncAutomatically(account, authority, sync);
        } catch (RemoteException e) {
            // exception ignored; if this is thrown then it means the runtime is in the midst of
            // being restarted
        }
    }

    /**
     * Gets the master auto-sync setting that applies to all the providers and accounts.
     * If this is false then the per-provider auto-sync setting is ignored.
     *
     * @return the master auto-sync setting that applies to all the providers and accounts
     */
    public static boolean getMasterSyncAutomatically() {
        try {
            return getContentService().getMasterSyncAutomatically();
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * Sets the master auto-sync setting that applies to all the providers and accounts.
     * If this is false then the per-provider auto-sync setting is ignored.
     *
     * @param sync the master auto-sync setting that applies to all the providers and accounts
     */
    public static void setMasterSyncAutomatically(boolean sync) {
        try {
            getContentService().setMasterSyncAutomatically(sync);
        } catch (RemoteException e) {
            // exception ignored; if this is thrown then it means the runtime is in the midst of
            // being restarted
        }
    }

    /**
     * Returns true if there is currently a sync operation for the given
     * account or authority in the pending list, or actively being processed.
     * @param account the account whose setting we are querying
     * @param authority the provider whose behavior is being queried
     * @return true if a sync is active for the given account or authority.
     */
    public static boolean isSyncActive(Account account, String authority) {
        try {
            return getContentService().isSyncActive(account, authority);
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * If a sync is active returns the information about it, otherwise returns false.
     * @return the ActiveSyncInfo for the currently active sync or null if one is not active.
     * @hide
     */
    public static ActiveSyncInfo getActiveSync() {
        try {
            return getContentService().getActiveSync();
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * Returns the status that matches the authority. If there are multiples accounts for
     * the authority, the one with the latest "lastSuccessTime" status is returned.
     * @param account the account whose setting we are querying
     * @param authority the provider whose behavior is being queried
     * @return the SyncStatusInfo for the authority, or null if none exists
     * @hide
     */
    public static SyncStatusInfo getSyncStatus(Account account, String authority) {
        try {
            return getContentService().getSyncStatus(account, authority);
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * Return true if the pending status is true of any matching authorities.
     * @param account the account whose setting we are querying
     * @param authority the provider whose behavior is being queried
     * @return true if there is a pending sync with the matching account and authority
     */
    public static boolean isSyncPending(Account account, String authority) {
        try {
            return getContentService().isSyncPending(account, authority);
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    public static Object addStatusChangeListener(int mask, final SyncStatusObserver callback) {
        try {
            ISyncStatusObserver.Stub observer = new ISyncStatusObserver.Stub() {
                public void onStatusChanged(int which) throws RemoteException {
                    callback.onStatusChanged(which);
                }
            };
            getContentService().addStatusChangeListener(mask, observer);
            return observer;
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    public static void removeStatusChangeListener(Object handle) {
        try {
            getContentService().cancelSync(uri);
            getContentService().removeStatusChangeListener((ISyncStatusObserver.Stub) handle);
        } catch (RemoteException e) {
            // exception ignored; if this is thrown then it means the runtime is in the midst of
            // being restarted
        }
    }


    private final class CursorWrapperInner extends CursorWrapper {
        private IContentProvider mContentProvider;
        public static final String TAG="CursorWrapperInner";
+44 −27

File changed.

Preview size limit exceeded, changes collapsed.

+15 −8
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.content;
import android.accounts.Account;
import android.content.ActiveSyncInfo;
import android.content.ISyncStatusObserver;
import android.content.SyncAdapterType;
import android.content.SyncStatusInfo;
import android.net.Uri;
import android.os.Bundle;
@@ -35,15 +36,15 @@ interface IContentService {
    void notifyChange(in Uri uri, IContentObserver observer,
            boolean observerWantsSelfNotifications, boolean syncToNetwork);

    void startSync(in Uri url, in Bundle extras);
    void cancelSync(in Uri uri);
    void requestSync(in Account account, String authority, in Bundle extras);
    void cancelSync(in Account account, String authority);
    
    /**
     * Check if the provider should be synced when a network tickle is received
     * @param providerName the provider whose setting we are querying
     * @return true of the provider should be synced when a network tickle is received
     */
    boolean getSyncProviderAutomatically(String providerName);
    boolean getSyncAutomatically(in Account account, String providerName);

    /**
     * Set whether or not the provider is synced when it receives a network tickle.
@@ -51,11 +52,11 @@ interface IContentService {
     * @param providerName the provider whose behavior is being controlled
     * @param sync true if the provider should be synced when tickles are received for it
     */
    void setSyncProviderAutomatically(String providerName, boolean sync);
    void setSyncAutomatically(in Account account, String providerName, boolean sync);

    void setListenForNetworkTickles(boolean flag);
    void setMasterSyncAutomatically(boolean flag);

    boolean getListenForNetworkTickles();
    boolean getMasterSyncAutomatically();
    
    /**
     * Returns true if there is currently a sync operation for the given
@@ -65,18 +66,24 @@ interface IContentService {
    
    ActiveSyncInfo getActiveSync();
    
    /**
     * Returns the types of the SyncAdapters that are registered with the system.
     * @return Returns the types of the SyncAdapters that are registered with the system.
     */
    SyncAdapterType[] getSyncAdapterTypes();

    /**
     * Returns the status that matches the authority. If there are multiples accounts for
     * the authority, the one with the latest "lastSuccessTime" status is returned.
     * @param authority the authority whose row should be selected
     * @return the SyncStatusInfo for the authority, or null if none exists
     */
    SyncStatusInfo getStatusByAuthority(String authority);
    SyncStatusInfo getSyncStatus(in Account account, String authority);

    /**
     * Return true if the pending status is true of any matching authorities.
     */
    boolean isAuthorityPending(in Account account, String authority);
    boolean isSyncPending(in Account account, String authority);
    
    void addStatusChangeListener(int mask, ISyncStatusObserver callback);
    
Loading