Skip to content

Commit

Permalink
Don't crash if Window permission isn't granted for dev loading view
Browse files Browse the repository at this point in the history
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 56969d5
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
}

Expand Down Expand Up @@ -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.