summaryrefslogtreecommitdiff
path: root/SafetyCenter
diff options
context:
space:
mode:
Diffstat (limited to 'SafetyCenter')
-rw-r--r--SafetyCenter/Annotations/java/com/android/safetycenter/annotations/NonNullByDefault.java25
-rw-r--r--SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java7
2 files changed, 21 insertions, 11 deletions
diff --git a/SafetyCenter/Annotations/java/com/android/safetycenter/annotations/NonNullByDefault.java b/SafetyCenter/Annotations/java/com/android/safetycenter/annotations/NonNullByDefault.java
index d19110652..34b6ce798 100644
--- a/SafetyCenter/Annotations/java/com/android/safetycenter/annotations/NonNullByDefault.java
+++ b/SafetyCenter/Annotations/java/com/android/safetycenter/annotations/NonNullByDefault.java
@@ -15,19 +15,28 @@
*/
package com.android.safetycenter.annotations;
-import androidx.annotation.NonNull;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PACKAGE;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.CLASS;
-import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
/**
- * Annotation to declare all type usages in the annotated instance as {@link NonNull}, unless
- * explicitly marked with a nullable annotation.
+ * Specifies that all type uses are {@link Nonnull} within the annotated package, unless tagged with
+ * {@code @Nullable}. This helps IDEs flag all potential nullability issues without having to use
+ * {@code @NonNull} annotations.
+ *
+ * <p>This is similar to {@code @ParametersAreNonnullByDefault}, but is also applied more widely
+ * (e.g. to methods return types and fields).
*/
-@NonNull
-@TypeQualifierDefault(ElementType.TYPE_USE)
-@Retention(RetentionPolicy.CLASS)
+@Retention(CLASS)
+@Target(PACKAGE)
+@TypeQualifierDefault({PARAMETER, FIELD, METHOD})
+@Nonnull // Android variant cannot be applied as a type qualifier.
public @interface NonNullByDefault {}
diff --git a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
index bc56d18ee..5417e7b89 100644
--- a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
+++ b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
@@ -290,6 +290,7 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
/** Retrieve assets held in the Safety Center resources APK. */
@Override
+ @Nullable
public AssetManager getAssets() {
if (mAssetsFromApk == null) {
Context resourcesApkContext = getResourcesApkContext();
@@ -302,6 +303,7 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
/** Retrieve resources held in the Safety Center resources APK. */
@Override
+ @Nullable
public Resources getResources() {
if (mResourcesFromApk == null) {
Context resourcesApkContext = getResourcesApkContext();
@@ -314,6 +316,7 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
/** Retrieve theme held in the Safety Center resources APK. */
@Override
+ @Nullable
public Resources.Theme getTheme() {
if (mThemeFromApk == null) {
Context resourcesApkContext = getResourcesApkContext();
@@ -366,9 +369,7 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
return null;
}
- /**
- * Gets a color by resource name
- */
+ /** Gets a color by resource name */
@ColorInt
@Nullable
public Integer getColorByName(String name) {