Move 3rd party wallpaper pickers to the front

This is a feature request from Steve so here you go!

Change-Id: Iac6a26c7b51752d65026a871712c3590caa926d9
(cherry picked from commit f44a681b4403d3c690e2d62c9981dd5ac88a7522)
Include default wallpaper in LockscreenWallpaperPickerActivity

Change-Id: I0e3d46688bdb257bc32e10d9255dfc4fbf7beb4c
(cherry picked from commit fbd922760ad7c29f47ccadfe0b93ec0452487e8f)
Add navbar background preview to ThemesContract

Change-Id: Id3ed43c86649b1757fec7f3fc7dee2d2730258e2
(cherry picked from commit 7feef1de1880afff835c25880655866da8c76627)
Proximity : Check proximity flags only if from native

Change-Id: Id1be619e638de6a45252d8390eab6e38bd5de5a7
(cherry picked from commit 276da94ae7bf6ec0993ede12bed195f03455083c)
NetworkManagementService: Change exception type thrown on IPv6

Changed the exception type thrown from IllegalStateException to
RemoteException whenever the IPv6 tethering rules fail to apply. The
IllegalStateException is not caught by the caller causing the JVM
to crash. By throwing RemoteException, the caller will catch and
print and error message instead of crashing.

CRs-Fixed: 662171
Change-Id: I92fadd43479a330f09bb20f699a4b9852123ab68
(cherry picked from commit b2edbdb5fd42e7a260f19df060f31dd8fffba8bb)
Broadcast upstream interface change event independently for IPv4 & IPv6

On change in tethering upstream interface for IPV4 or IPV6 address,
broadcast an intent with the information viz iface name, ip address
type and update type(i.e add or delete).

Change-Id: I69339dc0cfe3ceb566eb1891e264ccfd07785b48
CRs-Fixed: 680728
(cherry picked from commit 625ac4143a0bbd45c1fd34bd5337b2496312c0f9)
Revert " Audio: SetForceUse config check in AudioService"

This reverts commit 0af88afe6dc16760b57afa74ca42e40fbe6ff9cf.

- During playback over BT using the Google Play Music app,
  if BT is disconnected through the app and playback is resumed,
  it continues over BT and not the speaker.
- The original commit forces playback to continue over BT
  although it is disconnected.
- Reverting the commit fixes this issue and the issue
  addressed by the commit is also not observed after reversion.

CRs-Fixed: 679301
Change-Id: Ic4d0f13615c696a12401f7a8a58651b88f31e99b
(cherry picked from commit 808aa25ba23a3ca1f97db5f5a62b5e63b64b9070)
Revert "[View] Clear Hardware-Layers before system destroys HardwareRenderer​."

This reverts commit af52834898f45c62d83e4310c67907990d707543.

(cherry picked from commit 04b26b375bc5c6a4bdaab2e281d5c15a81c78b57)
[View] Clear Hardware-Layers before system destroys HardwareRenderer​.

Symptom: Sometimes HardwareLayer display is corrupted.

Root Cause: In some cases, ViewRootImpl destroys HardwareRenderer​ without
clearing HardwareLayers in the view hirarchy. If the system trims memory fully
and kill the glContext at the same time, HardwareLayer may corrupt.

Solution: Clear Hardware-Layers before system destroys HardwareRenderer​.

Reproduce steps: Modify the cache's trim memory mechanism to make it easier to
trim fully, HardwareLayers implemented in app will easily be corrupted.
Modification of the cache is not required but make it easier to reproduce.

Change-Id: If57c802cdacf8dc37cbbcc199e74f9482834f981
(cherry picked from commit 4d499ed8c4e0a82198846006fba7dfd85113c87b)
[ActivityManager] Ensure alive process is not killedByAm.

Symptom: Unable to kill by Am again and will be skipped updating its oom adj.

Root Cause:
A restarted process will reuse original process record.
The flag killedByAm will keep previous state.

Solution:
Reset the flag killedByAm to false when the process is started.

Note: Found another similiar patch If95137d91939cc44882ad2813131bcde0edd0c1b

Change-Id: I59a86648ca8d0aed4c489d92751af120aae5ef90
(cherry picked from commit 5578ea29a9018a86f801671df458ad296ce0ad09)
[ActivityManager] Prevent kill a restarted process again.

Root Cause:
Use removeTask with flag ActivityManager.REMOVE_TASK_KILL_PROCESS will set waitingToKill = "remove task"
to the target process when its setSchedGroup is not BG_NONINTERACTIVE.
Later the target process may be killed when applying oom-adj due to setSchedGroup has changed to BG_NONINTERACTIVE.
If the process is needed to restart, the process record will be resued.
Then the restarted process may be killed again because its waitingToKill is not null.

