• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

修订版2f4457484a13422a28698cd06ce2efb2906d2f5f (tree)
时间2010-02-27 17:46:27
作者Chih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

merge from donut

更改概述

差异

--- a/core/java/android/content/SyncStorageEngine.java
+++ b/core/java/android/content/SyncStorageEngine.java
@@ -377,7 +377,7 @@ public class SyncStorageEngine extends Handler {
377377 int i = mAuthorities.size();
378378 while (i > 0) {
379379 i--;
380- AuthorityInfo authority = mAuthorities.get(i);
380+ AuthorityInfo authority = mAuthorities.valueAt(i);
381381 if (authority.authority.equals(providerName)
382382 && authority.enabled) {
383383 return true;
@@ -399,7 +399,7 @@ public class SyncStorageEngine extends Handler {
399399 int i = mAuthorities.size();
400400 while (i > 0) {
401401 i--;
402- AuthorityInfo authority = mAuthorities.get(i);
402+ AuthorityInfo authority = mAuthorities.valueAt(i);
403403 if (authority.authority.equals(providerName)) {
404404 authority.enabled = sync;
405405 }
@@ -548,7 +548,7 @@ public class SyncStorageEngine extends Handler {
548548 mPendingOperations.clear();
549549 final int N = mSyncStatus.size();
550550 for (int i=0; i<N; i++) {
551- mSyncStatus.get(i).pending = false;
551+ mSyncStatus.valueAt(i).pending = false;
552552 }
553553 writePendingOperationsLocked();
554554 }
@@ -843,7 +843,7 @@ public class SyncStorageEngine extends Handler {
843843 SyncStatusInfo best = null;
844844 final int N = mSyncStatus.size();
845845 for (int i=0; i<N; i++) {
846- SyncStatusInfo cur = mSyncStatus.get(i);
846+ SyncStatusInfo cur = mSyncStatus.valueAt(i);
847847 AuthorityInfo ainfo = mAuthorities.get(cur.authorityId);
848848 if (ainfo != null && ainfo.authority.equals(authority)) {
849849 if (best == null) {
@@ -864,7 +864,7 @@ public class SyncStorageEngine extends Handler {
864864 synchronized (mAuthorities) {
865865 final int N = mSyncStatus.size();
866866 for (int i=0; i<N; i++) {
867- SyncStatusInfo cur = mSyncStatus.get(i);
867+ SyncStatusInfo cur = mSyncStatus.valueAt(i);
868868 AuthorityInfo ainfo = mAuthorities.get(cur.authorityId);
869869 if (ainfo == null) {
870870 continue;
@@ -1131,7 +1131,7 @@ public class SyncStorageEngine extends Handler {
11311131
11321132 final int N = mAuthorities.size();
11331133 for (int i=0; i<N; i++) {
1134- AuthorityInfo authority = mAuthorities.get(i);
1134+ AuthorityInfo authority = mAuthorities.valueAt(i);
11351135 out.startTag(null, "authority");
11361136 out.attribute(null, "id", Integer.toString(authority.ident));
11371137 out.attribute(null, "account", authority.account);
@@ -1217,7 +1217,7 @@ public class SyncStorageEngine extends Handler {
12171217 SyncStatusInfo st = null;
12181218 while (i > 0) {
12191219 i--;
1220- st = mSyncStatus.get(i);
1220+ st = mSyncStatus.valueAt(i);
12211221 if (st.authorityId == authority.ident) {
12221222 found = true;
12231223 break;
--- a/core/jni/android/opengl/util.cpp
+++ b/core/jni/android/opengl/util.cpp
@@ -1,16 +1,16 @@
11 /**
22 ** Copyright 2007, The Android Open Source Project
33 **
4- ** Licensed under the Apache License, Version 2.0 (the "License");
5- ** you may not use this file except in compliance with the License.
6- ** You may obtain a copy of the License at
4+ ** Licensed under the Apache License, Version 2.0 (the "License");
5+ ** you may not use this file except in compliance with the License.
6+ ** You may obtain a copy of the License at
77 **
8- ** http://www.apache.org/licenses/LICENSE-2.0
8+ ** http://www.apache.org/licenses/LICENSE-2.0
99 **
10- ** Unless required by applicable law or agreed to in writing, software
11- ** distributed under the License is distributed on an "AS IS" BASIS,
12- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- ** See the License for the specific language governing permissions and
10+ ** Unless required by applicable law or agreed to in writing, software
11+ ** distributed under the License is distributed on an "AS IS" BASIS,
12+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ ** See the License for the specific language governing permissions and
1414 ** limitations under the License.
1515 */
1616
@@ -53,18 +53,18 @@ public:
5353 MallocHelper() {
5454 mData = 0;
5555 }
56-
56+
5757 ~MallocHelper() {
5858 if (mData != 0) {
5959 free(mData);
6060 }
6161 }
62-
62+
6363 void* alloc(size_t size) {
6464 mData = malloc(size);
6565 return mData;
6666 }
67-
67+
6868 private:
6969 void* mData;
7070 };
@@ -88,17 +88,17 @@ int visibilityTest(float* pWS, float* pPositions, int positionsLength,
8888 int result = POLY_CLIP_OUT;
8989 float* pTransformed = 0;
9090 int transformedIndexCount = 0;
91-
91+
9292 if ( indexCount < 3 ) {
9393 return POLY_CLIP_OUT;
9494 }
95-
95+
9696 // Find out how many vertices we need to transform
9797 // We transform every vertex between the min and max indices, inclusive.
9898 // This is OK for the data sets we expect to use with this function, but
9999 // for other loads it might be better to use a more sophisticated vertex
100100 // cache of some sort.
101-
101+
102102 int minIndex = 65536;
103103 int maxIndex = -1;
104104 for(int i = 0; i < indexCount; i++) {
@@ -110,18 +110,18 @@ int visibilityTest(float* pWS, float* pPositions, int positionsLength,
110110 maxIndex = index;
111111 }
112112 }
113-
113+
114114 if ( maxIndex * 3 > positionsLength) {
115115 return -1;
116116 }
117-
117+
118118 transformedIndexCount = maxIndex - minIndex + 1;
119119 pTransformed = (float*) mallocHelper.alloc(transformedIndexCount * 4 * sizeof(float));
120-
120+
121121 if (pTransformed == 0 ) {
122122 return -2;
123123 }
124-
124+
125125 // Transform the vertices
126126 {
127127 const float* pSrc = pPositions + 3 * minIndex;
@@ -130,9 +130,9 @@ int visibilityTest(float* pWS, float* pPositions, int positionsLength,
130130 mx4transform(pSrc[0], pSrc[1], pSrc[2], 1.0f, pWS, pDst);
131131 }
132132 }
133-
133+
134134 // Clip the triangles
135-
135+
136136 Poly poly;
137137 float* pDest = & poly.vert[0].sx;
138138 for (int i = 0; i < indexCount; i += 3) {
@@ -166,14 +166,14 @@ public:
166166 mEnv->ReleasePrimitiveArrayCritical(mRef, mBase, mReleaseParam);
167167 }
168168 }
169-
169+
170170 // We seperate the bounds check from the initialization because we want to
171171 // be able to bounds-check multiple arrays, and we can't throw an exception
172172 // after we've called GetPrimitiveArrayCritical.
173-
173+
174174 // Return true if the bounds check succeeded
175175 // Else instruct the runtime to throw an exception
176-
176+
177177 bool check() {
178178 if ( ! mRef) {
179179 mEnv->ThrowNew(gIAEClass, "array == null");
@@ -190,9 +190,9 @@ public:
190190 }
191191 return true;
192192 }
193-
193+
194194 // Bind the array.
195-
195+
196196 void bind() {
197197 mBase = (T*) mEnv->GetPrimitiveArrayCritical(mRef, (jboolean *) 0);
198198 mData = mBase + mOffset;
@@ -201,10 +201,10 @@ public:
201201 void commitChanges() {
202202 mReleaseParam = 0;
203203 }
204-
204+
205205 T* mData;
206206 int mLength;
207-
207+
208208 private:
209209 T* mBase;
210210 JNIEnv* mEnv;
@@ -226,29 +226,29 @@ inline float distance2(float x, float y, float z) {
226226 inline float distance(float x, float y, float z) {
227227 return sqrtf(distance2(x, y, z));
228228 }
229-
229+
230230 static
231231 void util_computeBoundingSphere(JNIEnv *env, jclass clazz,
232232 jfloatArray positions_ref, jint positionsOffset, jint positionsCount,
233233 jfloatArray sphere_ref, jint sphereOffset) {
234234 FloatArrayHelper positions(env, positions_ref, positionsOffset, 0);
235235 FloatArrayHelper sphere(env, sphere_ref, sphereOffset, 4);
236-
236+
237237 bool checkOK = positions.check() && sphere.check();
238238 if (! checkOK) {
239239 return;
240240 }
241-
241+
242242 positions.bind();
243243 sphere.bind();
244-
244+
245245 if ( positionsCount < 1 ) {
246246 env->ThrowNew(gIAEClass, "positionsCount < 1");
247247 return;
248248 }
249-
249+
250250 const float* pSrc = positions.mData;
251-
251+
252252 // find bounding box
253253 float x0 = *pSrc++;
254254 float x1 = x0;
@@ -256,7 +256,7 @@ void util_computeBoundingSphere(JNIEnv *env, jclass clazz,
256256 float y1 = y0;
257257 float z0 = *pSrc++;
258258 float z1 = z0;
259-
259+
260260 for(int i = 1; i < positionsCount; i++) {
261261 {
262262 float x = *pSrc++;
@@ -286,7 +286,7 @@ void util_computeBoundingSphere(JNIEnv *env, jclass clazz,
286286 }
287287 }
288288 }
289-
289+
290290 // Because we know our input meshes fit pretty well into bounding boxes,
291291 // just take the diagonal of the box as defining our sphere.
292292 float* pSphere = sphere.mData;
@@ -297,7 +297,7 @@ void util_computeBoundingSphere(JNIEnv *env, jclass clazz,
297297 *pSphere++ = y0 + dy * 0.5f;
298298 *pSphere++ = z0 + dz * 0.5f;
299299 *pSphere++ = distance(dx, dy, dz) * 0.5f;
300-
300+
301301 sphere.commitChanges();
302302 }
303303
@@ -344,7 +344,7 @@ static void computeFrustum(const float* m, float* f) {
344344 normalizePlane(f);
345345 f+= 4;
346346
347- // left
347+ // left
348348 f[0] = m3 + m[0];
349349 f[1] = m7 + m[4];
350350 f[2] = m11 + m[8];
@@ -396,20 +396,20 @@ int util_frustumCullSpheres(JNIEnv *env, jclass clazz,
396396 FloatArrayHelper mvp(env, mvp_ref, mvpOffset, 16);
397397 FloatArrayHelper spheres(env, spheres_ref, spheresOffset, spheresCount * 4);
398398 IntArrayHelper results(env, results_ref, resultsOffset, resultsCapacity);
399-
399+
400400 bool initializedOK = mvp.check() && spheres.check() && results.check();
401401 if (! initializedOK) {
402402 return -1;
403403 }
404-
404+
405405 mvp.bind();
406406 spheres.bind();
407407 results.bind();
408-
408+
409409 computeFrustum(mvp.mData, frustum);
410-
410+
411411 // Cull the spheres
412-
412+
413413 pSphere = spheres.mData;
414414 pResults = results.mData;
415415 outputCount = 0;
@@ -436,27 +436,27 @@ int util_visibilityTest(JNIEnv *env, jclass clazz,
436436 jfloatArray ws_ref, jint wsOffset,
437437 jfloatArray positions_ref, jint positionsOffset,
438438 jcharArray indices_ref, jint indicesOffset, jint indexCount) {
439-
439+
440440 FloatArrayHelper ws(env, ws_ref, wsOffset, 16);
441441 FloatArrayHelper positions(env, positions_ref, positionsOffset, 0);
442442 UnsignedShortArrayHelper indices(env, indices_ref, indicesOffset, 0);
443-
443+
444444 bool checkOK = ws.check() && positions.check() && indices.check();
445445 if (! checkOK) {
446446 // Return value will be ignored, because an exception has been thrown.
447447 return -1;
448448 }
449-
449+
450450 if (indices.mLength < indexCount) {
451451 env->ThrowNew(gIAEClass, "length < offset + indexCount");
452452 // Return value will be ignored, because an exception has been thrown.
453453 return -1;
454454 }
455-
455+
456456 ws.bind();
457457 positions.bind();
458458 indices.bind();
459-
459+
460460 return visibilityTest(ws.mData,
461461 positions.mData, positions.mLength,
462462 indices.mData, indexCount);
@@ -496,19 +496,19 @@ void util_multiplyMM(JNIEnv *env, jclass clazz,
496496 FloatArrayHelper resultMat(env, result_ref, resultOffset, 16);
497497 FloatArrayHelper lhs(env, lhs_ref, lhsOffset, 16);
498498 FloatArrayHelper rhs(env, rhs_ref, rhsOffset, 16);
499-
499+
500500 bool checkOK = resultMat.check() && lhs.check() && rhs.check();
501-
501+
502502 if ( !checkOK ) {
503503 return;
504504 }
505-
505+
506506 resultMat.bind();
507507 lhs.bind();
508508 rhs.bind();
509-
509+
510510 multiplyMM(resultMat.mData, lhs.mData, rhs.mData);
511-
511+
512512 resultMat.commitChanges();
513513 }
514514
@@ -527,19 +527,19 @@ void util_multiplyMV(JNIEnv *env, jclass clazz,
527527 FloatArrayHelper resultV(env, result_ref, resultOffset, 4);
528528 FloatArrayHelper lhs(env, lhs_ref, lhsOffset, 16);
529529 FloatArrayHelper rhs(env, rhs_ref, rhsOffset, 4);
530-
530+
531531 bool checkOK = resultV.check() && lhs.check() && rhs.check();
532-
532+
533533 if ( !checkOK ) {
534534 return;
535535 }
536-
536+
537537 resultV.bind();
538538 lhs.bind();
539539 rhs.bind();
540-
540+
541541 multiplyMV(resultV.mData, lhs.mData, rhs.mData);
542-
542+
543543 resultV.commitChanges();
544544 }
545545
@@ -550,7 +550,7 @@ static jfieldID nativeBitmapID = 0;
550550 void nativeUtilsClassInit(JNIEnv *env, jclass clazz)
551551 {
552552 jclass bitmapClass = env->FindClass("android/graphics/Bitmap");
553- nativeBitmapID = env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
553+ nativeBitmapID = env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
554554 }
555555
556556 static int checkFormat(SkBitmap::Config config, int format, int type)
@@ -653,7 +653,7 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz,
653653 }
654654 int err = checkFormat(config, internalformat, type);
655655 if (err)
656- return err;
656+ return err;
657657 bitmap.lockPixels();
658658 const int w = bitmap.width();
659659 const int h = bitmap.height();
@@ -665,14 +665,15 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz,
665665 }
666666 const size_t size = bitmap.getSize();
667667 const size_t palette_size = 256*sizeof(SkPMColor);
668- void* const data = malloc(size + palette_size);
668+ const size_t imageSize = size + palette_size;
669+ void* const data = malloc(imageSize);
669670 if (data) {
670671 void* const pixels = (char*)data + palette_size;
671672 SkColorTable* ctable = bitmap.getColorTable();
672673 memcpy(data, ctable->lockColors(), ctable->count() * sizeof(SkPMColor));
673674 memcpy(pixels, p, size);
674675 ctable->unlockColors(false);
675- glCompressedTexImage2D(target, level, internalformat, w, h, border, 0, data);
676+ glCompressedTexImage2D(target, level, internalformat, w, h, border, imageSize, data);
676677 free(data);
677678 } else {
678679 err = -1;
@@ -700,7 +701,7 @@ static jint util_texSubImage2D(JNIEnv *env, jclass clazz,
700701 }
701702 int err = checkFormat(config, format, type);
702703 if (err)
703- return err;
704+ return err;
704705 bitmap.lockPixels();
705706 const int w = bitmap.width();
706707 const int h = bitmap.height();
@@ -723,22 +724,22 @@ lookupClasses(JNIEnv* env) {
723724 }
724725
725726 static JNINativeMethod gMatrixMethods[] = {
726- { "multiplyMM", "([FI[FI[FI)V", (void*)util_multiplyMM },
727- { "multiplyMV", "([FI[FI[FI)V", (void*)util_multiplyMV },
727+ { "multiplyMM", "([FI[FI[FI)V", (void*)util_multiplyMM },
728+ { "multiplyMV", "([FI[FI[FI)V", (void*)util_multiplyMV },
728729 };
729730
730731 static JNINativeMethod gVisiblityMethods[] = {
731- { "computeBoundingSphere", "([FII[FI)V", (void*)util_computeBoundingSphere },
732+ { "computeBoundingSphere", "([FII[FI)V", (void*)util_computeBoundingSphere },
732733 { "frustumCullSpheres", "([FI[FII[III)I", (void*)util_frustumCullSpheres },
733- { "visibilityTest", "([FI[FI[CII)I", (void*)util_visibilityTest },
734+ { "visibilityTest", "([FI[FI[CII)I", (void*)util_visibilityTest },
734735 };
735736
736737 static JNINativeMethod gUtilsMethods[] = {
737738 {"nativeClassInit", "()V", (void*)nativeUtilsClassInit },
738- { "native_getInternalFormat", "(Landroid/graphics/Bitmap;)I", (void*) util_getInternalFormat },
739- { "native_getType", "(Landroid/graphics/Bitmap;)I", (void*) util_getType },
740- { "native_texImage2D", "(IIILandroid/graphics/Bitmap;II)I", (void*)util_texImage2D },
741- { "native_texSubImage2D", "(IIIILandroid/graphics/Bitmap;II)I", (void*)util_texSubImage2D },
739+ { "native_getInternalFormat", "(Landroid/graphics/Bitmap;)I", (void*) util_getInternalFormat },
740+ { "native_getType", "(Landroid/graphics/Bitmap;)I", (void*) util_getType },
741+ { "native_texImage2D", "(IIILandroid/graphics/Bitmap;II)I", (void*)util_texImage2D },
742+ { "native_texSubImage2D", "(IIIILandroid/graphics/Bitmap;II)I", (void*)util_texSubImage2D },
742743 };
743744
744745 typedef struct _ClassRegistrationInfo {
--- a/core/jni/android_hardware_Camera.cpp
+++ b/core/jni/android_hardware_Camera.cpp
@@ -112,7 +112,7 @@ void JNICameraContext::notify(int32_t msgType, int32_t ext1, int32_t ext2)
112112 }
113113 JNIEnv *env = AndroidRuntime::getJNIEnv();
114114 env->CallStaticVoidMethod(mCameraJClass, fields.post_event,
115- mCameraJObjectWeak, msgType, ext1, ext2);
115+ mCameraJObjectWeak, msgType, ext1, ext2, NULL);
116116 }
117117
118118 void JNICameraContext::copyAndPost(JNIEnv* env, const sp<IMemory>& dataPtr, int msgType)
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -32,6 +32,7 @@
3232 #include <sys/errno.h>
3333 #include <sys/resource.h>
3434 #include <sys/types.h>
35+#include <cutils/sched_policy.h>
3536 #include <dirent.h>
3637 #include <fcntl.h>
3738 #include <grp.h>
@@ -50,13 +51,7 @@ pid_t gettid() { return syscall(__NR_gettid);}
5051 #undef __KERNEL__
5152 #endif
5253
53-/*
54- * List of cgroup names which map to ANDROID_TGROUP_ values in Thread.h
55- * and Process.java
56- * These names are used to construct the path to the cgroup control dir
57- */
58-
59-static const char *cgroup_names[] = { NULL, "bg_non_interactive", "fg_boost" };
54+#define POLICY_DEBUG 0
6055
6156 using namespace android;
6257
@@ -194,28 +189,6 @@ jint android_os_Process_getGidForName(JNIEnv* env, jobject clazz, jstring name)
194189 return -1;
195190 }
196191
197-static int add_pid_to_cgroup(int pid, int grp)
198-{
199- int fd;
200- char path[255];
201- char text[64];
202-
203- sprintf(path, "/dev/cpuctl/%s/tasks",
204- (cgroup_names[grp] ? cgroup_names[grp] : ""));
205-
206- if ((fd = open(path, O_WRONLY)) < 0)
207- return -1;
208-
209- sprintf(text, "%d", pid);
210- if (write(fd, text, strlen(text)) < 0) {
211- close(fd);
212- return -1;
213- }
214-
215- close(fd);
216- return 0;
217-}
218-
219192 void android_os_Process_setThreadGroup(JNIEnv* env, jobject clazz, int pid, jint grp)
220193 {
221194 if (grp > ANDROID_TGROUP_MAX || grp < 0) {
@@ -223,10 +196,9 @@ void android_os_Process_setThreadGroup(JNIEnv* env, jobject clazz, int pid, jint
223196 return;
224197 }
225198
226- if (add_pid_to_cgroup(pid, grp)) {
227- // If the thread exited on us, don't generate an exception
228- if (errno != ESRCH && errno != ENOENT)
229- signalExceptionForGroupError(env, clazz, errno);
199+ if (set_sched_policy(pid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ?
200+ SP_BACKGROUND : SP_FOREGROUND)) {
201+ signalExceptionForGroupError(env, clazz, errno);
230202 }
231203 }
232204
@@ -242,6 +214,26 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
242214 return;
243215 }
244216
217+#if POLICY_DEBUG
218+ char cmdline[32];
219+ int fd;
220+
221+ strcpy(cmdline, "unknown");
222+
223+ sprintf(proc_path, "/proc/%d/cmdline", pid);
224+ fd = open(proc_path, O_RDONLY);
225+ if (fd >= 0) {
226+ int rc = read(fd, cmdline, sizeof(cmdline)-1);
227+ cmdline[rc] = 0;
228+ close(fd);
229+ }
230+
231+ if (grp == ANDROID_TGROUP_BG_NONINTERACT) {
232+ LOGD("setProcessGroup: vvv pid %d (%s)", pid, cmdline);
233+ } else {
234+ LOGD("setProcessGroup: ^^^ pid %d (%s)", pid, cmdline);
235+ }
236+#endif
245237 sprintf(proc_path, "/proc/%d/task", pid);
246238 if (!(d = opendir(proc_path))) {
247239 // If the process exited on us, don't generate an exception
@@ -271,13 +263,10 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
271263 continue;
272264 }
273265
274- if (add_pid_to_cgroup(t_pid, grp)) {
275- // If the thread exited on us, ignore it and keep going
276- if (errno != ESRCH && errno != ENOENT) {
277- signalExceptionForGroupError(env, clazz, errno);
278- closedir(d);
279- return;
280- }
266+ if (set_sched_policy(t_pid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ?
267+ SP_BACKGROUND : SP_FOREGROUND)) {
268+ signalExceptionForGroupError(env, clazz, errno);
269+ break;
281270 }
282271 }
283272 closedir(d);
@@ -286,10 +275,17 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
286275 void android_os_Process_setThreadPriority(JNIEnv* env, jobject clazz,
287276 jint pid, jint pri)
288277 {
278+ int rc = 0;
279+
289280 if (pri >= ANDROID_PRIORITY_BACKGROUND) {
290- add_pid_to_cgroup(pid, ANDROID_TGROUP_BG_NONINTERACT);
281+ rc = set_sched_policy(pid, SP_BACKGROUND);
291282 } else if (getpriority(PRIO_PROCESS, pid) >= ANDROID_PRIORITY_BACKGROUND) {
292- add_pid_to_cgroup(pid, ANDROID_TGROUP_DEFAULT);
283+ rc = set_sched_policy(pid, SP_FOREGROUND);
284+ }
285+
286+ if (rc) {
287+ signalExceptionForGroupError(env, clazz, errno);
288+ return;
293289 }
294290
295291 if (setpriority(PRIO_PROCESS, pid, pri) < 0) {
--- a/libs/utils/IPCThreadState.cpp
+++ b/libs/utils/IPCThreadState.cpp
@@ -18,6 +18,7 @@
1818
1919 #include <utils/Binder.h>
2020 #include <utils/BpBinder.h>
21+#include <cutils/sched_policy.h>
2122 #include <utils/Debug.h>
2223 #include <utils/Log.h>
2324 #include <utils/TextOutput.h>
@@ -426,6 +427,21 @@ void IPCThreadState::joinThreadPool(bool isMain)
426427 result = executeCommand(cmd);
427428 }
428429
430+ // After executing the command, ensure that the thread is returned to the
431+ // default cgroup and priority before rejoining the pool. This is a failsafe
432+ // in case the command implementation failed to properly restore the thread's
433+ // scheduling parameters upon completion.
434+ int my_id;
435+#ifdef HAVE_GETTID
436+ my_id = gettid();
437+#else
438+ my_id = getpid();
439+#endif
440+ if (!set_sched_policy(my_id, SP_FOREGROUND)) {
441+ // success; reset the priority as well
442+ setpriority(PRIO_PROCESS, my_id, ANDROID_PRIORITY_NORMAL);
443+ }
444+
429445 // Let this thread exit the thread pool if it is no longer
430446 // needed and it is not the main process thread.
431447 if(result == TIMED_OUT && !isMain) {