Пример #1
0
        public void InstallRemotePackageTest()
        {
            var adbClient = new DummyAdbClient();

            adbClient.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            adbClient.Commands.Add("pm install /data/test.apk", string.Empty);
            adbClient.Commands.Add("pm install -r /data/test.apk", string.Empty);

            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            PackageManager manager = new PackageManager(adbClient, device);

            manager.InstallRemotePackage("/data/test.apk", false);

            Assert.Equal(2, adbClient.ReceivedCommands.Count);
            Assert.Equal("pm install /data/test.apk", adbClient.ReceivedCommands[1]);

            manager.InstallRemotePackage("/data/test.apk", true);

            Assert.Equal(3, adbClient.ReceivedCommands.Count);
            Assert.Equal("pm install -r /data/test.apk", adbClient.ReceivedCommands[2]);
        }
Пример #2
0
        public void InstallPackageTest()
        {
            var syncService = new DummySyncService();

            Factories.SyncServiceFactory = (c, d) => syncService;

            var adbClient = new DummyAdbClient();

            adbClient.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            adbClient.Commands.Add("pm install /data/local/tmp/test.txt", string.Empty);
            adbClient.Commands.Add("rm /data/local/tmp/test.txt", string.Empty);

            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            PackageManager manager = new PackageManager(adbClient, device);

            manager.InstallPackage("test.txt", false);
            Assert.Equal(3, adbClient.ReceivedCommands.Count);
            Assert.Equal("pm install /data/local/tmp/test.txt", adbClient.ReceivedCommands[1]);
            Assert.Equal("rm /data/local/tmp/test.txt", adbClient.ReceivedCommands[2]);

            Assert.Single(syncService.UploadedFiles);
            Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/test.txt"));
        }
Пример #3
0
        public void ListPropertiesTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();

            client.Commands.Add("/system/bin/getprop", @"[init.svc.BGW]: [running]
[init.svc.MtkCodecService]: [running]
[init.svc.bootanim]: [stopped]");
            AdbClient.Instance = client;

            var properties = device.GetProperties();

            Assert.NotNull(properties);
            Assert.Equal(3, properties.Count);
            Assert.True(properties.ContainsKey("init.svc.BGW"));
            Assert.True(properties.ContainsKey("init.svc.MtkCodecService"));
            Assert.True(properties.ContainsKey("init.svc.bootanim"));

            Assert.Equal("running", properties["init.svc.BGW"]);
            Assert.Equal("running", properties["init.svc.MtkCodecService"]);
            Assert.Equal("stopped", properties["init.svc.bootanim"]);
        }
Пример #4
0
        public void InstallRemotePackageTest()
        {
            var adbClient = new DummyAdbClient();

            adbClient.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            adbClient.Commands.Add("pm install /data/test.apk", string.Empty);
            adbClient.Commands.Add("pm install -r /data/test.apk", string.Empty);

            AdbClient.Instance = adbClient;

            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            PackageManager manager = new PackageManager(device);
            manager.InstallRemotePackage("/data/test.apk", false);

            Assert.AreEqual(2, adbClient.ReceivedCommands.Count);
            Assert.AreEqual("pm install /data/test.apk", adbClient.ReceivedCommands[1]);

            manager.InstallRemotePackage("/data/test.apk", true);

            Assert.AreEqual(3, adbClient.ReceivedCommands.Count);
            Assert.AreEqual("pm install -r /data/test.apk", adbClient.ReceivedCommands[2]);
        }
Пример #5
0
        public void ParseThirdPartyPackage()
        {
            // Arrange
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();

            AdbClient.Instance = client;

            PackageManager         manager  = new PackageManager(device, thirdPartyOnly: false, client: client, syncServiceFactory: null, skipInit: true);
            PackageManagerReceiver receiver = new PackageManagerReceiver(device, manager);

            // Act
            receiver.AddOutput("package:/data/app/com.google.android.apps.plus-qQaDuXCpNqJuQSbIS6OxGA==/base.apk=com.google.android.apps.plus");
            receiver.AddOutput("package:/system/app/LegacyCamera.apk=com.android.camera");
            receiver.AddOutput("package:mwc2015.be");
            receiver.Flush();

            // Assert
            Assert.Equal(3, manager.Packages.Count);
            Assert.True(manager.Packages.ContainsKey("com.google.android.apps.plus"));
            Assert.True(manager.Packages.ContainsKey("com.android.camera"));
            Assert.True(manager.Packages.ContainsKey("mwc2015.be"));

            Assert.Equal("/data/app/com.google.android.apps.plus-qQaDuXCpNqJuQSbIS6OxGA==/base.apk", manager.Packages["com.google.android.apps.plus"]);
        }
Пример #6
0
        public void InstallPackageTest()
        {
            var syncService = new DummySyncService();
            Factories.SyncServiceFactory = (d) => syncService;

            var adbClient = new DummyAdbClient();

            adbClient.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            adbClient.Commands.Add("pm install /storage/sdcard0/tmp/test.txt", string.Empty);
            adbClient.Commands.Add("rm /storage/sdcard0/tmp/test.txt", string.Empty);

            AdbClient.Instance = adbClient;

            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            PackageManager manager = new PackageManager(device);
            manager.InstallPackage("test.txt", false);
            Assert.AreEqual(3, adbClient.ReceivedCommands.Count);
            Assert.AreEqual("pm install /storage/sdcard0/tmp/test.txt", adbClient.ReceivedCommands[1]);
            Assert.AreEqual("rm /storage/sdcard0/tmp/test.txt", adbClient.ReceivedCommands[2]);

            Assert.AreEqual(1, syncService.UploadedFiles.Count);
            Assert.IsTrue(syncService.UploadedFiles.ContainsKey("/storage/sdcard0/tmp/test.txt"));
        }
Пример #7
0
        public void PackagesPropertyTest2()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();

            client.Commands.Add("pm list packages -f", "package:mwc2015.be");
            PackageManager manager = new PackageManager(client, device);

            Assert.True(manager.Packages.ContainsKey("mwc2015.be"));
            Assert.Null(manager.Packages["mwc2015.be"]);
        }
Пример #8
0
        public void PackagesPropertyTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();

            client.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            PackageManager manager = new PackageManager(client, device);

            Assert.True(manager.Packages.ContainsKey("com.android.gallery3d"));
            Assert.Equal("/system/app/Gallery2/Gallery2.apk", manager.Packages["com.android.gallery3d"]);
        }
Пример #9
0
        public void GetEnvironmentVariablesTest()
        {
            var adbClient = new DummyAdbClient();
            AdbClient.Instance = adbClient;

            adbClient.Commands.Add(EnvironmentVariablesReceiver.PrintEnvCommand, "a=b");

            var device = new DeviceData();

            var variables = device.GetEnvironmentVariables();
            Assert.IsNotNull(variables);
            Assert.AreEqual(1, variables.Keys.Count);
            Assert.IsTrue(variables.ContainsKey("a"));
            Assert.AreEqual("b", variables["a"]);
        }
Пример #10
0
        public void GetEnvironmentVariablesTest()
        {
            var adbClient = new DummyAdbClient();

            AdbClient.Instance = adbClient;

            adbClient.Commands.Add(EnvironmentVariablesReceiver.PrintEnvCommand, "a=b");

            var device = new DeviceData();

            var variables = device.GetEnvironmentVariables();

            Assert.IsNotNull(variables);
            Assert.AreEqual(1, variables.Keys.Count);
            Assert.IsTrue(variables.ContainsKey("a"));
            Assert.AreEqual("b", variables["a"]);
        }
Пример #11
0
        public void GetPackageVersionInfoTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();

            client.Commands.Add("dumpsys package com.google.android.gms", File.ReadAllText("gapps.txt"));
            PackageManager manager = new PackageManager(client, device, skipInit: true);

            var versionInfo = manager.GetVersionInfo("com.google.android.gms");

            Assert.Equal(11062448, versionInfo.VersionCode);
            Assert.Equal("11.0.62 (448-160311229)", versionInfo.VersionName);
        }
Пример #12
0
        public void UninstallPackageTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();

            client.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            client.Commands.Add("pm uninstall com.android.gallery3d", "Success");
            PackageManager manager = new PackageManager(client, device);

            // Command should execute correctly; if the wrong command is passed an exception
            // would be thrown.
            manager.UninstallPackage("com.android.gallery3d");
        }
Пример #13
0
        public void ListPropertiesTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();
            client.Commands.Add("/system/bin/getprop", @"[init.svc.BGW]: [running]
            [init.svc.MtkCodecService]: [running]
            [init.svc.bootanim]: [stopped]");
            AdbClient.Instance = client;

            var properties = device.GetProperties();
            Assert.IsNotNull(properties);
            Assert.AreEqual(3, properties.Count);
            Assert.IsTrue(properties.ContainsKey("init.svc.BGW"));
            Assert.IsTrue(properties.ContainsKey("init.svc.MtkCodecService"));
            Assert.IsTrue(properties.ContainsKey("init.svc.bootanim"));

            Assert.AreEqual("running", properties["init.svc.BGW"]);
            Assert.AreEqual("running", properties["init.svc.MtkCodecService"]);
            Assert.AreEqual("stopped", properties["init.svc.bootanim"]);
        }
Пример #14
0
        public void PackagesPropertyTest2()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();
            client.Commands.Add("pm list packages -f", "package:mwc2015.be");
            AdbClient.Instance = client;
            PackageManager manager = new PackageManager(device);

            Assert.IsTrue(manager.Packages.ContainsKey("mwc2015.be"));
            Assert.AreEqual(null, manager.Packages["mwc2015.be"]);
        }
Пример #15
0
        public void PackagesPropertyTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();
            client.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            AdbClient.Instance = client;
            PackageManager manager = new PackageManager(device);

            Assert.IsTrue(manager.Packages.ContainsKey("com.android.gallery3d"));
            Assert.AreEqual("/system/app/Gallery2/Gallery2.apk", manager.Packages["com.android.gallery3d"]);
        }
Пример #16
0
        public void UninstallPackageTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();
            client.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            client.Commands.Add("pm uninstall com.android.gallery3d", "Success");
            AdbClient.Instance = client;
            PackageManager manager = new PackageManager(device);

            // Command should execute correctly; if the wrong command is passed an exception
            // would be thrown.
            manager.UninstallPackage("com.android.gallery3d");
        }