Skip to content

Commit

Permalink
Ask user to grant INTERNET permission + grant all-files access
Browse files Browse the repository at this point in the history
  • Loading branch information
elviscapiaq committed Jan 15, 2025
1 parent 79e7368 commit 81b60ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 81b60ed

Please sign in to comment.