private boolean msgTypeDocked(BluetoothDevice device, final int state, final int startId) { if (DEBUG) { // TODO figure out why hasMsg always returns false if device // is supplied Log.d( TAG, "1 Has undock perm msg = " + mServiceHandler.hasMessages(MSG_TYPE_UNDOCKED_PERMANENT, mDevice)); Log.d( TAG, "2 Has undock perm msg = " + mServiceHandler.hasMessages(MSG_TYPE_UNDOCKED_PERMANENT, device)); } mServiceHandler.removeMessages(MSG_TYPE_UNDOCKED_PERMANENT); mServiceHandler.removeMessages(MSG_TYPE_DISABLE_BT); getPrefs().edit().remove(KEY_DISABLE_BT).apply(); if (device != null) { if (!device.equals(mDevice)) { if (mDevice != null) { // Not expected. Cleanup/undock existing handleUndocked(mDevice); } mDevice = device; // Register first in case LocalBluetoothProfileManager // becomes ready after isManagerReady is called and it // would be too late to register a service listener. mProfileManager.addServiceListener(this); if (mProfileManager.isManagerReady()) { handleDocked(device, state, startId); // Not needed after all mProfileManager.removeServiceListener(this); } else { final BluetoothDevice d = device; mRunnable = new Runnable() { public void run() { handleDocked(d, state, startId); // FIXME: WTF runnable here? } }; return true; } } } else { // display dialog to enable dock for media audio only in the case of low end docks and // if not already selected by user int dockAudioMediaEnabled = Settings.Global.getInt( getContentResolver(), Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, -1); if (dockAudioMediaEnabled == -1 && state == Intent.EXTRA_DOCK_STATE_LE_DESK) { handleDocked(null, state, startId); return true; } } return false; }
@Override public int onStartCommand(Intent intent, int flags, int startId) { // When receiving a new intent, delay the schedule until 5 seconds from now. mServiceHandler.removeMessages(0); mServiceHandler.sendEmptyMessageDelayed(0, SCHEDULE_UPDATE_DELAY_MILLIS); // Remove pending updates involving this session ID. String sessionId = intent.getStringExtra(EXTRA_SESSION_ID); Iterator<Intent> updatesIterator = mScheduleUpdates.iterator(); while (updatesIterator.hasNext()) { Intent existingIntent = updatesIterator.next(); if (sessionId.equals(existingIntent.getStringExtra(EXTRA_SESSION_ID))) { updatesIterator.remove(); } } // Queue this schedule update. synchronized (mScheduleUpdates) { mScheduleUpdates.add(intent); } return START_REDELIVER_INTENT; }