| 
					
				 | 
			
			
				@@ -1,5 +1,6 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package org.iotivity.bridge.homeserver; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.annotation.SuppressLint; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.app.AlarmManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.app.IntentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.app.Notification; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -57,12 +58,27 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // IRemoteService MSG TYPEs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public static final int MSG_REPORT = 1 ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // Message Handler MSG TYPEs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static final int MSG_RESULT = 1 ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static final int MSG_STRING = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static final int MSG_LINE = 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static final int MSG_DEVICE_DISCOVERED = 4 ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // IBridgeService RESULT TYPEs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public enum ResultType { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        OK, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        FAIL, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ERROR 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // IBridgeService RESULT RESPONSE TYPEs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public enum ResponseType{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        GET, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        OBSERVE, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        OBSERVE_STOP, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        POST, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        PUT 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public BridgeService() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         super(BridgeService.class.getName()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -176,22 +192,22 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public boolean requestObserveResource(String device_uuid, String resource_uri) throws RemoteException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return doObserveResource(device_uuid, resource_uri) ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public boolean requestStopObserveResource(String device_uuid, String resource_uri) throws RemoteException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return stopObserveResource(device_uuid, resource_uri); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public boolean requestObserveDeviceSpecificResources(String device_uuid) throws RemoteException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return doObserveDeviceSpecificResources(device_uuid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public boolean requestStopObserveDeviceAllResources(String device_uuid) throws RemoteException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return stopObserveDeviceSpecificResources(device_uuid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public void killCallbacks() { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -202,6 +218,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public void broadcastResultToClients(int result_code, String result_data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // Broadcast to all clients the new value. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             final int count = sCallbacks.beginBroadcast(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Log.i(TAG, "ServiceClientCallback count=" + count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (int index=0; index<count; index++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     sCallbacks.getBroadcastItem(index).onResultReceived(result_code, result_data); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -266,7 +283,12 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         mHandler.sendEmptyMessage(MSG_LINE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void broadcastResult(int result_code, String result_data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        mHandler.sendMessage(mHandler.obtainMessage(MSG_RESULT,result_code, 0, result_data)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final Handler mHandler = new Handler() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @SuppressLint("HandlerLeak") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         @Override public void handleMessage(Message msg) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             switch (msg.what) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 case MSG_LINE: { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -278,6 +300,9 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 case MSG_DEVICE_DISCOVERED: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     rBinder.broadcastDeviceDiscoveredToClients(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } break ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                case MSG_RESULT: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    rBinder.broadcastResultToClients(msg.arg1, (String)msg.obj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } break ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     super.handleMessage(msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -332,7 +357,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Log.d(TAG, "onTaskRemoved()"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        this.restartServiceByAlarmManager(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //this.restartServiceByAlarmManager(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -410,7 +435,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }, 10, 60, TimeUnit.SECONDS); // 60sec interval after 10sec delay 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }, 10, 90, TimeUnit.SECONDS); //90 sec interval after 10sec delay 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /*executorService.scheduleAtFixedRate(new Runnable() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             @Override 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -419,7 +444,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 bridgeServer.loadPairwisedDeviceUUIDs(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }, 30, 60, TimeUnit.SECONDS); // 30sec interval after 30sec delay 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /*executorService.schedule(new Runnable() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             public void run() { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -448,7 +473,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return false ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public OcRemoteDevice findPairwisedRemoteDevice (String device_uuid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public OcRemoteDevice findPairwisedRemoteDevice(String device_uuid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(bridgeServer!=null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return bridgeServer.getPairwisedDevice(device_uuid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -579,7 +604,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return false ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public boolean registerObserverOnDeviceSpecificResources(String device_uuid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public boolean doObserveDeviceSpecificResources(String device_uuid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         OcRemoteDevice remoteDevice = findPairwisedRemoteDevice(device_uuid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (remoteDevice == null) return false ; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -600,7 +625,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else return false ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public boolean registerObserver(String device_uuid, String resource_uri) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public boolean doObserveResource(String device_uuid, String resource_uri) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         OcRemoteDevice remoteDevice = findPairwisedRemoteDevice(device_uuid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (remoteDevice == null) return false ; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -615,7 +640,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return false ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public boolean unregisterObserverOnDeviceSpecificResources(String device_uuid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public boolean stopObserveDeviceSpecificResources(String device_uuid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         OcRemoteDevice remoteDevice = findPairwisedRemoteDevice(device_uuid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (remoteDevice == null) return false ; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -632,7 +657,7 @@ public class BridgeService extends IntentService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else return false ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public boolean unregisterObserver(String device_uuid, String resource_uri) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public boolean stopObserveResource(String device_uuid, String resource_uri) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         OcRemoteDevice remoteDevice = findPairwisedRemoteDevice(device_uuid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (remoteDevice == null) return false ; 
			 |