1 /* 2 * Copyright (C) 2020 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 com.android.internal.annotations.GuardedBy; 20 import com.android.internal.annotations.VisibleForTesting; 21 22 import java.io.PrintWriter; 23 24 /** 25 * The state info of app when it's cached, used by the optimizer. 26 */ 27 final class ProcessCachedOptimizerRecord { 28 private final ProcessRecord mApp; 29 30 private final ActivityManagerGlobalLock mProcLock; 31 32 @VisibleForTesting 33 static final String IS_FROZEN = "isFrozen"; 34 35 /** 36 * The last time that this process was compacted. 37 */ 38 @GuardedBy("mProcLock") 39 private long mLastCompactTime; 40 41 /** 42 * The most recent compaction action requested for this app. 43 */ 44 @GuardedBy("mProcLock") 45 private int mReqCompactAction; 46 47 /** 48 * The most recent compaction action performed for this app. 49 */ 50 @GuardedBy("mProcLock") 51 private int mLastCompactAction; 52 53 /** 54 * This process has been scheduled for a memory compaction. 55 */ 56 @GuardedBy("mProcLock") 57 private boolean mPendingCompact; 58 59 /** 60 * True when the process is frozen. 61 */ 62 @GuardedBy("mProcLock") 63 private boolean mFrozen; 64 65 /** 66 * An override on the freeze state is in progress. 67 */ 68 @GuardedBy("mProcLock") 69 boolean mFreezerOverride; 70 71 /** 72 * Last time the app was (un)frozen, 0 for never. 73 */ 74 @GuardedBy("mProcLock") 75 private long mFreezeUnfreezeTime; 76 77 /** 78 * True if a process has a WPRI binding from an unfrozen process. 79 */ 80 @GuardedBy("mProcLock") 81 private boolean mShouldNotFreeze; 82 83 /** 84 * Exempt from freezer (now for system apps with INSTALL_PACKAGES permission) 85 */ 86 @GuardedBy("mProcLock") 87 private boolean mFreezeExempt; 88 89 /** 90 * This process has been scheduled for freezing 91 */ 92 @GuardedBy("mProcLock") 93 private boolean mPendingFreeze; 94 95 @GuardedBy("mProcLock") getLastCompactTime()96 long getLastCompactTime() { 97 return mLastCompactTime; 98 } 99 100 @GuardedBy("mProcLock") setLastCompactTime(long lastCompactTime)101 void setLastCompactTime(long lastCompactTime) { 102 mLastCompactTime = lastCompactTime; 103 } 104 105 @GuardedBy("mProcLock") getReqCompactAction()106 int getReqCompactAction() { 107 return mReqCompactAction; 108 } 109 110 @GuardedBy("mProcLock") setReqCompactAction(int reqCompactAction)111 void setReqCompactAction(int reqCompactAction) { 112 mReqCompactAction = reqCompactAction; 113 } 114 115 @GuardedBy("mProcLock") getLastCompactAction()116 int getLastCompactAction() { 117 return mLastCompactAction; 118 } 119 120 @GuardedBy("mProcLock") setLastCompactAction(int lastCompactAction)121 void setLastCompactAction(int lastCompactAction) { 122 mLastCompactAction = lastCompactAction; 123 } 124 125 @GuardedBy("mProcLock") hasPendingCompact()126 boolean hasPendingCompact() { 127 return mPendingCompact; 128 } 129 130 @GuardedBy("mProcLock") setHasPendingCompact(boolean pendingCompact)131 void setHasPendingCompact(boolean pendingCompact) { 132 mPendingCompact = pendingCompact; 133 } 134 135 @GuardedBy("mProcLock") isFrozen()136 boolean isFrozen() { 137 return mFrozen; 138 } 139 140 @GuardedBy("mProcLock") setFrozen(boolean frozen)141 void setFrozen(boolean frozen) { 142 mFrozen = frozen; 143 } 144 145 @GuardedBy("mProcLock") hasFreezerOverride()146 boolean hasFreezerOverride() { 147 return mFreezerOverride; 148 } 149 150 @GuardedBy("mProcLock") setFreezerOverride(boolean freezerOverride)151 void setFreezerOverride(boolean freezerOverride) { 152 mFreezerOverride = freezerOverride; 153 } 154 155 @GuardedBy("mProcLock") getFreezeUnfreezeTime()156 long getFreezeUnfreezeTime() { 157 return mFreezeUnfreezeTime; 158 } 159 160 @GuardedBy("mProcLock") setFreezeUnfreezeTime(long freezeUnfreezeTime)161 void setFreezeUnfreezeTime(long freezeUnfreezeTime) { 162 mFreezeUnfreezeTime = freezeUnfreezeTime; 163 } 164 165 @GuardedBy("mProcLock") shouldNotFreeze()166 boolean shouldNotFreeze() { 167 return mShouldNotFreeze; 168 } 169 170 @GuardedBy("mProcLock") setShouldNotFreeze(boolean shouldNotFreeze)171 void setShouldNotFreeze(boolean shouldNotFreeze) { 172 mShouldNotFreeze = shouldNotFreeze; 173 } 174 175 @GuardedBy("mProcLock") isFreezeExempt()176 boolean isFreezeExempt() { 177 return mFreezeExempt; 178 } 179 180 @GuardedBy("mProcLock") setPendingFreeze(boolean freeze)181 void setPendingFreeze(boolean freeze) { 182 mPendingFreeze = freeze; 183 } 184 185 @GuardedBy("mProcLock") isPendingFreeze()186 boolean isPendingFreeze() { 187 return mPendingFreeze; 188 } 189 190 @GuardedBy("mProcLock") setFreezeExempt(boolean exempt)191 void setFreezeExempt(boolean exempt) { 192 mFreezeExempt = exempt; 193 } 194 ProcessCachedOptimizerRecord(ProcessRecord app)195 ProcessCachedOptimizerRecord(ProcessRecord app) { 196 mApp = app; 197 mProcLock = app.mService.mProcLock; 198 } 199 init(long nowUptime)200 void init(long nowUptime) { 201 mFreezeUnfreezeTime = nowUptime; 202 } 203 204 @GuardedBy("mProcLock") dump(PrintWriter pw, String prefix, long nowUptime)205 void dump(PrintWriter pw, String prefix, long nowUptime) { 206 pw.print(prefix); pw.print("lastCompactTime="); pw.print(mLastCompactTime); 207 pw.print(" lastCompactAction="); pw.println(mLastCompactAction); 208 pw.print(prefix); pw.print("isFreezeExempt="); pw.print(mFreezeExempt); 209 pw.print(" isPendingFreeze="); pw.print(mPendingFreeze); 210 pw.print(" " + IS_FROZEN + "="); pw.println(mFrozen); 211 } 212 } 213