Java Code Examples for android.app.job.JobParameters#getJobId()

The following examples show how to use android.app.job.JobParameters#getJobId() . 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: BackgroundDexOptService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: FetchJobService.java    From transistor-background-fetch with MIT License 6 votes vote down vote up
@Override
public boolean onStartJob(final JobParameters params) {
    PersistableBundle extras = params.getExtras();
    final String taskId = extras.getString(BackgroundFetchConfig.FIELD_TASK_ID);

    CompletionHandler completionHandler = new CompletionHandler() {
        @Override
        public void finish() {
            Log.d(BackgroundFetch.TAG, "- jobFinished");
            jobFinished(params, false);
        }
    };
    BGTask task = new BGTask(taskId, completionHandler, params.getJobId());
    BackgroundFetch.getInstance(getApplicationContext()).onFetch(task);

    return true;
}
 
Example 3
Source File: JobExecutionService.java    From BackPackTrackII with GNU General Public License v3.0 6 votes vote down vote up
@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 4
Source File: ScanJob.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: SyncJobService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {

    mLogger.purgeOldLogs();

    boolean isLoggable = Log.isLoggable(TAG, Log.VERBOSE);
    synchronized (mLock) {
        final int jobId = params.getJobId();
        mJobParamsMap.put(jobId, params);

        mStartedSyncs.delete(jobId);
        mJobStartUptimes.put(jobId, SystemClock.uptimeMillis());
    }
    Message m = Message.obtain();
    m.what = SyncManager.SyncHandler.MESSAGE_START_SYNC;
    SyncOperation op = SyncOperation.maybeCreateFromJobExtras(params.getExtras());

    mLogger.log("onStartJob() jobid=", params.getJobId(), " op=", op);

    if (op == null) {
        Slog.e(TAG, "Got invalid job " + params.getJobId());
        return false;
    }
    if (isLoggable) {
        Slog.v(TAG, "Got start job message " + op.target);
    }
    m.obj = op;
    sendMessage(m);
    return true;
}
 
Example 6
Source File: SyncJobService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public static String jobParametersToString(JobParameters params) {
    if (params == null) {
        return "job:null";
    } else {
        return "job:#" + params.getJobId() + ":"
                + "sr=[" + params.getStopReason() + "/" + params.getDebugStopReason() + "]:"
                + SyncOperation.maybeCreateFromJobExtras(params.getExtras());
    }
}
 
Example 7
Source File: BackgroundDexOptService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
    if (DEBUG_DEXOPT) {
        Log.i(TAG, "onStartJob");
    }

    // NOTE: PackageManagerService.isStorageLow uses a different set of criteria from
    // the checks above. This check is not "live" - the value is determined by a background
    // restart with a period of ~1 minute.
    PackageManagerService pm = (PackageManagerService)ServiceManager.getService("package");
    if (pm.isStorageLow()) {
        if (DEBUG_DEXOPT) {
            Log.i(TAG, "Low storage, skipping this run");
        }
        return false;
    }

    final ArraySet<String> pkgs = pm.getOptimizablePackages();
    if (pkgs.isEmpty()) {
        if (DEBUG_DEXOPT) {
            Log.i(TAG, "No packages to optimize");
        }
        return false;
    }

    boolean result;
    if (params.getJobId() == JOB_POST_BOOT_UPDATE) {
        result = runPostBootUpdate(params, pm, pkgs);
    } else {
        result = runIdleOptimization(params, pm, pkgs);
    }

    return result;
}
 
Example 8
Source File: ReportWatchlistJobService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStartJob(final JobParameters jobParameters) {
    if (jobParameters.getJobId() != REPORT_WATCHLIST_RECORDS_JOB_ID) {
        return false;
    }
    if (DEBUG) Slog.d(TAG, "Start scheduled job.");
    new NetworkWatchlistManager(this).reportWatchlistIfNecessary();
    jobFinished(jobParameters, false);
    return true;
}
 
