| 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.lang.ref.WeakReference; |
| 22 |
|
| 23 |
|
| 24 |
public class Registrant |
| 25 |
{ |
| 26 |
@UnsupportedAppUsage |
| 27 |
public |
| 28 |
Registrant(Handler h, int what, Object obj) |
| 29 |
{ |
| 30 |
refH = new WeakReference(h); |
| 31 |
this.what = what; |
| 32 |
userObj = obj; |
| 33 |
} |
| 34 |
|
| 35 |
@UnsupportedAppUsage |
| 36 |
public void |
| 37 |
clear() |
| 38 |
{ |
| 39 |
refH = null; |
| 40 |
userObj = null; |
| 41 |
} |
| 42 |
|
| 43 |
@UnsupportedAppUsage |
| 44 |
public void |
| 45 |
notifyRegistrant() |
| 46 |
{ |
| 47 |
internalNotifyRegistrant (null, null); |
| 48 |
} |
| 49 |
|
| 50 |
@UnsupportedAppUsage |
| 51 |
public void |
| 52 |
notifyResult(Object result) |
| 53 |
{ |
| 54 |
internalNotifyRegistrant (result, null); |
| 55 |
} |
| 56 |
|
| 57 |
public void |
| 58 |
notifyException(Throwable exception) |
| 59 |
{ |
| 60 |
internalNotifyRegistrant (null, exception); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
@UnsupportedAppUsage |
| 67 |
public void |
| 68 |
notifyRegistrant(AsyncResult ar) |
| 69 |
{ |
| 70 |
internalNotifyRegistrant (ar.result, ar.exception); |
| 71 |
} |
| 72 |
|
| 73 |
void |
| 74 |
internalNotifyRegistrant (Object result, Throwable exception) |
| 75 |
{ |
| 76 |
Handler h = getHandler(); |
| 77 |
|
| 78 |
if (h == null) { |
| 79 |
clear(); |
| 80 |
} else { |
| 81 |
Message msg = Message.obtain(); |
| 82 |
|
| 83 |
msg.what = what; |
| 84 |
msg.obj = new AsyncResult(userObj, result, exception); |
| 85 |
h.sendMessage(msg); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
@UnsupportedAppUsage |
| 94 |
public Message |
| 95 |
messageForRegistrant() |
| 96 |
{ |
| 97 |
Handler h = getHandler(); |
| 98 |
|
| 99 |
if (h == null) { |
| 100 |
clear(); |
| 101 |
|
| 102 |
return null; |
| 103 |
} else { |
| 104 |
Message msg = h.obtainMessage(); |
| 105 |
|
| 106 |
msg.what = what; |
| 107 |
msg.obj = userObj; |
| 108 |
|
| 109 |
return msg; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 114 |
public Handler |
| 115 |
getHandler() |
| 116 |
{ |
| 117 |
if (refH == null) |
| 118 |
return null; |
| 119 |
|
| 120 |
return (Handler) refH.get(); |
| 121 |
} |
| 122 |
|
| 123 |
WeakReference refH; |
| 124 |
int what; |
| 125 |
Object userObj; |
| 126 |
} |