导航菜单

页面标题

页面副标题

管控平台 v5.2.3.0. - LocationService.java 源代码

正在查看: 管控平台 v5.2.3.0. 应用的 LocationService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.iflytek.mdmservice.service;

import android.app.AlarmManager;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.alibaba.fastjson.JSONObject;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.DistanceUtil;
import com.iflytek.mdmcommon.LogUtil;
import com.iflytek.mdmcommon.SpHelper;
import com.iflytek.mdmservice.MDMApp;
import com.iflytek.mdmservice.R$drawable;
import com.iflytek.mdmservice.k.d0;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.sqlcipher.BuildConfig;

public class LocationService extends IntentService {

    private int f488a;

    private boolean f489b;

    private com.iflytek.mdmservice.l.a f490c;
    private LocationClient d;
    private BDAbstractLocationListener e;
    boolean f;

    class a extends BDAbstractLocationListener {
        a() {
        }

        public void onReceiveLocation(BDLocation bDLocation) {
            if (LocationService.this.d != null && LocationService.this.e != null) {
                LocationService.this.d.unRegisterLocationListener(LocationService.this.e);
            }
            String addrStr = bDLocation.getAddrStr();
            String country = bDLocation.getCountry();
            String province = bDLocation.getProvince();
            String city = bDLocation.getCity();
            String district = bDLocation.getDistrict();
            String street = bDLocation.getStreet();
            double latitude = bDLocation.getLatitude();
            double longitude = bDLocation.getLongitude();
            String locationDescribe = bDLocation.getLocationDescribe();
            String coorType = bDLocation.getCoorType();
            int locType = bDLocation.getLocType();
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("addr", addrStr);
            jSONObject.put("country", country);
            jSONObject.put("province", province);
            jSONObject.put("city", city);
            jSONObject.put("district", district);
            jSONObject.put("street", street);
            jSONObject.put("bdLatitude", Double.valueOf(latitude));
            jSONObject.put("bdLongitude", Double.valueOf(longitude));
            jSONObject.put("locationDescribe", locationDescribe);
            jSONObject.put("coorType", coorType);
            jSONObject.put("locType", Integer.valueOf(locType));
            if (LocationService.this.d != null) {
                LocationService.this.d.stop();
            }
            boolean z = LocationService.this.f489b;
            LogUtil.c("MDMLocation", "Location: " + jSONObject.toJSONString());
            if (locType == 61 || locType == 161) {
                String string = SpHelper.getString("lastCoordinate ", BuildConfig.FLAVOR);
                if (!TextUtils.isEmpty(string)) {
                    String[] split = string.split("&");
                    LogUtil.c("MDMLocation", "Location: {lastCoordinate:" + string + "}");
                    if (split.length == 2) {
                        double distance = DistanceUtil.getDistance(new LatLng(Double.parseDouble(split[0]), Double.parseDouble(split[1])), new LatLng(latitude, longitude));
                        LogUtil.c("MDMLocation", "LocationService{distance:" + distance + "米}");
                        if (distance >= 1000.0d) {
                            z = true;
                        }
                    }
                }
                if (!z) {
                    int i = SpHelper.getInt("placeCollectionInteval", 0);
                    LogUtil.c("MDMLocation", "LocationService{placeCollectionInteval:" + i + "min}");
                    if (i > 0) {
                        long j = SpHelper.getLong("placeCollectionLatestTime", 0L);
                        LogUtil.c("MDMLocation", "LocationService{placeCollectionLatestTime:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(j)) + "}");
                        long j2 = j + (((long) (i * 60)) * 1000);
                        if (System.currentTimeMillis() < j2 && j2 - System.currentTimeMillis() > com.igexin.push.config.c.B) {
                            LogUtil.c("MDMLocation", "LocationService: return");
                            LocationService.this.f = true;
                            return;
                        }
                    }
                }
                LocationService.this.f490c.k(longitude, latitude, addrStr);
                d0.b0().A1(longitude, latitude, addrStr);
            } else {
                jSONObject.put("locTypeDescription", bDLocation.getLocTypeDescription());
                if (LocationService.this.f488a < 2) {
                    LogUtil.c("MDMLocation", "Location: location fail, retry => " + LocationService.this.f488a);
                    LocationService locationService = LocationService.this;
                    locationService.f488a = locationService.f488a + 1;
                    Intent intent = new Intent(MDMApp.j(), (Class<?>) LocationService.class);
                    intent.putExtra("force", z);
                    intent.putExtra("retryCount", LocationService.this.f488a);
                    MDMApp.j().startService(intent);
                }
            }
            LocationService locationService2 = LocationService.this;
            locationService2.f = true;
            if (locationService2.d != null) {
                LocationService.this.d.disableLocInForeground(true);
            }
        }
    }

