SystemUI: Status bar clock - fixes

This commit fixes:

- no overlapping more from status bar icons on center clock.
  The width depending on what the user has setuped (date and clock) is exactly meassured now
- do not start animations if they are not needed
- reduce settings provider calls
- a bit cleanup

Change-Id: I7a37a6ae8f9bad0f265119af05dc20cf21cd6890
bootanimation: Only try to shutdown the mediaplayer if it was prepared

The bootanimation tries to shutdown the mediaplayer gracefully by waiting
on an asynchronous shutdown event for 5 seconds.

If, however, there is no boot sound, that asynchronous shutdown event will
never happen and the animation will be stopped for 5 seconds before shutting
down.

Visibly, this fixes the issue where the bootanimation would simply stop near
the end for exactly 5 seconds.

Change-Id: I77f5631368c7d9b9fef7941a6278af9c36032044
Automatic translation import

Change-Id: If096e5980528f71d62b07783f27db02b2d5139ab
SystemUI: Ensure that the Clock is actually enabled in IconMerger

to device if we need to calculate

Change-Id: If12b0e26b32f044f1a82cf8b539283194d1d0b4c
Fix lockscreen selection view in landscape mode.

Added a dimen-value for selector in landscape-layout to fit screen. Issue is described here:
https://github.com/LegacyXperia/local_manifests/issues/677

Change-Id: I9501c91fed2660e947f1eae617f9a31d95766ed8
SystemUI: make alarm text selector less blocky

It now matches the rest of the selectable items in the expanded header.
None of them had these boundries and neither should this.

Change-Id: I92041ee685a0c16f80c003658abbfd0a6143c07c
Signed-off-by: Roman Birg <roman@cyngn.com>
Add handling SQLiteDatabaseCorruptException.

When SQLiteDatabaseCorruptException occurred on execute() or executeForString(),
DefaultDatabaseErrorHandler.onCorrupt() is not to be called.
So, Malformed DB file can't be deleted.
Because, Instead SQLiteDatabaseCorruptException, code is throwing SQLiteException.
On boot time, system can't open DB file and it throws RuntimeException.
This causes infinite reset.
So, I modified to throw SQLiteDatabaseCorruptException.

Change-Id: I125b69d62acc4c0690b8dd17d4e14b49be141095
Signed-off-by: muzbit.kim <muzbit.kim@lge.com>
Enable stencil clipping within clearLayerRegions

Previously stencil clipping within clearLayerRegions is disabled by commit
62d307c2402777d5e53b4590af5f32f8c55afd81. However, clearing whole layer
regions causes black-colored triangle regions when a TextView has
RotateAnimation because the draw within clearLayerRegions does not
affected by the current stencil clip.

Change-Id: Id32a0b16754b109905f833e063ebfa156bd953f2
Signed-off-by: Dohyun Lee <dohyun.lee@lge.com>
Prevent ANR when broadcast receiver is killed

If the process of a BroacastReceiver is dying at the same time
as the system is trying to send an ordered broadcast to the
receiver, the system will try to start the process again. The
BroadcastQueue will store the BroadcastRecord in mPendingBroadcast
to be able to handle it again when the process is awake. A
timeout Message is posted to the handler of the BroadcastQueue.

As part of the shutdown sequence skipCurrentReceiver is called for
the ProcessRecord. This will check if there is a curReceiver set
for the application and make sure to finish the receiver.

Each of the foreground and background BroadcastQueues have their
own handler for managing broadcast timeouts. If the wrong
BroadcastQueue finishes the receiver, the pending timeout Message
will never be cancelled, leading to an ANR report for a receiver
that has already been finished.

Change-Id: I960c0d8f1a8b739b54a8f09f496b32a3498b9e9a
Dont call close in in BluetoothA2dp finalize

The close in finalize() is pointless, as finalize() will only be called
if there are no references to BluetoothA2dp. Until close() is called,
BluetoothManagerService will have a reference to BluetoothA2dp,
preventing garbage collection and finalize() to be called. This means
finalize() is not serving its purpose of cleaning up in cases close()
is not called, as finalize() is only called if close() has already
been called.

Actually calling close in finalize here means unregistering the already
unregistered mBluetoothStateChangeCallback which can lead to crashes
when pairing/unpairing BTH. A typical crash would look like:

*** FATAL EXCEPTION IN SYSTEM PROCESS: BluetoothManager
java.lang.NullPointerException
at android.os.RemoteCallbackList.unregister(RemoteCallbackList.java:143)
at com.android.server.BluetoothManagerService$BluetoothHandler.handleMessage(BluetoothManagerService.java:780)
at android.os.Handler.dispatchMessage(Handler.java:99)

Change-Id: Ib65962917ecbacf7900d7fe540057e6915f0532d
Correct check of is user running

Before the ActivityManagerService sends an intent or
starts an activity it checks if target user is in
mStartedUsers array.

When removing a non-owner user process the
UserStartedState instance will still be in mStartedUsers
array with mState STOPPING or SHUTDOWN.

This should be checked before sending an intent or start
an activity.

isUserRunningLocked(...) will interpret mState STOPPING
and SHUTDOWN as a non running user.

Change-Id: I1b51bcdb62bdd0f6dbe05dab4d529d4ad40d0d44
Fix NullPointerException in ListView

There is a NullPointerException in `handleHorizontalFocusWithinListItem()`
because `selectedView.findFocus()` returns null and then there is no null
check when when the assigned variable `currentFocus` is used, although
`View.findFocus()` states that it may return null.

Change-Id: I6897027e9a2a238d9283e6b9f5146198989fcac0