Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask user to grant INTERNET permission + grant all-files access #160

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions capture_service/android_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ VulkanApplication::~VulkanApplication()
absl::Status VulkanApplication::Setup()
{
LOGD("Setup Vulkan application: %s\n", m_package.c_str());
RETURN_IF_ERROR(HasInternetPermission());
RETURN_IF_ERROR(GrantAllFilesAccess());
RETURN_IF_ERROR(m_dev.Adb().Run("root"));
RETURN_IF_ERROR(m_dev.Adb().Run("wait-for-device"));
Stop().IgnoreError();
Expand Down Expand Up @@ -294,9 +296,36 @@ absl::Status AndroidApplication::GfxrSetup()
return absl::OkStatus();
}

absl::Status AndroidApplication::HasInternetPermission()
{
const std::string cmd = absl::
StrFormat("shell dumpsys package %s | grep 'android.permission.INTERNET: granted=true'",
m_package);
auto res = m_dev.Adb().RunAndGetResult(cmd);
if (!res.ok())
{
return res.status();
}
if ((*res).empty())
{
return absl::Status(absl::StatusCode::kUnknown,
"The android.permission.INTERNET permission wasn't granted. Add it to "
"your AndroidManifest.xml file");
}
return absl::OkStatus();
}

absl::Status AndroidApplication::GrantAllFilesAccess()
{
return m_dev.Adb().Run(
absl::StrFormat("shell appops set --uid %s MANAGE_EXTERNAL_STORAGE allow", m_package));
}

absl::Status OpenXRApplication::Setup()
{
LOGD("OpenXRApplication %s Setup\n", m_package.c_str());
RETURN_IF_ERROR(HasInternetPermission());
RETURN_IF_ERROR(GrantAllFilesAccess());
RETURN_IF_ERROR(m_dev.Adb().Run("root"));
RETURN_IF_ERROR(m_dev.Adb().Run("wait-for-device"));
RETURN_IF_ERROR(m_dev.Adb().Run("remount"));
Expand Down Expand Up @@ -357,6 +386,8 @@ VulkanCliApplication::~VulkanCliApplication()
// the global path.
absl::Status VulkanCliApplication::Setup()
{
RETURN_IF_ERROR(HasInternetPermission());
RETURN_IF_ERROR(GrantAllFilesAccess());
RETURN_IF_ERROR(m_dev.Adb().Run("root"));
RETURN_IF_ERROR(m_dev.Adb().Run("wait-for-device"));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell mkdir -p %s", kVulkanGlobalPath)));
Expand Down
2 changes: 2 additions & 0 deletions capture_service/android_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class AndroidApplication
};
absl::Status CreateGfxrDirectory(const std::string command_args);
absl::Status GfxrSetup();
absl::Status HasInternetPermission();
absl::Status GrantAllFilesAccess();

protected:
absl::Status ParsePackage();
Expand Down