Avoid duplication of AppWindowToken in created Task

When WindowManagerService creates a new Task, it passes atoken to the
Task constructor. In this case atoken is added to mAppTokens list by
the Task constructor and then it is added manually again by calling
newTask.mAppTokens.add(atoken). As a result, the same atoken is present
in mAppTokens list twice.

When another window token is added to the list, it may be placed in
beetwen duplicated tokens and corresponding window will be hidden from
the screen by corresponding duplicated windows.
From user perspective it means that some windows will not be displayed
on the screen.

The issue is fixed by avoid adding atoken to mAppTokens list manually
when it was added already in Task constructor.

Change-Id: I10628e68186160fffdde07beb7d84ab3cecb7051
Harden NsdManager against null-dereference crashes

Due to race conditions or programming errors, the NsdManager
can attempt to process an asynchronous status message (and issue
a callback to the listener) after the listener has already been
removed from the NsdManager state.  This causes dereferencing of
null objects, and a crash.

Split out the three async-queue message cases:  these are ones
in which message.arg2 does not hold an NsdManager array index
and the code should not interpret this field as if it were.

Add an explicit check for "null listener" (the array index in the
message has already been released), log a warning, and exit early.

Safeguard accesses to the "NSD service type" string from a (possibly
null) NsdServiceInfo object... return a constant "?" string rather
than crashing.

Bug: 9016259

Change-Id: I40aabdfc65d86fdd0eaac7a1e7e56e6ff69796cf
Validate objects are from the correct context.

Change-Id: I7d87b0e253b8d2e36d1aed790cfe3a7dd23e158f
Fix descriptor leak after accepting connections

After accepting a connection on a listening socket and
storing the resulting FileDescriptor into a newly created
LocalSocketImpl, the new impl's "descriptor was created
locally and should be closed normally" flag should be set.

(cherrypicked from 3e7305c6bf6062b5cb1e2ddcec6c6d30b4a8bc0d)

Bug: 11805817
Change-Id: I0a1a7c62ec3fbcf647a44a22110ddc778d14e5f4
server: Handle broadcast intent and receiver

Ensure the receivers of broadcast intent is not launched before boot
completion by adding an intent flag, since connectivity events can
happen before boot has completed.

Change-Id: Id6fc9e34c89d947d768def38e5c5bb0df54a3a7b
NFC: getNdefMessage() should throw exception if no tag in field.

According to documentation, an TagLostException should be thrown, if
the tag has been moved out of field when reading NDEF message.

Change-Id: Ib7e485ed442027fdebd5bc7a46101fbca0c88bdb
take account of RotationVector's new extra parameter

Rotation vector has a new 5th parameter introduced in API 18. But the code classified the 5 parameter the same as it would be 3 and overriden the 4th parameter which is unnecessary and also caused an unexpected behavior.

Issue #63268:
https://code.google.com/p/android/issues/detail?id=63268
Signed-off-by: Balint Ureczky <ubalint@gmail.com>

Change-Id: I6f9a5fc401da655695ab03694b4a74dc5be936ed
Hang off call by power button while screen is on

Enable power button end call and screen is off.  User use power button
to turn on screen will end call.  Should turn on screen and not end call

Change-Id: Idf34f7724dbf1796205332c5c7ef663102f8a30c
Signed-off-by: shower <shower929@gmail.com>
Round off when calculate next step in Seekbar

When the positions for the new step is calculated in
a Seekbar, a rounding error can appear.
This is fixed by round off before casting.

Change-Id: Ie2cf201ef670ccc2297e9bc4c7f415a826e44a41
frameworks: including build.prop property "ro.config.vc_music_vol_steps"
to control music steps amount (like it is
with "ro.config.vc_call_vol_steps" and call volume steps)

Change-Id: I81a3188919482383e015974818e7042d521ac679
Service: Keep services needing restart.

Services needing restart after crash include:
1) service with 'persistent == true'
2) service explicitly reuqired restart by returning START_STICKY
   or START_REDELIVER_INTENT from onStartCommand

Change-Id: Idc490a1ceb1e151a3eb7f34b7b4cf8058a06f34a
Signed-off-by: Liangcai Li <liangcail@nvidia.com>
VolumePanel: Don't force navigation bar

