| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import android.compat.annotation.UnsupportedAppUsage; |
| 20 |
|
| 21 |
import java.util.ArrayList; |
| 22 |
|
| 23 |
|
| 24 |
public class RegistrantList |
| 25 |
{ |
| 26 |
ArrayList registrants = new ArrayList(); |
| 27 |
|
| 28 |
@UnsupportedAppUsage |
| 29 |
public RegistrantList() { |
| 30 |
} |
| 31 |
|
| 32 |
@UnsupportedAppUsage |
| 33 |
public synchronized void |
| 34 |
add(Handler h, int what, Object obj) |
| 35 |
{ |
| 36 |
add(new Registrant(h, what, obj)); |
| 37 |
} |
| 38 |
|
| 39 |
@UnsupportedAppUsage |
| 40 |
public synchronized void |
| 41 |
addUnique(Handler h, int what, Object obj) |
| 42 |
{ |
| 43 |
|
| 44 |
remove(h); |
| 45 |
add(new Registrant(h, what, obj)); |
| 46 |
} |
| 47 |
|
| 48 |
@UnsupportedAppUsage |
| 49 |
public synchronized void |
| 50 |
add(Registrant r) |
| 51 |
{ |
| 52 |
removeCleared(); |
| 53 |
registrants.add(r); |
| 54 |
} |
| 55 |
|
| 56 |
@UnsupportedAppUsage |
| 57 |
public synchronized void |
| 58 |
removeCleared() |
| 59 |
{ |
| 60 |
for (int i = registrants.size() - 1; i >= 0 ; i--) { |
| 61 |
Registrant r = (Registrant) registrants.get(i); |
| 62 |
|
| 63 |
if (r.refH == null) { |
| 64 |
registrants.remove(i); |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public synchronized void removeAll() { |
| 70 |
registrants.clear(); |
| 71 |
} |
| 72 |
|
| 73 |
@UnsupportedAppUsage |
| 74 |
public synchronized int |
| 75 |
size() |
| 76 |
{ |
| 77 |
return registrants.size(); |
| 78 |
} |
| 79 |
|
| 80 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 81 |
public synchronized Object |
| 82 |
get(int index) |
| 83 |
{ |
| 84 |
return registrants.get(index); |
| 85 |
} |
| 86 |
|
| 87 |
private synchronized void |
| 88 |
internalNotifyRegistrants (Object result, Throwable exception) |
| 89 |
{ |
| 90 |
for (int i = 0, s = registrants.size(); i < s ; i++) { |
| 91 |
Registrant r = (Registrant) registrants.get(i); |
| 92 |
r.internalNotifyRegistrant(result, exception); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
@UnsupportedAppUsage |
| 97 |
public void |
| 98 |
notifyRegistrants() |
| 99 |
{ |
| 100 |
internalNotifyRegistrants(null, null); |
| 101 |
} |
| 102 |
|
| 103 |
public void |
| 104 |
notifyException(Throwable exception) |
| 105 |
{ |
| 106 |
internalNotifyRegistrants (null, exception); |
| 107 |
} |
| 108 |
|
| 109 |
@UnsupportedAppUsage |
| 110 |
public void |
| 111 |
notifyResult(Object result) |
| 112 |
{ |
| 113 |
internalNotifyRegistrants (result, null); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
@UnsupportedAppUsage |
| 118 |
public void |
| 119 |
notifyRegistrants(AsyncResult ar) |
| 120 |
{ |
| 121 |
internalNotifyRegistrants(ar.result, ar.exception); |
| 122 |
} |
| 123 |
|
| 124 |
@UnsupportedAppUsage |
| 125 |
public synchronized void |
| 126 |
remove(Handler h) |
| 127 |
{ |
| 128 |
for (int i = 0, s = registrants.size() ; i < s ; i++) { |
| 129 |
Registrant r = (Registrant) registrants.get(i); |
| 130 |
Handler rh; |
| 131 |
|
| 132 |
rh = r.getHandler(); |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
if (rh == null || rh == h) { |
| 138 |
r.clear(); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
removeCleared(); |
| 143 |
} |
| 144 |
} |