content: package androidx.core.location;
  
  import android.location.Location;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.SystemClock;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.util.concurrent.TimeUnit;
  
  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_SPEED_ACCURACY = "speedAccuracy";
      public static final String EXTRA_VERTICAL_ACCURACY = "verticalAccuracy";
      private static Method sSetIsFromMockProviderMethod;
  
      private static class Api17Impl {
          private Api17Impl() {
          }
  
          static long getElapsedRealtimeNanos(Location location) {
              return location.getElapsedRealtimeNanos();
          }
      }
  
      private static class Api18Impl {
          private Api18Impl() {
          }
  
          static boolean isMock(Location location) {
              return location.isFromMockProvider();
          }
      }
  
      private static class Api26Impl {
          private Api26Impl() {
          }
  
          static float getBearingAccuracyDegrees(Location location) {
              return location.getBearingAccuracyDegrees();
          }
  
          static float getSpeedAccuracyMetersPerSecond(Location location) {
              return location.getSpeedAccuracyMetersPerSecond();
          }
  
          static float getVerticalAccuracyMeters(Location location) {
              return location.getVerticalAccuracyMeters();
          }
  
          static boolean hasBearingAccuracy(Location location) {
              return location.hasBearingAccuracy();
          }
  
          static boolean hasSpeedAccuracy(Location location) {
              return location.hasSpeedAccuracy();
          }
  
          static boolean hasVerticalAccuracy(Location location) {
              return location.hasVerticalAccuracy();
          }
  
          static void setBearingAccuracyDegrees(Location location, float bearingAccuracyD) {
              location.setBearingAccuracyDegrees(bearingAccuracyD);
          }
  
          static void setSpeedAccuracyMetersPerSecond(Location location, float speedAccuracyMps) {
              location.setSpeedAccuracyMetersPerSecond(speedAccuracyMps);
          }
  
          static void setVerticalAccuracyMeters(Location location, float verticalAccuracyM) {
              location.setVerticalAccuracyMeters(verticalAccuracyM);
          }
      }
  
      private LocationCompat() {
      }
  
      public static float getBearingAccuracyDegrees(Location location) {
          if (Build.VERSION.SDK_INT >= 26) {
              return Api26Impl.getBearingAccuracyDegrees(location);
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              return 0.0f;
          }
          return extras.getFloat(EXTRA_BEARING_ACCURACY, 0.0f);
      }
  
      public static long getElapsedRealtimeMillis(Location location) {
          if (Build.VERSION.SDK_INT >= 17) {
              return TimeUnit.NANOSECONDS.toMillis(Api17Impl.getElapsedRealtimeNanos(location));
          }
          long currentTimeMillis = System.currentTimeMillis() - location.getTime();
          long elapsedRealtime = SystemClock.elapsedRealtime();
          if (currentTimeMillis < 0) {
              return elapsedRealtime;
          }
          if (currentTimeMillis > elapsedRealtime) {
              return 0;
          }
          return elapsedRealtime - currentTimeMillis;
      }
  
      public static long getElapsedRealtimeNanos(Location location) {
          return Build.VERSION.SDK_INT >= 17 ? Api17Impl.getElapsedRealtimeNanos(location) : TimeUnit.MILLISECONDS.toNanos(getElapsedRealtimeMillis(location));
      }
  
      private static Method getSetIsFromMockProviderMethod() throws NoSuchMethodException {
          if (sSetIsFromMockProviderMethod == null) {
              Method declaredMethod = Location.class.getDeclaredMethod("setIsFromMockProvider", new Class[]{Boolean.TYPE});
              sSetIsFromMockProviderMethod = declaredMethod;
              declaredMethod.setAccessible(true);
          }
          return sSetIsFromMockProviderMethod;
      }
  
      public static float getSpeedAccuracyMetersPerSecond(Location location) {
          if (Build.VERSION.SDK_INT >= 26) {
              return Api26Impl.getSpeedAccuracyMetersPerSecond(location);
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              return 0.0f;
          }
          return extras.getFloat(EXTRA_SPEED_ACCURACY, 0.0f);
      }
  
      public static float getVerticalAccuracyMeters(Location location) {
          if (Build.VERSION.SDK_INT >= 26) {
              return Api26Impl.getVerticalAccuracyMeters(location);
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              return 0.0f;
          }
          return extras.getFloat(EXTRA_VERTICAL_ACCURACY, 0.0f);
      }
  
      public static boolean hasBearingAccuracy(Location location) {
          if (Build.VERSION.SDK_INT >= 26) {
              return Api26Impl.hasBearingAccuracy(location);
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              return false;
          }
          return extras.containsKey(EXTRA_BEARING_ACCURACY);
      }
  
      public static boolean hasSpeedAccuracy(Location location) {
          if (Build.VERSION.SDK_INT >= 26) {
              return Api26Impl.hasSpeedAccuracy(location);
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              return false;
          }
          return extras.containsKey(EXTRA_SPEED_ACCURACY);
      }
  
      public static boolean hasVerticalAccuracy(Location location) {
          if (Build.VERSION.SDK_INT >= 26) {
              return Api26Impl.hasVerticalAccuracy(location);
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              return false;
          }
          return extras.containsKey(EXTRA_VERTICAL_ACCURACY);
      }
  
      public static boolean isMock(Location location) {
          if (Build.VERSION.SDK_INT >= 18) {
              return Api18Impl.isMock(location);
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              return false;
          }
          return extras.getBoolean(EXTRA_IS_MOCK, false);
      }
  
      public static void setBearingAccuracyDegrees(Location location, float bearingAccuracyD) {
          if (Build.VERSION.SDK_INT >= 26) {
              Api26Impl.setBearingAccuracyDegrees(location, bearingAccuracyD);
              return;
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              location.setExtras(new Bundle());
              extras = location.getExtras();
          }
          extras.putFloat(EXTRA_BEARING_ACCURACY, bearingAccuracyD);
      }
  
      public static void setMock(Location location, boolean mock) {
          if (Build.VERSION.SDK_INT >= 18) {
              try {
                  getSetIsFromMockProviderMethod().invoke(location, new Object[]{Boolean.valueOf(mock)});
              } catch (NoSuchMethodException e) {
                  NoSuchMethodError noSuchMethodError = new NoSuchMethodError();
                  noSuchMethodError.initCause(e);
                  throw noSuchMethodError;
              } catch (IllegalAccessException e2) {
                  IllegalAccessError illegalAccessError = new IllegalAccessError();
                  illegalAccessError.initCause(e2);
                  throw illegalAccessError;
              } catch (InvocationTargetException e3) {
                  throw new RuntimeException(e3);
              }
          } else {
              Bundle extras = location.getExtras();
              if (extras == null) {
                  if (mock) {
                      Bundle bundle = new Bundle();
                      bundle.putBoolean(EXTRA_IS_MOCK, true);
                      location.setExtras(bundle);
                  }
              } else if (mock) {
                  extras.putBoolean(EXTRA_IS_MOCK, true);
              } else {
                  extras.remove(EXTRA_IS_MOCK);
                  if (extras.isEmpty()) {
                      location.setExtras((Bundle) null);
                  }
              }
          }
      }
  
      public static void setSpeedAccuracyMetersPerSecond(Location location, float speedAccuracyMps) {
          if (Build.VERSION.SDK_INT >= 26) {
              Api26Impl.setSpeedAccuracyMetersPerSecond(location, speedAccuracyMps);
              return;
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              location.setExtras(new Bundle());
              extras = location.getExtras();
          }
          extras.putFloat(EXTRA_SPEED_ACCURACY, speedAccuracyMps);
      }
  
      public static void setVerticalAccuracyMeters(Location location, float verticalAccuracyM) {
          if (Build.VERSION.SDK_INT >= 26) {
              Api26Impl.setVerticalAccuracyMeters(location, verticalAccuracyM);
              return;
          }
          Bundle extras = location.getExtras();
          if (extras == null) {
              location.setExtras(new Bundle());
              extras = location.getExtras();
          }
          extras.putFloat(EXTRA_VERTICAL_ACCURACY, verticalAccuracyM);
      }
  }
  