Merge "Useful annotations for code documentation." into jb-mr1.1-dev

This commit is contained in:
Jeff Sharkey
2012-11-15 11:48:20 -08:00
committed by Android (Google) Code Review
17 changed files with 158 additions and 27 deletions

View File

@ -58,6 +58,7 @@ import android.util.Pair;
import android.util.Slog; import android.util.Slog;
import com.android.internal.R; import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import com.google.android.collect.Lists; import com.google.android.collect.Lists;
import com.google.android.collect.Maps; import com.google.android.collect.Maps;
@ -155,7 +156,7 @@ public class SyncManager {
private SyncStorageEngine mSyncStorageEngine; private SyncStorageEngine mSyncStorageEngine;
// @GuardedBy("mSyncQueue") @GuardedBy("mSyncQueue")
private final SyncQueue mSyncQueue; private final SyncQueue mSyncQueue;
protected final ArrayList<ActiveSyncContext> mActiveSyncContexts = Lists.newArrayList(); protected final ArrayList<ActiveSyncContext> mActiveSyncContexts = Lists.newArrayList();

View File

@ -16,6 +16,7 @@
package android.content; package android.content;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.FastXmlSerializer;
@ -74,7 +75,7 @@ public class SyncStorageEngine extends Handler {
private static final long DEFAULT_POLL_FREQUENCY_SECONDS = 60 * 60 * 24; // One day private static final long DEFAULT_POLL_FREQUENCY_SECONDS = 60 * 60 * 24; // One day
// @VisibleForTesting @VisibleForTesting
static final long MILLIS_IN_4WEEKS = 1000L * 60 * 60 * 24 * 7 * 4; static final long MILLIS_IN_4WEEKS = 1000L * 60 * 60 * 24 * 7 * 4;
/** Enum value for a sync start event. */ /** Enum value for a sync start event. */

View File

@ -34,6 +34,7 @@ import android.util.Slog;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.Xml; import android.util.Xml;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.FastXmlSerializer;
import com.google.android.collect.Lists; import com.google.android.collect.Lists;
import com.google.android.collect.Maps; import com.google.android.collect.Maps;
@ -77,15 +78,15 @@ public abstract class RegisteredServicesCache<V> {
private final Object mServicesLock = new Object(); private final Object mServicesLock = new Object();
// @GuardedBy("mServicesLock") @GuardedBy("mServicesLock")
private boolean mPersistentServicesFileDidNotExist; private boolean mPersistentServicesFileDidNotExist;
// @GuardedBy("mServicesLock") @GuardedBy("mServicesLock")
private final SparseArray<UserServices<V>> mUserServices = new SparseArray<UserServices<V>>(); private final SparseArray<UserServices<V>> mUserServices = new SparseArray<UserServices<V>>();
private static class UserServices<V> { private static class UserServices<V> {
// @GuardedBy("mServicesLock") @GuardedBy("mServicesLock")
public final Map<V, Integer> persistentServices = Maps.newHashMap(); public final Map<V, Integer> persistentServices = Maps.newHashMap();
// @GuardedBy("mServicesLock") @GuardedBy("mServicesLock")
public Map<V, ServiceInfo<V>> services = null; public Map<V, ServiceInfo<V>> services = null;
} }

View File

@ -21,6 +21,7 @@ import android.os.Parcelable;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Objects; import com.android.internal.util.Objects;
@ -190,14 +191,14 @@ public class NetworkStats implements Parcelable {
return clone; return clone;
} }
// @VisibleForTesting @VisibleForTesting
public NetworkStats addIfaceValues( public NetworkStats addIfaceValues(
String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) { String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) {
return addValues( return addValues(
iface, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, 0L); iface, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, 0L);
} }
// @VisibleForTesting @VisibleForTesting
public NetworkStats addValues(String iface, int uid, int set, int tag, long rxBytes, public NetworkStats addValues(String iface, int uid, int set, int tag, long rxBytes,
long rxPackets, long txBytes, long txPackets, long operations) { long rxPackets, long txBytes, long txPackets, long operations) {
return addValues(new Entry( return addValues(new Entry(
@ -269,7 +270,7 @@ public class NetworkStats implements Parcelable {
return size; return size;
} }
// @VisibleForTesting @VisibleForTesting
public int internalSize() { public int internalSize() {
return iface.length; return iface.length;
} }
@ -335,7 +336,7 @@ public class NetworkStats implements Parcelable {
* Find first stats index that matches the requested parameters, starting * Find first stats index that matches the requested parameters, starting
* search around the hinted index as an optimization. * search around the hinted index as an optimization.
*/ */
// @VisibleForTesting @VisibleForTesting
public int findIndexHinted(String iface, int uid, int set, int tag, int hintIndex) { public int findIndexHinted(String iface, int uid, int set, int tag, int hintIndex) {
for (int offset = 0; offset < size; offset++) { for (int offset = 0; offset < size; offset++) {
final int halfOffset = offset / 2; final int halfOffset = offset / 2;

View File

@ -33,6 +33,7 @@ import android.content.res.Resources;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Objects; import com.android.internal.util.Objects;
/** /**
@ -63,7 +64,7 @@ public class NetworkTemplate implements Parcelable {
private static boolean sForceAllNetworkTypes = false; private static boolean sForceAllNetworkTypes = false;
// @VisibleForTesting @VisibleForTesting
public static void forceAllNetworkTypes() { public static void forceAllNetworkTypes() {
sForceAllNetworkTypes = true; sForceAllNetworkTypes = true;
} }

View File

@ -22,6 +22,8 @@ import android.os.storage.StorageVolume;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import java.io.File; import java.io.File;
/** /**
@ -47,7 +49,7 @@ public class Environment {
private static final Object sLock = new Object(); private static final Object sLock = new Object();
// @GuardedBy("sLock") @GuardedBy("sLock")
private static volatile StorageVolume sPrimaryVolume; private static volatile StorageVolume sPrimaryVolume;
private static StorageVolume getPrimaryVolume() { private static StorageVolume getPrimaryVolume() {

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2012 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.internal.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation type used to mark a method or field that can only be accessed when
* holding the referenced lock.
*/
@Target({ ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.CLASS)
public @interface GuardedBy {
String value();
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) 2012 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.internal.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation type used to mark a class which is immutable.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
public @interface Immutable {
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2012 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.internal.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Denotes that the class, method or field has its visibility relaxed so
* that unit tests can access it.
* <p/>
* The <code>visibility</code> argument can be used to specific what the original
* visibility should have been if it had not been made public or package-private for testing.
* The default is to consider the element private.
*/
@Retention(RetentionPolicy.SOURCE)
public @interface VisibleForTesting {
/**
* Intended visibility if the element had not been made public or package-private for
* testing.
*/
enum Visibility {
/** The element should be considered protected. */
PROTECTED,
/** The element should be considered package-private. */
PACKAGE,
/** The element should be considered private. */
PRIVATE
}
/**
* Intended visibility if the element had not been made public or package-private for testing.
* If not specified, one should assume the element originally intended to be private.
*/
Visibility visibility() default Visibility.PRIVATE;
}

View File

@ -25,6 +25,7 @@ import android.net.NetworkStats;
import android.os.StrictMode; import android.os.StrictMode;
import android.os.SystemClock; import android.os.SystemClock;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ProcFileReader; import com.android.internal.util.ProcFileReader;
import java.io.File; import java.io.File;
@ -53,7 +54,7 @@ public class NetworkStatsFactory {
this(new File("/proc/")); this(new File("/proc/"));
} }
// @VisibleForTesting @VisibleForTesting
public NetworkStatsFactory(File procRoot) { public NetworkStatsFactory(File procRoot) {
mStatsXtIfaceAll = new File(procRoot, "net/xt_qtaguid/iface_stat_all"); mStatsXtIfaceAll = new File(procRoot, "net/xt_qtaguid/iface_stat_all");
mStatsXtIfaceFmt = new File(procRoot, "net/xt_qtaguid/iface_stat_fmt"); mStatsXtIfaceFmt = new File(procRoot, "net/xt_qtaguid/iface_stat_fmt");

View File

@ -57,6 +57,8 @@ import android.util.AttributeSet;
import android.util.Slog; import android.util.Slog;
import android.util.Xml; import android.util.Xml;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IMediaContainerService; import com.android.internal.app.IMediaContainerService;
import com.android.internal.util.Preconditions; import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils; import com.android.internal.util.XmlUtils;
@ -181,13 +183,13 @@ class MountService extends IMountService.Stub
/** When defined, base template for user-specific {@link StorageVolume}. */ /** When defined, base template for user-specific {@link StorageVolume}. */
private StorageVolume mEmulatedTemplate; private StorageVolume mEmulatedTemplate;
// @GuardedBy("mVolumesLock") @GuardedBy("mVolumesLock")
private final ArrayList<StorageVolume> mVolumes = Lists.newArrayList(); private final ArrayList<StorageVolume> mVolumes = Lists.newArrayList();
/** Map from path to {@link StorageVolume} */ /** Map from path to {@link StorageVolume} */
// @GuardedBy("mVolumesLock") @GuardedBy("mVolumesLock")
private final HashMap<String, StorageVolume> mVolumesByPath = Maps.newHashMap(); private final HashMap<String, StorageVolume> mVolumesByPath = Maps.newHashMap();
/** Map from path to state */ /** Map from path to state */
// @GuardedBy("mVolumesLock") @GuardedBy("mVolumesLock")
private final HashMap<String, String> mVolumeStates = Maps.newHashMap(); private final HashMap<String, String> mVolumeStates = Maps.newHashMap();
private volatile boolean mSystemReady = false; private volatile boolean mSystemReady = false;
@ -2565,7 +2567,7 @@ class MountService extends IMountService.Stub
} }
} }
// @VisibleForTesting @VisibleForTesting
public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) { public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) {
// TODO: allow caller to provide Environment for full testing // TODO: allow caller to provide Environment for full testing

View File

@ -25,6 +25,7 @@ import android.os.SystemClock;
import android.util.LocalLog; import android.util.LocalLog;
import android.util.Slog; import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.google.android.collect.Lists; import com.google.android.collect.Lists;
import java.nio.charset.Charsets; import java.nio.charset.Charsets;
@ -400,7 +401,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
* Append the given argument to {@link StringBuilder}, escaping as needed, * Append the given argument to {@link StringBuilder}, escaping as needed,
* and surrounding with quotes when it contains spaces. * and surrounding with quotes when it contains spaces.
*/ */
// @VisibleForTesting @VisibleForTesting
static void appendEscaped(StringBuilder builder, String arg) { static void appendEscaped(StringBuilder builder, String arg) {
final boolean hasSpaces = arg.indexOf(' ') >= 0; final boolean hasSpaces = arg.indexOf(' ') >= 0;
if (hasSpaces) { if (hasSpaces) {

View File

@ -131,6 +131,7 @@ import android.util.TrustedTime;
import android.util.Xml; import android.util.Xml;
import com.android.internal.R; import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Objects; import com.android.internal.util.Objects;
@ -184,9 +185,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final int VERSION_SWITCH_UID = 10; private static final int VERSION_SWITCH_UID = 10;
private static final int VERSION_LATEST = VERSION_SWITCH_UID; private static final int VERSION_LATEST = VERSION_SWITCH_UID;
// @VisibleForTesting @VisibleForTesting
public static final int TYPE_WARNING = 0x1; public static final int TYPE_WARNING = 0x1;
@VisibleForTesting
public static final int TYPE_LIMIT = 0x2; public static final int TYPE_LIMIT = 0x2;
@VisibleForTesting
public static final int TYPE_LIMIT_SNOOZED = 0x3; public static final int TYPE_LIMIT_SNOOZED = 0x3;
private static final String TAG_POLICY_LIST = "policy-list"; private static final String TAG_POLICY_LIST = "policy-list";
@ -214,10 +217,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final String TAG_ALLOW_BACKGROUND = TAG + ":allowBackground"; private static final String TAG_ALLOW_BACKGROUND = TAG + ":allowBackground";
// @VisibleForTesting private static final String ACTION_ALLOW_BACKGROUND =
public static final String ACTION_ALLOW_BACKGROUND =
"com.android.server.net.action.ALLOW_BACKGROUND"; "com.android.server.net.action.ALLOW_BACKGROUND";
public static final String ACTION_SNOOZE_WARNING = private static final String ACTION_SNOOZE_WARNING =
"com.android.server.net.action.SNOOZE_WARNING"; "com.android.server.net.action.SNOOZE_WARNING";
private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS; private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS;
@ -2063,7 +2065,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
return intent; return intent;
} }
// @VisibleForTesting @VisibleForTesting
public void addIdleHandler(IdleHandler handler) { public void addIdleHandler(IdleHandler handler) {
mHandler.getLooper().getQueue().addIdleHandler(handler); mHandler.getLooper().getQueue().addIdleHandler(handler);
} }

View File

@ -115,6 +115,7 @@ import android.util.Slog;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import android.util.TrustedTime; import android.util.TrustedTime;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils; import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FileRotator; import com.android.internal.util.FileRotator;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
@ -165,7 +166,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private IConnectivityManager mConnManager; private IConnectivityManager mConnManager;
// @VisibleForTesting @VisibleForTesting
public static final String ACTION_NETWORK_STATS_POLL = public static final String ACTION_NETWORK_STATS_POLL =
"com.android.server.action.NETWORK_STATS_POLL"; "com.android.server.action.NETWORK_STATS_POLL";
public static final String ACTION_NETWORK_STATS_UPDATED = public static final String ACTION_NETWORK_STATS_UPDATED =

View File

@ -47,6 +47,8 @@ import android.provider.Settings;
import android.util.Pair; import android.util.Pair;
import android.util.Slog; import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import java.io.File; import java.io.File;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -105,7 +107,7 @@ public class UsbDeviceManager {
private final Context mContext; private final Context mContext;
private final ContentResolver mContentResolver; private final ContentResolver mContentResolver;
// @GuardedBy("mLock") @GuardedBy("mLock")
private UsbSettingsManager mCurrentSettings; private UsbSettingsManager mCurrentSettings;
private NotificationManager mNotificationManager; private NotificationManager mNotificationManager;
private final boolean mHasUsbAccessory; private final boolean mHasUsbAccessory;

View File

@ -26,6 +26,8 @@ import android.os.ParcelFileDescriptor;
import android.os.Parcelable; import android.os.Parcelable;
import android.util.Slog; import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.HashMap; import java.util.HashMap;
@ -46,7 +48,7 @@ public class UsbHostManager {
private final Context mContext; private final Context mContext;
private final Object mLock = new Object(); private final Object mLock = new Object();
// @GuardedBy("mLock") @GuardedBy("mLock")
private UsbSettingsManager mCurrentSettings; private UsbSettingsManager mCurrentSettings;
public UsbHostManager(Context context) { public UsbHostManager(Context context) {

View File

@ -30,6 +30,7 @@ import android.os.ParcelFileDescriptor;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.SparseArray; import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import java.io.File; import java.io.File;
@ -52,7 +53,7 @@ public class UsbService extends IUsbManager.Stub {
private final Object mLock = new Object(); private final Object mLock = new Object();
/** Map from {@link UserHandle} to {@link UsbSettingsManager} */ /** Map from {@link UserHandle} to {@link UsbSettingsManager} */
// @GuardedBy("mLock") @GuardedBy("mLock")
private final SparseArray<UsbSettingsManager> private final SparseArray<UsbSettingsManager>
mSettingsByUser = new SparseArray<UsbSettingsManager>(); mSettingsByUser = new SparseArray<UsbSettingsManager>();