package androidx.core.location; import android.annotation.SuppressLint; import android.location.Location; import android.os.Build; import android.os.Bundle; import androidx.annotation.FloatRange; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.ReplaceWith; import androidx.annotation.RequiresApi; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.concurrent.TimeUnit; /* loaded from: classes.dex */ public final class LocationCompat { public static final String EXTRA_BEARING_ACCURACY = "bearingAccuracy"; public static final String EXTRA_IS_MOCK = "mockLocation"; public static final String EXTRA_MSL_ALTITUDE = "androidx.core.location.extra.MSL_ALTITUDE"; public static final String EXTRA_MSL_ALTITUDE_ACCURACY = "androidx.core.location.extra.MSL_ALTITUDE_ACCURACY"; public static final String EXTRA_SPEED_ACCURACY = "speedAccuracy"; public static final String EXTRA_VERTICAL_ACCURACY = "verticalAccuracy"; @Nullable private static Field sFieldsMaskField; @Nullable private static Integer sHasBearingAccuracyMask; @Nullable private static Integer sHasSpeedAccuracyMask; @Nullable private static Integer sHasVerticalAccuracyMask; @Nullable private static Method sSetIsFromMockProviderMethod; private LocationCompat() { } @ReplaceWith(expression = "location.getElapsedRealtimeNanos()") @Deprecated public static long getElapsedRealtimeNanos(@NonNull Location location) { return location.getElapsedRealtimeNanos(); } public static long getElapsedRealtimeMillis(@NonNull Location location) { return TimeUnit.NANOSECONDS.toMillis(location.getElapsedRealtimeNanos()); } public static boolean hasVerticalAccuracy(@NonNull Location location) { return Api26Impl.hasVerticalAccuracy(location); } public static float getVerticalAccuracyMeters(@NonNull Location location) { return Api26Impl.getVerticalAccuracyMeters(location); } public static void setVerticalAccuracyMeters(@NonNull Location location, float f) { Api26Impl.setVerticalAccuracyMeters(location, f); } public static void removeVerticalAccuracy(@NonNull Location location) { int i = Build.VERSION.SDK_INT; if (i >= 33) { Api33Impl.removeVerticalAccuracy(location); return; } if (i >= 29) { Api29Impl.removeVerticalAccuracy(location); } else if (i >= 28) { Api28Impl.removeVerticalAccuracy(location); } else { Api26Impl.removeVerticalAccuracy(location); } } public static boolean hasSpeedAccuracy(@NonNull Location location) { return Api26Impl.hasSpeedAccuracy(location); } public static float getSpeedAccuracyMetersPerSecond(@NonNull Location location) { return Api26Impl.getSpeedAccuracyMetersPerSecond(location); } public static void setSpeedAccuracyMetersPerSecond(@NonNull Location location, float f) { Api26Impl.setSpeedAccuracyMetersPerSecond(location, f); } public static void removeSpeedAccuracy(@NonNull Location location) { int i = Build.VERSION.SDK_INT; if (i >= 33) { Api33Impl.removeSpeedAccuracy(location); return; } if (i >= 29) { Api29Impl.removeSpeedAccuracy(location); } else if (i >= 28) { Api28Impl.removeSpeedAccuracy(location); } else { Api26Impl.removeSpeedAccuracy(location); } } public static boolean hasBearingAccuracy(@NonNull Location location) { return Api26Impl.hasBearingAccuracy(location); } public static float getBearingAccuracyDegrees(@NonNull Location location) { return Api26Impl.getBearingAccuracyDegrees(location); } public static void setBearingAccuracyDegrees(@NonNull Location location, float f) { Api26Impl.setBearingAccuracyDegrees(location, f); } public static void removeBearingAccuracy(@NonNull Location location) { int i = Build.VERSION.SDK_INT; if (i >= 33) { Api33Impl.removeBearingAccuracy(location); return; } if (i >= 29) { Api29Impl.removeBearingAccuracy(location); } else if (i >= 28) { Api28Impl.removeBearingAccuracy(location); } else { Api26Impl.removeBearingAccuracy(location); } } public static double getMslAltitudeMeters(@NonNull Location location) { if (Build.VERSION.SDK_INT >= 34) { return Api34Impl.getMslAltitudeMeters(location); } return getOrCreateExtras(location).getDouble(EXTRA_MSL_ALTITUDE); } public static void setMslAltitudeMeters(@NonNull Location location, double d) { if (Build.VERSION.SDK_INT >= 34) { Api34Impl.setMslAltitudeMeters(location, d); } else { getOrCreateExtras(location).putDouble(EXTRA_MSL_ALTITUDE, d); } } public static boolean hasMslAltitude(@NonNull Location location) { if (Build.VERSION.SDK_INT >= 34) { return Api34Impl.hasMslAltitude(location); } return containsExtra(location, EXTRA_MSL_ALTITUDE); } public static void removeMslAltitude(@NonNull Location location) { if (Build.VERSION.SDK_INT >= 34) { Api34Impl.removeMslAltitude(location); } else { removeExtra(location, EXTRA_MSL_ALTITUDE); } } @FloatRange(from = 0.0d) public static float getMslAltitudeAccuracyMeters(@NonNull Location location) { if (Build.VERSION.SDK_INT >= 34) { return Api34Impl.getMslAltitudeAccuracyMeters(location); } return getOrCreateExtras(location).getFloat(EXTRA_MSL_ALTITUDE_ACCURACY); } public static void setMslAltitudeAccuracyMeters(@NonNull Location location, @FloatRange(from = 0.0d) float f) { if (Build.VERSION.SDK_INT >= 34) { Api34Impl.setMslAltitudeAccuracyMeters(location, f); } else { getOrCreateExtras(location).putFloat(EXTRA_MSL_ALTITUDE_ACCURACY, f); } } public static boolean hasMslAltitudeAccuracy(@NonNull Location location) { if (Build.VERSION.SDK_INT >= 34) { return Api34Impl.hasMslAltitudeAccuracy(location); } return containsExtra(location, EXTRA_MSL_ALTITUDE_ACCURACY); } public static void removeMslAltitudeAccuracy(@NonNull Location location) { if (Build.VERSION.SDK_INT >= 34) { Api34Impl.removeMslAltitudeAccuracy(location); } else { removeExtra(location, EXTRA_MSL_ALTITUDE_ACCURACY); } } public static boolean isMock(@NonNull Location location) { if (Build.VERSION.SDK_INT >= 31) { return Api31Impl.isMock(location); } return location.isFromMockProvider(); } @SuppressLint({"BanUncheckedReflection"}) public static void setMock(@NonNull Location location, boolean z) { try { getSetIsFromMockProviderMethod().invoke(location, Boolean.valueOf(z)); } catch (IllegalAccessException e) { IllegalAccessError illegalAccessError = new IllegalAccessError(); illegalAccessError.initCause(e); throw illegalAccessError; } catch (NoSuchMethodException e2) { NoSuchMethodError noSuchMethodError = new NoSuchMethodError(); noSuchMethodError.initCause(e2); throw noSuchMethodError; } catch (InvocationTargetException e3) { throw new RuntimeException(e3); } } @RequiresApi(34) public static class Api34Impl { private Api34Impl() { } public static double getMslAltitudeMeters(Location location) { return location.getMslAltitudeMeters(); } public static void setMslAltitudeMeters(Location location, double d) { location.setMslAltitudeMeters(d); } public static boolean hasMslAltitude(Location location) { return location.hasMslAltitude(); } public static void removeMslAltitude(Location location) { location.removeMslAltitude(); } public static float getMslAltitudeAccuracyMeters(Location location) { return location.getMslAltitudeAccuracyMeters(); } public static void setMslAltitudeAccuracyMeters(Location location, float f) { location.setMslAltitudeAccuracyMeters(f); } public static boolean hasMslAltitudeAccuracy(Location location) { return location.hasMslAltitudeAccuracy(); } public static void removeMslAltitudeAccuracy(Location location) { location.removeMslAltitudeAccuracy(); } } @RequiresApi(33) public static class Api33Impl { private Api33Impl() { } public static void removeVerticalAccuracy(Location location) { location.removeVerticalAccuracy(); } public static void removeSpeedAccuracy(Location location) { location.removeSpeedAccuracy(); } public static void removeBearingAccuracy(Location location) { location.removeBearingAccuracy(); } } @RequiresApi(29) public static class Api29Impl { private Api29Impl() { } public static void removeVerticalAccuracy(Location location) { if (location.hasVerticalAccuracy()) { double elapsedRealtimeUncertaintyNanos = location.getElapsedRealtimeUncertaintyNanos(); Api28Impl.removeVerticalAccuracy(location); location.setElapsedRealtimeUncertaintyNanos(elapsedRealtimeUncertaintyNanos); } } public static void removeSpeedAccuracy(Location location) { if (location.hasSpeedAccuracy()) { double elapsedRealtimeUncertaintyNanos = location.getElapsedRealtimeUncertaintyNanos(); Api28Impl.removeSpeedAccuracy(location); location.setElapsedRealtimeUncertaintyNanos(elapsedRealtimeUncertaintyNanos); } } public static void removeBearingAccuracy(Location location) { if (location.hasBearingAccuracy()) { double elapsedRealtimeUncertaintyNanos = location.getElapsedRealtimeUncertaintyNanos(); Api28Impl.removeBearingAccuracy(location); location.setElapsedRealtimeUncertaintyNanos(elapsedRealtimeUncertaintyNanos); } } } @RequiresApi(28) public static class Api28Impl { private Api28Impl() { } public static void removeVerticalAccuracy(Location location) { if (location.hasVerticalAccuracy()) { String provider = location.getProvider(); long time = location.getTime(); long elapsedRealtimeNanos = location.getElapsedRealtimeNanos(); double latitude = location.getLatitude(); double longitude = location.getLongitude(); boolean hasAltitude = location.hasAltitude(); double altitude = location.getAltitude(); boolean hasSpeed = location.hasSpeed(); float speed = location.getSpeed(); boolean hasBearing = location.hasBearing(); float bearing = location.getBearing(); boolean hasAccuracy = location.hasAccuracy(); float accuracy = location.getAccuracy(); boolean hasSpeedAccuracy = location.hasSpeedAccuracy(); float speedAccuracyMetersPerSecond = location.getSpeedAccuracyMetersPerSecond(); boolean hasBearingAccuracy = location.hasBearingAccuracy(); float bearingAccuracyDegrees = location.getBearingAccuracyDegrees(); Bundle extras = location.getExtras(); location.reset(); location.setProvider(provider); location.setTime(time); location.setElapsedRealtimeNanos(elapsedRealtimeNanos); location.setLatitude(latitude); location.setLongitude(longitude); if (hasAltitude) { location.setAltitude(altitude); } if (hasSpeed) { location.setSpeed(speed); } if (hasBearing) { location.setBearing(bearing); } if (hasAccuracy) { location.setAccuracy(accuracy); } if (hasSpeedAccuracy) { location.setSpeedAccuracyMetersPerSecond(speedAccuracyMetersPerSecond); } if (hasBearingAccuracy) { location.setBearingAccuracyDegrees(bearingAccuracyDegrees); } if (extras != null) { location.setExtras(extras); } } } public static void removeSpeedAccuracy(Location location) { if (location.hasSpeedAccuracy()) { String provider = location.getProvider(); long time = location.getTime(); long elapsedRealtimeNanos = location.getElapsedRealtimeNanos(); double latitude = location.getLatitude(); double longitude = location.getLongitude(); boolean hasAltitude = location.hasAltitude(); double altitude = location.getAltitude(); boolean hasSpeed = location.hasSpeed(); float speed = location.getSpeed(); boolean hasBearing = location.hasBearing(); float bearing = location.getBearing(); boolean hasAccuracy = location.hasAccuracy(); float accuracy = location.getAccuracy(); boolean hasVerticalAccuracy = location.hasVerticalAccuracy(); float verticalAccuracyMeters = location.getVerticalAccuracyMeters(); boolean hasBearingAccuracy = location.hasBearingAccuracy(); float bearingAccuracyDegrees = location.getBearingAccuracyDegrees(); Bundle extras = location.getExtras(); location.reset(); location.setProvider(provider); location.setTime(time); location.setElapsedRealtimeNanos(elapsedRealtimeNanos); location.setLatitude(latitude); location.setLongitude(longitude); if (hasAltitude) { location.setAltitude(altitude); } if (hasSpeed) { location.setSpeed(speed); } if (hasBearing) { location.setBearing(bearing); } if (hasAccuracy) { location.setAccuracy(accuracy); } if (hasVerticalAccuracy) { location.setVerticalAccuracyMeters(verticalAccuracyMeters); } if (hasBearingAccuracy) { location.setBearingAccuracyDegrees(bearingAccuracyDegrees); } if (extras != null) { location.setExtras(extras); } } } public static void removeBearingAccuracy(Location location) { if (location.hasBearingAccuracy()) { String provider = location.getProvider(); long time = location.getTime(); long elapsedRealtimeNanos = location.getElapsedRealtimeNanos(); double latitude = location.getLatitude(); double longitude = location.getLongitude(); boolean hasAltitude = location.hasAltitude(); double altitude = location.getAltitude(); boolean hasSpeed = location.hasSpeed(); float speed = location.getSpeed(); boolean hasBearing = location.hasBearing(); float bearing = location.getBearing(); boolean hasAccuracy = location.hasAccuracy(); float accuracy = location.getAccuracy(); boolean hasVerticalAccuracy = location.hasVerticalAccuracy(); float verticalAccuracyMeters = location.getVerticalAccuracyMeters(); boolean hasSpeedAccuracy = location.hasSpeedAccuracy(); float speedAccuracyMetersPerSecond = location.getSpeedAccuracyMetersPerSecond(); Bundle extras = location.getExtras(); location.reset(); location.setProvider(provider); location.setTime(time); location.setElapsedRealtimeNanos(elapsedRealtimeNanos); location.setLatitude(latitude); location.setLongitude(longitude); if (hasAltitude) { location.setAltitude(altitude); } if (hasSpeed) { location.setSpeed(speed); } if (hasBearing) { location.setBearing(bearing); } if (hasAccuracy) { location.setAccuracy(accuracy); } if (hasVerticalAccuracy) { location.setVerticalAccuracyMeters(verticalAccuracyMeters); } if (hasSpeedAccuracy) { location.setBearingAccuracyDegrees(speedAccuracyMetersPerSecond); } if (extras != null) { location.setExtras(extras); } } } } @RequiresApi(26) public static class Api26Impl { private Api26Impl() { } public static boolean hasVerticalAccuracy(Location location) { return location.hasVerticalAccuracy(); } public static float getVerticalAccuracyMeters(Location location) { return location.getVerticalAccuracyMeters(); } public static void setVerticalAccuracyMeters(Location location, float f) { location.setVerticalAccuracyMeters(f); } public static void removeVerticalAccuracy(Location location) { try { LocationCompat.getFieldsMaskField().setByte(location, (byte) (LocationCompat.getFieldsMaskField().getByte(location) & (~LocationCompat.getHasVerticalAccuracyMask()))); } catch (IllegalAccessException | NoSuchFieldException e) { IllegalAccessError illegalAccessError = new IllegalAccessError(); illegalAccessError.initCause(e); throw illegalAccessError; } } public static boolean hasSpeedAccuracy(Location location) { return location.hasSpeedAccuracy(); } public static float getSpeedAccuracyMetersPerSecond(Location location) { return location.getSpeedAccuracyMetersPerSecond(); } public static void setSpeedAccuracyMetersPerSecond(Location location, float f) { location.setSpeedAccuracyMetersPerSecond(f); } public static void removeSpeedAccuracy(Location location) { try { LocationCompat.getFieldsMaskField().setByte(location, (byte) (LocationCompat.getFieldsMaskField().getByte(location) & (~LocationCompat.getHasSpeedAccuracyMask()))); } catch (IllegalAccessException e) { IllegalAccessError illegalAccessError = new IllegalAccessError(); illegalAccessError.initCause(e); throw illegalAccessError; } catch (NoSuchFieldException e2) { NoSuchFieldError noSuchFieldError = new NoSuchFieldError(); noSuchFieldError.initCause(e2); throw noSuchFieldError; } } public static boolean hasBearingAccuracy(Location location) { return location.hasBearingAccuracy(); } public static float getBearingAccuracyDegrees(Location location) { return location.getBearingAccuracyDegrees(); } public static void setBearingAccuracyDegrees(Location location, float f) { location.setBearingAccuracyDegrees(f); } public static void removeBearingAccuracy(Location location) { try { LocationCompat.getFieldsMaskField().setByte(location, (byte) (LocationCompat.getFieldsMaskField().getByte(location) & (~LocationCompat.getHasBearingAccuracyMask()))); } catch (IllegalAccessException e) { IllegalAccessError illegalAccessError = new IllegalAccessError(); illegalAccessError.initCause(e); throw illegalAccessError; } catch (NoSuchFieldException e2) { NoSuchFieldError noSuchFieldError = new NoSuchFieldError(); noSuchFieldError.initCause(e2); throw noSuchFieldError; } } } private static Method getSetIsFromMockProviderMethod() throws NoSuchMethodException { if (sSetIsFromMockProviderMethod == null) { Method declaredMethod = Location.class.getDeclaredMethod("setIsFromMockProvider", Boolean.TYPE); sSetIsFromMockProviderMethod = declaredMethod; declaredMethod.setAccessible(true); } return sSetIsFromMockProviderMethod; } @SuppressLint({"BlockedPrivateApi"}) public static Field getFieldsMaskField() throws NoSuchFieldException { if (sFieldsMaskField == null) { Field declaredField = Location.class.getDeclaredField("mFieldsMask"); sFieldsMaskField = declaredField; declaredField.setAccessible(true); } return sFieldsMaskField; } @SuppressLint({"SoonBlockedPrivateApi"}) public static int getHasSpeedAccuracyMask() throws NoSuchFieldException, IllegalAccessException { if (sHasSpeedAccuracyMask == null) { Field declaredField = Location.class.getDeclaredField("HAS_SPEED_ACCURACY_MASK"); declaredField.setAccessible(true); sHasSpeedAccuracyMask = Integer.valueOf(declaredField.getInt(null)); } return sHasSpeedAccuracyMask.intValue(); } @SuppressLint({"SoonBlockedPrivateApi"}) public static int getHasBearingAccuracyMask() throws NoSuchFieldException, IllegalAccessException { if (sHasBearingAccuracyMask == null) { Field declaredField = Location.class.getDeclaredField("HAS_BEARING_ACCURACY_MASK"); declaredField.setAccessible(true); sHasBearingAccuracyMask = Integer.valueOf(declaredField.getInt(null)); } return sHasBearingAccuracyMask.intValue(); } @SuppressLint({"SoonBlockedPrivateApi"}) public static int getHasVerticalAccuracyMask() throws NoSuchFieldException, IllegalAccessException { if (sHasVerticalAccuracyMask == null) { Field declaredField = Location.class.getDeclaredField("HAS_VERTICAL_ACCURACY_MASK"); declaredField.setAccessible(true); sHasVerticalAccuracyMask = Integer.valueOf(declaredField.getInt(null)); } return sHasVerticalAccuracyMask.intValue(); } private static Bundle getOrCreateExtras(@NonNull Location location) { Bundle extras = location.getExtras(); if (extras != null) { return extras; } location.setExtras(new Bundle()); return location.getExtras(); } private static boolean containsExtra(@NonNull Location location, String str) { Bundle extras = location.getExtras(); return extras != null && extras.containsKey(str); } private static void removeExtra(@NonNull Location location, String str) { Bundle extras = location.getExtras(); if (extras != null) { extras.remove(str); if (extras.isEmpty()) { location.setExtras(null); } } } @RequiresApi(31) public static class Api31Impl { private Api31Impl() { } public static boolean isMock(Location location) { return location.isMock(); } } }