Example 9
Source File: RemoteVerifyJob.java    From Auditor with MIT License 5 votes vote down vote up
@Override
public boolean onStartJob(final JobParameters params) {
    if (params.getJobId() == FIRST_RUN_JOB_ID && params.isOverrideDeadlineExpired()) {
        Log.d(TAG, "override deadline expired");
        return false;
    }
    task = new RemoteVerifyTask(params);
    task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
    return true;
}
 
Example 10
Source File: EpgSyncJobService.java    From xipl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStopJob(JobParameters params) {
    synchronized (mTaskArray) {
        int jobId = params.getJobId();
        EpgSyncTask epgSyncTask = mTaskArray.get(jobId);
        if (epgSyncTask != null) {
            epgSyncTask.cancel(true);
            mTaskArray.delete(params.getJobId());
        }
    }
    return false;
}
 
Example 11
Source File: StubJob.java    From container with GNU General Public License v3.0 5 votes vote down vote up
@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 12
Source File: MobileMessagingJobService.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: DataEstimator.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: EpgSyncJobService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStopJob(JobParameters params) {
    synchronized (mTaskArray) {
        int jobId = params.getJobId();
        EpgSyncTask epgSyncTask = mTaskArray.get(jobId);
        if (epgSyncTask != null) {
            epgSyncTask.cancel(true);
            mTaskArray.delete(params.getJobId());
        }
    }
    return false;
}
 
Example 15
Source File: SyncJobService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean onStopJob(JobParameters params) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Slog.v(TAG, "onStopJob called " + params.getJobId() + ", reason: "
                    + params.getStopReason());
        }
        final boolean readyToSync = SyncManager.readyToSync();

        mLogger.log("onStopJob() ", mLogger.jobParametersToString(params),
                " readyToSync=", readyToSync);
        synchronized (mLock) {
            final int jobId = params.getJobId();
            mJobParamsMap.remove(jobId);

            final long startUptime = mJobStartUptimes.get(jobId);
            final long nowUptime = SystemClock.uptimeMillis();
            final long runtime = nowUptime - startUptime;


            if (startUptime == 0) {
                wtf("Job " + jobId + " start uptime not found: "
                        + " params=" + jobParametersToString(params));
            } else if (runtime > 60 * 1000) {
                // WTF if startSyncH() hasn't happened, *unless* onStopJob() was called too soon.
                // (1 minute threshold.)
                // Also don't wtf when it's not ready to sync.
                if (readyToSync && !mStartedSyncs.get(jobId)) {
                    wtf("Job " + jobId + " didn't start: "
                            + " startUptime=" + startUptime
                            + " nowUptime=" + nowUptime
                            + " params=" + jobParametersToString(params));
                }
            } else if (runtime < 10 * 1000) {
                // This happens too in a normal case too, and it's rather too often.
                // Disable it for now.
//                // Job stopped too soon. WTF.
//                wtf("Job " + jobId + " stopped in " + runtime + " ms: "
//                        + " startUptime=" + startUptime
//                        + " nowUptime=" + nowUptime
//                        + " params=" + jobParametersToString(params));
            }

            mStartedSyncs.delete(jobId);
            mJobStartUptimes.delete(jobId);
        }
        Message m = Message.obtain();
        m.what = SyncManager.SyncHandler.MESSAGE_STOP_SYNC;
        m.obj = SyncOperation.maybeCreateFromJobExtras(params.getExtras());
        if (m.obj == null) {
            return false;
        }

        // Reschedule if this job was NOT explicitly canceled.
        m.arg1 = params.getStopReason() != JobParameters.REASON_CANCELED ? 1 : 0;
        // Apply backoff only if stop is called due to timeout.
        m.arg2 = params.getStopReason() == JobParameters.REASON_TIMEOUT ? 1 : 0;

        sendMessage(m);
        return false;
    }