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

Commit ef5867a3 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed database not closed after use

Test: Telephony sanity tests
bug:

Change-Id: Ifb8f058bef78810ad21c038a1abc97e3be2f0713
parent ef4062e1
Loading
Loading
Loading
Loading
+28 −26
Original line number Diff line number Diff line
@@ -16,17 +16,16 @@

package com.android.internal.telephony;

import android.util.Log;
import android.content.Context;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.telephony.Rlog;

import com.android.internal.telephony.HbpcdLookup;
import com.android.internal.telephony.HbpcdLookup.ArbitraryMccSidMatch;
import com.android.internal.telephony.HbpcdLookup.MccIdd;
import com.android.internal.telephony.HbpcdLookup.MccLookup;
import com.android.internal.telephony.HbpcdLookup.MccSidConflicts;
import com.android.internal.telephony.HbpcdLookup.MccSidRange;
import com.android.internal.telephony.HbpcdLookup.ArbitraryMccSidMatch;

public final class HbpcdUtils {
    private static final String LOG_TAG = "HbpcdUtils";
@@ -55,16 +54,16 @@ public final class HbpcdUtils {
        if (c2 != null) {
            int c2Counter = c2.getCount();
            if (DBG) {
                Log.d(LOG_TAG, "Query unresolved arbitrary table, entries are " + c2Counter);
                Rlog.d(LOG_TAG, "Query unresolved arbitrary table, entries are " + c2Counter);
            }
            if (c2Counter == 1) {
                if (DBG) {
                    Log.d(LOG_TAG, "Query Unresolved arbitrary returned the cursor " + c2 );
                    Rlog.d(LOG_TAG, "Query Unresolved arbitrary returned the cursor " + c2);
                }
                c2.moveToFirst();
                tmpMcc = c2.getInt(0);
                if (DBG) {
                    Log.d(LOG_TAG, "MCC found in arbitrary_mcc_sid_match: " + tmpMcc);
                    Rlog.d(LOG_TAG, "MCC found in arbitrary_mcc_sid_match: " + tmpMcc);
                }
                c2.close();
                return tmpMcc;
@@ -86,22 +85,25 @@ public final class HbpcdUtils {
            int c3Counter = c3.getCount();
            if (c3Counter > 0) {
                if (c3Counter > 1) {
                    Log.w(LOG_TAG, "something wrong, get more results for 1 conflict SID: " + c3);
                    Rlog.w(LOG_TAG, "something wrong, get more results for 1 conflict SID: " + c3);
                }
                if (DBG) Log.d(LOG_TAG, "Query conflict sid returned the cursor " + c3 );
                if (DBG) Rlog.d(LOG_TAG, "Query conflict sid returned the cursor " + c3);
                c3.moveToFirst();
                tmpMcc = c3.getInt(0);
                if (DBG) Log.d(LOG_TAG,
                        "MCC found in mcc_lookup_table. Return tmpMcc = " + tmpMcc);
                if (DBG) {
                    Rlog.d(LOG_TAG, "MCC found in mcc_lookup_table. Return tmpMcc = " + tmpMcc);
                }
                if (!isNitzTimeZone) {
                    // time zone is not accurate, it may get wrong mcc, ignore it.
                    if (DBG) {
                        Rlog.d(LOG_TAG, "time zone is not accurate, mcc may be " + tmpMcc);
                    }
                    tmpMcc = 0;
                }
                c3.close();
                if (isNitzTimeZone) {
                return tmpMcc;
            } else {
                    // time zone is not accurate, it may get wrong mcc, ignore it.
                    if (DBG) Log.d(LOG_TAG, "time zone is not accurate, mcc may be "
                            + tmpMcc);
                        return 0;
                }
                c3.close();
            }
        }

@@ -113,18 +115,18 @@ public final class HbpcdUtils {
                null, null);
        if (c5 != null) {
            if (c5.getCount() > 0) {
                if (DBG) Log.d(LOG_TAG, "Query Range returned the cursor " + c5 );
                if (DBG) Rlog.d(LOG_TAG, "Query Range returned the cursor " + c5);
                c5.moveToFirst();
                tmpMcc = c5.getInt(0);
                if (DBG) Log.d(LOG_TAG, "SID found in mcc_sid_range. Return tmpMcc = " + tmpMcc);
                if (DBG) Rlog.d(LOG_TAG, "SID found in mcc_sid_range. Return tmpMcc = " + tmpMcc);
                c5.close();
                return tmpMcc;
            }
            c5.close();
        }
        if (DBG) Log.d(LOG_TAG, "SID NOT found in mcc_sid_range.");
        if (DBG) Rlog.d(LOG_TAG, "SID NOT found in mcc_sid_range.");

        if (DBG) Log.d(LOG_TAG, "Exit getMccByOtherFactors. Return tmpMcc =  " + tmpMcc );
        if (DBG) Rlog.d(LOG_TAG, "Exit getMccByOtherFactors. Return tmpMcc =  " + tmpMcc);
        // If unknown MCC still could not be resolved,
        return tmpMcc;
    }
@@ -133,7 +135,7 @@ public final class HbpcdUtils {
     *  Gets country information with given MCC.
    */
    public String getIddByMcc(int mcc) {
        if (DBG) Log.d(LOG_TAG, "Enter getHbpcdInfoByMCC.");
        if (DBG) Rlog.d(LOG_TAG, "Enter getHbpcdInfoByMCC.");
        String idd = "";

        Cursor c = null;
@@ -143,19 +145,19 @@ public final class HbpcdUtils {
                MccIdd.MCC + "=" + mcc, null, null);
        if (cur != null) {
            if (cur.getCount() > 0) {
                if (DBG) Log.d(LOG_TAG, "Query Idd returned the cursor " + cur );
                if (DBG) Rlog.d(LOG_TAG, "Query Idd returned the cursor " + cur);
                // TODO: for those country having more than 1 IDDs, need more information
                // to decide which IDD would be used. currently just use the first 1.
                cur.moveToFirst();
                idd = cur.getString(0);
                if (DBG) Log.d(LOG_TAG, "IDD = " + idd);
                if (DBG) Rlog.d(LOG_TAG, "IDD = " + idd);

            }
            cur.close();
        }
        if (c != null) c.close();

        if (DBG) Log.d(LOG_TAG, "Exit getHbpcdInfoByMCC.");
        if (DBG) Rlog.d(LOG_TAG, "Exit getHbpcdInfoByMCC.");
        return idd;
    }
}