Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix-kujaku-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Jan 14, 2025
2 parents 338fbc6 + 8c1aae0 commit bef023b
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 26 deletions.
4 changes: 1 addition & 3 deletions configs.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ ext {
mapboxAnnotationPluginVersion = "0.9.0"
mapboxSdkVersion = "9.7.1"
mapboxSdkTurfVersion = "7.2.0"
robolectricShadowsMultidexVersion = "4.13"
robolectricVersion = "4.13"
supportVersion = "1.0.0"
volleyVersion = "1.2.1"
Expand All @@ -123,13 +122,12 @@ ext {
mapboxSDKTurf = "com.mapbox.mapboxsdk:mapbox-sdk-turf:$mapboxSdkTurfVersion"
mapboxAnnotationPlugin = "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:$mapboxAnnotationPluginVersion"
robolectric = "org.robolectric:robolectric:$robolectricVersion"
robolectricShadowsMultidex = "org.robolectric:shadows-multidex:$robolectricShadowsMultidexVersion"
}

ext.mapboxDependencies = { instance, configuration ->

configuration.implementation("com.mapbox.maps:android:$mapboxSdkVersion") {
transitive = true;
transitive = true
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-fragment'
Expand Down
20 changes: 8 additions & 12 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
apply plugin: 'realm-android'
apply plugin: 'maven-publish'

version '0.10.6-2-SNAPSHOT'
version '0.10.8-SNAPSHOT'

project.version = this.version

Expand Down Expand Up @@ -42,7 +42,6 @@ android {
versionCode 1
versionName this.version
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
multiDexEnabled true
}

buildTypes {
Expand All @@ -57,11 +56,11 @@ android {
properties.containsKey("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");
println("One of the required config variables is not set in your local.properties")
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"sample_key\""
}
} else {
println("local.properties does not exist");
println("local.properties does not exist")
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"sample_key\""
}
}
Expand All @@ -77,11 +76,11 @@ android {
properties.containsKey("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");
println("One of the required config variables is not set in your local.properties")
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"sample_key\""
}
} else {
println("local.properties does not exist");
println("local.properties does not exist")
buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", "\"sample_key\""

}
Expand All @@ -107,7 +106,7 @@ android {
dependencies { configuration ->
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation (mapboxSDK) {
transitive = true;
transitive = true
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-fragment'
Expand All @@ -120,9 +119,9 @@ dependencies { configuration ->
implementation mapboxAnnotationPlugin

// Comment the line below when creating releases - The line is for development of the library & utils
//implementation (project(":utils")) {
implementation (project(":utils")) {
// Uncomment the line below when creating releases
implementation('io.ona.kujaku:utils:0.10.6-SNAPSHOT') {
implementation('io.ona.kujaku:utils:0.10.8-SNAPSHOT') {
transitive = true
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-sdk'
exclude group: 'com.android.support', module: 'support-v4'
Expand All @@ -134,8 +133,6 @@ dependencies { configuration ->
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.1'
implementation 'com.jakewharton.timber:timber:5.0.1'

implementation 'androidx.multidex:multidex:2.0.1'

customDependencies(this, configuration)
appPermissionsDependencies(configuration)
infoWindowDependencies(this, configuration)
Expand All @@ -147,7 +144,6 @@ private static void testDependencies(instance, configuration) {
configuration.testImplementation instance.junit

configuration.testImplementation instance.robolectric
configuration.testImplementation instance.robolectricShadowsMultidex

configuration.testImplementation 'org.mockito:mockito-inline:5.2.0'

Expand Down
2 changes: 1 addition & 1 deletion library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Expand Down
14 changes: 12 additions & 2 deletions library/src/main/java/io/ona/kujaku/helpers/PermissionsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@
import com.karumi.dexter.Dexter;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;

import java.util.ArrayList;
import java.util.List;

import io.ona.kujaku.utils.KujakuMultiplePermissionListener;
import timber.log.Timber;

public class PermissionsHelper {

public static void checkPermissions(String TAG, Context context) {
if (context instanceof Activity) {
List<String> permissions = new ArrayList<>();
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S) {
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
final Activity activity = (Activity) context;

MultiplePermissionsListener dialogMultiplePermissionListener = new KujakuMultiplePermissionListener(activity);

Dexter.withActivity(activity)
.withPermissions(Manifest.permission.ACCESS_FINE_LOCATION, (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) ? Manifest.permission.MANAGE_EXTERNAL_STORAGE : Manifest.permission.WRITE_EXTERNAL_STORAGE)
.withPermissions(permissions)
.withListener(dialogMultiplePermissionListener)
.check();

} else {
Log.wtf(TAG, "KujakuMapView was not started in an activity!! This is very bad or it is being used in tests. We are going to ignore the permissions check! Good luck");
Timber.tag(TAG).wtf("KujakuMapView was not started in an activity!! This is very bad or it is being used in tests. We are going to ignore the permissions check! Good luck");
}
}
}
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);
}
}
7 changes: 2 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ android {
versionCode getMasterCommitCount()
versionName getVersionName()

multiDexEnabled true
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

Expand Down Expand Up @@ -95,8 +94,6 @@ dependencies { configuration ->
exclude group: "com.android.support", module: "appcompat-v7"
}

implementation 'androidx.multidex:multidex:2.0.1'

testImplementation junit
testImplementation robolectric
}
Expand All @@ -111,15 +108,15 @@ private static void libraryModuleDevelopment(instance, configuration) {
}

configuration.implementation(instance.project(":utils")) {
transitive = true;
transitive = true
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-sdk'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'org.jacoco'
}

configuration.implementation(instance.mapboxSDK) {
transitive = true;
transitive = true
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-fragment'
Expand Down
5 changes: 3 additions & 2 deletions sample/src/main/java/io/ona/kujaku/sample/MyApplication.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package io.ona.kujaku.sample;

import androidx.multidex.MultiDexApplication;
import io.ona.kujaku.KujakuLibrary;
import io.ona.kujaku.sample.repository.KujakuRepository;
import io.ona.kujaku.sample.repository.PointsRepository;
import timber.log.Timber;

import static io.ona.kujaku.sample.util.Constants.DATABASE_NAME;

public class MyApplication extends MultiDexApplication {
import android.app.Application;

public class MyApplication extends Application {

private static final String TAG = MyApplication.class.getName();

Expand Down
2 changes: 1 addition & 1 deletion utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'

version '0.10.6-SNAPSHOT'
version '0.10.8-SNAPSHOT'
project.version = this.version


Expand Down

0 comments on commit bef023b

Please sign in to comment.