The open source OpenXR runtime
1// Copyright 2024-2025, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Content class function.
6 * @author Simon Zeni <simon.zeni@collabora.com>
7 * @ingroup aux_android
8 */
9
10#include "android_content.h"
11#include "util/u_logging.h"
12
13#include "wrap/android.content.h"
14#include "wrap/java.io.h"
15
16#include <string>
17
18bool
19android_content_get_files_dir(void *context, char *dir, size_t size)
20{
21 if (size == 0 || dir == NULL) {
22 U_LOG_E("Invalid argument");
23 return false;
24 }
25
26 wrap::java::io::File file = wrap::android::content::Context{(jobject)context}.getFilesDir();
27 if (file.isNull()) {
28 U_LOG_E("Failed to get File object");
29 return false;
30 }
31
32
33 const std::string dirPath = file.getAbsolutePath();
34 if (size < (dirPath.length() + 1)) {
35 U_LOG_E("Output string is too small");
36 return false;
37 }
38
39 dirPath.copy(dir, dirPath.length());
40 dir[dirPath.length()] = '\0';
41 return true;
42}