|
楼主 |
发表于 2012-7-13 00:02
|
显示全部楼层
// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov Date: 2012/7/12 23:51:595 u4 ?5 C% G2 `+ Y$ d% u4 _6 D
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
0 H& ~) S( c+ K// Decompiler options: packimports(3)
0 t" n u& C$ f// Source File Name: ChargeBatteryStage.java
) Z6 v9 L& G( U+ i( p
Y$ d0 a( D4 x( c( L3 d* ?package com.palm.nova.installer.core.stages;
. r( Z8 N" |- f1 Z
1 P i+ {# e; L! K- r% D1 gimport com.palm.nova.installer.core.*;
0 ?* w9 M/ w5 ]( |/ C4 yimport com.palm.novacom.*;6 ~9 J: x2 r/ y \ U
import java.io.IOException;; N0 Q0 C1 s1 O
- ~4 P& C% m3 u; @( w8 U
// Referenced classes of package com.palm.nova.installer.core.stages:' E( K. }# z4 D6 u" ~( O8 u
// BaseStage, GoIntoUpdateModeStage
6 j0 ]4 w& a! ~% ]3 k8 Q1 W7 ` o# F6 E9 Z
public class ChargeBatteryStage extends BaseStage( d) e4 c' v6 I0 m5 j& J Q
implements IInstallerStage* R* L9 X9 M7 c
{
: ^, W5 m' L- w2 C+ f: P
0 j, X3 g& [$ U2 W public ChargeBatteryStage(INovacomDevice device)7 Q6 ^5 u% d% N7 m% q% U/ Z; s, d
{
2 w3 Y' H% a9 M5 Q% Q2 b jobId = null;
3 S& M, A/ `# w progress = null;$ D& O+ o# F( v7 A% j
currentChargeLevel = 0;) a* \/ l; t5 Z/ F2 \6 m
this.device = device;; ]: A, U% W6 V) T
}
7 g; S+ F8 [2 T- w; |! N, ~/ S- W; g. b
4 f* w; k, f$ C6 J. O" R public String toString()3 o5 R& U; S) c4 Z0 B8 m% y
{
; y! ?; L' c6 f( u4 [ return "Battery Charger";
2 a! p8 ?- @) L8 m) E }
5 {' W' n% z! {8 v! M: B& s9 z% F+ y1 x( j% A' f
private void chargeBattery()1 a- |- @) f d
throws NovacomException, IOException' D+ R: o" k& K6 [+ G
{
: C! b+ r' J: B! A' M3 Q INovacomStream stream = device.runProgram("", null); V7 `0 _$ s* i# Y, o9 `( i- t
String command = (new StringBuilder()).append("charging enable ").append(REQUIRED_POWER_PERCENTAGE).toString();
( w: O H5 U) R2 s1 W9 G% w byte bytes[] = command.getBytes("US-ASCII");
7 o `% c0 h; I( K+ n, T stream.write(bytes);5 F! l- ]3 J* K7 C& @; W P
stream.closeOutput();! v; L& X% O9 A8 L$ @) d6 v" K9 X
String streamReturn = stream.readLine();& ] ?6 J- E- E; _. U7 k
do
5 Y5 I% E/ l: H, t1 m5 E' s {
! n$ b& P4 s" @3 z# M, X) a streamReturn = stream.readLine();
: x6 |# q' [- F if(streamReturn == null)
^3 Q0 G/ P4 Q, v$ g1 J% Z" g S# d {
$ X. [ L! p1 V y+ m! S# T" [ progress.commentOnJob(jobId, "stream interupted");7 i/ U4 V; ~! p2 k% j
throw new NovacomException(-1, "stream interupted");: v+ _; g4 Q. @" M
}
( }# u: Y' X2 U- K if(streamReturn.length() == 0)
+ }) i* P1 `" ?0 r" H {
( E' \$ e0 w' h( R/ e+ p! U: y progress.commentOnJob(jobId, "power charged up");$ f) E7 R" L" a" f$ z4 j$ G
break;
) J9 y7 n/ B1 A }, p4 J: q( f) {3 F6 b! ]
int start;
A3 c3 U3 T. E: }5 _, Z* o5 y int end;0 @6 A9 M" v& h1 b; M+ f W
if((start = streamReturn.indexOf("p=")) >= 0 && (end = streamReturn.indexOf(" ", start + 2)) >= 2)
8 |8 j6 l$ ^* R: j- b {7 w% @" y" c& d
start += 2;
$ t( i9 g1 x6 U6 K9 }$ v( a String strReadBatteryPercentage = streamReturn.substring(start, end);
/ z6 b* Y$ Y/ P7 S3 I9 ` try5 i0 p3 M7 K1 `/ _) x9 D
{
9 B( {: f( D4 B H int readBatteryPercentage = (new Integer(strReadBatteryPercentage)).intValue();- M5 {' p0 }" }" u c4 E; X
if(readBatteryPercentage > currentChargeLevel)' I8 V% s& g1 M
{5 d9 D7 N$ U9 o& _- `$ x8 E
currentChargeLevel = readBatteryPercentage;- ~! M6 N% A1 f8 k
progress.updateJob(jobId, currentChargeLevel);: K8 W3 c, j2 [6 m
progress.commentOnJob(jobId, (new StringBuilder()).append("battery percentage changed: ").append(currentChargeLevel).toString());9 r& g" }# w1 e+ P, H5 ?
}
6 V) f' N( p2 H1 k2 E5 ?- V9 h Thread.sleep(500L);
) G# Y; C: r" M: J* y3 {) }8 I }2 R( [; j* c5 r* ^2 _
catch(NumberFormatException e)
' @5 O x' q+ e; B/ l {" e6 ?$ ~) Z" |
progress.commentOnJob(jobId, (new StringBuilder()).append("+++++").append(streamReturn).append("-----").toString());1 h$ ]) i4 {' P3 C( v
}
2 g1 A; a+ M( x1 [5 N' m catch(InterruptedException e) { }
) g1 c1 @4 Y2 w& K S% ]# h } else
6 u5 E' Q& m/ _/ y1 Z6 R( l {& b7 ?) L4 }- c7 _: |4 {1 ~
progress.commentOnJob(jobId, (new StringBuilder()).append("+++++").append(streamReturn).append("-----").toString());
- V, y4 g) u: f }4 u! F3 S; c8 `# ~* K; Q+ y$ t4 m5 o
stream.flush();. r9 W/ G& V* G U- |) R
} while(true);
5 z7 t8 ]8 X8 h r/ c stream.close();
- h+ o& n6 Y9 I) ~8 h! v) y- A }/ d6 \8 v8 c) J9 j1 O
! v5 D0 ^* p, a: b$ n$ E1 D public void run()% H8 V n( I: N) T8 B
throws NovacomException, IOException
# ?" k- a9 n) q2 v0 u7 _% Q4 Y9 l4 e2 i {: L% }5 U2 [) F
progress = getProgressHandler();
+ P4 T: d) C2 w' Q4 i3 Q% K jobId = progress.startJob("Battery Charger Stage", 100); X: K3 f; x2 F$ c7 g
if(device.getState() != com.palm.novacom.Novacom.DeviceState.BOOTLOADER)
. J1 @! H1 ]. E {! V( T! M1 e* H8 J. A5 V* @# W
GoIntoUpdateModeStage intoUpdateMode = new GoIntoUpdateModeStage(device);
+ u9 s' f0 \$ f intoUpdateMode.run();
1 p) F- \( c: t/ ~ }9 F; J0 [( ~ }5 \- V6 `7 `
BootieUtilities bootie = new BootieUtilities(device);9 H- D! f- ~" T
int currentPercentage = bootie.checkPowerStatus().intValue();# U) T/ Y) L6 ^) K
if(REQUIRED_POWER_PERCENTAGE.intValue() > currentPercentage)" H3 H+ r* ^- x
{
5 d4 l+ { r1 I* K/ m" L* c progress.commentOnJob(jobId, (new StringBuilder()).append("Battery at ").append(currentPercentage).append("%").toString());
; O6 k3 e! _5 Q6 d( M int count = 0;
; B, Y6 q7 `3 ?7 C# b4 q do2 Q, |7 M- N1 H2 s' S
{
: U: ], _1 X7 \ progress.commentOnJob(jobId, "Battery Charging Started");" B' [; a/ y1 m5 Z
progress.commentOnJob(jobId, (new StringBuilder()).append("Charging to Sufficient Power (").append(REQUIRED_POWER_PERCENTAGE).append("%), this may take a couple of minutes").toString());
* P7 ^5 q: I+ b! A. `3 q chargeBattery();/ ^# ]4 ?4 T; z$ ~
if(++count > RECHARGE_RETRY_COUNT.intValue())
( a8 `5 M& k& L' R k' n5 w throw new NovacomException(-1, "failed to charge batttery");3 f+ @3 i; {6 b& Y
} while(REQUIRED_POWER_PERCENTAGE.intValue() > currentChargeLevel);
' t! m- a |6 v6 T; E. E }: }/ A. T- @6 K+ Q u# |
progress.endJob(jobId);
, U2 z1 T! I" e$ U3 U( O }
: x; J" ]- ]% k' q) ]( h0 H
1 p& M1 v! W5 ]/ r4 F! U private static final Integer REQUIRED_POWER_PERCENTAGE = Integer.valueOf(25);. s4 S& f+ j3 N; F9 I( V
private static final Integer RECHARGE_RETRY_COUNT = Integer.valueOf(5);
2 ~; j1 I8 t4 o$ \+ q0 o2 ]/ l private final INovacomDevice device; f, H9 ]6 } e3 c
private Object jobId;
5 `1 j9 j1 W2 D* t' O4 J; T private IStageProgressReporter progress;
: \, d W/ n* ?" q X* i; o( b private int currentChargeLevel;1 S$ h# }& S$ m9 R7 f
1 d7 R* \" X5 i7 C2 z, e1 F, c: B& o
}' [# M# _" S' P
( E( L& z9 v3 x/ l2 i6 _7 P" J
, q ^# L! L, u% l0 w1 Y求编译~~~~~~~~~~~~~~~~~ |
|