code: @SuppressWarnings("ChainOfInstanceofChecks")
      private CellInfo fromCellLocation(CellLocation cellLocation) {
          try {
              if (cellLocation instanceof GsmCellLocation) {
                  GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
                  CellIdentityGsm identity = CellIdentityGsm.class.getConstructor(int.class, int.class, int.class, int.class)
                          .newInstance(getMcc(), getMnc(), gsmCellLocation.getLac(), gsmCellLocation.getCid());
                  CellSignalStrengthGsm strength = CellSignalStrengthGsm.class.newInstance();
                  CellInfoGsm info = CellInfoGsm.class.newInstance();
                  CellInfoGsm.class.getMethod("setCellIdentity", CellIdentityGsm.class).invoke(info, identity);
                  CellInfoGsm.class.getMethod("setCellSignalStrength", CellSignalStrengthGsm.class).invoke(info, strength);
                  return info;
              }
              if (cellLocation instanceof CdmaCellLocation) {
                  CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
                  CellIdentityCdma identity = CellIdentityCdma.class.getConstructor(int.class, int.class, int.class, int.class, int.class)
                          .newInstance(cdmaCellLocation.getNetworkId(), cdmaCellLocation.getSystemId(), cdmaCellLocation.getBaseStationId(),
                                  cdmaCellLocation.getBaseStationLongitude(), cdmaCellLocation.getBaseStationLatitude());
                  CellSignalStrengthCdma strength = CellSignalStrengthCdma.class.newInstance();
                  CellInfoCdma info = CellInfoCdma.class.newInstance();
                  CellInfoCdma.class.getMethod("setCellIdentity", CellIdentityCdma.class).invoke(info, identity);
                  CellInfoCdma.class.getMethod("setCellSignalStrength", CellSignalStrengthCdma.class).invoke(info, strength);
                  return info;
              }
          } catch (Exception e) {
          }
          return null;
      }
docs: This is to support some broken implementations that do not support {@link TelephonyManager#getAllCellInfo()}