调研通 v3.0.3版本的 MD5 值为:fe075d21227d488bdb9f6aa09d3b3f35
以下内容为反编译后的 UFTMqttService.java 源代码,内容仅作参考
package com.yyt.common.mqtt;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;
import c.o.a.a.b;
import com.yyt.common.YYTCordovaActivity;
import com.yyt.common.o.n;
import com.yyt.common.o.r;
import com.yyt.common.plugin.logger.c;
import java.util.Locale;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
public class UFTMqttService extends Service {
public static final String f11126f = "UFTMqttService";
public static String g = "UFT";
private static final String h = "UFTMqttService[UFTMqttService]";
public static String i = "";
public static final int j = 0;
public static int[] k = {0};
private static final String l = "tcp://%s";
private static final String m = "uft_%s";
private boolean f11127a = false;
private String f11128b;
private Handler f11129c;
private MqttDefaultFilePersistence f11130d;
private MqttClient f11131e;
public class a implements Runnable {
a() {
}
@Override
public void run() {
try {
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setCleanSession(true);
mqttConnectOptions.setUserName("admin");
mqttConnectOptions.setAutomaticReconnect(true);
mqttConnectOptions.setPassword("password".toCharArray());
mqttConnectOptions.setKeepAliveInterval(30);
UFTMqttService.this.f11131e.connect(mqttConnectOptions);
UFTMqttService.this.f11131e.subscribe(new String[]{UFTMqttService.this.f11128b}, UFTMqttService.k);
UFTMqttService.this.f11131e.setCallback(new com.yyt.common.mqtt.a(UFTMqttService.this.getApplicationContext()));
UFTMqttService.this.f11127a = true;
c.b(UFTMqttService.f11126f, "成功连接推送服务器并启动心跳包闹钟");
} catch (MqttException e2) {
Log.e(UFTMqttService.f11126f, e2.getMessage(), e2);
c.a(UFTMqttService.f11126f, "mClient.connect()异常." + e2.getMessage(), e2);
}
}
}
public static void d(Context context, String str) {
Intent intent = new Intent(context, (Class<?>) UFTMqttService.class);
intent.putExtra("MQTT_BROKER", str);
context.startService(intent);
}
private synchronized void e() {
String format = String.format(Locale.US, l, i);
c.b(f11126f, "连接推送服务器 设备id:" + this.f11128b + " with URL:" + format);
try {
this.f11131e = new MqttClient(format, this.f11128b, this.f11130d);
} catch (MqttException e2) {
c.b(f11126f, "new MqttClient异常,url:" + format + ",mDeviceId:" + this.f11128b + ",mDataStore:" + this.f11130d + "." + e2);
}
this.f11129c.post(new a());
}
@Override
public boolean isRestricted() {
return super.isRestricted();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
c.b(f11126f, "oncreate");
this.f11128b = r.s(Settings.Secure.getString(getContentResolver(), "android_id") + n.f(getApplicationContext()).packageName);
HandlerThread handlerThread = new HandlerThread(h);
handlerThread.start();
this.f11129c = new Handler(handlerThread.getLooper());
this.f11130d = new MqttDefaultFilePersistence(getCacheDir().getAbsolutePath());
}
@Override
public int onStartCommand(Intent intent, int i2, int i3) {
i = intent.getStringExtra("MQTT_BROKER");
c.b(f11126f, "接收到《启动》推送服务命令");
if (!this.f11127a) {
e();
}
super.onStartCommand(intent, i2, i3);
new Notification.Builder(this).setWhen(System.currentTimeMillis()).setContentTitle(getString(b.q.app_name)).setContentText("移动门户").setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), (Class<?>) YYTCordovaActivity.class), 0)).build();
return 3;
}
}