commit
fd7730e7c8
@ -1,10 +1,16 @@
|
|||||||
cmake_minimum_required(VERSION 3.8)
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
|
||||||
add_library(citra-android SHARED
|
add_library(citra-android SHARED
|
||||||
dummy.cpp
|
logging/log.cpp
|
||||||
|
logging/logcat_backend.cpp
|
||||||
|
logging/logcat_backend.h
|
||||||
|
native_interface.cpp
|
||||||
|
native_interface.h
|
||||||
|
ui/main/main_activity.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# find Android's log library
|
# find Android's log library
|
||||||
find_library(log-lib log)
|
find_library(log-lib log)
|
||||||
|
|
||||||
target_link_libraries(citra-android ${log-lib} core common inih)
|
target_link_libraries(citra-android ${log-lib} core common inih)
|
||||||
|
target_include_directories(citra-android PRIVATE "../../../../../" "./")
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
int dummy(int a, int b) {
|
|
||||||
return a + b;
|
|
||||||
}
|
|
@ -0,0 +1,15 @@
|
|||||||
|
#include "common/logging/log.h"
|
||||||
|
#include "native_interface.h"
|
||||||
|
|
||||||
|
namespace Log {
|
||||||
|
extern "C" {
|
||||||
|
JNICALL void Java_org_citra_1emu_citra_LOG_logEntry(JNIEnv* env, jclass type, jint level,
|
||||||
|
jstring file_name, jint line_number,
|
||||||
|
jstring function, jstring msg) {
|
||||||
|
using CitraJNI::GetJString;
|
||||||
|
FmtLogMessage(Class::Frontend, static_cast<Level>(level), GetJString(env, file_name).data(),
|
||||||
|
static_cast<unsigned int>(line_number), GetJString(env, function).data(),
|
||||||
|
GetJString(env, msg).data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace Log
|
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2019 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <android/log.h>
|
||||||
|
#include "common/assert.h"
|
||||||
|
#include "common/logging/text_formatter.h"
|
||||||
|
#include "logcat_backend.h"
|
||||||
|
|
||||||
|
namespace Log {
|
||||||
|
void LogcatBackend::Write(const Entry& entry) {
|
||||||
|
android_LogPriority priority;
|
||||||
|
switch (entry.log_level) {
|
||||||
|
case Level::Trace:
|
||||||
|
priority = ANDROID_LOG_VERBOSE;
|
||||||
|
break;
|
||||||
|
case Level::Debug:
|
||||||
|
priority = ANDROID_LOG_DEBUG;
|
||||||
|
break;
|
||||||
|
case Level::Info:
|
||||||
|
priority = ANDROID_LOG_INFO;
|
||||||
|
break;
|
||||||
|
case Level::Warning:
|
||||||
|
priority = ANDROID_LOG_WARN;
|
||||||
|
break;
|
||||||
|
case Level::Error:
|
||||||
|
priority = ANDROID_LOG_ERROR;
|
||||||
|
break;
|
||||||
|
case Level::Critical:
|
||||||
|
priority = ANDROID_LOG_FATAL;
|
||||||
|
break;
|
||||||
|
case Level::Count:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
__android_log_print(priority, "citra", "%s\n", FormatLogMessage(entry).c_str());
|
||||||
|
}
|
||||||
|
} // namespace Log
|
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2019 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/logging/backend.h"
|
||||||
|
|
||||||
|
namespace Log {
|
||||||
|
class LogcatBackend : public Backend {
|
||||||
|
public:
|
||||||
|
static const char* Name() {
|
||||||
|
return "Logcat";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* GetName() const override {
|
||||||
|
return Name();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Write(const Entry& entry) override;
|
||||||
|
};
|
||||||
|
} // namespace Log
|
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2019 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "native_interface.h"
|
||||||
|
|
||||||
|
namespace CitraJNI {
|
||||||
|
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||||
|
return JNI_VERSION_1_6;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetJString(JNIEnv* env, jstring jstr) {
|
||||||
|
std::string result = "";
|
||||||
|
if (!jstr)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
const char* s = env->GetStringUTFChars(jstr, nullptr);
|
||||||
|
result = s;
|
||||||
|
env->ReleaseStringUTFChars(jstr, s);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} // namespace CitraJNI
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2019 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
namespace CitraJNI {
|
||||||
|
extern "C" {
|
||||||
|
jint JNI_OnLoad(JavaVM* vm, void* reserved);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetJString(JNIEnv* env, jstring jstr);
|
||||||
|
} // namespace CitraJNI
|
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2019 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "common/common_paths.h"
|
||||||
|
#include "common/file_util.h"
|
||||||
|
#include "common/logging/filter.h"
|
||||||
|
#include "common/logging/log.h"
|
||||||
|
#include "core/settings.h"
|
||||||
|
#include "logging/logcat_backend.h"
|
||||||
|
#include "native_interface.h"
|
||||||
|
|
||||||
|
namespace MainActivity {
|
||||||
|
extern "C" {
|
||||||
|
JNICALL void Java_org_citra_1emu_citra_ui_main_MainActivity_initUserPath(JNIEnv* env, jclass type,
|
||||||
|
jstring path) {
|
||||||
|
FileUtil::SetUserPath(CitraJNI::GetJString(env, path) + '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
JNICALL void Java_org_citra_1emu_citra_ui_main_MainActivity_initLogging(JNIEnv* env, jclass type) {
|
||||||
|
Log::Filter log_filter(Log::Level::Debug);
|
||||||
|
log_filter.ParseFilterString(Settings::values.log_filter);
|
||||||
|
Log::SetGlobalFilter(log_filter);
|
||||||
|
|
||||||
|
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
||||||
|
FileUtil::CreateFullPath(log_dir);
|
||||||
|
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
||||||
|
Log::AddBackend(std::make_unique<Log::LogcatBackend>());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}; // namespace MainActivity
|
@ -0,0 +1,41 @@
|
|||||||
|
package org.citra_emu.citra;
|
||||||
|
|
||||||
|
public class LOG {
|
||||||
|
|
||||||
|
private interface LOG_LEVEL {
|
||||||
|
int TRACE = 0, DEBUG = 1, INFO = 2, WARNING = 3, ERROR = 4, CRITICAL = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TRACE(String msg, Object... args) {
|
||||||
|
LOG(LOG_LEVEL.TRACE, msg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DEBUG(String msg, Object... args) {
|
||||||
|
LOG(LOG_LEVEL.DEBUG, msg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void INFO(String msg, Object... args) {
|
||||||
|
LOG(LOG_LEVEL.INFO, msg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WARNING(String msg, Object... args) {
|
||||||
|
LOG(LOG_LEVEL.WARNING, msg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ERROR(String msg, Object... args) {
|
||||||
|
LOG(LOG_LEVEL.ERROR, msg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CRITICAL(String msg, Object... args) {
|
||||||
|
LOG(LOG_LEVEL.CRITICAL, msg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LOG(int level, String msg, Object... args) {
|
||||||
|
StackTraceElement trace = Thread.currentThread().getStackTrace()[4];
|
||||||
|
logEntry(level, trace.getFileName(), trace.getLineNumber(), trace.getMethodName(),
|
||||||
|
String.format(msg, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native void logEntry(int level, String file_name, int line_number,
|
||||||
|
String function, String message);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2019 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
package org.citra_emu.citra.utils;
|
||||||
|
|
||||||
|
import android.os.Environment;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class FileUtil {
|
||||||
|
public static File getUserPath() {
|
||||||
|
File storage = Environment.getExternalStorageDirectory();
|
||||||
|
File userPath = new File(storage, "citra");
|
||||||
|
if (!userPath.isDirectory())
|
||||||
|
userPath.mkdir();
|
||||||
|
return userPath;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2019 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
package org.citra_emu.citra.utils;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
|
public class PermissionUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks a permission, if needed shows a dialog to request it
|
||||||
|
*
|
||||||
|
* @param activity the activity requiring the permission
|
||||||
|
* @param permission the permission needed
|
||||||
|
* @param requestCode supplied to the callback to determine the next action
|
||||||
|
*/
|
||||||
|
public static void verifyPermission(Activity activity, String permission, int requestCode) {
|
||||||
|
if (ContextCompat.checkSelfPermission(activity, permission) ==
|
||||||
|
PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// call the callback called by requestPermissions
|
||||||
|
activity.onRequestPermissionsResult(requestCode, new String[] {permission},
|
||||||
|
new int[] {PackageManager.PERMISSION_GRANTED});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActivityCompat.requestPermissions(activity, new String[] {permission}, requestCode);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue