Residency is checked by factors like physical presence, management place, domicile etc. The particulars are based on DTAA provisions between the countries involved.