Merge changes I6993325b,Icb5114fe

* changes:
  Frameworks: Annotate trivial @GuardedBy in services/core
  Frameworks: Annotate trivial @GuardedBy in core/java
This commit is contained in:
TreeHugger Robot
2018-02-08 23:32:03 +00:00
committed by Android (Google) Code Review
44 changed files with 246 additions and 0 deletions

View File

@@ -409,6 +409,7 @@ class ContextImpl extends Context {
return sp;
}
@GuardedBy("ContextImpl.class")
private ArrayMap<File, SharedPreferencesImpl> getSharedPreferencesCacheLocked() {
if (sSharedPrefsCache == null) {
sSharedPrefsCache = new ArrayMap<>();

View File

@@ -274,6 +274,7 @@ public final class RuntimePermissionPresenter {
}
}
@GuardedBy("mLock")
private void scheduleNextMessageIfNeededLocked() {
if (mBound && mRemoteInstance != null && !mPendingWork.isEmpty()) {
Message nextMessage = mPendingWork.remove(0);

View File

@@ -143,6 +143,7 @@ public final class AssetManager implements AutoCloseable {
/**
* This must be called from Zygote so that system assets are shared by all applications.
*/
@GuardedBy("sSync")
private static void createSystemAssetsInZygoteLocked() {
if (sSystem != null) {
return;
@@ -366,6 +367,7 @@ public final class AssetManager implements AutoCloseable {
* The AssetManager may have been closed, but references to it still exist
* and therefore the native implementation is not destroyed.
*/
@GuardedBy("this")
private void ensureValidLocked() {
if (mObject == 0) {
throw new RuntimeException("AssetManager has been destroyed");
@@ -376,6 +378,7 @@ public final class AssetManager implements AutoCloseable {
* Ensures that the AssetManager has not been explicitly closed. If this method passes,
* then this implies that ensureValidLocked() also passes.
*/
@GuardedBy("this")
private void ensureOpenLocked() {
// If mOpen is true, this implies that mObject != 0.
if (!mOpen) {
@@ -1189,6 +1192,7 @@ public final class AssetManager implements AutoCloseable {
}
}
@GuardedBy("this")
private void incRefsLocked(long id) {
if (DEBUG_REFS) {
if (mRefStacks == null) {
@@ -1201,6 +1205,7 @@ public final class AssetManager implements AutoCloseable {
mNumRefs++;
}
@GuardedBy("this")
private void decRefsLocked(long id) {
if (DEBUG_REFS && mRefStacks != null) {
mRefStacks.remove(id);

View File

@@ -422,6 +422,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private boolean recycleConnectionLocked(SQLiteConnection connection,
AcquiredConnectionStatus status) {
if (status == AcquiredConnectionStatus.RECONFIGURE) {
@@ -531,6 +532,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private void closeAvailableConnectionsAndLogExceptionsLocked() {
closeAvailableNonPrimaryConnectionsAndLogExceptionsLocked();
@@ -541,6 +543,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private boolean closeAvailableConnectionLocked(int connectionId) {
final int count = mAvailableNonPrimaryConnections.size();
for (int i = count - 1; i >= 0; i--) {
@@ -562,6 +565,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private void closeAvailableNonPrimaryConnectionsAndLogExceptionsLocked() {
final int count = mAvailableNonPrimaryConnections.size();
for (int i = 0; i < count; i++) {
@@ -581,6 +585,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private void closeExcessConnectionsAndLogExceptionsLocked() {
int availableCount = mAvailableNonPrimaryConnections.size();
while (availableCount-- > mMaxConnectionPoolSize - 1) {
@@ -591,6 +596,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private void closeConnectionAndLogExceptionsLocked(SQLiteConnection connection) {
try {
connection.close(); // might throw
@@ -609,6 +615,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private void reconfigureAllConnectionsLocked() {
if (mAvailablePrimaryConnection != null) {
try {
@@ -776,6 +783,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private void cancelConnectionWaiterLocked(ConnectionWaiter waiter) {
if (waiter.mAssignedConnection != null || waiter.mException != null) {
// Waiter is done waiting but has not woken up yet.
@@ -848,6 +856,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Can't throw.
@GuardedBy("mLock")
private void wakeConnectionWaitersLocked() {
// Unpark all waiters that have requests that we can fulfill.
// This method is designed to not throw runtime exceptions, although we might send
@@ -910,6 +919,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Might throw.
@GuardedBy("mLock")
private SQLiteConnection tryAcquirePrimaryConnectionLocked(int connectionFlags) {
// If the primary connection is available, acquire it now.
SQLiteConnection connection = mAvailablePrimaryConnection;
@@ -935,6 +945,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Might throw.
@GuardedBy("mLock")
private SQLiteConnection tryAcquireNonPrimaryConnectionLocked(
String sql, int connectionFlags) {
// Try to acquire the next connection in the queue.
@@ -974,6 +985,7 @@ public final class SQLiteConnectionPool implements Closeable {
}
// Might throw.
@GuardedBy("mLock")
private void finishAcquireConnectionLocked(SQLiteConnection connection, int connectionFlags) {
try {
final boolean readOnly = (connectionFlags & CONNECTION_FLAG_READ_ONLY) != 0;

View File

@@ -1343,6 +1343,7 @@ public abstract class NotificationListenerService extends Service {
/**
* @hide
*/
@GuardedBy("mLock")
public final void applyUpdateLocked(NotificationRankingUpdate update) {
mRankingMap = new RankingMap(update);
}

View File

@@ -619,6 +619,7 @@ public final class AutofillManager {
/**
* @hide
*/
@GuardedBy("mLock")
public boolean isCompatibilityModeEnabledLocked() {
return mCompatibilityBridge != null;
}
@@ -709,6 +710,7 @@ public final class AutofillManager {
notifyViewEntered(view, 0);
}
@GuardedBy("mLock")
private boolean shouldIgnoreViewEnteredLocked(@NonNull View view, int flags) {
if (isDisabledByServiceLocked()) {
if (sVerbose) {
@@ -749,6 +751,7 @@ public final class AutofillManager {
}
/** Returns AutofillCallback if need fire EVENT_INPUT_UNAVAILABLE */
@GuardedBy("mLock")
private AutofillCallback notifyViewEnteredLocked(@NonNull View view, int flags) {
if (shouldIgnoreViewEnteredLocked(view, flags)) return null;
@@ -792,6 +795,7 @@ public final class AutofillManager {
}
}
@GuardedBy("mLock")
void notifyViewExitedLocked(@NonNull View view) {
ensureServiceClientAddedIfNeededLocked();
@@ -893,6 +897,7 @@ public final class AutofillManager {
}
/** Returns AutofillCallback if need fire EVENT_INPUT_UNAVAILABLE */
@GuardedBy("mLock")
private AutofillCallback notifyViewEnteredLocked(View view, int virtualId, Rect bounds,
int flags) {
AutofillCallback callback = null;
@@ -936,6 +941,7 @@ public final class AutofillManager {
}
}
@GuardedBy("mLock")
private void notifyViewExitedLocked(@NonNull View view, int virtualId) {
ensureServiceClientAddedIfNeededLocked();
@@ -1087,6 +1093,7 @@ public final class AutofillManager {
}
}
@GuardedBy("mLock")
private void commitLocked() {
if (!mEnabled && !isActiveLocked()) {
return;
@@ -1115,6 +1122,7 @@ public final class AutofillManager {
}
}
@GuardedBy("mLock")
private void cancelLocked() {
if (!mEnabled && !isActiveLocked()) {
return;
@@ -1378,6 +1386,7 @@ public final class AutofillManager {
return new AutofillId(parent.getAutofillViewId(), virtualId);
}
@GuardedBy("mLock")
private void startSessionLocked(@NonNull AutofillId id, @NonNull Rect bounds,
@NonNull AutofillValue value, int flags) {
if (sVerbose) {
@@ -1408,6 +1417,7 @@ public final class AutofillManager {
}
}
@GuardedBy("mLock")
private void finishSessionLocked() {
if (sVerbose) Log.v(TAG, "finishSessionLocked(): " + getStateAsStringLocked());
@@ -1422,6 +1432,7 @@ public final class AutofillManager {
resetSessionLocked();
}
@GuardedBy("mLock")
private void cancelSessionLocked() {
if (sVerbose) Log.v(TAG, "cancelSessionLocked(): " + getStateAsStringLocked());
@@ -1436,6 +1447,7 @@ public final class AutofillManager {
resetSessionLocked();
}
@GuardedBy("mLock")
private void resetSessionLocked() {
mSessionId = NO_SESSION;
mState = STATE_UNKNOWN;
@@ -1444,6 +1456,7 @@ public final class AutofillManager {
mSaveTriggerId = null;
}
@GuardedBy("mLock")
private void updateSessionLocked(AutofillId id, Rect bounds, AutofillValue value, int action,
int flags) {
if (sVerbose && action != ACTION_VIEW_EXITED) {
@@ -1478,6 +1491,7 @@ public final class AutofillManager {
}
}
@GuardedBy("mLock")
private void ensureServiceClientAddedIfNeededLocked() {
if (getClient() == null) {
return;
@@ -1947,6 +1961,7 @@ public final class AutofillManager {
pw.print(" verbose: "); pw.println(sVerbose);
}
@GuardedBy("mLock")
private String getStateAsStringLocked() {
switch (mState) {
case STATE_UNKNOWN:
@@ -1964,14 +1979,17 @@ public final class AutofillManager {
}
}
@GuardedBy("mLock")
private boolean isActiveLocked() {
return mState == STATE_ACTIVE;
}
@GuardedBy("mLock")
private boolean isDisabledByServiceLocked() {
return mState == STATE_DISABLED_BY_SERVICE;
}
@GuardedBy("mLock")
private boolean isFinishedLocked() {
return mState == STATE_FINISHED;
}
@@ -2167,6 +2185,7 @@ public final class AutofillManager {
AutofillValue.forText(node.getText()));
}
@GuardedBy("mLock")
private void updateTrackedViewsLocked() {
if (mTrackedViews != null) {
mTrackedViews.onVisibleForAutofillChangedLocked();
@@ -2311,6 +2330,7 @@ public final class AutofillManager {
* @param id the id of the view/virtual view whose visibility changed.
* @param isVisible visible if the view is visible in the view hierarchy.
*/
@GuardedBy("mLock")
void notifyViewVisibilityChangedLocked(@NonNull AutofillId id, boolean isVisible) {
if (sDebug) {
Log.d(TAG, "notifyViewVisibilityChangedLocked(): id=" + id + " isVisible="
@@ -2344,6 +2364,7 @@ public final class AutofillManager {
*
* @see AutofillClient#autofillClientIsVisibleForAutofill()
*/
@GuardedBy("mLock")
void onVisibleForAutofillChangedLocked() {
// The visibility of the views might have changed while the client was not be visible,
// hence update the visibility state for all views.

View File

@@ -3828,6 +3828,7 @@ public class BatteryStatsImpl extends BatteryStats {
mActiveHistoryStates2 = 0xffffffff;
}
@GuardedBy("this")
public void updateTimeBasesLocked(boolean unplugged, int screenState, long uptime,
long realtime) {
final boolean screenOff = !isScreenOn(screenState);
@@ -3905,6 +3906,7 @@ public class BatteryStatsImpl extends BatteryStats {
* This should only be called after the cpu times have been read.
* @see #scheduleRemoveIsolatedUidLocked(int, int)
*/
@GuardedBy("this")
public void removeIsolatedUidLocked(int isolatedUid) {
StatsLog.write(
StatsLog.ISOLATED_UID_CHANGED, mIsolatedUids.get(isolatedUid, -1),
@@ -4734,6 +4736,7 @@ public class BatteryStatsImpl extends BatteryStats {
return;
}
@GuardedBy("this")
public void noteScreenStateLocked(int state) {
state = mPretendScreenOff ? Display.STATE_OFF : state;
@@ -9650,6 +9653,7 @@ public class BatteryStatsImpl extends BatteryStats {
return ps;
}
@GuardedBy("mBsi")
public void updateUidProcessStateLocked(int procState) {
int uidRunningState;
// Make special note of Foreground Services
@@ -11762,6 +11766,7 @@ public class BatteryStatsImpl extends BatteryStats {
* and we are on battery with screen off, we give more of the cpu time to those apps holding
* wakelocks. If the screen is on, we just assign the actual cpu time an app used.
*/
@GuardedBy("this")
public void updateCpuTimeLocked() {
if (mPowerProfile == null) {
return;
@@ -12207,6 +12212,7 @@ public class BatteryStatsImpl extends BatteryStats {
return false;
}
@GuardedBy("this")
protected void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime,
final boolean onBattery, final int oldStatus, final int level, final int chargeUAh) {
boolean doWrite = false;
@@ -12383,6 +12389,7 @@ public class BatteryStatsImpl extends BatteryStats {
// This should probably be exposed in the API, though it's not critical
public static final int BATTERY_PLUGGED_NONE = OsProtoEnums.BATTERY_PLUGGED_NONE; // = 0
@GuardedBy("this")
public void setBatteryStateLocked(final int status, final int health, final int plugType,
final int level, /* not final */ int temp, final int volt, final int chargeUAh,
final int chargeFullUAh) {
@@ -13198,6 +13205,7 @@ public class BatteryStatsImpl extends BatteryStats {
}
}
@GuardedBy("this")
public void dumpConstantsLocked(PrintWriter pw) {
mConstants.dumpLocked(pw);
}

View File

@@ -283,6 +283,7 @@ public class FuseAppLoop implements Handler.Callback {
return -OsConstants.EBADF;
}
@GuardedBy("mLock")
private CallbackEntry getCallbackEntryOrThrowLocked(long inode) throws ErrnoException {
final CallbackEntry entry = mCallbackMap.get(checkInode(inode));
if (entry == null) {
@@ -291,12 +292,14 @@ public class FuseAppLoop implements Handler.Callback {
return entry;
}
@GuardedBy("mLock")
private void recycleLocked(Args args) {
if (mArgsPool.size() < ARGS_POOL_SIZE) {
mArgsPool.add(args);
}
}
@GuardedBy("mLock")
private void replySimpleLocked(long unique, int result) {
if (mInstance != 0) {
native_replySimple(mInstance, unique, result);