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

Commit c0eda8e8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add detailed log around requestSync. Bug: 113136683 Test: Boot and trigger sync"

parents 75098dbb e183a407
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -2130,7 +2130,7 @@ public abstract class ContentResolver {
                    uri, observer == null ? null : observer.getContentObserver(),
                    observer != null && observer.deliverSelfNotifications(),
                    syncToNetwork ? NOTIFY_SYNC_TO_NETWORK : 0,
                    userHandle, mTargetSdkVersion);
                    userHandle, mTargetSdkVersion, mContext.getPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2147,7 +2147,7 @@ public abstract class ContentResolver {
            getContentService().notifyChange(
                    uri, observer == null ? null : observer.getContentObserver(),
                    observer != null && observer.deliverSelfNotifications(), flags,
                    userHandle, mTargetSdkVersion);
                    userHandle, mTargetSdkVersion, mContext.getPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2320,7 +2320,9 @@ public abstract class ContentResolver {
                .syncOnce()     // Immediate sync.
                .build();
        try {
            getContentService().syncAsUser(request, userId);
            // Note ActivityThread.currentPackageName() may not be accurate in a shared process
            // case, but it's only for debugging.
            getContentService().syncAsUser(request, userId, ActivityThread.currentPackageName());
        } catch(RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2332,7 +2334,9 @@ public abstract class ContentResolver {
     */
    public static void requestSync(SyncRequest request) {
        try {
            getContentService().sync(request);
            // Note ActivityThread.currentPackageName() may not be accurate in a shared process
            // case, but it's only for debugging.
            getContentService().sync(request, ActivityThread.currentPackageName());
        } catch(RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+4 −4
Original line number Diff line number Diff line
@@ -53,14 +53,14 @@ interface IContentService {
     */
    void notifyChange(in Uri uri, IContentObserver observer,
            boolean observerWantsSelfNotifications, int flags,
            int userHandle, int targetSdkVersion);
            int userHandle, int targetSdkVersion, String callingPackage);

    void requestSync(in Account account, String authority, in Bundle extras);
    void requestSync(in Account account, String authority, in Bundle extras, String callingPackage);
    /**
     * Start a sync given a request.
     */
    void sync(in SyncRequest request);
    void syncAsUser(in SyncRequest request, int userId);
    void sync(in SyncRequest request, String callingPackage);
    void syncAsUser(in SyncRequest request, int userId, String callingPackage);
    void cancelSync(in Account account, String authority, in ComponentName cname);
    void cancelSyncAsUser(in Account account, String authority, in ComponentName cname, int userId);

+35 −26
Original line number Diff line number Diff line
@@ -385,7 +385,7 @@ public final class ContentService extends IContentService.Stub {
    @Override
    public void notifyChange(Uri uri, IContentObserver observer,
            boolean observerWantsSelfNotifications, int flags, int userHandle,
            int targetSdkVersion) {
            int targetSdkVersion, String callingPackage) {
        if (DEBUG) Slog.d(TAG, "Notifying update of " + uri + " for user " + userHandle
                + " from observer " + observer + ", flags " + Integer.toHexString(flags));

@@ -393,11 +393,11 @@ public final class ContentService extends IContentService.Stub {
            throw new NullPointerException("Uri must not be null");
        }

        final int uid = Binder.getCallingUid();
        final int pid = Binder.getCallingPid();
        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();
        final int callingUserHandle = UserHandle.getCallingUserId();

        userHandle = handleIncomingUser(uri, pid, uid,
        userHandle = handleIncomingUser(uri, callingPid, callingUid,
                Intent.FLAG_GRANT_WRITE_URI_PERMISSION, true, userHandle);

        final String msg = LocalServices.getService(ActivityManagerInternal.class)
@@ -410,7 +410,7 @@ public final class ContentService extends IContentService.Stub {
                    // Sigh, we need to quietly let apps targeting older API
                    // levels notify on non-existent providers.
                } else {
                    Log.w(TAG, "Ignoring notify for " + uri + " from " + uid + ": " + msg);
                    Log.w(TAG, "Ignoring notify for " + uri + " from " + callingUid + ": " + msg);
                    return;
                }
            }
@@ -453,8 +453,10 @@ public final class ContentService extends IContentService.Stub {
            if ((flags&ContentResolver.NOTIFY_SYNC_TO_NETWORK) != 0) {
                SyncManager syncManager = getSyncManager();
                if (syncManager != null) {
                    syncManager.scheduleLocalSync(null /* all accounts */, callingUserHandle, uid,
                            uri.getAuthority(), getSyncExemptionForCaller(uid));
                    syncManager.scheduleLocalSync(null /* all accounts */, callingUserHandle,
                            callingUid,
                            uri.getAuthority(), getSyncExemptionForCaller(callingUid),
                            callingUid, callingPid, callingPackage);
                }
            }

@@ -477,10 +479,11 @@ public final class ContentService extends IContentService.Stub {
    }

    public void notifyChange(Uri uri, IContentObserver observer,
                             boolean observerWantsSelfNotifications, boolean syncToNetwork) {
            boolean observerWantsSelfNotifications, boolean syncToNetwork,
            String callingPackage) {
        notifyChange(uri, observer, observerWantsSelfNotifications,
                syncToNetwork ? ContentResolver.NOTIFY_SYNC_TO_NETWORK : 0,
                UserHandle.getCallingUserId(), Build.VERSION_CODES.CUR_DEVELOPMENT);
                UserHandle.getCallingUserId(), Build.VERSION_CODES.CUR_DEVELOPMENT, callingPackage);
    }

    /**
@@ -504,14 +507,16 @@ public final class ContentService extends IContentService.Stub {
    }

    @Override
    public void requestSync(Account account, String authority, Bundle extras) {
    public void requestSync(Account account, String authority, Bundle extras,
            String callingPackage) {
        Bundle.setDefusable(extras, true);
        ContentResolver.validateSyncExtrasBundle(extras);
        int userId = UserHandle.getCallingUserId();
        int uId = Binder.getCallingUid();
        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();

        validateExtras(uId, extras);
        final int syncExemption = getSyncExemptionAndCleanUpExtrasForCaller(uId, extras);
        validateExtras(callingUid, extras);
        final int syncExemption = getSyncExemptionAndCleanUpExtrasForCaller(callingUid, extras);

        // This makes it so that future permission checks will be in the context of this
        // process rather than the caller's process. We will restore this before returning.
@@ -519,9 +524,9 @@ public final class ContentService extends IContentService.Stub {
        try {
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                syncManager.scheduleSync(account, userId, uId, authority, extras,
                syncManager.scheduleSync(account, userId, callingUid, authority, extras,
                        SyncStorageEngine.AuthorityInfo.UNDEFINED,
                        syncExemption);
                        syncExemption, callingUid, callingPid, callingPackage);
            }
        } finally {
            restoreCallingIdentity(identityToken);
@@ -538,8 +543,8 @@ public final class ContentService extends IContentService.Stub {
     * @param request The request object. Validation of this object is done by its builder.
     */
    @Override
    public void sync(SyncRequest request) {
        syncAsUser(request, UserHandle.getCallingUserId());
    public void sync(SyncRequest request, String callingPackage) {
        syncAsUser(request, UserHandle.getCallingUserId(), callingPackage);
    }

    private long clampPeriod(long period) {
@@ -557,14 +562,15 @@ public final class ContentService extends IContentService.Stub {
     * INTERACT_ACROSS_USERS_FULL permission.
     */
    @Override
    public void syncAsUser(SyncRequest request, int userId) {
    public void syncAsUser(SyncRequest request, int userId, String callingPackage) {
        enforceCrossUserPermission(userId, "no permission to request sync as user: " + userId);
        int callerUid = Binder.getCallingUid();
        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();

        final Bundle extras = request.getBundle();

        validateExtras(callerUid, extras);
        final int syncExemption = getSyncExemptionAndCleanUpExtrasForCaller(callerUid, extras);
        validateExtras(callingUid, extras);
        final int syncExemption = getSyncExemptionAndCleanUpExtrasForCaller(callingUid, extras);

        // This makes it so that future permission checks will be in the context of this
        // process rather than the caller's process. We will restore this before returning.
@@ -590,9 +596,9 @@ public final class ContentService extends IContentService.Stub {
                        flextime, extras);
            } else {
                syncManager.scheduleSync(
                        request.getAccount(), userId, callerUid, request.getProvider(), extras,
                        request.getAccount(), userId, callingUid, request.getProvider(), extras,
                        SyncStorageEngine.AuthorityInfo.UNDEFINED,
                        syncExemption);
                        syncExemption, callingUid, callingPid, callingPackage);
            }
        } finally {
            restoreCallingIdentity(identityToken);
@@ -781,6 +787,7 @@ public final class ContentService extends IContentService.Stub {
        enforceCrossUserPermission(userId,
                "no permission to modify the sync settings for user " + userId);
        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();
        final int syncExemptionFlag = getSyncExemptionForCaller(callingUid);

        long identityToken = clearCallingIdentity();
@@ -788,7 +795,7 @@ public final class ContentService extends IContentService.Stub {
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                syncManager.getSyncStorageEngine().setSyncAutomatically(account, userId,
                        providerName, sync, syncExemptionFlag, callingUid);
                        providerName, sync, syncExemptionFlag, callingUid, callingPid);
            }
        } finally {
            restoreCallingIdentity(identityToken);
@@ -916,6 +923,7 @@ public final class ContentService extends IContentService.Stub {

        syncable = normalizeSyncable(syncable);
        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();

        int userId = UserHandle.getCallingUserId();
        long identityToken = clearCallingIdentity();
@@ -923,7 +931,7 @@ public final class ContentService extends IContentService.Stub {
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                syncManager.getSyncStorageEngine().setIsSyncable(
                        account, userId, providerName, syncable, callingUid);
                        account, userId, providerName, syncable, callingUid, callingPid);
            }
        } finally {
            restoreCallingIdentity(identityToken);
@@ -971,13 +979,14 @@ public final class ContentService extends IContentService.Stub {
                "no permission to write the sync settings");

        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();

        long identityToken = clearCallingIdentity();
        try {
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                syncManager.getSyncStorageEngine().setMasterSyncAutomatically(flag, userId,
                        getSyncExemptionForCaller(callingUid), callingUid);
                        getSyncExemptionForCaller(callingUid), callingUid, callingPid);
            }
        } finally {
            restoreCallingIdentity(identityToken);
+46 −50
Original line number Diff line number Diff line
@@ -584,9 +584,9 @@ public class SyncManager {
        mSyncStorageEngine.setOnSyncRequestListener(new OnSyncRequestListener() {
            @Override
            public void onSyncRequest(SyncStorageEngine.EndPoint info, int reason, Bundle extras,
                    @SyncExemption int syncExemptionFlag) {
                    @SyncExemption int syncExemptionFlag, int callingUid, int callingPid) {
                scheduleSync(info.account, info.userId, reason, info.provider, extras,
                        AuthorityInfo.UNDEFINED, syncExemptionFlag);
                        AuthorityInfo.UNDEFINED, syncExemptionFlag, callingUid, callingPid, null);
            }
        });

@@ -619,7 +619,8 @@ public class SyncManager {
                    scheduleSync(null, UserHandle.USER_ALL,
                            SyncOperation.REASON_SERVICE_CHANGED,
                            type.authority, null, AuthorityInfo.UNDEFINED,
                            ContentResolver.SYNC_EXEMPTION_NONE);
                            ContentResolver.SYNC_EXEMPTION_NONE,
                            Process.myUid(), -1, null);
                }
            }
        }, mSyncHandler);
@@ -666,7 +667,8 @@ public class SyncManager {
                scheduleSync(account, UserHandle.getUserId(uid),
                        SyncOperation.REASON_ACCOUNTS_UPDATED,
                        null, null, AuthorityInfo.SYNCABLE_NO_ACCOUNT_ACCESS,
                        ContentResolver.SYNC_EXEMPTION_NONE);
                        ContentResolver.SYNC_EXEMPTION_NONE,
                        Process.myUid(), -2, null);
            }
        });

@@ -893,9 +895,11 @@ public class SyncManager {
     */
    public void scheduleSync(Account requestedAccount, int userId, int reason,
            String requestedAuthority, Bundle extras, int targetSyncState,
            @SyncExemption int syncExemptionFlag) {
            @SyncExemption int syncExemptionFlag, int callingUid, int callingPid,
            String callingPackage) {
        scheduleSync(requestedAccount, userId, reason, requestedAuthority, extras, targetSyncState,
                0 /* min delay */, true /* checkIfAccountReady */, syncExemptionFlag);
                0 /* min delay */, true /* checkIfAccountReady */, syncExemptionFlag,
                callingUid, callingPid, callingPackage);
    }

    /**
@@ -904,18 +908,21 @@ public class SyncManager {
    private void scheduleSync(Account requestedAccount, int userId, int reason,
            String requestedAuthority, Bundle extras, int targetSyncState,
            final long minDelayMillis, boolean checkIfAccountReady,
            @SyncExemption int syncExemptionFlag) {
        final boolean isLoggable = Log.isLoggable(TAG, Log.VERBOSE);
            @SyncExemption int syncExemptionFlag,
            int callingUid, int callingPid, String callingPackage) {
        if (extras == null) {
            extras = new Bundle();
        }
        if (isLoggable) {
            Log.d(TAG, "one-time sync for: " + requestedAccount + " " + extras.toString() + " "
                    + requestedAuthority
                    + " reason=" + reason
                    + " checkIfAccountReady=" + checkIfAccountReady
                    + " syncExemptionFlag=" + syncExemptionFlag);
        }
        extras.size(); // Force unpacel.
        mLogger.log("scheduleSync: account=", requestedAccount,
                " u", userId,
                " authority=", requestedAuthority,
                " reason=", reason,
                " extras=", extras,
                " cuid=", callingUid, " cpid=", callingPid, " cpkg=", callingPackage,
                " mdm=", minDelayMillis,
                " ciar=", checkIfAccountReady,
                " sef=", syncExemptionFlag);

        AccountAndUser[] accounts = null;
        if (requestedAccount != null) {
@@ -934,9 +941,7 @@ public class SyncManager {
        }

        if (ArrayUtils.isEmpty(accounts)) {
            if (isLoggable) {
                Slog.v(TAG, "scheduleSync: no accounts configured, dropping");
            }
            mLogger.log("scheduleSync: no accounts configured, dropping");
            return;
        }

@@ -1007,10 +1012,8 @@ public class SyncManager {
                final int owningUid = syncAdapterInfo.uid;

                if (isSyncable == AuthorityInfo.SYNCABLE_NO_ACCOUNT_ACCESS) {
                    if (isLoggable) {
                        Slog.v(TAG, "    Not scheduling sync operation: "
                    mLogger.log("scheduleSync: Not scheduling sync operation: "
                                + "isSyncable == SYNCABLE_NO_ACCOUNT_ACCESS");
                    }
                    Bundle finalExtras = new Bundle(extras);
                    String packageName = syncAdapterInfo.componentName.getPackageName();
                    // If the app did not run and has no account access, done
@@ -1025,7 +1028,8 @@ public class SyncManager {
                                    scheduleSync(account.account, userId, reason, authority,
                                            finalExtras, targetSyncState, minDelayMillis,
                                            true /* checkIfAccountReady */,
                                            syncExemptionFlag);
                                            syncExemptionFlag, callingUid, callingPid,
                                            callingPackage);
                                }
                            }
                        ));
