コード例 #1
0
        public void GetVersionTest()
        {
            VersionInfoReceiver receiver = new VersionInfoReceiver();
            Assert.AreEqual<int>(10210, (int)receiver.GetVersionCode("versionCode=10210 targetSdk=18"));
            Assert.AreEqual<object>(null, receiver.GetVersionCode(null));
            Assert.AreEqual<object>(null, receiver.GetVersionCode(string.Empty));
            Assert.AreEqual<object>(null, receiver.GetVersionCode("versionCode=10210targetSdk=18"));

            Assert.AreEqual<string>("4.7.1", (string)receiver.GetVersionName("    versionName=4.7.1"));
            Assert.AreEqual<string>(null, (string)receiver.GetVersionName(null));
            Assert.AreEqual<string>(null, (string)receiver.GetVersionName(" test"));
            Assert.AreEqual<string>(null, (string)receiver.GetVersionName("    versionName"));
            Assert.AreEqual<string>(string.Empty, (string)receiver.GetVersionName("    versionName="));

            DeviceData device = new DeviceData();

            var dumpsys = string.Join(Environment.NewLine, File.ReadAllLines(@"dumpsys_package.txt"));

            StringReader reader = new StringReader(dumpsys);

            while (reader.Peek() >= 0)
            {
                receiver.AddOutput(reader.ReadLine());
            }

            receiver.Flush();

            Assert.AreEqual(10210, receiver.VersionInfo.VersionCode);
            Assert.AreEqual("4.7.1", receiver.VersionInfo.VersionName);
        }
コード例 #2
0
        /// <summary>
        /// Requests the version information from the device.
        /// </summary>
        /// <param name="packageName">
        /// The name of the package from which to get the application version.
        /// </param>
        public VersionInfo GetVersionInfo(string packageName)
        {
            this.ValidateDevice();

            VersionInfoReceiver receiver = new VersionInfoReceiver();

            this.Device.ExecuteShellCommand($"dumpsys package {packageName}", receiver);
            return(receiver.VersionInfo);
        }
コード例 #3
0
ファイル: PackageManager.cs プロジェクト: vebin/madb
        /// <summary>
        /// Requests the version information from the device.
        /// </summary>
        /// <param name="packageName">
        /// The name of the package from which to get the application version.
        /// </param>
        public VersionInfo GetVersionInfo(string packageName)
        {
            this.ValidateDevice();

            VersionInfoReceiver receiver = new VersionInfoReceiver();
            this.Device.ExecuteShellCommand($"dumpsys package {packageName}", receiver);
            return receiver.VersionInfo;
        }