package com.example.fine.ndksample.ndkInterface;

import java.util.ArrayList;

/**
 * Messenger
 */
@SuppressWarnings("ALL")
public class Messenger {

    /**
     * Lock used to modify the content of {@link #sCallBacks}. Any write operation
     * performed on the array should be synchronized on this lock.
     */
    private static final Object mLock = new Object();

    private static ArrayList<MessageCallBack> sCallBacks = new ArrayList<>();

    public static void addListener(MessageCallBack callBack) {
        synchronized (mLock) {
            if (!sCallBacks.contains(callBack)) {
                sCallBacks.add(callBack);
            }
        }
    }

    public static void removeListener(MessageCallBack callBack) {
        synchronized (mLock) {
            if (sCallBacks.contains(callBack)) {
                sCallBacks.remove(callBack);
            }
        }
    }

    public void notifyMessage(String msg) {
        for (MessageCallBack callBack : sCallBacks) {
            callBack.onCallBack(msg);
        }
    }

    public interface MessageCallBack {
        void onCallBack(String msg);
    }
}

@@ -342,21 +342,22 @@
  Object 
-mLock
+sMutex
  = new O
@@ -522,37 +522,38 @@
   synchronized (
-mLock
+sMutex
 ) %7B%0A            
@@ -755,13 +755,14 @@
 ed (
-mLock
+sMutex
 ) %7B%0A
@@ -926,24 +926,60 @@
 ring msg) %7B%0A
+        synchronized (sMutex) %7B%0A    
         for 
@@ -1032,16 +1032,20 @@
         
+    
 callBack
@@ -1058,24 +1058,38 @@
 lBack(msg);%0A
+            %7D%0A
         %7D%0A  

update synchronized lock