#14652: rename sflphoneservice and handle new "service" java package
diff --git a/src/com/savoirfairelinux/sflphone/client/CallManagerJNI.java b/src/com/savoirfairelinux/sflphone/client/CallManagerJNI.java
deleted file mode 100644
index 0788ad3..0000000
--- a/src/com/savoirfairelinux/sflphone/client/CallManagerJNI.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.4
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.savoirfairelinux.sflphone.client;
-
-public class CallManagerJNI {
-  private long swigCPtr;
-  protected boolean swigCMemOwn;
-
-  public CallManagerJNI(long cPtr, boolean cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = cPtr;
-  }
-
-  public static long getCPtr(CallManagerJNI obj) {
-    return (obj == null) ? 0 : obj.swigCPtr;
-  }
-
-  protected void finalize() {
-    delete();
-  }
-
-  public synchronized void delete() {
-    if (swigCPtr != 0) {
-      if (swigCMemOwn) {
-        swigCMemOwn = false;
-        sflphoneserviceJNI.delete_CallManagerJNI(swigCPtr);
-      }
-      swigCPtr = 0;
-    }
-  }
-
-  public void placeCall(String accountID, String callID, String to) {
-    sflphoneserviceJNI.CallManagerJNI_placeCall(swigCPtr, this, accountID, callID, to);
-  }
-
-  public void refuse(String callID) {
-    sflphoneserviceJNI.CallManagerJNI_refuse(swigCPtr, this, callID);
-  }
-
-  public void accept(String callID) {
-    sflphoneserviceJNI.CallManagerJNI_accept(swigCPtr, this, callID);
-  }
-
-  public void hangUp(String callID) {
-    sflphoneserviceJNI.CallManagerJNI_hangUp(swigCPtr, this, callID);
-  }
-
-  public CallManagerJNI() {
-    this(sflphoneserviceJNI.new_CallManagerJNI(), true);
-  }
-
-}
diff --git a/src/com/savoirfairelinux/sflphone/client/Callback.java b/src/com/savoirfairelinux/sflphone/client/Callback.java
deleted file mode 100644
index 60e027a..0000000
--- a/src/com/savoirfairelinux/sflphone/client/Callback.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.4
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.savoirfairelinux.sflphone.client;
-
-public class Callback {
-  private long swigCPtr;
-  protected boolean swigCMemOwn;
-
-  public Callback(long cPtr, boolean cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = cPtr;
-  }
-
-  public static long getCPtr(Callback obj) {
-    return (obj == null) ? 0 : obj.swigCPtr;
-  }
-
-  protected void finalize() {
-    delete();
-  }
-
-  public synchronized void delete() {
-    if (swigCPtr != 0) {
-      if (swigCMemOwn) {
-        swigCMemOwn = false;
-        sflphoneserviceJNI.delete_Callback(swigCPtr);
-      }
-      swigCPtr = 0;
-    }
-  }
-
-  protected void swigDirectorDisconnect() {
-    swigCMemOwn = false;
-    delete();
-  }
-
-  public void swigReleaseOwnership() {
-    swigCMemOwn = false;
-    sflphoneserviceJNI.Callback_change_ownership(this, swigCPtr, false);
-  }
-
-  public void swigTakeOwnership() {
-    swigCMemOwn = true;
-    sflphoneserviceJNI.Callback_change_ownership(this, swigCPtr, true);
-  }
-
-  public void on_incoming_call(String arg1, String arg2, String arg3) {
-    if (getClass() == Callback.class) sflphoneserviceJNI.Callback_on_incoming_call(swigCPtr, this, arg1, arg2, arg3); else sflphoneserviceJNI.Callback_on_incoming_callSwigExplicitCallback(swigCPtr, this, arg1, arg2, arg3);
-  }
-
-  public Callback() {
-    this(sflphoneserviceJNI.new_Callback(), true);
-    sflphoneserviceJNI.Callback_director_connect(this, swigCPtr, swigCMemOwn, true);
-  }
-
-}
diff --git a/src/com/savoirfairelinux/sflphone/client/Manager.java b/src/com/savoirfairelinux/sflphone/client/Manager.java
index 0da5c1a..6ee701b 100644
--- a/src/com/savoirfairelinux/sflphone/client/Manager.java
+++ b/src/com/savoirfairelinux/sflphone/client/Manager.java
@@ -10,6 +10,10 @@
 import android.widget.ImageButton;
 
 import com.savoirfairelinux.sflphone.R;
