/// <summary>
        /// Wrapper for VerifyLocation. Verification of location based on the device location and the cell tower location
        /// </summary>
        /// <returns>bool Task</returns>
        public async Task <bool> VerifyLocation(string dmeHost = null, uint dmePort = 0)
        {
            latestVerifyLocationStatus = false;

            if (!latestRegisterStatus)
            {
                Debug.LogError("MobiledgeX: Last RegisterClient was unsuccessful. Call RegisterClient again before VerifyLocation");
                return(false);
            }

            await UpdateLocationAndCarrierInfo();

            VerifyLocationRequest req = matchingEngine.CreateVerifyLocationRequest(location, carrierName);
            VerifyLocationReply   reply;

            if (dmeHost == null || dmePort == 0)
            {
                reply = await matchingEngine.VerifyLocation(req);
            }
            else
            {
                reply = await matchingEngine.VerifyLocation(dmeHost, dmePort, req);
            }

            // The return is not binary, but one can decide the particular app's policy
            // on pass or failing the location check. Not being verified or the country
            // not matching at all is on such policy decision:
            // GPS and Tower Status:
            switch (reply.gps_location_status)
            {
            case VerifyLocationReply.GPSLocationStatus.LOC_ROAMING_COUNTRY_MISMATCH:
            case VerifyLocationReply.GPSLocationStatus.LOC_ERROR_UNAUTHORIZED:
            case VerifyLocationReply.GPSLocationStatus.LOC_ERROR_OTHER:
            case VerifyLocationReply.GPSLocationStatus.LOC_UNKNOWN:
                return(false);
            }

            switch (reply.tower_status)
            {
            case VerifyLocationReply.TowerStatus.NOT_CONNECTED_TO_SPECIFIED_TOWER:
            case VerifyLocationReply.TowerStatus.TOWER_UNKNOWN:
                return(false);
            }

            // Distance? A negative value means no verification was done.
            if (reply.gps_location_accuracy_km < 0f)
            {
                return(false);
            }

            // A per app policy decision might be 0.5 km, or 25km, or 100km:
            if (reply.gps_location_accuracy_km < 100f)
            {
                return(true);
            }
            // Too far for this app.
            return(false);
        }
Пример #2
0
    public async Task <bool> VerifyLocation()
    {
        Loc loc = await GetLocationFromDevice();

        // If MEX is reachable on your SIM card:
        string aCarrierName = GetCarrierName();
        string eCarrierName;

        if (me.useOnlyWifi) // There's no host (PC, UnityEditor, etc.)...
        {
            eCarrierName = carrierName;
        }
        else
        {
            eCarrierName = aCarrierName;
        }

        VerifyLocationRequest req = me.CreateVerifyLocationRequest(eCarrierName, loc, cellID, tags);

        VerifyLocationReply reply = await me.VerifyLocation(req);

        // The return is not binary, but one can decide the particular app's policy
        // on pass or failing the location check. Not being verified or the country
        // not matching at all is on such policy decision:

        // GPS and Tower Status:
        switch (reply.gps_location_status)
        {
        case VerifyLocationReply.GPSLocationStatus.LOC_ROAMING_COUNTRY_MISMATCH:
        case VerifyLocationReply.GPSLocationStatus.LOC_ERROR_UNAUTHORIZED:
        case VerifyLocationReply.GPSLocationStatus.LOC_ERROR_OTHER:
        case VerifyLocationReply.GPSLocationStatus.LOC_UNKNOWN:
            return(false);
        }

        switch (reply.tower_status)
        {
        case VerifyLocationReply.TowerStatus.NOT_CONNECTED_TO_SPECIFIED_TOWER:
        case VerifyLocationReply.TowerStatus.TOWER_UNKNOWN:
            return(false);
        }

        // Distance? A negative value means no verification was done.
        if (reply.gps_location_accuracy_km < 0f)
        {
            return(false);
        }

        // A per app policy decision might be 0.5 km, or 25km, or 100km:
        if (reply.gps_location_accuracy_km < 100f)
        {
            return(true);
        }

        // Too far for this app.
        return(false);
    }