DevTools: Stop asking Android devices for installed packages list

BUG=354051

Review URL: https://codereview.chromium.org/291893011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272544 0039d316-1c4b-4281-b951-d872f2087c98
parent cdd86bc9
......@@ -12,7 +12,6 @@ namespace {
const char kDeviceModelCommand[] = "shell:getprop ro.product.model";
const char kInstalledChromePackagesCommand[] = "shell:pm list packages";
const char kOpenedUnixSocketsCommand[] = "shell:cat /proc/net/unix";
const char kListProcessesCommand[] = "shell:ps";
const char kDumpsysCommand[] = "shell:dumpsys window policy";
......@@ -83,31 +82,6 @@ const BrowserDescriptor* FindBrowserDescriptor(const std::string& package) {
return NULL;
}
typedef std::map<std::string, const BrowserDescriptor*> DescriptorMap;
static DescriptorMap FindInstalledBrowserPackages(const std::string& response) {
// Parse 'pm list packages' output which on Android looks like this:
//
// package:com.android.chrome
// package:com.chrome.beta
// package:com.example.app
//
DescriptorMap package_to_descriptor;
const std::string package_prefix = "package:";
std::vector<std::string> entries;
Tokenize(response, "'\r\n", &entries);
for (size_t i = 0; i < entries.size(); ++i) {
if (entries[i].find(package_prefix) != 0)
continue;
std::string package = entries[i].substr(package_prefix.size());
const BrowserDescriptor* descriptor = FindBrowserDescriptor(package);
if (!descriptor)
continue;
package_to_descriptor[descriptor->package] = descriptor;
}
return package_to_descriptor;
}
typedef std::map<std::string, std::string> StringMap;
static void MapProcessesToPackages(const std::string& response,
......@@ -247,8 +221,8 @@ void AdbDeviceInfoQuery::ReceivedDumpsys(int result,
ParseDumpsysResponse(response);
command_callback_.Run(
kInstalledChromePackagesCommand,
base::Bind(&AdbDeviceInfoQuery::ReceivedPackages,
kListProcessesCommand,
base::Bind(&AdbDeviceInfoQuery::ReceivedProcesses,
base::Unretained(this)));
}
......@@ -285,22 +259,7 @@ void AdbDeviceInfoQuery::ParseScreenSize(const std::string& str) {
}
void AdbDeviceInfoQuery::ReceivedPackages(
int result,
const std::string& packages_response) {
DCHECK(CalledOnValidThread());
if (result < 0) {
Respond();
return;
}
command_callback_.Run(
kListProcessesCommand,
base::Bind(&AdbDeviceInfoQuery::ReceivedProcesses,
base::Unretained(this), packages_response));
}
void AdbDeviceInfoQuery::ReceivedProcesses(
const std::string& packages_response,
int result,
const std::string& processes_response) {
DCHECK(CalledOnValidThread());
......@@ -312,28 +271,23 @@ void AdbDeviceInfoQuery::ReceivedProcesses(
kOpenedUnixSocketsCommand,
base::Bind(&AdbDeviceInfoQuery::ReceivedSockets,
base::Unretained(this),
packages_response,
processes_response));
}
void AdbDeviceInfoQuery::ReceivedSockets(
const std::string& packages_response,
const std::string& processes_response,
int result,
const std::string& sockets_response) {
DCHECK(CalledOnValidThread());
if (result >= 0)
ParseBrowserInfo(packages_response, processes_response, sockets_response);
ParseBrowserInfo(processes_response, sockets_response);
Respond();
}
void AdbDeviceInfoQuery::ParseBrowserInfo(
const std::string& packages_response,
const std::string& processes_response,
const std::string& sockets_response) {
DCHECK(CalledOnValidThread());
DescriptorMap package_to_descriptor =
FindInstalledBrowserPackages(packages_response);
StringMap pid_to_package;
StringMap package_to_pid;
MapProcessesToPackages(processes_response, pid_to_package, package_to_pid);
......@@ -367,42 +321,6 @@ void AdbDeviceInfoQuery::ParseBrowserInfo(
browser_info.display_name = GetDisplayName(socket, package);
device_info_.browser_info.push_back(browser_info);
}
// Find installed packages not mapped to browsers.
typedef std::multimap<std::string, const BrowserDescriptor*>
DescriptorMultimap;
DescriptorMultimap socket_to_descriptor;
for (DescriptorMap::iterator it = package_to_descriptor.begin();
it != package_to_descriptor.end(); ++it) {
std::string package = it->first;
const BrowserDescriptor* descriptor = it->second;
if (packages_for_running_browsers.count(package))
continue; // This package is already mapped to a browser.
if (package_to_pid.find(package) != package_to_pid.end()) {
// This package is running but not mapped to a browser.
socket_to_descriptor.insert(
DescriptorMultimap::value_type(descriptor->socket, descriptor));
continue;
}
}
// Try naming remaining unnamed browsers.
for (DescriptorMultimap::iterator it = socket_to_descriptor.begin();
it != socket_to_descriptor.end(); ++it) {
std::string socket = it->first;
const BrowserDescriptor* descriptor = it->second;
if (socket_to_descriptor.count(socket) != 1)
continue; // No definitive match.
BrowserMap::iterator bit = socket_to_unnamed_browser_index.find(socket);
if (bit != socket_to_unnamed_browser_index.end()) {
device_info_.browser_info[bit->second].display_name =
descriptor->display_name;
}
}
}
void AdbDeviceInfoQuery::Respond() {
......
......@@ -39,19 +39,14 @@ class AdbDeviceInfoQuery : public base::NonThreadSafe {
void ParseScreenSize(const std::string& str);
void ReceivedPackages(int result, const std::string& response);
void ReceivedProcesses(const std::string& packages_response,
int result,
void ReceivedProcesses(int result,
const std::string& processes_response);
void ReceivedSockets(const std::string& packages_response,
const std::string& processes_response,
void ReceivedSockets(const std::string& processes_response,
int result,
const std::string& sockets_response);
void ParseBrowserInfo(const std::string& packages_response,
const std::string& processes_response,
void ParseBrowserInfo(const std::string& processes_response,
const std::string& sockets_response);
void Respond();
......
......@@ -26,7 +26,6 @@ const char kOpenedUnixSocketsCommand[] = "shell:cat /proc/net/unix";
const char kDeviceModelCommand[] = "shell:getprop ro.product.model";
const char kDumpsysCommand[] = "shell:dumpsys window policy";
const char kListProcessesCommand[] = "shell:ps";
const char kInstalledChromePackagesCommand[] = "shell:pm list packages";
const char kSerialOnline[] = "01498B321301A00A";
const char kSerialOffline[] = "01498B2B0D01300E";
......@@ -67,13 +66,6 @@ const char kSampleListProcesses[] =
"u0_a77 1002 125 111111 222222 ffffffff 00000000 S com.chrome.beta\r\n"
"u0_a78 1003 126 111111 222222 ffffffff 00000000 S com.noprocess.app\r\n";
const char kSampleListPackages[] =
"package:com.sample.feed\r\n"
"package:com.android.nfc\r\n"
"package:com.android.chrome\r\n"
"package:com.chrome.beta\r\n"
"package:com.google.android.apps.chrome\r\n";
const char kSampleDumpsys[] =
"WINDOW MANAGER POLICY STATE (dumpsys window policy)\r\n"
" mSafeMode=false mSystemReady=true mSystemBooted=true\r\n"
......@@ -480,8 +472,6 @@ class MockAdbServer : SingleConnectionServer::Parser,
SendResponse(kSampleDumpsys);
} else if (command == kListProcessesCommand) {
SendResponse(kSampleListProcesses);
} else if (command == kInstalledChromePackagesCommand) {
SendResponse(kSampleListPackages);
} else if (command.find(kLocalAbstractPrefix) == 0) {
selected_socket_ = command.substr(strlen(kLocalAbstractPrefix));
SendResponse("");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment