Пример #1
0
        public async Task <bool> HasPackage(string pkgname)
        {
            //pm list packages com.miui.home
            bool hasPackage = false;
            var  ar         = new AsyncReceiver((lines) =>
            {
                string data      = string.Join("\n", lines);
                bool isInstalled = data.ToLower().Contains($"package:{pkgname}");
                hasPackage       = isInstalled;
                return(true);
            });
            // Create the token source.
            CancellationTokenSource cts = new CancellationTokenSource();

            this.ExecuteShellCommand($"pm list packages {pkgname}", ar, cts.Token);
            int timeout = 1000;
            var task    = ar.WaitAsync();

            if (await Task.WhenAny(task, Task.Delay(timeout)) == task)
            {
                // task completed within timeout
            }
            else
            {
                cts.Cancel();
                // timeout logic
            }
            return(hasPackage);
        }
Пример #2
0
        public async Task <bool> StartActivity(string act)
        {
            bool isOk = false;
            var  ar   = new AsyncReceiver((lines) =>
            {
                string data = string.Join("\n", lines);
                isOk        = data.ToLower().Contains("Starting: Intent");
                return(true);
            });

            this.ExecuteShellCommand($"am start {act}", ar);
            await ar.WaitAsync();

            return(isOk);
        }
Пример #3
0
        public async Task Uninstall(string pkgname, IShellOutputReceiver receiver)
        {
            var ar = new AsyncReceiver((lines) =>
            {
                string data    = string.Join("\n", lines);
                bool isUnknown = data.ToLower().Contains("unknown package");
                if (isUnknown)
                {
                    return(true);
                }
                Console.WriteLine(data);
                return(true);
            });

            this.ExecuteShellCommand($"pm uninstall {pkgname}", ar);
            await ar.WaitAsync();
        }