Home | History | Annotate | Download | only in am
      1 /*
      2  * Copyright (C) 2018 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.am;
     18 
     19 import android.util.SparseArray;
     20 
     21 /** Class for tracking active uids for running processes. */
     22 final class ActiveUids {
     23 
     24     private ActivityManagerService mService;
     25 
     26     private boolean mPostChangesToAtm;
     27     private final SparseArray<UidRecord> mActiveUids = new SparseArray<>();
     28 
     29     ActiveUids(ActivityManagerService service, boolean postChangesToAtm) {
     30         mService = service;
     31         mPostChangesToAtm = postChangesToAtm;
     32     }
     33 
     34     void put(int uid, UidRecord value) {
     35         mActiveUids.put(uid, value);
     36         if (mPostChangesToAtm) {
     37             mService.mAtmInternal.onUidActive(uid, value.getCurProcState());
     38         }
     39     }
     40 
     41     void remove(int uid) {
     42         mActiveUids.remove(uid);
     43         if (mPostChangesToAtm) {
     44             mService.mAtmInternal.onUidInactive(uid);
     45         }
     46     }
     47 
     48     void clear() {
     49         mActiveUids.clear();
     50         if (mPostChangesToAtm) {
     51             mService.mAtmInternal.onActiveUidsCleared();
     52         }
     53     }
     54 
     55     UidRecord get(int uid) {
     56         return mActiveUids.get(uid);
     57     }
     58 
     59     int size() {
     60         return mActiveUids.size();
     61     }
     62 
     63     UidRecord valueAt(int index) {
     64         return mActiveUids.valueAt(index);
     65     }
     66 
     67     int keyAt(int index) {
     68         return mActiveUids.keyAt(index);
     69     }
     70 
     71     int indexOfKey(int uid) {
     72         return mActiveUids.indexOfKey(uid);
     73     }
     74 }
     75