android 定时上报gps,Android GPS数据上报线程的开启流程

接下来就该讨论JNI(java部分)(GpsLocationProvider.java)层的数据传输了,在JNI(java部分)层中,JNI(c/c++)层的函数Android_location_GpsLocationProvider_wait_for_event被映射成函数native_wait_for_event,其在:

private final class GpsEventThread extends Thread {

public GpsEventThread() {

super("GpsEventThread");

}

public void run() {

if (DEBUG) Log.d(TAG, "GpsEventThread starting");

// Exit as soon as disable() is called instead of waiting for the GPS to stop.

while (mEnabled) {

// this will wait for an event from the GPS,

// which will be reported via reportLocation or reportStatus

native_wait_for_event();             //接受冲JNI层穿上来的数据

}

if (DEBUG) Log.d(TAG, "GpsEventThread exiting");

}

}

继续跟踪可发现,这个现在

private void handleEnable() {

if (DEBUG) Log.d(TAG, "handleEnable");

if (mEnabled) return;

mEnabled = native_init();

if (mEnabled) {

if (mSuplServerHost != null) {

native_set_agps_server(AGPS_TYPE_SUPL, mSuplServerHost, mSuplServerPort);

}

if (mC2KServerHost != null) {

native_set_agps_server(AGPS_TYPE_C2K, mC2KServerHost, mC2KServerPort);

}

// run event listener thread while we are enabled

mEventThread = new GpsEventThread(); //创建线程并运行

mEventThread.start();

} else {

Log.w(TAG, "Failed to enable location provider");

}

}

中被创建,并运行,而这个函数有是在

private final class ProviderHandler extends Handler {

@Override

public void handleMessage(Message msg)

{

switch (msg.what) {

case ENABLE:

if (msg.arg1 == 1) {

handleEnable();//调用

} else {

handleDisable();

}

break;

。。。省略。。。

}

。。。省略。。。

}

}

被调用,接着这个句柄,是在

private final class GpsLocationProviderThread extends Thread {

public GpsLocationProviderThread() {

super("GpsLocationProvider");

}

public void run() {

Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

initialize();

Looper.prepare();

mHandler = new ProviderHandler();

// signal when we are initialized and ready to go

mInitializedLatch.countDown();

Looper.loop();

}

}

这个线程中被创建使用,这个线程又在GpsLocationProvider中被创建并运行使得数据开始上报:

public GpsLocationProvider(Context context, ILocationManager locationManager){

。。。省略。。。

mThread = new GpsLocationProviderThread();

mThread.start();

。。。省略。。。

}

这个函数是类GpsLocationProvider的构造函数,此构造函数将在server(LocationManagerService.java)中的_loadProvidersLocked函数被调用。

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值