1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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 14 * limitations under the License. 15 */ 16 17 package com.android.server.wm; 18 19 import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; 20 21 import android.util.SparseIntArray; 22 23 /** 24 * This is a partial mirror of {@link @com.android.server.am.ActiveUids}. It is already thread 25 * safe so the heavy service lock is not needed when updating state from activity manager (oom 26 * adjustment) or getting state from window manager (background start check). 27 */ 28 class MirrorActiveUids { 29 private SparseIntArray mUidStates = new SparseIntArray(); 30 onUidActive(int uid, int procState)31 synchronized void onUidActive(int uid, int procState) { 32 mUidStates.put(uid, procState); 33 } 34 onUidInactive(int uid)35 synchronized void onUidInactive(int uid) { 36 mUidStates.delete(uid); 37 } 38 onActiveUidsCleared()39 synchronized void onActiveUidsCleared() { 40 mUidStates.clear(); 41 } 42 onUidProcStateChanged(int uid, int procState)43 synchronized void onUidProcStateChanged(int uid, int procState) { 44 final int index = mUidStates.indexOfKey(uid); 45 if (index >= 0) { 46 mUidStates.setValueAt(index, procState); 47 } 48 } 49 getUidState(int uid)50 synchronized int getUidState(int uid) { 51 return mUidStates.get(uid, PROCESS_STATE_NONEXISTENT); 52 } 53 } 54