    public LocationService() {
        super("LocationService");
        this.f490c = new com.iflytek.mdmservice.l.a();
        this.d = null;
        this.e = new a();
    }

    @Override
    public void onCreate() {
        LogUtil.i("MDMLocation", "onCreate");
        super.onCreate();
        if (Build.VERSION.SDK_INT >= 26) {
            String packageName = getPackageName();
            NotificationManager notificationManager = (NotificationManager) getSystemService(com.igexin.push.core.b.l);
            NotificationChannel notificationChannel = new NotificationChannel(packageName, "主服务", 4);
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(-65536);
            notificationChannel.setShowBadge(true);
            notificationChannel.setDescription("管控平台正在后台运行,请勿停用此服务!");
            notificationChannel.setLockscreenVisibility(-1);
            notificationManager.createNotificationChannel(notificationChannel);
            startForeground(1118, new Notification.Builder(this, packageName).setContentTitle("正在进行设备管控").setContentText("管控平台正在后台定位,请勿停用此服务!").setWhen(System.currentTimeMillis()).setSmallIcon(R$drawable.ic_notification_mdm).build());
        }
        this.d = new LocationClient(getApplicationContext());
        LocationClientOption locationClientOption = new LocationClientOption();
        locationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        locationClientOption.setIsNeedAddress(true);
        locationClientOption.setCoorType("bd09ll");
        locationClientOption.setScanSpan(1000);
        locationClientOption.setOpenGps(true);
        locationClientOption.setIgnoreKillProcess(false);
        locationClientOption.setWifiCacheTimeOut(300000);
        locationClientOption.setEnableSimulateGps(false);
        locationClientOption.setIsNeedLocationDescribe(true);
        this.d.setLocOption(locationClientOption);
        this.d.registerLocationListener(this.e);
    }

    @Override
    public void onDestroy() {
        LogUtil.i("MDMLocation", "onDestroy");
        super.onDestroy();
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        int i;
        LogUtil.i("MDMLocation", "onHandleIntent");
        if (intent.getBooleanExtra("repeat", false) && (i = SpHelper.getInt("placeCollectionInteval", 0)) > 0) {
            AlarmManager alarmManager = (AlarmManager) getSystemService("alarm");
            Intent intent2 = new Intent(MDMApp.j(), (Class<?>) LocationService.class);
            intent2.putExtra("repeat", true);
            PendingIntent service = PendingIntent.getService(MDMApp.j(), 0, intent2, 134217728);
            long currentTimeMillis = System.currentTimeMillis() + (i * 60 * 1000);
            if (Build.VERSION.SDK_INT < 19) {
                alarmManager.set(0, currentTimeMillis, service);
            } else {
                alarmManager.setExact(0, currentTimeMillis, service);
            }
        }
        this.f489b = intent.getBooleanExtra("force", false);
        this.f488a = intent.getIntExtra("retryCount", 0);
        LogUtil.c("MDMLocation", "Location: onHandleIntent{force: " + this.f489b + ", retryCount:" + this.f488a + "}");
        LocationClient locationClient = this.d;
        if (locationClient != null) {
            locationClient.start();
        }
    }

    @Override
    public int onStartCommand(@Nullable Intent intent, int i, int i2) {
        LogUtil.i("MDMLocation", "onStartCommand");
        if (Build.VERSION.SDK_INT >= 26) {
            String packageName = getPackageName();
            NotificationManager notificationManager = (NotificationManager) getSystemService(com.igexin.push.core.b.l);
            NotificationChannel notificationChannel = new NotificationChannel(packageName, "主服务", 4);
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(-65536);
            notificationChannel.setShowBadge(true);
            notificationChannel.setDescription("管控平台正在后台运行,请勿停用此服务!");
            notificationChannel.setLockscreenVisibility(-1);
            notificationManager.createNotificationChannel(notificationChannel);
            startForeground(1118, new Notification.Builder(this, packageName).setContentTitle("正在进行设备管控").setContentText("管控平台正在后台定位,请勿停用此服务!").setWhen(System.currentTimeMillis()).setSmallIcon(R$drawable.ic_notification_mdm).build());
        }
        return super.onStartCommand(intent, i, i2);
    }
}