正在查看: bbinstant v6.24.0 应用的 KapchatService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: bbinstant v6.24.0 应用的 KapchatService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.adjetter.kapchatsdk;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import androidx.browser.customtabs.CustomTabsCallback;
import com.adjetter.kapchatsdk.structure.KapchatQANotification;
import com.adjetter.kapchatsdk.structure.MarkableElement;
import com.adjetter.kapchatsdk.structure.NoCarbon;
import com.google.gson.Gson;
import de.measite.minidns.DNSClient;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jivesoftware.smackx.carbons.CarbonManager;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.delay.packet.DelayInformation;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.forward.packet.Forwarded;
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
import org.jivesoftware.smackx.mam.MamManager;
import org.jivesoftware.smackx.mam.element.MamFinIQ;
import org.jivesoftware.smackx.mam.element.MamPrefsIQ;
import org.jivesoftware.smackx.ping.PingFailedListener;
import org.jivesoftware.smackx.ping.PingManager;
import org.jivesoftware.smackx.rsm.packet.RSMSet;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.jid.impl.JidCreate;
public class KapchatService extends Service {
public static Boolean isConnecting = Boolean.FALSE;
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Ringtone messageRingtone = null;
Chat newChat = null;
public class KapchatConnect extends AsyncTask<Void, Void, Void> {
String password;
String userName;
public KapchatConnect(String str, String str2) {
this.userName = str;
this.password = str2;
}
@Override
public Void doInBackground(Void... voidArr) {
String str;
try {
String str2 = this.userName;
if (str2 != null && !str2.equalsIgnoreCase("") && (str = this.password) != null && !str.equalsIgnoreCase("")) {
StringBuilder sb = new StringBuilder();
sb.append("login");
sb.append(this.userName);
sb.append("pass ");
sb.append(this.password);
if (KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("kapchatresource", "").equalsIgnoreCase("")) {
SharedPreferences.Editor edit = KapchatService.this.getSharedPreferences("kapchatpreference", 0).edit();
KapchatService kapchatService = KapchatService.this;
if (kapchatService.isTablet(kapchatService.getApplicationContext())) {
edit.putString("kapchatresource", KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("resourcePrefix", "CMApp") + "-android-tablet-" + (new Random().nextInt(900000) + 100000));
} else {
edit.putString("kapchatresource", KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("resourcePrefix", "CMApp") + "-android-mobile-" + (new Random().nextInt(900000) + 100000));
}
edit.apply();
}
org.jxmpp.jid.b domainBareFrom = JidCreate.domainBareFrom(KapchatHelper.serviceName);
XMPPTCPConnection xMPPTCPConnection = new XMPPTCPConnection(XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(this.userName, this.password).setServiceName(domainBareFrom).setHostAddress(InetAddress.getByName(KapchatHelper.Host)).setPort(5222).setDebuggerEnabled(true).setResource(KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("kapchatresource", "")).setXmppDomain(domainBareFrom).setSecurityMode(ConnectionConfiguration.SecurityMode.disabled).build());
KapchatConnection.mConnection = xMPPTCPConnection;
xMPPTCPConnection.setPacketReplyTimeout(15000L);
de.measite.minidns.dnsserverlookup.d dVar = de.measite.minidns.dnsserverlookup.b.INSTANCE;
DNSClient.removeDNSServerLookupMechanism(dVar);
DNSClient.addDnsServerLookupMechanism(dVar);
KapchatService.this.addConnectionListener();
KapchatConnection.mConnection.connect();
}
} catch (Exception e) {
System.out.println("###### crash is here 5 : " + e.getMessage());
e.printStackTrace();
KapchatConnection.mConnection = null;
}
return null;
}
@Override
public void onPostExecute(Void r1) {
super.onPostExecute((KapchatConnect) r1);
KapchatService.isConnecting = Boolean.FALSE;
}
}
public void addConnectionListener() {
XMPPTCPConnection xMPPTCPConnection = KapchatConnection.mConnection;
if (xMPPTCPConnection != null) {
xMPPTCPConnection.addConnectionListener(new ConnectionListener() {
public void authenticated(XMPPConnection xMPPConnection, boolean z) {
List list;
Presence presence = new Presence(Presence.Type.available);
presence.setStatus(CustomTabsCallback.ONLINE_EXTRAS_KEY);
ProviderManager.addExtensionProvider("forwarded", "urn:xmpp:forward:0", new ForwardedProvider());
ProviderManager.addExtensionProvider(MarkableElement.Markable, "urn:xmpp:chat-markers:0", new MarkableElement.Provider());
try {
KapchatConnection.mConnection.sendStanza(presence);
Bundle bundle = new Bundle();
bundle.putString("chatlistener", "yes");
Intent intent = new Intent("com.adjetter.kapchatupdate");
intent.putExtras(bundle);
KapchatService.this.sendBroadcast(intent);
} catch (Exception e) {
e.printStackTrace();
}
new KapchatOfflineMessage(KapchatService.this.getApplicationContext(), "");
try {
MamManager instanceFor = MamManager.getInstanceFor(KapchatConnection.mConnection);
if (instanceFor.isSupportedByServer()) {
SharedPreferences sharedPreferences = KapchatService.this.getSharedPreferences("kapchatpreference", 0);
String string = sharedPreferences.getString("lastLogout", "");
MamPrefsIQ mamPrefsIQ = instanceFor.retrieveArchivingPreferences().mamPrefs;
ArrayList arrayList = new ArrayList();
arrayList.add(JidCreate.bareFrom(KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("supportId", "")));
arrayList.add(JidCreate.bareFrom(KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("userName", "") + KapchatHelper.mServiceName));
instanceFor.updateArchivingPreferences(arrayList, mamPrefsIQ.getNeverJids(), MamPrefsIQ.DefaultBehavior.valueOf("always"));
if (string.equalsIgnoreCase("")) {
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.putString("lastLogout", "" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
edit.apply();
DataForm dataForm = new DataForm(DataForm.Type.submit);
FormField formField = new FormField("FORM_TYPE");
formField.setType(FormField.Type.hidden);
formField.addValue("urn:xmpp:mam:1");
dataForm.addField(formField);
FormField formField2 = new FormField("with");
formField2.addValue(KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("supportId", ""));
dataForm.addField(formField2);
MamManager.MamQueryResult page = instanceFor.page(dataForm, new RSMSet(30, "", RSMSet.PageDirection.before));
List list2 = page.forwardedMessages;
MamFinIQ mamFinIQ = page.mamFin;
if (mamFinIQ != null && mamFinIQ.getRSMSet() != null) {
StringBuilder sb = new StringBuilder();
sb.append("first index ");
sb.append(mamFinIQ.getRSMSet().toXML());
StringBuilder sb2 = new StringBuilder();
sb2.append("first index ");
sb2.append(mamFinIQ.getRSMSet().getFirst());
SharedPreferences.Editor edit2 = sharedPreferences.edit();
edit2.putString("firstIndex", "" + mamFinIQ.getRSMSet().getFirst());
edit2.apply();
}
ArrayList<Message> arrayList2 = new ArrayList<>();
ArrayList<DelayInformation> arrayList3 = new ArrayList<>();
for (int i = 0; i < list2.size(); i++) {
Message message = (Message) ((Forwarded) list2.get(i)).getForwardedStanza();
DelayInformation delayInformation = ((Forwarded) list2.get(i)).getDelayInformation();
if (message.getStanzaId() != null) {
if (i > 0) {
int i2 = 0;
while (true) {
if (i2 >= arrayList2.size()) {
arrayList2.add(message);
arrayList3.add(delayInformation);
break;
} else if (arrayList2.get(i2) == null || !message.getStanzaId().equalsIgnoreCase(arrayList2.get(i2).getStanzaId())) {
i2++;
}
}
} else {
arrayList2.add(message);
arrayList3.add(delayInformation);
}
}
}
if (arrayList2.size() > 0) {
KapchatService.this.insertBulkMessage(arrayList2, arrayList3, Boolean.FALSE);
return;
}
return;
}
StringBuilder sb3 = new StringBuilder();
sb3.append("lastlogouttime");
sb3.append(string);
Date parse = KapchatService.this.dateFormat.parse(string);
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(12, 5);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(parse);
calendar2.add(12, -2);
SharedPreferences.Editor edit3 = sharedPreferences.edit();
edit3.putString("lastLogout", "" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
edit3.apply();
StringBuilder sb4 = new StringBuilder();
sb4.append("starttime");
sb4.append(calendar2.getTime().toString());
StringBuilder sb5 = new StringBuilder();
sb5.append("endtime");
sb5.append(calendar.getTime().toString());
MamManager.MamQueryResult queryArchive = instanceFor.queryArchive(calendar2.getTime(), calendar.getTime());
if (queryArchive == null || (list = queryArchive.forwardedMessages) == null || list.size() <= 0) {
return;
}
ArrayList<Message> arrayList4 = new ArrayList<>();
ArrayList<DelayInformation> arrayList5 = new ArrayList<>();
for (int i3 = 0; i3 < list.size(); i3++) {
Message message2 = (Message) ((Forwarded) list.get(i3)).getForwardedStanza();
DelayInformation delayInformation2 = ((Forwarded) list.get(i3)).getDelayInformation();
if (message2.getStanzaId() != null) {
if (i3 > 0) {
int i4 = 0;
while (true) {
if (i4 >= arrayList4.size()) {
arrayList4.add(message2);
arrayList5.add(delayInformation2);
break;
} else if (arrayList4.get(i4) == null || !message2.getStanzaId().equalsIgnoreCase(arrayList4.get(i4).getStanzaId())) {
i4++;
}
}
} else {
arrayList4.add(message2);
arrayList5.add(delayInformation2);
}
}
StringBuilder sb6 = new StringBuilder();
sb6.append("message ");
sb6.append(message2.getBody());
sb6.append(" stanza ");
sb6.append(message2.getStanzaId());
}
if (arrayList4.size() > 0) {
KapchatService.this.insertBulkMessage(arrayList4, arrayList5, Boolean.TRUE);
}
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
public void connected(XMPPConnection xMPPConnection) {
KapchatService.isConnecting = Boolean.FALSE;
KapchatService.this.addpacketlistener();
ServiceDiscoveryManager instanceFor = ServiceDiscoveryManager.getInstanceFor(KapchatConnection.mConnection);
instanceFor.addFeature(NoCarbon.NAMESPACE);
instanceFor.addFeature("http://jabber.org/protocol/offline");
StringBuilder sb = new StringBuilder();
sb.append("connected ");
sb.append(KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("userName", ""));
try {
KapchatConnection.mConnection.login(KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("userName", ""), KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("password", ""));
} catch (Exception e) {
e.printStackTrace();
}
try {
CarbonManager.getInstanceFor(KapchatConnection.mConnection).enableCarbons();
PingManager instanceFor2 = PingManager.getInstanceFor(KapchatConnection.mConnection);
instanceFor2.setPingInterval(150000);
instanceFor2.registerPingFailedListener(new PingFailedListener() {
public void pingFailed() {
KapchatService kapchatService = KapchatService.this;
if (kapchatService.isOnline(kapchatService.getApplicationContext()) && KapchatService.isConnecting.booleanValue() && !KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("userName", "").equalsIgnoreCase("")) {
KapchatService.this.connect();
}
}
});
} catch (Exception e2) {
e2.printStackTrace();
}
}
public void connectionClosed() {
KapchatService.isConnecting = Boolean.FALSE;
KapchatConnection.mConnection = null;
KapchatService kapchatService = KapchatService.this;
if (kapchatService.isOnline(kapchatService.getApplicationContext()) && KapchatService.isConnecting.booleanValue() && !KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("userName", "").equalsIgnoreCase("")) {
KapchatService.this.connect();
}
}
public void connectionClosedOnError(Exception exc) {
KapchatService.isConnecting = Boolean.FALSE;
KapchatConnection.mConnection = null;
try {
if (KapchatHelper.foregrounded()) {
KapchatService.this.startService(new Intent(KapchatService.this.getBaseContext(), (Class<?>) NetworkconnectionChecker.class));
}
} catch (Exception e) {
e.printStackTrace();
}
KapchatService kapchatService = KapchatService.this;
if (kapchatService.isOnline(kapchatService.getApplicationContext()) && KapchatService.isConnecting.booleanValue() && !KapchatService.this.getSharedPreferences("kapchatpreference", 0).getString("userName", "").equalsIgnoreCase("")) {
KapchatService.this.connect();
}
}
public void reconnectingIn(int i) {
}
public void reconnectionFailed(Exception exc) {
}
public void reconnectionSuccessful() {
}
});
}
}
public void addpacketlistener() {
KapchatConnection.mConnection.addSyncStanzaListener(new StanzaListener() {
public void processStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
Message message = (Message) stanza;
CarbonExtension from = CarbonExtension.from(message);
ExtensionElement extension = message.getExtension("http://jabber.org/protocol/chatstates");
if (extension != null) {
StringBuilder sb = new StringBuilder();
sb.append("ele name ");
sb.append(extension.getElementName());
StringBuilder sb2 = new StringBuilder();
sb2.append("ele name ");
sb2.append(extension.getNamespace());
}
if (from == null) {
KapchatService.this.insertMessage(message, false);
return;
}
Message forwardedStanza = from.getForwarded().getForwardedStanza();
StringBuilder sb3 = new StringBuilder();
sb3.append("msg body ");
sb3.append(forwardedStanza.getBody());
KapchatService.this.insertMessage(forwardedStanza, true);
}
}, MessageTypeFilter.CHAT);
}
public void connect() {
try {
isConnecting = Boolean.TRUE;
new KapchatConnect(getSharedPreferences("kapchatpreference", 0).getString("userName", ""), getSharedPreferences("kapchatpreference", 0).getString("password", "")).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
public void insertBulkMessage(java.util.ArrayList<org.jivesoftware.smack.packet.Message> r18, java.util.ArrayList<org.jivesoftware.smackx.delay.packet.DelayInformation> r19, java.lang.Boolean r20) {
throw new UnsupportedOperationException("Method not decompiled: com.adjetter.kapchatsdk.KapchatService.insertBulkMessage(java.util.ArrayList, java.util.ArrayList, java.lang.Boolean):void");
}
public void insertMessage(org.jivesoftware.smack.packet.Message r19, boolean r20) {
throw new UnsupportedOperationException("Method not decompiled: com.adjetter.kapchatsdk.KapchatService.insertMessage(org.jivesoftware.smack.packet.Message, boolean):void");
}
public void insertQuestionOnly(String str) {
KapchatQANotification kapchatQANotification;
if (str.equalsIgnoreCase("") || (kapchatQANotification = (KapchatQANotification) new Gson().fromJson(str, KapchatQANotification.class)) == null) {
return;
}
ArrayList arrayList = new ArrayList();
arrayList.clear();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setSendDate("" + kapchatQANotification.getSentDate());
kapchatMessageList.setFromJid("" + kapchatQANotification.getFromJid());
kapchatMessageList.setToJid(kapchatQANotification.getToJid());
kapchatMessageList.setMessageType("1");
kapchatMessageList.setMessage(kapchatQANotification.getQuestion());
kapchatMessageList.setDownload("0");
kapchatMessageList.setDownloadPath("0");
kapchatMessageList.setMessageStatus("1");
kapchatMessageList.setMime("0");
kapchatMessageList.setMimeurl("0");
kapchatMessageList.setBlob(new byte[]{0});
kapchatMessageList.setStanzaId(kapchatQANotification.getStanzaId());
arrayList.add(kapchatMessageList);
new KapchatMessageInsertion(getApplicationContext(), null, Boolean.FALSE).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
}
public boolean isOnline(Context context) {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
public boolean isTablet(Context context) {
if (context == null) {
return false;
}
try {
return (context.getResources().getConfiguration().screenLayout & 15) >= 3;
} catch (Exception unused) {
return false;
}
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
XMPPTCPConnection.setUseStreamManagementDefault(false);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(false);
this.messageRingtone = RingtoneManager.getRingtone(getApplicationContext(), RingtoneManager.getDefaultUri(2));
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
if (KapchatConnection.mConnection != null) {
if (intent == null || intent.getExtras() == null || intent.getExtras().getString("reconnect") == null || getSharedPreferences("kapchatpreference", 0).getString("userName", "").equalsIgnoreCase("")) {
return 2;
}
isConnecting = Boolean.TRUE;
connect();
return 2;
}
if (intent != null && intent.getExtras() != null && intent.getExtras().getString("userName") != null) {
StringBuilder sb = new StringBuilder();
sb.append("username");
sb.append(intent.getExtras().getString("userName"));
StringBuilder sb2 = new StringBuilder();
sb2.append("password");
sb2.append(intent.getExtras().getString("password"));
if (!getSharedPreferences("kapchatpreference", 0).getString("userName", "").equalsIgnoreCase(intent.getExtras().getString("userName"))) {
SharedPreferences.Editor edit = getSharedPreferences("kapchatpreference", 0).edit();
edit.putString("userName", intent.getExtras().getString("userName"));
edit.putString("password", intent.getExtras().getString("password"));
edit.putString("contactName", intent.getExtras().getString("contactName"));
edit.putString("supportId", intent.getExtras().getString("supportId") + KapchatHelper.mServiceName);
edit.putString("kapchatNotificationList", "");
if (isTablet(getApplicationContext())) {
edit.putString("kapchatresource", getSharedPreferences("kapchatpreference", 0).getString("resourcePrefix", "CMApp") + "-android-tablet-" + (new Random().nextInt(900000) + 100000));
} else {
edit.putString("kapchatresource", getSharedPreferences("kapchatpreference", 0).getString("resourcePrefix", "CMApp") + "-android-mobile-" + (new Random().nextInt(900000) + 100000));
}
edit.putString("bucketName", "" + intent.getExtras().getString("bucketName"));
edit.putString("uploadSecretKey", "" + intent.getExtras().getString("uploadSecretKey"));
edit.putString("uploadAccessKey", "" + intent.getExtras().getString("uploadAccessKey"));
edit.apply();
}
}
if (getSharedPreferences("kapchatpreference", 0).getString("userName", "").equalsIgnoreCase("") || isConnecting.booleanValue()) {
return 2;
}
isConnecting = Boolean.TRUE;
String string = getSharedPreferences("kapchatpreference", 0).getString("userName", "");
if (string == null || string.equalsIgnoreCase("")) {
return 2;
}
StringBuilder sb3 = new StringBuilder();
sb3.append("username ");
sb3.append(string);
connect();
return 2;
}
@Override
public void onTaskRemoved(Intent intent) {
super.onTaskRemoved(intent);
}
}