@@ -1037,7 +1041,7 @@ public class SyncManager {
                if (!checkIfAccountReady && isSyncable < 0 && isAlwaysSyncable) {
                    mSyncStorageEngine.setIsSyncable(
                            account.account, account.userId, authority, AuthorityInfo.SYNCABLE,
                            SyncLogger.CALLING_UID_SELF);
                            callingUid, callingPid);
                    isSyncable = AuthorityInfo.SYNCABLE;
                }

@@ -1056,10 +1060,8 @@ public class SyncManager {
                                && mSyncStorageEngine.getSyncAutomatically(account.account,
                                account.userId, authority));
                if (!syncAllowed) {
                    if (isLoggable) {
                        Log.d(TAG, "scheduleSync: sync of " + account + ", " + authority
                                + " is not allowed, dropping request");
                    }
                    mLogger.log("scheduleSync: sync of ", account, " ", authority,
                            " is not allowed, dropping request");
                    continue;
                }
                SyncStorageEngine.EndPoint info =
@@ -1077,21 +1079,16 @@ public class SyncManager {
                        sendOnUnsyncableAccount(mContext, syncAdapterInfo, account.userId,
                                () -> scheduleSync(account.account, account.userId, reason,
                                        authority, finalExtras, targetSyncState, minDelayMillis,
                                        false, syncExemptionFlag));
                                        false, syncExemptionFlag, callingUid, callingPid,
                                        callingPackage));
                    } else {
                        // Initialisation sync.
                        Bundle newExtras = new Bundle();
                        newExtras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true);
                        if (isLoggable) {
                            Slog.v(TAG, "schedule initialisation Sync:"
                                    + ", delay until " + delayUntil
                                    + ", run by " + 0
                                    + ", flexMillis " + 0
                                    + ", source " + source
                                    + ", account " + account
                                    + ", authority " + authority
                                    + ", extras " + newExtras);
                        }

                        mLogger.log("scheduleSync: schedule initialisation sync ",
                                account, " ", authority);

                        postScheduleSyncMessage(
                                new SyncOperation(account.account, account.userId,
                                        owningUid, owningPackage, reason, source,
@@ -1102,20 +1099,17 @@ public class SyncManager {
                    }
                } else if (targetSyncState == AuthorityInfo.UNDEFINED
                        || targetSyncState == isSyncable) {
                    if (isLoggable) {
                        Slog.v(TAG, "scheduleSync:"
                                + " delay until " + delayUntil
                                + ", source " + source
                                + ", account " + account
                                + ", authority " + authority
                                + ", extras " + extras);
                    }
                    mLogger.log("scheduleSync: scheduling sync ",
                            account, " ", authority);
                    postScheduleSyncMessage(
                            new SyncOperation(account.account, account.userId,
                                    owningUid, owningPackage, reason, source,
                                    authority, extras, allowParallelSyncs, syncExemptionFlag),
                            minDelayMillis
                    );
                } else {
                    mLogger.log("scheduleSync: not handling ",
                            account, " ", authority);
                }
            }
        }
