|
楼主 |
发表于 2012-7-13 00:02
|
显示全部楼层
// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov Date: 2012/7/12 23:51:59
$ m f( P* d% z5 O: I% o// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!% _/ m& ]- w4 |. n
// Decompiler options: packimports(3)
% @: {- {3 B: r- Z y- l1 j// Source File Name: ChargeBatteryStage.java. ~# | p( T; I" T4 B7 U+ p: E
+ O. Z5 G% a( |+ N
package com.palm.nova.installer.core.stages;2 W( E2 a6 k% W3 f6 a) Q. j* p3 N
Z/ `5 |# {: c$ qimport com.palm.nova.installer.core.*;4 i) {* ~. w% E+ f% h* O+ w5 f
import com.palm.novacom.*;
4 s* _4 C) n2 Fimport java.io.IOException;! K; k1 V& N8 q. n4 f4 R
9 L" V+ D" m2 |$ a// Referenced classes of package com.palm.nova.installer.core.stages:
$ q" E$ o7 k, w; y// BaseStage, GoIntoUpdateModeStage+ m- v- x; S! u; H3 k' b3 m; }
% n" t' q0 a1 O' u/ Z# {9 tpublic class ChargeBatteryStage extends BaseStage
; P/ a6 p4 X2 `: G implements IInstallerStage
; \6 ^$ v+ G- a$ _' C7 L{. [7 n4 ~% o- s+ p
: z3 ~7 a, c; Y public ChargeBatteryStage(INovacomDevice device)
4 k) j. r4 O& b5 n) V; \/ t" E {: w* {" e- Q9 o9 x$ ]% {& M
jobId = null;
" I1 M1 S+ a+ g7 { progress = null;1 N0 [. a) F2 B0 u3 l/ a4 u8 S
currentChargeLevel = 0;3 u9 Q, e4 u3 b% f6 g
this.device = device;: E: w4 r( y' C+ y6 f# p
}
- S* a4 r1 V7 j% A" i% C- L L% s
" B6 w4 j; y P1 M* } public String toString()
. M5 V8 B4 W! `! O z" C& B: \+ t {' r) B; ~" G$ m# y6 z
return "Battery Charger";3 R5 s7 u9 a, k+ l- _% I! s
}# c, }9 U- |3 @. W7 x
# w9 Z. e9 q# o3 s7 ^
private void chargeBattery()+ `+ N p: U" ~( y' R
throws NovacomException, IOException
" r) c' C! ]( @( Z7 S {; H& M3 J9 B$ @+ ?$ d
INovacomStream stream = device.runProgram("", null);
/ e- V/ |4 e- g String command = (new StringBuilder()).append("charging enable ").append(REQUIRED_POWER_PERCENTAGE).toString();5 P0 j5 E' a" H5 \# J
byte bytes[] = command.getBytes("US-ASCII");2 [/ R' ?& L* l
stream.write(bytes);0 L; f. @& X' i# r! _
stream.closeOutput();6 j; {) B6 a. S3 q) {
String streamReturn = stream.readLine();
# u) p2 h- ]$ r6 P) [ do& _& U" C- I8 R) J! f/ U, G
{
2 n B/ z/ D% l0 r streamReturn = stream.readLine();4 @- h5 z+ N, }: d) ? y; B
if(streamReturn == null)
3 b/ C2 ^; t) N* e {
/ _* |" k0 V& Z9 D- ?" I" k' l* } progress.commentOnJob(jobId, "stream interupted");! p7 T) p$ F' z8 }! C7 V, h
throw new NovacomException(-1, "stream interupted");
+ V! i9 `9 C; S; w, \2 O# A }
6 s8 t0 T. u8 N, o B# C if(streamReturn.length() == 0)6 t4 q+ L6 `- L p R* H0 B
{2 N5 C3 [3 J9 y# j8 O7 n
progress.commentOnJob(jobId, "power charged up");' p) d1 d* t8 x& v! m0 o
break;( q# d9 V" t4 v) u+ T3 {
}- ~0 d0 C6 G; _" w8 ]
int start;
9 @ \8 G. W1 U# I) c6 W( w! x int end;
7 _1 n+ n% c! D+ W' A8 Q. m if((start = streamReturn.indexOf("p=")) >= 0 && (end = streamReturn.indexOf(" ", start + 2)) >= 2)# @! C- Z% b, K# X
{
2 {! I/ `$ o3 C6 s% m- \1 ^8 p start += 2;% A" r2 P) c) J. E4 m0 G7 ]
String strReadBatteryPercentage = streamReturn.substring(start, end);
* F" E# \+ c# d' u( h7 h# E2 R try
% ^% z; s- A6 S3 v3 I0 d' ^- { {. b7 n% W" y" d8 V! z& b6 M V( ?, S0 G, R( V
int readBatteryPercentage = (new Integer(strReadBatteryPercentage)).intValue();
# @; \7 W1 z; G0 @, q" w6 [ if(readBatteryPercentage > currentChargeLevel)
' \, y+ f6 s8 c2 W/ z3 t6 { {8 r) G0 ~( o2 D8 R/ _' D6 i9 z* w
currentChargeLevel = readBatteryPercentage;7 X9 z Y6 l# D5 [* v/ z# M2 b
progress.updateJob(jobId, currentChargeLevel);, `- E0 T S$ n/ E; s' r
progress.commentOnJob(jobId, (new StringBuilder()).append("battery percentage changed: ").append(currentChargeLevel).toString());
, _: ^. m# K" w5 s1 U: ] }4 U4 z: x. A+ q5 H( H9 C: T
Thread.sleep(500L);
- T# ]" m$ o. e0 O }1 \' ]1 O M7 i+ e# |9 v, S9 T# a% d
catch(NumberFormatException e)
' C+ S, k( W) z {1 P* K2 }6 Y- d2 \. z% f
progress.commentOnJob(jobId, (new StringBuilder()).append("+++++").append(streamReturn).append("-----").toString());1 p+ n- [" I: U7 e- i% T0 m
}- E. g$ g, z5 w' x) E( l- `- m7 O
catch(InterruptedException e) { }9 c" H3 g% m# f7 `
} else
' [4 [% C3 j; c0 h5 e; C ? {
+ X* j) V8 Y5 A progress.commentOnJob(jobId, (new StringBuilder()).append("+++++").append(streamReturn).append("-----").toString());/ X8 Y' f" u9 a- j4 d7 p& N" E( H
}
^: \ A1 H8 b0 S! E- S8 J stream.flush();
4 Q1 m# M8 B+ e6 r; r& L3 M } while(true);" x/ [" ~# t( v6 j
stream.close();- z* [! {+ X! ~0 K8 G
}* ^; u2 V& t4 P# Q* ^3 H
" H1 I6 r4 X. l- T) G" D! b% G2 r& ^1 J
public void run()
" E6 m, x9 n# o; B; S throws NovacomException, IOException- y$ O# T2 f) W* |# z: S
{
9 Y5 i2 T3 y( u e7 [ progress = getProgressHandler();
/ R8 h0 l- H: f4 Y8 x" h jobId = progress.startJob("Battery Charger Stage", 100);' f* r7 a' I) y
if(device.getState() != com.palm.novacom.Novacom.DeviceState.BOOTLOADER). e, s; d! ^3 O: d
{ u. O, J+ Q! n: b) Y/ _
GoIntoUpdateModeStage intoUpdateMode = new GoIntoUpdateModeStage(device);; `+ d, v% d1 K' |" O
intoUpdateMode.run();
8 B/ |- P+ M6 Q7 U! ^% e }
0 }8 c0 R: E3 }) D! _( X+ V. I BootieUtilities bootie = new BootieUtilities(device);. v, w! X3 c% O$ r' Z; d& ]4 _
int currentPercentage = bootie.checkPowerStatus().intValue(); ~$ y7 C: V" o# x/ ?& V
if(REQUIRED_POWER_PERCENTAGE.intValue() > currentPercentage)
+ b; t4 C$ u+ b! W, q& M {
7 C) F3 \6 c: s, d/ |: O9 S progress.commentOnJob(jobId, (new StringBuilder()).append("Battery at ").append(currentPercentage).append("%").toString());* Y4 A: e( G w. Z' G
int count = 0;, [$ g, g1 m. I: F/ |% o: ^2 o
do/ C% |# s$ P$ r2 k' A
{( Y" M; _7 a/ Q6 f8 W
progress.commentOnJob(jobId, "Battery Charging Started");& q( F/ j! O$ c" }+ V. l
progress.commentOnJob(jobId, (new StringBuilder()).append("Charging to Sufficient Power (").append(REQUIRED_POWER_PERCENTAGE).append("%), this may take a couple of minutes").toString());7 I& R& j2 N+ ?* z
chargeBattery();
0 Z6 G5 u- K' v) `/ R3 N! A P% { if(++count > RECHARGE_RETRY_COUNT.intValue())' h+ `* W" S6 w" Z
throw new NovacomException(-1, "failed to charge batttery");/ h0 n% H% k9 c" B
} while(REQUIRED_POWER_PERCENTAGE.intValue() > currentChargeLevel);# o7 k4 c. }. w- k5 w3 L" J* r
}
3 o3 U' _- V; V5 Z' z progress.endJob(jobId);
0 j2 c+ q: h6 z$ q% ~ }
9 K( S: l8 E- f: g6 j, _+ T/ J/ Q* [8 n2 G/ ~* d9 U6 m/ M
private static final Integer REQUIRED_POWER_PERCENTAGE = Integer.valueOf(25);: f! V A9 u3 y( B$ ^
private static final Integer RECHARGE_RETRY_COUNT = Integer.valueOf(5);
! v9 o! f& o/ K' o1 F: y; Y private final INovacomDevice device;
- E0 d2 g/ B9 J0 }- F4 a private Object jobId;
2 ~6 W; i+ E' l0 w9 _4 } private IStageProgressReporter progress;9 W" j% _9 m9 Q0 |
private int currentChargeLevel;
; M& g% L% W5 a Y$ J
) Q/ t9 D) m5 m; ^& A4 j8 r}$ y, ?* j# A- {4 `8 G/ D
2 U* Q3 f' L9 K. o
6 W% D; `7 T! y. a. s0 g7 x求编译~~~~~~~~~~~~~~~~~ |
|