package com.dowse.base.manager;

import android.annotation.SuppressLint;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import com.dowse.base.data.DSLocation;
import com.dowse.base.log.DSLog;
import com.dowse.base.util.ContextUtil;

/* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/manager/DSGPSManager.class */
public class DSGPSManager {
    private static final String TAG = "DSGPSManager";
    private Context mContext;
    private Location mLastLocation = null;
    private LocationListener mLocationListener = new LocationListener() { // from class: com.dowse.base.manager.DSGPSManager.1
        @Override // android.location.LocationListener
        public void onLocationChanged(Location location) {
            DSLog.d(DSGPSManager.TAG, "onLocationChanged...");
            DSGPSManager.this.updateLocation(location);
        }

        @Override // android.location.LocationListener
        public void onStatusChanged(String provider, int status, Bundle extras) {
            DSLog.d(DSGPSManager.TAG, "onStatusChanged...");
        }

        @Override // android.location.LocationListener
        public void onProviderEnabled(String provider) {
            DSLog.d(DSGPSManager.TAG, "onProviderEnabled...");
            DSGPSManager.this.updateLocation(DSGPSManager.this.getLastLocation(provider));
        }

        @Override // android.location.LocationListener
        public void onProviderDisabled(String provider) {
            DSLog.d(DSGPSManager.TAG, "onProviderDisabled...");
            DSGPSManager.this.updateLocation(null);
        }
    };

    /* JADX INFO: Access modifiers changed from: private */
    public synchronized void updateLocation(Location location) {
        this.mLastLocation = location;
    }

    private synchronized Location getLastLocation() {
        return this.mLastLocation;
    }

    public DSGPSManager() {
        this.mContext = null;
        this.mContext = ContextUtil.getApplication();
        getGPSLocation(this.mLocationListener);
        updateLocation(getLastLocation("gps"));
    }

    public static DSGPSManager getInstance() {
        return DSGPSManagerHolder.instance;
    }

    /* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/manager/DSGPSManager$DSGPSManagerHolder.class */
    private static class DSGPSManagerHolder {
        public static final DSGPSManager instance = new DSGPSManager();

        private DSGPSManagerHolder() {
        }
    }

    public boolean isOpenGPS() {
        if (this.mContext != null) {
            LocationManager locationManager = (LocationManager) this.mContext.getSystemService("location");
            return locationManager.isProviderEnabled("gps");
        }
        DSLog.e(TAG, "isOpenGPS mContext is null!");
        return false;
    }

    @SuppressLint({"MissingPermission"})
    public Location getLastLocation(String provider) {
        if (this.mContext != null) {
            LocationManager locationManager = (LocationManager) this.mContext.getSystemService("location");
            return locationManager.getLastKnownLocation(provider);
        }
        DSLog.e(TAG, "getLastLocation mContext is null!");
        return null;
    }

    @SuppressLint({"MissingPermission"})
    public void getGPSLocation(LocationListener listener) {
        if (this.mContext != null) {
            LocationManager locationManager = (LocationManager) this.mContext.getSystemService("location");
            locationManager.requestLocationUpdates("gps", 2000L, 8.0f, listener);
            return;
        }
        DSLog.e(TAG, "getGPSLocation mContext is null!");
    }

    public boolean setGPS(boolean isOpen) {
        if (this.mContext != null) {
            Settings.Secure.setLocationProviderEnabled(this.mContext.getContentResolver(), "gps", isOpen);
            return true;
        }
        DSLog.e(TAG, "setGPSStatus mContext is null!");
        return false;
    }

    public DSLocation getDSLocation() {
        return new DSLocation(isOpenGPS() ? 1 : 0, getLastLocation());
    }
}
