Compare commits
10 Commits
fix_androi
...
logv
Author | SHA1 | Date | |
---|---|---|---|
0de534d3bc | |||
488991116b | |||
5c95d18beb | |||
1039f9b531 | |||
19ca02cd8f | |||
937fa704a6 | |||
7db0189f23 | |||
8b90e1d3f4 | |||
df017160ed | |||
b846d3a085 |
@ -20,6 +20,7 @@ src = [
|
|||||||
'src/stream.c',
|
'src/stream.c',
|
||||||
'src/tiny_xpm.c',
|
'src/tiny_xpm.c',
|
||||||
'src/video_buffer.c',
|
'src/video_buffer.c',
|
||||||
|
'src/util/log.c',
|
||||||
'src/util/net.c',
|
'src/util/net.c',
|
||||||
'src/util/process.c',
|
'src/util/process.c',
|
||||||
'src/util/str_util.c',
|
'src/util/str_util.c',
|
||||||
|
@ -193,7 +193,7 @@ It requires to lock the video orientation (see --lock-video-orientation).
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-V, \-\-verbosity " value
|
.BI "\-V, \-\-verbosity " value
|
||||||
Set the log level ("debug", "info", "warn" or "error").
|
Set the log level ("verbose", "debug", "info", "warn" or "error").
|
||||||
|
|
||||||
Default is "info" for release builds, "debug" for debug builds.
|
Default is "info" for release builds, "debug" for debug builds.
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ scrcpy_print_usage(const char *arg0) {
|
|||||||
"\n"
|
"\n"
|
||||||
#endif
|
#endif
|
||||||
" -V, --verbosity value\n"
|
" -V, --verbosity value\n"
|
||||||
" Set the log level (debug, info, warn or error).\n"
|
" Set the log level (verbose, debug, info, warn or error).\n"
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
" Default is debug.\n"
|
" Default is debug.\n"
|
||||||
#else
|
#else
|
||||||
@ -505,6 +505,11 @@ parse_display_id(const char *s, uint32_t *display_id) {
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_log_level(const char *s, enum sc_log_level *log_level) {
|
parse_log_level(const char *s, enum sc_log_level *log_level) {
|
||||||
|
if (!strcmp(s, "verbose")) {
|
||||||
|
*log_level = SC_LOG_LEVEL_VERBOSE;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!strcmp(s, "debug")) {
|
if (!strcmp(s, "debug")) {
|
||||||
*log_level = SC_LOG_LEVEL_DEBUG;
|
*log_level = SC_LOG_LEVEL_DEBUG;
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "control_msg.h"
|
#include "control_msg.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -8,6 +9,52 @@
|
|||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/str_util.h"
|
#include "util/str_util.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map an enum value to a string based on an array, without crashing on an
|
||||||
|
* out-of-bounds index.
|
||||||
|
*/
|
||||||
|
#define ENUM_TO_LABEL(labels, value) \
|
||||||
|
((size_t) (value) < ARRAY_LEN(labels) ? labels[value] : "???")
|
||||||
|
|
||||||
|
#define KEYEVENT_ACTION_LABEL(value) \
|
||||||
|
ENUM_TO_LABEL(android_keyevent_action_labels, value)
|
||||||
|
|
||||||
|
#define MOTIONEVENT_ACTION_LABEL(value) \
|
||||||
|
ENUM_TO_LABEL(android_motionevent_action_labels, value)
|
||||||
|
|
||||||
|
#define SCREEN_POWER_MODE_LABEL(value) \
|
||||||
|
ENUM_TO_LABEL(screen_power_mode_labels, value)
|
||||||
|
|
||||||
|
static const char *const android_keyevent_action_labels[] = {
|
||||||
|
"down",
|
||||||
|
"up",
|
||||||
|
"multi",
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *const android_motionevent_action_labels[] = {
|
||||||
|
"down",
|
||||||
|
"up",
|
||||||
|
"move",
|
||||||
|
"cancel",
|
||||||
|
"outside",
|
||||||
|
"ponter-down",
|
||||||
|
"pointer-up",
|
||||||
|
"hover-move",
|
||||||
|
"scroll",
|
||||||
|
"hover-enter"
|
||||||
|
"hover-exit",
|
||||||
|
"btn-press",
|
||||||
|
"btn-release",
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *const screen_power_mode_labels[] = {
|
||||||
|
"off",
|
||||||
|
"doze",
|
||||||
|
"normal",
|
||||||
|
"doze-suspend",
|
||||||
|
"suspend",
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_position(uint8_t *buf, const struct position *position) {
|
write_position(uint8_t *buf, const struct position *position) {
|
||||||
buffer_write32be(&buf[0], position->point.x);
|
buffer_write32be(&buf[0], position->point.x);
|
||||||
@ -93,6 +140,94 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
control_msg_log(const struct control_msg *msg) {
|
||||||
|
#define LOG_CMSG(fmt, ...) LOGV("input: " fmt, ## __VA_ARGS__)
|
||||||
|
switch (msg->type) {
|
||||||
|
case CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
||||||
|
LOG_CMSG("key %-4s code=%d repeat=%" PRIu32 " meta=%06lx",
|
||||||
|
KEYEVENT_ACTION_LABEL(msg->inject_keycode.action),
|
||||||
|
(int) msg->inject_keycode.keycode,
|
||||||
|
msg->inject_keycode.repeat,
|
||||||
|
(long) msg->inject_keycode.metastate);
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_INJECT_TEXT:
|
||||||
|
LOG_CMSG("text \"%s\"", msg->inject_text.text);
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT: {
|
||||||
|
int action = msg->inject_touch_event.action
|
||||||
|
& AMOTION_EVENT_ACTION_MASK;
|
||||||
|
uint64_t id = msg->inject_touch_event.pointer_id;
|
||||||
|
if (id == POINTER_ID_MOUSE || id == POINTER_ID_VIRTUAL_FINGER) {
|
||||||
|
// string pointer id
|
||||||
|
LOG_CMSG("touch [id=%s] %-4s position=%" PRIi32 ",%" PRIi32
|
||||||
|
" pressure=%g buttons=%06lx",
|
||||||
|
id == POINTER_ID_MOUSE ? "mouse" : "vfinger",
|
||||||
|
MOTIONEVENT_ACTION_LABEL(action),
|
||||||
|
msg->inject_touch_event.position.point.x,
|
||||||
|
msg->inject_touch_event.position.point.y,
|
||||||
|
msg->inject_touch_event.pressure,
|
||||||
|
(long) msg->inject_touch_event.buttons);
|
||||||
|
} else {
|
||||||
|
// numeric pointer id
|
||||||
|
#ifndef __WIN32
|
||||||
|
# define PRIu64_ PRIu64
|
||||||
|
#else
|
||||||
|
# define PRIu64_ "I64u" // Windows...
|
||||||
|
#endif
|
||||||
|
LOG_CMSG("touch [id=%" PRIu64_ "] %-4s position=%" PRIi32 ",%"
|
||||||
|
PRIi32 " pressure=%g buttons=%06lx",
|
||||||
|
id,
|
||||||
|
MOTIONEVENT_ACTION_LABEL(action),
|
||||||
|
msg->inject_touch_event.position.point.x,
|
||||||
|
msg->inject_touch_event.position.point.y,
|
||||||
|
msg->inject_touch_event.pressure,
|
||||||
|
(long) msg->inject_touch_event.buttons);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT:
|
||||||
|
LOG_CMSG("scroll position=%" PRIi32 ",%" PRIi32 " hscroll=%" PRIi32
|
||||||
|
" vscroll=%" PRIi32,
|
||||||
|
msg->inject_scroll_event.position.point.x,
|
||||||
|
msg->inject_scroll_event.position.point.y,
|
||||||
|
msg->inject_scroll_event.hscroll,
|
||||||
|
msg->inject_scroll_event.vscroll);
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||||
|
LOG_CMSG("back-or-screen-on %s",
|
||||||
|
KEYEVENT_ACTION_LABEL(msg->inject_keycode.action));
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_SET_CLIPBOARD:
|
||||||
|
LOG_CMSG("clipboard %s \"%s\"",
|
||||||
|
msg->set_clipboard.paste ? "paste" : "copy",
|
||||||
|
msg->set_clipboard.text);
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE:
|
||||||
|
LOG_CMSG("power mode %s",
|
||||||
|
SCREEN_POWER_MODE_LABEL(msg->set_screen_power_mode.mode));
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
|
LOG_CMSG("expand notification panel");
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL:
|
||||||
|
LOG_CMSG("expand settings panel");
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_COLLAPSE_PANELS:
|
||||||
|
LOG_CMSG("collapse panels");
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
||||||
|
LOG_CMSG("get clipboard");
|
||||||
|
break;
|
||||||
|
case CONTROL_MSG_TYPE_ROTATE_DEVICE:
|
||||||
|
LOG_CMSG("rotate device");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LOG_CMSG("unknown type: %u", (unsigned) msg->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
control_msg_destroy(struct control_msg *msg) {
|
control_msg_destroy(struct control_msg *msg) {
|
||||||
switch (msg->type) {
|
switch (msg->type) {
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
// type: 1 byte; paste flag: 1 byte; length: 4 bytes
|
// type: 1 byte; paste flag: 1 byte; length: 4 bytes
|
||||||
#define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH (CONTROL_MSG_MAX_SIZE - 6)
|
#define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH (CONTROL_MSG_MAX_SIZE - 6)
|
||||||
|
|
||||||
#define POINTER_ID_MOUSE UINT64_C(-1);
|
#define POINTER_ID_MOUSE UINT64_C(-1)
|
||||||
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2);
|
#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2)
|
||||||
|
|
||||||
enum control_msg_type {
|
enum control_msg_type {
|
||||||
CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||||
@ -84,6 +84,9 @@ struct control_msg {
|
|||||||
size_t
|
size_t
|
||||||
control_msg_serialize(const struct control_msg *msg, unsigned char *buf);
|
control_msg_serialize(const struct control_msg *msg, unsigned char *buf);
|
||||||
|
|
||||||
|
void
|
||||||
|
control_msg_log(const struct control_msg *msg);
|
||||||
|
|
||||||
void
|
void
|
||||||
control_msg_destroy(struct control_msg *msg);
|
control_msg_destroy(struct control_msg *msg);
|
||||||
|
|
||||||
|
@ -48,6 +48,10 @@ controller_destroy(struct controller *controller) {
|
|||||||
bool
|
bool
|
||||||
controller_push_msg(struct controller *controller,
|
controller_push_msg(struct controller *controller,
|
||||||
const struct control_msg *msg) {
|
const struct control_msg *msg) {
|
||||||
|
if (sc_get_log_level() <= SC_LOG_LEVEL_VERBOSE) {
|
||||||
|
control_msg_log(msg);
|
||||||
|
}
|
||||||
|
|
||||||
sc_mutex_lock(&controller->mutex);
|
sc_mutex_lock(&controller->mutex);
|
||||||
bool was_empty = cbuf_is_empty(&controller->queue);
|
bool was_empty = cbuf_is_empty(&controller->queue);
|
||||||
bool res = cbuf_push(&controller->queue, *msg);
|
bool res = cbuf_push(&controller->queue, *msg);
|
||||||
|
@ -595,8 +595,12 @@ convert_mouse_motion(const SDL_MouseMotionEvent *from, struct screen *screen,
|
|||||||
static void
|
static void
|
||||||
input_manager_process_mouse_motion(struct input_manager *im,
|
input_manager_process_mouse_motion(struct input_manager *im,
|
||||||
const SDL_MouseMotionEvent *event) {
|
const SDL_MouseMotionEvent *event) {
|
||||||
if (!event->state) {
|
uint32_t mask = SDL_BUTTON_LMASK;
|
||||||
// do not send motion events when no button is pressed
|
if (im->forward_all_clicks) {
|
||||||
|
mask |= SDL_BUTTON_MMASK | SDL_BUTTON_RMASK;
|
||||||
|
}
|
||||||
|
if (!(event->state & mask)) {
|
||||||
|
// do not send motion events when no click is pressed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event->which == SDL_TOUCH_MOUSEID) {
|
if (event->which == SDL_TOUCH_MOUSEID) {
|
||||||
|
@ -38,24 +38,6 @@ print_version(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_LogPriority
|
|
||||||
convert_log_level_to_sdl(enum sc_log_level level) {
|
|
||||||
switch (level) {
|
|
||||||
case SC_LOG_LEVEL_DEBUG:
|
|
||||||
return SDL_LOG_PRIORITY_DEBUG;
|
|
||||||
case SC_LOG_LEVEL_INFO:
|
|
||||||
return SDL_LOG_PRIORITY_INFO;
|
|
||||||
case SC_LOG_LEVEL_WARN:
|
|
||||||
return SDL_LOG_PRIORITY_WARN;
|
|
||||||
case SC_LOG_LEVEL_ERROR:
|
|
||||||
return SDL_LOG_PRIORITY_ERROR;
|
|
||||||
default:
|
|
||||||
assert(!"unexpected log level");
|
|
||||||
return SDL_LOG_PRIORITY_INFO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[]) {
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
@ -79,8 +61,7 @@ main(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_LogPriority sdl_log = convert_log_level_to_sdl(args.opts.log_level);
|
sc_set_log_level(args.opts.log_level);
|
||||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, sdl_log);
|
|
||||||
|
|
||||||
if (args.help) {
|
if (args.help) {
|
||||||
scrcpy_print_usage(argv[0]);
|
scrcpy_print_usage(argv[0]);
|
||||||
|
@ -216,14 +216,15 @@ av_log_callback(void *avcl, int level, const char *fmt, va_list vl) {
|
|||||||
if (priority == 0) {
|
if (priority == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char *local_fmt = malloc(strlen(fmt) + 10);
|
|
||||||
|
size_t fmt_len = strlen(fmt);
|
||||||
|
char *local_fmt = malloc(fmt_len + 10);
|
||||||
if (!local_fmt) {
|
if (!local_fmt) {
|
||||||
LOGC("Could not allocate string");
|
LOGC("Could not allocate string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// strcpy is safe here, the destination is large enough
|
memcpy(local_fmt, "[FFmpeg] ", 9); // do not write the final '\0'
|
||||||
strcpy(local_fmt, "[FFmpeg] ");
|
memcpy(local_fmt + 9, fmt, fmt_len + 1); // include '\0'
|
||||||
strcpy(local_fmt + 9, fmt);
|
|
||||||
SDL_LogMessageV(SDL_LOG_CATEGORY_VIDEO, priority, local_fmt, vl);
|
SDL_LogMessageV(SDL_LOG_CATEGORY_VIDEO, priority, local_fmt, vl);
|
||||||
free(local_fmt);
|
free(local_fmt);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
enum sc_log_level {
|
enum sc_log_level {
|
||||||
|
SC_LOG_LEVEL_VERBOSE,
|
||||||
SC_LOG_LEVEL_DEBUG,
|
SC_LOG_LEVEL_DEBUG,
|
||||||
SC_LOG_LEVEL_INFO,
|
SC_LOG_LEVEL_INFO,
|
||||||
SC_LOG_LEVEL_WARN,
|
SC_LOG_LEVEL_WARN,
|
||||||
|
@ -235,6 +235,8 @@ enable_tunnel_any_port(struct server *server, struct sc_port_range port_range,
|
|||||||
static const char *
|
static const char *
|
||||||
log_level_to_server_string(enum sc_log_level level) {
|
log_level_to_server_string(enum sc_log_level level) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
case SC_LOG_LEVEL_VERBOSE:
|
||||||
|
return "verbose";
|
||||||
case SC_LOG_LEVEL_DEBUG:
|
case SC_LOG_LEVEL_DEBUG:
|
||||||
return "debug";
|
return "debug";
|
||||||
case SC_LOG_LEVEL_INFO:
|
case SC_LOG_LEVEL_INFO:
|
||||||
|
53
app/src/util/log.c
Normal file
53
app/src/util/log.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
static SDL_LogPriority
|
||||||
|
log_level_sc_to_sdl(enum sc_log_level level) {
|
||||||
|
switch (level) {
|
||||||
|
case SC_LOG_LEVEL_VERBOSE:
|
||||||
|
return SDL_LOG_PRIORITY_VERBOSE;
|
||||||
|
case SC_LOG_LEVEL_DEBUG:
|
||||||
|
return SDL_LOG_PRIORITY_DEBUG;
|
||||||
|
case SC_LOG_LEVEL_INFO:
|
||||||
|
return SDL_LOG_PRIORITY_INFO;
|
||||||
|
case SC_LOG_LEVEL_WARN:
|
||||||
|
return SDL_LOG_PRIORITY_WARN;
|
||||||
|
case SC_LOG_LEVEL_ERROR:
|
||||||
|
return SDL_LOG_PRIORITY_ERROR;
|
||||||
|
default:
|
||||||
|
assert(!"unexpected log level");
|
||||||
|
return SDL_LOG_PRIORITY_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static enum sc_log_level
|
||||||
|
log_level_sdl_to_sc(SDL_LogPriority priority) {
|
||||||
|
switch (priority) {
|
||||||
|
case SDL_LOG_PRIORITY_VERBOSE:
|
||||||
|
return SC_LOG_LEVEL_VERBOSE;
|
||||||
|
case SDL_LOG_PRIORITY_DEBUG:
|
||||||
|
return SC_LOG_LEVEL_DEBUG;
|
||||||
|
case SDL_LOG_PRIORITY_INFO:
|
||||||
|
return SC_LOG_LEVEL_INFO;
|
||||||
|
case SDL_LOG_PRIORITY_WARN:
|
||||||
|
return SC_LOG_LEVEL_WARN;
|
||||||
|
case SDL_LOG_PRIORITY_ERROR:
|
||||||
|
return SC_LOG_LEVEL_ERROR;
|
||||||
|
default:
|
||||||
|
assert(!"unexpected log level");
|
||||||
|
return SC_LOG_LEVEL_INFO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_set_log_level(enum sc_log_level level) {
|
||||||
|
SDL_LogPriority sdl_log = log_level_sc_to_sdl(level);
|
||||||
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, sdl_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum sc_log_level
|
||||||
|
sc_get_log_level(void) {
|
||||||
|
SDL_LogPriority sdl_log = SDL_LogGetPriority(SDL_LOG_CATEGORY_APPLICATION);
|
||||||
|
return log_level_sdl_to_sc(sdl_log);
|
||||||
|
}
|
@ -1,8 +1,12 @@
|
|||||||
#ifndef LOG_H
|
#ifndef SC_LOG_H
|
||||||
#define LOG_H
|
#define SC_LOG_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_log.h>
|
#include <SDL2/SDL_log.h>
|
||||||
|
|
||||||
|
#include "scrcpy.h"
|
||||||
|
|
||||||
#define LOGV(...) SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
#define LOGV(...) SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||||
#define LOGD(...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
#define LOGD(...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||||
#define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
#define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||||
@ -10,4 +14,10 @@
|
|||||||
#define LOGE(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
#define LOGE(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||||
#define LOGC(...) SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
#define LOGC(...) SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_set_log_level(enum sc_log_level level);
|
||||||
|
|
||||||
|
enum sc_log_level
|
||||||
|
sc_get_log_level(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,7 +12,7 @@ public final class Ln {
|
|||||||
private static final String PREFIX = "[server] ";
|
private static final String PREFIX = "[server] ";
|
||||||
|
|
||||||
enum Level {
|
enum Level {
|
||||||
DEBUG, INFO, WARN, ERROR
|
VERBOSE, DEBUG, INFO, WARN, ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Level threshold = Level.INFO;
|
private static Level threshold = Level.INFO;
|
||||||
@ -36,6 +36,13 @@ public final class Ln {
|
|||||||
return level.ordinal() >= threshold.ordinal();
|
return level.ordinal() >= threshold.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void v(String message) {
|
||||||
|
if (isEnabled(Level.VERBOSE)) {
|
||||||
|
Log.v(TAG, message);
|
||||||
|
System.out.println(PREFIX + "VERBOSE: " + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void d(String message) {
|
public static void d(String message) {
|
||||||
if (isEnabled(Level.DEBUG)) {
|
if (isEnabled(Level.DEBUG)) {
|
||||||
Log.d(TAG, message);
|
Log.d(TAG, message);
|
||||||
|
@ -2,6 +2,7 @@ package com.genymobile.scrcpy.wrappers;
|
|||||||
|
|
||||||
import com.genymobile.scrcpy.Ln;
|
import com.genymobile.scrcpy.Ln;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
@ -37,6 +38,8 @@ public class ContentProvider implements Closeable {
|
|||||||
private Method callMethod;
|
private Method callMethod;
|
||||||
private int callMethodVersion;
|
private int callMethodVersion;
|
||||||
|
|
||||||
|
private Object attributionSource;
|
||||||
|
|
||||||
ContentProvider(ActivityManager manager, Object provider, String name, IBinder token) {
|
ContentProvider(ActivityManager manager, Object provider, String name, IBinder token) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
@ -44,36 +47,58 @@ public class ContentProvider implements Closeable {
|
|||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("PrivateApi")
|
||||||
private Method getCallMethod() throws NoSuchMethodException {
|
private Method getCallMethod() throws NoSuchMethodException {
|
||||||
if (callMethod == null) {
|
if (callMethod == null) {
|
||||||
|
try {
|
||||||
|
Class<?> attributionSourceClass = Class.forName("android.content.AttributionSource");
|
||||||
|
callMethod = provider.getClass().getMethod("call", attributionSourceClass, String.class, String.class, String.class, Bundle.class);
|
||||||
|
callMethodVersion = 0;
|
||||||
|
} catch (NoSuchMethodException | ClassNotFoundException e0) {
|
||||||
|
// old versions
|
||||||
try {
|
try {
|
||||||
callMethod = provider.getClass()
|
callMethod = provider.getClass()
|
||||||
.getMethod("call", String.class, String.class, String.class, String.class, String.class, Bundle.class);
|
.getMethod("call", String.class, String.class, String.class, String.class, String.class, Bundle.class);
|
||||||
callMethodVersion = 0;
|
callMethodVersion = 1;
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e1) {
|
||||||
// old versions
|
|
||||||
try {
|
try {
|
||||||
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, String.class, Bundle.class);
|
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, String.class, Bundle.class);
|
||||||
callMethodVersion = 1;
|
callMethodVersion = 2;
|
||||||
} catch (NoSuchMethodException e2) {
|
} catch (NoSuchMethodException e2) {
|
||||||
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, Bundle.class);
|
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, Bundle.class);
|
||||||
callMethodVersion = 2;
|
callMethodVersion = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return callMethod;
|
return callMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("PrivateApi")
|
||||||
|
private Object getAttributionSource()
|
||||||
|
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||||
|
if (attributionSource == null) {
|
||||||
|
Class<?> cl = Class.forName("android.content.AttributionSource$Builder");
|
||||||
|
Object builder = cl.getConstructor(int.class).newInstance(ServiceManager.USER_ID);
|
||||||
|
cl.getDeclaredMethod("setPackageName", String.class).invoke(builder, ServiceManager.PACKAGE_NAME);
|
||||||
|
attributionSource = cl.getDeclaredMethod("build").invoke(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
return attributionSource;
|
||||||
|
}
|
||||||
|
|
||||||
private Bundle call(String callMethod, String arg, Bundle extras) {
|
private Bundle call(String callMethod, String arg, Bundle extras) {
|
||||||
try {
|
try {
|
||||||
Method method = getCallMethod();
|
Method method = getCallMethod();
|
||||||
Object[] args;
|
Object[] args;
|
||||||
switch (callMethodVersion) {
|
switch (callMethodVersion) {
|
||||||
case 0:
|
case 0:
|
||||||
args = new Object[]{ServiceManager.PACKAGE_NAME, null, "settings", callMethod, arg, extras};
|
args = new Object[]{getAttributionSource(), "settings", callMethod, arg, extras};
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
args = new Object[]{ServiceManager.PACKAGE_NAME, null, "settings", callMethod, arg, extras};
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
args = new Object[]{ServiceManager.PACKAGE_NAME, "settings", callMethod, arg, extras};
|
args = new Object[]{ServiceManager.PACKAGE_NAME, "settings", callMethod, arg, extras};
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -81,7 +106,7 @@ public class ContentProvider implements Closeable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (Bundle) method.invoke(provider, args);
|
return (Bundle) method.invoke(provider, args);
|
||||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException | ClassNotFoundException | InstantiationException e) {
|
||||||
Ln.e("Could not invoke method", e);
|
Ln.e("Could not invoke method", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user