|
楼主 |
发表于 2012-7-13 00:02
|
显示全部楼层
// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov Date: 2012/7/12 23:51:59* `6 V" [: g5 ?( p5 R y
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
e! l2 ^( Y* v5 e! D* k5 X// Decompiler options: packimports(3)
' I7 g- g9 D: N' Q// Source File Name: ChargeBatteryStage.java
- ^* ` b3 s y+ t% D/ w# B( T. F$ l- c1 \
package com.palm.nova.installer.core.stages;6 k p" q( b$ H( @, Q
# C: H7 y' s3 G2 U( n1 Dimport com.palm.nova.installer.core.*;
7 Z9 J. E: X' t$ O8 pimport com.palm.novacom.*;0 w2 a" G; m8 Z$ N& G4 ~
import java.io.IOException;
$ W- S& g4 f8 U m+ E, y2 a/ h8 s6 ]4 W1 a4 B+ |" p
// Referenced classes of package com.palm.nova.installer.core.stages:
" {$ P2 W( f7 J( w// BaseStage, GoIntoUpdateModeStage
. g* m* n5 R/ Q! d) A. p% _5 K( H6 v& S& ~3 |2 Z5 y
public class ChargeBatteryStage extends BaseStage
: Q+ I5 x% }& h& C implements IInstallerStage
8 |3 Z. i0 n8 i6 M- f{' L& s: L9 F& D+ V0 G0 o# G& T
( y1 ?9 K3 u; K @- d9 T, G8 o
public ChargeBatteryStage(INovacomDevice device)! M" h8 e4 v9 J* a! U7 z9 i
{' {( n% O4 T/ k5 N; [$ ^, a
jobId = null;) Z( I( s7 Y1 W( n+ y
progress = null;
( n- [) F/ i) D* N" w5 g2 P. e currentChargeLevel = 0;
3 e8 `! s$ n8 F p* U this.device = device;
9 H( Z6 K' `$ M! }8 D0 o/ { }
h4 |# P7 \2 Z3 ^6 @8 `: H
+ g& c! E/ B4 n public String toString()8 G" e7 [) Z" S) g
{
" L8 t) V* W' I G8 K$ N# N return "Battery Charger";, @1 @, h% F; u0 x! `, Y: C( O' Z1 O
}" {3 g' K" Z R0 a6 E9 I, n: u
" u: W* Z1 ]/ \
private void chargeBattery()9 h0 C( |0 t2 t+ b3 \
throws NovacomException, IOException
* Z/ P( C! W9 h1 S N7 _, P- E {
) \5 ?( G( s+ V. u e' | INovacomStream stream = device.runProgram("", null);$ V( ]! h6 g( S7 z% H4 R
String command = (new StringBuilder()).append("charging enable ").append(REQUIRED_POWER_PERCENTAGE).toString();% T& y" h! b* e. g/ ~6 t
byte bytes[] = command.getBytes("US-ASCII");) M* ~$ j6 d5 B* o* C/ o, s
stream.write(bytes);
6 d3 ~' j, c7 f/ q# z* ? stream.closeOutput();
+ P; H o" Z( x String streamReturn = stream.readLine();
$ n) W* |# b) {* F7 e/ a; a9 ] do
5 B0 s8 l& @. x( N! S$ s# X {
, x! N8 r6 _2 f6 b4 X3 J. { m* I$ ` streamReturn = stream.readLine();
" }$ J& Q3 R* G if(streamReturn == null)8 N/ C% ~- j3 ]9 n/ u S* a
{6 D2 P: h" ^' `/ R4 G
progress.commentOnJob(jobId, "stream interupted");
+ T* e6 @ |. y* t: p1 K' x throw new NovacomException(-1, "stream interupted");
( Q3 @2 m9 {" `" R5 Y }2 m8 e- W% Z" \0 f$ r
if(streamReturn.length() == 0)
9 A( s$ o$ x$ M8 j7 p( q7 k3 L$ r {% a# y; ^2 {: n$ A& [& Y! V
progress.commentOnJob(jobId, "power charged up");
" F2 [$ _- L& c/ V# P( i break;& X* U1 m6 m9 j* a1 A: X) u
}' ~5 v: Q( j# p# A
int start;
! r( j1 y, h$ p0 S5 n int end;
# x# Q# n: X8 c if((start = streamReturn.indexOf("p=")) >= 0 && (end = streamReturn.indexOf(" ", start + 2)) >= 2)# V6 H6 R* D; S% S5 G7 N; Q$ A
{6 v& W3 |. n# P6 D9 `7 N
start += 2;. c2 A+ B( F" `. F7 T# @! @$ E
String strReadBatteryPercentage = streamReturn.substring(start, end);
8 R2 I: r8 j7 p1 A4 J6 y& e try
7 l$ F2 g* @* R& r. p& ` {! O, M" C. @4 h3 ], ?! G1 f
int readBatteryPercentage = (new Integer(strReadBatteryPercentage)).intValue();
; S+ o+ v# w) h% K/ R0 k* F& w/ d if(readBatteryPercentage > currentChargeLevel)/ X4 c: M o* C1 ?- J
{
' M2 p f5 K' y2 s3 W* B4 l F currentChargeLevel = readBatteryPercentage;
. t. R9 Q2 H* l D" H/ C6 u progress.updateJob(jobId, currentChargeLevel);! l# P' I/ K% P* t: ~
progress.commentOnJob(jobId, (new StringBuilder()).append("battery percentage changed: ").append(currentChargeLevel).toString());4 w2 B ]1 U5 t9 W3 v
}0 N( B7 [ g1 ~# ^$ u* t' I" p% E
Thread.sleep(500L);) j( ~. N9 r# c0 E
}
% }3 G8 P' j* B% s3 K" s- I" \: _ catch(NumberFormatException e)% I: B. K5 T, @0 M1 D) C
{
( V- M5 v" s6 d5 V5 z3 o$ P1 _ progress.commentOnJob(jobId, (new StringBuilder()).append("+++++").append(streamReturn).append("-----").toString());
4 d4 |! c2 Q" w/ p }0 m# j0 \1 K) [, F$ x3 K7 K3 \
catch(InterruptedException e) { }0 C& T N5 |5 q7 { w
} else* a E4 g6 M4 S2 Q* P2 S( }0 ]
{9 D$ D; p( J4 n8 ?7 k" y
progress.commentOnJob(jobId, (new StringBuilder()).append("+++++").append(streamReturn).append("-----").toString());
" S4 ~3 t, w8 A$ p+ i3 u* H }" n0 _% c6 P8 {. S: v: x6 u9 `
stream.flush();) @/ V' N0 n& L& m
} while(true);
9 }& `( X) Y4 u+ q6 V; T1 C% N stream.close();: c5 [- A9 G& L# g- g( B5 b5 R4 _
}
4 I" a% ?% B, @6 A, [: W( M. m& ?. P- B' `* I# c% {
public void run()' [2 ~( [- Q6 X
throws NovacomException, IOException( |) @8 |9 \. O# {/ Y; Y
{+ F. |% w, ]* @% n8 F& B
progress = getProgressHandler();% J6 o! i% M' C& B B( k- Y4 S
jobId = progress.startJob("Battery Charger Stage", 100);6 m/ \! M9 K& g/ S
if(device.getState() != com.palm.novacom.Novacom.DeviceState.BOOTLOADER)
+ U* Z) \# J+ o8 H F {
, D, v O% W- u$ Z5 g, R# ] GoIntoUpdateModeStage intoUpdateMode = new GoIntoUpdateModeStage(device);
/ T8 y# U; T8 a intoUpdateMode.run();8 m$ {; V) y: C, Q' ?4 H( [" J
}
- n& G2 p3 w9 S BootieUtilities bootie = new BootieUtilities(device);; Q9 P* F4 v+ C: E" P' n
int currentPercentage = bootie.checkPowerStatus().intValue();) R* z9 n U9 K0 X: N
if(REQUIRED_POWER_PERCENTAGE.intValue() > currentPercentage)
$ U: L- Q6 q8 [2 T {/ P x) h8 A! H8 J: m
progress.commentOnJob(jobId, (new StringBuilder()).append("Battery at ").append(currentPercentage).append("%").toString());
! y, l6 e D! V& b" G0 n+ x; `7 o7 w int count = 0;- i) r% n* _6 r3 x/ z/ ?" Z
do
% W Y" `, s) O: w0 \% W {
9 _: H& U6 ?& {. T6 Z9 t6 i progress.commentOnJob(jobId, "Battery Charging Started");+ l! C) H, S: u( B8 m
progress.commentOnJob(jobId, (new StringBuilder()).append("Charging to Sufficient Power (").append(REQUIRED_POWER_PERCENTAGE).append("%), this may take a couple of minutes").toString());; I6 B& i5 l p+ u
chargeBattery();
2 j0 S' P3 ?" X if(++count > RECHARGE_RETRY_COUNT.intValue())
* Y- x3 Y1 `9 @0 k, b3 w throw new NovacomException(-1, "failed to charge batttery");
( f$ _$ _3 M2 W } while(REQUIRED_POWER_PERCENTAGE.intValue() > currentChargeLevel);4 P7 v8 X2 u5 n3 a6 D: \/ @
}
4 f* |6 x+ h q7 R R progress.endJob(jobId);7 Z3 k- i0 s& c0 p, F( [3 ~
}
6 s% A- V3 b* x5 ]& a. J C: s# ^# ^: s; C
private static final Integer REQUIRED_POWER_PERCENTAGE = Integer.valueOf(25);
2 _1 G) a1 G1 r; U# X( D. t& h private static final Integer RECHARGE_RETRY_COUNT = Integer.valueOf(5);
% Q7 l+ m) w! M) U$ \- ^ private final INovacomDevice device;
- B1 Z) F9 D- k" j private Object jobId;6 ?8 I- \. {6 |3 {- s! F. m
private IStageProgressReporter progress;" N, _2 T& [5 \6 N
private int currentChargeLevel;3 J. D0 R6 k! W6 m* t: q) [: A
" n) w7 Z1 A; ^, S4 V}
8 i4 d2 J/ o: F/ Q8 t$ a7 v# E; C% o; C5 K' H
5 _, @( o+ m5 j) `7 Q6 L
求编译~~~~~~~~~~~~~~~~~ |
|