Themes: Update provider with components that were applied

There may be times when one or more components do not get applied
so we should remove them from the component map and then update
the provider after all changes have been made.

Change-Id: I75d2a674d84c6a0de3f0b613d1dfc50654c2d181
(cherry picked from commit 84749d635d733c53cc3b2d214727ec0e40b69550)
Themes: Load correct common resources

In order to support theming separate packages we need to make sure
we load that theme's common resources.  We were currently loading
the system wide theme's common resources which is incorrect for
package level theming.

Change-Id: Ie594458be9b6b3f4a25c56c9c5c9ba5bd8cf063a
(cherry picked from commit a67c2cfafd933598fc3c0fa0f9500cc5feb03b0e)
ActivityManagerService: Fix heavy games kill during incoming call

Force heavy apps penalisation only to large "cached" apps. Donot
include "previous" app in this category. This ensures large apps
are not killed during special incoming alerts like incall, sms.

Change-Id: I51b4a238415efad63ef36f7e0cd056823a72a47d
(cherry picked from commit a7bc4c0391cacc3486118d484ce6b941b1b49d8b)
Prevent killing of process during service bringup

ActivityManagerService sometimes kills the process whose service
is being brought up during bindService.
This happens when the process starts hitting some Pss threashold.
Specifically this is causing InCallUI process to be killed during
bind request from Phone app.

CRs-Fixed: 681329

Change-Id: Id548a22d7e7ce3aa0b0511763078f813fafd6e16
(cherry picked from commit 9f5de64d4ed811d5566f0780f1a38284ed7e4a4a)
base: Change mobile provision checking to 3 times' HTTP connection

For mobile provisioning checking, somehow server is unreachable.
There is more than 10 TCP packets sending out without any TCP ACK
in 1 minutes. It will trigger data stall detection and finally
will cause radio reset happened after several iterations.

This fix will change mobile provisioning checking to only use HTTP
connection for at most 3 times. It will be finished in shorter time
and less than 10 TCP SYNC packets are sent. Hence even server is
unreachable, it will not trigger data stall detection.

CRs-Fixed: 715233
Change-Id: I01a76214b801415969436fee33fdb2c40dcf5793
(cherry picked from commit 1870690c8a2a31426ab30b77c925e1d100562de2)
Remove unnecessary explicit GC in ZygoteInit.

Removes > 1s of GC time and hundreds of GC during device boot.

Zygote size before: 8388608
Zygote size after: 8388608

No increase in zygote space size due to zygote compaction.

Bug: 16398684

Change-Id: I3c6f5a0b26a207ab39bb0a952400d7488e42f00c
(cherry picked from commit e9978634f39756671c261797db9bffb9ae9ffb59)
[Resources] fix preload drawables low issue

Symptom: preload drawables too few
Root Cause: verifyPreloadConfig() function not correct. We need to
convert the config to native config and mask the 0x40000000 bit.
Solution: correct the verifyPreloadConfig() function.
Project: AOSP
Note:

Change-Id: I63eb2a7bf50c89fcb37e62423aae8f4f7e81c6aa
(cherry picked from commit 7f1641689fb3bb5d4a932fb073c2c5679571298d)
[AssetAtlas]: Fix AssetAtlas not consider all size of texture.

Symptom:
Atlas service get exception because the result is null.

Root Cause:
The original logic will miss the largest width in each thread.
Take two processors as an example, first thread will miss 2048, second thread will miss 1984.
With some condition, only 2048*2048 or 1984*2048 can exceed the mThreshold.
In this case, the mResults is empty and cause crash when trying to use the first result.

Solution:
Adjust the boundary and the condition so that it can consider all size of texture.

Change-Id: Id54de57cd1501ed7355f2237f05726d2965aed6d
(cherry picked from commit adc81a8e6868d97781a975cd1a16fb1a1eafd050)
[AssetAtlas] Avoid packing 1-pixel width or height asset into AssetAtlas

Symptom: For preloaded asset which has 1-pixel width (or 1-pixel height),
         sampling the atlas texture will get a color mixed with the surrounding
         pixels' color.
         If we have padding in the atlas texture , sampling will mix the
         padding's black color and result in an obvious defect.

Solugion: We avoid packing 1-pixel width (or 1-pixel height) asset into
          AssetAtlas.

Change-Id: I765673dfa13cf3f3709196cf15f35d3493d1edd8
(cherry picked from commit 54e8be8be00565166ad6dc05bbb58f242d3d4880)
[ActivityManager] Fix ServiceRecord leakage

Symptom:
The first step of cleaning up application services is
to clear the app state from services (which set sr.app
to null). Then it clean up the service connections.
In some scenario, the Service might be removed during
the connection cleanup (i.e. the Service is no longer
needed). In that case, the Service will be removed from
ServiceMap, but won't be removed from r.app.services
(line 1612) because the r.app is null.

Solution:
Remove the service connection first.

Change-Id: I644d73af58fe0e7c1c4a6c9779fe6b5d747b880d
(cherry picked from commit 0d720bae855613ff064e43ba4c793f14c3698fac)
[ActivityManager] Ensure provider external access count will be released.

Sympton: Oom-adj of provider process will be always 0.

Root Cause: Exception happend in openContentUri
may not call removeContentProviderExternalUnchecked.

