gpt4 book ai didi

android - 无法从 ART 创建磁盘文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:13:49 26 4
gpt4 key购买 nike

我希望 Android 运行时 (ART) 写入文件。因此,我将以下代码添加到 WORKING_DIRECTORY/art/runtime/runtime.cc。

  std::string pid_str = std::to_string(getpid());
time_t n = time(nullptr);
struct tm* local = localtime(&n);
char strTime[80];
strftime(strTime, 80, "%Y-%m-%d %H-%M-%S", local);
std::string perf_filename = std::string("/storage/self/primary") + "/" + strTime + "-" + pid_str + ".log";

auto log = std::ofstream(perf_filename.c_str());
struct passwd *pwd = getpwuid(getuid());
if (log.is_open())
LOG(INFO) << "User " << pwd->pw_name << "(" << pwd->pw_uid << ") created field log is created at " << perf_filename;
else {
LOG(WARNING) << "User " << pwd->pw_name << "(" << pwd->pw_uid << ") cannot opening field log at " << perf_filename << ". Error: " << strerror(errno);
}
$ adb logcat | grep -F "field log"
04-23 15:28:34.390 3521 3521 W zygote64: User u0_a44(10044) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-34-3521.log. Error: Permission denied
04-23 15:28:34.517 3581 3581 I zygote64: User nfc(1027) created field log is created at /storage/self/primary/nvm-1970-04-23 15-28-34-3581.log
04-23 15:28:34.539 3597 3597 W zygote64: User u0_a57(10057) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-34-3597.log. Error: Permission denied
04-23 15:28:34.620 3641 3641 W zygote64: User u0_a15(10015) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-34-3641.log. Error: Permission denied
04-23 15:28:34.656 3660 3660 W zygote64: User u0_a19(10019) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-34-3660.log. Error: Permission denied
04-23 15:28:34.743 3718 3718 I zygote64: User system(1000) created field log is created at /storage/self/primary/nvm-1970-04-23 15-28-34-3718.log
04-23 15:28:35.728 3841 3841 W zygote64: User u0_a16(10016) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-35-3841.log. Error: Permission denied
04-23 15:28:35.817 3860 3860 W zygote64: User u0_a58(10058) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-35-3860.log. Error: Permission denied
04-23 15:28:35.928 3886 3886 I zygote64: User u0_a3(10003) created field log is created at /storage/self/primary/nvm-1970-04-23 15-28-35-3886.log
04-23 15:28:36.217 3906 3906 W zygote64: User u0_a2(10002) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-36-3906.log. Error: Permission denied
04-23 15:28:36.392 3968 3968 W zygote64: User u0_a59(10059) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-36-3968.log. Error: Permission denied
04-23 15:28:37.892 4189 4189 W zygote64: User u0_a13(10013) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-37-4189.log. Error: Permission denied
04-23 15:28:38.359 4233 4233 W zygote64: User u0_a36(10036) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-38-4233.log. Error: Permission denied
04-23 15:28:38.549 4289 4289 I zygote64: User u0_a39(10039) created field log is created at /storage/self/primary/nvm-1970-04-23 15-28-38-4289.log
04-23 15:28:38.738 4309 4309 W zygote64: User u0_a8(10008) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-38-4309.log. Error: Permission denied
04-23 15:28:38.881 4328 4328 W zygote64: User u0_a7(10007) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-38-4328.log. Error: Permission denied
04-23 15:28:39.194 4373 4373 I zygote64: User u0_a45(10045) created field log is created at /storage/self/primary/nvm-1970-04-23 15-28-39-4373.log
04-23 15:28:39.797 4425 4425 I zygote64: User u0_a48(10048) created field log is created at /storage/self/primary/nvm-1970-04-23 15-28-39-4425.log
04-23 15:28:40.014 4441 4441 I zygote64: User u0_a62(10062) created field log is created at /storage/self/primary/nvm-1970-04-23 15-28-40-4441.log
04-23 15:28:40.320 4460 4460 W zygote64: User u0_a17(10017) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-40-4460.log. Error: Permission denied
04-23 15:28:40.551 4505 4505 W zygote64: User u0_a21(10021) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-28-40-4505.log. Error: Permission denied
04-23 15:29:02.961 4821 4821 I zygote64: User system(1000) created field log is created at /storage/self/primary/nvm-1970-04-23 15-29-02-4821.log
04-23 15:29:29.317 4891 4891 W zygote64: User u0_a47(10047) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-29-29-4891.log. Error: Permission denied
04-23 15:29:55.592 5012 5012 W zygote64: User u0_a2(10002) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-29-55-5012.log. Error: Permission denied
04-23 15:31:29.829 5084 5084 I zygote64: User u0_a5(10005) created field log is created at /storage/self/primary/nvm-1970-04-23 15-31-29-5084.log
04-23 15:32:07.743 5144 5144 W zygote64: User u0_a23(10023) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-32-07-5144.log. Error: Permission denied
04-23 15:32:16.602 5217 5217 W zygote : User u0_a63(10063) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-32-16-5217.log. Error: Permission denied
04-23 15:32:23.596 5405 5405 W zygote : User u0_a54(10054) cannot opening field log at /storage/self/primary/nvm-1970-04-23 15-32-23-5405.log. Error: Permission denied

adb logcat 显示一些用户 u0_a39、u0_a3、u0_a5 能够创建文件,而其他用户则不能。有谁知道为什么吗?

最佳答案

这是因为权限。如果 ART 托管的应用请求并且用户授予 android.permission.WRITE_EXTERNAL_STORAGE,则代码有效。

目前还不清楚为什么 Java 级别的权限会影响运行时代码。

关于android - 无法从 ART 创建磁盘文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56678182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com