正在查看: Loan Locker v1.5 应用的 GpsTrackerService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Loan Locker v1.5 应用的 GpsTrackerService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.user.a4keygen.services;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import com.google.common.net.HttpHeaders;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.gson.JsonObject;
import com.user.a4keygen.R;
import com.user.a4keygen.constants.ServiceKeyValueConstant;
import com.user.a4keygen.constants.WebServiceUrlConstant;
import com.user.a4keygen.model.CommonResponseModel;
import com.user.a4keygen.network.ApiClient;
import com.user.a4keygen.network.ApiInterface;
import com.user.a4keygen.sharedprefrence.SharedPrefManager;
import com.user.a4keygen.util.Config;
import com.user.a4keygen.util.IconUtils;
import com.user.a4keygen.webutil.WebClientService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class GpsTrackerService extends Service implements LocationListener {
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;
private static final long MIN_TIME_BW_UPDATES = 60000;
boolean canGetLocation;
boolean isGPSEnabled;
boolean isNetworkEnabled;
private int lastShownNotificationId;
double latitude;
Location location;
protected LocationManager locationManager;
double longitude;
private Context mContext;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onProviderDisabled(String str) {
}
@Override
public void onProviderEnabled(String str) {
}
@Override
public void onStatusChanged(String str, int i, Bundle bundle) {
}
public GpsTrackerService(Context context) {
this.isGPSEnabled = false;
this.isNetworkEnabled = false;
this.canGetLocation = false;
this.latitude = 0.0d;
this.longitude = 0.0d;
this.lastShownNotificationId = 321;
this.mContext = context;
getLocation();
}
public GpsTrackerService() {
this.isGPSEnabled = false;
this.isNetworkEnabled = false;
this.canGetLocation = false;
this.latitude = 0.0d;
this.longitude = 0.0d;
this.lastShownNotificationId = 321;
this.mContext = null;
}
@Override
public void onCreate() {
super.onCreate();
this.mContext = this;
}
public Location getLocation() {
try {
LocationManager locationManager = (LocationManager) this.mContext.getSystemService(FirebaseAnalytics.Param.LOCATION);
this.locationManager = locationManager;
this.isGPSEnabled = locationManager.isProviderEnabled("gps");
boolean isProviderEnabled = this.locationManager.isProviderEnabled("network");
this.isNetworkEnabled = isProviderEnabled;
boolean z = this.isGPSEnabled;
if (z || isProviderEnabled) {
this.canGetLocation = true;
if (z && Build.VERSION.SDK_INT >= 23 && ((ContextCompat.checkSelfPermission(this.mContext, "android.permission.ACCESS_FINE_LOCATION") == 0 || ContextCompat.checkSelfPermission(this.mContext, "android.permission.ACCESS_COARSE_LOCATION") == 0) && this.location == null)) {
this.locationManager.requestLocationUpdates("gps", MIN_TIME_BW_UPDATES, 10.0f, this);
LocationManager locationManager2 = this.locationManager;
if (locationManager2 != null) {
Location lastKnownLocation = locationManager2.getLastKnownLocation("gps");
this.location = lastKnownLocation;
if (lastKnownLocation != null) {
this.latitude = lastKnownLocation.getLatitude();
this.longitude = this.location.getLongitude();
}
}
}
if (this.isNetworkEnabled) {
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(this.mContext, "android.permission.ACCESS_FINE_LOCATION") == 0 || ContextCompat.checkSelfPermission(this.mContext, "android.permission.ACCESS_COARSE_LOCATION") == 0) {
this.locationManager.requestLocationUpdates("network", MIN_TIME_BW_UPDATES, 10.0f, this);
LocationManager locationManager3 = this.locationManager;
if (locationManager3 != null) {
Location lastKnownLocation2 = locationManager3.getLastKnownLocation("network");
this.location = lastKnownLocation2;
if (lastKnownLocation2 != null) {
this.latitude = lastKnownLocation2.getLatitude();
this.longitude = this.location.getLongitude();
}
}
}
} else {
this.locationManager.requestLocationUpdates("network", MIN_TIME_BW_UPDATES, 10.0f, this);
LocationManager locationManager4 = this.locationManager;
if (locationManager4 != null) {
Location lastKnownLocation3 = locationManager4.getLastKnownLocation("network");
this.location = lastKnownLocation3;
if (lastKnownLocation3 != null) {
this.latitude = lastKnownLocation3.getLatitude();
this.longitude = this.location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return this.location;
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
getLocation();
Toast.makeText(this, this.latitude + "," + this.longitude, 0).show();
sendLTandLNGtoApi(this);
if (Build.VERSION.SDK_INT >= 26) {
createAndShowForegroundNotification(this, 123);
}
SharedPrefManager.getInstance(this).saveUsersLatLong(String.valueOf(this.latitude), String.valueOf(this.longitude));
return 1;
}
private void sendLTandLNGtoApi(final Context context) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userId", SharedPrefManager.getInstance(context).getUserId());
jsonObject.addProperty("longitude", String.valueOf(this.longitude));
jsonObject.addProperty("latitude", String.valueOf(this.latitude));
((ApiInterface) ApiClient.getInstance(this).getClient().create(ApiInterface.class)).saveLTandLNG(jsonObject).enqueue(new Callback<CommonResponseModel>() {
public void onFailure(Call<CommonResponseModel> call, Throwable th) {
}
public void onResponse(Call<CommonResponseModel> call, Response<CommonResponseModel> response) {
if (response.isSuccessful()) {
if ("S".equals(((CommonResponseModel) response.body()).getStatus())) {
Toast.makeText(context, "Success", 0).show();
} else {
Toast.makeText(context, "Fail", 0).show();
}
}
}
});
}
private void createAndShowForegroundNotification(Service service, int i) {
NotificationCompat.Builder notificationBuilder = getNotificationBuilder(service, Config.CHANNEL_ID, 4);
NotificationCompat.Builder smallIcon = notificationBuilder.setOngoing(true).setSmallIcon(IconUtils.getAppIcon());
boolean equals = WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.GMM_WEB_SERVICE_URL);
String str = ServiceKeyValueConstant.LOCATION_FETCHING;
NotificationCompat.Builder contentTitle = smallIcon.setContentTitle(equals ? ServiceKeyValueConstant.LOCATION_FETCHING : HttpHeaders.LOCATION);
if (!WebClientService.getWebServiceUrl().equals(WebServiceUrlConstant.GMM_WEB_SERVICE_URL)) {
str = HttpHeaders.LOCATION;
}
contentTitle.setContentTitle(str).setPriority(1).setAutoCancel(true);
service.startForeground(i, notificationBuilder.build());
if (i != this.lastShownNotificationId) {
((NotificationManager) service.getSystemService("notification")).cancel(this.lastShownNotificationId);
}
this.lastShownNotificationId = i;
}
public static NotificationCompat.Builder getNotificationBuilder(Context context, String str, int i) {
if (Build.VERSION.SDK_INT >= 26) {
prepareChannel(context, str, i);
return new NotificationCompat.Builder(context, str);
}
return new NotificationCompat.Builder(context);
}
private static void prepareChannel(Context context, String str, int i) {
String string = context.getString(R.string.app_name);
NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
if (notificationManager == null || notificationManager.getNotificationChannel(str) != null) {
return;
}
NotificationChannel notificationChannel = new NotificationChannel(str, string, i);
notificationChannel.setDescription(HttpHeaders.LOCATION);
notificationManager.createNotificationChannel(notificationChannel);
}
@Override
public void onDestroy() {
if (Build.VERSION.SDK_INT >= 26) {
stopForeground(true);
}
}
}