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

Commit 2729dc12 authored by arunvoddu's avatar arunvoddu Committed by Arun Voddu
Browse files

Handle UNKNOWN SIM application type correctly for creating CatService.

Ensures file handler is taken from a valid SIM app, preventing issues with malformed SIM reports.

Bug: 417398404
Flag: com.android.internal.telephony.flags.cat_service_creation_fix
Test: atest and Manually verified.
Change-Id: Icc8434fb5765b1777430cd17a45e8bf361f92512
parent 0f37f72c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -134,3 +134,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)) {