mvp/injection: Abstraction layer for Log mecanism

Log is now defined in the low level layer so that Models and Services
can access it. Android Logcat is now one of the possible implementations
but we could provide another one as soon as it implements the LogService

Change-Id: If7928418ad035f37e51d46db7afd9a8cca399824
Tuleap: #1304
diff --git a/ring-android/app/src/main/java/cx/ring/application/RingApplication.java b/ring-android/app/src/main/java/cx/ring/application/RingApplication.java
index 7430c1b..ca76d69 100644
--- a/ring-android/app/src/main/java/cx/ring/application/RingApplication.java
+++ b/ring-android/app/src/main/java/cx/ring/application/RingApplication.java
@@ -24,18 +24,26 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.inject.Inject;
+
 import cx.ring.dependencyinjection.DaggerRingInjectionComponent;
 import cx.ring.dependencyinjection.PresenterInjectionModule;
 import cx.ring.dependencyinjection.RingInjectionComponent;
 import cx.ring.dependencyinjection.RingInjectionModule;
 import cx.ring.dependencyinjection.ServiceInjectionModule;
+import cx.ring.services.LogService;
+import cx.ring.utils.Log;
 
 public class RingApplication extends Application {
 
-    private RingInjectionComponent mRingInjectionComponent;
+    private final static String TAG = RingApplication.class.getName();
 
+    private RingInjectionComponent mRingInjectionComponent;
     private Map<String, Boolean> mPermissionsBeingAsked;
 
+    @Inject
+    LogService mLogService;
+
     @Override
     public void onCreate() {
         super.onCreate();
@@ -51,6 +59,11 @@
 
         // we can now inject in our self whatever modules define
         mRingInjectionComponent.inject(this);
+        // Injecting LogService into the app logger
+        // as it is a static class, the injection is done manually
+        Log.injectLogService(mLogService);
+
+        Log.d(TAG, "Dependency Injection finished");
     }
 
     public RingInjectionComponent getRingInjectionComponent() {
diff --git a/ring-android/app/src/main/java/cx/ring/dependencyinjection/ServiceInjectionModule.java b/ring-android/app/src/main/java/cx/ring/dependencyinjection/ServiceInjectionModule.java
index e11382f..c8effcb 100755
--- a/ring-android/app/src/main/java/cx/ring/dependencyinjection/ServiceInjectionModule.java
+++ b/ring-android/app/src/main/java/cx/ring/dependencyinjection/ServiceInjectionModule.java
@@ -24,6 +24,8 @@
 import cx.ring.application.RingApplication;
 import cx.ring.services.HistoryService;
 import cx.ring.services.HistoryServiceImpl;
+import cx.ring.services.LogService;
+import cx.ring.services.LogServiceImpl;
 import cx.ring.services.SettingsService;
 import cx.ring.services.SettingsServiceImpl;
 import cx.ring.services.StateService;
@@ -61,4 +63,10 @@
         historyService.initHelper();
         return historyService;
     }
+
+    @Provides
+    @Singleton
+    LogService provideLogService() {
+        return new LogServiceImpl();
+    }
 }
diff --git a/ring-android/app/src/main/java/cx/ring/services/LogServiceImpl.java b/ring-android/app/src/main/java/cx/ring/services/LogServiceImpl.java
new file mode 100644
index 0000000..dc34a91
--- /dev/null
+++ b/ring-android/app/src/main/java/cx/ring/services/LogServiceImpl.java
@@ -0,0 +1,59 @@
+/*
+ *  Copyright (C) 2016 Savoir-faire Linux Inc.
+ *
+ *  Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package cx.ring.services;
+
+import android.util.Log;
+
+public class LogServiceImpl implements LogService {
+
+    public void e(String tag, String message) {
+        Log.e(tag, message);
+    }
+
+    public void d(String tag, String message) {
+        Log.d(tag, message);
+    }
+
+    public void w(String tag, String message) {
+        Log.w(tag, message);
+    }
+
+    public void i(String tag, String message) {
+        Log.i(tag, message);
+    }
+
+    public void e(String tag, String message, Throwable e) {
+        Log.e(tag, message, e);
+    }
+
+    public void d(String tag, String message, Throwable e) {
+        Log.d(tag, message, e);
+    }
+
+    public void w(String tag, String message, Throwable e) {
+        Log.w(tag, message, e);
+    }
+
+    public void i(String tag, String message, Throwable e) {
+        Log.i(tag, message, e);
+    }
+
+
+}
diff --git a/ring-android/libringclient/src/main/java/cx/ring/model/Codec.java b/ring-android/libringclient/src/main/java/cx/ring/model/Codec.java
index 47a6327..217a874 100644
--- a/ring-android/libringclient/src/main/java/cx/ring/model/Codec.java
+++ b/ring-android/libringclient/src/main/java/cx/ring/model/Codec.java
@@ -23,6 +23,8 @@
 
 import java.util.Map;
 
+import cx.ring.utils.Log;
+
 public class Codec {
 
     public enum Type {AUDIO, VIDEO}
@@ -36,12 +38,11 @@
     private boolean mIsEnabled;
 
     public Codec(long i, Map<String, String> audioCodecDetails, boolean enabled) {
-        // todo use a Log abstraction compliant with separation of concerns
 
-       /* Log.d("CodecDetail", Long.toString(i));
-        for (String s : audioCodecDetails.keys()) {
+        Log.d("CodecDetail", Long.toString(i));
+        for (String s : audioCodecDetails.keySet()) {
             Log.d("CodecDetail", s + " -> " + audioCodecDetails.get(s));
-        }*/
+        }
 
         mPayload = i;
         mName = audioCodecDetails.get("CodecInfo.name");
