Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: LocationManager provider #174

Merged
merged 9 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdk 30
compileSdk 31

defaultConfig {
minSdkVersion 21
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 30
targetSdkVersion 31
Dor-bl marked this conversation as resolved.
Show resolved Hide resolved
versionCode 85
versionName "5.9.2"
applicationId "io.appium.settings"
Expand Down
62 changes: 48 additions & 14 deletions app/src/main/java/io/appium/settings/LocationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package io.appium.settings;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.location.provider.ProviderProperties;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
Expand Down Expand Up @@ -182,25 +184,57 @@ private List<MockLocationProvider> createMockProviders(LocationManager locationM
return mockProviders;
}

/**
* Creates a mock location provider based on the given provider name.
*
* @param locationManager the location manager
* @param providerName the name of the provider
* @return a MockLocationProvider if the provider exists, otherwise null
*/
@Nullable
private MockLocationProvider createLocationManagerMockProvider(LocationManager locationManager, String providerName) {
if (providerName == null) {
return null;
}
// API level check for existence of provider properties
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { // API level 31 and above
ProviderProperties providerProperties = locationManager.getProviderProperties(providerName);
if (providerProperties == null) {
return null;
}
return new LocationManagerProvider(
locationManager,
providerName,
providerProperties.hasNetworkRequirement(),
providerProperties.hasSatelliteRequirement(),
providerProperties.hasCellRequirement(),
providerProperties.hasMonetaryCost(),
providerProperties.hasAltitudeSupport(),
providerProperties.hasSpeedSupport(),
providerProperties.hasBearingSupport(),
providerProperties.getPowerUsage(),
providerProperties.getAccuracy()
);
}
LocationProvider provider = locationManager.getProvider(providerName);
return provider == null ? null : createLocationManagerMockProvider(locationManager, provider);
if (provider == null) {
return null;
}
return new LocationManagerProvider(
locationManager,
provider.getName(),
provider.requiresNetwork(),
provider.requiresSatellite(),
provider.requiresCell(),
provider.hasMonetaryCost(),
provider.supportsAltitude(),
provider.supportsSpeed(),
provider.supportsBearing(),
provider.getPowerRequirement(),
provider.getAccuracy()
);
}

private MockLocationProvider createLocationManagerMockProvider(LocationManager locationManager, LocationProvider locationProvider) {
return new LocationManagerProvider(locationManager,
locationProvider.getName(),
locationProvider.requiresNetwork(),
locationProvider.requiresSatellite(),
locationProvider.requiresCell(),
locationProvider.hasMonetaryCost(),
locationProvider.supportsAltitude(),
locationProvider.supportsSpeed(),
locationProvider.supportsBearing(),
locationProvider.getPowerRequirement(),
locationProvider.getAccuracy());
}

private FusedLocationProvider createFusedLocationProvider() {
FusedLocationProviderClient locationProviderClient = LocationServices.getFusedLocationProviderClient(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.appium.settings.recorder;

import android.annotation.SuppressLint;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.media.AudioAttributes;
Expand Down Expand Up @@ -152,6 +153,7 @@ private MediaCodec initAudioCodec(int sampleRate) throws IOException {
}

@RequiresApi(api = Build.VERSION_CODES.Q)
@SuppressLint("MissingPermission")
private AudioRecord initAudioRecord(MediaProjection mediaProjection, int sampleRate) {
int channelConfig = AudioFormat.CHANNEL_IN_MONO;
int minBufferSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig,
Expand Down
Loading