@Test @SdkSuppress(minSdkVersion = WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) public void testGetBackgroundScheduler_withJobSchedulerApiLevel() { Scheduler scheduler = Schedulers.createBestAvailableBackgroundScheduler(mAppContext, mWorkManager); assertThat(scheduler, is(instanceOf(SystemJobScheduler.class))); assertServicesEnabled(true, false, false); }
static @NonNull Scheduler createBestAvailableBackgroundScheduler( @NonNull Context context, @NonNull WorkManagerImpl workManager) { Scheduler scheduler; boolean enableFirebaseJobService = false; boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler = new SystemJobScheduler(context, workManager); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; Log.d(TAG, "Created FirebaseJobScheduler"); } catch (Exception e) { scheduler = new SystemAlarmScheduler(context); enableSystemAlarmService = true; Log.d(TAG, "Created SystemAlarmScheduler"); } } try { Class firebaseJobServiceClass = Class.forName(FIREBASE_JOB_SERVICE_CLASSNAME); setComponentEnabled(context, firebaseJobServiceClass, enableFirebaseJobService); } catch (ClassNotFoundException e) { } setComponentEnabled(context, SystemAlarmService.class, enableSystemAlarmService); return scheduler; }
Schedulers { static @NonNull Scheduler createBestAvailableBackgroundScheduler( @NonNull Context context, @NonNull WorkManagerImpl workManager) { Scheduler scheduler; boolean enableFirebaseJobService = false; boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler = new SystemJobScheduler(context, workManager); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; Log.d(TAG, "Created FirebaseJobScheduler"); } catch (Exception e) { scheduler = new SystemAlarmScheduler(context); enableSystemAlarmService = true; Log.d(TAG, "Created SystemAlarmScheduler"); } } try { Class firebaseJobServiceClass = Class.forName(FIREBASE_JOB_SERVICE_CLASSNAME); setComponentEnabled(context, firebaseJobServiceClass, enableFirebaseJobService); } catch (ClassNotFoundException e) { } setComponentEnabled(context, SystemAlarmService.class, enableSystemAlarmService); return scheduler; } }
Schedulers { static @NonNull Scheduler createBestAvailableBackgroundScheduler( @NonNull Context context, @NonNull WorkManagerImpl workManager) { Scheduler scheduler; boolean enableFirebaseJobService = false; boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler = new SystemJobScheduler(context, workManager); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; Log.d(TAG, "Created FirebaseJobScheduler"); } catch (Exception e) { scheduler = new SystemAlarmScheduler(context); enableSystemAlarmService = true; Log.d(TAG, "Created SystemAlarmScheduler"); } } try { Class firebaseJobServiceClass = Class.forName(FIREBASE_JOB_SERVICE_CLASSNAME); setComponentEnabled(context, firebaseJobServiceClass, enableFirebaseJobService); } catch (ClassNotFoundException e) { } setComponentEnabled(context, SystemAlarmService.class, enableSystemAlarmService); return scheduler; } private  Schedulers(); }
Schedulers { static @NonNull Scheduler createBestAvailableBackgroundScheduler( @NonNull Context context, @NonNull WorkManagerImpl workManager) { Scheduler scheduler; boolean enableFirebaseJobService = false; boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler = new SystemJobScheduler(context, workManager); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; Log.d(TAG, "Created FirebaseJobScheduler"); } catch (Exception e) { scheduler = new SystemAlarmScheduler(context); enableSystemAlarmService = true; Log.d(TAG, "Created SystemAlarmScheduler"); } } try { Class firebaseJobServiceClass = Class.forName(FIREBASE_JOB_SERVICE_CLASSNAME); setComponentEnabled(context, firebaseJobServiceClass, enableFirebaseJobService); } catch (ClassNotFoundException e) { } setComponentEnabled(context, SystemAlarmService.class, enableSystemAlarmService); return scheduler; } private  Schedulers(); static void schedule(
            @NonNull Configuration configuration,
            @NonNull WorkDatabase workDatabase,
            List<Scheduler> schedulers); }
Schedulers { static @NonNull Scheduler createBestAvailableBackgroundScheduler( @NonNull Context context, @NonNull WorkManagerImpl workManager) { Scheduler scheduler; boolean enableFirebaseJobService = false; boolean enableSystemAlarmService = false; if (Build.VERSION.SDK_INT >= WorkManagerImpl.MIN_JOB_SCHEDULER_API_LEVEL) { scheduler = new SystemJobScheduler(context, workManager); setComponentEnabled(context, SystemJobService.class, true); Log.d(TAG, "Created SystemJobScheduler and enabled SystemJobService"); } else { try { scheduler = tryCreateFirebaseJobScheduler(context); enableFirebaseJobService = true; Log.d(TAG, "Created FirebaseJobScheduler"); } catch (Exception e) { scheduler = new SystemAlarmScheduler(context); enableSystemAlarmService = true; Log.d(TAG, "Created SystemAlarmScheduler"); } } try { Class firebaseJobServiceClass = Class.forName(FIREBASE_JOB_SERVICE_CLASSNAME); setComponentEnabled(context, firebaseJobServiceClass, enableFirebaseJobService); } catch (ClassNotFoundException e) { } setComponentEnabled(context, SystemAlarmService.class, enableSystemAlarmService); return scheduler; } private  Schedulers(); static void schedule(
            @NonNull Configuration configuration,
            @NonNull WorkDatabase workDatabase,
            List<Scheduler> schedulers);  }