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

Add option to cleanup device #28

Merged
merged 1 commit into from
Oct 26, 2023
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
2 changes: 1 addition & 1 deletion capture_service/android_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ std::string AndroidApplication::GetMainActivity()
void AndroidApplication::Start()
{
m_dev.Adb().Run("shell input keyevent KEYCODE_WAKEUP");
m_dev.Adb().Run(absl::StrFormat("shell am start %s/%s", m_package, m_main_activity));
m_dev.Adb().Run(absl::StrFormat("shell am start -S -W %s/%s", m_package, m_main_activity));
m_started = true;
}

Expand Down
26 changes: 26 additions & 0 deletions capture_service/device_mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ std::vector<std::string> DeviceManager::ListDevice() const

return dev_list;
}
void DeviceManager::Cleanup(const std::string &serial, const std::string &package)
{
AdbSession adb(serial);
// Remove installed libs and libraries on device.
adb.Run("root");
adb.Run("wait-for-device");
adb.Run("remount");

adb.Run(absl::StrFormat("shell rm %s/%s", kTargetPath, kWrapLibName), true);
adb.Run(absl::StrFormat("shell rm %s/%s", kTargetPath, kVkLayerLibName), true);
adb.Run(absl::StrFormat("shell rm %s/%s", kTargetPath, kXrLayerLibName), true);
adb.Run(absl::StrFormat("shell rm -r %s", kManifestFilePath), true);
adb.Run(absl::StrFormat("forward --remove tcp:%d", kPort), true);

adb.Run("shell settings delete global enable_gpu_debug_layers");
adb.Run("shell settings delete global gpu_debug_app");
adb.Run("shell settings delete global gpu_debug_layers");
adb.Run("shell settings delete global gpu_debug_layer_app");
adb.Run("shell settings delete global gpu_debug_layers_gles");

// If package specified, remove package related settings.
if (!package.empty())
{
adb.Run(absl::StrFormat("shell setprop wrap.%s \\\"\\\"", package));
}
}

void AndroidDevice::RetrieveTraceFile(const std::string &trace_file_path,
const std::string &save_path)
Expand Down
1 change: 1 addition & 0 deletions capture_service/device_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DeviceManager
}

AndroidDevice *GetDevice() const { return m_device.get(); }
void Cleanup(const std::string &serial, const std::string &package);

private:
std::unique_ptr<AndroidDevice> m_device;
Expand Down
28 changes: 28 additions & 0 deletions capture_service/dive_client_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class Command
kListPackage,
kRunPackage,
kRunAndCapture,
kCleanup,
};

bool AbslParseFlag(absl::string_view text, Command* command, std::string* error)
Expand All @@ -63,6 +64,11 @@ bool AbslParseFlag(absl::string_view text, Command* command, std::string* error)
*command = Command::kRunAndCapture;
return true;
}
if (text == "cleanup")
{
*command = Command::kCleanup;
return true;
}
if (text.empty())
{
*command = Command::kNone;
Expand All @@ -81,6 +87,7 @@ std::string AbslUnparseFlag(Command command)
case Command::kListPackage: return "list_package";
case Command::kRunPackage: return "run";
case Command::kRunAndCapture: return "capture";
case Command::kCleanup: return "cleanup";

default: return absl::StrCat(command);
}
Expand Down Expand Up @@ -178,6 +185,22 @@ bool run_and_capture(Dive::DeviceManager& mgr, const std::string& package)
return true;
}

bool clean_up_app_and_device(Dive::DeviceManager& mgr, const std::string& package)
{
std::string serial = absl::GetFlag(FLAGS_device);

if (serial.empty() || package.empty())
{
std::cout << "Please run with `--device [serial]` and `--package [package]` options."
<< std::endl;
print_usage();
return false;
}

mgr.Cleanup(serial, package);
return true;
}

int main(int argc, char** argv)
{
absl::SetProgramUsageMessage("Run app with --help for more details");
Expand Down Expand Up @@ -220,6 +243,11 @@ int main(int argc, char** argv)
run_and_capture(mgr, package);
break;
}
case Command::kCleanup:
{
clean_up_app_and_device(mgr, package);
break;
}
case Command::kNone:
{
print_usage();
Expand Down
Loading