+import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
+import com.savoirfairelinux.sflphone.service.CallManagerJNI;
+import com.savoirfairelinux.sflphone.service.ManagerImpl;
+import com.savoirfairelinux.sflphone.service.SFLPhoneservice;
 
 public class Manager {
 	
@@ -29,7 +33,7 @@
 		// FIXME: this is the 2nd time we call ManagerImpl's constructor.
 		//        First time was at JNI_OnLoad... 
 //	    managerImpl = new ManagerImpl(sflphoneserviceJNI.instance(), true);
-	    managerImpl = sflphoneservice.instance();
+	    managerImpl = SFLPhoneservice.instance();
 		Log.i(TAG, "ManagerImpl::instance() = " + managerImpl);
 	}
 
@@ -50,8 +54,8 @@
 		this.h = h;
 		callmanagerJNI = new CallManagerJNI();
 		callManagerCallBack = new CallManagerCallBack();
-        sflphoneservice.setCallbackObject(callManagerCallBack);
-        Log.i(TAG, "sflphoneservice.setCallbackObject(callManagerCallBack) = " + callManagerCallBack);
+		SFLPhoneservice.setCallbackObject(callManagerCallBack);
+        Log.i(TAG, "callManagerCallBack = " + callManagerCallBack);
 	}
 	
 	public static void callBack(String s) {
diff --git a/src/com/savoirfairelinux/sflphone/client/ManagerImpl.java b/src/com/savoirfairelinux/sflphone/client/ManagerImpl.java
deleted file mode 100644
index de41dbc..0000000
--- a/src/com/savoirfairelinux/sflphone/client/ManagerImpl.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.8
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.savoirfairelinux.sflphone.client;
-
-public class ManagerImpl {
-  private long swigCPtr;
-  protected boolean swigCMemOwn;
-
-  protected ManagerImpl(long cPtr, boolean cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = cPtr;
-  }
-
-  protected static long getCPtr(ManagerImpl obj) {
-    return (obj == null) ? 0 : obj.swigCPtr;
-  }
-
-  protected void finalize() {
-    delete();
-  }
-
-  public synchronized void delete() {
-    if (swigCPtr != 0) {
-      if (swigCMemOwn) {
-        swigCMemOwn = false;
-        sflphoneserviceJNI.delete_ManagerImpl(swigCPtr);
-      }
-      swigCPtr = 0;
-    }
-  }
-
-  public void init(String config_file) {
-    sflphoneserviceJNI.ManagerImpl_init(swigCPtr, this, config_file);
-  }
-
-  public void setPath(String path) {
-    sflphoneserviceJNI.ManagerImpl_setPath(swigCPtr, this, path);
-  }
-
-  public boolean outgoingCall(String arg0, String arg1, String arg2, String arg3) {
-    return sflphoneserviceJNI.ManagerImpl_outgoingCall__SWIG_0(swigCPtr, this, arg0, arg1, arg2, arg3);
-  }
-
-  public boolean outgoingCall(String arg0, String arg1, String arg2) {
-    return sflphoneserviceJNI.ManagerImpl_outgoingCall__SWIG_1(swigCPtr, this, arg0, arg1, arg2);
-  }
-
-  public void refuseCall(String id) {
-    sflphoneserviceJNI.ManagerImpl_refuseCall(swigCPtr, this, id);
-  }
-
-  public boolean answerCall(String id) {
-    return sflphoneserviceJNI.ManagerImpl_answerCall(swigCPtr, this, id);
-  }
-
-  public void hangupCall(String id) {
-    sflphoneserviceJNI.ManagerImpl_hangupCall(swigCPtr, this, id);
-  }
-
-  public ManagerImpl() {
-    this(sflphoneserviceJNI.new_ManagerImpl(), true);
-  }
-
-}
diff --git a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
index 0b66831..8d2d7a5 100644
--- a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
+++ b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
@@ -34,6 +34,7 @@
 
 import android.app.ActionBar;
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
@@ -63,6 +64,7 @@
 import android.widget.TextView;
 
 import com.savoirfairelinux.sflphone.R;
+import com.savoirfairelinux.sflphone.service.ServiceConstants;
 import com.savoirfairelinux.sflphone.service.SipService;
 
 public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
@@ -145,13 +147,6 @@
 		buttonCall = (ImageButton) findViewById(R.id.buttonCall);
 		buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
 
-		manager = new Manager(callbackHandler);
-		Log.i(TAG, "ManagerImpl::instance() = " + manager.managerImpl);
-		manager.setActivity(this);
-		/* set static AppPath before calling manager.init */
-		manager.managerImpl.setPath(getAppPath());
-		Log.i(TAG, "manager created with callbackHandler " + callbackHandler);
-
 	}
 
 	// FIXME
