175 lines
6.3 KiB
Java
175 lines
6.3 KiB
Java
package com.discord.utilities.system;
|
|
|
|
import android.app.IntentService;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
import android.os.Messenger;
|
|
import android.os.Process;
|
|
import android.util.Log;
|
|
import c.d.b.a.a;
|
|
import com.discord.models.domain.ModelAuditLogEntry;
|
|
import com.discord.utilities.logging.Logger;
|
|
import com.discord.utilities.logging.LoggingProvider;
|
|
import com.discord.utilities.time.NtpClock;
|
|
import d0.z.d.m;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
/* compiled from: RemoteIntentService.kt */
|
|
public abstract class RemoteIntentService extends IntentService {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String MESSENGER_KEY = "com.discord.utilities.analytics.RemoteIntentService.MESSENGER_KEY";
|
|
private static final String TAG = "RemoteIntentService";
|
|
private static final int WHAT_CALLBACK_RESULT = 1;
|
|
private final String name;
|
|
|
|
/* compiled from: RemoteIntentService.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public static final /* synthetic */ String access$messageToString(Companion companion, Message message) {
|
|
return companion.messageToString(message);
|
|
}
|
|
|
|
private final String messageToString(Message message) {
|
|
StringBuilder L = a.L("Message(what=");
|
|
L.append(message.what);
|
|
L.append(", arg1=");
|
|
L.append(message.arg1);
|
|
L.append(", arg2=");
|
|
L.append(message.arg2);
|
|
L.append(", obj=");
|
|
L.append(message.obj);
|
|
L.append(", replyTo=");
|
|
L.append(message.replyTo);
|
|
L.append(')');
|
|
return L.toString();
|
|
}
|
|
|
|
public final void startRemoteServiceWithCallback(Context context, Class<?> cls, IpcCallback ipcCallback) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(cls, "serviceClass");
|
|
m.checkNotNullParameter(ipcCallback, "callback");
|
|
Logger logger = LoggingProvider.INSTANCE.get();
|
|
StringBuilder L = a.L("Starting service in remote process: ");
|
|
L.append(cls.getSimpleName());
|
|
L.append(", app pid=");
|
|
L.append(Process.myPid());
|
|
Logger.d$default(logger, RemoteIntentService.TAG, L.toString(), null, 4, null);
|
|
Intent intent = new Intent(context, cls);
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable(RemoteIntentService.MESSENGER_KEY, ipcCallback.getMessenger());
|
|
intent.putExtras(bundle);
|
|
context.startService(intent);
|
|
}
|
|
}
|
|
|
|
/* compiled from: RemoteIntentService.kt */
|
|
public static abstract class IpcCallback {
|
|
private final Handler handler;
|
|
private final String name;
|
|
|
|
public IpcCallback(String str, Looper looper) {
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_NAME);
|
|
m.checkNotNullParameter(looper, "callbackLooper");
|
|
this.name = str;
|
|
this.handler = new Handler(looper, new RemoteIntentService$IpcCallback$handler$1(this));
|
|
}
|
|
|
|
public static final /* synthetic */ String access$getName$p(IpcCallback ipcCallback) {
|
|
return ipcCallback.name;
|
|
}
|
|
|
|
public final Messenger getMessenger() {
|
|
return new Messenger(this.handler);
|
|
}
|
|
|
|
public abstract void onFailure(Throwable th);
|
|
|
|
public abstract void onSuccess(Bundle bundle);
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public RemoteIntentService(String str) {
|
|
super(str);
|
|
m.checkNotNullParameter(str, ModelAuditLogEntry.CHANGE_KEY_NAME);
|
|
this.name = str;
|
|
}
|
|
|
|
public abstract Bundle doWork(Intent intent);
|
|
|
|
@Override // android.app.IntentService, android.app.Service
|
|
public final void onCreate() {
|
|
super.onCreate();
|
|
StringBuilder J = a.J('[');
|
|
J.append(this.name);
|
|
J.append("] created, remote pid=");
|
|
J.append(Process.myPid());
|
|
Log.d(TAG, J.toString());
|
|
}
|
|
|
|
@Override // android.app.IntentService, android.app.Service
|
|
public final void onDestroy() {
|
|
StringBuilder J = a.J('[');
|
|
J.append(this.name);
|
|
J.append("] destroyed");
|
|
Log.d(TAG, J.toString());
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Override // android.app.IntentService
|
|
public final void onHandleIntent(Intent intent) {
|
|
Bundle th;
|
|
StringBuilder J = a.J('[');
|
|
J.append(this.name);
|
|
J.append("] onHandleIntent() start, pid=");
|
|
J.append(Process.myPid());
|
|
Log.d(TAG, J.toString());
|
|
if (intent == null) {
|
|
StringBuilder J2 = a.J('[');
|
|
J2.append(this.name);
|
|
J2.append("] null intent");
|
|
Log.d(TAG, J2.toString());
|
|
return;
|
|
}
|
|
NtpClock ntpClock = new NtpClock(c.m.a.a.a(this, null, null, 0, 0, 0, 62));
|
|
long currentTimeMillis = ntpClock.currentTimeMillis();
|
|
try {
|
|
th = doWork(intent);
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
StringBuilder J3 = a.J('[');
|
|
J3.append(this.name);
|
|
J3.append("] doWork returned error: ");
|
|
J3.append(th);
|
|
Log.e(TAG, J3.toString());
|
|
}
|
|
long currentTimeMillis2 = ntpClock.currentTimeMillis() - currentTimeMillis;
|
|
StringBuilder J4 = a.J('[');
|
|
J4.append(this.name);
|
|
J4.append("] doWork finished: ");
|
|
J4.append(currentTimeMillis2);
|
|
J4.append(" ms");
|
|
Log.d(TAG, J4.toString());
|
|
Message obtain = Message.obtain();
|
|
obtain.what = 1;
|
|
obtain.arg1 = (int) currentTimeMillis2;
|
|
obtain.obj = th;
|
|
Messenger messenger = (Messenger) intent.getParcelableExtra(MESSENGER_KEY);
|
|
if (messenger != null) {
|
|
messenger.send(obtain);
|
|
return;
|
|
}
|
|
StringBuilder J5 = a.J('[');
|
|
J5.append(this.name);
|
|
J5.append("] reply-to Messenger not set by caller");
|
|
Log.e(TAG, J5.toString());
|
|
}
|
|
}
|