Skip to content

Commit 056c191

Browse files
committed
Move Android property system to fastrpc_android.c/.h
Move Android property arrays (ANDROIDP_DEBUG_VAR_NAME and ANDROID_DEBUG_VAR_NAME) to fastrpc_android.c. Add functions android_get_property_int(), android_get_property_string(), and android_is_debug_build() to handle Android-specific property operations and build type checking. Update fastrpc_apps_user.c to call Android functions when on Android platform while maintaining environment variable fallback. Update fastrpc_log.c to use android_is_debug_build() for debug buffer allocation. Android functionality preserved and isolated in dedicated files. Signed-off-by: Vinayak Katoch <vkatoch@qti.qualcomm.com>
1 parent 9276537 commit 056c191

4 files changed

Lines changed: 148 additions & 79 deletions

File tree

inc/fastrpc_android.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
#ifndef FASTRPC_ANDROID_H
55
#define FASTRPC_ANDROID_H
66

7+
#include "fastrpc_common.h"
8+
79
#define DEFAULT_DSP_SEARCH_PATHS ";/vendor/lib/rfsa/adsp;/vendor/dsp/;"
810

11+
/* Android property system functions */
12+
int property_get_int32(const char *name, int value);
13+
int property_get(const char *name, int *def, int *value);
14+
15+
/* Android-specific property getter functions */
16+
int android_get_property_int(fastrpc_properties UserPropKey, int defValue);
17+
int android_get_property_string(fastrpc_properties UserPropKey, char *value, char *defValue);
18+
19+
/* Android build type checking function */
20+
int android_is_debug_build(void);
21+
922
#endif /*FASTRPC_ANDROID_H*/

