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

Commit b6f7017f authored by Shishir Agrawal's avatar Shishir Agrawal Committed by Android (Google) Code Review
Browse files

Merge "SIM state loaded should wait for carrier priviliges to load." into lmp-dev

parents 31d370f2 c9877fe3
Loading
Loading
Loading
Loading
+27 −5
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ public class IccCardProxy extends Handler implements IccCard {
    private static final int EVENT_ICC_RECORD_EVENTS = 500;
    private static final int EVENT_SUBSCRIPTION_ACTIVATED = 501;
    private static final int EVENT_SUBSCRIPTION_DEACTIVATED = 502;
    private static final int EVENT_CARRIER_PRIVILIGES_LOADED = 503;

    // FIXME Rename mCardIndex to mSlotId.
    private Integer mCardIndex = null;
@@ -120,6 +121,8 @@ public class IccCardProxy extends Handler implements IccCard {
    private boolean mInitialized = false;
    private State mExternalState = State.UNKNOWN;

    private int mRecordsToLoad;  // number of pending load requests

    public IccCardProxy(Context context, CommandsInterface ci) {
        log("Creating");
        mContext = context;
@@ -278,7 +281,7 @@ public class IccCardProxy extends Handler implements IccCard {
                        loge("EVENT_RECORDS_LOADED Operator name is null");
                    }
                }
                broadcastIccStateChangedIntent(IccCardConstants.INTENT_VALUE_ICC_LOADED, null);
                onRecordsLoaded();
                break;
            case EVENT_IMSI_READY:
                broadcastIccStateChangedIntent(IccCardConstants.INTENT_VALUE_ICC_IMSI, null);
@@ -312,6 +315,11 @@ public class IccCardProxy extends Handler implements IccCard {
                }
                break;

            case EVENT_CARRIER_PRIVILIGES_LOADED:
                log("EVENT_CARRIER_PRIVILEGES_LOADED");
                onRecordsLoaded();
                break;

            default:
                loge("Unhandled message with number: " + msg.what);
                break;
@@ -332,6 +340,14 @@ public class IccCardProxy extends Handler implements IccCard {
        updateStateProperty();
    }

    private void onRecordsLoaded() {
        synchronized (mLock) {
            --mRecordsToLoad;
            if (mRecordsToLoad == 0) {
                broadcastIccStateChangedIntent(IccCardConstants.INTENT_VALUE_ICC_LOADED, null);
            }
        }
    }

    private void updateIccAvailability() {
        synchronized (mLock) {
@@ -349,6 +365,7 @@ public class IccCardProxy extends Handler implements IccCard {

            if (mIccRecords != newRecords || mUiccApplication != newApp || mUiccCard != newCard) {
                if (DBG) log("Icc changed. Reregestering.");
                mRecordsToLoad = 0;
                unregisterUiccCardEvents();
                mUiccCard = newCard;
                mUiccApplication = newApp;
@@ -422,7 +439,14 @@ public class IccCardProxy extends Handler implements IccCard {
    }

    private void registerUiccCardEvents() {
        if (mUiccCard != null) mUiccCard.registerForAbsent(this, EVENT_ICC_ABSENT, null);
        mRecordsToLoad = (mUiccCard != null ? 1 : 0) +
            (mIccRecords != null ? 1 : 0);

        if (mUiccCard != null) {
            mUiccCard.registerForAbsent(this, EVENT_ICC_ABSENT, null);
            mUiccCard.registerForCarrierPrivilegeRulesLoaded(
                    this, EVENT_CARRIER_PRIVILIGES_LOADED, null);
        }
        if (mUiccApplication != null) {
            mUiccApplication.registerForReady(this, EVENT_APP_READY, null);
            mUiccApplication.registerForLocked(this, EVENT_ICC_LOCKED, null);
@@ -431,15 +455,13 @@ public class IccCardProxy extends Handler implements IccCard {
        if (mIccRecords != null) {
            mIccRecords.registerForImsiReady(this, EVENT_IMSI_READY, null);
            mIccRecords.registerForRecordsLoaded(this, EVENT_RECORDS_LOADED, null);
        }

        if (mIccRecords != null) {
            mIccRecords.registerForRecordsEvents(this, EVENT_ICC_RECORD_EVENTS, null);
        }
    }

    private void unregisterUiccCardEvents() {
        if (mUiccCard != null) mUiccCard.unregisterForAbsent(this);
        if (mUiccCard != null) mUiccCard.unregisterForCarrierPrivilegeRulesLoaded(this);
        if (mUiccApplication != null) mUiccApplication.unregisterForReady(this);
        if (mUiccApplication != null) mUiccApplication.unregisterForLocked(this);
        if (mUiccApplication != null) mUiccApplication.unregisterForNetworkLocked(this);
+39 −1
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public class UiccCard {
    private UiccCarrierPrivilegeRules mCarrierPrivilegeRules;

    private RegistrantList mAbsentRegistrants = new RegistrantList();
    private RegistrantList mCarrierPrivilegeRegistrants = new RegistrantList();

    private static final int EVENT_CARD_REMOVED = 13;
    private static final int EVENT_CARD_ADDED = 14;
@@ -92,6 +93,7 @@ public class UiccCard {
    private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 17;
    private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 18;
    private static final int EVENT_SIM_IO_DONE = 19;
    private static final int EVENT_CARRIER_PRIVILIGES_LOADED = 20;

    int mSlotId;

@@ -163,7 +165,8 @@ public class UiccCard {
            // Reload the carrier privilege rules if necessary.
            log("Before privilege rules: " + mCarrierPrivilegeRules + " : " + mCardState);
            if (mCarrierPrivilegeRules == null && mCardState == CardState.CARDSTATE_PRESENT) {
                mCarrierPrivilegeRules = new UiccCarrierPrivilegeRules(this);
                mCarrierPrivilegeRules = new UiccCarrierPrivilegeRules(this,
                        mHandler.obtainMessage(EVENT_CARRIER_PRIVILIGES_LOADED));
            } else if (mCarrierPrivilegeRules != null && mCardState != CardState.CARDSTATE_PRESENT) {
                mCarrierPrivilegeRules = null;
            }
@@ -272,6 +275,28 @@ public class UiccCard {
        }
    }

    /**
     * Notifies handler when carrier privilege rules are loaded.
     */
    public void registerForCarrierPrivilegeRulesLoaded(Handler h, int what, Object obj) {
        synchronized (mLock) {
            Registrant r = new Registrant (h, what, obj);

            mCarrierPrivilegeRegistrants.add(r);

            if (mCarrierPrivilegeRules == null ||
                mCarrierPrivilegeRules.areCarrierPriviligeRulesLoaded()) {
                r.notifyRegistrant();
            }
        }
    }

    public void unregisterForCarrierPrivilegeRulesLoaded(Handler h) {
        synchronized (mLock) {
            mCarrierPrivilegeRegistrants.remove(h);
        }
    }

    private void onIccSwap(boolean isAdded) {

        boolean isHotSwapSupported = mContext.getResources().getBoolean(
@@ -356,12 +381,21 @@ public class UiccCard {
                    AsyncResult.forMessage((Message)ar.userObj, ar.result, ar.exception);
                    ((Message)ar.userObj).sendToTarget();
                    break;
                case EVENT_CARRIER_PRIVILIGES_LOADED:
                    onCarrierPriviligesLoadedMessage();
                    break;
                default:
                    loge("Unknown Event " + msg.what);
            }
        }
    };

    private void onCarrierPriviligesLoadedMessage() {
        synchronized (mLock) {
            mCarrierPrivilegeRegistrants.notifyRegistrants();
        }
    }

    public boolean isApplicationOnIcc(IccCardApplicationStatus.AppType type) {
        synchronized (mLock) {
            for (int i = 0 ; i < mUiccApplications.length; i++) {
@@ -591,6 +625,10 @@ public class UiccCard {
            pw.println("  mAbsentRegistrants[" + i + "]="
                    + ((Registrant)mAbsentRegistrants.get(i)).getHandler());
        }
        for (int i = 0; i < mCarrierPrivilegeRegistrants.size(); i++) {
            pw.println("  mCarrierPrivilegeRegistrants[" + i + "]="
                    + ((Registrant)mCarrierPrivilegeRegistrants.get(i)).getHandler());
        }
        pw.println(" mCardState=" + mCardState);
        pw.println(" mUniversalPinState=" + mUniversalPinState);
        pw.println(" mGsmUmtsSubscriptionAppIndex=" + mGsmUmtsSubscriptionAppIndex);
+25 −6
Original line number Diff line number Diff line
@@ -177,17 +177,26 @@ public class UiccCarrierPrivilegeRules extends Handler {
    private UiccCard mUiccCard;  // Parent
    private AtomicInteger mState;
    private List<AccessRule> mAccessRules;
    private Message mLoadedCallback;

    public UiccCarrierPrivilegeRules(UiccCard uiccCard) {
    public UiccCarrierPrivilegeRules(UiccCard uiccCard, Message loadedCallback) {
        Rlog.d(LOG_TAG, "Creating UiccCarrierPrivilegeRules");
        mUiccCard = uiccCard;
        mState = new AtomicInteger(STATE_LOADING);
        mLoadedCallback = loadedCallback;

        // Start loading the rules.
        mUiccCard.iccOpenLogicalChannel(AID,
            obtainMessage(EVENT_OPEN_LOGICAL_CHANNEL_DONE, null));
    }

    /**
     * Returns true if the carrier privilege rules have finished loading.
     */
    public boolean areCarrierPriviligeRulesLoaded() {
        return mState.get() != STATE_LOADING;
    }

    /**
     * Returns the status of the carrier privileges for the input certificate and package name.
     *
@@ -315,7 +324,7 @@ public class UiccCarrierPrivilegeRules extends Handler {
                      obtainMessage(EVENT_TRANSMIT_LOGICAL_CHANNEL_DONE, new Integer(channelId)));
              } else {
                  Rlog.e(LOG_TAG, "Error opening channel");
                  mState.set(STATE_ERROR);
                  updateState(STATE_ERROR);
              }
              break;

@@ -327,19 +336,19 @@ public class UiccCarrierPrivilegeRules extends Handler {
                  if (response.payload != null && response.sw1 == 0x90 && response.sw2 == 0x00) {
                      try {
                          mAccessRules = parseRules(IccUtils.bytesToHexString(response.payload));
                          mState.set(STATE_LOADED);
                          updateState(STATE_LOADED);
                      } catch (IllegalArgumentException ex) {
                          Rlog.e(LOG_TAG, "Error parsing rules: " + ex);
                          mState.set(STATE_ERROR);
                          updateState(STATE_ERROR);
                      }
                   } else {
                      Rlog.e(LOG_TAG, "Invalid response: payload=" + response.payload +
                              " sw1=" + response.sw1 + " sw2=" + response.sw2);
                      mState.set(STATE_ERROR);
                      updateState(STATE_ERROR);
                   }
              } else {
                  Rlog.e(LOG_TAG, "Error reading value from SIM.");
                  mState.set(STATE_ERROR);
                  updateState(STATE_ERROR);
              }

              int channelId = (Integer) ar.userObj;
@@ -463,4 +472,14 @@ public class UiccCarrierPrivilegeRules extends Handler {
        Rlog.e(LOG_TAG, "Cannot compute cert hash");
        return null;
    }

    /*
     * Updates the state and notifies the UiccCard that the rules have finished loading.
     */
    private void updateState(int newState) {
        mState.set(newState);
        if (mLoadedCallback != null) {
            mLoadedCallback.sendToTarget();
        }
    }
}