Add looper to the thread to fix system_server crash

Toast message internally creates handler and we can't create
handler inside thread that has not called Looper.prepare().
Thus, we added looper to the thread to avoid system_server
carsh.

Change-Id: I09b9c4923c109f0b2707f8346e091efbd24b5089
CRs-Fixed: 669467
Bluetooth: Avoid fd leak for Bluetooth server socket connections

-As the close function of local socket implementation is dependent
 on mFdCreatedInternally, it will not be set for bluetooth server
 sockets, this will lead to fd leak on bluetooth socket connection.

-Exposed the API to set mFdCreatedExternally flag to close fd which
 was opened externally, so that when the actual close request comes
 fd will be closed successfully based on flag check.

CRs-Fixed: 638042
Change-Id: I22c6a973b30531407148f9d9e50820422d4427b0

Bluetooth: Avoid fd leak for Bluetooth server socket connections

-As the close function of local socket implementation is dependent
 on mFdCreatedInternally, it will not be set for bluetooth server
 sockets, this will lead to fd leak on bluetooth socket connection.

-Exposed the API to set mFdCreatedExternally flag to close fd which
 was opened externally, so that when the actual close request comes
 fd will be closed successfully based on flag check.

CRs-Fixed: 638042
Change-Id: I22c6a973b30531407148f9d9e50820422d4427b0
Remove some pointless code.

Unnecessary disk reads for values that are never
used (and cached elsewhere, so that optimization is
rendered pointless).

Change-Id: Ic14a8b53a96908bb03eae28759d7be2c217e8125
Ensure to add persistent apps to LruProcess list on app restart

This change will ensure to add Persistent Apps to mLruProcesses
if not already present while restarting.Previously, on some
occasions, the process was not getting added to the list
resulting in SecurityException as this process was not found
in the mLruProcesses.

Change-Id: I26813a794e01aae316dffd3cf2bb38ab66ac69a9
Set an enough dirty rect for a magnification's boundary line

When using accessibility mode magnification gestures inside
a video artifacts are left on the screen when magnification
is shrunk. It's caused by an incomplete dirty rect.

1. Turn on magnification gestures (in accessibility menu)
2. Play a movie
3. Tap on the bottom of the screen 3 times to zoom.
4. Tap screen once.

The menu buttons will appear, but they will have artifacts from
zoom rectangle drawn on top of them.

The dirty rect is lacking 1 px when a width of the boundary
line is an odd number. It's calculated by the round-off half
of the boundary width.

This change solved the lacking 1 px.

Change-Id: I87f705f239babdb60a5029fd69107501bbab949a
LightsService: Fix to avoid pulse request on a light when its flashing

Change-Id: I69ec6b998d56f20b5b2bae00fe27969a8f5132c8
Fast Media Scan feature implementation

MediaScanner has been modified to support fast
media scan. The entire media scanning is
done in two steps now. First step writes
the basic information of a media file to MediaStore and
second step parses the meta data from media file
and updates the MediaStore. User can view and use the
media files at the end of first step.

Change-Id: I60823bca991bcba6f70bb3cbb3eb7594cc02cf24
NsdService: Fix retrieving the client id

SparseArray.indexOfValue() doesn't work properly on Integer
objects, because its doing an Integer == Integer comparision.
This works for the first 127 client id's due to the boxing
implementation having static Integer objects from -128->127,
but fails on the 128th.

Walk through the clientInfo.mClientIds array manually instead.

This fixes exceptions in NsdManager of the pattern:
FATAL EXCEPTION: NsdManager
java.lang.NullPointerException
     at android.net.nsd.NsdManager$ServiceHandler.handleMessage(NsdManager.java:367)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:137)
     at android.os.HandlerThread.run(HandlerThread.java:61)

due to the client id/listener being -1.

Change-Id: I02a5392fb81f37f5da32f6e7d4619ace1ea6a0ef
Fix External SD Read Write Permission