Home | History | Annotate | Download | only in am
      1 /*
      2  * Copyright (C) 2015 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.app.ActivityManager;
     20 import android.os.SystemClock;
     21 import android.os.UserHandle;
     22 import android.util.TimeUtils;
     23 
     24 /**
     25  * Overall information about a uid that has actively running processes.
     26  */
     27 public final class UidRecord {
     28     final int uid;
     29     int curProcState;
     30     int setProcState = ActivityManager.PROCESS_STATE_NONEXISTENT;
     31     long lastBackgroundTime;
     32     boolean idle;
     33     int numProcs;
     34 
     35     static final int CHANGE_PROCSTATE = 0;
     36     static final int CHANGE_GONE = 1;
     37     static final int CHANGE_GONE_IDLE = 2;
     38     static final int CHANGE_IDLE = 3;
     39     static final int CHANGE_ACTIVE = 4;
     40 
     41     static final class ChangeItem {
     42         UidRecord uidRecord;
     43         int uid;
     44         int change;
     45         int processState;
     46     }
     47 
     48     ChangeItem pendingChange;
     49 
     50     public UidRecord(int _uid) {
     51         uid = _uid;
     52         reset();
     53     }
     54 
     55     public void reset() {
     56         curProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
     57     }
     58 
     59     public String toString() {
     60         StringBuilder sb = new StringBuilder(128);
     61         sb.append("UidRecord{");
     62         sb.append(Integer.toHexString(System.identityHashCode(this)));
     63         sb.append(' ');
     64         UserHandle.formatUid(sb, uid);
     65         sb.append(' ');
     66         sb.append(ProcessList.makeProcStateString(curProcState));
     67         if (lastBackgroundTime > 0) {
     68             sb.append(" bg:");
     69             TimeUtils.formatDuration(SystemClock.elapsedRealtime()-lastBackgroundTime, sb);
     70         }
     71         if (idle) {
     72             sb.append(" idle");
     73         }
     74         sb.append(" procs:");
     75         sb.append(numProcs);
     76         sb.append("}");
     77         return sb.toString();
     78     }
     79 }
     80