protected void IntegrateQueryDevices(IAndroidLogcatTaskResult resut) { var deviceIdsResult = ((AndroidLogcatRetrieveDeviceIdsResult)resut); var deviceInfos = deviceIdsResult.deviceInfo; foreach (var d in m_Devices) { d.Value.UpdateState(IAndroidLogcatDevice.DeviceState.Disconnected); } foreach (var info in deviceInfos) { GetOrCreateDevice(info.id).UpdateState(info.state); } // If our selected device was removed, deselect it if (m_SelectedDevice != null && m_SelectedDevice.State != IAndroidLogcatDevice.DeviceState.Connected) { m_SelectedDevice = null; if (deviceIdsResult.notifyListeners) DeviceSelected?.Invoke(m_SelectedDevice); } if (m_SelectedDevice != null) { if (m_SelectedDevice != m_Devices[m_SelectedDevice.Id]) throw new Exception("The selected device is not among our list of devices"); } DevicesUpdated?.Invoke(); }
internal void SelectDevice(IAndroidLogcatDevice device, bool notifyListeners = true) { if (m_SelectedDevice == device) return; if (device != null && device.State != IAndroidLogcatDevice.DeviceState.Connected) { AndroidLogcatInternalLog.Log("Trying to select device which is not connected: " + device.Id); if (m_SelectedDevice == null) return; m_SelectedDevice = null; } else { m_SelectedDevice = device; } if (m_SelectedDevice != null && !m_Devices.Keys.Contains(m_SelectedDevice.Id)) throw new Exception("Selected device is not among our listed devices"); m_Runtime.UserSettings.LastSelectedDeviceId = m_SelectedDevice != null ? m_SelectedDevice.Id : ""; if (notifyListeners) DeviceSelected?.Invoke(m_SelectedDevice); }
public static string GetPackageNameFromPid(AndroidBridge.ADB adb, IAndroidLogcatDevice device, int processId) { if (device == null) { return(string.Empty); } try { // Note: Flag -o doesn't work on Android 5.0 devices (tested on LGE LG-D620, 5.0.2) string cmd = string.Format("-s {0} shell ps -p {1}", device.Id, processId); AndroidLogcatInternalLog.Log("{0} {1}", adb.GetADBPath(), cmd); var output = adb.Run(new[] { cmd }, "Unable to get the package name for pid " + processId); if (string.IsNullOrEmpty(output)) { return(string.Empty); } var result = ProcessOutputFromPS(output); if (string.IsNullOrEmpty(result)) { AndroidLogcatInternalLog.Log("Unable to get the package name for pid " + processId + "\nOutput:\n" + output); } return(result); } catch (Exception ex) { AndroidLogcatInternalLog.Log(ex.Message); return(string.Empty); } }
/// <summary> /// Return the pid of the given package on the given device. /// </summary> public static int GetPidFromPackageName(AndroidBridge.ADB adb, IAndroidLogcatDevice device, string packageName) { if (device == null) return -1; try { string cmd = null; if (device.SupportsFilteringByPid) cmd = string.Format("-s {0} shell pidof -s {1}", device.Id, packageName); else cmd = string.Format("-s {0} shell ps", device.Id); AndroidLogcatInternalLog.Log("{0} {1}", adb.GetADBPath(), cmd); var output = adb.Run(new[] { cmd }, "Unable to get the pid of the given packages."); if (string.IsNullOrEmpty(output)) return -1; if (device.SupportsFilteringByPid) { AndroidLogcatInternalLog.Log(output); return int.Parse(output); } return ParsePidInfo(packageName, output); } catch (Exception ex) { AndroidLogcatInternalLog.Log(ex.Message); return -1; } }
internal void QueueMemoryRequest(IAndroidLogcatDevice device, PackageInformation package) { m_ExpectedDevice = device; m_ExpectedPackageFromRequest = package; if (m_ExpectedPackageFromRequest == null || !m_ExpectedPackageFromRequest.IsAlive() || m_ExpectedDevice == null) { return; } // Don't make a memory request, if previous requests haven't finished yet // Otherwise async queue will grow bigger and bigger const int kMaxRequestsInQueue = 3; if (m_RequestsInQueue > kMaxRequestsInQueue) { return; } m_RequestsInQueue++; m_Runtime.Dispatcher.Schedule( new AndroidLogcatQueryMemoryInput() { adb = ADB.GetInstance(), packageProcessId = m_ExpectedPackageFromRequest.processId, packageName = m_ExpectedPackageFromRequest.name, deviceId = device.Id }, QueryMemoryAsync, IntegrateQueryMemory, false); }
private void DisconnectDevice(IAndroidLogcatDevice device) { var command = "disconnect " + device.Id; AndroidLogcatInternalLog.Log("adb " + command); var result = m_Runtime.Tools.ADB.Run(new[] { command }, "Failed to disconnect " + device.Id); AndroidLogcatInternalLog.Log(result); }
private void OnLogcatDisconnected(IAndroidLogcatDevice device) { StopLogCat(); var msg = "Either adb application crashed or device disconnected (device id: " + device.DisplayName + ")"; AndroidLogcatInternalLog.Log(msg); m_Runtime.DeviceQuery.UpdateConnectedDevicesList(true); UpdateStatusBar(msg); }
internal void ClearEntries() { m_SelectedEntry = -1; m_EntryCount = 0; m_CurrentEntry = 0; m_UpperMemoryBoundry = 32 * 1000 * 1000; m_ExpectedPackageFromRequest = null; m_ExpectedDevice = null; }
private void OnSelectedDevice(IAndroidLogcatDevice device) { if (device == null) { return; } ResetPackages(device); UpdateDebuggablePackages(); RestartLogCat(); }
public AndroidLogcat(AndroidLogcatRuntimeBase runtime, ADB adb, IAndroidLogcatDevice device, int packagePid, Priority priority, string filter, bool filterIsRegex, string[] tags) { this.m_Runtime = runtime; this.adb = adb; this.m_Device = device; this.m_PackagePid = packagePid; this.m_MessagePriority = priority; this.m_FilterIsRegex = filterIsRegex; InitFilterRegex(filter); this.m_Tags = tags; LogEntry.SetTimeFormat(m_Device.SupportYearFormat ? LogEntry.kTimeFormatWithYear : LogEntry.kTimeFormatWithoutYear); }
internal AndroidLogcatMessageProviderBase(AndroidBridge.ADB adb, string filter, Priority priority, int packageID, string logPrintFormat, IAndroidLogcatDevice device, Action <string> logCallbackAction) { m_ADB = adb; m_Filter = filter; m_Priority = priority; m_PackageID = packageID; m_LogPrintFormat = logPrintFormat; m_Device = device; m_LogCallbackAction = logCallbackAction; if (device != null && !device.SupportsFilteringByRegex && !string.IsNullOrEmpty(m_Filter)) { throw new Exception($"Device '{device.Id}' doesn't support filtering by regex, by filter was specified?"); } }
private List <PackageInformation> GetOrCreatePackagesForDevice(IAndroidLogcatDevice device) { if (device == null) { return(new List <PackageInformation>()); } List <PackageInformation> packages = null; if (!m_KnownPackages.TryGetValue(device.Id, out packages)) { packages = new List <PackageInformation>(); m_KnownPackages[device.Id] = packages; } return(packages); }
private void GetDeviceAndPackageFromSavedState(out IAndroidLogcatDevice savedDevice, out PackageInformation savedPackage) { savedDevice = null; savedPackage = null; var settings = m_Runtime.UserSettings; if (!settings.LastSelectedDeviceIdValid) { return; } var savedDeviceId = settings.LastSelectedDeviceId; savedDevice = m_Runtime.DeviceQuery.GetDevice(savedDeviceId); savedPackage = settings.LastSelectedPackage; }
public void CleanupDeadPackagesForDevice(IAndroidLogcatDevice device) { if (device == null) { return; } List <PackageInformation> packages = null; if (!m_KnownPackages.TryGetValue(device.Id, out packages)) { return; } int deadPackageCount = 0; for (int i = 0; i < packages.Count; i++) { if (packages[i].IsAlive() == false) { deadPackageCount++; } } // Need to remove the package which were added first, since they are the oldest packages int deadPackagesToRemove = deadPackageCount - kMaxExitedPackages; if (deadPackagesToRemove <= 0) { return; } for (int i = 0; i < packages.Count && deadPackagesToRemove > 0;) { if (packages[i].IsAlive()) { i++; continue; } deadPackagesToRemove--; packages.RemoveAt(i); } RefreshPackagesForSerialization(); }
/// <summary> /// Get the top activity on the given device. /// </summary> public static bool GetTopActivityInfo(AndroidBridge.ADB adb, IAndroidLogcatDevice device, ref string packageName, ref int packagePid) { if (device == null) return false; try { var cmd = "-s " + device.Id + " shell \"dumpsys activity\" "; AndroidLogcatInternalLog.Log("{0} {1}", adb.GetADBPath(), cmd); var output = adb.Run(new[] { cmd }, "Unable to get the top activity."); packagePid = AndroidLogcatUtilities.ParseTopActivityPackageInfo(output, out packageName); return packagePid != -1; } catch (Exception) { return false; } }
public static string GetPackageNameFromPid(ADB adb, IAndroidLogcatDevice device, int processId) { if (device == null) { return(string.Empty); } try { string cmd = string.Format("-s {0} shell ps -p {1} -o NAME", device.Id, processId); AndroidLogcatInternalLog.Log("{0} {1}", adb.GetADBPath(), cmd); var output = adb.Run(new[] { cmd }, "Unable to get the package name for pid " + processId); if (string.IsNullOrEmpty(output)) { return(string.Empty); } using (var sr = new StringReader(output)) { string line; while ((line = sr.ReadLine().Trim()) != null) { if (line.Equals("NAME")) { continue; } return(line); } } AndroidLogcatInternalLog.Log("Unable to get the package name for pid " + processId + "\nOutput:\n" + output); return(string.Empty); } catch (Exception ex) { AndroidLogcatInternalLog.Log(ex.Message); return(string.Empty); } }
internal void Clear() { m_SelectedDevice = null; }
public IReadOnlyList <PackageInformation> GetKnownPackages(IAndroidLogcatDevice device) { return(GetOrCreatePackagesForDevice(device)); }
public PackageInformation CreatePackageInformation(string packageName, int pid, IAndroidLogcatDevice device) { if (pid <= 0) { return(null); } var packages = GetOrCreatePackagesForDevice(device); PackageInformation info = packages.FirstOrDefault(package => package.processId == pid); if (info != null) { return(info); } var newPackage = new PackageInformation() { name = packageName, processId = pid, deviceId = device.Id }; packages.Add(newPackage); RefreshPackagesForSerialization(); return(newPackage); }
private void OnLogcatConnected(IAndroidLogcatDevice device) { UpdateStatusBar(string.Empty); }
internal void SetExpectedDeviceAndPackage(IAndroidLogcatDevice device, PackageInformation package) { m_ExpectedDevice = device; m_ExpectedPackageFromRequest = package; }
public abstract AndroidLogcatMessageProviderBase CreateMessageProvider(AndroidBridge.ADB adb, string filter, Priority priority, int packageID, string logPrintFormat, IAndroidLogcatDevice device, Action <string> logCallbackAction);
private void OnLogcatConnected(IAndroidLogcatDevice device) { UpdateStatusBar(); }
private void ResetPackages(IAndroidLogcatDevice device) { AndroidLogcatInternalLog.Log("Reset packages"); SetPacakge(null); }
private int GetPidFromPackageName(Dictionary <string, int> cache, string packageName, IAndroidLogcatDevice device) { if (device == null) { return(-1); } // Getting pid for packages is a very costly operation, use cache to make less queries int pid; if (cache != null && cache.TryGetValue(packageName, out pid)) { return(pid); } pid = AndroidLogcatUtilities.GetPidFromPackageName(m_Runtime.Tools.ADB, device, packageName); if (cache != null) { cache[packageName] = pid; } return(pid); }
internal AndroidLogcatMessageProvider(AndroidBridge.ADB adb, string filter, Priority priority, int packageID, string logPrintFormat, IAndroidLogcatDevice device, Action <string> logCallbackAction) : base(adb, filter, priority, packageID, logPrintFormat, device, logCallbackAction) { }