|
楼主 |
发表于 2012-7-13 00:02
|
显示全部楼层
// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov Date: 2012/7/12 23:51:59 a# | \% d- q' }
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
) |7 ~1 b1 R4 j% |4 g% F// Decompiler options: packimports(3)
' D& G1 W8 C0 r% ?// Source File Name: ChargeBatteryStage.java2 A! N8 \# r, W) i
3 a2 H! _7 u2 I9 o B' {1 w+ X# Jpackage com.palm.nova.installer.core.stages;8 ~$ B9 c2 d [) K) c: X
# p d/ k9 K$ X' w) |* v9 t
import com.palm.nova.installer.core.*;
; p( D* E" q l: m+ l" \' cimport com.palm.novacom.*;% o, g! e3 B$ p* r
import java.io.IOException;' m p, `: J$ V4 ]7 f2 L
9 W6 c: Q1 u' D% p( g' W// Referenced classes of package com.palm.nova.installer.core.stages:" w+ M' F: {5 u9 Q
// BaseStage, GoIntoUpdateModeStage
9 Y$ s5 i% B5 \2 \6 b/ }9 c" W, c& O3 E. H3 D) P
public class ChargeBatteryStage extends BaseStage
7 K ~9 `* s0 `8 Q& J5 U implements IInstallerStage
. N. Q, m( O$ g" G6 j( d( J& z9 {( l{
* [8 P ~ G3 P7 H: C4 D) p/ M- H( s. U2 i% I; M4 U- B
public ChargeBatteryStage(INovacomDevice device). A' c7 k0 E; q0 ?/ I
{
$ i+ F$ m% x9 I( v8 m5 p jobId = null;
, Q" y9 A) @0 N3 n! f0 e) P+ y1 M progress = null;$ _$ B: |2 j' O, n( f& p9 T9 L
currentChargeLevel = 0;
3 n" i, V( f p& c+ J5 r9 R this.device = device;4 N5 B1 p, G) n3 c# @, @
}
+ `0 f6 m& c6 w, [- m R( s* m, ?- {2 A7 ~) S3 H
public String toString()
$ ~9 b% E! [# n {
9 _6 q/ `/ C9 b; J/ g! e return "Battery Charger";% @3 h. N; k5 Y% H
}% P2 U2 g0 x8 K1 A
; f0 f% J7 @3 K
private void chargeBattery()
# K- b- k" r- D3 K throws NovacomException, IOException
) e5 ?8 d5 q$ J7 c {3 b$ k. Z9 U2 ^9 V
INovacomStream stream = device.runProgram("", null);) v6 ?2 _- T$ ~* i3 e; R$ L2 O
String command = (new StringBuilder()).append("charging enable ").append(REQUIRED_POWER_PERCENTAGE).toString();* a0 m( i$ k8 C+ f3 x6 O' r- W
byte bytes[] = command.getBytes("US-ASCII");
# w+ t' Y* W3 U9 {! d$ ?9 J stream.write(bytes);! |( D5 J; E' Z8 I2 x
stream.closeOutput();
5 _% v n8 ?+ S2 b. n5 z: h String streamReturn = stream.readLine();
& Z) |% M, X6 ` do4 h/ D2 ~* U" Y3 z# H0 Z* S, b, W& t
{( Q$ s# j7 K4 E- w7 z- m* H
streamReturn = stream.readLine();
7 c( D1 \3 O$ g/ [3 e if(streamReturn == null)8 n+ E. I) u7 v# a- v4 }
{. Z6 V1 r2 p. u% T F
progress.commentOnJob(jobId, "stream interupted");; ^; h$ D+ {5 Y6 G
throw new NovacomException(-1, "stream interupted");6 a* U4 N# Z- J, A% K
}- u. g/ E% x7 D/ W
if(streamReturn.length() == 0)
: _0 @% }" a, v7 I {8 j$ s8 S6 s3 q0 n4 Y L; w
progress.commentOnJob(jobId, "power charged up");+ }+ w% u9 x( h" V0 b5 y. a+ z
break;- Q3 C; l# n z+ L) G
}
- \7 r; i1 [# w5 b+ X2 |/ W int start;
; M4 i0 p* l$ z& R6 N" h3 u int end;! j' c* L- T" y7 k# X( W, ^
if((start = streamReturn.indexOf("p=")) >= 0 && (end = streamReturn.indexOf(" ", start + 2)) >= 2)
0 @. R# h5 Q$ a) t% ~ {
1 M7 Z9 d& H4 C K3 T# {$ k+ C start += 2;8 q- i& }% W" f( ]
String strReadBatteryPercentage = streamReturn.substring(start, end);! M8 {& C2 p7 F0 A0 C0 V0 ]6 m8 N
try, b# a: O- }) P- T5 l4 a( w: T
{% T% u" B; V+ @ ?; N
int readBatteryPercentage = (new Integer(strReadBatteryPercentage)).intValue();+ P# N8 X: G0 M M
if(readBatteryPercentage > currentChargeLevel)
+ B! i6 {5 v. V, a6 C( U& w3 ]1 N {7 R3 M: D% K+ N) u& q$ L; v& R
currentChargeLevel = readBatteryPercentage;0 I/ N) h, @7 _" o m3 i
progress.updateJob(jobId, currentChargeLevel);
/ E) o. B% w: p progress.commentOnJob(jobId, (new StringBuilder()).append("battery percentage changed: ").append(currentChargeLevel).toString());
1 w2 m6 v' L$ k; j/ X9 x* H" a( c( j, V }
2 b" U5 Z3 k/ ^ Thread.sleep(500L);
& V3 F- p- u9 G; I }
+ F, x* S+ G* g1 k catch(NumberFormatException e)
% y) N3 I5 Y- z {
% n4 R8 F6 a3 {; `( g9 P, a progress.commentOnJob(jobId, (new StringBuilder()).append("+++++").append(streamReturn).append("-----").toString());
1 R2 W& H. ]2 k; c6 n- S! H, p }
; `6 m1 e3 t# o) R0 A* T9 w catch(InterruptedException e) { }# H: a; ~# e& G' z7 V9 r) p
} else7 f7 V7 L: v- x6 ~9 t+ @) n6 f' d
{, @( z# l- p- ]) t7 |% G7 S
progress.commentOnJob(jobId, (new StringBuilder()).append("+++++").append(streamReturn).append("-----").toString());
$ e" k! f' C3 @2 \, I }
, {" I5 [% k1 b2 K stream.flush();
+ k# u! i) L4 F7 Y& K } while(true);! ]1 u. H; p0 W: {. h7 S
stream.close();
9 h* f0 @& i3 B( x ]$ u }
/ o8 @ |7 y$ t, p+ g) {2 b/ ^) I0 K2 G& C) R% o6 v& _: a
public void run()2 {5 ?6 a0 _& q$ |3 l/ T+ M
throws NovacomException, IOException
' e: I9 Y3 k. d, @+ B2 j! ]! X {2 _# \" e; N) L* T% a" W
progress = getProgressHandler();* }) t6 e+ w7 i8 u9 U9 f: q
jobId = progress.startJob("Battery Charger Stage", 100);
, p* ?) J. L; l! k7 b* Y if(device.getState() != com.palm.novacom.Novacom.DeviceState.BOOTLOADER)
' y' U" e3 \4 H* o3 @8 ]8 l {# Z* I8 m% V# h8 l' c) Y3 w9 @/ M8 O
GoIntoUpdateModeStage intoUpdateMode = new GoIntoUpdateModeStage(device);; \' E. X- V: q: T
intoUpdateMode.run();/ K7 f# L x6 S$ P% p
}: \, z1 U) L& f- v
BootieUtilities bootie = new BootieUtilities(device);
, `1 W8 G3 ?% ~6 F int currentPercentage = bootie.checkPowerStatus().intValue();. d9 T; [5 {7 e/ B2 {, w G$ C
if(REQUIRED_POWER_PERCENTAGE.intValue() > currentPercentage). y! q- ^1 @( w0 d
{( [- n! L/ G3 b: Y% F% q
progress.commentOnJob(jobId, (new StringBuilder()).append("Battery at ").append(currentPercentage).append("%").toString());
% U( Q% o2 h0 |2 p8 B! e) h int count = 0;3 I+ Z+ C; d! x& D
do6 [* R( b9 ^- ]3 t8 ^5 Y0 i2 ?, @- g
{
+ O/ }$ d q6 d [ progress.commentOnJob(jobId, "Battery Charging Started");
* n' v% n. X9 R# @ progress.commentOnJob(jobId, (new StringBuilder()).append("Charging to Sufficient Power (").append(REQUIRED_POWER_PERCENTAGE).append("%), this may take a couple of minutes").toString());% Q, F0 h5 o1 w1 Z: T# j
chargeBattery();
* L$ ] v1 }9 M+ q; F) n if(++count > RECHARGE_RETRY_COUNT.intValue())
$ n: M% }3 M. T& B: L' a throw new NovacomException(-1, "failed to charge batttery");
/ j) Y% u) ?+ a& n } while(REQUIRED_POWER_PERCENTAGE.intValue() > currentChargeLevel);( s( u" \( g3 ~ A* ?( L
}! ]" s+ u. n8 q6 A/ n3 x$ X$ Y
progress.endJob(jobId);
. i: e5 J1 A5 F) e& E# ? }* S0 U8 I* f9 C: Q3 a$ w: y
) t) k4 o; Y' ^ private static final Integer REQUIRED_POWER_PERCENTAGE = Integer.valueOf(25);
+ t m. E0 M5 z. T J private static final Integer RECHARGE_RETRY_COUNT = Integer.valueOf(5);# i9 s H) y& C1 [6 a$ X. \
private final INovacomDevice device;: q E0 w! W2 {" B$ Q+ x x
private Object jobId;2 \& m5 }- L5 s% L7 a
private IStageProgressReporter progress;
' L8 I$ R( A# C& K% @& T private int currentChargeLevel;: A8 ` y* G& p K* c' X
4 R1 L2 a- ~( w5 Q}
. q) ]2 N7 l7 N& ]8 K2 D) \6 {: V$ z& C+ }! ]( `3 t! W
" f4 z- g& T) Z# Z! l4 @; I求编译~~~~~~~~~~~~~~~~~ |
|