@@ -1227,12 +1221,13 @@ public class SyncManager {
     * ms to batch syncs.
     */
    public void scheduleLocalSync(Account account, int userId, int reason, String authority,
            @SyncExemption int syncExemptionFlag) {
            @SyncExemption int syncExemptionFlag,
            int callingUid, int callingPid, String callingPackage) {
        final Bundle extras = new Bundle();
        extras.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true);
        scheduleSync(account, userId, reason, authority, extras,
                AuthorityInfo.UNDEFINED, LOCAL_SYNC_DELAY, true /* checkIfAccountReady */,
                syncExemptionFlag);
                syncExemptionFlag, callingUid, callingPid, callingPackage);
    }

    public SyncAdapterType[] getSyncAdapterTypes(int userId) {
@@ -1769,7 +1764,8 @@ public class SyncManager {
                mContext.getOpPackageName());
        for (Account account : accounts) {
            scheduleSync(account, userId, SyncOperation.REASON_USER_START, null, null,
                    AuthorityInfo.NOT_INITIALIZED, ContentResolver.SYNC_EXEMPTION_NONE);
                    AuthorityInfo.NOT_INITIALIZED, ContentResolver.SYNC_EXEMPTION_NONE,
                    Process.myUid(), -3, null);
        }
    }

@@ -3272,7 +3268,7 @@ public class SyncManager {
                scheduleSync(syncTargets.account, syncTargets.userId,
                        SyncOperation.REASON_ACCOUNTS_UPDATED, syncTargets.provider,
                        null, AuthorityInfo.NOT_INITIALIZED,
                        ContentResolver.SYNC_EXEMPTION_NONE);
                        ContentResolver.SYNC_EXEMPTION_NONE, Process.myUid(), -4, null);
            }
        }

+21 −16

File changed.

Preview size limit exceeded, changes collapsed.