question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Intenet permission" problem

See original GitHub issue

Hi My App run on TV has many crash,as follow:


1 java.lang.SecurityException:Permission denied (missing INTERNET permission?)
--
2 java.net.InetAddress.lookupHostByName(InetAddress.java:451)
3 ......
4 Caused by:
5 android.system.ErrnoException:android_getaddrinfo failed: EACCES (Permission denied)
6 libcore.io.Posix.android_getaddrinfo(Native Method)
7 libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
8 java.net.InetAddress.lookupHostByName(InetAddress.java:438)
9 java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
10 java.net.InetAddress.getAllByName(InetAddress.java:215)
11 okhttp3.Dns$1.lookup(Dns.java:39)
12 okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:171)
13 okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:137)
14 okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:82)
15 okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:171)
16 okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
17 okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
18 okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
19 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
20 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
21 okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
22 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
23 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
24 okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
25 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
26 okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
27 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
28 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
29 okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
30 okhttp3.RealCall$AsyncCall.execute(RealCall.java:135)
31 okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
32 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
33 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
34 java.lang.Thread.run(Thread.java:818)

I know this issue has reported by other developer,but don`t get a good answer。There are some clue :

  • all crash happened at background
  • at crash time , has Network ,has the net permission,but can’t do net operation。
  • when crash happened,I can catch the crash, when call Call.execute() ,but can’t catch when call Call.enqueue() I suggest that, at asynchronous call mode(Call.enqueue()) , to callback Callback.onFailure when this exception happend。

My English is poor , may be don’t describe clear.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
wujingchaocommented, Jul 25, 2017

I think you can write a Application Interceptor to catch java.lang.Throwable or java.lang.RuntimeException that you want. Wrapping the exception as a IOException and throw out, your Callback#onFailure method will be invoked. You can also get the wrapped exception in the method parameter.

ref : https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/RealCall.java#L151

0reactions
linyongshengcommented, Jul 25, 2017

I put the code here, may be help other one.

    public static OkHttpClient getHttpClient() {
        if (httpClient == null) {
            synchronized (TvBase.class) {
                if (httpClient == null) {
                    OkHttpClient.Builder builder = new OkHttpClient.Builder();
                    builder.addInterceptor(new OkHttpExceptionInterceptor());
                    builder.connectTimeout(30, TimeUnit.SECONDS);
                    builder.writeTimeout(30, TimeUnit.SECONDS);
                    builder.readTimeout(30, TimeUnit.SECONDS);
                    httpClient = builder.build();
                    httpClient.dispatcher().setMaxRequestsPerHost(30);
                }
            }
        }
        return httpClient;
    }

    /** okhttp AsyncCall only catch the IOException, other exception will occur crash,this Interceptor impl can transform all exception to IOException */
    private static class OkHttpExceptionInterceptor implements Interceptor {

        @Override
        public Response intercept(Chain chain) throws IOException {
            try {
                return chain.proceed(chain.request());
            } catch (Throwable e) {
                if (e instanceof IOException) {
                    throw e;
                } else {
                    throw new IOException(e);
                }
            }
        }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Studio Internet Permission error - Stack Overflow
I have used the internet permission in my manifest I have placed it above the application and below the application but no matter...
Read more >
Cannot enable "INTERNET" permission on AndroidManifest ...
Right click on the project -> Options. On the left panel, click on Build->Android Application. Check the [x] INTERNET checkbox to be enabled....
Read more >
Solved: Versa message "This app requires the 'internet' pe...
"This app requires the "internet" permission to be granted". Does anyone know how to fix this? I'm using a Samsung S8. Thanks. Answered!...
Read more >
[Solved] Add Internet Permission in AndroidManifest.xml in ...
Solution. In order to access the internet in your app, add the below line in your AndroidManifest.xml that will solve the internet permission....
Read more >
APK internet Permission is missing -error - Appium Studio
Hi, I am trying to import an android apk file into Appium Studio/import app for Android device into Appium Studio. I click the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found