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 android.app; 18 19 import android.annotation.IntDef; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * State (oom score) for processes known to activity manager. 25 * {@hide} 26 */ 27 public final class ProcessMemoryState implements Parcelable { 28 /** 29 * The type of the component this process is hosting; 30 * this means not hosting any components (cached). 31 */ 32 public static final int HOSTING_COMPONENT_TYPE_EMPTY = 33 AppProtoEnums.HOSTING_COMPONENT_TYPE_EMPTY; 34 35 /** 36 * The type of the component this process is hosting; 37 * this means it's a system process. 38 */ 39 public static final int HOSTING_COMPONENT_TYPE_SYSTEM = 40 AppProtoEnums.HOSTING_COMPONENT_TYPE_SYSTEM; 41 42 /** 43 * The type of the component this process is hosting; 44 * this means it's a persistent process. 45 */ 46 public static final int HOSTING_COMPONENT_TYPE_PERSISTENT = 47 AppProtoEnums.HOSTING_COMPONENT_TYPE_PERSISTENT; 48 49 /** 50 * The type of the component this process is hosting; 51 * this means it's hosting a backup/restore agent. 52 */ 53 public static final int HOSTING_COMPONENT_TYPE_BACKUP = 54 AppProtoEnums.HOSTING_COMPONENT_TYPE_BACKUP; 55 56 /** 57 * The type of the component this process is hosting; 58 * this means it's hosting an instrumentation. 59 */ 60 public static final int HOSTING_COMPONENT_TYPE_INSTRUMENTATION = 61 AppProtoEnums.HOSTING_COMPONENT_TYPE_INSTRUMENTATION; 62 63 /** 64 * The type of the component this process is hosting; 65 * this means it's hosting an activity. 66 */ 67 public static final int HOSTING_COMPONENT_TYPE_ACTIVITY = 68 AppProtoEnums.HOSTING_COMPONENT_TYPE_ACTIVITY; 69 70 /** 71 * The type of the component this process is hosting; 72 * this means it's hosting a broadcast receiver. 73 */ 74 public static final int HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER = 75 AppProtoEnums.HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER; 76 77 /** 78 * The type of the component this process is hosting; 79 * this means it's hosting a content provider. 80 */ 81 public static final int HOSTING_COMPONENT_TYPE_PROVIDER = 82 AppProtoEnums.HOSTING_COMPONENT_TYPE_PROVIDER; 83 84 /** 85 * The type of the component this process is hosting; 86 * this means it's hosting a started service. 87 */ 88 public static final int HOSTING_COMPONENT_TYPE_STARTED_SERVICE = 89 AppProtoEnums.HOSTING_COMPONENT_TYPE_STARTED_SERVICE; 90 91 /** 92 * The type of the component this process is hosting; 93 * this means it's hosting a foreground service. 94 */ 95 public static final int HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE = 96 AppProtoEnums.HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE; 97 98 /** 99 * The type of the component this process is hosting; 100 * this means it's being bound via a service binding. 101 */ 102 public static final int HOSTING_COMPONENT_TYPE_BOUND_SERVICE = 103 AppProtoEnums.HOSTING_COMPONENT_TYPE_BOUND_SERVICE; 104 105 /** 106 * The type of the component this process is hosting. 107 * @hide 108 */ 109 @IntDef(flag = true, prefix = { "HOSTING_COMPONENT_TYPE_" }, value = { 110 HOSTING_COMPONENT_TYPE_EMPTY, 111 HOSTING_COMPONENT_TYPE_SYSTEM, 112 HOSTING_COMPONENT_TYPE_PERSISTENT, 113 HOSTING_COMPONENT_TYPE_BACKUP, 114 HOSTING_COMPONENT_TYPE_INSTRUMENTATION, 115 HOSTING_COMPONENT_TYPE_ACTIVITY, 116 HOSTING_COMPONENT_TYPE_BROADCAST_RECEIVER, 117 HOSTING_COMPONENT_TYPE_PROVIDER, 118 HOSTING_COMPONENT_TYPE_STARTED_SERVICE, 119 HOSTING_COMPONENT_TYPE_FOREGROUND_SERVICE, 120 HOSTING_COMPONENT_TYPE_BOUND_SERVICE, 121 }) 122 public @interface HostingComponentType {} 123 124 public final int uid; 125 public final int pid; 126 public final String processName; 127 public final int oomScore; 128 public final boolean hasForegroundServices; 129 130 /** 131 * The types of the components this process is hosting at the moment this snapshot is taken. 132 * 133 * Its value is the combination of {@link HostingComponentType}. 134 */ 135 public final int mHostingComponentTypes; 136 137 /** 138 * The historical types of the components this process is or was hosting since it's born. 139 * 140 * Its value is the combination of {@link HostingComponentType}. 141 */ 142 public final int mHistoricalHostingComponentTypes; 143 ProcessMemoryState(int uid, int pid, String processName, int oomScore, boolean hasForegroundServices, int hostingComponentTypes, int historicalHostingComponentTypes)144 public ProcessMemoryState(int uid, int pid, String processName, int oomScore, 145 boolean hasForegroundServices, int hostingComponentTypes, 146 int historicalHostingComponentTypes) { 147 this.uid = uid; 148 this.pid = pid; 149 this.processName = processName; 150 this.oomScore = oomScore; 151 this.hasForegroundServices = hasForegroundServices; 152 this.mHostingComponentTypes = hostingComponentTypes; 153 this.mHistoricalHostingComponentTypes = historicalHostingComponentTypes; 154 } 155 ProcessMemoryState(Parcel in)156 private ProcessMemoryState(Parcel in) { 157 uid = in.readInt(); 158 pid = in.readInt(); 159 processName = in.readString(); 160 oomScore = in.readInt(); 161 hasForegroundServices = in.readInt() == 1; 162 mHostingComponentTypes = in.readInt(); 163 mHistoricalHostingComponentTypes = in.readInt(); 164 } 165 166 public static final @android.annotation.NonNull Creator<ProcessMemoryState> CREATOR = new Creator<ProcessMemoryState>() { 167 @Override 168 public ProcessMemoryState createFromParcel(Parcel in) { 169 return new ProcessMemoryState(in); 170 } 171 172 @Override 173 public ProcessMemoryState[] newArray(int size) { 174 return new ProcessMemoryState[size]; 175 } 176 }; 177 178 @Override describeContents()179 public int describeContents() { 180 return 0; 181 } 182 183 @Override writeToParcel(Parcel parcel, int i)184 public void writeToParcel(Parcel parcel, int i) { 185 parcel.writeInt(uid); 186 parcel.writeInt(pid); 187 parcel.writeString(processName); 188 parcel.writeInt(oomScore); 189 parcel.writeInt(hasForegroundServices ? 1 : 0); 190 parcel.writeInt(mHostingComponentTypes); 191 parcel.writeInt(mHistoricalHostingComponentTypes); 192 } 193 } 194