Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4cf0eee7 authored by Conley Owens's avatar Conley Owens Committed by Android Code Review
Browse files

Merge "Fixing concurrency issue on IccPhoneBookInterfaceManager."

parents 4b41df61 d7784628
Loading
Loading
Loading
Loading
+33 −22
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.Message;
import android.os.ServiceManager;
import android.os.ServiceManager;


import java.util.List;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;


/**
/**
 * SimPhoneBookInterfaceManager to provide an inter-process communication to
 * SimPhoneBookInterfaceManager to provide an inter-process communication to
@@ -63,14 +64,14 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
                                    " total " + recordSize[1] +
                                    " total " + recordSize[1] +
                                    " #record " + recordSize[2]);
                                    " #record " + recordSize[2]);
                        }
                        }
                        mLock.notifyAll();
                        notifyPending(ar);
                    }
                    }
                    break;
                    break;
                case EVENT_UPDATE_DONE:
                case EVENT_UPDATE_DONE:
                    ar = (AsyncResult) msg.obj;
                    ar = (AsyncResult) msg.obj;
                    synchronized (mLock) {
                    synchronized (mLock) {
                        success = (ar.exception == null);
                        success = (ar.exception == null);
                        mLock.notifyAll();
                        notifyPending(ar);
                    }
                    }
                    break;
                    break;
                case EVENT_LOAD_DONE:
                case EVENT_LOAD_DONE:
@@ -84,11 +85,20 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
                                records.clear();
                                records.clear();
                            }
                            }
                        }
                        }
                        mLock.notifyAll();
                        notifyPending(ar);
                    }
                    }
                    break;
                    break;
            }
            }
        }
        }

        private void notifyPending(AsyncResult ar) {
            if (ar.userObj == null) {
                return;
            }
            AtomicBoolean status = (AtomicBoolean) ar.userObj;
            status.set(true);
            mLock.notifyAll();
        }
    };
    };


    public IccPhoneBookInterfaceManager(PhoneBase phone) {
    public IccPhoneBookInterfaceManager(PhoneBase phone) {
@@ -150,15 +160,12 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
        synchronized(mLock) {
        synchronized(mLock) {
            checkThread();
            checkThread();
            success = false;
            success = false;
            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE);
            AtomicBoolean status = new AtomicBoolean(false);
            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, status);
            AdnRecord oldAdn = new AdnRecord(oldTag, oldPhoneNumber);
            AdnRecord oldAdn = new AdnRecord(oldTag, oldPhoneNumber);
            AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
            AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
            adnCache.updateAdnBySearch(efid, oldAdn, newAdn, pin2, response);
            adnCache.updateAdnBySearch(efid, oldAdn, newAdn, pin2, response);
            try {
            waitForResult(status);
                mLock.wait();
            } catch (InterruptedException e) {
                logd("interrupted while trying to update by search");
            }
        }
        }
        return success;
        return success;
    }
    }
@@ -197,14 +204,11 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
        synchronized(mLock) {
        synchronized(mLock) {
            checkThread();
            checkThread();
            success = false;
            success = false;
            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE);
            AtomicBoolean status = new AtomicBoolean(false);
            Message response = mBaseHandler.obtainMessage(EVENT_UPDATE_DONE, status);
            AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
            AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
            adnCache.updateAdnByIndex(efid, newAdn, index, pin2, response);
            adnCache.updateAdnByIndex(efid, newAdn, index, pin2, response);
            try {
            waitForResult(status);
                mLock.wait();
            } catch (InterruptedException e) {
                logd("interrupted while trying to update by index");
            }
        }
        }
        return success;
        return success;
    }
    }
@@ -243,13 +247,10 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {


        synchronized(mLock) {
        synchronized(mLock) {
            checkThread();
            checkThread();
            Message response = mBaseHandler.obtainMessage(EVENT_LOAD_DONE);
            AtomicBoolean status = new AtomicBoolean(false);
            Message response = mBaseHandler.obtainMessage(EVENT_LOAD_DONE, status);
            adnCache.requestLoadAllAdnLike(efid, adnCache.extensionEfForEf(efid), response);
            adnCache.requestLoadAllAdnLike(efid, adnCache.extensionEfForEf(efid), response);
            try {
            waitForResult(status);
                mLock.wait();
            } catch (InterruptedException e) {
                logd("interrupted while trying to load from the SIM");
            }
        }
        }
        return records;
        return records;
    }
    }
@@ -265,6 +266,16 @@ public abstract class IccPhoneBookInterfaceManager extends IIccPhoneBook.Stub {
        }
        }
    }
    }


    protected void waitForResult(AtomicBoolean status) {
        while (!status.get()) {
            try {
                mLock.wait();
            } catch (InterruptedException e) {
                logd("interrupted while trying to update by search");
            }
        }
    }

    private int updateEfForIccType(int efid) {
    private int updateEfForIccType(int efid) {
        // Check if we are trying to read ADN records
        // Check if we are trying to read ADN records
        if (efid == IccConstants.EF_ADN) {
        if (efid == IccConstants.EF_ADN) {
+5 −6
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.internal.telephony.cdma;
package com.android.internal.telephony.cdma;


import java.util.concurrent.atomic.AtomicBoolean;

import android.os.Message;
import android.os.Message;
import android.util.Log;
import android.util.Log;


@@ -56,14 +58,11 @@ public class RuimPhoneBookInterfaceManager extends IccPhoneBookInterfaceManager
            recordSize = new int[3];
            recordSize = new int[3];


            //Using mBaseHandler, no difference in EVENT_GET_SIZE_DONE handling
            //Using mBaseHandler, no difference in EVENT_GET_SIZE_DONE handling
            Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE);
            AtomicBoolean status = new AtomicBoolean(false);
            Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE, status);


            phone.getIccFileHandler().getEFLinearRecordSize(efid, response);
            phone.getIccFileHandler().getEFLinearRecordSize(efid, response);
            try {
            waitForResult(status);
                mLock.wait();
            } catch (InterruptedException e) {
                logd("interrupted while trying to load from the RUIM");
            }
        }
        }


        return recordSize;
        return recordSize;
+5 −6
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.internal.telephony.gsm;
package com.android.internal.telephony.gsm;


import java.util.concurrent.atomic.AtomicBoolean;

import android.os.Message;
import android.os.Message;
import android.util.Log;
import android.util.Log;


@@ -56,14 +58,11 @@ public class SimPhoneBookInterfaceManager extends IccPhoneBookInterfaceManager {
            recordSize = new int[3];
            recordSize = new int[3];


            //Using mBaseHandler, no difference in EVENT_GET_SIZE_DONE handling
            //Using mBaseHandler, no difference in EVENT_GET_SIZE_DONE handling
            Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE);
            AtomicBoolean status = new AtomicBoolean(false);
            Message response = mBaseHandler.obtainMessage(EVENT_GET_SIZE_DONE, status);


            phone.getIccFileHandler().getEFLinearRecordSize(efid, response);
            phone.getIccFileHandler().getEFLinearRecordSize(efid, response);
            try {
            waitForResult(status);
                mLock.wait();
            } catch (InterruptedException e) {
                logd("interrupted while trying to load from the SIM");
            }
        }
        }


        return recordSize;
        return recordSize;