src/fastrpc_android.c

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,127 @@
11
// Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
#include "fastrpc_android.h"
4+
#include "fastrpc_android.h"
5+
#include "HAP_farf.h"
6+
#include <string.h>
7+
8+
#define PROPERTY_VALUE_MAX 92
9+
10+
/* Android P (vendor) property names */
11+
const char *ANDROIDP_DEBUG_VAR_NAME[] = {"vendor.fastrpc.process.attrs",
12+
"vendor.fastrpc.debug.trace",
13+
"vendor.fastrpc.debug.testsig",
14+
"vendor.fastrpc.perf.kernel",
15+
"vendor.fastrpc.perf.adsp",
16+
"vendor.fastrpc.perf.freq",
17+
"vendor.fastrpc.debug.systrace",
18+
"vendor.fastrpc.debug.pddump",
19+
"persist.vendor.fastrpc.process.attrs",
20+
"ro.build.type"};
21+
22+
/* Android (system) property names */
23+
const char *ANDROID_DEBUG_VAR_NAME[] = {"fastrpc.process.attrs",
24+
"fastrpc.debug.trace",
25+
"fastrpc.debug.testsig",
26+
"fastrpc.perf.kernel",
27+
"fastrpc.perf.adsp",
28+
"fastrpc.perf.freq",
29+
"fastrpc.debug.systrace",
30+
"fastrpc.debug.pddump",
31+
"persist.fastrpc.process.attrs",
32+
"ro.build.type"};
33+
34+
int NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS =
35+
sizeof(ANDROIDP_DEBUG_VAR_NAME) / sizeof(char *);
36+
int NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS =
37+
sizeof(ANDROID_DEBUG_VAR_NAME) / sizeof(char *);
38+
39+
/* Stub implementations for property functions - to be implemented with actual Android property API */
40+
int property_get_int32(const char *name, int value) {
41+
return 0;
42+
}
43+
44+
int property_get(const char *name, int *def, int *value) {
45+
return 0;
46+
}
47+
48+
int android_get_property_int(fastrpc_properties UserPropKey, int defValue) {
49+
#if !defined(LE_ENABLE) // Android platform
50+
#if !defined(SYSTEM_RPC_LIBRARY) // vendor library
51+
if (((int)UserPropKey > NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
52+
FARF(
53+
ERROR,
54+
"%s: Index %d out-of-bound for ANDROIDP_DEBUG_VAR_NAME array of len %d",
55+
__func__, UserPropKey, NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS);
56+
return defValue;
57+
}
58+
return (int)property_get_int32(ANDROIDP_DEBUG_VAR_NAME[UserPropKey],
59+
defValue);
60+
#else // system library
61+
if (((int)UserPropKey > NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
62+
FARF(ERROR,
63+
"%s: Index %d out-of-bound for ANDROID_DEBUG_VAR_NAME array of len %d",
64+
__func__, UserPropKey, NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS);
65+
return defValue;
66+
}
67+
return (int)property_get_int32(ANDROID_DEBUG_VAR_NAME[UserPropKey], defValue);
68+
#endif
69+
#else // non-Android platforms
70+
return defValue;
71+
#endif
72+
}
73+
74+
int android_get_property_string(fastrpc_properties UserPropKey, char *value,
75+
char *defValue) {
76+
int len = 0;
77+
#if !defined(LE_ENABLE) // Android platform
78+
#if !defined(SYSTEM_RPC_LIBRARY) // vendor library
79+
if (((int)UserPropKey > NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
80+
FARF(
81+
ERROR,
82+
"%s: Index %d out-of-bound for ANDROIDP_DEBUG_VAR_NAME array of len %d",
83+
__func__, UserPropKey, NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS);
84+
return len;
85+
}
86+
return property_get(ANDROIDP_DEBUG_VAR_NAME[UserPropKey], (int *)value,
87+
(int *)defValue);
88+
#else // system library
89+
if (((int)UserPropKey > NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
90+
FARF(ERROR,
91+
"%s: Index %d out-of-bound for ANDROID_DEBUG_VAR_NAME array of len %d",
92+
__func__, UserPropKey, NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS);
93+
return len;
94+
}
95+
return property_get(ANDROID_DEBUG_VAR_NAME[UserPropKey], value, defValue);
96+
#endif
97+
#else // non-Android platforms
98+
if (defValue != NULL) {
99+
strncpy(value, defValue, PROPERTY_VALUE_MAX - 1);
100+
value[PROPERTY_VALUE_MAX - 1] = '\0';
101+
return strlen(defValue);
102+
}
103+
return len;
104+
#endif
105+
}
106+
107+
/* Check if Android build is debug/eng/userdebug type */
108+
int android_is_debug_build(void) {
109+
int debug_build_type = 0;
110+
char build_type[PROPERTY_VALUE_MAX];
111+
112+
/*
113+
* Get build type by reading the target properties,
114+
* if build type is eng or userdebug return 1.
115+
*/
116+
if (android_get_property_string(FASTRPC_BUILD_TYPE, build_type, NULL)) {
117+
#if !defined(LE_ENABLE)
118+
if (!strncmp(build_type, "eng", PROPERTY_VALUE_MAX) ||
119+
!strncmp(build_type, "userdebug", PROPERTY_VALUE_MAX))
120+
debug_build_type = 1;
121+
#else
122+
if (atoi(build_type))
123+
debug_build_type = 1;
124+
#endif
125+
}
126+
return debug_build_type;
127+
}

src/fastrpc_apps_user.c

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -225,28 +225,7 @@ const char *ENV_DEBUG_VAR_NAME[] = {"FASTRPC_PROCESS_ATTRS",
225225
"FASTRPC_PERF_FREQ",
226226
"FASTRPC_DEBUG_SYSTRACE",
227227
"FASTRPC_DEBUG_PDDUMP",
228-
"FASTRPC_PROCESS_ATTRS_PERSISTENT",
229-
"ro.debuggable"};
230-
const char *ANDROIDP_DEBUG_VAR_NAME[] = {"vendor.fastrpc.process.attrs",
231-
"vendor.fastrpc.debug.trace",
232-
"vendor.fastrpc.debug.testsig",
233-
"vendor.fastrpc.perf.kernel",
234-
"vendor.fastrpc.perf.adsp",
235-
"vendor.fastrpc.perf.freq",
236-
"vendor.fastrpc.debug.systrace",
237-
"vendor.fastrpc.debug.pddump",
238-
"persist.vendor.fastrpc.process.attrs",
239-
"ro.build.type"};
240-
const char *ANDROID_DEBUG_VAR_NAME[] = {"fastrpc.process.attrs",
241-
"fastrpc.debug.trace",
242-
"fastrpc.debug.testsig",
243-
"fastrpc.perf.kernel",
244-
"fastrpc.perf.adsp",
245-
"fastrpc.perf.freq",
246-
"fastrpc.debug.systrace",
247-
"fastrpc.debug.pddump",
248-
"persist.fastrpc.process.attrs",
249-
"ro.build.type"};
228+
"FASTRPC_PROCESS_ATTRS_PERSISTENT"};
250229

251230
const char *SUBSYSTEM_NAME[] = {"adsp", "mdsp", "sdsp", "cdsp", "cdsp1", "gdsp0", "gdsp1", "reserved"};
252231

@@ -260,10 +239,6 @@ static const size_t invoke_end_trace_strlen = sizeof(INVOKE_END_TRACE_STR) - 1;
260239

261240
int NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS =
262241
sizeof(ENV_DEBUG_VAR_NAME) / sizeof(char *);
263-
int NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS =
264-
sizeof(ANDROIDP_DEBUG_VAR_NAME) / sizeof(char *);
265-
int NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS =
266-
sizeof(ANDROID_DEBUG_VAR_NAME) / sizeof(char *);
267242

268243
/* Shell prefix for signed and unsigned */
269244
const char *const SIGNED_SHELL = "fastrpc_shell_";
@@ -471,10 +446,6 @@ static uint32_t crc32_lut(unsigned char *data, int nbyte, uint32_t *crctab) {
471446
return crc;
472447
}
473448

474-
int property_get_int32(const char *name, int value) { return 0; }
475-
476-
int property_get(const char *name, int *def, int *value) { return 0; }
477-
478449
int fastrpc_get_property_int(fastrpc_properties UserPropKey, int defValue) {
479450
if (((int)UserPropKey > NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
480451
FARF(ERROR,
@@ -486,25 +457,7 @@ int fastrpc_get_property_int(fastrpc_properties UserPropKey, int defValue) {
486457
if (env != 0)
487458
return (int)atoi(env);
488459
#if !defined(LE_ENABLE) // Android platform
489-
#if !defined(SYSTEM_RPC_LIBRARY) // vendor library
490-
if (((int)UserPropKey > NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
491-
FARF(
492-
ERROR,
493-
"%s: Index %d out-of-bound for ANDROIDP_DEBUG_VAR_NAME array of len %d",
494-
__func__, UserPropKey, NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS);
495-
return defValue;
496-
}
497-
return (int)property_get_int32(ANDROIDP_DEBUG_VAR_NAME[UserPropKey],
498-
defValue);
499-
#else // system library
500-
if (((int)UserPropKey > NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
501-
FARF(ERROR,
502-
"%s: Index %d out-of-bound for ANDROID_DEBUG_VAR_NAME array of len %d",
503-
__func__, UserPropKey, NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS);
504-
return defValue;
505-
}
506-
return (int)property_get_int32(ANDROID_DEBUG_VAR_NAME[UserPropKey], defValue);
507-
#endif
460+
return android_get_property_int(UserPropKey, defValue);
508461
#else // non-Android platforms
509462
return defValue;
510463
#endif
@@ -525,25 +478,7 @@ int fastrpc_get_property_string(fastrpc_properties UserPropKey, char *value,
525478
return strlen(env);
526479
}
527480
#if !defined(LE_ENABLE) // Android platform
528-
#if !defined(SYSTEM_RPC_LIBRARY) // vendor library
529-
if (((int)UserPropKey > NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
530-
FARF(
531-
ERROR,
532-
"%s: Index %d out-of-bound for ANDROIDP_DEBUG_VAR_NAME array of len %d",
533-
__func__, UserPropKey, NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS);
534-
return len;
535-
}
536-
return property_get(ANDROIDP_DEBUG_VAR_NAME[UserPropKey], (int *)value,
537-
(int *)defValue);
538-
#else // system library
539-
if (((int)UserPropKey > NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) {
540-
FARF(ERROR,
541-
"%s: Index %d out-of-bound for ANDROID_DEBUG_VAR_NAME array of len %d",
542-
__func__, UserPropKey, NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS);
543-
return len;
544-
}
545-
return property_get(ANDROID_DEBUG_VAR_NAME[UserPropKey], value, defValue);
546-
#endif
481+
return android_get_property_string(UserPropKey, value, defValue);
547482
#else // non-Android platforms
548483
if (defValue != NULL) {
549484
strncpy(value, defValue, PROPERTY_VALUE_MAX - 1);

src/fastrpc_log.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "rpcmem_internal.h"
2020
#include "verify.h"
2121

22+
#if defined(ANDROID) || defined(_ANDROID)
23+
#include "fastrpc_android.h"
24+
#endif
25+
2226
#define PROPERTY_VALUE_MAX 72
2327
/* Create persist buffer of size 1 MB */
2428
#define DEBUG_BUF_SIZE 1024 * 1024
@@ -288,18 +292,12 @@ void fastrpc_log_init() {
288292
pthread_mutex_lock(&persist_buf.mut);
289293
/*
290294
* Get build type by reading the target properties,
291-
* if buuid type is eng or userdebug allocate 1 MB persist buf.
295+
* if build type is eng or userdebug allocate 1 MB persist buf.
292296
*/
293-
if (fastrpc_get_property_string(FASTRPC_BUILD_TYPE, build_type, NULL)) {
294-
#if !defined(LE_ENABLE)
295-
if (!strncmp(build_type, "eng", PROPERTY_VALUE_MAX) ||
296-
!strncmp(build_type, "userdebug", PROPERTY_VALUE_MAX))
297-
debug_build_type = true;
298-
#else
299-
if (atoi(build_type))
300-
debug_build_type = true;
297+
#if !defined(LE_ENABLE) // Android platform
298+
debug_build_type = android_is_debug_build();
301299
#endif
302-
}
300+
303301
if (persist_buf.buf == NULL && debug_build_type) {
304302
/* Create a debug buffer to append DEBUG FARF level message. */
305303
persist_buf.buf = (char *)rpcmem_alloc_internal(

0 commit comments

Comments
 (0)