Inverted adjustments
Do not show Home behind full screen activity

When ensureActivitiesVisibleLocked goes through foreground activity
stack and reaches non-fullscreen activity, it sets showHomeBehindStack
variable to true.

If there is a fullscreen activity behind, showHomeBehindStack remains
unchanged, which causes Home application to be displayed anyway.
In this case user will see a fullscreen activity and Home activity
simultaneously.

To fix the issue we set showHomeBehindStack to false when we reach
fullscreen activity in the activity stack.

This was made visible by the following commit:
446ef1de8d373c1b017df8d19ebf9a47811fb402

Change-Id: I535c1283a4e26f5cf606375b837d4b7195324af0
Prevent Lockscreen album art from activating FLAG_KEEP_SCREEN_ON

This is a small fix to the showWallpaper method, in which a power
consumption problem has been introduced. This showWallpaper method
toggles the window flag FLAG_SHOW_WALLPAPER, when album art is being
shown in Lockscreen. It is important to set pixel format to
PixelFormat.OPAQUE if flag FLAG_SHOW_WALLPAPER is not being set.

If not, an application that uses window flag FLAG_KEEP_SCREEN_ON
will prevent the keyguard from going to sleep and drain battery.

Change-Id: I1808be28047977ae5ac4dd1168ea25cac8a55a78
Solve three memory leaks related to PatchCache

A Patch can be fairly large, holding bitmap data, but
is also frequently leaked which adds to the severity.
The feature is used in many important processes such
as Home, SystemUI and Chrome.

The following leaks are solved:

1. The Patch itself was not always freed.
PatchCache::removeDeferred() can mark patches to be
cared for by PatchCache::clearGarbage(). But
mCache.remove() would only destroy the container
and the pointer, not the Patch object itself.

2. The vertices stored in the Patch at Patch::createMesh()
would always leak. The empty/default destructor in Patch
would not properly destroy "vertices" since it's just a
pointer.

3. A BufferBlock that's added to the mFreeBlocks
in PatchCache could leak. The leak happened when a
patch later needed the entire free block, because the
object was removed from the list but never deleted
in PatchCache::setupMesh().

Change-Id: I41e60824479230b67426fc546d3dbff294c8891f
Convert all selinux_android_restorecon and _setfilecon calls to new API.

libselinux selinux_android_restorecon API is changing to the more
general interface with flags and dropping the older variants.

Also get rid of the old, no longer used selinux_android_setfilecon API
and rename selinux_android_setfilecon2 to it as it is the only API in use.

Change-Id: I1e71ec398ccdc24cac4ec76f1b858d0f680f4925
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
[ActivityManager] Fix a bug: unable to start activity after starting activities during screen off.

Symptom: Unable to start any activity.
Root Cause: ActivityStack.mPausingActivity() points to a destroyed activity of a died process, so that ActivityStackSupervisor.allPausedActivitiesComplete() always returns false.
Solution: Set mPausingActivity to null in ActivityStack.cleanUpActivityLocked().
Reproduce steps:
    a. Turn screen off.
    b. A background service starts an activity X (in process X).
    c. A background service starts a no-history activity Y (in process Y), but the main thread of Y was blocked.
    d. A background service starts Y 3~4 times --> this causes am_failed_to_pause on X.
    e. Main thread of Y is freed finally --> this causes Y crash for android.view.WindowManager$BadTokenException.
    f. Turn screen on, X is shown on screen, but neither back key nor home key can work because mPausingActivity is Y.

Change-Id: I320b3db407e2d4cc745c8ca22a6e548742234242
[ActivityManager] Ensure consistency behavior when a background activity brings another existed activity to front.

Symptom: ANR occurs on previous activity.
Root Cause:
In KK, when a background activity starts another existed background activity (bring to front),
if current focused stack is not the same as the stack of target starting activity,
it will still resume the top of target stack, even the top activity on the target stack may not the same as target activity.
And it will result incorrect focus, press back key will send to previous stack's top then popup ANR on previous activity:
"Reason: Waiting because no window has focus but there is a focused application".

By original code comment, it looks 'bring to front' should not happen in this issue case.
// If the target task is not in the front, then we need
// to bring it to the front...  except...  well, with
// SINGLE_TASK_LAUNCH it's not entirely clear.  We'd like
// to have the same behavior as if a new instance was
// being started, which means not bringing it to the front
// if the caller is not itself in the front.

If the caller and target are in the same stask, it will just deliver new intent without changing task order (the same behavior as JellyBean).
So the patch concept is just to avoid to use target stack to resume top when caller and target are in different stack.

Solution: Do not allow to resume another stack top if non-top activity try to bring existed activity to front.
It may not be a good solution, just a reminder for the issue case.

Reproduce steps:
Assume A, B, C are different app tasks.
When the application stack is like:
  Top C
      B
      A

 #Case 1: Home is foreground
  A starts B with NEW_TASK, C will resume, focus still stays at Home, and window order does not update.
  Then press back key or volumn key will result ANR on Home.

 #Case 2: App is foreground (Resumed activity is C)
  A starts Home, Home will resume, focus still stays at C, and window order does did not update.
  Then press back key or volumn key will result ANR on C.

Change-Id: If05070123b248e2335791e43a4d4ddee6db11d84
GlobalActions: Fix Airplane Mode on/off issue

