Add an API for starting and stopping logcat
Issue: FPFL-6
Change-Id: Ia71a25ae059d6bca6f7d7e0f443287ef4e9497ed
diff --git a/java/com/fairphone/common/Core.java b/java/com/fairphone/common/Core.java
index 1c834bd..67e42d8 100644
--- a/java/com/fairphone/common/Core.java
+++ b/java/com/fairphone/common/Core.java
@@ -15,6 +15,14 @@
*/
package com.fairphone.common;
+import android.annotation.NonNull;
+import android.annotation.StringDef;
+import android.util.Log;
+
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
/**
* Provide an interface extending Android's framework.
*
@@ -23,7 +31,43 @@
*/
public abstract class Core {
+ /**
+ * Available logcat buffers to log.
+ *
+ * Default: main,system,crash
+ */
+ public static final String LOGCAT_ALL = "all";
+ public static final String LOGCAT_CRASH = "crash";
+ public static final String LOGCAT_DEFAULT = "default";
+ public static final String LOGCAT_EVENTS = "events";
+ public static final String LOGCAT_MAIN = "main";
+ public static final String LOGCAT_RADIO = "radio";
+ public static final String LOGCAT_SYSTEM = "system";
+ @Retention(SOURCE)
+ @StringDef({
+ LOGCAT_ALL,
+ LOGCAT_CRASH,
+ LOGCAT_DEFAULT,
+ LOGCAT_EVENTS,
+ LOGCAT_MAIN,
+ LOGCAT_RADIO,
+ LOGCAT_SYSTEM
+ })
+ public @interface LogcatBuffer {}
+
private static final int LIBRARY_VERSION = 0;
+ private static final String TAG = Core.class.getSimpleName();
+
+ private static Core sInstance;
+
+ @NonNull
+ public static Core getInstance() {
+ if (sInstance == null) {
+ Log.i(TAG, "Instantiating Fairphone's framework interface");
+ sInstance = new CoreImpl();
+ }
+ return sInstance;
+ }
/**
* Get this interface's version number.
@@ -33,4 +77,22 @@
public final int getVersion() {
return LIBRARY_VERSION;
}
+
+ /**
+ * Start logcat logging.
+ *
+ * Logcat has access to different buffers when logging. By default these are main, system and
+ * crash. The full list of buffer types can be found in {@code LogcatBuffer}.
+ *
+ * Starting logcat from here will persist selected logs and make them available across reboots.
+ * These logs will be provided when obtaining crash information.
+ *
+ * @param bufferNames Variable length arguments for {@code LogcatBuffer}s to log.
+ */
+ public abstract void logcatStart(@NonNull @LogcatBuffer String... bufferNames);
+
+ /**
+ * Stop logcat logging.
+ */
+ public abstract void logcatStop();
}
diff --git a/java/com/fairphone/common/CoreImpl.java b/java/com/fairphone/common/CoreImpl.java
new file mode 100644
index 0000000..15771d8
--- /dev/null
+++ b/java/com/fairphone/common/CoreImpl.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2019 Fairphone B.V.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.fairphone.common;
+
+import android.annotation.NonNull;
+
+final class CoreImpl extends Core {
+
+ CoreImpl() {}
+
+ /** {@inheritDoc} */
+ @Override
+ public void logcatStart(@NonNull @LogcatBuffer String... bufferNames) {
+ // TODO: Start logcat logging
+ return;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void logcatStop() {
+ // TODO: Stop logcat logging
+ return;
+ }
+}