10825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville/*
20825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Copyright (C) 2006 The Android Open Source Project
30825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville *
40825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Licensed under the Apache License, Version 2.0 (the "License");
50825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * you may not use this file except in compliance with the License.
60825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * You may obtain a copy of the License at
70825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville *
80825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville *      http://www.apache.org/licenses/LICENSE-2.0
90825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville *
100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * Unless required by applicable law or agreed to in writing, software
110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * distributed under the License is distributed on an "AS IS" BASIS,
120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * See the License for the specific language governing permissions and
140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville * limitations under the License.
150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville */
160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
17d720945f2be5ea5fe0faf67e67d9ea0e184eba67Alex Yakavenkapackage com.android.internal.telephony.uicc;
180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
190825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport java.util.ArrayList;
200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
210825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport android.os.AsyncResult;
220825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport android.os.Handler;
230825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport android.os.Looper;
240825495a331bb44df395a0cdb79fab85e68db5d5Wink Savilleimport android.os.Message;
25ded9c0af7fa49504c047275ed34c2d3b22bf0c3aWink Savilleimport android.telephony.Rlog;
260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
270825495a331bb44df395a0cdb79fab85e68db5d5Wink Savillepublic class AdnRecordLoader extends Handler {
28cbaa45bbf2cab852b6c9c3a887e9f803d4e857eaWink Saville    final static String LOG_TAG = "AdnRecordLoader";
29cbaa45bbf2cab852b6c9c3a887e9f803d4e857eaWink Saville    final static boolean VDBG = false;
300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    //***** Instance Variables
320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    private IccFileHandler mFh;
3422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    int mEf;
3522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    int mExtensionEF;
3622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    int mPendingExtLoads;
3722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    Message mUserResponse;
3822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    String mPin2;
390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    // For "load one"
4122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    int mRecordNumber;
420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    // for "load all"
4422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    ArrayList<AdnRecord> mAdns; // only valid after EVENT_ADN_LOAD_ALL_DONE
450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    // Either an AdnRecord or a reference to adns depending
470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    // if this is a load one or load all operation
4822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville    Object mResult;
490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    //***** Event Constants
510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    static final int EVENT_ADN_LOAD_DONE = 1;
530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    static final int EVENT_EXT_RECORD_LOAD_DONE = 2;
540825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    static final int EVENT_ADN_LOAD_ALL_DONE = 3;
550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    static final int EVENT_EF_LINEAR_RECORD_SIZE_DONE = 4;
560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    static final int EVENT_UPDATE_RECORD_DONE = 5;
570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    //***** Constructor
590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
60d720945f2be5ea5fe0faf67e67d9ea0e184eba67Alex Yakavenka    AdnRecordLoader(IccFileHandler fh) {
610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        // The telephony unit-test cases may create AdnRecords
620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        // in secondary threads
630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        super(Looper.getMainLooper());
640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        mFh = fh;
650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
670825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    /**
680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * Resulting AdnRecord is placed in response.obj.result
690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * or response.obj.exception is set
700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     */
710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    public void
720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    loadFromEF(int ef, int extensionEF, int recordNumber,
730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                Message response) {
7422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mEf = ef;
7522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mExtensionEF = extensionEF;
7622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mRecordNumber = recordNumber;
7722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mUserResponse = response;
780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
790825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        mFh.loadEFLinearFixed(
800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    ef, recordNumber,
810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    obtainMessage(EVENT_ADN_LOAD_DONE));
820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    /**
870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * Resulting ArrayList&lt;adnRecord> is placed in response.obj.result
880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * or response.obj.exception is set
890825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     */
900825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    public void
910825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    loadAllFromEF(int ef, int extensionEF,
920825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                Message response) {
9322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mEf = ef;
9422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mExtensionEF = extensionEF;
9522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mUserResponse = response;
960825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
970825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        mFh.loadEFLinearFixedAll(
980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    ef,
990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    obtainMessage(EVENT_ADN_LOAD_ALL_DONE));
1000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
1020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1030825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    /**
1040825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * Write adn to a EF SIM record
1050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * It will get the record size of EF record and compose hex adn array
1060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * then write the hex array to EF record
1070825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     *
1080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * @param adn is set with alphaTag and phone number
1090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * @param ef EF fileid
1100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * @param extensionEF extension EF fileid
1110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * @param recordNumber 1-based record index
1120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * @param pin2 for CHV2 operations, must be null if pin2 is not needed
1130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     * @param response will be sent to its handler when completed
1140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville     */
1150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    public void
1160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    updateEF(AdnRecord adn, int ef, int extensionEF, int recordNumber,
1170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville            String pin2, Message response) {
11822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mEf = ef;
11922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mExtensionEF = extensionEF;
12022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mRecordNumber = recordNumber;
12122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mUserResponse = response;
12222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        mPin2 = pin2;
1230825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        mFh.getEFLinearRecordSize( ef,
1250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville            obtainMessage(EVENT_EF_LINEAR_RECORD_SIZE_DONE, adn));
1260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
1270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1280825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    //***** Overridden from Handler
1290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
130cbaa45bbf2cab852b6c9c3a887e9f803d4e857eaWink Saville    @Override
1310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    public void
1320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    handleMessage(Message msg) {
1330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        AsyncResult ar;
1340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        byte data[];
1350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        AdnRecord adn;
1360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        try {
1380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville            switch (msg.what) {
1390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                case EVENT_EF_LINEAR_RECORD_SIZE_DONE:
1400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    ar = (AsyncResult)(msg.obj);
1410825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    adn = (AdnRecord)(ar.userObj);
1420825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1430825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    if (ar.exception != null) {
1440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        throw new RuntimeException("get EF record size failed",
1450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                                ar.exception);
1460825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
1470825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    int[] recordSize = (int[])ar.result;
1490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    // recordSize is int[3] array
1500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    // int[0]  is the record length
1510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    // int[1]  is the total length of the EF file
1520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    // int[2]  is the number of records in the EF file
1530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    // So int[0] * int[2] = int[1]
15422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                   if (recordSize.length != 3 || mRecordNumber > recordSize[2]) {
1550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        throw new RuntimeException("get wrong EF record size format",
1560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                                ar.exception);
1570825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
1580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    data = adn.buildAdnString(recordSize[0]);
1600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    if(data == null) {
1620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        throw new RuntimeException("wrong ADN format",
1630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                                ar.exception);
1640825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
1650825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
16622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mFh.updateEFLinearFixed(mEf, mRecordNumber,
16722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                            data, mPin2, obtainMessage(EVENT_UPDATE_RECORD_DONE));
1680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
16922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mPendingExtLoads = 1;
1700825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    break;
1720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                case EVENT_UPDATE_RECORD_DONE:
1730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    ar = (AsyncResult)(msg.obj);
1740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    if (ar.exception != null) {
1750825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        throw new RuntimeException("update EF adn record failed",
1760825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                                ar.exception);
1770825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
17822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mPendingExtLoads = 0;
17922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mResult = null;
1800825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    break;
1810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                case EVENT_ADN_LOAD_DONE:
1820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    ar = (AsyncResult)(msg.obj);
1830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    data = (byte[])(ar.result);
1840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    if (ar.exception != null) {
1860825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        throw new RuntimeException("load failed", ar.exception);
1870825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
1880825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
189cbaa45bbf2cab852b6c9c3a887e9f803d4e857eaWink Saville                    if (VDBG) {
190ded9c0af7fa49504c047275ed34c2d3b22bf0c3aWink Saville                        Rlog.d(LOG_TAG,"ADN EF: 0x"
19122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                            + Integer.toHexString(mEf)
19222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                            + ":" + mRecordNumber
1930825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                            + "\n" + IccUtils.bytesToHexString(data));
1940825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
1950825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
19622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    adn = new AdnRecord(mEf, mRecordNumber, data);
19722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mResult = adn;
1980825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
1990825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    if (adn.hasExtendedRecord()) {
2000825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        // If we have a valid value in the ext record field,
2010825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        // we're not done yet: we need to read the corresponding
2020825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        // ext record and append it
2030825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
20422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                        mPendingExtLoads = 1;
2050825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2060825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        mFh.loadEFLinearFixed(
20722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                            mExtensionEF, adn.mExtRecord,
2080825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                            obtainMessage(EVENT_EXT_RECORD_LOAD_DONE, adn));
2090825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
2100825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                break;
2110825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2120825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                case EVENT_EXT_RECORD_LOAD_DONE:
2130825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    ar = (AsyncResult)(msg.obj);
2140825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    data = (byte[])(ar.result);
2150825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    adn = (AdnRecord)(ar.userObj);
2160825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2170825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    if (ar.exception != null) {
2180825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        throw new RuntimeException("load failed", ar.exception);
2190825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
2200825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
221ded9c0af7fa49504c047275ed34c2d3b22bf0c3aWink Saville                    Rlog.d(LOG_TAG,"ADN extension EF: 0x"
22222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                        + Integer.toHexString(mExtensionEF)
22322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                        + ":" + adn.mExtRecord
2240825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        + "\n" + IccUtils.bytesToHexString(data));
2250825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2260825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    adn.appendExtRecord(data);
2270825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
22822d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mPendingExtLoads--;
2290825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    // result should have been set in
2300825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    // EVENT_ADN_LOAD_DONE or EVENT_ADN_LOAD_ALL_DONE
2310825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                break;
2320825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2330825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                case EVENT_ADN_LOAD_ALL_DONE:
2340825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    ar = (AsyncResult)(msg.obj);
2350825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    ArrayList<byte[]> datas = (ArrayList<byte[]>)(ar.result);
2360825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2370825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    if (ar.exception != null) {
2380825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        throw new RuntimeException("load failed", ar.exception);
2390825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
2400825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
24122d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mAdns = new ArrayList<AdnRecord>(datas.size());
24222d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mResult = mAdns;
24322d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                    mPendingExtLoads = 0;
2440825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2450825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    for(int i = 0, s = datas.size() ; i < s ; i++) {
24622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                        adn = new AdnRecord(mEf, 1 + i, datas.get(i));
24722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                        mAdns.add(adn);
2480825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2490825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        if (adn.hasExtendedRecord()) {
2500825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                            // If we have a valid value in the ext record field,
2510825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                            // we're not done yet: we need to read the corresponding
2520825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                            // ext record and append it
2530825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
25422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                            mPendingExtLoads++;
2550825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2560825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                            mFh.loadEFLinearFixed(
25722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                                mExtensionEF, adn.mExtRecord,
2580825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                                obtainMessage(EVENT_EXT_RECORD_LOAD_DONE, adn));
2590825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                        }
2600825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                    }
2610825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                break;
2620825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville            }
2630825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        } catch (RuntimeException exc) {
26422d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            if (mUserResponse != null) {
26522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                AsyncResult.forMessage(mUserResponse)
2660825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                                .exception = exc;
26722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                mUserResponse.sendToTarget();
2680825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                // Loading is all or nothing--either every load succeeds
2690825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville                // or we fail the whole thing.
27022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                mUserResponse = null;
2710825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville            }
2720825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville            return;
2730825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        }
2740825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
27522d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville        if (mUserResponse != null && mPendingExtLoads == 0) {
27622d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            AsyncResult.forMessage(mUserResponse).result
27722d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville                = mResult;
2780825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
27922d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mUserResponse.sendToTarget();
28022d85a8e3a575a6d01d2c788587971657dfe20c6Wink Saville            mUserResponse = null;
2810825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville        }
2820825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville    }
2830825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2840825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville
2850825495a331bb44df395a0cdb79fab85e68db5d5Wink Saville}
286