Skip to content

Commit 07c2c9f

Browse files
Jaikumar GaneshAndroid Git Automerger
authored andcommitted
am 38342c9: am d426c33: Merge "Reduce likelihood of crash in state machine." into ics-mr1
* commit '38342c9d858d8b021bc5c616cfe6c0ab9f359b2b': Reduce likelihood of crash in state machine.
2 parents 10fd37d + 38342c9 commit 07c2c9f

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

core/java/com/android/internal/util/StateMachine.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,20 +1367,24 @@ public final Handler getHandler() {
13671367
/**
13681368
* Get a message and set Message.target = this.
13691369
*
1370-
* @return message
1370+
* @return message or null if SM has quit
13711371
*/
13721372
public final Message obtainMessage()
13731373
{
1374+
if (mSmHandler == null) return null;
1375+
13741376
return Message.obtain(mSmHandler);
13751377
}
13761378

13771379
/**
13781380
* Get a message and set Message.target = this and what
13791381
*
13801382
* @param what is the assigned to Message.what.
1381-
* @return message
1383+
* @return message or null if SM has quit
13821384
*/
13831385
public final Message obtainMessage(int what) {
1386+
if (mSmHandler == null) return null;
1387+
13841388
return Message.obtain(mSmHandler, what);
13851389
}
13861390

@@ -1390,10 +1394,12 @@ public final Message obtainMessage(int what) {
13901394
*
13911395
* @param what is the assigned to Message.what.
13921396
* @param obj is assigned to Message.obj.
1393-
* @return message
1397+
* @return message or null if SM has quit
13941398
*/
13951399
public final Message obtainMessage(int what, Object obj)
13961400
{
1401+
if (mSmHandler == null) return null;
1402+
13971403
return Message.obtain(mSmHandler, what, obj);
13981404
}
13991405

@@ -1404,10 +1410,13 @@ public final Message obtainMessage(int what, Object obj)
14041410
* @param what is assigned to Message.what
14051411
* @param arg1 is assigned to Message.arg1
14061412
* @param arg2 is assigned to Message.arg2
1407-
* @return A Message object from the global pool.
1413+
* @return A Message object from the global pool or null if
1414+
* SM has quit
14081415
*/
14091416
public final Message obtainMessage(int what, int arg1, int arg2)
14101417
{
1418+
if (mSmHandler == null) return null;
1419+
14111420
return Message.obtain(mSmHandler, what, arg1, arg2);
14121421
}
14131422

@@ -1419,52 +1428,73 @@ public final Message obtainMessage(int what, int arg1, int arg2)
14191428
* @param arg1 is assigned to Message.arg1
14201429
* @param arg2 is assigned to Message.arg2
14211430
* @param obj is assigned to Message.obj
1422-
* @return A Message object from the global pool.
1431+
* @return A Message object from the global pool or null if
1432+
* SM has quit
14231433
*/
14241434
public final Message obtainMessage(int what, int arg1, int arg2, Object obj)
14251435
{
1436+
if (mSmHandler == null) return null;
1437+
14261438
return Message.obtain(mSmHandler, what, arg1, arg2, obj);
14271439
}
14281440

14291441
/**
14301442
* Enqueue a message to this state machine.
14311443
*/
14321444
public final void sendMessage(int what) {
1445+
// mSmHandler can be null if the state machine has quit.
1446+
if (mSmHandler == null) return;
1447+
14331448
mSmHandler.sendMessage(obtainMessage(what));
14341449
}
14351450

14361451
/**
14371452
* Enqueue a message to this state machine.
14381453
*/
14391454
public final void sendMessage(int what, Object obj) {
1455+
// mSmHandler can be null if the state machine has quit.
1456+
if (mSmHandler == null) return;
1457+
14401458
mSmHandler.sendMessage(obtainMessage(what,obj));
14411459
}
14421460

14431461
/**
14441462
* Enqueue a message to this state machine.
14451463
*/
14461464
public final void sendMessage(Message msg) {
1465+
// mSmHandler can be null if the state machine has quit.
1466+
if (mSmHandler == null) return;
1467+
14471468
mSmHandler.sendMessage(msg);
14481469
}
14491470

14501471
/**
14511472
* Enqueue a message to this state machine after a delay.
14521473
*/
14531474
public final void sendMessageDelayed(int what, long delayMillis) {
1475+
// mSmHandler can be null if the state machine has quit.
1476+
if (mSmHandler == null) return;
1477+
14541478
mSmHandler.sendMessageDelayed(obtainMessage(what), delayMillis);
14551479
}
14561480

14571481
/**
14581482
* Enqueue a message to this state machine after a delay.
14591483
*/
14601484
public final void sendMessageDelayed(int what, Object obj, long delayMillis) {
1485+
// mSmHandler can be null if the state machine has quit.
1486+
if (mSmHandler == null) return;
1487+
14611488
mSmHandler.sendMessageDelayed(obtainMessage(what, obj), delayMillis);
14621489
}
14631490

14641491
/**
14651492
* Enqueue a message to this state machine after a delay.
14661493
*/
14671494
public final void sendMessageDelayed(Message msg, long delayMillis) {
1495+
// mSmHandler can be null if the state machine has quit.
1496+
if (mSmHandler == null) return;
1497+
14681498
mSmHandler.sendMessageDelayed(msg, delayMillis);
14691499
}
14701500

@@ -1509,6 +1539,9 @@ protected final void removeMessages(int what) {
15091539
* will be processed.
15101540
*/
15111541
public final void quit() {
1542+
// mSmHandler can be null if the state machine has quit.
1543+
if (mSmHandler == null) return;
1544+
15121545
mSmHandler.quit();
15131546
}
15141547

@@ -1523,6 +1556,9 @@ protected final boolean isQuit(Message msg) {
15231556
* @return if debugging is enabled
15241557
*/
15251558
public boolean isDbg() {
1559+
// mSmHandler can be null if the state machine has quit.
1560+
if (mSmHandler == null) return false;
1561+
15261562
return mSmHandler.isDbg();
15271563
}
15281564

@@ -1532,13 +1568,19 @@ public boolean isDbg() {
15321568
* @param dbg is true to enable debugging.
15331569
*/
15341570
public void setDbg(boolean dbg) {
1571+
// mSmHandler can be null if the state machine has quit.
1572+
if (mSmHandler == null) return;
1573+
15351574
mSmHandler.setDbg(dbg);
15361575
}
15371576

15381577
/**
15391578
* Start the state machine.
15401579
*/
15411580
public void start() {
1581+
// mSmHandler can be null if the state machine has quit.
1582+
if (mSmHandler == null) return;
1583+
15421584
/** Send the complete construction message */
15431585
mSmHandler.completeConstruction();
15441586
}

0 commit comments

Comments
 (0)