MD5 校验值:4052dee5c91531cc54bd705da77dcf1d
JobIntentService.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.onesignal; import android.app.Service; import android.app.job.JobInfo; import android.app.job.JobParameters; import android.app.job.JobScheduler; import android.app.job.JobServiceEngine; import android.app.job.JobWorkItem; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Build; import android.os.IBinder; import android.os.PowerManager; import android.util.Log; import java.util.ArrayList; import java.util.HashMap; public abstract class JobIntentService extends Service { static final Object f19936v = new Object(); static final HashMap<ComponentNameWithWakeful, WorkEnqueuer> f19937w = new HashMap<>(); CompatJobEngine f19938o; WorkEnqueuer f19939p; CommandProcessor f19940q; boolean f19941r = false; boolean f19942s = false; boolean f19943t = false; final ArrayList<CompatWorkItem> f19944u = new ArrayList<>(); public final class CommandProcessor extends AsyncTask<Void, Void, Void> { CommandProcessor() { } @Override public Void doInBackground(Void... voidArr) { while (true) { GenericWorkItem a10 = JobIntentService.this.a(); if (a10 == null) { return null; } JobIntentService.this.g(a10.getIntent()); a10.complete(); } } @Override public void onCancelled(Void r12) { JobIntentService.this.i(); } @Override public void onPostExecute(Void r12) { JobIntentService.this.i(); } } public interface CompatJobEngine { IBinder compatGetBinder(); GenericWorkItem dequeueWork(); } public static final class CompatWorkEnqueuer extends WorkEnqueuer { private final Context mContext; private final PowerManager.WakeLock mLaunchWakeLock; boolean mLaunchingService; private final PowerManager.WakeLock mRunWakeLock; boolean mServiceProcessing; CompatWorkEnqueuer(Context context, ComponentName componentName) { super(componentName); this.mContext = context.getApplicationContext(); PowerManager powerManager = (PowerManager) context.getSystemService("power"); PowerManager.WakeLock newWakeLock = powerManager.newWakeLock(1, componentName.getClassName() + ":launch"); this.mLaunchWakeLock = newWakeLock; newWakeLock.setReferenceCounted(false); PowerManager.WakeLock newWakeLock2 = powerManager.newWakeLock(1, componentName.getClassName() + ":run"); this.mRunWakeLock = newWakeLock2; newWakeLock2.setReferenceCounted(false); } @Override void enqueueWork(Intent intent) { Intent intent2 = new Intent(intent); intent2.setComponent(this.mComponentName); if (this.mContext.startService(intent2) != null) { synchronized (this) { if (!this.mLaunchingService) { this.mLaunchingService = true; if (!this.mServiceProcessing) { this.mLaunchWakeLock.acquire(60000L); } } } } } @Override public void serviceProcessingFinished() { synchronized (this) { if (this.mServiceProcessing) { if (this.mLaunchingService) { this.mLaunchWakeLock.acquire(60000L); } this.mServiceProcessing = false; this.mRunWakeLock.release(); } } } @Override public void serviceProcessingStarted() { synchronized (this) { if (!this.mServiceProcessing) { this.mServiceProcessing = true; this.mRunWakeLock.acquire(600000L); this.mLaunchWakeLock.release(); } } } @Override public void serviceStartReceived() { synchronized (this) { this.mLaunchingService = false; } } } public final class CompatWorkItem implements GenericWorkItem { final Intent mIntent; final int mStartId; CompatWorkItem(Intent intent, int i10) { this.mIntent = intent; this.mStartId = i10; } @Override public void complete() { JobIntentService.this.stopSelf(this.mStartId); } @Override public Intent getIntent() { return this.mIntent; } } public static class ComponentNameWithWakeful { private ComponentName componentName; private boolean useWakefulService; ComponentNameWithWakeful(ComponentName componentName, boolean z9) { this.componentName = componentName; this.useWakefulService = z9; } } public interface GenericWorkItem { void complete(); Intent getIntent(); } static final class JobServiceEngineImpl extends JobServiceEngine implements CompatJobEngine { static final boolean DEBUG = false; static final String TAG = "JobServiceEngineImpl"; final Object mLock; JobParameters mParams; final JobIntentService mService; final class WrapperWorkItem implements GenericWorkItem { final JobWorkItem mJobWork; WrapperWorkItem(JobWorkItem jobWorkItem) { this.mJobWork = jobWorkItem; } @Override public void complete() { String str; String str2; synchronized (JobServiceEngineImpl.this.mLock) { JobParameters jobParameters = JobServiceEngineImpl.this.mParams; if (jobParameters != null) { try { jobParameters.completeWork(this.mJobWork); } catch (IllegalArgumentException e10) { e = e10; str = JobServiceEngineImpl.TAG; str2 = "IllegalArgumentException: Failed to run mParams.completeWork(mJobWork)!"; Log.e(str, str2, e); } catch (SecurityException e11) { e = e11; str = JobServiceEngineImpl.TAG; str2 = "SecurityException: Failed to run mParams.completeWork(mJobWork)!"; Log.e(str, str2, e); } } } } @Override public Intent getIntent() { return this.mJobWork.getIntent(); } } JobServiceEngineImpl(JobIntentService jobIntentService) { super(jobIntentService); this.mLock = new Object(); this.mService = jobIntentService; } @Override public IBinder compatGetBinder() { return getBinder(); } @Override public GenericWorkItem dequeueWork() { synchronized (this.mLock) { JobParameters jobParameters = this.mParams; if (jobParameters == null) { return null; } try { JobWorkItem dequeueWork = jobParameters.dequeueWork(); if (dequeueWork == null) { return null; } dequeueWork.getIntent().setExtrasClassLoader(this.mService.getClassLoader()); return new WrapperWorkItem(dequeueWork); } catch (SecurityException e10) { Log.e(TAG, "Failed to run mParams.dequeueWork()!", e10); return null; } } } @Override public boolean onStartJob(JobParameters jobParameters) { this.mParams = jobParameters; this.mService.e(false); return true; } @Override public boolean onStopJob(JobParameters jobParameters) { boolean b10 = this.mService.b(); synchronized (this.mLock) { this.mParams = null; } return b10; } } public static final class JobWorkEnqueuer extends WorkEnqueuer { private final JobInfo mJobInfo; private final JobScheduler mJobScheduler; JobWorkEnqueuer(Context context, ComponentName componentName, int i10) { super(componentName); ensureJobId(i10); this.mJobInfo = new JobInfo.Builder(i10, this.mComponentName).setOverrideDeadline(0L).build(); this.mJobScheduler = (JobScheduler) context.getApplicationContext().getSystemService("jobscheduler"); } @Override void enqueueWork(Intent intent) { this.mJobScheduler.enqueue(this.mJobInfo, new JobWorkItem(intent)); } } public static abstract class WorkEnqueuer { final ComponentName mComponentName; boolean mHasJobId; int mJobId; WorkEnqueuer(ComponentName componentName) { this.mComponentName = componentName; } abstract void enqueueWork(Intent intent); void ensureJobId(int i10) { if (!this.mHasJobId) { this.mHasJobId = true; this.mJobId = i10; } else { if (this.mJobId == i10) { return; } throw new IllegalArgumentException("Given job ID " + i10 + " is different than previous " + this.mJobId); } } public void serviceProcessingFinished() { } public void serviceProcessingStarted() { } public void serviceStartReceived() { } } public static void c(Context context, ComponentName componentName, int i10, Intent intent, boolean z9) { if (intent == null) { throw new IllegalArgumentException("work must not be null"); } synchronized (f19936v) { WorkEnqueuer f10 = f(context, componentName, true, i10, z9); f10.ensureJobId(i10); try { f10.enqueueWork(intent); } catch (IllegalStateException e10) { if (!z9) { throw e10; } f(context, componentName, true, i10, false).enqueueWork(intent); } } } public static void d(Context context, Class cls, int i10, Intent intent, boolean z9) { c(context, new ComponentName(context, (Class<?>) cls), i10, intent, z9); } static WorkEnqueuer f(Context context, ComponentName componentName, boolean z9, int i10, boolean z10) { WorkEnqueuer compatWorkEnqueuer; ComponentNameWithWakeful componentNameWithWakeful = new ComponentNameWithWakeful(componentName, z10); HashMap<ComponentNameWithWakeful, WorkEnqueuer> hashMap = f19937w; WorkEnqueuer workEnqueuer = hashMap.get(componentNameWithWakeful); if (workEnqueuer != null) { return workEnqueuer; } if (Build.VERSION.SDK_INT < 26 || z10) { compatWorkEnqueuer = new CompatWorkEnqueuer(context, componentName); } else { if (!z9) { throw new IllegalArgumentException("Can't be here without a job id"); } compatWorkEnqueuer = new JobWorkEnqueuer(context, componentName, i10); } WorkEnqueuer workEnqueuer2 = compatWorkEnqueuer; hashMap.put(componentNameWithWakeful, workEnqueuer2); return workEnqueuer2; } GenericWorkItem a() { GenericWorkItem dequeueWork; CompatJobEngine compatJobEngine = this.f19938o; if (compatJobEngine != null && (dequeueWork = compatJobEngine.dequeueWork()) != null) { return dequeueWork; } synchronized (this.f19944u) { if (this.f19944u.size() > 0) { return this.f19944u.remove(0); } return null; } } boolean b() { CommandProcessor commandProcessor = this.f19940q; if (commandProcessor != null) { commandProcessor.cancel(this.f19941r); } this.f19942s = true; return h(); } void e(boolean z9) { if (this.f19940q == null) { this.f19940q = new CommandProcessor(); WorkEnqueuer workEnqueuer = this.f19939p; if (workEnqueuer != null && z9) { workEnqueuer.serviceProcessingStarted(); } this.f19940q.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]); } } protected abstract void g(Intent intent); public boolean h() { return true; } void i() { ArrayList<CompatWorkItem> arrayList = this.f19944u; if (arrayList != null) { synchronized (arrayList) { this.f19940q = null; ArrayList<CompatWorkItem> arrayList2 = this.f19944u; if (arrayList2 != null && arrayList2.size() > 0) { e(false); } else if (!this.f19943t) { this.f19939p.serviceProcessingFinished(); } } } } @Override public IBinder onBind(Intent intent) { CompatJobEngine compatJobEngine = this.f19938o; if (compatJobEngine != null) { return compatJobEngine.compatGetBinder(); } return null; } @Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= 26) { this.f19938o = new JobServiceEngineImpl(this); this.f19939p = null; } this.f19939p = f(this, new ComponentName(this, getClass()), false, 0, true); } @Override public void onDestroy() { super.onDestroy(); b(); synchronized (this.f19944u) { this.f19943t = true; this.f19939p.serviceProcessingFinished(); } } @Override public int onStartCommand(Intent intent, int i10, int i11) { this.f19939p.serviceStartReceived(); synchronized (this.f19944u) { ArrayList<CompatWorkItem> arrayList = this.f19944u; if (intent == null) { intent = new Intent(); } arrayList.add(new CompatWorkItem(intent, i11)); e(true); } return 3; } }