It always annoyed me that when changing volume while in immersive the navigation bar is shown.

Change-Id: I82bff7d22b741950ef26eaf092eb6272ab9ed7ff
NsdService does not clean up after exiting clients

When a client of the NsdService exits, NsdService should
clean up the requests it has sent to the mDNS daemon:
cancel any pending resource-discovery and resource-resolution
queries, and remove any services registered by this client.

If this isn't done, several bad things happen. The daemon will
continue to run unnecessarily, will report service discoveries
that can't be forwarded on to the client, and will continue to
advertise service ports for an application which is no longer
running until the device is rebooted (mDNS pollution).

Bug: 9801184
Change-Id: I0aa7311480322aefcff16f902fbbf34f50985d38
NULL previous background bitmap upon changing wallpaper

Step to reproduce it on Nexus 10 with 4.4.2(KOT49H):
1. Long press on home screen.
2. Choose wallpaper from Wallpapers.
3. Select new wallpaper and set it.
4. Repeat step 1-3 several times.
See black background instead of the wallpaper.

There are two binder objects who hold reference to the
ImageWallpaper$DrawableEngine, which keeps the big chunk
bitmap from being recycled.
One is WallpaperService$IWallpaperEngineWrapper. The client
references went away slowly, maybe several minutes after
changing wallpaper. Then the finalizer has to been executed
to GC it.
The other one is WallpaperService$Engine$BaseIWindow. Don't
know who still held reference to it even after the window
was removed.
Anyway, let the bitmap be GCed first.

Change-Id: I27f6971a3edd26472b69e59b542b27fd7c8e7b90
Signed-off-by: jshe32X<jianchunx.shen@intel.com>
Signed-off-by: Guobin Zhang <guobin.zhang@intel.com>
remove unnecessary switchUser call

If userId doesn't change, no need to do switchuser.or it will
introduce some tweak for gps modules in quick off/on because
they need cost time in off/on.

Change-Id: Ie5e408dc8be69c8a63a18bcb2cfe478cef4d70e6
Signed-off-by: Jianzheng Zhou <jianzheng.zhou@freescale.com>
Fix to memory leak leaving WallpaperCropActivity.

After running wallpaper cropper serveral times it crashes with
an OutOfMemotyException.

When leaving WallpaperCropActivity all textures are leaking until end
of process lifetime. This is due to a missing call to function
TiledImageView.destroy which in turn assures TiledImageRenderer
releases held resources.

Resolved by assuring WallpaperCropActivity calls TiledImageView.destroy
from WallpaperCropActivity.onDestroy. In case where onDestroy is not
called resources will be released anyway by process being brought down.

Change-Id: I016b1b9da5f4db8d2b14767edb59fe742415e074
Null pointer exception in FileRotator.java

Sometimes a null pointer exception is thrown when examining files
managed by the file rotator.

The logs from the test show that the Wifi state is changed a large
number of times. On every state change, a write operation is
initiated on the file system. This will eventually result in out
of memory and the call to mBasePath.list() in the maybeRotate(...)
method in FileRotator.java will return null so the iteration will
throw a NullPointerException.

Change-Id: I5d5980d9593bc9ec75281169ca27ee591809903f
Fix progress of VolumePanel never refresh

On some occasions when disconnecting a headset it is possible for
the volume slider to enter a state where it is no longer updates.

The cause was that ProgressBar enters a state where a call to
doRefreshProgress no longer updates the progress.

The solution was to make sure mRefreshIsPosted is set to false
when mRefreshProgressRunnable is removed.

Change-Id: I1929e4916a582d09a7ec4911eb4f0052ad7a51ba
Prevent a duplicated registration of Observers

If same Observer and same URI are registered, the callback functions are called multiple times
when data identified by a given content URI changes.
It makes system slow and it cause ANR sometimes.
And When run unregisterContentObserver(), just one deleted
but others are remained in mObservers.
So add prevent code to avoid to duplicated registraion of Observers

Change-Id: I5c7845deb682db289ff0d53150ef012174859767
Signed-off-by: muzbit.kim <muzbit.kim@lge.com>
Don't recreate keyguard for MCC/MNC changes.

Change-Id: I9e5dfdb12df522dc7dd50c26f35aba26b1bbe44e