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

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

add sync polling

- added the ability to specify that a sync (of account/authority/extras)
  should occur at a given frequency
- the existing daily poll code was replaced with seeding each
  account/authority with a 24 hour periodic sync
- enhanced the "adb shell dumpsys content" output to show the
  periodic syncs and when they will next run
parent 0a45a098
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -222,6 +222,7 @@ aidl_files := \
	frameworks/base/core/java/android/content/ComponentName.aidl \
	frameworks/base/core/java/android/content/Intent.aidl \
	frameworks/base/core/java/android/content/IntentSender.aidl \
	frameworks/base/core/java/android/content/PeriodicSync.aidl \
	frameworks/base/core/java/android/content/SyncStats.aidl \
	frameworks/base/core/java/android/content/res/Configuration.aidl \
	frameworks/base/core/java/android/appwidget/AppWidgetProviderInfo.aidl \
+156 −2
Original line number Diff line number Diff line
@@ -31107,6 +31107,25 @@
<parameter name="name" type="java.lang.String">
</parameter>
</method>
<method name="addPeriodicSync"
 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>
<parameter name="pollFrequency" type="long">
</parameter>
</method>
<method name="addStatusChangeListener"
 return="java.lang.Object"
 abstract="false"
@@ -31227,6 +31246,21 @@
 visibility="public"
>
</method>
<method name="getPeriodicSyncs"
 return="java.util.List&lt;android.content.PeriodicSync&gt;"
 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="getSyncAdapterTypes"
 return="android.content.SyncAdapterType[]"
 abstract="false"
@@ -31462,6 +31496,23 @@
<parameter name="observer" type="android.database.ContentObserver">
</parameter>
</method>
<method name="removePeriodicSync"
 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="removeStatusChangeListener"
 return="void"
 abstract="false"
@@ -39745,6 +39796,109 @@
>
</method>
</class>
<class name="PeriodicSync"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<implements name="android.os.Parcelable">
</implements>
<constructor name="PeriodicSync"
 type="android.content.PeriodicSync"
 static="false"
 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>
<parameter name="period" type="long">
</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="account"
 type="android.accounts.Account"
 transient="false"
 volatile="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="authority"
 type="java.lang.String"
 transient="false"
 volatile="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="extras"
 type="android.os.Bundle"
 transient="false"
 volatile="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="period"
 type="long"
 transient="false"
 volatile="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="ReceiverCallNotAllowedException"
 extends="android.util.AndroidRuntimeException"
 abstract="false"
@@ -72352,7 +72506,7 @@
 type="float"
 transient="false"
 volatile="false"
 value="0.001f"
 value="0.0010f"
 static="true"
 final="true"
 deprecated="not deprecated"
@@ -209987,7 +210141,7 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="t" type="T">
<parameter name="arg0" type="T">
</parameter>
</method>
</interface>
+9 −5
Original line number Diff line number Diff line
@@ -560,9 +560,13 @@ public class AccountManager {
     * user to enter credentials. If it is able to retrieve the authtoken it will be returned
     * in the result.
     * <p>
     * If the authenticator needs to prompt the user for credentials it will return an intent for
     * If the authenticator needs to prompt the user for credentials, rather than returning the
     * authtoken it will instead return an intent for
     * an activity that will do the prompting. If an intent is returned and notifyAuthFailure
     * is true then a notification will be created that launches this intent.
     * is true then a notification will be created that launches this intent. This intent can be
     * invoked by the caller directly to start the activity that prompts the user for the
     * updated credentials. Otherwise this activity will not be run until the user activates
     * the notification.
     * <p>
     * This call returns immediately but runs asynchronously and the result is accessed via the
     * {@link AccountManagerFuture} that is returned. This future is also passed as the sole
+60 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;


/**
@@ -965,6 +966,65 @@ public abstract class ContentResolver {
        }
    }

    /**
     * Specifies that a sync should be requested with the specified the account, authority,
     * and extras at the given frequency. If there is already another periodic sync scheduled
     * with the account, authority and extras then a new periodic sync won't be added, instead
     * the frequency of the previous one will be updated.
     * <p>
     * These periodic syncs honor the "syncAutomatically" and "masterSyncAutomatically" settings.
     * Although these sync are scheduled at the specified frequency, it may take longer for it to
     * actually be started if other syncs are ahead of it in the sync operation queue. This means
     * that the actual start time may drift.
     *
     * @param account the account to specify in the sync
     * @param authority the provider to specify in the sync request
     * @param extras extra parameters to go along with the sync request
     * @param pollFrequency how frequently the sync should be performed, in seconds.
     */
    public static void addPeriodicSync(Account account, String authority, Bundle extras,
            long pollFrequency) {
        validateSyncExtrasBundle(extras);
        try {
            getContentService().addPeriodicSync(account, authority, extras, pollFrequency);
        } catch (RemoteException e) {
            // exception ignored; if this is thrown then it means the runtime is in the midst of
            // being restarted
        }
    }

    /**
     * Remove a periodic sync. Has no affect if account, authority and extras don't match
     * an existing periodic sync.
     *
     * @param account the account of the periodic sync to remove
     * @param authority the provider of the periodic sync to remove
     * @param extras the extras of the periodic sync to remove
     */
    public static void removePeriodicSync(Account account, String authority, Bundle extras) {
        validateSyncExtrasBundle(extras);
        try {
            getContentService().removePeriodicSync(account, authority, extras);
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * Get the list of information about the periodic syncs for the given account and authority.
     *
     * @param account the account whose periodic syncs we are querying
     * @param authority the provider whose periodic syncs we are querying
     * @return a list of PeriodicSync objects. This list may be empty but will never be null.
     */
    public static List<PeriodicSync> getPeriodicSyncs(Account account, String authority) {
        try {
            return getContentService().getPeriodicSyncs(account, authority);
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * Check if this account/provider is syncable.
     * @return >0 if it is syncable, 0 if not, and <0 if the state isn't known yet.
+38 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.Manifest;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * {@hide}
@@ -273,6 +275,42 @@ public final class ContentService extends IContentService.Stub {
        }
    }

    public void addPeriodicSync(Account account, String authority, Bundle extras,
            long pollFrequency) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                "no permission to write the sync settings");
        long identityToken = clearCallingIdentity();
        try {
            getSyncManager().getSyncStorageEngine().addPeriodicSync(
                    account, authority, extras, pollFrequency);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void removePeriodicSync(Account account, String authority, Bundle extras) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                "no permission to write the sync settings");
        long identityToken = clearCallingIdentity();
        try {
            getSyncManager().getSyncStorageEngine().removePeriodicSync(account, authority, extras);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public List<PeriodicSync> getPeriodicSyncs(Account account, String providerName) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS,
                "no permission to read the sync settings");
        long identityToken = clearCallingIdentity();
        try {
            return getSyncManager().getSyncStorageEngine().getPeriodicSyncs(
                    account, providerName);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public int getIsSyncable(Account account, String providerName) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS,
                "no permission to read the sync settings");
Loading