一:原理分析
  1. 主要sendExtraCommand方法中传递两个参数, 根据如下源码可以知道第一个参数传递delete_aiding_data,第二个参数传递null即可。
    @Override
public boolean sendExtraCommand(String command, Bundle extras) { long identity = Binder.clearCallingIdentity();
boolean result = false; if ("delete_aiding_data".equals(command)) {
result = deleteAidingData(extras);
} else if ("force_time_injection".equals(command)) {
sendMessage(INJECT_NTP_TIME, 0, null);
result = true;
} else if ("force_xtra_injection".equals(command)) {
if (mSupportsXtra) {
xtraDownloadRequest();
result = true;
}
} else {
Log.w(TAG, "sendExtraCommand: unknown command " + command);
} Binder.restoreCallingIdentity(identity);
return result;
}

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;
}

根据flags值GPS_DELETE_ALL清除数据

static void android_location_GpsLocationProvider_delete_aiding_data(JNIEnv* /* env */,
jobject /* obj */,
jint flags)
{
if (sGpsInterface)
sGpsInterface->delete_aiding_data(flags);
}
    /**
* Specifies that the next call to start will not use the
* information defined in the flags. GPS_DELETE_ALL is passed for
* a cold start.
*/
void (*delete_aiding_data)(GpsAidingData flags);
二:实现方式

java层主要代码如下:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Bundle bundle = null;
locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "force_xtra_injection", bundle);
locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "force_time_injection", bundle);
//GPS cold start
locationManager.sendExtraCommand(LocationManager.GPS_PROVIDER, "delete_aiding_data", bundle);

所需权限配置如下, 6.0版本可能需要动态申请权限。

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>

喜欢源码分析系列可参考其他文章:

Android源码分析(一)-----如何快速掌握Android编译文件

Android源码分析(二)-----如何编译修改后的framework资源文件

Android源码分析(三)-----系统框架设计思想

Android源码分析(四)-----Android源码编译及刷机步骤

Android源码分析(五)-----如何从架构师的角度去设计Framework框架

Android源码分析(十五)----GPS冷启动实现原理分析的更多相关文章

  1. Android源码浅析(五)——关于定制系统,如何给你的Android应用系统签名

    Android源码浅析(五)--关于定制系统,如何给你的Android应用系统签名 今天来点简单的我相信很多定制系统的同学都会有一些特定功能的需求,比如 修改系统时间 静默安装 执行某shell命令 ...

  2. spring源码系列(十): 读取xml入口类 ClassPathXmlApplicationContext 分析

    环境准备: 使用spring5.1.6版本 1 xml配置文件 <?xml version="1.0" encoding="UTF-8"?> < ...

  3. OpenJDK源码研究笔记(十五):吐槽JDK中的10个富有争议的设计

    前14篇文章,分享了JDK中值得学习和借鉴的编码和设计方法. 每个硬币都是有两面的.Every coin has two sides. 当然,JDK中也有很多值得改进或者说富有争议的设计. 本篇,就来 ...

  4. Spark源码剖析(五):Master原理与源码剖析(下)

    一. 状态改变机制源码分析 在剖析Master核心的资源调度算法之前,让我们先来看看Master的状态改变机制. Driver状态改变  可以看出,一旦Driver状态发生改变,基本没有好事情,后果要 ...

  5. 【一起学源码-微服务】Ribbon 源码三:Ribbon与Eureka整合原理分析

    前言 前情回顾 上一篇讲了Ribbon的初始化过程,从LoadBalancerAutoConfiguration 到RibbonAutoConfiguration 再到RibbonClientConf ...

  6. Android恢复出厂设置流程分析【Android源码解析十】

    最近看恢复出厂的一个问题,以前也查过这方面的流程,所以这里整理一些AP+framework层的流程: 在setting-->备份与重置--->恢复出厂设置--->重置手机---> ...

  7. 《四 spring源码》spring的事务注解@Transactional 原理分析

    先了解什么是注解 注解 Jdk1.5新增新技术,注解.很多框架为了简化代码,都会提供有些注解.可以理解为插件,是代码级别的插件,在类的方法上写:@XXX,就是在代码上插入了一个插件. 注解不会也不能影 ...

  8. JVM源码系列:ThreadMXBean 打出堆栈信息原理分析

    我们通常会使用工具jstack 去跟踪线程信息,其如何实现使用attach 的方式还是ptrace 的方式,这些可以去参考本人的博客的其他文章. 但这些方式都是外部使用的方式,如何直接使用java代码 ...

  9. Android源码之Gallery专题研究(1)

    前言 时光飞逝,从事Android系统开发已经两年了,总想写点什么来安慰自己.思考了很久总是无法下笔,觉得没什么好写的.现在终于决定写一些符合大多数人需求的东西,想必使用过Android手机的人们一定 ...

随机推荐

  1. day13_7.15 迭代器和生成器

    1.迭代器 迭代就是一个更新换代的过程,每次迭代都必须基于上一次的结果. 迭代器就是迭代取值的工具.举个例子: while True: print('循环输出') 此代码会无限循环输出文字,是个死循环 ...

  2. Visual Studio 2017 软件包及教程

    下载地址:https://files.cnblogs.com/files/yungle/VisualStudio2017.rar 安装教程:https://mp.weixin.qq.com/s?__b ...

  3. JAVA并发-Executor

    结构 类继承图: 上面的各个接口/类的关系和作用: Executor 执行器接口,也是最顶层的抽象核心接口, 分离了任务和任务的执行. ExecutorService 在Executor的基础上提供了 ...

  4. Push to origin/master was rejected

    在IDEA中往码云上传项目的时候出现了如下的错误:Push to origin/master was rejected 因为我是把代码上传到一个新的仓库里面,所以第一次提交的时候和仓库里面的东西不同步 ...

  5. 【JSP】${pageContext.request.contextPath}

    取出部署的应用程序名或者是当前的项目名称 http://localhost:8080/demo1/a.jsp  ${pageContext.request.contextPath}或<%=req ...

  6. LeetCode 1257. Smallest Common Region

    原题链接在这里:https://leetcode.com/problems/smallest-common-region/ 题目: You are given some lists of region ...

  7. beeline无密码连接hiveserver2

    1.说明 #hiveserver2增加了权限控制,需要在hadoop的配置文件中配置 core-site.xml 增加以下内容: <property> <name>hadoop ...

  8. [LeetCode] 719. Find K-th Smallest Pair Distance 找第K小的数对儿距离

    Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pai ...

  9. [LeetCode] 505. The Maze II 迷宫之二

    There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolli ...

  10. oracle--ORA-38760

    01,ORA-38760: This database instance failed to turn on flashback 02,问题处理思路 第一步:查看日志文件 查看这次启动的时候alter ...