mirror of https://github.com/NekoX-Dev/NekoX.git
[TF][KILL] remove fusedlocationprovider
(cherry picked from commit ff1f6ce18ea02936ea20020e711a29da1ba27112)
This commit is contained in:
parent
84acf56d38
commit
c72c70c46e
|
@ -8,6 +8,7 @@
|
|||
|
||||
package org.telegram.messenger;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Address;
|
||||
|
@ -22,17 +23,6 @@ import android.text.TextUtils;
|
|||
import android.util.LongSparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
import com.google.android.gms.common.api.GoogleApiClient;
|
||||
import com.google.android.gms.common.api.PendingResult;
|
||||
import com.google.android.gms.common.api.Status;
|
||||
import com.google.android.gms.location.LocationRequest;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.location.LocationSettingsRequest;
|
||||
import com.google.android.gms.location.LocationSettingsResult;
|
||||
import com.google.android.gms.location.LocationSettingsStatusCodes;
|
||||
|
||||
import org.telegram.SQLite.SQLiteCursor;
|
||||
import org.telegram.SQLite.SQLitePreparedStatement;
|
||||
import org.telegram.tgnet.NativeByteBuffer;
|
||||
|
@ -44,7 +34,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocationController extends BaseController implements NotificationCenter.NotificationCenterDelegate, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
||||
public class LocationController extends BaseController implements NotificationCenter.NotificationCenterDelegate {
|
||||
|
||||
private LongSparseArray<SharingLocationInfo> sharingLocationsMap = new LongSparseArray<>();
|
||||
private ArrayList<SharingLocationInfo> sharingLocations = new ArrayList<>();
|
||||
|
@ -54,7 +44,6 @@ public class LocationController extends BaseController implements NotificationCe
|
|||
private GpsLocationListener gpsLocationListener = new GpsLocationListener();
|
||||
private GpsLocationListener networkLocationListener = new GpsLocationListener();
|
||||
private GpsLocationListener passiveLocationListener = new GpsLocationListener();
|
||||
private FusedLocationListener fusedLocationListener = new FusedLocationListener();
|
||||
private Location lastKnownLocation;
|
||||
private long lastLocationSendTime;
|
||||
private boolean locationSentSinceLastGoogleMapUpdate = true;
|
||||
|
@ -71,10 +60,6 @@ public class LocationController extends BaseController implements NotificationCe
|
|||
public ArrayList<SharingLocationInfo> sharingLocationsUI = new ArrayList<>();
|
||||
private LongSparseArray<SharingLocationInfo> sharingLocationsMapUI = new LongSparseArray<>();
|
||||
|
||||
private Boolean playServicesAvailable;
|
||||
private boolean wasConnectedToPlayServices;
|
||||
private GoogleApiClient googleApiClient;
|
||||
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
|
||||
private final static long UPDATE_INTERVAL = 1000, FASTEST_INTERVAL = 1000;
|
||||
private final static int BACKGROUD_UPDATE_TIME = 30 * 1000;
|
||||
private final static int LOCATION_ACQUIRE_TIME = 10 * 1000;
|
||||
|
@ -85,8 +70,6 @@ public class LocationController extends BaseController implements NotificationCe
|
|||
private ArrayList<TLRPC.TL_peerLocated> cachedNearbyUsers = new ArrayList<>();
|
||||
private ArrayList<TLRPC.TL_peerLocated> cachedNearbyChats = new ArrayList<>();
|
||||
|
||||
private LocationRequest locationRequest;
|
||||
|
||||
private static volatile LocationController[] Instance = new LocationController[UserConfig.MAX_ACCOUNT_COUNT];
|
||||
|
||||
public static LocationController getInstance(int num) {
|
||||
|
@ -144,30 +127,10 @@ public class LocationController extends BaseController implements NotificationCe
|
|||
}
|
||||
}
|
||||
|
||||
private class FusedLocationListener implements com.google.android.gms.location.LocationListener {
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
setLastKnownLocation(location);
|
||||
}
|
||||
}
|
||||
|
||||
public LocationController(int instance) {
|
||||
super(instance);
|
||||
|
||||
locationManager = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);
|
||||
googleApiClient = new GoogleApiClient.Builder(ApplicationLoader.applicationContext).
|
||||
addApi(LocationServices.API).
|
||||
addConnectionCallbacks(this).
|
||||
addOnConnectionFailedListener(this).build();
|
||||
|
||||
locationRequest = new LocationRequest();
|
||||
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||
locationRequest.setInterval(UPDATE_INTERVAL);
|
||||
locationRequest.setFastestInterval(FASTEST_INTERVAL);
|
||||
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
LocationController locationController = getAccountInstance().getLocationController();
|
||||
|
@ -275,93 +238,6 @@ public class LocationController extends BaseController implements NotificationCe
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(Bundle bundle) {
|
||||
wasConnectedToPlayServices = true;
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
|
||||
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
|
||||
result.setResultCallback(locationSettingsResult -> {
|
||||
final Status status = locationSettingsResult.getStatus();
|
||||
switch (status.getStatusCode()) {
|
||||
case LocationSettingsStatusCodes.SUCCESS:
|
||||
startFusedLocationRequest(true);
|
||||
break;
|
||||
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
|
||||
Utilities.stageQueue.postRunnable(() -> {
|
||||
if (lookingForPeopleNearby || !sharingLocations.isEmpty()) {
|
||||
AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.needShowPlayServicesAlert, status));
|
||||
}
|
||||
});
|
||||
break;
|
||||
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
|
||||
Utilities.stageQueue.postRunnable(() -> {
|
||||
playServicesAvailable = false;
|
||||
try {
|
||||
googleApiClient.disconnect();
|
||||
start();
|
||||
} catch (Throwable ignore) {
|
||||
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
startFusedLocationRequest(true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void startFusedLocationRequest(boolean permissionsGranted) {
|
||||
Utilities.stageQueue.postRunnable(() -> {
|
||||
if (!permissionsGranted) {
|
||||
playServicesAvailable = false;
|
||||
}
|
||||
if (shareMyCurrentLocation || lookingForPeopleNearby || !sharingLocations.isEmpty()) {
|
||||
if (permissionsGranted) {
|
||||
try {
|
||||
setLastKnownLocation(LocationServices.FusedLocationApi.getLastLocation(googleApiClient));
|
||||
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, fusedLocationListener);
|
||||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionSuspended(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFailed(ConnectionResult connectionResult) {
|
||||
if (wasConnectedToPlayServices) {
|
||||
return;
|
||||
}
|
||||
playServicesAvailable = false;
|
||||
if (started) {
|
||||
started = false;
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkPlayServices() {
|
||||
if (playServicesAvailable == null) {
|
||||
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
|
||||
int resultCode = apiAvailability.isGooglePlayServicesAvailable(ApplicationLoader.applicationContext);
|
||||
playServicesAvailable = resultCode == ConnectionResult.SUCCESS;
|
||||
}
|
||||
return playServicesAvailable;
|
||||
}
|
||||
|
||||
private void broadcastLastKnownLocation(boolean cancelCurrent) {
|
||||
if (lastKnownLocation == null) {
|
||||
return;
|
||||
|
@ -807,6 +683,8 @@ public class LocationController extends BaseController implements NotificationCe
|
|||
setLastKnownLocation(location);
|
||||
}
|
||||
|
||||
// TFOSS it asks properly anyway
|
||||
@SuppressLint("MissingPermission")
|
||||
private void start() {
|
||||
if (started) {
|
||||
return;
|
||||
|
@ -814,14 +692,6 @@ public class LocationController extends BaseController implements NotificationCe
|
|||
lastLocationStartTime = SystemClock.elapsedRealtime();
|
||||
started = true;
|
||||
boolean ok = false;
|
||||
if (checkPlayServices()) {
|
||||
try {
|
||||
googleApiClient.connect();
|
||||
ok = true;
|
||||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
try {
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 0, gpsLocationListener);
|
||||
|
@ -856,14 +726,6 @@ public class LocationController extends BaseController implements NotificationCe
|
|||
return;
|
||||
}
|
||||
started = false;
|
||||
if (checkPlayServices()) {
|
||||
try {
|
||||
LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, fusedLocationListener);
|
||||
googleApiClient.disconnect();
|
||||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
}
|
||||
locationManager.removeUpdates(gpsLocationListener);
|
||||
if (empty) {
|
||||
locationManager.removeUpdates(networkLocationListener);
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.graphics.Point;
|
|||
import android.graphics.Shader;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.location.Location;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -49,10 +50,6 @@ import android.widget.LinearLayout;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.common.api.Status;
|
||||
import com.microsoft.appcenter.AppCenter;
|
||||
import com.microsoft.appcenter.analytics.Analytics;
|
||||
|
||||
import org.telegram.messenger.AccountInstance;
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.BuildVars;
|
||||
|
@ -231,13 +228,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
|||
}
|
||||
}
|
||||
|
||||
private static final int PLAY_SERVICES_REQUEST_CHECK_SETTINGS = 140;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
ApplicationLoader.postInitApplication();
|
||||
AppCenter.start(getApplication(), "033a70ca-ea8d-4c2f-8c2c-b37f1b47f766", Analytics.class);
|
||||
AndroidUtilities.checkDisplaySize(this, getResources().getConfiguration());
|
||||
currentAccount = UserConfig.selectedAccount;
|
||||
if (!UserConfig.getInstance(currentAccount).isClientActivated()) {
|
||||
|
@ -2812,26 +2805,22 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
|||
UserConfig.getInstance(currentAccount).saveConfig(false);
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == PLAY_SERVICES_REQUEST_CHECK_SETTINGS) {
|
||||
LocationController.getInstance(currentAccount).startFusedLocationRequest(resultCode == Activity.RESULT_OK);
|
||||
} else {
|
||||
ThemeEditorView editorView = ThemeEditorView.getInstance();
|
||||
if (editorView != null) {
|
||||
editorView.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
if (actionBarLayout.fragmentsStack.size() != 0) {
|
||||
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
|
||||
ThemeEditorView editorView = ThemeEditorView.getInstance();
|
||||
if (editorView != null) {
|
||||
editorView.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
if (actionBarLayout.fragmentsStack.size() != 0) {
|
||||
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
|
||||
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
||||
}
|
||||
if (AndroidUtilities.isTablet()) {
|
||||
if (rightActionBarLayout.fragmentsStack.size() != 0) {
|
||||
BaseFragment fragment = rightActionBarLayout.fragmentsStack.get(rightActionBarLayout.fragmentsStack.size() - 1);
|
||||
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
||||
}
|
||||
if (AndroidUtilities.isTablet()) {
|
||||
if (rightActionBarLayout.fragmentsStack.size() != 0) {
|
||||
BaseFragment fragment = rightActionBarLayout.fragmentsStack.get(rightActionBarLayout.fragmentsStack.size() - 1);
|
||||
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
||||
}
|
||||
if (layersActionBarLayout.fragmentsStack.size() != 0) {
|
||||
BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1);
|
||||
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
||||
}
|
||||
if (layersActionBarLayout.fragmentsStack.size() != 0) {
|
||||
BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1);
|
||||
fragment.onActivityResultFragment(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3307,13 +3296,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (id == NotificationCenter.needShowPlayServicesAlert) {
|
||||
try {
|
||||
final Status status = (Status) args[0];
|
||||
status.startResolutionForResult(this, PLAY_SERVICES_REQUEST_CHECK_SETTINGS);
|
||||
} catch (Throwable ignore) {
|
||||
|
||||
}
|
||||
} else if (id == NotificationCenter.fileDidLoad) {
|
||||
if (loadingThemeFileName != null) {
|
||||
String path = (String) args[0];
|
||||
|
|
Loading…
Reference in New Issue