frameworks/base: Fix for the race in Wallpaperservice

Wallpaperservice has a race among message handler of
DO_DETACH and service's onDestroy. In certain cases,
the engine kept track in mActiveEngines is removed by
message handler of DO_DETACH and service's onDestroy
doesn't get a entry in mActivieEngines and isn't able
to invoke detach. This keeps the broadcast receiver,
mReceiver active and is unregistered by the framework
and a corresponding leak is reported.

  Later, the message handler of DO_DETACH continues
and invokes detach on mEngine, which attempts to
unregister mReceiver and framework throws an exception
"Receiver not registered: android.service.wallpaper.
WallpaperService$Engine$1@40874580" and causes the
framework to reboot.

  In case of system_server, WindownManagerPolicy and
android.server.ServerThread contest for access of
shared members, mActiveEngines and mEgine. Fix is to
protect the critical section via synchronized block.

Change-Id: Ice79cb8344fb54bcc6e9f76f4b143daac2608d7b
AssetAtlas: Fix NPE when there are no preloaded resources
Try to fix null window errors when hangling home action

Change-Id: I6b5cd4010fd619cbc9c1294d76d74b82f61f7839
frameworks/base: Add changes for Incall Music Delivery

- Add Flag and Stream type required for incall music delivery.
- Add Tone types for ToneGenerator

Change-Id: Ic05cd1af1172dda3c527af826c6e9a48d6ae20d5
potential GraphRunner leak in camera effects

if the camera FCs while recording effects.. *poof* a tiny leak is born.
so.. we close mRunner onDestroy.

Change-Id: I6a7983f120a03137f545a3cd9bb07ff51a9cd2d7
AudioService: Don't adjust volume when vol-downing to vibrate or silent

Pressing vol-down to vibrate or silent would (previously) still adjust the
stream volume, setting the last audible volume to 0, which is not allowed
for voice-capable devices.  Thus, the last audible volume would reset to
default on reboot if on vibrate/silent or the lowest volume setting.

By not adjusting volume when vol-downing to vibrate or silent on
voice-capable devices, the last audible volume is always preserved across
reboot.
AudioService: allow volume control on analog dock

This re-enables volume control on some Motorola docks.

Change-Id: If7751867de2c0cefb5a8518b5a6a607a9676b946
Prevent audio players starting on startup.

Previously, (at least) Apollo was started on startup (in that it
appeared in the notification bar) because it listens to the AUDIO_BECOMING_NOISY
intent to silence itself in that case. This intent is broadcast by
AudioService when there's a user switch to silence any potential audio
players for the old user. As the system also sends around a
USER_SWITCHED intent on startup, this led to the aforementioned player
startup.
As the intent of AudioService was to act on a user backgrounding anyway,
send out AUDIO_BECOMING_NOISY as reaction to a USER_BACKGROUND intent
instead of the USER_SWITCHED intent.

Change-Id: Iba35844a1274c9dd195f104068304e6a7ffa809e
audio: Add overlay to fix analog docks.

Of particular interest to devices using libhardware_legacy and
affected by commit 5a484b753cc72d6a50c1dd3bbf68b3403c741a3a: http://goo.gl/rVR1Z
which restricted the routing of AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET
to docks using FORCE_ANALOG_DOCK cases. The EXTRA_DOCK_STATE_CAR case is
returning FORCE_BT_CAR_DOCK, preventing the dock audio from routing properly.

Add an overlay option for overriding to FORCE_ANALOG_DOCK.

Change-Id: Ib7d70c242aa6f537ea5d65098ceb2c591662d8bb

Conflicts:
	core/res/res/values/config.xml
	core/res/res/values/symbols.xml
Fix ringer mode being unneededly changed by setting ringer mode volume
to 0.

When having set the ringer mode to silent on a device with vibrator and
calling setStreamVolume() for the ringer stream again (e.g. in one of
the volume control dialogs in the settings app), the ringer mode is set
to vibrate, although there's no reason to do so.

Fix that by remembering the last non-normal (that is, either silent or
vibrate) ringer mode and using that when setting the stream volume to 0.

Change-Id: I27f1c75a0fef52bd63ac20f4101042808ce2c458
JIRA: CYAN-1403
AudioService: Go back to virtual SCO calls on multi-function units

Direct raw audio channels to these HFP devices is resulting in
dead audio on hangouts, on all devices. Until that is figured
out and/or fixed, go back to establishing a virtual call to open
up the audio channels

Change-Id: I794e75eed96ac09cfbb1c9d28c90d3161cfb7149
Move 'start music player on headset connection' option out of DSPManager
(1/2)

This option isn't related to DSP manager at all, so it shouldn't be
implemented there.

Change-Id: Ibe35c9739ccb4f4587ee71f514d16fb317bf4034

Conflicts:
	media/java/android/media/AudioService.java
Fix up 'launch player on headset connection' option.

- don't crash system_server if no music player can be found
- use the active user's setting instead of the owner's setting

Change-Id: I38a07fe5c8c3d67ececd0768e1fcc01a6cf7fa5a
Add keymapping for select BT headsets

Per CYAN-522, select BT headsets (e.g. Jabra Street, Jabra BT3030, etc)
send key 159 for fast-forward button, instead of the expected key 208.

Need's testing with affected BT devices.

Change-Id: I06ba689f77dd1058fb82b1de9f72b4df59150cf9