Issue: Unable to turn off Airplane mode from power button
       after phone reboot

Fix: Initialize mHasTelephony before the PhoneStateListener is
     registered to the TelephonyManager so that correct value
     of mHasTelephony is reflected when onServiceStateChanged
     callback is called.

Bug: 13697360
Change-Id: Ide8afd9c16ea90b98b5912dbff440c5fd67b178d
Fix problem where PhoneWindowManager waits for keyguard to draw

This fixes a problem where PhoneWindowManager times out waiting
for keyguard to draw when it's disabled.  Instead, we pass a null
token back which allows PhoneWindowManager to continue.

Fixes bug 11190932

Change-Id: I041ea1d88dca681476d9477a3aab54559976b312

Conflicts:

	packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java
Catch the NameNotFoundException and return to avoid null pointer when updating package in AMS.

Change-Id: I26cf200cc84639e1261085b6905a567320cbb0a9
Author: Bing Deng <bingx.deng@intel.com>
Signed-off-by: Bing Deng <bingx.deng@intel.com>
Signed-off-by: Shuo Gao <shuo.gao@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Author-tracking-BZ: 63612
Fix SSLCertificateSocketFactory.getDefaultCipherSuites.

The method was returning all supported cipher suites instead of the
default ones only. The default list of cipher suites actually used by
sockets created by this factory is not affected by this issue.

Change-Id: I2e4d7c6547fcb29ff7a0943bc8791706cc8d22bc
ANR caused by incorrect cleanup in BroadcastQueue.

Two broadcasts could be sent to the same app simultaneously:
one foreground, one background. For example, LOCALE_CHANGED
and PACKAGE_CHANGED are delievered to com.android.vending
at the same time.
1. AMS started new vending process to handle LOCALE_CHANGED.
   And set app.curReceiver = LOCALE_CHANGED.
2. Before LOCALE_CHANGED is handled by vending process,
   PACKAGE_CHANGED was delievered to vending process too.
   AMS set app.curReceiver = PACKAGE_CHANGED. Bad!
3. Vending process finished handling LOCALE_CHANGED.
   AMS clear app.curReceiver = NULL. Bad!
   And Vending process  killed itself without handling
   PACKAGE_CHANGED.
4. AMS known vending process has died, but didn't know that
   BgBroadcastQueue was still waiting for finish message
   for PACKAGE_CHANGED.
At last, BgBroadcastQueue reported ANR for PACKAGE_CHANGED.

This patch adds protection before clearing app.curReceiver,
only set to NULL if the finishing receiver = app.curReceiver
So handleAppDied would know that PACKAGE_CHANGED was not
finished yet, it will abort the broadcast and continue.

Change-Id: Ic4f31b35e21823d4a3c27712391ecbede213a494
Signed-off-by: Guobin Zhang <guobin.zhang@intel.com>
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
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
Fix null check for BaseObj.equals.

Change-Id: I4f060697db175cbf0b5617c1220db853bbe53f1f
GC: Improve the string parsing for GC parameter setting

Improve the string parsing for GC parameter system property.
Previously we only recoganize plain number for dalvik.vm.heapminfree
and dalvik.vm.heapconcurrentstart, while users tend to use format as
2m.  Improve the string parse to cover such cases.

Change-Id: Iaf0152bc4d77e1caabc307a9a7b0e5b261f8e441
server: start cne service

Connectivity Engine (CnE) provides advanced network selection per socket,
reduced signalling traffic, and increased power savings.
The service implements the interface defined by CNEManager which Android
applications may use.

Change-Id: I9ffd1f5d60f5e9e185ab482a35b3b07f29a4124c
(cherry picked from commit 3a4e3ba1bc67c460ec3c2fd4ef169ae25e3e69b1)
(cherry picked from commit 1bb0036652318ac8bbecf3e6c810bbc779387c61)
(cherry picked from commit 3c8af4a2546d9b71d113072d680107cb56651e71)
(cherry picked from commit 861a4b062196020bf24a5b3731c717b5b95a7d77)
(cherry picked from commit e3dba9799892f13c5bc2376b81cf5dceae17492c)

Add Connectivity Engine (CnE) WQE support

Enhanced connectivity features viz. Wifi Quality Estimation.
Supports dual network mode - wifi & mobile simultaneously.
Use QcConnectivityService when CnE is enabled for all CnE features.

Change-Id: I14b02e21515bfc1b5fd2fc4f28e5190fa80f83f8

server: Initialize ConnectivityService on low memory device

Skip initialization of QcConnectivityService and
use ConnectivityService.java for a low memory device

CRs-Fixed: 531430

Change-Id: I2111ec32f6e40ca79b7fc91ec4cef97ac27f3b3a

Update CNE feature values.

Start QcConnectivityServices for the new
application traffic profiling feature too.

Change-Id: I52ae76420ebd098d43fe0663f41ce622a407b90e

connectivity: allow inheritance to subclass

set modifier to protected in order to allow
subclass to use the same data and avoid redefinition.

Change-Id: I2dc688d3e433775cb073ec6faae3981807212cc9

Change visibility of methods

Change the visibility of some methods so that
they are accessible to the child class.

Change-Id: Ie1a45978b42742cac0aaedba29fb2375882c0ae4
CRs-Fixed: 611347