@@ -172,10 +167,90 @@
 		System.loadLibrary("sflphone");
 	}
 
-        @Override
-        public boolean onOptionsItemSelected(MenuItem item) {
-            Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
+    @Override
+    protected void onStart() {
+        Log.i(TAG, "onStart");
+        super.onStart();
+    }
 
+    @Override
+    protected void onRestart() {
+        super.onRestart();
+    }
+
+    @Override
+    protected void onResume() {
+        Log.i(TAG, "onResume");
+        super.onResume();
+
+        Log.i(TAG, "starting SipService");
+        startSipService();
+    }
+
+    @Override
+    protected void onPause() {
+        /* stop the service, no need to check if it is running */
+        stopService(new Intent(this, SipService.class));
+        serviceIsOn = false;
+        super.onPause();
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+    }
+
+    private void startSipService() {
+        Thread thread = new Thread("StartSFLphoneService") {
+            public void run() {
+                Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
+                //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
+                startService(sipServiceIntent);
+            };
+        };
+        try {
+            thread.start();
+        } catch (IllegalThreadStateException e) {
+            AlertDialog.Builder builder = new AlertDialog.Builder(this);
+            builder.setMessage("Cannot start SFLPhone SipService!");
+            AlertDialog alert = builder.create();
+            alert.show();
+            finish();
+        }
+
+        // FIXME
+        callbackHandler = new Handler() {
+            public void handleMessage(Message msg) {
+                Bundle b = msg.getData();
+                TextView callVoidText;
+
+                Log.i(TAG, "handleMessage");
+
+                callVoidText = buttonFragment.getcallVoidText();
+                if (callVoidText == null)
+                    Log.e(TAG, "SFLPhoneHome: callVoidText is " + callVoidText);
+                callVoidText.setText(b.getString("callback_string"));
+
+                Log.i(TAG, "handleMessage: " + b.getString("callback_string"));
+            }
+        };
+
+        manager = new Manager(callbackHandler);
+        Log.i(TAG, "ManagerImpl::instance() = " + Manager.managerImpl);
+        Manager.setActivity(this);
+        /* set static AppPath before calling manager.init */
+        Manager.managerImpl.setPath(getAppPath());
+        Log.i(TAG, "manager created with callbackHandler " + callbackHandler);
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
             if(item.getItemId() != 0) {
                 // When the button is clicked, launch an activity through this intent
                 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
diff --git a/src/com/savoirfairelinux/sflphone/client/CallManagerCallBack.java b/src/com/savoirfairelinux/sflphone/service/CallManagerCallBack.java
similarity index 87%
rename from src/com/savoirfairelinux/sflphone/client/CallManagerCallBack.java
rename to src/com/savoirfairelinux/sflphone/service/CallManagerCallBack.java
index 2191a42..9aeec2b 100644
--- a/src/com/savoirfairelinux/sflphone/client/CallManagerCallBack.java
+++ b/src/com/savoirfairelinux/sflphone/service/CallManagerCallBack.java
@@ -1,4 +1,4 @@
-package com.savoirfairelinux.sflphone.client;
+package com.savoirfairelinux.sflphone.service;
 
 import android.util.Log;
 
diff --git a/src/com/savoirfairelinux/sflphone/service/ServiceConstants.java b/src/com/savoirfairelinux/sflphone/service/ServiceConstants.java
new file mode 100644
index 0000000..70b8409
--- /dev/null
+++ b/src/com/savoirfairelinux/sflphone/service/ServiceConstants.java
@@ -0,0 +1,8 @@
+package com.savoirfairelinux.sflphone.service;
+
+public final class ServiceConstants {
+    
+    public static final String INTENT_SIP_SERVICE = "com.savoirfairelinux.sflphone.service.SipService";
+    public static final String EXTRA_OUTGOING_ACTIVITY = "outgoing_activity";
+
+}
diff --git a/src/com/savoirfairelinux/sflphone/service/SipService.java b/src/com/savoirfairelinux/sflphone/service/SipService.java
index 822dbc4..b8f116f 100644
--- a/src/com/savoirfairelinux/sflphone/service/SipService.java
+++ b/src/com/savoirfairelinux/sflphone/service/SipService.java
@@ -84,10 +84,10 @@
         
         @Override
         public void run() {
+            Log.i(TAG, "SipService thread running...");
             SipService sipService = SipService.this;
             while(sipService.runFlag) {
                 try {
-                    //Log.i(TAG, "SipService thread running...");
                     Thread.sleep(DELAY);
                 } catch (InterruptedException e) {
                     sipService.runFlag = false;