1)注册了database的改变监控。
2)通知栏信息的刷新
3)清理数据库
4)注册ACTION_STATE_CHANGED的receiver
5)开始rfcomm的socket的监听
6)启动update的thread,在传输过程中根据传输的情况进行不断地刷新。
void BluetoothOppService::onCreate() {
GLOGENTRY();Service::onCreate();
GLOGI("Service onCreate");
mHandler = new BtoppServiceHandler(this);
GLOGD("BluetoothOppService:: BtoppServiceHandler count %d", getStrongCount());
//注册ACTION_STATE_CHANGED的receiver,用于处理蓝牙文件传输过程中的蓝牙开关操作
GLOGD("BluetoothOppService:: BtoppServiceBroadcastReceiver count %d", getStrongCount());
sp<IntentFilter> filter = new IntentFilter(BluetoothAdapter::ACTION_STATE_CHANGED());
registerReceiver(mBluetoothReceiver, filter);
GLOGD("BluetoothOppService:: count %d", getStrongCount());
mAdapter = BluetoothAdapter::getDefaultAdapter();
GLOGD("BluetoothOppService:: count %d", getStrongCount());
mSocketListener = new BluetoothOppRfcommListener(mAdapter);
GLOGD("BluetoothOppService:: count %d", getStrongCount());
mShares = new GArrayList<BluetoothOppShareInfo>();
GLOGD("BluetoothOppService:: count %d", getStrongCount());
mBatchs = new GArrayList<BluetoothOppBatch>();
GLOGD("BluetoothOppService:: count %d", getStrongCount());
mObserver = new BluetoothShareContentObserver(this);
GLOGD("BluetoothOppService:: BluetoothShareContentObserver count %d", getStrongCount());
getContentResolver()->registerContentObserver(BluetoothShare::CONTENT_URI(), true, mObserver);
GLOGD("BluetoothOppService:: BluetoothShareContentObserver count %d", getStrongCount());
mBatchId = 1;
mNotifier = new BluetoothOppNotification(this);
GLOGD("BluetoothOppService:: BluetoothOppNotification count %d", getStrongCount());
mNotifier->mNotificationMgr->cancelAll();
mNotifier->updateNotification();
// sp<ContentResolver> contentResolver = getContentResolver();
sp<GThread> thread = new onCreateThread(this);
GLOGD("BluetoothOppService:: onCreateThread count %d", getStrongCount());
thread->run("trimDatabase");
{
RecursiveMutex::Autolock _l(mBluetoothOppServiceMutex);
if (mAdapter == NULL) {
GLOGW("Local BT device is not enabled");
} else {
startListener();
}
}
updateFromProvider();
GLOGD("BluetoothOppService:: count %d", getStrongCount());
}
void BluetoothOppNotification::updateNotification() {
GLOGENTRY();
Mutex::Autolock autoLock(mOppNotificationMutex);
mPendingUpdate++;
if (mPendingUpdate > 1) {
GLOGI("update too frequent, put in queue");
return;
}
if (!mHandler->hasMessages(NOTIFY)) {
GLOGI("send message");
mHandler->sendMessage(mHandler->obtainMessage(NOTIFY));
}
}