Solution:
Clean waitingToKill when process is dead.

Change-Id: I5ffb5388127f4221da4c700d3f1c224f7ca6e7b2
(cherry picked from commit 80421cd9ee4bb096d75c5b136403725bb6227414)
[ActivityManager] Avoid keeping restarting home when only home activity exists.

Root Cause:
When there is only home activity existed,
updating home apk will call forceStopPackageLocked to finish the activity.
Then activity history becomes empty, then home will be launched,
but its package is still target to close that results a loop.

Solution:
If home activity has been force-stopped, do not stop the same home activity again.

Change-Id: Icff12028d407873c2e6f50a06bcad231b908ccbd
(cherry picked from commit 72dc1b24703758f3f6363d04cb20bf6d5962b1f0)
[ActivityManager] Prevent potential deadlock from system error dialog and InputMethodManager.

Sympton:
When application crash in a special timing and system server's InputMethodManager is binding, deadlock may occur.

Root Cause:
Thread(1): When using InputMethodManager in system server, it will lock mH(handler) of InputMethodManager,
and sometimes it will call to InputMethodManagerService::showCurrentInputLocked and will call bindService at some condition,
then it will also lock ActivityManagerService.
Thread(2): When an application crashed, it will lock ActivityManager when showing crash dialog, inside the dialog,
it will call setEnabled of Button and lock mH of InputMethodManager.setEnable of TextView will lock IMM's handler.
So the deadlock happened as the flow: (2) lock AMS -> (1)lock mH -> (2)wait mH -> (1) wait AMS

Solution:
Reduce nested lock of error dialog: post message to let (2) lock mH after release AMS lock.

Change-Id: Id85c29406236db3b5fca9655fde1fcaf0afd1337
(cherry picked from commit 2dbeaa1c99d8e1cda63dceece53df61e09fd3434)
[ActivityManager] Move top task to top in window manager

Symptom:
In certain situations, application starts activity while
it is in background. When an existing background activity
starts a new activity which results to be kept in the same
background task, the new activity won't be resumed.
In that case, the background task (sourceTask) should not be
moved to top in window manager.

Solution:
Move top task of the target stack to top in window manager

Change-Id: Id7a37ea67ce1f80e0c2b5399865c51fd7113deb8
(cherry picked from commit 7ed8e5d98b4ff681a0c63b4805035ec213570436)
[ActivityManager] Do not finish root activity when reset task

Symptom:
The root activity not always located at index 0 of the task.
For example, the index 1 activity will become the new root
when the original root activity (at index 0) finished.
The new root activity might be finished unexpectedly before
the original root activity actually destroyed.

Solution:
Check frontOfTask to avoid finishing the root activity unexpectedly

Change-Id: I623ab97e9c95c83b3cfe7c9dfc151a291a391ea4
(cherry picked from commit d11e5515b177f4255ee8042deb5a34c7fcf3250a)
[ActivityManager]: Update home process when home activity resumed

Symptom:
  When switch between two home activities, the home process might not be updated to the correct one. In that case, the home activity might be killed easily.

Root Cause:
  The home process is updated only when a home activity is newly created or being restarted. ActivityManager did not update the home process when simply resume a home activity.

Solution:
  Update home process when home activity resumed

Reproduce Steps:
  1. Install a launcher application, such as Apex Launcher
  2. Press home key to change to Apex Launcher by "Just once" option
  3. Press home key to switch back to original home activity by "Just once" option.
     (The home process is still the Apex Launcher's process because ActivityManager does not update the home process when resuming the original home activity.)

Change-Id: I046279ca7ba851a283ee67ea19202890f7b3f343
(cherry picked from commit 68aa07f6a630256d7c3eb2a1fbe13befa6fe4283)
[ActivityManager] Prevent coredump file may not complete for testing.

Sympton:
During testing, skip kill native crash process manually because it will continue to die by default.

Root Cause:
Large process may take some time to do coredump.In auto test, crash process will be killed immediately that results incomplete coredump file.

Solution:
If the tester (IActivityController) will handle app crash event,
Do not kill native crashed process if the rom is debuggable.

Change-Id: Ia360af147d694125d440e5ba2f958c4759a50494
(cherry picked from commit 78acfc4911e0f8d0a8a8014a708c55d030ec8539)
LockscreenTile : Don't rely on DEVICE_POLICY broadcast

The current trigger used for initialization is too finicky and doesn't
work on some devices. Switch to trigger based on instantiation of the service
inside the delegate instead.

Also fix inverted drawable state.

Change-Id: I8439ed50281de805ae68fe7b5a81220475d98022
(cherry picked from commit 33fb78db4fc24d3c0b799e62b3997bf37d880d07)