mirror of https://github.com/mvdan/fdroidcl.git
2 changed files with 67 additions and 0 deletions
@ -0,0 +1,66 @@
|
||||
// Copyright (c) 2024, Thomas Dickson
|
||||
// See LICENSE for licensing information
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strings" |
||||
|
||||
"mvdan.cc/fdroidcl/adb" |
||||
) |
||||
|
||||
var cmdScan = &Command{ |
||||
UsageLine: "scan", |
||||
Short: "Scan for all recognised apps on a connected device", |
||||
} |
||||
|
||||
func init() { |
||||
cmdScan.Run = runScan |
||||
} |
||||
|
||||
func runScan(args []string) error { |
||||
if err := startAdbIfNeeded(); err != nil { |
||||
return err |
||||
} |
||||
devices, err := adb.Devices() |
||||
if err != nil { |
||||
return fmt.Errorf("could not get devices: %v", err) |
||||
} |
||||
|
||||
if len(devices) == 0 { |
||||
return fmt.Errorf("no devices found") |
||||
} |
||||
|
||||
for _, device := range devices { |
||||
fmt.Printf("Scanning %s - %s (%s)\n", device.ID, device.Model, device.Product) |
||||
scanForPackages(device) |
||||
fmt.Println("Scan completed without error") |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func scanForPackages(device *adb.Device) { |
||||
cmd := device.AdbShell("pm list packages") |
||||
|
||||
out, err := cmd.Output() |
||||
if err != nil { |
||||
fmt.Println("could not run command: ", err) |
||||
} |
||||
// fmt.Println(string(out))
|
||||
// otherwise, print the output from running the command
|
||||
lines := strings.Split(string(out), "\n") |
||||
// fmt.Println(lines)
|
||||
|
||||
for _, line := range lines { |
||||
if len(line) > 8 { |
||||
line = line[8:] |
||||
// fmt.Println(line)
|
||||
|
||||
apps, err := findApps([]string{line}) |
||||
if err == nil { |
||||
fmt.Println(apps[0].PackageName) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue