Skip to content

Commit

Permalink
Merge branch 'Fix-permission-prompt' of github.com:onaio/kujaku into …
Browse files Browse the repository at this point in the history
…Fix-permission-prompt
  • Loading branch information
dubdabasoduba committed Oct 14, 2024
2 parents b463265 + 6ab5617 commit 77a43b2
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
sudo udevadm trigger --name-match=kvm
- name: Create local.properties file
run: touch local.properties && echo "mapbox.repo.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties
run: touch local.properties && echo "mapbox.sdk.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties

- name: Print Java version
run: java -version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
java-version: 17

- name: Create local.properties file
run: touch local.properties && echo "mapbox.repo.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties
run: touch local.properties && echo "mapbox.sdk.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties

- name: Print Java version
run: java -version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/utils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
java-version: 17

- name: Create local.properties file
run: touch local.properties && echo "mapbox.repo.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties
run: touch local.properties && echo "mapbox.sdk.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties

- name: Print Java version
run: java -version
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ allprojects {
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = localProperties['mapbox.repo.token'] ?: ""
password = localProperties['mapbox.sdk.token'] ?: ""
}
}
maven{url "https://oss.sonatype.org/content/repositories/snapshots"}
Expand Down
2 changes: 1 addition & 1 deletion configs.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ext.getVersionName = getVersionName

// LOAD PROPERTIES FILE
Properties properties = new Properties()
String[] propertyKeys = ["cgr.username", "cgr.password", "cgr.url", "mapbox.sdk.token", "mapbox.repo.token"]
String[] propertyKeys = ["cgr.username", "cgr.password", "cgr.url", "mapbox.sdk.token"]


if (project.rootProject.file("local.properties").exists()) {
Expand Down
9 changes: 7 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ android {
properties.load(project.rootProject.file("local.properties").newDataInputStream())
if (properties != null &&
properties.containsKey("mapbox.sdk.token")) {
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", localProperties["mapbox.sdk.token"]
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"" + localProperties["mapbox.sdk.token"] + "\""
} else {
println("One of the required config variables is not set in your local.properties");
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"sample_key\""
Expand All @@ -75,7 +75,7 @@ android {
properties.load(project.rootProject.file("local.properties").newDataInputStream())
if (properties != null &&
properties.containsKey("mapbox.sdk.token")) {
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", localProperties["mapbox.sdk.token"]
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"" + localProperties["mapbox.sdk.token"] + "\""
} else {
println("One of the required config variables is not set in your local.properties");
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"sample_key\""
Expand Down Expand Up @@ -136,6 +136,11 @@ dependencies { configuration ->

implementation 'androidx.multidex:multidex:2.0.1'

androidTestImplementation 'org.powermock:powermock-module-junit4:2.0.9'
androidTestImplementation 'org.powermock:powermock-api-mockito2:2.0.9'
androidTestImplementation 'org.mockito:mockito-core:5.12.0'
androidTestImplementation 'org.robolectric:robolectric:4.13'

customDependencies(this, configuration)
appPermissionsDependencies(configuration)
infoWindowDependencies(this, configuration)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.ona.kujaku.helpers;

import static org.junit.Assert.assertFalse;

import android.app.Activity;
import android.content.Context;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import com.karumi.dexter.MultiplePermissionsReport;
import io.ona.kujaku.utils.KujakuMultiplePermissionListener;

@RunWith(RobolectricTestRunner.class)
public class PermissionsHelperTest {

@Mock
Context mockContext;

@Before
public void setUp() {
MockitoAnnotations.openMocks(this);
// Use a real context
mockContext = Robolectric.setupActivity(Activity.class).getApplicationContext();
}

@Test
public void testOnPermissionsCheckedWhenAnyPermissionPermanentlyDenied() {
MultiplePermissionsReport report = Mockito.mock(MultiplePermissionsReport.class);
Mockito.when(report.isAnyPermissionPermanentlyDenied()).thenReturn(true);
Mockito.when(report.areAllPermissionsGranted()).thenReturn(false);
KujakuMultiplePermissionListener listener = new KujakuMultiplePermissionListener(mockContext);
listener.onPermissionsChecked(report);

// Check that the dialog was created with the expected properties
Mockito.verify(report).isAnyPermissionPermanentlyDenied();
}

@Test
public void testOnPermissionsCheckedWhenAnyPermissionNotPermanentlyDenied() {
MultiplePermissionsReport report = Mockito.mock(MultiplePermissionsReport.class);
Mockito.when(report.isAnyPermissionPermanentlyDenied()).thenReturn(false);
Mockito.when(report.areAllPermissionsGranted()).thenReturn(false);
KujakuMultiplePermissionListener listener = new KujakuMultiplePermissionListener(mockContext);
listener.onPermissionsChecked(report);

boolean result = report.isAnyPermissionPermanentlyDenied();

// Use the result in your assertions or further logic
assertFalse(result);
}
}
4 changes: 2 additions & 2 deletions sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Use this sample application to view Kujaku's features. Add the following lines i
`../local.properties` file before compiling this module:

```
mapbox.repo.token="[YOUR MAPBOX REPO ACCESS TOKEN]"
mapbox.sdk.token="[YOUR MAPBOX REPO ACCESS TOKEN]"
mapbox.sdk.token=[YOUR MAPBOX SDK TOKEN]
cgr.username="[YOUR_CGR_USERNAME_WITHOUT_BRACKETS]"
cgr.password="[YOUR_CGR_PASSWORD_WITHOUT_BRACKETS]"
cgr.url="[CGR_URL_WITHOUT_BRACKETS]"
```
If you don't have a Mapbox account, [sign up](https://www.mapbox.com/signup/), and then navigate to your [Account](https://www.mapbox.com/account/) page. Copy your default public token to your clipboard then use it as `[YOUR MAPBOX SDK TOKEN]` above. Generate another token, a secret access token, that gives you access to `Downloads:Read` scope. This allows you to access the Mapbox repository with the dependencies

**NB: The `mapbox.sdk.token` has double quotation marks around the value while the `mapbox.repo.token` does not have double quotation marks around the value.**
**NB: The `mapbox.sdk.token` has double quotation marks around the value while the `mapbox.sdk.token` does not have double quotation marks around the value.**
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", localProperties["mapbox.sdk.token"]
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"" + localProperties["mapbox.sdk.token"] + "\""
buildConfigField "String", "CGR_USERNAME", localProperties["cgr.username"]
buildConfigField "String", "CGR_PASSWORD", localProperties["cgr.password"]
buildConfigField "String", "CGR_URL", localProperties["cgr.url"]
Expand All @@ -47,7 +47,7 @@ android {
debug {
// See bug https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/issues/183
testCoverageEnabled true
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", localProperties["mapbox.sdk.token"]
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"" + localProperties["mapbox.sdk.token"] + "\""
buildConfigField "String", "CGR_USERNAME", localProperties["cgr.username"]
buildConfigField "String", "CGR_PASSWORD", localProperties["cgr.password"]
buildConfigField "String", "CGR_URL", localProperties["cgr.url"]
Expand Down

0 comments on commit 77a43b2

Please sign in to comment.