热启动:就是在上一次GPS定位到的情况下。关掉GPS,然后再打开,然后打开GPS去定位。一般3秒左右。

温启动:就是在上一次GPS定位到的情况下。关掉GPS,然后清除星历数据,然后打开GPS去定位。一般30秒左右。

冷启动:就是在上一次GPS定位到的情况下。关掉GPS,然后清除所有数据,然后重启手机(有的手机需要),然后打开GPS去定位。时间最长。

 清除数据的代码如下,都是通过sendExtraCommand来实现的,只是带的bundle不一样而已。

private LocationManager mLocationManager;
 
 
 
mLocationManager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
 
 
 
 
private void sendWarmCommand(){
        Bundle bundleWarm = new Bundle();
        bundleWarm.putBoolean( "ephemeris", true );
        boolean b=  mLocationManager.sendExtraCommand( LocationManager.GPS_PROVIDER,
                "delete_aiding_data", bundleWarm );
        Log.i( TAG,"delete_aiding_data ephemeris" +b);
    }
 
 
private void sendColdCommand(){
        boolean b=  mLocationManager.sendExtraCommand( LocationManager.GPS_PROVIDER,
                "delete_aiding_data", null );
        Log.i( TAG,"delete_aiding_data null" +b);
    }

下面是android9.0源码,在/frameworks/base/services/core/java/com/android/server/location/GnssLocationProvider.java

当你执行了sendExtraCommand就会走到这里,这里有很多GPS相关的数据,可以根据需求,发送来清除。

    @Override
    public boolean sendExtraCommand(String command, Bundle extras) {
 
        long identity = Binder.clearCallingIdentity();
        try {
            boolean result = false;
 
            if ("delete_aiding_data".equals(command)) {
                result = deleteAidingData(extras);
            } else if ("force_time_injection".equals(command)) {
                requestUtcTime();
                result = true;
            } else if ("force_xtra_injection".equals(command)) {
                if (mSupportsXtra) {
                    xtraDownloadRequest();
                    result = true;
                }
            } else {
                Log.w(TAG, "sendExtraCommand: unknown command " + command);
            }
            return result;
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }
 
 
 
 
 
    private boolean deleteAidingData(Bundle extras) {
        int flags;
 
        if (extras == null) {
            flags = GPS_DELETE_ALL;
        } else {
            flags = 0;
            if (extras.getBoolean("ephemeris")) flags |= GPS_DELETE_EPHEMERIS;
            if (extras.getBoolean("almanac")) flags |= GPS_DELETE_ALMANAC;
            if (extras.getBoolean("position")) flags |= GPS_DELETE_POSITION;
            if (extras.getBoolean("time")) flags |= GPS_DELETE_TIME;
            if (extras.getBoolean("iono")) flags |= GPS_DELETE_IONO;
            if (extras.getBoolean("utc")) flags |= GPS_DELETE_UTC;
            if (extras.getBoolean("health")) flags |= GPS_DELETE_HEALTH;
            if (extras.getBoolean("svdir")) flags |= GPS_DELETE_SVDIR;
            if (extras.getBoolean("svsteer")) flags |= GPS_DELETE_SVSTEER;
            if (extras.getBoolean("sadata")) flags |= GPS_DELETE_SADATA;
            if (extras.getBoolean("rti")) flags |= GPS_DELETE_RTI;
            if (extras.getBoolean("celldb-info")) flags |= GPS_DELETE_CELLDB_INFO;
            if (extras.getBoolean("all")) flags |= GPS_DELETE_ALL;
        }
 
        if (flags != 0) {
            native_delete_aiding_data(flags);
            return true;
        }
 
        return false;
    }

 

 

 

 

 

 

 

 

 

 

 

 

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