Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benpious authored and muandrew committed Feb 28, 2019
1 parent 2c321f9 commit 44397f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
20 changes: 10 additions & 10 deletions AndroidTool/ApkHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@

import Cocoa

protocol ApkHandlerDelegate {
protocol ApkHandlerDelegate: AnyObject {
func apkHandlerDidStart()
func apkHandlerDidGetInfo(_ apk:Apk)
func apkHandlerDidUpdate(_ update:String)
func apkHandlerDidFinish()
}

class ApkHandler: NSObject {
var filepath:String!
var delegate:ApkHandlerDelegate?
var device:Device!
var filepath:String?
weak var delegate:ApkHandlerDelegate?
var device:Device

init(filepath:String, device:Device){
print(">>apk init apkhandler")
super.init()
self.filepath = filepath
self.device = device
print(">>apk init apkhandler")
super.init()
}

init(device:Device){
self.device = device
print(">>apk init apkhandler with no apk")
super.init()
self.device = device
}

func installAndLaunch(_ complete:@escaping ()->Void){
Expand All @@ -53,7 +53,7 @@ class ApkHandler: NSObject {
if device.adbIdentifier == nil { print("no adbIdentifier, aborting"); return }
let s = ShellTasker(scriptFile: "installApkOnDevice")

s.run(arguments: [device.adbIdentifier!, filepath]) { (output) -> Void in
s.run(arguments: [device.adbIdentifier!, filepath!]) { (output) -> Void in
self.delegate?.apkHandlerDidUpdate("Installed")
completion()
}
Expand All @@ -76,14 +76,14 @@ class ApkHandler: NSObject {
delegate?.apkHandlerDidUpdate("Getting info...")

let shell = ShellTasker(scriptFile: "getApkInfo")
shell.run(arguments: [self.filepath]) { (output) -> Void in
shell.run(arguments: [self.filepath!]) { (output) -> Void in
let apk = Apk(rawAaptBadgingData: output as String)
self.delegate?.apkHandlerDidGetInfo(apk)

// try getting the icon out

let iconShell = ShellTasker(scriptFile: "extractIconFromApk")
iconShell.run(arguments: [self.filepath]) { (output) -> Void in
iconShell.run(arguments: [self.filepath!]) { (output) -> Void in
print("Ready to add nsurl path to apk object: \(output)")

apk.localIconPath = (output as String).trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
Expand Down
16 changes: 7 additions & 9 deletions AndroidTool/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
import Cocoa
import AVFoundation

protocol DeviceDelegate{
//
}

enum DeviceType:String {
case Phone="Phone", Watch="Watch", Tv="Tv", Auto="Auto"
}
Expand Down Expand Up @@ -42,8 +38,7 @@ class Device: NSObject {
var currentActivity : String = ""

convenience init(avDevice:AVCaptureDevice) {
self.init()
deviceOS = DeviceOS.ios
self.init(deviceOS: .ios)
firstBoot = hashFromString(avDevice.uniqueID)
brand = "Apple"
name = avDevice.localizedName
Expand All @@ -53,10 +48,9 @@ class Device: NSObject {
}

convenience init(properties:[String:String], adbIdentifier:String) {
self.init()
self.init(deviceOS: .android)

deviceOS = .android
self.adbIdentifier = adbIdentifier.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
self.adbIdentifier = adbIdentifier.trimmingCharacters(in: .whitespacesAndNewlines)

model = properties["ro.product.model"]
name = properties["ro.product.name"]
Expand Down Expand Up @@ -93,6 +87,10 @@ class Device: NSObject {
}
}

init(deviceOS: DeviceOS) {
self.deviceOS = deviceOS
}


func getCurrentActivity(_ completion:@escaping (_ activityName:String)->Void){
let task = ShellTasker(scriptFile: "getCurrentActivityForIdentifier")
Expand Down
8 changes: 0 additions & 8 deletions AndroidTool/UITweaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,32 @@ class UITweaker: NSObject {
if ud.bool(forKey: prop) { show = "show" }
let tweak = Tweak(command: "\(cmd) -e \(prop) \(show)", description: "\(show) \(prop)")
tweaks.append(tweak)
break
case "location", "alarm", "sync", "tty", "eri", "mute", "speakerphone": // status showhide
let cmd = "status"
var show = "hide"
if ud.bool(forKey: prop) { show = "show" }
let tweak = Tweak(command: "\(cmd) -e \(prop) \(show)", description: "\(show) \(prop)")
tweaks.append(tweak)
break
case "bluetooth":
var show = "hide"
if ud.bool(forKey: "bluetooth") {
show = "connected"
}
let tweak = Tweak(command: "status -e bluetooth \(show)", description: "Tweaking Bluetooth")
tweaks.append(tweak)
break
case "notifications":
var visible = "false"
if ud.bool(forKey: prop) {
visible = "true"
}
let tweak = Tweak(command: "\(prop) -e visible \(visible)", description: "Tweaking notfications")
tweaks.append(tweak)
break
case "clock":
if ud.bool(forKey: prop) {
let hhmm = formatTime(ud.string(forKey: C.PREF_TIME_VALUE)!)
let tweak = Tweak(command: "clock -e hhmm \(hhmm)", description: "Setting time to \(ud.string(forKey: C.PREF_TIME_VALUE)!)")
tweaks.append(tweak)
}
break
case "wifi":
var show = "hide"
var level = ""
Expand All @@ -91,7 +86,6 @@ class UITweaker: NSObject {
}
let tweak = Tweak(command: "network -e \(prop) \(show) \(level)", description: "\(show) \(prop)")
tweaks.append(tweak)
break
case "mobile":
var tweak:Tweak!
if ud.bool(forKey: prop){
Expand All @@ -102,7 +96,6 @@ class UITweaker: NSObject {
tweak = Tweak(command: "network -e mobile hide", description: "Turn cell icon off")
}
tweaks.append(tweak)
break
case "batteryCharging":
var showCharging = "false"
var description = "Set battery not charging"
Expand All @@ -113,7 +106,6 @@ class UITweaker: NSObject {
}
let tweak = Tweak(command: "battery -e plugged \(showCharging) -e level \(batLevel!)", description: description)
tweaks.append(tweak)
break
default:
break
}
Expand Down

0 comments on commit 44397f1

Please sign in to comment.