| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import com.android.internal.os.IResultReceiver; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class ResultReceiver implements Parcelable { |
| 35 |
final boolean mLocal; |
| 36 |
final Handler mHandler; |
| 37 |
|
| 38 |
IResultReceiver mReceiver; |
| 39 |
|
| 40 |
class MyRunnable implements Runnable { |
| 41 |
final int mResultCode; |
| 42 |
final Bundle mResultData; |
| 43 |
|
| 44 |
MyRunnable(int resultCode, Bundle resultData) { |
| 45 |
mResultCode = resultCode; |
| 46 |
mResultData = resultData; |
| 47 |
} |
| 48 |
|
| 49 |
public void run() { |
| 50 |
onReceiveResult(mResultCode, mResultData); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
class MyResultReceiver extends IResultReceiver.Stub { |
| 55 |
public void send(int resultCode, Bundle resultData) { |
| 56 |
if (mHandler != null) { |
| 57 |
mHandler.post(new MyRunnable(resultCode, resultData)); |
| 58 |
} else { |
| 59 |
onReceiveResult(resultCode, resultData); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public ResultReceiver(Handler handler) { |
| 70 |
mLocal = true; |
| 71 |
mHandler = handler; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public void send(int resultCode, Bundle resultData) { |
| 82 |
if (mLocal) { |
| 83 |
if (mHandler != null) { |
| 84 |
mHandler.post(new MyRunnable(resultCode, resultData)); |
| 85 |
} else { |
| 86 |
onReceiveResult(resultCode, resultData); |
| 87 |
} |
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
if (mReceiver != null) { |
| 92 |
try { |
| 93 |
mReceiver.send(resultCode, resultData); |
| 94 |
} catch (RemoteException e) { |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
protected void onReceiveResult(int resultCode, Bundle resultData) { |
| 107 |
} |
| 108 |
|
| 109 |
public int describeContents() { |
| 110 |
return 0; |
| 111 |
} |
| 112 |
|
| 113 |
public void writeToParcel(Parcel out, int flags) { |
| 114 |
synchronized (this) { |
| 115 |
if (mReceiver == null) { |
| 116 |
mReceiver = new MyResultReceiver(); |
| 117 |
} |
| 118 |
out.writeStrongBinder(mReceiver.asBinder()); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
ResultReceiver(Parcel in) { |
| 123 |
mLocal = false; |
| 124 |
mHandler = null; |
| 125 |
mReceiver = IResultReceiver.Stub.asInterface(in.readStrongBinder()); |
| 126 |
} |
| 127 |
|
| 128 |
public static final @android.annotation.NonNull Parcelable.Creator<ResultReceiver> CREATOR |
| 129 |
= new Parcelable.Creator<ResultReceiver>() { |
| 130 |
public ResultReceiver createFromParcel(Parcel in) { |
| 131 |
return new ResultReceiver(in); |
| 132 |
} |
| 133 |
public ResultReceiver[] newArray(int size) { |
| 134 |
return new ResultReceiver[size]; |
| 135 |
} |
| 136 |
}; |
| 137 |
} |