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

Commit b5f93cd3 authored by Fred Quintana's avatar Fred Quintana Committed by Android Git Automerger
Browse files

am 5e787c42: - add a "isSyncable" flag to a given account/authority pair that ...

am 5e787c42: - add a "isSyncable" flag to a given account/authority pair that   indicates whether or not syncs should be attempted for it. - add public methods to get and set this parameter

Merge commit '5e787c42'

* commit '5e787c42':
  - add a "isSyncable" flag to a given account/authority pair that
parents 59619188 5e787c42
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -27032,6 +27032,21 @@
<parameter name="selectionArgs" type="java.lang.String[]">
</parameter>
</method>
<method name="getIsSyncable"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 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>
</method>
<method name="getMasterSyncAutomatically"
 return="boolean"
 abstract="false"
@@ -27329,6 +27344,23 @@
<parameter name="extras" type="android.os.Bundle">
</parameter>
</method>
<method name="setIsSyncable"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 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="syncable" type="int">
</parameter>
</method>
<method name="setMasterSyncAutomatically"
 return="void"
 abstract="false"
+25 −0
Original line number Diff line number Diff line
@@ -1011,6 +1011,31 @@ public abstract class ContentResolver {
        }
    }

    /**
     * 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.
     */
    public int getIsSyncable(Account account, String authority) {
        try {
            return getContentService().getIsSyncable(account, authority);
        } catch (RemoteException e) {
            throw new RuntimeException("the ContentService should always be reachable", e);
        }
    }

    /**
     * Set whether this account/provider is syncable.
     * @param syncable, >0 denotes syncable, 0 means not syncable, <0 means unknown
     */
    public void setIsSyncable(Account account, String authority, int syncable) {
        try {
            getContentService().setIsSyncable(account, authority, syncable);
        } 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.
+31 −0
Original line number Diff line number Diff line
@@ -272,6 +272,37 @@ public final class ContentService extends IContentService.Stub {
        }
    }

    public int getIsSyncable(Account account, String providerName) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS,
                "no permission to read the sync settings");
        long identityToken = clearCallingIdentity();
        try {
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                return syncManager.getSyncStorageEngine().getIsSyncable(
                        account, providerName);
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
        return -1;
    }

    public void setIsSyncable(Account account, String providerName, int syncable) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS,
                "no permission to write the sync settings");
        long identityToken = clearCallingIdentity();
        try {
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                syncManager.getSyncStorageEngine().setIsSyncable(
                        account, providerName, syncable);
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public boolean getMasterSyncAutomatically() {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS,
                "no permission to read the sync settings");
+12 −0
Original line number Diff line number Diff line
@@ -54,6 +54,18 @@ interface IContentService {
     */
    void setSyncAutomatically(in Account account, String providerName, boolean sync);

    /**
     * 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.
     */
    int getIsSyncable(in Account account, String providerName);

    /**
     * Set whether this account/provider is syncable.
     * @param syncable, >0 denotes syncable, 0 means not syncable, <0 means unknown
     */
    void setIsSyncable(in Account account, String providerName, int syncable);

    void setMasterSyncAutomatically(boolean flag);

    boolean getMasterSyncAutomatically();
+9 −8
Original line number Diff line number Diff line
@@ -589,22 +589,21 @@ class SyncManager implements OnAccountsUpdatedListener {
        // if the url was specified then replace the list of authorities with just this authority
        // or clear it if this authority isn't syncable
        if (requestedAuthority != null) {
            final boolean isSyncable = syncableAuthorities.contains(requestedAuthority);
            final boolean hasSyncAdapter = syncableAuthorities.contains(requestedAuthority);
            syncableAuthorities.clear();
            if (isSyncable) syncableAuthorities.add(requestedAuthority);
            if (hasSyncAdapter) syncableAuthorities.add(requestedAuthority);
        }

        for (String authority : syncableAuthorities) {
            for (Account account : accounts) {
                boolean isSyncable = mSyncStorageEngine.getIsSyncable(account, authority) > 0;
                if (!isSyncable) {
                    continue;
                }
                if (mSyncAdapters.getServiceInfo(new SyncAdapterType(authority, account.type))
                        != null) {
                    scheduleSyncOperation(
                            new SyncOperation(account, source, authority, extras, delay));
                    // TODO: remove this when Calendar supports multiple accounts. Until then
                    // pretend that only the first account exists when syncing calendar.
                    if ("calendar".equals(authority)) {
                        break;
                    }
                }
            }
        }
@@ -1589,9 +1588,11 @@ class SyncManager implements OnAccountsUpdatedListener {
                    final boolean syncAutomatically =
                            mSyncStorageEngine.getSyncAutomatically(op.account, op.authority)
                                    && mSyncStorageEngine.getMasterSyncAutomatically();
                    boolean isSyncable =
                            mSyncStorageEngine.getIsSyncable(op.account, op.authority) > 0;
                    boolean syncAllowed =
                            manualSync || (backgroundDataUsageAllowed && syncAutomatically);
                    if (!syncAllowed) {
                    if (!syncAllowed || !isSyncable) {
                        if (isLoggable) {
                            Log.v(TAG, "runStateIdle: sync off, dropping " + op);
                        }
Loading