android.app.job.JobParameters Java Examples
The following examples show how to use
android.app.job.JobParameters.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: myJobService.java From service with Apache License 2.0 | 6 votes |
@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). int max = params.getExtras().getInt("max", 6); //something low so I know it didn't work. Log.wtf(TAG, "max is " + max); // Process work here... we'll pretend by sleeping for 3 seconds. try { Thread.sleep(3000); } catch (InterruptedException e) { } Toast.makeText(getApplicationContext(), "Job: number is " + mGenerator.nextInt(max), Toast.LENGTH_SHORT).show(); Log.i(TAG, "Job: I'm working on something..."); //since there seems to be threshold on recurring. say 10 to 30 minutes, based on simple tests. //you could just reschedule the job here. Then the time frame can be much shorter. //scheduleJob(getApplicationContext(),max, true); // Return true as there's more work to be done with this job. return true; }
Example #2
Source File: ContentSynchronizationJobService.java From ml-authentication with Apache License 2.0 | 6 votes |
@Override public boolean onStartJob(JobParameters params) { Log.i(getClass().getName(), "onStartJob"); // Start processing work boolean isWifiEnabled = ConnectivityHelper.isWifiEnabled(getApplicationContext()); Log.i(getClass().getName(), "isWifiEnabled: " + isWifiEnabled); boolean isWifiConnected = ConnectivityHelper.isWifiConnected(getApplicationContext()); Log.i(getClass().getName(), "isWifiConnected: " + isWifiConnected); if (!isWifiEnabled) { // Toast.makeText(getApplicationContext(), getString(R.string.wifi_needs_to_be_enabled), Toast.LENGTH_SHORT).show(); Log.i(getClass().getName(), getString(R.string.wifi_needs_to_be_enabled)); } else if (!isWifiConnected) { // Toast.makeText(getApplicationContext(), getString(R.string.wifi_needs_to_be_connected), Toast.LENGTH_SHORT).show(); Log.i(getClass().getName(), getString(R.string.wifi_needs_to_be_connected)); } else { new ReadDeviceAsyncTask(getApplicationContext()).execute(); } boolean isWorkProcessingPending = false; return isWorkProcessingPending; }
Example #3
Source File: EpgSyncJobService.java From xipl with Apache License 2.0 | 6 votes |
@Override public boolean onStartJob(JobParameters params) { if (DEBUG) { Log.d(TAG, "onStartJob(" + params.getJobId() + ")"); } // Broadcast status Intent intent = createSyncStartedIntent(params.getExtras().getString(BUNDLE_KEY_INPUT_ID)); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); EpgSyncTask epgSyncTask = new EpgSyncTask(params); synchronized (mTaskArray) { mTaskArray.put(params.getJobId(), epgSyncTask); } // Run the task on a single threaded custom executor in order not to block the AsyncTasks // running on application side. epgSyncTask.executeOnExecutor(SINGLE_THREAD_EXECUTOR); return true; }
Example #4
Source File: FcmJobService.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Override public boolean onStartJob(JobParameters params) { Log.d(TAG, "onStartJob()"); if (BackgroundMessageRetriever.shouldIgnoreFetch(this)) { Log.i(TAG, "App is foregrounded. No need to run."); return false; } SignalExecutors.UNBOUNDED.execute(() -> { Context context = getApplicationContext(); BackgroundMessageRetriever retriever = ApplicationDependencies.getBackgroundMessageRetriever(); boolean success = retriever.retrieveMessages(context, new RestStrategy(), new RestStrategy()); if (success) { Log.i(TAG, "Successfully retrieved messages."); jobFinished(params, false); } else { Log.w(TAG, "Failed to retrieve messages. Scheduling a retry."); jobFinished(params, true); } }); return true; }
Example #5
Source File: BackgroundDexOptService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public boolean onStopJob(JobParameters params) { if (DEBUG_DEXOPT) { Log.i(TAG, "onStopJob"); } if (params.getJobId() == JOB_POST_BOOT_UPDATE) { mAbortPostBootUpdate.set(true); // Do not reschedule. // TODO: We should reschedule if we didn't process all apps, yet. return false; } else { mAbortIdleOptimization.set(true); // Reschedule the run. // TODO: Should this be dependent on the stop reason? return true; } }
Example #6
Source File: BackgroundTaskJobService.java From 365browser with Apache License 2.0 | 6 votes |
@Override public boolean onStopJob(JobParameters params) { ThreadUtils.assertOnUiThread(); if (!mCurrentTasks.containsKey(params.getJobId())) { Log.w(TAG, "Failed to stop job, because job with job id " + params.getJobId() + " does not exist."); return false; } BackgroundTask backgroundTask = mCurrentTasks.get(params.getJobId()); TaskParameters taskParams = BackgroundTaskSchedulerJobService.getTaskParametersFromJobParameters(params); boolean taskNeedsReschedule = backgroundTask.onStopTask(getApplicationContext(), taskParams); mCurrentTasks.remove(params.getJobId()); return taskNeedsReschedule; }
Example #7
Source File: BackgroundDexOptService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private boolean runIdleOptimization(final JobParameters jobParams, final PackageManagerService pm, final ArraySet<String> pkgs) { new Thread("BackgroundDexOptService_IdleOptimization") { @Override public void run() { int result = idleOptimization(pm, pkgs, BackgroundDexOptService.this); if (result != OPTIMIZE_ABORT_BY_JOB_SCHEDULER) { Log.w(TAG, "Idle optimizations aborted because of space constraints."); // If we didn't abort we ran to completion (or stopped because of space). // Abandon our timeslice and do not reschedule. jobFinished(jobParams, /* reschedule */ false); } } }.start(); return true; }
Example #8
Source File: EpgSyncJobService.java From androidtv-sample-inputs with Apache License 2.0 | 6 votes |
@Override public boolean onStartJob(JobParameters params) { if (DEBUG) { Log.d(TAG, "onStartJob(" + params.getJobId() + ")"); } // Broadcast status Intent intent = createSyncStartedIntent(params.getExtras().getString(BUNDLE_KEY_INPUT_ID)); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); EpgSyncTask epgSyncTask = new EpgSyncTask(params); synchronized (mTaskArray) { mTaskArray.put(params.getJobId(), epgSyncTask); } // Run the task on a single threaded custom executor in order not to block the AsyncTasks // running on application side. epgSyncTask.executeOnExecutor(SINGLE_THREAD_EXECUTOR); return true; }
Example #9
Source File: JobService.java From neverEndingProcessAndroid7- with MIT License | 6 votes |
/** * called if Android kills the job service * @param jobParameters * @return */ @Override public boolean onStopJob(JobParameters jobParameters) { Log.i(TAG, "Stopping job"); Intent broadcastIntent = new Intent(Globals.RESTART_INTENT); sendBroadcast(broadcastIntent); // give the time to run new Handler().postDelayed(new Runnable() { @Override public void run() { unregisterReceiver(restartSensorServiceReceiver); } }, 1000); return false; }
Example #10
Source File: LocationUpdateServiceRetryJob.java From your-local-weather with GNU General Public License v3.0 | 6 votes |
@Override public boolean onStartJob(JobParameters params) { this.params = params; connectedServicesCounter = 0; appendLog(this, TAG, "starting cells only location lookup"); if (locationUpdateService == null) { try { Intent intent = new Intent(getApplicationContext(), LocationUpdateService.class); getApplicationContext().bindService(intent, locationUpdateServiceConnection, Context.BIND_AUTO_CREATE); } catch (Exception ie) { appendLog(getBaseContext(), TAG, "currentWeatherServiceIsNotBound interrupted:", ie); } } else { locationUpdateService.updateNetworkLocation( params.getExtras().getBoolean("byLastLocationOnly"), null, params.getExtras().getInt("attempts")); jobFinished(params, false); } return true; }
Example #11
Source File: ScanJob.java From android-beacon-library with Apache License 2.0 | 6 votes |
@Override public boolean onStopJob(JobParameters params) { // See corresponding synchronized block in onStartJob synchronized(ScanJob.this) { mStopCalled = true; if (params.getJobId() == getPeriodicScanJobId(this)) { LogManager.i(TAG, "onStopJob called for periodic scan " + this); } else { LogManager.i(TAG, "onStopJob called for immediate scan " + this); } LogManager.d(TAG, "ScanJob Lifecycle STOP: "+ScanJob.this); // Cancel the stop timer. The OS is stopping prematurely mStopHandler.removeCallbacksAndMessages(null); stopScanning(); startPassiveScanIfNeeded(); if (mScanHelper != null) { mScanHelper.terminateThreads(); } } return false; }
Example #12
Source File: JobExecutionService.java From BackPackTrackII with GNU General Public License v3.0 | 6 votes |
@Override public boolean onStartJob(JobParameters jobParameters) { Log.i(TAG, "Start params=" + jobParameters); Intent intent = new Intent(this, BackgroundService.class); int id = jobParameters.getJobId(); if (id == JOB_UPLOAD_GPX) { intent.setAction(BackgroundService.ACTION_UPLOAD_GPX); intent.putExtras(Util.getBundle(jobParameters.getExtras())); } else if (id == JOB_CONNECTIVITY) intent.setAction(BackgroundService.ACTION_CONNECTIVITY); else Log.w(TAG, "Unknown job id=" + id); Log.i(TAG, "Starting intent=" + intent); startService(intent); return false; }
Example #13
Source File: JobService.java From timecat with Apache License 2.0 | 5 votes |
@Override public boolean onStopJob(JobParameters params) { LogUtil.d(TAG, "onStopJob"); startService(new Intent(JobService.this, TimeCatMonitorService.class)); startService(new Intent(JobService.this, ListenClipboardService.class)); return false; }
Example #14
Source File: AuthenticationJobService.java From ml-authentication with Apache License 2.0 | 5 votes |
@Override public boolean onStopJob(JobParameters jobParameters) { Log.i(getClass().getName(), "onStopJob"); if ((authenticationThread != null) && (authenticationThread.isAlive())){ authenticationThread.interrupt(); } return false; }
Example #15
Source File: RefreshService.java From ActivityDiary with GNU General Public License v3.0 | 5 votes |
private void refresh(JobParameters jobParameters) { if (jobCancelled) return; isWorking = false; boolean needsReschedule = false; ActivityHelper.helper.scheduleRefresh(); LocationHelper.helper.updateLocation(); jobFinished(jobParameters, needsReschedule); }
Example #16
Source File: JobSchedulerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public void onDeviceIdleStateChanged(boolean deviceIdle) { synchronized (mLock) { if (deviceIdle) { // When becoming idle, make sure no jobs are actively running, // except those using the idle exemption flag. for (int i=0; i<mActiveServices.size(); i++) { JobServiceContext jsc = mActiveServices.get(i); final JobStatus executing = jsc.getRunningJobLocked(); if (executing != null && (executing.getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) == 0) { jsc.cancelExecutingJobLocked(JobParameters.REASON_DEVICE_IDLE, "cancelled due to doze"); } } } else { // When coming out of idle, allow thing to start back up. if (mReadyToRock) { if (mLocalDeviceIdleController != null) { if (!mReportedActive) { mReportedActive = true; mLocalDeviceIdleController.setJobsActive(true); } } mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget(); } } } }
Example #17
Source File: FaceRecognitionTrainingJobService.java From ml-authentication with Apache License 2.0 | 5 votes |
@Override public boolean onStartJob(JobParameters jobParameters) { Log.i(getClass().getName(), "onStartJob"); if (StartPrefsHelper.activateAuthentication()) { this.jobParameters = jobParameters; trainingThread = new TrainingThread(this); trainingThread.start(); } return false; }
Example #18
Source File: AuthenticationJobService.java From ml-authentication with Apache License 2.0 | 5 votes |
@Override public boolean onStartJob(JobParameters jobParameters) { Log.i(getClass().getName(), "onStartJob"); if (StartPrefsHelper.activateAuthentication()){ this.jobParameters = jobParameters; authenticationThread = new AuthenticationThread(this); authenticationThread.start(); } return false; }
Example #19
Source File: StubJob.java From container with GNU General Public License v3.0 | 5 votes |
@Override public void stopJob(JobParameters jobParams) throws RemoteException { int jobId = jobParams.getJobId(); synchronized (mJobSessions) { JobSession session = mJobSessions.get(jobId); if (session != null) { session.stopSession(); } } }
Example #20
Source File: ItemSyncJobService.java From materialistic with Apache License 2.0 | 5 votes |
@Override public boolean onStopJob(JobParameters jobParameters) { String key = String.valueOf(jobParameters.getJobId()); if (mSyncDelegates.containsKey(key)) { mSyncDelegates.remove(key).stopSync(); } return true; }
Example #21
Source File: DataEstimator.java From batteryhub with Apache License 2.0 | 5 votes |
@Override public boolean onStartJob(JobParameters params) { final int jobID = params.getJobId(); Intent service = new Intent(mContext, DataEstimatorService.class); service.putExtra("OriginalAction", mAction); service.fillIn(mIntent, 0); startService(service); jobFinished(params, false); return true; }
Example #22
Source File: MountServiceIdler.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean onStopJob(JobParameters params) { // Once we kick off the fstrim we aren't actually interruptible; just note // that we don't need to call jobFinished(), and let everything happen in // the callback from the mount service. StorageManagerService ms = StorageManagerService.sSelf; if (ms != null) { ms.abortIdleMaint(mFinishCallback); synchronized (mFinishCallback) { mStarted = false; } } return false; }
Example #23
Source File: SynchronizeDatabaseJobService.java From leanback-homescreen-channels with Apache License 2.0 | 5 votes |
@Override public boolean onStopJob(JobParameters jobParameters) { if (mSynchronizeDatabaseTask != null) { mSynchronizeDatabaseTask.cancel(true); mSynchronizeDatabaseTask = null; } return true; }
Example #24
Source File: AddWatchNextService.java From leanback-homescreen-channels with Apache License 2.0 | 5 votes |
@Override public boolean onStartJob(JobParameters jobParameters) { AddWatchNextContinueInBackground newTask = new AddWatchNextContinueInBackground( jobParameters); newTask.execute(); return true; }
Example #25
Source File: ItemSyncJobService.java From materialistic with Apache License 2.0 | 5 votes |
@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; }
Example #26
Source File: MobileMessagingJobService.java From mobile-messaging-sdk-android with Apache License 2.0 | 5 votes |
@Override public boolean onStartJob(JobParameters params) { int connectivityScheduleId = getScheduleId(this, ON_NETWORK_AVAILABLE_JOB_ID); if (params.getJobId() == connectivityScheduleId) { if (TextUtils.isEmpty(mobileMessagingCore().getApplicationCode())) { return false; } MobileMessagingLogger.d(TAG, "Network available"); mobileMessagingCore().retrySyncOnNetworkAvailable(); return false; } return false; }
Example #27
Source File: BackgroundDexOptService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private boolean runPostBootUpdate(final JobParameters jobParams, final PackageManagerService pm, final ArraySet<String> pkgs) { if (mExitPostBootUpdate.get()) { // This job has already been superseded. Do not start it. return false; } new Thread("BackgroundDexOptService_PostBootUpdate") { @Override public void run() { postBootUpdate(jobParams, pm, pkgs); } }.start(); return true; }
Example #28
Source File: RefreshService.java From ActivityDiary with GNU General Public License v3.0 | 5 votes |
@Override public boolean onStopJob(JobParameters jobParameters) { jobCancelled = true; boolean needsReschedule = isWorking; jobFinished(jobParameters, needsReschedule); return needsReschedule; }
Example #29
Source File: BackgroundJobService.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
@Override public boolean onStartJob(final JobParameters params) { // TODO Do work directly on the main Thread // return false; // if no time consuming work remains to be done. // Execute additional work within a background thread. mJobTask = new AsyncTask<Void, Void, Boolean>() { @Override protected Boolean doInBackground(Void... voids) { // TODO Do your background work. // Return true if the job succeeded or false if it should be // rescheduled due to a transient failure return true; } @Override protected void onPostExecute(Boolean success) { // Reschedule the job if it did not succeed jobFinished(params, !success); } }; mJobTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); // You must return true to signify that you're doing work // in the background return true; }
Example #30
Source File: ColorExtractionService.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
@Override public boolean onStartJob(final JobParameters jobParameters) { mWorkerHandler.post(new Runnable() { @Override public void run() { WallpaperManager wallpaperManager = WallpaperManager.getInstance( ColorExtractionService.this); int wallpaperId = ExtractionUtils.getWallpaperId(wallpaperManager); ExtractedColors extractedColors = new ExtractedColors(); if (wallpaperManager.getWallpaperInfo() != null) { // We can't extract colors from live wallpapers; always use the default color. extractedColors.updateHotseatPalette(null); } else { // We extract colors for the hotseat and status bar separately, // since they only consider part of the wallpaper. extractedColors.updateHotseatPalette(getHotseatPalette()); if (PreferencesState.isLightStatusBarPrefEnabled(getBaseContext())) { extractedColors.updateStatusBarPalette(getStatusBarPalette()); } } // Save the extracted colors and wallpaper id to LauncherProvider. String colorsString = extractedColors.encodeAsString(); Bundle extras = new Bundle(); extras.putInt(LauncherSettings.Settings.EXTRA_WALLPAPER_ID, wallpaperId); extras.putString(LauncherSettings.Settings.EXTRA_EXTRACTED_COLORS, colorsString); getContentResolver().call( LauncherSettings.Settings.CONTENT_URI, LauncherSettings.Settings.METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID, null, extras); jobFinished(jobParameters, false /* needsReschedule */); } }); return true; }