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

Commit 7a83e689 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Added LocalLog for UICC.

And some other code cleanup.

Test: Basic sanity, manually looked at a bugreport for dumped locallog
Bug: 72463963
Change-Id: Ia57b378b021ae79db6dfbbe37c74cea2dd67ccf1
parent 800fafbc
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -344,12 +344,12 @@ public class SubscriptionInfoUpdater extends Handler {
        if (iccId == null) {
            IccCard iccCard = mPhone[slotId].getIccCard();
            if (iccCard == null) {
                logd("handleSimLoaded: IccCard null");
                logd("handleSimLocked: IccCard null");
                return;
            }
            IccRecords records = iccCard.getIccRecords();
            if (records == null) {
                logd("handleSimLoaded: IccRecords null");
                logd("handleSimLocked: IccRecords null");
                return;
            }
            if (IccUtils.stripTrailingFs(records.getFullIccId()) == null) {
+0 −8
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.os.Handler;
import android.os.Message;
import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.util.LocalLog;

import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.TelephonyComponentFactory;
@@ -47,8 +46,6 @@ public class UiccCard {
    public static final String EXTRA_ICC_CARD_ADDED =
            "com.android.internal.telephony.uicc.ICC_CARD_ADDED";

    private static final String OPERATOR_BRAND_OVERRIDE_PREFIX = "operator_branding_";

    private final Object mLock = new Object();
    private CardState mCardState;
    private String mIccid;
@@ -56,7 +53,6 @@ public class UiccCard {
    private UiccProfile mUiccProfile;
    private Context mContext;
    private CommandsInterface mCi;
    private static final LocalLog mLocalLog = new LocalLog(100);
    private final int mPhoneId;

    public UiccCard(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId) {
@@ -506,10 +502,6 @@ public class UiccCard {
        Rlog.e(LOG_TAG, msg);
    }

    private void loglocal(String msg) {
        if (DBG) mLocalLog.log(msg);
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("UiccCard:");
        pw.println(" mCi=" + mCi);
+28 −37
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import android.os.RegistrantList;
import android.os.storage.StorageManager;
import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.text.format.Time;
import android.util.LocalLog;

import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandsInterface;
@@ -38,7 +38,6 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

/**
@@ -123,14 +122,13 @@ public class UiccController extends Handler {
    private UiccStateChangedLauncher mLauncher;
    private RadioConfig mRadioConfig;

    // Logging for dumpsys. Useful in cases when the cards run into errors.
    private static final int MAX_PROACTIVE_COMMANDS_TO_LOG = 20;
    private LinkedList<String> mCardLogs = new LinkedList<String>();
    // LocalLog buffer to hold important SIM related events for debugging
    static LocalLog sLocalLog = new LocalLog(100);

    public static UiccController make(Context c, CommandsInterface[] ci) {
        synchronized (mLock) {
            if (mInstance != null) {
                throw new RuntimeException("MSimUiccController.make() should only be called once");
                throw new RuntimeException("UiccController.make() should only be called once");
            }
            mInstance = new UiccController(c, ci);
            return mInstance;
@@ -141,9 +139,11 @@ public class UiccController extends Handler {
        if (DBG) log("Creating UiccController");
        mContext = c;
        mCis = ci;
        if (VDBG) {
            log("config_num_physical_slots = " + c.getResources().getInteger(
                    com.android.internal.R.integer.config_num_physical_slots));
        if (DBG) {
            String logStr = "config_num_physical_slots = " + c.getResources().getInteger(
                    com.android.internal.R.integer.config_num_physical_slots);
            log(logStr);
            sLocalLog.log(logStr);
        }
        int numPhysicalSlots = c.getResources().getInteger(
                com.android.internal.R.integer.config_num_physical_slots);
@@ -369,6 +369,8 @@ public class UiccController extends Handler {
                return;
            }

            sLocalLog.log("handleMessage: Received " + msg.what + " for phoneId " + phoneId);

            AsyncResult ar = (AsyncResult)msg.obj;
            switch (msg.what) {
                case EVENT_ICC_STATUS_CHANGED:
@@ -471,6 +473,8 @@ public class UiccController extends Handler {

        IccCardStatus status = (IccCardStatus)ar.result;

        sLocalLog.log("onGetIccCardStatusDone: phoneId " + index + " IccCardStatus: " + status);

        int slotId = status.physicalSlotIndex;
        if (VDBG) log("onGetIccCardStatusDone: phoneId " + index + " physicalSlotIndex " + slotId);
        if (slotId == INVALID_SLOT_ID) {
@@ -501,15 +505,20 @@ public class UiccController extends Handler {
        }
        Throwable e = ar.exception;
        if (e != null) {
            String logStr;
            if (!(e instanceof CommandException) || ((CommandException) e).getCommandError()
                    != CommandException.Error.REQUEST_NOT_SUPPORTED) {
                // this is not expected; there should be no exception other than
                // REQUEST_NOT_SUPPORTED
                Rlog.e(LOG_TAG, "Unexpected error getting slot status: " + ar.exception);
                logStr = "Unexpected error getting slot status: " + ar.exception;
                Rlog.e(LOG_TAG, logStr);
                sLocalLog.log(logStr);
            } else {
                // REQUEST_NOT_SUPPORTED
                log("onGetSlotStatusDone: request not supported; marking mIsSlotStatusSupported "
                        + "to false");
                logStr = "onGetSlotStatusDone: request not supported; marking "
                        + "mIsSlotStatusSupported to false";
                log(logStr);
                sLocalLog.log(logStr);
                mIsSlotStatusSupported = false;
            }
            return;
@@ -522,6 +531,8 @@ public class UiccController extends Handler {
            return;
        }

        sLastSlotStatus = status;

        int numActiveSlots = 0;
        for (int i = 0; i < status.size(); i++) {
            IccSlotStatus iss = status.get(i);
@@ -587,22 +598,10 @@ public class UiccController extends Handler {
            log("    phoneId " + i + " slotId " + mPhoneIdToSlotId[i]);
        }
    }
    /**
     * Slots are initialized when none of them are null.
     * todo: is this even needed?
     */
    private synchronized boolean areSlotsInitialized() {
        for (UiccSlot slot : mUiccSlots) {
            if (slot == null) {
                return false;
            }
        }
        return true;
    }

    private void onSimRefresh(AsyncResult ar, Integer index) {
        if (ar.exception != null) {
            Rlog.e(LOG_TAG, "Sim REFRESH with exception: " + ar.exception);
            Rlog.e(LOG_TAG, "onSimRefresh: Sim REFRESH with exception: " + ar.exception);
            return;
        }

@@ -613,6 +612,7 @@ public class UiccController extends Handler {

        IccRefreshResponse resp = (IccRefreshResponse) ar.result;
        log("onSimRefresh: " + resp);
        sLocalLog.log("onSimRefresh: " + resp);

        if (resp == null) {
            Rlog.e(LOG_TAG, "onSimRefresh: received without input");
@@ -625,7 +625,6 @@ public class UiccController extends Handler {
            return;
        }

        log("Handling refresh: " + resp);
        boolean changed = false;
        switch(resp.refreshResult) {
            case IccRefreshResponse.REFRESH_RESULT_RESET:
@@ -662,14 +661,8 @@ public class UiccController extends Handler {
        Rlog.d(LOG_TAG, string);
    }

    // TODO: This is hacky. We need a better way of saving the logs.
    public void addCardLog(String data) {
        Time t = new Time();
        t.setToNow();
        mCardLogs.addLast(t.format("%m-%d %H:%M:%S") + " " + data);
        if (mCardLogs.size() > MAX_PROACTIVE_COMMANDS_TO_LOG) {
            mCardLogs.removeFirst();
        }
        sLocalLog.log(data);
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
@@ -692,9 +685,7 @@ public class UiccController extends Handler {
                mUiccSlots[i].dump(fd, pw, args);
            }
        }
        pw.println("mCardLogs: ");
        for (int i = 0; i < mCardLogs.size(); ++i) {
            pw.println("  " + mCardLogs.get(i));
        }
        pw.println(" sLocalLog= ");
        sLocalLog.dump(fd, pw, args);
    }
}
+30 −45
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.telephony.UiccAccessRule;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandsInterface;
@@ -87,7 +86,6 @@ public class UiccProfile extends Handler implements IccCard {
    protected static final String LOG_TAG = "UiccProfile";
    protected static final boolean DBG = true;
    private static final boolean VDBG = false; //STOPSHIP if true
    private static final boolean ICC_CARD_PROXY_REMOVED = true;

    private static final String OPERATOR_BRAND_OVERRIDE_PREFIX = "operator_branding_";

@@ -114,8 +112,6 @@ public class UiccProfile extends Handler implements IccCard {
    private static final int EVENT_SIM_IO_DONE = 19;
    private static final int EVENT_CARRIER_PRIVILEGES_LOADED = 20;

    private static final LocalLog sLocalLog = new LocalLog(100);

    private final int mPhoneId;

    /*----------------------------------------------------*/
@@ -159,27 +155,21 @@ public class UiccProfile extends Handler implements IccCard {
        if (DBG) log("Creating profile");
        mUiccCard = uiccCard;
        mPhoneId = phoneId;
        if (ICC_CARD_PROXY_REMOVED) {
        // set current app type based on phone type - do this before calling update() as that
        // calls updateIccAvailability() which uses mCurrentAppType
        Phone phone = PhoneFactory.getPhone(phoneId);
        if (phone != null) {
            setCurrentAppType(phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM);
        }
        }

        if (mUiccCard instanceof EuiccCard) {
            ((EuiccCard) mUiccCard).registerForEidReady(this, EVENT_EID_READY, null);
        }

        update(c, ci, ics);

        if (ICC_CARD_PROXY_REMOVED) {
        ci.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_UNAVAILABLE, null);

        resetProperties();
    }
    }

    /**
     * Dispose the UiccProfile.
@@ -198,9 +188,7 @@ public class UiccProfile extends Handler implements IccCard {
                ((EuiccCard) mUiccCard).unregisterForEidReady(this);
            }

            if (ICC_CARD_PROXY_REMOVED) {
            mCi.unregisterForOffOrNotAvailable(this);
            }

            if (mCatService != null) mCatService.dispose();
            for (UiccCardApplication app : mUiccApplications) {
@@ -248,6 +236,7 @@ public class UiccProfile extends Handler implements IccCard {
            loge("handleMessage: Received " + msg.what + " after dispose(); ignoring the message");
            return;
        }
        loglocal("handleMessage: Received " + msg.what + " for phoneId " + mPhoneId);
        switch (msg.what) {
            case EVENT_NETWORK_LOCKED:
                mNetworkLockedRegistrants.notifyRegistrants();
@@ -273,7 +262,7 @@ public class UiccProfile extends Handler implements IccCard {
                break;

            case EVENT_CARRIER_PRIVILEGES_LOADED:
                if (VDBG) log("EVENT_CARRIER_PRIVILEGES_LOADED");
                if (VDBG) log("handleMessage: EVENT_CARRIER_PRIVILEGES_LOADED");
                onCarrierPrivilegesLoadedMessage();
                updateExternalState();
                break;
@@ -285,15 +274,15 @@ public class UiccProfile extends Handler implements IccCard {
            case EVENT_SIM_IO_DONE:
                AsyncResult ar = (AsyncResult) msg.obj;
                if (ar.exception != null) {
                    loglocal("Exception: " + ar.exception);
                    log("Error in SIM access with exception" + ar.exception);
                    loglocal("handleMessage: Exception " + ar.exception);
                    log("handleMessage: Error in SIM access with exception" + ar.exception);
                }
                AsyncResult.forMessage((Message) ar.userObj, ar.result, ar.exception);
                ((Message) ar.userObj).sendToTarget();
                break;

            default:
                loge("Unhandled message with number: " + msg.what);
                loge("handleMessage: Unhandled message with number: " + msg.what);
                break;
        }
    }
@@ -500,8 +489,10 @@ public class UiccProfile extends Handler implements IccCard {
        intent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE, value);
        intent.putExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON, reason);
        intent.putExtra(PhoneConstants.PHONE_KEY, phoneId);  // SubId may not be valid.
        log("Sending intent ACTION_INTERNAL_SIM_STATE_CHANGED value=" + value
                + " for mPhoneId : " + phoneId);
        String logStr = "Sending intent ACTION_INTERNAL_SIM_STATE_CHANGED value=" + value
                + " for mPhoneId : " + phoneId;
        log(logStr);
        UiccController.sLocalLog.log("UiccProfile[" + phoneId + "]: " + logStr);
        ActivityManager.broadcastStickyIntent(intent, UserHandle.USER_ALL);
    }

@@ -1217,7 +1208,7 @@ public class UiccProfile extends Handler implements IccCard {
     * Exposes {@link CommandsInterface#iccOpenLogicalChannel}
     */
    public void iccOpenLogicalChannel(String aid, int p2, Message response) {
        loglocal("Open Logical Channel: " + aid + " , " + p2 + " by pid:" + Binder.getCallingPid()
        loglocal("iccOpenLogicalChannel: " + aid + " , " + p2 + " by pid:" + Binder.getCallingPid()
                + " uid:" + Binder.getCallingUid());
        mCi.iccOpenLogicalChannel(aid, p2,
                obtainMessage(EVENT_OPEN_LOGICAL_CHANNEL_DONE, response));
@@ -1227,7 +1218,7 @@ public class UiccProfile extends Handler implements IccCard {
     * Exposes {@link CommandsInterface#iccCloseLogicalChannel}
     */
    public void iccCloseLogicalChannel(int channel, Message response) {
        loglocal("Close Logical Channel: " + channel);
        loglocal("iccCloseLogicalChannel: " + channel);
        mCi.iccCloseLogicalChannel(channel,
                obtainMessage(EVENT_CLOSE_LOGICAL_CHANNEL_DONE, response));
    }
@@ -1445,8 +1436,8 @@ public class UiccProfile extends Handler implements IccCard {
        Rlog.e(LOG_TAG, msg);
    }

    private static void loglocal(String msg) {
        if (DBG) sLocalLog.log(msg);
    private void loglocal(String msg) {
        if (DBG) UiccController.sLocalLog.log("UiccProfile[" + mPhoneId + "]: " + msg);
    }

    /**
@@ -1505,7 +1496,6 @@ public class UiccProfile extends Handler implements IccCard {
        }
        pw.flush();

        if (ICC_CARD_PROXY_REMOVED) {
        pw.println(" mNetworkLockedRegistrants: size=" + mNetworkLockedRegistrants.size());
        for (int i = 0; i < mNetworkLockedRegistrants.size(); i++) {
            pw.println("  mNetworkLockedRegistrants[" + i + "]="
@@ -1518,9 +1508,4 @@ public class UiccProfile extends Handler implements IccCard {
        pw.println(" mExternalState=" + mExternalState);
        pw.flush();
    }

        pw.println("sLocalLog:");
        sLocalLog.dump(fd, pw, args);
        pw.flush();
    }
}
+0 −9
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.telephony.Rlog;
import android.util.LocalLog;
import android.view.WindowManager;

import com.android.internal.R;
@@ -66,8 +65,6 @@ public class UiccSlot extends Handler {
    private static final int EVENT_CARD_REMOVED = 13;
    private static final int EVENT_CARD_ADDED = 14;

    private static final LocalLog sLocalLog = new LocalLog(100);

    public UiccSlot(Context c, boolean isActive) {
        if (DBG) log("Creating");
        mContext = c;
@@ -339,10 +336,6 @@ public class UiccSlot extends Handler {
        Rlog.e(TAG, msg);
    }

    private void loglocal(String msg) {
        if (DBG) sLocalLog.log(msg);
    }

    /**
     * Dump
     */
@@ -360,8 +353,6 @@ public class UiccSlot extends Handler {
        }
        pw.println();
        pw.flush();
        pw.println("sLocalLog:");
        sLocalLog.dump(fd, pw, args);
        pw.flush();
    }
}