Merge "MediaRouter: add routing controller in MRM"
diff --git a/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java b/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java
index 83195dc..0aa685d 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java
+++ b/apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * 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.
@@ -25,9 +25,12 @@
import com.android.internal.infra.AndroidFuture;
import com.google.android.icing.proto.SchemaProto;
+import com.google.android.icing.proto.SearchResultProto;
+import com.google.android.icing.protobuf.InvalidProtocolBufferException;
import java.util.List;
import java.util.concurrent.Executor;
+import java.util.function.BiConsumer;
import java.util.function.Consumer;
/**
@@ -127,4 +130,94 @@
// TODO(b/147614371) Fix error report for multiple documents.
future.whenCompleteAsync((noop, err) -> callback.accept(err), executor);
}
+
+ /**
+ * This method searches for documents based on a given query string. It also accepts
+ * specifications regarding how to search and format the results.
+ *
+ *<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
+ * ‘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
+ * ‘cat’”).
+ * Example: dog OR puppy
+ * <li>Exclusion
+ * 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.
+ * “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.
+ * “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
+ * 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
+ * that contain the query term ‘dog’ and are of either the ‘Email’ schema type or the
+ * ‘Video’ schema type.
+ * </ul>
+ *
+ * <p> It is strongly recommended to use Jetpack APIs.
+ *
+ * @param queryExpression Query String to search.
+ * @param searchSpec Spec for setting filters, raw query etc.
+ * @param executor Executor on which to invoke the callback.
+ * @param callback Callback to receive errors resulting from the query operation. If the
+ * operation succeeds, the callback will be invoked with {@code null}.
+ * @hide
+ */
+ @NonNull
+ public void query(
+ @NonNull String queryExpression,
+ @NonNull SearchSpec searchSpec,
+ @NonNull @CallbackExecutor Executor executor,
+ @NonNull BiConsumer<? super SearchResults, ? super Throwable> callback) {
+ AndroidFuture<byte[]> future = new AndroidFuture<>();
+ future.whenCompleteAsync((searchResultBytes, err) -> {
+ if (err != null) {
+ callback.accept(null, err);
+ return;
+ }
+
+ if (searchResultBytes != null) {
+ SearchResultProto searchResultProto;
+ try {
+ searchResultProto = SearchResultProto.parseFrom(searchResultBytes);
+ } catch (InvalidProtocolBufferException e) {
+ callback.accept(null, e);
+ return;
+ }
+ if (searchResultProto.hasError()) {
+ // TODO(sidchhabra): Add better exception handling.
+ callback.accept(
+ null,
+ new RuntimeException(searchResultProto.getError().getErrorMessage()));
+ return;
+ }
+ SearchResults searchResults = new SearchResults(searchResultProto);
+ callback.accept(searchResults, null);
+ return;
+ }
+
+ // Nothing was supplied in the future at all
+ callback.accept(
+ null, new IllegalStateException("Unknown failure occurred while querying"));
+ }, executor);
+
+ try {
+ mService.query(queryExpression, searchSpec.getProto().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 fc83d8c..22250f4 100644
--- a/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl
+++ b/apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl
@@ -1,5 +1,5 @@
/**
- * Copyright 2019, The Android Open Source Project
+ * Copyright 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.
@@ -29,4 +29,13 @@
*/
void setSchema(in byte[] schemaProto, in AndroidFuture callback);
void put(in byte[] documentBytes, in AndroidFuture callback);
+ /**
+ * Searches a document based on a given query string.
+ *
+ * @param queryExpression Query String to search.
+ * @param searchSpec Serialized SearchSpecProto.
+ * @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);
}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/IllegalSearchSpecException.java b/apex/appsearch/framework/java/android/app/appsearch/IllegalSearchSpecException.java
new file mode 100644
index 0000000..0d029f0
--- /dev/null
+++ b/apex/appsearch/framework/java/android/app/appsearch/IllegalSearchSpecException.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * Indicates that a {@link android.app.appsearch.SearchResults} has logical inconsistencies such
+ * as unpopulated mandatory fields or illegal combinations of parameters.
+ *
+ * @hide
+ */
+public class IllegalSearchSpecException extends IllegalArgumentException {
+ /**
+ * Constructs a new {@link IllegalSearchSpecException}.
+ *
+ * @param message A developer-readable description of the issue with the bundle.
+ */
+ public IllegalSearchSpecException(@NonNull String message) {
+ super(message);
+ }
+}
diff --git a/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
new file mode 100644
index 0000000..ec4258d
--- /dev/null
+++ b/apex/appsearch/framework/java/android/app/appsearch/SearchResults.java
@@ -0,0 +1,89 @@
+/*
+ * 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 com.google.android.icing.proto.SearchResultProto;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * 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.
+ * @hide
+ */
+public final class SearchResults {
+
+ private final SearchResultProto mSearchResultProto;
+
+ /** @hide */
+ public SearchResults(SearchResultProto searchResultProto) {
+ mSearchResultProto = searchResultProto;
+ }
+
+ /**
+ * This class represents the result obtained from the query. It will contain the document which
+ * which matched the specified query string and specifications.
+ * @hide
+ */
+ public static final class Result {
+ private final SearchResultProto.ResultProto mResultProto;
+
+ private Result(SearchResultProto.ResultProto resultProto) {
+ mResultProto = resultProto;
+ }
+
+ /**
+ * Contains the matching {@link AppSearch.Document}.
+ * @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())
+ .setCreationTimestampSecs(mResultProto.getDocument().getCreationTimestampSecs())
+ .setScore(mResultProto.getDocument().getScore())
+ .build();
+ }
+
+ // TODO(sidchhabra): Add Getter for ResultReader for Snippet.
+ }
+
+ @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
new file mode 100644
index 0000000..5df7108
--- /dev/null
+++ b/apex/appsearch/framework/java/android/app/appsearch/SearchSpec.java
@@ -0,0 +1,127 @@
+/*
+ * 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.IntDef;
+import android.annotation.NonNull;
+
+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 SearchSpec(SearchSpecProto searchSpecProto) {
+ mSearchSpecProto = searchSpecProto;
+ }
+
+ /** Creates a new {@link SearchSpec.Builder}. */
+ @NonNull
+ public static SearchSpec.Builder newBuilder() {
+ return new SearchSpec.Builder();
+ }
+
+ /** @hide */
+ @NonNull
+ SearchSpecProto getProto() {
+ return mSearchSpecProto;
+ }
+
+ /** 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}
+ @IntDef(prefix = {"TERM_MATCH_TYPE_"}, value = {
+ TERM_MATCH_TYPE_EXACT_ONLY,
+ TERM_MATCH_TYPE_PREFIX
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface TermMatchTypeCode {}
+
+ public static final int TERM_MATCH_TYPE_EXACT_ONLY = 1;
+ public static final int TERM_MATCH_TYPE_PREFIX = 2;
+
+ /** Builder for {@link SearchSpec objects}. */
+ public static final class Builder {
+
+ private final SearchSpecProto.Builder mBuilder = SearchSpecProto.newBuilder();
+
+ 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);
+ }
+ mBuilder.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.
+ */
+ @NonNull
+ public Builder setSchemaTypes(@NonNull String... schemaTypes) {
+ for (String schemaType : schemaTypes) {
+ mBuilder.addSchemaTypeFilters(schemaType);
+ }
+ return this;
+ }
+
+ /**
+ * Constructs a new {@link SearchSpec} from the contents of this builder.
+ *
+ * <p>After calling this method, the builder must no longer be used.
+ */
+ @NonNull
+ public SearchSpec build() {
+ if (mBuilder.getTermMatchType() == TermMatchType.Code.UNKNOWN) {
+ throw new IllegalSearchSpecException("Missing termMatchType field.");
+ }
+ return new SearchSpec(mBuilder.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 ce7e04c..f63abd9 100644
--- a/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java
+++ b/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * 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.
@@ -15,6 +15,7 @@
*/
package com.android.server.appsearch;
+import android.annotation.NonNull;
import android.app.appsearch.IAppSearchManager;
import android.content.Context;
import android.os.Binder;
@@ -24,9 +25,13 @@
import com.android.internal.util.Preconditions;
import com.android.server.SystemService;
import com.android.server.appsearch.impl.AppSearchImpl;
+import com.android.server.appsearch.impl.FakeIcing;
import com.android.server.appsearch.impl.ImplInstanceManager;
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.protobuf.InvalidProtocolBufferException;
/**
* TODO(b/142567528): add comments when implement this class
@@ -35,8 +40,11 @@
public AppSearchManagerService(Context context) {
super(context);
+ mFakeIcing = new FakeIcing();
}
+ private final FakeIcing mFakeIcing;
+
@Override
public void onStart() {
publishBinderService(Context.APP_SEARCH_SERVICE, new Stub());
@@ -70,5 +78,22 @@
callback.completeExceptionally(t);
}
}
+ // 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);
+ Preconditions.checkNotNull(searchSpec);
+ SearchSpecProto searchSpecProto = null;
+ try {
+ searchSpecProto = SearchSpecProto.parseFrom(searchSpec);
+ } catch (InvalidProtocolBufferException e) {
+ throw new RuntimeException(e);
+ }
+ SearchResultProto searchResults =
+ mFakeIcing.query(queryExpression);
+ callback.complete(searchResults.toByteArray());
+ }
}
}
diff --git a/api/current.txt b/api/current.txt
index e27c318..d9c305a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -39750,8 +39750,8 @@
field public static final String EXTRA_INPUT_METHOD_ID = "input_method_id";
field public static final String EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME = "android.provider.extra.NOTIFICATION_LISTENER_COMPONENT_NAME";
field public static final String EXTRA_SUB_ID = "android.provider.extra.SUB_ID";
- field public static final String EXTRA_WIFI_CONFIGURATION_LIST = "android.provider.extra.WIFI_CONFIGURATION_LIST";
- field public static final String EXTRA_WIFI_CONFIGURATION_RESULT_LIST = "android.provider.extra.WIFI_CONFIGURATION_RESULT_LIST";
+ field public static final String EXTRA_WIFI_NETWORK_LIST = "android.provider.extra.WIFI_NETWORK_LIST";
+ field public static final String EXTRA_WIFI_NETWORK_RESULT_LIST = "android.provider.extra.WIFI_NETWORK_RESULT_LIST";
field public static final String INTENT_CATEGORY_USAGE_ACCESS_CONFIG = "android.intent.category.USAGE_ACCESS_CONFIG";
field public static final String METADATA_USAGE_ACCESS_REASON = "android.settings.metadata.USAGE_ACCESS_REASON";
}
@@ -55697,7 +55697,7 @@
method public int describeContents();
method @NonNull public android.os.Bundle getExtras();
method @NonNull public java.util.Collection<android.view.textclassifier.TextLinks.TextLink> getLinks();
- method @NonNull public String getText();
+ method @NonNull public CharSequence getText();
method public void writeToParcel(android.os.Parcel, int);
field public static final int APPLY_STRATEGY_IGNORE = 0; // 0x0
field public static final int APPLY_STRATEGY_REPLACE = 1; // 0x1
diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java
index d23754e..7ab85a4 100644
--- a/core/java/android/app/ResourcesManager.java
+++ b/core/java/android/app/ResourcesManager.java
@@ -1208,8 +1208,7 @@
WeakReference<ResourcesImpl> weakImplRef = mResourceImpls.valueAt(i);
ResourcesImpl r = weakImplRef != null ? weakImplRef.get() : null;
if (r != null) {
- applyConfigurationToResourcesLocked(config, compat, tmpConfig,
- defaultDisplayMetrics, key, r);
+ applyConfigurationToResourcesLocked(config, compat, tmpConfig, key, r);
} else {
mResourceImpls.removeAt(i);
}
@@ -1224,8 +1223,7 @@
}
applyConfigurationToResourcesLocked(config, compat, tmpConfig,
- defaultDisplayMetrics, resourcesWithLoaders.resourcesKey(),
- resources.getImpl());
+ resourcesWithLoaders.resourcesKey(), resources.getImpl());
}
return changes != 0;
@@ -1236,40 +1234,33 @@
private void applyConfigurationToResourcesLocked(@NonNull Configuration config,
@Nullable CompatibilityInfo compat, Configuration tmpConfig,
- DisplayMetrics defaultDisplayMetrics, ResourcesKey key, ResourcesImpl resourcesImpl) {
+ ResourcesKey key, ResourcesImpl resourcesImpl) {
if (DEBUG || DEBUG_CONFIGURATION) {
Slog.v(TAG, "Changing resources "
+ resourcesImpl + " config to: " + config);
}
int displayId = key.mDisplayId;
- boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
- DisplayMetrics dm = defaultDisplayMetrics;
final boolean hasOverrideConfiguration = key.hasOverrideConfiguration();
- if (!isDefaultDisplay || hasOverrideConfiguration) {
- tmpConfig.setTo(config);
+ tmpConfig.setTo(config);
- // Get new DisplayMetrics based on the DisplayAdjustments given
- // to the ResourcesImpl. Update a copy if the CompatibilityInfo
- // changed, because the ResourcesImpl object will handle the
- // update internally.
- DisplayAdjustments daj = resourcesImpl.getDisplayAdjustments();
- if (compat != null) {
- daj = new DisplayAdjustments(daj);
- daj.setCompatibilityInfo(compat);
- }
- dm = getDisplayMetrics(displayId, daj);
-
- if (!isDefaultDisplay) {
- applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
- }
-
- if (hasOverrideConfiguration) {
- tmpConfig.updateFrom(key.mOverrideConfiguration);
- }
- resourcesImpl.updateConfiguration(tmpConfig, dm, compat);
- } else {
- resourcesImpl.updateConfiguration(config, dm, compat);
+ // Get new DisplayMetrics based on the DisplayAdjustments given to the ResourcesImpl. Update
+ // a copy if the CompatibilityInfo changed, because the ResourcesImpl object will handle the
+ // update internally.
+ DisplayAdjustments daj = resourcesImpl.getDisplayAdjustments();
+ if (compat != null) {
+ daj = new DisplayAdjustments(daj);
+ daj.setCompatibilityInfo(compat);
}
+ daj.setConfiguration(config);
+ DisplayMetrics dm = getDisplayMetrics(displayId, daj);
+ if (displayId != Display.DEFAULT_DISPLAY) {
+ applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
+ }
+
+ if (hasOverrideConfiguration) {
+ tmpConfig.updateFrom(key.mOverrideConfiguration);
+ }
+ resourcesImpl.updateConfiguration(tmpConfig, dm, compat);
}
/**
diff --git a/core/java/android/app/servertransaction/TransactionExecutorHelper.java b/core/java/android/app/servertransaction/TransactionExecutorHelper.java
index 6df92a7..a34be5c 100644
--- a/core/java/android/app/servertransaction/TransactionExecutorHelper.java
+++ b/core/java/android/app/servertransaction/TransactionExecutorHelper.java
@@ -75,9 +75,15 @@
mLifecycleSequence.clear();
if (finish >= start) {
- // just go there
- for (int i = start + 1; i <= finish; i++) {
- mLifecycleSequence.add(i);
+ if (start == ON_START && finish == ON_STOP) {
+ // A case when we from start to stop state soon, we don't need to go
+ // through the resumed, paused state.
+ mLifecycleSequence.add(ON_STOP);
+ } else {
+ // just go there
+ for (int i = start + 1; i <= finish; i++) {
+ mLifecycleSequence.add(i);
+ }
}
} else { // finish < start, can't just cycle down
if (start == ON_PAUSE && finish == ON_RESUME) {
diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java
index 799dff9..fb5f136 100644
--- a/core/java/android/hardware/display/DisplayManager.java
+++ b/core/java/android/hardware/display/DisplayManager.java
@@ -26,6 +26,7 @@
import android.app.KeyguardManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.Point;
import android.media.projection.MediaProjection;
import android.os.Handler;
@@ -400,10 +401,10 @@
if (display == null) {
// TODO: We cannot currently provide any override configurations for metrics on displays
// other than the display the context is associated with.
- final Context context = mContext.getDisplayId() == displayId
- ? mContext : mContext.getApplicationContext();
+ final Resources resources = mContext.getDisplayId() == displayId
+ ? mContext.getResources() : null;
- display = mGlobal.getCompatibleDisplay(displayId, context.getResources());
+ display = mGlobal.getCompatibleDisplay(displayId, resources);
if (display != null) {
mDisplays.put(displayId, display);
}
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index f6633201..1d759af 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -14360,46 +14360,74 @@
/**
* Activity Action: Show setting page to process the addition of Wi-Fi networks to the user's
- * saved network list. The app should send a new intent with an extra that holds a maximum of
- * five {@link android.net.wifi.WifiConfiguration} that specify credentials for the networks to
- * be added to the user's database. The Intent should be sent via the {@link
- * android.app.Activity#startActivityForResult(Intent, int)} API.
+ * saved network list. The app should send a new intent with an extra that holds a maximum
+ * of five {@link android.net.wifi.WifiNetworkSuggestion} that specify credentials for the
+ * networks to be added to the user's database. The Intent should be sent via the
+ * {@link android.app.Activity#startActivityForResult(Intent, int)} API.
* <p>
* Note: The app sending the Intent to add the credentials doesn't get any ownership over the
* newly added network(s). For the Wi-Fi stack, these networks will look like the user
* manually added them from the Settings UI.
* <p>
- * Input: The app should put parcelable array list to
- * {@link android.net.wifi.WifiConfiguration} into the
- * {@link #EXTRA_WIFI_CONFIGURATION_LIST} extra.
+ * Input: The app should put parcelable array list of
+ * {@link android.net.wifi.WifiNetworkSuggestion} into the {@link #EXTRA_WIFI_NETWORK_LIST}
+ * extra.
* <p>
* Output: After {@link android.app.Activity#startActivityForResult(Intent, int)}, the
* callback {@link android.app.Activity#onActivityResult(int, int, Intent)} will have a
* result code {@link android.app.Activity#RESULT_OK} to indicate user pressed the save
* button to save the networks or {@link android.app.Activity#RESULT_CANCELED} to indicate
* that the user rejected the request. Additionally, an integer array list, stored in
- * {@link #EXTRA_WIFI_CONFIGURATION_RESULT_LIST}, will indicate the process result of
- * each network.
+ * {@link #EXTRA_WIFI_NETWORK_RESULT_LIST}, will indicate the process result of each network.
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_WIFI_ADD_NETWORKS =
"android.settings.WIFI_ADD_NETWORKS";
/**
- * A bundle extra of {@link #ACTION_WIFI_ADD_NETWORKS} intent action that indicates all the
- * {@link android.net.wifi.WifiConfiguration} that would be saved.
+ * A bundle extra of {@link #ACTION_WIFI_ADD_NETWORKS} intent action that indicates the list
+ * of the {@link android.net.wifi.WifiNetworkSuggestion} elements. The maximum count of the
+ * {@link android.net.wifi.WifiNetworkSuggestion} elements in the list will be five.
+ * <p>
+ * For example:
+ * To provide credentials for one open and one WPA2 networks:
+ *
+ * <pre>{@code
+ * final WifiNetworkSuggestion suggestion1 =
+ * new WifiNetworkSuggestion.Builder()
+ * .setSsid("test111111")
+ * .build();
+ * final WifiNetworkSuggestion suggestion2 =
+ * new WifiNetworkSuggestion.Builder()
+ * .setSsid("test222222")
+ * .setWpa2Passphrase("test123456")
+ * .build();
+ * final List<WifiNetworkSuggestion> suggestionsList = new ArrayList<>;
+ * suggestionsList.add(suggestion1);
+ * suggestionsList.add(suggestion2);
+ * Bundle bundle = new Bundle();
+ * bundle.putParcelableArrayList(Settings.EXTRA_WIFI_NETWORK_LIST,(ArrayList<? extends
+ * Parcelable>) suggestionsList);
+ * final Intent intent = new Intent(Settings.ACTION_WIFI_ADD_NETWORKS);
+ * intent.putExtras(bundle);
+ * startActivityForResult(intent, 0);
+ * }</pre>
*/
- public static final String EXTRA_WIFI_CONFIGURATION_LIST =
- "android.provider.extra.WIFI_CONFIGURATION_LIST";
+ public static final String EXTRA_WIFI_NETWORK_LIST =
+ "android.provider.extra.WIFI_NETWORK_LIST";
/**
* A bundle extra of the result of {@link #ACTION_WIFI_ADD_NETWORKS} intent action that
- * indicates the action result of the saved {@link android.net.wifi.WifiConfiguration}. It's
- * value of AddWifiResult interface, and will be 1:1 mapping to the element in {@link
- * #EXTRA_WIFI_CONFIGURATION_LIST}.
+ * indicates the action result of the saved {@link android.net.wifi.WifiNetworkSuggestion}.
+ * Its value is a list of integers, and all the elements will be 1:1 mapping to the elements
+ * in {@link #EXTRA_WIFI_NETWORK_LIST}, if user press cancel to cancel the add networks
+ * request, then its value will be null.
+ * <p>
+ * Note: The integer value will be one of the {@link #ADD_WIFI_RESULT_SUCCESS},
+ * {@link #ADD_WIFI_RESULT_ADD_OR_UPDATE_FAILED}, or {@link #ADD_WIFI_RESULT_ALREADY_EXISTS}}.
*/
- public static final String EXTRA_WIFI_CONFIGURATION_RESULT_LIST =
- "android.provider.extra.WIFI_CONFIGURATION_RESULT_LIST";
+ public static final String EXTRA_WIFI_NETWORK_RESULT_LIST =
+ "android.provider.extra.WIFI_NETWORK_RESULT_LIST";
/** @hide */
@Retention(RetentionPolicy.SOURCE)
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index 178b3c0..904c510 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -454,7 +454,7 @@
mResources = res;
mDisplayAdjustments = mResources != null
? new DisplayAdjustments(mResources.getConfiguration())
- : daj != null ? new DisplayAdjustments(daj) : null;
+ : daj != null ? new DisplayAdjustments(daj) : new DisplayAdjustments();
mIsValid = true;
// Cache properties that cannot change as long as the display is valid.
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index 3dfeffb..9cbba87 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -1444,6 +1444,29 @@
return null;
}
+ /**
+ *
+ * Sets an {@link IWindowMagnificationConnection} that manipulates window magnification.
+ *
+ * @param connection The connection that manipulates window magnification.
+ * @hide
+ */
+ public void setWindowMagnificationConnection(@Nullable
+ IWindowMagnificationConnection connection) {
+ final IAccessibilityManager service;
+ synchronized (mLock) {
+ service = getServiceLocked();
+ if (service == null) {
+ return;
+ }
+ }
+ try {
+ service.setWindowMagnificationConnection(connection);
+ } catch (RemoteException re) {
+ Log.e(LOG_TAG, "Error setting window magnfication connection", re);
+ }
+ }
+
private IAccessibilityManager getServiceLocked() {
if (mService == null) {
tryConnectToServiceLocked(null);
diff --git a/core/java/android/view/accessibility/IAccessibilityManager.aidl b/core/java/android/view/accessibility/IAccessibilityManager.aidl
index fcaaa2e..7f8fdf8 100644
--- a/core/java/android/view/accessibility/IAccessibilityManager.aidl
+++ b/core/java/android/view/accessibility/IAccessibilityManager.aidl
@@ -25,6 +25,7 @@
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.IAccessibilityInteractionConnection;
import android.view.accessibility.IAccessibilityManagerClient;
+import android.view.accessibility.IWindowMagnificationConnection;
import android.view.IWindow;
/**
@@ -86,4 +87,5 @@
oneway void registerSystemAction(in RemoteAction action, int actionId);
oneway void unregisterSystemAction(int actionId);
+ oneway void setWindowMagnificationConnection(in IWindowMagnificationConnection connection);
}
diff --git a/core/java/android/view/accessibility/IWindowMagnificationConnection.aidl b/core/java/android/view/accessibility/IWindowMagnificationConnection.aidl
new file mode 100644
index 0000000..0b45c6b
--- /dev/null
+++ b/core/java/android/view/accessibility/IWindowMagnificationConnection.aidl
@@ -0,0 +1,75 @@
+/*
+ * 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.view.accessibility;
+
+import android.graphics.PointF;
+import android.graphics.Rect;
+import android.view.accessibility.IWindowMagnificationConnectionCallback;
+
+/**
+ * Interface for interaction between {@link AccessibilityManagerService}
+ * and {@link WindowMagnification} in SystemUI.
+ *
+ * @hide
+ */
+oneway interface IWindowMagnificationConnection {
+
+ /**
+ * Enables window magnification on specifed display with specified center and scale.
+ *
+ * @param displayId The logical display id.
+ * @param scale magnification scale.
+ * @param centerX the screen-relative X coordinate around which to center,
+ * or {@link Float#NaN} to leave unchanged.
+ * @param centerY the screen-relative Y coordinate around which to center,
+ * or {@link Float#NaN} to leave unchanged.
+ */
+ void enableWindowMagnification(int displayId, float scale, float centerX, float centerY);
+
+ /**
+ * Sets the scale of the window magnifier on specifed display.
+ *
+ * @param displayId The logical display id.
+ * @param scale magnification scale.
+ */
+ void setScale(int displayId, float scale);
+
+ /**
+ * Disables window magnification on specifed display.
+ *
+ * @param displayId The logical display id.
+ */
+ void disableWindowMagnification(int displayId);
+
+ /**
+ * Moves the window magnifier on the specifed display.
+ *
+ * @param offsetX the amount in pixels to offset the window magnifier in the X direction, in
+ * current screen pixels.
+ * @param offsetY the amount in pixels to offset the window magnifier in the Y direction, in
+ * current screen pixels.
+ */
+ void moveWindowMagnifier(int displayId, float offsetX, float offsetY);
+
+ /**
+ * Sets {@link IWindowMagnificationConnectionCallback} to receive the request or the callback.
+ *
+ *
+ * @param callback the interface to be called.
+ */
+ void setConnectionCallback(in IWindowMagnificationConnectionCallback callback);
+}
diff --git a/core/java/android/view/accessibility/IWindowMagnificationConnectionCallback.aidl b/core/java/android/view/accessibility/IWindowMagnificationConnectionCallback.aidl
new file mode 100644
index 0000000..7327bb5
--- /dev/null
+++ b/core/java/android/view/accessibility/IWindowMagnificationConnectionCallback.aidl
@@ -0,0 +1,44 @@
+/*
+ * 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.view.accessibility;
+
+import android.graphics.Rect;
+
+/**
+ * interface to notify the change of the window magnifier bounds and request to change
+ * the magnification mode.
+ *
+ * @hide
+ */
+ oneway interface IWindowMagnificationConnectionCallback {
+
+ /**
+ * Called when the bounds of the window magnifier is changed.
+ *
+ * @param displayId The logical display id.
+ * @param bounds The window magnifier bounds in screen coordinates.
+ */
+ void onWindowMagnifierBoundsChanged(int display, in Rect bounds);
+ /**
+ * Changes the magnification mode on specified display. It is invoked by System UI when the
+ * switch button is toggled.
+ *
+ * @param displayId The logical display id.
+ * @param magnificationMode new magnification mode.
+ */
+ void onChangeMagnificationMode(int display, int magnificationMode);
+}
diff --git a/core/java/android/view/textclassifier/TextLinks.java b/core/java/android/view/textclassifier/TextLinks.java
index 1aa2aec..bda12b0 100644
--- a/core/java/android/view/textclassifier/TextLinks.java
+++ b/core/java/android/view/textclassifier/TextLinks.java
@@ -113,7 +113,7 @@
* Returns the text that was used to generate these links.
*/
@NonNull
- public String getText() {
+ public CharSequence getText() {
return mFullText;
}
@@ -370,8 +370,8 @@
}
/**
- * @return ordered list of locale preferences that can be used to disambiguate
- * the provided text
+ * Returns an ordered list of locale preferences that can be used to disambiguate the
+ * provided text.
*/
@Nullable
public LocaleList getDefaultLocales() {
@@ -379,7 +379,8 @@
}
/**
- * @return The config representing the set of entities to look for
+ * Returns the config representing the set of entities to look for
+ *
* @see Builder#setEntityConfig(EntityConfig)
*/
@Nullable
@@ -398,8 +399,8 @@
}
/**
- * @return reference time based on which relative dates (e.g. "tomorrow") should be
- * interpreted.
+ * Returns reference time based on which relative dates (e.g. "tomorrow") should be
+ * interpreted.
*/
@Nullable
public ZonedDateTime getReferenceTime() {
@@ -473,6 +474,9 @@
}
/**
+ * Sets ordered list of locale preferences that may be used to disambiguate the
+ * provided text.
+ *
* @param defaultLocales ordered list of locale preferences that may be used to
* disambiguate the provided text. If no locale preferences exist,
* set this to null or an empty locale list.
@@ -524,9 +528,11 @@
}
/**
- * @param referenceTime reference time based on which relative dates (e.g. "tomorrow"
- * should be interpreted. This should usually be the time when the text was
- * originally composed.
+ * Sets the reference time based on which relative dates (e.g.
+ * "tomorrow") should be interpreted.
+ *
+ * @param referenceTime reference time based on which relative dates. This should
+ * usually be the time when the text was originally composed.
*
* @return this builder
*/
@@ -716,6 +722,8 @@
}
/**
+ * Adds a TextLink.
+ *
* @see #addLink(int, int, Map)
* @param urlSpan An optional URLSpan to delegate to. NOTE: Not parcelled.
*/
diff --git a/core/java/android/view/textclassifier/TextLinksParams.java b/core/java/android/view/textclassifier/TextLinksParams.java
index b7d63bf..f12b0d7 100644
--- a/core/java/android/view/textclassifier/TextLinksParams.java
+++ b/core/java/android/view/textclassifier/TextLinksParams.java
@@ -113,7 +113,7 @@
return TextLinks.STATUS_UNSUPPORTED_CHARACTER;
}
- if (!textString.startsWith(textLinks.getText())) {
+ if (!textString.startsWith(textLinks.getText().toString())) {
return TextLinks.STATUS_DIFFERENT_TEXT;
}
if (textLinks.getLinks().isEmpty()) {
diff --git a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java
index 3fdedc8..93659a4 100644
--- a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java
+++ b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java
@@ -371,7 +371,9 @@
// targets during boot. Needs to read settings directly here.
String shortcutTargets = Settings.Secure.getStringForUser(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, mUserId);
- if (TextUtils.isEmpty(shortcutTargets)) {
+ // A11y warning dialog updates settings to empty string, when user disables a11y shortcut.
+ // Only fallback to default a11y service, when setting is never updated.
+ if (shortcutTargets == null) {
shortcutTargets = mContext.getString(R.string.config_defaultAccessibilityService);
}
return !TextUtils.isEmpty(shortcutTargets);
diff --git a/core/tests/coretests/src/android/app/appsearch/SearchResultsTest.java b/core/tests/coretests/src/android/app/appsearch/SearchResultsTest.java
new file mode 100644
index 0000000..21259cc
--- /dev/null
+++ b/core/tests/coretests/src/android/app/appsearch/SearchResultsTest.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.app.appsearch;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.testng.Assert.assertThrows;
+
+import androidx.test.filters.SmallTest;
+
+import com.google.android.icing.proto.DocumentProto;
+import com.google.android.icing.proto.SearchResultProto;
+
+import org.junit.Test;
+
+@SmallTest
+public class SearchResultsTest {
+
+ @Test
+ public void testSearchResultsEqual() {
+ final String uri = "testUri";
+ final String schemaType = "testSchema";
+ SearchResultProto.ResultProto result1 = SearchResultProto.ResultProto.newBuilder()
+ .setDocument(DocumentProto.newBuilder()
+ .setUri(uri)
+ .setSchema(schemaType)
+ .build())
+ .build();
+ SearchResultProto searchResults1 = SearchResultProto.newBuilder()
+ .addResults(result1)
+ .build();
+ SearchResults res1 = new SearchResults(searchResults1);
+ SearchResultProto.ResultProto result2 = SearchResultProto.ResultProto.newBuilder()
+ .setDocument(DocumentProto.newBuilder()
+ .setUri(uri)
+ .setSchema(schemaType)
+ .build())
+ .build();
+ SearchResultProto searchResults2 = SearchResultProto.newBuilder()
+ .addResults(result2)
+ .build();
+ SearchResults res2 = new SearchResults(searchResults2);
+ assertThat(res1.toString()).isEqualTo(res2.toString());
+ }
+
+ @Test
+ public void buildSearchSpecWithoutTermMatchType() {
+ assertThrows(RuntimeException.class, () -> SearchSpec.newBuilder()
+ .setSchemaTypes("testSchemaType")
+ .build());
+ }
+}
diff --git a/core/tests/coretests/src/android/app/servertransaction/TransactionExecutorTests.java b/core/tests/coretests/src/android/app/servertransaction/TransactionExecutorTests.java
index 1410f4f..09ea1b1 100644
--- a/core/tests/coretests/src/android/app/servertransaction/TransactionExecutorTests.java
+++ b/core/tests/coretests/src/android/app/servertransaction/TransactionExecutorTests.java
@@ -124,7 +124,7 @@
assertArrayEquals(new int[] {}, path(ON_START));
assertArrayEquals(new int[] {ON_RESUME}, path(ON_RESUME));
assertArrayEquals(new int[] {ON_RESUME, ON_PAUSE}, path(ON_PAUSE));
- assertArrayEquals(new int[] {ON_RESUME, ON_PAUSE, ON_STOP}, path(ON_STOP));
+ assertArrayEquals(new int[] {ON_STOP}, path(ON_STOP));
assertArrayEquals(new int[] {ON_RESUME, ON_PAUSE, ON_STOP, ON_DESTROY}, path(ON_DESTROY));
}
@@ -362,7 +362,9 @@
public void testClosestStateResolutionFromOnStart() {
mClientRecord.setState(ON_START);
assertEquals(ON_RESUME, mExecutorHelper.getClosestOfStates(mClientRecord, shuffledArray(
- new int[] {ON_CREATE, ON_RESUME, ON_PAUSE, ON_STOP, ON_DESTROY})));
+ new int[] {ON_CREATE, ON_RESUME, ON_PAUSE, ON_DESTROY})));
+ assertEquals(ON_STOP, mExecutorHelper.getClosestOfStates(mClientRecord, shuffledArray(
+ new int[] {ON_STOP})));
assertEquals(ON_CREATE, mExecutorHelper.getClosestOfStates(mClientRecord, shuffledArray(
new int[] {ON_CREATE})));
}
diff --git a/core/tests/coretests/src/android/view/accessibility/AccessibilityManagerTest.java b/core/tests/coretests/src/android/view/accessibility/AccessibilityManagerTest.java
index e23c51e..8e24907 100644
--- a/core/tests/coretests/src/android/view/accessibility/AccessibilityManagerTest.java
+++ b/core/tests/coretests/src/android/view/accessibility/AccessibilityManagerTest.java
@@ -46,6 +46,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
@@ -193,4 +194,15 @@
}
});
}
+
+ @Test
+ public void testSetWindowMagnificationConnection() throws Exception {
+ AccessibilityManager manager = createManager(WITH_A11Y_ENABLED);
+ IWindowMagnificationConnection connection = Mockito.mock(
+ IWindowMagnificationConnection.class);
+
+ manager.setWindowMagnificationConnection(connection);
+
+ verify(mMockService).setWindowMagnificationConnection(connection);
+ }
}
diff --git a/media/java/android/media/IMediaRoute2Provider.aidl b/media/java/android/media/IMediaRoute2Provider.aidl
index aa38e51..a25aff6 100644
--- a/media/java/android/media/IMediaRoute2Provider.aidl
+++ b/media/java/android/media/IMediaRoute2Provider.aidl
@@ -18,13 +18,15 @@
import android.content.Intent;
import android.media.IMediaRoute2ProviderClient;
+import android.os.Bundle;
/**
* {@hide}
*/
oneway interface IMediaRoute2Provider {
void setClient(IMediaRoute2ProviderClient client);
- void requestCreateSession(String packageName, String routeId, long requestId);
+ void requestCreateSession(String packageName, String routeId, long requestId,
+ in @nullable Bundle sessionHints);
void releaseSession(String sessionId);
void selectRoute(String sessionId, String routeId);
diff --git a/media/java/android/media/IMediaRouterService.aidl b/media/java/android/media/IMediaRouterService.aidl
index b435f25..281e7c6b 100644
--- a/media/java/android/media/IMediaRouterService.aidl
+++ b/media/java/android/media/IMediaRouterService.aidl
@@ -24,6 +24,7 @@
import android.media.MediaRouterClientState;
import android.media.RouteDiscoveryPreference;
import android.media.RoutingSessionInfo;
+import android.os.Bundle;
/**
* {@hide}
@@ -52,7 +53,8 @@
void requestSetVolume2(IMediaRouter2Client client, in MediaRoute2Info route, int volume);
void requestUpdateVolume2(IMediaRouter2Client client, in MediaRoute2Info route, int direction);
- void requestCreateSession(IMediaRouter2Client client, in MediaRoute2Info route, int requestId);
+ void requestCreateSession(IMediaRouter2Client client, in MediaRoute2Info route, int requestId,
+ in @nullable Bundle sessionHints);
void setDiscoveryRequest2(IMediaRouter2Client client, in RouteDiscoveryPreference preference);
void selectRoute(IMediaRouter2Client client, String sessionId, in MediaRoute2Info route);
void deselectRoute(IMediaRouter2Client client, String sessionId, in MediaRoute2Info route);
diff --git a/media/java/android/media/MediaRoute2ProviderService.java b/media/java/android/media/MediaRoute2ProviderService.java
index 1443538..6bfa851 100644
--- a/media/java/android/media/MediaRoute2ProviderService.java
+++ b/media/java/android/media/MediaRoute2ProviderService.java
@@ -161,8 +161,8 @@
* @param sessionInfo information of the new session.
* The {@link RoutingSessionInfo#getId() id} of the session must be unique.
* @param requestId id of the previous request to create this session provided in
- * {@link #onCreateSession(String, String, long)}
- * @see #onCreateSession(String, String, long)
+ * {@link #onCreateSession(String, String, long, Bundle)}
+ * @see #onCreateSession(String, String, long, Bundle)
* @hide
*/
public final void notifySessionCreated(@NonNull RoutingSessionInfo sessionInfo,
@@ -195,8 +195,8 @@
* Notifies clients of that the session could not be created.
*
* @param requestId id of the previous request to create the session provided in
- * {@link #onCreateSession(String, String, long)}.
- * @see #onCreateSession(String, String, long)
+ * {@link #onCreateSession(String, String, long, Bundle)}.
+ * @see #onCreateSession(String, String, long, Bundle)
* @hide
*/
public final void notifySessionCreationFailed(long requestId) {
@@ -289,6 +289,9 @@
* @param packageName the package name of the application that selected the route
* @param routeId the id of the route initially being connected
* @param requestId the id of this session creation request
+ * @param sessionHints an optional bundle of app-specific arguments sent by
+ * {@link MediaRouter2}, or null if none. The contents of this bundle
+ * may affect the result of session creation.
*
* @see RoutingSessionInfo.Builder#Builder(String, String)
* @see RoutingSessionInfo.Builder#addSelectedRoute(String)
@@ -296,7 +299,7 @@
* @hide
*/
public abstract void onCreateSession(@NonNull String packageName, @NonNull String routeId,
- long requestId);
+ long requestId, @Nullable Bundle sessionHints);
/**
* Called when the session should be released. A client of the session or system can request
@@ -431,12 +434,14 @@
}
@Override
- public void requestCreateSession(String packageName, String routeId, long requestId) {
+ public void requestCreateSession(String packageName, String routeId, long requestId,
+ @Nullable Bundle requestCreateSession) {
if (!checkCallerisSystem()) {
return;
}
mHandler.sendMessage(obtainMessage(MediaRoute2ProviderService::onCreateSession,
- MediaRoute2ProviderService.this, packageName, routeId, requestId));
+ MediaRoute2ProviderService.this, packageName, routeId, requestId,
+ requestCreateSession));
}
@Override
diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java
index 971b08d..51d08ec 100644
--- a/media/java/android/media/MediaRouter2.java
+++ b/media/java/android/media/MediaRouter2.java
@@ -92,6 +92,7 @@
@GuardedBy("sRouterLock")
private boolean mShouldUpdateRoutes;
private volatile List<MediaRoute2Info> mFilteredRoutes = Collections.emptyList();
+ private volatile OnCreateSessionListener mOnCreateSessionListener;
/**
* Gets an instance of the media router associated with the context.
@@ -281,6 +282,19 @@
}
/**
+ * Sets an {@link OnCreateSessionListener} to send hints when creating a session.
+ * To send the hints, listener should be set <em>BEFORE</em> calling
+ * {@link #requestCreateSession(MediaRoute2Info)}.
+ *
+ * @param listener A listener to send optional app-specific hints when creating a session.
+ * {@code null} for unset.
+ * @hide
+ */
+ public void setOnCreateSessionListener(@Nullable OnCreateSessionListener listener) {
+ mOnCreateSessionListener = listener;
+ }
+
+ /**
* Requests the media route provider service to create a session with the given route.
*
* @param route the route you want to create a session with.
@@ -300,13 +314,24 @@
SessionCreationRequest request = new SessionCreationRequest(requestId, route);
mSessionCreationRequests.add(request);
+
+ OnCreateSessionListener listener = mOnCreateSessionListener;
+ Bundle sessionHints = null;
+ if (listener != null) {
+ sessionHints = listener.onCreateSession(route);
+ if (sessionHints != null) {
+ sessionHints = new Bundle(sessionHints);
+ }
+ }
+
Client2 client;
synchronized (sRouterLock) {
client = mClient;
}
if (client != null) {
try {
- mMediaRouterService.requestCreateSession(client, route, requestId);
+ mMediaRouterService.requestCreateSession(client, route, requestId,
+ sessionHints);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to request to create session.", ex);
mHandler.sendMessage(obtainMessage(MediaRouter2::createControllerOnHandler,
@@ -707,6 +732,34 @@
}
/**
+ * A listener interface to send an optional app-specific hints when creating a session.
+ *
+ * @hide
+ */
+ public interface OnCreateSessionListener {
+ /**
+ * Called when the {@link MediaRouter2} is about to request
+ * the media route provider service to create a session with the given route.
+ * The {@link Bundle} returned here will be sent to media route provider service as a hint
+ * for creating a session.
+ * <p>
+ * To send hints when creating the session, set this listener before calling
+ * {@link #requestCreateSession(MediaRoute2Info)}.
+ * <p>
+ * This will be called on the same thread which calls
+ * {@link #requestCreateSession(MediaRoute2Info)}.
+ *
+ * @param route The route to create session with
+ * @return An optional bundle of app-specific arguments to send to the provider,
+ * or null if none. The contents of this bundle may affect the result of
+ * session creation.
+ * @see MediaRoute2ProviderService#onCreateSession(String, String, long, Bundle)
+ */
+ @Nullable
+ Bundle onCreateSession(@NonNull MediaRoute2Info route);
+ }
+
+ /**
* A class to control media routing session in media route provider.
* For example, selecting/deselcting/transferring routes to session can be done through this
* class. Instances are created by {@link MediaRouter2}.
diff --git a/media/tests/MediaRouteProvider/src/com/android/mediarouteprovider/example/SampleMediaRoute2ProviderService.java b/media/tests/MediaRouteProvider/src/com/android/mediarouteprovider/example/SampleMediaRoute2ProviderService.java
index d3b5826..6595cae 100644
--- a/media/tests/MediaRouteProvider/src/com/android/mediarouteprovider/example/SampleMediaRoute2ProviderService.java
+++ b/media/tests/MediaRouteProvider/src/com/android/mediarouteprovider/example/SampleMediaRoute2ProviderService.java
@@ -19,10 +19,12 @@
import static android.media.MediaRoute2Info.DEVICE_TYPE_REMOTE_SPEAKER;
import static android.media.MediaRoute2Info.DEVICE_TYPE_REMOTE_TV;
+import android.annotation.Nullable;
import android.content.Intent;
import android.media.MediaRoute2Info;
import android.media.MediaRoute2ProviderService;
import android.media.RoutingSessionInfo;
+import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
@@ -167,7 +169,8 @@
}
@Override
- public void onCreateSession(String packageName, String routeId, long requestId) {
+ public void onCreateSession(String packageName, String routeId, long requestId,
+ @Nullable Bundle sessionHints) {
MediaRoute2Info route = mRoutes.get(routeId);
if (route == null || TextUtils.equals(ROUTE_ID3_SESSION_CREATION_FAILED, routeId)) {
// Tell the router that session cannot be created by passing null as sessionInfo.
@@ -188,6 +191,8 @@
.addSelectedRoute(routeId)
.addSelectableRoute(ROUTE_ID4_TO_SELECT_AND_DESELECT)
.addTransferrableRoute(ROUTE_ID5_TO_TRANSFER_TO)
+ // Set control hints with given sessionHints
+ .setControlHints(sessionHints)
.build();
notifySessionCreated(sessionInfo, requestId);
publishRoutes();
diff --git a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2Test.java b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2Test.java
index e782aae..32d03db 100644
--- a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2Test.java
+++ b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouter2Test.java
@@ -43,12 +43,14 @@
import android.content.Context;
import android.media.MediaRoute2Info;
import android.media.MediaRouter2;
+import android.media.MediaRouter2.OnCreateSessionListener;
import android.media.MediaRouter2.RouteCallback;
import android.media.MediaRouter2.RoutingController;
import android.media.MediaRouter2.SessionCallback;
import android.media.RouteDiscoveryPreference;
import android.media.RoutingSessionInfo;
import android.net.Uri;
+import android.os.Bundle;
import android.os.Parcel;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
@@ -80,6 +82,9 @@
private static final int TIMEOUT_MS = 5000;
+ private static final String TEST_KEY = "test_key";
+ private static final String TEST_VALUE = "test_value";
+
@Before
public void setUp() throws Exception {
mContext = InstrumentationRegistry.getTargetContext();
@@ -328,6 +333,74 @@
}
@Test
+ public void testSetOnCreateSessionListener() throws Exception {
+ final List<String> sampleRouteFeature = new ArrayList<>();
+ sampleRouteFeature.add(FEATURE_SAMPLE);
+
+ Map<String, MediaRoute2Info> routes = waitAndGetRoutes(sampleRouteFeature);
+ MediaRoute2Info route = routes.get(ROUTE_ID1);
+ assertNotNull(route);
+
+ final Bundle createSessionHints = new Bundle();
+ createSessionHints.putString(TEST_KEY, TEST_VALUE);
+ final OnCreateSessionListener listener = new OnCreateSessionListener() {
+ @Override
+ public Bundle onCreateSession(MediaRoute2Info route) {
+ return createSessionHints;
+ }
+ };
+
+ final CountDownLatch successLatch = new CountDownLatch(1);
+ final CountDownLatch failureLatch = new CountDownLatch(1);
+ final List<RoutingController> controllers = new ArrayList<>();
+
+ // Create session with this route
+ SessionCallback sessionCallback = new SessionCallback() {
+ @Override
+ public void onSessionCreated(RoutingController controller) {
+ assertNotNull(controller);
+ assertTrue(createRouteMap(controller.getSelectedRoutes()).containsKey(ROUTE_ID1));
+
+ // The SampleMediaRoute2ProviderService supposed to set control hints
+ // with the given creationSessionHints.
+ Bundle controlHints = controller.getControlHints();
+ assertNotNull(controlHints);
+ assertTrue(controlHints.containsKey(TEST_KEY));
+ assertEquals(TEST_VALUE, controlHints.getString(TEST_KEY));
+
+ controllers.add(controller);
+ successLatch.countDown();
+ }
+
+ @Override
+ public void onSessionCreationFailed(MediaRoute2Info requestedRoute) {
+ failureLatch.countDown();
+ }
+ };
+
+ // TODO: Remove this once the MediaRouter2 becomes always connected to the service.
+ RouteCallback routeCallback = new RouteCallback();
+ mRouter2.registerRouteCallback(mExecutor, routeCallback, RouteDiscoveryPreference.EMPTY);
+
+ try {
+ mRouter2.registerSessionCallback(mExecutor, sessionCallback);
+
+ // The SampleMediaRoute2ProviderService supposed to set control hints
+ // with the given creationSessionHints.
+ mRouter2.setOnCreateSessionListener(listener);
+ mRouter2.requestCreateSession(route);
+ assertTrue(successLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
+
+ // onSessionCreationFailed should not be called.
+ assertFalse(failureLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
+ } finally {
+ releaseControllers(controllers);
+ mRouter2.unregisterRouteCallback(routeCallback);
+ mRouter2.unregisterSessionCallback(sessionCallback);
+ }
+ }
+
+ @Test
public void testSessionCallbackIsNotCalledAfterUnregistered() throws Exception {
final List<String> sampleRouteType = new ArrayList<>();
sampleRouteType.add(FEATURE_SAMPLE);
diff --git a/packages/SystemUI/res/layout/tv_audio_recording_indicator.xml b/packages/SystemUI/res/layout/tv_audio_recording_indicator.xml
index f04226e..cd90efe 100644
--- a/packages/SystemUI/res/layout/tv_audio_recording_indicator.xml
+++ b/packages/SystemUI/res/layout/tv_audio_recording_indicator.xml
@@ -32,8 +32,8 @@
android:orientation="horizontal">
<FrameLayout
- android:layout_width="90dp"
- android:layout_height="94dp">
+ android:layout_width="45dp"
+ android:layout_height="47dp">
<View
android:id="@+id/icon_container_bg"
@@ -43,35 +43,34 @@
<FrameLayout
android:id="@+id/icon_mic"
- android:layout_width="70dp"
- android:layout_height="70dp"
- android:layout_marginLeft="12dp"
- android:layout_marginTop="12dp"
- android:layout_marginRight="8dp"
- android:layout_marginBottom="12dp">
+ android:layout_width="35dp"
+ android:layout_height="35dp"
+ android:layout_marginLeft="6dp"
+ android:layout_marginTop="6dp"
+ android:layout_marginBottom="6dp">
<View
- android:layout_width="54dp"
- android:layout_height="54dp"
+ android:layout_width="27dp"
+ android:layout_height="27dp"
android:layout_gravity="center"
android:background="@drawable/tv_circle_dark"/>
<ImageView
android:id="@+id/pulsating_circle"
- android:layout_width="54dp"
- android:layout_height="54dp"
+ android:layout_width="27dp"
+ android:layout_height="27dp"
android:layout_gravity="center"
android:background="@drawable/tv_circle_white_translucent"/>
<ImageView
- android:layout_width="54dp"
- android:layout_height="54dp"
+ android:layout_width="27dp"
+ android:layout_height="27dp"
android:layout_gravity="center"
android:src="@drawable/tv_ring_white"/>
<ImageView
- android:layout_width="32dp"
- android:layout_height="32dp"
+ android:layout_width="16dp"
+ android:layout_height="16dp"
android:layout_gravity="center"
android:background="@drawable/tv_ic_mic_white"/>
</FrameLayout>
@@ -81,29 +80,30 @@
<LinearLayout
android:id="@+id/texts_container"
android:layout_width="wrap_content"
- android:layout_height="94dp"
+ android:layout_height="47dp"
android:background="@color/tv_audio_recording_indicator_background"
- android:gravity="center_vertical"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_height="14dp"
+ android:layout_marginTop="10dp"
+ android:layout_marginBottom="1dp"
android:text="@string/mic_active"
android:textColor="@android:color/white"
android:fontFamily="sans-serif"
- android:textSize="20dp"/>
+ android:textSize="10dp"/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_height="14dp"
android:singleLine="true"
android:text="SomeApplication accessed your microphone"
android:textColor="@android:color/white"
android:fontFamily="sans-serif"
- android:textSize="16dp"/>
+ android:textSize="8dp"/>
</LinearLayout>
@@ -113,8 +113,8 @@
<View
android:id="@+id/bg_right"
- android:layout_width="24dp"
- android:layout_height="94dp"
+ android:layout_width="12dp"
+ android:layout_height="47dp"
android:background="@drawable/tv_rect_dark_right_rounded"
android:visibility="visible"/>
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index c9fdd5a..f3a415e 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -94,6 +94,7 @@
import android.view.accessibility.IAccessibilityInteractionConnection;
import android.view.accessibility.IAccessibilityManager;
import android.view.accessibility.IAccessibilityManagerClient;
+import android.view.accessibility.IWindowMagnificationConnection;
import com.android.internal.R;
import com.android.internal.accessibility.AccessibilityShortcutController;
@@ -106,6 +107,7 @@
import com.android.internal.util.IntPair;
import com.android.server.LocalServices;
import com.android.server.SystemService;
+import com.android.server.accessibility.magnification.WindowMagnificationManager;
import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.WindowManagerInternal;
@@ -204,6 +206,8 @@
private AccessibilityInputFilter mInputFilter;
+ private WindowMagnificationManager mWindowMagnificationMgr;
+
private boolean mHasInputFilter;
private KeyEventDispatcher mKeyEventDispatcher;
@@ -877,11 +881,8 @@
*/
@Override
public void notifyAccessibilityButtonVisibilityChanged(boolean shown) {
- if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE)
- != PackageManager.PERMISSION_GRANTED) {
- throw new SecurityException("Caller does not hold permission "
- + android.Manifest.permission.STATUS_BAR_SERVICE);
- }
+ mSecurityPolicy.enforceCallingOrSelfPermission(
+ android.Manifest.permission.STATUS_BAR_SERVICE);
synchronized (mLock) {
notifyAccessibilityButtonVisibilityChangedLocked(shown);
}
@@ -1883,11 +1884,12 @@
}
private boolean readAccessibilityShortcutKeySettingLocked(AccessibilityUserState userState) {
+ final String settingValue = Settings.Secure.getStringForUser(mContext.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, userState.mUserId);
final Set<String> targetsFromSetting = new ArraySet<>();
- readColonDelimitedSettingToSet(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
- userState.mUserId, targetsFromSetting, str -> str);
- if (targetsFromSetting.isEmpty()) {
- // Fall back to device's default a11y service.
+ readColonDelimitedStringToSet(settingValue, targetsFromSetting, false, str -> str);
+ // Fall back to device's default a11y service, only when setting is never updated.
+ if (settingValue == null) {
final String defaultService = mContext.getString(
R.string.config_defaultAccessibilityService);
if (!TextUtils.isEmpty(defaultService)) {
@@ -2588,6 +2590,24 @@
}
@Override
+ public void setWindowMagnificationConnection(
+ IWindowMagnificationConnection connection) throws RemoteException {
+ mSecurityPolicy.enforceCallingOrSelfPermission(
+ android.Manifest.permission.STATUS_BAR_SERVICE);
+
+ getWindowMagnificationMgr().setConnection(connection);
+ }
+
+ WindowMagnificationManager getWindowMagnificationMgr() {
+ synchronized (mLock) {
+ if (mWindowMagnificationMgr == null) {
+ mWindowMagnificationMgr = new WindowMagnificationManager();
+ }
+ return mWindowMagnificationMgr;
+ }
+ }
+
+ @Override
public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, LOG_TAG, pw)) return;
synchronized (mLock) {
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilitySecurityPolicy.java b/services/accessibility/java/com/android/server/accessibility/AccessibilitySecurityPolicy.java
index 7dbec7c..7a42cd1 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilitySecurityPolicy.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilitySecurityPolicy.java
@@ -550,4 +550,17 @@
Binder.restoreCallingIdentity(identityToken);
}
}
+
+ /**
+ * Enforcing permission check to IPC caller or grant it if it's not through IPC.
+ *
+ * @param permission The permission to check
+ */
+ public void enforceCallingOrSelfPermission(@NonNull String permission) {
+ if (mContext.checkCallingOrSelfPermission(permission)
+ != PackageManager.PERMISSION_GRANTED) {
+ throw new SecurityException("Caller does not hold permission "
+ + permission);
+ }
+ }
}
diff --git a/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationConnectionWrapper.java b/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationConnectionWrapper.java
new file mode 100644
index 0000000..351c9e0
--- /dev/null
+++ b/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationConnectionWrapper.java
@@ -0,0 +1,110 @@
+/*
+ * 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.accessibility.magnification;
+
+import static android.os.IBinder.DeathRecipient;
+
+import android.annotation.NonNull;
+import android.os.RemoteException;
+import android.util.Slog;
+import android.view.accessibility.IWindowMagnificationConnection;
+import android.view.accessibility.IWindowMagnificationConnectionCallback;
+
+/**
+ * A wrapper of {@link IWindowMagnificationConnection}.
+ */
+class WindowMagnificationConnectionWrapper {
+
+ private static final boolean DBG = false;
+ private static final String TAG = "WindowMagnificationConnectionWrapper";
+
+ private final @NonNull IWindowMagnificationConnection mConnection;
+
+ WindowMagnificationConnectionWrapper(@NonNull IWindowMagnificationConnection connection) {
+ mConnection = connection;
+ }
+
+ //Should not use this instance anymore after calling it.
+ void unlinkToDeath(@NonNull DeathRecipient deathRecipient) {
+ mConnection.asBinder().unlinkToDeath(deathRecipient, 0);
+ }
+
+ void linkToDeath(@NonNull DeathRecipient deathRecipient) throws RemoteException {
+ mConnection.asBinder().linkToDeath(deathRecipient, 0);
+ }
+
+ boolean enableWindowMagnification(int displayId, float scale, float centerX, float centerY) {
+ try {
+ mConnection.enableWindowMagnification(displayId, scale, centerX, centerY);
+ } catch (RemoteException e) {
+ if (DBG) {
+ Slog.e(TAG, "Error calling enableWindowMagnification()");
+ }
+ return false;
+ }
+ return true;
+ }
+
+ boolean setScale(int displayId, float scale) {
+ try {
+ mConnection.setScale(displayId, scale);
+ } catch (RemoteException e) {
+ if (DBG) {
+ Slog.e(TAG, "Error calling setScale()");
+ }
+ return false;
+ }
+ return true;
+ }
+
+ boolean disableWindowMagnification(int displayId) {
+ try {
+ mConnection.disableWindowMagnification(displayId);
+ } catch (RemoteException e) {
+ if (DBG) {
+ Slog.e(TAG, "Error calling disableWindowMagnification()");
+ }
+ return false;
+ }
+ return true;
+ }
+
+ boolean moveWindowMagnifier(int displayId, float offsetX, float offsetY) {
+ try {
+ mConnection.moveWindowMagnifier(displayId, offsetX, offsetY);
+ } catch (RemoteException e) {
+ if (DBG) {
+ Slog.e(TAG, "Error calling moveWindowMagnifier()");
+ }
+ return false;
+ }
+ return true;
+ }
+
+ boolean setConnectionCallback(IWindowMagnificationConnectionCallback connectionCallback) {
+ try {
+ mConnection.setConnectionCallback(connectionCallback);
+ } catch (RemoteException e) {
+ if (DBG) {
+ Slog.e(TAG, "Error calling setConnectionCallback()");
+ }
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationManager.java b/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationManager.java
new file mode 100644
index 0000000..00db3294
--- /dev/null
+++ b/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationManager.java
@@ -0,0 +1,98 @@
+/*
+ * 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.accessibility.magnification;
+
+import android.annotation.Nullable;
+import android.graphics.Rect;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Slog;
+import android.view.accessibility.IWindowMagnificationConnection;
+import android.view.accessibility.IWindowMagnificationConnectionCallback;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+/**
+ * A class to manipulate window magnification through {@link WindowMagnificationConnectionWrapper}.
+ */
+public final class WindowMagnificationManager {
+
+ private static final String TAG = "WindowMagnificationMgr";
+ private final Object mLock = new Object();
+ @VisibleForTesting
+ @Nullable WindowMagnificationConnectionWrapper mConnectionWrapper;
+ private ConnectionCallback mConnectionCallback;
+
+ /**
+ * Sets {@link IWindowMagnificationConnection}.
+ * @param connection {@link IWindowMagnificationConnection}
+ */
+ public void setConnection(@Nullable IWindowMagnificationConnection connection) {
+ synchronized (mLock) {
+ //Reset connectionWrapper.
+ if (mConnectionWrapper != null) {
+ mConnectionWrapper.setConnectionCallback(null);
+ if (mConnectionCallback != null) {
+ mConnectionCallback.mExpiredDeathRecipient = true;
+ }
+ mConnectionWrapper.unlinkToDeath(mConnectionCallback);
+ mConnectionWrapper = null;
+ }
+ if (connection != null) {
+ mConnectionWrapper = new WindowMagnificationConnectionWrapper(connection);
+ }
+
+ if (mConnectionWrapper != null) {
+ try {
+ mConnectionCallback = new ConnectionCallback();
+ mConnectionWrapper.linkToDeath(mConnectionCallback);
+ mConnectionWrapper.setConnectionCallback(mConnectionCallback);
+ } catch (RemoteException e) {
+ Slog.e(TAG, "setConnection failed", e);
+ mConnectionWrapper = null;
+ }
+ }
+ }
+ }
+
+ private class ConnectionCallback extends IWindowMagnificationConnectionCallback.Stub implements
+ IBinder.DeathRecipient {
+ private boolean mExpiredDeathRecipient = false;
+
+ @Override
+ public void onWindowMagnifierBoundsChanged(int display, Rect frame) throws RemoteException {
+ }
+
+ @Override
+ public void onChangeMagnificationMode(int display, int magnificationMode)
+ throws RemoteException {
+ }
+
+ @Override
+ public void binderDied() {
+ synchronized (mLock) {
+ if (mExpiredDeathRecipient) {
+ Slog.w(TAG, "binderDied DeathRecipient is expired");
+ return;
+ }
+ mConnectionWrapper.unlinkToDeath(this);
+ mConnectionWrapper = null;
+ mConnectionCallback = null;
+ }
+ }
+ }
+}
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index c1e23e4..5e495b9 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -39,6 +39,7 @@
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN;
import static android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY;
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
+import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_VPN;
import static android.net.NetworkPolicyManager.RULE_NONE;
import static android.net.NetworkPolicyManager.uidRulesToString;
@@ -5840,11 +5841,6 @@
} else {
newNc.addCapability(NET_CAPABILITY_FOREGROUND);
}
- if (nai.isSuspended()) {
- newNc.removeCapability(NET_CAPABILITY_NOT_SUSPENDED);
- } else {
- newNc.addCapability(NET_CAPABILITY_NOT_SUSPENDED);
- }
if (nai.partialConnectivity) {
newNc.addCapability(NET_CAPABILITY_PARTIAL_CONNECTIVITY);
} else {
@@ -5852,6 +5848,11 @@
}
newNc.setPrivateDnsBroken(nai.networkCapabilities.isPrivateDnsBroken());
+ // TODO : remove this once all factories are updated to send NOT_SUSPENDED
+ if (!newNc.hasTransport(TRANSPORT_CELLULAR)) {
+ newNc.addCapability(NET_CAPABILITY_NOT_SUSPENDED);
+ }
+
return newNc;
}
@@ -5896,6 +5897,17 @@
// on this network. We might have been called by rematchNetworkAndRequests when a
// network changed foreground state.
processListenRequests(nai);
+ final boolean prevSuspended = !prevNc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED);
+ final boolean suspended = !newNc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED);
+ if (prevSuspended != suspended) {
+ // TODO (b/73132094) : remove this call once the few users of onSuspended and
+ // onResumed have been removed.
+ notifyNetworkCallbacks(nai, suspended ? ConnectivityManager.CALLBACK_SUSPENDED
+ : ConnectivityManager.CALLBACK_RESUMED);
+ // updateNetworkInfo will mix in the suspended info from the capabilities and
+ // take appropriate action for the network having possibly changed state.
+ updateNetworkInfo(nai, nai.networkInfo);
+ }
} else {
// If the requestable capabilities have changed or the score changed, we can't have been
// called by rematchNetworkAndRequests, so it's safe to start a rematch.
@@ -5903,6 +5915,9 @@
notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_CAP_CHANGED);
}
+ // TODO : static analysis indicates that prevNc can't be null here (getAndSetNetworkCaps
+ // never returns null), so mark the relevant members and functions in nai as @NonNull and
+ // remove this test
if (prevNc != null) {
final boolean oldMetered = prevNc.isMetered();
final boolean newMetered = newNc.isMetered();
@@ -6597,10 +6612,30 @@
}
}
- private void updateNetworkInfo(NetworkAgentInfo networkAgent, NetworkInfo newInfo) {
+ @NonNull
+ private NetworkInfo mixInInfo(@NonNull final NetworkAgentInfo nai, @NonNull NetworkInfo info) {
+ final NetworkInfo newInfo = new NetworkInfo(info);
+ // The suspended bit is managed in NetworkCapabilities.
+ final boolean suspended =
+ !nai.networkCapabilities.hasCapability(NET_CAPABILITY_NOT_SUSPENDED);
+ if (suspended && info.getDetailedState() == NetworkInfo.DetailedState.CONNECTED) {
+ // Only override the state with SUSPENDED if the network is currently in CONNECTED
+ // state. This is because the network could have been suspended before connecting,
+ // or it could be disconnecting while being suspended, and in both these cases
+ // the state should not be overridden. Note that the only detailed state that
+ // maps to State.CONNECTED is DetailedState.CONNECTED, so there is also no need to
+ // worry about multiple different substates of CONNECTED.
+ newInfo.setDetailedState(NetworkInfo.DetailedState.SUSPENDED, info.getReason(),
+ info.getExtraInfo());
+ }
+ return newInfo;
+ }
+
+ private void updateNetworkInfo(NetworkAgentInfo networkAgent, NetworkInfo info) {
+ final NetworkInfo newInfo = mixInInfo(networkAgent, info);
+
final NetworkInfo.State state = newInfo.getState();
NetworkInfo oldInfo = null;
- final int oldScore = networkAgent.getCurrentScore();
synchronized (networkAgent) {
oldInfo = networkAgent.networkInfo;
networkAgent.networkInfo = newInfo;
@@ -6682,17 +6717,6 @@
}
} else if (networkAgent.created && (oldInfo.getState() == NetworkInfo.State.SUSPENDED ||
state == NetworkInfo.State.SUSPENDED)) {
- // going into or coming out of SUSPEND: re-score and notify
- if (networkAgent.getCurrentScore() != oldScore) {
- rematchAllNetworksAndRequests();
- }
- updateCapabilities(networkAgent.getCurrentScore(), networkAgent,
- networkAgent.networkCapabilities);
- // TODO (b/73132094) : remove this call once the few users of onSuspended and
- // onResumed have been removed.
- notifyNetworkCallbacks(networkAgent, (state == NetworkInfo.State.SUSPENDED ?
- ConnectivityManager.CALLBACK_SUSPENDED :
- ConnectivityManager.CALLBACK_RESUMED));
mLegacyTypeTracker.update(networkAgent);
}
}
diff --git a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
index c1ab551..d66aec5 100644
--- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
+++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java
@@ -451,15 +451,6 @@
&& !isLingering();
}
- /**
- * Returns whether this network is currently suspended. A network is suspended if it is still
- * connected but data temporarily fails to transfer. See {@link NetworkInfo.State#SUSPENDED}
- * and {@link NetworkCapabilities#NET_CAPABILITY_NOT_SUSPENDED}.
- */
- public boolean isSuspended() {
- return networkInfo.getState() == NetworkInfo.State.SUSPENDED;
- }
-
// Does this network satisfy request?
public boolean satisfies(NetworkRequest request) {
return created &&
diff --git a/services/core/java/com/android/server/media/MediaRoute2Provider.java b/services/core/java/com/android/server/media/MediaRoute2Provider.java
index b186771..1cd8aad 100644
--- a/services/core/java/com/android/server/media/MediaRoute2Provider.java
+++ b/services/core/java/com/android/server/media/MediaRoute2Provider.java
@@ -22,6 +22,7 @@
import android.content.Intent;
import android.media.MediaRoute2ProviderInfo;
import android.media.RoutingSessionInfo;
+import android.os.Bundle;
import com.android.internal.annotations.GuardedBy;
@@ -49,7 +50,8 @@
mCallback = callback;
}
- public abstract void requestCreateSession(String packageName, String routeId, long requestId);
+ public abstract void requestCreateSession(String packageName, String routeId, long requestId,
+ @Nullable Bundle sessionHints);
public abstract void releaseSession(String sessionId);
public abstract void selectRoute(String sessionId, String routeId);
diff --git a/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java b/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java
index 4b992be..9761461 100644
--- a/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java
+++ b/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java
@@ -26,6 +26,7 @@
import android.media.MediaRoute2ProviderInfo;
import android.media.MediaRoute2ProviderService;
import android.media.RoutingSessionInfo;
+import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
@@ -73,9 +74,11 @@
}
@Override
- public void requestCreateSession(String packageName, String routeId, long requestId) {
+ public void requestCreateSession(String packageName, String routeId, long requestId,
+ Bundle sessionHints) {
if (mConnectionReady) {
- mActiveConnection.requestCreateSession(packageName, routeId, requestId);
+ mActiveConnection.requestCreateSession(
+ packageName, routeId, requestId, sessionHints);
updateBinding();
}
}
@@ -427,9 +430,10 @@
mClient.dispose();
}
- public void requestCreateSession(String packageName, String routeId, long requestId) {
+ public void requestCreateSession(String packageName, String routeId, long requestId,
+ Bundle sessionHints) {
try {
- mProvider.requestCreateSession(packageName, routeId, requestId);
+ mProvider.requestCreateSession(packageName, routeId, requestId, sessionHints);
} catch (RemoteException ex) {
Slog.e(TAG, "Failed to deliver request to create a session.", ex);
}
diff --git a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
index 6e3154c..f023085 100644
--- a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
+++ b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
@@ -178,14 +178,14 @@
}
public void requestCreateSession(IMediaRouter2Client client, MediaRoute2Info route,
- int requestId) {
+ int requestId, Bundle sessionHints) {
Objects.requireNonNull(client, "client must not be null");
Objects.requireNonNull(route, "route must not be null");
final long token = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
- requestCreateSessionLocked(client, route, requestId);
+ requestCreateSessionLocked(client, route, requestId, sessionHints);
}
} finally {
Binder.restoreCallingIdentity(token);
@@ -494,7 +494,7 @@
}
private void requestCreateSessionLocked(@NonNull IMediaRouter2Client client,
- @NonNull MediaRoute2Info route, long requestId) {
+ @NonNull MediaRoute2Info route, long requestId, @Nullable Bundle sessionHints) {
final IBinder binder = client.asBinder();
final Client2Record clientRecord = mAllClientRecords.get(binder);
@@ -506,7 +506,8 @@
if (clientRecord != null) {
clientRecord.mUserRecord.mHandler.sendMessage(
obtainMessage(UserHandler::requestCreateSessionOnHandler,
- clientRecord.mUserRecord.mHandler, clientRecord, route, requestId));
+ clientRecord.mUserRecord.mHandler,
+ clientRecord, route, requestId, sessionHints));
}
}
@@ -665,9 +666,9 @@
}
long uniqueRequestId = toUniqueRequestId(managerRecord.mClientId, requestId);
if (clientRecord != null && managerRecord.mTrusted) {
- //TODO: select route feature properly
+ //TODO: Use client's OnCreateSessionListener to send proper session hints.
requestCreateSessionLocked(clientRecord.mClient, route,
- uniqueRequestId);
+ uniqueRequestId, null /* sessionHints */);
}
}
}
@@ -1121,7 +1122,7 @@
}
private void requestCreateSessionOnHandler(Client2Record clientRecord,
- MediaRoute2Info route, long requestId) {
+ MediaRoute2Info route, long requestId, @Nullable Bundle sessionHints) {
final MediaRoute2Provider provider = findProvider(route.getProviderId());
if (provider == null) {
@@ -1137,7 +1138,7 @@
mSessionCreationRequests.add(request);
provider.requestCreateSession(clientRecord.mPackageName, route.getOriginalId(),
- requestId);
+ requestId, sessionHints);
}
private void selectRouteOnHandler(@NonNull Client2Record clientRecord,
diff --git a/services/core/java/com/android/server/media/MediaRouterService.java b/services/core/java/com/android/server/media/MediaRouterService.java
index b33f5aa..5437fad 100644
--- a/services/core/java/com/android/server/media/MediaRouterService.java
+++ b/services/core/java/com/android/server/media/MediaRouterService.java
@@ -42,6 +42,7 @@
import android.media.RouteDiscoveryPreference;
import android.media.RoutingSessionInfo;
import android.os.Binder;
+import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -460,8 +461,8 @@
// Binder call
@Override
public void requestCreateSession(IMediaRouter2Client client, MediaRoute2Info route,
- int requestId) {
- mService2.requestCreateSession(client, route, requestId);
+ int requestId, Bundle sessionHints) {
+ mService2.requestCreateSession(client, route, requestId, sessionHints);
}
// Binder call
diff --git a/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java b/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
index 3759ba9..56c33fe 100644
--- a/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
+++ b/services/core/java/com/android/server/media/SystemMediaRoute2Provider.java
@@ -26,6 +26,7 @@
import android.media.IAudioService;
import android.media.MediaRoute2Info;
import android.media.MediaRoute2ProviderInfo;
+import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
@@ -96,7 +97,8 @@
}
@Override
- public void requestCreateSession(String packageName, String routeId, long requestId) {
+ public void requestCreateSession(String packageName, String routeId, long requestId,
+ Bundle sessionHints) {
// Do nothing
}
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 3f3408f..b596d2a 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -1680,6 +1680,7 @@
if (root == this) {
task.setRootProcess(proc);
}
+ proc.addActivityIfNeeded(this);
}
boolean hasProcess() {
@@ -6918,7 +6919,7 @@
// Update last reported values.
final Configuration newMergedOverrideConfig = getMergedOverrideConfiguration();
- setLastReportedConfiguration(mAtmService.getGlobalConfiguration(), newMergedOverrideConfig);
+ setLastReportedConfiguration(getProcessGlobalConfiguration(), newMergedOverrideConfig);
if (mState == INITIALIZING) {
// No need to relaunch or schedule new config for activity that hasn't been launched
@@ -7017,6 +7018,11 @@
return true;
}
+ /** Get process configuration, or global config if the process is not set. */
+ private Configuration getProcessGlobalConfiguration() {
+ return app != null ? app.getConfiguration() : mAtmService.getGlobalConfiguration();
+ }
+
/**
* When assessing a configuration change, decide if the changes flags and the new configurations
* should cause the Activity to relaunch.
@@ -7129,7 +7135,7 @@
startRelaunching();
final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(pendingResults,
pendingNewIntents, configChangeFlags,
- new MergedConfiguration(mAtmService.getGlobalConfiguration(),
+ new MergedConfiguration(getProcessGlobalConfiguration(),
getMergedOverrideConfiguration()),
preserveWindow);
final ActivityLifecycleItem lifecycleItem;
diff --git a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
index aa90248..0a68408 100644
--- a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
@@ -848,8 +848,6 @@
if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r);
- proc.addActivityIfNeeded(r);
-
final LockTaskController lockTaskController = mService.getLockTaskController();
if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE
|| task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index e308f6b..47e8b87 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -6743,7 +6743,7 @@
return;
}
process.mIsImeProcess = true;
- process.registerDisplayConfigurationListenerLocked(displayContent);
+ process.registerDisplayConfigurationListener(displayContent);
}
}
diff --git a/services/core/java/com/android/server/wm/ConfigurationContainer.java b/services/core/java/com/android/server/wm/ConfigurationContainer.java
index 1e60ce8..7b23e2d 100644
--- a/services/core/java/com/android/server/wm/ConfigurationContainer.java
+++ b/services/core/java/com/android/server/wm/ConfigurationContainer.java
@@ -134,8 +134,8 @@
resolveOverrideConfiguration(newParentConfig);
mFullConfiguration.setTo(newParentConfig);
mFullConfiguration.updateFrom(mResolvedOverrideConfiguration);
+ onMergedOverrideConfigurationChanged();
if (!mResolvedTmpConfig.equals(mResolvedOverrideConfiguration)) {
- onMergedOverrideConfigurationChanged();
// This depends on the assumption that change-listeners don't do
// their own override resolution. This way, dependent hierarchies
// can stay properly synced-up with a primary hierarchy's constraints.
@@ -147,6 +147,10 @@
mResolvedOverrideConfiguration);
}
}
+ for (int i = mChangeListeners.size() - 1; i >= 0; --i) {
+ mChangeListeners.get(i).onMergedOverrideConfigurationChanged(
+ mMergedOverrideConfiguration);
+ }
if (forwardToChildren) {
for (int i = getChildCount() - 1; i >= 0; --i) {
final ConfigurationContainer child = getChildAt(i);
@@ -545,6 +549,7 @@
}
mChangeListeners.add(listener);
listener.onRequestedOverrideConfigurationChanged(mResolvedOverrideConfiguration);
+ listener.onMergedOverrideConfigurationChanged(mMergedOverrideConfiguration);
}
void unregisterConfigurationChangeListener(ConfigurationContainerListener listener) {
diff --git a/services/core/java/com/android/server/wm/ConfigurationContainerListener.java b/services/core/java/com/android/server/wm/ConfigurationContainerListener.java
index dc4939d..3d84e17 100644
--- a/services/core/java/com/android/server/wm/ConfigurationContainerListener.java
+++ b/services/core/java/com/android/server/wm/ConfigurationContainerListener.java
@@ -24,5 +24,8 @@
public interface ConfigurationContainerListener {
/** {@see ConfigurationContainer#onRequestedOverrideConfigurationChanged} */
- void onRequestedOverrideConfigurationChanged(Configuration overrideConfiguration);
+ default void onRequestedOverrideConfigurationChanged(Configuration overrideConfiguration) {}
+
+ /** Called when new merged override configuration is reported. */
+ default void onMergedOverrideConfigurationChanged(Configuration mergedOverrideConfiguration) {}
}
diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java
index 9a40b1b1..ceb38f7 100644
--- a/services/core/java/com/android/server/wm/WindowProcessController.java
+++ b/services/core/java/com/android/server/wm/WindowProcessController.java
@@ -17,6 +17,7 @@
package com.android.server.wm;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.os.Build.VERSION_CODES.Q;
import static android.view.Display.INVALID_DISPLAY;
@@ -178,8 +179,10 @@
// Last configuration that was reported to the process.
private final Configuration mLastReportedConfiguration;
+ private final Configuration mNewOverrideConfig = new Configuration();
// Registered display id as a listener to override config change
private int mDisplayId;
+ private ActivityRecord mConfigActivityRecord;
/** Whether our process is currently running a {@link RecentsAnimation} */
private boolean mRunningRecentsAnimation;
@@ -327,6 +330,12 @@
return mDisplayId != INVALID_DISPLAY;
}
+ /** @return {@code true} if the process registered to an activity as a config listener. */
+ @VisibleForTesting
+ boolean registeredForActivityConfigChanges() {
+ return mConfigActivityRecord != null;
+ }
+
void postPendingUiCleanMsg(boolean pendingUiClean) {
if (mListener == null) return;
// Posting on handler so WM lock isn't held when we call into AM.
@@ -483,7 +492,10 @@
@Override
protected ConfigurationContainer getParent() {
- return null;
+ // Returning RootWindowContainer as the parent, so that this process controller always
+ // has full configuration and overrides (e.g. from display) are always added on top of
+ // global config.
+ return mAtm.mRootWindowContainer;
}
@HotPath(caller = HotPath.PROCESS_CHANGE)
@@ -507,10 +519,12 @@
return;
}
mActivities.add(r);
+ updateActivityConfigurationListener();
}
void removeActivity(ActivityRecord r) {
mActivities.remove(r);
+ updateActivityConfigurationListener();
}
void makeFinishingForProcessRemoved() {
@@ -521,6 +535,7 @@
void clearActivities() {
mActivities.clear();
+ updateActivityConfigurationListener();
}
@HotPath(caller = HotPath.OOM_ADJUSTMENT)
@@ -964,19 +979,20 @@
mAtm.mH.sendMessage(m);
}
- void registerDisplayConfigurationListenerLocked(DisplayContent displayContent) {
+ void registerDisplayConfigurationListener(DisplayContent displayContent) {
if (displayContent == null) {
return;
}
- // A process can only register to one display to listener to the override configuration
+ // A process can only register to one display to listen to the override configuration
// change. Unregister existing listener if it has one before register the new one.
- unregisterDisplayConfigurationListenerLocked();
+ unregisterDisplayConfigurationListener();
+ unregisterActivityConfigurationListener();
mDisplayId = displayContent.mDisplayId;
displayContent.registerConfigurationChangeListener(this);
}
@VisibleForTesting
- void unregisterDisplayConfigurationListenerLocked() {
+ void unregisterDisplayConfigurationListener() {
if (mDisplayId == INVALID_DISPLAY) {
return;
}
@@ -986,6 +1002,48 @@
displayContent.unregisterConfigurationChangeListener(this);
}
mDisplayId = INVALID_DISPLAY;
+ onMergedOverrideConfigurationChanged(Configuration.EMPTY);
+ }
+
+ private void registerActivityConfigurationListener(ActivityRecord activityRecord) {
+ if (activityRecord == null) {
+ return;
+ }
+ // A process can only register to one activityRecord to listen to the override configuration
+ // change. Unregister existing listener if it has one before register the new one.
+ unregisterDisplayConfigurationListener();
+ unregisterActivityConfigurationListener();
+ mConfigActivityRecord = activityRecord;
+ activityRecord.registerConfigurationChangeListener(this);
+ }
+
+ private void unregisterActivityConfigurationListener() {
+ if (mConfigActivityRecord == null) {
+ return;
+ }
+ mConfigActivityRecord.unregisterConfigurationChangeListener(this);
+ mConfigActivityRecord = null;
+ onMergedOverrideConfigurationChanged(Configuration.EMPTY);
+ }
+
+ /**
+ * Check if activity configuration override for the activity process needs an update and perform
+ * if needed. By default we try to override the process configuration to match the top activity
+ * config to increase app compatibility with multi-window and multi-display. The process will
+ * always track the configuration of the non-finishing activity last added to the process.
+ */
+ private void updateActivityConfigurationListener() {
+ for (int i = mActivities.size() - 1; i >= 0; i--) {
+ final ActivityRecord activityRecord = mActivities.get(i);
+ if (!activityRecord.finishing && !activityRecord.containsListener(this)) {
+ // Eligible activity is found, update listener.
+ registerActivityConfigurationListener(activityRecord);
+ return;
+ }
+ }
+
+ // No eligible activities found, let's remove the configuration listener.
+ unregisterActivityConfigurationListener();
}
@Override
@@ -995,8 +1053,11 @@
}
@Override
- public void onRequestedOverrideConfigurationChanged(Configuration newOverrideConfig) {
- super.onRequestedOverrideConfigurationChanged(newOverrideConfig);
+ public void onMergedOverrideConfigurationChanged(Configuration mergedOverrideConfig) {
+ // Make sure that we don't accidentally override the activity type.
+ mNewOverrideConfig.setTo(mergedOverrideConfig);
+ mNewOverrideConfig.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
+ super.onRequestedOverrideConfigurationChanged(mNewOverrideConfig);
updateConfiguration();
}
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 36e9273..a4297416 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -3402,7 +3402,7 @@
"Reporting new frame to %s: %s", this,
mWindowFrames.mCompatFrame);
final MergedConfiguration mergedConfiguration =
- new MergedConfiguration(mWmService.mRoot.getConfiguration(),
+ new MergedConfiguration(getProcessGlobalConfiguration(),
getMergedOverrideConfiguration());
setLastReportedMergedConfiguration(mergedConfiguration);
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/magnification/WindowMagnificationConnectionWrapperTest.java b/services/tests/servicestests/src/com/android/server/accessibility/magnification/WindowMagnificationConnectionWrapperTest.java
new file mode 100644
index 0000000..09466e7
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/accessibility/magnification/WindowMagnificationConnectionWrapperTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.accessibility.magnification;
+
+
+import static org.mockito.Mockito.verify;
+
+import android.os.RemoteException;
+import android.view.Display;
+import android.view.accessibility.IWindowMagnificationConnection;
+import android.view.accessibility.IWindowMagnificationConnectionCallback;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Tests for WindowMagnificationConnectionWrapper. We don't test {@code
+ * WindowMagnificationConnectionWrapper#linkToDeath(IBinder.DeathRecipient)} since it's tested in
+ * {@link WindowMagnificationManagerTest}.
+ */
+public class WindowMagnificationConnectionWrapperTest {
+
+ private static final int TEST_DISPLAY = Display.DEFAULT_DISPLAY;
+
+ @Mock
+ private IWindowMagnificationConnection mConnection;
+ @Mock
+ private IWindowMagnificationConnectionCallback mCallback;
+ private WindowMagnificationConnectionWrapper mConnectionWrapper;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mConnectionWrapper = new WindowMagnificationConnectionWrapper(mConnection);
+ }
+
+ @Test
+ public void enableWindowMagnification() throws RemoteException {
+ mConnectionWrapper.enableWindowMagnification(TEST_DISPLAY, 2, 100f, 200f);
+ verify(mConnection).enableWindowMagnification(TEST_DISPLAY, 2, 100f, 200f);
+ }
+
+ @Test
+ public void setScale() throws RemoteException {
+ mConnectionWrapper.setScale(TEST_DISPLAY, 3.0f);
+ verify(mConnection).setScale(TEST_DISPLAY, 3.0f);
+ }
+
+ @Test
+ public void disableWindowMagnification() throws RemoteException {
+ mConnectionWrapper.disableWindowMagnification(TEST_DISPLAY);
+ verify(mConnection).disableWindowMagnification(TEST_DISPLAY);
+ }
+
+ @Test
+ public void moveWindowMagnifier() throws RemoteException {
+ mConnectionWrapper.moveWindowMagnifier(0, 100, 150);
+ verify(mConnection).moveWindowMagnifier(0, 100, 150);
+ }
+
+ @Test
+ public void setMirrorWindowCallback() throws RemoteException {
+ mConnectionWrapper.setConnectionCallback(mCallback);
+ verify(mConnection).setConnectionCallback(mCallback);
+ }
+
+}
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/magnification/WindowMagnificationManagerTest.java b/services/tests/servicestests/src/com/android/server/accessibility/magnification/WindowMagnificationManagerTest.java
new file mode 100644
index 0000000..780a6c0
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/accessibility/magnification/WindowMagnificationManagerTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.accessibility.magnification;
+
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.view.accessibility.IWindowMagnificationConnection;
+import android.view.accessibility.IWindowMagnificationConnectionCallback;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for WindowMagnificationManager.
+ */
+public class WindowMagnificationManagerTest {
+
+ private MockWindowMagnificationConnection mMockConnection;
+ private WindowMagnificationManager mWindowMagnificationManager;
+
+ @Before
+ public void setUp() {
+ mMockConnection = new MockWindowMagnificationConnection();
+ mWindowMagnificationManager = new WindowMagnificationManager();
+ }
+
+ @Test
+ public void setConnection_connectionIsNull_wrapperIsNullAndLinkToDeath() {
+ mWindowMagnificationManager.setConnection(mMockConnection.getConnection());
+ assertNotNull(mWindowMagnificationManager.mConnectionWrapper);
+ verify(mMockConnection.asBinder()).linkToDeath(any(IBinder.DeathRecipient.class), eq(0));
+ }
+
+ @Test
+ public void setConnection_connectionIsNull_setMirrorWindowCallbackAndHasWrapper()
+ throws RemoteException {
+ mWindowMagnificationManager.setConnection(mMockConnection.getConnection());
+
+ assertNotNull(mWindowMagnificationManager.mConnectionWrapper);
+ verify(mMockConnection.asBinder()).linkToDeath(any(IBinder.DeathRecipient.class), eq(0));
+ verify(mMockConnection.getConnection()).setConnectionCallback(
+ any(IWindowMagnificationConnectionCallback.class));
+ }
+
+ @Test
+ public void binderDied_hasConnection_wrapperIsNullAndUnlinkToDeath() {
+ mWindowMagnificationManager.setConnection(mMockConnection.getConnection());
+
+ mMockConnection.getDeathRecipient().binderDied();
+
+ assertNull(mWindowMagnificationManager.mConnectionWrapper);
+ verify(mMockConnection.asBinder()).unlinkToDeath(mMockConnection.getDeathRecipient(),
+ 0);
+ }
+
+ /**
+ * This test simulates {@link WindowMagnificationManager#setConnection} is called by thread A
+ * and then the former connection is called by thread B. In this situation we should keep the
+ * new connection.
+ */
+ @Test
+ public void
+ setSecondConnectionAndFormerConnectionBinderDead_hasWrapperAndNotCallUnlinkToDeath() {
+ mWindowMagnificationManager.setConnection(mMockConnection.getConnection());
+ MockWindowMagnificationConnection secondConnection =
+ new MockWindowMagnificationConnection();
+
+ mWindowMagnificationManager.setConnection(secondConnection.getConnection());
+ mMockConnection.getDeathRecipient().binderDied();
+
+ assertNotNull(mWindowMagnificationManager.mConnectionWrapper);
+ verify(mMockConnection.asBinder()).unlinkToDeath(mMockConnection.getDeathRecipient(), 0);
+ verify(secondConnection.asBinder(), never()).unlinkToDeath(
+ secondConnection.getDeathRecipient(), 0);
+ }
+
+ @Test
+ public void setNullConnection_hasConnection_wrapperIsNull() throws RemoteException {
+ mWindowMagnificationManager.setConnection(mMockConnection.getConnection());
+
+ mWindowMagnificationManager.setConnection(null);
+
+ assertNull(mWindowMagnificationManager.mConnectionWrapper);
+ verify(mMockConnection.getConnection()).setConnectionCallback(null);
+ }
+
+ private static class MockWindowMagnificationConnection {
+
+ private final IWindowMagnificationConnection mConnection;
+ private final Binder mBinder;
+ private IBinder.DeathRecipient mDeathRecipient;
+
+ MockWindowMagnificationConnection() {
+ mConnection = mock(IWindowMagnificationConnection.class);
+ mBinder = mock(Binder.class);
+ when(mConnection.asBinder()).thenReturn(mBinder);
+ doAnswer((invocation) -> {
+ mDeathRecipient = invocation.getArgument(0);
+ return null;
+ }).when(mBinder).linkToDeath(
+ any(IBinder.DeathRecipient.class), eq(0));
+ }
+
+ IWindowMagnificationConnection getConnection() {
+ return mConnection;
+ }
+
+ public IBinder.DeathRecipient getDeathRecipient() {
+ return mDeathRecipient;
+ }
+
+ Binder asBinder() {
+ return mBinder;
+ }
+ }
+}
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index a3e94599..ad63d07 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -16,6 +16,8 @@
package com.android.server.wm;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
+import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
@@ -56,6 +58,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -1175,4 +1178,160 @@
verify(mActivity).removeFromHistory(anyString());
}
+
+ @Test
+ public void testActivityOverridesProcessConfig() {
+ final WindowProcessController wpc = mActivity.app;
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertFalse(wpc.registeredForDisplayConfigChanges());
+
+ final ActivityRecord secondaryDisplayActivity =
+ createActivityOnDisplay(false /* defaultDisplay */, null /* process */);
+
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertEquals(0, mActivity.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ assertNotEquals(mActivity.getConfiguration(),
+ secondaryDisplayActivity.getConfiguration());
+ }
+
+ @Test
+ public void testActivityOverridesProcessConfig_TwoActivities() {
+ final WindowProcessController wpc = mActivity.app;
+ assertTrue(wpc.registeredForActivityConfigChanges());
+
+ final Task firstTaskRecord = mActivity.getTask();
+ final ActivityRecord secondActivityRecord =
+ new ActivityBuilder(mService).setTask(firstTaskRecord).setUseProcess(wpc).build();
+
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertEquals(0, secondActivityRecord.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ }
+
+ @Test
+ public void testActivityOverridesProcessConfig_TwoActivities_SecondaryDisplay() {
+ final WindowProcessController wpc = mActivity.app;
+ assertTrue(wpc.registeredForActivityConfigChanges());
+
+ final ActivityRecord secondActivityRecord =
+ new ActivityBuilder(mService).setTask(mTask).setUseProcess(wpc).build();
+
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertEquals(0, secondActivityRecord.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ }
+
+ @Test
+ public void testActivityOverridesProcessConfig_TwoActivities_DifferentTasks() {
+ final WindowProcessController wpc = mActivity.app;
+ assertTrue(wpc.registeredForActivityConfigChanges());
+
+ final ActivityRecord secondActivityRecord =
+ createActivityOnDisplay(true /* defaultDisplay */, wpc);
+
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertEquals(0, secondActivityRecord.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ }
+
+ @Test
+ public void testActivityOnDifferentDisplayUpdatesProcessOverride() {
+ final ActivityRecord secondaryDisplayActivity =
+ createActivityOnDisplay(false /* defaultDisplay */, null /* process */);
+ final WindowProcessController wpc = secondaryDisplayActivity.app;
+ assertTrue(wpc.registeredForActivityConfigChanges());
+
+ final ActivityRecord secondActivityRecord =
+ createActivityOnDisplay(true /* defaultDisplay */, wpc);
+
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertEquals(0, secondActivityRecord.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ assertFalse(wpc.registeredForDisplayConfigChanges());
+ }
+
+ @Test
+ public void testActivityReparentChangesProcessOverride() {
+ final WindowProcessController wpc = mActivity.app;
+ final Task initialTask = mActivity.getTask();
+ final Configuration initialConf =
+ new Configuration(mActivity.getMergedOverrideConfiguration());
+ assertEquals(0, mActivity.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ assertTrue(wpc.registeredForActivityConfigChanges());
+
+ // Create a new task with custom config to reparent the activity to.
+ final Task newTask =
+ new TaskBuilder(mSupervisor).setStack(initialTask.getStack()).build();
+ final Configuration newConfig = newTask.getConfiguration();
+ newConfig.densityDpi += 100;
+ newTask.onRequestedOverrideConfigurationChanged(newConfig);
+ assertEquals(newTask.getConfiguration().densityDpi, newConfig.densityDpi);
+
+ // Reparent the activity and verify that config override changed.
+ mActivity.reparent(newTask, 0 /* top */, "test");
+ assertEquals(mActivity.getConfiguration().densityDpi, newConfig.densityDpi);
+ assertEquals(mActivity.getMergedOverrideConfiguration().densityDpi, newConfig.densityDpi);
+
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertNotEquals(initialConf, wpc.getRequestedOverrideConfiguration());
+ assertEquals(0, mActivity.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ }
+
+ @Test
+ public void testActivityReparentDoesntClearProcessOverride_TwoActivities() {
+ final WindowProcessController wpc = mActivity.app;
+ final Configuration initialConf =
+ new Configuration(mActivity.getMergedOverrideConfiguration());
+ final Task initialTask = mActivity.getTask();
+ final ActivityRecord secondActivity = new ActivityBuilder(mService).setTask(initialTask)
+ .setUseProcess(wpc).build();
+
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertEquals(0, secondActivity.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+
+ // Create a new task with custom config to reparent the second activity to.
+ final Task newTask =
+ new TaskBuilder(mSupervisor).setStack(initialTask.getStack()).build();
+ final Configuration newConfig = newTask.getConfiguration();
+ newConfig.densityDpi += 100;
+ newTask.onRequestedOverrideConfigurationChanged(newConfig);
+
+ // Reparent the activity and verify that config override changed.
+ secondActivity.reparent(newTask, 0 /* top */, "test");
+
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertEquals(0, secondActivity.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ assertNotEquals(initialConf, wpc.getRequestedOverrideConfiguration());
+
+ // Reparent the first activity and verify that config override didn't change.
+ mActivity.reparent(newTask, 1 /* top */, "test");
+ assertTrue(wpc.registeredForActivityConfigChanges());
+ assertEquals(0, secondActivity.getMergedOverrideConfiguration()
+ .diff(wpc.getRequestedOverrideConfiguration()));
+ assertNotEquals(initialConf, wpc.getRequestedOverrideConfiguration());
+ }
+
+ /**
+ * Creates an activity on display. For non-default display request it will also create a new
+ * display with custom DisplayInfo.
+ */
+ private ActivityRecord createActivityOnDisplay(boolean defaultDisplay,
+ WindowProcessController process) {
+ final DisplayContent display;
+ if (defaultDisplay) {
+ display = mRootWindowContainer.getDefaultDisplay();
+ } else {
+ display = new TestDisplayContent.Builder(mService, 2000, 1000).setDensityDpi(300)
+ .setPosition(DisplayContent.POSITION_TOP).build();
+ }
+ final ActivityStack stack = display.createStack(WINDOWING_MODE_UNDEFINED,
+ ACTIVITY_TYPE_STANDARD, true /* onTop */);
+ final Task task = new TaskBuilder(mSupervisor).setStack(stack).build();
+ return new ActivityBuilder(mService).setTask(task).setUseProcess(process).build();
+ }
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
index 0f22724..4beede9 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityTestsBase.java
@@ -111,6 +111,7 @@
private int mConfigChanges;
private int mLaunchedFromPid;
private int mLaunchedFromUid;
+ private WindowProcessController mWpc;
ActivityBuilder(ActivityTaskManagerService service) {
mService = service;
@@ -201,6 +202,11 @@
return this;
}
+ ActivityBuilder setUseProcess(WindowProcessController wpc) {
+ mWpc = wpc;
+ return this;
+ }
+
ActivityRecord build() {
try {
mService.deferWindowLayout();
@@ -263,10 +269,16 @@
activity.setVisible(true);
}
- final WindowProcessController wpc = new WindowProcessController(mService,
- mService.mContext.getApplicationInfo(), mProcessName, mUid,
- UserHandle.getUserId(12345), mock(Object.class),
- mock(WindowProcessListener.class));
+ final WindowProcessController wpc;
+ if (mWpc != null) {
+ wpc = mWpc;
+ } else {
+ wpc = new WindowProcessController(mService,
+ mService.mContext.getApplicationInfo(), mProcessName, mUid,
+ UserHandle.getUserId(12345), mock(Object.class),
+ mock(WindowProcessListener.class));
+ wpc.setThread(mock(IApplicationThread.class));
+ }
wpc.setThread(mock(IApplicationThread.class));
activity.setProcess(wpc);
doReturn(wpc).when(mService).getProcessController(
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java
index 421a4582..db4fdc77 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowProcessControllerTests.java
@@ -26,6 +26,7 @@
import static org.mockito.Mockito.times;
import android.content.pm.ApplicationInfo;
+import android.content.res.Configuration;
import android.platform.test.annotations.Presubmit;
import org.junit.Before;
@@ -62,33 +63,33 @@
// Register to display 1 as a listener.
TestDisplayContent testDisplayContent1 = createTestDisplayContentInContainer();
- mWpc.registerDisplayConfigurationListenerLocked(testDisplayContent1);
+ mWpc.registerDisplayConfigurationListener(testDisplayContent1);
assertTrue(testDisplayContent1.containsListener(mWpc));
assertEquals(testDisplayContent1.mDisplayId, mWpc.getDisplayId());
// Move to display 2.
TestDisplayContent testDisplayContent2 = createTestDisplayContentInContainer();
- mWpc.registerDisplayConfigurationListenerLocked(testDisplayContent2);
+ mWpc.registerDisplayConfigurationListener(testDisplayContent2);
assertFalse(testDisplayContent1.containsListener(mWpc));
assertTrue(testDisplayContent2.containsListener(mWpc));
assertEquals(testDisplayContent2.mDisplayId, mWpc.getDisplayId());
// Null DisplayContent will not change anything.
- mWpc.registerDisplayConfigurationListenerLocked(null);
+ mWpc.registerDisplayConfigurationListener(null);
assertTrue(testDisplayContent2.containsListener(mWpc));
assertEquals(testDisplayContent2.mDisplayId, mWpc.getDisplayId());
// Unregister listener will remove the wpc from registered displays.
- mWpc.unregisterDisplayConfigurationListenerLocked();
+ mWpc.unregisterDisplayConfigurationListener();
assertFalse(testDisplayContent1.containsListener(mWpc));
assertFalse(testDisplayContent2.containsListener(mWpc));
assertEquals(INVALID_DISPLAY, mWpc.getDisplayId());
// Unregistration still work even if the display was removed.
- mWpc.registerDisplayConfigurationListenerLocked(testDisplayContent1);
+ mWpc.registerDisplayConfigurationListener(testDisplayContent1);
assertEquals(testDisplayContent1.mDisplayId, mWpc.getDisplayId());
mRootWindowContainer.removeChild(testDisplayContent1);
- mWpc.unregisterDisplayConfigurationListenerLocked();
+ mWpc.unregisterDisplayConfigurationListener();
assertEquals(INVALID_DISPLAY, mWpc.getDisplayId());
}
@@ -129,6 +130,24 @@
orderVerifier.verifyNoMoreInteractions();
}
+ @Test
+ public void testConfigurationForSecondaryScreen() {
+ final WindowProcessController wpc = new WindowProcessController(
+ mService, mock(ApplicationInfo.class), null, 0, -1, null, null);
+ // By default, the process should not listen to any display.
+ assertEquals(INVALID_DISPLAY, wpc.getDisplayId());
+
+ // Register to a new display as a listener.
+ final DisplayContent display = new TestDisplayContent.Builder(mService, 2000, 1000)
+ .setDensityDpi(300).setPosition(DisplayContent.POSITION_TOP).build();
+ wpc.registerDisplayConfigurationListener(display);
+
+ assertEquals(display.mDisplayId, wpc.getDisplayId());
+ final Configuration expectedConfig = mService.mRootWindowContainer.getConfiguration();
+ expectedConfig.updateFrom(display.getConfiguration());
+ assertEquals(expectedConfig, wpc.getConfiguration());
+ }
+
private TestDisplayContent createTestDisplayContentInContainer() {
return new TestDisplayContent.Builder(mService, 1000, 1500).build();
}
diff --git a/tests/net/integration/util/com/android/server/NetworkAgentWrapper.java b/tests/net/integration/util/com/android/server/NetworkAgentWrapper.java
index 11d5b25..1c69209 100644
--- a/tests/net/integration/util/com/android/server/NetworkAgentWrapper.java
+++ b/tests/net/integration/util/com/android/server/NetworkAgentWrapper.java
@@ -16,6 +16,7 @@
package com.android.server;
+import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
@@ -74,6 +75,7 @@
final String typeName = ConnectivityManager.getNetworkTypeName(type);
mNetworkInfo = new NetworkInfo(type, 0, typeName, "Mock");
mNetworkCapabilities = new NetworkCapabilities();
+ mNetworkCapabilities.addCapability(NET_CAPABILITY_NOT_SUSPENDED);
mNetworkCapabilities.addTransportType(transport);
switch (transport) {
case TRANSPORT_ETHERNET:
@@ -206,13 +208,11 @@
}
public void suspend() {
- mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.SUSPENDED, null, null);
- mNetworkAgent.sendNetworkInfo(mNetworkInfo);
+ removeCapability(NET_CAPABILITY_NOT_SUSPENDED);
}
public void resume() {
- mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null);
- mNetworkAgent.sendNetworkInfo(mNetworkInfo);
+ addCapability(NET_CAPABILITY_NOT_SUSPENDED);
}
public void disconnect() {