333 lines
16 KiB
Java
333 lines
16 KiB
Java
|
package com.google.android.gms.location;
|
||
|
|
||
|
import android.app.Activity;
|
||
|
import android.app.PendingIntent;
|
||
|
import android.content.Context;
|
||
|
import android.location.Location;
|
||
|
import android.os.Looper;
|
||
|
import android.os.SystemClock;
|
||
|
import android.os.WorkSource;
|
||
|
import com.google.android.gms.common.api.Api;
|
||
|
import com.google.android.gms.common.api.GoogleApi;
|
||
|
import com.google.android.gms.common.api.internal.ListenerHolder;
|
||
|
import com.google.android.gms.common.api.internal.ListenerHolders;
|
||
|
import com.google.android.gms.common.api.internal.RegistrationMethods;
|
||
|
import com.google.android.gms.common.api.internal.RemoteCall;
|
||
|
import com.google.android.gms.common.api.internal.TaskApiCall;
|
||
|
import com.google.android.gms.common.internal.ClientIdentity;
|
||
|
import com.google.android.gms.common.internal.Preconditions;
|
||
|
import com.google.android.gms.common.util.WorkSourceUtil;
|
||
|
import com.google.android.gms.location.CurrentLocationRequest;
|
||
|
import com.google.android.gms.location.LastLocationRequest;
|
||
|
import com.google.android.gms.tasks.CancellationToken;
|
||
|
import com.google.android.gms.tasks.Continuation;
|
||
|
import com.google.android.gms.tasks.Task;
|
||
|
import com.google.android.gms.tasks.TaskCompletionSource;
|
||
|
import java.util.List;
|
||
|
import java.util.concurrent.Executor;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public class FusedLocationProviderClient extends GoogleApi<Api.ApiOptions.NoOptions> {
|
||
|
public static final String KEY_MOCK_LOCATION = "mockLocation";
|
||
|
public static final String KEY_VERTICAL_ACCURACY = "verticalAccuracy";
|
||
|
|
||
|
public FusedLocationProviderClient(Activity activity) {
|
||
|
super(activity, LocationServices.API, Api.ApiOptions.NO_OPTIONS, GoogleApi.Settings.DEFAULT_SETTINGS);
|
||
|
}
|
||
|
|
||
|
private final Task zza(final com.google.android.gms.internal.location.zzbf zzbfVar, final ListenerHolder listenerHolder) {
|
||
|
final zzaq zzaqVar = new zzaq(this, listenerHolder);
|
||
|
return doRegisterEventListener(RegistrationMethods.builder().register(new RemoteCall(this, zzaqVar, listenerHolder, zzbfVar) { // from class: com.google.android.gms.location.zzan
|
||
|
public final FusedLocationProviderClient zza;
|
||
|
public final zzaw zzb;
|
||
|
public final ListenerHolder zzc;
|
||
|
public final com.google.android.gms.internal.location.zzbf zzd;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
FusedLocationProviderClient fusedLocationProviderClient = this.zza;
|
||
|
zzaw zzawVar = this.zzb;
|
||
|
ListenerHolder listenerHolder2 = this.zzc;
|
||
|
((com.google.android.gms.internal.location.zzbe) obj).zzB(this.zzd, listenerHolder2, new zzau((TaskCompletionSource) obj2, new zzaf(fusedLocationProviderClient, zzawVar, listenerHolder2), null));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = this;
|
||
|
this.zzb = zzaqVar;
|
||
|
this.zzc = listenerHolder;
|
||
|
this.zzd = zzbfVar;
|
||
|
}
|
||
|
}).unregister(zzaqVar).withHolder(listenerHolder).setMethodKey(2436).build());
|
||
|
}
|
||
|
|
||
|
public Task<Void> flushLocations() {
|
||
|
return doWrite(TaskApiCall.builder().run(new RemoteCall() { // from class: com.google.android.gms.location.zzad
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
((com.google.android.gms.internal.location.zzbe) obj).zzs(new zzav((TaskCompletionSource) obj2));
|
||
|
}
|
||
|
}).setMethodKey(2422).build());
|
||
|
}
|
||
|
|
||
|
public Task<Location> getCurrentLocation(int i, final CancellationToken cancellationToken) {
|
||
|
LocationRequest create = LocationRequest.create();
|
||
|
create.setPriority(i);
|
||
|
create.setInterval(0L);
|
||
|
create.setFastestInterval(0L);
|
||
|
create.setExpirationDuration(30000L);
|
||
|
final com.google.android.gms.internal.location.zzbf zzc = com.google.android.gms.internal.location.zzbf.zzc(null, create);
|
||
|
zzc.zzd(true);
|
||
|
zzc.zze(30000L);
|
||
|
if (cancellationToken != null) {
|
||
|
Preconditions.checkArgument(true ^ cancellationToken.isCancellationRequested(), "cancellationToken may not be already canceled");
|
||
|
}
|
||
|
Task doRead = doRead(TaskApiCall.builder().run(new RemoteCall(this, zzc, cancellationToken) { // from class: com.google.android.gms.location.zzaa
|
||
|
public final FusedLocationProviderClient zza;
|
||
|
public final com.google.android.gms.internal.location.zzbf zzb;
|
||
|
public final CancellationToken zzc;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
FusedLocationProviderClient fusedLocationProviderClient = this.zza;
|
||
|
com.google.android.gms.internal.location.zzbf zzbfVar = this.zzb;
|
||
|
CancellationToken cancellationToken2 = this.zzc;
|
||
|
com.google.android.gms.internal.location.zzbe zzbeVar = (com.google.android.gms.internal.location.zzbe) obj;
|
||
|
TaskCompletionSource taskCompletionSource = (TaskCompletionSource) obj2;
|
||
|
CurrentLocationRequest.Builder builder = new CurrentLocationRequest.Builder();
|
||
|
builder.setPriority(zzbfVar.zzb().getPriority());
|
||
|
builder.setDurationMillis(zzbfVar.zzb().getExpirationTime() != Long.MAX_VALUE ? zzbfVar.zzb().getExpirationTime() - SystemClock.elapsedRealtime() : Long.MAX_VALUE);
|
||
|
builder.setMaxUpdateAgeMillis(zzbfVar.zza());
|
||
|
builder.zza(zzbfVar.zzg());
|
||
|
List<ClientIdentity> zzf = zzbfVar.zzf();
|
||
|
WorkSource workSource = new WorkSource();
|
||
|
for (ClientIdentity clientIdentity : zzf) {
|
||
|
WorkSourceUtil.add(workSource, clientIdentity.uid, clientIdentity.packageName);
|
||
|
}
|
||
|
builder.zzb(workSource);
|
||
|
zzbeVar.zzt(builder.build(), cancellationToken2, new zzap(fusedLocationProviderClient, taskCompletionSource));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = this;
|
||
|
this.zzb = zzc;
|
||
|
this.zzc = cancellationToken;
|
||
|
}
|
||
|
}).setMethodKey(2415).build());
|
||
|
if (cancellationToken == null) {
|
||
|
return doRead;
|
||
|
}
|
||
|
final TaskCompletionSource taskCompletionSource = new TaskCompletionSource(cancellationToken);
|
||
|
doRead.continueWith(new Continuation(taskCompletionSource) { // from class: com.google.android.gms.location.zzag
|
||
|
public final TaskCompletionSource zza;
|
||
|
|
||
|
@Override // com.google.android.gms.tasks.Continuation
|
||
|
public final Object then(Task task) {
|
||
|
TaskCompletionSource taskCompletionSource2 = this.zza;
|
||
|
String str = FusedLocationProviderClient.KEY_MOCK_LOCATION;
|
||
|
if (task.isSuccessful()) {
|
||
|
taskCompletionSource2.trySetResult((Location) task.getResult());
|
||
|
return null;
|
||
|
}
|
||
|
taskCompletionSource2.trySetException((Exception) Preconditions.checkNotNull(task.getException()));
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = taskCompletionSource;
|
||
|
}
|
||
|
});
|
||
|
return taskCompletionSource.getTask();
|
||
|
}
|
||
|
|
||
|
public Task<Location> getLastLocation() {
|
||
|
return doRead(TaskApiCall.builder().run(new RemoteCall(this) { // from class: com.google.android.gms.location.zzak
|
||
|
public final FusedLocationProviderClient zza;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
((com.google.android.gms.internal.location.zzbe) obj).zzu(new LastLocationRequest.Builder().build(), new zzat(this.zza, (TaskCompletionSource) obj2));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = this;
|
||
|
}
|
||
|
}).setMethodKey(2414).build());
|
||
|
}
|
||
|
|
||
|
public Task<LocationAvailability> getLocationAvailability() {
|
||
|
return doRead(TaskApiCall.builder().run(new RemoteCall() { // from class: com.google.android.gms.location.zzae
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
String str = FusedLocationProviderClient.KEY_MOCK_LOCATION;
|
||
|
((TaskCompletionSource) obj2).setResult(((com.google.android.gms.internal.location.zzbe) obj).zzp());
|
||
|
}
|
||
|
}).setMethodKey(2416).build());
|
||
|
}
|
||
|
|
||
|
public Task<Void> removeLocationUpdates(final PendingIntent pendingIntent) {
|
||
|
return doWrite(TaskApiCall.builder().run(new RemoteCall(pendingIntent) { // from class: com.google.android.gms.location.zzz
|
||
|
public final PendingIntent zza;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
((com.google.android.gms.internal.location.zzbe) obj).zzA(this.zza, new zzav((TaskCompletionSource) obj2));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = pendingIntent;
|
||
|
}
|
||
|
}).setMethodKey(2418).build());
|
||
|
}
|
||
|
|
||
|
public Task<Void> requestLocationUpdates(LocationRequest locationRequest, final PendingIntent pendingIntent) {
|
||
|
final com.google.android.gms.internal.location.zzbf zzc = com.google.android.gms.internal.location.zzbf.zzc(null, locationRequest);
|
||
|
return doWrite(TaskApiCall.builder().run(new RemoteCall(zzc, pendingIntent) { // from class: com.google.android.gms.location.zzac
|
||
|
public final com.google.android.gms.internal.location.zzbf zza;
|
||
|
public final PendingIntent zzb;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
((com.google.android.gms.internal.location.zzbe) obj).zzD(this.zza, this.zzb, new zzav((TaskCompletionSource) obj2));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = zzc;
|
||
|
this.zzb = pendingIntent;
|
||
|
}
|
||
|
}).setMethodKey(2417).build());
|
||
|
}
|
||
|
|
||
|
public Task<Void> setMockLocation(final Location location) {
|
||
|
Preconditions.checkArgument(location != null);
|
||
|
return doWrite(TaskApiCall.builder().run(new RemoteCall(this, location) { // from class: com.google.android.gms.location.zzal
|
||
|
public final FusedLocationProviderClient zza;
|
||
|
public final Location zzb;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
com.google.android.gms.internal.location.zzbe zzbeVar = (com.google.android.gms.internal.location.zzbe) obj;
|
||
|
zzbeVar.zzE(this.zzb, new zzas(this.zza, (TaskCompletionSource) obj2));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = this;
|
||
|
this.zzb = location;
|
||
|
}
|
||
|
}).setMethodKey(2421).build());
|
||
|
}
|
||
|
|
||
|
public Task<Void> setMockMode(final boolean z) {
|
||
|
return doWrite(TaskApiCall.builder().run(new RemoteCall(this, z) { // from class: com.google.android.gms.location.zzab
|
||
|
public final FusedLocationProviderClient zza;
|
||
|
public final boolean zzb;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
com.google.android.gms.internal.location.zzbe zzbeVar = (com.google.android.gms.internal.location.zzbe) obj;
|
||
|
zzbeVar.zzF(this.zzb, new zzas(this.zza, (TaskCompletionSource) obj2));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = this;
|
||
|
this.zzb = z;
|
||
|
}
|
||
|
}).setMethodKey(2420).build());
|
||
|
}
|
||
|
|
||
|
public FusedLocationProviderClient(Context context) {
|
||
|
super(context, LocationServices.API, Api.ApiOptions.NO_OPTIONS, GoogleApi.Settings.DEFAULT_SETTINGS);
|
||
|
}
|
||
|
|
||
|
public Task<Location> getLastLocation(final LastLocationRequest lastLocationRequest) {
|
||
|
return doRead(TaskApiCall.builder().run(new RemoteCall(this, lastLocationRequest) { // from class: com.google.android.gms.location.zzao
|
||
|
public final FusedLocationProviderClient zza;
|
||
|
public final LastLocationRequest zzb;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
com.google.android.gms.internal.location.zzbe zzbeVar = (com.google.android.gms.internal.location.zzbe) obj;
|
||
|
zzbeVar.zzu(this.zzb, new zzat(this.zza, (TaskCompletionSource) obj2));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = this;
|
||
|
this.zzb = lastLocationRequest;
|
||
|
}
|
||
|
}).setMethodKey(2414).setFeatures(zzy.zzf).build());
|
||
|
}
|
||
|
|
||
|
public Task<Void> removeLocationUpdates(LocationCallback locationCallback) {
|
||
|
return doUnregisterEventListener(ListenerHolders.createListenerKey(locationCallback, "LocationCallback"), 2418).continueWith(new Executor() { // from class: com.google.android.gms.location.zzaj
|
||
|
@Override // java.util.concurrent.Executor
|
||
|
public final void execute(Runnable runnable) {
|
||
|
runnable.run();
|
||
|
}
|
||
|
}, new Continuation() { // from class: com.google.android.gms.location.zzai
|
||
|
@Override // com.google.android.gms.tasks.Continuation
|
||
|
public final Object then(Task task) {
|
||
|
String str = FusedLocationProviderClient.KEY_MOCK_LOCATION;
|
||
|
return null;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public Task<Void> requestLocationUpdates(LocationRequest locationRequest, LocationCallback locationCallback, Looper looper) {
|
||
|
com.google.android.gms.internal.location.zzbf zzc = com.google.android.gms.internal.location.zzbf.zzc(null, locationRequest);
|
||
|
if (looper != null || (looper = Looper.myLooper()) != null) {
|
||
|
return zza(zzc, ListenerHolders.createListenerHolder(locationCallback, looper, "LocationCallback"));
|
||
|
}
|
||
|
throw new IllegalStateException();
|
||
|
}
|
||
|
|
||
|
public Task<Void> requestLocationUpdates(LocationRequest locationRequest, Executor executor, LocationCallback locationCallback) {
|
||
|
return zza(com.google.android.gms.internal.location.zzbf.zzc(null, locationRequest), ListenerHolders.createListenerHolder(locationCallback, executor, "LocationCallback"));
|
||
|
}
|
||
|
|
||
|
public Task<Location> getCurrentLocation(final CurrentLocationRequest currentLocationRequest, final CancellationToken cancellationToken) {
|
||
|
if (cancellationToken != null) {
|
||
|
Preconditions.checkArgument(!cancellationToken.isCancellationRequested(), "cancellationToken may not be already canceled");
|
||
|
}
|
||
|
Task doRead = doRead(TaskApiCall.builder().run(new RemoteCall(this, currentLocationRequest, cancellationToken) { // from class: com.google.android.gms.location.zzam
|
||
|
public final FusedLocationProviderClient zza;
|
||
|
public final CurrentLocationRequest zzb;
|
||
|
public final CancellationToken zzc;
|
||
|
|
||
|
@Override // com.google.android.gms.common.api.internal.RemoteCall
|
||
|
public final void accept(Object obj, Object obj2) {
|
||
|
com.google.android.gms.internal.location.zzbe zzbeVar = (com.google.android.gms.internal.location.zzbe) obj;
|
||
|
zzbeVar.zzt(this.zzb, this.zzc, new zzat(this.zza, (TaskCompletionSource) obj2));
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = this;
|
||
|
this.zzb = currentLocationRequest;
|
||
|
this.zzc = cancellationToken;
|
||
|
}
|
||
|
}).setFeatures(zzy.zze).setMethodKey(2415).build());
|
||
|
if (cancellationToken == null) {
|
||
|
return doRead;
|
||
|
}
|
||
|
final TaskCompletionSource taskCompletionSource = new TaskCompletionSource(cancellationToken);
|
||
|
doRead.continueWith(new Continuation(taskCompletionSource) { // from class: com.google.android.gms.location.zzah
|
||
|
public final TaskCompletionSource zza;
|
||
|
|
||
|
@Override // com.google.android.gms.tasks.Continuation
|
||
|
public final Object then(Task task) {
|
||
|
TaskCompletionSource taskCompletionSource2 = this.zza;
|
||
|
String str = FusedLocationProviderClient.KEY_MOCK_LOCATION;
|
||
|
if (task.isSuccessful()) {
|
||
|
taskCompletionSource2.trySetResult((Location) task.getResult());
|
||
|
return null;
|
||
|
}
|
||
|
taskCompletionSource2.trySetException((Exception) Preconditions.checkNotNull(task.getException()));
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.zza = taskCompletionSource;
|
||
|
}
|
||
|
});
|
||
|
return taskCompletionSource.getTask();
|
||
|
}
|
||
|
}
|