Browse Source

android: trying and failing to avoid OverlayPermissions

Daniel Zlotin 7 years ago
parent
commit
8691fe1e18

+ 1
- 4
android/app/src/main/java/com/reactnativenavigation/react/ReactDevPermission.java View File

@@ -13,10 +13,8 @@ import com.reactnativenavigation.controllers.NavigationApplication;
13 13
 
14 14
 public class ReactDevPermission {
15 15
 
16
-    private static boolean hasRequestedPermissions = false;
17
-
18 16
     public static boolean shouldAskPermission() {
19
-        return !hasRequestedPermissions && NavigationApplication.instance.isDebug() &&
17
+        return NavigationApplication.instance.isDebug() &&
20 18
                 Build.VERSION.SDK_INT >= 23 &&
21 19
                 !Settings.canDrawOverlays(NavigationApplication.instance);
22 20
     }
@@ -24,7 +22,6 @@ public class ReactDevPermission {
24 22
     @TargetApi(23)
25 23
     public static void askPermission(Context context) {
26 24
         if (shouldAskPermission()) {
27
-            hasRequestedPermissions = true;
28 25
             Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
29 26
             context.startActivity(serviceIntent);
30 27
             String msg = "Overlay permissions needs to be granted in order for react native apps to run in dev mode";

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/utils/ViewIdGenerator.java View File

@@ -1,6 +1,7 @@
1 1
 package com.reactnativenavigation.utils;
2 2
 
3 3
 import android.os.Build;
4
+import android.support.v4.view.ViewCompat;
4 5
 import android.view.View;
5 6
 
6 7
 import java.util.concurrent.atomic.AtomicInteger;
@@ -17,7 +18,7 @@ public class ViewIdGenerator {
17 18
     }
18 19
 
19 20
     private static int compatGenerateViewId() {
20
-        while(true) {
21
+        while (true) {
21 22
             final int result = viewId.get();
22 23
             // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
23 24
             int newValue = result + 1;

+ 3
- 15
playground/android/app/src/androidTest/java/com/reactnativenavigation/playground/ApplicationLifecycleTest.java View File

@@ -1,7 +1,6 @@
1 1
 package com.reactnativenavigation.playground;
2 2
 
3 3
 import android.provider.Settings;
4
-import android.support.annotation.RequiresApi;
5 4
 import android.support.test.espresso.Espresso;
6 5
 import android.support.test.espresso.IdlingResource;
7 6
 import android.support.test.filters.SdkSuppress;
@@ -24,12 +23,9 @@ import static android.support.test.espresso.assertion.ViewAssertions.matches;
24 23
 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
25 24
 import static android.support.test.espresso.matcher.ViewMatchers.withText;
26 25
 import static org.assertj.core.api.Java6Assertions.assertThat;
27
-import static org.junit.Assume.assumeFalse;
28
-import static org.junit.Assume.assumeTrue;
29 26
 
30 27
 @RunWith(AndroidJUnit4.class)
31 28
 @SdkSuppress(minSdkVersion = 23)
32
-@RequiresApi(api = 23)
33 29
 public class ApplicationLifecycleTest {
34 30
 
35 31
     @Rule
@@ -37,11 +33,11 @@ public class ApplicationLifecycleTest {
37 33
         @Override
38 34
         protected void afterActivityLaunched() {
39 35
             super.afterActivityLaunched();
40
-            registerIdlingResource(rule.getActivity());
36
+            registerReactIdlingResource(rule.getActivity());
41 37
         }
42 38
     };
43 39
 
44
-    private void registerIdlingResource(final NavigationActivity activity) {
40
+    private void registerReactIdlingResource(final NavigationActivity activity) {
45 41
         Espresso.registerIdlingResources(new IdlingResource() {
46 42
             @Override
47 43
             public String getName() {
@@ -91,20 +87,12 @@ public class ApplicationLifecycleTest {
91 87
     }
92 88
 
93 89
     @Test
94
-    public void startApp_RequiredOverlayPermissions_LoadsBridge_ThenShowsWelcomeScreen() throws Exception {
95
-        assumeFalse(Settings.canDrawOverlays(getInstrumentation().getContext()));
90
+    public void acceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
96 91
         launchActivity();
97 92
         acceptOverlayPermissionIfNeeded();
98 93
         onView(withText("React Native Navigation!")).check(matches(isDisplayed()));
99 94
     }
100 95
 
101
-    @Test
102
-    public void startApp_NoPermissionRequired_ShowsWelcomeScreen() {
103
-        assumeTrue(Settings.canDrawOverlays(getInstrumentation().getContext()));
104
-        launchActivity();
105
-        onView(withText("React Native Navigation!")).check(matches(isDisplayed()));
106
-    }
107
-
108 96
     @Test
109 97
     public void showsSplashOnStartup() throws Exception {
110 98
         launchActivity();

+ 5
- 0
playground/src/containers/WelcomeScreen.js View File

@@ -19,6 +19,7 @@ class WelcomeScreen extends Component {
19 19
         <Button title="Switch to lifecycle screen" onPress={this.onClickLifecycleScreen} />
20 20
         <Button title="Push" onPress={this.onClickPush} />
21 21
         <Button title="Show Modal" onPress={this.onClickShowModal} />
22
+        <Button title="Show Redbox" onPress={this.onClickShowRedbox} />
22 23
         <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
23 24
       </View>
24 25
     );
@@ -114,6 +115,10 @@ class WelcomeScreen extends Component {
114 115
       }
115 116
     });
116 117
   }
118
+
119
+  onClickShowRedbox() {
120
+    undefined();
121
+  }
117 122
 }
118 123
 
119 124
 export default WelcomeScreen;