Merge changes Iee5024b8,Ic8afc2eb into udc-dev

* changes:
  Ignore BIND_ABOVE_CLIENT for same-process connections
  Fix setAttachingSchedGroupLSP() to support use_fifo_ui
This commit is contained in:
Jing Ji
2023-05-26 04:38:10 +00:00
committed by Android (Google) Code Review
4 changed files with 33 additions and 3 deletions

View File

@@ -3797,7 +3797,9 @@ public final class ActiveServices {
}
clientPsr.addConnection(c);
c.startAssociationIfNeeded();
if (c.hasFlag(Context.BIND_ABOVE_CLIENT)) {
// Don't set hasAboveClient if binding to self to prevent modifyRawOomAdj() from
// dropping the process' adjustment level.
if (b.client != s.app && c.hasFlag(Context.BIND_ABOVE_CLIENT)) {
clientPsr.setHasAboveClient(true);
}
if (c.hasFlag(BIND_ALLOW_WHITELIST_MANAGEMENT)) {

View File

@@ -3253,7 +3253,11 @@ public class OomAdjuster {
// {@link SCHED_GROUP_TOP_APP}. We don't check render thread because it
// is not ready when attaching.
app.getWindowProcessController().onTopProcChanged();
setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST);
if (mService.mUseFifoUiScheduling) {
mService.scheduleAsFifoPriority(app.getPid(), true);
} else {
setThreadPriority(app.getPid(), THREAD_PRIORITY_TOP_APP_BOOST);
}
initialSchedGroup = SCHED_GROUP_TOP_APP;
} catch (Exception e) {
Slog.w(TAG, "Failed to pre-set top priority to " + app + " " + e);

View File

@@ -341,7 +341,8 @@ final class ProcessServiceRecord {
mHasAboveClient = false;
for (int i = mConnections.size() - 1; i >= 0; i--) {
ConnectionRecord cr = mConnections.valueAt(i);
if (cr.hasFlag(Context.BIND_ABOVE_CLIENT)) {
if (cr.binding.service.app.mServices != this
&& cr.hasFlag(Context.BIND_ABOVE_CLIENT)) {
mHasAboveClient = true;
break;
}

View File

@@ -68,6 +68,7 @@ import static com.android.server.am.ProcessList.UNKNOWN_ADJ;
import static com.android.server.am.ProcessList.VISIBLE_APP_ADJ;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.AdditionalAnswers.answer;
@@ -2489,6 +2490,28 @@ public class MockingOomAdjusterTests {
assertProcStates(app2, false, PROCESS_STATE_SERVICE, SERVICE_ADJ, "started-services");
}
@SuppressWarnings("GuardedBy")
@Test
public void testUpdateOomAdj_DoOne_AboveClient_SameProcess() {
ProcessRecord app = spy(makeDefaultProcessRecord(MOCKAPP_PID, MOCKAPP_UID,
MOCKAPP_PROCESSNAME, MOCKAPP_PACKAGENAME, true));
doReturn(PROCESS_STATE_TOP).when(sService.mAtmInternal).getTopProcessState();
doReturn(app).when(sService).getTopApp();
sService.mWakefulness.set(PowerManagerInternal.WAKEFULNESS_AWAKE);
sService.mOomAdjuster.updateOomAdjLocked(app, OOM_ADJ_REASON_NONE);
assertEquals(FOREGROUND_APP_ADJ, app.mState.getSetAdj());
// Simulate binding to a service in the same process using BIND_ABOVE_CLIENT and
// verify that its OOM adjustment level is unaffected.
bindService(app, app, null, Context.BIND_ABOVE_CLIENT, mock(IBinder.class));
app.mServices.updateHasAboveClientLocked();
assertFalse(app.mServices.hasAboveClient());
sService.mOomAdjuster.updateOomAdjLocked(app, OOM_ADJ_REASON_NONE);
assertEquals(FOREGROUND_APP_ADJ, app.mState.getSetAdj());
}
private ProcessRecord makeDefaultProcessRecord(int pid, int uid, String processName,
String packageName, boolean hasShownUi) {
long now = SystemClock.uptimeMillis();