Merge "Add TV audio device management APIs."
diff --git a/Android.bp b/Android.bp
index 58f6119..3ecb5a9 100644
--- a/Android.bp
+++ b/Android.bp
@@ -297,6 +297,8 @@
],
}
+// AIDL files under these paths are mixture of public and private ones.
+// They shouldn't be exported across module boundaries.
java_defaults {
name: "framework-aidl-export-defaults",
aidl: {
@@ -321,12 +323,6 @@
"wifi/aidl-export",
],
},
-
- required: [
- // TODO: remove gps_debug and protolog.conf.json when the build system propagates "required" properly.
- "gps_debug.conf",
- "protolog.conf.json.gz",
- ],
}
// Collection of classes that are generated from non-Java files that are not listed in
@@ -416,6 +412,12 @@
"view-inspector-annotation-processor",
"staledataclass-annotation-processor",
],
+
+ required: [
+ // TODO: remove gps_debug and protolog.conf.json when the build system propagates "required" properly.
+ "gps_debug.conf",
+ "protolog.conf.json.gz",
+ ],
}
filegroup {
@@ -539,7 +541,6 @@
java_library {
name: "framework-annotation-proc",
- defaults: ["framework-aidl-export-defaults"],
srcs: [":framework-all-sources"],
libs: [
"app-compat-annotations",
@@ -713,7 +714,10 @@
name: "framework-tethering-annotations",
srcs: [
"core/java/android/annotation/NonNull.java",
+ "core/java/android/annotation/Nullable.java",
+ "core/java/android/annotation/RequiresPermission.java",
"core/java/android/annotation/SystemApi.java",
+ "core/java/android/annotation/TestApi.java",
],
}
// Build ext.jar
diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearch.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearch.java
index fd20186..8bf13ee 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/AppSearch.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearch.java
@@ -101,6 +101,54 @@
this(document.mProto, document.mPropertyBundle);
}
+ /** @hide */
+ Document(@NonNull DocumentProto documentProto) {
+ this(documentProto, new Bundle());
+ for (int i = 0; i < documentProto.getPropertiesCount(); i++) {
+ PropertyProto property = documentProto.getProperties(i);
+ String name = property.getName();
+ if (property.getStringValuesCount() > 0) {
+ String[] values = new String[property.getStringValuesCount()];
+ for (int j = 0; j < values.length; j++) {
+ values[j] = property.getStringValues(j);
+ }
+ mPropertyBundle.putStringArray(name, values);
+ } else if (property.getInt64ValuesCount() > 0) {
+ long[] values = new long[property.getInt64ValuesCount()];
+ for (int j = 0; j < values.length; j++) {
+ values[j] = property.getInt64Values(j);
+ }
+ mPropertyBundle.putLongArray(property.getName(), values);
+ } else if (property.getDoubleValuesCount() > 0) {
+ double[] values = new double[property.getDoubleValuesCount()];
+ for (int j = 0; j < values.length; j++) {
+ values[j] = property.getDoubleValues(j);
+ }
+ mPropertyBundle.putDoubleArray(property.getName(), values);
+ } else if (property.getBooleanValuesCount() > 0) {
+ boolean[] values = new boolean[property.getBooleanValuesCount()];
+ for (int j = 0; j < values.length; j++) {
+ values[j] = property.getBooleanValues(j);
+ }
+ mPropertyBundle.putBooleanArray(property.getName(), values);
+ } else if (property.getBytesValuesCount() > 0) {
+ byte[][] values = new byte[property.getBytesValuesCount()][];
+ for (int j = 0; j < values.length; j++) {
+ values[j] = property.getBytesValues(j).toByteArray();
+ }
+ mPropertyBundle.putObject(name, values);
+ } else if (property.getDocumentValuesCount() > 0) {
+ Document[] values = new Document[property.getDocumentValuesCount()];
+ for (int j = 0; j < values.length; j++) {
+ values[j] = new Document(property.getDocumentValues(j));
+ }
+ mPropertyBundle.putObject(name, values);
+ } else {
+ throw new IllegalStateException("Unknown type of value: " + name);
+ }
+ }
+ }
+
/**
* Creates a new {@link Document.Builder}.
*
diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java
index e3f6b3d..15c3368 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java
@@ -26,6 +26,7 @@
import com.google.android.icing.proto.SchemaProto;
import com.google.android.icing.proto.SearchResultProto;
+import com.google.android.icing.proto.SearchSpecProto;
import com.google.android.icing.proto.StatusProto;
import com.google.android.icing.protobuf.InvalidProtocolBufferException;
@@ -186,28 +187,28 @@
*<p>Currently we support following features in the raw query format:
* <ul>
* <li>AND
- * AND joins (e.g. “match documents that have both the terms ‘dog’ and
+ * <p>AND joins (e.g. “match documents that have both the terms ‘dog’ and
* ‘cat’”).
* Example: hello world matches documents that have both ‘hello’ and ‘world’
* <li>OR
- * OR joins (e.g. “match documents that have either the term ‘dog’ or
+ * <p>OR joins (e.g. “match documents that have either the term ‘dog’ or
* ‘cat’”).
* Example: dog OR puppy
* <li>Exclusion
- * Exclude a term (e.g. “match documents that do
+ * <p>Exclude a term (e.g. “match documents that do
* not have the term ‘dog’”).
* Example: -dog excludes the term ‘dog’
* <li>Grouping terms
- * Allow for conceptual grouping of subqueries to enable hierarchical structures (e.g.
+ * <p>Allow for conceptual grouping of subqueries to enable hierarchical structures (e.g.
* “match documents that have either ‘dog’ or ‘puppy’, and either ‘cat’ or ‘kitten’”).
* Example: (dog puppy) (cat kitten) two one group containing two terms.
* <li>Property restricts
- * which properties of a document to specifically match terms in (e.g.
+ * <p> Specifies which properties of a document to specifically match terms in (e.g.
* “match documents where the ‘subject’ property contains ‘important’”).
* Example: subject:important matches documents with the term ‘important’ in the
* ‘subject’ property
* <li>Schema type restricts
- * This is similar to property restricts, but allows for restricts on top-level document
+ * <p>This is similar to property restricts, but allows for restricts on top-level document
* fields, such as schema_type. Clients should be able to limit their query to documents of
* a certain schema_type (e.g. “match documents that are of the ‘Email’ schema_type”).
* Example: { schema_type_filters: “Email”, “Video”,query: “dog” } will match documents
@@ -263,7 +264,11 @@
}, executor);
try {
- mService.query(queryExpression, searchSpec.getProto().toByteArray(), future);
+ SearchSpecProto searchSpecProto = searchSpec.getSearchSpecProto();
+ searchSpecProto = searchSpecProto.toBuilder().setQuery(queryExpression).build();
+ mService.query(searchSpecProto.toByteArray(),
+ searchSpec.getResultSpecProto().toByteArray(),
+ searchSpec.getScoringSpecProto().toByteArray(), future);
} catch (RemoteException e) {
future.completeExceptionally(e);
}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl b/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl
index 20c8af98..eef41ed 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl
+++ b/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl
@@ -47,12 +47,14 @@
void putDocuments(in List documentsBytes, in AndroidFuture<AppSearchBatchResult> callback);
/**
- * Searches a document based on a given query string.
+ * Searches a document based on a given specifications.
*
- * @param queryExpression Query String to search.
- * @param searchSpec Serialized SearchSpecProto.
+ * @param searchSpecBytes Serialized SearchSpecProto.
+ * @param resultSpecBytes Serialized SearchResultsProto.
+ * @param scoringSpecBytes Serialized ScoringSpecProto.
* @param callback {@link AndroidFuture}. Will be completed with a serialized
* {@link SearchResultsProto}, or completed exceptionally if query fails.
*/
- void query(in String queryExpression, in byte[] searchSpecBytes, in AndroidFuture callback);
+ void query(in byte[] searchSpecBytes, in byte[] resultSpecBytes,
+ in byte[] scoringSpecBytes, in AndroidFuture callback);
}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/MatchInfo.java b/apex/appsearch/framework/java/android/app/appsearch/MatchInfo.java
new file mode 100644
index 0000000..6aa91a3f
--- /dev/null
+++ b/apex/appsearch/framework/java/android/app/appsearch/MatchInfo.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2020 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.app.appsearch;
+
+import android.annotation.NonNull;
+import android.util.Range;
+
+import com.google.android.icing.proto.SnippetMatchProto;
+
+/**
+ * Snippet: It refers to a substring of text from the content of document that is returned as a
+ * part of search result.
+ * This class represents a match objects for any Snippets that might be present in
+ * {@link SearchResults} from query. Using this class user can get the full text, exact matches and
+ * Snippets of document content for a given match.
+ *
+ * <p>Class Example 1:
+ * A document contains following text in property subject:
+ * <p>A commonly used fake word is foo. Another nonsense word that’s used a lot is bar.
+ *
+ * <p>If the queryExpression is "foo".
+ *
+ * <p>{@link MatchInfo#getPropertyPath()} returns "subject"
+ * <p>{@link MatchInfo#getFullText()} returns "A commonly used fake word is foo. Another nonsense
+ * word that’s used a lot is bar."
+ * <p>{@link MatchInfo#getExactMatchPosition()} returns [29, 32]
+ * <p>{@link MatchInfo#getExactMatch()} returns "foo"
+ * <p>{@link MatchInfo#getSnippetPosition()} returns [29, 41]
+ * <p>{@link MatchInfo#getSnippet()} returns "is foo. Another"
+ * <p>
+ * <p>Class Example 2:
+ * A document contains a property name sender which contains 2 property names name and email, so
+ * we will have 2 property paths: {@code sender.name} and {@code sender.email}.
+ * <p> Let {@code sender.name = "Test Name Jr."} and {@code sender.email = "TestNameJr@gmail.com"}
+ *
+ * <p>If the queryExpression is "Test". We will have 2 matches.
+ *
+ * <p> Match-1
+ * <p>{@link MatchInfo#getPropertyPath()} returns "sender.name"
+ * <p>{@link MatchInfo#getFullText()} returns "Test Name Jr."
+ * <p>{@link MatchInfo#getExactMatchPosition()} returns [0, 4]
+ * <p>{@link MatchInfo#getExactMatch()} returns "Test"
+ * <p>{@link MatchInfo#getSnippetPosition()} returns [0, 9]
+ * <p>{@link MatchInfo#getSnippet()} returns "Test Name Jr."
+ * <p> Match-2
+ * <p>{@link MatchInfo#getPropertyPath()} returns "sender.email"
+ * <p>{@link MatchInfo#getFullText()} returns "TestNameJr@gmail.com"
+ * <p>{@link MatchInfo#getExactMatchPosition()} returns [0, 20]
+ * <p>{@link MatchInfo#getExactMatch()} returns "TestNameJr@gmail.com"
+ * <p>{@link MatchInfo#getSnippetPosition()} returns [0, 20]
+ * <p>{@link MatchInfo#getSnippet()} returns "TestNameJr@gmail.com"
+ * @hide
+ */
+// TODO(sidchhabra): Capture real snippet after integration with icingLib.
+public final class MatchInfo {
+
+ private final String mPropertyPath;
+ private final SnippetMatchProto mSnippetMatch;
+ private final AppSearch.Document mDocument;
+ /**
+ * List of content with same property path in a document when there are multiple matches in
+ * repeated sections.
+ */
+ private final String[] mValues;
+
+ /** @hide */
+ public MatchInfo(@NonNull String propertyPath, @NonNull SnippetMatchProto snippetMatch,
+ @NonNull AppSearch.Document document) {
+ mPropertyPath = propertyPath;
+ mSnippetMatch = snippetMatch;
+ mDocument = document;
+ // In IcingLib snippeting is available for only 3 data types i.e String, double and long,
+ // so we need to check which of these three are requested.
+ // TODO (sidchhabra): getPropertyStringArray takes property name, handle for property path.
+ String[] values = mDocument.getPropertyStringArray(propertyPath);
+ if (values == null) {
+ values = doubleToString(mDocument.getPropertyDoubleArray(propertyPath));
+ }
+ if (values == null) {
+ values = longToString(mDocument.getPropertyLongArray(propertyPath));
+ }
+ if (values == null) {
+ throw new IllegalStateException("No content found for requested property path!");
+ }
+ mValues = values;
+ }
+
+ /**
+ * Gets the property path corresponding to the given entry.
+ * <p>Property Path: '.' - delimited sequence of property names indicating which property in
+ * the Document these snippets correspond to.
+ * <p>Example properties: 'body', 'sender.name', 'sender.emailaddress', etc.
+ * For class example 1 this returns "subject"
+ */
+ @NonNull
+ public String getPropertyPath() {
+ return mPropertyPath;
+ }
+
+ /**
+ * Gets the full text corresponding to the given entry.
+ * <p>For class example this returns "A commonly used fake word is foo. Another nonsense word
+ * that’s used a lot is bar."
+ */
+ @NonNull
+ public String getFullText() {
+ return mValues[mSnippetMatch.getValuesIndex()];
+ }
+
+ /**
+ * Gets the exact match range corresponding to the given entry.
+ * <p>For class example 1 this returns [29, 32]
+ */
+ @NonNull
+ public Range getExactMatchPosition() {
+ return new Range(mSnippetMatch.getExactMatchPosition(),
+ mSnippetMatch.getExactMatchPosition() + mSnippetMatch.getExactMatchBytes());
+ }
+
+ /**
+ * Gets the exact match corresponding to the given entry.
+ * <p>For class example 1 this returns "foo"
+ */
+ @NonNull
+ public CharSequence getExactMatch() {
+ return getSubstring(getExactMatchPosition());
+ }
+
+ /**
+ * Gets the snippet range corresponding to the given entry.
+ * <p>For class example 1 this returns [29, 41]
+ */
+ @NonNull
+ public Range getSnippetPosition() {
+ return new Range(mSnippetMatch.getWindowPosition(),
+ mSnippetMatch.getWindowPosition() + mSnippetMatch.getWindowBytes());
+ }
+
+ /**
+ * Gets the snippet corresponding to the given entry.
+ * <p>Snippet - Provides a subset of the content to display. The
+ * length of this content can be changed {@link SearchSpec.Builder#setMaxSnippetSize(int)}.
+ * Windowing is centered around the middle of the matched token with content on either side
+ * clipped to token boundaries.
+ * <p>For class example 1 this returns "foo. Another"
+ */
+ @NonNull
+ public CharSequence getSnippet() {
+ return getSubstring(getSnippetPosition());
+ }
+
+ private CharSequence getSubstring(Range range) {
+ return getFullText()
+ .substring((int) range.getLower(), (int) range.getUpper());
+ }
+
+ /** Utility method to convert double[] to String[] */
+ private String[] doubleToString(double[] values) {
+ //TODO(sidchhabra): Implement the method.
+ return null;
+ }
+
+ /** Utility method to convert long[] to String[] */
+ private String[] longToString(long[] values) {
+ //TODO(sidchhabra): Implement the method.
+ return null;
+ }
+}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
index d763103..f48ebde 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
@@ -17,27 +17,51 @@
package android.app.appsearch;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import com.google.android.icing.proto.SearchResultProto;
+import com.google.android.icing.proto.SnippetMatchProto;
+import com.google.android.icing.proto.SnippetProto;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.NoSuchElementException;
/**
* SearchResults are a list of results that are returned from a query. Each result from this
* list contains a document and may contain other fields like snippets based on request.
+ * This iterator class is not thread safe.
* @hide
*/
-public final class SearchResults {
+public final class SearchResults implements Iterator<SearchResults.Result> {
private final SearchResultProto mSearchResultProto;
+ private int mNextIdx;
/** @hide */
public SearchResults(SearchResultProto searchResultProto) {
mSearchResultProto = searchResultProto;
}
+ @Override
+ public boolean hasNext() {
+ return mNextIdx < mSearchResultProto.getResultsCount();
+ }
+
+ @NonNull
+ @Override
+ public Result next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ Result result = new Result(mSearchResultProto.getResults(mNextIdx));
+ mNextIdx++;
+ return result;
+ }
+
+
+
/**
* This class represents the result obtained from the query. It will contain the document which
* which matched the specified query string and specifications.
@@ -46,6 +70,9 @@
public static final class Result {
private final SearchResultProto.ResultProto mResultProto;
+ @Nullable
+ private AppSearch.Document mDocument;
+
private Result(SearchResultProto.ResultProto resultProto) {
mResultProto = resultProto;
}
@@ -55,35 +82,47 @@
* @return Document object which matched the query.
* @hide
*/
- // TODO(sidchhabra): Switch to Document constructor that takes proto.
@NonNull
public AppSearch.Document getDocument() {
- return AppSearch.Document.newBuilder(mResultProto.getDocument().getUri(),
- mResultProto.getDocument().getSchema())
- .setCreationTimestampMillis(mResultProto.getDocument().getCreationTimestampMs())
- .setScore(mResultProto.getDocument().getScore())
- .build();
+ if (mDocument == null) {
+ mDocument = new AppSearch.Document(mResultProto.getDocument());
+ }
+ return mDocument;
}
- // TODO(sidchhabra): Add Getter for ResultReader for Snippet.
+ /**
+ * Contains a list of Snippets that matched the request. Only populated when requested in
+ * {@link SearchSpec.Builder#setMaxSnippetSize(int)}.
+ * @return List of matches based on {@link SearchSpec}, if snippeting is disabled and this
+ * method is called it will return {@code null}. Users can also restrict snippet population
+ * using {@link SearchSpec.Builder#setNumToSnippet} and
+ * {@link SearchSpec.Builder#setNumMatchesPerProperty}, for all results after that value
+ * this method will return {@code null}.
+ * @hide
+ */
+ // TODO(sidchhabra): Replace Document with proper constructor.
+ @Nullable
+ public List<MatchInfo> getMatchInfo() {
+ if (!mResultProto.hasSnippet()) {
+ return null;
+ }
+ AppSearch.Document document = getDocument();
+ List<MatchInfo> matchList = new ArrayList<>();
+ for (Iterator entryProtoIterator = mResultProto.getSnippet()
+ .getEntriesList().iterator(); entryProtoIterator.hasNext(); ) {
+ SnippetProto.EntryProto entry = (SnippetProto.EntryProto) entryProtoIterator.next();
+ for (Iterator snippetMatchProtoIterator = entry.getSnippetMatchesList().iterator();
+ snippetMatchProtoIterator.hasNext(); ) {
+ matchList.add(new MatchInfo(entry.getPropertyName(),
+ (SnippetMatchProto) snippetMatchProtoIterator.next(), document));
+ }
+ }
+ return matchList;
+ }
}
@Override
public String toString() {
return mSearchResultProto.toString();
}
-
- /**
- * Returns a {@link Result} iterator. Returns Empty Iterator if there are no matching results.
- * @hide
- */
- @NonNull
- public Iterator<Result> getResults() {
- List<Result> results = new ArrayList<>();
- // TODO(sidchhabra): Pass results using a RemoteStream.
- for (SearchResultProto.ResultProto resultProto : mSearchResultProto.getResultsList()) {
- results.add(new Result(resultProto));
- }
- return results.iterator();
- }
}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/SearchSpec.java b/apex/appsearch/framework/java/android/app/appsearch/SearchSpec.java
index 5df7108..c276ae1 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/SearchSpec.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/SearchSpec.java
@@ -19,25 +19,32 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
+import com.google.android.icing.proto.ResultSpecProto;
+import com.google.android.icing.proto.ScoringSpecProto;
import com.google.android.icing.proto.SearchSpecProto;
import com.google.android.icing.proto.TermMatchType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+
/**
* This class represents the specification logic for AppSearch. It can be used to set the type of
* search, like prefix or exact only or apply filters to search for a specific schema type only etc.
* @hide
- *
*/
// TODO(sidchhabra) : AddResultSpec fields for Snippets etc.
public final class SearchSpec {
private final SearchSpecProto mSearchSpecProto;
+ private final ResultSpecProto mResultSpecProto;
+ private final ScoringSpecProto mScoringSpecProto;
- private SearchSpec(SearchSpecProto searchSpecProto) {
+ private SearchSpec(@NonNull SearchSpecProto searchSpecProto,
+ @NonNull ResultSpecProto resultSpecProto, @NonNull ScoringSpecProto scoringSpecProto) {
mSearchSpecProto = searchSpecProto;
+ mResultSpecProto = resultSpecProto;
+ mScoringSpecProto = scoringSpecProto;
}
/** Creates a new {@link SearchSpec.Builder}. */
@@ -48,10 +55,22 @@
/** @hide */
@NonNull
- SearchSpecProto getProto() {
+ SearchSpecProto getSearchSpecProto() {
return mSearchSpecProto;
}
+ /** @hide */
+ @NonNull
+ ResultSpecProto getResultSpecProto() {
+ return mResultSpecProto;
+ }
+
+ /** @hide */
+ @NonNull
+ ScoringSpecProto getScoringSpecProto() {
+ return mScoringSpecProto;
+ }
+
/** Term Match Type for the query. */
// NOTE: The integer values of these constants must match the proto enum constants in
// {@link com.google.android.icing.proto.SearchSpecProto.termMatchType}
@@ -62,54 +81,167 @@
@Retention(RetentionPolicy.SOURCE)
public @interface TermMatchTypeCode {}
+ /**
+ * Query terms will only match exact tokens in the index.
+ * <p>Ex. A query term "foo" will only match indexed token "foo", and not "foot" or "football".
+ */
public static final int TERM_MATCH_TYPE_EXACT_ONLY = 1;
+ /**
+ * Query terms will match indexed tokens when the query term is a prefix of the token.
+ * <p>Ex. A query term "foo" will match indexed tokens like "foo", "foot", and "football".
+ */
public static final int TERM_MATCH_TYPE_PREFIX = 2;
+ /** Ranking Strategy for query result.*/
+ // NOTE: The integer values of these constants must match the proto enum constants in
+ // {@link ScoringSpecProto.RankingStrategy.Code }
+ @IntDef(prefix = {"RANKING_STRATEGY_"}, value = {
+ RANKING_STRATEGY_NONE,
+ RANKING_STRATEGY_DOCUMENT_SCORE,
+ RANKING_STRATEGY_CREATION_TIMESTAMP
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface RankingStrategyCode {}
+
+ /** No Ranking, results are returned in arbitrary order.*/
+ public static final int RANKING_STRATEGY_NONE = 0;
+ /** Ranked by app-provided document scores. */
+ public static final int RANKING_STRATEGY_DOCUMENT_SCORE = 1;
+ /** Ranked by document creation timestamps. */
+ public static final int RANKING_STRATEGY_CREATION_TIMESTAMP = 2;
+
+ /** Order for query result.*/
+ // NOTE: The integer values of these constants must match the proto enum constants in
+ // {@link ScoringSpecProto.Order.Code }
+ @IntDef(prefix = {"ORDER_"}, value = {
+ ORDER_DESCENDING,
+ ORDER_ASCENDING
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface OrderCode {}
+
+ /** Search results will be returned in a descending order. */
+ public static final int ORDER_DESCENDING = 0;
+ /** Search results will be returned in an ascending order. */
+ public static final int ORDER_ASCENDING = 1;
+
/** Builder for {@link SearchSpec objects}. */
public static final class Builder {
- private final SearchSpecProto.Builder mBuilder = SearchSpecProto.newBuilder();
+ private final SearchSpecProto.Builder mSearchSpecBuilder = SearchSpecProto.newBuilder();
+ private final ResultSpecProto.Builder mResultSpecBuilder = ResultSpecProto.newBuilder();
+ private final ScoringSpecProto.Builder mScoringSpecBuilder = ScoringSpecProto.newBuilder();
+ private final ResultSpecProto.SnippetSpecProto.Builder mSnippetSpecBuilder =
+ ResultSpecProto.SnippetSpecProto.newBuilder();
- private Builder(){}
+ private Builder() {
+ }
/**
* Indicates how the query terms should match {@link TermMatchTypeCode} in the index.
- *
- * TermMatchType.Code=EXACT_ONLY
- * Query terms will only match exact tokens in the index.
- * Ex. A query term "foo" will only match indexed token "foo", and not "foot"
- * or "football"
- *
- * TermMatchType.Code=PREFIX
- * Query terms will match indexed tokens when the query term is a prefix of
- * the token.
- * Ex. A query term "foo" will match indexed tokens like "foo", "foot", and
- * "football".
*/
@NonNull
public Builder setTermMatchType(@TermMatchTypeCode int termMatchTypeCode) {
TermMatchType.Code termMatchTypeCodeProto =
TermMatchType.Code.forNumber(termMatchTypeCode);
if (termMatchTypeCodeProto == null) {
- throw new IllegalArgumentException("Invalid term match type: " + termMatchTypeCode);
+ throw new IllegalArgumentException("Invalid term match type: "
+ + termMatchTypeCode);
}
- mBuilder.setTermMatchType(termMatchTypeCodeProto);
+ mSearchSpecBuilder.setTermMatchType(termMatchTypeCodeProto);
return this;
}
/**
- * Adds a Schema type filter to {@link SearchSpec} Entry.
- * Only search for documents that have the specified schema types.
- * If unset, the query will search over all schema types.
+ * Adds a Schema type filter to {@link SearchSpec} Entry. Only search for documents that
+ * have the specified schema types.
+ * <p>If unset, the query will search over all schema types.
*/
@NonNull
public Builder setSchemaTypes(@NonNull String... schemaTypes) {
for (String schemaType : schemaTypes) {
- mBuilder.addSchemaTypeFilters(schemaType);
+ mSearchSpecBuilder.addSchemaTypeFilters(schemaType);
}
return this;
}
+ /** Sets the maximum number of results to retrieve from the query */
+ @NonNull
+ public SearchSpec.Builder setNumToRetrieve(int numToRetrieve) {
+ mResultSpecBuilder.setNumToRetrieve(numToRetrieve);
+ return this;
+ }
+
+ /** Sets ranking strategy for AppSearch results.*/
+ @NonNull
+ public Builder setRankingStrategy(@RankingStrategyCode int rankingStrategy) {
+ ScoringSpecProto.RankingStrategy.Code rankingStrategyCodeProto =
+ ScoringSpecProto.RankingStrategy.Code.forNumber(rankingStrategy);
+ if (rankingStrategyCodeProto == null) {
+ throw new IllegalArgumentException("Invalid result ranking strategy: "
+ + rankingStrategyCodeProto);
+ }
+ mScoringSpecBuilder.setRankBy(rankingStrategyCodeProto);
+ return this;
+ }
+
+ /**
+ * Indicates the order of returned search results, the default is DESC, meaning that results
+ * with higher scores come first.
+ * <p>This order field will be ignored if RankingStrategy = {@code RANKING_STRATEGY_NONE}.
+ */
+ @NonNull
+ public Builder setOrder(@OrderCode int order) {
+ ScoringSpecProto.Order.Code orderCodeProto =
+ ScoringSpecProto.Order.Code.forNumber(order);
+ if (orderCodeProto == null) {
+ throw new IllegalArgumentException("Invalid result ranking order: "
+ + orderCodeProto);
+ }
+ mScoringSpecBuilder.setOrderBy(orderCodeProto);
+ return this;
+ }
+
+ /**
+ * Only the first {@code numToSnippet} documents based on the ranking strategy
+ * will have snippet information provided.
+ * <p>If set to 0 (default), snippeting is disabled and
+ * {@link SearchResults.Result#getMatchInfo} will return {@code null} for that result.
+ */
+ @NonNull
+ public SearchSpec.Builder setNumToSnippet(int numToSnippet) {
+ mSnippetSpecBuilder.setNumToSnippet(numToSnippet);
+ return this;
+ }
+
+ /**
+ * Only the first {@code numMatchesPerProperty} matches for a every property of
+ * {@link AppSearchDocument} will contain snippet information.
+ * <p>If set to 0, snippeting is disabled and {@link SearchResults.Result#getMatchInfo}
+ * will return {@code null} for that result.
+ */
+ @NonNull
+ public SearchSpec.Builder setNumMatchesPerProperty(int numMatchesPerProperty) {
+ mSnippetSpecBuilder.setNumMatchesPerProperty(numMatchesPerProperty);
+ return this;
+ }
+
+ /**
+ * Sets {@code maxSnippetSize}, the maximum snippet size. Snippet windows start at
+ * {@code maxSnippetSize/2} bytes before the middle of the matching token and end at
+ * {@code maxSnippetSize/2} bytes after the middle of the matching token. It respects
+ * token boundaries, therefore the returned window may be smaller than requested.
+ * <p> Setting {@code maxSnippetSize} to 0 will disable windowing and an empty string will
+ * be returned. If matches enabled is also set to false, then snippeting is disabled.
+ * <p>Ex. {@code maxSnippetSize} = 16. "foo bar baz bat rat" with a query of "baz" will
+ * return a window of "bar baz bat" which is only 11 bytes long.
+ */
+ @NonNull
+ public SearchSpec.Builder setMaxSnippetSize(int maxSnippetSize) {
+ mSnippetSpecBuilder.setMaxWindowBytes(maxSnippetSize);
+ return this;
+ }
+
/**
* Constructs a new {@link SearchSpec} from the contents of this builder.
*
@@ -117,11 +249,12 @@
*/
@NonNull
public SearchSpec build() {
- if (mBuilder.getTermMatchType() == TermMatchType.Code.UNKNOWN) {
+ if (mSearchSpecBuilder.getTermMatchType() == TermMatchType.Code.UNKNOWN) {
throw new IllegalSearchSpecException("Missing termMatchType field.");
}
- return new SearchSpec(mBuilder.build());
+ mResultSpecBuilder.setSnippetSpec(mSnippetSpecBuilder);
+ return new SearchSpec(mSearchSpecBuilder.build(), mResultSpecBuilder.build(),
+ mScoringSpecBuilder.build());
}
}
-
}
diff --git a/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java b/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java
index d2d9cf9..6293ee7 100644
--- a/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java
+++ b/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java
@@ -106,10 +106,11 @@
// TODO(sidchhabra):Init FakeIcing properly.
// TODO(sidchhabra): Do this in a threadpool.
@Override
- public void query(@NonNull String queryExpression, @NonNull byte[] searchSpec,
- AndroidFuture callback) {
- Preconditions.checkNotNull(queryExpression);
+ public void query(@NonNull byte[] searchSpec, @NonNull byte[] resultSpec,
+ @NonNull byte[] scoringSpec, AndroidFuture callback) {
Preconditions.checkNotNull(searchSpec);
+ Preconditions.checkNotNull(resultSpec);
+ Preconditions.checkNotNull(scoringSpec);
SearchSpecProto searchSpecProto = null;
try {
searchSpecProto = SearchSpecProto.parseFrom(searchSpec);
@@ -117,7 +118,7 @@
throw new RuntimeException(e);
}
SearchResultProto searchResults =
- mFakeIcing.query(queryExpression);
+ mFakeIcing.query(searchSpecProto.getQuery());
callback.complete(searchResults.toByteArray());
}
}
diff --git a/apex/permission/service/java/com/android/permission/persistence/RuntimePermissionsPersistenceImpl.java b/apex/permission/service/java/com/android/permission/persistence/RuntimePermissionsPersistenceImpl.java
index 51b911a..1dbad45 100644
--- a/apex/permission/service/java/com/android/permission/persistence/RuntimePermissionsPersistenceImpl.java
+++ b/apex/permission/service/java/com/android/permission/persistence/RuntimePermissionsPersistenceImpl.java
@@ -18,6 +18,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.content.ApexContext;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.AtomicFile;
@@ -48,6 +49,8 @@
private static final String LOG_TAG = RuntimePermissionsPersistenceImpl.class.getSimpleName();
+ private static final String APEX_MODULE_NAME = "com.android.permission";
+
private static final String RUNTIME_PERMISSIONS_FILE_NAME = "runtime-permissions.xml";
private static final String TAG_PACKAGE = "package";
@@ -253,9 +256,8 @@
@NonNull
private static File getFile(@NonNull UserHandle user) {
- // TODO: Use an API for this.
- File dataDirectory = new File("/data/misc_de/" + user.getIdentifier()
- + "/apexdata/com.android.permission");
+ ApexContext apexContext = ApexContext.getApexContext(APEX_MODULE_NAME);
+ File dataDirectory = apexContext.getDeviceProtectedDataDirForUser(user);
return new File(dataDirectory, RUNTIME_PERMISSIONS_FILE_NAME);
}
}
diff --git a/apex/permission/service/java/com/android/role/persistence/RolesPersistenceImpl.java b/apex/permission/service/java/com/android/role/persistence/RolesPersistenceImpl.java
index 5061742..06fad77 100644
--- a/apex/permission/service/java/com/android/role/persistence/RolesPersistenceImpl.java
+++ b/apex/permission/service/java/com/android/role/persistence/RolesPersistenceImpl.java
@@ -18,6 +18,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.content.ApexContext;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -50,6 +51,8 @@
private static final String LOG_TAG = RolesPersistenceImpl.class.getSimpleName();
+ private static final String APEX_MODULE_NAME = "com.android.permission";
+
private static final String ROLES_FILE_NAME = "roles.xml";
private static final String TAG_ROLES = "roles";
@@ -209,9 +212,8 @@
@NonNull
private static File getFile(@NonNull UserHandle user) {
- // TODO: Use an API for this.
- File dataDirectory = new File("/data/misc_de/" + user.getIdentifier()
- + "/apexdata/com.android.permission");
+ ApexContext apexContext = ApexContext.getApexContext(APEX_MODULE_NAME);
+ File dataDirectory = apexContext.getDeviceProtectedDataDirForUser(user);
return new File(dataDirectory, ROLES_FILE_NAME);
}
}
diff --git a/api/current.txt b/api/current.txt
index 7dea56e..69f22ca 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -10101,6 +10101,7 @@
field public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
field public static final String CLIPBOARD_SERVICE = "clipboard";
field public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
+ field public static final String CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics";
field public static final String CONNECTIVITY_SERVICE = "connectivity";
field public static final String CONSUMER_IR_SERVICE = "consumer_ir";
field public static final int CONTEXT_IGNORE_SECURITY = 2; // 0x2
@@ -12077,6 +12078,7 @@
field public static final String FEATURE_VR_HEADTRACKING = "android.hardware.vr.headtracking";
field @Deprecated public static final String FEATURE_VR_MODE = "android.software.vr.mode";
field public static final String FEATURE_VR_MODE_HIGH_PERFORMANCE = "android.hardware.vr.high_performance";
+ field public static final String FEATURE_VULKAN_DEQP_LEVEL = "android.software.vulkan.deqp.level";
field public static final String FEATURE_VULKAN_HARDWARE_COMPUTE = "android.hardware.vulkan.compute";
field public static final String FEATURE_VULKAN_HARDWARE_LEVEL = "android.hardware.vulkan.level";
field public static final String FEATURE_VULKAN_HARDWARE_VERSION = "android.hardware.vulkan.version";
@@ -29551,8 +29553,6 @@
public class ConnectivityDiagnosticsManager {
method public void registerConnectivityDiagnosticsCallback(@NonNull android.net.NetworkRequest, @NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback);
method public void unregisterConnectivityDiagnosticsCallback(@NonNull android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback);
- field public static final int DETECTION_METHOD_DNS_EVENTS = 1; // 0x1
- field public static final int DETECTION_METHOD_TCP_METRICS = 2; // 0x2
}
public abstract static class ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback {
@@ -29562,21 +29562,29 @@
method public void onNetworkConnectivityReported(@NonNull android.net.Network, boolean);
}
- public static class ConnectivityDiagnosticsManager.ConnectivityReport {
+ public static final class ConnectivityDiagnosticsManager.ConnectivityReport implements android.os.Parcelable {
ctor public ConnectivityDiagnosticsManager.ConnectivityReport(@NonNull android.net.Network, long, @NonNull android.net.LinkProperties, @NonNull android.net.NetworkCapabilities, @NonNull android.os.PersistableBundle);
- field @NonNull public final android.os.PersistableBundle additionalInfo;
- field @NonNull public final android.net.LinkProperties linkProperties;
- field @NonNull public final android.net.Network network;
- field @NonNull public final android.net.NetworkCapabilities networkCapabilities;
- field public final long reportTimestamp;
+ method public int describeContents();
+ method @NonNull public android.os.PersistableBundle getAdditionalInfo();
+ method @NonNull public android.net.LinkProperties getLinkProperties();
+ method @NonNull public android.net.Network getNetwork();
+ method @NonNull public android.net.NetworkCapabilities getNetworkCapabilities();
+ method public long getReportTimestamp();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.net.ConnectivityDiagnosticsManager.ConnectivityReport> CREATOR;
}
- public static class ConnectivityDiagnosticsManager.DataStallReport {
+ public static final class ConnectivityDiagnosticsManager.DataStallReport implements android.os.Parcelable {
ctor public ConnectivityDiagnosticsManager.DataStallReport(@NonNull android.net.Network, long, int, @NonNull android.os.PersistableBundle);
- field public final int detectionMethod;
- field @NonNull public final android.net.Network network;
- field public final long reportTimestamp;
- field @NonNull public final android.os.PersistableBundle stallDetails;
+ method public int describeContents();
+ method public int getDetectionMethod();
+ method @NonNull public android.net.Network getNetwork();
+ method public long getReportTimestamp();
+ method @NonNull public android.os.PersistableBundle getStallDetails();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.net.ConnectivityDiagnosticsManager.DataStallReport> CREATOR;
+ field public static final int DETECTION_METHOD_DNS_EVENTS = 1; // 0x1
+ field public static final int DETECTION_METHOD_TCP_METRICS = 2; // 0x2
}
public class ConnectivityManager {
@@ -43528,7 +43536,7 @@
field public static final int STATE_HARDWARE_UNAVAILABLE = -2; // 0xfffffffe
field public static final int STATE_KEYPHRASE_ENROLLED = 2; // 0x2
field public static final int STATE_KEYPHRASE_UNENROLLED = 1; // 0x1
- field public static final int STATE_KEYPHRASE_UNSUPPORTED = -1; // 0xffffffff
+ field @Deprecated public static final int STATE_KEYPHRASE_UNSUPPORTED = -1; // 0xffffffff
}
public abstract static class AlwaysOnHotwordDetector.Callback {
@@ -46130,6 +46138,7 @@
field public static final String KEY_SHOW_CALL_BLOCKING_DISABLED_NOTIFICATION_ALWAYS_BOOL = "show_call_blocking_disabled_notification_always_bool";
field public static final String KEY_SHOW_CARRIER_DATA_ICON_PATTERN_STRING = "show_carrier_data_icon_pattern_string";
field public static final String KEY_SHOW_CDMA_CHOICES_BOOL = "show_cdma_choices_bool";
+ field public static final String KEY_SHOW_FORWARDED_NUMBER_BOOL = "show_forwarded_number_bool";
field public static final String KEY_SHOW_ICCID_IN_SIM_STATUS_BOOL = "show_iccid_in_sim_status_bool";
field public static final String KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL = "show_ims_registration_status_bool";
field public static final String KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL = "show_onscreen_dial_button_bool";
@@ -46176,6 +46185,15 @@
field public static final String KEY_WORLD_PHONE_BOOL = "world_phone_bool";
}
+ public static final class CarrierConfigManager.Apn {
+ field public static final String KEY_PREFIX = "apn.";
+ field public static final String KEY_SETTINGS_DEFAULT_PROTOCOL_STRING = "apn.settings_default_protocol_string";
+ field public static final String KEY_SETTINGS_DEFAULT_ROAMING_PROTOCOL_STRING = "apn.settings_default_roaming_protocol_string";
+ field public static final String PROTOCOL_IPV4 = "IP";
+ field public static final String PROTOCOL_IPV4V6 = "IPV4V6";
+ field public static final String PROTOCOL_IPV6 = "IPV6";
+ }
+
public static final class CarrierConfigManager.Gps {
field public static final String KEY_PERSIST_LPP_MODE_BOOL = "gps.persist_lpp_mode_bool";
field public static final String KEY_PREFIX = "gps.";
@@ -46275,6 +46293,7 @@
public final class CellIdentityLte extends android.telephony.CellIdentity {
method @NonNull public java.util.List<java.lang.String> getAdditionalPlmns();
+ method @NonNull public java.util.List<java.lang.Integer> getBands();
method public int getBandwidth();
method public int getCi();
method @Nullable public android.telephony.ClosedSubscriberGroupInfo getClosedSubscriberGroupInfo();
@@ -46292,7 +46311,7 @@
public final class CellIdentityNr extends android.telephony.CellIdentity {
method @NonNull public java.util.List<java.lang.String> getAdditionalPlmns();
- method public int getBand();
+ method @NonNull public java.util.List<java.lang.Integer> getBands();
method @Nullable public String getMccString();
method @Nullable public String getMncString();
method public long getNci();
@@ -47213,6 +47232,7 @@
method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public String getImei();
method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public String getImei(int);
method @RequiresPermission(anyOf={android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.READ_SMS, android.Manifest.permission.READ_PHONE_NUMBERS}) public String getLine1Number();
+ method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) public String getManualNetworkSelectionPlmn();
method @Nullable public String getManufacturerCode();
method @Nullable public String getManufacturerCode(int);
method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public String getMeid();
@@ -47268,6 +47288,7 @@
method @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_NETWORK_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isDataRoamingEnabled();
method public boolean isEmergencyNumber(@NonNull String);
method public boolean isHearingAidCompatibilitySupported();
+ method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRECISE_PHONE_STATE, "android.permission.READ_PRIVILEGED_PHONE_STATE"}) public boolean isManualNetworkSelectionAllowed();
method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int isMultiSimSupported();
method public boolean isNetworkRoaming();
method public boolean isRttSupported();
@@ -47676,10 +47697,42 @@
field public static final int EMBEDDED_SUBSCRIPTION_RESULT_ERROR = 2; // 0x2
field public static final int EMBEDDED_SUBSCRIPTION_RESULT_OK = 0; // 0x0
field public static final int EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR = 1; // 0x1
+ field public static final int ERROR_ADDRESS_MISSING = 10011; // 0x271b
+ field public static final int ERROR_CARRIER_LOCKED = 10000; // 0x2710
+ field public static final int ERROR_CERTIFICATE_ERROR = 10012; // 0x271c
+ field public static final int ERROR_CONNECTION_ERROR = 10014; // 0x271e
+ field public static final int ERROR_DISALLOWED_BY_PPR = 10010; // 0x271a
+ field public static final int ERROR_EUICC_GSMA_INSTALL_ERROR = 10009; // 0x2719
+ field public static final int ERROR_EUICC_INSUFFICIENT_MEMORY = 10004; // 0x2714
+ field public static final int ERROR_EUICC_MISSING = 10006; // 0x2716
+ field public static final int ERROR_INCOMPATIBLE_CARRIER = 10003; // 0x2713
+ field public static final int ERROR_INVALID_ACTIVATION_CODE = 10001; // 0x2711
+ field public static final int ERROR_INVALID_CONFIRMATION_CODE = 10002; // 0x2712
+ field public static final int ERROR_INVALID_RESPONSE = 10015; // 0x271f
+ field public static final int ERROR_NO_PROFILES_AVAILABLE = 10013; // 0x271d
+ field public static final int ERROR_OPERATION_BUSY = 10016; // 0x2720
+ field public static final int ERROR_SIM_MISSING = 10008; // 0x2718
+ field public static final int ERROR_TIME_OUT = 10005; // 0x2715
+ field public static final int ERROR_UNSUPPORTED_VERSION = 10007; // 0x2717
field public static final String EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE = "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_DETAILED_CODE";
field public static final String EXTRA_EMBEDDED_SUBSCRIPTION_DOWNLOADABLE_SUBSCRIPTION = "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_DOWNLOADABLE_SUBSCRIPTION";
+ field public static final String EXTRA_EMBEDDED_SUBSCRIPTION_ERROR_CODE = "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_ERROR_CODE";
+ field public static final String EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE = "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_OPERATION_CODE";
+ field public static final String EXTRA_EMBEDDED_SUBSCRIPTION_SMDX_REASON_CODE = "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_SMDX_REASON_CODE";
+ field public static final String EXTRA_EMBEDDED_SUBSCRIPTION_SMDX_SUBJECT_CODE = "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_SMDX_SUBJECT_CODE";
field public static final String EXTRA_USE_QR_SCANNER = "android.telephony.euicc.extra.USE_QR_SCANNER";
field public static final String META_DATA_CARRIER_ICON = "android.telephony.euicc.carriericon";
+ field public static final int OPERATION_APDU = 8; // 0x8
+ field public static final int OPERATION_DOWNLOAD = 5; // 0x5
+ field public static final int OPERATION_EUICC_CARD = 3; // 0x3
+ field public static final int OPERATION_EUICC_GSMA = 7; // 0x7
+ field public static final int OPERATION_HTTP = 11; // 0xb
+ field public static final int OPERATION_METADATA = 6; // 0x6
+ field public static final int OPERATION_SIM_SLOT = 2; // 0x2
+ field public static final int OPERATION_SMDX = 9; // 0x9
+ field public static final int OPERATION_SMDX_SUBJECT_REASON_CODE = 10; // 0xa
+ field public static final int OPERATION_SWITCH = 4; // 0x4
+ field public static final int OPERATION_SYSTEM = 1; // 0x1
}
}
@@ -52602,6 +52655,20 @@
field @NonNull public static final android.os.Parcelable.Creator<android.view.SurfaceControl.Transaction> CREATOR;
}
+ public class SurfaceControlViewHost {
+ ctor public SurfaceControlViewHost(@NonNull android.content.Context, @NonNull android.view.Display, @Nullable android.os.IBinder);
+ method public void addView(@NonNull android.view.View, int, int);
+ method @Nullable public android.view.SurfaceControlViewHost.SurfacePackage getSurfacePackage();
+ method public void relayout(int, int);
+ method public void release();
+ }
+
+ public static final class SurfaceControlViewHost.SurfacePackage implements android.os.Parcelable {
+ method public int describeContents();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.view.SurfaceControlViewHost.SurfacePackage> CREATOR;
+ }
+
public interface SurfaceHolder {
method public void addCallback(android.view.SurfaceHolder.Callback);
method public android.view.Surface getSurface();
@@ -52646,7 +52713,9 @@
ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int, int);
method public boolean gatherTransparentRegion(android.graphics.Region);
method public android.view.SurfaceHolder getHolder();
+ method @Nullable public android.os.IBinder getHostToken();
method public android.view.SurfaceControl getSurfaceControl();
+ method public void setChildSurfacePackage(@NonNull android.view.SurfaceControlViewHost.SurfacePackage);
method public void setSecure(boolean);
method public void setZOrderMediaOverlay(boolean);
method public void setZOrderOnTop(boolean);
@@ -55793,7 +55862,12 @@
ctor public EditorInfo();
method public int describeContents();
method public void dump(android.util.Printer, String);
+ method @Nullable public CharSequence getInitialSelectedText(int);
+ method @Nullable public CharSequence getInitialTextAfterCursor(int, int);
+ method @Nullable public CharSequence getInitialTextBeforeCursor(int, int);
method public final void makeCompatible(int);
+ method public void setInitialSurroundingSubText(@NonNull CharSequence, int);
+ method public void setInitialSurroundingText(@NonNull CharSequence);
method public void writeToParcel(android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.view.inputmethod.EditorInfo> CREATOR;
field public static final int IME_ACTION_DONE = 6; // 0x6
diff --git a/api/system-current.txt b/api/system-current.txt
index 53b71a7..9e53c94 100755
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -55,6 +55,7 @@
field public static final String CAPTURE_AUDIO_HOTWORD = "android.permission.CAPTURE_AUDIO_HOTWORD";
field public static final String CAPTURE_MEDIA_OUTPUT = "android.permission.CAPTURE_MEDIA_OUTPUT";
field public static final String CAPTURE_TV_INPUT = "android.permission.CAPTURE_TV_INPUT";
+ field public static final String CAPTURE_VOICE_COMMUNICATION_OUTPUT = "android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT";
field public static final String CHANGE_APP_IDLE_STATE = "android.permission.CHANGE_APP_IDLE_STATE";
field public static final String CHANGE_DEVICE_IDLE_TEMP_WHITELIST = "android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST";
field public static final String CLEAR_APP_USER_DATA = "android.permission.CLEAR_APP_USER_DATA";
@@ -129,6 +130,7 @@
field public static final String MODIFY_PARENTAL_CONTROLS = "android.permission.MODIFY_PARENTAL_CONTROLS";
field public static final String MODIFY_QUIET_MODE = "android.permission.MODIFY_QUIET_MODE";
field public static final String MODIFY_SETTINGS_OVERRIDEABLE_BY_RESTORE = "android.permission.MODIFY_SETTINGS_OVERRIDEABLE_BY_RESTORE";
+ field public static final String MONITOR_DEVICE_CONFIG_ACCESS = "android.permission.MONITOR_DEVICE_CONFIG_ACCESS";
field public static final String MOVE_PACKAGE = "android.permission.MOVE_PACKAGE";
field public static final String NETWORK_AIRPLANE_MODE = "android.permission.NETWORK_AIRPLANE_MODE";
field public static final String NETWORK_CARRIER_PROVISIONING = "android.permission.NETWORK_CARRIER_PROVISIONING";
@@ -231,7 +233,7 @@
field public static final String WRITE_DEVICE_CONFIG = "android.permission.WRITE_DEVICE_CONFIG";
field public static final String WRITE_DREAM_STATE = "android.permission.WRITE_DREAM_STATE";
field public static final String WRITE_EMBEDDED_SUBSCRIPTIONS = "android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS";
- field public static final String WRITE_MEDIA_STORAGE = "android.permission.WRITE_MEDIA_STORAGE";
+ field @Deprecated public static final String WRITE_MEDIA_STORAGE = "android.permission.WRITE_MEDIA_STORAGE";
field public static final String WRITE_OBB = "android.permission.WRITE_OBB";
}
@@ -388,6 +390,7 @@
field public static final String OPSTR_POST_NOTIFICATION = "android:post_notification";
field public static final String OPSTR_PROJECT_MEDIA = "android:project_media";
field public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard";
+ field public static final String OPSTR_READ_DEVICE_IDENTIFIERS = "android:read_device_identifiers";
field public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms";
field public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio";
field public static final String OPSTR_READ_MEDIA_IMAGES = "android:read_media_images";
@@ -3634,9 +3637,34 @@
package android.hardware.soundtrigger {
public class SoundTrigger {
+ field public static final int RECOGNITION_MODE_GENERIC = 8; // 0x8
+ field public static final int RECOGNITION_MODE_USER_AUTHENTICATION = 4; // 0x4
+ field public static final int RECOGNITION_MODE_USER_IDENTIFICATION = 2; // 0x2
+ field public static final int RECOGNITION_MODE_VOICE_TRIGGER = 1; // 0x1
field public static final int STATUS_OK = 0; // 0x0
}
+ public static final class SoundTrigger.Keyphrase implements android.os.Parcelable {
+ ctor public SoundTrigger.Keyphrase(int, int, @NonNull java.util.Locale, @NonNull String, @Nullable int[]);
+ method @NonNull public static android.hardware.soundtrigger.SoundTrigger.Keyphrase readFromParcel(@NonNull android.os.Parcel);
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.Keyphrase> CREATOR;
+ field public final int id;
+ field @NonNull public final java.util.Locale locale;
+ field public final int recognitionModes;
+ field @NonNull public final String text;
+ field @NonNull public final int[] users;
+ }
+
+ public static final class SoundTrigger.KeyphraseSoundModel extends android.hardware.soundtrigger.SoundTrigger.SoundModel implements android.os.Parcelable {
+ ctor public SoundTrigger.KeyphraseSoundModel(@NonNull java.util.UUID, @NonNull java.util.UUID, @Nullable byte[], @Nullable android.hardware.soundtrigger.SoundTrigger.Keyphrase[], int);
+ ctor public SoundTrigger.KeyphraseSoundModel(@NonNull java.util.UUID, @NonNull java.util.UUID, @Nullable byte[], @Nullable android.hardware.soundtrigger.SoundTrigger.Keyphrase[]);
+ method @NonNull public static android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel readFromParcel(@NonNull android.os.Parcel);
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel> CREATOR;
+ field @NonNull public final android.hardware.soundtrigger.SoundTrigger.Keyphrase[] keyphrases;
+ }
+
public static final class SoundTrigger.ModelParamRange implements android.os.Parcelable {
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.ModelParamRange> CREATOR;
@@ -3675,6 +3703,16 @@
method public boolean isCaptureAvailable();
}
+ public static class SoundTrigger.SoundModel {
+ field public static final int TYPE_GENERIC_SOUND = 1; // 0x1
+ field public static final int TYPE_KEYPHRASE = 0; // 0x0
+ field @NonNull public final byte[] data;
+ field public final int type;
+ field @NonNull public final java.util.UUID uuid;
+ field @NonNull public final java.util.UUID vendorUuid;
+ field public final int version;
+ }
+
}
package android.hardware.usb {
@@ -5882,6 +5920,16 @@
}
+package android.media.voice {
+
+ public final class KeyphraseModelManager {
+ method @RequiresPermission("android.permission.MANAGE_VOICE_KEYPHRASES") public void deleteKeyphraseSoundModel(int, @NonNull java.util.Locale);
+ method @Nullable @RequiresPermission("android.permission.MANAGE_VOICE_KEYPHRASES") public android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel getKeyphraseSoundModel(int, @NonNull java.util.Locale);
+ method @RequiresPermission("android.permission.MANAGE_VOICE_KEYPHRASES") public void updateKeyphraseSoundModel(@NonNull android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel);
+ }
+
+}
+
package android.metrics {
public class LogMaker {
@@ -5968,27 +6016,27 @@
method @NonNull @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD) public android.net.SocketKeepalive createNattKeepalive(@NonNull android.net.Network, @NonNull android.os.ParcelFileDescriptor, @NonNull java.net.InetAddress, @NonNull java.net.InetAddress, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
method @NonNull @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD) public android.net.SocketKeepalive createSocketKeepalive(@NonNull android.net.Network, @NonNull java.net.Socket, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
method @Deprecated @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public String getCaptivePortalServerUrl();
- method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void getLatestTetheringEntitlementResult(int, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEntitlementResultListener);
- method @RequiresPermission(anyOf={android.Manifest.permission.TETHER_PRIVILEGED, android.Manifest.permission.WRITE_SETTINGS}) public boolean isTetheringSupported();
+ method @Deprecated @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void getLatestTetheringEntitlementResult(int, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEntitlementResultListener);
+ method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.TETHER_PRIVILEGED, android.Manifest.permission.WRITE_SETTINGS}) public boolean isTetheringSupported();
method @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public int registerNetworkProvider(@NonNull android.net.NetworkProvider);
- method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void registerTetheringEventCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEventCallback);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void registerTetheringEventCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEventCallback);
method @Deprecated public void requestNetwork(@NonNull android.net.NetworkRequest, @NonNull android.net.ConnectivityManager.NetworkCallback, int, int, @NonNull android.os.Handler);
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_AIRPLANE_MODE, android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD, android.Manifest.permission.NETWORK_STACK}) public void setAirplaneMode(boolean);
method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK}) public boolean shouldAvoidBadWifi();
method @RequiresPermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) public void startCaptivePortalApp(@NonNull android.net.Network, @NonNull android.os.Bundle);
method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback);
method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback, android.os.Handler);
- method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void stopTethering(int);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void stopTethering(int);
method @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public void unregisterNetworkProvider(@NonNull android.net.NetworkProvider);
- method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void unregisterTetheringEventCallback(@NonNull android.net.ConnectivityManager.OnTetheringEventCallback);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void unregisterTetheringEventCallback(@NonNull android.net.ConnectivityManager.OnTetheringEventCallback);
field public static final String EXTRA_CAPTIVE_PORTAL_PROBE_SPEC = "android.net.extra.CAPTIVE_PORTAL_PROBE_SPEC";
field public static final String EXTRA_CAPTIVE_PORTAL_USER_AGENT = "android.net.extra.CAPTIVE_PORTAL_USER_AGENT";
field public static final int TETHERING_BLUETOOTH = 2; // 0x2
field public static final int TETHERING_USB = 1; // 0x1
field public static final int TETHERING_WIFI = 0; // 0x0
- field public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN = 13; // 0xd
- field public static final int TETHER_ERROR_NO_ERROR = 0; // 0x0
- field public static final int TETHER_ERROR_PROVISION_FAILED = 11; // 0xb
+ field @Deprecated public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN = 13; // 0xd
+ field @Deprecated public static final int TETHER_ERROR_NO_ERROR = 0; // 0x0
+ field @Deprecated public static final int TETHER_ERROR_PROVISION_FAILED = 11; // 0xb
field public static final int TYPE_NONE = -1; // 0xffffffff
field @Deprecated public static final int TYPE_WIFI_P2P = 13; // 0xd
}
@@ -5999,13 +6047,13 @@
method public void onTetheringStarted();
}
- public static interface ConnectivityManager.OnTetheringEntitlementResultListener {
- method public void onTetheringEntitlementResult(int);
+ @Deprecated public static interface ConnectivityManager.OnTetheringEntitlementResultListener {
+ method @Deprecated public void onTetheringEntitlementResult(int);
}
- public abstract static class ConnectivityManager.OnTetheringEventCallback {
- ctor public ConnectivityManager.OnTetheringEventCallback();
- method public void onUpstreamChanged(@Nullable android.net.Network);
+ @Deprecated public abstract static class ConnectivityManager.OnTetheringEventCallback {
+ ctor @Deprecated public ConnectivityManager.OnTetheringEventCallback();
+ method @Deprecated public void onUpstreamChanged(@Nullable android.net.Network);
}
public class InvalidPacketException extends java.lang.Exception {
@@ -6393,19 +6441,65 @@
method @NonNull public android.net.StaticIpConfiguration.Builder setIpAddress(@Nullable android.net.LinkAddress);
}
- public final class StringNetworkSpecifier extends android.net.NetworkSpecifier implements android.os.Parcelable {
- ctor public StringNetworkSpecifier(@NonNull String);
- method public int describeContents();
- method public boolean satisfiedBy(android.net.NetworkSpecifier);
- method public void writeToParcel(@NonNull android.os.Parcel, int);
- field @NonNull public static final android.os.Parcelable.Creator<android.net.StringNetworkSpecifier> CREATOR;
- field @NonNull public final String specifier;
- }
-
public final class TelephonyNetworkSpecifier extends android.net.NetworkSpecifier implements android.os.Parcelable {
method public boolean satisfiedBy(android.net.NetworkSpecifier);
}
+ public class TetheringManager {
+ method public void registerTetheringEventCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.TetheringManager.TetheringEventCallback);
+ method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void requestLatestTetheringEntitlementResult(int, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.net.TetheringManager.OnTetheringEntitlementResultListener);
+ method public void stopAllTethering();
+ method public void stopTethering(int);
+ method public void unregisterTetheringEventCallback(@NonNull android.net.TetheringManager.TetheringEventCallback);
+ field public static final String ACTION_TETHER_STATE_CHANGED = "android.net.conn.TETHER_STATE_CHANGED";
+ field public static final String EXTRA_ACTIVE_LOCAL_ONLY = "android.net.extra.ACTIVE_LOCAL_ONLY";
+ field public static final String EXTRA_ACTIVE_TETHER = "tetherArray";
+ field public static final String EXTRA_AVAILABLE_TETHER = "availableArray";
+ field public static final String EXTRA_ERRORED_TETHER = "erroredArray";
+ field public static final int TETHERING_BLUETOOTH = 2; // 0x2
+ field public static final int TETHERING_INVALID = -1; // 0xffffffff
+ field public static final int TETHERING_USB = 1; // 0x1
+ field public static final int TETHERING_WIFI = 0; // 0x0
+ field public static final int TETHERING_WIFI_P2P = 3; // 0x3
+ field public static final int TETHER_ERROR_DHCPSERVER_ERROR = 12; // 0xc
+ field public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9; // 0x9
+ field public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8; // 0x8
+ field public static final int TETHER_ERROR_ENTITLEMENT_UNKNOWN = 13; // 0xd
+ field public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10; // 0xa
+ field public static final int TETHER_ERROR_MASTER_ERROR = 5; // 0x5
+ field public static final int TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION = 15; // 0xf
+ field public static final int TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION = 14; // 0xe
+ field public static final int TETHER_ERROR_NO_ERROR = 0; // 0x0
+ field public static final int TETHER_ERROR_PROVISION_FAILED = 11; // 0xb
+ field public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2; // 0x2
+ field public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6; // 0x6
+ field public static final int TETHER_ERROR_UNAVAIL_IFACE = 4; // 0x4
+ field public static final int TETHER_ERROR_UNKNOWN_IFACE = 1; // 0x1
+ field public static final int TETHER_ERROR_UNSUPPORTED = 3; // 0x3
+ field public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7; // 0x7
+ }
+
+ public static interface TetheringManager.OnTetheringEntitlementResultListener {
+ method public void onTetheringEntitlementResult(int);
+ }
+
+ public abstract static class TetheringManager.TetheringEventCallback {
+ ctor public TetheringManager.TetheringEventCallback();
+ method public void onError(@NonNull String, int);
+ method @Deprecated public void onTetherableInterfaceRegexpsChanged(@NonNull android.net.TetheringManager.TetheringInterfaceRegexps);
+ method public void onTetherableInterfacesChanged(@NonNull java.util.List<java.lang.String>);
+ method public void onTetheredInterfacesChanged(@NonNull java.util.List<java.lang.String>);
+ method public void onTetheringSupported(boolean);
+ method public void onUpstreamChanged(@Nullable android.net.Network);
+ }
+
+ @Deprecated public static class TetheringManager.TetheringInterfaceRegexps {
+ ctor @Deprecated public TetheringManager.TetheringInterfaceRegexps(@NonNull String[], @NonNull String[], @NonNull String[]);
+ method @Deprecated @NonNull public java.util.List<java.lang.String> getTetherableBluetoothRegexs();
+ method @Deprecated @NonNull public java.util.List<java.lang.String> getTetherableUsbRegexs();
+ method @Deprecated @NonNull public java.util.List<java.lang.String> getTetherableWifiRegexs();
+ }
+
public class TrafficStats {
method public static void setThreadStatsTagApp();
method public static void setThreadStatsTagBackup();
@@ -10049,6 +10143,7 @@
public abstract class EuiccService extends android.app.Service {
ctor public EuiccService();
method public void dump(@NonNull java.io.PrintWriter);
+ method public int encodeSmdxSubjectAndReasonCode(@Nullable String, @Nullable String) throws java.lang.IllegalArgumentException, java.lang.NumberFormatException, java.lang.UnsupportedOperationException;
method @CallSuper public android.os.IBinder onBind(android.content.Intent);
method public abstract int onDeleteSubscription(int, String);
method public android.service.euicc.DownloadSubscriptionResult onDownloadSubscription(int, @NonNull android.telephony.euicc.DownloadableSubscription, boolean, boolean, @Nullable android.os.Bundle);
@@ -10409,6 +10504,14 @@
}
+package android.service.voice {
+
+ public class VoiceInteractionService extends android.app.Service {
+ method @NonNull @RequiresPermission("android.permission.MANAGE_VOICE_KEYPHRASES") public final android.media.voice.KeyphraseModelManager createKeyphraseModelManager();
+ }
+
+}
+
package android.service.wallpaper {
public class WallpaperService.Engine {
@@ -11969,7 +12072,6 @@
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) @WorkerThread public boolean isIccLockEnabled();
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isIdle();
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isInEmergencySmsMode();
- method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isManualNetworkSelectionAllowed();
method public boolean isModemEnabledForSlot(int);
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isOffhook();
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isOpportunisticNetworkEnabled();
@@ -12631,6 +12733,7 @@
field public static final String EXTRA_DIALSTRING = "dialstring";
field public static final String EXTRA_DISPLAY_TEXT = "DisplayText";
field public static final String EXTRA_EMERGENCY_CALL = "e_call";
+ field public static final String EXTRA_FORWARDED_NUMBER = "android.telephony.ims.extra.FORWARDED_NUMBER";
field public static final String EXTRA_IS_CALL_PULL = "CallPull";
field public static final String EXTRA_OI = "oi";
field public static final String EXTRA_OIR = "oir";
@@ -13420,6 +13523,7 @@
method public int transact(android.os.Bundle);
method public int updateCallBarring(int, int, String[]);
method public int updateCallBarringForServiceClass(int, int, String[], int);
+ method public int updateCallBarringWithPassword(int, int, @Nullable String[], int, @NonNull String);
method public int updateCallForward(int, int, String, int, int);
method public int updateCallWaiting(boolean, int);
method public int updateClip(boolean);
@@ -14089,4 +14193,3 @@
}
}
-
diff --git a/api/system-lint-baseline.txt b/api/system-lint-baseline.txt
index fde6bb3..23e1ed7 100644
--- a/api/system-lint-baseline.txt
+++ b/api/system-lint-baseline.txt
@@ -8,6 +8,15 @@
ActionValue: android.net.wifi.WifiManager#ACTION_LINK_CONFIGURATION_CHANGED:
+// Tethering broadcast action / extras cannot change name for backwards compatibility
+ActionValue: android.net.TetheringManager#ACTION_TETHER_STATE_CHANGED:
+ Inconsistent action value; expected `android.net.action.TETHER_STATE_CHANGED`, was `android.net.conn.TETHER_STATE_CHANGED`
+ActionValue: android.net.TetheringManager#EXTRA_ACTIVE_TETHER:
+ Inconsistent extra value; expected `android.net.extra.ACTIVE_TETHER`, was `tetherArray`
+ActionValue: android.net.TetheringManager#EXTRA_AVAILABLE_TETHER:
+ Inconsistent extra value; expected `android.net.extra.AVAILABLE_TETHER`, was `availableArray`
+ActionValue: android.net.TetheringManager#EXTRA_ERRORED_TETHER:
+ Inconsistent extra value; expected `android.net.extra.ERRORED_TETHER`, was `erroredArray`
ArrayReturn: android.bluetooth.BluetoothCodecStatus#BluetoothCodecStatus(android.bluetooth.BluetoothCodecConfig, android.bluetooth.BluetoothCodecConfig[], android.bluetooth.BluetoothCodecConfig[]) parameter #1:
Method parameter should be Collection<BluetoothCodecConfig> (or subclass) instead of raw array; was `android.bluetooth.BluetoothCodecConfig[]`
diff --git a/api/test-current.txt b/api/test-current.txt
index dc6b515..f179d87 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -19,7 +19,7 @@
field public static final String SUSPEND_APPS = "android.permission.SUSPEND_APPS";
field public static final String TEST_MANAGE_ROLLBACKS = "android.permission.TEST_MANAGE_ROLLBACKS";
field public static final String WRITE_DEVICE_CONFIG = "android.permission.WRITE_DEVICE_CONFIG";
- field public static final String WRITE_MEDIA_STORAGE = "android.permission.WRITE_MEDIA_STORAGE";
+ field @Deprecated public static final String WRITE_MEDIA_STORAGE = "android.permission.WRITE_MEDIA_STORAGE";
field public static final String WRITE_OBB = "android.permission.WRITE_OBB";
}
@@ -1664,6 +1664,61 @@
method public void teardownTestNetwork(@NonNull android.net.Network);
}
+ public class TetheringManager {
+ method public void registerTetheringEventCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.TetheringManager.TetheringEventCallback);
+ method @RequiresPermission("android.permission.TETHER_PRIVILEGED") public void requestLatestTetheringEntitlementResult(int, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.net.TetheringManager.OnTetheringEntitlementResultListener);
+ method public void stopAllTethering();
+ method public void stopTethering(int);
+ method public void unregisterTetheringEventCallback(@NonNull android.net.TetheringManager.TetheringEventCallback);
+ field public static final String ACTION_TETHER_STATE_CHANGED = "android.net.conn.TETHER_STATE_CHANGED";
+ field public static final String EXTRA_ACTIVE_LOCAL_ONLY = "android.net.extra.ACTIVE_LOCAL_ONLY";
+ field public static final String EXTRA_ACTIVE_TETHER = "tetherArray";
+ field public static final String EXTRA_AVAILABLE_TETHER = "availableArray";
+ field public static final String EXTRA_ERRORED_TETHER = "erroredArray";
+ field public static final int TETHERING_BLUETOOTH = 2; // 0x2
+ field public static final int TETHERING_INVALID = -1; // 0xffffffff
+ field public static final int TETHERING_USB = 1; // 0x1
+ field public static final int TETHERING_WIFI = 0; // 0x0
+ field public static final int TETHERING_WIFI_P2P = 3; // 0x3
+ field public static final int TETHER_ERROR_DHCPSERVER_ERROR = 12; // 0xc
+ field public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9; // 0x9
+ field public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8; // 0x8
+ field public static final int TETHER_ERROR_ENTITLEMENT_UNKNOWN = 13; // 0xd
+ field public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10; // 0xa
+ field public static final int TETHER_ERROR_MASTER_ERROR = 5; // 0x5
+ field public static final int TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION = 15; // 0xf
+ field public static final int TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION = 14; // 0xe
+ field public static final int TETHER_ERROR_NO_ERROR = 0; // 0x0
+ field public static final int TETHER_ERROR_PROVISION_FAILED = 11; // 0xb
+ field public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2; // 0x2
+ field public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6; // 0x6
+ field public static final int TETHER_ERROR_UNAVAIL_IFACE = 4; // 0x4
+ field public static final int TETHER_ERROR_UNKNOWN_IFACE = 1; // 0x1
+ field public static final int TETHER_ERROR_UNSUPPORTED = 3; // 0x3
+ field public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7; // 0x7
+ }
+
+ public static interface TetheringManager.OnTetheringEntitlementResultListener {
+ method public void onTetheringEntitlementResult(int);
+ }
+
+ public abstract static class TetheringManager.TetheringEventCallback {
+ ctor public TetheringManager.TetheringEventCallback();
+ method public void onError(@NonNull String, int);
+ method @Deprecated public void onTetherableInterfaceRegexpsChanged(@NonNull android.net.TetheringManager.TetheringInterfaceRegexps);
+ method public void onTetherableInterfacesChanged(@NonNull java.util.List<java.lang.String>);
+ method public void onTetheredInterfacesChanged(@NonNull java.util.List<java.lang.String>);
+ method public void onTetheringSupported(boolean);
+ method public void onUpstreamChanged(@Nullable android.net.Network);
+ }
+
+ @Deprecated public static class TetheringManager.TetheringInterfaceRegexps {
+ ctor @Deprecated public TetheringManager.TetheringInterfaceRegexps(@NonNull String[], @NonNull String[], @NonNull String[]);
+ method @Deprecated @NonNull public java.util.List<java.lang.String> getTetherableBluetoothRegexs();
+ method @Deprecated @NonNull public java.util.List<java.lang.String> getTetherableUsbRegexs();
+ method @Deprecated @NonNull public java.util.List<java.lang.String> getTetherableWifiRegexs();
+ }
+
public class TrafficStats {
method public static long getLoopbackRxBytes();
method public static long getLoopbackRxPackets();
@@ -3522,6 +3577,7 @@
field public static final String EXTRA_DIALSTRING = "dialstring";
field public static final String EXTRA_DISPLAY_TEXT = "DisplayText";
field public static final String EXTRA_EMERGENCY_CALL = "e_call";
+ field public static final String EXTRA_FORWARDED_NUMBER = "android.telephony.ims.extra.FORWARDED_NUMBER";
field public static final String EXTRA_IS_CALL_PULL = "CallPull";
field public static final String EXTRA_OEM_EXTRAS = "android.telephony.ims.extra.OEM_EXTRAS";
field public static final String EXTRA_OI = "oi";
@@ -4260,6 +4316,7 @@
method public int transact(android.os.Bundle);
method public int updateCallBarring(int, int, String[]);
method public int updateCallBarringForServiceClass(int, int, String[], int);
+ method public int updateCallBarringWithPassword(int, int, @Nullable String[], int, @NonNull String);
method public int updateCallForward(int, int, String, int, int);
method public int updateCallWaiting(boolean, int);
method public int updateClip(boolean);
@@ -4547,22 +4604,6 @@
method public abstract String asyncImpl() default "";
}
- public class SurfaceControlViewHost {
- ctor public SurfaceControlViewHost(@NonNull android.content.Context, @NonNull android.view.Display, @Nullable android.os.IBinder);
- method public void addView(android.view.View, android.view.WindowManager.LayoutParams);
- method public void dispose();
- method @Nullable public android.view.SurfaceControlViewHost.SurfacePackage getSurfacePackage();
- method public void relayout(android.view.WindowManager.LayoutParams);
- }
-
- public class SurfaceControlViewHost.SurfacePackage {
- method @NonNull public android.view.SurfaceControl getSurfaceControl();
- }
-
- public class SurfaceView extends android.view.View {
- method @Nullable public android.os.IBinder getInputToken();
- }
-
@UiThread public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback {
method public android.view.View getTooltipView();
method public boolean isAutofilled();
diff --git a/api/test-lint-baseline.txt b/api/test-lint-baseline.txt
index 603f7a2..54f7f68 100644
--- a/api/test-lint-baseline.txt
+++ b/api/test-lint-baseline.txt
@@ -7,6 +7,16 @@
ActionValue: android.location.Location#EXTRA_NO_GPS_LOCATION:
+// Tethering broadcast action / extras cannot change name for backwards compatibility
+ActionValue: android.net.TetheringManager#ACTION_TETHER_STATE_CHANGED:
+ Inconsistent action value; expected `android.net.action.TETHER_STATE_CHANGED`, was `android.net.conn.TETHER_STATE_CHANGED`
+ActionValue: android.net.TetheringManager#EXTRA_ACTIVE_TETHER:
+ Inconsistent extra value; expected `android.net.extra.ACTIVE_TETHER`, was `tetherArray`
+ActionValue: android.net.TetheringManager#EXTRA_AVAILABLE_TETHER:
+ Inconsistent extra value; expected `android.net.extra.AVAILABLE_TETHER`, was `availableArray`
+ActionValue: android.net.TetheringManager#EXTRA_ERRORED_TETHER:
+ Inconsistent extra value; expected `android.net.extra.ERRORED_TETHER`, was `erroredArray`
+
ActionValue: android.telephony.ims.ImsCallProfile#EXTRA_ADDITIONAL_CALL_INFO:
ActionValue: android.telephony.ims.ImsCallProfile#EXTRA_CALL_RAT_TYPE:
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index b82a675..2ca5b1d 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -7326,6 +7326,15 @@
}
}
+ float getFloatCoreSetting(String key, float defaultValue) {
+ synchronized (mResourcesManager) {
+ if (mCoreSettings != null) {
+ return mCoreSettings.getFloat(key, defaultValue);
+ }
+ return defaultValue;
+ }
+ }
+
private static class AndroidOs extends ForwardingOs {
/**
* Install selective syscall interception. For example, this is used to
diff --git a/core/java/android/app/AppGlobals.java b/core/java/android/app/AppGlobals.java
index 81e1565..f66bf0d 100644
--- a/core/java/android/app/AppGlobals.java
+++ b/core/java/android/app/AppGlobals.java
@@ -75,4 +75,20 @@
return defaultValue;
}
}
+
+ /**
+ * Gets the value of a float core setting.
+ *
+ * @param key The setting key.
+ * @param defaultValue The setting default value.
+ * @return The core settings.
+ */
+ public static float getFloatCoreSetting(String key, float defaultValue) {
+ ActivityThread currentActivityThread = ActivityThread.currentActivityThread();
+ if (currentActivityThread != null) {
+ return currentActivityThread.getFloatCoreSetting(key, defaultValue);
+ } else {
+ return defaultValue;
+ }
+ }
}
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index bc7e1e5..46f8669 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -1159,6 +1159,7 @@
@SystemApi
public static final String OPSTR_ACCESS_ACCESSIBILITY = "android:access_accessibility";
/** @hide Read device identifiers */
+ @SystemApi
public static final String OPSTR_READ_DEVICE_IDENTIFIERS = "android:read_device_identifiers";
/** @hide Query all packages on device */
public static final String OPSTR_QUERY_ALL_PACKAGES = "android:query_all_packages";
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index c1e5356..3abd509 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -106,6 +106,7 @@
import android.media.soundtrigger.SoundTriggerManager;
import android.media.tv.ITvInputManager;
import android.media.tv.TvInputManager;
+import android.net.ConnectivityDiagnosticsManager;
import android.net.ConnectivityManager;
import android.net.ConnectivityThread;
import android.net.EthernetManager;
@@ -376,6 +377,18 @@
return new IpSecManager(ctx, service);
}});
+ registerService(Context.CONNECTIVITY_DIAGNOSTICS_SERVICE,
+ ConnectivityDiagnosticsManager.class,
+ new CachedServiceFetcher<ConnectivityDiagnosticsManager>() {
+ @Override
+ public ConnectivityDiagnosticsManager createService(ContextImpl ctx)
+ throws ServiceNotFoundException {
+ // ConnectivityDiagnosticsManager is backed by ConnectivityService
+ IBinder b = ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE);
+ IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
+ return new ConnectivityDiagnosticsManager(ctx, service);
+ }});
+
registerService(
Context.TEST_NETWORK_SERVICE,
TestNetworkManager.class,
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 2943e39..7b0cdcf 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -3984,6 +3984,16 @@
/**
* Use with {@link #getSystemService(String)} to retrieve a {@link
+ * android.net.ConnectivityDiagnosticsManager} for performing network connectivity diagnostics
+ * as well as receiving network connectivity information from the system.
+ *
+ * @see #getSystemService(String)
+ * @see android.net.ConnectivityDiagnosticsManager
+ */
+ public static final String CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics";
+
+ /**
+ * Use with {@link #getSystemService(String)} to retrieve a {@link
* android.net.TestNetworkManager} for building TUNs and limited-use Networks
*
* @see #getSystemService(String)
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index fe5e672..a2d425b 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -2203,6 +2203,23 @@
/**
* Feature for {@link #getSystemAvailableFeatures} and
+ * {@link #hasSystemFeature(String, int)}: If this feature is supported, the feature version
+ * specifies a date such that the device is known to pass the Vulkan dEQP test suite associated
+ * with that date. The date is encoded as follows:
+ * <ul>
+ * <li>Year in bits 31-16</li>
+ * <li>Month in bits 15-8</li>
+ * <li>Day in bits 7-0</li>
+ * </ul>
+ * <p>
+ * Example: 2019-03-01 is encoded as 0x07E30301, and would indicate that the device passes the
+ * Vulkan dEQP test suite version that was current on 2019-03-01.
+ */
+ @SdkConstant(SdkConstantType.FEATURE)
+ public static final String FEATURE_VULKAN_DEQP_LEVEL = "android.software.vulkan.deqp.level";
+
+ /**
+ * Feature for {@link #getSystemAvailableFeatures} and
* {@link #hasSystemFeature}: The device includes broadcast radio tuner.
* @hide
*/
diff --git a/core/java/android/content/pm/ProcessInfo.java b/core/java/android/content/pm/ProcessInfo.java
new file mode 100644
index 0000000..c77a267
--- /dev/null
+++ b/core/java/android/content/pm/ProcessInfo.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2020 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.content.pm;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.text.TextUtils;
+import android.util.ArraySet;
+
+/**
+ * Information about a process an app may run. This corresponds to information collected from the
+ * AndroidManifest.xml's <permission-group> tags.
+ * @hide
+ */
+public class ProcessInfo implements Parcelable {
+ /**
+ * The name of the process, fully-qualified based on the app's package name.
+ */
+ public String name;
+
+ /**
+ * If non-null, these are permissions that are not allowed in this process.
+ */
+ @Nullable
+ public ArraySet<String> deniedPermissions;
+
+ public ProcessInfo(String name, ArraySet<String> deniedPermissions) {
+ this.name = name;
+ this.deniedPermissions = deniedPermissions;
+ }
+
+ @Deprecated
+ public ProcessInfo(@NonNull ProcessInfo orig) {
+ this.name = orig.name;
+ this.deniedPermissions = orig.deniedPermissions;
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel dest, int parcelableFlags) {
+ dest.writeString(this.name);
+ final int numDenied = this.deniedPermissions != null
+ ? this.deniedPermissions.size() : 0;
+ dest.writeInt(numDenied);
+ for (int i = 0; i < numDenied; i++) {
+ dest.writeString(this.deniedPermissions.valueAt(i));
+ }
+ }
+
+ public static final @NonNull Creator<ProcessInfo> CREATOR =
+ new Creator<ProcessInfo>() {
+ public ProcessInfo createFromParcel(Parcel source) {
+ return new ProcessInfo(source);
+ }
+ public ProcessInfo[] newArray(int size) {
+ return new ProcessInfo[size];
+ }
+ };
+
+ private ProcessInfo(Parcel source) {
+ this.name = source.readString();
+ final int numDenied = source.readInt();
+ if (numDenied > 0) {
+ this.deniedPermissions = new ArraySet<>(numDenied);
+ for (int i = numDenied - 1; i >= 0; i--) {
+ this.deniedPermissions.add(TextUtils.safeIntern(source.readString()));
+ }
+ }
+ }
+}
diff --git a/core/java/android/content/pm/parsing/AndroidPackage.java b/core/java/android/content/pm/parsing/AndroidPackage.java
index 990c835..fbe5a48 100644
--- a/core/java/android/content/pm/parsing/AndroidPackage.java
+++ b/core/java/android/content/pm/parsing/AndroidPackage.java
@@ -36,6 +36,7 @@
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
+import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.SparseArray;
@@ -379,6 +380,9 @@
@Nullable
long[] getUsesStaticLibrariesVersions();
+ @Nullable
+ ArrayMap<String, ComponentParseUtils.ParsedProcess> getProcesses();
+
int getVersionCode();
int getVersionCodeMajor();
diff --git a/core/java/android/content/pm/parsing/ApkParseUtils.java b/core/java/android/content/pm/parsing/ApkParseUtils.java
index 9b069ac..3018230 100644
--- a/core/java/android/content/pm/parsing/ApkParseUtils.java
+++ b/core/java/android/content/pm/parsing/ApkParseUtils.java
@@ -2426,6 +2426,21 @@
XmlUtils.skipCurrentTag(parser);
break;
+ case "processes":
+ ArrayMap<String, ComponentParseUtils.ParsedProcess> processes =
+ ComponentParseUtils.parseProcesses(separateProcesses,
+ parsingPackage,
+ res, parser, flags,
+ outError);
+ if (processes == null) {
+ return parseInput.error(
+ PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
+ outError[0]
+ );
+ }
+
+ parsingPackage.setProcesses(processes);
+ break;
case "uses-package":
// Dependencies for app installers; we don't currently try to
// enforce this.
diff --git a/core/java/android/content/pm/parsing/ComponentParseUtils.java b/core/java/android/content/pm/parsing/ComponentParseUtils.java
index 3846202a..9a0a6d5 100644
--- a/core/java/android/content/pm/parsing/ComponentParseUtils.java
+++ b/core/java/android/content/pm/parsing/ComponentParseUtils.java
@@ -50,6 +50,7 @@
import android.os.Parcelable;
import android.os.PatternMatcher;
import android.text.TextUtils;
+import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.Log;
@@ -1366,6 +1367,72 @@
};
}
+ public static class ParsedProcess implements Parcelable {
+
+ public String name;
+ @Nullable
+ public ArraySet<String> deniedPermissions;
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(this.name);
+ final int numDenied = this.deniedPermissions != null
+ ? this.deniedPermissions.size() : 0;
+ dest.writeInt(numDenied);
+ for (int i = 0; i < numDenied; i++) {
+ dest.writeString(this.deniedPermissions.valueAt(i));
+ }
+ }
+
+ public ParsedProcess() {
+ }
+
+ public ParsedProcess(@NonNull ParsedProcess other) {
+ name = other.name;
+ if (other.deniedPermissions != null) {
+ deniedPermissions = new ArraySet<>(other.deniedPermissions);
+ }
+ }
+
+ public void addStateFrom(@NonNull ParsedProcess other) {
+ if (other.deniedPermissions != null) {
+ for (int i = other.deniedPermissions.size() - 1; i >= 0; i--) {
+ if (deniedPermissions == null) {
+ deniedPermissions = new ArraySet<>(other.deniedPermissions.size());
+ }
+ deniedPermissions.add(other.deniedPermissions.valueAt(i));
+ }
+ }
+ }
+
+ protected ParsedProcess(Parcel in) {
+ this.name = TextUtils.safeIntern(in.readString());
+ final int numDenied = in.readInt();
+ if (numDenied > 0) {
+ this.deniedPermissions = new ArraySet<>(numDenied);
+ this.deniedPermissions.add(TextUtils.safeIntern(in.readString()));
+ }
+ }
+
+ public static final Creator<ParsedProcess> CREATOR =
+ new Creator<ParsedProcess>() {
+ @Override
+ public ParsedProcess createFromParcel(Parcel source) {
+ return new ParsedProcess(source);
+ }
+
+ @Override
+ public ParsedProcess[] newArray(int size) {
+ return new ParsedProcess[size];
+ }
+ };
+ }
+
public static ParsedActivity parseActivity(
String[] separateProcesses,
ParsingPackage parsingPackage,
@@ -3266,6 +3333,189 @@
return result;
}
+ private static @Nullable ArraySet<String> parseDenyPermission(
+ ArraySet<String> perms,
+ Resources res,
+ XmlResourceParser parser,
+ String[] outError
+ ) throws IOException, XmlPullParserException {
+ TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestDenyPermission);
+ if (sa == null) {
+ outError[0] = "<deny-permission> could not be parsed";
+ return null;
+ }
+
+ try {
+ String perm = sa.getNonConfigurationString(
+ R.styleable.AndroidManifestDenyPermission_name,0);
+ if (perm != null && perm.equals(android.Manifest.permission.INTERNET)) {
+ if (perms == null) {
+ perms = new ArraySet<>();
+ }
+ perms.add(perm);
+ }
+ } finally {
+ sa.recycle();
+ }
+ XmlUtils.skipCurrentTag(parser);
+ return perms;
+ }
+
+ private static ArraySet<String> parseAllowPermission(
+ ArraySet<String> perms,
+ Resources res,
+ XmlResourceParser parser,
+ String[] outError
+ ) throws IOException, XmlPullParserException {
+ TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestAllowPermission);
+ if (sa == null) {
+ outError[0] = "<allow-permission> could not be parsed";
+ return null;
+ }
+
+ try {
+ String perm = sa.getNonConfigurationString(
+ R.styleable.AndroidManifestAllowPermission_name,0);
+ if (perm != null && perm.equals(android.Manifest.permission.INTERNET)
+ && perms != null) {
+ perms.remove(perm);
+ if (perms.size() <= 0) {
+ perms = null;
+ }
+ }
+ } finally {
+ sa.recycle();
+ }
+ XmlUtils.skipCurrentTag(parser);
+ return perms;
+ }
+
+ public static ParsedProcess parseProcess(
+ ArraySet<String> perms,
+ String[] separateProcesses,
+ ParsingPackage parsingPackage,
+ Resources res,
+ XmlResourceParser parser,
+ int flags,
+ String[] outError
+ ) throws IOException, XmlPullParserException {
+ TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestProcess);
+ if (sa == null) {
+ outError[0] = "<process> could not be parsed";
+ return null;
+ }
+
+ ParsedProcess proc = new ParsedProcess();
+ if (perms != null) {
+ proc.deniedPermissions = new ArraySet(perms);
+ }
+
+ try {
+ proc.name = sa.getNonConfigurationString(
+ R.styleable.AndroidManifestProcess_process,0);
+ proc.name = PackageParser.buildProcessName(parsingPackage.getPackageName(),
+ null, proc.name, flags, separateProcesses, outError);
+
+ if (proc.name == null || proc.name.length() <= 0) {
+ outError[0] = "<process> does not specify android:process";
+ return null;
+ }
+ proc.name = PackageParser.buildProcessName(parsingPackage.getPackageName(),
+ parsingPackage.getPackageName(), proc.name,
+ flags, separateProcesses, outError);
+ if (outError[0] != null) {
+ return null;
+ }
+ } finally {
+ sa.recycle();
+ }
+
+ int type;
+ final int innerDepth = parser.getDepth();
+ while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
+ if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+ continue;
+ }
+
+ String tagName = parser.getName();
+ if (tagName.equals("deny-permission")) {
+ proc.deniedPermissions = parseDenyPermission(proc.deniedPermissions, res, parser,
+ outError);
+ if (outError[0] != null) {
+ return null;
+ }
+ } else if (tagName.equals("allow-permission")) {
+ proc.deniedPermissions = parseAllowPermission(proc.deniedPermissions, res, parser,
+ outError);
+ if (outError[0] != null) {
+ return null;
+ }
+ } else {
+ Slog.w(TAG, "Unknown element under <process>: " + tagName
+ + " at " + parsingPackage.getBaseCodePath() + " "
+ + parser.getPositionDescription());
+ XmlUtils.skipCurrentTag(parser);
+ continue;
+ }
+ }
+
+ return proc;
+ }
+
+ public static ArrayMap<String, ParsedProcess> parseProcesses(
+ String[] separateProcesses,
+ ParsingPackage parsingPackage,
+ Resources res,
+ XmlResourceParser parser,
+ int flags,
+ String[] outError
+ ) throws IOException, XmlPullParserException {
+ ArraySet<String> deniedPerms = null;
+ ArrayMap<String, ParsedProcess> processes = new ArrayMap<>();
+
+ int type;
+ final int innerDepth = parser.getDepth();
+ while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
+ if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+ continue;
+ }
+
+ String tagName = parser.getName();
+ if (tagName.equals("deny-permission")) {
+ deniedPerms = parseDenyPermission(deniedPerms, res, parser, outError);
+ if (outError[0] != null) {
+ return null;
+ }
+ } else if (tagName.equals("allow-permission")) {
+ deniedPerms = parseAllowPermission(deniedPerms, res, parser, outError);
+ if (outError[0] != null) {
+ return null;
+ }
+ } else if (tagName.equals("process")) {
+ ParsedProcess proc = parseProcess(deniedPerms, separateProcesses, parsingPackage,
+ res, parser, flags, outError);
+ if (outError[0] != null) {
+ return null;
+ }
+ if (processes.get(proc.name) != null) {
+ outError[0] = "<process> specified existing name '" + proc.name + "'";
+ return null;
+ }
+ processes.put(proc.name, proc);
+ } else {
+ Slog.w(TAG, "Unknown element under <processes>: " + tagName
+ + " at " + parsingPackage.getBaseCodePath() + " "
+ + parser.getPositionDescription());
+ XmlUtils.skipCurrentTag(parser);
+ continue;
+ }
+ }
+
+ return processes;
+ }
+
public static ActivityInfo.WindowLayout parseLayout(Resources res, AttributeSet attrs) {
TypedArray sw = res.obtainAttributes(attrs,
R.styleable.AndroidManifestLayout);
diff --git a/core/java/android/content/pm/parsing/PackageImpl.java b/core/java/android/content/pm/parsing/PackageImpl.java
index 8677fce..9baf325 100644
--- a/core/java/android/content/pm/parsing/PackageImpl.java
+++ b/core/java/android/content/pm/parsing/PackageImpl.java
@@ -215,6 +215,9 @@
@Nullable
private ArrayList<String> queriesPackages;
+ @Nullable
+ private ArrayMap<String, ComponentParseUtils.ParsedProcess> processes;
+
private String[] splitClassLoaderNames;
private String[] splitCodePaths;
private SparseArray<int[]> splitDependencies;
@@ -527,6 +530,12 @@
return usesStaticLibraries;
}
+ @Nullable
+ @Override
+ public ArrayMap<String, ComponentParseUtils.ParsedProcess> getProcesses() {
+ return processes;
+ }
+
@Override
public boolean isBaseHardwareAccelerated() {
return baseHardwareAccelerated;
@@ -948,6 +957,12 @@
}
@Override
+ public PackageImpl setProcesses(ArrayMap<String, ComponentParseUtils.ParsedProcess> processes) {
+ this.processes = processes;
+ return this;
+ }
+
+ @Override
public PackageImpl setSupportsSmallScreens(int supportsSmallScreens) {
if (supportsSmallScreens == 1) {
return this;
@@ -3010,6 +3025,11 @@
dest.writeStringList(this.usesOptionalLibraries);
dest.writeStringList(this.usesStaticLibraries);
dest.writeLongArray(this.usesStaticLibrariesVersions);
+ final int numProcesses = this.processes != null ? this.processes.size() : 0;
+ dest.writeInt(numProcesses);
+ for (int i = 0; i < numProcesses; i++) {
+ this.processes.valueAt(i).writeToParcel(dest, 0);
+ }
if (this.usesStaticLibrariesCertDigests == null) {
dest.writeInt(-1);
@@ -3161,6 +3181,16 @@
this.usesStaticLibraries = in.createStringArrayList();
internStringArrayList(usesStaticLibraries);
this.usesStaticLibrariesVersions = in.createLongArray();
+ final int numProcesses = in.readInt();
+ if (numProcesses > 0) {
+ this.processes = new ArrayMap<>(numProcesses);
+ for (int i = 0; i < numProcesses; i++) {
+ ComponentParseUtils.ParsedProcess proc = new ComponentParseUtils.ParsedProcess(in);
+ this.processes.put(proc.name, proc);
+ }
+ } else {
+ this.processes = null;
+ }
int digestsSize = in.readInt();
if (digestsSize >= 0) {
diff --git a/core/java/android/content/pm/parsing/PackageInfoUtils.java b/core/java/android/content/pm/parsing/PackageInfoUtils.java
index e0ba99b..72df189 100644
--- a/core/java/android/content/pm/parsing/PackageInfoUtils.java
+++ b/core/java/android/content/pm/parsing/PackageInfoUtils.java
@@ -32,6 +32,7 @@
import android.content.pm.PackageUserState;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
+import android.content.pm.ProcessInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.SELinuxUtil;
import android.content.pm.ServiceInfo;
@@ -41,11 +42,11 @@
import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation;
import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup;
+import android.util.ArrayMap;
import android.util.ArraySet;
import com.android.internal.util.ArrayUtils;
-import java.util.LinkedHashSet;
import java.util.Set;
/** @hide */
@@ -459,6 +460,24 @@
return ii;
}
+ public static ArrayMap<String, ProcessInfo> generateProcessInfo(
+ ArrayMap<String, ComponentParseUtils.ParsedProcess> procs,
+ @PackageManager.ComponentInfoFlags int flags) {
+ if (procs == null) {
+ return null;
+ }
+
+ final int numProcs = procs.size();
+ ArrayMap<String, ProcessInfo> retProcs = new ArrayMap(numProcs);
+ for (int i = 0; i < numProcs; i++) {
+ ComponentParseUtils.ParsedProcess proc = procs.valueAt(i);
+ retProcs.put(proc.name, new ProcessInfo(proc.name,
+ proc.deniedPermissions != null
+ ? new ArraySet<>(proc.deniedPermissions) : null));
+ }
+ return retProcs;
+ }
+
public static PermissionInfo generatePermissionInfo(ParsedPermission p,
@PackageManager.ComponentInfoFlags int flags) {
if (p == null) return null;
diff --git a/core/java/android/content/pm/parsing/ParsingPackage.java b/core/java/android/content/pm/parsing/ParsingPackage.java
index 411c749..9ddcc09 100644
--- a/core/java/android/content/pm/parsing/ParsingPackage.java
+++ b/core/java/android/content/pm/parsing/ParsingPackage.java
@@ -31,6 +31,7 @@
import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
import android.content.pm.parsing.ComponentParseUtils.ParsedService;
import android.os.Bundle;
+import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.SparseArray;
@@ -99,6 +100,8 @@
ParsingPackage addQueriesPackage(String packageName);
+ ParsingPackage setProcesses(ArrayMap<String, ComponentParseUtils.ParsedProcess> processes);
+
ParsingPackage asSplit(
String[] splitNames,
String[] splitCodePaths,
diff --git a/core/java/android/hardware/soundtrigger/ConversionUtil.java b/core/java/android/hardware/soundtrigger/ConversionUtil.java
index d43a619..a30fd6b 100644
--- a/core/java/android/hardware/soundtrigger/ConversionUtil.java
+++ b/core/java/android/hardware/soundtrigger/ConversionUtil.java
@@ -130,7 +130,7 @@
aidlPhrase.id = apiPhrase.id;
aidlPhrase.recognitionModes = api2aidlRecognitionModes(apiPhrase.recognitionModes);
aidlPhrase.users = Arrays.copyOf(apiPhrase.users, apiPhrase.users.length);
- aidlPhrase.locale = apiPhrase.locale;
+ aidlPhrase.locale = apiPhrase.locale.toLanguageTag();
aidlPhrase.text = apiPhrase.text;
return aidlPhrase;
}
diff --git a/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java b/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java
index eb5d0cb..ef76c62 100644
--- a/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java
+++ b/core/java/android/hardware/soundtrigger/KeyphraseEnrollmentInfo.java
@@ -17,6 +17,7 @@
package android.hardware.soundtrigger;
import android.Manifest;
+import android.annotation.IntDef;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -24,7 +25,6 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
-import android.service.voice.AlwaysOnHotwordDetector;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.AttributeSet;
@@ -35,6 +35,8 @@
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
@@ -66,9 +68,10 @@
"com.android.intent.action.MANAGE_VOICE_KEYPHRASES";
/**
* Intent extra: The intent extra for the specific manage action that needs to be performed.
- * Possible values are {@link AlwaysOnHotwordDetector#MANAGE_ACTION_ENROLL},
- * {@link AlwaysOnHotwordDetector#MANAGE_ACTION_RE_ENROLL}
- * or {@link AlwaysOnHotwordDetector#MANAGE_ACTION_UN_ENROLL}.
+ *
+ * @see #MANAGE_ACTION_ENROLL
+ * @see #MANAGE_ACTION_RE_ENROLL
+ * @see #MANAGE_ACTION_UN_ENROLL
*/
public static final String EXTRA_VOICE_KEYPHRASE_ACTION =
"com.android.intent.extra.VOICE_KEYPHRASE_ACTION";
@@ -86,6 +89,31 @@
"com.android.intent.extra.VOICE_KEYPHRASE_LOCALE";
/**
+ * Keyphrase management actions used with the {@link #EXTRA_VOICE_KEYPHRASE_ACTION} intent extra
+ * @hide
+ */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(prefix = { "MANAGE_ACTION_" }, value = {
+ MANAGE_ACTION_ENROLL,
+ MANAGE_ACTION_RE_ENROLL,
+ MANAGE_ACTION_UN_ENROLL
+ })
+ public @interface ManageActions {}
+
+ /**
+ * Indicates desired action to enroll keyphrase model
+ */
+ public static final int MANAGE_ACTION_ENROLL = 0;
+ /**
+ * Indicates desired action to re-enroll keyphrase model
+ */
+ public static final int MANAGE_ACTION_RE_ENROLL = 1;
+ /**
+ * Indicates desired action to un-enroll keyphrase model
+ */
+ public static final int MANAGE_ACTION_UN_ENROLL = 2;
+
+ /**
* List of available keyphrases.
*/
final private KeyphraseMetadata[] mKeyphrases;
@@ -294,15 +322,13 @@
* for the locale.
*
* @param action The enrollment related action that this intent is supposed to perform.
- * This can be one of {@link AlwaysOnHotwordDetector#MANAGE_ACTION_ENROLL},
- * {@link AlwaysOnHotwordDetector#MANAGE_ACTION_RE_ENROLL}
- * or {@link AlwaysOnHotwordDetector#MANAGE_ACTION_UN_ENROLL}
* @param keyphrase The keyphrase that the user needs to be enrolled to.
* @param locale The locale for which the enrollment needs to be performed.
* @return An {@link Intent} to manage the keyphrase. This can be null if managing the
* given keyphrase/locale combination isn't possible.
*/
- public Intent getManageKeyphraseIntent(int action, String keyphrase, Locale locale) {
+ public Intent getManageKeyphraseIntent(@ManageActions int action, String keyphrase,
+ Locale locale) {
if (mKeyphrasePackageMap == null || mKeyphrasePackageMap.isEmpty()) {
Slog.w(TAG, "No enrollment application exists");
return null;
diff --git a/core/java/android/hardware/soundtrigger/KeyphraseMetadata.aidl b/core/java/android/hardware/soundtrigger/KeyphraseMetadata.aidl
new file mode 100644
index 0000000..7a5e932
--- /dev/null
+++ b/core/java/android/hardware/soundtrigger/KeyphraseMetadata.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (C) 2014 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.hardware.soundtrigger;
+
+parcelable KeyphraseMetadata;
diff --git a/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java b/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java
index ed8c296..15462de 100644
--- a/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java
+++ b/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java
@@ -16,8 +16,13 @@
package android.hardware.soundtrigger;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.Parcelable;
import android.util.ArraySet;
+import com.android.internal.util.DataClass;
+
import java.util.Locale;
/**
@@ -25,37 +30,168 @@
*
* @hide
*/
-public class KeyphraseMetadata {
+@DataClass(
+ genEqualsHashCode = true,
+ genToString = true,
+ genConstructor = false,
+ genHiddenConstDefs = true)
+public final class KeyphraseMetadata implements Parcelable {
public final int id;
+ @NonNull
public final String keyphrase;
+ @NonNull
public final ArraySet<Locale> supportedLocales;
public final int recognitionModeFlags;
- public KeyphraseMetadata(int id, String keyphrase, ArraySet<Locale> supportedLocales,
- int recognitionModeFlags) {
+ public KeyphraseMetadata(int id, @NonNull String keyphrase,
+ @NonNull ArraySet<Locale> supportedLocales, int recognitionModeFlags) {
this.id = id;
this.keyphrase = keyphrase;
this.supportedLocales = supportedLocales;
this.recognitionModeFlags = recognitionModeFlags;
}
- @Override
- public String toString() {
- return "id=" + id + ", keyphrase=" + keyphrase + ", supported-locales=" + supportedLocales
- + ", recognition-modes=" + recognitionModeFlags;
- }
-
/**
* @return Indicates if we support the given phrase.
*/
- public boolean supportsPhrase(String phrase) {
+ public boolean supportsPhrase(@Nullable String phrase) {
return keyphrase.isEmpty() || keyphrase.equalsIgnoreCase(phrase);
}
/**
* @return Indicates if we support the given locale.
*/
- public boolean supportsLocale(Locale locale) {
+ public boolean supportsLocale(@Nullable Locale locale) {
return supportedLocales.isEmpty() || supportedLocales.contains(locale);
}
+
+
+
+
+ // Code below generated by codegen v1.0.14.
+ //
+ // DO NOT MODIFY!
+ // CHECKSTYLE:OFF Generated code
+ //
+ // To regenerate run:
+ // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java
+ //
+ // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
+ // Settings > Editor > Code Style > Formatter Control
+ //@formatter:off
+
+
+ @Override
+ @DataClass.Generated.Member
+ public String toString() {
+ // You can override field toString logic by defining methods like:
+ // String fieldNameToString() { ... }
+
+ return "KeyphraseMetadata { " +
+ "id = " + id + ", " +
+ "keyphrase = " + keyphrase + ", " +
+ "supportedLocales = " + supportedLocales + ", " +
+ "recognitionModeFlags = " + recognitionModeFlags +
+ " }";
+ }
+
+ @Override
+ @DataClass.Generated.Member
+ public boolean equals(@Nullable Object o) {
+ // You can override field equality logic by defining either of the methods like:
+ // boolean fieldNameEquals(KeyphraseMetadata other) { ... }
+ // boolean fieldNameEquals(FieldType otherValue) { ... }
+
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ @SuppressWarnings("unchecked")
+ KeyphraseMetadata that = (KeyphraseMetadata) o;
+ //noinspection PointlessBooleanExpression
+ return true
+ && id == that.id
+ && java.util.Objects.equals(keyphrase, that.keyphrase)
+ && java.util.Objects.equals(supportedLocales, that.supportedLocales)
+ && recognitionModeFlags == that.recognitionModeFlags;
+ }
+
+ @Override
+ @DataClass.Generated.Member
+ public int hashCode() {
+ // You can override field hashCode logic by defining methods like:
+ // int fieldNameHashCode() { ... }
+
+ int _hash = 1;
+ _hash = 31 * _hash + id;
+ _hash = 31 * _hash + java.util.Objects.hashCode(keyphrase);
+ _hash = 31 * _hash + java.util.Objects.hashCode(supportedLocales);
+ _hash = 31 * _hash + recognitionModeFlags;
+ return _hash;
+ }
+
+ @Override
+ @DataClass.Generated.Member
+ public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
+ // You can override field parcelling by defining methods like:
+ // void parcelFieldName(Parcel dest, int flags) { ... }
+
+ dest.writeInt(id);
+ dest.writeString(keyphrase);
+ dest.writeArraySet(supportedLocales);
+ dest.writeInt(recognitionModeFlags);
+ }
+
+ @Override
+ @DataClass.Generated.Member
+ public int describeContents() { return 0; }
+
+ /** @hide */
+ @SuppressWarnings({"unchecked", "RedundantCast"})
+ @DataClass.Generated.Member
+ /* package-private */ KeyphraseMetadata(@NonNull android.os.Parcel in) {
+ // You can override field unparcelling by defining methods like:
+ // static FieldType unparcelFieldName(Parcel in) { ... }
+
+ int _id = in.readInt();
+ String _keyphrase = in.readString();
+ ArraySet<Locale> _supportedLocales = (ArraySet) in.readArraySet(null);
+ int _recognitionModeFlags = in.readInt();
+
+ this.id = _id;
+ this.keyphrase = _keyphrase;
+ com.android.internal.util.AnnotationValidations.validate(
+ NonNull.class, null, keyphrase);
+ this.supportedLocales = _supportedLocales;
+ com.android.internal.util.AnnotationValidations.validate(
+ NonNull.class, null, supportedLocales);
+ this.recognitionModeFlags = _recognitionModeFlags;
+
+ // onConstructed(); // You can define this method to get a callback
+ }
+
+ @DataClass.Generated.Member
+ public static final @NonNull Parcelable.Creator<KeyphraseMetadata> CREATOR
+ = new Parcelable.Creator<KeyphraseMetadata>() {
+ @Override
+ public KeyphraseMetadata[] newArray(int size) {
+ return new KeyphraseMetadata[size];
+ }
+
+ @Override
+ public KeyphraseMetadata createFromParcel(@NonNull android.os.Parcel in) {
+ return new KeyphraseMetadata(in);
+ }
+ };
+
+ @DataClass.Generated(
+ time = 1579290593964L,
+ codegenVersion = "1.0.14",
+ sourceFile = "frameworks/base/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java",
+ inputSignatures = "public final int id\npublic final @android.annotation.NonNull java.lang.String keyphrase\npublic final @android.annotation.NonNull android.util.ArraySet<java.util.Locale> supportedLocales\npublic final int recognitionModeFlags\npublic boolean supportsPhrase(java.lang.String)\npublic boolean supportsLocale(java.util.Locale)\nclass KeyphraseMetadata extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genConstructor=false, genHiddenConstDefs=true)")
+ @Deprecated
+ private void __metadata() {}
+
+
+ //@formatter:on
+ // End of generated code
+
}
diff --git a/core/java/android/hardware/soundtrigger/SoundTrigger.java b/core/java/android/hardware/soundtrigger/SoundTrigger.java
index 1932f46..d505ae5 100644
--- a/core/java/android/hardware/soundtrigger/SoundTrigger.java
+++ b/core/java/android/hardware/soundtrigger/SoundTrigger.java
@@ -49,6 +49,7 @@
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Locale;
import java.util.UUID;
/**
@@ -148,6 +149,7 @@
public final int maxUsers;
/** Supported recognition modes (bit field, RECOGNITION_MODE_VOICE_TRIGGER ...) */
+ @RecognitionModes
public final int recognitionModes;
/** Supports seamless transition to capture mode after recognition */
@@ -175,9 +177,9 @@
ModuleProperties(int id, @NonNull String implementor, @NonNull String description,
@NonNull String uuid, int version, @NonNull String supportedModelArch,
- int maxSoundModels, int maxKeyphrases, int maxUsers, int recognitionModes,
- boolean supportsCaptureTransition, int maxBufferMs,
- boolean supportsConcurrentCapture, int powerConsumptionMw,
+ int maxSoundModels, int maxKeyphrases, int maxUsers,
+ @RecognitionModes int recognitionModes, boolean supportsCaptureTransition,
+ int maxBufferMs, boolean supportsConcurrentCapture, int powerConsumptionMw,
boolean returnsTriggerInEvent, int audioCapabilities) {
this.id = id;
this.implementor = requireNonNull(implementor);
@@ -271,16 +273,27 @@
}
}
- /*****************************************************************************
+ /**
* A SoundModel describes the attributes and contains the binary data used by the hardware
* implementation to detect a particular sound pattern.
* A specialized version {@link KeyphraseSoundModel} is defined for key phrase
* sound models.
- *
- * @hide
- ****************************************************************************/
+ */
public static class SoundModel {
- /** Undefined sound model type */
+
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ TYPE_GENERIC_SOUND,
+ TYPE_KEYPHRASE,
+ TYPE_UNKNOWN,
+ })
+ public @interface SoundModelType {}
+
+ /**
+ * Undefined sound model type
+ * @hide
+ */
public static final int TYPE_UNKNOWN = -1;
/** Keyphrase sound model */
@@ -293,15 +306,14 @@
public static final int TYPE_GENERIC_SOUND = 1;
/** Unique sound model identifier */
- @UnsupportedAppUsage
@NonNull
public final UUID uuid;
/** Sound model type (e.g. TYPE_KEYPHRASE); */
+ @SoundModelType
public final int type;
/** Unique sound model vendor identifier */
- @UnsupportedAppUsage
@NonNull
public final UUID vendorUuid;
@@ -309,11 +321,11 @@
public final int version;
/** Opaque data. For use by vendor implementation and enrollment application */
- @UnsupportedAppUsage
@NonNull
public final byte[] data;
- public SoundModel(@NonNull UUID uuid, @Nullable UUID vendorUuid, int type,
+ /** @hide */
+ public SoundModel(@NonNull UUID uuid, @Nullable UUID vendorUuid, @SoundModelType int type,
@Nullable byte[] data, int version) {
this.uuid = requireNonNull(uuid);
this.vendorUuid = vendorUuid != null ? vendorUuid : new UUID(0, 0);
@@ -336,67 +348,90 @@
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (!(obj instanceof SoundModel))
+ }
+ if (!(obj instanceof SoundModel)) {
return false;
+ }
SoundModel other = (SoundModel) obj;
- if (type != other.type)
+ if (type != other.type) {
return false;
+ }
if (uuid == null) {
- if (other.uuid != null)
+ if (other.uuid != null) {
return false;
- } else if (!uuid.equals(other.uuid))
+ }
+ } else if (!uuid.equals(other.uuid)) {
return false;
+ }
if (vendorUuid == null) {
- if (other.vendorUuid != null)
+ if (other.vendorUuid != null) {
return false;
- } else if (!vendorUuid.equals(other.vendorUuid))
+ }
+ } else if (!vendorUuid.equals(other.vendorUuid)) {
return false;
- if (!Arrays.equals(data, other.data))
+ }
+ if (!Arrays.equals(data, other.data)) {
return false;
- if (version != other.version)
+ }
+ if (version != other.version) {
return false;
+ }
return true;
}
}
- /*****************************************************************************
+ /**
* A Keyphrase describes a key phrase that can be detected by a
* {@link KeyphraseSoundModel}
- *
- * @hide
- ****************************************************************************/
- public static class Keyphrase implements Parcelable {
+ */
+ public static final class Keyphrase implements Parcelable {
/** Unique identifier for this keyphrase */
- @UnsupportedAppUsage
public final int id;
- /** Recognition modes supported for this key phrase in the model */
- @UnsupportedAppUsage
+ /**
+ * Recognition modes supported for this key phrase in the model
+ *
+ * @see #RECOGNITION_MODE_VOICE_TRIGGER
+ * @see #RECOGNITION_MODE_USER_IDENTIFICATION
+ * @see #RECOGNITION_MODE_USER_AUTHENTICATION
+ * @see #RECOGNITION_MODE_GENERIC
+ */
+ @RecognitionModes
public final int recognitionModes;
- /** Locale of the keyphrase. JAVA Locale string e.g en_US */
- @UnsupportedAppUsage
+ /** Locale of the keyphrase. */
@NonNull
- public final String locale;
+ public final Locale locale;
/** Key phrase text */
- @UnsupportedAppUsage
@NonNull
public final String text;
- /** Users this key phrase has been trained for. countains sound trigger specific user IDs
- * derived from system user IDs {@link android.os.UserHandle#getIdentifier()}. */
- @UnsupportedAppUsage
+ /**
+ * Users this key phrase has been trained for. countains sound trigger specific user IDs
+ * derived from system user IDs {@link android.os.UserHandle#getIdentifier()}.
+ */
@NonNull
public final int[] users;
- @UnsupportedAppUsage
- public Keyphrase(int id, int recognitionModes, @NonNull String locale, @NonNull String text,
- @Nullable int[] users) {
+ /**
+ * Constructor for Keyphrase describes a key phrase that can be detected by a
+ * {@link KeyphraseSoundModel}
+ *
+ * @param id Unique keyphrase identifier for this keyphrase
+ * @param recognitionModes Bit field representation of recognition modes this keyphrase
+ * supports
+ * @param locale Locale of the keyphrase
+ * @param text Key phrase text
+ * @param users Users this key phrase has been trained for.
+ */
+ public Keyphrase(int id, @RecognitionModes int recognitionModes, @NonNull Locale locale,
+ @NonNull String text, @Nullable int[] users) {
this.id = id;
this.recognitionModes = recognitionModes;
this.locale = requireNonNull(locale);
@@ -404,21 +439,27 @@
this.users = users != null ? users : new int[0];
}
- public static final @android.annotation.NonNull Parcelable.Creator<Keyphrase> CREATOR
- = new Parcelable.Creator<Keyphrase>() {
- public Keyphrase createFromParcel(Parcel in) {
- return Keyphrase.fromParcel(in);
+ public static final @NonNull Parcelable.Creator<Keyphrase> CREATOR =
+ new Parcelable.Creator<Keyphrase>() {
+ @NonNull
+ public Keyphrase createFromParcel(@NonNull Parcel in) {
+ return Keyphrase.readFromParcel(in);
}
+ @NonNull
public Keyphrase[] newArray(int size) {
return new Keyphrase[size];
}
};
- private static Keyphrase fromParcel(Parcel in) {
+ /**
+ * Read from Parcel to generate keyphrase
+ */
+ @NonNull
+ public static Keyphrase readFromParcel(@NonNull Parcel in) {
int id = in.readInt();
int recognitionModes = in.readInt();
- String locale = in.readString();
+ Locale locale = Locale.forLanguageTag(in.readString());
String text = in.readString();
int[] users = null;
int numUsers = in.readInt();
@@ -430,10 +471,10 @@
}
@Override
- public void writeToParcel(Parcel dest, int flags) {
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(id);
dest.writeInt(recognitionModes);
- dest.writeString(locale);
+ dest.writeString(locale.toLanguageTag());
dest.writeString(text);
if (users != null) {
dest.writeInt(users.length);
@@ -443,6 +484,7 @@
}
}
+ /** @hide */
@Override
public int describeContents() {
return 0;
@@ -462,49 +504,57 @@
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Keyphrase other = (Keyphrase) obj;
if (text == null) {
- if (other.text != null)
+ if (other.text != null) {
return false;
- } else if (!text.equals(other.text))
+ }
+ } else if (!text.equals(other.text)) {
return false;
- if (id != other.id)
+ }
+ if (id != other.id) {
return false;
+ }
if (locale == null) {
- if (other.locale != null)
+ if (other.locale != null) {
return false;
- } else if (!locale.equals(other.locale))
+ }
+ } else if (!locale.equals(other.locale)) {
return false;
- if (recognitionModes != other.recognitionModes)
+ }
+ if (recognitionModes != other.recognitionModes) {
return false;
- if (!Arrays.equals(users, other.users))
+ }
+ if (!Arrays.equals(users, other.users)) {
return false;
+ }
return true;
}
@Override
public String toString() {
- return "Keyphrase [id=" + id + ", recognitionModes=" + recognitionModes + ", locale="
- + locale + ", text=" + text + ", users=" + Arrays.toString(users) + "]";
+ return "Keyphrase [id=" + id + ", recognitionModes=" + recognitionModes
+ + ", locale=" + locale.toLanguageTag() + ", text=" + text
+ + ", users=" + Arrays.toString(users) + "]";
}
}
- /*****************************************************************************
+ /**
* A KeyphraseSoundModel is a specialized {@link SoundModel} for key phrases.
* It contains data needed by the hardware to detect a certain number of key phrases
* and the list of corresponding {@link Keyphrase} descriptors.
- *
- * @hide
- ****************************************************************************/
- public static class KeyphraseSoundModel extends SoundModel implements Parcelable {
+ */
+ public static final class KeyphraseSoundModel extends SoundModel implements Parcelable {
/** Key phrases in this sound model */
- @UnsupportedAppUsage
@NonNull
public final Keyphrase[] keyphrases; // keyword phrases in model
@@ -515,24 +565,29 @@
this.keyphrases = keyphrases != null ? keyphrases : new Keyphrase[0];
}
- @UnsupportedAppUsage
public KeyphraseSoundModel(@NonNull UUID uuid, @NonNull UUID vendorUuid,
@Nullable byte[] data, @Nullable Keyphrase[] keyphrases) {
this(uuid, vendorUuid, data, keyphrases, -1);
}
- public static final @android.annotation.NonNull Parcelable.Creator<KeyphraseSoundModel> CREATOR
- = new Parcelable.Creator<KeyphraseSoundModel>() {
- public KeyphraseSoundModel createFromParcel(Parcel in) {
- return KeyphraseSoundModel.fromParcel(in);
+ public static final @NonNull Parcelable.Creator<KeyphraseSoundModel> CREATOR =
+ new Parcelable.Creator<KeyphraseSoundModel>() {
+ @NonNull
+ public KeyphraseSoundModel createFromParcel(@NonNull Parcel in) {
+ return KeyphraseSoundModel.readFromParcel(in);
}
+ @NonNull
public KeyphraseSoundModel[] newArray(int size) {
return new KeyphraseSoundModel[size];
}
};
- private static KeyphraseSoundModel fromParcel(Parcel in) {
+ /**
+ * Read from Parcel to generate KeyphraseSoundModel
+ */
+ @NonNull
+ public static KeyphraseSoundModel readFromParcel(@NonNull Parcel in) {
UUID uuid = UUID.fromString(in.readString());
UUID vendorUuid = null;
int length = in.readInt();
@@ -545,13 +600,14 @@
return new KeyphraseSoundModel(uuid, vendorUuid, data, keyphrases, version);
}
+ /** @hide */
@Override
public int describeContents() {
return 0;
}
@Override
- public void writeToParcel(Parcel dest, int flags) {
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(uuid.toString());
if (vendorUuid == null) {
dest.writeInt(-1);
@@ -583,15 +639,19 @@
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (!(obj instanceof KeyphraseSoundModel))
+ }
+ if (!(obj instanceof KeyphraseSoundModel)) {
return false;
+ }
KeyphraseSoundModel other = (KeyphraseSoundModel) obj;
- if (!Arrays.equals(keyphrases, other.keyphrases))
+ if (!Arrays.equals(keyphrases, other.keyphrases)) {
return false;
+ }
return true;
}
}
@@ -760,31 +820,32 @@
}
/**
- * Modes for key phrase recognition
+ * Modes for key phrase recognition
+ * @hide
*/
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(flag = true, prefix = { "RECOGNITION_MODE_" }, value = {
+ RECOGNITION_MODE_VOICE_TRIGGER,
+ RECOGNITION_MODE_USER_IDENTIFICATION,
+ RECOGNITION_MODE_USER_AUTHENTICATION,
+ RECOGNITION_MODE_GENERIC
+ })
+ public @interface RecognitionModes {}
/**
- * Simple recognition of the key phrase
- *
- * @hide
+ * Trigger on recognition of a key phrase
*/
public static final int RECOGNITION_MODE_VOICE_TRIGGER = 0x1;
/**
* Trigger only if one user is identified
- *
- * @hide
*/
public static final int RECOGNITION_MODE_USER_IDENTIFICATION = 0x2;
/**
* Trigger only if one user is authenticated
- *
- * @hide
*/
public static final int RECOGNITION_MODE_USER_AUTHENTICATION = 0x4;
/**
* Generic (non-speech) recognition.
- *
- * @hide
*/
public static final int RECOGNITION_MODE_GENERIC = 0x8;
diff --git a/core/java/android/net/ConnectivityDiagnosticsManager.aidl b/core/java/android/net/ConnectivityDiagnosticsManager.aidl
new file mode 100644
index 0000000..82ba0ca
--- /dev/null
+++ b/core/java/android/net/ConnectivityDiagnosticsManager.aidl
@@ -0,0 +1,21 @@
+/**
+ *
+ * Copyright (C) 2020 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.net;
+
+parcelable ConnectivityDiagnosticsManager.ConnectivityReport;
+parcelable ConnectivityDiagnosticsManager.DataStallReport;
\ No newline at end of file
diff --git a/core/java/android/net/ConnectivityDiagnosticsManager.java b/core/java/android/net/ConnectivityDiagnosticsManager.java
index 6afdb5e..a6f9b96 100644
--- a/core/java/android/net/ConnectivityDiagnosticsManager.java
+++ b/core/java/android/net/ConnectivityDiagnosticsManager.java
@@ -18,10 +18,18 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.os.PersistableBundle;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.Preconditions;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -47,38 +55,47 @@
* </ul>
*/
public class ConnectivityDiagnosticsManager {
- public static final int DETECTION_METHOD_DNS_EVENTS = 1;
- public static final int DETECTION_METHOD_TCP_METRICS = 2;
+ private final Context mContext;
+ private final IConnectivityManager mService;
/** @hide */
- @Retention(RetentionPolicy.SOURCE)
- @IntDef(
- prefix = {"DETECTION_METHOD_"},
- value = {DETECTION_METHOD_DNS_EVENTS, DETECTION_METHOD_TCP_METRICS})
- public @interface DetectionMethod {}
+ public ConnectivityDiagnosticsManager(Context context, IConnectivityManager service) {
+ mContext = Preconditions.checkNotNull(context, "missing context");
+ mService = Preconditions.checkNotNull(service, "missing IConnectivityManager");
+ }
/** @hide */
- public ConnectivityDiagnosticsManager() {}
+ @VisibleForTesting
+ public static boolean persistableBundleEquals(
+ @Nullable PersistableBundle a, @Nullable PersistableBundle b) {
+ if (a == b) return true;
+ if (a == null || b == null) return false;
+ if (!Objects.equals(a.keySet(), b.keySet())) return false;
+ for (String key : a.keySet()) {
+ if (!Objects.equals(a.get(key), b.get(key))) return false;
+ }
+ return true;
+ }
/** Class that includes connectivity information for a specific Network at a specific time. */
- public static class ConnectivityReport {
+ public static final class ConnectivityReport implements Parcelable {
/** The Network for which this ConnectivityReport applied */
- @NonNull public final Network network;
+ @NonNull private final Network mNetwork;
/**
* The timestamp for the report. The timestamp is taken from {@link
* System#currentTimeMillis}.
*/
- public final long reportTimestamp;
+ private final long mReportTimestamp;
/** LinkProperties available on the Network at the reported timestamp */
- @NonNull public final LinkProperties linkProperties;
+ @NonNull private final LinkProperties mLinkProperties;
/** NetworkCapabilities available on the Network at the reported timestamp */
- @NonNull public final NetworkCapabilities networkCapabilities;
+ @NonNull private final NetworkCapabilities mNetworkCapabilities;
/** PersistableBundle that may contain additional info about the report */
- @NonNull public final PersistableBundle additionalInfo;
+ @NonNull private final PersistableBundle mAdditionalInfo;
/**
* Constructor for ConnectivityReport.
@@ -101,30 +118,148 @@
@NonNull LinkProperties linkProperties,
@NonNull NetworkCapabilities networkCapabilities,
@NonNull PersistableBundle additionalInfo) {
- this.network = network;
- this.reportTimestamp = reportTimestamp;
- this.linkProperties = linkProperties;
- this.networkCapabilities = networkCapabilities;
- this.additionalInfo = additionalInfo;
+ mNetwork = network;
+ mReportTimestamp = reportTimestamp;
+ mLinkProperties = linkProperties;
+ mNetworkCapabilities = networkCapabilities;
+ mAdditionalInfo = additionalInfo;
}
+
+ /**
+ * Returns the Network for this ConnectivityReport.
+ *
+ * @return The Network for which this ConnectivityReport applied
+ */
+ @NonNull
+ public Network getNetwork() {
+ return mNetwork;
+ }
+
+ /**
+ * Returns the epoch timestamp (milliseconds) for when this report was taken.
+ *
+ * @return The timestamp for the report. Taken from {@link System#currentTimeMillis}.
+ */
+ public long getReportTimestamp() {
+ return mReportTimestamp;
+ }
+
+ /**
+ * Returns the LinkProperties available when this report was taken.
+ *
+ * @return LinkProperties available on the Network at the reported timestamp
+ */
+ @NonNull
+ public LinkProperties getLinkProperties() {
+ return new LinkProperties(mLinkProperties);
+ }
+
+ /**
+ * Returns the NetworkCapabilities when this report was taken.
+ *
+ * @return NetworkCapabilities available on the Network at the reported timestamp
+ */
+ @NonNull
+ public NetworkCapabilities getNetworkCapabilities() {
+ return new NetworkCapabilities(mNetworkCapabilities);
+ }
+
+ /**
+ * Returns a PersistableBundle with additional info for this report.
+ *
+ * @return PersistableBundle that may contain additional info about the report
+ */
+ @NonNull
+ public PersistableBundle getAdditionalInfo() {
+ return new PersistableBundle(mAdditionalInfo);
+ }
+
+ @Override
+ public boolean equals(@Nullable Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ConnectivityReport)) return false;
+ final ConnectivityReport that = (ConnectivityReport) o;
+
+ // PersistableBundle is optimized to avoid unparcelling data unless fields are
+ // referenced. Because of this, use {@link ConnectivityDiagnosticsManager#equals} over
+ // {@link PersistableBundle#kindofEquals}.
+ return mReportTimestamp == that.mReportTimestamp
+ && mNetwork.equals(that.mNetwork)
+ && mLinkProperties.equals(that.mLinkProperties)
+ && mNetworkCapabilities.equals(that.mNetworkCapabilities)
+ && persistableBundleEquals(mAdditionalInfo, that.mAdditionalInfo);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ mNetwork,
+ mReportTimestamp,
+ mLinkProperties,
+ mNetworkCapabilities,
+ mAdditionalInfo);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeParcelable(mNetwork, flags);
+ dest.writeLong(mReportTimestamp);
+ dest.writeParcelable(mLinkProperties, flags);
+ dest.writeParcelable(mNetworkCapabilities, flags);
+ dest.writeParcelable(mAdditionalInfo, flags);
+ }
+
+ /** Implement the Parcelable interface */
+ public static final @NonNull Creator<ConnectivityReport> CREATOR =
+ new Creator<>() {
+ public ConnectivityReport createFromParcel(Parcel in) {
+ return new ConnectivityReport(
+ in.readParcelable(null),
+ in.readLong(),
+ in.readParcelable(null),
+ in.readParcelable(null),
+ in.readParcelable(null));
+ }
+
+ public ConnectivityReport[] newArray(int size) {
+ return new ConnectivityReport[size];
+ }
+ };
}
/** Class that includes information for a suspected data stall on a specific Network */
- public static class DataStallReport {
+ public static final class DataStallReport implements Parcelable {
+ public static final int DETECTION_METHOD_DNS_EVENTS = 1;
+ public static final int DETECTION_METHOD_TCP_METRICS = 2;
+
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(
+ prefix = {"DETECTION_METHOD_"},
+ value = {DETECTION_METHOD_DNS_EVENTS, DETECTION_METHOD_TCP_METRICS})
+ public @interface DetectionMethod {}
+
/** The Network for which this DataStallReport applied */
- @NonNull public final Network network;
+ @NonNull private final Network mNetwork;
/**
* The timestamp for the report. The timestamp is taken from {@link
* System#currentTimeMillis}.
*/
- public final long reportTimestamp;
+ private long mReportTimestamp;
/** The detection method used to identify the suspected data stall */
- @DetectionMethod public final int detectionMethod;
+ @DetectionMethod private final int mDetectionMethod;
/** PersistableBundle that may contain additional information on the suspected data stall */
- @NonNull public final PersistableBundle stallDetails;
+ @NonNull private final PersistableBundle mStallDetails;
/**
* Constructor for DataStallReport.
@@ -143,11 +278,101 @@
long reportTimestamp,
@DetectionMethod int detectionMethod,
@NonNull PersistableBundle stallDetails) {
- this.network = network;
- this.reportTimestamp = reportTimestamp;
- this.detectionMethod = detectionMethod;
- this.stallDetails = stallDetails;
+ mNetwork = network;
+ mReportTimestamp = reportTimestamp;
+ mDetectionMethod = detectionMethod;
+ mStallDetails = stallDetails;
}
+
+ /**
+ * Returns the Network for this DataStallReport.
+ *
+ * @return The Network for which this DataStallReport applied
+ */
+ @NonNull
+ public Network getNetwork() {
+ return mNetwork;
+ }
+
+ /**
+ * Returns the epoch timestamp (milliseconds) for when this report was taken.
+ *
+ * @return The timestamp for the report. Taken from {@link System#currentTimeMillis}.
+ */
+ public long getReportTimestamp() {
+ return mReportTimestamp;
+ }
+
+ /**
+ * Returns the detection method used to identify this suspected data stall.
+ *
+ * @return The detection method used to identify the suspected data stall
+ */
+ public int getDetectionMethod() {
+ return mDetectionMethod;
+ }
+
+ /**
+ * Returns a PersistableBundle with additional info for this report.
+ *
+ * @return PersistableBundle that may contain additional information on the suspected data
+ * stall
+ */
+ @NonNull
+ public PersistableBundle getStallDetails() {
+ return new PersistableBundle(mStallDetails);
+ }
+
+ @Override
+ public boolean equals(@Nullable Object o) {
+ if (this == o) return true;
+ if (!(o instanceof DataStallReport)) return false;
+ final DataStallReport that = (DataStallReport) o;
+
+ // PersistableBundle is optimized to avoid unparcelling data unless fields are
+ // referenced. Because of this, use {@link ConnectivityDiagnosticsManager#equals} over
+ // {@link PersistableBundle#kindofEquals}.
+ return mReportTimestamp == that.mReportTimestamp
+ && mDetectionMethod == that.mDetectionMethod
+ && mNetwork.equals(that.mNetwork)
+ && persistableBundleEquals(mStallDetails, that.mStallDetails);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mNetwork, mReportTimestamp, mDetectionMethod, mStallDetails);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeParcelable(mNetwork, flags);
+ dest.writeLong(mReportTimestamp);
+ dest.writeInt(mDetectionMethod);
+ dest.writeParcelable(mStallDetails, flags);
+ }
+
+ /** Implement the Parcelable interface */
+ public static final @NonNull Creator<DataStallReport> CREATOR =
+ new Creator<DataStallReport>() {
+ public DataStallReport createFromParcel(Parcel in) {
+ return new DataStallReport(
+ in.readParcelable(null),
+ in.readLong(),
+ in.readInt(),
+ in.readParcelable(null));
+ }
+
+ public DataStallReport[] newArray(int size) {
+ return new DataStallReport[size];
+ }
+ };
}
/**
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 8ba3131..753e754 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -33,6 +33,7 @@
import android.content.Intent;
import android.net.IpSecManager.UdpEncapsulationSocket;
import android.net.SocketKeepalive.Callback;
+import android.net.TetheringManager.TetheringEventCallback;
import android.os.Binder;
import android.os.Build;
import android.os.Build.VERSION_CODES;
@@ -58,6 +59,7 @@
import android.util.Log;
import android.util.SparseIntArray;
+import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Protocol;
@@ -75,6 +77,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -484,34 +487,35 @@
* enable if any.
* @hide
*/
- public static final String EXTRA_ADD_TETHER_TYPE = TetheringManager.EXTRA_ADD_TETHER_TYPE;
+ public static final String EXTRA_ADD_TETHER_TYPE = TetheringConstants.EXTRA_ADD_TETHER_TYPE;
/**
* Extra used for communicating with the TetherService. Includes the type of tethering for
* which to cancel provisioning.
* @hide
*/
- public static final String EXTRA_REM_TETHER_TYPE = TetheringManager.EXTRA_REM_TETHER_TYPE;
+ public static final String EXTRA_REM_TETHER_TYPE = TetheringConstants.EXTRA_REM_TETHER_TYPE;
/**
* Extra used for communicating with the TetherService. True to schedule a recheck of tether
* provisioning.
* @hide
*/
- public static final String EXTRA_SET_ALARM = TetheringManager.EXTRA_SET_ALARM;
+ public static final String EXTRA_SET_ALARM = TetheringConstants.EXTRA_SET_ALARM;
/**
* Tells the TetherService to run a provision check now.
* @hide
*/
- public static final String EXTRA_RUN_PROVISION = TetheringManager.EXTRA_RUN_PROVISION;
+ public static final String EXTRA_RUN_PROVISION = TetheringConstants.EXTRA_RUN_PROVISION;
/**
* Extra used for communicating with the TetherService. Contains the {@link ResultReceiver}
* which will receive provisioning results. Can be left empty.
* @hide
*/
- public static final String EXTRA_PROVISION_CALLBACK = TetheringManager.EXTRA_PROVISION_CALLBACK;
+ public static final String EXTRA_PROVISION_CALLBACK =
+ TetheringConstants.EXTRA_PROVISION_CALLBACK;
/**
* The absence of a connection type.
@@ -2368,10 +2372,12 @@
*
* @return an array of 0 or more Strings of tetherable interface names.
*
+ * @deprecated Use {@link TetheringEventCallback#onTetherableInterfacesChanged(List)} instead.
* {@hide}
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage
+ @Deprecated
public String[] getTetherableIfaces() {
return getTetheringManager().getTetherableIfaces();
}
@@ -2381,10 +2387,12 @@
*
* @return an array of 0 or more String of currently tethered interface names.
*
+ * @deprecated Use {@link TetheringEventCallback#onTetherableInterfacesChanged(List)} instead.
* {@hide}
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage
+ @Deprecated
public String[] getTetheredIfaces() {
return getTetheringManager().getTetheredIfaces();
}
@@ -2400,10 +2408,12 @@
* @return an array of 0 or more String indicating the interface names
* which failed to tether.
*
+ * @deprecated Use {@link TetheringEventCallback#onError(String, int)} instead.
* {@hide}
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage
+ @Deprecated
public String[] getTetheringErroredIfaces() {
return getTetheringManager().getTetheringErroredIfaces();
}
@@ -2412,9 +2422,11 @@
* Get the set of tethered dhcp ranges.
*
* @return an array of 0 or more {@code String} of tethered dhcp ranges.
+ * @deprecated This API just return the default value which is not used in DhcpServer.
* {@hide}
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
+ @Deprecated
public String[] getTetheredDhcpRanges() {
return getTetheringManager().getTetheredDhcpRanges();
}
@@ -2467,6 +2479,7 @@
* {@hide}
*/
@UnsupportedAppUsage
+ @Deprecated
public int untether(String iface) {
return getTetheringManager().untether(iface);
}
@@ -2487,6 +2500,7 @@
*
* @return a boolean - {@code true} indicating Tethering is supported.
*
+ * @deprecated Use {@link TetheringEventCallback#onTetheringSupported(boolean)} instead.
* {@hide}
*/
@SystemApi
@@ -2573,9 +2587,12 @@
* {@link ConnectivityManager.TETHERING_WIFI},
* {@link ConnectivityManager.TETHERING_USB}, or
* {@link ConnectivityManager.TETHERING_BLUETOOTH}.
+ *
+ * @deprecated Use {@link TetheringManager#stopTethering} instead.
* @hide
*/
@SystemApi
+ @Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void stopTethering(int type) {
getTetheringManager().stopTethering(type);
@@ -2585,9 +2602,11 @@
* Callback for use with {@link registerTetheringEventCallback} to find out tethering
* upstream status.
*
- *@hide
+ * @deprecated Use {@line TetheringManager#OnTetheringEventCallback} instead.
+ * @hide
*/
@SystemApi
+ @Deprecated
public abstract static class OnTetheringEventCallback {
/**
@@ -2600,6 +2619,10 @@
public void onUpstreamChanged(@Nullable Network network) {}
}
+ @GuardedBy("mTetheringEventCallbacks")
+ private final ArrayMap<OnTetheringEventCallback, TetheringEventCallback>
+ mTetheringEventCallbacks = new ArrayMap<>();
+
/**
* Start listening to tethering change events. Any new added callback will receive the last
* tethering status right away. If callback is registered when tethering has no upstream or
@@ -2608,16 +2631,30 @@
*
* @param executor the executor on which callback will be invoked.
* @param callback the callback to be called when tethering has change events.
+ *
+ * @deprecated Use {@line TetheringManager#registerTetheringEventCallback} instead.
* @hide
*/
@SystemApi
+ @Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void registerTetheringEventCallback(
@NonNull @CallbackExecutor Executor executor,
@NonNull final OnTetheringEventCallback callback) {
Preconditions.checkNotNull(callback, "OnTetheringEventCallback cannot be null.");
- getTetheringManager().registerTetheringEventCallback(executor, callback);
+ final TetheringEventCallback tetherCallback =
+ new TetheringEventCallback() {
+ @Override
+ public void onUpstreamChanged(@Nullable Network network) {
+ callback.onUpstreamChanged(network);
+ }
+ };
+
+ synchronized (mTetheringEventCallbacks) {
+ mTetheringEventCallbacks.put(callback, tetherCallback);
+ getTetheringManager().registerTetheringEventCallback(executor, tetherCallback);
+ }
}
/**
@@ -2625,13 +2662,21 @@
* {@link #registerTetheringEventCallback}.
*
* @param callback previously registered callback.
+ *
+ * @deprecated Use {@link TetheringManager#unregisterTetheringEventCallback} instead.
* @hide
*/
@SystemApi
+ @Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void unregisterTetheringEventCallback(
@NonNull final OnTetheringEventCallback callback) {
- getTetheringManager().unregisterTetheringEventCallback(callback);
+ Objects.requireNonNull(callback, "The callback must be non-null");
+ synchronized (mTetheringEventCallbacks) {
+ final TetheringEventCallback tetherCallback =
+ mTetheringEventCallbacks.remove(callback);
+ getTetheringManager().unregisterTetheringEventCallback(tetherCallback);
+ }
}
@@ -2643,10 +2688,12 @@
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable usb interfaces.
*
+ * @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged} instead.
* {@hide}
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage
+ @Deprecated
public String[] getTetherableUsbRegexs() {
return getTetheringManager().getTetherableUsbRegexs();
}
@@ -2659,10 +2706,12 @@
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable wifi interfaces.
*
+ * @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged} instead.
* {@hide}
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage
+ @Deprecated
public String[] getTetherableWifiRegexs() {
return getTetheringManager().getTetherableWifiRegexs();
}
@@ -2675,10 +2724,13 @@
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable bluetooth interfaces.
*
+ * @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged(
+ *TetheringManager.TetheringInterfaceRegexps)} instead.
* {@hide}
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage
+ @Deprecated
public String[] getTetherableBluetoothRegexs() {
return getTetheringManager().getTetherableBluetoothRegexs();
}
@@ -2705,37 +2757,104 @@
return getTetheringManager().setUsbTethering(enable);
}
- /** {@hide} */
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_NO_ERROR}.
+ * {@hide}
+ */
@SystemApi
- public static final int TETHER_ERROR_NO_ERROR = 0;
- /** {@hide} */
- public static final int TETHER_ERROR_UNKNOWN_IFACE = 1;
- /** {@hide} */
- public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2;
- /** {@hide} */
- public static final int TETHER_ERROR_UNSUPPORTED = 3;
- /** {@hide} */
- public static final int TETHER_ERROR_UNAVAIL_IFACE = 4;
- /** {@hide} */
- public static final int TETHER_ERROR_MASTER_ERROR = 5;
- /** {@hide} */
- public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
- /** {@hide} */
- public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
- /** {@hide} */
- public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8;
- /** {@hide} */
- public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9;
- /** {@hide} */
- public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10;
- /** {@hide} */
+ @Deprecated
+ public static final int TETHER_ERROR_NO_ERROR = TetheringManager.TETHER_ERROR_NO_ERROR;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNKNOWN_IFACE}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_UNKNOWN_IFACE =
+ TetheringManager.TETHER_ERROR_UNKNOWN_IFACE;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_SERVICE_UNAVAIL}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_SERVICE_UNAVAIL =
+ TetheringManager.TETHER_ERROR_SERVICE_UNAVAIL;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNSUPPORTED}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_UNSUPPORTED = TetheringManager.TETHER_ERROR_UNSUPPORTED;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNAVAIL_IFACE}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_UNAVAIL_IFACE =
+ TetheringManager.TETHER_ERROR_UNAVAIL_IFACE;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_MASTER_ERROR}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_MASTER_ERROR = TetheringManager.TETHER_ERROR_MASTER_ERROR;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_TETHER_IFACE_ERROR}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_TETHER_IFACE_ERROR =
+ TetheringManager.TETHER_ERROR_TETHER_IFACE_ERROR;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNTETHER_IFACE_ERROR}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR =
+ TetheringManager.TETHER_ERROR_UNTETHER_IFACE_ERROR;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_ENABLE_NAT_ERROR}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_ENABLE_NAT_ERROR =
+ TetheringManager.TETHER_ERROR_ENABLE_NAT_ERROR;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_DISABLE_NAT_ERROR}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_DISABLE_NAT_ERROR =
+ TetheringManager.TETHER_ERROR_DISABLE_NAT_ERROR;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_IFACE_CFG_ERROR}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_IFACE_CFG_ERROR =
+ TetheringManager.TETHER_ERROR_IFACE_CFG_ERROR;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_PROVISION_FAILED}.
+ * {@hide}
+ */
@SystemApi
- public static final int TETHER_ERROR_PROVISION_FAILED = 11;
- /** {@hide} */
- public static final int TETHER_ERROR_DHCPSERVER_ERROR = 12;
- /** {@hide} */
+ @Deprecated
+ public static final int TETHER_ERROR_PROVISION_FAILED =
+ TetheringManager.TETHER_ERROR_PROVISION_FAILED;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_DHCPSERVER_ERROR}.
+ * {@hide}
+ */
+ @Deprecated
+ public static final int TETHER_ERROR_DHCPSERVER_ERROR =
+ TetheringManager.TETHER_ERROR_DHCPSERVER_ERROR;
+ /**
+ * @deprecated Use {@link TetheringManager#TETHER_ERROR_ENTITLEMENT_UNKNOWN}.
+ * {@hide}
+ */
@SystemApi
- public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN = 13;
+ @Deprecated
+ public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN =
+ TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN;
/**
* Get a more detailed error code after a Tethering or Untethering
@@ -2745,10 +2864,12 @@
* @return error The error code of the last error tethering or untethering the named
* interface
*
+ * @deprecated Use {@link TetheringEventCallback#onError(String, int)} instead.
* {@hide}
*/
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage
+ @Deprecated
public int getLastTetherError(String iface) {
return getTetheringManager().getLastTetherError(iface);
}
@@ -2766,9 +2887,12 @@
/**
* Callback for use with {@link #getLatestTetheringEntitlementResult} to find out whether
* entitlement succeeded.
+ *
+ * @deprecated Use {@link TetheringManager#OnTetheringEntitlementResultListener} instead.
* @hide
*/
@SystemApi
+ @Deprecated
public interface OnTetheringEntitlementResultListener {
/**
* Called to notify entitlement result.
@@ -2798,9 +2922,11 @@
* @param listener an {@link OnTetheringEntitlementResultListener} which will be called to
* notify the caller of the result of entitlement check. The listener may be called zero
* or one time.
+ * @deprecated Use {@link TetheringManager#requestLatestTetheringEntitlementResult} instead.
* {@hide}
*/
@SystemApi
+ @Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void getLatestTetheringEntitlementResult(int type, boolean showEntitlementUi,
@NonNull @CallbackExecutor Executor executor,
diff --git a/core/java/android/net/NetworkAgent.java b/core/java/android/net/NetworkAgent.java
index 7cc78f7..7cc569a 100644
--- a/core/java/android/net/NetworkAgent.java
+++ b/core/java/android/net/NetworkAgent.java
@@ -304,7 +304,10 @@
private static NetworkInfo getLegacyNetworkInfo(final NetworkAgentConfig config) {
// The subtype can be changed with (TODO) setLegacySubtype, but it starts
// with the type and an empty description.
- return new NetworkInfo(config.legacyType, config.legacyType, config.legacyTypeName, "");
+ final NetworkInfo ni = new NetworkInfo(config.legacyType, config.legacyType,
+ config.legacyTypeName, "");
+ ni.setIsAvailable(true);
+ return ni;
}
/**
diff --git a/core/java/android/net/StringNetworkSpecifier.java b/core/java/android/net/StringNetworkSpecifier.java
index 83dbc63..6ae5971 100644
--- a/core/java/android/net/StringNetworkSpecifier.java
+++ b/core/java/android/net/StringNetworkSpecifier.java
@@ -17,7 +17,6 @@
package android.net;
import android.annotation.NonNull;
-import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -27,7 +26,6 @@
import java.util.Objects;
/** @hide */
-@SystemApi
public final class StringNetworkSpecifier extends NetworkSpecifier implements Parcelable {
/**
* Arbitrary string used to pass (additional) information to the network factory.
diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java
index 84ceca0..091d78e 100644
--- a/core/java/android/provider/DeviceConfig.java
+++ b/core/java/android/provider/DeviceConfig.java
@@ -796,6 +796,14 @@
}
/**
+ * Returns list of namespaces that can be read without READ_DEVICE_CONFIG_PERMISSION;
+ * @hide
+ */
+ public static @NonNull List<String> getPublicNamespaces() {
+ return PUBLIC_NAMESPACES;
+ }
+
+ /**
* Interface for monitoring changes to properties. Implementations will receive callbacks when
* properties change, including a {@link Properties} object which contains a single namespace
* and all of the properties which changed for that namespace. This includes properties which
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index c7c3140..00b2feb 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -63,6 +63,7 @@
import android.os.LocaleList;
import android.os.PowerManager.AutoPowerSaveModeTriggers;
import android.os.Process;
+import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ServiceManager;
@@ -2161,6 +2162,11 @@
public static final String CALL_METHOD_PREFIX_KEY = "_prefix";
/**
+ * @hide - RemoteCallback monitor callback argument extra to the fast-path call()-based requests
+ */
+ public static final String CALL_METHOD_MONITOR_CALLBACK_KEY = "_monitor_callback_key";
+
+ /**
* @hide - String argument extra to the fast-path call()-based requests
*/
public static final String CALL_METHOD_FLAGS_KEY = "_flags";
@@ -2218,6 +2224,26 @@
/** @hide - Private call() method to reset to defaults the 'configuration' table */
public static final String CALL_METHOD_LIST_CONFIG = "LIST_config";
+ /** @hide - Private call() method to register monitor callback for 'configuration' table */
+ public static final String CALL_METHOD_REGISTER_MONITOR_CALLBACK_CONFIG =
+ "REGISTER_MONITOR_CALLBACK_config";
+
+ /** @hide - String argument extra to the config monitor callback */
+ public static final String EXTRA_MONITOR_CALLBACK_TYPE = "monitor_callback_type";
+
+ /** @hide - String argument extra to the config monitor callback */
+ public static final String EXTRA_ACCESS_CALLBACK = "access_callback";
+
+ /** @hide - String argument extra to the config monitor callback */
+ public static final String EXTRA_NAMESPACE_UPDATED_CALLBACK =
+ "namespace_updated_callback";
+
+ /** @hide - String argument extra to the config monitor callback */
+ public static final String EXTRA_NAMESPACE = "namespace";
+
+ /** @hide - String argument extra to the config monitor callback */
+ public static final String EXTRA_CALLING_PACKAGE = "calling_package";
+
/**
* Activity Extra: Limit available options in launched activity based on the given authority.
* <p>
@@ -14155,6 +14181,37 @@
}
}
+ /**
+ * Register callback for monitoring Config table.
+ *
+ * @param resolver Handle to the content resolver.
+ * @param callback callback to register
+ *
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(Manifest.permission.MONITOR_DEVICE_CONFIG_ACCESS)
+ public static void registerMonitorCallback(@NonNull ContentResolver resolver,
+ @NonNull RemoteCallback callback) {
+ registerMonitorCallbackAsUser(resolver, resolver.getUserId(), callback);
+ }
+
+ private static void registerMonitorCallbackAsUser(
+ @NonNull ContentResolver resolver, @UserIdInt int userHandle,
+ @NonNull RemoteCallback callback) {
+ try {
+ Bundle arg = new Bundle();
+ arg.putInt(CALL_METHOD_USER_KEY, userHandle);
+ arg.putParcelable(CALL_METHOD_MONITOR_CALLBACK_KEY, callback);
+ IContentProvider cp = sProviderHolder.getProvider(resolver);
+ cp.call(resolver.getPackageName(), resolver.getFeatureId(),
+ sProviderHolder.mUri.getAuthority(),
+ CALL_METHOD_REGISTER_MONITOR_CALLBACK_CONFIG, null, arg);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Can't register config monitor callback", e);
+ }
+ }
+
private static String createCompositeName(@NonNull String namespace, @NonNull String name) {
Preconditions.checkNotNull(namespace);
Preconditions.checkNotNull(name);
diff --git a/core/java/android/security/ConfirmationPrompt.java b/core/java/android/security/ConfirmationPrompt.java
index 5330cff..f67af85 100644
--- a/core/java/android/security/ConfirmationPrompt.java
+++ b/core/java/android/security/ConfirmationPrompt.java
@@ -212,20 +212,16 @@
private int getUiOptionsAsFlags() {
int uiOptionsAsFlags = 0;
- try {
- ContentResolver contentResolver = mContext.getContentResolver();
- int inversionEnabled = Settings.Secure.getInt(contentResolver,
- Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
- if (inversionEnabled == 1) {
- uiOptionsAsFlags |= UI_OPTION_ACCESSIBILITY_INVERTED_FLAG;
- }
- float fontScale = Settings.System.getFloat(contentResolver,
- Settings.System.FONT_SCALE);
- if (fontScale > 1.0) {
- uiOptionsAsFlags |= UI_OPTION_ACCESSIBILITY_MAGNIFIED_FLAG;
- }
- } catch (SettingNotFoundException e) {
- Log.w(TAG, "Unexpected SettingNotFoundException");
+ ContentResolver contentResolver = mContext.getContentResolver();
+ int inversionEnabled = Settings.Secure.getInt(contentResolver,
+ Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0);
+ if (inversionEnabled == 1) {
+ uiOptionsAsFlags |= UI_OPTION_ACCESSIBILITY_INVERTED_FLAG;
+ }
+ float fontScale = Settings.System.getFloat(contentResolver,
+ Settings.System.FONT_SCALE, (float) 1.0);
+ if (fontScale > 1.0) {
+ uiOptionsAsFlags |= UI_OPTION_ACCESSIBILITY_MAGNIFIED_FLAG;
}
return uiOptionsAsFlags;
}
diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java
index 0f33998..1966f17 100644
--- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java
+++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java
@@ -29,7 +29,6 @@
import android.hardware.soundtrigger.SoundTrigger.ConfidenceLevel;
import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent;
import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra;
-import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel;
import android.hardware.soundtrigger.SoundTrigger.ModuleProperties;
import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig;
import android.media.AudioFormat;
@@ -67,7 +66,12 @@
/**
* Indicates that recognition for the given keyphrase is not supported.
* No further interaction should be performed with the detector that returns this availability.
+ *
+ * @deprecated This is no longer a valid state. Enrollment can occur outside of
+ * {@link KeyphraseEnrollmentInfo} through another privileged application. We can no longer
+ * determine ahead of time if the keyphrase and locale are unsupported by the system.
*/
+ @Deprecated
public static final int STATE_KEYPHRASE_UNSUPPORTED = -1;
/**
* Indicates that the given keyphrase is not enrolled.
@@ -85,34 +89,6 @@
*/
private static final int STATE_NOT_READY = 0;
- // Keyphrase management actions. Used in getManageIntent() ----//
- @Retention(RetentionPolicy.SOURCE)
- @IntDef(prefix = { "MANAGE_ACTION_" }, value = {
- MANAGE_ACTION_ENROLL,
- MANAGE_ACTION_RE_ENROLL,
- MANAGE_ACTION_UN_ENROLL
- })
- private @interface ManageActions {}
-
- /**
- * Indicates that we need to enroll.
- *
- * @hide
- */
- public static final int MANAGE_ACTION_ENROLL = 0;
- /**
- * Indicates that we need to re-enroll.
- *
- * @hide
- */
- public static final int MANAGE_ACTION_RE_ENROLL = 1;
- /**
- * Indicates that we need to un-enroll.
- *
- * @hide
- */
- public static final int MANAGE_ACTION_UN_ENROLL = 2;
-
//-- Flags for startRecognition ----//
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@@ -248,7 +224,8 @@
* The metadata of the Keyphrase, derived from the enrollment application.
* This may be null if this keyphrase isn't supported by the enrollment application.
*/
- private final KeyphraseMetadata mKeyphraseMetadata;
+ @Nullable
+ private KeyphraseMetadata mKeyphraseMetadata;
private final KeyphraseEnrollmentInfo mKeyphraseEnrollmentInfo;
private final IVoiceInteractionService mVoiceInteractionService;
private final IVoiceInteractionManagerService mModelManagementService;
@@ -448,7 +425,6 @@
mText = text;
mLocale = locale;
mKeyphraseEnrollmentInfo = keyphraseEnrollmentInfo;
- mKeyphraseMetadata = mKeyphraseEnrollmentInfo.getKeyphraseMetadata(text, locale);
mExternalCallback = callback;
mHandler = new MyHandler();
mInternalCallback = new SoundTriggerListener(mHandler);
@@ -484,8 +460,7 @@
}
// This method only makes sense if we can actually support a recognition.
- if (mAvailability != STATE_KEYPHRASE_ENROLLED
- && mAvailability != STATE_KEYPHRASE_UNENROLLED) {
+ if (mAvailability != STATE_KEYPHRASE_ENROLLED || mKeyphraseMetadata == null) {
throw new UnsupportedOperationException(
"Getting supported recognition modes for the keyphrase is not supported");
}
@@ -679,7 +654,7 @@
public Intent createEnrollIntent() {
if (DBG) Slog.d(TAG, "createEnrollIntent");
synchronized (mLock) {
- return getManageIntentLocked(MANAGE_ACTION_ENROLL);
+ return getManageIntentLocked(KeyphraseEnrollmentInfo.MANAGE_ACTION_ENROLL);
}
}
@@ -700,7 +675,7 @@
public Intent createUnEnrollIntent() {
if (DBG) Slog.d(TAG, "createUnEnrollIntent");
synchronized (mLock) {
- return getManageIntentLocked(MANAGE_ACTION_UN_ENROLL);
+ return getManageIntentLocked(KeyphraseEnrollmentInfo.MANAGE_ACTION_UN_ENROLL);
}
}
@@ -721,11 +696,11 @@
public Intent createReEnrollIntent() {
if (DBG) Slog.d(TAG, "createReEnrollIntent");
synchronized (mLock) {
- return getManageIntentLocked(MANAGE_ACTION_RE_ENROLL);
+ return getManageIntentLocked(KeyphraseEnrollmentInfo.MANAGE_ACTION_RE_ENROLL);
}
}
- private Intent getManageIntentLocked(int action) {
+ private Intent getManageIntentLocked(@KeyphraseEnrollmentInfo.ManageActions int action) {
if (mAvailability == STATE_INVALID) {
throw new IllegalStateException("getManageIntent called on an invalid detector");
}
@@ -761,8 +736,7 @@
void onSoundModelsChanged() {
synchronized (mLock) {
if (mAvailability == STATE_INVALID
- || mAvailability == STATE_HARDWARE_UNAVAILABLE
- || mAvailability == STATE_KEYPHRASE_UNSUPPORTED) {
+ || mAvailability == STATE_HARDWARE_UNAVAILABLE) {
Slog.w(TAG, "Received onSoundModelsChanged for an unsupported keyphrase/config");
return;
}
@@ -772,7 +746,9 @@
// or was deleted.
// The availability change callback should ensure that the client starts recognition
// again if needed.
- stopRecognitionLocked();
+ if (mAvailability == STATE_KEYPHRASE_ENROLLED) {
+ stopRecognitionLocked();
+ }
// Execute a refresh availability task - which should then notify of a change.
new RefreshAvailabiltyTask().execute();
@@ -955,20 +931,17 @@
@Override
public Void doInBackground(Void... params) {
int availability = internalGetInitialAvailability();
- boolean enrolled = false;
- // Fetch the sound model if the availability is one of the supported ones.
- if (availability == STATE_NOT_READY
- || availability == STATE_KEYPHRASE_UNENROLLED
- || availability == STATE_KEYPHRASE_ENROLLED) {
- enrolled = internalGetIsEnrolled(mKeyphraseMetadata.id, mLocale);
- if (!enrolled) {
- availability = STATE_KEYPHRASE_UNENROLLED;
- } else {
- availability = STATE_KEYPHRASE_ENROLLED;
- }
- }
synchronized (mLock) {
+ if (availability == STATE_NOT_READY) {
+ internalUpdateEnrolledKeyphraseMetadata();
+ if (mKeyphraseMetadata != null) {
+ availability = STATE_KEYPHRASE_ENROLLED;
+ } else {
+ availability = STATE_KEYPHRASE_UNENROLLED;
+ }
+ }
+
if (DBG) {
Slog.d(TAG, "Hotword availability changed from " + mAvailability
+ " -> " + availability);
@@ -997,28 +970,22 @@
} catch (RemoteException e) {
Slog.w(TAG, "RemoteException in getDspProperties!", e);
}
+
// No DSP available
if (dspModuleProperties == null) {
return STATE_HARDWARE_UNAVAILABLE;
}
- // No enrollment application supports this keyphrase/locale
- if (mKeyphraseMetadata == null) {
- return STATE_KEYPHRASE_UNSUPPORTED;
- }
+
return STATE_NOT_READY;
}
- /**
- * @return The corresponding {@link KeyphraseSoundModel} or null if none is found.
- */
- private boolean internalGetIsEnrolled(int keyphraseId, Locale locale) {
+ private void internalUpdateEnrolledKeyphraseMetadata() {
try {
- return mModelManagementService.isEnrolledForKeyphrase(
- mVoiceInteractionService, keyphraseId, locale.toLanguageTag());
+ mKeyphraseMetadata = mModelManagementService.getEnrolledKeyphraseMetadata(
+ mVoiceInteractionService, mText, mLocale.toLanguageTag());
} catch (RemoteException e) {
- Slog.w(TAG, "RemoteException in listRegisteredKeyphraseSoundModels!", e);
+ Slog.w(TAG, "RemoteException in internalUpdateEnrolledKeyphraseMetadata", e);
}
- return false;
}
}
diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java
index 36e057f..fc99836 100644
--- a/core/java/android/service/voice/VoiceInteractionService.java
+++ b/core/java/android/service/voice/VoiceInteractionService.java
@@ -16,14 +16,18 @@
package android.service.voice;
+import android.Manifest;
import android.annotation.NonNull;
+import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
+import android.annotation.SystemApi;
import android.app.Service;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.hardware.soundtrigger.KeyphraseEnrollmentInfo;
+import android.media.voice.KeyphraseModelManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -304,6 +308,23 @@
}
/**
+ * Creates an {@link KeyphraseModelManager} to use for enrolling voice models outside of the
+ * pre-bundled system voice models.
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES)
+ @NonNull
+ public final KeyphraseModelManager createKeyphraseModelManager() {
+ if (mSystemService == null) {
+ throw new IllegalStateException("Not available until onReady() is called");
+ }
+ synchronized (mLock) {
+ return new KeyphraseModelManager(mSystemService);
+ }
+ }
+
+ /**
* @return Details of keyphrases available for enrollment.
* @hide
*/
diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java
index 4f8aecd..71cf051 100644
--- a/core/java/android/view/SurfaceControlViewHost.java
+++ b/core/java/android/view/SurfaceControlViewHost.java
@@ -20,15 +20,21 @@
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.content.Context;
+import android.graphics.PixelFormat;
import android.os.IBinder;
+import android.os.Parcel;
+import android.os.Parcelable;
/**
- * Utility class for adding a view hierarchy to a SurfaceControl.
- *
- * See WindowlessWmTest for example usage.
- * @hide
+ * Utility class for adding a View hierarchy to a {@link SurfaceControl}. The View hierarchy
+ * will render in to a root SurfaceControl, and receive input based on the SurfaceControl's
+ * placement on-screen. The primary usage of this class is to embed a View hierarchy from
+ * one process in to another. After the SurfaceControlViewHost has been set up in the embedded
+ * content provider, we can send the {@link SurfaceControlViewHost.SurfacePackage}
+ * to the host process. The host process can then attach the hierarchy to a SurfaceView within
+ * its own by calling
+ * {@link SurfaceView#setChildSurfacePackage}.
*/
-@TestApi
public class SurfaceControlViewHost {
private ViewRootImpl mViewRoot;
private WindowlessWindowManager mWm;
@@ -36,20 +42,52 @@
private SurfaceControl mSurfaceControl;
/**
- * @hide
+ * Package encapsulating a Surface hierarchy which contains interactive view
+ * elements. It's expected to get this object from
+ * {@link SurfaceControlViewHost#getSurfacePackage} afterwards it can be embedded within
+ * a SurfaceView by calling {@link SurfaceView#setChildSurfacePackage}.
*/
- @TestApi
- public class SurfacePackage {
- final SurfaceControl mSurfaceControl;
+ public static final class SurfacePackage implements Parcelable {
+ private final SurfaceControl mSurfaceControl;
// TODO: Accessibility ID goes here
SurfacePackage(SurfaceControl sc) {
mSurfaceControl = sc;
}
+ private SurfacePackage(Parcel in) {
+ mSurfaceControl = new SurfaceControl();
+ mSurfaceControl.readFromParcel(in);
+ }
+
+ /**
+ * Use {@link SurfaceView#setChildSurfacePackage} or manually fix
+ * accessibility (see SurfaceView implementation).
+ * @hide
+ */
public @NonNull SurfaceControl getSurfaceControl() {
return mSurfaceControl;
}
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel out, int flags) {
+ mSurfaceControl.writeToParcel(out, flags);
+ }
+
+ public static final @NonNull Creator<SurfacePackage> CREATOR
+ = new Creator<SurfacePackage>() {
+ public SurfacePackage createFromParcel(Parcel in) {
+ return new SurfacePackage(in);
+ }
+ public SurfacePackage[] newArray(int size) {
+ return new SurfacePackage[size];
+ }
+ };
}
/** @hide */
@@ -59,17 +97,36 @@
mViewRoot = new ViewRootImpl(c, d, mWm);
}
- public SurfaceControlViewHost(@NonNull Context c, @NonNull Display d,
- @Nullable IBinder hostInputToken) {
+ /**
+ * Construct a new SurfaceControlViewHost. The root Surface will be
+ * allocated internally and is accessible via getSurfacePackage().
+ *
+ * The {@param hostToken} parameter, primarily used for ANR reporting,
+ * must be obtained from whomever will be hosting the embedded hierarchy.
+ * It's accessible from {@link SurfaceView#getHostToken}.
+ *
+ * @param context The Context object for your activity or application.
+ * @param display The Display the hierarchy will be placed on.
+ * @param hostToken The host token, as discussed above.
+ */
+ public SurfaceControlViewHost(@NonNull Context context, @NonNull Display display,
+ @Nullable IBinder hostToken) {
mSurfaceControl = new SurfaceControl.Builder()
.setContainerLayer()
.setName("SurfaceControlViewHost")
.build();
- mWm = new WindowlessWindowManager(c.getResources().getConfiguration(), mSurfaceControl,
- hostInputToken);
- mViewRoot = new ViewRootImpl(c, d, mWm);
+ mWm = new WindowlessWindowManager(context.getResources().getConfiguration(),
+ mSurfaceControl, hostToken);
+ mViewRoot = new ViewRootImpl(context, display, mWm);
}
+ /**
+ * Return a SurfacePackage for the root SurfaceControl of the embedded hierarchy.
+ * Rather than be directly reparented using {@link SurfaceControl.Transaction} this
+ * SurfacePackage should be passed to {@link SurfaceView#setChildSurfacePackage}
+ * which will not only reparent the Surface, but ensure the accessibility hierarchies
+ * are linked.
+ */
public @Nullable SurfacePackage getSurfacePackage() {
if (mSurfaceControl != null) {
return new SurfacePackage(mSurfaceControl);
@@ -78,10 +135,32 @@
}
}
- public void addView(View view, WindowManager.LayoutParams attrs) {
+ /**
+ * @hide
+ */
+ public void addView(@NonNull View view, WindowManager.LayoutParams attrs) {
mViewRoot.setView(view, attrs, null);
}
+ /**
+ * Set the root view of the SurfaceControlViewHost. This view will render in to
+ * the SurfaceControl, and receive input based on the SurfaceControls positioning on
+ * screen. It will be laid as if it were in a window of the passed in width and height.
+ *
+ * @param view The View to add
+ * @param width The width to layout the View within, in pixels.
+ * @param height The height to layout the View within, in pixels.
+ */
+ public void addView(@NonNull View view, int width, int height) {
+ final WindowManager.LayoutParams lp =
+ new WindowManager.LayoutParams(width, height,
+ WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.TRANSPARENT);
+ addView(view, lp);
+ }
+
+ /**
+ * @hide
+ */
public void relayout(WindowManager.LayoutParams attrs) {
mViewRoot.setLayoutParams(attrs, false);
mViewRoot.setReportNextDraw();
@@ -90,8 +169,27 @@
});
}
- public void dispose() {
+ /**
+ * Modify the size of the root view.
+ *
+ * @param width Width in pixels
+ * @param height Height in pixels
+ */
+ public void relayout(int width, int height) {
+ final WindowManager.LayoutParams lp =
+ new WindowManager.LayoutParams(width, height,
+ WindowManager.LayoutParams.TYPE_APPLICATION, 0, PixelFormat.TRANSPARENT);
+ relayout(width, height);
+ }
+
+ /**
+ * Trigger the tear down of the embedded view hierarchy and release the SurfaceControl.
+ * This will result in onDispatchedFromWindow being dispatched to the embedded view hierarchy
+ * and render the object unusable.
+ */
+ public void release() {
mViewRoot.dispatchDetachedFromWindow();
+ mSurfaceControl.release();
}
/**
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index 0de1a4f..1981bdd 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -20,6 +20,7 @@
import static android.view.WindowManagerPolicyConstants.APPLICATION_MEDIA_SUBLAYER;
import static android.view.WindowManagerPolicyConstants.APPLICATION_PANEL_SUBLAYER;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
@@ -43,6 +44,7 @@
import android.util.Log;
import android.view.SurfaceControl.Transaction;
import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.SurfaceControlViewHost;
import com.android.internal.view.SurfaceCallbackHelper;
@@ -204,6 +206,7 @@
// The token of embedded windowless view hierarchy.
private IBinder mEmbeddedViewHierarchy;
+ SurfaceControlViewHost.SurfacePackage mSurfacePackage;
public SurfaceView(Context context) {
this(context, null);
@@ -877,6 +880,11 @@
} else {
mTmpTransaction.hide(mSurfaceControl);
}
+
+ if (mSurfacePackage != null) {
+ reparentSurfacePackage(mTmpTransaction, mSurfacePackage);
+ }
+
updateBackgroundVisibility(mTmpTransaction);
if (mUseAlpha) {
mTmpTransaction.setAlpha(mSurfaceControl, alpha);
@@ -1471,11 +1479,12 @@
}
/**
- * @return The token used to identify the windows input channel.
- * @hide
+ * A token used for constructing {@link SurfaceControlViewHost}. This token should
+ * be passed from the host process to the client process.
+ *
+ * @return The token
*/
- @TestApi
- public @Nullable IBinder getInputToken() {
+ public @Nullable IBinder getHostToken() {
final ViewRootImpl viewRoot = getViewRootImpl();
if (viewRoot == null) {
return null;
@@ -1537,6 +1546,33 @@
}
/**
+ * Display the view-hierarchy embedded within a {@link SurfaceControlViewHost.SurfacePackage}
+ * within this SurfaceView. If this SurfaceView is above it's host Surface (see
+ * {@link #setZOrderOnTop} then the embedded Surface hierarchy will be able to receive
+ * input.
+ *
+ * @param p The SurfacePackage to embed.
+ */
+ public void setChildSurfacePackage(@NonNull SurfaceControlViewHost.SurfacePackage p) {
+ final SurfaceControl sc = p != null ? p.getSurfaceControl() : null;
+ final SurfaceControl lastSc = mSurfacePackage != null ?
+ mSurfacePackage.getSurfaceControl() : null;
+ if (mSurfaceControl != null && lastSc != null) {
+ mTmpTransaction.reparent(lastSc, null).apply();
+ } else if (mSurfaceControl != null) {
+ reparentSurfacePackage(mTmpTransaction, p);
+ mTmpTransaction.apply();
+ }
+ mSurfacePackage = p;
+ }
+
+ private void reparentSurfacePackage(SurfaceControl.Transaction t,
+ SurfaceControlViewHost.SurfacePackage p) {
+ // TODO: Link accessibility IDs here.
+ t.reparent(p.getSurfaceControl(), mSurfaceControl);
+ }
+
+ /**
* Add the token of embedded view hierarchy. Set {@code null} to clear the embedded view
* hierarchy.
*
diff --git a/core/java/android/view/inputmethod/EditorInfo.java b/core/java/android/view/inputmethod/EditorInfo.java
index a26243c..c80a1ae 100644
--- a/core/java/android/view/inputmethod/EditorInfo.java
+++ b/core/java/android/view/inputmethod/EditorInfo.java
@@ -18,6 +18,8 @@
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
+import android.annotation.IntDef;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.os.Bundle;
@@ -28,7 +30,13 @@
import android.text.InputType;
import android.text.TextUtils;
import android.util.Printer;
+import android.view.View;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.Preconditions;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
/**
@@ -491,6 +499,238 @@
@Nullable
public UserHandle targetInputMethodUser = null;
+ @IntDef({TrimPolicy.HEAD, TrimPolicy.TAIL})
+ @Retention(RetentionPolicy.SOURCE)
+ @interface TrimPolicy {
+ int HEAD = 0;
+ int TAIL = 1;
+ }
+
+ /**
+ * The maximum length of initialSurroundingText. When the input text from
+ * {@code setInitialSurroundingText(CharSequence)} is longer than this, trimming shall be
+ * performed to keep memory efficiency.
+ */
+ @VisibleForTesting
+ static final int MEMORY_EFFICIENT_TEXT_LENGTH = 2048;
+ /**
+ * When the input text is longer than {@code #MEMORY_EFFICIENT_TEXT_LENGTH}, we start trimming
+ * the input text into three parts: BeforeCursor, Selection, and AfterCursor. We don't want to
+ * trim the Selection but we also don't want it consumes all available space. Therefore, the
+ * maximum acceptable Selection length is half of {@code #MEMORY_EFFICIENT_TEXT_LENGTH}.
+ */
+ @VisibleForTesting
+ static final int MAX_INITIAL_SELECTION_LENGTH = MEMORY_EFFICIENT_TEXT_LENGTH / 2;
+
+ @NonNull
+ private InitialSurroundingText mInitialSurroundingText = new InitialSurroundingText();
+
+ /**
+ * Editors may use this method to provide initial input text to IMEs. As the surrounding text
+ * could be used to provide various input assistance, we recommend editors to provide the
+ * complete initial input text in its {@link View#onCreateInputConnection(EditorInfo)} callback.
+ * The supplied text will then be processed to serve {@code #getInitialTextBeforeCursor},
+ * {@code #getInitialSelectedText}, and {@code #getInitialTextBeforeCursor}. System is allowed
+ * to trim {@code sourceText} for various reasons while keeping the most valuable data to IMEs.
+ *
+ * <p><strong>Editor authors: </strong>Providing the initial input text helps reducing IPC calls
+ * for IMEs to provide many modern features right after the connection setup. We recommend
+ * calling this method in your implementation.
+ *
+ * @param sourceText The complete input text.
+ */
+ public void setInitialSurroundingText(@NonNull CharSequence sourceText) {
+ setInitialSurroundingSubText(sourceText, /* subTextStart = */ 0);
+ }
+
+ /**
+ * Editors may use this method to provide initial input text to IMEs. As the surrounding text
+ * could be used to provide various input assistance, we recommend editors to provide the
+ * complete initial input text in its {@link View#onCreateInputConnection(EditorInfo)} callback.
+ * When trimming the input text is needed, call this method instead of
+ * {@code setInitialSurroundingText(CharSequence)} and provide the trimmed position info. Always
+ * try to include the selected text within {@code subText} to give the system best flexibility
+ * to choose where and how to trim {@code subText} when necessary.
+ *
+ * @param subText The input text. When it was trimmed, {@code subTextStart} must be provided
+ * correctly.
+ * @param subTextStart The position that the input text got trimmed. For example, when the
+ * editor wants to trim out the first 10 chars, subTextStart should be 10.
+ */
+ public void setInitialSurroundingSubText(@NonNull CharSequence subText, int subTextStart) {
+ Preconditions.checkNotNull(subText);
+
+ // Swap selection start and end if necessary.
+ final int subTextSelStart = initialSelStart > initialSelEnd
+ ? initialSelEnd - subTextStart : initialSelStart - subTextStart;
+ final int subTextSelEnd = initialSelStart > initialSelEnd
+ ? initialSelStart - subTextStart : initialSelEnd - subTextStart;
+
+ final int subTextLength = subText.length();
+ // Unknown or invalid selection.
+ if (subTextStart < 0 || subTextSelStart < 0 || subTextSelEnd > subTextLength) {
+ mInitialSurroundingText = new InitialSurroundingText();
+ return;
+ }
+
+ // For privacy protection reason, we don't carry password inputs to IMEs.
+ if (isPasswordInputType(inputType)) {
+ mInitialSurroundingText = new InitialSurroundingText();
+ return;
+ }
+
+ if (subTextLength <= MEMORY_EFFICIENT_TEXT_LENGTH) {
+ mInitialSurroundingText = new InitialSurroundingText(subText, subTextSelStart,
+ subTextSelEnd);
+ return;
+ }
+
+ // The input text is too long. Let's try to trim it reasonably. Fundamental rules are:
+ // 1. Text before the cursor is the most important information to IMEs.
+ // 2. Text after the cursor is the second important information to IMEs.
+ // 3. Selected text is the least important information but it shall NEVER be truncated.
+ // When it is too long, just drop it.
+ //
+ // Source: <TextBeforeCursor><Selection><TextAfterCursor>
+ // Possible results:
+ // 1. <(maybeTrimmedAtHead)TextBeforeCursor><Selection><TextAfterCursor(maybeTrimmedAtTail)>
+ // 2. <(maybeTrimmedAtHead)TextBeforeCursor><TextAfterCursor(maybeTrimmedAtTail)>
+ //
+ final int sourceSelLength = subTextSelEnd - subTextSelStart;
+ // When the selected text is too long, drop it.
+ final int newSelLength = (sourceSelLength > MAX_INITIAL_SELECTION_LENGTH)
+ ? 0 : sourceSelLength;
+
+ // Distribute rest of length quota to TextBeforeCursor and TextAfterCursor in 4:1 ratio.
+ final int subTextBeforeCursorLength = subTextSelStart;
+ final int subTextAfterCursorLength = subTextLength - subTextSelEnd;
+ final int maxLengthMinusSelection = MEMORY_EFFICIENT_TEXT_LENGTH - newSelLength;
+ final int possibleMaxBeforeCursorLength =
+ Math.min(subTextBeforeCursorLength, (int) (0.8 * maxLengthMinusSelection));
+ int newAfterCursorLength = Math.min(subTextAfterCursorLength,
+ maxLengthMinusSelection - possibleMaxBeforeCursorLength);
+ int newBeforeCursorLength = Math.min(subTextBeforeCursorLength,
+ maxLengthMinusSelection - newAfterCursorLength);
+
+ // As trimming may happen at the head of TextBeforeCursor, calculate new starting position.
+ int newBeforeCursorHead = subTextBeforeCursorLength - newBeforeCursorLength;
+
+ // We don't want to cut surrogate pairs in the middle. Exam that at the new head and tail.
+ if (isCutOnSurrogate(subText,
+ subTextSelStart - newBeforeCursorLength, TrimPolicy.HEAD)) {
+ newBeforeCursorHead = newBeforeCursorHead + 1;
+ newBeforeCursorLength = newBeforeCursorLength - 1;
+ }
+ if (isCutOnSurrogate(subText,
+ subTextSelEnd + newAfterCursorLength - 1, TrimPolicy.TAIL)) {
+ newAfterCursorLength = newAfterCursorLength - 1;
+ }
+
+ // Now we know where to trim, compose the initialSurroundingText.
+ final int newTextLength = newBeforeCursorLength + newSelLength + newAfterCursorLength;
+ CharSequence newInitialSurroundingText;
+ if (newSelLength != sourceSelLength) {
+ final CharSequence beforeCursor = subText.subSequence(newBeforeCursorHead,
+ newBeforeCursorHead + newBeforeCursorLength);
+
+ final CharSequence afterCursor = subText.subSequence(subTextSelEnd,
+ subTextSelEnd + newAfterCursorLength);
+
+ newInitialSurroundingText = TextUtils.concat(beforeCursor, afterCursor);
+ } else {
+ newInitialSurroundingText = subText
+ .subSequence(newBeforeCursorHead, newBeforeCursorHead + newTextLength);
+ }
+
+ // As trimming may happen at the head, adjust cursor position in the initialSurroundingText
+ // obj.
+ newBeforeCursorHead = 0;
+ final int newSelHead = newBeforeCursorHead + newBeforeCursorLength;
+ mInitialSurroundingText = new InitialSurroundingText(
+ newInitialSurroundingText, newSelHead, newSelHead + newSelLength);
+ }
+
+ /**
+ * Get <var>n</var> characters of text before the current cursor position. May be {@code null}
+ * when the protocol is not supported.
+ *
+ * @param length The expected length of the text.
+ * @param flags Supplies additional options controlling how the text is returned. May be
+ * either 0 or {@link InputConnection#GET_TEXT_WITH_STYLES}.
+ * @return the text before the cursor position; the length of the returned text might be less
+ * than <var>n</var>. When there is no text before the cursor, an empty string will be returned.
+ * It could also be {@code null} when the editor or system could not support this protocol.
+ */
+ @Nullable
+ public CharSequence getInitialTextBeforeCursor(int length, int flags) {
+ return mInitialSurroundingText.getInitialTextBeforeCursor(length, flags);
+ }
+
+ /**
+ * Gets the selected text, if any. May be {@code null} when no text is selected or the selected
+ * text is way too long.
+ *
+ * @param flags Supplies additional options controlling how the text is returned. May be
+ * either 0 or {@link InputConnection#GET_TEXT_WITH_STYLES}.
+ * @return the text that is currently selected, if any. It could be an empty string when there
+ * is no text selected. When {@code null} is returned, the selected text might be too long or
+ * this protocol is not supported.
+ */
+ @Nullable
+ public CharSequence getInitialSelectedText(int flags) {
+ // Swap selection start and end if necessary.
+ final int correctedTextSelStart = initialSelStart > initialSelEnd
+ ? initialSelEnd : initialSelStart;
+ final int correctedTextSelEnd = initialSelStart > initialSelEnd
+ ? initialSelStart : initialSelEnd;
+
+ final int sourceSelLength = correctedTextSelEnd - correctedTextSelStart;
+ if (initialSelStart < 0 || initialSelEnd < 0
+ || mInitialSurroundingText.getSelectionLength() != sourceSelLength) {
+ return null;
+ }
+ return mInitialSurroundingText.getInitialSelectedText(flags);
+ }
+
+ /**
+ * Get <var>n</var> characters of text after the current cursor position. May be {@code null}
+ * when the protocol is not supported.
+ *
+ * @param length The expected length of the text.
+ * @param flags Supplies additional options controlling how the text is returned. May be
+ * either 0 or {@link InputConnection#GET_TEXT_WITH_STYLES}.
+ * @return the text after the cursor position; the length of the returned text might be less
+ * than <var>n</var>. When there is no text after the cursor, an empty string will be returned.
+ * It could also be {@code null} when the editor or system could not support this protocol.
+ */
+ @Nullable
+ public CharSequence getInitialTextAfterCursor(int length, int flags) {
+ return mInitialSurroundingText.getInitialTextAfterCursor(length, flags);
+ }
+
+ private static boolean isCutOnSurrogate(CharSequence sourceText, int cutPosition,
+ @TrimPolicy int policy) {
+ switch (policy) {
+ case TrimPolicy.HEAD:
+ return Character.isLowSurrogate(sourceText.charAt(cutPosition));
+ case TrimPolicy.TAIL:
+ return Character.isHighSurrogate(sourceText.charAt(cutPosition));
+ default:
+ return false;
+ }
+ }
+
+ private static boolean isPasswordInputType(int inputType) {
+ final int variation =
+ inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
+ return variation
+ == (TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD)
+ || variation
+ == (TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD)
+ || variation
+ == (TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD);
+ }
+
/**
* Ensure that the data in this EditorInfo is compatible with an application
* that was developed against the given target API version. This can
@@ -573,6 +813,7 @@
dest.writeInt(fieldId);
dest.writeString(fieldName);
dest.writeBundle(extras);
+ mInitialSurroundingText.writeToParcel(dest, flags);
if (hintLocales != null) {
hintLocales.writeToParcel(dest, flags);
} else {
@@ -603,6 +844,9 @@
res.fieldId = source.readInt();
res.fieldName = source.readString();
res.extras = source.readBundle();
+ InitialSurroundingText initialSurroundingText =
+ InitialSurroundingText.CREATOR.createFromParcel(source);
+ res.mInitialSurroundingText = initialSurroundingText;
LocaleList hintLocales = LocaleList.CREATOR.createFromParcel(source);
res.hintLocales = hintLocales.isEmpty() ? null : hintLocales;
res.contentMimeTypes = source.readStringArray();
@@ -619,4 +863,93 @@
return 0;
}
+ // TODO(b/148035211): Unit tests for this class
+ static final class InitialSurroundingText implements Parcelable {
+ @Nullable final CharSequence mSurroundingText;
+ final int mSelectionHead;
+ final int mSelectionEnd;
+
+ InitialSurroundingText() {
+ mSurroundingText = null;
+ mSelectionHead = 0;
+ mSelectionEnd = 0;
+ }
+
+ InitialSurroundingText(@Nullable CharSequence surroundingText, int selectionHead,
+ int selectionEnd) {
+ mSurroundingText = surroundingText;
+ mSelectionHead = selectionHead;
+ mSelectionEnd = selectionEnd;
+ }
+
+ @Nullable
+ private CharSequence getInitialTextBeforeCursor(int n, int flags) {
+ if (mSurroundingText == null) {
+ return null;
+ }
+
+ final int length = Math.min(n, mSelectionHead);
+ return ((flags & InputConnection.GET_TEXT_WITH_STYLES) != 0)
+ ? mSurroundingText.subSequence(mSelectionHead - length, mSelectionHead)
+ : TextUtils.substring(mSurroundingText, mSelectionHead - length,
+ mSelectionHead);
+ }
+
+ @Nullable
+ private CharSequence getInitialSelectedText(int flags) {
+ if (mSurroundingText == null) {
+ return null;
+ }
+
+ return ((flags & InputConnection.GET_TEXT_WITH_STYLES) != 0)
+ ? mSurroundingText.subSequence(mSelectionHead, mSelectionEnd)
+ : TextUtils.substring(mSurroundingText, mSelectionHead, mSelectionEnd);
+ }
+
+ @Nullable
+ private CharSequence getInitialTextAfterCursor(int n, int flags) {
+ if (mSurroundingText == null) {
+ return null;
+ }
+
+ final int length = Math.min(n, mSurroundingText.length() - mSelectionEnd);
+ return ((flags & InputConnection.GET_TEXT_WITH_STYLES) != 0)
+ ? mSurroundingText.subSequence(mSelectionEnd, mSelectionEnd + length)
+ : TextUtils.substring(mSurroundingText, mSelectionEnd, mSelectionEnd + length);
+ }
+
+ private int getSelectionLength() {
+ return mSelectionEnd - mSelectionHead;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ TextUtils.writeToParcel(mSurroundingText, dest, flags);
+ dest.writeInt(mSelectionHead);
+ dest.writeInt(mSelectionEnd);
+ }
+
+ public static final @android.annotation.NonNull Parcelable.Creator<InitialSurroundingText>
+ CREATOR = new Parcelable.Creator<InitialSurroundingText>() {
+ @Override
+ public InitialSurroundingText createFromParcel(Parcel source) {
+ final CharSequence initialText =
+ TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
+ final int selectionHead = source.readInt();
+ final int selectionEnd = source.readInt();
+
+ return new InitialSurroundingText(initialText, selectionHead, selectionEnd);
+ }
+
+ @Override
+ public InitialSurroundingText[] newArray(int size) {
+ return new InitialSurroundingText[size];
+ }
+ };
+ }
}
diff --git a/core/java/android/view/inputmethod/InputConnection.java b/core/java/android/view/inputmethod/InputConnection.java
index e554540..4337ed5 100644
--- a/core/java/android/view/inputmethod/InputConnection.java
+++ b/core/java/android/view/inputmethod/InputConnection.java
@@ -158,7 +158,11 @@
* trigger an IPC round-trip that will take some time. Assume this
* method consumes a lot of time. Also, please keep in mind the
* Editor may choose to return less characters than requested even
- * if they are available for performance reasons.</p>
+ * if they are available for performance reasons. If you are using
+ * this to get the initial text around the cursor, you may consider
+ * using {@link EditorInfo#getInitialTextBeforeCursor(int, int)},
+ * {@link EditorInfo#getInitialSelectedText(int)}, and
+ * {@link EditorInfo#getInitialTextAfterCursor(int, int)} to prevent IPC costs.</p>
*
* <p><strong>Editor authors:</strong> please be careful of race
* conditions in implementing this call. An IME can make a change
@@ -196,7 +200,11 @@
*
* <p><strong>IME authors:</strong> please consider this will
* trigger an IPC round-trip that will take some time. Assume this
- * method consumes a lot of time.</p>
+ * method consumes a lot of time. If you are using this to get the
+ * initial text around the cursor, you may consider using
+ * {@link EditorInfo#getInitialTextBeforeCursor(int, int)},
+ * {@link EditorInfo#getInitialSelectedText(int)}, and
+ * {@link EditorInfo#getInitialTextAfterCursor(int, int)} to prevent IPC costs.</p>
*
* <p><strong>Editor authors:</strong> please be careful of race
* conditions in implementing this call. An IME can make a change
@@ -234,7 +242,11 @@
*
* <p><strong>IME authors:</strong> please consider this will
* trigger an IPC round-trip that will take some time. Assume this
- * method consumes a lot of time.</p>
+ * method consumes a lot of time. If you are using this to get the
+ * initial text around the cursor, you may consider using
+ * {@link EditorInfo#getInitialTextBeforeCursor(int, int)},
+ * {@link EditorInfo#getInitialSelectedText(int)}, and
+ * {@link EditorInfo#getInitialTextAfterCursor(int, int)} to prevent IPC costs.</p>
*
* <p><strong>Editor authors:</strong> please be careful of race
* conditions in implementing this call. An IME can make a change
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index b10631b..cdf8c68 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -391,6 +391,9 @@
// This can only be true if the text view is editable.
private boolean mCursorControlEnabled;
+ // Specifies whether the new magnifier (with fish-eye effect) is enabled.
+ private final boolean mNewMagnifierEnabled;
+
Editor(TextView textView) {
mTextView = textView;
// Synchronize the filter list, which places the undo input filter at the end.
@@ -401,9 +404,13 @@
mCursorControlEnabled = AppGlobals.getIntCoreSetting(
WidgetFlags.KEY_ENABLE_CURSOR_CONTROL , 0) != 0;
+ mNewMagnifierEnabled = AppGlobals.getIntCoreSetting(
+ WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, 0) != 0;
if (TextView.DEBUG_CURSOR) {
logCursor("Editor", "Cursor control is %s.",
mCursorControlEnabled ? "enabled" : "disabled");
+ logCursor("Editor", "New magnifier is %s.",
+ mNewMagnifierEnabled ? "enabled" : "disabled");
}
}
@@ -422,7 +429,7 @@
if (FLAG_USE_MAGNIFIER && mMagnifierAnimator == null) {
// Lazy creates the magnifier instance because it requires the text height which cannot
// be measured at the time of Editor instance being created.
- final Magnifier.Builder builder = shouldUseNewMagnifier()
+ final Magnifier.Builder builder = mNewMagnifierEnabled
? createBuilderWithInlineMagnifierDefaults()
: Magnifier.createBuilderWithOldMagnifierDefaults(mTextView);
mMagnifierAnimator = new MagnifierMotionAnimator(builder.build());
@@ -430,24 +437,28 @@
return mMagnifierAnimator;
}
- private boolean shouldUseNewMagnifier() {
- // TODO: use a separate flag to enable new magnifier.
- return mCursorControlEnabled;
- }
-
private Magnifier.Builder createBuilderWithInlineMagnifierDefaults() {
final Magnifier.Builder params = new Magnifier.Builder(mTextView);
// TODO: supports changing the height/width dynamically because the text height can be
// dynamically changed.
+ float zoom = AppGlobals.getFloatCoreSetting(
+ WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, 1.5f);
+ float aspectRatio = AppGlobals.getFloatCoreSetting(
+ WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, 5.5f);
+ // Avoid invalid/unsupported values.
+ if (zoom < 1.2f || zoom > 1.8f) {
+ zoom = 1.5f;
+ }
+ if (aspectRatio < 3 || aspectRatio > 8) {
+ aspectRatio = 5.5f;
+ }
+
final Paint.FontMetrics fontMetrics = mTextView.getPaint().getFontMetrics();
final float sourceHeight = fontMetrics.descent - fontMetrics.ascent;
- final float zoom = 1.5f;
- final float widthHeightRatio = 5.5f;
// Slightly increase the height to avoid tooLargeTextForMagnifier() returns true.
int height = (int)(sourceHeight * zoom) + 2;
- int width = (int)(widthHeightRatio * height);
-
+ int width = (int)(aspectRatio * height);
params.setFishEyeStyle()
.setSize(width, height)
@@ -4680,11 +4691,11 @@
}
};
- private int getPreferredWidth() {
+ protected final int getPreferredWidth() {
return Math.max(mDrawable.getIntrinsicWidth(), mMinSize);
}
- private int getPreferredHeight() {
+ protected final int getPreferredHeight() {
return Math.max(mDrawable.getIntrinsicHeight(), mMinSize);
}
@@ -5089,7 +5100,7 @@
mTextView.invalidateCursorPath();
suspendBlink();
- if (shouldUseNewMagnifier()) {
+ if (mNewMagnifierEnabled) {
// Calculates the line bounds as the content source bounds to the magnifier.
Layout layout = mTextView.getLayout();
int line = layout.getLineForOffset(getCurrentCursorOffset());
@@ -5218,7 +5229,7 @@
// Whether the popup window is in the invisible state and will be dismissed when finger up.
private boolean mPendingDismissOnUp = false;
// The alpha value of the drawable.
- private final int mDrawableOpacity = 255;
+ private final int mDrawableOpacity;
// Members for toggling the insertion menu in touch through mode.
@@ -5239,8 +5250,29 @@
// of the touch through events.
private float mTextHeight;
- public InsertionHandleView(Drawable drawable) {
+ // The delta height applied to the insertion handle view.
+ private final int mDeltaHeight;
+
+ InsertionHandleView(Drawable drawable) {
super(drawable, drawable, com.android.internal.R.id.insertion_handle);
+
+ int deltaHeight = 0;
+ int opacity = 255;
+ if (mCursorControlEnabled) {
+ deltaHeight = AppGlobals.getIntCoreSetting(
+ WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, 25);
+ opacity = AppGlobals.getIntCoreSetting(
+ WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, 50);
+ // Avoid invalid/unsupported values.
+ if (deltaHeight < -25 || deltaHeight > 50) {
+ deltaHeight = 25;
+ }
+ if (opacity < 10 || opacity > 100) {
+ opacity = 50;
+ }
+ }
+ mDeltaHeight = deltaHeight;
+ mDrawableOpacity = opacity;
}
private void hideAfterDelay() {
@@ -5293,6 +5325,17 @@
}
@Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ if (mCursorControlEnabled) {
+ final int height = Math.max(
+ getPreferredHeight() + mDeltaHeight, mDrawable.getIntrinsicHeight());
+ setMeasuredDimension(getPreferredWidth(), height);
+ return;
+ }
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+
+ @Override
public boolean onTouchEvent(MotionEvent ev) {
if (mCursorControlEnabled && FLAG_ENABLE_CURSOR_DRAG) {
// Should only enable touch through when cursor drag is enabled.
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index 733a775..970d70c 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -52,7 +52,6 @@
import android.view.ViewDebug;
import android.view.ViewHierarchyEncoder;
import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
@@ -307,6 +306,9 @@
setMax(a.getInt(R.styleable.ProgressBar_max, mMax));
setProgress(a.getInt(R.styleable.ProgressBar_progress, mProgress));
+ // onProgressRefresh() is only called when the progress changes. So we should set
+ // stateDescription during initialization here.
+ super.setStateDescription(formatStateDescription(mProgress));
setSecondaryProgress(a.getInt(
R.styleable.ProgressBar_secondaryProgress, mSecondaryProgress));
@@ -1599,8 +1601,7 @@
}
void onProgressRefresh(float scale, boolean fromUser, int progress) {
- if (AccessibilityManager.getInstance(mContext).isEnabled()
- && mCustomStateDescription == null) {
+ if (mCustomStateDescription == null) {
super.setStateDescription(formatStateDescription(mProgress));
}
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 32d3fef..8ce6ee5 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -8668,6 +8668,7 @@
outAttrs.initialSelStart = getSelectionStart();
outAttrs.initialSelEnd = getSelectionEnd();
outAttrs.initialCapsMode = ic.getCursorCapsMode(getInputType());
+ outAttrs.setInitialSurroundingText(mText);
return ic;
}
}
diff --git a/core/java/android/widget/WidgetFlags.java b/core/java/android/widget/WidgetFlags.java
index fa1e498d..1a8e7a7 100644
--- a/core/java/android/widget/WidgetFlags.java
+++ b/core/java/android/widget/WidgetFlags.java
@@ -35,6 +35,66 @@
*/
public static final String KEY_ENABLE_CURSOR_CONTROL = "widget__enable_cursor_control";
+ /**
+ * The flag of delta height applies to the insertion handle when cursor control flag is enabled.
+ * The default value is 25.
+ */
+ public static final String INSERTION_HANDLE_DELTA_HEIGHT =
+ "CursorControlFeature__insertion_handle_delta_height";
+
+ /**
+ * The key name used in app core settings for {@link #INSERTION_HANDLE_DELTA_HEIGHT}.
+ */
+ public static final String KEY_INSERTION_HANDLE_DELTA_HEIGHT =
+ "widget__insertion_handle_delta_height";
+
+ /**
+ * The flag of opacity applies to the insertion handle when cursor control flag is enabled.
+ * The opacity value is in the range of {0..100}. The default value is 50.
+ */
+ public static final String INSERTION_HANDLE_OPACITY =
+ "CursorControlFeature__insertion_handle_opacity";
+
+ /**
+ * The key name used in app core settings for {@link #INSERTION_HANDLE_OPACITY}.
+ */
+ public static final String KEY_INSERTION_HANDLE_OPACITY =
+ "widget__insertion_handle_opacity";
+
+ /**
+ * The flag of enabling the new magnifier.
+ */
+ public static final String ENABLE_NEW_MAGNIFIER = "CursorControlFeature__enable_new_magnifier";
+
+ /**
+ * The key name used in app core settings for {@link #ENABLE_NEW_MAGNIFIER}.
+ */
+ public static final String KEY_ENABLE_NEW_MAGNIFIER = "widget__enable_new_magnifier";
+
+ /**
+ * The flag of zoom factor applies to the new magnifier.
+ * The default value is 1.5f.
+ */
+ public static final String MAGNIFIER_ZOOM_FACTOR =
+ "CursorControlFeature__magnifier_zoom_factor";
+
+ /**
+ * The key name used in app core settings for {@link #MAGNIFIER_ZOOM_FACTOR}.
+ */
+ public static final String KEY_MAGNIFIER_ZOOM_FACTOR = "widget__magnifier_zoom_factor";
+
+ /**
+ * The flag of aspect ratio (width/height) applies to the new magnifier.
+ * The default value is 5.5f.
+ */
+ public static final String MAGNIFIER_ASPECT_RATIO =
+ "CursorControlFeature__magnifier_aspect_ratio";
+
+ /**
+ * The key name used in app core settings for {@link #MAGNIFIER_ASPECT_RATIO}.
+ */
+ public static final String KEY_MAGNIFIER_ASPECT_RATIO = "widget__magnifier_aspect_ratio";
+
private WidgetFlags() {
}
}
diff --git a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl
index be2d1d6..f3b6d29 100644
--- a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl
+++ b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl
@@ -26,6 +26,7 @@
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.IVoiceInteractionSessionListener;
import android.hardware.soundtrigger.IRecognitionStatusCallback;
+import android.hardware.soundtrigger.KeyphraseMetadata;
import android.hardware.soundtrigger.ModelParams;
import android.hardware.soundtrigger.SoundTrigger;
import android.service.voice.IVoiceInteractionService;
@@ -72,8 +73,8 @@
*/
SoundTrigger.ModuleProperties getDspModuleProperties(in IVoiceInteractionService service);
/**
- * Indicates if there's a keyphrase sound model available for the given keyphrase ID.
- * This performs the check for the current user.
+ * Indicates if there's a keyphrase sound model available for the given keyphrase ID and the
+ * user ID of the caller.
*
* @param service The current VoiceInteractionService.
* @param keyphraseId The unique identifier for the keyphrase.
@@ -82,6 +83,18 @@
boolean isEnrolledForKeyphrase(IVoiceInteractionService service, int keyphraseId,
String bcp47Locale);
/**
+ * Generates KeyphraseMetadata for an enrolled sound model based on keyphrase string, locale,
+ * and the user ID of the caller.
+ *
+ * @param service The current VoiceInteractionService
+ * @param keyphrase Keyphrase text associated with the enrolled model
+ * @param bcp47Locale The BCP47 language tag for the keyphrase's locale.
+ * @return The metadata for the enrolled voice model bassed on the passed in parameters. Null if
+ * no matching voice model exists.
+ */
+ KeyphraseMetadata getEnrolledKeyphraseMetadata(IVoiceInteractionService service,
+ String keyphrase, String bcp47Locale);
+ /**
* Starts a recognition for the given keyphrase.
*/
int startRecognition(in IVoiceInteractionService service, int keyphraseId,
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 3c65753..1fb08f2 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2253,6 +2253,9 @@
<eat-comment />
<!-- @SystemApi @TestApi Allows an application to write to internal media storage
+ @deprecated This permission is no longer honored in the system and no longer adds
+ the media_rw gid as a supplementary gid to the holder. Use the
+ android.permission.MANAGE_EXTERNAL_STORAGE instead.
@hide -->
<permission android:name="android.permission.WRITE_MEDIA_STORAGE"
android:protectionLevel="signature|privileged" />
@@ -2709,6 +2712,11 @@
<permission android:name="android.permission.READ_DEVICE_CONFIG"
android:protectionLevel="signature|preinstalled" />
+ <!-- @SystemApi @hide Allows an application to monitor config settings access.
+ <p>Not for use by third-party applications. -->
+ <permission android:name="android.permission.MONITOR_DEVICE_CONFIG_ACCESS"
+ android:protectionLevel="signature"/>
+
<!-- @SystemApi @TestApi Allows an application to call
{@link android.app.ActivityManager#forceStopPackage}.
@hide -->
@@ -3793,6 +3801,24 @@
<permission android:name="android.permission.CAPTURE_MEDIA_OUTPUT"
android:protectionLevel="signature|privileged" />
+ <!-- @SystemApi Allows an application to capture the audio played by other apps
+ with the {@code USAGE_VOICE_COMMUNICATION} usage.
+
+ The application may opt out of capturing by setting an allow capture policy of
+ {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_NONE}.
+
+ There are strong restriction listed at
+ {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_SYSTEM}
+ on what an app can do with the captured audio.
+
+ See {@code CAPTURE_AUDIO_OUTPUT} and {@code CAPTURE_MEDIA_OUTPUT} for capturing
+ audio use cases other than voice communication playback.
+
+ <p>Not for use by third-party applications.</p>
+ @hide -->
+ <permission android:name="android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT"
+ android:protectionLevel="signature|privileged" />
+
<!-- @SystemApi Allows an application to capture audio for hotword detection.
<p>Not for use by third-party applications.</p>
@hide -->
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 0895edc..cfed805 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -2260,6 +2260,55 @@
<attr name="name" />
</declare-styleable>
+ <!-- The <code>processes</code> tag specifies the processes the application will run code in
+ and optionally characteristics of those processes. This tag is optional; if not
+ specified, components will simply run in the processes they specify. If supplied,
+ they can only specify processes that are enumerated here, and if they don't this
+ will be treated as a corrupt apk and result in an install failure.
+
+ <p>This appears as a child tag of the
+ {@link #AndroidManifestApplication application} tag. -->
+ <declare-styleable name="AndroidManifestProcesses" parent="AndroidManifestApplication">
+ </declare-styleable>
+
+ <!-- The <code>process</code> tag enumerates one of the available processes under its
+ containing <code>processes</code> tag.
+
+ <p>This appears as a child tag of the
+ {@link #AndroidManifestProcesses processes} tag. -->
+ <declare-styleable name="AndroidManifestProcess" parent="AndroidManifestProcesses">
+ <!-- Required name of the process that is allowed -->
+ <attr name="process" />
+ </declare-styleable>
+
+ <!-- The <code>deny-permission</code> tag specifies that a permission is to be denied
+ for a particular process (if specified under the
+ {@link #AndroidManifestProcess process} tag) or by default for all
+ processes {if specified under the
+ @link #AndroidManifestProcesses processes} tag).
+
+ <p>This appears as a child tag of the
+ {@link #AndroidManifestProcesses processes} and
+ {@link #AndroidManifestProcess process} tags. -->
+ <declare-styleable name="AndroidManifestDenyPermission"
+ parent="AndroidManifestProcesses">
+ <!-- Required name of the permission that is to be denied -->
+ <attr name="name" />
+ </declare-styleable>
+
+ <!-- The <code>allow-permission</code> tag specifies that a permission is to be allowed
+ for a particular process, when it was previously denied for all processes through
+ {@link #AndroidManifestDenyPermission deny-permission}
+
+ <p>This appears as a child tag of the
+ {@link #AndroidManifestProcesses processes} and
+ {@link #AndroidManifestProcess process} tags. -->
+ <declare-styleable name="AndroidManifestAllowPermission"
+ parent="AndroidManifestProcesses">
+ <!-- Required name of the permission that is to be allowed. -->
+ <attr name="name" />
+ </declare-styleable>
+
<!-- The <code>provider</code> tag declares a
{@link android.content.ContentProvider} class that is available
as part of the package's application components, supplying structured
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 7fd444a..ec3208e 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1628,29 +1628,21 @@
config_timeZoneRulesUpdateTrackingEnabled are true.] -->
<integer name="config_timeZoneRulesCheckRetryCount">5</integer>
- <!-- Whether to enable network location overlay which allows network
- location provider to be replaced by an app at run-time. When disabled,
- only the config_networkLocationProviderPackageName package will be
- searched for network location provider, otherwise packages whose
- signature matches the signatures of config_locationProviderPackageNames
- will be searched, and the service with the highest version number will
- be picked. Anyone who wants to disable the overlay mechanism can set it
- to false.
- -->
+ <!-- Whether to enable network location overlay which allows network location provider to be
+ replaced by an app at run-time. When disabled, only the
+ config_networkLocationProviderPackageName package will be searched for network location
+ provider, otherwise any system package is eligible. Anyone who wants to disable the overlay
+ mechanism can set it to false. -->
<bool name="config_enableNetworkLocationOverlay" translatable="false">true</bool>
<!-- Package name providing network location support. Used only when
config_enableNetworkLocationOverlay is false. -->
<string name="config_networkLocationProviderPackageName" translatable="false">@null</string>
- <!-- Whether to enable fused location provider overlay which allows fused
- location provider to be replaced by an app at run-time. When disabled,
- only the config_fusedLocationProviderPackageName package will be
- searched for fused location provider, otherwise packages whose
- signature matches the signatures of config_locationProviderPackageNames
- will be searched, and the service with the highest version number will
- be picked. Anyone who wants to disable the overlay mechanism can set it
- to false.
- -->
+ <!-- Whether to enable fused location provider overlay which allows fused location provider to
+ be replaced by an app at run-time. When disabled, only the
+ config_fusedLocationProviderPackageName package will be searched for fused location
+ provider, otherwise any system package is eligible. Anyone who wants to disable the overlay
+ mechanism can set it to false. -->
<bool name="config_enableFusedLocationOverlay" translatable="false">true</bool>
<!-- Package name providing fused location support. Used only when
config_enableFusedLocationOverlay is false. -->
@@ -1669,25 +1661,10 @@
-->
<string name="config_defaultNetworkRecommendationProviderPackage" translatable="false"></string>
- <!-- Whether to enable Hardware FLP overlay which allows Hardware FLP to be
- replaced by an app at run-time. When disabled, only the
- config_hardwareFlpPackageName package will be searched for Hardware Flp,
- otherwise packages whose signature matches the signatures of
- config_locationProviderPackageNames will be searched, and the service
- with the highest version number will be picked. Anyone who wants to
- disable the overlay mechanism can set it to false.
- -->
- <bool name="config_enableHardwareFlpOverlay" translatable="false">true</bool>
- <!-- Package name providing Hardware Flp. Used only when
- config_enableHardwareFlpOverlay is false. -->
- <string name="config_hardwareFlpPackageName" translatable="false">com.android.location.fused</string>
-
<!-- Whether to enable geocoder overlay which allows geocoder to be replaced
by an app at run-time. When disabled, only the
config_geocoderProviderPackageName package will be searched for
- geocoder, otherwise packages whose signature matches the signatures of
- config_locationProviderPackageNames will be searched, and the service
- with the highest version number will be picked. Anyone who wants to
+ geocoder, otherwise any system package is eligible. Anyone who wants to
disable the overlay mechanism can set it to false.
-->
<bool name="config_enableGeocoderOverlay" translatable="false">true</bool>
@@ -1698,9 +1675,7 @@
<!-- Whether to enable geofence overlay which allows geofence to be replaced
by an app at run-time. When disabled, only the
config_geofenceProviderPackageName package will be searched for
- geofence implementation, otherwise packages whose signature matches the
- signatures of config_locationProviderPackageNames will be searched, and
- the service with the highest version number will be picked. Anyone who
+ geofence implementation, otherwise any system package is eligible. Anyone who
wants to disable the overlay mechanism can set it to false.
-->
<bool name="config_enableGeofenceOverlay" translatable="false">true</bool>
@@ -1711,9 +1686,7 @@
<!-- Whether to enable Hardware Activity-Recognition overlay which allows Hardware
Activity-Recognition to be replaced by an app at run-time. When disabled, only the
config_activityRecognitionHardwarePackageName package will be searched for
- its implementation, otherwise packages whose signature matches the
- signatures of config_locationProviderPackageNames will be searched, and
- the service with the highest version number will be picked. Anyone who
+ its implementation, otherwise any system package is eligible. Anyone who
wants to disable the overlay mechanism can set it to false.
-->
<bool name="config_enableActivityRecognitionHardwareOverlay" translatable="false">true</bool>
@@ -1721,19 +1694,8 @@
config_enableActivityRecognitionHardwareOverlay is false. -->
<string name="config_activityRecognitionHardwarePackageName" translatable="false">@null</string>
- <!-- Package name(s) containing location provider support.
- These packages can contain services implementing location providers,
- such as the Geocode Provider, Network Location Provider, and
- Fused Location Provider. They will each be searched for
- service components implementing these providers.
- It is strongly recommended that the packages explicitly named
- below are on the system image, so that they will not map to
- a 3rd party application.
- The location framework also has support for installation
- of new location providers at run-time. The new package does not
- have to be explicitly listed here, however it must have a signature
- that matches the signature of at least one package on this list.
- -->
+ <!-- Package name(s) containing location provider support. These packages will be auto-granted
+ several permissions by the system, and should be system packages. -->
<string-array name="config_locationProviderPackageNames" translatable="false">
<!-- The standard AOSP fused location provider -->
<item>com.android.location.fused</item>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 357b1f0..81ef872 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1869,7 +1869,6 @@
<java-symbol type="bool" name="config_dozeAfterScreenOffByDefault" />
<java-symbol type="bool" name="config_enableActivityRecognitionHardwareOverlay" />
<java-symbol type="bool" name="config_enableFusedLocationOverlay" />
- <java-symbol type="bool" name="config_enableHardwareFlpOverlay" />
<java-symbol type="bool" name="config_enableGeocoderOverlay" />
<java-symbol type="bool" name="config_enableGeofenceOverlay" />
<java-symbol type="bool" name="config_enableNetworkLocationOverlay" />
@@ -2019,7 +2018,6 @@
<java-symbol type="string" name="config_datause_iface" />
<java-symbol type="string" name="config_activityRecognitionHardwarePackageName" />
<java-symbol type="string" name="config_fusedLocationProviderPackageName" />
- <java-symbol type="string" name="config_hardwareFlpPackageName" />
<java-symbol type="string" name="config_geocoderProviderPackageName" />
<java-symbol type="string" name="config_geofenceProviderPackageName" />
<java-symbol type="string" name="config_networkLocationProviderPackageName" />
diff --git a/core/tests/coretests/src/android/app/appsearch/SnippetTest.java b/core/tests/coretests/src/android/app/appsearch/SnippetTest.java
new file mode 100644
index 0000000..3103708
--- /dev/null
+++ b/core/tests/coretests/src/android/app/appsearch/SnippetTest.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2019 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.app.appsearch;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import androidx.test.filters.SmallTest;
+
+import com.google.android.icing.proto.DocumentProto;
+import com.google.android.icing.proto.PropertyProto;
+import com.google.android.icing.proto.SearchResultProto;
+import com.google.android.icing.proto.SnippetMatchProto;
+import com.google.android.icing.proto.SnippetProto;
+
+import org.junit.Test;
+
+@SmallTest
+public class SnippetTest {
+
+ // TODO(sidchhabra): Add tests for Double and Long Snippets.
+ @Test
+ public void testSingleStringSnippet() {
+
+ final String propertyKeyString = "content";
+ final String propertyValueString = "A commonly used fake word is foo.\n"
+ + " Another nonsense word that’s used a lot\n"
+ + " is bar.\n";
+ final String uri = "uri1";
+ final String schemaType = "schema1";
+ final String searchWord = "foo";
+ final String exactMatch = "foo";
+ final String window = "is foo";
+
+ // Building the SearchResult received from query.
+ PropertyProto property = PropertyProto.newBuilder()
+ .setName(propertyKeyString)
+ .addStringValues(propertyValueString)
+ .build();
+ DocumentProto documentProto = DocumentProto.newBuilder()
+ .setUri(uri)
+ .setSchema(schemaType)
+ .addProperties(property)
+ .build();
+ SnippetProto snippetProto = SnippetProto.newBuilder()
+ .addEntries(SnippetProto.EntryProto.newBuilder()
+ .setPropertyName(propertyKeyString)
+ .addSnippetMatches(SnippetMatchProto.newBuilder()
+ .setValuesIndex(0)
+ .setExactMatchPosition(29)
+ .setExactMatchBytes(3)
+ .setWindowPosition(26)
+ .setWindowBytes(6)
+ .build())
+ .build())
+ .build();
+ SearchResultProto.ResultProto resultProto = SearchResultProto.ResultProto.newBuilder()
+ .setDocument(documentProto)
+ .setSnippet(snippetProto)
+ .build();
+ SearchResultProto searchResultProto = SearchResultProto.newBuilder()
+ .addResults(resultProto)
+ .build();
+ SearchResults searchResults = new SearchResults(searchResultProto);
+
+ // Making ResultReader and getting Snippet values.
+ while (searchResults.hasNext()) {
+ SearchResults.Result result = searchResults.next();
+ MatchInfo match = result.getMatchInfo().get(0);
+ assertThat(match.getPropertyPath()).isEqualTo(propertyKeyString);
+ assertThat(match.getFullText()).isEqualTo(propertyValueString);
+ assertThat(match.getExactMatch()).isEqualTo(exactMatch);
+ assertThat(match.getSnippet()).isEqualTo(window);
+ }
+ }
+
+ // TODO(sidchhabra): Add tests for Double and Long Snippets.
+ @Test
+ public void testNoSnippets() {
+
+ final String propertyKeyString = "content";
+ final String propertyValueString = "A commonly used fake word is foo.\n"
+ + " Another nonsense word that’s used a lot\n"
+ + " is bar.\n";
+ final String uri = "uri1";
+ final String schemaType = "schema1";
+ final String searchWord = "foo";
+ final String exactMatch = "foo";
+ final String window = "is foo";
+
+ // Building the SearchResult received from query.
+ PropertyProto property = PropertyProto.newBuilder()
+ .setName(propertyKeyString)
+ .addStringValues(propertyValueString)
+ .build();
+ DocumentProto documentProto = DocumentProto.newBuilder()
+ .setUri(uri)
+ .setSchema(schemaType)
+ .addProperties(property)
+ .build();
+ SearchResultProto.ResultProto resultProto = SearchResultProto.ResultProto.newBuilder()
+ .setDocument(documentProto)
+ .build();
+ SearchResultProto searchResultProto = SearchResultProto.newBuilder()
+ .addResults(resultProto)
+ .build();
+ SearchResults searchResults = new SearchResults(searchResultProto);
+
+ while (searchResults.hasNext()) {
+ SearchResults.Result result = searchResults.next();
+ assertThat(result.getMatchInfo()).isEqualTo(null);
+ }
+ }
+
+ @Test
+ public void testMultipleStringSnippet() {
+ final String searchWord = "Test";
+
+ // Building the SearchResult received from query.
+ PropertyProto property1 = PropertyProto.newBuilder()
+ .setName("sender.name")
+ .addStringValues("Test Name Jr.")
+ .build();
+ PropertyProto property2 = PropertyProto.newBuilder()
+ .setName("sender.email")
+ .addStringValues("TestNameJr@gmail.com")
+ .build();
+ DocumentProto documentProto = DocumentProto.newBuilder()
+ .setUri("uri1")
+ .setSchema("schema1")
+ .addProperties(property1)
+ .addProperties(property2)
+ .build();
+ SnippetProto snippetProto = SnippetProto.newBuilder()
+ .addEntries(
+ SnippetProto.EntryProto.newBuilder()
+ .setPropertyName("sender.name")
+ .addSnippetMatches(
+ SnippetMatchProto.newBuilder()
+ .setValuesIndex(0)
+ .setExactMatchPosition(0)
+ .setExactMatchBytes(4)
+ .setWindowPosition(0)
+ .setWindowBytes(9)
+ .build())
+ .build())
+ .addEntries(
+ SnippetProto.EntryProto.newBuilder()
+ .setPropertyName("sender.email")
+ .addSnippetMatches(
+ SnippetMatchProto.newBuilder()
+ .setValuesIndex(0)
+ .setExactMatchPosition(0)
+ .setExactMatchBytes(20)
+ .setWindowPosition(0)
+ .setWindowBytes(20)
+ .build())
+ .build()
+ )
+ .build();
+ SearchResultProto.ResultProto resultProto = SearchResultProto.ResultProto.newBuilder()
+ .setDocument(documentProto)
+ .setSnippet(snippetProto)
+ .build();
+ SearchResultProto searchResultProto = SearchResultProto.newBuilder()
+ .addResults(resultProto)
+ .build();
+ SearchResults searchResults = new SearchResults(searchResultProto);
+
+ // Making ResultReader and getting Snippet values.
+ while (searchResults.hasNext()) {
+ SearchResults.Result result = searchResults.next();
+
+ MatchInfo match1 = result.getMatchInfo().get(0);
+ assertThat(match1.getPropertyPath()).isEqualTo("sender.name");
+ assertThat(match1.getFullText()).isEqualTo("Test Name Jr.");
+ assertThat(match1.getExactMatch()).isEqualTo("Test");
+ assertThat(match1.getSnippet()).isEqualTo("Test Name");
+
+ MatchInfo match2 = result.getMatchInfo().get(1);
+ assertThat(match2.getPropertyPath()).isEqualTo("sender.email");
+ assertThat(match2.getFullText()).isEqualTo("TestNameJr@gmail.com");
+ assertThat(match2.getExactMatch()).isEqualTo("TestNameJr@gmail.com");
+ assertThat(match2.getSnippet()).isEqualTo("TestNameJr@gmail.com");
+ }
+ }
+}
diff --git a/core/tests/coretests/src/android/view/inputmethod/EditorInfoTest.java b/core/tests/coretests/src/android/view/inputmethod/EditorInfoTest.java
index 68099fe..12c057f 100644
--- a/core/tests/coretests/src/android/view/inputmethod/EditorInfoTest.java
+++ b/core/tests/coretests/src/android/view/inputmethod/EditorInfoTest.java
@@ -18,9 +18,15 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import android.annotation.Nullable;
import android.os.Parcel;
import android.os.UserHandle;
+import android.text.Spannable;
+import android.text.SpannableStringBuilder;
+import android.text.TextUtils;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -71,4 +77,227 @@
}
}
}
+
+ @Test
+ public void testNullTextInputComposeInitialSurroundingText() {
+ final Spannable testText = null;
+ final EditorInfo editorInfo = new EditorInfo();
+
+ try {
+ editorInfo.setInitialSurroundingText(testText);
+ fail("Shall not take null input");
+ } catch (NullPointerException expected) {
+ // Expected behavior, nothing to do.
+ }
+ }
+
+ @Test
+ public void testNonNullTextInputComposeInitialSurroundingText() {
+ final Spannable testText = createTestText(/* prependLength= */ 0,
+ EditorInfo.MEMORY_EFFICIENT_TEXT_LENGTH);
+ final EditorInfo editorInfo = new EditorInfo();
+
+ // Cursor at position 0.
+ int selectionLength = 0;
+ editorInfo.initialSelStart = 0;
+ editorInfo.initialSelEnd = editorInfo.initialSelStart + selectionLength;
+ int expectedTextBeforeCursorLength = 0;
+ int expectedTextAfterCursorLength = testText.length();
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength, selectionLength,
+ expectedTextAfterCursorLength);
+
+ // Cursor at the end.
+ editorInfo.initialSelStart = testText.length() - selectionLength;
+ editorInfo.initialSelEnd = testText.length();
+ expectedTextBeforeCursorLength = testText.length();
+ expectedTextAfterCursorLength = 0;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength, selectionLength,
+ expectedTextAfterCursorLength);
+
+ // Cursor at the middle.
+ selectionLength = 2;
+ editorInfo.initialSelStart = testText.length() / 2;
+ editorInfo.initialSelEnd = editorInfo.initialSelStart + selectionLength;
+ expectedTextBeforeCursorLength = editorInfo.initialSelStart;
+ expectedTextAfterCursorLength = testText.length() - editorInfo.initialSelEnd;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength, selectionLength,
+ expectedTextAfterCursorLength);
+
+ // Accidentally swap selection start and end.
+ editorInfo.initialSelEnd = testText.length() / 2;
+ editorInfo.initialSelStart = editorInfo.initialSelEnd + selectionLength;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength, selectionLength,
+ expectedTextAfterCursorLength);
+
+ // Invalid cursor position.
+ editorInfo.initialSelStart = -1;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo,
+ /* expectBeforeCursorLength= */null,
+ /* expectSelectionLength= */null,
+ /* expectAfterCursorLength= */null);
+ }
+
+ @Test
+ public void testTooLongTextInputComposeInitialSurroundingText() {
+ final Spannable testText = createTestText(/* prependLength= */ 0,
+ EditorInfo.MEMORY_EFFICIENT_TEXT_LENGTH + 2);
+ final EditorInfo editorInfo = new EditorInfo();
+
+ // Cursor at position 0.
+ int selectionLength = 0;
+ editorInfo.initialSelStart = 0;
+ editorInfo.initialSelEnd = 0 + selectionLength;
+ int expectedTextBeforeCursorLength = 0;
+ int expectedTextAfterCursorLength = editorInfo.MEMORY_EFFICIENT_TEXT_LENGTH;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength, selectionLength,
+ expectedTextAfterCursorLength);
+
+ // Cursor at the end.
+ editorInfo.initialSelStart = testText.length() - selectionLength;
+ editorInfo.initialSelEnd = testText.length();
+ expectedTextBeforeCursorLength = editorInfo.MEMORY_EFFICIENT_TEXT_LENGTH;
+ expectedTextAfterCursorLength = 0;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength, selectionLength,
+ expectedTextAfterCursorLength);
+
+ // Cursor at the middle.
+ selectionLength = 2;
+ editorInfo.initialSelStart = testText.length() / 2;
+ editorInfo.initialSelEnd = editorInfo.initialSelStart + selectionLength;
+ expectedTextBeforeCursorLength = Math.min(editorInfo.initialSelStart,
+ (int) (0.8 * (EditorInfo.MEMORY_EFFICIENT_TEXT_LENGTH - selectionLength)));
+ expectedTextAfterCursorLength = EditorInfo.MEMORY_EFFICIENT_TEXT_LENGTH
+ - expectedTextBeforeCursorLength - selectionLength;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength, selectionLength,
+ expectedTextAfterCursorLength);
+
+ // Accidentally swap selection start and end.
+ editorInfo.initialSelEnd = testText.length() / 2;
+ editorInfo.initialSelStart = editorInfo.initialSelEnd + selectionLength;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength, selectionLength,
+ expectedTextAfterCursorLength);
+
+ // Selection too long, selected text should be dropped.
+ selectionLength = EditorInfo.MAX_INITIAL_SELECTION_LENGTH + 1;
+ editorInfo.initialSelStart = testText.length() / 2;
+ editorInfo.initialSelEnd = editorInfo.initialSelStart + selectionLength;
+ expectedTextBeforeCursorLength = Math.min(editorInfo.initialSelStart,
+ (int) (0.8 * EditorInfo.MEMORY_EFFICIENT_TEXT_LENGTH));
+ expectedTextAfterCursorLength = testText.length() - editorInfo.initialSelEnd;
+
+ editorInfo.setInitialSurroundingText(testText);
+
+ assertExpectedTextLength(editorInfo, expectedTextBeforeCursorLength,
+ /* expectSelectionLength= */null, expectedTextAfterCursorLength);
+ }
+
+ @Test
+ public void testTooLongSubTextInputComposeInitialSurroundingText() {
+ final int prependLength = 5;
+ final int subTextLength = EditorInfo.MEMORY_EFFICIENT_TEXT_LENGTH;
+ final Spannable fullText = createTestText(prependLength, subTextLength);
+ final EditorInfo editorInfo = new EditorInfo();
+ // Cursor at the middle.
+ final int selectionLength = 2;
+ editorInfo.initialSelStart = fullText.length() / 2;
+ editorInfo.initialSelEnd = editorInfo.initialSelStart + selectionLength;
+ // #prependLength characters will be trimmed out.
+ final Spannable expectedTextBeforeCursor = createExpectedText(/* startNumber= */0,
+ editorInfo.initialSelStart - prependLength);
+ final Spannable expectedSelectedText = createExpectedText(
+ editorInfo.initialSelStart - prependLength, selectionLength);
+ final Spannable expectedTextAfterCursor = createExpectedText(
+ editorInfo.initialSelEnd - prependLength,
+ fullText.length() - editorInfo.initialSelEnd);
+
+ editorInfo.setInitialSurroundingSubText(fullText.subSequence(prependLength,
+ fullText.length()), prependLength);
+
+ assertTrue(TextUtils.equals(expectedTextBeforeCursor,
+ editorInfo.getInitialTextBeforeCursor(editorInfo.MEMORY_EFFICIENT_TEXT_LENGTH,
+ InputConnection.GET_TEXT_WITH_STYLES)));
+ assertTrue(TextUtils.equals(expectedSelectedText,
+ editorInfo.getInitialSelectedText(InputConnection.GET_TEXT_WITH_STYLES)));
+ assertTrue(TextUtils.equals(expectedTextAfterCursor,
+ editorInfo.getInitialTextAfterCursor(editorInfo.MEMORY_EFFICIENT_TEXT_LENGTH,
+ InputConnection.GET_TEXT_WITH_STYLES)));
+ }
+
+ private static void assertExpectedTextLength(EditorInfo editorInfo,
+ @Nullable Integer expectBeforeCursorLength, @Nullable Integer expectSelectionLength,
+ @Nullable Integer expectAfterCursorLength) {
+ final CharSequence textBeforeCursor =
+ editorInfo.getInitialTextBeforeCursor(editorInfo.MEMORY_EFFICIENT_TEXT_LENGTH,
+ InputConnection.GET_TEXT_WITH_STYLES);
+ final CharSequence selectedText =
+ editorInfo.getInitialSelectedText(InputConnection.GET_TEXT_WITH_STYLES);
+ final CharSequence textAfterCursor =
+ editorInfo.getInitialTextAfterCursor(editorInfo.MEMORY_EFFICIENT_TEXT_LENGTH,
+ InputConnection.GET_TEXT_WITH_STYLES);
+
+ if (expectBeforeCursorLength == null) {
+ assertNull(textBeforeCursor);
+ } else {
+ assertEquals(expectBeforeCursorLength.intValue(), textBeforeCursor.length());
+ }
+
+ if (expectSelectionLength == null) {
+ assertNull(selectedText);
+ } else {
+ assertEquals(expectSelectionLength.intValue(), selectedText.length());
+ }
+
+ if (expectAfterCursorLength == null) {
+ assertNull(textAfterCursor);
+ } else {
+ assertEquals(expectAfterCursorLength.intValue(), textAfterCursor.length());
+ }
+ }
+
+ private static Spannable createTestText(int prependLength, int surroundingLength) {
+ final SpannableStringBuilder builder = new SpannableStringBuilder();
+ for (int i = 0; i < prependLength; i++) {
+ builder.append("a");
+ }
+
+ for (int i = 0; i < surroundingLength; i++) {
+ builder.append(Integer.toString(i % 10));
+ }
+ return builder;
+ }
+
+ private static Spannable createExpectedText(int startNumber, int length) {
+ final SpannableStringBuilder builder = new SpannableStringBuilder();
+ for (int i = startNumber; i < startNumber + length; i++) {
+ builder.append(Integer.toString(i % 10));
+ }
+ return builder;
+ }
}
diff --git a/data/etc/platform.xml b/data/etc/platform.xml
index 877ef26..0541db1 100644
--- a/data/etc/platform.xml
+++ b/data/etc/platform.xml
@@ -60,10 +60,6 @@
<group gid="log" />
</permission>
- <permission name="android.permission.WRITE_MEDIA_STORAGE" >
- <group gid="media_rw" />
- </permission>
-
<permission name="android.permission.ACCESS_MTP" >
<group gid="mtp" />
</permission>
diff --git a/location/java/com/android/internal/location/ProviderRequest.java b/location/java/com/android/internal/location/ProviderRequest.java
index b2314c5..572fbc3 100644
--- a/location/java/com/android/internal/location/ProviderRequest.java
+++ b/location/java/com/android/internal/location/ProviderRequest.java
@@ -118,6 +118,7 @@
for (LocationRequest request : locationRequests) {
request.writeToParcel(parcel, flags);
}
+ parcel.writeParcelable(workSource, flags);
}
@Override
diff --git a/media/java/android/media/session/MediaSession.java b/media/java/android/media/session/MediaSession.java
index 9953626..870c1b4 100644
--- a/media/java/android/media/session/MediaSession.java
+++ b/media/java/android/media/session/MediaSession.java
@@ -146,6 +146,8 @@
* the system but will not be published until {@link #setActive(boolean)
* setActive(true)} is called. You must call {@link #release()} when
* finished with the session.
+ * <p>
+ * Note that {@link RuntimeException} will be thrown if an app creates too many sessions.
*
* @param context The context to use to create the session.
* @param tag A short name for debugging purposes.
@@ -163,6 +165,8 @@
* The {@code sessionInfo} can include additional unchanging information about this session.
* For example, it can include the version of the application, or the list of the custom
* commands that this session supports.
+ * <p>
+ * Note that {@link RuntimeException} will be thrown if an app creates too many sessions.
*
* @param context The context to use to create the session.
* @param tag A short name for debugging purposes.
diff --git a/media/java/android/media/tv/TvTrackInfo.java b/media/java/android/media/tv/TvTrackInfo.java
index 5e0b1ea..b40d43a 100644
--- a/media/java/android/media/tv/TvTrackInfo.java
+++ b/media/java/android/media/tv/TvTrackInfo.java
@@ -353,8 +353,7 @@
if (!TextUtils.equals(mId, obj.mId) || mType != obj.mType
|| !TextUtils.equals(mLanguage, obj.mLanguage)
|| !TextUtils.equals(mDescription, obj.mDescription)
- || mEncrypted != obj.mEncrypted
- || !Objects.equals(mExtra, obj.mExtra)) {
+ || mEncrypted != obj.mEncrypted) {
return false;
}
@@ -382,7 +381,16 @@
@Override
public int hashCode() {
- return Objects.hashCode(mId);
+ int result = Objects.hash(mId, mType, mLanguage, mDescription);
+
+ if (mType == TYPE_AUDIO) {
+ result = Objects.hash(result, mAudioChannelCount, mAudioSampleRate);
+ } else if (mType == TYPE_VIDEO) {
+ result = Objects.hash(result, mVideoWidth, mVideoHeight, mVideoFrameRate,
+ mVideoPixelAspectRatio);
+ }
+
+ return result;
}
public static final @android.annotation.NonNull Parcelable.Creator<TvTrackInfo> CREATOR =
diff --git a/media/java/android/media/voice/KeyphraseModelManager.java b/media/java/android/media/voice/KeyphraseModelManager.java
new file mode 100644
index 0000000..3fa38e0
--- /dev/null
+++ b/media/java/android/media/voice/KeyphraseModelManager.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2020 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.media.voice;
+
+import android.Manifest;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
+import android.annotation.SystemApi;
+import android.hardware.soundtrigger.SoundTrigger;
+import android.os.RemoteException;
+import android.os.ServiceSpecificException;
+import android.util.Slog;
+
+import com.android.internal.app.IVoiceInteractionManagerService;
+
+import java.util.Locale;
+import java.util.Objects;
+
+/**
+ * This class provides management of voice based sound recognition models. Usage of this class is
+ * restricted to system or signature applications only. This allows OEMs to write apps that can
+ * manage voice based sound trigger models.
+ * Callers of this class are expected to have whitelist manifest permission MANAGE_VOICE_KEYPHRASES.
+ * Callers of this class are expected to be the designated voice interaction service via
+ * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
+ * @hide
+ */
+@SystemApi
+public final class KeyphraseModelManager {
+ private static final boolean DBG = false;
+ private static final String TAG = "KeyphraseModelManager";
+
+ private final IVoiceInteractionManagerService mVoiceInteractionManagerService;
+
+ /**
+ * @hide
+ */
+ public KeyphraseModelManager(
+ IVoiceInteractionManagerService voiceInteractionManagerService) {
+ if (DBG) {
+ Slog.i(TAG, "KeyphraseModelManager created.");
+ }
+ mVoiceInteractionManagerService = voiceInteractionManagerService;
+ }
+
+
+ /**
+ * Gets the registered sound model for keyphrase detection for the current user.
+ * The keyphraseId and locale passed must match a supported model passed in via
+ * {@link #updateKeyphraseSoundModel}.
+ * If the active voice interaction service changes from the current user, all requests will be
+ * rejected, and any registered models will be unregistered.
+ *
+ * @param keyphraseId The unique identifier for the keyphrase.
+ * @param locale The locale language tag supported by the desired model.
+ * @return Registered keyphrase sound model matching the keyphrase ID and locale. May be null if
+ * no matching sound model exists.
+ * @throws SecurityException Thrown when caller does not have MANAGE_VOICE_KEYPHRASES permission
+ * or if the caller is not the active voice interaction service.
+ */
+ @RequiresPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES)
+ @Nullable
+ public SoundTrigger.KeyphraseSoundModel getKeyphraseSoundModel(int keyphraseId,
+ @NonNull Locale locale) {
+ Objects.requireNonNull(locale);
+ try {
+ return mVoiceInteractionManagerService.getKeyphraseSoundModel(keyphraseId,
+ locale.toLanguageTag());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Add or update the given keyphrase sound model to the registered models pool for the current
+ * user.
+ * If a model exists with the same Keyphrase ID, locale, and user list. The registered model
+ * will be overwritten with the new model.
+ * If the active voice interaction service changes from the current user, all requests will be
+ * rejected, and any registered models will be unregistered.
+ *
+ * @param model Keyphrase sound model to be updated.
+ * @throws ServiceSpecificException Thrown with error code if failed to update the keyphrase
+ * sound model.
+ * @throws SecurityException Thrown when caller does not have MANAGE_VOICE_KEYPHRASES permission
+ * or if the caller is not the active voice interaction service.
+ */
+ @RequiresPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES)
+ public void updateKeyphraseSoundModel(@NonNull SoundTrigger.KeyphraseSoundModel model) {
+ Objects.requireNonNull(model);
+ try {
+ int status = mVoiceInteractionManagerService.updateKeyphraseSoundModel(model);
+ if (status != SoundTrigger.STATUS_OK) {
+ throw new ServiceSpecificException(status);
+ }
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Delete keyphrase sound model from the registered models pool for the current user matching\
+ * the keyphrase ID and locale.
+ * The keyphraseId and locale passed must match a supported model passed in via
+ * {@link #updateKeyphraseSoundModel}.
+ * If the active voice interaction service changes from the current user, all requests will be
+ * rejected, and any registered models will be unregistered.
+ *
+ * @param keyphraseId The unique identifier for the keyphrase.
+ * @param locale The locale language tag supported by the desired model.
+ * @throws ServiceSpecificException Thrown with error code if failed to delete the keyphrase
+ * sound model.
+ * @throws SecurityException Thrown when caller does not have MANAGE_VOICE_KEYPHRASES permission
+ * or if the caller is not the active voice interaction service.
+ */
+ @RequiresPermission(Manifest.permission.MANAGE_VOICE_KEYPHRASES)
+ public void deleteKeyphraseSoundModel(int keyphraseId, @NonNull Locale locale) {
+ Objects.requireNonNull(locale);
+ try {
+ int status = mVoiceInteractionManagerService.deleteKeyphraseSoundModel(keyphraseId,
+ locale.toLanguageTag());
+ if (status != SoundTrigger.STATUS_OK) {
+ throw new ServiceSpecificException(status);
+ }
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+}
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index c913999..486386f 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -62,6 +62,7 @@
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.Process;
+import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.SELinux;
import android.os.ServiceManager;
@@ -275,6 +276,9 @@
private final Object mLock = new Object();
@GuardedBy("mLock")
+ private RemoteCallback mConfigMonitorCallback;
+
+ @GuardedBy("mLock")
private SettingsRegistry mSettingsRegistry;
@GuardedBy("mLock")
@@ -450,8 +454,17 @@
case Settings.CALL_METHOD_LIST_CONFIG: {
String prefix = getSettingPrefix(args);
- return packageValuesForCallResult(getAllConfigFlags(prefix),
+ Bundle result = packageValuesForCallResult(getAllConfigFlags(prefix),
isTrackingGeneration(args));
+ reportDeviceConfigAccess(prefix);
+ return result;
+ }
+
+ case Settings.CALL_METHOD_REGISTER_MONITOR_CALLBACK_CONFIG: {
+ RemoteCallback callback = args.getParcelable(
+ Settings.CALL_METHOD_MONITOR_CALLBACK_KEY);
+ setMonitorCallback(callback);
+ break;
}
case Settings.CALL_METHOD_LIST_GLOBAL: {
@@ -1052,8 +1065,9 @@
enforceWritePermission(Manifest.permission.WRITE_DEVICE_CONFIG);
synchronized (mLock) {
- return mSettingsRegistry.setSettingsLocked(SETTINGS_TYPE_CONFIG, UserHandle.USER_SYSTEM,
- prefix, keyValues, resolveCallingPackage());
+ final int key = makeKey(SETTINGS_TYPE_CONFIG, UserHandle.USER_SYSTEM);
+ return mSettingsRegistry.setConfigSettingsLocked(key, prefix, keyValues,
+ resolveCallingPackage());
}
}
@@ -2155,6 +2169,59 @@
return result;
}
+ private void setMonitorCallback(RemoteCallback callback) {
+ if (callback == null) {
+ return;
+ }
+ getContext().enforceCallingOrSelfPermission(
+ Manifest.permission.MONITOR_DEVICE_CONFIG_ACCESS,
+ "Permission denial: registering for config access requires: "
+ + Manifest.permission.MONITOR_DEVICE_CONFIG_ACCESS);
+ synchronized (mLock) {
+ mConfigMonitorCallback = callback;
+ }
+ }
+
+ private void reportDeviceConfigAccess(@Nullable String prefix) {
+ if (prefix == null) {
+ return;
+ }
+ String callingPackage = getCallingPackage();
+ String namespace = prefix.replace("/", "");
+ if (DeviceConfig.getPublicNamespaces().contains(namespace)) {
+ return;
+ }
+ synchronized (mLock) {
+ if (mConfigMonitorCallback != null) {
+ Bundle callbackResult = new Bundle();
+ callbackResult.putString(Settings.EXTRA_MONITOR_CALLBACK_TYPE,
+ Settings.EXTRA_ACCESS_CALLBACK);
+ callbackResult.putString(Settings.EXTRA_CALLING_PACKAGE, callingPackage);
+ callbackResult.putString(Settings.EXTRA_NAMESPACE, namespace);
+ mConfigMonitorCallback.sendResult(callbackResult);
+ }
+ }
+ }
+
+ private void reportDeviceConfigUpdate(@Nullable String prefix) {
+ if (prefix == null) {
+ return;
+ }
+ String namespace = prefix.replace("/", "");
+ if (DeviceConfig.getPublicNamespaces().contains(namespace)) {
+ return;
+ }
+ synchronized (mLock) {
+ if (mConfigMonitorCallback != null) {
+ Bundle callbackResult = new Bundle();
+ callbackResult.putString(Settings.EXTRA_MONITOR_CALLBACK_TYPE,
+ Settings.EXTRA_NAMESPACE_UPDATED_CALLBACK);
+ callbackResult.putString(Settings.EXTRA_NAMESPACE, namespace);
+ mConfigMonitorCallback.sendResult(callbackResult);
+ }
+ }
+ }
+
private static int getRequestingUserId(Bundle args) {
final int callingUserId = UserHandle.getCallingUserId();
return (args != null) ? args.getInt(Settings.CALL_METHOD_USER_KEY, callingUserId)
@@ -2715,22 +2782,20 @@
}
/**
- * Set Settings using consumed keyValues, returns true if the keyValues can be set, false
- * otherwise.
+ * Set Config Settings using consumed keyValues, returns true if the keyValues can be set,
+ * false otherwise.
*/
- public boolean setSettingsLocked(int type, int userId, String prefix,
+ public boolean setConfigSettingsLocked(int key, String prefix,
Map<String, String> keyValues, String packageName) {
- final int key = makeKey(type, userId);
-
SettingsState settingsState = peekSettingsStateLocked(key);
if (settingsState != null) {
- if (SETTINGS_TYPE_CONFIG == type && settingsState.isNewConfigBannedLocked(prefix,
- keyValues)) {
+ if (settingsState.isNewConfigBannedLocked(prefix, keyValues)) {
return false;
}
List<String> changedSettings =
settingsState.setSettingsLocked(prefix, keyValues, packageName);
if (!changedSettings.isEmpty()) {
+ reportDeviceConfigUpdate(prefix);
notifyForConfigSettingsChangeLocked(key, prefix, changedSettings);
}
}
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java
index 70a464d..871cae3 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/UniversalSmartspaceUtils.java
@@ -37,7 +37,7 @@
Intent intent = new Intent(ACTION_REQUEST_SMARTSPACE_VIEW);
Bundle inputBundle = new Bundle();
- inputBundle.putBinder(BUNDLE_KEY_INPUT_TOKEN, surfaceView.getInputToken());
+ inputBundle.putBinder(BUNDLE_KEY_INPUT_TOKEN, surfaceView.getHostToken());
return intent
.putExtra(INTENT_KEY_SURFACE_CONTROL, surfaceView.getSurfaceControl())
.putExtra(INTENT_KEY_INPUT_BUNDLE, inputBundle)
diff --git a/packages/SystemUI/src/com/android/keyguard/AdminSecondaryLockScreenController.java b/packages/SystemUI/src/com/android/keyguard/AdminSecondaryLockScreenController.java
index 2f8ef2d..b2423b9 100644
--- a/packages/SystemUI/src/com/android/keyguard/AdminSecondaryLockScreenController.java
+++ b/packages/SystemUI/src/com/android/keyguard/AdminSecondaryLockScreenController.java
@@ -172,7 +172,7 @@
private void onSurfaceReady() {
try {
- mClient.onSurfaceReady(mView.getInputToken(), mCallback);
+ mClient.onSurfaceReady(mView.getHostToken(), mCallback);
} catch (RemoteException e) {
Log.e(TAG, "Error in onSurfaceReady", e);
dismiss(KeyguardUpdateMonitor.getCurrentUser());
diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
index 4a5bc2a..0106609 100644
--- a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
+++ b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java
@@ -39,7 +39,6 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
-import com.android.internal.telephony.TelephonyIntents;
import com.android.settingslib.WirelessUtils;
import com.android.systemui.Dependency;
import com.android.systemui.R;
@@ -337,15 +336,15 @@
CharSequence text =
getContext().getText(com.android.internal.R.string.emergency_calls_only);
Intent i = getContext().registerReceiver(null,
- new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
+ new IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED));
if (i != null) {
String spn = "";
String plmn = "";
- if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false)) {
- spn = i.getStringExtra(TelephonyIntents.EXTRA_SPN);
+ if (i.getBooleanExtra(TelephonyManager.EXTRA_SHOW_SPN, false)) {
+ spn = i.getStringExtra(TelephonyManager.EXTRA_SPN);
}
- if (i.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false)) {
- plmn = i.getStringExtra(TelephonyIntents.EXTRA_PLMN);
+ if (i.getBooleanExtra(TelephonyManager.EXTRA_SHOW_PLMN, false)) {
+ plmn = i.getStringExtra(TelephonyManager.EXTRA_PLMN);
}
if (DEBUG) Log.d(TAG, "Getting plmn/spn sticky brdcst " + plmn + "/" + spn);
if (Objects.equals(plmn, spn)) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java
index e675a7f..5dc9104 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java
@@ -29,7 +29,6 @@
import android.util.AttributeSet;
import android.widget.TextView;
-import com.android.internal.telephony.TelephonyIntents;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.systemui.Dependency;
@@ -137,9 +136,9 @@
displayText = getContext().getText(
com.android.internal.R.string.emergency_calls_only);
Intent i = getContext().registerReceiver(null,
- new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
+ new IntentFilter(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED));
if (i != null) {
- displayText = i.getStringExtra(TelephonyIntents.EXTRA_PLMN);
+ displayText = i.getStringExtra(TelephonyManager.EXTRA_PLMN);
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
index a76d41c..3a1feaa 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/MobileSignalController.java
@@ -41,7 +41,6 @@
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.telephony.TelephonyIntents;
import com.android.settingslib.Utils;
import com.android.settingslib.graph.SignalDrawable;
import com.android.settingslib.net.SignalStrengthUtil;
@@ -430,12 +429,12 @@
public void handleBroadcast(Intent intent) {
String action = intent.getAction();
- if (action.equals(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION)) {
- updateNetworkName(intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false),
- intent.getStringExtra(TelephonyIntents.EXTRA_SPN),
- intent.getStringExtra(TelephonyIntents.EXTRA_DATA_SPN),
- intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false),
- intent.getStringExtra(TelephonyIntents.EXTRA_PLMN));
+ if (action.equals(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED)) {
+ updateNetworkName(intent.getBooleanExtra(TelephonyManager.EXTRA_SHOW_SPN, false),
+ intent.getStringExtra(TelephonyManager.EXTRA_SPN),
+ intent.getStringExtra(TelephonyManager.EXTRA_DATA_SPN),
+ intent.getBooleanExtra(TelephonyManager.EXTRA_SHOW_PLMN, false),
+ intent.getStringExtra(TelephonyManager.EXTRA_PLMN));
notifyListenersIfNecessary();
} else if (action.equals(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
updateDataSim();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
index 899279d..50052b8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java
@@ -319,7 +319,7 @@
filter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
filter.addAction(TelephonyManager.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED);
filter.addAction(Intent.ACTION_SERVICE_STATE);
- filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
+ filter.addAction(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED);
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java
index cd89d3c..4406248 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/NetworkControllerSignalTest.java
@@ -36,7 +36,6 @@
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
-import com.android.internal.telephony.TelephonyIntents;
import com.android.settingslib.graph.SignalDrawable;
import com.android.settingslib.net.DataUsageController;
import com.android.systemui.R;
@@ -411,13 +410,13 @@
boolean showPlmn, String plmn) {
Intent intent = new Intent();
- intent.setAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
+ intent.setAction(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED);
- intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn);
- intent.putExtra(TelephonyIntents.EXTRA_SPN, spn);
+ intent.putExtra(TelephonyManager.EXTRA_SHOW_SPN, showSpn);
+ intent.putExtra(TelephonyManager.EXTRA_SPN, spn);
- intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
- intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
+ intent.putExtra(TelephonyManager.EXTRA_SHOW_PLMN, showPlmn);
+ intent.putExtra(TelephonyManager.EXTRA_PLMN, plmn);
SubscriptionManager.putSubscriptionIdExtra(intent, mSubId);
return intent;
diff --git a/packages/Tethering/common/TetheringLib/Android.bp b/packages/Tethering/common/TetheringLib/Android.bp
index 264ce44..a8d1239 100644
--- a/packages/Tethering/common/TetheringLib/Android.bp
+++ b/packages/Tethering/common/TetheringLib/Android.bp
@@ -36,6 +36,7 @@
sdk_version: "system_current",
srcs: [
"src/android/net/TetheringManager.java",
+ "src/android/net/TetheringConstants.java",
":framework-tethering-annotations",
],
static_libs: [
@@ -63,9 +64,11 @@
name: "framework-tethering-srcs",
srcs: [
"src/android/net/TetheringManager.java",
+ "src/android/net/TetheringConstants.java",
"src/android/net/IIntResultListener.aidl",
"src/android/net/ITetheringEventCallback.aidl",
"src/android/net/ITetheringConnector.aidl",
+ "src/android/net/TetheringCallbackStartedParcel.aidl",
"src/android/net/TetheringConfigurationParcel.aidl",
"src/android/net/TetherStatesParcel.aidl",
],
diff --git a/packages/Tethering/common/TetheringLib/src/android/net/ITetheringEventCallback.aidl b/packages/Tethering/common/TetheringLib/src/android/net/ITetheringEventCallback.aidl
index 2836195..28a810d 100644
--- a/packages/Tethering/common/TetheringLib/src/android/net/ITetheringEventCallback.aidl
+++ b/packages/Tethering/common/TetheringLib/src/android/net/ITetheringEventCallback.aidl
@@ -18,6 +18,7 @@
import android.net.Network;
import android.net.TetheringConfigurationParcel;
+import android.net.TetheringCallbackStartedParcel;
import android.net.TetherStatesParcel;
/**
@@ -26,8 +27,8 @@
*/
oneway interface ITetheringEventCallback
{
- void onCallbackStarted(in Network network, in TetheringConfigurationParcel config,
- in TetherStatesParcel states);
+ /** Called immediately after the callbacks are registered */
+ void onCallbackStarted(in TetheringCallbackStartedParcel parcel);
void onCallbackStopped(int errorCode);
void onUpstreamChanged(in Network network);
void onConfigurationChanged(in TetheringConfigurationParcel config);
diff --git a/packages/Tethering/common/TetheringLib/src/android/net/TetheringCallbackStartedParcel.aidl b/packages/Tethering/common/TetheringLib/src/android/net/TetheringCallbackStartedParcel.aidl
new file mode 100644
index 0000000..14ee2d3
--- /dev/null
+++ b/packages/Tethering/common/TetheringLib/src/android/net/TetheringCallbackStartedParcel.aidl
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2020 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.net;
+
+import android.net.Network;
+import android.net.TetheringConfigurationParcel;
+import android.net.TetherStatesParcel;
+
+/**
+ * Initial information reported by tethering upon callback registration.
+ * @hide
+ */
+parcelable TetheringCallbackStartedParcel {
+ boolean tetheringSupported;
+ Network upstreamNetwork;
+ TetheringConfigurationParcel config;
+ TetherStatesParcel states;
+}
\ No newline at end of file
diff --git a/packages/Tethering/common/TetheringLib/src/android/net/TetheringConstants.java b/packages/Tethering/common/TetheringLib/src/android/net/TetheringConstants.java
new file mode 100644
index 0000000..00cf98e
--- /dev/null
+++ b/packages/Tethering/common/TetheringLib/src/android/net/TetheringConstants.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2020 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.net;
+
+import android.os.ResultReceiver;
+
+/**
+ * Collections of constants for internal tethering usage.
+ *
+ * <p>These hidden constants are not in TetheringManager as they are not part of the API stubs
+ * generated for TetheringManager, which prevents the tethering module from linking them at
+ * build time.
+ * TODO: investigate changing the tethering build rules so that Tethering can reference hidden
+ * symbols from framework-tethering even when they are in a non-hidden class.
+ * @hide
+ */
+public class TetheringConstants {
+ /**
+ * Extra used for communicating with the TetherService. Includes the type of tethering to
+ * enable if any.
+ *
+ * {@hide}
+ */
+ public static final String EXTRA_ADD_TETHER_TYPE = "extraAddTetherType";
+ /**
+ * Extra used for communicating with the TetherService. Includes the type of tethering for
+ * which to cancel provisioning.
+ *
+ * {@hide}
+ */
+ public static final String EXTRA_REM_TETHER_TYPE = "extraRemTetherType";
+ /**
+ * Extra used for communicating with the TetherService. True to schedule a recheck of tether
+ * provisioning.
+ *
+ * {@hide}
+ */
+ public static final String EXTRA_SET_ALARM = "extraSetAlarm";
+ /**
+ * Tells the TetherService to run a provision check now.
+ *
+ * {@hide}
+ */
+ public static final String EXTRA_RUN_PROVISION = "extraRunProvision";
+ /**
+ * Extra used for communicating with the TetherService. Contains the {@link ResultReceiver}
+ * which will receive provisioning results. Can be left empty.
+ *
+ * {@hide}
+ */
+ public static final String EXTRA_PROVISION_CALLBACK = "extraProvisionCallback";
+}
diff --git a/packages/Tethering/common/TetheringLib/src/android/net/TetheringManager.java b/packages/Tethering/common/TetheringLib/src/android/net/TetheringManager.java
index 11e5718..e1b9c16 100644
--- a/packages/Tethering/common/TetheringLib/src/android/net/TetheringManager.java
+++ b/packages/Tethering/common/TetheringLib/src/android/net/TetheringManager.java
@@ -16,8 +16,12 @@
package android.net;
import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.RequiresPermission;
+import android.annotation.SystemApi;
+import android.annotation.TestApi;
import android.content.Context;
-import android.net.ConnectivityManager.OnTetheringEventCallback;
+import android.os.Bundle;
import android.os.ConditionVariable;
import android.os.IBinder;
import android.os.RemoteException;
@@ -25,6 +29,11 @@
import android.util.ArrayMap;
import android.util.Log;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -34,7 +43,8 @@
*
* @hide
*/
-// TODO: make it @SystemApi
+@SystemApi
+@TestApi
public class TetheringManager {
private static final String TAG = TetheringManager.class.getSimpleName();
private static final int DEFAULT_TIMEOUT_MS = 60_000;
@@ -44,7 +54,7 @@
private final ITetheringConnector mConnector;
private final TetheringCallbackInternal mCallback;
private final Context mContext;
- private final ArrayMap<OnTetheringEventCallback, ITetheringEventCallback>
+ private final ArrayMap<TetheringEventCallback, ITetheringEventCallback>
mTetheringEventCallbacks = new ArrayMap<>();
private TetheringConfigurationParcel mTetheringConfiguration;
@@ -72,7 +82,7 @@
* gives a String[] listing all the interfaces currently in local-only
* mode (ie, has DHCPv4+IPv6-ULA support and no packet forwarding)
*/
- public static final String EXTRA_ACTIVE_LOCAL_ONLY = "localOnlyArray";
+ public static final String EXTRA_ACTIVE_LOCAL_ONLY = "android.net.extra.ACTIVE_LOCAL_ONLY";
/**
* gives a String[] listing all the interfaces currently tethered
@@ -118,35 +128,6 @@
*/
public static final int TETHERING_WIFI_P2P = 3;
- /**
- * Extra used for communicating with the TetherService. Includes the type of tethering to
- * enable if any.
- */
- public static final String EXTRA_ADD_TETHER_TYPE = "extraAddTetherType";
-
- /**
- * Extra used for communicating with the TetherService. Includes the type of tethering for
- * which to cancel provisioning.
- */
- public static final String EXTRA_REM_TETHER_TYPE = "extraRemTetherType";
-
- /**
- * Extra used for communicating with the TetherService. True to schedule a recheck of tether
- * provisioning.
- */
- public static final String EXTRA_SET_ALARM = "extraSetAlarm";
-
- /**
- * Tells the TetherService to run a provision check now.
- */
- public static final String EXTRA_RUN_PROVISION = "extraRunProvision";
-
- /**
- * Extra used for communicating with the TetherService. Contains the {@link ResultReceiver}
- * which will receive provisioning results. Can be left empty.
- */
- public static final String EXTRA_PROVISION_CALLBACK = "extraProvisionCallback";
-
public static final int TETHER_ERROR_NO_ERROR = 0;
public static final int TETHER_ERROR_UNKNOWN_IFACE = 1;
public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2;
@@ -160,12 +141,14 @@
public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10;
public static final int TETHER_ERROR_PROVISION_FAILED = 11;
public static final int TETHER_ERROR_DHCPSERVER_ERROR = 12;
- public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN = 13;
+ public static final int TETHER_ERROR_ENTITLEMENT_UNKNOWN = 13;
public static final int TETHER_ERROR_NO_CHANGE_TETHERING_PERMISSION = 14;
public static final int TETHER_ERROR_NO_ACCESS_TETHERING_PERMISSION = 15;
/**
* Create a TetheringManager object for interacting with the tethering service.
+ *
+ * {@hide}
*/
public TetheringManager(@NonNull final Context context, @NonNull final IBinder service) {
mContext = context;
@@ -229,10 +212,9 @@
private final ConditionVariable mWaitForCallback = new ConditionVariable();
@Override
- public void onCallbackStarted(Network network, TetheringConfigurationParcel config,
- TetherStatesParcel states) {
- mTetheringConfiguration = config;
- mTetherStatesParcel = states;
+ public void onCallbackStarted(TetheringCallbackStartedParcel parcel) {
+ mTetheringConfiguration = parcel.config;
+ mTetherStatesParcel = parcel.states;
mWaitForCallback.open();
}
@@ -275,6 +257,8 @@
*
* @param iface the interface name to tether.
* @return error a {@code TETHER_ERROR} value indicating success or failure type
+ *
+ * {@hide}
*/
@Deprecated
public int tether(@NonNull final String iface) {
@@ -296,6 +280,8 @@
*
* @deprecated The only usages is PanService. It uses this for legacy reasons
* and will migrate away as soon as possible.
+ *
+ * {@hide}
*/
@Deprecated
public int untether(@NonNull final String iface) {
@@ -320,6 +306,8 @@
* #startTethering or #stopTethering which encapsulate proper entitlement logic. If the API is
* used and an entitlement check is needed, downstream USB tethering will be enabled but will
* not have any upstream.
+ *
+ * {@hide}
*/
@Deprecated
public int setUsbTethering(final boolean enable) {
@@ -340,7 +328,7 @@
/**
* Starts tethering and runs tether provisioning for the given type if needed. If provisioning
* fails, stopTethering will be called automatically.
- *
+ * @hide
*/
// TODO: improve the usage of ResultReceiver, b/145096122
public void startTethering(final int type, @NonNull final ResultReceiver receiver,
@@ -375,11 +363,63 @@
}
/**
+ * Callback for use with {@link #getLatestTetheringEntitlementResult} to find out whether
+ * entitlement succeeded.
+ */
+ public interface OnTetheringEntitlementResultListener {
+ /**
+ * Called to notify entitlement result.
+ *
+ * @param resultCode an int value of entitlement result. It may be one of
+ * {@link #TETHER_ERROR_NO_ERROR},
+ * {@link #TETHER_ERROR_PROVISION_FAILED}, or
+ * {@link #TETHER_ERROR_ENTITLEMENT_UNKNOWN}.
+ */
+ void onTetheringEntitlementResult(int resultCode);
+ }
+
+ /**
* Request the latest value of the tethering entitlement check.
*
- * Note: Allow privileged apps who have TETHER_PRIVILEGED permission to access. If it turns
- * out some such apps are observed to abuse this API, change to per-UID limits on this API
- * if it's really needed.
+ * <p>This method will only return the latest entitlement result if it is available. If no
+ * cached entitlement result is available, and {@code showEntitlementUi} is false,
+ * {@link #TETHER_ERROR_ENTITLEMENT_UNKNOWN} will be returned. If {@code showEntitlementUi} is
+ * true, entitlement will be run.
+ *
+ * @param type the downstream type of tethering. Must be one of {@code #TETHERING_*} constants.
+ * @param showEntitlementUi a boolean indicating whether to run UI-based entitlement check.
+ * @param executor the executor on which callback will be invoked.
+ * @param listener an {@link OnTetheringEntitlementResultListener} which will be called to
+ * notify the caller of the result of entitlement check. The listener may be called zero
+ * or one time.
+ */
+ @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
+ public void requestLatestTetheringEntitlementResult(int type, boolean showEntitlementUi,
+ @NonNull Executor executor,
+ @NonNull final OnTetheringEntitlementResultListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException(
+ "OnTetheringEntitlementResultListener cannot be null.");
+ }
+
+ ResultReceiver wrappedListener = new ResultReceiver(null /* handler */) {
+ @Override
+ protected void onReceiveResult(int resultCode, Bundle resultData) {
+ executor.execute(() -> {
+ listener.onTetheringEntitlementResult(resultCode);
+ });
+ }
+ };
+
+ requestLatestTetheringEntitlementResult(type, wrappedListener,
+ showEntitlementUi);
+ }
+
+ /**
+ * Helper function of #requestLatestTetheringEntitlementResult to remain backwards compatible
+ * with ConnectivityManager#getLatestTetheringEntitlementResult
+ *
+ * {@hide}
*/
// TODO: improve the usage of ResultReceiver, b/145096122
public void requestLatestTetheringEntitlementResult(final int type,
@@ -396,9 +436,126 @@
}
/**
+ * Callback for use with {@link registerTetheringEventCallback} to find out tethering
+ * upstream status.
+ */
+ public abstract static class TetheringEventCallback {
+ /**
+ * Called when tethering supported status changed.
+ *
+ * <p>This will be called immediately after the callback is registered, and may be called
+ * multiple times later upon changes.
+ *
+ * <p>Tethering may be disabled via system properties, device configuration, or device
+ * policy restrictions.
+ *
+ * @param supported The new supported status
+ */
+ public void onTetheringSupported(boolean supported) {}
+
+ /**
+ * Called when tethering upstream changed.
+ *
+ * <p>This will be called immediately after the callback is registered, and may be called
+ * multiple times later upon changes.
+ *
+ * @param network the {@link Network} of tethering upstream. Null means tethering doesn't
+ * have any upstream.
+ */
+ public void onUpstreamChanged(@Nullable Network network) {}
+
+ /**
+ * Called when there was a change in tethering interface regular expressions.
+ *
+ * <p>This will be called immediately after the callback is registered, and may be called
+ * multiple times later upon changes.
+ * @param reg The new regular expressions.
+ * @deprecated Referencing interfaces by regular expressions is a deprecated mechanism.
+ */
+ @Deprecated
+ public void onTetherableInterfaceRegexpsChanged(@NonNull TetheringInterfaceRegexps reg) {}
+
+ /**
+ * Called when there was a change in the list of tetherable interfaces.
+ *
+ * <p>This will be called immediately after the callback is registered, and may be called
+ * multiple times later upon changes.
+ * @param interfaces The list of tetherable interfaces.
+ */
+ public void onTetherableInterfacesChanged(@NonNull List<String> interfaces) {}
+
+ /**
+ * Called when there was a change in the list of tethered interfaces.
+ *
+ * <p>This will be called immediately after the callback is registered, and may be called
+ * multiple times later upon changes.
+ * @param interfaces The list of tethered interfaces.
+ */
+ public void onTetheredInterfacesChanged(@NonNull List<String> interfaces) {}
+
+ /**
+ * Called when an error occurred configuring tethering.
+ *
+ * <p>This will be called immediately after the callback is registered if the latest status
+ * on the interface is an error, and may be called multiple times later upon changes.
+ * @param ifName Name of the interface.
+ * @param error One of {@code TetheringManager#TETHER_ERROR_*}.
+ */
+ public void onError(@NonNull String ifName, int error) {}
+ }
+
+ /**
+ * Regular expressions used to identify tethering interfaces.
+ * @deprecated Referencing interfaces by regular expressions is a deprecated mechanism.
+ */
+ @Deprecated
+ public static class TetheringInterfaceRegexps {
+ private final String[] mTetherableBluetoothRegexs;
+ private final String[] mTetherableUsbRegexs;
+ private final String[] mTetherableWifiRegexs;
+
+ public TetheringInterfaceRegexps(@NonNull String[] tetherableBluetoothRegexs,
+ @NonNull String[] tetherableUsbRegexs, @NonNull String[] tetherableWifiRegexs) {
+ mTetherableBluetoothRegexs = tetherableBluetoothRegexs.clone();
+ mTetherableUsbRegexs = tetherableUsbRegexs.clone();
+ mTetherableWifiRegexs = tetherableWifiRegexs.clone();
+ }
+
+ @NonNull
+ public List<String> getTetherableBluetoothRegexs() {
+ return Collections.unmodifiableList(Arrays.asList(mTetherableBluetoothRegexs));
+ }
+
+ @NonNull
+ public List<String> getTetherableUsbRegexs() {
+ return Collections.unmodifiableList(Arrays.asList(mTetherableUsbRegexs));
+ }
+
+ @NonNull
+ public List<String> getTetherableWifiRegexs() {
+ return Collections.unmodifiableList(Arrays.asList(mTetherableWifiRegexs));
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mTetherableBluetoothRegexs, mTetherableUsbRegexs,
+ mTetherableWifiRegexs);
+ }
+
+ @Override
+ public boolean equals(@Nullable Object obj) {
+ if (!(obj instanceof TetheringInterfaceRegexps)) return false;
+ final TetheringInterfaceRegexps other = (TetheringInterfaceRegexps) obj;
+ return Arrays.equals(mTetherableBluetoothRegexs, other.mTetherableBluetoothRegexs)
+ && Arrays.equals(mTetherableUsbRegexs, other.mTetherableUsbRegexs)
+ && Arrays.equals(mTetherableWifiRegexs, other.mTetherableWifiRegexs);
+ }
+ }
+
+ /**
* Start listening to tethering change events. Any new added callback will receive the last
* tethering status right away. If callback is registered,
- * {@link OnTetheringEventCallback#onUpstreamChanged} will immediately be called. If tethering
+ * {@link TetheringEventCallback#onUpstreamChanged} will immediately be called. If tethering
* has no upstream or disabled, the argument of callback will be null. The same callback object
* cannot be registered twice.
*
@@ -406,15 +563,20 @@
* @param callback the callback to be called when tethering has change events.
*/
public void registerTetheringEventCallback(@NonNull Executor executor,
- @NonNull OnTetheringEventCallback callback) {
+ @NonNull TetheringEventCallback callback) {
final String callerPkg = mContext.getOpPackageName();
Log.i(TAG, "registerTetheringEventCallback caller:" + callerPkg);
synchronized (mTetheringEventCallbacks) {
- if (!mTetheringEventCallbacks.containsKey(callback)) {
+ if (mTetheringEventCallbacks.containsKey(callback)) {
throw new IllegalArgumentException("callback was already registered.");
}
final ITetheringEventCallback remoteCallback = new ITetheringEventCallback.Stub() {
+ // Only accessed with a lock on this object
+ private final HashMap<String, Integer> mErrorStates = new HashMap<>();
+ private String[] mLastTetherableInterfaces = null;
+ private String[] mLastTetheredInterfaces = null;
+
@Override
public void onUpstreamChanged(Network network) throws RemoteException {
executor.execute(() -> {
@@ -422,11 +584,45 @@
});
}
+ private synchronized void sendErrorCallbacks(final TetherStatesParcel newStates) {
+ for (int i = 0; i < newStates.erroredIfaceList.length; i++) {
+ final String iface = newStates.erroredIfaceList[i];
+ final Integer lastError = mErrorStates.get(iface);
+ final int newError = newStates.lastErrorList[i];
+ if (newError != TETHER_ERROR_NO_ERROR
+ && !Objects.equals(lastError, newError)) {
+ callback.onError(iface, newError);
+ }
+ mErrorStates.put(iface, newError);
+ }
+ }
+
+ private synchronized void maybeSendTetherableIfacesChangedCallback(
+ final TetherStatesParcel newStates) {
+ if (Arrays.equals(mLastTetherableInterfaces, newStates.availableList)) return;
+ mLastTetherableInterfaces = newStates.availableList.clone();
+ callback.onTetherableInterfacesChanged(
+ Collections.unmodifiableList(Arrays.asList(mLastTetherableInterfaces)));
+ }
+
+ private synchronized void maybeSendTetheredIfacesChangedCallback(
+ final TetherStatesParcel newStates) {
+ if (Arrays.equals(mLastTetheredInterfaces, newStates.tetheredList)) return;
+ mLastTetheredInterfaces = newStates.tetheredList.clone();
+ callback.onTetheredInterfacesChanged(
+ Collections.unmodifiableList(Arrays.asList(mLastTetheredInterfaces)));
+ }
+
+ // Called immediately after the callbacks are registered.
@Override
- public void onCallbackStarted(Network network, TetheringConfigurationParcel config,
- TetherStatesParcel states) {
+ public void onCallbackStarted(TetheringCallbackStartedParcel parcel) {
executor.execute(() -> {
- callback.onUpstreamChanged(network);
+ callback.onTetheringSupported(parcel.tetheringSupported);
+ callback.onUpstreamChanged(parcel.upstreamNetwork);
+ sendErrorCallbacks(parcel.states);
+ sendRegexpsChanged(parcel.config);
+ maybeSendTetherableIfacesChangedCallback(parcel.states);
+ maybeSendTetheredIfacesChangedCallback(parcel.states);
});
}
@@ -437,11 +633,26 @@
});
}
- @Override
- public void onConfigurationChanged(TetheringConfigurationParcel config) { }
+ private void sendRegexpsChanged(TetheringConfigurationParcel parcel) {
+ callback.onTetherableInterfaceRegexpsChanged(new TetheringInterfaceRegexps(
+ parcel.tetherableBluetoothRegexs,
+ parcel.tetherableUsbRegexs,
+ parcel.tetherableWifiRegexs));
+ }
@Override
- public void onTetherStatesChanged(TetherStatesParcel states) { }
+ public void onConfigurationChanged(TetheringConfigurationParcel config) {
+ executor.execute(() -> sendRegexpsChanged(config));
+ }
+
+ @Override
+ public void onTetherStatesChanged(TetherStatesParcel states) {
+ executor.execute(() -> {
+ sendErrorCallbacks(states);
+ maybeSendTetherableIfacesChangedCallback(states);
+ maybeSendTetheredIfacesChangedCallback(states);
+ });
+ }
};
try {
mConnector.registerTetheringEventCallback(remoteCallback, callerPkg);
@@ -458,7 +669,7 @@
*
* @param callback previously registered callback.
*/
- public void unregisterTetheringEventCallback(@NonNull final OnTetheringEventCallback callback) {
+ public void unregisterTetheringEventCallback(@NonNull final TetheringEventCallback callback) {
final String callerPkg = mContext.getOpPackageName();
Log.i(TAG, "unregisterTetheringEventCallback caller:" + callerPkg);
@@ -482,6 +693,7 @@
* @param iface The name of the interface of interest
* @return error The error code of the last error tethering or untethering the named
* interface
+ * @hide
*/
public int getLastTetherError(@NonNull final String iface) {
mCallback.waitForStarted();
@@ -503,6 +715,7 @@
*
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable usb interfaces.
+ * @hide
*/
public @NonNull String[] getTetherableUsbRegexs() {
mCallback.waitForStarted();
@@ -516,6 +729,7 @@
*
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable wifi interfaces.
+ * @hide
*/
public @NonNull String[] getTetherableWifiRegexs() {
mCallback.waitForStarted();
@@ -529,6 +743,7 @@
*
* @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable bluetooth interfaces.
+ * @hide
*/
public @NonNull String[] getTetherableBluetoothRegexs() {
mCallback.waitForStarted();
@@ -540,6 +755,7 @@
* device configuration and current interface existence.
*
* @return an array of 0 or more Strings of tetherable interface names.
+ * @hide
*/
public @NonNull String[] getTetherableIfaces() {
mCallback.waitForStarted();
@@ -552,6 +768,7 @@
* Get the set of tethered interfaces.
*
* @return an array of 0 or more String of currently tethered interface names.
+ * @hide
*/
public @NonNull String[] getTetheredIfaces() {
mCallback.waitForStarted();
@@ -570,6 +787,7 @@
*
* @return an array of 0 or more String indicating the interface names
* which failed to tether.
+ * @hide
*/
public @NonNull String[] getTetheringErroredIfaces() {
mCallback.waitForStarted();
@@ -582,6 +800,7 @@
* Get the set of tethered dhcp ranges.
*
* @deprecated This API just return the default value which is not used in DhcpServer.
+ * @hide
*/
@Deprecated
public @NonNull String[] getTetheredDhcpRanges() {
@@ -595,6 +814,7 @@
* due to device configuration.
*
* @return a boolean - {@code true} indicating Tethering is supported.
+ * @hide
*/
public boolean isTetheringSupported() {
final String callerPkg = mContext.getOpPackageName();
diff --git a/packages/Tethering/src/com/android/server/connectivity/tethering/EntitlementManager.java b/packages/Tethering/src/com/android/server/connectivity/tethering/EntitlementManager.java
index 1cabc8d..e81d6ac 100644
--- a/packages/Tethering/src/com/android/server/connectivity/tethering/EntitlementManager.java
+++ b/packages/Tethering/src/com/android/server/connectivity/tethering/EntitlementManager.java
@@ -16,14 +16,14 @@
package com.android.server.connectivity.tethering;
-import static android.net.TetheringManager.EXTRA_ADD_TETHER_TYPE;
-import static android.net.TetheringManager.EXTRA_PROVISION_CALLBACK;
-import static android.net.TetheringManager.EXTRA_RUN_PROVISION;
+import static android.net.TetheringConstants.EXTRA_ADD_TETHER_TYPE;
+import static android.net.TetheringConstants.EXTRA_PROVISION_CALLBACK;
+import static android.net.TetheringConstants.EXTRA_RUN_PROVISION;
import static android.net.TetheringManager.TETHERING_BLUETOOTH;
import static android.net.TetheringManager.TETHERING_INVALID;
import static android.net.TetheringManager.TETHERING_USB;
import static android.net.TetheringManager.TETHERING_WIFI;
-import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKONWN;
+import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN;
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
import static android.net.TetheringManager.TETHER_ERROR_PROVISION_FAILED;
@@ -577,7 +577,7 @@
private static String errorString(int value) {
switch (value) {
- case TETHER_ERROR_ENTITLEMENT_UNKONWN: return "TETHER_ERROR_ENTITLEMENT_UNKONWN";
+ case TETHER_ERROR_ENTITLEMENT_UNKNOWN: return "TETHER_ERROR_ENTITLEMENT_UNKONWN";
case TETHER_ERROR_NO_ERROR: return "TETHER_ERROR_NO_ERROR";
case TETHER_ERROR_PROVISION_FAILED: return "TETHER_ERROR_PROVISION_FAILED";
default:
@@ -657,7 +657,7 @@
}
final int cacheValue = mEntitlementCacheValue.get(
- downstream, TETHER_ERROR_ENTITLEMENT_UNKONWN);
+ downstream, TETHER_ERROR_ENTITLEMENT_UNKNOWN);
if (cacheValue == TETHER_ERROR_NO_ERROR || !showEntitlementUi) {
receiver.send(cacheValue, null);
} else {
diff --git a/packages/Tethering/src/com/android/server/connectivity/tethering/Tethering.java b/packages/Tethering/src/com/android/server/connectivity/tethering/Tethering.java
index 8d1e0c9..5370145 100644
--- a/packages/Tethering/src/com/android/server/connectivity/tethering/Tethering.java
+++ b/packages/Tethering/src/com/android/server/connectivity/tethering/Tethering.java
@@ -74,6 +74,7 @@
import android.net.Network;
import android.net.NetworkInfo;
import android.net.TetherStatesParcel;
+import android.net.TetheringCallbackStartedParcel;
import android.net.TetheringConfigurationParcel;
import android.net.ip.IpServer;
import android.net.shared.NetdUtils;
@@ -951,6 +952,7 @@
mWrapper.showTetheredNotification(
R.drawable.stat_sys_tether_general, false);
mWrapper.untetherAll();
+ // TODO(b/148139325): send tetheringSupported on restriction change
}
}
}
@@ -1844,9 +1846,13 @@
void registerTetheringEventCallback(ITetheringEventCallback callback) {
mHandler.post(() -> {
mTetheringEventCallbacks.register(callback);
+ final TetheringCallbackStartedParcel parcel = new TetheringCallbackStartedParcel();
+ parcel.tetheringSupported = mDeps.isTetheringSupported();
+ parcel.upstreamNetwork = mTetherUpstream;
+ parcel.config = mConfig.toStableParcelable();
+ parcel.states = mTetherStatesParcel;
try {
- callback.onCallbackStarted(mTetherUpstream, mConfig.toStableParcelable(),
- mTetherStatesParcel);
+ callback.onCallbackStarted(parcel);
} catch (RemoteException e) {
// Not really very much to do here.
}
@@ -1881,6 +1887,7 @@
for (int i = 0; i < length; i++) {
try {
mTetheringEventCallbacks.getBroadcastItem(i).onConfigurationChanged(config);
+ // TODO(b/148139325): send tetheringSupported on configuration change
} catch (RemoteException e) {
// Not really very much to do here.
}
diff --git a/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/EntitlementManagerTest.java b/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/EntitlementManagerTest.java
index 4f07461..3a1d4a6 100644
--- a/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/EntitlementManagerTest.java
+++ b/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/EntitlementManagerTest.java
@@ -19,7 +19,7 @@
import static android.net.TetheringManager.TETHERING_BLUETOOTH;
import static android.net.TetheringManager.TETHERING_USB;
import static android.net.TetheringManager.TETHERING_WIFI;
-import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKONWN;
+import static android.net.TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN;
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
import static android.net.TetheringManager.TETHER_ERROR_PROVISION_FAILED;
import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY;
@@ -110,7 +110,7 @@
}
public class WrappedEntitlementManager extends EntitlementManager {
- public int fakeEntitlementResult = TETHER_ERROR_ENTITLEMENT_UNKONWN;
+ public int fakeEntitlementResult = TETHER_ERROR_ENTITLEMENT_UNKNOWN;
public int uiProvisionCount = 0;
public int silentProvisionCount = 0;
@@ -120,7 +120,7 @@
}
public void reset() {
- fakeEntitlementResult = TETHER_ERROR_ENTITLEMENT_UNKONWN;
+ fakeEntitlementResult = TETHER_ERROR_ENTITLEMENT_UNKNOWN;
uiProvisionCount = 0;
silentProvisionCount = 0;
}
@@ -274,7 +274,7 @@
receiver = new ResultReceiver(null) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
- assertEquals(TETHER_ERROR_ENTITLEMENT_UNKONWN, resultCode);
+ assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode);
mCallbacklatch.countDown();
}
};
@@ -343,7 +343,7 @@
receiver = new ResultReceiver(null) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
- assertEquals(TETHER_ERROR_ENTITLEMENT_UNKONWN, resultCode);
+ assertEquals(TETHER_ERROR_ENTITLEMENT_UNKNOWN, resultCode);
mCallbacklatch.countDown();
}
};
diff --git a/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/TetheringTest.java b/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/TetheringTest.java
index d6afa47..9f0d876 100644
--- a/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/TetheringTest.java
+++ b/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/TetheringTest.java
@@ -86,6 +86,7 @@
import android.net.NetworkRequest;
import android.net.RouteInfo;
import android.net.TetherStatesParcel;
+import android.net.TetheringCallbackStartedParcel;
import android.net.TetheringConfigurationParcel;
import android.net.dhcp.DhcpServerCallbacks;
import android.net.dhcp.DhcpServingParamsParcel;
@@ -1113,11 +1114,10 @@
}
@Override
- public void onCallbackStarted(Network network, TetheringConfigurationParcel config,
- TetherStatesParcel states) {
- mActualUpstreams.add(network);
- mTetheringConfigs.add(config);
- mTetherStates.add(states);
+ public void onCallbackStarted(TetheringCallbackStartedParcel parcel) {
+ mActualUpstreams.add(parcel.upstreamNetwork);
+ mTetheringConfigs.add(parcel.config);
+ mTetherStates.add(parcel.states);
}
@Override
diff --git a/services/core/java/android/content/pm/PackageManagerInternal.java b/services/core/java/android/content/pm/PackageManagerInternal.java
index 368416b..c3cc5de 100644
--- a/services/core/java/android/content/pm/PackageManagerInternal.java
+++ b/services/core/java/android/content/pm/PackageManagerInternal.java
@@ -33,6 +33,7 @@
import android.content.pm.parsing.ComponentParseUtils;
import android.os.Bundle;
import android.os.PersistableBundle;
+import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.SparseArray;
@@ -689,6 +690,27 @@
int userId);
/**
+ * Return the processes that have been declared for a uid.
+ *
+ * @param uid The uid to query.
+ *
+ * @return Returns null if there are no declared processes for the uid; otherwise,
+ * returns the set of processes it declared.
+ */
+ public abstract ArrayMap<String, ProcessInfo> getProcessesForUid(int uid);
+
+ /**
+ * Return the gids associated with a particular permission.
+ *
+ * @param permissionName The name of the permission to query.
+ * @param userId The user id the gids will be associated with.
+ *
+ * @return Returns null if there are no gids associated with the permission, otherwise an
+ * array if the gid ints.
+ */
+ public abstract int[] getPermissionGids(String permissionName, int userId);
+
+ /**
* Return if device is currently in a "core" boot environment, typically
* used to support full-disk encryption. Only apps marked with
* {@code coreApp} attribute are available.
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
index e9db9c8..003525c9 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/LocationManagerService.java
@@ -18,6 +18,8 @@
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
+import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
+import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.location.LocationManager.FUSED_PROVIDER;
import static android.location.LocationManager.GPS_PROVIDER;
@@ -35,14 +37,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ResolveInfo;
-import android.content.pm.Signature;
-import android.content.res.Resources;
-import android.hardware.location.ActivityRecognitionHardware;
import android.location.Address;
import android.location.Criteria;
import android.location.GeocoderParams;
@@ -52,6 +47,7 @@
import android.location.IGnssMeasurementsListener;
import android.location.IGnssNavigationMessageListener;
import android.location.IGnssStatusListener;
+import android.location.IGpsGeofenceHardware;
import android.location.ILocationListener;
import android.location.ILocationManager;
import android.location.Location;
@@ -91,11 +87,11 @@
import com.android.internal.util.Preconditions;
import com.android.server.location.AbstractLocationProvider;
import com.android.server.location.AbstractLocationProvider.State;
-import com.android.server.location.ActivityRecognitionProxy;
import com.android.server.location.CallerIdentity;
import com.android.server.location.GeocoderProxy;
import com.android.server.location.GeofenceManager;
import com.android.server.location.GeofenceProxy;
+import com.android.server.location.HardwareActivityRecognitionProxy;
import com.android.server.location.LocationFudger;
import com.android.server.location.LocationProviderProxy;
import com.android.server.location.LocationRequestStatistics;
@@ -114,7 +110,6 @@
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -543,77 +538,6 @@
}
@GuardedBy("mLock")
- private void ensureFallbackFusedProviderPresentLocked(String[] pkgs) {
- PackageManager pm = mContext.getPackageManager();
- String systemPackageName = mContext.getPackageName();
- ArrayList<HashSet<Signature>> sigSets = ServiceWatcher.getSignatureSets(mContext, pkgs);
-
- List<ResolveInfo> rInfos = pm.queryIntentServicesAsUser(
- new Intent(FUSED_LOCATION_SERVICE_ACTION),
- PackageManager.GET_META_DATA, mUserInfoStore.getCurrentUserId());
- for (ResolveInfo rInfo : rInfos) {
- String packageName = rInfo.serviceInfo.packageName;
-
- // Check that the signature is in the list of supported sigs. If it's not in
- // this list the standard provider binding logic won't bind to it.
- try {
- PackageInfo pInfo;
- pInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
- if (!ServiceWatcher.isSignatureMatch(pInfo.signatures, sigSets)) {
- Log.w(TAG, packageName + " resolves service " + FUSED_LOCATION_SERVICE_ACTION +
- ", but has wrong signature, ignoring");
- continue;
- }
- } catch (NameNotFoundException e) {
- Log.e(TAG, "missing package: " + packageName);
- continue;
- }
-
- // Get the version info
- if (rInfo.serviceInfo.metaData == null) {
- Log.w(TAG, "Found fused provider without metadata: " + packageName);
- continue;
- }
-
- int version = rInfo.serviceInfo.metaData.getInt(
- ServiceWatcher.EXTRA_SERVICE_VERSION, -1);
- if (version == 0) {
- // This should be the fallback fused location provider.
-
- // Make sure it's in the system partition.
- if ((rInfo.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
- if (D) Log.d(TAG, "Fallback candidate not in /system: " + packageName);
- continue;
- }
-
- // Check that the fallback is signed the same as the OS
- // as a proxy for coreApp="true"
- if (pm.checkSignatures(systemPackageName, packageName)
- != PackageManager.SIGNATURE_MATCH) {
- if (D) {
- Log.d(TAG, "Fallback candidate not signed the same as system: "
- + packageName);
- }
- continue;
- }
-
- // Found a valid fallback.
- if (D) Log.d(TAG, "Found fallback provider: " + packageName);
- return;
- } else {
- if (D) Log.d(TAG, "Fallback candidate not version 0: " + packageName);
- }
- }
-
- throw new IllegalStateException("Unable to find a fused location provider that is in the "
- + "system partition with version 0 and signed with the platform certificate. "
- + "Such a package is needed to provide a default fused location provider in the "
- + "event that no other fused location provider has been installed or is currently "
- + "available. For example, coreOnly boot mode when decrypting the data "
- + "partition. The fallback must also be marked coreApp=\"true\" in the manifest");
- }
-
- @GuardedBy("mLock")
private void initializeProvidersLocked() {
if (GnssManagerService.isGnssSupported()) {
mGnssManagerService = new GnssManagerService(this, mContext, mLocationUsageLogger);
@@ -622,33 +546,11 @@
gnssManager.setRealProvider(mGnssManagerService.getGnssLocationProvider());
}
- /*
- Load package name(s) containing location provider support.
- These packages can contain services implementing location providers:
- Geocoder Provider, Network Location Provider, and
- Fused Location Provider. They will each be searched for
- service components implementing these providers.
- The location framework also has support for installation
- of new location providers at run-time. The new package does not
- have to be explicitly listed here, however it must have a signature
- that matches the signature of at least one package on this list.
- */
- Resources resources = mContext.getResources();
- String[] pkgs = resources.getStringArray(
- com.android.internal.R.array.config_locationProviderPackageNames);
- if (D) {
- Log.d(TAG, "certificates for location providers pulled from: " +
- Arrays.toString(pkgs));
- }
-
- ensureFallbackFusedProviderPresentLocked(pkgs);
-
- LocationProviderProxy networkProvider = LocationProviderProxy.createAndBind(
+ LocationProviderProxy networkProvider = LocationProviderProxy.createAndRegister(
mContext,
NETWORK_LOCATION_SERVICE_ACTION,
com.android.internal.R.bool.config_enableNetworkLocationOverlay,
- com.android.internal.R.string.config_networkLocationProviderPackageName,
- com.android.internal.R.array.config_locationProviderPackageNames);
+ com.android.internal.R.string.config_networkLocationProviderPackageName);
if (networkProvider != null) {
LocationProviderManager networkManager = new LocationProviderManager(NETWORK_PROVIDER);
mProviderManagers.add(networkManager);
@@ -657,13 +559,18 @@
Slog.w(TAG, "no network location provider found");
}
+ // ensure that a fused provider exists which will work in direct boot
+ Preconditions.checkState(!mContext.getPackageManager().queryIntentServicesAsUser(
+ new Intent(FUSED_LOCATION_SERVICE_ACTION),
+ MATCH_DIRECT_BOOT_AWARE | MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM).isEmpty(),
+ "Unable to find a direct boot aware fused location provider");
+
// bind to fused provider
- LocationProviderProxy fusedProvider = LocationProviderProxy.createAndBind(
+ LocationProviderProxy fusedProvider = LocationProviderProxy.createAndRegister(
mContext,
FUSED_LOCATION_SERVICE_ACTION,
com.android.internal.R.bool.config_enableFusedLocationOverlay,
- com.android.internal.R.string.config_fusedLocationProviderPackageName,
- com.android.internal.R.array.config_locationProviderPackageNames);
+ com.android.internal.R.string.config_fusedLocationProviderPackageName);
if (fusedProvider != null) {
LocationProviderManager fusedManager = new LocationProviderManager(FUSED_PROVIDER);
mProviderManagers.add(fusedManager);
@@ -674,47 +581,30 @@
}
// bind to geocoder provider
- mGeocodeProvider = GeocoderProxy.createAndBind(mContext,
- com.android.internal.R.bool.config_enableGeocoderOverlay,
- com.android.internal.R.string.config_geocoderProviderPackageName,
- com.android.internal.R.array.config_locationProviderPackageNames);
+ mGeocodeProvider = GeocoderProxy.createAndRegister(mContext);
if (mGeocodeProvider == null) {
Slog.e(TAG, "no geocoder provider found");
}
+ // bind to geofence proxy
if (mGnssManagerService != null) {
- // bind to geofence provider
- GeofenceProxy provider = GeofenceProxy.createAndBind(
- mContext, com.android.internal.R.bool.config_enableGeofenceOverlay,
- com.android.internal.R.string.config_geofenceProviderPackageName,
- com.android.internal.R.array.config_locationProviderPackageNames,
- mGnssManagerService.getGpsGeofenceProxy(),
- null);
- if (provider == null) {
- Slog.d(TAG, "Unable to bind FLP Geofence proxy.");
+ IGpsGeofenceHardware gpsGeofenceHardware = mGnssManagerService.getGpsGeofenceProxy();
+ if (gpsGeofenceHardware != null) {
+ GeofenceProxy provider = GeofenceProxy.createAndBind(mContext, gpsGeofenceHardware);
+ if (provider == null) {
+ Slog.d(TAG, "unable to bind to GeofenceProxy");
+ }
}
}
// bind to hardware activity recognition
- boolean activityRecognitionHardwareIsSupported = ActivityRecognitionHardware.isSupported();
- ActivityRecognitionHardware activityRecognitionHardware = null;
- if (activityRecognitionHardwareIsSupported) {
- activityRecognitionHardware = ActivityRecognitionHardware.getInstance(mContext);
- } else {
- Slog.d(TAG, "Hardware Activity-Recognition not supported.");
- }
- ActivityRecognitionProxy proxy = ActivityRecognitionProxy.createAndBind(
- mContext,
- activityRecognitionHardwareIsSupported,
- activityRecognitionHardware,
- com.android.internal.R.bool.config_enableActivityRecognitionHardwareOverlay,
- com.android.internal.R.string.config_activityRecognitionHardwarePackageName,
- com.android.internal.R.array.config_locationProviderPackageNames);
- if (proxy == null) {
- Slog.d(TAG, "Unable to bind ActivityRecognitionProxy.");
+ HardwareActivityRecognitionProxy hardwareActivityRecognitionProxy =
+ HardwareActivityRecognitionProxy.createAndRegister(mContext);
+ if (hardwareActivityRecognitionProxy == null) {
+ Log.e(TAG, "unable to bind ActivityRecognitionProxy");
}
- String[] testProviderStrings = resources.getStringArray(
+ String[] testProviderStrings = mContext.getResources().getStringArray(
com.android.internal.R.array.config_testLocationProviders);
for (String testProviderString : testProviderStrings) {
String[] fragments = testProviderString.split(",");
diff --git a/services/core/java/com/android/server/RescueParty.java b/services/core/java/com/android/server/RescueParty.java
index e8e3b39d..131a22b 100644
--- a/services/core/java/com/android/server/RescueParty.java
+++ b/services/core/java/com/android/server/RescueParty.java
@@ -18,6 +18,7 @@
import static com.android.server.pm.PackageManagerServiceUtils.logCriticalInfo;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ContentResolver;
import android.content.Context;
@@ -25,14 +26,18 @@
import android.content.pm.PackageManager;
import android.content.pm.VersionedPackage;
import android.os.Build;
+import android.os.Bundle;
import android.os.Environment;
import android.os.FileUtils;
import android.os.Process;
import android.os.RecoverySystem;
+import android.os.RemoteCallback;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
+import android.provider.DeviceConfig;
import android.provider.Settings;
+import android.util.ArraySet;
import android.util.ExceptionUtils;
import android.util.Log;
import android.util.MathUtils;
@@ -46,10 +51,16 @@
import com.android.server.PackageWatchdog.PackageHealthObserver;
import com.android.server.PackageWatchdog.PackageHealthObserverImpact;
import com.android.server.am.SettingsToPropertiesMapper;
-import com.android.server.utils.FlagNamespaceUtils;
import java.io.File;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
/**
* Utilities to help rescue the system from crash loops. Callers are expected to
@@ -64,8 +75,6 @@
@VisibleForTesting
static final String PROP_ENABLE_RESCUE = "persist.sys.enable_rescue";
@VisibleForTesting
- static final int TRIGGER_COUNT = 5;
- @VisibleForTesting
static final String PROP_RESCUE_LEVEL = "sys.rescue_level";
@VisibleForTesting
static final int LEVEL_NONE = 0;
@@ -81,6 +90,8 @@
static final String PROP_RESCUE_BOOT_COUNT = "sys.rescue_boot_count";
@VisibleForTesting
static final String TAG = "RescueParty";
+ @VisibleForTesting
+ static final long DEFAULT_OBSERVING_DURATION_MS = TimeUnit.DAYS.toMillis(2);
private static final String NAME = "rescue-party-observer";
@@ -139,7 +150,11 @@
*/
public static void onSettingsProviderPublished(Context context) {
handleNativeRescuePartyResets();
- executeRescueLevel(context);
+ executeRescueLevel(context, /*failedPackage=*/ null);
+ ContentResolver contentResolver = context.getContentResolver();
+ Settings.Config.registerMonitorCallback(contentResolver, new RemoteCallback(result -> {
+ handleMonitorCallback(context, result);
+ }));
}
@VisibleForTesting
@@ -147,10 +162,53 @@
return SystemClock.elapsedRealtime();
}
+ private static void handleMonitorCallback(Context context, Bundle result) {
+ String callbackType = result.getString(Settings.EXTRA_MONITOR_CALLBACK_TYPE, "");
+ switch (callbackType) {
+ case Settings.EXTRA_NAMESPACE_UPDATED_CALLBACK:
+ String updatedNamespace = result.getString(Settings.EXTRA_NAMESPACE);
+ if (updatedNamespace != null) {
+ startObservingPackages(context, updatedNamespace);
+ }
+ break;
+ case Settings.EXTRA_ACCESS_CALLBACK:
+ String callingPackage = result.getString(Settings.EXTRA_CALLING_PACKAGE, null);
+ String namespace = result.getString(Settings.EXTRA_NAMESPACE, null);
+ if (namespace != null && callingPackage != null) {
+ RescuePartyObserver.getInstance(context).recordDeviceConfigAccess(
+ callingPackage,
+ namespace);
+ }
+ break;
+ default:
+ Slog.w(TAG, "Unrecognized DeviceConfig callback");
+ break;
+ }
+ }
+
+ private static void startObservingPackages(Context context, @NonNull String updatedNamespace) {
+ RescuePartyObserver rescuePartyObserver = RescuePartyObserver.getInstance(context);
+ Set<String> callingPackages = rescuePartyObserver.getCallingPackagesSet(updatedNamespace);
+ if (callingPackages == null) {
+ return;
+ }
+ List<String> callingPackageList = new ArrayList<>();
+ callingPackageList.addAll(callingPackages);
+ Slog.i(TAG, "Starting to observe: " + callingPackageList + ", updated namespace: "
+ + updatedNamespace);
+ PackageWatchdog.getInstance(context).startObservingHealth(
+ rescuePartyObserver,
+ callingPackageList,
+ DEFAULT_OBSERVING_DURATION_MS);
+ }
+
private static void handleNativeRescuePartyResets() {
if (SettingsToPropertiesMapper.isNativeFlagsResetPerformed()) {
- FlagNamespaceUtils.resetDeviceConfig(Settings.RESET_MODE_TRUSTED_DEFAULTS,
- Arrays.asList(SettingsToPropertiesMapper.getResetNativeCategories()));
+ String[] resetNativeCategories = SettingsToPropertiesMapper.getResetNativeCategories();
+ for (int i = 0; i < resetNativeCategories.length; i++) {
+ DeviceConfig.resetToDefaults(Settings.RESET_MODE_TRUSTED_DEFAULTS,
+ resetNativeCategories[i]);
+ }
}
}
@@ -164,7 +222,7 @@
/**
* Escalate to the next rescue level. After incrementing the level you'll
- * probably want to call {@link #executeRescueLevel(Context)}.
+ * probably want to call {@link #executeRescueLevel(Context, String)}.
*/
private static void incrementRescueLevel(int triggerUid) {
final int level = MathUtils.constrain(
@@ -177,13 +235,13 @@
+ levelToString(level) + " triggered by UID " + triggerUid);
}
- private static void executeRescueLevel(Context context) {
+ private static void executeRescueLevel(Context context, @Nullable String failedPackage) {
final int level = SystemProperties.getInt(PROP_RESCUE_LEVEL, LEVEL_NONE);
if (level == LEVEL_NONE) return;
Slog.w(TAG, "Attempting rescue level " + levelToString(level));
try {
- executeRescueLevelInternal(context, level);
+ executeRescueLevelInternal(context, level, failedPackage);
EventLogTags.writeRescueSuccess(level);
logCriticalInfo(Log.DEBUG,
"Finished rescue level " + levelToString(level));
@@ -195,24 +253,23 @@
}
}
- private static void executeRescueLevelInternal(Context context, int level) throws Exception {
+ private static void executeRescueLevelInternal(Context context, int level, @Nullable
+ String failedPackage) throws Exception {
StatsLog.write(StatsLog.RESCUE_PARTY_RESET_REPORTED, level);
switch (level) {
case LEVEL_RESET_SETTINGS_UNTRUSTED_DEFAULTS:
- resetAllSettings(context, Settings.RESET_MODE_UNTRUSTED_DEFAULTS);
+ resetAllSettings(context, Settings.RESET_MODE_UNTRUSTED_DEFAULTS, failedPackage);
break;
case LEVEL_RESET_SETTINGS_UNTRUSTED_CHANGES:
- resetAllSettings(context, Settings.RESET_MODE_UNTRUSTED_CHANGES);
+ resetAllSettings(context, Settings.RESET_MODE_UNTRUSTED_CHANGES, failedPackage);
break;
case LEVEL_RESET_SETTINGS_TRUSTED_DEFAULTS:
- resetAllSettings(context, Settings.RESET_MODE_TRUSTED_DEFAULTS);
+ resetAllSettings(context, Settings.RESET_MODE_TRUSTED_DEFAULTS, failedPackage);
break;
case LEVEL_FACTORY_RESET:
RecoverySystem.rebootPromptAndWipeUserData(context, TAG);
break;
}
- FlagNamespaceUtils.addToKnownResetNamespaces(
- FlagNamespaceUtils.NAMESPACE_NO_PACKAGE);
}
private static int mapRescueLevelToUserImpact(int rescueLevel) {
@@ -237,13 +294,14 @@
}
}
- private static void resetAllSettings(Context context, int mode) throws Exception {
+ private static void resetAllSettings(Context context, int mode, @Nullable String failedPackage)
+ throws Exception {
// Try our best to reset all settings possible, and once finished
// rethrow any exception that we encountered
Exception res = null;
final ContentResolver resolver = context.getContentResolver();
try {
- FlagNamespaceUtils.resetDeviceConfig(mode);
+ resetDeviceConfig(context, mode, failedPackage);
} catch (Exception e) {
res = new RuntimeException("Failed to reset config settings", e);
}
@@ -264,6 +322,41 @@
}
}
+ private static void resetDeviceConfig(Context context, int resetMode,
+ @Nullable String failedPackage) {
+ if (!shouldPerformScopedResets() || failedPackage == null) {
+ DeviceConfig.resetToDefaults(resetMode, /*namespace=*/ null);
+ } else {
+ performScopedReset(context, resetMode, failedPackage);
+ }
+ }
+
+ private static boolean shouldPerformScopedResets() {
+ int rescueLevel = MathUtils.constrain(
+ SystemProperties.getInt(PROP_RESCUE_LEVEL, LEVEL_NONE),
+ LEVEL_NONE, LEVEL_FACTORY_RESET);
+ return rescueLevel <= LEVEL_RESET_SETTINGS_UNTRUSTED_CHANGES;
+ }
+
+ private static void performScopedReset(Context context, int resetMode,
+ @NonNull String failedPackage) {
+ RescuePartyObserver rescuePartyObserver = RescuePartyObserver.getInstance(context);
+ Set<String> affectedNamespaces = rescuePartyObserver.getAffectedNamespaceSet(
+ failedPackage);
+ if (affectedNamespaces == null) {
+ DeviceConfig.resetToDefaults(resetMode, /*namespace=*/ null);
+ } else {
+ Slog.w(TAG,
+ "Performing scoped reset for package: " + failedPackage
+ + ", affected namespaces: "
+ + Arrays.toString(affectedNamespaces.toArray()));
+ Iterator<String> it = affectedNamespaces.iterator();
+ while (it.hasNext()) {
+ DeviceConfig.resetToDefaults(resetMode, it.next());
+ }
+ }
+ }
+
/**
* Handle mitigation action for package failures. This observer will be register to Package
* Watchdog and will receive calls about package failures. This observer is persistent so it
@@ -271,7 +364,9 @@
*/
public static class RescuePartyObserver implements PackageHealthObserver {
- private Context mContext;
+ private final Context mContext;
+ private final Map<String, Set<String>> mCallingPackageNamespaceSetMap = new HashMap<>();
+ private final Map<String, Set<String>> mNamespaceCallingPackageSetMap = new HashMap<>();
@GuardedBy("RescuePartyObserver.class")
static RescuePartyObserver sRescuePartyObserver;
@@ -290,6 +385,13 @@
}
}
+ @VisibleForTesting
+ static void reset() {
+ synchronized (RescuePartyObserver.class) {
+ sRescuePartyObserver = null;
+ }
+ }
+
@Override
public int onHealthCheckFailed(@Nullable VersionedPackage failedPackage,
@FailureReasons int failureReason) {
@@ -314,7 +416,8 @@
|| failureReason == PackageWatchdog.FAILURE_REASON_APP_NOT_RESPONDING) {
int triggerUid = getPackageUid(mContext, failedPackage.getPackageName());
incrementRescueLevel(triggerUid);
- executeRescueLevel(mContext);
+ executeRescueLevel(mContext,
+ failedPackage == null ? null : failedPackage.getPackageName());
return true;
} else {
return false;
@@ -355,7 +458,7 @@
return false;
}
incrementRescueLevel(Process.ROOT_UID);
- executeRescueLevel(mContext);
+ executeRescueLevel(mContext, /*failedPackage=*/ null);
return true;
}
@@ -363,6 +466,32 @@
public String getName() {
return NAME;
}
+
+ private synchronized void recordDeviceConfigAccess(@NonNull String callingPackage,
+ @NonNull String namespace) {
+ // Record it in calling packages to namespace map
+ Set<String> namespaceSet = mCallingPackageNamespaceSetMap.get(callingPackage);
+ if (namespaceSet == null) {
+ namespaceSet = new ArraySet<>();
+ mCallingPackageNamespaceSetMap.put(callingPackage, namespaceSet);
+ }
+ namespaceSet.add(namespace);
+ // Record it in namespace to calling packages map
+ Set<String> callingPackageSet = mNamespaceCallingPackageSetMap.get(namespace);
+ if (callingPackageSet == null) {
+ callingPackageSet = new ArraySet<>();
+ }
+ callingPackageSet.add(callingPackage);
+ mNamespaceCallingPackageSetMap.put(namespace, callingPackageSet);
+ }
+
+ private synchronized Set<String> getAffectedNamespaceSet(String failedPackage) {
+ return mCallingPackageNamespaceSetMap.get(failedPackage);
+ }
+
+ private synchronized Set<String> getCallingPackagesSet(String namespace) {
+ return mNamespaceCallingPackageSetMap.get(namespace);
+ }
}
private static int[] getAllUserIds() {
diff --git a/services/core/java/com/android/server/ServiceWatcher.java b/services/core/java/com/android/server/ServiceWatcher.java
index 7f51aa9..8564cb4 100644
--- a/services/core/java/com/android/server/ServiceWatcher.java
+++ b/services/core/java/com/android/server/ServiceWatcher.java
@@ -16,7 +16,19 @@
package com.android.server;
+import static android.content.Context.BIND_AUTO_CREATE;
+import static android.content.Context.BIND_NOT_FOREGROUND;
+import static android.content.Context.BIND_NOT_VISIBLE;
+import static android.content.pm.PackageManager.GET_META_DATA;
+import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AUTO;
+import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
+import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
+import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
+
+import android.annotation.BoolRes;
import android.annotation.Nullable;
+import android.annotation.StringRes;
+import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -24,11 +36,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
-import android.content.pm.Signature;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
@@ -37,15 +45,10 @@
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
-import android.util.Slog;
import com.android.internal.content.PackageMonitor;
import com.android.internal.util.Preconditions;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
@@ -55,16 +58,16 @@
import java.util.concurrent.TimeoutException;
/**
- * Find the best Service, and bind to it.
- * Handles run-time package changes.
+ * Maintains a binding to the best service that matches the given intent information. Bind and
+ * unbind callbacks, as well as all binder operations, will all be run on the given handler.
*/
public class ServiceWatcher implements ServiceConnection {
private static final String TAG = "ServiceWatcher";
- private static final boolean D = false;
+ private static final boolean D = Log.isLoggable(TAG, Log.DEBUG);
- public static final String EXTRA_SERVICE_VERSION = "serviceVersion";
- public static final String EXTRA_SERVICE_IS_MULTIUSER = "serviceIsMultiuser";
+ private static final String EXTRA_SERVICE_VERSION = "serviceVersion";
+ private static final String EXTRA_SERVICE_IS_MULTIUSER = "serviceIsMultiuser";
private static final long BLOCKING_BINDER_TIMEOUT_MS = 30 * 1000;
@@ -83,280 +86,300 @@
T run(IBinder binder) throws RemoteException;
}
- public static ArrayList<HashSet<Signature>> getSignatureSets(Context context,
- String... packageNames) {
- PackageManager pm = context.getPackageManager();
+ /**
+ * Information on the service ServiceWatcher has selected as the best option for binding.
+ */
+ public static final class ServiceInfo implements Comparable<ServiceInfo> {
- ArrayList<HashSet<Signature>> signatureSets = new ArrayList<>(packageNames.length);
- for (String packageName : packageNames) {
- try {
- Signature[] signatures = pm.getPackageInfo(packageName,
- PackageManager.MATCH_SYSTEM_ONLY
- | PackageManager.GET_SIGNATURES).signatures;
+ public static final ServiceInfo NONE = new ServiceInfo(Integer.MIN_VALUE, null,
+ UserHandle.USER_NULL);
- HashSet<Signature> set = new HashSet<>();
- Collections.addAll(set, signatures);
- signatureSets.add(set);
- } catch (NameNotFoundException e) {
- Log.w(TAG, packageName + " not found");
+ public final int version;
+ @Nullable public final ComponentName component;
+ @UserIdInt public final int userId;
+
+ private ServiceInfo(ResolveInfo resolveInfo, int currentUserId) {
+ Preconditions.checkArgument(resolveInfo.serviceInfo.getComponentName() != null);
+
+ Bundle metadata = resolveInfo.serviceInfo.metaData;
+ boolean isMultiuser;
+ if (metadata != null) {
+ version = metadata.getInt(EXTRA_SERVICE_VERSION, Integer.MIN_VALUE);
+ isMultiuser = metadata.getBoolean(EXTRA_SERVICE_IS_MULTIUSER, false);
+ } else {
+ version = Integer.MIN_VALUE;
+ isMultiuser = false;
}
+
+ component = resolveInfo.serviceInfo.getComponentName();
+ userId = isMultiuser ? UserHandle.USER_SYSTEM : currentUserId;
}
- return signatureSets;
- }
- /** Checks if signatures match. */
- public static boolean isSignatureMatch(Signature[] signatures,
- List<HashSet<Signature>> sigSets) {
- if (signatures == null) return false;
+ private ServiceInfo(int version, @Nullable ComponentName component, int userId) {
+ Preconditions.checkArgument(component != null || version == Integer.MIN_VALUE);
+ this.version = version;
+ this.component = component;
+ this.userId = userId;
+ }
- // build hashset of input to test against
- HashSet<Signature> inputSet = new HashSet<>();
- Collections.addAll(inputSet, signatures);
-
- // test input against each of the signature sets
- for (HashSet<Signature> referenceSet : sigSets) {
- if (referenceSet.equals(inputSet)) {
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
return true;
}
+ if (!(o instanceof ServiceInfo)) {
+ return false;
+ }
+ ServiceInfo that = (ServiceInfo) o;
+ return version == that.version && userId == that.userId
+ && Objects.equals(component, that.component);
}
- return false;
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(version, component, userId);
+ }
+
+ @Override
+ public int compareTo(ServiceInfo that) {
+ // ServiceInfos with higher version numbers always win (having a version number >
+ // MIN_VALUE implies having a non-null component). if version numbers are equal, a
+ // non-null component wins over a null component. if the version numbers are equal and
+ // both components exist then we prefer components that work for all users vs components
+ // that only work for a single user at a time. otherwise everything's equal.
+ int ret = Integer.compare(version, that.version);
+ if (ret == 0) {
+ if (component == null && that.component != null) {
+ ret = -1;
+ } else if (component != null && that.component == null) {
+ ret = 1;
+ } else {
+ if (userId != UserHandle.USER_SYSTEM && that.userId == UserHandle.USER_SYSTEM) {
+ ret = -1;
+ } else if (userId == UserHandle.USER_SYSTEM
+ && that.userId != UserHandle.USER_SYSTEM) {
+ ret = 1;
+ }
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public String toString() {
+ return component + "@" + version + "[u" + userId + "]";
+ }
}
private final Context mContext;
- private final String mTag;
- private final String mAction;
- private final String mServicePackageName;
- private final List<HashSet<Signature>> mSignatureSets;
-
private final Handler mHandler;
+ private final Intent mIntent;
- // read/write from handler thread
- private IBinder mBestService;
+ @Nullable private final BinderRunner mOnBind;
+ @Nullable private final Runnable mOnUnbind;
+
+ // read/write from handler thread only
private int mCurrentUserId;
- // read from any thread, write from handler thread
- private volatile ComponentName mBestComponent;
- private volatile int mBestVersion;
- private volatile int mBestUserId;
+ // write from handler thread only, read anywhere
+ private volatile ServiceInfo mServiceInfo;
- public ServiceWatcher(Context context, String logTag, String action,
- int overlaySwitchResId, int defaultServicePackageNameResId,
- int initialPackageNamesResId, Handler handler) {
- Resources resources = context.getResources();
+ // read/write from handler thread only
+ private IBinder mBinder;
+ public ServiceWatcher(Context context, Handler handler, String action,
+ @Nullable BinderRunner onBind, @Nullable Runnable onUnbind,
+ @BoolRes int enableOverlayResId, @StringRes int nonOverlayPackageResId) {
mContext = context;
- mTag = logTag;
- mAction = action;
+ mHandler = FgThread.getHandler();
+ mIntent = new Intent(Objects.requireNonNull(action));
- boolean enableOverlay = resources.getBoolean(overlaySwitchResId);
- if (enableOverlay) {
- String[] pkgs = resources.getStringArray(initialPackageNamesResId);
- mServicePackageName = null;
- mSignatureSets = getSignatureSets(context, pkgs);
- if (D) Log.d(mTag, "Overlay enabled, packages=" + Arrays.toString(pkgs));
- } else {
- mServicePackageName = resources.getString(defaultServicePackageNameResId);
- mSignatureSets = getSignatureSets(context, mServicePackageName);
- if (D) Log.d(mTag, "Overlay disabled, default package=" + mServicePackageName);
+ Resources resources = context.getResources();
+ boolean enableOverlay = resources.getBoolean(enableOverlayResId);
+ if (!enableOverlay) {
+ mIntent.setPackage(resources.getString(nonOverlayPackageResId));
}
- mHandler = handler;
+ mOnBind = onBind;
+ mOnUnbind = onUnbind;
- mBestComponent = null;
- mBestVersion = Integer.MIN_VALUE;
- mBestUserId = UserHandle.USER_NULL;
+ mCurrentUserId = UserHandle.USER_NULL;
- mBestService = null;
+ mServiceInfo = ServiceInfo.NONE;
+ mBinder = null;
}
- protected void onBind() {}
-
- protected void onUnbind() {}
-
/**
- * Start this watcher, including binding to the current best match and
- * re-binding to any better matches down the road.
- * <p>
- * Note that if there are no matching encryption-aware services, we may not
- * bind to a real service until after the current user is unlocked.
- *
- * @return {@code true} if a potential service implementation was found.
+ * Register this class, which will start the process of determining the best matching service
+ * and maintaining a binding to it. Will return false and fail if there are no possible matching
+ * services at the time this functions is called.
*/
- public final boolean start() {
- // if we have to return false, do it before registering anything
- if (isServiceMissing()) return false;
-
- // listen for relevant package changes if service overlay is enabled on handler
- if (mServicePackageName == null) {
- new PackageMonitor() {
- @Override
- public void onPackageUpdateFinished(String packageName, int uid) {
- bindBestPackage(Objects.equals(packageName, getCurrentPackageName()));
- }
-
- @Override
- public void onPackageAdded(String packageName, int uid) {
- bindBestPackage(Objects.equals(packageName, getCurrentPackageName()));
- }
-
- @Override
- public void onPackageRemoved(String packageName, int uid) {
- bindBestPackage(Objects.equals(packageName, getCurrentPackageName()));
- }
-
- @Override
- public boolean onPackageChanged(String packageName, int uid, String[] components) {
- bindBestPackage(Objects.equals(packageName, getCurrentPackageName()));
- return super.onPackageChanged(packageName, uid, components);
- }
- }.register(mContext, UserHandle.ALL, true, mHandler);
+ public boolean register() {
+ if (mContext.getPackageManager().queryIntentServicesAsUser(mIntent,
+ MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE | MATCH_SYSTEM_ONLY,
+ UserHandle.USER_SYSTEM).isEmpty()) {
+ return false;
}
- // listen for user change on handler
+ new PackageMonitor() {
+ @Override
+ public void onPackageUpdateFinished(String packageName, int uid) {
+ ServiceWatcher.this.onPackageChanged(packageName);
+ }
+
+ @Override
+ public void onPackageAdded(String packageName, int uid) {
+ ServiceWatcher.this.onPackageChanged(packageName);
+ }
+
+ @Override
+ public void onPackageRemoved(String packageName, int uid) {
+ ServiceWatcher.this.onPackageChanged(packageName);
+ }
+
+ @Override
+ public boolean onPackageChanged(String packageName, int uid, String[] components) {
+ ServiceWatcher.this.onPackageChanged(packageName);
+ return super.onPackageChanged(packageName, uid, components);
+ }
+ }.register(mContext, UserHandle.ALL, true, mHandler);
+
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
mContext.registerReceiverAsUser(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- final String action = intent.getAction();
- final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
- UserHandle.USER_NULL);
- if (Intent.ACTION_USER_SWITCHED.equals(action)) {
- mCurrentUserId = userId;
- bindBestPackage(false);
- } else if (Intent.ACTION_USER_UNLOCKED.equals(action)) {
- if (userId == mCurrentUserId) {
- bindBestPackage(false);
- }
+ String action = intent.getAction();
+ if (action == null) {
+ return;
}
+ int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
+ if (userId == UserHandle.USER_NULL) {
+ return;
+ }
+
+ switch (action) {
+ case Intent.ACTION_USER_SWITCHED:
+ onUserSwitched(userId);
+ break;
+ case Intent.ACTION_USER_UNLOCKED:
+ onUserUnlocked(userId);
+ break;
+ default:
+ break;
+ }
+
}
}, UserHandle.ALL, intentFilter, null, mHandler);
mCurrentUserId = ActivityManager.getCurrentUser();
- mHandler.post(() -> bindBestPackage(false));
+ mHandler.post(() -> onBestServiceChanged(false));
return true;
}
- /** Returns the name of the currently connected package or null. */
- @Nullable
- public String getCurrentPackageName() {
- ComponentName bestComponent = mBestComponent;
- return bestComponent == null ? null : bestComponent.getPackageName();
+ /**
+ * Returns information on the currently selected service.
+ */
+ public ServiceInfo getBoundService() {
+ return mServiceInfo;
}
- private boolean isServiceMissing() {
- return mContext.getPackageManager().queryIntentServicesAsUser(new Intent(mAction),
- PackageManager.MATCH_DIRECT_BOOT_AWARE
- | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
- UserHandle.USER_SYSTEM).isEmpty();
- }
-
- private void bindBestPackage(boolean forceRebind) {
+ private void onBestServiceChanged(boolean forceRebind) {
Preconditions.checkState(Looper.myLooper() == mHandler.getLooper());
- Intent intent = new Intent(mAction);
- if (mServicePackageName != null) {
- intent.setPackage(mServicePackageName);
- }
-
- List<ResolveInfo> rInfos = mContext.getPackageManager().queryIntentServicesAsUser(intent,
- PackageManager.GET_META_DATA | PackageManager.MATCH_DIRECT_BOOT_AUTO,
+ List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentServicesAsUser(
+ mIntent,
+ GET_META_DATA | MATCH_DIRECT_BOOT_AUTO | MATCH_SYSTEM_ONLY,
mCurrentUserId);
- if (rInfos == null) {
- rInfos = Collections.emptyList();
- }
- ComponentName bestComponent = null;
- int bestVersion = Integer.MIN_VALUE;
- boolean bestIsMultiuser = false;
-
- for (ResolveInfo rInfo : rInfos) {
- ComponentName component = rInfo.serviceInfo.getComponentName();
- String packageName = component.getPackageName();
-
- // check signature
- try {
- PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(packageName,
- PackageManager.GET_SIGNATURES
- | PackageManager.MATCH_DIRECT_BOOT_AUTO);
- if (!isSignatureMatch(pInfo.signatures, mSignatureSets)) {
- Log.w(mTag, packageName + " resolves service " + mAction
- + ", but has wrong signature, ignoring");
- continue;
- }
- } catch (NameNotFoundException e) {
- Log.wtf(mTag, e);
- continue;
- }
-
- // check metadata
- Bundle metadata = rInfo.serviceInfo.metaData;
- int version = Integer.MIN_VALUE;
- boolean isMultiuser = false;
- if (metadata != null) {
- version = metadata.getInt(EXTRA_SERVICE_VERSION, Integer.MIN_VALUE);
- isMultiuser = metadata.getBoolean(EXTRA_SERVICE_IS_MULTIUSER, false);
- }
-
- if (version > bestVersion) {
- bestComponent = component;
- bestVersion = version;
- bestIsMultiuser = isMultiuser;
+ ServiceInfo bestServiceInfo = ServiceInfo.NONE;
+ for (ResolveInfo resolveInfo : resolveInfos) {
+ ServiceInfo serviceInfo = new ServiceInfo(resolveInfo, mCurrentUserId);
+ if (serviceInfo.compareTo(bestServiceInfo) > 0) {
+ bestServiceInfo = serviceInfo;
}
}
- if (D) {
- Log.d(mTag, String.format("bindBestPackage for %s : %s found %d, %s", mAction,
- (mServicePackageName == null ? ""
- : "(" + mServicePackageName + ") "), rInfos.size(),
- (bestComponent == null ? "no new best component"
- : "new best component: " + bestComponent)));
+ if (forceRebind || !bestServiceInfo.equals(mServiceInfo)) {
+ rebind(bestServiceInfo);
+ }
+ }
+
+ private void rebind(ServiceInfo newServiceInfo) {
+ Preconditions.checkState(Looper.myLooper() == mHandler.getLooper());
+
+ if (!mServiceInfo.equals(ServiceInfo.NONE)) {
+ if (D) {
+ Log.i(TAG, "[" + mIntent.getAction() + "] unbinding from " + mServiceInfo);
+ }
+
+ mContext.unbindService(this);
+ mServiceInfo = ServiceInfo.NONE;
}
- if (bestComponent == null) {
- Slog.w(mTag, "Odd, no component found for service " + mAction);
- unbind();
+ mServiceInfo = newServiceInfo;
+ if (mServiceInfo.equals(ServiceInfo.NONE)) {
return;
}
- int userId = bestIsMultiuser ? UserHandle.USER_SYSTEM : mCurrentUserId;
- boolean alreadyBound = Objects.equals(bestComponent, mBestComponent)
- && bestVersion == mBestVersion && userId == mBestUserId;
- if (forceRebind || !alreadyBound) {
- unbind();
- bind(bestComponent, bestVersion, userId);
+ Preconditions.checkState(mServiceInfo.component != null);
+
+ if (D) {
+ Log.i(TAG, getLogPrefix() + " binding to " + mServiceInfo);
+ }
+
+ Intent bindIntent = new Intent(mIntent).setComponent(mServiceInfo.component);
+ mContext.bindServiceAsUser(bindIntent, this,
+ BIND_AUTO_CREATE | BIND_NOT_FOREGROUND | BIND_NOT_VISIBLE,
+ mHandler, UserHandle.of(mServiceInfo.userId));
+ }
+
+ @Override
+ public final void onServiceConnected(ComponentName component, IBinder binder) {
+ Preconditions.checkState(Looper.myLooper() == mHandler.getLooper());
+
+ if (D) {
+ Log.i(TAG, getLogPrefix() + " connected to " + component);
+ }
+
+ mBinder = binder;
+ if (mOnBind != null) {
+ runOnBinder(mOnBind);
}
}
- private void bind(ComponentName component, int version, int userId) {
+ @Override
+ public final void onServiceDisconnected(ComponentName component) {
Preconditions.checkState(Looper.myLooper() == mHandler.getLooper());
- Intent intent = new Intent(mAction);
- intent.setComponent(component);
-
- mBestComponent = component;
- mBestVersion = version;
- mBestUserId = userId;
-
- if (D) Log.d(mTag, "binding " + component + " (v" + version + ") (u" + userId + ")");
- mContext.bindServiceAsUser(intent, this,
- Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_VISIBLE,
- UserHandle.of(userId));
- }
-
- private void unbind() {
- Preconditions.checkState(Looper.myLooper() == mHandler.getLooper());
-
- if (mBestComponent != null) {
- if (D) Log.d(mTag, "unbinding " + mBestComponent);
- mContext.unbindService(this);
+ if (D) {
+ Log.i(TAG, getLogPrefix() + " disconnected from " + component);
}
- mBestComponent = null;
- mBestVersion = Integer.MIN_VALUE;
- mBestUserId = UserHandle.USER_NULL;
+ mBinder = null;
+ if (mOnUnbind != null) {
+ mOnUnbind.run();
+ }
+ }
+
+ private void onUserSwitched(@UserIdInt int userId) {
+ mCurrentUserId = userId;
+ onBestServiceChanged(false);
+ }
+
+ private void onUserUnlocked(@UserIdInt int userId) {
+ if (userId == mCurrentUserId) {
+ onBestServiceChanged(false);
+ }
+ }
+
+ private void onPackageChanged(String packageName) {
+ // force a rebind if the changed package was the currently connected package
+ String currentPackageName =
+ mServiceInfo.component != null ? mServiceInfo.component.getPackageName() : null;
+ onBestServiceChanged(packageName.equals(currentPackageName));
}
/**
@@ -365,26 +388,26 @@
*/
public final void runOnBinder(BinderRunner runner) {
runOnHandler(() -> {
- if (mBestService == null) {
+ if (mBinder == null) {
return;
}
try {
- runner.run(mBestService);
- } catch (RuntimeException e) {
- // the code being run is privileged, but may be outside the system server, and thus
- // we cannot allow runtime exceptions to crash the system server
- Log.e(TAG, "exception while while running " + runner + " on " + mBestService
- + " from " + this, e);
- } catch (RemoteException e) {
- // do nothing
+ runner.run(mBinder);
+ } catch (RuntimeException | RemoteException e) {
+ // binders may propagate some specific non-RemoteExceptions from the other side
+ // through the binder as well - we cannot allow those to crash the system server
+ Log.e(TAG, getLogPrefix() + " exception running on " + mServiceInfo, e);
}
});
}
/**
* Runs the given function synchronously if currently connected, and returns the default value
- * if not currently connected or if any exception is thrown.
+ * if not currently connected or if any exception is thrown. Do not obtain any locks within the
+ * BlockingBinderRunner, or risk deadlock. The default value will be returned if there is no
+ * service connection when this is run, if a RemoteException occurs, or if the operation times
+ * out.
*
* @deprecated Using this function is an indication that your AIDL API is broken. Calls from
* system server to outside MUST be one-way, and so cannot return any result, and this
@@ -395,13 +418,16 @@
public final <T> T runOnBinderBlocking(BlockingBinderRunner<T> runner, T defaultValue) {
try {
return runOnHandlerBlocking(() -> {
- if (mBestService == null) {
+ if (mBinder == null) {
return defaultValue;
}
try {
- return runner.run(mBestService);
- } catch (RemoteException e) {
+ return runner.run(mBinder);
+ } catch (RuntimeException | RemoteException e) {
+ // binders may propagate some specific non-RemoteExceptions from the other side
+ // through the binder as well - we cannot allow those to crash the system server
+ Log.e(TAG, getLogPrefix() + " exception running on " + mServiceInfo, e);
return defaultValue;
}
});
@@ -410,30 +436,6 @@
}
}
- @Override
- public final void onServiceConnected(ComponentName component, IBinder binder) {
- runOnHandler(() -> {
- if (D) Log.d(mTag, component + " connected");
- mBestService = binder;
- onBind();
- });
- }
-
- @Override
- public final void onServiceDisconnected(ComponentName component) {
- runOnHandler(() -> {
- if (D) Log.d(mTag, component + " disconnected");
- mBestService = null;
- onUnbind();
- });
- }
-
- @Override
- public String toString() {
- ComponentName bestComponent = mBestComponent;
- return bestComponent == null ? "null" : bestComponent.toShortString() + "@" + mBestVersion;
- }
-
private void runOnHandler(Runnable r) {
if (Looper.myLooper() == mHandler.getLooper()) {
r.run();
@@ -467,4 +469,8 @@
}
}
}
+
+ private String getLogPrefix() {
+ return "[" + mIntent.getAction() + "]";
+ }
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 00c0b3e..5596b2f 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -214,6 +214,7 @@
import android.content.pm.ParceledListSlice;
import android.content.pm.PathPermission;
import android.content.pm.PermissionInfo;
+import android.content.pm.ProcessInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.SELinuxUtil;
@@ -751,67 +752,23 @@
}
/**
+ * These are the currently running processes for which we have a ProcessInfo.
+ * Note: needs to be static since the permission checking call chain is static. This
+ * all probably should be refactored into a separate permission checking object.
+ */
+ @GuardedBy("sActiveProcessInfoSelfLocked")
+ static final SparseArray<ProcessInfo> sActiveProcessInfoSelfLocked = new SparseArray<>();
+
+ /**
* All of the processes we currently have running organized by pid.
* The keys are the pid running the application.
*
* <p>NOTE: This object is protected by its own lock, NOT the global activity manager lock!
*/
final PidMap mPidsSelfLocked = new PidMap();
- final class PidMap {
+ static final class PidMap {
private final SparseArray<ProcessRecord> mPidMap = new SparseArray<>();
- /**
- * Puts the process record in the map.
- * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this
- * method.
- */
- void put(ProcessRecord app) {
- synchronized (this) {
- mPidMap.put(app.pid, app);
- }
- mAtmInternal.onProcessMapped(app.pid, app.getWindowProcessController());
- }
-
- /**
- * Removes the process record from the map.
- * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this
- * method.
- */
- void remove(ProcessRecord app) {
- boolean removed = false;
- synchronized (this) {
- final ProcessRecord existingApp = mPidMap.get(app.pid);
- if (existingApp != null && existingApp.startSeq == app.startSeq) {
- mPidMap.remove(app.pid);
- removed = true;
- }
- }
- if (removed) {
- mAtmInternal.onProcessUnMapped(app.pid);
- }
- }
-
- /**
- * Removes the process record from the map if it has a thread.
- * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this
- * method.
- */
- boolean removeIfNoThread(ProcessRecord app) {
- boolean removed = false;
- synchronized (this) {
- final ProcessRecord existingApp = get(app.pid);
- if (existingApp != null && existingApp.startSeq == app.startSeq
- && app.thread == null) {
- mPidMap.remove(app.pid);
- removed = true;
- }
- }
- if (removed) {
- mAtmInternal.onProcessUnMapped(app.pid);
- }
- return removed;
- }
-
ProcessRecord get(int pid) {
return mPidMap.get(pid);
}
@@ -831,6 +788,82 @@
int indexOfKey(int key) {
return mPidMap.indexOfKey(key);
}
+
+ void doAddInternal(ProcessRecord app) {
+ mPidMap.put(app.pid, app);
+ }
+
+ boolean doRemoveInternal(ProcessRecord app) {
+ final ProcessRecord existingApp = mPidMap.get(app.pid);
+ if (existingApp != null && existingApp.startSeq == app.startSeq) {
+ mPidMap.remove(app.pid);
+ return true;
+ }
+ return false;
+ }
+
+ boolean doRemoveIfNoThreadInternal(ProcessRecord app) {
+ if (app == null || app.thread != null) {
+ return false;
+ }
+ return doRemoveInternal(app);
+ }
+ }
+
+ /**
+ * Puts the process record in the map.
+ * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this
+ * method.
+ */
+ void addPidLocked(ProcessRecord app) {
+ synchronized (mPidsSelfLocked) {
+ mPidsSelfLocked.doAddInternal(app);
+ }
+ synchronized (sActiveProcessInfoSelfLocked) {
+ if (app.processInfo != null) {
+ sActiveProcessInfoSelfLocked.put(app.pid, app.processInfo);
+ } else {
+ sActiveProcessInfoSelfLocked.remove(app.pid);
+ }
+ }
+ mAtmInternal.onProcessMapped(app.pid, app.getWindowProcessController());
+ }
+
+ /**
+ * Removes the process record from the map.
+ * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this
+ * method.
+ */
+ void removePidLocked(ProcessRecord app) {
+ final boolean removed;
+ synchronized (mPidsSelfLocked) {
+ removed = mPidsSelfLocked.doRemoveInternal(app);
+ }
+ if (removed) {
+ synchronized (sActiveProcessInfoSelfLocked) {
+ sActiveProcessInfoSelfLocked.remove(app.pid);
+ }
+ mAtmInternal.onProcessUnMapped(app.pid);
+ }
+ }
+
+ /**
+ * Removes the process record from the map if it doesn't have a thread.
+ * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this
+ * method.
+ */
+ boolean removePidIfNoThread(ProcessRecord app) {
+ final boolean removed;
+ synchronized (mPidsSelfLocked) {
+ removed = mPidsSelfLocked.doRemoveIfNoThreadInternal(app);
+ }
+ if (removed) {
+ synchronized (sActiveProcessInfoSelfLocked) {
+ sActiveProcessInfoSelfLocked.remove(app.pid);
+ }
+ mAtmInternal.onProcessUnMapped(app.pid);
+ }
+ return removed;
}
/**
@@ -2061,7 +2094,7 @@
app.getWindowProcessController().setPid(MY_PID);
app.maxAdj = ProcessList.SYSTEM_ADJ;
app.makeActive(mSystemThread.getApplicationThread(), mProcessStats);
- mPidsSelfLocked.put(app);
+ addPidLocked(app);
mProcessList.updateLruProcessLocked(app, false, null);
updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_NONE);
}
@@ -4723,7 +4756,7 @@
@GuardedBy("this")
private final void processStartTimedOutLocked(ProcessRecord app) {
final int pid = app.pid;
- boolean gone = mPidsSelfLocked.removeIfNoThread(app);
+ boolean gone = removePidIfNoThread(app);
if (gone) {
Slog.w(TAG, "Process " + app + " failed to attach");
@@ -4796,7 +4829,7 @@
// If there is already an app occupying that pid that hasn't been cleaned up
cleanUpApplicationRecordLocked(app, false, false, -1,
true /*replacingPid*/);
- mPidsSelfLocked.remove(app);
+ removePidLocked(app);
app = null;
}
} else {
@@ -5896,6 +5929,21 @@
if (pid == MY_PID) {
return PackageManager.PERMISSION_GRANTED;
}
+ // If there is an explicit permission being checked, and this is coming from a process
+ // that has been denied access to that permission, then just deny. Ultimately this may
+ // not be quite right -- it means that even if the caller would have access for another
+ // reason (such as being the owner of the component it is trying to access), it would still
+ // fail. This also means the system and root uids would be able to deny themselves
+ // access to permissions, which... well okay. ¯\_(ツ)_/¯
+ if (permission != null) {
+ synchronized (sActiveProcessInfoSelfLocked) {
+ ProcessInfo procInfo = sActiveProcessInfoSelfLocked.get(pid);
+ if (procInfo != null && procInfo.deniedPermissions != null
+ && procInfo.deniedPermissions.contains(permission)) {
+ return PackageManager.PERMISSION_DENIED;
+ }
+ }
+ }
return ActivityManager.checkComponentPermission(permission, uid,
owningUid, exported);
}
@@ -14367,7 +14415,7 @@
return true;
} else if (app.pid > 0 && app.pid != MY_PID) {
// Goodbye!
- mPidsSelfLocked.remove(app);
+ removePidLocked(app);
mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid);
if (app.isolated) {
diff --git a/services/core/java/com/android/server/am/CoreSettingsObserver.java b/services/core/java/com/android/server/am/CoreSettingsObserver.java
index fa55701..a03f0bb 100644
--- a/services/core/java/com/android/server/am/CoreSettingsObserver.java
+++ b/services/core/java/com/android/server/am/CoreSettingsObserver.java
@@ -108,6 +108,21 @@
sDeviceConfigEntries.add(new DeviceConfigEntry(
DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_CURSOR_CONTROL,
WidgetFlags.KEY_ENABLE_CURSOR_CONTROL, boolean.class));
+ sDeviceConfigEntries.add(new DeviceConfigEntry(
+ DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_DELTA_HEIGHT,
+ WidgetFlags.KEY_INSERTION_HANDLE_DELTA_HEIGHT, int.class));
+ sDeviceConfigEntries.add(new DeviceConfigEntry(
+ DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.INSERTION_HANDLE_OPACITY,
+ WidgetFlags.KEY_INSERTION_HANDLE_OPACITY, int.class));
+ sDeviceConfigEntries.add(new DeviceConfigEntry(
+ DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ENABLE_NEW_MAGNIFIER,
+ WidgetFlags.KEY_ENABLE_NEW_MAGNIFIER, boolean.class));
+ sDeviceConfigEntries.add(new DeviceConfigEntry(
+ DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ZOOM_FACTOR,
+ WidgetFlags.KEY_MAGNIFIER_ZOOM_FACTOR, float.class));
+ sDeviceConfigEntries.add(new DeviceConfigEntry(
+ DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO,
+ WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class));
// add other device configs here...
}
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 4a89845..38cb501 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -1564,7 +1564,7 @@
long startTime = SystemClock.uptimeMillis();
if (app.pid > 0 && app.pid != ActivityManagerService.MY_PID) {
checkSlow(startTime, "startProcess: removing from pids map");
- mService.mPidsSelfLocked.remove(app);
+ mService.removePidLocked(app);
mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
checkSlow(startTime, "startProcess: done removing from pids map");
app.setPid(0);
@@ -1609,10 +1609,28 @@
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
+
+ // Remove any gids needed if the process has been denied permissions.
+ // NOTE: eventually we should probably have the package manager pre-compute
+ // this for us?
+ if (app.processInfo != null && app.processInfo.deniedPermissions != null) {
+ for (int i = app.processInfo.deniedPermissions.size() - 1; i >= 0; i--) {
+ int[] denyGids = mService.mPackageManagerInt.getPermissionGids(
+ app.processInfo.deniedPermissions.valueAt(i), app.userId);
+ if (denyGids != null) {
+ for (int gid : denyGids) {
+ permGids = ArrayUtils.removeInt(permGids, gid);
+ }
+ }
+ }
+ }
+
int numGids = 3;
- if (mountExternal == Zygote.MOUNT_EXTERNAL_ANDROID_WRITABLE) {
+ if (mountExternal == Zygote.MOUNT_EXTERNAL_ANDROID_WRITABLE
+ || app.info.packageName.equals("com.android.externalstorage")) {
numGids++;
}
+
/*
* Add shared application and profile GIDs so applications can share some
* resources like shared libraries and access user-wide resources
@@ -1626,8 +1644,14 @@
gids[0] = UserHandle.getSharedAppGid(UserHandle.getAppId(uid));
gids[1] = UserHandle.getCacheAppGid(UserHandle.getAppId(uid));
gids[2] = UserHandle.getUserGid(UserHandle.getUserId(uid));
+
if (numGids > 3) {
- gids[3] = Process.SDCARD_RW_GID;
+ if (app.info.packageName.equals("com.android.externalstorage")) {
+ // Allows access to 'unreliable' (USB OTG) volumes via SAF
+ gids[3] = Process.MEDIA_RW_GID;
+ } else if (mountExternal == Zygote.MOUNT_EXTERNAL_ANDROID_WRITABLE) {
+ gids[3] = Process.SDCARD_RW_GID;
+ }
}
// Replace any invalid GIDs
@@ -2311,7 +2335,7 @@
mService.cleanUpApplicationRecordLocked(oldApp, false, false, -1,
true /*replacingPid*/);
}
- mService.mPidsSelfLocked.put(app);
+ mService.addPidLocked(app);
synchronized (mService.mPidsSelfLocked) {
if (!procAttached) {
Message msg = mService.mHandler.obtainMessage(PROC_START_TIMEOUT_MSG);
@@ -2492,7 +2516,7 @@
.pendingStart)) {
int pid = app.pid;
if (pid > 0) {
- mService.mPidsSelfLocked.remove(app);
+ mService.removePidLocked(app);
mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
mService.mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid);
if (app.isolated) {
@@ -3945,4 +3969,3 @@
}
};
}
-
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
index 156466c..0e1e0f9 100644
--- a/services/core/java/com/android/server/am/ProcessRecord.java
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
@@ -35,6 +35,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.ProcessInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.VersionedPackage;
import android.content.res.CompatibilityInfo;
@@ -84,6 +85,7 @@
private final ActivityManagerService mService; // where we came from
final ApplicationInfo info; // all about the first app in the process
+ final ProcessInfo processInfo; // if non-null, process-specific manifest info
final boolean isolated; // true if this is a special isolated process
final boolean appZygote; // true if this is forked from the app zygote
final int uid; // uid of process; may be different from 'info' if isolated
@@ -603,6 +605,13 @@
int _uid) {
mService = _service;
info = _info;
+ if (_service.mPackageManagerInt != null) {
+ ArrayMap<String, ProcessInfo> processes =
+ _service.mPackageManagerInt.getProcessesForUid(_uid);
+ processInfo = processes != null ? processes.get(_processName) : null;
+ } else {
+ processInfo = null;
+ }
isolated = _info.uid != _uid;
appZygote = (UserHandle.getAppId(_uid) >= Process.FIRST_APP_ZYGOTE_ISOLATED_UID
&& UserHandle.getAppId(_uid) <= Process.LAST_APP_ZYGOTE_ISOLATED_UID);
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 46972d9..73ec43f 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -21,6 +21,7 @@
import static android.media.AudioManager.RINGER_MODE_SILENT;
import static android.media.AudioManager.RINGER_MODE_VIBRATE;
import static android.media.AudioManager.STREAM_SYSTEM;
+import static android.media.audiopolicy.AudioMixingRule.RULE_MATCH_ATTRIBUTE_USAGE;
import static android.os.Process.FIRST_APPLICATION_UID;
import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE;
import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
@@ -89,6 +90,7 @@
import android.media.VolumePolicy;
import android.media.audiofx.AudioEffect;
import android.media.audiopolicy.AudioMix;
+import android.media.audiopolicy.AudioMixingRule.AudioMixMatchCriterion;
import android.media.audiopolicy.AudioPolicy;
import android.media.audiopolicy.AudioPolicyConfig;
import android.media.audiopolicy.AudioProductStrategy;
@@ -6774,6 +6776,7 @@
boolean requireValidProjection = false;
boolean requireCaptureAudioOrMediaOutputPerm = false;
+ boolean requireVoiceComunicationOutputPerm = false;
boolean requireModifyRouting = false;
if (hasFocusAccess || isVolumeController) {
@@ -6783,8 +6786,15 @@
requireModifyRouting |= true;
}
for (AudioMix mix : policyConfig.getMixes()) {
- // If mix is requesting a privileged capture
- if (mix.getRule().allowPrivilegedPlaybackCapture()) {
+ // If mix is trying to capture USAGE_VOICE_COMMUNICATION using playback capture
+ if (isVoiceCommunicationPlaybackCaptureMix(mix)) {
+ // then it must have CAPTURE_USAGE_VOICE_COMMUNICATION_OUTPUT permission
+ requireVoiceComunicationOutputPerm |= true;
+ }
+ // If mix is requesting privileged capture and is capturing at
+ // least one usage which is not USAGE_VOICE_COMMUNICATION.
+ if (mix.getRule().allowPrivilegedPlaybackCapture()
+ && isNonVoiceCommunicationCaptureMix(mix)) {
// then it must have CAPTURE_MEDIA_OUTPUT or CAPTURE_AUDIO_OUTPUT permission
requireCaptureAudioOrMediaOutputPerm |= true;
// and its format must be low quality enough
@@ -6812,6 +6822,14 @@
return false;
}
+ if (requireVoiceComunicationOutputPerm
+ && !callerHasPermission(
+ android.Manifest.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT)) {
+ Log.e(TAG, "Privileged audio capture for voice communication requires "
+ + "CAPTURE_VOICE_COMMUNICATION_OUTPUT system permission");
+ return false;
+ }
+
if (requireValidProjection && !canProjectAudio(projection)) {
return false;
}
@@ -6825,6 +6843,41 @@
return true;
}
+ /**
+ * Checks whether a given AudioMix is used for playback capture
+ * (has the ROUTE_FLAG_LOOP_BACK_RENDER flag) and has a matching
+ * criterion for USAGE_VOICE_COMMUNICATION.
+ */
+ private boolean isVoiceCommunicationPlaybackCaptureMix(AudioMix mix) {
+ if (mix.getRouteFlags() != mix.ROUTE_FLAG_LOOP_BACK_RENDER) {
+ return false;
+ }
+
+ for (AudioMixMatchCriterion criterion : mix.getRule().getCriteria()) {
+ if (criterion.getRule() == RULE_MATCH_ATTRIBUTE_USAGE
+ && criterion.getAudioAttributes().getUsage()
+ == AudioAttributes.USAGE_VOICE_COMMUNICATION) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks whether a given AudioMix has a matching
+ * criterion for a usage which is not USAGE_VOICE_COMMUNICATION.
+ */
+ private boolean isNonVoiceCommunicationCaptureMix(AudioMix mix) {
+ for (AudioMixMatchCriterion criterion : mix.getRule().getCriteria()) {
+ if (criterion.getRule() == RULE_MATCH_ATTRIBUTE_USAGE
+ && criterion.getAudioAttributes().getUsage()
+ != AudioAttributes.USAGE_VOICE_COMMUNICATION) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private boolean callerHasPermission(String permission) {
return mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
diff --git a/services/core/java/com/android/server/display/DisplayDeviceConfig.java b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
index 4796edf..e09cf61 100644
--- a/services/core/java/com/android/server/display/DisplayDeviceConfig.java
+++ b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
@@ -20,6 +20,7 @@
import android.util.Slog;
import com.android.server.display.config.DisplayConfiguration;
+import com.android.server.display.config.NitsMap;
import com.android.server.display.config.Point;
import com.android.server.display.config.XmlParser;
@@ -30,6 +31,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.math.BigDecimal;
import java.util.List;
import javax.xml.datatype.DatatypeConfigurationException;
@@ -40,12 +42,15 @@
public class DisplayDeviceConfig {
private static final String TAG = "DisplayDeviceConfig";
+ public static final float HIGH_BRIGHTNESS_MODE_UNSUPPORTED = Float.NaN;
+
private static final String ETC_DIR = "etc";
private static final String DISPLAY_CONFIG_DIR = "displayconfig";
private static final String CONFIG_FILE_FORMAT = "display_%d.xml";
private float[] mNits;
private float[] mBrightness;
+ private BigDecimal mHighBrightnessModeStart;
private DisplayDeviceConfig() {
}
@@ -83,6 +88,18 @@
return mBrightness;
}
+ /**
+ * Returns the point along the brightness value range {@link #getBrightness()} that
+ * high-brightness-mode begins. If high-brightness-mode is not supported, then
+ * Float.NaN is returned.
+ *
+ * @return The high brightness mode threshold, or Float.NaN if not supported.
+ */
+ public float getHighBrightnessModeStart() {
+ return mHighBrightnessModeStart != null
+ ? mHighBrightnessModeStart.floatValue() : HIGH_BRIGHTNESS_MODE_UNSUPPORTED;
+ }
+
private void initFromFile(File configFile) {
if (!configFile.exists()) {
// Display configuration files aren't required to exist.
@@ -104,7 +121,8 @@
}
private void loadBrightnessMap(DisplayConfiguration config) {
- final List<Point> points = config.getScreenBrightnessMap().getPoint();
+ final NitsMap map = config.getScreenBrightnessMap();
+ final List<Point> points = map.getPoint();
final int size = points.size();
float[] nits = new float[size];
@@ -130,7 +148,9 @@
}
++i;
}
+ final BigDecimal hbmStart = map.getHighBrightnessStart();
+ mHighBrightnessModeStart = hbmStart;
mNits = nits;
mBrightness = backlight;
}
diff --git a/services/core/java/com/android/server/lights/OWNERS b/services/core/java/com/android/server/lights/OWNERS
index c7c6d56..0e795b9 100644
--- a/services/core/java/com/android/server/lights/OWNERS
+++ b/services/core/java/com/android/server/lights/OWNERS
@@ -1,2 +1,3 @@
michaelwr@google.com
-dangittik@google.com
+santoscordon@google.com
+flc@google.com
diff --git a/services/core/java/com/android/server/location/ActivityRecognitionProxy.java b/services/core/java/com/android/server/location/ActivityRecognitionProxy.java
deleted file mode 100644
index 80ab790..0000000
--- a/services/core/java/com/android/server/location/ActivityRecognitionProxy.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2014 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.server.location;
-
-import android.content.Context;
-import android.hardware.location.ActivityRecognitionHardware;
-import android.hardware.location.IActivityRecognitionHardwareClient;
-import android.hardware.location.IActivityRecognitionHardwareWatcher;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.util.Log;
-
-import com.android.server.FgThread;
-import com.android.server.ServiceWatcher;
-
-/**
- * Proxy class to bind GmsCore to the ActivityRecognitionHardware.
- *
- * @hide
- */
-public class ActivityRecognitionProxy {
-
- private static final String TAG = "ActivityRecognitionProxy";
-
- /**
- * Creates an instance of the proxy and binds it to the appropriate FusedProvider.
- *
- * @return An instance of the proxy if it could be bound, null otherwise.
- */
- public static ActivityRecognitionProxy createAndBind(
- Context context,
- boolean activityRecognitionHardwareIsSupported,
- ActivityRecognitionHardware activityRecognitionHardware,
- int overlaySwitchResId,
- int defaultServicePackageNameResId,
- int initialPackageNameResId) {
- ActivityRecognitionProxy activityRecognitionProxy = new ActivityRecognitionProxy(
- context,
- activityRecognitionHardwareIsSupported,
- activityRecognitionHardware,
- overlaySwitchResId,
- defaultServicePackageNameResId,
- initialPackageNameResId);
-
- if (activityRecognitionProxy.mServiceWatcher.start()) {
- return activityRecognitionProxy;
- } else {
- return null;
- }
- }
-
- private final ServiceWatcher mServiceWatcher;
- private final boolean mIsSupported;
- private final ActivityRecognitionHardware mInstance;
-
- private ActivityRecognitionProxy(
- Context context,
- boolean activityRecognitionHardwareIsSupported,
- ActivityRecognitionHardware activityRecognitionHardware,
- int overlaySwitchResId,
- int defaultServicePackageNameResId,
- int initialPackageNameResId) {
- mIsSupported = activityRecognitionHardwareIsSupported;
- mInstance = activityRecognitionHardware;
-
- mServiceWatcher = new ServiceWatcher(
- context,
- TAG,
- "com.android.location.service.ActivityRecognitionProvider",
- overlaySwitchResId,
- defaultServicePackageNameResId,
- initialPackageNameResId,
- FgThread.getHandler()) {
- @Override
- protected void onBind() {
- runOnBinder(ActivityRecognitionProxy.this::initializeService);
- }
- };
- }
-
- private void initializeService(IBinder binder) {
- try {
- String descriptor = binder.getInterfaceDescriptor();
-
- if (IActivityRecognitionHardwareWatcher.class.getCanonicalName().equals(
- descriptor)) {
- IActivityRecognitionHardwareWatcher watcher =
- IActivityRecognitionHardwareWatcher.Stub.asInterface(binder);
- if (mInstance != null) {
- watcher.onInstanceChanged(mInstance);
- }
- } else if (IActivityRecognitionHardwareClient.class.getCanonicalName()
- .equals(descriptor)) {
- IActivityRecognitionHardwareClient client =
- IActivityRecognitionHardwareClient.Stub.asInterface(binder);
- client.onAvailabilityChanged(mIsSupported, mInstance);
- } else {
- Log.e(TAG, "Invalid descriptor found on connection: " + descriptor);
- }
- } catch (RemoteException e) {
- Log.w(TAG, e);
- }
- }
-}
diff --git a/services/core/java/com/android/server/location/GeocoderProxy.java b/services/core/java/com/android/server/location/GeocoderProxy.java
index e6f0ed9..536f95a 100644
--- a/services/core/java/com/android/server/location/GeocoderProxy.java
+++ b/services/core/java/com/android/server/location/GeocoderProxy.java
@@ -16,6 +16,7 @@
package com.android.server.location;
+import android.annotation.Nullable;
import android.content.Context;
import android.location.Address;
import android.location.GeocoderParams;
@@ -28,40 +29,38 @@
/**
* Proxy for IGeocodeProvider implementations.
+ *
+ * @hide
*/
public class GeocoderProxy {
- private static final String TAG = "GeocoderProxy";
private static final String SERVICE_ACTION = "com.android.location.service.GeocodeProvider";
- private final ServiceWatcher mServiceWatcher;
-
- public static GeocoderProxy createAndBind(Context context,
- int overlaySwitchResId, int defaultServicePackageNameResId,
- int initialPackageNamesResId) {
- GeocoderProxy proxy = new GeocoderProxy(context, overlaySwitchResId,
- defaultServicePackageNameResId, initialPackageNamesResId);
- if (proxy.bind()) {
+ /**
+ * Creates and registers this proxy. If no suitable service is available for the proxy, returns
+ * null.
+ */
+ @Nullable
+ public static GeocoderProxy createAndRegister(Context context) {
+ GeocoderProxy proxy = new GeocoderProxy(context);
+ if (proxy.register()) {
return proxy;
} else {
return null;
}
}
- private GeocoderProxy(Context context,
- int overlaySwitchResId, int defaultServicePackageNameResId,
- int initialPackageNamesResId) {
- mServiceWatcher = new ServiceWatcher(context, TAG, SERVICE_ACTION, overlaySwitchResId,
- defaultServicePackageNameResId, initialPackageNamesResId,
- BackgroundThread.getHandler());
+ private final ServiceWatcher mServiceWatcher;
+
+ private GeocoderProxy(Context context) {
+ mServiceWatcher = new ServiceWatcher(context, BackgroundThread.getHandler(), SERVICE_ACTION,
+ null, null,
+ com.android.internal.R.bool.config_enableGeocoderOverlay,
+ com.android.internal.R.string.config_geocoderProviderPackageName);
}
- private boolean bind() {
- return mServiceWatcher.start();
- }
-
- public String getConnectedPackageName() {
- return mServiceWatcher.getCurrentPackageName();
+ private boolean register() {
+ return mServiceWatcher.register();
}
public String getFromLocation(double latitude, double longitude, int maxResults,
@@ -83,5 +82,4 @@
maxResults, params, addrs);
}, "Service not Available");
}
-
}
diff --git a/services/core/java/com/android/server/location/GeofenceProxy.java b/services/core/java/com/android/server/location/GeofenceProxy.java
index ce93661..f006fb1 100644
--- a/services/core/java/com/android/server/location/GeofenceProxy.java
+++ b/services/core/java/com/android/server/location/GeofenceProxy.java
@@ -22,7 +22,6 @@
import android.content.ServiceConnection;
import android.hardware.location.GeofenceHardwareService;
import android.hardware.location.IGeofenceHardware;
-import android.location.IFusedGeofenceHardware;
import android.location.IGeofenceProvider;
import android.location.IGpsGeofenceHardware;
import android.os.IBinder;
@@ -33,6 +32,8 @@
import com.android.server.FgThread;
import com.android.server.ServiceWatcher;
+import java.util.Objects;
+
/**
* @hide
*/
@@ -41,64 +42,41 @@
private static final String TAG = "GeofenceProxy";
private static final String SERVICE_ACTION = "com.android.location.service.GeofenceProvider";
- private final Context mContext;
- private final ServiceWatcher mServiceWatcher;
-
@Nullable
- private final IGpsGeofenceHardware mGpsGeofenceHardware;
- @Nullable
- private final IFusedGeofenceHardware mFusedGeofenceHardware;
-
- private volatile IGeofenceHardware mGeofenceHardware;
-
- private final ServiceWatcher.BinderRunner mUpdateGeofenceHardware = (binder) -> {
- IGeofenceProvider provider = IGeofenceProvider.Stub.asInterface(binder);
- try {
- provider.setGeofenceHardware(mGeofenceHardware);
- } catch (RemoteException e) {
- Log.w(TAG, e);
- }
- };
-
- public static GeofenceProxy createAndBind(Context context,
- int overlaySwitchResId, int defaultServicePackageNameResId,
- int initialPackageNamesResId, @Nullable IGpsGeofenceHardware gpsGeofence,
- @Nullable IFusedGeofenceHardware fusedGeofenceHardware) {
- GeofenceProxy proxy = new GeofenceProxy(context, overlaySwitchResId,
- defaultServicePackageNameResId, initialPackageNamesResId, gpsGeofence,
- fusedGeofenceHardware);
-
- if (proxy.bind()) {
+ public static GeofenceProxy createAndBind(Context context, IGpsGeofenceHardware gpsGeofence) {
+ GeofenceProxy proxy = new GeofenceProxy(context, gpsGeofence);
+ if (proxy.register(context)) {
return proxy;
} else {
return null;
}
}
- private GeofenceProxy(Context context,
- int overlaySwitchResId, int defaultServicePackageNameResId,
- int initialPackageNamesResId, @Nullable IGpsGeofenceHardware gpsGeofence,
- @Nullable IFusedGeofenceHardware fusedGeofenceHardware) {
- mContext = context;
- mServiceWatcher = new ServiceWatcher(context, TAG, SERVICE_ACTION, overlaySwitchResId,
- defaultServicePackageNameResId, initialPackageNamesResId,
- FgThread.getHandler()) {
- @Override
- protected void onBind() {
- runOnBinder(mUpdateGeofenceHardware);
- }
- };
+ private final IGpsGeofenceHardware mGpsGeofenceHardware;
+ private final ServiceWatcher mServiceWatcher;
- mGpsGeofenceHardware = gpsGeofence;
- mFusedGeofenceHardware = fusedGeofenceHardware;
+ private volatile IGeofenceHardware mGeofenceHardware;
+
+ private GeofenceProxy(Context context, IGpsGeofenceHardware gpsGeofence) {
+ mGpsGeofenceHardware = Objects.requireNonNull(gpsGeofence);
+ mServiceWatcher = new ServiceWatcher(context, FgThread.getHandler(), SERVICE_ACTION,
+ this::updateGeofenceHardware, null,
+ com.android.internal.R.bool.config_enableGeofenceOverlay,
+ com.android.internal.R.string.config_geofenceProviderPackageName);
mGeofenceHardware = null;
}
- private boolean bind() {
- if (mServiceWatcher.start()) {
- mContext.bindServiceAsUser(new Intent(mContext, GeofenceHardwareService.class),
- new GeofenceProxyServiceConnection(), Context.BIND_AUTO_CREATE,
+ private void updateGeofenceHardware(IBinder binder) throws RemoteException {
+ IGeofenceProvider.Stub.asInterface(binder).setGeofenceHardware(mGeofenceHardware);
+ }
+
+ private boolean register(Context context) {
+ if (mServiceWatcher.register()) {
+ context.bindServiceAsUser(
+ new Intent(context, GeofenceHardwareService.class),
+ new GeofenceProxyServiceConnection(),
+ Context.BIND_AUTO_CREATE,
UserHandle.SYSTEM);
return true;
}
@@ -113,24 +91,18 @@
IGeofenceHardware geofenceHardware = IGeofenceHardware.Stub.asInterface(service);
try {
- if (mGpsGeofenceHardware != null) {
- geofenceHardware.setGpsGeofenceHardware(mGpsGeofenceHardware);
- }
- if (mFusedGeofenceHardware != null) {
- geofenceHardware.setFusedGeofenceHardware(mFusedGeofenceHardware);
- }
-
+ geofenceHardware.setGpsGeofenceHardware(mGpsGeofenceHardware);
mGeofenceHardware = geofenceHardware;
- mServiceWatcher.runOnBinder(mUpdateGeofenceHardware);
- } catch (Exception e) {
- Log.w(TAG, e);
+ mServiceWatcher.runOnBinder(GeofenceProxy.this::updateGeofenceHardware);
+ } catch (RemoteException e) {
+ Log.w(TAG, "unable to initialize geofence hardware", e);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
mGeofenceHardware = null;
- mServiceWatcher.runOnBinder(mUpdateGeofenceHardware);
+ mServiceWatcher.runOnBinder(GeofenceProxy.this::updateGeofenceHardware);
}
}
}
diff --git a/services/core/java/com/android/server/location/HardwareActivityRecognitionProxy.java b/services/core/java/com/android/server/location/HardwareActivityRecognitionProxy.java
new file mode 100644
index 0000000..9d9852b
--- /dev/null
+++ b/services/core/java/com/android/server/location/HardwareActivityRecognitionProxy.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014 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.server.location;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.hardware.location.ActivityRecognitionHardware;
+import android.hardware.location.IActivityRecognitionHardwareClient;
+import android.hardware.location.IActivityRecognitionHardwareWatcher;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Log;
+
+import com.android.server.FgThread;
+import com.android.server.ServiceWatcher;
+
+/**
+ * Proxy class to bind GmsCore to the ActivityRecognitionHardware.
+ *
+ * @hide
+ */
+public class HardwareActivityRecognitionProxy {
+
+ private static final String TAG = "ARProxy";
+ private static final String SERVICE_ACTION =
+ "com.android.location.service.ActivityRecognitionProvider";
+
+ /**
+ * Creates and registers this proxy. If no suitable service is available for the proxy, returns
+ * null.
+ */
+ @Nullable
+ public static HardwareActivityRecognitionProxy createAndRegister(Context context) {
+ HardwareActivityRecognitionProxy arProxy = new HardwareActivityRecognitionProxy(context);
+ if (arProxy.register()) {
+ return arProxy;
+ } else {
+ return null;
+ }
+ }
+
+ private final boolean mIsSupported;
+ private final ActivityRecognitionHardware mInstance;
+
+ private final ServiceWatcher mServiceWatcher;
+
+ private HardwareActivityRecognitionProxy(Context context) {
+ mIsSupported = ActivityRecognitionHardware.isSupported();
+ if (mIsSupported) {
+ mInstance = ActivityRecognitionHardware.getInstance(context);
+ } else {
+ mInstance = null;
+ }
+
+ mServiceWatcher = new ServiceWatcher(context,
+ FgThread.getHandler(),
+ SERVICE_ACTION,
+ this::onBind,
+ null,
+ com.android.internal.R.bool.config_enableActivityRecognitionHardwareOverlay,
+ com.android.internal.R.string.config_activityRecognitionHardwarePackageName);
+ }
+
+ private boolean register() {
+ return mServiceWatcher.register();
+ }
+
+ private void onBind(IBinder binder) throws RemoteException {
+ String descriptor = binder.getInterfaceDescriptor();
+
+ if (IActivityRecognitionHardwareWatcher.class.getCanonicalName().equals(descriptor)) {
+ IActivityRecognitionHardwareWatcher watcher =
+ IActivityRecognitionHardwareWatcher.Stub.asInterface(binder);
+ if (mInstance != null) {
+ watcher.onInstanceChanged(mInstance);
+ }
+ } else if (IActivityRecognitionHardwareClient.class.getCanonicalName().equals(descriptor)) {
+ IActivityRecognitionHardwareClient client =
+ IActivityRecognitionHardwareClient.Stub.asInterface(binder);
+ client.onAvailabilityChanged(mIsSupported, mInstance);
+ } else {
+ Log.e(TAG, "Unknown descriptor: " + descriptor);
+ }
+ }
+}
diff --git a/services/core/java/com/android/server/location/LocationProviderProxy.java b/services/core/java/com/android/server/location/LocationProviderProxy.java
index 8a149af..805b018 100644
--- a/services/core/java/com/android/server/location/LocationProviderProxy.java
+++ b/services/core/java/com/android/server/location/LocationProviderProxy.java
@@ -19,12 +19,11 @@
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
import android.annotation.Nullable;
+import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.HandlerExecutor;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.ArraySet;
@@ -35,7 +34,6 @@
import com.android.internal.location.ProviderProperties;
import com.android.internal.location.ProviderRequest;
import com.android.server.FgThread;
-import com.android.server.LocationManagerService;
import com.android.server.ServiceWatcher;
import java.io.FileDescriptor;
@@ -49,17 +47,31 @@
public class LocationProviderProxy extends AbstractLocationProvider {
private static final String TAG = "LocationProviderProxy";
- private static final boolean D = LocationManagerService.D;
private static final int MAX_ADDITIONAL_PACKAGES = 2;
+ /**
+ * Creates and registers this proxy. If no suitable service is available for the proxy, returns
+ * null.
+ */
+ @Nullable
+ public static LocationProviderProxy createAndRegister(Context context, String action,
+ int enableOverlayResId, int nonOverlayPackageResId) {
+ LocationProviderProxy proxy = new LocationProviderProxy(context, action, enableOverlayResId,
+ nonOverlayPackageResId);
+ if (proxy.register()) {
+ return proxy;
+ } else {
+ return null;
+ }
+ }
+
private final ILocationProviderManager.Stub mManager = new ILocationProviderManager.Stub() {
// executed on binder thread
@Override
public void onSetAdditionalProviderPackages(List<String> packageNames) {
- int maxCount = Math.min(MAX_ADDITIONAL_PACKAGES, packageNames.size()) + 1;
+ int maxCount = Math.min(MAX_ADDITIONAL_PACKAGES, packageNames.size());
ArraySet<String> allPackages = new ArraySet<>(maxCount);
- allPackages.add(mServiceWatcher.getCurrentPackageName());
for (String packageName : packageNames) {
if (packageNames.size() >= maxCount) {
return;
@@ -74,6 +86,12 @@
}
}
+ // add the binder package
+ ComponentName service = mServiceWatcher.getBoundService().component;
+ if (service != null) {
+ allPackages.add(service.getPackageName());
+ }
+
setPackageNames(allPackages);
}
@@ -100,63 +118,39 @@
@Nullable private ProviderRequest mRequest;
- /**
- * Creates a new LocationProviderProxy and immediately begins binding to the best applicable
- * service.
- */
- @Nullable
- public static LocationProviderProxy createAndBind(Context context, String action,
- int overlaySwitchResId, int defaultServicePackageNameResId,
- int initialPackageNamesResId) {
- LocationProviderProxy proxy = new LocationProviderProxy(context, FgThread.getHandler(),
- action, overlaySwitchResId, defaultServicePackageNameResId,
- initialPackageNamesResId);
- if (proxy.bind()) {
- return proxy;
- } else {
- return null;
- }
- }
+ private LocationProviderProxy(Context context, String action, int enableOverlayResId,
+ int nonOverlayPackageResId) {
+ super(context, FgThread.getExecutor());
- private LocationProviderProxy(Context context, Handler handler, String action,
- int overlaySwitchResId, int defaultServicePackageNameResId,
- int initialPackageNamesResId) {
- super(context, new HandlerExecutor(handler), Collections.emptySet());
-
- mServiceWatcher = new ServiceWatcher(context, TAG, action, overlaySwitchResId,
- defaultServicePackageNameResId, initialPackageNamesResId, handler) {
-
- @Override
- protected void onBind() {
- runOnBinder(LocationProviderProxy.this::initializeService);
- }
-
- @Override
- protected void onUnbind() {
- setState(State.EMPTY_STATE);
- }
- };
+ mServiceWatcher = new ServiceWatcher(context, FgThread.getHandler(), action, this::onBind,
+ this::onUnbind, enableOverlayResId, nonOverlayPackageResId);
mRequest = null;
}
- private boolean bind() {
- return mServiceWatcher.start();
+ private boolean register() {
+ return mServiceWatcher.register();
}
- private void initializeService(IBinder binder) throws RemoteException {
- ILocationProvider service = ILocationProvider.Stub.asInterface(binder);
- if (D) Log.d(TAG, "applying state to connected service " + mServiceWatcher);
+ private void onBind(IBinder binder) throws RemoteException {
+ ILocationProvider provider = ILocationProvider.Stub.asInterface(binder);
- setPackageNames(Collections.singleton(mServiceWatcher.getCurrentPackageName()));
+ ComponentName service = mServiceWatcher.getBoundService().component;
+ if (service != null) {
+ setPackageNames(Collections.singleton(service.getPackageName()));
+ }
- service.setLocationProviderManager(mManager);
+ provider.setLocationProviderManager(mManager);
if (mRequest != null) {
- service.setRequest(mRequest, mRequest.workSource);
+ provider.setRequest(mRequest, mRequest.workSource);
}
}
+ private void onUnbind() {
+ setState(State.EMPTY_STATE);
+ }
+
@Override
public void onSetRequest(ProviderRequest request) {
mServiceWatcher.runOnBinder(binder -> {
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index 4a6fcdf7..a6ad57a 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -103,6 +103,7 @@
private static final int WAKELOCK_TIMEOUT = 5000;
private static final int MEDIA_KEY_LISTENER_TIMEOUT = 1000;
+ private static final int SESSION_CREATION_LIMIT_PER_UID = 100;
private final Context mContext;
private final SessionManagerImpl mSessionManagerImpl;
@@ -428,6 +429,18 @@
Log.d(TAG, "Destroying " + session);
}
FullUserRecord user = getFullUserRecordLocked(session.getUserId());
+
+ if (user != null) {
+ final int uid = session.getUid();
+ final int sessionCount = user.mUidToSessionCount.get(uid, 0);
+ if (sessionCount <= 0) {
+ Log.w(TAG, "destroySessionLocked: sessionCount should be positive. "
+ + "sessionCount=" + sessionCount);
+ } else {
+ user.mUidToSessionCount.put(uid, sessionCount - 1);
+ }
+ }
+
if (mGlobalPrioritySession == session) {
mGlobalPrioritySession = null;
if (session.isActive() && user != null) {
@@ -490,6 +503,20 @@
}
}
+ private boolean hasMediaControlPermission(int pid, int uid) {
+ // Check if it's system server or has MEDIA_CONTENT_CONTROL.
+ // Note that system server doesn't have MEDIA_CONTENT_CONTROL, so we need extra
+ // check here.
+ if (uid == Process.SYSTEM_UID || mContext.checkPermission(
+ android.Manifest.permission.MEDIA_CONTENT_CONTROL, pid, uid)
+ == PackageManager.PERMISSION_GRANTED) {
+ return true;
+ } else if (DEBUG) {
+ Log.d(TAG, "uid(" + uid + ") hasn't granted MEDIA_CONTENT_CONTROL");
+ }
+ return false;
+ }
+
/**
* This checks if the component is an enabled notification listener for the
* specified user. Enabled components may only operate on behalf of the user
@@ -544,6 +571,14 @@
throw new RuntimeException("Media Session owner died prematurely.", e);
}
+ final int sessionCount = user.mUidToSessionCount.get(callerUid, 0);
+ if (sessionCount >= SESSION_CREATION_LIMIT_PER_UID
+ && !hasMediaControlPermission(callerPid, callerUid)) {
+ throw new RuntimeException("Created too many sessions. count="
+ + sessionCount + ")");
+ }
+ user.mUidToSessionCount.put(callerUid, sessionCount + 1);
+
user.mPriorityStack.addSession(session);
mHandler.postSessionsChanged(session);
@@ -723,6 +758,7 @@
mOnMediaKeyEventDispatchedListeners = new HashMap<>();
private final HashMap<IBinder, OnMediaKeyEventSessionChangedListenerRecord>
mOnMediaKeyEventSessionChangedListeners = new HashMap<>();
+ private final SparseIntArray mUidToSessionCount = new SparseIntArray();
private PendingIntent mLastMediaButtonReceiver;
private ComponentName mRestoredMediaButtonReceiver;
@@ -1954,20 +1990,6 @@
return resolvedUserId;
}
- private boolean hasMediaControlPermission(int pid, int uid) {
- // Check if it's system server or has MEDIA_CONTENT_CONTROL.
- // Note that system server doesn't have MEDIA_CONTENT_CONTROL, so we need extra
- // check here.
- if (uid == Process.SYSTEM_UID || mContext.checkPermission(
- android.Manifest.permission.MEDIA_CONTENT_CONTROL, pid, uid)
- == PackageManager.PERMISSION_GRANTED) {
- return true;
- } else if (DEBUG) {
- Log.d(TAG, "uid(" + uid + ") hasn't granted MEDIA_CONTENT_CONTROL");
- }
- return false;
- }
-
private boolean hasEnabledNotificationListener(int resolvedUserId, String packageName)
throws RemoteException {
// You may not access another user's content as an enabled listener.
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 3a33313..afd9e09 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -185,6 +185,7 @@
import android.content.pm.ParceledListSlice;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
+import android.content.pm.ProcessInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.SELinuxUtil;
@@ -3158,6 +3159,7 @@
// Adjust seInfo to ensure apps which share a sharedUserId are placed in the same
// SELinux domain.
setting.fixSeInfoLocked();
+ setting.updateProcesses();
}
// Now that we know all the packages we are keeping,
@@ -23487,6 +23489,20 @@
}
@Override
+ public ArrayMap<String, ProcessInfo> getProcessesForUid(int uid) {
+ synchronized (mLock) {
+ return getProcessesForUidLocked(uid);
+ }
+ }
+
+ @Override
+ public int[] getPermissionGids(String permissionName, int userId) {
+ synchronized (mLock) {
+ return getPermissionGidsLocked(permissionName, userId);
+ }
+ }
+
+ @Override
public boolean isOnlyCoreApps() {
return PackageManagerService.this.isOnlyCoreApps();
}
@@ -23741,6 +23757,30 @@
return res != null ? res : EmptyArray.STRING;
}
+ @GuardedBy("mLock")
+ public ArrayMap<String, ProcessInfo> getProcessesForUidLocked(int uid) {
+ final int appId = UserHandle.getAppId(uid);
+ final SettingBase obj = mSettings.getSettingLPr(appId);
+ if (obj instanceof SharedUserSetting) {
+ final SharedUserSetting sus = (SharedUserSetting) obj;
+ return PackageInfoUtils.generateProcessInfo(sus.processes, 0);
+ } else if (obj instanceof PackageSetting) {
+ final PackageSetting ps = (PackageSetting) obj;
+ return PackageInfoUtils.generateProcessInfo(ps.pkg.getProcesses(), 0);
+ }
+ return null;
+ }
+
+ @GuardedBy("mLock")
+ public int[] getPermissionGidsLocked(String permissionName, int userId) {
+ BasePermission perm
+ = mPermissionManager.getPermissionSettings().getPermission(permissionName);
+ if (perm != null) {
+ return perm.computeGids(userId);
+ }
+ return null;
+ }
+
@Override
public int getRuntimePermissionsVersion(@UserIdInt int userId) {
Preconditions.checkArgumentNonnegative(userId);
diff --git a/services/core/java/com/android/server/pm/SharedUserSetting.java b/services/core/java/com/android/server/pm/SharedUserSetting.java
index 0a42ccf..b9bb9e0 100644
--- a/services/core/java/com/android/server/pm/SharedUserSetting.java
+++ b/services/core/java/com/android/server/pm/SharedUserSetting.java
@@ -19,7 +19,9 @@
import android.annotation.Nullable;
import android.content.pm.ApplicationInfo;
import android.content.pm.parsing.AndroidPackage;
+import android.content.pm.parsing.ComponentParseUtils;
import android.service.pm.PackageServiceDumpProto;
+import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.proto.ProtoOutputStream;
@@ -51,6 +53,8 @@
final PackageSignatures signatures = new PackageSignatures();
Boolean signaturesChanged;
+ ArrayMap<String, ComponentParseUtils.ParsedProcess> processes;
+
SharedUserSetting(String _name, int _pkgFlags, int _pkgPrivateFlags) {
super(_pkgFlags, _pkgPrivateFlags);
uidFlags = _pkgFlags;
@@ -72,6 +76,25 @@
proto.end(token);
}
+ void addProcesses(ArrayMap<String, ComponentParseUtils.ParsedProcess> newProcs) {
+ if (newProcs != null) {
+ final int numProcs = newProcs.size();
+ if (processes == null) {
+ processes = new ArrayMap<>(numProcs);
+ }
+ for (int i = 0; i < numProcs; i++) {
+ ComponentParseUtils.ParsedProcess newProc = newProcs.valueAt(i);
+ ComponentParseUtils.ParsedProcess proc = processes.get(newProc.name);
+ if (proc == null) {
+ proc = new ComponentParseUtils.ParsedProcess(newProc);
+ processes.put(newProc.name, proc);
+ } else {
+ proc.addStateFrom(newProc);
+ }
+ }
+ }
+ }
+
boolean removePackage(PackageSetting packageSetting) {
if (!packages.remove(packageSetting)) {
return false;
@@ -91,6 +114,8 @@
}
setPrivateFlags(aggregatedPrivateFlags);
}
+ // recalculate processes.
+ updateProcesses();
return true;
}
@@ -104,6 +129,9 @@
setFlags(this.pkgFlags | packageSetting.pkgFlags);
setPrivateFlags(this.pkgPrivateFlags | packageSetting.pkgPrivateFlags);
}
+ if (packageSetting.pkg != null) {
+ addProcesses(packageSetting.pkg.getProcesses());
+ }
}
public @Nullable List<AndroidPackage> getPackages() {
@@ -148,6 +176,16 @@
}
}
+ /**
+ * Update tracked data about processes based on all known packages in the shared user ID.
+ */
+ public void updateProcesses() {
+ processes = null;
+ for (int i = packages.size() - 1; i >= 0; i--) {
+ addProcesses(packages.valueAt(i).pkg.getProcesses());
+ }
+ }
+
/** Returns userIds which doesn't have any packages with this sharedUserId */
public int[] getNotInstalledUserIds() {
int[] excludedUserIds = null;
@@ -176,6 +214,17 @@
this.packages.clear();
this.packages.addAll(sharedUser.packages);
this.signaturesChanged = sharedUser.signaturesChanged;
+ if (sharedUser.processes != null) {
+ final int numProcs = sharedUser.processes.size();
+ this.processes = new ArrayMap<>(numProcs);
+ for (int i = 0; i < numProcs; i++) {
+ ComponentParseUtils.ParsedProcess proc =
+ new ComponentParseUtils.ParsedProcess(sharedUser.processes.valueAt(i));
+ this.processes.put(proc.name, proc);
+ }
+ } else {
+ this.processes = null;
+ }
return this;
}
}
diff --git a/services/core/java/com/android/server/policy/GlobalKeyManager.java b/services/core/java/com/android/server/policy/GlobalKeyManager.java
index e08c004..157f825 100644
--- a/services/core/java/com/android/server/policy/GlobalKeyManager.java
+++ b/services/core/java/com/android/server/policy/GlobalKeyManager.java
@@ -74,7 +74,7 @@
Intent intent = new Intent(Intent.ACTION_GLOBAL_BUTTON)
.setComponent(component)
.setFlags(Intent.FLAG_RECEIVER_FOREGROUND)
- .putExtra(Intent.EXTRA_KEY_EVENT, event);
+ .putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(event));
context.sendBroadcastAsUser(intent, UserHandle.CURRENT, null);
return true;
}
diff --git a/services/core/java/com/android/server/utils/FlagNamespaceUtils.java b/services/core/java/com/android/server/utils/FlagNamespaceUtils.java
deleted file mode 100644
index f8c7447..0000000
--- a/services/core/java/com/android/server/utils/FlagNamespaceUtils.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (C) 2019 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.server.utils;
-
-import android.annotation.Nullable;
-import android.provider.DeviceConfig;
-
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.server.RescueParty;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Utilities for interacting with the {@link android.provider.DeviceConfig}.
- *
- * @hide
- */
-public final class FlagNamespaceUtils {
- /**
- * Special String used for communicating through {@link #RESET_PLATFORM_PACKAGE_FLAG} that
- * Settings were reset by the RescueParty, no actual namespace with this name exists in
- * {@link DeviceConfig}.
- */
- public static final String NAMESPACE_NO_PACKAGE = "no_package";
-
- /**
- * Name of the special namespace in DeviceConfig table used for communicating resets.
- */
- @VisibleForTesting
- public static final String NAMESPACE_RESCUE_PARTY = "rescue_party_namespace";
- /**
- * Flag in the {@link DeviceConfig} in {@link #NAMESPACE_RESCUE_PARTY}, holding all known {@link
- * DeviceConfig} namespaces, as a {@link #DELIMITER} separated String. It's updated after the
- * first time flags are written to the new namespace in the {@link DeviceConfig}.
- */
- @VisibleForTesting
- public static final String ALL_KNOWN_NAMESPACES_FLAG = "all_known_namespaces";
- /**
- * Flag in the {@link DeviceConfig} in {@link #NAMESPACE_RESCUE_PARTY} with integer counter
- * suffix added to it, holding {@link DeviceConfig} namespace value whose flags were recently
- * reset by the {@link RescueParty}. It's updated by {@link RescueParty} every time given
- * namespace flags are reset.
- */
- @VisibleForTesting
- public static final String RESET_PLATFORM_PACKAGE_FLAG = "reset_platform_package";
- private static final String DELIMITER = ":";
- /**
- * Maximum value of the counter used in combination with {@link #RESET_PLATFORM_PACKAGE_FLAG}
- * when communicating recently reset by the RescueParty namespace values.
- */
- private static final int MAX_COUNTER_VALUE = 50;
-
- private static int sKnownResetNamespacesFlagCounter = -1;
-
- /**
- * Sets the union of {@link #RESET_PLATFORM_PACKAGE_FLAG} with
- * {@link #sKnownResetNamespacesFlagCounter} in the DeviceConfig for each namespace
- * in the consumed namespacesList. These flags are used for communicating the namespaces
- * (aka platform packages) whose flags in {@link DeviceConfig} were just reset
- * by the RescueParty.
- */
- public static void addToKnownResetNamespaces(@Nullable List<String> namespacesList) {
- if (namespacesList == null) {
- return;
- }
- for (String namespace : namespacesList) {
- addToKnownResetNamespaces(namespace);
- }
- }
-
- /**
- * Sets the union of {@link #RESET_PLATFORM_PACKAGE_FLAG} with
- * {@link #sKnownResetNamespacesFlagCounter} in the DeviceConfig for the consumed namespace.
- * This flag is used for communicating the namespace (aka platform package) whose flags
- * in {@link DeviceConfig} were just reset by the RescueParty.
- */
- public static void addToKnownResetNamespaces(String namespace) {
- int nextFlagCounter = incrementAndRetrieveResetNamespacesFlagCounter();
- DeviceConfig.setProperty(NAMESPACE_RESCUE_PARTY,
- RESET_PLATFORM_PACKAGE_FLAG + nextFlagCounter,
- namespace, /*makeDefault=*/ true);
- }
-
- /**
- * Reset all namespaces in DeviceConfig with consumed resetMode.
- */
- public static void resetDeviceConfig(int resetMode) {
- resetDeviceConfig(resetMode, getAllKnownDeviceConfigNamespacesList());
- }
-
- /**
- * Reset all consumed namespaces in DeviceConfig with consumed resetMode.
- */
- public static void resetDeviceConfig(int resetMode, List<String> namespacesList) {
- for (String namespace : namespacesList) {
- DeviceConfig.resetToDefaults(resetMode, namespace);
- }
- addToKnownResetNamespaces(namespacesList);
- }
-
- /**
- * Resets known reset namespaces flag counter for tests only.
- */
- @VisibleForTesting
- public static void resetKnownResetNamespacesFlagCounterForTest() {
- sKnownResetNamespacesFlagCounter = -1;
- }
-
- /**
- * Returns a list of all known DeviceConfig namespaces, except for the special {@link
- * #NAMESPACE_RESCUE_PARTY}
- */
- private static List<String> getAllKnownDeviceConfigNamespacesList() {
- String namespacesStr = DeviceConfig.getProperty(NAMESPACE_RESCUE_PARTY,
- ALL_KNOWN_NAMESPACES_FLAG);
- List<String> namespacesList = toStringList(namespacesStr);
- namespacesList.remove(NAMESPACE_RESCUE_PARTY);
- return namespacesList;
- }
-
- private static List<String> toStringList(String serialized) {
- if (serialized == null || serialized.length() == 0) {
- return new ArrayList<>();
- }
- return Arrays.asList(serialized.split(DELIMITER));
- }
-
- private static int incrementAndRetrieveResetNamespacesFlagCounter() {
- sKnownResetNamespacesFlagCounter++;
- if (sKnownResetNamespacesFlagCounter == MAX_COUNTER_VALUE) {
- sKnownResetNamespacesFlagCounter = 0;
- }
- return sKnownResetNamespacesFlagCounter;
- }
-}
diff --git a/services/core/xsd/display-device-config/display-device-config.xsd b/services/core/xsd/display-device-config/display-device-config.xsd
index c26629d..5c7f305 100644
--- a/services/core/xsd/display-device-config/display-device-config.xsd
+++ b/services/core/xsd/display-device-config/display-device-config.xsd
@@ -35,6 +35,7 @@
<xs:complexType name="nitsMap">
<xs:sequence>
<xs:element name="point" type="point" maxOccurs="unbounded" minOccurs="2"/>
+ <xs:element name="highBrightnessStart" minOccurs="0" type="nonNegativeDecimal"/>
</xs:sequence>
</xs:complexType>
diff --git a/services/core/xsd/display-device-config/schema/current.txt b/services/core/xsd/display-device-config/schema/current.txt
index e2b1b9b..5a9c945 100644
--- a/services/core/xsd/display-device-config/schema/current.txt
+++ b/services/core/xsd/display-device-config/schema/current.txt
@@ -9,7 +9,9 @@
public class NitsMap {
ctor public NitsMap();
+ method public java.math.BigDecimal getHighBrightnessStart();
method public java.util.List<com.android.server.display.config.Point> getPoint();
+ method public void setHighBrightnessStart(java.math.BigDecimal);
}
public class Point {
diff --git a/services/tests/mockingservicestests/AndroidManifest.xml b/services/tests/mockingservicestests/AndroidManifest.xml
index b3b5af0..0e24b03 100644
--- a/services/tests/mockingservicestests/AndroidManifest.xml
+++ b/services/tests/mockingservicestests/AndroidManifest.xml
@@ -21,6 +21,7 @@
<uses-permission android:name="android.permission.HARDWARE_TEST"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.MANAGE_APPOPS"/>
+ <uses-permission android:name="android.permission.MONITOR_DEVICE_CONFIG_ACCESS"/>
<application android:testOnly="true"
android:debuggable="true">
diff --git a/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java b/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java
index c3602f8..2080fdf 100644
--- a/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java
@@ -30,11 +30,14 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.times;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.VersionedPackage;
+import android.os.Bundle;
import android.os.RecoverySystem;
+import android.os.RemoteCallback;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.DeviceConfig;
@@ -44,18 +47,21 @@
import com.android.server.PackageWatchdog.PackageHealthObserverImpact;
import com.android.server.RescueParty.RescuePartyObserver;
import com.android.server.am.SettingsToPropertiesMapper;
-import com.android.server.utils.FlagNamespaceUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoSession;
import org.mockito.quality.Strictness;
import org.mockito.stubbing.Answer;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
/**
* Test RescueParty.
@@ -69,16 +75,25 @@
private static VersionedPackage sFailingPackage = new VersionedPackage("com.package.name", 1);
private static final String PROP_DISABLE_RESCUE = "persist.sys.disable_rescue";
+ private static final String CALLING_PACKAGE1 = "com.package.name1";
+ private static final String CALLING_PACKAGE2 = "com.package.name2";
+ private static final String NAMESPACE1 = "namespace1";
+ private static final String NAMESPACE2 = "namespace2";
private MockitoSession mSession;
+ private HashMap<String, String> mSystemSettingsMap;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mMockContext;
-
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PackageWatchdog mMockPackageWatchdog;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ContentResolver mMockContentResolver;
- private HashMap<String, String> mSystemSettingsMap;
+ @Captor
+ private ArgumentCaptor<RemoteCallback> mMonitorCallbackCaptor;
+ @Captor
+ private ArgumentCaptor<List<String>> mPackageListCaptor;
@Before
public void setUp() throws Exception {
@@ -90,14 +105,17 @@
.spyStatic(SystemProperties.class)
.spyStatic(Settings.Global.class)
.spyStatic(Settings.Secure.class)
+ .spyStatic(Settings.Config.class)
.spyStatic(SettingsToPropertiesMapper.class)
.spyStatic(RecoverySystem.class)
.spyStatic(RescueParty.class)
+ .spyStatic(PackageWatchdog.class)
.startMocking();
mSystemSettingsMap = new HashMap<>();
when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver);
-
+ // Reset observer instance to get new mock context on every run
+ RescuePartyObserver.reset();
// Mock SystemProperties setter and various getters
doAnswer((Answer<Void>) invocationOnMock -> {
@@ -143,9 +161,11 @@
doAnswer((Answer<Void>) invocationOnMock -> null)
.when(() -> DeviceConfig.resetToDefaults(anyInt(), anyString()));
+ // Mock PackageWatchdog
+ doAnswer((Answer<PackageWatchdog>) invocationOnMock -> mMockPackageWatchdog)
+ .when(() -> PackageWatchdog.getInstance(mMockContext));
doReturn(CURRENT_NETWORK_TIME_MILLIS).when(() -> RescueParty.getElapsedRealtime());
- FlagNamespaceUtils.resetKnownResetNamespacesFlagCounterForTest();
SystemProperties.set(RescueParty.PROP_RESCUE_LEVEL,
Integer.toString(RescueParty.LEVEL_NONE));
@@ -162,19 +182,19 @@
public void testBootLoopDetectionWithExecutionForAllRescueLevels() {
noteBoot();
- verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS);
+ verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS, /*resetNamespaces=*/ null);
assertEquals(RescueParty.LEVEL_RESET_SETTINGS_UNTRUSTED_DEFAULTS,
SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
noteBoot();
- verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_CHANGES);
+ verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_CHANGES, /*resetNamespaces=*/ null);
assertEquals(RescueParty.LEVEL_RESET_SETTINGS_UNTRUSTED_CHANGES,
SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
noteBoot();
- verifySettingsResets(Settings.RESET_MODE_TRUSTED_DEFAULTS);
+ verifySettingsResets(Settings.RESET_MODE_TRUSTED_DEFAULTS, /*resetNamespaces=*/ null);
assertEquals(RescueParty.LEVEL_RESET_SETTINGS_TRUSTED_DEFAULTS,
SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
@@ -189,19 +209,19 @@
public void testPersistentAppCrashDetectionWithExecutionForAllRescueLevels() {
notePersistentAppCrash();
- verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS);
+ verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS, /*resetNamespaces=*/ null);
assertEquals(RescueParty.LEVEL_RESET_SETTINGS_UNTRUSTED_DEFAULTS,
SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
notePersistentAppCrash();
- verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_CHANGES);
+ verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_CHANGES, /*resetNamespaces=*/ null);
assertEquals(RescueParty.LEVEL_RESET_SETTINGS_UNTRUSTED_CHANGES,
SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
notePersistentAppCrash();
- verifySettingsResets(Settings.RESET_MODE_TRUSTED_DEFAULTS);
+ verifySettingsResets(Settings.RESET_MODE_TRUSTED_DEFAULTS, /*resetNamespaces=*/ null);
assertEquals(RescueParty.LEVEL_RESET_SETTINGS_TRUSTED_DEFAULTS,
SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
@@ -213,6 +233,54 @@
}
@Test
+ public void testNonPersistentAppCrashDetectionWithScopedResets() {
+ RescueParty.onSettingsProviderPublished(mMockContext);
+ verify(() -> Settings.Config.registerMonitorCallback(eq(mMockContentResolver),
+ mMonitorCallbackCaptor.capture()));
+
+ // Record DeviceConfig accesses
+ RescuePartyObserver observer = RescuePartyObserver.getInstance(mMockContext);
+ RemoteCallback monitorCallback = mMonitorCallbackCaptor.getValue();
+ monitorCallback.sendResult(getConfigAccessBundle(CALLING_PACKAGE1, NAMESPACE1));
+ monitorCallback.sendResult(getConfigAccessBundle(CALLING_PACKAGE1, NAMESPACE2));
+ monitorCallback.sendResult(getConfigAccessBundle(CALLING_PACKAGE2, NAMESPACE2));
+ // Fake DeviceConfig value changes
+ monitorCallback.sendResult(getConfigNamespaceUpdateBundle(NAMESPACE1));
+ verify(mMockPackageWatchdog).startObservingHealth(observer,
+ Arrays.asList(CALLING_PACKAGE1), RescueParty.DEFAULT_OBSERVING_DURATION_MS);
+ monitorCallback.sendResult(getConfigNamespaceUpdateBundle(NAMESPACE2));
+ verify(mMockPackageWatchdog, times(2)).startObservingHealth(eq(observer),
+ mPackageListCaptor.capture(),
+ eq(RescueParty.DEFAULT_OBSERVING_DURATION_MS));
+ assertTrue(mPackageListCaptor.getValue().containsAll(
+ Arrays.asList(CALLING_PACKAGE1, CALLING_PACKAGE2)));
+ // Perform and verify scoped resets
+ final String[] expectedResetNamespaces = new String[]{NAMESPACE1, NAMESPACE2};
+ observer.execute(new VersionedPackage(
+ CALLING_PACKAGE1, 1), PackageWatchdog.FAILURE_REASON_APP_CRASH);
+ verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS, expectedResetNamespaces);
+ assertEquals(RescueParty.LEVEL_RESET_SETTINGS_UNTRUSTED_DEFAULTS,
+ SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
+
+ observer.execute(new VersionedPackage(
+ CALLING_PACKAGE1, 1), PackageWatchdog.FAILURE_REASON_APP_NOT_RESPONDING);
+ verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_CHANGES, expectedResetNamespaces);
+ assertEquals(RescueParty.LEVEL_RESET_SETTINGS_UNTRUSTED_CHANGES,
+ SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
+
+ observer.execute(new VersionedPackage(
+ CALLING_PACKAGE1, 1), PackageWatchdog.FAILURE_REASON_APP_NOT_RESPONDING);
+ verifySettingsResets(Settings.RESET_MODE_TRUSTED_DEFAULTS, /*resetNamespaces=*/null);
+ assertEquals(RescueParty.LEVEL_RESET_SETTINGS_TRUSTED_DEFAULTS,
+ SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
+
+ observer.execute(new VersionedPackage(
+ CALLING_PACKAGE1, 1), PackageWatchdog.FAILURE_REASON_APP_CRASH);
+ verify(() -> RecoverySystem.rebootPromptAndWipeUserData(mMockContext, RescueParty.TAG));
+ assertTrue(RescueParty.isAttemptingFactoryReset());
+ }
+
+ @Test
public void testIsAttemptingFactoryReset() {
for (int i = 0; i < LEVEL_FACTORY_RESET; i++) {
noteBoot();
@@ -227,7 +295,7 @@
RescueParty.onSettingsProviderPublished(mMockContext);
- verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS);
+ verifySettingsResets(Settings.RESET_MODE_UNTRUSTED_DEFAULTS, /*resetNamespaces=*/ null);
assertEquals(RescueParty.LEVEL_RESET_SETTINGS_UNTRUSTED_DEFAULTS,
SystemProperties.getInt(RescueParty.PROP_RESCUE_LEVEL, RescueParty.LEVEL_NONE));
}
@@ -244,15 +312,6 @@
FAKE_NATIVE_NAMESPACE1));
verify(() -> DeviceConfig.resetToDefaults(Settings.RESET_MODE_TRUSTED_DEFAULTS,
FAKE_NATIVE_NAMESPACE2));
-
- ExtendedMockito.verify(
- () -> DeviceConfig.setProperty(FlagNamespaceUtils.NAMESPACE_RESCUE_PARTY,
- FlagNamespaceUtils.RESET_PLATFORM_PACKAGE_FLAG + 0,
- FAKE_NATIVE_NAMESPACE1, /*makeDefault=*/true));
- ExtendedMockito.verify(
- () -> DeviceConfig.setProperty(FlagNamespaceUtils.NAMESPACE_RESCUE_PARTY,
- FlagNamespaceUtils.RESET_PLATFORM_PACKAGE_FLAG + 1,
- FAKE_NATIVE_NAMESPACE2, /*makeDefault=*/true));
}
@Test
@@ -326,11 +385,19 @@
RescueParty.LEVEL_RESET_SETTINGS_UNTRUSTED_DEFAULTS);
}
- private void verifySettingsResets(int resetMode) {
+ private void verifySettingsResets(int resetMode, String[] resetNamespaces) {
verify(() -> Settings.Global.resetToDefaultsAsUser(mMockContentResolver, null,
resetMode, UserHandle.USER_SYSTEM));
verify(() -> Settings.Secure.resetToDefaultsAsUser(eq(mMockContentResolver), isNull(),
eq(resetMode), anyInt()));
+ // Verify DeviceConfig resets
+ if (resetNamespaces == null) {
+ verify(() -> DeviceConfig.resetToDefaults(resetMode, /*namespace=*/ null));
+ } else {
+ for (String namespace : resetNamespaces) {
+ verify(() -> DeviceConfig.resetToDefaults(resetMode, namespace));
+ }
+ }
}
private void noteBoot() {
@@ -339,6 +406,22 @@
private void notePersistentAppCrash() {
RescuePartyObserver.getInstance(mMockContext).execute(new VersionedPackage(
- "com.package.name", 1), PackageWatchdog.FAILURE_REASON_UNKNOWN);
+ "com.package.name", 1), PackageWatchdog.FAILURE_REASON_APP_CRASH);
+ }
+
+ private Bundle getConfigAccessBundle(String callingPackage, String namespace) {
+ Bundle result = new Bundle();
+ result.putString(Settings.EXTRA_MONITOR_CALLBACK_TYPE, Settings.EXTRA_ACCESS_CALLBACK);
+ result.putString(Settings.EXTRA_CALLING_PACKAGE, callingPackage);
+ result.putString(Settings.EXTRA_NAMESPACE, namespace);
+ return result;
+ }
+
+ private Bundle getConfigNamespaceUpdateBundle(String updatedNamespace) {
+ Bundle result = new Bundle();
+ result.putString(Settings.EXTRA_MONITOR_CALLBACK_TYPE,
+ Settings.EXTRA_NAMESPACE_UPDATED_CALLBACK);
+ result.putString(Settings.EXTRA_NAMESPACE, updatedNamespace);
+ return result;
}
}
diff --git a/services/tests/servicestests/src/com/android/server/net/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/net/NetworkPolicyManagerServiceTest.java
index 355cada..a1baf0e 100644
--- a/services/tests/servicestests/src/com/android/server/net/NetworkPolicyManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/net/NetworkPolicyManagerServiceTest.java
@@ -138,6 +138,7 @@
import android.util.RecurrenceRule;
import androidx.test.InstrumentationRegistry;
+import androidx.test.filters.FlakyTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.test.BroadcastInterceptingContext;
@@ -1055,6 +1056,7 @@
computeLastCycleBoundary(parseTime("2013-01-14T15:11:00.000-08:00"), policy));
}
+ @FlakyTest
@Test
public void testNetworkPolicyAppliedCycleLastMonth() throws Exception {
NetworkState[] state = null;
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
index c58b6da..af81ab6 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
@@ -46,18 +46,21 @@
private static final String NAME = "sound_model.db";
private static final int VERSION = 7;
- public static interface SoundModelContract {
- public static final String TABLE = "sound_model";
- public static final String KEY_MODEL_UUID = "model_uuid";
- public static final String KEY_VENDOR_UUID = "vendor_uuid";
- public static final String KEY_KEYPHRASE_ID = "keyphrase_id";
- public static final String KEY_TYPE = "type";
- public static final String KEY_DATA = "data";
- public static final String KEY_RECOGNITION_MODES = "recognition_modes";
- public static final String KEY_LOCALE = "locale";
- public static final String KEY_HINT_TEXT = "hint_text";
- public static final String KEY_USERS = "users";
- public static final String KEY_MODEL_VERSION = "model_version";
+ /**
+ * Keyphrase sound model database columns
+ */
+ public interface SoundModelContract {
+ String TABLE = "sound_model";
+ String KEY_MODEL_UUID = "model_uuid";
+ String KEY_VENDOR_UUID = "vendor_uuid";
+ String KEY_KEYPHRASE_ID = "keyphrase_id";
+ String KEY_TYPE = "type";
+ String KEY_DATA = "data";
+ String KEY_RECOGNITION_MODES = "recognition_modes";
+ String KEY_LOCALE = "locale";
+ String KEY_HINT_TEXT = "hint_text";
+ String KEY_USERS = "users";
+ String KEY_MODEL_VERSION = "model_version";
}
// Table Create Statement
@@ -173,7 +176,8 @@
soundModel.keyphrases[0].recognitionModes);
values.put(SoundModelContract.KEY_USERS,
getCommaSeparatedString(soundModel.keyphrases[0].users));
- values.put(SoundModelContract.KEY_LOCALE, soundModel.keyphrases[0].locale);
+ values.put(SoundModelContract.KEY_LOCALE,
+ soundModel.keyphrases[0].locale.toLanguageTag());
values.put(SoundModelContract.KEY_HINT_TEXT, soundModel.keyphrases[0].text);
try {
return db.insertWithOnConflict(SoundModelContract.TABLE, null, values,
@@ -190,7 +194,7 @@
* Deletes the sound model and associated keyphrases.
*/
public boolean deleteKeyphraseSoundModel(int keyphraseId, int userHandle, String bcp47Locale) {
- // Sanitize the locale to guard against SQL injection.
+ // Normalize the locale to guard against SQL injection.
bcp47Locale = Locale.forLanguageTag(bcp47Locale).toLanguageTag();
synchronized(this) {
KeyphraseSoundModel soundModel = getKeyphraseSoundModel(keyphraseId, userHandle,
@@ -226,92 +230,119 @@
String selectQuery = "SELECT * FROM " + SoundModelContract.TABLE
+ " WHERE " + SoundModelContract.KEY_KEYPHRASE_ID + "= '" + keyphraseId
+ "' AND " + SoundModelContract.KEY_LOCALE + "='" + bcp47Locale + "'";
- SQLiteDatabase db = getReadableDatabase();
- Cursor c = db.rawQuery(selectQuery, null);
-
- try {
- if (c.moveToFirst()) {
- do {
- int type = c.getInt(c.getColumnIndex(SoundModelContract.KEY_TYPE));
- if (type != SoundTrigger.SoundModel.TYPE_KEYPHRASE) {
- if (DBG) {
- Slog.w(TAG, "Ignoring SoundModel since it's type is incorrect");
- }
- continue;
- }
-
- String modelUuid = c.getString(
- c.getColumnIndex(SoundModelContract.KEY_MODEL_UUID));
- if (modelUuid == null) {
- Slog.w(TAG, "Ignoring SoundModel since it doesn't specify an ID");
- continue;
- }
-
- String vendorUuidString = null;
- int vendorUuidColumn = c.getColumnIndex(SoundModelContract.KEY_VENDOR_UUID);
- if (vendorUuidColumn != -1) {
- vendorUuidString = c.getString(vendorUuidColumn);
- }
- byte[] data = c.getBlob(c.getColumnIndex(SoundModelContract.KEY_DATA));
- int recognitionModes = c.getInt(
- c.getColumnIndex(SoundModelContract.KEY_RECOGNITION_MODES));
- int[] users = getArrayForCommaSeparatedString(
- c.getString(c.getColumnIndex(SoundModelContract.KEY_USERS)));
- String modelLocale = c.getString(
- c.getColumnIndex(SoundModelContract.KEY_LOCALE));
- String text = c.getString(
- c.getColumnIndex(SoundModelContract.KEY_HINT_TEXT));
- int version = c.getInt(
- c.getColumnIndex(SoundModelContract.KEY_MODEL_VERSION));
-
- // Only add keyphrases meant for the current user.
- if (users == null) {
- // No users present in the keyphrase.
- Slog.w(TAG, "Ignoring SoundModel since it doesn't specify users");
- continue;
- }
-
- boolean isAvailableForCurrentUser = false;
- for (int user : users) {
- if (userHandle == user) {
- isAvailableForCurrentUser = true;
- break;
- }
- }
- if (!isAvailableForCurrentUser) {
- if (DBG) {
- Slog.w(TAG, "Ignoring SoundModel since user handles don't match");
- }
- continue;
- } else {
- if (DBG) Slog.d(TAG, "Found a SoundModel for user: " + userHandle);
- }
-
- Keyphrase[] keyphrases = new Keyphrase[1];
- keyphrases[0] = new Keyphrase(
- keyphraseId, recognitionModes, modelLocale, text, users);
- UUID vendorUuid = null;
- if (vendorUuidString != null) {
- vendorUuid = UUID.fromString(vendorUuidString);
- }
- KeyphraseSoundModel model = new KeyphraseSoundModel(
- UUID.fromString(modelUuid), vendorUuid, data, keyphrases, version);
- if (DBG) {
- Slog.d(TAG, "Found SoundModel for the given keyphrase/locale/user: "
- + model);
- }
- return model;
- } while (c.moveToNext());
- }
- Slog.w(TAG, "No SoundModel available for the given keyphrase");
- } finally {
- c.close();
- db.close();
- }
- return null;
+ return getValidKeyphraseSoundModelForUser(selectQuery, userHandle);
}
}
+ /**
+ * Returns a matching {@link KeyphraseSoundModel} for the keyphrase string.
+ * Returns null if a match isn't found.
+ *
+ * TODO: We only support one keyphrase currently.
+ */
+ public KeyphraseSoundModel getKeyphraseSoundModel(String keyphrase, int userHandle,
+ String bcp47Locale) {
+ // Sanitize the locale to guard against SQL injection.
+ bcp47Locale = Locale.forLanguageTag(bcp47Locale).toLanguageTag();
+ synchronized (this) {
+ // Find the corresponding sound model ID for the keyphrase.
+ String selectQuery = "SELECT * FROM " + SoundModelContract.TABLE
+ + " WHERE " + SoundModelContract.KEY_HINT_TEXT + "= '" + keyphrase
+ + "' AND " + SoundModelContract.KEY_LOCALE + "='" + bcp47Locale + "'";
+ return getValidKeyphraseSoundModelForUser(selectQuery, userHandle);
+ }
+ }
+
+ private KeyphraseSoundModel getValidKeyphraseSoundModelForUser(String selectQuery,
+ int userHandle) {
+ SQLiteDatabase db = getReadableDatabase();
+ Cursor c = db.rawQuery(selectQuery, null);
+
+ try {
+ if (c.moveToFirst()) {
+ do {
+ int type = c.getInt(c.getColumnIndex(SoundModelContract.KEY_TYPE));
+ if (type != SoundTrigger.SoundModel.TYPE_KEYPHRASE) {
+ if (DBG) {
+ Slog.w(TAG, "Ignoring SoundModel since its type is incorrect");
+ }
+ continue;
+ }
+
+ String modelUuid = c.getString(
+ c.getColumnIndex(SoundModelContract.KEY_MODEL_UUID));
+ if (modelUuid == null) {
+ Slog.w(TAG, "Ignoring SoundModel since it doesn't specify an ID");
+ continue;
+ }
+
+ String vendorUuidString = null;
+ int vendorUuidColumn = c.getColumnIndex(SoundModelContract.KEY_VENDOR_UUID);
+ if (vendorUuidColumn != -1) {
+ vendorUuidString = c.getString(vendorUuidColumn);
+ }
+ int keyphraseId = c.getInt(
+ c.getColumnIndex(SoundModelContract.KEY_KEYPHRASE_ID));
+ byte[] data = c.getBlob(c.getColumnIndex(SoundModelContract.KEY_DATA));
+ int recognitionModes = c.getInt(
+ c.getColumnIndex(SoundModelContract.KEY_RECOGNITION_MODES));
+ int[] users = getArrayForCommaSeparatedString(
+ c.getString(c.getColumnIndex(SoundModelContract.KEY_USERS)));
+ Locale modelLocale = Locale.forLanguageTag(c.getString(
+ c.getColumnIndex(SoundModelContract.KEY_LOCALE)));
+ String text = c.getString(
+ c.getColumnIndex(SoundModelContract.KEY_HINT_TEXT));
+ int version = c.getInt(
+ c.getColumnIndex(SoundModelContract.KEY_MODEL_VERSION));
+
+ // Only add keyphrases meant for the current user.
+ if (users == null) {
+ // No users present in the keyphrase.
+ Slog.w(TAG, "Ignoring SoundModel since it doesn't specify users");
+ continue;
+ }
+
+ boolean isAvailableForCurrentUser = false;
+ for (int user : users) {
+ if (userHandle == user) {
+ isAvailableForCurrentUser = true;
+ break;
+ }
+ }
+ if (!isAvailableForCurrentUser) {
+ if (DBG) {
+ Slog.w(TAG, "Ignoring SoundModel since user handles don't match");
+ }
+ continue;
+ } else {
+ if (DBG) Slog.d(TAG, "Found a SoundModel for user: " + userHandle);
+ }
+
+ Keyphrase[] keyphrases = new Keyphrase[1];
+ keyphrases[0] = new Keyphrase(
+ keyphraseId, recognitionModes, modelLocale, text, users);
+ UUID vendorUuid = null;
+ if (vendorUuidString != null) {
+ vendorUuid = UUID.fromString(vendorUuidString);
+ }
+ KeyphraseSoundModel model = new KeyphraseSoundModel(
+ UUID.fromString(modelUuid), vendorUuid, data, keyphrases, version);
+ if (DBG) {
+ Slog.d(TAG, "Found SoundModel for the given keyphrase/locale/user: "
+ + model);
+ }
+ return model;
+ } while (c.moveToNext());
+ }
+ Slog.w(TAG, "No SoundModel available for the given keyphrase");
+ } finally {
+ c.close();
+ db.close();
+ }
+
+ return null;
+ }
+
private static String getCommaSeparatedString(int[] users) {
if (users == null) {
return "";
@@ -431,8 +462,11 @@
}
}
+ /**
+ * Dumps contents of database for dumpsys
+ */
public void dump(PrintWriter pw) {
- synchronized(this) {
+ synchronized (this) {
String selectQuery = "SELECT * FROM " + SoundModelContract.TABLE;
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
index 506c67e..d5eec33 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
@@ -41,7 +41,9 @@
import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.soundtrigger.IRecognitionStatusCallback;
+import android.hardware.soundtrigger.KeyphraseMetadata;
import android.hardware.soundtrigger.ModelParams;
+import android.hardware.soundtrigger.SoundTrigger;
import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel;
import android.hardware.soundtrigger.SoundTrigger.ModelParamRange;
import android.hardware.soundtrigger.SoundTrigger.ModuleProperties;
@@ -90,6 +92,7 @@
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.List;
+import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.Executor;
@@ -923,6 +926,8 @@
}
//----------------- Model management APIs --------------------------------//
+ // TODO: add check to only allow active voice interaction service or keyphrase enrollment
+ // application to manage voice models
@Override
public KeyphraseSoundModel getKeyphraseSoundModel(int keyphraseId, String bcp47Locale) {
@@ -1022,6 +1027,41 @@
}
}
+ @Nullable
+ public KeyphraseMetadata getEnrolledKeyphraseMetadata(IVoiceInteractionService service,
+ String keyphrase, String bcp47Locale) {
+ synchronized (this) {
+ enforceIsCurrentVoiceInteractionService(service);
+ }
+
+ if (bcp47Locale == null) {
+ throw new IllegalArgumentException("Illegal argument(s) in isEnrolledForKeyphrase");
+ }
+
+ final int callingUid = UserHandle.getCallingUserId();
+ final long caller = Binder.clearCallingIdentity();
+ try {
+ KeyphraseSoundModel model =
+ mDbHelper.getKeyphraseSoundModel(keyphrase, callingUid, bcp47Locale);
+ if (model == null) {
+ return null;
+ }
+
+ for (SoundTrigger.Keyphrase phrase : model.keyphrases) {
+ if (keyphrase.equals(phrase.text)) {
+ ArraySet<Locale> locales = new ArraySet<>();
+ locales.add(phrase.locale);
+ return new KeyphraseMetadata(phrase.id, phrase.text, locales,
+ phrase.recognitionModes);
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(caller);
+ }
+
+ return null;
+ }
+
@Override
public ModuleProperties getDspModuleProperties(IVoiceInteractionService service) {
// Allow the call if this is the current voice interaction service.
diff --git a/telephony/common/com/android/internal/telephony/SmsApplication.java b/telephony/common/com/android/internal/telephony/SmsApplication.java
index 9b82828..ffb3cb1 100644
--- a/telephony/common/com/android/internal/telephony/SmsApplication.java
+++ b/telephony/common/com/android/internal/telephony/SmsApplication.java
@@ -205,7 +205,7 @@
< android.os.Process.FIRST_APPLICATION_UID) {
return contextUserId;
} else {
- return UserHandle.getUserId(callingUid);
+ return UserHandle.getUserHandleForUid(callingUid).getIdentifier();
}
}
@@ -811,10 +811,10 @@
// This should never happen in prod -- unit tests will put the receiver into a
// unusual state where the pending result is null, which produces a NPE when calling
// getSendingUserId. Just pretend like it's the system user for testing.
- userId = UserHandle.USER_SYSTEM;
+ userId = UserHandle.SYSTEM.getIdentifier();
}
Context userContext = mContext;
- if (userId != UserHandle.USER_SYSTEM) {
+ if (userId != UserHandle.SYSTEM.getIdentifier()) {
try {
userContext = mContext.createPackageContextAsUser(mContext.getPackageName(), 0,
UserHandle.of(userId));
diff --git a/telephony/java/android/service/euicc/EuiccService.java b/telephony/java/android/service/euicc/EuiccService.java
index ef11f46..9315586 100644
--- a/telephony/java/android/service/euicc/EuiccService.java
+++ b/telephony/java/android/service/euicc/EuiccService.java
@@ -31,7 +31,9 @@
import android.telephony.TelephonyManager;
import android.telephony.euicc.DownloadableSubscription;
import android.telephony.euicc.EuiccInfo;
+import android.telephony.euicc.EuiccManager;
import android.telephony.euicc.EuiccManager.OtaStatus;
+import android.text.TextUtils;
import android.util.Log;
import java.io.PrintWriter;
@@ -311,6 +313,65 @@
mStubWrapper = new IEuiccServiceWrapper();
}
+ /**
+ * Given a SubjectCode[5.2.6.1] and ReasonCode[5.2.6.2] from GSMA (SGP.22 v2.2), encode it to
+ * the format described in
+ * {@link android.telephony.euicc.EuiccManager#OPERATION_SMDX_SUBJECT_REASON_CODE}
+ *
+ * @param subjectCode SubjectCode[5.2.6.1] from GSMA (SGP.22 v2.2)
+ * @param reasonCode ReasonCode[5.2.6.2] from GSMA (SGP.22 v2.2)
+ * @return encoded error code described in
+ * {@link android.telephony.euicc.EuiccManager#OPERATION_SMDX_SUBJECT_REASON_CODE}
+ * @throws NumberFormatException when the Subject/Reason code contains non digits
+ * @throws IllegalArgumentException when Subject/Reason code is null/empty
+ * @throws UnsupportedOperationException when sections has more than four layers (e.g 5.8.1.2)
+ * or when an number is bigger than 15
+ */
+ public int encodeSmdxSubjectAndReasonCode(@Nullable String subjectCode,
+ @Nullable String reasonCode)
+ throws NumberFormatException, IllegalArgumentException, UnsupportedOperationException {
+ final int maxSupportedSection = 3;
+ final int maxSupportedDigit = 15;
+ final int bitsPerSection = 4;
+
+ if (TextUtils.isEmpty(subjectCode) || TextUtils.isEmpty(reasonCode)) {
+ throw new IllegalArgumentException("SubjectCode/ReasonCode is empty");
+ }
+
+ final String[] subjectCodeToken = subjectCode.split("\\.");
+ final String[] reasonCodeToken = reasonCode.split("\\.");
+
+ if (subjectCodeToken.length > maxSupportedSection
+ || reasonCodeToken.length > maxSupportedSection) {
+ throw new UnsupportedOperationException("Only three nested layer is supported.");
+ }
+
+ int result = EuiccManager.OPERATION_SMDX_SUBJECT_REASON_CODE;
+
+ // Pad the 0s needed for subject code
+ result = result << (maxSupportedSection - subjectCodeToken.length) * bitsPerSection;
+
+ for (String digitString : subjectCodeToken) {
+ int num = Integer.parseInt(digitString);
+ if (num > maxSupportedDigit) {
+ throw new UnsupportedOperationException("SubjectCode exceeds " + maxSupportedDigit);
+ }
+ result = (result << bitsPerSection) + num;
+ }
+
+ // Pad the 0s needed for reason code
+ result = result << (maxSupportedSection - reasonCodeToken.length) * bitsPerSection;
+ for (String digitString : reasonCodeToken) {
+ int num = Integer.parseInt(digitString);
+ if (num > maxSupportedDigit) {
+ throw new UnsupportedOperationException("ReasonCode exceeds " + maxSupportedDigit);
+ }
+ result = (result << bitsPerSection) + num;
+ }
+
+ return result;
+ }
+
@Override
@CallSuper
public void onCreate() {
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index 822e55b..b30f586 100755
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -1454,6 +1454,50 @@
"apn_settings_default_apn_types_string_array";
/**
+ * Configs used for APN setup.
+ */
+ public static final class Apn {
+ /** Prefix of all Apn.KEY_* constants. */
+ public static final String KEY_PREFIX = "apn.";
+
+ /** IPv4 internet protocol */
+ public static final String PROTOCOL_IPV4 = "IP";
+ /** IPv6 internet protocol */
+ public static final String PROTOCOL_IPV6 = "IPV6";
+ /** IPv4 or IPv6 internet protocol */
+ public static final String PROTOCOL_IPV4V6 = "IPV4V6";
+
+ /**
+ * Default value of APN protocol field if not specified by user when adding/modifying
+ * an APN.
+ *
+ * Available options are: {@link #PROTOCOL_IPV4}, {@link #PROTOCOL_IPV6},
+ * {@link #PROTOCOL_IPV4V6}
+ */
+ public static final String KEY_SETTINGS_DEFAULT_PROTOCOL_STRING =
+ KEY_PREFIX + "settings_default_protocol_string";
+
+ /**
+ * Default value of APN roaming protocol field if not specified by user when
+ * adding/modifying an APN.
+ *
+ * Available options are: {@link #PROTOCOL_IPV4}, {@link #PROTOCOL_IPV6},
+ * {@link #PROTOCOL_IPV4V6}
+ */
+ public static final String KEY_SETTINGS_DEFAULT_ROAMING_PROTOCOL_STRING =
+ KEY_PREFIX + "settings_default_roaming_protocol_string";
+
+ private Apn() {}
+
+ private static PersistableBundle getDefaults() {
+ PersistableBundle defaults = new PersistableBundle();
+ defaults.putString(KEY_SETTINGS_DEFAULT_PROTOCOL_STRING, "");
+ defaults.putString(KEY_SETTINGS_DEFAULT_ROAMING_PROTOCOL_STRING, "");
+ return defaults;
+ }
+ }
+
+ /**
* Boolean indicating if intent for emergency call state changes should be broadcast
* @hide
*/
@@ -3420,6 +3464,14 @@
"prevent_clir_activation_and_deactivation_code_bool";
/**
+ * Flag specifying whether to show forwarded number on call-in-progress screen.
+ * When true, forwarded number is shown.
+ * When false, forwarded number is not shown.
+ */
+ public static final String KEY_SHOW_FORWARDED_NUMBER_BOOL =
+ "show_forwarded_number_bool";
+
+ /**
* Configs used for epdg tunnel bring up.
*
* @see <a href="https://tools.ietf.org/html/rfc7296">RFC 7296, Internet Key Exchange
@@ -3903,6 +3955,8 @@
sDefaults.putStringArray(KEY_READ_ONLY_APN_TYPES_STRING_ARRAY, new String[] {"dun"});
sDefaults.putStringArray(KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY, null);
sDefaults.putStringArray(KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY, null);
+ sDefaults.putAll(Apn.getDefaults());
+
sDefaults.putBoolean(KEY_BROADCAST_EMERGENCY_CALL_STATE_CHANGES_BOOL, false);
sDefaults.putBoolean(KEY_ALWAYS_SHOW_EMERGENCY_ALERT_ONOFF_BOOL, false);
sDefaults.putStringArray(KEY_CARRIER_DATA_CALL_RETRY_CONFIG_STRINGS, new String[]{
@@ -4274,6 +4328,7 @@
// Default wifi configurations.
sDefaults.putAll(Wifi.getDefaults());
sDefaults.putBoolean(ENABLE_EAP_METHOD_PREFIX_BOOL, false);
+ sDefaults.putBoolean(KEY_SHOW_FORWARDED_NUMBER_BOOL, false);
sDefaults.putAll(Iwlan.getDefaults());
}
diff --git a/telephony/java/android/telephony/CellIdentityLte.java b/telephony/java/android/telephony/CellIdentityLte.java
index 560c895..cf8fe6a 100644
--- a/telephony/java/android/telephony/CellIdentityLte.java
+++ b/telephony/java/android/telephony/CellIdentityLte.java
@@ -209,6 +209,19 @@
}
/**
+ * Get bands of the cell
+ *
+ * Reference: 3GPP TS 36.101 section 5.5
+ *
+ * @return List of band number or empty list if not available.
+ */
+ @NonNull
+ public List<Integer> getBands() {
+ // Todo: Add actual support
+ return Collections.emptyList();
+ }
+
+ /**
* @return Cell bandwidth in kHz,
* {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
*/
diff --git a/telephony/java/android/telephony/CellIdentityNr.java b/telephony/java/android/telephony/CellIdentityNr.java
index 40927a1..d4f181f 100644
--- a/telephony/java/android/telephony/CellIdentityNr.java
+++ b/telephony/java/android/telephony/CellIdentityNr.java
@@ -23,6 +23,7 @@
import android.telephony.AccessNetworkConstants.NgranBands.NgranBand;
import android.telephony.gsm.GsmCellLocation;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -42,7 +43,7 @@
private final int mPci;
private final int mTac;
private final long mNci;
- private final int mBand;
+ private final List<Integer> mBands;
// a list of additional PLMN-IDs reported for this cell
private final List<String> mAdditionalPlmns;
@@ -52,7 +53,7 @@
* @param pci Physical Cell Id in range [0, 1007].
* @param tac 16-bit Tracking Area Code.
* @param nrArfcn NR Absolute Radio Frequency Channel Number, in range [0, 3279165].
- * @param band Band number defined in 3GPP TS 38.101-1 and TS 38.101-2.
+ * @param bands Bands used by the cell. Band number defined in 3GPP TS 38.101-1 and TS 38.101-2.
* @param mccStr 3-digit Mobile Country Code in string format.
* @param mncStr 2 or 3-digit Mobile Network Code in string format.
* @param nci The 36-bit NR Cell Identity in range [0, 68719476735].
@@ -62,28 +63,28 @@
*
* @hide
*/
- public CellIdentityNr(int pci, int tac, int nrArfcn, @NgranBand int band, String mccStr,
- String mncStr, long nci, String alphal, String alphas, List<String> additionalPlmns) {
+ public CellIdentityNr(int pci, int tac, int nrArfcn, @NgranBand List<Integer> bands,
+ String mccStr, String mncStr, long nci, String alphal, String alphas,
+ List<String> additionalPlmns) {
super(TAG, CellInfo.TYPE_NR, mccStr, mncStr, alphal, alphas);
mPci = inRangeOrUnavailable(pci, 0, MAX_PCI);
mTac = inRangeOrUnavailable(tac, 0, MAX_TAC);
mNrArfcn = inRangeOrUnavailable(nrArfcn, 0, MAX_NRARFCN);
- mBand = inRangeOrUnavailable(band, AccessNetworkConstants.NgranBands.BAND_1,
- AccessNetworkConstants.NgranBands.BAND_261);
+ mBands = new ArrayList<>(bands);
mNci = inRangeOrUnavailable(nci, 0, MAX_NCI);
- mAdditionalPlmns = additionalPlmns;
+ mAdditionalPlmns = new ArrayList<>(additionalPlmns);
}
/** @hide */
public CellIdentityNr(android.hardware.radio.V1_4.CellIdentityNr cid) {
- this(cid.pci, cid.tac, cid.nrarfcn, 0, cid.mcc, cid.mnc, cid.nci,
+ this(cid.pci, cid.tac, cid.nrarfcn, Collections.emptyList(), cid.mcc, cid.mnc, cid.nci,
cid.operatorNames.alphaLong, cid.operatorNames.alphaShort,
Collections.emptyList());
}
/** @hide */
public CellIdentityNr(android.hardware.radio.V1_5.CellIdentityNr cid) {
- this(cid.base.pci, cid.base.tac, cid.base.nrarfcn, cid.band, cid.base.mcc, cid.base.mnc,
+ this(cid.base.pci, cid.base.tac, cid.base.nrarfcn, cid.bands, cid.base.mcc, cid.base.mnc,
cid.base.nci, cid.base.operatorNames.alphaLong,
cid.base.operatorNames.alphaShort, cid.additionalPlmns);
}
@@ -92,7 +93,7 @@
@Override
public @NonNull CellIdentityNr sanitizeLocationInfo() {
return new CellIdentityNr(CellInfo.UNAVAILABLE, CellInfo.UNAVAILABLE, mNrArfcn,
- mBand, mMccStr, mMncStr, CellInfo.UNAVAILABLE, mAlphaLong, mAlphaShort,
+ mBands, mMccStr, mMncStr, CellInfo.UNAVAILABLE, mAlphaLong, mAlphaShort,
mAdditionalPlmns);
}
@@ -109,7 +110,7 @@
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mPci, mTac,
- mNrArfcn, mBand, mNci, mAdditionalPlmns.hashCode());
+ mNrArfcn, mBands.hashCode(), mNci, mAdditionalPlmns.hashCode());
}
@Override
@@ -120,7 +121,7 @@
CellIdentityNr o = (CellIdentityNr) other;
return super.equals(o) && mPci == o.mPci && mTac == o.mTac && mNrArfcn == o.mNrArfcn
- && mBand == o.mBand && mNci == o.mNci
+ && mBands.equals(o.mBands) && mNci == o.mNci
&& mAdditionalPlmns.equals(o.mAdditionalPlmns);
}
@@ -148,16 +149,17 @@
}
/**
- * Get band of the cell
+ * Get bands of the cell
*
* Reference: TS 38.101-1 table 5.2-1
* Reference: TS 38.101-2 table 5.2-1
*
- * @return band number or {@link CellInfo@UNAVAILABLE} if not available.
+ * @return List of band number or empty list if not available.
*/
@NgranBand
- public int getBand() {
- return mBand;
+ @NonNull
+ public List<Integer> getBands() {
+ return Collections.unmodifiableList(mBands);
}
/**
@@ -205,7 +207,7 @@
*/
@NonNull
public List<String> getAdditionalPlmns() {
- return mAdditionalPlmns;
+ return Collections.unmodifiableList(mAdditionalPlmns);
}
@Override
@@ -214,7 +216,7 @@
.append(" mPci = ").append(mPci)
.append(" mTac = ").append(mTac)
.append(" mNrArfcn = ").append(mNrArfcn)
- .append(" mBand = ").append(mBand)
+ .append(" mBands = ").append(mBands)
.append(" mMcc = ").append(mMccStr)
.append(" mMnc = ").append(mMncStr)
.append(" mNci = ").append(mNci)
@@ -231,7 +233,7 @@
dest.writeInt(mPci);
dest.writeInt(mTac);
dest.writeInt(mNrArfcn);
- dest.writeInt(mBand);
+ dest.writeList(mBands);
dest.writeLong(mNci);
dest.writeList(mAdditionalPlmns);
}
@@ -242,7 +244,7 @@
mPci = in.readInt();
mTac = in.readInt();
mNrArfcn = in.readInt();
- mBand = in.readInt();
+ mBands = in.readArrayList(null);
mNci = in.readLong();
mAdditionalPlmns = in.readArrayList(null);
}
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index a1f3cef..903be6f 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -2781,7 +2781,7 @@
@UnsupportedAppUsage
public boolean isNetworkRoaming(int subId) {
int phoneId = SubscriptionManager.getPhoneId(subId);
- return getTelephonyProperty(subId, TelephonyProperties.operator_is_roaming(), false);
+ return getTelephonyProperty(phoneId, TelephonyProperties.operator_is_roaming(), false);
}
/**
@@ -8095,6 +8095,30 @@
}
/**
+ * Get the PLMN chosen for Manual Network Selection if active.
+ * Return empty string if in automatic selection.
+ *
+ * <p>Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE
+ * READ_PRECISE_PHONE_STATE} or that the calling app has carrier privileges
+ * (see {@link #hasCarrierPrivileges})
+ *
+ * @return manually selected network info on success or empty string on failure
+ */
+ @SuppressAutoDoc // No support carrier privileges (b/72967236).
+ @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE)
+ public @NonNull String getManualNetworkSelectionPlmn() {
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null && isManualNetworkSelectionAllowed()) {
+ return telephony.getManualNetworkSelectionPlmn(getSubId());
+ }
+ } catch (RemoteException ex) {
+ Rlog.e(TAG, "getManualNetworkSelectionPlmn RemoteException", ex);
+ }
+ return "";
+ }
+
+ /**
* Query Telephony to see if there has recently been an emergency SMS sent to the network by the
* user and we are still within the time interval after the emergency SMS was sent that we are
* considered in Emergency SMS mode.
@@ -11147,15 +11171,18 @@
/**
* Checks if manual network selection is allowed.
*
+ * <p>Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE
+ * READ_PRECISE_PHONE_STATE} or that the calling app has carrier privileges
+ * (see {@link #hasCarrierPrivileges})
+ *
* <p>If this object has been created with {@link #createForSubscriptionId}, applies to the
* given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}.
*
* @return {@code true} if manual network selection is allowed, otherwise return {@code false}.
- *
- * @hide
*/
- @SystemApi
- @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
+ @SuppressAutoDoc // No support carrier privileges (b/72967236).
+ @RequiresPermission(anyOf = {android.Manifest.permission.READ_PRECISE_PHONE_STATE,
+ android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE})
public boolean isManualNetworkSelectionAllowed() {
try {
ITelephony telephony = getITelephony();
diff --git a/telephony/java/android/telephony/euicc/EuiccManager.java b/telephony/java/android/telephony/euicc/EuiccManager.java
index d5a48df..27a7022 100644
--- a/telephony/java/android/telephony/euicc/EuiccManager.java
+++ b/telephony/java/android/telephony/euicc/EuiccManager.java
@@ -246,13 +246,56 @@
* Key for an extra set on {@link PendingIntent} result callbacks providing a detailed result
* code.
*
- * <p>This code is an implementation detail of the embedded subscription manager and is only
- * intended for logging or debugging purposes.
+ * <p>The value of this key is an integer and contains two portions. The first byte is
+ * OperationCode and the reaming three bytes is the ErrorCode.
+ *
+ * OperationCode is the first byte of the result code and is a categorization which defines what
+ * type of operation took place when an error occurred. e.g {@link #OPERATION_DOWNLOAD} means
+ * the error is related to download.Since the OperationCode only uses at most one byte, the
+ * maximum allowed quantity is 255(0xFF).
+ *
+ * ErrorCode is the remaing three bytes of the result code, and it denotes what happened.
+ * e.g a combination of {@link #OPERATION_DOWNLOAD} and {@link #ERROR_TIME_OUT} will suggest the
+ * download operation has timed out. The only exception here is
+ * {@link #OPERATION_SMDX_SUBJECT_REASON_CODE}, where instead of ErrorCode, SubjectCode[5.2.6.1
+ * from GSMA (SGP.22 v2.2) and ReasonCode[5.2.6.2] from GSMA (SGP.22 v2.2) are encoded. @see
+ * {@link #EXTRA_EMBEDDED_SUBSCRIPTION_SMDX_SUBJECT_CODE} and
+ * {@link #EXTRA_EMBEDDED_SUBSCRIPTION_SMDX_REASON_CODE}
*/
public static final String EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE =
"android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_DETAILED_CODE";
/**
+ * Key for an extra set on {@link PendingIntent} result callbacks providing a
+ * OperationCode of {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE}.
+ */
+ public static final String EXTRA_EMBEDDED_SUBSCRIPTION_OPERATION_CODE =
+ "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_OPERATION_CODE";
+
+ /**
+ * Key for an extra set on {@link PendingIntent} result callbacks providing a
+ * ErrorCode of {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE}.
+ */
+ public static final String EXTRA_EMBEDDED_SUBSCRIPTION_ERROR_CODE =
+ "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_ERROR_CODE";
+
+ /**
+ * Key for an extra set on {@link PendingIntent} result callbacks providing a
+ * SubjectCode[5.2.6.1] from GSMA (SGP.22 v2.2) decoded from
+ * {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE}.
+ */
+ public static final String EXTRA_EMBEDDED_SUBSCRIPTION_SMDX_SUBJECT_CODE =
+ "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_SMDX_SUBJECT_CODE";
+
+ /**
+ * Key for an extra set on {@link PendingIntent} result callbacks providing a
+ * ReasonCode[5.2.6.2] from GSMA (SGP.22 v2.2) decoded from
+ * {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE}.
+ */
+ public static final String EXTRA_EMBEDDED_SUBSCRIPTION_SMDX_REASON_CODE =
+ "android.telephony.euicc.extra.EMBEDDED_SUBSCRIPTION_SMDX_REASON_CODE";
+
+ /**
* Key for an extra set on {@code #getDownloadableSubscriptionMetadata} PendingIntent result
* callbacks providing the downloadable subscription metadata.
*/
@@ -491,6 +534,259 @@
@SystemApi
public static final int EUICC_OTA_STATUS_UNAVAILABLE = 5;
+ /**
+ * List of OperationCode corresponding to {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE}'s
+ * value, an integer. @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ *
+ * @hide
+ */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(prefix = {"OPERATION_"}, value = {
+ OPERATION_SYSTEM,
+ OPERATION_SIM_SLOT,
+ OPERATION_EUICC_CARD,
+ OPERATION_SWITCH,
+ OPERATION_DOWNLOAD,
+ OPERATION_METADATA,
+ OPERATION_EUICC_GSMA,
+ OPERATION_APDU,
+ OPERATION_SMDX,
+ OPERATION_HTTP,
+ OPERATION_SMDX_SUBJECT_REASON_CODE,
+ })
+ public @interface OperationCode {
+ }
+
+ /**
+ * Internal system error.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_SYSTEM = 1;
+
+ /**
+ * SIM slot error. Failed to switch slot, failed to access the physical slot etc.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_SIM_SLOT = 2;
+
+ /**
+ * eUICC card error.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_EUICC_CARD = 3;
+
+ /**
+ * Generic switching profile error
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_SWITCH = 4;
+
+ /**
+ * Download profile error.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_DOWNLOAD = 5;
+
+ /**
+ * Subscription's metadata error
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_METADATA = 6;
+
+ /**
+ * eUICC returned an error defined in GSMA (SGP.22 v2.2) while running one of the ES10x
+ * functions.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_EUICC_GSMA = 7;
+
+ /**
+ * The exception of failing to execute an APDU command. It can be caused by an error
+ * happening on opening the basic or logical channel, or the response of the APDU command is
+ * not success (0x9000).
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_APDU = 8;
+
+ /**
+ * SMDX(SMDP/SMDS) error
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_SMDX = 9;
+
+ /**
+ * SubjectCode[5.2.6.1] and ReasonCode[5.2.6.2] error from GSMA (SGP.22 v2.2)
+ * When {@link #OPERATION_SMDX_SUBJECT_REASON_CODE} is used as the
+ * {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE}, the remaining three bytes of the integer
+ * result from {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} will be used to stored the
+ * SubjectCode and ReasonCode from the GSMA spec and NOT ErrorCode.
+ *
+ * The encoding will follow the format of:
+ * 1. The first byte of the result will be 255(0xFF).
+ * 2. Remaining three bytes(24 bits) will be split into six sections, 4 bits in each section.
+ * 3. A SubjectCode/ReasonCode will take 12 bits each.
+ * 4. The maximum number can be represented per section is 15, as that is the maximum number
+ * allowed to be stored into 4 bits
+ * 5. Maximum supported nested category from GSMA is three layers. E.g 8.11.1.2 is not
+ * supported.
+ *
+ * E.g given SubjectCode(8.11.1) and ReasonCode(5.1)
+ *
+ * Base10: 0 10 8 11 1 0 5 1
+ * Base2: 0000 1010 1000 1011 0001 0000 0101 0001
+ * Base16: 0 A 8 B 1 0 5 1
+ *
+ * Thus the integer stored in {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} is
+ * 0xA8B1051(176885841)
+ *
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_SMDX_SUBJECT_REASON_CODE = 10;
+
+ /**
+ * HTTP error
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int OPERATION_HTTP = 11;
+
+ /**
+ * List of ErrorCode corresponding to {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE}
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ * @hide
+ */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(prefix = {"ERROR_"}, value = {
+ ERROR_CARRIER_LOCKED,
+ ERROR_INVALID_ACTIVATION_CODE,
+ ERROR_INVALID_CONFIRMATION_CODE,
+ ERROR_INCOMPATIBLE_CARRIER,
+ ERROR_EUICC_INSUFFICIENT_MEMORY,
+ ERROR_TIME_OUT,
+ ERROR_EUICC_MISSING,
+ ERROR_UNSUPPORTED_VERSION,
+ ERROR_SIM_MISSING,
+ ERROR_EUICC_GSMA_INSTALL_ERROR,
+ ERROR_DISALLOWED_BY_PPR,
+ ERROR_ADDRESS_MISSING,
+ ERROR_CERTIFICATE_ERROR,
+ ERROR_NO_PROFILES_AVAILABLE,
+ ERROR_CONNECTION_ERROR,
+ ERROR_INVALID_RESPONSE,
+ ERROR_OPERATION_BUSY,
+ })
+ public @interface ErrorCode{}
+
+ /**
+ * Operation such as downloading/switching to another profile failed due to device being
+ * carrier locked.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_CARRIER_LOCKED = 10000;
+
+ /**
+ * The activation code(SGP.22 v2.2 section[4.1]) is invalid.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_INVALID_ACTIVATION_CODE = 10001;
+
+ /**
+ * The confirmation code(SGP.22 v2.2 section[4.7]) is invalid.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_INVALID_CONFIRMATION_CODE = 10002;
+
+ /**
+ * The profile's carrier is incompatible with the LPA.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_INCOMPATIBLE_CARRIER = 10003;
+
+ /**
+ * There is no more space available on the eUICC for new profiles.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_EUICC_INSUFFICIENT_MEMORY = 10004;
+
+ /**
+ * Timed out while waiting for an operation to complete. i.e restart, disable,
+ * switch reset etc.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_TIME_OUT = 10005;
+
+ /**
+ * eUICC is missing or defective on the device.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_EUICC_MISSING = 10006;
+
+ /**
+ * The eUICC card(hardware) version is incompatible with the software
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_UNSUPPORTED_VERSION = 10007;
+
+ /**
+ * No SIM card is available in the device.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_SIM_MISSING = 10008;
+
+ /**
+ * Failure to load the profile onto the eUICC card. i.e
+ * 1. iccid of the profile already exists on the eUICC.
+ * 2. GSMA(.22 v2.2) Profile Install Result - installFailedDueToDataMismatch
+ * 3. operation was interrupted
+ * 4. SIMalliance error in PEStatus(SGP.22 v2.2 section 2.5.6.1)
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_EUICC_GSMA_INSTALL_ERROR = 10009;
+
+ /**
+ * Failed to load profile onto eUICC due to Profile Poicly Rules.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_DISALLOWED_BY_PPR = 10010;
+
+
+ /**
+ * Address is missing e.g SMDS/SMDP address is missing.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_ADDRESS_MISSING = 10011;
+
+ /**
+ * Certificate needed for authentication is not valid or missing. E.g SMDP/SMDS authentication
+ * failed.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_CERTIFICATE_ERROR = 10012;
+
+
+ /**
+ * No profiles available.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_NO_PROFILES_AVAILABLE = 10013;
+
+ /**
+ * Failure to create a connection.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_CONNECTION_ERROR = 10014;
+
+ /**
+ * Response format is invalid. e.g SMDP/SMDS response contains invalid json, header or/and ASN1.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_INVALID_RESPONSE = 10015;
+
+ /**
+ * The operation is currently busy, try again later.
+ * @see {@link #EXTRA_EMBEDDED_SUBSCRIPTION_DETAILED_CODE} for details
+ */
+ public static final int ERROR_OPERATION_BUSY = 10016;
+
private final Context mContext;
private int mCardId;
diff --git a/telephony/java/android/telephony/ims/ImsCallProfile.java b/telephony/java/android/telephony/ims/ImsCallProfile.java
index 8c9765b..9c1be48 100644
--- a/telephony/java/android/telephony/ims/ImsCallProfile.java
+++ b/telephony/java/android/telephony/ims/ImsCallProfile.java
@@ -328,6 +328,14 @@
@Deprecated
public static final String EXTRA_CALL_RAT_TYPE_ALT = "callRadioTech";
+ /**
+ * String extra property containing forwarded numbers associated with the current connection
+ * for an IMS call. The value is string array, and it can include multiple numbers, and
+ * the array values are expected E164 (e.g. +1 (650) 253-0000) format.
+ */
+ public static final String EXTRA_FORWARDED_NUMBER =
+ "android.telephony.ims.extra.FORWARDED_NUMBER";
+
/** @hide */
public int mServiceType;
/** @hide */
diff --git a/telephony/java/android/telephony/ims/stub/ImsUtImplBase.java b/telephony/java/android/telephony/ims/stub/ImsUtImplBase.java
index 3ec4f34..f13371c 100644
--- a/telephony/java/android/telephony/ims/stub/ImsUtImplBase.java
+++ b/telephony/java/android/telephony/ims/stub/ImsUtImplBase.java
@@ -17,6 +17,8 @@
package android.telephony.ims.stub;
import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.os.Bundle;
@@ -206,6 +208,13 @@
return ImsUtImplBase.this.updateCallBarringForServiceClass(
cbType, action, barrList, serviceClass);
}
+
+ @Override
+ public int updateCallBarringWithPassword(int cbType, int action, String[] barrList,
+ int serviceClass, String password) throws RemoteException {
+ return ImsUtImplBase.this.updateCallBarringWithPassword(
+ cbType, action, barrList, serviceClass, password);
+ }
};
/**
@@ -328,6 +337,14 @@
}
/**
+ * Updates the configuration of the call barring for specified service class with password.
+ */
+ public int updateCallBarringWithPassword(int cbType, int action, @Nullable String[] barrList,
+ int serviceClass, @NonNull String password) {
+ return -1;
+ }
+
+ /**
* Updates the configuration of the call forward.
*/
public int updateCallForward(int action, int condition, String number, int serviceClass,
diff --git a/telephony/java/com/android/ims/ImsUtInterface.java b/telephony/java/com/android/ims/ImsUtInterface.java
index 15f8371..4a5380e 100644
--- a/telephony/java/com/android/ims/ImsUtInterface.java
+++ b/telephony/java/com/android/ims/ImsUtInterface.java
@@ -166,6 +166,12 @@
String[] barrList, int serviceClass);
/**
+ * Modifies the configuration of the call barring for specified service class with password.
+ */
+ public void updateCallBarring(int cbType, int action, Message result,
+ String[] barrList, int serviceClass, String password);
+
+ /**
* Modifies the configuration of the call forward.
*/
public void updateCallForward(int action, int condition, String number,
diff --git a/telephony/java/com/android/ims/internal/IImsUt.aidl b/telephony/java/com/android/ims/internal/IImsUt.aidl
index 4f97cc5..302be65 100644
--- a/telephony/java/com/android/ims/internal/IImsUt.aidl
+++ b/telephony/java/com/android/ims/internal/IImsUt.aidl
@@ -122,4 +122,10 @@
*/
int updateCallBarringForServiceClass(int cbType, int action, in String[] barrList,
int serviceClass);
+
+ /**
+ * Updates the configuration of the call barring for specified service class with password.
+ */
+ int updateCallBarringWithPassword(int cbType, int action, in String[] barrList,
+ int serviceClass, String password);
}
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 0bc6640..6aa5a52 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -2197,4 +2197,13 @@
* This is safe to call from any thread, with any window manager locks held or not.
*/
oneway void userActivity();
+
+ /**
+ * Get the user manual network selection.
+ * Return empty string if in automatic selection.
+ *
+ * @param subId the id of the subscription
+ * @return operatorinfo on success
+ */
+ String getManualNetworkSelectionPlmn(int subId);
}
diff --git a/telephony/java/com/android/internal/telephony/TelephonyIntents.java b/telephony/java/com/android/internal/telephony/TelephonyIntents.java
index b697d58..48f7850 100644
--- a/telephony/java/com/android/internal/telephony/TelephonyIntents.java
+++ b/telephony/java/com/android/internal/telephony/TelephonyIntents.java
@@ -212,37 +212,6 @@
public static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";
/**
- * Broadcast Action: The Service Provider string(s) have been updated. Activities or
- * services that use these strings should update their display.
- * The intent will have the following extra values:</p>
- *
- * <dl>
- * <dt>showPlmn</dt><dd>Boolean that indicates whether the PLMN should be shown.</dd>
- * <dt>plmn</dt><dd>The operator name of the registered network, as a string.</dd>
- * <dt>showSpn</dt><dd>Boolean that indicates whether the SPN should be shown.</dd>
- * <dt>spn</dt><dd>The service provider name, as a string.</dd>
- * </dl>
- *
- * Note that <em>showPlmn</em> may indicate that <em>plmn</em> should be displayed, even
- * though the value for <em>plmn</em> is null. This can happen, for example, if the phone
- * has not registered to a network yet. In this case the receiver may substitute an
- * appropriate placeholder string (eg, "No service").
- *
- * It is recommended to display <em>plmn</em> before / above <em>spn</em> if
- * both are displayed.
- *
- * <p>Note: this is a protected intent that can only be sent by the system.
- */
- public static final String SPN_STRINGS_UPDATED_ACTION =
- "android.provider.Telephony.SPN_STRINGS_UPDATED";
-
- public static final String EXTRA_SHOW_PLMN = "showPlmn";
- public static final String EXTRA_PLMN = "plmn";
- public static final String EXTRA_SHOW_SPN = "showSpn";
- public static final String EXTRA_SPN = "spn";
- public static final String EXTRA_DATA_SPN = "spnData";
-
- /**
* <p>Broadcast Action: It indicates one column of a subinfo record has been changed
* <p class="note">This is a protected intent that can only be sent
* by the system.
diff --git a/tests/ApkVerityTest/block_device_writer/Android.bp b/tests/ApkVerityTest/block_device_writer/Android.bp
index e7a63e4..78850c5 100644
--- a/tests/ApkVerityTest/block_device_writer/Android.bp
+++ b/tests/ApkVerityTest/block_device_writer/Android.bp
@@ -30,7 +30,23 @@
"-g",
],
shared_libs: ["libbase", "libutils"],
+ // For some reasons, cuttlefish (x86) uses x86_64 test suites for testing. Unfortunately, when
+ // the uploader does not pick up the executable from correct output location. The following
+ // workaround allows the test to:
+ // * upload the 32-bit exectuable for both 32 and 64 bits devices to use
+ // * refer to the same executable name in Java
+ // * no need to force the Java test to be archiecture specific.
+ //
+ // See b/145573317 for details.
+ multilib: {
+ lib32: {
+ suffix: "",
+ },
+ lib64: {
+ suffix: "64", // not really used
+ },
+ },
- test_suites: ["general-tests"],
+ test_suites: ["general-tests", "pts"],
gtest: false,
}
diff --git a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java
index 65a3d8a..c900eae 100644
--- a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java
+++ b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java
@@ -30,6 +30,7 @@
import android.test.suitebuilder.annotation.SmallTest;
import java.util.Arrays;
+import java.util.Locale;
import java.util.Random;
import java.util.UUID;
@@ -38,7 +39,8 @@
@SmallTest
public void testKeyphraseParcelUnparcel_noUsers() throws Exception {
- Keyphrase keyphrase = new Keyphrase(1, 0, "en-US", "hello", null);
+ Keyphrase keyphrase = new Keyphrase(1, 0,
+ Locale.forLanguageTag("en-US"), "hello", null);
// Write to a parcel
Parcel parcel = Parcel.obtain();
@@ -57,7 +59,8 @@
@SmallTest
public void testKeyphraseParcelUnparcel_zeroUsers() throws Exception {
- Keyphrase keyphrase = new Keyphrase(1, 0, "en-US", "hello", new int[0]);
+ Keyphrase keyphrase = new Keyphrase(1, 0,
+ Locale.forLanguageTag("en-US"), "hello", new int[0]);
// Write to a parcel
Parcel parcel = Parcel.obtain();
@@ -76,7 +79,8 @@
@SmallTest
public void testKeyphraseParcelUnparcel_pos() throws Exception {
- Keyphrase keyphrase = new Keyphrase(1, 0, "en-US", "hello", new int[] {1, 2, 3, 4, 5});
+ Keyphrase keyphrase = new Keyphrase(1, 0,
+ Locale.forLanguageTag("en-US"), "hello", new int[] {1, 2, 3, 4, 5});
// Write to a parcel
Parcel parcel = Parcel.obtain();
@@ -96,8 +100,10 @@
@SmallTest
public void testKeyphraseSoundModelParcelUnparcel_noData() throws Exception {
Keyphrase[] keyphrases = new Keyphrase[2];
- keyphrases[0] = new Keyphrase(1, 0, "en-US", "hello", new int[] {0});
- keyphrases[1] = new Keyphrase(2, 0, "fr-FR", "there", new int[] {1, 2});
+ keyphrases[0] = new Keyphrase(1, 0, Locale.forLanguageTag("en-US"),
+ "hello", new int[] {0});
+ keyphrases[1] = new Keyphrase(2, 0, Locale.forLanguageTag("fr-FR"),
+ "there", new int[] {1, 2});
KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(),
null, keyphrases);
@@ -119,8 +125,10 @@
@SmallTest
public void testKeyphraseSoundModelParcelUnparcel_zeroData() throws Exception {
Keyphrase[] keyphrases = new Keyphrase[2];
- keyphrases[0] = new Keyphrase(1, 0, "en-US", "hello", new int[] {0});
- keyphrases[1] = new Keyphrase(2, 0, "fr-FR", "there", new int[] {1, 2});
+ keyphrases[0] = new Keyphrase(1, 0, Locale.forLanguageTag("en-US"),
+ "hello", new int[] {0});
+ keyphrases[1] = new Keyphrase(2, 0, Locale.forLanguageTag("fr-FR"),
+ "there", new int[] {1, 2});
KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(),
new byte[0], keyphrases);
@@ -186,8 +194,10 @@
@LargeTest
public void testKeyphraseSoundModelParcelUnparcel_largeData() throws Exception {
Keyphrase[] keyphrases = new Keyphrase[2];
- keyphrases[0] = new Keyphrase(1, 0, "en-US", "hello", new int[] {0});
- keyphrases[1] = new Keyphrase(2, 0, "fr-FR", "there", new int[] {1, 2});
+ keyphrases[0] = new Keyphrase(1, 0, Locale.forLanguageTag("en-US"),
+ "hello", new int[] {0});
+ keyphrases[1] = new Keyphrase(2, 0, Locale.forLanguageTag("fr-FR"),
+ "there", new int[] {1, 2});
byte[] data = new byte[200 * 1024];
mRandom.nextBytes(data);
KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(),
diff --git a/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java b/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java
index 6687f83..6169671 100644
--- a/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java
+++ b/tests/SurfaceControlViewHostTest/src/com/android/test/viewembed/SurfaceControlViewHostTest.java
@@ -46,15 +46,15 @@
mView.setZOrderOnTop(true);
mView.getHolder().addCallback(this);
+
+ addEmbeddedView();
}
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
+ void addEmbeddedView() {
mVr = new SurfaceControlViewHost(this, this.getDisplay(),
- mView.getInputToken());
+ mView.getHostToken());
- final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
- t.reparent(mVr.getSurfacePackage().getSurfaceControl(), mView.getSurfaceControl()).apply();
+ mView.setChildSurfacePackage(mVr.getSurfacePackage());
Button v = new Button(this);
v.setBackgroundColor(Color.BLUE);
@@ -70,6 +70,10 @@
}
@Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ }
+
+ @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Canvas canvas = holder.lockCanvas();
canvas.drawColor(Color.GREEN);
diff --git a/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java b/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java
index 54c944f9..b357ad0 100644
--- a/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java
+++ b/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java
@@ -16,9 +16,6 @@
package com.android.test.voiceenrollment;
-import java.util.Random;
-import java.util.UUID;
-
import android.app.Activity;
import android.hardware.soundtrigger.SoundTrigger;
import android.hardware.soundtrigger.SoundTrigger.Keyphrase;
@@ -29,6 +26,13 @@
import android.view.View;
import android.widget.Toast;
+import java.util.Locale;
+import java.util.Random;
+import java.util.UUID;
+
+/**
+ * TODO: must be transitioned to a service.
+ */
public class TestEnrollmentActivity extends Activity {
private static final String TAG = "TestEnrollmentActivity";
private static final boolean DBG = false;
@@ -56,7 +60,8 @@
* Performs a fresh enrollment.
*/
public void onEnrollButtonClicked(View v) {
- Keyphrase kp = new Keyphrase(KEYPHRASE_ID, RECOGNITION_MODES, BCP47_LOCALE, TEXT,
+ Keyphrase kp = new Keyphrase(KEYPHRASE_ID, RECOGNITION_MODES,
+ Locale.forLanguageTag(BCP47_LOCALE), TEXT,
new int[] { UserManager.get(this).getUserHandle() /* current user */});
UUID modelUuid = UUID.randomUUID();
// Generate a fake model to push.
diff --git a/tests/net/java/android/net/ConnectivityDiagnosticsManagerTest.java b/tests/net/java/android/net/ConnectivityDiagnosticsManagerTest.java
new file mode 100644
index 0000000..065add4
--- /dev/null
+++ b/tests/net/java/android/net/ConnectivityDiagnosticsManagerTest.java
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2020 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.net;
+
+import static android.net.ConnectivityDiagnosticsManager.ConnectivityReport;
+import static android.net.ConnectivityDiagnosticsManager.DataStallReport;
+
+import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import android.os.PersistableBundle;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class ConnectivityDiagnosticsManagerTest {
+ private static final int NET_ID = 1;
+ private static final int DETECTION_METHOD = 2;
+ private static final long TIMESTAMP = 10L;
+ private static final String INTERFACE_NAME = "interface";
+ private static final String BUNDLE_KEY = "key";
+ private static final String BUNDLE_VALUE = "value";
+
+ private ConnectivityReport createSampleConnectivityReport() {
+ final LinkProperties linkProperties = new LinkProperties();
+ linkProperties.setInterfaceName(INTERFACE_NAME);
+
+ final NetworkCapabilities networkCapabilities = new NetworkCapabilities();
+ networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_IMS);
+
+ final PersistableBundle bundle = new PersistableBundle();
+ bundle.putString(BUNDLE_KEY, BUNDLE_VALUE);
+
+ return new ConnectivityReport(
+ new Network(NET_ID), TIMESTAMP, linkProperties, networkCapabilities, bundle);
+ }
+
+ private ConnectivityReport createDefaultConnectivityReport() {
+ return new ConnectivityReport(
+ new Network(0),
+ 0L,
+ new LinkProperties(),
+ new NetworkCapabilities(),
+ PersistableBundle.EMPTY);
+ }
+
+ @Test
+ public void testPersistableBundleEquals() {
+ assertFalse(
+ ConnectivityDiagnosticsManager.persistableBundleEquals(
+ null, PersistableBundle.EMPTY));
+ assertFalse(
+ ConnectivityDiagnosticsManager.persistableBundleEquals(
+ PersistableBundle.EMPTY, null));
+ assertTrue(
+ ConnectivityDiagnosticsManager.persistableBundleEquals(
+ PersistableBundle.EMPTY, PersistableBundle.EMPTY));
+
+ final PersistableBundle a = new PersistableBundle();
+ a.putString(BUNDLE_KEY, BUNDLE_VALUE);
+
+ final PersistableBundle b = new PersistableBundle();
+ b.putString(BUNDLE_KEY, BUNDLE_VALUE);
+
+ final PersistableBundle c = new PersistableBundle();
+ c.putString(BUNDLE_KEY, null);
+
+ assertFalse(
+ ConnectivityDiagnosticsManager.persistableBundleEquals(PersistableBundle.EMPTY, a));
+ assertFalse(
+ ConnectivityDiagnosticsManager.persistableBundleEquals(a, PersistableBundle.EMPTY));
+
+ assertTrue(ConnectivityDiagnosticsManager.persistableBundleEquals(a, b));
+ assertTrue(ConnectivityDiagnosticsManager.persistableBundleEquals(b, a));
+
+ assertFalse(ConnectivityDiagnosticsManager.persistableBundleEquals(a, c));
+ assertFalse(ConnectivityDiagnosticsManager.persistableBundleEquals(c, a));
+ }
+
+ @Test
+ public void testConnectivityReportEquals() {
+ assertEquals(createSampleConnectivityReport(), createSampleConnectivityReport());
+ assertEquals(createDefaultConnectivityReport(), createDefaultConnectivityReport());
+
+ final LinkProperties linkProperties = new LinkProperties();
+ linkProperties.setInterfaceName(INTERFACE_NAME);
+
+ final NetworkCapabilities networkCapabilities = new NetworkCapabilities();
+ networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_IMS);
+
+ final PersistableBundle bundle = new PersistableBundle();
+ bundle.putString(BUNDLE_KEY, BUNDLE_VALUE);
+
+ assertNotEquals(
+ createDefaultConnectivityReport(),
+ new ConnectivityReport(
+ new Network(NET_ID),
+ 0L,
+ new LinkProperties(),
+ new NetworkCapabilities(),
+ PersistableBundle.EMPTY));
+ assertNotEquals(
+ createDefaultConnectivityReport(),
+ new ConnectivityReport(
+ new Network(0),
+ TIMESTAMP,
+ new LinkProperties(),
+ new NetworkCapabilities(),
+ PersistableBundle.EMPTY));
+ assertNotEquals(
+ createDefaultConnectivityReport(),
+ new ConnectivityReport(
+ new Network(0),
+ 0L,
+ linkProperties,
+ new NetworkCapabilities(),
+ PersistableBundle.EMPTY));
+ assertNotEquals(
+ createDefaultConnectivityReport(),
+ new ConnectivityReport(
+ new Network(0),
+ TIMESTAMP,
+ new LinkProperties(),
+ networkCapabilities,
+ PersistableBundle.EMPTY));
+ assertNotEquals(
+ createDefaultConnectivityReport(),
+ new ConnectivityReport(
+ new Network(0),
+ TIMESTAMP,
+ new LinkProperties(),
+ new NetworkCapabilities(),
+ bundle));
+ }
+
+ @Test
+ public void testConnectivityReportParcelUnparcel() {
+ assertParcelSane(createSampleConnectivityReport(), 5);
+ }
+
+ private DataStallReport createSampleDataStallReport() {
+ final PersistableBundle bundle = new PersistableBundle();
+ bundle.putString(BUNDLE_KEY, BUNDLE_VALUE);
+ return new DataStallReport(new Network(NET_ID), TIMESTAMP, DETECTION_METHOD, bundle);
+ }
+
+ private DataStallReport createDefaultDataStallReport() {
+ return new DataStallReport(new Network(0), 0L, 0, PersistableBundle.EMPTY);
+ }
+
+ @Test
+ public void testDataStallReportEquals() {
+ assertEquals(createSampleDataStallReport(), createSampleDataStallReport());
+ assertEquals(createDefaultDataStallReport(), createDefaultDataStallReport());
+
+ final PersistableBundle bundle = new PersistableBundle();
+ bundle.putString(BUNDLE_KEY, BUNDLE_VALUE);
+
+ assertNotEquals(
+ createDefaultDataStallReport(),
+ new DataStallReport(new Network(NET_ID), 0L, 0, PersistableBundle.EMPTY));
+ assertNotEquals(
+ createDefaultDataStallReport(),
+ new DataStallReport(new Network(0), TIMESTAMP, 0, PersistableBundle.EMPTY));
+ assertNotEquals(
+ createDefaultDataStallReport(),
+ new DataStallReport(new Network(0), 0L, DETECTION_METHOD, PersistableBundle.EMPTY));
+ assertNotEquals(
+ createDefaultDataStallReport(), new DataStallReport(new Network(0), 0L, 0, bundle));
+ }
+
+ @Test
+ public void testDataStallReportParcelUnparcel() {
+ assertParcelSane(createSampleDataStallReport(), 4);
+ }
+}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
index 8fa9c3d..9562f95 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
@@ -66,12 +66,20 @@
/** @hide */
public String passphrase = "";
- /** Get the required band for the group owner. */
+ /**
+ * Get the required band for the group owner.
+ * The result will be one of the following:
+ * {@link #GROUP_OWNER_BAND_AUTO},
+ * {@link #GROUP_OWNER_BAND_2GHZ},
+ * {@link #GROUP_OWNER_BAND_5GHZ}
+ */
+ @GroupOperatingBandType
public int getGroupOwnerBand() {
return groupOwnerBand;
}
/** @hide */
+ @GroupOperatingBandType
public int groupOwnerBand = GROUP_OWNER_BAND_AUTO;
/** @hide */