2021-06-27 20:44:35 +00:00
package androidx.core.location ;
2021-09-29 00:45:08 +00:00
import android.location.GnssStatus ;
import android.location.GpsStatus ;
import android.location.Location ;
import android.location.LocationListener ;
2021-06-27 20:44:35 +00:00
import android.location.LocationManager ;
import android.os.Build ;
2021-09-29 00:45:08 +00:00
import android.os.Bundle ;
import android.os.Handler ;
import android.os.Looper ;
import android.os.SystemClock ;
import androidx.annotation.DoNotInline ;
import androidx.annotation.GuardedBy ;
2021-06-27 20:44:35 +00:00
import androidx.annotation.NonNull ;
2021-09-29 00:45:08 +00:00
import androidx.annotation.Nullable ;
import androidx.annotation.RequiresApi ;
import androidx.annotation.RequiresPermission ;
import androidx.collection.SimpleArrayMap ;
import androidx.core.location.GnssStatusCompat ;
import androidx.core.os.CancellationSignal ;
import androidx.core.os.ExecutorCompat ;
import androidx.core.util.Consumer ;
import androidx.core.util.Preconditions ;
import java.lang.reflect.Field ;
import java.util.concurrent.Callable ;
import java.util.concurrent.ExecutionException ;
import java.util.concurrent.Executor ;
import java.util.concurrent.FutureTask ;
import java.util.concurrent.RejectedExecutionException ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.TimeoutException ;
2021-06-27 20:44:35 +00:00
public final class LocationManagerCompat {
2021-09-29 00:45:08 +00:00
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 ;
@GuardedBy ( " sGnssStatusListeners " )
private static final SimpleArrayMap < Object , Object > sGnssStatusListeners = new SimpleArrayMap < > ( ) ;
/* renamed from: androidx.core.location.LocationManagerCompat$1 reason: invalid class name */
public class AnonymousClass1 implements Runnable {
public final /* synthetic */ Consumer val$consumer ;
public final /* synthetic */ Location val$location ;
public AnonymousClass1 ( Consumer consumer , Location location ) {
this . val$consumer = consumer ;
this . val$location = location ;
}
@Override // java.lang.Runnable
public void run ( ) {
this . val$consumer . accept ( this . val$location ) ;
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$2 reason: invalid class name */
public class AnonymousClass2 implements CancellationSignal . OnCancelListener {
public final /* synthetic */ CancellableLocationListener val$listener ;
public AnonymousClass2 ( CancellableLocationListener cancellableLocationListener ) {
this . val$listener = cancellableLocationListener ;
}
@Override // androidx.core.os.CancellationSignal.OnCancelListener
@RequiresPermission ( anyOf = { " android.permission.ACCESS_COARSE_LOCATION " , " android.permission.ACCESS_FINE_LOCATION " } )
public void onCancel ( ) {
this . val$listener . cancel ( ) ;
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$3 reason: invalid class name */
public class AnonymousClass3 implements Callable < Boolean > {
public final /* synthetic */ LocationManager val$locationManager ;
public final /* synthetic */ GpsStatusTransport val$myTransport ;
public AnonymousClass3 ( LocationManager locationManager , GpsStatusTransport gpsStatusTransport ) {
this . val$locationManager = locationManager ;
this . val$myTransport = gpsStatusTransport ;
}
@Override // java.util.concurrent.Callable
@RequiresPermission ( " android.permission.ACCESS_FINE_LOCATION " )
public Boolean call ( ) {
return Boolean . valueOf ( this . val$locationManager . addGpsStatusListener ( this . val$myTransport ) ) ;
}
}
@RequiresApi ( 28 )
public static class Api28Impl {
private Api28Impl ( ) {
}
@DoNotInline
public static String getGnssHardwareModelName ( LocationManager locationManager ) {
return locationManager . getGnssHardwareModelName ( ) ;
}
@DoNotInline
public static int getGnssYearOfHardware ( LocationManager locationManager ) {
return locationManager . getGnssYearOfHardware ( ) ;
}
@DoNotInline
public static boolean isLocationEnabled ( LocationManager locationManager ) {
return locationManager . isLocationEnabled ( ) ;
}
}
@RequiresApi ( 30 )
public static class Api30Impl {
/* renamed from: androidx.core.location.LocationManagerCompat$Api30Impl$1 reason: invalid class name */
public class AnonymousClass1 implements java . util . function . Consumer < Location > {
public final /* synthetic */ Consumer val$consumer ;
public AnonymousClass1 ( Consumer consumer ) {
this . val$consumer = consumer ;
}
public void accept ( Location location ) {
this . val$consumer . accept ( location ) ;
}
}
private Api30Impl ( ) {
}
@RequiresPermission ( anyOf = { " android.permission.ACCESS_COARSE_LOCATION " , " android.permission.ACCESS_FINE_LOCATION " } )
@DoNotInline
public static void getCurrentLocation ( LocationManager locationManager , @NonNull String str , @Nullable CancellationSignal cancellationSignal , @NonNull Executor executor , @NonNull Consumer < Location > consumer ) {
locationManager . getCurrentLocation ( str , cancellationSignal ! = null ? ( android . os . CancellationSignal ) cancellationSignal . getCancellationSignalObject ( ) : null , executor , new AnonymousClass1 ( consumer ) ) ;
}
}
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
public Runnable mTimeoutRunnable ;
@GuardedBy ( " this " )
private boolean mTriggered ;
/* renamed from: androidx.core.location.LocationManagerCompat$CancellableLocationListener$1 reason: invalid class name */
public class AnonymousClass1 implements Runnable {
public AnonymousClass1 ( ) {
}
@Override // java.lang.Runnable
@RequiresPermission ( anyOf = { " android.permission.ACCESS_COARSE_LOCATION " , " android.permission.ACCESS_FINE_LOCATION " } )
public void run ( ) {
CancellableLocationListener cancellableLocationListener = CancellableLocationListener . this ;
cancellableLocationListener . mTimeoutRunnable = null ;
cancellableLocationListener . onLocationChanged ( null ) ;
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$CancellableLocationListener$2 reason: invalid class name */
public class AnonymousClass2 implements Runnable {
public final /* synthetic */ Consumer val$consumer ;
public final /* synthetic */ Location val$location ;
public AnonymousClass2 ( Consumer consumer , Location location ) {
this . val$consumer = consumer ;
this . val$location = location ;
}
@Override // java.lang.Runnable
public void run ( ) {
this . val$consumer . accept ( this . val$location ) ;
}
}
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 " } )
private void cleanup ( ) {
this . mConsumer = null ;
this . mLocationManager . removeUpdates ( this ) ;
Runnable runnable = this . mTimeoutRunnable ;
if ( runnable ! = null ) {
this . mTimeoutHandler . removeCallbacks ( runnable ) ;
this . mTimeoutRunnable = null ;
}
}
@RequiresPermission ( anyOf = { " android.permission.ACCESS_COARSE_LOCATION " , " android.permission.ACCESS_FINE_LOCATION " } )
public void cancel ( ) {
synchronized ( this ) {
if ( ! this . mTriggered ) {
this . mTriggered = true ;
cleanup ( ) ;
}
}
}
@Override // android.location.LocationListener
@RequiresPermission ( anyOf = { " android.permission.ACCESS_COARSE_LOCATION " , " android.permission.ACCESS_FINE_LOCATION " } )
public void onLocationChanged ( @Nullable Location location ) {
synchronized ( this ) {
if ( ! this . mTriggered ) {
this . mTriggered = true ;
this . mExecutor . execute ( new AnonymousClass2 ( this . mConsumer , location ) ) ;
cleanup ( ) ;
}
}
}
@Override // android.location.LocationListener
@RequiresPermission ( anyOf = { " android.permission.ACCESS_COARSE_LOCATION " , " android.permission.ACCESS_FINE_LOCATION " } )
public void onProviderDisabled ( @NonNull String str ) {
onLocationChanged ( null ) ;
}
@Override // android.location.LocationListener
public void onProviderEnabled ( @NonNull String str ) {
}
@Override // android.location.LocationListener
public void onStatusChanged ( String str , int i , Bundle bundle ) {
}
public void startTimeout ( long j ) {
synchronized ( this ) {
if ( ! this . mTriggered ) {
AnonymousClass1 r0 = new AnonymousClass1 ( ) ;
this . mTimeoutRunnable = r0 ;
this . mTimeoutHandler . postDelayed ( r0 , j ) ;
}
}
}
}
@RequiresApi ( 30 )
public static class GnssStatusTransport extends GnssStatus . Callback {
public 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 onFirstFix ( int i ) {
this . mCallback . onFirstFix ( i ) ;
}
@Override // android.location.GnssStatus.Callback
public void onSatelliteStatusChanged ( GnssStatus gnssStatus ) {
this . mCallback . onSatelliteStatusChanged ( GnssStatusCompat . wrap ( gnssStatus ) ) ;
}
@Override // android.location.GnssStatus.Callback
public void onStarted ( ) {
this . mCallback . onStarted ( ) ;
}
@Override // android.location.GnssStatus.Callback
public void onStopped ( ) {
this . mCallback . onStopped ( ) ;
}
}
public static class GpsStatusTransport implements GpsStatus . Listener {
public final GnssStatusCompat . Callback mCallback ;
@Nullable
public volatile Executor mExecutor ;
private final LocationManager mLocationManager ;
/* renamed from: androidx.core.location.LocationManagerCompat$GpsStatusTransport$1 reason: invalid class name */
public class AnonymousClass1 implements Runnable {
public final /* synthetic */ Executor val$executor ;
public AnonymousClass1 ( Executor executor ) {
this . val$executor = executor ;
}
@Override // java.lang.Runnable
public void run ( ) {
if ( GpsStatusTransport . this . mExecutor = = this . val$executor ) {
GpsStatusTransport . this . mCallback . onStarted ( ) ;
}
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$GpsStatusTransport$2 reason: invalid class name */
public class AnonymousClass2 implements Runnable {
public final /* synthetic */ Executor val$executor ;
public AnonymousClass2 ( Executor executor ) {
this . val$executor = executor ;
}
@Override // java.lang.Runnable
public void run ( ) {
if ( GpsStatusTransport . this . mExecutor = = this . val$executor ) {
GpsStatusTransport . this . mCallback . onStopped ( ) ;
}
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$GpsStatusTransport$3 reason: invalid class name */
public class AnonymousClass3 implements Runnable {
public final /* synthetic */ Executor val$executor ;
public final /* synthetic */ int val$ttff ;
public AnonymousClass3 ( Executor executor , int i ) {
this . val$executor = executor ;
this . val$ttff = i ;
}
@Override // java.lang.Runnable
public void run ( ) {
if ( GpsStatusTransport . this . mExecutor = = this . val$executor ) {
GpsStatusTransport . this . mCallback . onFirstFix ( this . val$ttff ) ;
}
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$GpsStatusTransport$4 reason: invalid class name */
public class AnonymousClass4 implements Runnable {
public final /* synthetic */ Executor val$executor ;
public final /* synthetic */ GnssStatusCompat val$gnssStatus ;
public AnonymousClass4 ( Executor executor , GnssStatusCompat gnssStatusCompat ) {
this . val$executor = executor ;
this . val$gnssStatus = gnssStatusCompat ;
}
@Override // java.lang.Runnable
public void run ( ) {
if ( GpsStatusTransport . this . mExecutor = = this . val$executor ) {
GpsStatusTransport . this . mCallback . onSatelliteStatusChanged ( this . val$gnssStatus ) ;
}
}
}
public GpsStatusTransport ( LocationManager locationManager , GnssStatusCompat . Callback callback ) {
Preconditions . checkArgument ( callback ! = null , " invalid null callback " ) ;
this . mLocationManager = locationManager ;
this . mCallback = callback ;
}
@Override // android.location.GpsStatus.Listener
@RequiresPermission ( " android.permission.ACCESS_FINE_LOCATION " )
public void onGpsStatusChanged ( int i ) {
GpsStatus gpsStatus ;
Executor executor = this . mExecutor ;
if ( executor ! = null ) {
if ( i = = 1 ) {
executor . execute ( new AnonymousClass1 ( executor ) ) ;
} else if ( i = = 2 ) {
executor . execute ( new AnonymousClass2 ( executor ) ) ;
} else if ( i = = 3 ) {
GpsStatus gpsStatus2 = this . mLocationManager . getGpsStatus ( null ) ;
if ( gpsStatus2 ! = null ) {
executor . execute ( new AnonymousClass3 ( executor , gpsStatus2 . getTimeToFirstFix ( ) ) ) ;
}
} else if ( i = = 4 & & ( gpsStatus = this . mLocationManager . getGpsStatus ( null ) ) ! = null ) {
executor . execute ( new AnonymousClass4 ( executor , GnssStatusCompat . wrap ( gpsStatus ) ) ) ;
}
}
}
public void register ( Executor executor ) {
Preconditions . checkState ( this . mExecutor = = null ) ;
this . mExecutor = executor ;
}
public void unregister ( ) {
this . mExecutor = 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 ) ) ) {
throw new RejectedExecutionException ( this . mHandler + " is shutting down " ) ;
}
}
}
@RequiresApi ( 24 )
public static class PreRGnssStatusTransport extends GnssStatus . Callback {
public final GnssStatusCompat . Callback mCallback ;
@Nullable
public volatile Executor mExecutor ;
/* renamed from: androidx.core.location.LocationManagerCompat$PreRGnssStatusTransport$1 reason: invalid class name */
public class AnonymousClass1 implements Runnable {
public final /* synthetic */ Executor val$executor ;
public AnonymousClass1 ( Executor executor ) {
this . val$executor = executor ;
}
@Override // java.lang.Runnable
public void run ( ) {
if ( PreRGnssStatusTransport . this . mExecutor = = this . val$executor ) {
PreRGnssStatusTransport . this . mCallback . onStarted ( ) ;
}
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$PreRGnssStatusTransport$2 reason: invalid class name */
public class AnonymousClass2 implements Runnable {
public final /* synthetic */ Executor val$executor ;
public AnonymousClass2 ( Executor executor ) {
this . val$executor = executor ;
}
@Override // java.lang.Runnable
public void run ( ) {
if ( PreRGnssStatusTransport . this . mExecutor = = this . val$executor ) {
PreRGnssStatusTransport . this . mCallback . onStopped ( ) ;
}
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$PreRGnssStatusTransport$3 reason: invalid class name */
public class AnonymousClass3 implements Runnable {
public final /* synthetic */ Executor val$executor ;
public final /* synthetic */ int val$ttffMillis ;
public AnonymousClass3 ( Executor executor , int i ) {
this . val$executor = executor ;
this . val$ttffMillis = i ;
}
@Override // java.lang.Runnable
public void run ( ) {
if ( PreRGnssStatusTransport . this . mExecutor = = this . val$executor ) {
PreRGnssStatusTransport . this . mCallback . onFirstFix ( this . val$ttffMillis ) ;
}
}
}
/* renamed from: androidx.core.location.LocationManagerCompat$PreRGnssStatusTransport$4 reason: invalid class name */
public class AnonymousClass4 implements Runnable {
public final /* synthetic */ Executor val$executor ;
public final /* synthetic */ GnssStatus val$status ;
public AnonymousClass4 ( Executor executor , GnssStatus gnssStatus ) {
this . val$executor = executor ;
this . val$status = gnssStatus ;
}
@Override // java.lang.Runnable
public void run ( ) {
if ( PreRGnssStatusTransport . this . mExecutor = = this . val$executor ) {
PreRGnssStatusTransport . this . mCallback . onSatelliteStatusChanged ( GnssStatusCompat . wrap ( this . val$status ) ) ;
}
}
}
public PreRGnssStatusTransport ( GnssStatusCompat . Callback callback ) {
Preconditions . checkArgument ( callback ! = null , " invalid null callback " ) ;
this . mCallback = callback ;
}
@Override // android.location.GnssStatus.Callback
public void onFirstFix ( int i ) {
Executor executor = this . mExecutor ;
if ( executor ! = null ) {
executor . execute ( new AnonymousClass3 ( executor , i ) ) ;
}
}
@Override // android.location.GnssStatus.Callback
public void onSatelliteStatusChanged ( GnssStatus gnssStatus ) {
Executor executor = this . mExecutor ;
if ( executor ! = null ) {
executor . execute ( new AnonymousClass4 ( executor , gnssStatus ) ) ;
}
}
@Override // android.location.GnssStatus.Callback
public void onStarted ( ) {
Executor executor = this . mExecutor ;
if ( executor ! = null ) {
executor . execute ( new AnonymousClass1 ( executor ) ) ;
}
}
@Override // android.location.GnssStatus.Callback
public void onStopped ( ) {
Executor executor = this . mExecutor ;
if ( executor ! = null ) {
executor . execute ( new AnonymousClass2 ( executor ) ) ;
}
}
public void register ( Executor executor ) {
boolean z2 = true ;
Preconditions . checkArgument ( executor ! = null , " invalid null executor " ) ;
if ( this . mExecutor ! = null ) {
z2 = false ;
}
Preconditions . checkState ( z2 ) ;
this . mExecutor = executor ;
}
public void unregister ( ) {
this . mExecutor = null ;
}
}
2021-06-27 20:44:35 +00:00
private LocationManagerCompat ( ) {
}
2021-09-29 00:45:08 +00:00
@RequiresPermission ( anyOf = { " android.permission.ACCESS_COARSE_LOCATION " , " android.permission.ACCESS_FINE_LOCATION " } )
public static void getCurrentLocation ( @NonNull LocationManager locationManager , @NonNull String str , @Nullable CancellationSignal cancellationSignal , @NonNull Executor executor , @NonNull Consumer < Location > consumer ) {
if ( Build . VERSION . SDK_INT > = 30 ) {
Api30Impl . getCurrentLocation ( locationManager , str , cancellationSignal , executor , consumer ) ;
return ;
}
if ( cancellationSignal ! = null ) {
cancellationSignal . throwIfCanceled ( ) ;
}
Location lastKnownLocation = locationManager . getLastKnownLocation ( str ) ;
if ( lastKnownLocation = = null | | SystemClock . elapsedRealtime ( ) - LocationCompat . getElapsedRealtimeMillis ( lastKnownLocation ) > = 10000 ) {
CancellableLocationListener cancellableLocationListener = new CancellableLocationListener ( locationManager , executor , consumer ) ;
locationManager . requestLocationUpdates ( str , 0 , 0 . 0f , cancellableLocationListener , Looper . getMainLooper ( ) ) ;
if ( cancellationSignal ! = null ) {
cancellationSignal . setOnCancelListener ( new AnonymousClass2 ( cancellableLocationListener ) ) ;
}
cancellableLocationListener . startTimeout ( 30000 ) ;
return ;
}
executor . execute ( new AnonymousClass1 ( consumer , lastKnownLocation ) ) ;
}
@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 ;
}
2021-06-27 20:44:35 +00:00
public static boolean isLocationEnabled ( @NonNull LocationManager locationManager ) {
2021-09-29 00:45:08 +00:00
return Build . VERSION . SDK_INT > = 28 ? Api28Impl . isLocationEnabled ( locationManager ) : locationManager . isProviderEnabled ( " network " ) | | locationManager . isProviderEnabled ( " gps " ) ;
}
/* JADX WARNING: Removed duplicated region for block: B:103:0x0129 */
/* JADX WARNING: Removed duplicated region for block: B:93:0x010a A[Catch:{ ExecutionException -> 0x0100, TimeoutException -> 0x00e7, all -> 0x00e4, all -> 0x0126 }] */
/* JADX WARNING: Removed duplicated region for block: B:99:0x011f A[Catch:{ ExecutionException -> 0x0100, TimeoutException -> 0x00e7, all -> 0x00e4, all -> 0x0126 }] */
@RequiresPermission ( " android.permission.ACCESS_FINE_LOCATION " )
private static boolean registerGnssStatusCallback ( LocationManager locationManager , Handler handler , Executor executor , GnssStatusCompat . Callback callback ) {
Throwable th ;
ExecutionException e ;
TimeoutException e2 ;
int i = Build . VERSION . SDK_INT ;
boolean z2 = true ;
if ( i > = 30 ) {
SimpleArrayMap < Object , Object > simpleArrayMap = sGnssStatusListeners ;
synchronized ( simpleArrayMap ) {
GnssStatus . Callback callback2 = ( GnssStatusTransport ) simpleArrayMap . get ( callback ) ;
if ( callback2 = = null ) {
callback2 = new GnssStatusTransport ( callback ) ;
}
if ( ! locationManager . registerGnssStatusCallback ( executor , callback2 ) ) {
return false ;
}
simpleArrayMap . put ( callback , callback2 ) ;
return true ;
}
} else if ( i > = 24 ) {
Preconditions . checkArgument ( handler ! = null ) ;
SimpleArrayMap < Object , Object > simpleArrayMap2 = sGnssStatusListeners ;
synchronized ( simpleArrayMap2 ) {
PreRGnssStatusTransport preRGnssStatusTransport = ( PreRGnssStatusTransport ) simpleArrayMap2 . get ( callback ) ;
if ( preRGnssStatusTransport = = null ) {
preRGnssStatusTransport = new PreRGnssStatusTransport ( callback ) ;
} else {
preRGnssStatusTransport . unregister ( ) ;
}
preRGnssStatusTransport . register ( executor ) ;
if ( ! locationManager . registerGnssStatusCallback ( preRGnssStatusTransport , handler ) ) {
return false ;
}
simpleArrayMap2 . put ( callback , preRGnssStatusTransport ) ;
return true ;
}
} else {
Preconditions . checkArgument ( handler ! = null ) ;
SimpleArrayMap < Object , Object > simpleArrayMap3 = sGnssStatusListeners ;
synchronized ( simpleArrayMap3 ) {
GpsStatusTransport gpsStatusTransport = ( GpsStatusTransport ) simpleArrayMap3 . get ( callback ) ;
if ( gpsStatusTransport = = null ) {
gpsStatusTransport = new GpsStatusTransport ( locationManager , callback ) ;
} else {
gpsStatusTransport . unregister ( ) ;
}
gpsStatusTransport . register ( executor ) ;
FutureTask futureTask = new FutureTask ( new AnonymousClass3 ( locationManager , gpsStatusTransport ) ) ;
if ( Looper . myLooper ( ) = = handler . getLooper ( ) ) {
futureTask . run ( ) ;
} else if ( ! handler . post ( futureTask ) ) {
throw new IllegalStateException ( handler + " is shutting down " ) ;
}
try {
2022-02-14 21:43:51 +00:00
long nanos = TimeUnit . SECONDS . toNanos ( 5 ) ;
2021-09-29 00:45:08 +00:00
boolean z3 = false ;
while ( true ) {
try {
break ;
} catch ( InterruptedException unused ) {
try {
nanos = ( System . nanoTime ( ) + nanos ) - System . nanoTime ( ) ;
z3 = true ;
} catch ( ExecutionException e3 ) {
e = e3 ;
if ( e . getCause ( ) instanceof RuntimeException ) {
}
} catch ( TimeoutException e4 ) {
e2 = e4 ;
throw new IllegalStateException ( handler + " appears to be blocked, please run registerGnssStatusCallback() directly on a Looper thread or ensure the main Looper is not blocked by this thread " , e2 ) ;
}
} catch ( ExecutionException e5 ) {
e = e5 ;
if ( e . getCause ( ) instanceof RuntimeException ) {
}
} catch ( TimeoutException e6 ) {
e2 = e6 ;
z2 = z3 ;
throw new IllegalStateException ( handler + " appears to be blocked, please run registerGnssStatusCallback() directly on a Looper thread or ensure the main Looper is not blocked by this thread " , e2 ) ;
} catch ( Throwable th2 ) {
th = th2 ;
z2 = z3 ;
if ( z2 ) {
}
throw th ;
}
}
if ( ( ( Boolean ) futureTask . get ( nanos , TimeUnit . NANOSECONDS ) ) . booleanValue ( ) ) {
sGnssStatusListeners . put ( callback , gpsStatusTransport ) ;
if ( z3 ) {
Thread . currentThread ( ) . interrupt ( ) ;
}
return true ;
}
if ( z3 ) {
Thread . currentThread ( ) . interrupt ( ) ;
}
return false ;
} catch ( ExecutionException e7 ) {
e = e7 ;
if ( e . getCause ( ) instanceof RuntimeException ) {
throw ( ( RuntimeException ) e . getCause ( ) ) ;
} else if ( e . getCause ( ) instanceof Error ) {
throw ( ( Error ) e . getCause ( ) ) ;
} else {
throw new IllegalStateException ( e ) ;
}
} catch ( TimeoutException e8 ) {
e2 = e8 ;
z2 = false ;
throw new IllegalStateException ( handler + " appears to be blocked, please run registerGnssStatusCallback() directly on a Looper thread or ensure the main Looper is not blocked by this thread " , e2 ) ;
} catch ( Throwable th3 ) {
th = th3 ;
if ( z2 ) {
}
throw th ;
}
}
}
}
@RequiresPermission ( " android.permission.ACCESS_FINE_LOCATION " )
public static boolean registerGnssStatusCallback ( @NonNull LocationManager locationManager , @NonNull GnssStatusCompat . Callback callback , @NonNull Handler handler ) {
return Build . VERSION . SDK_INT > = 30 ? registerGnssStatusCallback ( locationManager , ExecutorCompat . create ( handler ) , callback ) : 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 ) ;
}
public static void unregisterGnssStatusCallback ( @NonNull LocationManager locationManager , @NonNull GnssStatusCompat . Callback callback ) {
int i = Build . VERSION . SDK_INT ;
if ( i > = 30 ) {
SimpleArrayMap < Object , Object > simpleArrayMap = sGnssStatusListeners ;
synchronized ( simpleArrayMap ) {
GnssStatus . Callback callback2 = ( GnssStatusTransport ) simpleArrayMap . remove ( callback ) ;
if ( callback2 ! = null ) {
locationManager . unregisterGnssStatusCallback ( callback2 ) ;
}
}
} else if ( i > = 24 ) {
SimpleArrayMap < Object , Object > simpleArrayMap2 = sGnssStatusListeners ;
synchronized ( simpleArrayMap2 ) {
PreRGnssStatusTransport preRGnssStatusTransport = ( PreRGnssStatusTransport ) simpleArrayMap2 . remove ( callback ) ;
if ( preRGnssStatusTransport ! = null ) {
preRGnssStatusTransport . unregister ( ) ;
locationManager . unregisterGnssStatusCallback ( preRGnssStatusTransport ) ;
}
}
} else {
SimpleArrayMap < Object , Object > simpleArrayMap3 = sGnssStatusListeners ;
synchronized ( simpleArrayMap3 ) {
GpsStatusTransport gpsStatusTransport = ( GpsStatusTransport ) simpleArrayMap3 . remove ( callback ) ;
if ( gpsStatusTransport ! = null ) {
gpsStatusTransport . unregister ( ) ;
locationManager . removeGpsStatusListener ( gpsStatusTransport ) ;
}
}
}
2021-06-27 20:44:35 +00:00
}
}