getNeighboringCellInfo()方法问题

在ICS4.0上,getNeighboringCellInfo()这个方法不返回任何的数值。

有人在2.0,3.0上都报过同样的bug,但是,其它版本我并没有看code。

简单的看了下4.0的源码,root  cause如下:

当调用getNeighboringCellInfo()时,调用

private Object
   3406     responseCellList(Parcel p) {
   3407        int num, rssi;
   3408        String location;
   3409        ArrayList response;
   3410        NeighboringCellInfo cell;
   3411
   3412        num = p.readInt();
   3413        response = new ArrayList();
   3414
   3415        // Determine the radio access type
   3416        String radioString = SystemProperties.get(
   3417                TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, "unknown");
   3418        // If someday Google changes the return value format of method
   3419        // radioTechnologyToString(),
   3420        // the line below maybe needs to be removed or changed.
   3421        radioString = radioString.split(":")[0];
   3422        int radioType;
   3423        if (radioString.equals("GPRS")) {
   3424            radioType = NETWORK_TYPE_GPRS;
   3425        } else if (radioString.equals("EDGE")) {
   3426            radioType = NETWORK_TYPE_EDGE;
   3427        } else if (radioString.equals("UMTS")) {
   3428            radioType = NETWORK_TYPE_UMTS;
   3429        } else if (radioString.equals("HSDPA")) {
   3430            radioType = NETWORK_TYPE_HSDPA;
   3431        } else if (radioString.equals("HSUPA")) {
   3432            radioType = NETWORK_TYPE_HSUPA;
   3433        } else if (radioString.equals("HSPA")) {
   3434            radioType = NETWORK_TYPE_HSPA;
   3435        } else {
   3436            radioType = NETWORK_TYPE_UNKNOWN;
   3437        }
   3438
   3439        // Interpret the location based on radio access type
   3440        if (radioType != NETWORK_TYPE_UNKNOWN) {
   3441            for (int i = 0 ; i < num ; i++) {
   3442                rssi = p.readInt();
   3443                location = p.readString();
   3444                cell = new NeighboringCellInfo(rssi, location, radioType);
   3445                response.add(cell);
   3446            }
   3447        }
   3448        return response;
   3449     }

但是此时因为人networkType返回一直时unknown,所以,一直不解析底层上来的数据。为什么networktype一直是unknown呢?

原因在这里:

    public static String radioTechnologyToString(int rt) {
    399         String rtString;
    400
    401         switch(rt) {
    402             case 0:
    403                 rtString = "Unknown";
    404                 break;
    405             case 1:
    406                 rtString = "GPRS";
    407                 break;
    408             case 2:
    409                 rtString = "EDGE";
    410                 break;
    411             case 3:
    412                 rtString = "UMTS";
    413                 break;
    414             case 4:
    415                 rtString = "CDMA-IS95A";
    416                 break;
    417             case 5:
    418                 rtString = "CDMA-IS95B";
    419                 break;
    420             case 6:
    421                 rtString = "1xRTT";
    422                 break;
    423             case 7:
    424                 rtString = "EvDo-rev.0";
    425                 break;
    426             case 8:
    427                 rtString = "EvDo-rev.A";
    428                 break;
    429             case 9:
    430                 rtString = "HSDPA";
    431                 break;
    432             case 10:
    433                 rtString = "HSUPA";
    434                 break;
    435             case 11:
    436                 rtString = "HSPA";
    437                 break;
    438             case 12:
    439                 rtString = "EvDo-rev.B";
    440                 break;
    441             case 13:
    442                 rtString = "eHRPD";
    443                 break;
    444             case 14:
    445                 rtString = "LTE";
    446                 break;
    447             case 15:
    448                 rtString = "HSPAP";
    449                 break;
    450             default:
    451                 rtString = "Unexpected";
    452                 Log.w(LOG_TAG, "Unexpected radioTechnology=" + rt);
    453                 break;
    454         }
    455         return rtString + ":" + rt;
    456     }
    457


这里面google写错了代码,返回网络类型时,连同rt一起返回了,但是上层判断是没有解析判断。所以,倒是方法调用出错。下个版本,google会correct 的。

其它版本上如果这个方法没有问题,那么就是运营商本身就不支持,或者你所使用的手机的制造商修改了这部分代码。我试验了联通2G卡,无效,在室内。试验了移动全球通卡,ok..


你可能感兴趣的:(framework,network,string,google,access,object,制造)