diff --git a/ring-android/libringclient/src/main/java/cx/ring/services/LogService.java b/ring-android/libringclient/src/main/java/cx/ring/services/LogService.java
new file mode 100644
index 0000000..f47ec03
--- /dev/null
+++ b/ring-android/libringclient/src/main/java/cx/ring/services/LogService.java
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (C) 2016 Savoir-faire Linux Inc.
+ *
+ *  Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package cx.ring.services;
+
+public interface LogService {
+
+    void e(String tag, String message);
+
+    void d(String tag, String message);
+
+    void w(String tag, String message);
+
+    void i(String tag, String message);
+
+    void e(String tag, String message, Throwable e);
+
+    void d(String tag, String message, Throwable e);
+
+    void w(String tag, String message, Throwable e);
+
+    void i(String tag, String message, Throwable e);
+
+
+}
diff --git a/ring-android/libringclient/src/main/java/cx/ring/utils/Log.java b/ring-android/libringclient/src/main/java/cx/ring/utils/Log.java
new file mode 100644
index 0000000..d6849c5
--- /dev/null
+++ b/ring-android/libringclient/src/main/java/cx/ring/utils/Log.java
@@ -0,0 +1,65 @@
+/*
+ *  Copyright (C) 2016 Savoir-faire Linux Inc.
+ *
+ *  Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package cx.ring.utils;
+
+import cx.ring.services.LogService;
+
+public class Log {
+
+
+    private static LogService mLogService;
+
+    public static void injectLogService (LogService service) {
+        mLogService = service;
+    }
+
+    public static void d(String tag, String message) {
+        mLogService.d(tag, message);
+    }
+
+    public static void e(String tag, String message) {
+        mLogService.e(tag, message);
+    }
+
+    public static void i(String tag, String message) {
+        mLogService.i(tag, message);
+    }
+
+    public static void w(String tag, String message) {
+        mLogService.w(tag, message);
+    }
+
+    public static void d(String tag, String message, Throwable e) {
+        mLogService.d(tag, message, e);
+    }
+
+    public static void e(String tag, String message, Throwable e) {
+        mLogService.e(tag, message, e);
+    }
+
+    public static void i(String tag, String message, Throwable e) {
+        mLogService.i(tag, message, e);
+    }
+
+    public static void w(String tag, String message, Throwable e) {
+        mLogService.w(tag, message, e);
+    }
+
+}
diff --git a/ring-android/libringclient/src/main/java/cx/ring/utils/QRCodeUtils.java b/ring-android/libringclient/src/main/java/cx/ring/utils/QRCodeUtils.java
index c079dcd..b407c14 100644
--- a/ring-android/libringclient/src/main/java/cx/ring/utils/QRCodeUtils.java
+++ b/ring-android/libringclient/src/main/java/cx/ring/utils/QRCodeUtils.java
@@ -41,7 +41,7 @@
         try {
             qrImageMatrix = qrWriter.encode(input, BarcodeFormat.QR_CODE, QRCODE_IMAGE_SIZE, QRCODE_IMAGE_SIZE);
         } catch (WriterException e) {
-            //Log.e(TAG, "Error while encoding QR", e);
+            Log.e(TAG, "Error while encoding QR", e);
             return null;
         }