| /* |
| * Copyright (C) 2015 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.server.am; |
| |
| import android.app.ActivityManager; |
| import android.app.ActivityThread; |
| import android.app.IApplicationThread; |
| import android.os.RemoteCallbackList; |
| import android.os.SystemClock; |
| import android.os.UserHandle; |
| import android.util.DebugUtils; |
| import android.util.TimeUtils; |
| |
| /** |
| * Overall information about a uid that has actively running processes. |
| */ |
| public final class UidRecord { |
| final int uid; |
| int curProcState; |
| int setProcState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| long lastBackgroundTime; |
| boolean ephemeral; |
| boolean curWhitelist; |
| boolean setWhitelist; |
| boolean idle; |
| int numProcs; |
| /** |
| * Seq no. associated with the current process state change (from background to foreground or |
| * vice versa). |
| */ |
| long curProcStateSeq; |
| /** |
| * Latest seq number for which NetworkPolicyManagerService notified ActivityManagerService that |
| * network policy rules are updated. |
| */ |
| long lastProcStateSeqWithUpdatedNetworkState; |
| /** |
| * Current block state indicating whether components in the process corresponding to this |
| * uidRecord needs to block for network or unblock or if there is no change. |
| * value will be one of {@link ActivityThread#NETWORK_STATE_BLOCK}, |
| * {@link ActivityThread#NETWORK_STATE_UNBLOCK}, {@link ActivityThread#NETWORK_STATE_NO_CHANGE}. |
| */ |
| int blockState; |
| /** Indicates whether app threads need be notified of the current blockState change. */ |
| boolean shouldNotifyAppThreads; |
| /** Listeners waiting for the network policy rules to get updated. */ |
| RemoteCallbackList<IApplicationThread> appThreadListeners; |
| |
| static final int CHANGE_PROCSTATE = 0; |
| static final int CHANGE_GONE = 1; |
| static final int CHANGE_GONE_IDLE = 2; |
| static final int CHANGE_IDLE = 3; |
| static final int CHANGE_ACTIVE = 4; |
| |
| static final class ChangeItem { |
| UidRecord uidRecord; |
| int uid; |
| int change; |
| int processState; |
| boolean ephemeral; |
| long procStateSeq; |
| } |
| |
| ChangeItem pendingChange; |
| |
| public UidRecord(int _uid) { |
| uid = _uid; |
| reset(); |
| } |
| |
| public void reset() { |
| curProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY; |
| } |
| |
| public String toString() { |
| StringBuilder sb = new StringBuilder(128); |
| sb.append("UidRecord{"); |
| sb.append(Integer.toHexString(System.identityHashCode(this))); |
| sb.append(' '); |
| UserHandle.formatUid(sb, uid); |
| sb.append(' '); |
| sb.append(ProcessList.makeProcStateString(curProcState)); |
| if (ephemeral) { |
| sb.append(" ephemeral"); |
| } |
| if (curWhitelist) { |
| sb.append(" whitelist"); |
| } |
| if (lastBackgroundTime > 0) { |
| sb.append(" bg:"); |
| TimeUtils.formatDuration(SystemClock.elapsedRealtime()-lastBackgroundTime, sb); |
| } |
| if (idle) { |
| sb.append(" idle"); |
| } |
| sb.append(" procs:"); |
| sb.append(numProcs); |
| sb.append(" procStateSeq:"); |
| sb.append(curProcStateSeq); |
| sb.append(" lastProcStateSeqWithUpdatedNetworkState:"); |
| sb.append(lastProcStateSeqWithUpdatedNetworkState); |
| sb.append(" blockState:"); |
| sb.append(DebugUtils.valueToString(ActivityThread.class, "NETWORK_STATE_", blockState)); |
| sb.append(" shouldNotifyAppThreads:"); |
| sb.append(shouldNotifyAppThreads); |
| sb.append("}"); |
| return sb.toString(); |
| } |
| } |