MD5 校验值:51aae3247d6bd20bca268c4c9a4dd21c
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 f12999n = new Object(); static final HashMap f13000o = new HashMap(); CompatJobEngine f13001g; WorkEnqueuer f13002h; CommandProcessor f13003i; boolean f13004j = false; boolean f13005k = false; boolean f13006l = false; final ArrayList f13007m = new ArrayList(); public final class CommandProcessor extends AsyncTask<Void, Void, Void> { CommandProcessor() { } @Override public Void doInBackground(Void... voidArr) { while (true) { GenericWorkItem a5 = JobIntentService.this.a(); if (a5 == null) { return null; } JobIntentService.this.g(a5.getIntent()); a5.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) { try { if (!this.mLaunchingService) { this.mLaunchingService = true; if (!this.mServiceProcessing) { this.mLaunchWakeLock.acquire(60000L); } } } finally { } } } } @Override public void serviceProcessingFinished() { synchronized (this) { try { if (this.mServiceProcessing) { if (this.mLaunchingService) { this.mLaunchWakeLock.acquire(60000L); } this.mServiceProcessing = false; this.mRunWakeLock.release(); } } catch (Throwable th) { throw th; } } } @Override public void serviceProcessingStarted() { synchronized (this) { try { if (!this.mServiceProcessing) { this.mServiceProcessing = true; this.mRunWakeLock.acquire(600000L); this.mLaunchWakeLock.release(); } } catch (Throwable th) { throw th; } } } @Override public void serviceStartReceived() { synchronized (this) { this.mLaunchingService = false; } } } final class CompatWorkItem implements GenericWorkItem { final Intent mIntent; final int mStartId; CompatWorkItem(Intent intent, int i5) { this.mIntent = intent; this.mStartId = i5; } @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 z5) { this.componentName = componentName; this.useWakefulService = z5; } } 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 e5) { e = e5; str = JobServiceEngineImpl.TAG; str2 = "IllegalArgumentException: Failed to run mParams.completeWork(mJobWork)!"; Log.e(str, str2, e); } catch (SecurityException e6) { e = e6; str = JobServiceEngineImpl.TAG; str2 = "SecurityException: Failed to run mParams.completeWork(mJobWork)!"; Log.e(str, str2, e); } } } } @Override public Intent getIntent() { Intent intent; intent = this.mJobWork.getIntent(); return intent; } } JobServiceEngineImpl(JobIntentService jobIntentService) { super(jobIntentService); this.mLock = new Object(); this.mService = jobIntentService; } @Override public IBinder compatGetBinder() { IBinder binder; binder = getBinder(); return binder; } @Override public GenericWorkItem dequeueWork() { JobWorkItem dequeueWork; Intent intent; synchronized (this.mLock) { JobParameters jobParameters = this.mParams; if (jobParameters == null) { return null; } try { dequeueWork = jobParameters.dequeueWork(); if (dequeueWork == null) { return null; } intent = dequeueWork.getIntent(); intent.setExtrasClassLoader(this.mService.getClassLoader()); return new WrapperWorkItem(dequeueWork); } catch (SecurityException e5) { Log.e(TAG, "Failed to run mParams.dequeueWork()!", e5); return null; } } } public boolean onStartJob(JobParameters jobParameters) { this.mParams = jobParameters; this.mService.e(DEBUG); return true; } public boolean onStopJob(JobParameters jobParameters) { boolean b5 = this.mService.b(); synchronized (this.mLock) { this.mParams = null; } return b5; } } public static final class JobWorkEnqueuer extends WorkEnqueuer { private final JobInfo mJobInfo; private final JobScheduler mJobScheduler; JobWorkEnqueuer(Context context, ComponentName componentName, int i5) { super(componentName); ensureJobId(i5); this.mJobInfo = new JobInfo.Builder(i5, this.mComponentName).setOverrideDeadline(0L).build(); this.mJobScheduler = (JobScheduler) context.getApplicationContext().getSystemService("jobscheduler"); } @Override void enqueueWork(Intent intent) { this.mJobScheduler.enqueue(this.mJobInfo, M.a(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 i5) { if (!this.mHasJobId) { this.mHasJobId = true; this.mJobId = i5; } else { if (this.mJobId == i5) { return; } throw new IllegalArgumentException("Given job ID " + i5 + " is different than previous " + this.mJobId); } } public void serviceProcessingFinished() { } public void serviceProcessingStarted() { } public void serviceStartReceived() { } } public static void c(Context context, ComponentName componentName, int i5, Intent intent, boolean z5) { if (intent == null) { throw new IllegalArgumentException("work must not be null"); } synchronized (f12999n) { WorkEnqueuer f5 = f(context, componentName, true, i5, z5); f5.ensureJobId(i5); try { f5.enqueueWork(intent); } catch (IllegalStateException e5) { if (!z5) { throw e5; } f(context, componentName, true, i5, false).enqueueWork(intent); } } } public static void d(Context context, Class cls, int i5, Intent intent, boolean z5) { c(context, new ComponentName(context, (Class<?>) cls), i5, intent, z5); } static WorkEnqueuer f(Context context, ComponentName componentName, boolean z5, int i5, boolean z6) { WorkEnqueuer compatWorkEnqueuer; ComponentNameWithWakeful componentNameWithWakeful = new ComponentNameWithWakeful(componentName, z6); HashMap hashMap = f13000o; WorkEnqueuer workEnqueuer = (WorkEnqueuer) hashMap.get(componentNameWithWakeful); if (workEnqueuer == null) { if (Build.VERSION.SDK_INT < 26 || z6) { compatWorkEnqueuer = new CompatWorkEnqueuer(context, componentName); } else { if (!z5) { throw new IllegalArgumentException("Can't be here without a job id"); } compatWorkEnqueuer = new JobWorkEnqueuer(context, componentName, i5); } workEnqueuer = compatWorkEnqueuer; hashMap.put(componentNameWithWakeful, workEnqueuer); } return workEnqueuer; } GenericWorkItem a() { GenericWorkItem dequeueWork; CompatJobEngine compatJobEngine = this.f13001g; if (compatJobEngine != null && (dequeueWork = compatJobEngine.dequeueWork()) != null) { return dequeueWork; } synchronized (this.f13007m) { try { if (this.f13007m.size() > 0) { return (GenericWorkItem) this.f13007m.remove(0); } return null; } catch (Throwable th) { throw th; } } } boolean b() { CommandProcessor commandProcessor = this.f13003i; if (commandProcessor != null) { commandProcessor.cancel(this.f13004j); } this.f13005k = true; return h(); } void e(boolean z5) { if (this.f13003i == null) { this.f13003i = new CommandProcessor(); WorkEnqueuer workEnqueuer = this.f13002h; if (workEnqueuer != null && z5) { workEnqueuer.serviceProcessingStarted(); } this.f13003i.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]); } } protected abstract void g(Intent intent); public boolean h() { return true; } void i() { ArrayList arrayList = this.f13007m; if (arrayList != null) { synchronized (arrayList) { try { this.f13003i = null; ArrayList arrayList2 = this.f13007m; if (arrayList2 != null && arrayList2.size() > 0) { e(false); } else if (!this.f13006l) { this.f13002h.serviceProcessingFinished(); } } finally { } } } } @Override public IBinder onBind(Intent intent) { CompatJobEngine compatJobEngine = this.f13001g; if (compatJobEngine != null) { return compatJobEngine.compatGetBinder(); } return null; } @Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= 26) { this.f13001g = new JobServiceEngineImpl(this); this.f13002h = null; } this.f13002h = f(this, new ComponentName(this, getClass()), false, 0, true); } @Override public void onDestroy() { super.onDestroy(); b(); synchronized (this.f13007m) { this.f13006l = true; this.f13002h.serviceProcessingFinished(); } } @Override public int onStartCommand(Intent intent, int i5, int i6) { this.f13002h.serviceStartReceived(); synchronized (this.f13007m) { ArrayList arrayList = this.f13007m; if (intent == null) { intent = new Intent(); } arrayList.add(new CompatWorkItem(intent, i6)); e(true); } return 3; } }