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

Commit 08653139 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android (Google) Code Review
Browse files

Merge "Move SyncManager broadcast receivers off the main thread" into main

parents cac48c77 e6a2595f
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -340,3 +340,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "syncmanager_off_main_thread"
    namespace: "backstage_power"
    description: "Move broadcast receivers off the main thread to reduce ANR chances"
    bug: "409177829"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+27 −5
Original line number Diff line number Diff line
@@ -244,6 +244,7 @@ public class SyncManager {
    private final NotificationManager mNotificationMgr;
    private final IBatteryStats mBatteryStats;
    private JobScheduler mJobScheduler;
    private volatile boolean mJobSchedulerInitialized;

    private SyncStorageEngine mSyncStorageEngine;

@@ -574,10 +575,22 @@ public class SyncManager {
        mSyncStorageEngine.setJobAttributionFixed(allSyncsAttributed);
    }

    private synchronized void verifyJobScheduler() {
        if (mJobScheduler != null) {
            return;
    private void verifyJobScheduler() {
        if (mJobSchedulerInitialized) return;
        // Initialize JobScheduler
        synchronized (this) {
            if (initializeJobScheduler()) {
                mJobSchedulerInitialized = true;
            }
        }
    }

    /**
     * Initialize JobScheduler connection and load initial sync jobs.
     * @return true if successfully initialized
     */
    @GuardedBy("this")
    private boolean initializeJobScheduler() {
        final long token = Binder.clearCallingIdentity();
        try {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
@@ -625,6 +638,8 @@ public class SyncManager {
        } finally {
            Binder.restoreCallingIdentity(token);
        }

        return mJobScheduler != null;
    }

    /**
@@ -712,7 +727,13 @@ public class SyncManager {
        mAppCloningDeviceConfigHelper = AppCloningDeviceConfigHelper.getInstance(context);

        IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);

        if (com.android.server.am.Flags.syncmanagerOffMainThread()) {
            context.registerReceiver(mConnectivityIntentReceiver, intentFilter, null,
                    mSyncHandler);
        } else {
            context.registerReceiver(mConnectivityIntentReceiver, intentFilter);
        }

        intentFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);
        intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
@@ -723,7 +744,8 @@ public class SyncManager {
        intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
        intentFilter.addAction(Intent.ACTION_USER_STOPPED);
        mContext.registerReceiverAsUser(
                mUserIntentReceiver, UserHandle.ALL, intentFilter, null, null);
                mUserIntentReceiver, UserHandle.ALL, intentFilter, null,
                com.android.server.am.Flags.syncmanagerOffMainThread() ? mSyncHandler : null);


        mPackageMonitor = new PackageMonitorImpl();