Browse Source

android: trying and failing to avoid OverlayPermissions

Daniel Zlotin 8 years ago
parent
commit
8691fe1e18

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

13
 
13
 
14
 public class ReactDevPermission {
14
 public class ReactDevPermission {
15
 
15
 
16
-    private static boolean hasRequestedPermissions = false;
17
-
18
     public static boolean shouldAskPermission() {
16
     public static boolean shouldAskPermission() {
19
-        return !hasRequestedPermissions && NavigationApplication.instance.isDebug() &&
17
+        return NavigationApplication.instance.isDebug() &&
20
                 Build.VERSION.SDK_INT >= 23 &&
18
                 Build.VERSION.SDK_INT >= 23 &&
21
                 !Settings.canDrawOverlays(NavigationApplication.instance);
19
                 !Settings.canDrawOverlays(NavigationApplication.instance);
22
     }
20
     }
24
     @TargetApi(23)
22
     @TargetApi(23)
25
     public static void askPermission(Context context) {
23
     public static void askPermission(Context context) {
26
         if (shouldAskPermission()) {
24
         if (shouldAskPermission()) {
27
-            hasRequestedPermissions = true;
28
             Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
25
             Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
29
             context.startActivity(serviceIntent);
26
             context.startActivity(serviceIntent);
30
             String msg = "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
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
 package com.reactnativenavigation.utils;
1
 package com.reactnativenavigation.utils;
2
 
2
 
3
 import android.os.Build;
3
 import android.os.Build;
4
+import android.support.v4.view.ViewCompat;
4
 import android.view.View;
5
 import android.view.View;
5
 
6
 
6
 import java.util.concurrent.atomic.AtomicInteger;
7
 import java.util.concurrent.atomic.AtomicInteger;
17
     }
18
     }
18
 
19
 
19
     private static int compatGenerateViewId() {
20
     private static int compatGenerateViewId() {
20
-        while(true) {
21
+        while (true) {
21
             final int result = viewId.get();
22
             final int result = viewId.get();
22
             // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
23
             // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
23
             int newValue = result + 1;
24
             int newValue = result + 1;

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

1
 package com.reactnativenavigation.playground;
1
 package com.reactnativenavigation.playground;
2
 
2
 
3
 import android.provider.Settings;
3
 import android.provider.Settings;
4
-import android.support.annotation.RequiresApi;
5
 import android.support.test.espresso.Espresso;
4
 import android.support.test.espresso.Espresso;
6
 import android.support.test.espresso.IdlingResource;
5
 import android.support.test.espresso.IdlingResource;
7
 import android.support.test.filters.SdkSuppress;
6
 import android.support.test.filters.SdkSuppress;
24
 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
23
 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
25
 import static android.support.test.espresso.matcher.ViewMatchers.withText;
24
 import static android.support.test.espresso.matcher.ViewMatchers.withText;
26
 import static org.assertj.core.api.Java6Assertions.assertThat;
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
 @RunWith(AndroidJUnit4.class)
27
 @RunWith(AndroidJUnit4.class)
31
 @SdkSuppress(minSdkVersion = 23)
28
 @SdkSuppress(minSdkVersion = 23)
32
-@RequiresApi(api = 23)
33
 public class ApplicationLifecycleTest {
29
 public class ApplicationLifecycleTest {
34
 
30
 
35
     @Rule
31
     @Rule
37
         @Override
33
         @Override
38
         protected void afterActivityLaunched() {
34
         protected void afterActivityLaunched() {
39
             super.afterActivityLaunched();
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
         Espresso.registerIdlingResources(new IdlingResource() {
41
         Espresso.registerIdlingResources(new IdlingResource() {
46
             @Override
42
             @Override
47
             public String getName() {
43
             public String getName() {
91
     }
87
     }
92
 
88
 
93
     @Test
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
         launchActivity();
91
         launchActivity();
97
         acceptOverlayPermissionIfNeeded();
92
         acceptOverlayPermissionIfNeeded();
98
         onView(withText("React Native Navigation!")).check(matches(isDisplayed()));
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
     @Test
96
     @Test
109
     public void showsSplashOnStartup() throws Exception {
97
     public void showsSplashOnStartup() throws Exception {
110
         launchActivity();
98
         launchActivity();

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

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