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

Commit bfe3ada6 authored by Arun Voddu's avatar Arun Voddu Committed by Android (Google) Code Review
Browse files

Merge "Handle UNKNOWN SIM application type correctly for creating CatService." into main

parents 7a474a99 2729dc12
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -142,3 +142,11 @@ flag {
    description: "This flag reset the cache if the sim phonebook is empty"
    bug:"404094844"
}

# OWNER=arunvoddu TARGET=25Q4
flag {
    name: "cat_service_creation_fix"
    namespace: "telephony"
    description: "This flag reset the cache if the sim phonebook is empty"
    bug:"417398404"
}
 No newline at end of file
+37 −18
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.telephony.cat;
import static com.android.internal.telephony.cat.CatCmdMessage.SetupEventListConstants.IDLE_SCREEN_AVAILABLE_EVENT;
import static com.android.internal.telephony.cat.CatCmdMessage.SetupEventListConstants.LANGUAGE_SELECTION_EVENT;
import static com.android.internal.telephony.cat.CatCmdMessage.SetupEventListConstants.USER_ACTIVITY_EVENT;
import static com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType.APPTYPE_UNKNOWN;

import android.app.Activity;
import android.app.ActivityManager;
@@ -52,6 +53,7 @@ import com.android.internal.telephony.ProxyController;
import com.android.internal.telephony.SmsController;
import com.android.internal.telephony.flags.FeatureFlags;
import com.android.internal.telephony.flags.FeatureFlagsImpl;
import com.android.internal.telephony.flags.Flags;
import com.android.internal.telephony.subscription.SubscriptionManagerService;
import com.android.internal.telephony.uicc.IccCardStatus.CardState;
import com.android.internal.telephony.uicc.IccFileHandler;
@@ -218,6 +220,34 @@ public class CatService extends Handler implements AppInterface {
        mContext.registerReceiver(mSmsBroadcastReceiver, new IntentFilter(SMS_SENT_ACTION));
    }

    private static UiccCardApplication getValidUiccApplication(UiccProfile uiccProfile) {
        UiccCardApplication ca = null;
        if (uiccProfile != null) {
            /* Since Cat is not tied to any application, but rather is Uicc application
             * in itself - just get first FileHandler and IccRecords object
             */
            ca = uiccProfile.getApplicationIndex(0);

            /**
             * Case where the SIMs reporting "UNKNOWN" application type.
             * If an "UNKNOWN" application is detected, its file handler won't be initialized
             * correctly.
             * To avoid issues, always use the file handler from a known, valid SIM application.
             */
            if (Flags.catServiceCreationFix() && ca.getType() == APPTYPE_UNKNOWN
                    && uiccProfile.getNumApplications() > 1) {
                for (int i = 1; i < uiccProfile.getNumApplications(); i++) {
                    UiccCardApplication tmpCa = uiccProfile.getApplicationIndex(i);
                    if (tmpCa.getType() != APPTYPE_UNKNOWN) {
                        ca = tmpCa;
                        break;
                    }
                }
            }
        }
        return ca;
    }

    /**
     * Used for instantiating the Service from the Card.
     *
@@ -238,16 +268,11 @@ public class CatService extends Handler implements AppInterface {
        UiccCardApplication ca = null;
        IccFileHandler fh = null;
        IccRecords ir = null;
        if (uiccProfile != null) {
            /* Since Cat is not tied to any application, but rather is Uicc application
             * in itself - just get first FileHandler and IccRecords object
             */
            ca = uiccProfile.getApplicationIndex(0);
        ca = getValidUiccApplication(uiccProfile);
        if (ca != null) {
            fh = ca.getIccFileHandler();
            ir = ca.getIccRecords();
        }
        }

        synchronized (sInstanceLock) {
            if (sInstance == null) {
@@ -1302,16 +1327,10 @@ public class CatService extends Handler implements AppInterface {
            Context context, UiccProfile uiccProfile) {
        UiccCardApplication ca = null;
        IccRecords ir = null;

        if (uiccProfile != null) {
            /* Since Cat is not tied to any application, but rather is Uicc application
             * in itself - just get first FileHandler and IccRecords object
             */
            ca = uiccProfile.getApplicationIndex(0);
        ca = getValidUiccApplication(uiccProfile);
        if (ca != null) {
            ir = ca.getIccRecords();
        }
        }

        synchronized (sInstanceLock) {
            if ((ir != null) && (mIccRecords != ir)) {