示例#1
0
        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;
            }
        }
        public AndroidLogcat(AndroidLogcatRuntimeBase runtime, AndroidBridge.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);
        }
示例#4
0
        /// <summary>
        /// Capture the screenshot on the given device.
        /// </summary>
        /// <returns> Return the path to the screenshot on the PC. </returns>
        public static string CaptureScreen(AndroidBridge.ADB adb, string deviceId, out string error)
        {
            error = string.Empty;
            if (string.IsNullOrEmpty(deviceId))
            {
                error = "Invalid device id.";
                return(null);
            }

            try
            {
                const string screenshotPathOnDevice = "/sdcard/screen.png";

                // Capture the screen on the device.
                var cmd = string.Format("-s {0} shell screencap {1}", deviceId, screenshotPathOnDevice);
                AndroidLogcatInternalLog.Log("{0} {1}", adb.GetADBPath(), cmd);

                var errorMsg  = "Unable to capture the screen for device ";
                var outputMsg = adb.Run(new[] { cmd }, errorMsg + deviceId);
                if (outputMsg.StartsWith(errorMsg))
                {
                    AndroidLogcatInternalLog.Log(outputMsg);
                    Debug.LogError(outputMsg);
                    error = outputMsg;
                    return(null);
                }

                // Pull screenshot from the device to temp folder.
                var filePath = Path.Combine(Path.GetTempPath(), "screen_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".png");
                cmd = string.Format("-s {0} pull {1} {2}", deviceId, screenshotPathOnDevice, filePath);
                AndroidLogcatInternalLog.Log("{0} {1}", adb.GetADBPath(), cmd);

                errorMsg  = "Unable to pull the screenshot from device ";
                outputMsg = adb.Run(new[] { cmd }, errorMsg + deviceId);
                if (outputMsg.StartsWith(errorMsg))
                {
                    AndroidLogcatInternalLog.Log(outputMsg);
                    Debug.LogError(outputMsg);
                    error = outputMsg;
                    return(null);
                }

                return(filePath);
            }
            catch (Exception ex)
            {
                AndroidLogcatInternalLog.Log("Exception caugth while capturing screen on device {0}. Details\r\n:{1}", deviceId, ex);
                error = ex.Message;
                return(null);
            }
        }
        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?");
            }
        }
 /// <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;
     }
 }
        internal AndroidLogcatDevice(AndroidBridge.ADB adb, string deviceId)
        {
            m_Id = deviceId;

            if (adb == null)
            {
                m_Device = null;
                return;
            }

            try
            {
                m_Device = new AndroidBridge.AndroidDevice(adb, deviceId);
            }
            catch (Exception ex)
            {
                AndroidLogcatInternalLog.Log("Exception caugth while trying to retrieve device details for device {0}. This is harmless and device id will be used. Details\r\n:{1}", deviceId, ex);
                // device will be null in this case (and it will not be added to the cache)
                m_Device = null;
            }
        }
示例#8
0
 public abstract AndroidLogcatMessageProviderBase CreateMessageProvider(AndroidBridge.ADB adb, string filter, Priority priority, int packageID, string logPrintFormat, IAndroidLogcatDevice device, Action <string> logCallbackAction);
 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)
 {
 }