summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Giulio Fiscella <fiscella@google.com> 2022-03-02 17:24:31 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-03-02 17:24:31 +0000
commit65a265ff6c26ee927b5dfad07d55dfdcd23d894a (patch)
tree454a280ed9dc91adae711e4b9dd4a62853b125e4
parent45d4884afcc41317980e6d4b146c4d4992bad1cb (diff)
parent0cd06878eccd9b491ebe23bf9d0f4b7609d948f7 (diff)
Merge "Apply API feedback" into tm-dev
-rw-r--r--SafetyCenter/Config/safety_center_config.xsd8
-rw-r--r--framework-s/api/system-current.txt19
-rw-r--r--framework-s/java/android/safetycenter/config/ParseException.java41
-rw-r--r--framework-s/java/android/safetycenter/config/SafetyCenterConfig.java15
-rw-r--r--framework-s/java/android/safetycenter/config/SafetyCenterConfigParser.java (renamed from framework-s/java/android/safetycenter/config/Parser.java)46
-rw-r--r--framework-s/java/android/safetycenter/config/SafetySource.java76
-rw-r--r--service/java/com/android/safetycenter/SafetyCenterConfigReader.java6
7 files changed, 119 insertions, 92 deletions
diff --git a/SafetyCenter/Config/safety_center_config.xsd b/SafetyCenter/Config/safety_center_config.xsd
index 4a51559fd..77909d341 100644
--- a/SafetyCenter/Config/safety_center_config.xsd
+++ b/SafetyCenter/Config/safety_center_config.xsd
@@ -70,8 +70,8 @@
<xsd:attribute name="maxSeverityLevel" type="xsd:int" default="2147483647"/>
<xsd:attribute name="searchTerms" type="xsd:string"/>
<xsd:attribute name="broadcastReceiverClassName" type="xsd:string"/>
- <xsd:attribute name="allowLogging" type="xsd:boolean" default="true"/>
- <xsd:attribute name="allowRefreshOnPageOpen" type="xsd:boolean" default="false"/>
+ <xsd:attribute name="loggingAllowed" type="xsd:boolean" default="true"/>
+ <xsd:attribute name="refreshOnPageOpenAllowed" type="xsd:boolean" default="false"/>
</xsd:complexType>
<xsd:complexType name="issue-only-safety-source">
@@ -81,8 +81,8 @@
<xsd:attribute name="profile" type="profile" use="required"/>
<xsd:attribute name="maxSeverityLevel" type="xsd:int" default="2147483647"/>
<xsd:attribute name="broadcastReceiverClassName" type="xsd:string"/>
- <xsd:attribute name="allowLogging" type="xsd:boolean" default="true"/>
- <xsd:attribute name="allowRefreshOnPageOpen" type="xsd:boolean" default="false"/>
+ <xsd:attribute name="loggingAllowed" type="xsd:boolean" default="true"/>
+ <xsd:attribute name="refreshOnPageOpenAllowed" type="xsd:boolean" default="false"/>
</xsd:complexType>
<xsd:complexType name="static-safety-source">
diff --git a/framework-s/api/system-current.txt b/framework-s/api/system-current.txt
index e9565fb3b..c150e1b29 100644
--- a/framework-s/api/system-current.txt
+++ b/framework-s/api/system-current.txt
@@ -395,17 +395,14 @@ package android.safetycenter {
package android.safetycenter.config {
- public final class Parser {
- method @NonNull public static android.safetycenter.config.SafetyCenterConfig parseXmlResource(@NonNull android.content.res.XmlResourceParser) throws android.safetycenter.config.Parser.ParseException;
- }
-
- public static final class Parser.ParseException extends java.lang.Exception {
- ctor public Parser.ParseException(@NonNull String);
- ctor public Parser.ParseException(@NonNull String, @NonNull Throwable);
+ public final class ParseException extends java.lang.Exception {
+ ctor public ParseException(@NonNull String);
+ ctor public ParseException(@NonNull String, @NonNull Throwable);
}
public final class SafetyCenterConfig implements android.os.Parcelable {
method public int describeContents();
+ method @NonNull public static android.safetycenter.config.SafetyCenterConfig fromXml(@NonNull android.content.res.XmlResourceParser) throws android.safetycenter.config.ParseException;
method @NonNull public java.util.List<android.safetycenter.config.SafetySourcesGroup> getSafetySourcesGroups();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.safetycenter.config.SafetyCenterConfig> CREATOR;
@@ -431,8 +428,8 @@ package android.safetycenter.config {
method @StringRes public int getTitleForWorkResId();
method @StringRes public int getTitleResId();
method public int getType();
- method public boolean isAllowLogging();
- method public boolean isAllowRefreshOnPageOpen();
+ method public boolean isLoggingAllowed();
+ method public boolean isRefreshOnPageOpenAllowed();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.safetycenter.config.SafetySource> CREATOR;
field public static final int INITIAL_DISPLAY_STATE_DISABLED = 1; // 0x1
@@ -449,15 +446,15 @@ package android.safetycenter.config {
public static final class SafetySource.Builder {
ctor public SafetySource.Builder(int);
method @NonNull public android.safetycenter.config.SafetySource build();
- method @NonNull public android.safetycenter.config.SafetySource.Builder setAllowLogging(boolean);
- method @NonNull public android.safetycenter.config.SafetySource.Builder setAllowRefreshOnPageOpen(boolean);
method @NonNull public android.safetycenter.config.SafetySource.Builder setBroadcastReceiverClassName(@Nullable String);
method @NonNull public android.safetycenter.config.SafetySource.Builder setId(@Nullable String);
method @NonNull public android.safetycenter.config.SafetySource.Builder setInitialDisplayState(int);
method @NonNull public android.safetycenter.config.SafetySource.Builder setIntentAction(@Nullable String);
+ method @NonNull public android.safetycenter.config.SafetySource.Builder setLoggingAllowed(boolean);
method @NonNull public android.safetycenter.config.SafetySource.Builder setMaxSeverityLevel(int);
method @NonNull public android.safetycenter.config.SafetySource.Builder setPackageName(@Nullable String);
method @NonNull public android.safetycenter.config.SafetySource.Builder setProfile(int);
+ method @NonNull public android.safetycenter.config.SafetySource.Builder setRefreshOnPageOpenAllowed(boolean);
method @NonNull public android.safetycenter.config.SafetySource.Builder setSearchTermsResId(@StringRes int);
method @NonNull public android.safetycenter.config.SafetySource.Builder setSummaryResId(@StringRes int);
method @NonNull public android.safetycenter.config.SafetySource.Builder setTitleForWorkResId(@StringRes int);
diff --git a/framework-s/java/android/safetycenter/config/ParseException.java b/framework-s/java/android/safetycenter/config/ParseException.java
new file mode 100644
index 000000000..3b01e0bb7
--- /dev/null
+++ b/framework-s/java/android/safetycenter/config/ParseException.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2022 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 android.safetycenter.config;
+
+import static android.os.Build.VERSION_CODES.TIRAMISU;
+
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
+
+import androidx.annotation.RequiresApi;
+
+/**
+ * Exception thrown when there is an error parsing the Safety Center configuration
+ *
+ * @hide
+ */
+@SystemApi
+@RequiresApi(TIRAMISU)
+public final class ParseException extends Exception {
+ public ParseException(@NonNull String message) {
+ super(message);
+ }
+
+ public ParseException(@NonNull String message, @NonNull Throwable ex) {
+ super(message, ex);
+ }
+}
diff --git a/framework-s/java/android/safetycenter/config/SafetyCenterConfig.java b/framework-s/java/android/safetycenter/config/SafetyCenterConfig.java
index 235fa99f8..9f74be082 100644
--- a/framework-s/java/android/safetycenter/config/SafetyCenterConfig.java
+++ b/framework-s/java/android/safetycenter/config/SafetyCenterConfig.java
@@ -22,6 +22,7 @@ import static java.util.Objects.requireNonNull;
import android.annotation.NonNull;
import android.annotation.SystemApi;
+import android.content.res.XmlResourceParser;
import android.os.Parcel;
import android.os.Parcelable;
@@ -152,4 +153,18 @@ public final class SafetyCenterConfig implements Parcelable {
}
}
+ /**
+ * Parses and validates the given XML resource into a {@link SafetyCenterConfig} object.
+ *
+ * <p>It throws a {@link ParseException} if the given XML resource does not comply with the
+ * safety_center_config.xsd schema.
+ *
+ * @param parser the XML resource parsing interface
+ */
+ @NonNull
+ public static SafetyCenterConfig fromXml(@NonNull XmlResourceParser parser)
+ throws ParseException {
+ return SafetyCenterConfigParser.parseXmlResource(parser);
+ }
+
}
diff --git a/framework-s/java/android/safetycenter/config/Parser.java b/framework-s/java/android/safetycenter/config/SafetyCenterConfigParser.java
index bda37d3d5..75ca73758 100644
--- a/framework-s/java/android/safetycenter/config/Parser.java
+++ b/framework-s/java/android/safetycenter/config/SafetyCenterConfigParser.java
@@ -29,7 +29,6 @@ import static java.util.Objects.requireNonNull;
import android.annotation.NonNull;
import android.annotation.StringRes;
-import android.annotation.SystemApi;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.safetycenter.config.SafetySource.InitialDisplayState;
@@ -43,15 +42,9 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
-/**
- * Utility class to parse and validate a Safety Center Config
- *
- * @hide
- */
-@SystemApi
@RequiresApi(TIRAMISU)
-public final class Parser {
- private Parser() {
+final class SafetyCenterConfigParser {
+ private SafetyCenterConfigParser() {
}
private static final String TAG_SAFETY_CENTER_CONFIG = "safety-center-config";
@@ -78,9 +71,9 @@ public final class Parser {
private static final String ATTR_SAFETY_SOURCE_SEARCH_TERMS = "searchTerms";
private static final String ATTR_SAFETY_SOURCE_BROADCAST_RECEIVER_CLASS_NAME =
"broadcastReceiverClassName";
- private static final String ATTR_SAFETY_SOURCE_ALLOW_LOGGING = "allowLogging";
- private static final String ATTR_SAFETY_SOURCE_ALLOW_REFRESH_ON_PAGE_OPEN =
- "allowRefreshOnPageOpen";
+ private static final String ATTR_SAFETY_SOURCE_LOGGING_ALLOWED = "loggingAllowed";
+ private static final String ATTR_SAFETY_SOURCE_REFRESH_ON_PAGE_OPEN_ALLOWED =
+ "refreshOnPageOpenAllowed";
private static final String ENUM_STATELESS_ICON_TYPE_NONE = "none";
private static final String ENUM_STATELESS_ICON_TYPE_PRIVACY = "privacy";
@@ -92,27 +85,8 @@ public final class Parser {
private static final String ENUM_INITIAL_DISPLAY_STATE_DISABLED = "disabled";
private static final String ENUM_INITIAL_DISPLAY_STATE_HIDDEN = "hidden";
- /** Thrown when there is an error parsing the Safety Center Config */
- public static final class ParseException extends Exception {
- public ParseException(@NonNull String message) {
- super(message);
- }
-
- public ParseException(@NonNull String message, @NonNull Throwable ex) {
- super(message, ex);
- }
- }
-
- /**
- * Parses and validates the given XML resource into a {@link SafetyCenterConfig} object.
- *
- * <p>It throws a {@link ParseException} if the given XML resource does not comply with the
- * safety_center_config.xsd schema.
- *
- * @param parser the XML resource parsing interface
- */
@NonNull
- public static SafetyCenterConfig parseXmlResource(@NonNull XmlResourceParser parser)
+ static SafetyCenterConfig parseXmlResource(@NonNull XmlResourceParser parser)
throws ParseException {
requireNonNull(parser);
try {
@@ -258,12 +232,12 @@ public final class Parser {
case ATTR_SAFETY_SOURCE_BROADCAST_RECEIVER_CLASS_NAME:
builder.setBroadcastReceiverClassName(parser.getAttributeValue(i));
break;
- case ATTR_SAFETY_SOURCE_ALLOW_LOGGING:
- builder.setAllowLogging(parseBoolean(parser.getAttributeValue(i), name,
+ case ATTR_SAFETY_SOURCE_LOGGING_ALLOWED:
+ builder.setLoggingAllowed(parseBoolean(parser.getAttributeValue(i), name,
parser.getAttributeName(i)));
break;
- case ATTR_SAFETY_SOURCE_ALLOW_REFRESH_ON_PAGE_OPEN:
- builder.setAllowRefreshOnPageOpen(
+ case ATTR_SAFETY_SOURCE_REFRESH_ON_PAGE_OPEN_ALLOWED:
+ builder.setRefreshOnPageOpenAllowed(
parseBoolean(parser.getAttributeValue(i), name,
parser.getAttributeName(i)));
break;
diff --git a/framework-s/java/android/safetycenter/config/SafetySource.java b/framework-s/java/android/safetycenter/config/SafetySource.java
index 641796f5f..2ec6cfdba 100644
--- a/framework-s/java/android/safetycenter/config/SafetySource.java
+++ b/framework-s/java/android/safetycenter/config/SafetySource.java
@@ -139,8 +139,8 @@ public final class SafetySource implements Parcelable {
private final int mSearchTermsResId;
@Nullable
private final String mBroadcastReceiverClassName;
- private final boolean mAllowLogging;
- private final boolean mAllowRefreshOnPageOpen;
+ private final boolean mLoggingAllowed;
+ private final boolean mRefreshOnPageOpenAllowed;
/** Returns the id of this safety source. */
private SafetySource(
@@ -156,8 +156,8 @@ public final class SafetySource implements Parcelable {
int maxSeverityLevel,
@StringRes int searchTermsResId,
@Nullable String broadcastReceiverClassName,
- boolean allowLogging,
- boolean allowRefreshOnPageOpen) {
+ boolean loggingAllowed,
+ boolean refreshOnPageOpenAllowed) {
mType = type;
mId = id;
mPackageName = packageName;
@@ -170,8 +170,8 @@ public final class SafetySource implements Parcelable {
mMaxSeverityLevel = maxSeverityLevel;
mSearchTermsResId = searchTermsResId;
mBroadcastReceiverClassName = broadcastReceiverClassName;
- mAllowLogging = allowLogging;
- mAllowRefreshOnPageOpen = allowRefreshOnPageOpen;
+ mLoggingAllowed = loggingAllowed;
+ mRefreshOnPageOpenAllowed = refreshOnPageOpenAllowed;
}
/** Returns the type of this safety source. */
@@ -292,22 +292,22 @@ public final class SafetySource implements Parcelable {
return mBroadcastReceiverClassName;
}
- /** Returns the allow logging property of this safety source. */
- public boolean isAllowLogging() {
+ /** Returns the logging allowed property of this safety source. */
+ public boolean isLoggingAllowed() {
if (mType == SAFETY_SOURCE_TYPE_STATIC) {
throw new UnsupportedOperationException(
- "isAllowLogging unsupported for static safety source");
+ "isLoggingAllowed unsupported for static safety source");
}
- return mAllowLogging;
+ return mLoggingAllowed;
}
- /** Returns the allow refresh on page open property of this safety source. */
- public boolean isAllowRefreshOnPageOpen() {
+ /** Returns the refresh on page open allowed property of this safety source. */
+ public boolean isRefreshOnPageOpenAllowed() {
if (mType == SAFETY_SOURCE_TYPE_STATIC) {
throw new UnsupportedOperationException(
- "isAllowRefreshOnPageOpen unsupported for static safety source");
+ "isRefreshOnPageOpenAllowed unsupported for static safety source");
}
- return mAllowRefreshOnPageOpen;
+ return mRefreshOnPageOpenAllowed;
}
@Override
@@ -327,16 +327,16 @@ public final class SafetySource implements Parcelable {
&& mMaxSeverityLevel == that.mMaxSeverityLevel
&& mSearchTermsResId == that.mSearchTermsResId
&& Objects.equals(mBroadcastReceiverClassName, that.mBroadcastReceiverClassName)
- && mAllowLogging == that.mAllowLogging
- && mAllowRefreshOnPageOpen == that.mAllowRefreshOnPageOpen;
+ && mLoggingAllowed == that.mLoggingAllowed
+ && mRefreshOnPageOpenAllowed == that.mRefreshOnPageOpenAllowed;
}
@Override
public int hashCode() {
return Objects.hash(mType, mId, mPackageName, mTitleResId, mTitleForWorkResId,
mSummaryResId, mIntentAction, mProfile, mInitialDisplayState, mMaxSeverityLevel,
- mSearchTermsResId, mBroadcastReceiverClassName, mAllowLogging,
- mAllowRefreshOnPageOpen);
+ mSearchTermsResId, mBroadcastReceiverClassName, mLoggingAllowed,
+ mRefreshOnPageOpenAllowed);
}
@Override
@@ -354,8 +354,8 @@ public final class SafetySource implements Parcelable {
+ ", mMaxSeverityLevel=" + mMaxSeverityLevel
+ ", mSearchTermsResId=" + mSearchTermsResId
+ ", mBroadcastReceiverClassName='" + mBroadcastReceiverClassName + '\''
- + ", mAllowLogging=" + mAllowLogging
- + ", mAllowRefreshOnPageOpen=" + mAllowRefreshOnPageOpen
+ + ", mLoggingAllowed=" + mLoggingAllowed
+ + ", mRefreshOnPageOpenAllowed=" + mRefreshOnPageOpenAllowed
+ '}';
}
@@ -378,8 +378,8 @@ public final class SafetySource implements Parcelable {
dest.writeInt(mMaxSeverityLevel);
dest.writeInt(mSearchTermsResId);
dest.writeString(mBroadcastReceiverClassName);
- dest.writeBoolean(mAllowLogging);
- dest.writeBoolean(mAllowRefreshOnPageOpen);
+ dest.writeBoolean(mLoggingAllowed);
+ dest.writeBoolean(mRefreshOnPageOpenAllowed);
}
@NonNull
@@ -399,12 +399,12 @@ public final class SafetySource implements Parcelable {
int maxSeverityLevel = in.readInt();
int searchTermsResId = in.readInt();
String broadcastReceiverClassName = in.readString();
- boolean allowLogging = in.readBoolean();
- boolean allowRefreshOnPageOpen = in.readBoolean();
+ boolean loggingAllowed = in.readBoolean();
+ boolean refreshOnPageOpenAllowed = in.readBoolean();
return new SafetySource(type, id, packageName, titleResId, titleForWorkResId,
summaryResId, intentAction, profile, initialDisplayState,
maxSeverityLevel, searchTermsResId, broadcastReceiverClassName,
- allowLogging, allowRefreshOnPageOpen);
+ loggingAllowed, refreshOnPageOpenAllowed);
}
@Override
@@ -446,9 +446,9 @@ public final class SafetySource implements Parcelable {
@Nullable
private String mBroadcastReceiverClassName;
@Nullable
- private Boolean mAllowLogging;
+ private Boolean mLoggingAllowed;
@Nullable
- private Boolean mAllowRefreshOnPageOpen;
+ private Boolean mRefreshOnPageOpenAllowed;
/** Creates a {@link Builder} for a {@link SafetySource}. */
public Builder(@SafetySourceType int type) {
@@ -532,17 +532,17 @@ public final class SafetySource implements Parcelable {
return this;
}
- /** Sets the allow logging property of this safety source. */
+ /** Sets the logging allowed property of this safety source. */
@NonNull
- public Builder setAllowLogging(boolean allowLogging) {
- mAllowLogging = allowLogging;
+ public Builder setLoggingAllowed(boolean loggingAllowed) {
+ mLoggingAllowed = loggingAllowed;
return this;
}
- /** Sets the allow refresh on page open property of this safety source. */
+ /** Sets the refresh on page open allowed property of this safety source. */
@NonNull
- public Builder setAllowRefreshOnPageOpen(boolean allowRefreshOnPageOpen) {
- mAllowRefreshOnPageOpen = allowRefreshOnPageOpen;
+ public Builder setRefreshOnPageOpenAllowed(boolean refreshOnPageOpenAllowed) {
+ mRefreshOnPageOpenAllowed = refreshOnPageOpenAllowed;
return this;
}
@@ -583,14 +583,14 @@ public final class SafetySource implements Parcelable {
false, isIssueOnly);
BuilderUtils.validateAttribute(mBroadcastReceiverClassName,
"broadcastReceiverClassName", false, isStatic);
- boolean allowLogging = BuilderUtils.validateBoolean(mAllowLogging, "allowLogging",
+ boolean loggingAllowed = BuilderUtils.validateBoolean(mLoggingAllowed, "loggingAllowed",
false, isStatic, true);
- boolean allowRefreshOnPageOpen = BuilderUtils.validateBoolean(mAllowRefreshOnPageOpen,
- "allowRefreshOnPageOpen", false, isStatic, false);
+ boolean refreshOnPageOpenAllowed = BuilderUtils.validateBoolean(
+ mRefreshOnPageOpenAllowed, "refreshOnPageOpenAllowed", false, isStatic, false);
return new SafetySource(mType, mId, mPackageName, titleResId, titleForWorkResId,
summaryResId, mIntentAction, profile, initialDisplayState, maxSeverityLevel,
- searchTermsResId, mBroadcastReceiverClassName, allowLogging,
- allowRefreshOnPageOpen);
+ searchTermsResId, mBroadcastReceiverClassName, loggingAllowed,
+ refreshOnPageOpenAllowed);
}
}
diff --git a/service/java/com/android/safetycenter/SafetyCenterConfigReader.java b/service/java/com/android/safetycenter/SafetyCenterConfigReader.java
index df695a0d6..61315a125 100644
--- a/service/java/com/android/safetycenter/SafetyCenterConfigReader.java
+++ b/service/java/com/android/safetycenter/SafetyCenterConfigReader.java
@@ -24,7 +24,7 @@ import android.annotation.StringRes;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
-import android.safetycenter.config.Parser;
+import android.safetycenter.config.ParseException;
import android.safetycenter.config.SafetyCenterConfig;
import android.util.Log;
@@ -107,10 +107,10 @@ final class SafetyCenterConfigReader {
}
try {
- SafetyCenterConfig safetyCenterConfig = Parser.parseXmlResource(parser);
+ SafetyCenterConfig safetyCenterConfig = SafetyCenterConfig.fromXml(parser);
Log.i(TAG, "SafetyCenterConfig read successfully");
return safetyCenterConfig;
- } catch (Parser.ParseException e) {
+ } catch (ParseException e) {
Log.e(TAG, "Cannot read SafetyCenterConfig", e);
return null;
}