Permalink
Browse files

Don't crash if Window permission isn't granted for dev loading view

Reviewed By: AaaChiuuu

Differential Revision: D5263844

fbshipit-source-id: bf10375ddc43158ce77e09682605068e28f690ef
  • Loading branch information...
ayc1 authored and facebook-github-bot committed Jun 19, 2017
1 parent fa147f0 commit 56969d51fac4a6fd88e8203993b3e4f0c40db799
@@ -9,9 +9,18 @@
package com.facebook.react.devsupport;
import javax.annotation.Nullable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Build;
import android.provider.Settings;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.WindowManager;
@@ -22,11 +31,7 @@
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.ReactConstants;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
import javax.annotation.Nullable;
import static android.Manifest.permission.SYSTEM_ALERT_WINDOW;
/**
* Controller to display loading messages on top of the screen. All methods are thread safe.
@@ -52,7 +57,7 @@ public DevLoadingViewController(Context context) {
}
public void showMessage(final String message, final int color, final int backgroundColor) {
if (!sEnabled) {
if (!sEnabled || !isWindowPermissionGranted()) {
return;
}
@@ -148,4 +153,10 @@ private void setVisible(boolean visible) {
}
mIsVisible = visible;
}
private boolean isWindowPermissionGranted() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
(Settings.canDrawOverlays(mContext) ||
PackageManager.PERMISSION_GRANTED == mContext.checkSelfPermission(SYSTEM_ALERT_WINDOW));
}
}

0 comments on commit 56969d5

Please sign in to comment.