- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1180 lines
54 KiB
Java
1180 lines
54 KiB
Java
package androidx.core.location;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.location.GnssMeasurementsEvent;
|
|
import android.location.GnssStatus;
|
|
import android.location.GpsStatus;
|
|
import android.location.Location;
|
|
import android.location.LocationListener;
|
|
import android.location.LocationManager;
|
|
import android.location.LocationRequest;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.CancellationSignal;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.SystemClock;
|
|
import androidx.annotation.GuardedBy;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.annotation.RequiresPermission;
|
|
import androidx.collection.SimpleArrayMap;
|
|
import androidx.core.location.GnssStatusCompat;
|
|
import androidx.core.location.LocationManagerCompat;
|
|
import androidx.core.os.CancellationSignal;
|
|
import androidx.core.os.ExecutorCompat;
|
|
import androidx.core.util.Consumer;
|
|
import androidx.core.util.ObjectsCompat;
|
|
import androidx.core.util.Preconditions;
|
|
import java.lang.ref.WeakReference;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.WeakHashMap;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.RejectedExecutionException;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class LocationManagerCompat {
|
|
private static final long GET_CURRENT_LOCATION_TIMEOUT_MS = 30000;
|
|
private static final long MAX_CURRENT_LOCATION_AGE_MS = 10000;
|
|
private static final long PRE_N_LOOPER_TIMEOUT_S = 5;
|
|
private static Field sContextField;
|
|
private static Method sGnssRequestBuilderBuildMethod;
|
|
private static Class<?> sGnssRequestBuilderClass;
|
|
|
|
@GuardedBy("sLocationListeners")
|
|
static final WeakHashMap<LocationListenerKey, WeakReference<LocationListenerTransport>> sLocationListeners = new WeakHashMap<>();
|
|
private static Method sRegisterGnssMeasurementsCallbackMethod;
|
|
|
|
public static boolean isLocationEnabled(@NonNull LocationManager locationManager) {
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
return Api28Impl.isLocationEnabled(locationManager);
|
|
}
|
|
return locationManager.isProviderEnabled("network") || locationManager.isProviderEnabled("gps");
|
|
}
|
|
|
|
public static boolean hasProvider(@NonNull LocationManager locationManager, @NonNull String str) {
|
|
if (Build.VERSION.SDK_INT >= 31) {
|
|
return Api31Impl.hasProvider(locationManager, str);
|
|
}
|
|
if (locationManager.getAllProviders().contains(str)) {
|
|
return true;
|
|
}
|
|
try {
|
|
return locationManager.getProvider(str) != null;
|
|
} catch (SecurityException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
@Deprecated
|
|
public static void getCurrentLocation(@NonNull LocationManager locationManager, @NonNull String str, @Nullable CancellationSignal cancellationSignal, @NonNull Executor executor, @NonNull Consumer<Location> consumer) {
|
|
getCurrentLocation(locationManager, str, cancellationSignal != null ? (android.os.CancellationSignal) cancellationSignal.getCancellationSignalObject() : null, executor, consumer);
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public static void getCurrentLocation(@NonNull LocationManager locationManager, @NonNull String str, @Nullable android.os.CancellationSignal cancellationSignal, @NonNull Executor executor, @NonNull final Consumer<Location> consumer) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
Api30Impl.getCurrentLocation(locationManager, str, cancellationSignal, executor, consumer);
|
|
return;
|
|
}
|
|
if (cancellationSignal != null) {
|
|
cancellationSignal.throwIfCanceled();
|
|
}
|
|
final Location lastKnownLocation = locationManager.getLastKnownLocation(str);
|
|
if (lastKnownLocation != null && SystemClock.elapsedRealtime() - LocationCompat.getElapsedRealtimeMillis(lastKnownLocation) < 10000) {
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
Consumer.this.accept(lastKnownLocation);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
final CancellableLocationListener cancellableLocationListener = new CancellableLocationListener(locationManager, executor, consumer);
|
|
locationManager.requestLocationUpdates(str, 0L, 0.0f, cancellableLocationListener, Looper.getMainLooper());
|
|
if (cancellationSignal != null) {
|
|
cancellationSignal.setOnCancelListener(new CancellationSignal.OnCancelListener() { // from class: androidx.core.location.LocationManagerCompat$$ExternalSyntheticLambda1
|
|
@Override // android.os.CancellationSignal.OnCancelListener
|
|
public final void onCancel() {
|
|
LocationManagerCompat.CancellableLocationListener.this.cancel();
|
|
}
|
|
});
|
|
}
|
|
cancellableLocationListener.startTimeout(30000L);
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public static void requestLocationUpdates(@NonNull LocationManager locationManager, @NonNull String str, @NonNull LocationRequestCompat locationRequestCompat, @NonNull Executor executor, @NonNull LocationListenerCompat locationListenerCompat) {
|
|
int i = Build.VERSION.SDK_INT;
|
|
if (i >= 31) {
|
|
Api31Impl.requestLocationUpdates(locationManager, str, locationRequestCompat.toLocationRequest(), executor, locationListenerCompat);
|
|
return;
|
|
}
|
|
if (i < 30 || !Api30Impl.tryRequestLocationUpdates(locationManager, str, locationRequestCompat, executor, locationListenerCompat)) {
|
|
LocationListenerTransport locationListenerTransport = new LocationListenerTransport(new LocationListenerKey(str, locationListenerCompat), executor);
|
|
if (Api19Impl.tryRequestLocationUpdates(locationManager, str, locationRequestCompat, locationListenerTransport)) {
|
|
return;
|
|
}
|
|
synchronized (sLocationListeners) {
|
|
locationManager.requestLocationUpdates(str, locationRequestCompat.getIntervalMillis(), locationRequestCompat.getMinUpdateDistanceMeters(), locationListenerTransport, Looper.getMainLooper());
|
|
registerLocationListenerTransport(locationManager, locationListenerTransport);
|
|
}
|
|
}
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
@GuardedBy("sLocationListeners")
|
|
public static void registerLocationListenerTransport(LocationManager locationManager, LocationListenerTransport locationListenerTransport) {
|
|
WeakReference<LocationListenerTransport> put = sLocationListeners.put(locationListenerTransport.getKey(), new WeakReference<>(locationListenerTransport));
|
|
LocationListenerTransport locationListenerTransport2 = put != null ? put.get() : null;
|
|
if (locationListenerTransport2 != null) {
|
|
locationListenerTransport2.unregister();
|
|
locationManager.removeUpdates(locationListenerTransport2);
|
|
}
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public static void requestLocationUpdates(@NonNull LocationManager locationManager, @NonNull String str, @NonNull LocationRequestCompat locationRequestCompat, @NonNull LocationListenerCompat locationListenerCompat, @NonNull Looper looper) {
|
|
if (Build.VERSION.SDK_INT >= 31) {
|
|
Api31Impl.requestLocationUpdates(locationManager, str, locationRequestCompat.toLocationRequest(), ExecutorCompat.create(new Handler(looper)), locationListenerCompat);
|
|
} else {
|
|
if (Api19Impl.tryRequestLocationUpdates(locationManager, str, locationRequestCompat, locationListenerCompat, looper)) {
|
|
return;
|
|
}
|
|
locationManager.requestLocationUpdates(str, locationRequestCompat.getIntervalMillis(), locationRequestCompat.getMinUpdateDistanceMeters(), locationListenerCompat, looper);
|
|
}
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public static void removeUpdates(@NonNull LocationManager locationManager, @NonNull LocationListenerCompat locationListenerCompat) {
|
|
WeakHashMap<LocationListenerKey, WeakReference<LocationListenerTransport>> weakHashMap = sLocationListeners;
|
|
synchronized (weakHashMap) {
|
|
try {
|
|
Iterator<WeakReference<LocationListenerTransport>> it = weakHashMap.values().iterator();
|
|
ArrayList arrayList = null;
|
|
while (it.hasNext()) {
|
|
LocationListenerTransport locationListenerTransport = it.next().get();
|
|
if (locationListenerTransport != null) {
|
|
LocationListenerKey key = locationListenerTransport.getKey();
|
|
if (key.mListener == locationListenerCompat) {
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList();
|
|
}
|
|
arrayList.add(key);
|
|
locationListenerTransport.unregister();
|
|
locationManager.removeUpdates(locationListenerTransport);
|
|
}
|
|
}
|
|
}
|
|
if (arrayList != null) {
|
|
Iterator it2 = arrayList.iterator();
|
|
while (it2.hasNext()) {
|
|
sLocationListeners.remove((LocationListenerKey) it2.next());
|
|
}
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
locationManager.removeUpdates(locationListenerCompat);
|
|
}
|
|
|
|
@Nullable
|
|
public static String getGnssHardwareModelName(@NonNull LocationManager locationManager) {
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
return Api28Impl.getGnssHardwareModelName(locationManager);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static int getGnssYearOfHardware(@NonNull LocationManager locationManager) {
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
return Api28Impl.getGnssYearOfHardware(locationManager);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static class GnssListenersHolder {
|
|
|
|
@GuardedBy("sGnssStatusListeners")
|
|
static final SimpleArrayMap<Object, Object> sGnssStatusListeners = new SimpleArrayMap<>();
|
|
|
|
@GuardedBy("sGnssMeasurementListeners")
|
|
static final SimpleArrayMap<GnssMeasurementsEvent.Callback, GnssMeasurementsEvent.Callback> sGnssMeasurementListeners = new SimpleArrayMap<>();
|
|
|
|
private GnssListenersHolder() {
|
|
}
|
|
}
|
|
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
@RequiresApi(24)
|
|
public static boolean registerGnssMeasurementsCallback(@NonNull LocationManager locationManager, @NonNull GnssMeasurementsEvent.Callback callback, @NonNull Handler handler) {
|
|
int i = Build.VERSION.SDK_INT;
|
|
if (i > 30) {
|
|
return Api24Impl.registerGnssMeasurementsCallback(locationManager, callback, handler);
|
|
}
|
|
if (i == 30) {
|
|
return registerGnssMeasurementsCallbackOnR(locationManager, ExecutorCompat.create(handler), callback);
|
|
}
|
|
SimpleArrayMap<GnssMeasurementsEvent.Callback, GnssMeasurementsEvent.Callback> simpleArrayMap = GnssListenersHolder.sGnssMeasurementListeners;
|
|
synchronized (simpleArrayMap) {
|
|
try {
|
|
unregisterGnssMeasurementsCallback(locationManager, callback);
|
|
if (!Api24Impl.registerGnssMeasurementsCallback(locationManager, callback, handler)) {
|
|
return false;
|
|
}
|
|
simpleArrayMap.put(callback, callback);
|
|
return true;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
@RequiresApi(24)
|
|
public static boolean registerGnssMeasurementsCallback(@NonNull LocationManager locationManager, @NonNull Executor executor, @NonNull GnssMeasurementsEvent.Callback callback) {
|
|
int i = Build.VERSION.SDK_INT;
|
|
if (i > 30) {
|
|
return Api31Impl.registerGnssMeasurementsCallback(locationManager, executor, callback);
|
|
}
|
|
if (i == 30) {
|
|
return registerGnssMeasurementsCallbackOnR(locationManager, executor, callback);
|
|
}
|
|
SimpleArrayMap<GnssMeasurementsEvent.Callback, GnssMeasurementsEvent.Callback> simpleArrayMap = GnssListenersHolder.sGnssMeasurementListeners;
|
|
synchronized (simpleArrayMap) {
|
|
try {
|
|
GnssMeasurementsTransport gnssMeasurementsTransport = new GnssMeasurementsTransport(callback, executor);
|
|
unregisterGnssMeasurementsCallback(locationManager, callback);
|
|
if (!Api24Impl.registerGnssMeasurementsCallback(locationManager, gnssMeasurementsTransport)) {
|
|
return false;
|
|
}
|
|
simpleArrayMap.put(callback, gnssMeasurementsTransport);
|
|
return true;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@RequiresApi(24)
|
|
public static void unregisterGnssMeasurementsCallback(@NonNull LocationManager locationManager, @NonNull GnssMeasurementsEvent.Callback callback) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
Api24Impl.unregisterGnssMeasurementsCallback(locationManager, callback);
|
|
return;
|
|
}
|
|
SimpleArrayMap<GnssMeasurementsEvent.Callback, GnssMeasurementsEvent.Callback> simpleArrayMap = GnssListenersHolder.sGnssMeasurementListeners;
|
|
synchronized (simpleArrayMap) {
|
|
try {
|
|
GnssMeasurementsEvent.Callback remove = simpleArrayMap.remove(callback);
|
|
if (remove != null) {
|
|
if (remove instanceof GnssMeasurementsTransport) {
|
|
((GnssMeasurementsTransport) remove).unregister();
|
|
}
|
|
Api24Impl.unregisterGnssMeasurementsCallback(locationManager, remove);
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@RequiresApi(30)
|
|
private static boolean registerGnssMeasurementsCallbackOnR(@NonNull LocationManager locationManager, @NonNull Executor executor, @NonNull GnssMeasurementsEvent.Callback callback) {
|
|
if (Build.VERSION.SDK_INT == 30) {
|
|
try {
|
|
if (sGnssRequestBuilderClass == null) {
|
|
sGnssRequestBuilderClass = Class.forName("android.location.GnssRequest$Builder");
|
|
}
|
|
if (sGnssRequestBuilderBuildMethod == null) {
|
|
Method declaredMethod = sGnssRequestBuilderClass.getDeclaredMethod("build", new Class[0]);
|
|
sGnssRequestBuilderBuildMethod = declaredMethod;
|
|
declaredMethod.setAccessible(true);
|
|
}
|
|
if (sRegisterGnssMeasurementsCallbackMethod == null) {
|
|
Method declaredMethod2 = LocationManager.class.getDeclaredMethod("registerGnssMeasurementsCallback", Class.forName("android.location.GnssRequest"), Executor.class, GnssMeasurementsEvent.Callback.class);
|
|
sRegisterGnssMeasurementsCallbackMethod = declaredMethod2;
|
|
declaredMethod2.setAccessible(true);
|
|
}
|
|
Object invoke = sRegisterGnssMeasurementsCallbackMethod.invoke(locationManager, sGnssRequestBuilderBuildMethod.invoke(sGnssRequestBuilderClass.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]), new Object[0]), executor, callback);
|
|
if (invoke != null) {
|
|
return ((Boolean) invoke).booleanValue();
|
|
}
|
|
return false;
|
|
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
throw new IllegalStateException();
|
|
}
|
|
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
public static boolean registerGnssStatusCallback(@NonNull LocationManager locationManager, @NonNull GnssStatusCompat.Callback callback, @NonNull Handler handler) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
return registerGnssStatusCallback(locationManager, ExecutorCompat.create(handler), callback);
|
|
}
|
|
return registerGnssStatusCallback(locationManager, new InlineHandlerExecutor(handler), callback);
|
|
}
|
|
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
public static boolean registerGnssStatusCallback(@NonNull LocationManager locationManager, @NonNull Executor executor, @NonNull GnssStatusCompat.Callback callback) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
return registerGnssStatusCallback(locationManager, null, executor, callback);
|
|
}
|
|
Looper myLooper = Looper.myLooper();
|
|
if (myLooper == null) {
|
|
myLooper = Looper.getMainLooper();
|
|
}
|
|
return registerGnssStatusCallback(locationManager, new Handler(myLooper), executor, callback);
|
|
}
|
|
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
private static boolean registerGnssStatusCallback(LocationManager locationManager, Handler handler, Executor executor, GnssStatusCompat.Callback callback) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
return Api30Impl.registerGnssStatusCallback(locationManager, handler, executor, callback);
|
|
}
|
|
return Api24Impl.registerGnssStatusCallback(locationManager, handler, executor, callback);
|
|
}
|
|
|
|
public static void unregisterGnssStatusCallback(@NonNull LocationManager locationManager, @NonNull GnssStatusCompat.Callback callback) {
|
|
SimpleArrayMap<Object, Object> simpleArrayMap = GnssListenersHolder.sGnssStatusListeners;
|
|
synchronized (simpleArrayMap) {
|
|
try {
|
|
Object remove = simpleArrayMap.remove(callback);
|
|
if (remove != null) {
|
|
Api24Impl.unregisterGnssStatusCallback(locationManager, remove);
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
private LocationManagerCompat() {
|
|
}
|
|
|
|
public static class LocationListenerKey {
|
|
final LocationListenerCompat mListener;
|
|
final String mProvider;
|
|
|
|
public LocationListenerKey(String str, LocationListenerCompat locationListenerCompat) {
|
|
this.mProvider = (String) ObjectsCompat.requireNonNull(str, "invalid null provider");
|
|
this.mListener = (LocationListenerCompat) ObjectsCompat.requireNonNull(locationListenerCompat, "invalid null listener");
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (!(obj instanceof LocationListenerKey)) {
|
|
return false;
|
|
}
|
|
LocationListenerKey locationListenerKey = (LocationListenerKey) obj;
|
|
return this.mProvider.equals(locationListenerKey.mProvider) && this.mListener.equals(locationListenerKey.mListener);
|
|
}
|
|
|
|
public int hashCode() {
|
|
return ObjectsCompat.hash(this.mProvider, this.mListener);
|
|
}
|
|
}
|
|
|
|
public static class LocationListenerTransport implements LocationListener {
|
|
final Executor mExecutor;
|
|
|
|
@Nullable
|
|
volatile LocationListenerKey mKey;
|
|
|
|
public void unregister() {
|
|
this.mKey = null;
|
|
}
|
|
|
|
public LocationListenerTransport(@Nullable LocationListenerKey locationListenerKey, Executor executor) {
|
|
this.mKey = locationListenerKey;
|
|
this.mExecutor = executor;
|
|
}
|
|
|
|
public LocationListenerKey getKey() {
|
|
return (LocationListenerKey) ObjectsCompat.requireNonNull(this.mKey);
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
public void onLocationChanged(@NonNull final Location location) {
|
|
if (this.mKey == null) {
|
|
return;
|
|
}
|
|
this.mExecutor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$LocationListenerTransport$$ExternalSyntheticLambda4
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.LocationListenerTransport.this.lambda$onLocationChanged$0(location);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onLocationChanged$0(Location location) {
|
|
LocationListenerKey locationListenerKey = this.mKey;
|
|
if (locationListenerKey == null) {
|
|
return;
|
|
}
|
|
locationListenerKey.mListener.onLocationChanged(location);
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
public void onLocationChanged(@NonNull final List<Location> list) {
|
|
if (this.mKey == null) {
|
|
return;
|
|
}
|
|
this.mExecutor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$LocationListenerTransport$$ExternalSyntheticLambda2
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.LocationListenerTransport.this.lambda$onLocationChanged$1(list);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onLocationChanged$1(List list) {
|
|
LocationListenerKey locationListenerKey = this.mKey;
|
|
if (locationListenerKey == null) {
|
|
return;
|
|
}
|
|
locationListenerKey.mListener.onLocationChanged((List<Location>) list);
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
public void onFlushComplete(final int i) {
|
|
if (this.mKey == null) {
|
|
return;
|
|
}
|
|
this.mExecutor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$LocationListenerTransport$$ExternalSyntheticLambda1
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.LocationListenerTransport.this.lambda$onFlushComplete$2(i);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onFlushComplete$2(int i) {
|
|
LocationListenerKey locationListenerKey = this.mKey;
|
|
if (locationListenerKey == null) {
|
|
return;
|
|
}
|
|
locationListenerKey.mListener.onFlushComplete(i);
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
public void onStatusChanged(final String str, final int i, final Bundle bundle) {
|
|
if (this.mKey == null) {
|
|
return;
|
|
}
|
|
this.mExecutor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$LocationListenerTransport$$ExternalSyntheticLambda5
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.LocationListenerTransport.this.lambda$onStatusChanged$3(str, i, bundle);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onStatusChanged$3(String str, int i, Bundle bundle) {
|
|
LocationListenerKey locationListenerKey = this.mKey;
|
|
if (locationListenerKey == null) {
|
|
return;
|
|
}
|
|
locationListenerKey.mListener.onStatusChanged(str, i, bundle);
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
public void onProviderEnabled(@NonNull final String str) {
|
|
if (this.mKey == null) {
|
|
return;
|
|
}
|
|
this.mExecutor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$LocationListenerTransport$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.LocationListenerTransport.this.lambda$onProviderEnabled$4(str);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onProviderEnabled$4(String str) {
|
|
LocationListenerKey locationListenerKey = this.mKey;
|
|
if (locationListenerKey == null) {
|
|
return;
|
|
}
|
|
locationListenerKey.mListener.onProviderEnabled(str);
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
public void onProviderDisabled(@NonNull final String str) {
|
|
if (this.mKey == null) {
|
|
return;
|
|
}
|
|
this.mExecutor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$LocationListenerTransport$$ExternalSyntheticLambda3
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.LocationListenerTransport.this.lambda$onProviderDisabled$5(str);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onProviderDisabled$5(String str) {
|
|
LocationListenerKey locationListenerKey = this.mKey;
|
|
if (locationListenerKey == null) {
|
|
return;
|
|
}
|
|
locationListenerKey.mListener.onProviderDisabled(str);
|
|
}
|
|
}
|
|
|
|
@RequiresApi(24)
|
|
public static class GnssMeasurementsTransport extends GnssMeasurementsEvent.Callback {
|
|
final GnssMeasurementsEvent.Callback mCallback;
|
|
|
|
@Nullable
|
|
volatile Executor mExecutor;
|
|
|
|
public void unregister() {
|
|
this.mExecutor = null;
|
|
}
|
|
|
|
public GnssMeasurementsTransport(@NonNull GnssMeasurementsEvent.Callback callback, @NonNull Executor executor) {
|
|
this.mCallback = callback;
|
|
this.mExecutor = executor;
|
|
}
|
|
|
|
@Override // android.location.GnssMeasurementsEvent.Callback
|
|
public void onGnssMeasurementsReceived(final GnssMeasurementsEvent gnssMeasurementsEvent) {
|
|
final Executor executor = this.mExecutor;
|
|
if (executor == null) {
|
|
return;
|
|
}
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$GnssMeasurementsTransport$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.GnssMeasurementsTransport.this.lambda$onGnssMeasurementsReceived$0(executor, gnssMeasurementsEvent);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onGnssMeasurementsReceived$0(Executor executor, GnssMeasurementsEvent gnssMeasurementsEvent) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onGnssMeasurementsReceived(gnssMeasurementsEvent);
|
|
}
|
|
|
|
@Override // android.location.GnssMeasurementsEvent.Callback
|
|
public void onStatusChanged(final int i) {
|
|
final Executor executor = this.mExecutor;
|
|
if (executor == null) {
|
|
return;
|
|
}
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$GnssMeasurementsTransport$$ExternalSyntheticLambda1
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.GnssMeasurementsTransport.this.lambda$onStatusChanged$1(executor, i);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onStatusChanged$1(Executor executor, int i) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onStatusChanged(i);
|
|
}
|
|
}
|
|
|
|
@RequiresApi(30)
|
|
public static class GnssStatusTransport extends GnssStatus.Callback {
|
|
final GnssStatusCompat.Callback mCallback;
|
|
|
|
public GnssStatusTransport(GnssStatusCompat.Callback callback) {
|
|
Preconditions.checkArgument(callback != null, "invalid null callback");
|
|
this.mCallback = callback;
|
|
}
|
|
|
|
@Override // android.location.GnssStatus.Callback
|
|
public void onStarted() {
|
|
this.mCallback.onStarted();
|
|
}
|
|
|
|
@Override // android.location.GnssStatus.Callback
|
|
public void onStopped() {
|
|
this.mCallback.onStopped();
|
|
}
|
|
|
|
@Override // android.location.GnssStatus.Callback
|
|
public void onFirstFix(int i) {
|
|
this.mCallback.onFirstFix(i);
|
|
}
|
|
|
|
@Override // android.location.GnssStatus.Callback
|
|
public void onSatelliteStatusChanged(GnssStatus gnssStatus) {
|
|
this.mCallback.onSatelliteStatusChanged(GnssStatusCompat.wrap(gnssStatus));
|
|
}
|
|
}
|
|
|
|
@RequiresApi(24)
|
|
public static class PreRGnssStatusTransport extends GnssStatus.Callback {
|
|
final GnssStatusCompat.Callback mCallback;
|
|
|
|
@Nullable
|
|
volatile Executor mExecutor;
|
|
|
|
public void unregister() {
|
|
this.mExecutor = null;
|
|
}
|
|
|
|
public PreRGnssStatusTransport(GnssStatusCompat.Callback callback) {
|
|
Preconditions.checkArgument(callback != null, "invalid null callback");
|
|
this.mCallback = callback;
|
|
}
|
|
|
|
public void register(Executor executor) {
|
|
Preconditions.checkArgument(executor != null, "invalid null executor");
|
|
Preconditions.checkState(this.mExecutor == null);
|
|
this.mExecutor = executor;
|
|
}
|
|
|
|
@Override // android.location.GnssStatus.Callback
|
|
public void onStarted() {
|
|
final Executor executor = this.mExecutor;
|
|
if (executor == null) {
|
|
return;
|
|
}
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$PreRGnssStatusTransport$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.PreRGnssStatusTransport.this.lambda$onStarted$0(executor);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onStarted$0(Executor executor) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onStarted();
|
|
}
|
|
|
|
@Override // android.location.GnssStatus.Callback
|
|
public void onStopped() {
|
|
final Executor executor = this.mExecutor;
|
|
if (executor == null) {
|
|
return;
|
|
}
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$PreRGnssStatusTransport$$ExternalSyntheticLambda3
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.PreRGnssStatusTransport.this.lambda$onStopped$1(executor);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onStopped$1(Executor executor) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onStopped();
|
|
}
|
|
|
|
@Override // android.location.GnssStatus.Callback
|
|
public void onFirstFix(final int i) {
|
|
final Executor executor = this.mExecutor;
|
|
if (executor == null) {
|
|
return;
|
|
}
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$PreRGnssStatusTransport$$ExternalSyntheticLambda2
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.PreRGnssStatusTransport.this.lambda$onFirstFix$2(executor, i);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onFirstFix$2(Executor executor, int i) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onFirstFix(i);
|
|
}
|
|
|
|
@Override // android.location.GnssStatus.Callback
|
|
public void onSatelliteStatusChanged(final GnssStatus gnssStatus) {
|
|
final Executor executor = this.mExecutor;
|
|
if (executor == null) {
|
|
return;
|
|
}
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$PreRGnssStatusTransport$$ExternalSyntheticLambda1
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.PreRGnssStatusTransport.this.lambda$onSatelliteStatusChanged$3(executor, gnssStatus);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onSatelliteStatusChanged$3(Executor executor, GnssStatus gnssStatus) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onSatelliteStatusChanged(GnssStatusCompat.wrap(gnssStatus));
|
|
}
|
|
}
|
|
|
|
public static class GpsStatusTransport implements GpsStatus.Listener {
|
|
final GnssStatusCompat.Callback mCallback;
|
|
|
|
@Nullable
|
|
volatile Executor mExecutor;
|
|
private final LocationManager mLocationManager;
|
|
|
|
public void unregister() {
|
|
this.mExecutor = null;
|
|
}
|
|
|
|
public GpsStatusTransport(LocationManager locationManager, GnssStatusCompat.Callback callback) {
|
|
Preconditions.checkArgument(callback != null, "invalid null callback");
|
|
this.mLocationManager = locationManager;
|
|
this.mCallback = callback;
|
|
}
|
|
|
|
public void register(Executor executor) {
|
|
Preconditions.checkState(this.mExecutor == null);
|
|
this.mExecutor = executor;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onGpsStatusChanged$0(Executor executor) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onStarted();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onGpsStatusChanged$1(Executor executor) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onStopped();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onGpsStatusChanged$2(Executor executor, int i) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onFirstFix(i);
|
|
}
|
|
|
|
@Override // android.location.GpsStatus.Listener
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
public void onGpsStatusChanged(int i) {
|
|
GpsStatus gpsStatus;
|
|
final Executor executor = this.mExecutor;
|
|
if (executor == null) {
|
|
return;
|
|
}
|
|
if (i == 1) {
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$GpsStatusTransport$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.GpsStatusTransport.this.lambda$onGpsStatusChanged$0(executor);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
if (i == 2) {
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$GpsStatusTransport$$ExternalSyntheticLambda1
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.GpsStatusTransport.this.lambda$onGpsStatusChanged$1(executor);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
if (i != 3) {
|
|
if (i == 4 && (gpsStatus = this.mLocationManager.getGpsStatus(null)) != null) {
|
|
final GnssStatusCompat wrap = GnssStatusCompat.wrap(gpsStatus);
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$GpsStatusTransport$$ExternalSyntheticLambda3
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.GpsStatusTransport.this.lambda$onGpsStatusChanged$3(executor, wrap);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
GpsStatus gpsStatus2 = this.mLocationManager.getGpsStatus(null);
|
|
if (gpsStatus2 != null) {
|
|
final int timeToFirstFix = gpsStatus2.getTimeToFirstFix();
|
|
executor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$GpsStatusTransport$$ExternalSyntheticLambda2
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.GpsStatusTransport.this.lambda$onGpsStatusChanged$2(executor, timeToFirstFix);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$onGpsStatusChanged$3(Executor executor, GnssStatusCompat gnssStatusCompat) {
|
|
if (this.mExecutor != executor) {
|
|
return;
|
|
}
|
|
this.mCallback.onSatelliteStatusChanged(gnssStatusCompat);
|
|
}
|
|
}
|
|
|
|
public static final class CancellableLocationListener implements LocationListener {
|
|
private Consumer<Location> mConsumer;
|
|
private final Executor mExecutor;
|
|
private final LocationManager mLocationManager;
|
|
private final Handler mTimeoutHandler = new Handler(Looper.getMainLooper());
|
|
|
|
@Nullable
|
|
Runnable mTimeoutRunnable;
|
|
|
|
@GuardedBy("this")
|
|
private boolean mTriggered;
|
|
|
|
@Override // android.location.LocationListener
|
|
public void onProviderEnabled(@NonNull String str) {
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
public void onStatusChanged(String str, int i, Bundle bundle) {
|
|
}
|
|
|
|
public CancellableLocationListener(LocationManager locationManager, Executor executor, Consumer<Location> consumer) {
|
|
this.mLocationManager = locationManager;
|
|
this.mExecutor = executor;
|
|
this.mConsumer = consumer;
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public void cancel() {
|
|
synchronized (this) {
|
|
try {
|
|
if (this.mTriggered) {
|
|
return;
|
|
}
|
|
this.mTriggered = true;
|
|
cleanup();
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@SuppressLint({"MissingPermission"})
|
|
public void startTimeout(long j) {
|
|
synchronized (this) {
|
|
try {
|
|
if (this.mTriggered) {
|
|
return;
|
|
}
|
|
Runnable runnable = new Runnable() { // from class: androidx.core.location.LocationManagerCompat$CancellableLocationListener$$ExternalSyntheticLambda0
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
LocationManagerCompat.CancellableLocationListener.this.lambda$startTimeout$0();
|
|
}
|
|
};
|
|
this.mTimeoutRunnable = runnable;
|
|
this.mTimeoutHandler.postDelayed(runnable, j);
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public /* synthetic */ void lambda$startTimeout$0() {
|
|
this.mTimeoutRunnable = null;
|
|
onLocationChanged((Location) null);
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public void onProviderDisabled(@NonNull String str) {
|
|
onLocationChanged((Location) null);
|
|
}
|
|
|
|
@Override // android.location.LocationListener
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public void onLocationChanged(@Nullable final Location location) {
|
|
synchronized (this) {
|
|
try {
|
|
if (this.mTriggered) {
|
|
return;
|
|
}
|
|
this.mTriggered = true;
|
|
final Consumer<Location> consumer = this.mConsumer;
|
|
this.mExecutor.execute(new Runnable() { // from class: androidx.core.location.LocationManagerCompat$CancellableLocationListener$$ExternalSyntheticLambda1
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
Consumer.this.accept(location);
|
|
}
|
|
});
|
|
cleanup();
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
private void cleanup() {
|
|
this.mConsumer = null;
|
|
this.mLocationManager.removeUpdates(this);
|
|
Runnable runnable = this.mTimeoutRunnable;
|
|
if (runnable != null) {
|
|
this.mTimeoutHandler.removeCallbacks(runnable);
|
|
this.mTimeoutRunnable = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static final class InlineHandlerExecutor implements Executor {
|
|
private final Handler mHandler;
|
|
|
|
public InlineHandlerExecutor(@NonNull Handler handler) {
|
|
this.mHandler = (Handler) Preconditions.checkNotNull(handler);
|
|
}
|
|
|
|
@Override // java.util.concurrent.Executor
|
|
public void execute(@NonNull Runnable runnable) {
|
|
if (Looper.myLooper() == this.mHandler.getLooper()) {
|
|
runnable.run();
|
|
} else {
|
|
if (this.mHandler.post((Runnable) Preconditions.checkNotNull(runnable))) {
|
|
return;
|
|
}
|
|
throw new RejectedExecutionException(this.mHandler + " is shutting down");
|
|
}
|
|
}
|
|
}
|
|
|
|
@RequiresApi(31)
|
|
public static class Api31Impl {
|
|
private Api31Impl() {
|
|
}
|
|
|
|
public static boolean hasProvider(LocationManager locationManager, @NonNull String str) {
|
|
return locationManager.hasProvider(str);
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public static void requestLocationUpdates(LocationManager locationManager, @NonNull String str, @NonNull LocationRequest locationRequest, @NonNull Executor executor, @NonNull LocationListener locationListener) {
|
|
locationManager.requestLocationUpdates(str, locationRequest, executor, locationListener);
|
|
}
|
|
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
public static boolean registerGnssMeasurementsCallback(@NonNull LocationManager locationManager, @NonNull Executor executor, @NonNull GnssMeasurementsEvent.Callback callback) {
|
|
return locationManager.registerGnssMeasurementsCallback(executor, callback);
|
|
}
|
|
}
|
|
|
|
@RequiresApi(30)
|
|
public static class Api30Impl {
|
|
private static Class<?> sLocationRequestClass;
|
|
private static Method sRequestLocationUpdatesExecutorMethod;
|
|
|
|
private Api30Impl() {
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public static void getCurrentLocation(LocationManager locationManager, @NonNull String str, @Nullable android.os.CancellationSignal cancellationSignal, @NonNull Executor executor, @NonNull final Consumer<Location> consumer) {
|
|
Objects.requireNonNull(consumer);
|
|
locationManager.getCurrentLocation(str, cancellationSignal, executor, new java.util.function.Consumer() { // from class: androidx.core.location.LocationManagerCompat$Api30Impl$$ExternalSyntheticLambda0
|
|
@Override // java.util.function.Consumer
|
|
public final void accept(Object obj) {
|
|
Consumer.this.accept((Location) obj);
|
|
}
|
|
});
|
|
}
|
|
|
|
public static boolean tryRequestLocationUpdates(LocationManager locationManager, String str, LocationRequestCompat locationRequestCompat, Executor executor, LocationListenerCompat locationListenerCompat) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
try {
|
|
if (sLocationRequestClass == null) {
|
|
sLocationRequestClass = Class.forName("android.location.LocationRequest");
|
|
}
|
|
if (sRequestLocationUpdatesExecutorMethod == null) {
|
|
Method declaredMethod = LocationManager.class.getDeclaredMethod("requestLocationUpdates", sLocationRequestClass, Executor.class, LocationListener.class);
|
|
sRequestLocationUpdatesExecutorMethod = declaredMethod;
|
|
declaredMethod.setAccessible(true);
|
|
}
|
|
LocationRequest locationRequest = locationRequestCompat.toLocationRequest(str);
|
|
if (locationRequest != null) {
|
|
sRequestLocationUpdatesExecutorMethod.invoke(locationManager, locationRequest, executor, locationListenerCompat);
|
|
return true;
|
|
}
|
|
} catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | UnsupportedOperationException | InvocationTargetException unused) {
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public static boolean registerGnssStatusCallback(LocationManager locationManager, Handler handler, Executor executor, GnssStatusCompat.Callback callback) {
|
|
SimpleArrayMap<Object, Object> simpleArrayMap = GnssListenersHolder.sGnssStatusListeners;
|
|
synchronized (simpleArrayMap) {
|
|
try {
|
|
GnssStatusTransport gnssStatusTransport = (GnssStatusTransport) simpleArrayMap.get(callback);
|
|
if (gnssStatusTransport == null) {
|
|
gnssStatusTransport = new GnssStatusTransport(callback);
|
|
}
|
|
if (!locationManager.registerGnssStatusCallback(executor, gnssStatusTransport)) {
|
|
return false;
|
|
}
|
|
simpleArrayMap.put(callback, gnssStatusTransport);
|
|
return true;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@RequiresApi(28)
|
|
public static class Api28Impl {
|
|
private Api28Impl() {
|
|
}
|
|
|
|
public static boolean isLocationEnabled(LocationManager locationManager) {
|
|
return locationManager.isLocationEnabled();
|
|
}
|
|
|
|
public static String getGnssHardwareModelName(LocationManager locationManager) {
|
|
return locationManager.getGnssHardwareModelName();
|
|
}
|
|
|
|
public static int getGnssYearOfHardware(LocationManager locationManager) {
|
|
return locationManager.getGnssYearOfHardware();
|
|
}
|
|
}
|
|
|
|
public static class Api19Impl {
|
|
private static Class<?> sLocationRequestClass;
|
|
private static Method sRequestLocationUpdatesLooperMethod;
|
|
|
|
private Api19Impl() {
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
@SuppressLint({"BanUncheckedReflection"})
|
|
public static boolean tryRequestLocationUpdates(LocationManager locationManager, String str, LocationRequestCompat locationRequestCompat, LocationListenerTransport locationListenerTransport) {
|
|
try {
|
|
if (sLocationRequestClass == null) {
|
|
sLocationRequestClass = Class.forName("android.location.LocationRequest");
|
|
}
|
|
if (sRequestLocationUpdatesLooperMethod == null) {
|
|
Method declaredMethod = LocationManager.class.getDeclaredMethod("requestLocationUpdates", sLocationRequestClass, LocationListener.class, Looper.class);
|
|
sRequestLocationUpdatesLooperMethod = declaredMethod;
|
|
declaredMethod.setAccessible(true);
|
|
}
|
|
LocationRequest locationRequest = locationRequestCompat.toLocationRequest(str);
|
|
if (locationRequest != null) {
|
|
synchronized (LocationManagerCompat.sLocationListeners) {
|
|
sRequestLocationUpdatesLooperMethod.invoke(locationManager, locationRequest, locationListenerTransport, Looper.getMainLooper());
|
|
LocationManagerCompat.registerLocationListenerTransport(locationManager, locationListenerTransport);
|
|
}
|
|
return true;
|
|
}
|
|
} catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | UnsupportedOperationException | InvocationTargetException unused) {
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@SuppressLint({"BanUncheckedReflection"})
|
|
public static boolean tryRequestLocationUpdates(LocationManager locationManager, String str, LocationRequestCompat locationRequestCompat, LocationListenerCompat locationListenerCompat, Looper looper) {
|
|
try {
|
|
if (sLocationRequestClass == null) {
|
|
sLocationRequestClass = Class.forName("android.location.LocationRequest");
|
|
}
|
|
if (sRequestLocationUpdatesLooperMethod == null) {
|
|
Method declaredMethod = LocationManager.class.getDeclaredMethod("requestLocationUpdates", sLocationRequestClass, LocationListener.class, Looper.class);
|
|
sRequestLocationUpdatesLooperMethod = declaredMethod;
|
|
declaredMethod.setAccessible(true);
|
|
}
|
|
LocationRequest locationRequest = locationRequestCompat.toLocationRequest(str);
|
|
if (locationRequest != null) {
|
|
sRequestLocationUpdatesLooperMethod.invoke(locationManager, locationRequest, locationListenerCompat, looper);
|
|
return true;
|
|
}
|
|
} catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | UnsupportedOperationException | InvocationTargetException unused) {
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@RequiresApi(24)
|
|
public static class Api24Impl {
|
|
private Api24Impl() {
|
|
}
|
|
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
public static boolean registerGnssMeasurementsCallback(@NonNull LocationManager locationManager, @NonNull GnssMeasurementsEvent.Callback callback) {
|
|
return locationManager.registerGnssMeasurementsCallback(callback);
|
|
}
|
|
|
|
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
|
|
public static boolean registerGnssMeasurementsCallback(@NonNull LocationManager locationManager, @NonNull GnssMeasurementsEvent.Callback callback, @NonNull Handler handler) {
|
|
return locationManager.registerGnssMeasurementsCallback(callback, handler);
|
|
}
|
|
|
|
public static void unregisterGnssMeasurementsCallback(@NonNull LocationManager locationManager, @NonNull GnssMeasurementsEvent.Callback callback) {
|
|
locationManager.unregisterGnssMeasurementsCallback(callback);
|
|
}
|
|
|
|
@RequiresPermission(anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"})
|
|
public static boolean registerGnssStatusCallback(LocationManager locationManager, Handler handler, Executor executor, GnssStatusCompat.Callback callback) {
|
|
Preconditions.checkArgument(handler != null);
|
|
SimpleArrayMap<Object, Object> simpleArrayMap = GnssListenersHolder.sGnssStatusListeners;
|
|
synchronized (simpleArrayMap) {
|
|
try {
|
|
PreRGnssStatusTransport preRGnssStatusTransport = (PreRGnssStatusTransport) simpleArrayMap.get(callback);
|
|
if (preRGnssStatusTransport == null) {
|
|
preRGnssStatusTransport = new PreRGnssStatusTransport(callback);
|
|
} else {
|
|
preRGnssStatusTransport.unregister();
|
|
}
|
|
preRGnssStatusTransport.register(executor);
|
|
if (!locationManager.registerGnssStatusCallback(preRGnssStatusTransport, handler)) {
|
|
return false;
|
|
}
|
|
simpleArrayMap.put(callback, preRGnssStatusTransport);
|
|
return true;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void unregisterGnssStatusCallback(LocationManager locationManager, Object obj) {
|
|
if (obj instanceof PreRGnssStatusTransport) {
|
|
((PreRGnssStatusTransport) obj).unregister();
|
|
}
|
|
locationManager.unregisterGnssStatusCallback((GnssStatus.Callback) obj);
|
|
}
|
|
}
|
|
}
|