mirror of
https://gitee.com/farsunset/cim.git
synced 2025-08-02 12:44:50 +08:00
修改一处android-cim-sdk可能出现ConcurrentModificationException的问题
This commit is contained in:
parent
0e6f3ee400
commit
0f38754cda
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.farsunset</groupId>
|
||||
<artifactId>cim-android-sdk</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.8.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
|
@ -63,44 +63,55 @@ public class CIMListenerManager {
|
||||
}
|
||||
|
||||
public static void notifyOnNetworkChanged(NetworkInfo info) {
|
||||
for (CIMEventListener listener : cimListeners) {
|
||||
listener.onNetworkChanged(info);
|
||||
Iterator<CIMEventListener> iterable = cimListeners.iterator();
|
||||
while (iterable.hasNext()) {
|
||||
iterable.next().onNetworkChanged(info);
|
||||
}
|
||||
}
|
||||
|
||||
public static void notifyOnConnectFinished(boolean hasAutoBind) {
|
||||
for (CIMEventListener listener : cimListeners) {
|
||||
listener.onConnectFinished(hasAutoBind);
|
||||
Iterator<CIMEventListener> iterable = cimListeners.iterator();
|
||||
while (iterable.hasNext()) {
|
||||
iterable.next().onConnectFinished(hasAutoBind);
|
||||
}
|
||||
}
|
||||
|
||||
public static void notifyOnMessageReceived(Message message) {
|
||||
for (CIMEventListener listener : cimListeners) {
|
||||
listener.onMessageReceived(message);
|
||||
Iterator<CIMEventListener> iterable = cimListeners.iterator();
|
||||
while (iterable.hasNext()) {
|
||||
iterable.next().onMessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void notifyOnConnectionClosed() {
|
||||
for (CIMEventListener listener : cimListeners) {
|
||||
listener.onConnectionClosed();
|
||||
Iterator<CIMEventListener> iterable = cimListeners.iterator();
|
||||
while (iterable.hasNext()) {
|
||||
iterable.next().onConnectionClosed();
|
||||
}
|
||||
}
|
||||
|
||||
public static void notifyOnConnectFailed() {
|
||||
for (CIMEventListener listener : cimListeners) {
|
||||
listener.onConnectFailed();
|
||||
|
||||
Iterator<CIMEventListener> iterable = cimListeners.iterator();
|
||||
while (iterable.hasNext()) {
|
||||
iterable.next().onConnectFailed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void notifyOnReplyReceived(ReplyBody body) {
|
||||
for (CIMEventListener listener : cimListeners) {
|
||||
listener.onReplyReceived(body);
|
||||
|
||||
Iterator<CIMEventListener> iterable = cimListeners.iterator();
|
||||
while (iterable.hasNext()) {
|
||||
iterable.next().onReplyReceived(body);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void notifyOnSendFinished(SentBody body) {
|
||||
for (CIMEventListener listener : cimListeners) {
|
||||
listener.onSendFinished(body);
|
||||
Iterator<CIMEventListener> iterable = cimListeners.iterator();
|
||||
while (iterable.hasNext()) {
|
||||
iterable.next().onSendFinished(body);
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,8 +120,9 @@ public class CIMListenerManager {
|
||||
}
|
||||
|
||||
public static void logListenersName() {
|
||||
for (CIMEventListener listener : cimListeners) {
|
||||
Log.i(CIMEventListener.class.getSimpleName(), "#######" + listener.getClass().getName() + "#######");
|
||||
Iterator<CIMEventListener> iterable = cimListeners.iterator();
|
||||
while (iterable.hasNext()) {
|
||||
Log.i(CIMEventListener.class.getSimpleName(), "#######" + iterable.next().getClass().getName() + "#######");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,23 +40,24 @@ import java.util.UUID;
|
||||
*/
|
||||
public class CIMPushManager {
|
||||
|
||||
protected static final String ACTION_ACTIVATE_PUSH_SERVICE = "ACTION_ACTIVATE_PUSH_SERVICE";
|
||||
|
||||
protected static final String ACTION_CREATE_CIM_CONNECTION = "ACTION_CREATE_CIM_CONNECTION";
|
||||
|
||||
protected static final String ACTION_DESTROY_CIM_SERVICE = "ACTION_DESTROY_CIM_SERVICE";
|
||||
|
||||
protected static final String ACTION_ACTIVATE_PUSH_SERVICE = "ACTION_ACTIVATE_PUSH_SERVICE";
|
||||
|
||||
protected static final String ACTION_SEND_REQUEST_BODY = "ACTION_SEND_REQUEST_BODY";
|
||||
|
||||
protected static final String ACTION_CLOSE_CIM_CONNECTION = "ACTION_CLOSE_CIM_CONNECTION";
|
||||
|
||||
protected static final String ACTION_DESTROY_CIM_SERVICE = "ACTION_DESTROY_CIM_SERVICE";
|
||||
|
||||
protected static final String ACTION_SET_LOGGER_EATABLE = "ACTION_SET_LOGGER_EATABLE";
|
||||
|
||||
protected static final String ACTION_SHOW_PERSIST_NOTIFICATION = "ACTION_SHOW_PERSIST_NOTIFICATION";
|
||||
|
||||
protected static final String ACTION_HIDE_PERSIST_NOTIFICATION = "ACTION_HIDE_PERSIST_NOTIFICATION";
|
||||
|
||||
protected static final String ACTION_SEND_PONG = "ACTION_SEND_PONG";
|
||||
protected static final String ACTION_CIM_CONNECTION_PONG = "ACTION_CIM_CONNECTION_PONG";
|
||||
|
||||
/**
|
||||
* 初始化,连接服务端,在程序启动页或者 在Application里调用
|
||||
@ -120,9 +121,10 @@ public class CIMPushManager {
|
||||
}
|
||||
|
||||
public static void pong(Context context) {
|
||||
Intent serviceIntent = new Intent(context, CIMPushService.class);
|
||||
serviceIntent.setAction(ACTION_SEND_PONG);
|
||||
startService(context, serviceIntent);
|
||||
if (isDestroyed(context) || isStopped(context)) {
|
||||
return;
|
||||
}
|
||||
context.sendBroadcast(new Intent(ACTION_CIM_CONNECTION_PONG));
|
||||
}
|
||||
|
||||
private static void sendBindRequest(Context context, String account) {
|
||||
|
@ -53,15 +53,16 @@ public class CIMPushService extends Service {
|
||||
static final String KEY_NOTIFICATION_CHANNEL = "KEY_NOTIFICATION_CHANNEL";
|
||||
static final String KEY_NOTIFICATION_ICON = "KEY_NOTIFICATION_ICON";
|
||||
|
||||
private final static String TRANSIENT_NTC_CHANNEL_ID = "CIM_PUSH_TRANSIENT_NTC_ID";
|
||||
private final static String PERSIST_NTC_CHANNEL_ID = "CIM_PUSH_PERSIST_NTC_ID";
|
||||
private static final String TRANSIENT_NTC_CHANNEL_ID = "CIM_PUSH_TRANSIENT_NTC_ID";
|
||||
private static final String PERSIST_NTC_CHANNEL_ID = "CIM_PUSH_PERSIST_NTC_ID";
|
||||
|
||||
private final static int NOTIFICATION_ID = Integer.MAX_VALUE;
|
||||
private static final int NOTIFICATION_ID = Integer.MAX_VALUE;
|
||||
|
||||
private final static int PERSIST_NOTIFICATION_ID = Integer.MIN_VALUE;
|
||||
private static final int PERSIST_NOTIFICATION_ID = Integer.MIN_VALUE;
|
||||
|
||||
private CIMConnectorManager connectorManager;
|
||||
private KeepAliveBroadcastReceiver keepAliveReceiver;
|
||||
private InnerEventBroadcastReceiver innerEventReceiver;
|
||||
private ConnectivityManager connectivityManager;
|
||||
private NotificationManager notificationManager;
|
||||
private final AtomicBoolean persistHolder = new AtomicBoolean(false);
|
||||
@ -71,8 +72,11 @@ public class CIMPushService extends Service {
|
||||
public void onCreate() {
|
||||
connectorManager = CIMConnectorManager.getManager(this.getApplicationContext());
|
||||
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
||||
innerEventReceiver = new InnerEventBroadcastReceiver();
|
||||
registerReceiver(innerEventReceiver, innerEventReceiver.getIntentFilter());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
keepAliveReceiver = new KeepAliveBroadcastReceiver();
|
||||
registerReceiver(keepAliveReceiver, keepAliveReceiver.getIntentFilter());
|
||||
}
|
||||
@ -147,8 +151,9 @@ public class CIMPushService extends Service {
|
||||
handleKeepAlive();
|
||||
}
|
||||
|
||||
if (CIMPushManager.ACTION_SEND_PONG.equals(action)) {
|
||||
connectorManager.send(Pong.getInstance());
|
||||
if (CIMPushManager.ACTION_DESTROY_CIM_SERVICE.equals(action)) {
|
||||
connectorManager.close();
|
||||
this.stopSelf();
|
||||
}
|
||||
|
||||
if (CIMPushManager.ACTION_SET_LOGGER_EATABLE.equals(action)) {
|
||||
@ -156,11 +161,6 @@ public class CIMPushService extends Service {
|
||||
CIMLogger.getLogger().debugMode(enable);
|
||||
}
|
||||
|
||||
if (CIMPushManager.ACTION_DESTROY_CIM_SERVICE.equals(action)) {
|
||||
connectorManager.close();
|
||||
this.stopSelf();
|
||||
}
|
||||
|
||||
if (CIMPushManager.ACTION_SHOW_PERSIST_NOTIFICATION.equals(action)) {
|
||||
createPersistNotification(intent.getStringExtra(KEY_NOTIFICATION_CHANNEL),
|
||||
intent.getStringExtra(KEY_NOTIFICATION_MESSAGE),
|
||||
@ -239,6 +239,9 @@ public class CIMPushService extends Service {
|
||||
|
||||
persistHolder.set(false);
|
||||
|
||||
unregisterReceiver(innerEventReceiver);
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
unregisterReceiver(keepAliveReceiver);
|
||||
}
|
||||
@ -320,4 +323,19 @@ public class CIMPushService extends Service {
|
||||
|
||||
}
|
||||
|
||||
private class InnerEventBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
connectorManager.send(Pong.getInstance());
|
||||
}
|
||||
|
||||
public IntentFilter getIntentFilter() {
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(CIMPushManager.ACTION_CIM_CONNECTION_PONG);
|
||||
return intentFilter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user