From 96bfcafc97237cb05753f9fe73f434dc42d68020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 28 Jun 2017 11:38:50 +0200 Subject: [PATCH] [Android] Use target API 23 This reverts commit c9a29153ddf55fb9021000696e71b4e4f04b302b. Now that react-native-webrtc supports the permissions system in 23, use it since it provides a more pleasant experience to users. In addition, fix a bug in the previous code: the React Native view must be loaded after we have acquired the permission to draw on top of other apps, otherwise our app may crash while we accept the permission, since React may try to draw. --- android/build.gradle | 2 +- .../org/jitsi/meet/sdk/JitsiMeetActivity.java | 62 ++++++++++++++++--- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 18965d126..d5a82adf6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -30,7 +30,7 @@ ext { compileSdkVersion = 25 buildToolsVersion = "25.0.3" minSdkVersion = 16 - targetSdkVersion = 22 + targetSdkVersion = 23 } // Force the version of the Android build tools we have chosen on all diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java index 9c5b36888..b7234a0a8 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java @@ -17,7 +17,10 @@ package org.jitsi.meet.sdk; import android.content.Intent; +import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.provider.Settings; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; @@ -35,6 +38,13 @@ import java.net.URL; * JKConferenceView static methods. */ public class JitsiMeetActivity extends AppCompatActivity { + /** + * Code for identifying the permission to draw on top of other apps. The + * number is chosen arbitrarily and used to correlate the intent with its + * result. + */ + public static final int OVERLAY_PERMISSION_REQ_CODE = 4242; + /** * Instance of the {@link JitsiMeetView} which this activity will display. */ @@ -64,6 +74,26 @@ public class JitsiMeetActivity extends AppCompatActivity { view.loadURL(url); } + /** + * {@inheritDoc} + */ + @Override + protected void onActivityResult( + int requestCode, + int resultCode, + Intent data) { + if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!Settings.canDrawOverlays(this)) { + // Permission not granted. + return; + } + } + + setupView(); + } + } + /** * {@inheritDoc} */ @@ -82,15 +112,21 @@ public class JitsiMeetActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - view = new JitsiMeetView(this); + // In debug mode React needs permission to write over other apps in + // order to display the warning and error overlays. + if (BuildConfig.DEBUG + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + && !Settings.canDrawOverlays(this)) { + Intent intent + = new Intent( + Settings.ACTION_MANAGE_OVERLAY_PERMISSION, + Uri.parse("package:" + getPackageName())); - // In order to have the desired effect - // JitsiMeetView#setWelcomePageEnabled(boolean) must be invoked before - // JitsiMeetView#loadURL(URL). - view.setWelcomePageEnabled(welcomePageEnabled); - view.loadURL(null); + startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); + return; + } - setContentView(view); + setupView(); } /** @@ -131,6 +167,18 @@ public class JitsiMeetActivity extends AppCompatActivity { JitsiMeetView.onHostResume(this); } + private void setupView() { + view = new JitsiMeetView(this); + + // In order to have the desired effect + // JitsiMeetView#setWelcomePageEnabled(boolean) must be invoked before + // JitsiMeetView#loadURL(URL). + view.setWelcomePageEnabled(welcomePageEnabled); + view.loadURL(null); + + setContentView(view); + } + /** * * @see JitsiMeetView#setWelcomePageEnabled