Android GPRS network communication delay when receving call

239 views Asked by At

I've written an Android code that tries to access a server over the network upon an incoming call.

Network access is executed once an incoming call is received using a BroadcastReceiver with the intent-filer of READ_PHONE_STATE.

Data communication is performed over GPRS.

Using the logcat I've noticed that the data retrieval time from the network has large distribution, ranging from 1sec to 15sec.

Here is the code for sending a HTTP request and waiting for server response

        urlConnection = (HttpURLConnection) url.openConnection();
        Log.i("TIMINGS", "Connected to server.");
        jsonobj.put("id", id);
        String requestContent = jsonobj.toString();
        urlConnection.setDoOutput(true); // Will make a POST HTTP request
        urlConnection.setFixedLengthStreamingMode(requestContent.length());
        urlConnection.setRequestProperty("content-type", "application/json");
        urlConnection.setRequestProperty("Connection", "close");
        System.setProperty("http.keepAlive", "false");
        urlConnection.setDefaultUseCaches(false);

        Log.i("TIMINGS", "Sending request...");
        // Write the JSON string to the POST request content
        DataOutputStream out = new DataOutputStream(urlConnection.getOutputStream());
        out.writeBytes(requestContent);
        out.flush();
        out.close();
        Log.i("TIMINGS", "Request sent.");

        Log.i("DEBUG", "Connect response code: " + urlConnection.getResponseCode());

        // Get the output from the server
        Log.i("TIMINGS", "Extracting data from response...");
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        byte[] bytes = getBytesFromInputStream(in);
        if (bytes == null) {
            return null;
        }
        in.close();
        Log.i("TIMINGS", "Response extracted");
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        if (urlConnection != null) {
            Log.i("TIMINGS", "Disconnected.");
            urlConnection.disconnect();
        }
    }

When network access is performed via WIFI, results are consistently fast.

Has anyone encountered similar results? Can something be done to achieve consistent fast network access via GPRS when an incoming call is received?

Thanks,

1

There are 1 answers

0
user2314105 On

Latency is highly variable on a mobile network primarily due to the science, maths and engineering of capturing and recovering errors on a very poor transmission path (the atmosphere) AND managing the mobililty aspect.

Your device must request available resources from the network and wait until they are granted. On GSM networks voice traffic has priority, so this can take some time (yes 15 seconds is ok) - devices are told to queue the data.

On 3G networks the device is told every 4 milliseconds about the quality of the signal received at the tower. Your device must change the coding rate in accordance with the quality reported. The amount of redundant coding in the transmission is set so that your data can be recovered with a high degree of reliability. The constant variability in the coding rate impacts throughput and latency.

GSM-GPRS degrades like a brick wall, 3G-GPRS (modern) is a shared channel so degrades gracefully

Due to the poor transmission path for WiFi (impacted by water in atmosphere) - it can only exist across the room, so the scope for the variability can be much tighter without sudden degradation.