标签:getBoolean 源码 flags 冷启动 Android GPS DELETE extras
一:原理分析
- 主要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框架
标签:getBoolean,源码,flags,冷启动,Android,GPS,DELETE,extras 来源: https://www.cnblogs.com/ljx646566715/p/10893959.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。