@Override public boolean onStartJob(JobParameters params) { PersistableBundle pb=params.getExtras(); if (pb.getBoolean(MainActivity.KEY_DOWNLOAD, false)) { job=new DownloadThread(params); job.start(); return(true); } Log.d(getClass().getSimpleName(), "job invoked"); return(false); }
@Override public boolean onStartJob(JobParameters params) { PersistableBundle pb=params.getExtras(); if (pb.getBoolean(MainActivity.KEY_DOWNLOAD, false)) { job=new DownloadThread(params); job.start(); return(true); } Log.d(getClass().getSimpleName(), "job invoked"); return(false); }
@Override public boolean onStartJob(JobParameters params) { String className = params.getExtras().getString(RestartingAdministrator.EXTRA_LAST_ACTIVITY); if (className != null) { try { //noinspection unchecked Class<? extends Activity> activityClass = (Class<? extends Activity>) Class.forName(className); final Intent intent = new Intent(this, activityClass); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } catch (ClassNotFoundException e) { ACRA.log.w(ACRA.LOG_TAG, "Unable to find activity class" + className); } } return false; }
boolean onStopJob(JobParameters params) { SchedulerConstraint constraint; try { constraint = fromBundle(params.getExtras()); } catch (Exception e) { JqLog.e(e, "bad bundle from job scheduler stop callback"); return false; } return stop(constraint); } }
@Override public boolean onStartJob(JobParameters jobParameters) { String jobId = String.valueOf(jobParameters.getJobId()); SyncDelegate syncDelegate = createSyncDelegate(); mSyncDelegates.put(jobId, syncDelegate); syncDelegate.subscribe(token -> { if (TextUtils.equals(jobId, token)) { jobFinished(jobParameters, false); mSyncDelegates.remove(jobId); } }); syncDelegate.performSync(new SyncDelegate.Job(jobParameters.getExtras())); return true; }
@Override public boolean onStartJob(JobParameters params) { logd("PlatformSchedulerService started"); PersistableBundle extras = params.getExtras(); Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS)); if (requirements.checkRequirements(this)) { logd("Requirements are met"); String serviceAction = extras.getString(KEY_SERVICE_ACTION); String servicePackage = extras.getString(KEY_SERVICE_PACKAGE); Intent intent = new Intent(serviceAction).setPackage(servicePackage); logd("Starting service action: " + serviceAction + " package: " + servicePackage); Util.startForegroundService(this, intent); } else { logd("Requirements are not met"); jobFinished(params, /* needsReschedule */ true); } return false; }
@NonNull private JobParameters prepareJobParameters(SchedulerConstraint constraint) { JobInfo info = schedule(constraint); JobParameters params = mock(JobParameters.class); when(params.getExtras()).thenReturn(info.getExtras()); when(params.getJobId()).thenReturn(info.getId()); return params; }
@Override public boolean onStartJob(JobParameters params) { PersistableBundle extras = params.getExtras(); CoreConfiguration config = IOUtils.deserialize(CoreConfiguration.class, extras.getString(LegacySenderService.EXTRA_ACRA_CONFIG)); boolean onlySilent = extras.getBoolean(LegacySenderService.EXTRA_ONLY_SEND_SILENT_REPORTS); if (config != null) { new SendingConductor(this, config).sendReports(onlySilent); } return false; }
boolean onStartJob(JobParameters params) { SchedulerConstraint constraint; try { constraint = fromBundle(params.getExtras()); } catch (Exception e) { JqLog.e(e, "bad bundle from framework job scheduler start callback."); return false; } JqLog.d("[FW Scheduler] start job %s %d", constraint, params.getJobId()); constraint.setData(params); return start(constraint); }
@Test public void testStartJob() { JobParameters jobParameters = mock(JobParameters.class); when(jobParameters.getExtras()) .thenReturn(new SyncDelegate.JobBuilder(service, "1").build().toPersistableBundle()); when(jobParameters.getJobId()).thenReturn(2); service.onStartJob(jobParameters); verify(service.syncDelegate).subscribe(listenerCaptor.capture()); verify(service.syncDelegate).performSync(any(SyncDelegate.Job.class)); listenerCaptor.getValue().onDone("2"); }
public void run() { boolean found = false; LogManager.i(BluetoothTestJob.TAG, "Bluetooth Test Job running"); int testType = params.getExtras().getInt("test_type"); if(testType == BluetoothMedic.NO_TEST) { found = true;
/** * Receives callback from the service when a job has landed * on the app. Colours the UI and post a message to * uncolour it after a second. */ public void onReceivedStartJob(JobParameters params) { mShowStartView.setBackgroundColor(startJobColor); Message m = Message.obtain(mHandler, MSG_UNCOLOUR_START); mHandler.sendMessageDelayed(m, 1000L); // uncolour in 1 second. mParamsTextView.setText("Executing: " + params.getJobId() + " " + params.getExtras()); }
@Override public void onServiceConnected(ComponentName className, IBinder service) { LocationUpdateService.LocationUpdateServiceBinder binder = (LocationUpdateService.LocationUpdateServiceBinder) service; locationUpdateService = binder.getService(); locationUpdateService.updateNetworkLocation( params.getExtras().getBoolean("byLastLocationOnly"), null, params.getExtras().getInt("attempts")); new Thread(new Runnable() { public void run() { serviceConnected(locationUpdateServiceConnection); } }).start(); }
@Override public boolean onStartJob(JobParameters params) { Log.i(LOG_TAG, "Starting job " + params.toString()); PersistableBundle extras = params.getExtras(); String filePath = extras.getString(SCRIPT_FILE_PATH); Uri scriptUri = new Uri.Builder().scheme("com.termux.file").path(filePath).build(); Intent executeIntent = new Intent(ACTION_EXECUTE, scriptUri); executeIntent.setClassName("com.termux", TERMUX_SERVICE); executeIntent.putExtra(EXTRA_EXECUTE_IN_BACKGROUND, true); Context context = getApplicationContext(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // https://developer.android.com/about/versions/oreo/background.html context.startForegroundService(executeIntent); } else { context.startService(executeIntent); } Log.i(LOG_TAG, "Started job " + params.toString()); return false; }
private void sendMessage(int messageId, JobParameters params) { Message message=new Message(); message.arg1=messageId; message.what=params.getJobId(); message.obj=params.getExtras().getString(MyJobService.WORK_DURATION_KEY); try { messenger.send(message); } catch (RemoteException e) { e.printStackTrace(); } } }
private void finishEpgSync(JobParameters jobParams) { if (DEBUG) { Log.d(TAG, "taskFinished(" + jobParams.getJobId() + ")"); } mTaskArray.delete(jobParams.getJobId()); jobFinished(jobParams, false); if (DEBUG) { Log.d(TAG, "Send out broadcast"); } Intent intent = new Intent(ACTION_SYNC_STATUS_CHANGED); intent.putExtra( BUNDLE_KEY_INPUT_ID, jobParams.getExtras().getString(BUNDLE_KEY_INPUT_ID)); intent.putExtra(SYNC_STATUS, SYNC_FINISHED); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); }
@Override public boolean onStartJob(final JobParameters params) { // The work that this service "does" is simply wait for a certain duration and finish // the job (on another thread). sendMessage(MSG_COLOR_START, params.getJobId()); long duration = params.getExtras().getLong(WORK_DURATION_KEY); // Uses a handler to delay the execution of jobFinished(). Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { sendMessage(MSG_COLOR_STOP, params.getJobId()); jobFinished(params, false); } }, duration); Log.i(TAG, "on start job: " + params.getJobId()); // Return true as there's more work to be done with this job. return true; }
@Override public boolean onStartJob(JobParameters params) { PersistableBundle extras = params.getExtras(); String filePath = extras.getString(SCRIPT_FILE_PATH); Uri scriptUri = new Uri.Builder().scheme("com.termux.file").path(filePath).build(); Intent executeIntent = new Intent(ACTION_EXECUTE, scriptUri); executeIntent.setClassName("com.termux", TERMUX_SERVICE); executeIntent.putExtra(EXTRA_EXECUTE_IN_BACKGROUND, true); Context context = getApplicationContext(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // https://developer.android.com/about/versions/oreo/background.html context.startForegroundService(executeIntent); } else { context.startService(executeIntent); } return true; }
@Override public boolean onStartJob(JobParameters params) { if (DEBUG) { Log.d(TAG, "onStartJob(" + params.getJobId() + ")"); } // Broadcast status Intent intent = new Intent(ACTION_SYNC_STATUS_CHANGED); intent.putExtra(BUNDLE_KEY_INPUT_ID, params.getExtras().getString(BUNDLE_KEY_INPUT_ID)); intent.putExtra(SYNC_STATUS, SYNC_STARTED); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); EpgSyncTask epgSyncTask = new EpgSyncTask(params); synchronized (mTaskArray) { mTaskArray.put(params.getJobId(), epgSyncTask); } epgSyncTask.execute(); return true; }
private JobParameters toLocalParameters(android.app.job.JobParameters params, Bundle transientExtras) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return new JobParameters( params.getJobId(), new PersistableBundle(params.getExtras()), params.getTransientExtras(), params.isOverrideDeadlineExpired(), params.getTriggeredContentUris(), params.getTriggeredContentAuthorities()); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return new JobParameters( params.getJobId(), new PersistableBundle(params.getExtras()), transientExtras, params.isOverrideDeadlineExpired(), params.getTriggeredContentUris(), params.getTriggeredContentAuthorities()); } else { return new JobParameters( params.getJobId(), new PersistableBundle(params.getExtras()), transientExtras, params.isOverrideDeadlineExpired(), null, null); } } }