FileDocCategorySizeDatePackage
RIL.javaAPI DocAndroid 5.1 API170961Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony

RILRequest

public class RILRequest extends Object
{@hide}

Fields Summary
static final String
LOG_TAG
static Random
sRandom
static AtomicInteger
sNextSerial
private static Object
sPoolSync
private static RILRequest
sPool
private static int
sPoolSize
private static final int
MAX_POOL_SIZE
private android.content.Context
mContext
int
mSerial
int
mRequest
android.os.Message
mResult
android.os.Parcel
mParcel
RILRequest
mNext
Constructors Summary
private RILRequest()

    
Methods Summary
static com.android.internal.telephony.RILRequestobtain(int request, android.os.Message result)
Retrieves a new RILRequest instance from the pool.

param
request RIL_REQUEST_*
param
result sent when operation completes
return
a RILRequest instance from the pool.


                                 
          
        RILRequest rr = null;

        synchronized(sPoolSync) {
            if (sPool != null) {
                rr = sPool;
                sPool = rr.mNext;
                rr.mNext = null;
                sPoolSize--;
            }
        }

        if (rr == null) {
            rr = new RILRequest();
        }

        rr.mSerial = sNextSerial.getAndIncrement();

        rr.mRequest = request;
        rr.mResult = result;
        rr.mParcel = Parcel.obtain();

        if (result != null && result.getTarget() == null) {
            throw new NullPointerException("Message target must not be null");
        }

        // first elements in any RIL Parcel
        rr.mParcel.writeInt(request);
        rr.mParcel.writeInt(rr.mSerial);

        return rr;
    
voidonError(int error, java.lang.Object ret)

        CommandException ex;

        ex = CommandException.fromRilErrno(error);

        if (RIL.RILJ_LOGD) Rlog.d(LOG_TAG, serialString() + "< "
            + RIL.requestToString(mRequest)
            + " error: " + ex + " ret=" + RIL.retToString(mRequest, ret));

        if (mResult != null) {
            AsyncResult.forMessage(mResult, ret, ex);
            mResult.sendToTarget();
        }

        if (mParcel != null) {
            mParcel.recycle();
            mParcel = null;
        }
    
voidrelease()
Returns a RILRequest instance to the pool. Note: This should only be called once per use.

        synchronized (sPoolSync) {
            if (sPoolSize < MAX_POOL_SIZE) {
                mNext = sPool;
                sPool = this;
                sPoolSize++;
                mResult = null;
            }
        }
    
static voidresetSerial()

        // use a random so that on recovery we probably don't mix old requests
        // with new.
        sNextSerial.set(sRandom.nextInt());
    
java.lang.StringserialString()

        //Cheesy way to do %04d
        StringBuilder sb = new StringBuilder(8);
        String sn;

        long adjustedSerial = (((long)mSerial) - Integer.MIN_VALUE)%10000;

        sn = Long.toString(adjustedSerial);

        //sb.append("J[");
        sb.append('[");
        for (int i = 0, s = sn.length() ; i < 4 - s; i++) {
            sb.append('0");
        }

        sb.append(sn);
        sb.append(']");
        return sb.toString();