Log error when sonar is missing required permissions
Summary: Sonar won't work without the INTERNET permission, so it can talk TCP to the desktop, on localhost. Also, for genymotion, we use the IP address, so we need ACCESS_WIFI_STATE. Reviewed By: passy Differential Revision: D8855239 fbshipit-source-id: 35d0b0bba91daeba35a5de90e5ef87e89ac6bb51
This commit is contained in:
committed by
Facebook Github Bot
parent
d260afa300
commit
0729ce6959
@@ -8,18 +8,24 @@
|
||||
package com.facebook.sonar.android;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
import com.facebook.sonar.core.SonarClient;
|
||||
|
||||
public final class AndroidSonarClient {
|
||||
private static boolean sIsInitialized = false;
|
||||
private static SonarThread sSonarThread;
|
||||
private static SonarThread sConnectionThread;
|
||||
private static final String[] REQUIRED_PERMISSIONS =
|
||||
new String[] {"android.permission.INTERNET", "android.permission.ACCESS_WIFI_STATE"};
|
||||
|
||||
public static synchronized SonarClient getInstance(Context context) {
|
||||
if (!sIsInitialized) {
|
||||
checkRequiredPermissions(context);
|
||||
sSonarThread = new SonarThread("SonarEventBaseThread");
|
||||
sSonarThread.start();
|
||||
sConnectionThread = new SonarThread("SonarConnectionThread");
|
||||
@@ -42,6 +48,16 @@ public final class AndroidSonarClient {
|
||||
return SonarClientImpl.getInstance();
|
||||
}
|
||||
|
||||
static void checkRequiredPermissions(Context context) {
|
||||
// Don't terminate for compatibility reasons. Not all apps have ACCESS_WIFI_STATE permission.
|
||||
for (String permission : REQUIRED_PERMISSIONS) {
|
||||
if (ContextCompat.checkSelfPermission(context, permission)
|
||||
== PackageManager.PERMISSION_DENIED) {
|
||||
Log.e("Sonar", String.format("App needs permission \"%s\" to work with sonar", permission));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isRunningOnGenymotion() {
|
||||
return Build.FINGERPRINT.contains("vbox");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user