-
Notifications
You must be signed in to change notification settings - Fork 2
/
jflash.ps1
153 lines (122 loc) · 4.97 KB
/
jflash.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Set-Location -Path $PSScriptRoot
. .\Utilities\messages.ps1
. .\Utilities\countdown.ps1
. .\Utilities\adbflash.ps1
. .\Android\flashAndroid.ps1
function List-UsbDevices(){
return gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)};
}
function USBDevices(){
$device = List-UsbDevices | Where-Object {$_.Description -like '*Android*' -or $_.Description -like '*Google*'} | Select DeviceID
if ($device -eq $null) {
warning "No Android Devices Attached "
} else {
Write-host "Device in ADB mode Attached " $device
}
}
# ================================================================
# Check for the presense of java its version
# ================================================================
function checkjava () {
Write-Host
info 'Checking for java and minimum java version'
try {
# check for java
[string]$cmd = 'java'
[string]$arg = '-version'
[string]$result = & $cmd $arg 2>&1
info "Java version $result"
[string]$cmd = 'java'
[string]$arg = '-fullversion'
[string]$result = & $cmd $arg 2>&1
[int]$version = [convert]::ToInt32(((($result.split('"')[1]).split('-')[0]).replace('.','')).replace('_',''),10)
if ($version -lt 17079) {
Write-host
warning "The current version of Java is from an older release: version $result"
} else {
return 1
}
} catch {
Write-host
error "Java does not appear to be installed on this computer"
}
error "Please install at a minimum SE Runtime Environment 1.7.xxx"
Write-host
warning "JDK can be found here:"
warning "http://www.oracle.com/technetwork/java/javase/downloads/index.html"
Write-host
return 0
}
# ================================================================
# Script starts here
# ================================================================
# Read information regarding this flash operation
$content = (Get-Content ".\Product.txt") -split ' '
# ================================================================
# MODIFY THE ZIP FILENAME AND PRODUCT INFORMATION
# ================================================================
$ZipName= $content[0]
$BuildVersion= $content[1]
$Product= $content[2]
info "Windows Version"
[System.Environment]::OSVersion.Version
(Get-WmiObject -Class Win32_ComputerSystem).SystemType
Write-host
Write-host "Intrinsyc Technologies Corporation" -foreground green
Write-host "JFlash Updater for the " -foreground green -NoNewline
Write-host $Product -foreground white
Write-host "Build Version " -foreground green -NoNewLine
Write-host $BuildVersion -foreground white
if (checkjava -eq 1 ) {
Write-host
USBDevices
message "Rebooting the device into fastboot mode."
warning "Ignore <error: no devices found> potentially in fastboot already"
[string[]]$result = send_adb 'devices'
foreach ($response in $result) {
if ( -Not $response.contains("attached" )) {
if ( -Not $response.contains("server" )) {
if ( -Not $response.contains("successfully" )) {
if ( $response.contains("device" )) {
info "Device Build Information"
send_adb 'shell' 'getprop ro.build.description'
Write-host
info "Rebooting to Fastboot mode"
send_adb reboot-bootloader
# Give the device some time to reboot
Write-host
warning2 "Giving the device some time to reboot. Press Enter if already in" " in fastboot mode."
countdown 10
}
}
}
}
}
USBDevices
[string[]]$result = send_fastboot 'devices'
if ($result) {
if ( $result.Length -ne 0 ) {
foreach ($response in $result) {
if ($response.contains("fastboot") ) {
$response = send_fastboot 'getvar' 'product'
if ($response -Match $Product ){
success "Attached Model is Correct : $Product"
info "Flashing Meta Files"
# Flash the Meta files
java -Xms1G -Xmx1G -jar jflash.jar .\$ZipName$BuildVersion.zip NoPrompt
flash_Partitions
info "Rebooting the device"
send_fastboot 'reboot'
}
} else {
warning "No device attached"
}
}
}
else {
error "No Devices Found"
}
} else {
error "No Devices Found"
}
}