Example usage for android.app.job JobParameters getJobId

List of usage examples for android.app.job JobParameters getJobId

Introduction

In this page you can find the example usage for android.app.job JobParameters getJobId.

Prototype

public int getJobId() 

Source Link

Usage

From source file:eu.faircode.netguard.ServiceJob.java

@Override
public boolean onStopJob(JobParameters params) {
    Log.i(TAG, "Stop job=" + params.getJobId());
    return true;/*  ww w . ja v a 2 s  .  c o  m*/
}

From source file:eu.faircode.netguard.ServiceJob.java

@Override
public boolean onStartJob(JobParameters params) {
    Log.i(TAG, "Start job=" + params.getJobId());

    new AsyncTask<JobParameters, Object, Object>() {

        @Override/*  w  ww  .ja va2  s .co  m*/
        protected JobParameters doInBackground(JobParameters... params) {
            Log.i(TAG, "Executing job=" + params[0].getJobId());

            HttpsURLConnection urlConnection = null;
            try {
                String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
                JSONObject json = new JSONObject();

                json.put("device", Util.sha256(android_id, ""));
                json.put("product", Build.DEVICE);
                json.put("sdk", Build.VERSION.SDK_INT);
                json.put("country", Locale.getDefault().getCountry());

                json.put("netguard", Util.getSelfVersionCode(ServiceJob.this));
                try {
                    json.put("store", getPackageManager().getInstallerPackageName(getPackageName()));
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    json.put("store", null);
                }

                for (String name : params[0].getExtras().keySet())
                    json.put(name, params[0].getExtras().get(name));

                urlConnection = (HttpsURLConnection) new URL(cUrl).openConnection();
                urlConnection.setConnectTimeout(cTimeOutMs);
                urlConnection.setReadTimeout(cTimeOutMs);
                urlConnection.setRequestProperty("Accept", "application/json");
                urlConnection.setRequestProperty("Content-type", "application/json");
                urlConnection.setRequestMethod("POST");
                urlConnection.setDoInput(true);
                urlConnection.setDoOutput(true);

                OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
                out.write(json.toString().getBytes()); // UTF-8
                out.flush();

                int code = urlConnection.getResponseCode();
                if (code != HttpsURLConnection.HTTP_OK)
                    throw new IOException("HTTP " + code);

                InputStreamReader isr = new InputStreamReader(urlConnection.getInputStream());
                Log.i(TAG, "Response=" + Util.readString(isr).toString());

                jobFinished(params[0], false);

                if ("rule".equals(params[0].getExtras().getString("type"))) {
                    SharedPreferences history = getSharedPreferences("history", Context.MODE_PRIVATE);
                    history.edit().putLong(params[0].getExtras().getString("package") + ":submitted",
                            new Date().getTime()).apply();
                }

            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                jobFinished(params[0], true);

            } finally {
                if (urlConnection != null)
                    urlConnection.disconnect();

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ignored) {
                }
            }

            return null;
        }
    }.execute(params);

    return true;
}

From source file:com.example.android.sampletvinput.syncservice.SyncJobService.java

@Override
public boolean onStartJob(JobParameters params) {
    if (DEBUG) {/*from ww  w . j  a  v  a 2 s  .co  m*/
        Log.d(TAG, "onStartJob(" + params.getJobId() + ")");
    }
    EpgSyncTask epgSyncTask = new EpgSyncTask(params);
    synchronized (mTaskArray) {
        mTaskArray.put(params.getJobId(), epgSyncTask);
    }
    epgSyncTask.execute();
    return true;
}

From source file:com.example.android.sampletvinput.syncservice.SyncJobService.java

@Override
public boolean onStopJob(JobParameters params) {
    synchronized (mTaskArray) {
        int jobId = params.getJobId();
        EpgSyncTask epgSyncTask = mTaskArray.get(jobId);
        if (epgSyncTask != null) {
            epgSyncTask.cancel(true);/*from   w w  w .  j a va 2s.c o  m*/
            mTaskArray.delete(params.getJobId());
        }
    }
    return false;
}

From source file:com.google.android.media.tv.companionlibrary.EpgSyncJobService.java

@Override
public boolean onStartJob(JobParameters params) {
    if (DEBUG) {//from  w w  w. j  a  va2  s.c o m
        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;
}