FileDocCategorySizeDatePackage
HbpcdUtils.javaAPI DocAndroid 5.1 API6556Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony

HbpcdUtils

public final class HbpcdUtils extends Object

Fields Summary
private static final String
LOG_TAG
private static final boolean
DBG
private android.content.ContentResolver
resolver
Constructors Summary
public HbpcdUtils(android.content.Context context)


       
        resolver = context.getContentResolver();
    
Methods Summary
public java.lang.StringgetIddByMcc(int mcc)
Gets country information with given MCC.

        if (DBG) Log.d(LOG_TAG, "Enter getHbpcdInfoByMCC.");
        String idd = "";

        Cursor c = null;

        String projection[] = {MccIdd.IDD};
        Cursor cur = resolver.query(MccIdd.CONTENT_URI, projection,
                MccIdd.MCC + "=" + mcc, null, null);
        if (cur != null) {
            if (cur.getCount() > 0) {
                if (DBG) Log.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);

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

        if (DBG) Log.d(LOG_TAG, "Exit getHbpcdInfoByMCC.");
        return idd;
    
public intgetMcc(int sid, int tz, int DSTflag, boolean isNitzTimeZone)
Resolves the unknown MCC with SID and Timezone information.

        int tmpMcc = 0;

        // check if SID exists in arbitrary_mcc_sid_match table.
        // these SIDs are assigned to more than 1 operators, but they are known to
        // be used by a specific operator, other operators having the same SID are
        // not using it currently, if that SID is in this table, we don't need to
        // check other tables.
        String projection2[] = {ArbitraryMccSidMatch.MCC};
        Cursor c2 = resolver.query(ArbitraryMccSidMatch.CONTENT_URI, projection2,
                            ArbitraryMccSidMatch.SID + "=" + sid, null, null);

        if (c2 != null) {
            int c2Counter = c2.getCount();
            if (DBG) {
                Log.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 );
                }
                c2.moveToFirst();
                tmpMcc = c2.getInt(0);
                if (DBG) {
                    Log.d(LOG_TAG, "MCC found in arbitrary_mcc_sid_match: " + tmpMcc);
                }
                c2.close();
                return tmpMcc;
            }
            c2.close();
        }

        // Then check if SID exists in mcc_sid_conflict table.
        // and use the timezone in mcc_lookup table to check which MCC matches.
        String projection3[] = {MccSidConflicts.MCC};
        Cursor c3 = resolver.query(MccSidConflicts.CONTENT_URI, projection3,
                MccSidConflicts.SID_CONFLICT + "=" + sid + " and (((" +
                MccLookup.GMT_OFFSET_LOW + "<=" + tz + ") and (" + tz + "<=" +
                MccLookup.GMT_OFFSET_HIGH + ") and (" + "0=" + DSTflag + ")) or ((" +
                MccLookup.GMT_DST_LOW + "<=" + tz + ") and (" + tz + "<=" +
                MccLookup.GMT_DST_HIGH + ") and (" + "1=" + DSTflag + ")))",
                        null, null);
        if (c3 != null) {
            int c3Counter = c3.getCount();
            if (c3Counter > 0) {
                if (c3Counter > 1) {
                    Log.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 );
                c3.moveToFirst();
                tmpMcc = c3.getInt(0);
                if (DBG) Log.d(LOG_TAG,
                        "MCC found in mcc_lookup_table. Return tmpMcc = " + tmpMcc);
                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;
                }
            }
        }

        // if there is no conflict, then check if SID is in mcc_sid_range.
        String projection5[] = {MccSidRange.MCC};
        Cursor c5 = resolver.query(MccSidRange.CONTENT_URI, projection5,
                MccSidRange.RANGE_LOW + "<=" + sid + " and " +
                MccSidRange.RANGE_HIGH + ">=" + sid,
                null, null);
        if (c5 != null) {
            if (c5.getCount() > 0) {
                if (DBG) Log.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);
                c5.close();
                return tmpMcc;
            }
            c5.close();
        }
        if (DBG) Log.d(LOG_TAG, "SID NOT found in mcc_sid_range.");

        if (DBG) Log.d(LOG_TAG, "Exit getMccByOtherFactors. Return tmpMcc =  " + tmpMcc );
        // If unknown MCC still could not be resolved,
        return tmpMcc;