Flow:
application [MediaPlayer.setDataSource(Context context, Uri uri)]
    uri is invalid, IOException will be caught and below log will appear:
    "Couldn't open file on client side, trying server side"
    Continue to call setDataSource(String path, Map<String, String> headers)
 ->mediaserver [MediaPlayerService::Client::setDataSource]
    setDataSource(httpService, url, headers) calls openContentProviderFile
 ->system_server (ActivityManagerService) [openContentUri]
    Increase externalProcessNoHandleCount for media provider.
    Call [openFile] to media provider.
 ->android.process.media [check permission for openFile]
    enforceReadPermissionInner
 ->system_server [checkComponentPermission]
    Use mediaserver's uid to check READ_EXTERNAL_STORAGE
      -> not granted due to it is pure native process, not a known package.
    Throw security exception then the flow of openContentUri is broke.
    And externalProcessNoHandleCount is unable to decrease.

Application sample code:
 String invalidId = "54321";
 Uri externalUri = MediaStore.Files.getContentUri("external");
 Uri uri = Uri.withAppendedPath(externalUri, invalidId);
 mediaPlayer.setDataSource(mContext, uri);

Solution: Move removeContentProviderExternalUnchecked to finally block.

Change-Id: I75eec1f9631e9c6bb18449946d707d51ac21e8a7
(cherry picked from commit 8034514685be921a38f20d0a355b03fc519da110)
[ActivityManager] Fix NullPointerException when dumping ContentProviderRecord.

Sympton: If there is external access without handles, dumpsys will met exception as:
  * ContentProviderRecord{45ed0fc8 u0 com.android.providers.media/.MediaProvider}
...
    externals=
Exception occurred while dumping:
java.lang.NullPointerException
	at com.android.server.am.ContentProviderRecord.dump(ContentProviderRecord.java:171)

Root Cause: External handles may be empty but there is "no handle" count.

Solution: Check null and print with handle, no handle count.

Change-Id: I0ee497096113e5685d491a0d4346f57d398495e6
(cherry picked from commit 4b603fc4f3d6f9b0923f553c453ce699405033ab)
[ActivityManager] Prevent provider creating twice.

Root Cause:
If a process which contains provider is starting by not
from accessing provider, e.g. service/activity/receiver,
its providers' will be created during handleBindApplication.
And before the process complete publish provider to
ActivityManagerService, if there is an access to its provider,
these providers will be created again (there will have 2nd onCreate).

Solution:
Check if provider record is existed, do not schedule install provider,
becuase it is already creating and will be published later.

Change-Id: Ic200ceae042c014c86e7edee0acd013b513af334
(cherry picked from commit a0dfb3d9658773423a69772ba864a04a7b9a109f)
[ActivityManager] Fix index out of bounds when updating next pss time.

Symptom:
System server crash.

Root Cause:
The value curProcState for array index is -1 if the process has not attached yet.

Solution:
Skip compute for process which is not attached or have invalid curProcState.

Change-Id: I71aaf45bb78d73097ebe9dfebf76b72f2d243232
(cherry picked from commit 8f85faaf52eb209733573effc2b45d3cafb25aa6)
ContentProvider: Avoid duplicate initialization of AsyncTask

AsyncTask is being initialized by ActivityThread to ensure its static
handler initilization and ContentProvider need not duplicate the logic.

Change-Id: I48bc88bdba32b56114f09c04a75480e26508f704
(cherry picked from commit 139c7a02edd13711702871a4f2ea7f7a3e514a54)
[HWUI] The IBO state should be reset after glDeleteBuffers.

Symptom:
Can't bind to correct IBO.

Root Cause:
If a buffer object that is currently bound is deleted by glDeleteBuffers, the binding reverts to 0.
This may cause bindIndicesBuffer doesn't work if mCurrentIndicesBuffer not reset to 0.

Solution:
Reset mCurrentIndicesBuffer to 0 after glDeleteBuffers.

Change-Id: Iecd3ded76d876fcadde89a8893bab5f75b1eb312
(cherry picked from commit 37528a6c88039a00c26a18f4867e593b57daa2b0)
[HWUI] Infinite recursion in PathTessellator::recursiveQuadraticBezierVertices()

Symptom: In some cases like the distance between the calculating point is very
         small, the recursion may not terminate.
         If the calculated dx and dy are 0, d is 0 too. Then the termination
         condition(d*d < TH*TH*(dx*dx*sq + dy*dy*sq)) will never be met.
         Infinite recursion will cause stack-overflow.

Solution: We added one more threshold to terminate the recursion when d is very
          small (possibly 0).

Change-Id: I7d27a72811109766766f8f8cc5d8d88e75db7f60
(cherry picked from commit 2e3bf4e622f001100c0ed9d836c2415eec5884dc)
[HWUI]: Bind wrong VBO when drawing text

Symptom:
We should not set mDrawn to true if we have no GL draw call.

Root Cause:
In some case, issueDrawCommand may executed without GL draw call.
It may miss the unbindMeshBuffer in the next issueDrawCommand and the status of VBO of FontRenderer will incorrect.

Solution:
Add condition to check if have draw call.

Change-Id: I9e96cd0334c515172b0ed6c25b101c81cf6d2e6f
(cherry picked from commit 6173457ae8c6e8ca0ea8afd55df602aa39c89760)
Fixed display of '2147483647' on statusbar

For telephony  network signal strength text view
for some invalid signal values instead of displaying
Integer max use -∞.

Change-Id: I93a16a3b16df7a18cc805356904ab9027e7d0aee
(cherry picked from commit 816b68cbf93dab10bab66024a6b3ef311d167c20)
remove references to nonexistent ringtones

Change-Id: Ibf941da04c081cf065734d728427d033da3e475d
(cherry picked from commit 2b763697aad991e53d5fe13a3538611f495a694f)