Loading services/core/java/com/android/server/am/flags.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -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 } } services/core/java/com/android/server/content/SyncManager.java +27 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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)) { Loading Loading @@ -625,6 +638,8 @@ public class SyncManager { } finally { Binder.restoreCallingIdentity(token); } return mJobScheduler != null; } /** Loading Loading @@ -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); Loading @@ -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(); Loading Loading
services/core/java/com/android/server/am/flags.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -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 } }
services/core/java/com/android/server/content/SyncManager.java +27 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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)) { Loading Loading @@ -625,6 +638,8 @@ public class SyncManager { } finally { Binder.restoreCallingIdentity(token); } return mJobScheduler != null; } /** Loading Loading @@ -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); Loading @@ -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(); Loading