Merge "Update more tests to use a real TableLogBuffer instead of a mock." into main
diff --git a/core/api/current.txt b/core/api/current.txt
index 00541afee..65e4f27 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -52578,10 +52578,12 @@
ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int);
ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int, int);
method public void applyTransactionToFrame(@NonNull android.view.SurfaceControl.Transaction);
+ method @FlaggedApi("android.view.flags.surface_view_set_composition_order") public int getCompositionOrder();
method public android.view.SurfaceHolder getHolder();
method @Deprecated @Nullable public android.os.IBinder getHostToken();
method public android.view.SurfaceControl getSurfaceControl();
method public void setChildSurfacePackage(@NonNull android.view.SurfaceControlViewHost.SurfacePackage);
+ method @FlaggedApi("android.view.flags.surface_view_set_composition_order") public void setCompositionOrder(int);
method @FlaggedApi("com.android.graphics.hwui.flags.limited_hdr") public void setDesiredHdrHeadroom(@FloatRange(from=0.0f, to=10000.0) float);
method public void setSecure(boolean);
method public void setSurfaceLifecycle(int);
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 8edfc21..7781f88 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -18559,6 +18559,7 @@
method @Deprecated public abstract void setUserAgent(int);
method public abstract void setVideoOverlayForEmbeddedEncryptedVideoEnabled(boolean);
field public static final long ENABLE_SIMPLIFIED_DARK_MODE = 214741472L; // 0xcccb1e0L
+ field @FlaggedApi("android.webkit.user_agent_reduction") public static final long ENABLE_USER_AGENT_REDUCTION = 371034303L; // 0x161d88bfL
}
public class WebStorage {
diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java
index 93a9489..7eacaac 100644
--- a/core/java/android/app/Instrumentation.java
+++ b/core/java/android/app/Instrumentation.java
@@ -48,6 +48,9 @@
import android.os.TestLooperManager;
import android.os.UserHandle;
import android.os.UserManager;
+import android.ravenwood.annotation.RavenwoodKeep;
+import android.ravenwood.annotation.RavenwoodKeepPartialClass;
+import android.ravenwood.annotation.RavenwoodReplace;
import android.util.AndroidRuntimeException;
import android.util.Log;
import android.view.Display;
@@ -80,7 +83,7 @@
* implementation is described to the system through an AndroidManifest.xml's
* <instrumentation> tag.
*/
-@android.ravenwood.annotation.RavenwoodKeepPartialClass
+@RavenwoodKeepPartialClass
public class Instrumentation {
/**
@@ -136,7 +139,7 @@
private UiAutomation mUiAutomation;
private final Object mAnimationCompleteLock = new Object();
- @android.ravenwood.annotation.RavenwoodKeep
+ @RavenwoodKeep
public Instrumentation() {
}
@@ -147,7 +150,7 @@
* reflection, but it will serve as noticeable discouragement from
* doing such a thing.
*/
- @android.ravenwood.annotation.RavenwoodKeep
+ @RavenwoodKeep
private void checkInstrumenting(String method) {
// Check if we have an instrumentation context, as init should only get called by
// the system in startup processes that are being instrumented.
@@ -162,7 +165,7 @@
*
* @hide
*/
- @android.ravenwood.annotation.RavenwoodKeep
+ @RavenwoodKeep
public boolean isInstrumenting() {
// Check if we have an instrumentation context, as init should only get called by
// the system in startup processes that are being instrumented.
@@ -326,7 +329,7 @@
*
* @see #getTargetContext
*/
- @android.ravenwood.annotation.RavenwoodKeep
+ @RavenwoodKeep
public Context getContext() {
return mInstrContext;
}
@@ -351,7 +354,7 @@
*
* @see #getContext
*/
- @android.ravenwood.annotation.RavenwoodKeep
+ @RavenwoodKeep
public Context getTargetContext() {
return mAppContext;
}
@@ -2407,10 +2410,11 @@
*
* @hide
*/
- @android.ravenwood.annotation.RavenwoodKeep
- public final void basicInit(Context instrContext, Context appContext) {
+ @RavenwoodKeep
+ public final void basicInit(Context instrContext, Context appContext, UiAutomation ui) {
mInstrContext = instrContext;
mAppContext = appContext;
+ mUiAutomation = ui;
}
/** @hide */
@@ -2501,6 +2505,7 @@
*
* @see UiAutomation
*/
+ @RavenwoodKeep
public UiAutomation getUiAutomation() {
return getUiAutomation(0);
}
@@ -2539,6 +2544,7 @@
*
* @see UiAutomation
*/
+ @RavenwoodReplace
public UiAutomation getUiAutomation(@UiAutomationFlags int flags) {
boolean mustCreateNewAutomation = (mUiAutomation == null) || (mUiAutomation.isDestroyed());
@@ -2569,11 +2575,15 @@
return null;
}
+ private UiAutomation getUiAutomation$ravenwood(@UiAutomationFlags int flags) {
+ return mUiAutomation;
+ }
+
/**
* Takes control of the execution of messages on the specified looper until
* {@link TestLooperManager#release} is called.
*/
- @android.ravenwood.annotation.RavenwoodKeep
+ @RavenwoodKeep
public TestLooperManager acquireLooperManager(Looper looper) {
checkInstrumenting("acquireLooperManager");
return new TestLooperManager(looper);
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 9be928f..102540c 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -470,16 +470,9 @@
* that the user backed-out of provisioning or some precondition for provisioning wasn't met.
*
* <p>If a <a href="#roleholder">device policy management role holder</a> updater is present on
- * the device, an internet connection attempt must be made prior to launching this intent. If
- * an internet connection can not be established, provisioning will fail unless {@link
- * #EXTRA_PROVISIONING_ALLOW_OFFLINE} is explicitly set to {@code true}, in which case
- * provisioning will continue without using the
- * <a href="#roleholder">device policy management role holder</a>. If an internet connection
- * has been established, the <a href="#roleholder">device policy management role holder</a>
- * updater will be launched, which may update the
- * <a href="#roleholder">device policy management role holder</a> before continuing
- * provisioning.
+ * the device, an internet connection attempt must be made prior to launching this intent.
*/
+ // See b/365955253 for additional behaviours of this API.
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_PROVISION_MANAGED_PROFILE
= "android.app.action.PROVISION_MANAGED_PROFILE";
@@ -960,23 +953,8 @@
* A boolean extra indicating whether offline provisioning should be used.
*
* <p>The default value is {@code false}.
- *
- * <p>Usually during the <a href="#managedprovisioning">provisioning flow</a>, there will be
- * an attempt to download and install the latest version of the <a href="#roleholder">device
- * policy management role holder</a>. The platform will then
- * delegate provisioning to the <a href="#roleholder">device
- * * policy management role holder</a>.
- *
- * <p>When this extra is set to {@code true}, the
- * <a href="#managedprovisioning">provisioning flow</a> will always be handled by the platform
- * and the <a href="#roleholder">device policy management role holder</a>'s part skipped.
- *
- * <p>On Android versions prior to {@link Build.VERSION_CODES#TIRAMISU}, when this extra is
- * {@code false}, the <a href="#managedprovisioning">provisioning flow</a> will enforce that an
- * internet connection is established, or otherwise fail. When this extra is {@code true}, a
- * connection will still be attempted but when it cannot be established provisioning will
- * continue offline.
*/
+ // See b/365955253 for detailed behaviours of this API.
public static final String EXTRA_PROVISIONING_ALLOW_OFFLINE =
"android.app.extra.PROVISIONING_ALLOW_OFFLINE";
diff --git a/core/java/android/content/pm/SharedLibraryInfo.java b/core/java/android/content/pm/SharedLibraryInfo.java
index d77b2f5..f7191e6 100644
--- a/core/java/android/content/pm/SharedLibraryInfo.java
+++ b/core/java/android/content/pm/SharedLibraryInfo.java
@@ -209,6 +209,24 @@
}
/**
+ * @hide
+ * @param name
+ * @param versionMajor
+ */
+ public SharedLibraryInfo(String name, long versionMajor, int type) {
+ mPath = null;
+ mPackageName = null;
+ mName = name;
+ mVersion = versionMajor;
+ mType = type;
+ mDeclaringPackage = null;
+ mDependentPackages = null;
+ mDependencies = null;
+ mIsNative = false;
+ mOptionalDependentPackages = null;
+ }
+
+ /**
* Gets the type of this library.
*
* @return The library type.
diff --git a/core/java/android/content/pm/parsing/ApkLite.java b/core/java/android/content/pm/parsing/ApkLite.java
index 74ce62c..19a13db 100644
--- a/core/java/android/content/pm/parsing/ApkLite.java
+++ b/core/java/android/content/pm/parsing/ApkLite.java
@@ -21,6 +21,7 @@
import android.content.pm.ArchivedPackageParcel;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.pm.SharedLibraryInfo;
import android.content.pm.SigningDetails;
import android.content.pm.VerifierInfo;
@@ -149,6 +150,8 @@
*/
private final @Nullable String mEmergencyInstaller;
+ private final @NonNull List<SharedLibraryInfo> mDeclaredLibraries;
+
/**
* Archival install info.
*/
@@ -165,7 +168,7 @@
int minSdkVersion, int targetSdkVersion, int rollbackDataPolicy,
Set<String> requiredSplitTypes, Set<String> splitTypes,
boolean hasDeviceAdminReceiver, boolean isSdkLibrary, boolean updatableSystem,
- String emergencyInstaller) {
+ String emergencyInstaller, List<SharedLibraryInfo> declaredLibraries) {
mPath = path;
mPackageName = packageName;
mSplitName = splitName;
@@ -202,6 +205,7 @@
mUpdatableSystem = updatableSystem;
mEmergencyInstaller = emergencyInstaller;
mArchivedPackage = null;
+ mDeclaredLibraries = declaredLibraries;
}
public ApkLite(String path, ArchivedPackageParcel archivedPackage) {
@@ -241,6 +245,7 @@
mUpdatableSystem = true;
mEmergencyInstaller = null;
mArchivedPackage = archivedPackage;
+ mDeclaredLibraries = null;
}
/**
@@ -565,6 +570,11 @@
return mEmergencyInstaller;
}
+ @DataClass.Generated.Member
+ public @NonNull List<SharedLibraryInfo> getDeclaredLibraries() {
+ return mDeclaredLibraries;
+ }
+
/**
* Archival install info.
*/
@@ -574,10 +584,10 @@
}
@DataClass.Generated(
- time = 1706896661616L,
+ time = 1728333566322L,
codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/content/pm/parsing/ApkLite.java",
- inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.lang.String mPath\nprivate final @android.annotation.Nullable java.lang.String mSplitName\nprivate final @android.annotation.Nullable java.lang.String mUsesSplitName\nprivate final @android.annotation.Nullable java.lang.String mConfigForSplit\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String> mRequiredSplitTypes\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String> mSplitTypes\nprivate final int mVersionCodeMajor\nprivate final int mVersionCode\nprivate final int mRevisionCode\nprivate final int mInstallLocation\nprivate final int mMinSdkVersion\nprivate final int mTargetSdkVersion\nprivate final @android.annotation.NonNull android.content.pm.VerifierInfo[] mVerifiers\nprivate final @android.annotation.NonNull android.content.pm.SigningDetails mSigningDetails\nprivate final boolean mFeatureSplit\nprivate final boolean mIsolatedSplits\nprivate final boolean mSplitRequired\nprivate final boolean mCoreApp\nprivate final boolean mDebuggable\nprivate final boolean mProfileableByShell\nprivate final boolean mMultiArch\nprivate final boolean mUse32bitAbi\nprivate final boolean mExtractNativeLibs\nprivate final boolean mUseEmbeddedDex\nprivate final @android.annotation.Nullable java.lang.String mTargetPackageName\nprivate final boolean mOverlayIsStatic\nprivate final int mOverlayPriority\nprivate final @android.annotation.Nullable java.lang.String mRequiredSystemPropertyName\nprivate final @android.annotation.Nullable java.lang.String mRequiredSystemPropertyValue\nprivate final int mRollbackDataPolicy\nprivate final boolean mHasDeviceAdminReceiver\nprivate final boolean mIsSdkLibrary\nprivate final boolean mUpdatableSystem\nprivate final @android.annotation.Nullable java.lang.String mEmergencyInstaller\nprivate final @android.annotation.Nullable android.content.pm.ArchivedPackageParcel mArchivedPackage\npublic long getLongVersionCode()\nprivate boolean hasAnyRequiredSplitTypes()\nclass ApkLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)")
+ inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.lang.String mPath\nprivate final @android.annotation.Nullable java.lang.String mSplitName\nprivate final @android.annotation.Nullable java.lang.String mUsesSplitName\nprivate final @android.annotation.Nullable java.lang.String mConfigForSplit\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String> mRequiredSplitTypes\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String> mSplitTypes\nprivate final int mVersionCodeMajor\nprivate final int mVersionCode\nprivate final int mRevisionCode\nprivate final int mInstallLocation\nprivate final int mMinSdkVersion\nprivate final int mTargetSdkVersion\nprivate final @android.annotation.NonNull android.content.pm.VerifierInfo[] mVerifiers\nprivate final @android.annotation.NonNull android.content.pm.SigningDetails mSigningDetails\nprivate final boolean mFeatureSplit\nprivate final boolean mIsolatedSplits\nprivate final boolean mSplitRequired\nprivate final boolean mCoreApp\nprivate final boolean mDebuggable\nprivate final boolean mProfileableByShell\nprivate final boolean mMultiArch\nprivate final boolean mUse32bitAbi\nprivate final boolean mExtractNativeLibs\nprivate final boolean mUseEmbeddedDex\nprivate final @android.annotation.Nullable java.lang.String mTargetPackageName\nprivate final boolean mOverlayIsStatic\nprivate final int mOverlayPriority\nprivate final @android.annotation.Nullable java.lang.String mRequiredSystemPropertyName\nprivate final @android.annotation.Nullable java.lang.String mRequiredSystemPropertyValue\nprivate final int mRollbackDataPolicy\nprivate final boolean mHasDeviceAdminReceiver\nprivate final boolean mIsSdkLibrary\nprivate final boolean mUpdatableSystem\nprivate final @android.annotation.Nullable java.lang.String mEmergencyInstaller\nprivate final @android.annotation.NonNull java.util.List<android.content.pm.SharedLibraryInfo> mDeclaredLibraries\nprivate final @android.annotation.Nullable android.content.pm.ArchivedPackageParcel mArchivedPackage\npublic long getLongVersionCode()\nprivate boolean hasAnyRequiredSplitTypes()\nclass ApkLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)")
@Deprecated
private void __metadata() {}
diff --git a/core/java/android/content/pm/parsing/ApkLiteParseUtils.java b/core/java/android/content/pm/parsing/ApkLiteParseUtils.java
index ffb69c0..1a7f628 100644
--- a/core/java/android/content/pm/parsing/ApkLiteParseUtils.java
+++ b/core/java/android/content/pm/parsing/ApkLiteParseUtils.java
@@ -24,6 +24,7 @@
import android.app.admin.DeviceAdminReceiver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.pm.SharedLibraryInfo;
import android.content.pm.SigningDetails;
import android.content.pm.VerifierInfo;
import android.content.pm.parsing.result.ParseInput;
@@ -92,6 +93,8 @@
private static final String[] SDK_CODENAMES = Build.VERSION.ACTIVE_CODENAMES;
private static final String TAG_PROCESSES = "processes";
private static final String TAG_PROCESS = "process";
+ private static final String TAG_STATIC_LIBRARY = "static-library";
+ private static final String TAG_LIBRARY = "library";
/**
* Parse only lightweight details about the package at the given location.
@@ -457,6 +460,7 @@
boolean hasDeviceAdminReceiver = false;
boolean isSdkLibrary = false;
+ List<SharedLibraryInfo> declaredLibraries = new ArrayList<>();
// Only search the tree when the tag is the direct child of <manifest> tag
int type;
@@ -521,6 +525,51 @@
break;
case TAG_SDK_LIBRARY:
isSdkLibrary = true;
+ // Mirrors ParsingPackageUtils#parseSdkLibrary until lite and full
+ // parsing are combined
+ String sdkLibName = parser.getAttributeValue(
+ ANDROID_RES_NAMESPACE, "name");
+ int sdkLibVersionMajor = parser.getAttributeIntValue(
+ ANDROID_RES_NAMESPACE, "versionMajor", -1);
+ if (sdkLibName == null || sdkLibVersionMajor < 0) {
+ return input.error(
+ PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
+ "Bad uses-sdk-library declaration name: " + sdkLibName
+ + " version: " + sdkLibVersionMajor);
+ }
+ declaredLibraries.add(new SharedLibraryInfo(
+ sdkLibName, sdkLibVersionMajor,
+ SharedLibraryInfo.TYPE_SDK_PACKAGE));
+ break;
+ case TAG_STATIC_LIBRARY:
+ // Mirrors ParsingPackageUtils#parseStaticLibrary until lite and full
+ // parsing are combined
+ String staticLibName = parser.getAttributeValue(
+ ANDROID_RES_NAMESPACE, "name");
+ int staticLibVersion = parser.getAttributeIntValue(
+ ANDROID_RES_NAMESPACE, "version", -1);
+ int staticLibVersionMajor = parser.getAttributeIntValue(
+ ANDROID_RES_NAMESPACE, "versionMajor", 0);
+ if (staticLibName == null || staticLibVersion < 0) {
+ return input.error("Bad static-library declaration name: "
+ + staticLibName + " version: " + staticLibVersion);
+ }
+ declaredLibraries.add(new SharedLibraryInfo(staticLibName,
+ PackageInfo.composeLongVersionCode(staticLibVersionMajor,
+ staticLibVersion), SharedLibraryInfo.TYPE_STATIC));
+ break;
+ case TAG_LIBRARY:
+ // Mirrors ParsingPackageUtils#parseLibrary until lite and full parsing
+ // are combined
+ String libName = parser.getAttributeValue(
+ ANDROID_RES_NAMESPACE, "name");
+ if (libName == null) {
+ return input.error("Bad library declaration name: null");
+ }
+ libName = libName.intern();
+ declaredLibraries.add(new SharedLibraryInfo(libName,
+ SharedLibraryInfo.VERSION_UNDEFINED,
+ SharedLibraryInfo.TYPE_DYNAMIC));
break;
case TAG_PROCESSES:
final int processesDepth = parser.getDepth();
@@ -645,7 +694,8 @@
overlayIsStatic, overlayPriority, requiredSystemPropertyName,
requiredSystemPropertyValue, minSdkVersion, targetSdkVersion,
rollbackDataPolicy, requiredSplitTypes.first, requiredSplitTypes.second,
- hasDeviceAdminReceiver, isSdkLibrary, updatableSystem, emergencyInstaller));
+ hasDeviceAdminReceiver, isSdkLibrary, updatableSystem, emergencyInstaller,
+ declaredLibraries));
}
private static boolean isDeviceAdminReceiver(
diff --git a/core/java/android/content/pm/parsing/PackageLite.java b/core/java/android/content/pm/parsing/PackageLite.java
index 116dd1f..9a2ee7f 100644
--- a/core/java/android/content/pm/parsing/PackageLite.java
+++ b/core/java/android/content/pm/parsing/PackageLite.java
@@ -20,6 +20,7 @@
import android.annotation.Nullable;
import android.content.pm.ArchivedPackageParcel;
import android.content.pm.PackageInfo;
+import android.content.pm.SharedLibraryInfo;
import android.content.pm.SigningDetails;
import android.content.pm.VerifierInfo;
@@ -114,6 +115,8 @@
*/
private final boolean mIsSdkLibrary;
+ private final @NonNull List<SharedLibraryInfo> mDeclaredLibraries;
+
/**
* Archival install info.
*/
@@ -154,6 +157,7 @@
mSplitApkPaths = splitApkPaths;
mSplitRevisionCodes = splitRevisionCodes;
mTargetSdk = targetSdk;
+ mDeclaredLibraries = baseApk.getDeclaredLibraries();
mArchivedPackage = baseApk.getArchivedPackage();
}
@@ -433,6 +437,11 @@
return mIsSdkLibrary;
}
+ @DataClass.Generated.Member
+ public @NonNull List<SharedLibraryInfo> getDeclaredLibraries() {
+ return mDeclaredLibraries;
+ }
+
/**
* Archival install info.
*/
@@ -442,10 +451,10 @@
}
@DataClass.Generated(
- time = 1694792176268L,
+ time = 1728333569917L,
codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/content/pm/parsing/PackageLite.java",
- inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.lang.String mPath\nprivate final @android.annotation.NonNull java.lang.String mBaseApkPath\nprivate final @android.annotation.Nullable java.lang.String[] mSplitApkPaths\nprivate final @android.annotation.Nullable java.lang.String[] mSplitNames\nprivate final @android.annotation.Nullable java.lang.String[] mUsesSplitNames\nprivate final @android.annotation.Nullable java.lang.String[] mConfigForSplit\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String> mBaseRequiredSplitTypes\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String>[] mRequiredSplitTypes\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String>[] mSplitTypes\nprivate final int mVersionCodeMajor\nprivate final int mVersionCode\nprivate final int mTargetSdk\nprivate final int mBaseRevisionCode\nprivate final @android.annotation.Nullable int[] mSplitRevisionCodes\nprivate final int mInstallLocation\nprivate final @android.annotation.NonNull android.content.pm.VerifierInfo[] mVerifiers\nprivate final @android.annotation.NonNull android.content.pm.SigningDetails mSigningDetails\nprivate final @android.annotation.Nullable boolean[] mIsFeatureSplits\nprivate final boolean mIsolatedSplits\nprivate final boolean mSplitRequired\nprivate final boolean mCoreApp\nprivate final boolean mDebuggable\nprivate final boolean mMultiArch\nprivate final boolean mUse32bitAbi\nprivate final boolean mExtractNativeLibs\nprivate final boolean mProfileableByShell\nprivate final boolean mUseEmbeddedDex\nprivate final boolean mIsSdkLibrary\nprivate final @android.annotation.Nullable android.content.pm.ArchivedPackageParcel mArchivedPackage\npublic java.util.List<java.lang.String> getAllApkPaths()\npublic long getLongVersionCode()\nprivate boolean hasAnyRequiredSplitTypes()\nclass PackageLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)")
+ inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.lang.String mPath\nprivate final @android.annotation.NonNull java.lang.String mBaseApkPath\nprivate final @android.annotation.Nullable java.lang.String[] mSplitApkPaths\nprivate final @android.annotation.Nullable java.lang.String[] mSplitNames\nprivate final @android.annotation.Nullable java.lang.String[] mUsesSplitNames\nprivate final @android.annotation.Nullable java.lang.String[] mConfigForSplit\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String> mBaseRequiredSplitTypes\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String>[] mRequiredSplitTypes\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String>[] mSplitTypes\nprivate final int mVersionCodeMajor\nprivate final int mVersionCode\nprivate final int mTargetSdk\nprivate final int mBaseRevisionCode\nprivate final @android.annotation.Nullable int[] mSplitRevisionCodes\nprivate final int mInstallLocation\nprivate final @android.annotation.NonNull android.content.pm.VerifierInfo[] mVerifiers\nprivate final @android.annotation.NonNull android.content.pm.SigningDetails mSigningDetails\nprivate final @android.annotation.Nullable boolean[] mIsFeatureSplits\nprivate final boolean mIsolatedSplits\nprivate final boolean mSplitRequired\nprivate final boolean mCoreApp\nprivate final boolean mDebuggable\nprivate final boolean mMultiArch\nprivate final boolean mUse32bitAbi\nprivate final boolean mExtractNativeLibs\nprivate final boolean mProfileableByShell\nprivate final boolean mUseEmbeddedDex\nprivate final boolean mIsSdkLibrary\nprivate final @android.annotation.NonNull java.util.List<android.content.pm.SharedLibraryInfo> mDeclaredLibraries\nprivate final @android.annotation.Nullable android.content.pm.ArchivedPackageParcel mArchivedPackage\npublic java.util.List<java.lang.String> getAllApkPaths()\npublic long getLongVersionCode()\nprivate boolean hasAnyRequiredSplitTypes()\nclass PackageLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)")
@Deprecated
private void __metadata() {}
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index f7745d1..83b4971 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -16,6 +16,7 @@
package android.view;
+import static android.view.flags.Flags.FLAG_SURFACE_VIEW_SET_COMPOSITION_ORDER;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static android.view.WindowManagerPolicyConstants.APPLICATION_MEDIA_OVERLAY_SUBLAYER;
import static android.view.WindowManagerPolicyConstants.APPLICATION_MEDIA_SUBLAYER;
@@ -770,6 +771,36 @@
}
/**
+ * Controls the composition order of the SurfaceView. A non-negative composition order
+ * value indicates that the SurfaceView is composited on top of the parent window, while
+ * a negative composition order indicates that the SurfaceView is behind the parent
+ * window. A SurfaceView with a higher value appears above its peers with lower values.
+ * For SurfaceViews with the same composition order value, their relative order is
+ * undefined.
+ *
+ * @param compositionOrder the composition order of the surface view.
+ */
+ @FlaggedApi(FLAG_SURFACE_VIEW_SET_COMPOSITION_ORDER)
+ public void setCompositionOrder(int compositionOrder) {
+ mRequestedSubLayer = compositionOrder;
+ if (mSubLayer != mRequestedSubLayer) {
+ updateSurface();
+ }
+ }
+
+ /**
+ * Returns the composition order of the SurfaceView.
+ *
+ * @return composition order of the SurfaceView.
+ *
+ * @see #setCompositionOrder(int)
+ */
+ @FlaggedApi(FLAG_SURFACE_VIEW_SET_COMPOSITION_ORDER)
+ public int getCompositionOrder() {
+ return mRequestedSubLayer;
+ }
+
+ /**
* Control whether the surface view's surface is placed on top of another
* regular surface view in the window (but still behind the window itself).
* This is typically used to place overlays on top of an underlying media
@@ -1257,7 +1288,8 @@
final Transaction surfaceUpdateTransaction = new Transaction();
if (creating) {
updateOpaqueFlag();
- final String name = "SurfaceView[" + viewRoot.getTitle().toString() + "]";
+ final String name = Integer.toHexString(System.identityHashCode(this))
+ + " SurfaceView[" + viewRoot.getTitle().toString() + "]";
createBlastSurfaceControls(viewRoot, name, surfaceUpdateTransaction);
} else if (mSurfaceControl == null) {
return;
diff --git a/core/java/android/view/flags/view_flags.aconfig b/core/java/android/view/flags/view_flags.aconfig
index 5115b13..1cf26ab 100644
--- a/core/java/android/view/flags/view_flags.aconfig
+++ b/core/java/android/view/flags/view_flags.aconfig
@@ -109,3 +109,11 @@
purpose: PURPOSE_BUGFIX
}
}
+
+flag {
+ name: "surface_view_set_composition_order"
+ namespace: "window_surfaces"
+ description: "Add a SurfaceView composition order control API."
+ bug: "341021569"
+ is_fixed_read_only: true
+}
\ No newline at end of file
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index 7366b9a..ab5969b 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -16,10 +16,12 @@
package android.webkit;
+import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledAfter;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
@@ -151,6 +153,24 @@
public static final long ENABLE_SIMPLIFIED_DARK_MODE = 214741472L;
/**
+ * Enable User-Agent Reduction for webview.
+ * The OS, CPU, and Build information in the default User-Agent will be
+ * reduced to the static "Linux; Android 10; K" string.
+ * Minor/build/patch version information in the default User-Agent is
+ * reduced to "0.0.0". The rest of the default User-Agent remains unchanged.
+ *
+ * See https://developers.google.com/privacy-sandbox/protections/user-agent
+ * for details related to User-Agent Reduction.
+ *
+ * @hide
+ */
+ @ChangeId
+ @EnabledAfter(targetSdkVersion = android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM)
+ @FlaggedApi(android.webkit.Flags.FLAG_USER_AGENT_REDUCTION)
+ @SystemApi
+ public static final long ENABLE_USER_AGENT_REDUCTION = 371034303L;
+
+ /**
* Default cache usage mode. If the navigation type doesn't impose any
* specific behavior, use cached resources when they are available
* and not expired, otherwise load resources from the network.
diff --git a/core/java/android/webkit/flags.aconfig b/core/java/android/webkit/flags.aconfig
index b21a490..d1013a9 100644
--- a/core/java/android/webkit/flags.aconfig
+++ b/core/java/android/webkit/flags.aconfig
@@ -18,3 +18,11 @@
bug: "310653407"
is_fixed_read_only: true
}
+
+flag {
+ name: "user_agent_reduction"
+ is_exported: true
+ namespace: "webview"
+ description: "New feature reduce user-agent for webview"
+ bug: "371034303"
+}
diff --git a/core/java/android/window/OWNERS b/core/java/android/window/OWNERS
index 2c61df9..77c99b9 100644
--- a/core/java/android/window/OWNERS
+++ b/core/java/android/window/OWNERS
@@ -1,3 +1,5 @@
set noparent
include /services/core/java/com/android/server/wm/OWNERS
+
+per-file DesktopModeFlags.java = file:/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/OWNERS
diff --git a/core/java/com/android/internal/pm/pkg/component/AconfigFlags.java b/core/java/com/android/internal/pm/pkg/component/AconfigFlags.java
index 39aadfb..8faaf95 100644
--- a/core/java/com/android/internal/pm/pkg/component/AconfigFlags.java
+++ b/core/java/com/android/internal/pm/pkg/component/AconfigFlags.java
@@ -53,19 +53,18 @@
* @hide
*/
public class AconfigFlags {
+ private static final boolean DEBUG = false;
private static final String LOG_TAG = "AconfigFlags";
-
- public enum Permission {
- READ_WRITE,
- READ_ONLY
- }
+ private static final String OVERRIDE_PREFIX = "device_config_overrides/";
+ private static final String STAGED_PREFIX = "staged/";
private final ArrayMap<String, Boolean> mFlagValues = new ArrayMap<>();
- private final ArrayMap<String, Permission> mFlagPermissions = new ArrayMap<>();
public AconfigFlags() {
if (!Flags.manifestFlagging()) {
- Slog.v(LOG_TAG, "Feature disabled, skipped all loading");
+ if (DEBUG) {
+ Slog.v(LOG_TAG, "Feature disabled, skipped all loading");
+ }
return;
}
final var defaultFlagProtoFiles =
@@ -130,19 +129,17 @@
if (!"false".equalsIgnoreCase(value) && !"true".equalsIgnoreCase(value)) {
continue;
}
- final var overridePrefix = "device_config_overrides/";
- final var stagedPrefix = "staged/";
String separator = "/";
String prefix = "default";
int priority = 0;
- if (name.startsWith(overridePrefix)) {
- prefix = overridePrefix;
- name = name.substring(overridePrefix.length());
+ if (name.startsWith(OVERRIDE_PREFIX)) {
+ prefix = OVERRIDE_PREFIX;
+ name = name.substring(OVERRIDE_PREFIX.length());
separator = ":";
priority = 20;
- } else if (name.startsWith(stagedPrefix)) {
- prefix = stagedPrefix;
- name = name.substring(stagedPrefix.length());
+ } else if (name.startsWith(STAGED_PREFIX)) {
+ prefix = STAGED_PREFIX;
+ name = name.substring(STAGED_PREFIX.length());
separator = "*";
priority = 10;
}
@@ -155,12 +152,19 @@
if (!mFlagValues.containsKey(flagPackageAndName)) {
continue;
}
- Slog.d(LOG_TAG, "Found " + prefix
- + " Aconfig flag value for " + flagPackageAndName + " = " + value);
+ if (DEBUG) {
+ Slog.d(LOG_TAG, "Found " + prefix
+ + " Aconfig flag value in settings for " + flagPackageAndName
+ + " = " + value);
+ }
final Integer currentPriority = flagPriority.get(flagPackageAndName);
if (currentPriority != null && currentPriority >= priority) {
- Slog.i(LOG_TAG, "Skipping " + prefix + " flag " + flagPackageAndName
- + " because of the existing one with priority " + currentPriority);
+ if (DEBUG) {
+ Slog.d(LOG_TAG, "Skipping " + prefix + " flag "
+ + flagPackageAndName
+ + " in settings because of existing one with priority "
+ + currentPriority);
+ }
continue;
}
flagPriority.put(flagPackageAndName, priority);
@@ -185,15 +189,7 @@
for (parsed_flag flag : parsedFlags.parsedFlag) {
String flagPackageAndName = flag.package_ + "." + flag.name;
boolean flagValue = (flag.state == Aconfig.ENABLED);
- Slog.v(LOG_TAG, "Read Aconfig default flag value "
- + flagPackageAndName + " = " + flagValue);
mFlagValues.put(flagPackageAndName, flagValue);
-
- Permission permission = flag.permission == Aconfig.READ_ONLY
- ? Permission.READ_ONLY
- : Permission.READ_WRITE;
-
- mFlagPermissions.put(flagPackageAndName, permission);
}
}
@@ -203,24 +199,15 @@
* @return the current value of the given Aconfig flag, or null if there is no such flag
*/
@Nullable
- public Boolean getFlagValue(@NonNull String flagPackageAndName) {
+ private Boolean getFlagValue(@NonNull String flagPackageAndName) {
Boolean value = mFlagValues.get(flagPackageAndName);
- Slog.d(LOG_TAG, "Aconfig flag value for " + flagPackageAndName + " = " + value);
+ if (DEBUG) {
+ Slog.v(LOG_TAG, "Aconfig flag value for " + flagPackageAndName + " = " + value);
+ }
return value;
}
/**
- * Get the flag permission, or null if the flag doesn't exist.
- * @param flagPackageAndName Full flag name formatted as 'package.flag'
- * @return the current permission of the given Aconfig flag, or null if there is no such flag
- */
- @Nullable
- public Permission getFlagPermission(@NonNull String flagPackageAndName) {
- Permission permission = mFlagPermissions.get(flagPackageAndName);
- return permission;
- }
-
- /**
* Check if the element in {@code parser} should be skipped because of the feature flag.
* @param parser XML parser object currently parsing an element
* @return true if the element is disabled because of its feature flag
@@ -247,7 +234,7 @@
}
// Skip if flag==false && attr=="flag" OR flag==true && attr=="!flag" (negated)
if (flagValue == negated) {
- Slog.v(LOG_TAG, "Skipping element " + parser.getName()
+ Slog.i(LOG_TAG, "Skipping element " + parser.getName()
+ " behind feature flag " + featureFlag + " = " + flagValue);
return true;
}
diff --git a/core/java/com/android/internal/widget/NotificationProgressBar.java b/core/java/com/android/internal/widget/NotificationProgressBar.java
new file mode 100644
index 0000000..12e1dd9
--- /dev/null
+++ b/core/java/com/android/internal/widget/NotificationProgressBar.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+import android.app.Notification.ProgressStyle;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.ProgressBar;
+import android.widget.RemoteViews;
+
+import androidx.annotation.ColorInt;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.widget.NotificationProgressDrawable.Part;
+import com.android.internal.widget.NotificationProgressDrawable.Point;
+import com.android.internal.widget.NotificationProgressDrawable.Segment;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * NotificationProgressBar extends the capabilities of ProgressBar by adding functionalities to
+ * represent Notification ProgressStyle progress, such as for ridesharing and navigation.
+ */
+@RemoteViews.RemoteView
+public class NotificationProgressBar extends ProgressBar {
+ public NotificationProgressBar(Context context) {
+ this(context, null);
+ }
+
+ public NotificationProgressBar(Context context, AttributeSet attrs) {
+ this(context, attrs, com.android.internal.R.attr.progressBarStyle);
+ }
+
+ public NotificationProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public NotificationProgressBar(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ /**
+ * Processes the ProgressStyle data and convert to list of {@code
+ * NotificationProgressDrawable.Part}.
+ */
+ @VisibleForTesting
+ public static List<Part> processAndConvertToDrawableParts(
+ List<ProgressStyle.Segment> segments,
+ List<ProgressStyle.Point> points,
+ int progress,
+ boolean isStyledByProgress
+ ) {
+ if (segments.isEmpty()) {
+ throw new IllegalArgumentException("List of segments shouldn't be empty");
+ }
+
+ for (ProgressStyle.Segment segment : segments) {
+ final int length = segment.getLength();
+ if (length <= 0) {
+ throw new IllegalArgumentException("Invalid segment length : " + length);
+ }
+ }
+
+ final int progressMax = segments.stream().mapToInt(ProgressStyle.Segment::getLength).sum();
+
+ if (progress < 0 || progress > progressMax) {
+ throw new IllegalArgumentException("Invalid progress : " + progress);
+ }
+ for (ProgressStyle.Point point : points) {
+ final int pos = point.getPosition();
+ if (pos <= 0 || pos >= progressMax) {
+ throw new IllegalArgumentException("Invalid Point position : " + pos);
+ }
+ }
+
+ final Map<Integer, ProgressStyle.Segment> startToSegmentMap = generateStartToSegmentMap(
+ segments);
+ final Map<Integer, ProgressStyle.Point> positionToPointMap = generatePositionToPointMap(
+ points);
+ final SortedSet<Integer> sortedPos = generateSortedPositionSet(startToSegmentMap,
+ positionToPointMap, progress, isStyledByProgress);
+
+ final Map<Integer, ProgressStyle.Segment> startToSplitSegmentMap =
+ splitSegmentsByPointsAndProgress(
+ startToSegmentMap, sortedPos, progressMax);
+
+ return convertToDrawableParts(startToSplitSegmentMap, positionToPointMap, sortedPos,
+ progress, progressMax,
+ isStyledByProgress);
+ }
+
+
+ // Any segment with a point on it gets split by the point.
+ // If isStyledByProgress is true, also split the segment with the progress value in its range.
+ private static Map<Integer, ProgressStyle.Segment> splitSegmentsByPointsAndProgress(
+ Map<Integer, ProgressStyle.Segment> startToSegmentMap,
+ SortedSet<Integer> sortedPos,
+ int progressMax) {
+ int prevSegStart = 0;
+ for (Integer pos : sortedPos) {
+ if (pos == 0 || pos == progressMax) continue;
+ if (startToSegmentMap.containsKey(pos)) {
+ prevSegStart = pos;
+ continue;
+ }
+
+ final ProgressStyle.Segment prevSeg = startToSegmentMap.get(prevSegStart);
+ final ProgressStyle.Segment leftSeg = new ProgressStyle.Segment(
+ pos - prevSegStart).setColor(
+ prevSeg.getColor());
+ final ProgressStyle.Segment rightSeg = new ProgressStyle.Segment(
+ prevSegStart + prevSeg.getLength() - pos).setColor(prevSeg.getColor());
+
+ startToSegmentMap.put(prevSegStart, leftSeg);
+ startToSegmentMap.put(pos, rightSeg);
+
+ prevSegStart = pos;
+ }
+
+ return startToSegmentMap;
+ }
+
+ private static List<Part> convertToDrawableParts(
+ Map<Integer, ProgressStyle.Segment> startToSegmentMap,
+ Map<Integer, ProgressStyle.Point> positionToPointMap,
+ SortedSet<Integer> sortedPos,
+ int progress,
+ int progressMax,
+ boolean isStyledByProgress
+ ) {
+ List<Part> parts = new ArrayList<>();
+ boolean styleRemainingParts = false;
+ for (Integer pos : sortedPos) {
+ if (positionToPointMap.containsKey(pos)) {
+ final ProgressStyle.Point point = positionToPointMap.get(pos);
+ final int color = maybeGetFadedColor(point.getColor(), styleRemainingParts);
+ parts.add(new Point(null, color, styleRemainingParts));
+ }
+ // We want the Point at the current progress to be filled (not faded), but a Segment
+ // starting at this progress to be faded.
+ if (isStyledByProgress && !styleRemainingParts && pos == progress) {
+ styleRemainingParts = true;
+ }
+ if (startToSegmentMap.containsKey(pos)) {
+ final ProgressStyle.Segment seg = startToSegmentMap.get(pos);
+ final int color = maybeGetFadedColor(seg.getColor(), styleRemainingParts);
+ parts.add(new Segment(
+ (float) seg.getLength() / progressMax, color, styleRemainingParts));
+ }
+ }
+
+ return parts;
+ }
+
+ @ColorInt
+ private static int maybeGetFadedColor(@ColorInt int color, boolean fade) {
+ if (!fade) return color;
+
+ return NotificationProgressDrawable.getFadedColor(color);
+ }
+
+ private static Map<Integer, ProgressStyle.Segment> generateStartToSegmentMap(
+ List<ProgressStyle.Segment> segments) {
+ final Map<Integer, ProgressStyle.Segment> startToSegmentMap = new HashMap<>();
+
+ int currentStart = 0; // Initial start position is 0
+
+ for (ProgressStyle.Segment segment : segments) {
+ // Use the current start position as the key, and the segment as the value
+ startToSegmentMap.put(currentStart, segment);
+
+ // Update the start position for the next segment
+ currentStart += segment.getLength();
+ }
+
+ return startToSegmentMap;
+ }
+
+ private static Map<Integer, ProgressStyle.Point> generatePositionToPointMap(
+ List<ProgressStyle.Point> points) {
+ final Map<Integer, ProgressStyle.Point> positionToPointMap = new HashMap<>();
+
+ for (ProgressStyle.Point point : points) {
+ positionToPointMap.put(point.getPosition(), point);
+ }
+
+ return positionToPointMap;
+ }
+
+ private static SortedSet<Integer> generateSortedPositionSet(
+ Map<Integer, ProgressStyle.Segment> startToSegmentMap,
+ Map<Integer, ProgressStyle.Point> positionToPointMap, int progress,
+ boolean isStyledByProgress) {
+ final SortedSet<Integer> sortedPos = new TreeSet<>(startToSegmentMap.keySet());
+ sortedPos.addAll(positionToPointMap.keySet());
+ if (isStyledByProgress) {
+ sortedPos.add(progress);
+ }
+
+ return sortedPos;
+ }
+}
diff --git a/core/java/com/android/internal/widget/NotificationProgressDrawable.java b/core/java/com/android/internal/widget/NotificationProgressDrawable.java
index 4d88546..89ef875 100644
--- a/core/java/com/android/internal/widget/NotificationProgressDrawable.java
+++ b/core/java/com/android/internal/widget/NotificationProgressDrawable.java
@@ -45,6 +45,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Objects;
/**
* This is used by NotificationProgressBar for displaying a custom background. It composes of
@@ -126,7 +127,7 @@
* @see #setStroke(int, int, float, float)
*/
public void setStrokeDefaultColor(@ColorInt int color) {
- mState.mStrokeColor = color;
+ mState.setStrokeColor(color);
}
/**
@@ -138,7 +139,7 @@
* @see #mutate()
*/
public void setPointRectDefaultColor(@ColorInt int color) {
- mState.mPointRectColor = color;
+ mState.setPointRectColor(color);
}
private void setStrokeInternal(int width, float dashWidth, float dashGap) {
@@ -194,7 +195,7 @@
mStrokePaint.setColor(segment.mColor != Color.TRANSPARENT ? segment.mColor
: mState.mStrokeColor);
mDashedStrokePaint.setColor(segment.mColor != Color.TRANSPARENT ? segment.mColor
- : mState.mStrokeColor);
+ : mState.mFadedStrokeColor);
// Leave space for the rounded line cap which extends beyond start/end.
final float capWidth = mStrokePaint.getStrokeWidth() / 2F;
@@ -220,7 +221,8 @@
mPointRectF.inset(inset, inset);
mFillPaint.setColor(point.mColor != Color.TRANSPARENT ? point.mColor
- : mState.mPointRectColor);
+ : (point.mFaded ? mState.mFadedPointRectColor
+ : mState.mPointRectColor));
canvas.drawRoundRect(mPointRectF, cornerRadius, cornerRadius, mFillPaint);
}
@@ -424,8 +426,9 @@
state.mPointRectCornerRadius = a.getDimension(
R.styleable.NotificationProgressDrawablePoints_cornerRadius,
state.mPointRectCornerRadius);
- state.mPointRectColor = a.getColor(R.styleable.NotificationProgressDrawablePoints_color,
+ final int color = a.getColor(R.styleable.NotificationProgressDrawablePoints_color,
state.mPointRectColor);
+ setPointRectDefaultColor(color);
}
static int resolveDensity(@Nullable Resources r, int parentDensity) {
@@ -478,7 +481,6 @@
* {@link Point} with zero length.
*/
public interface Part {
-
}
/**
@@ -521,6 +523,24 @@
return "Segment(fraction=" + this.mFraction + ", color=" + this.mColor + ", dashed="
+ this.mDashed + ')';
}
+
+ // Needed for unit tests
+ @Override
+ public boolean equals(@Nullable Object other) {
+ if (this == other) return true;
+
+ if (other == null || getClass() != other.getClass()) return false;
+
+ Segment that = (Segment) other;
+ if (Float.compare(this.mFraction, that.mFraction) != 0) return false;
+ if (this.mColor != that.mColor) return false;
+ return this.mDashed == that.mDashed;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mFraction, mColor, mDashed);
+ }
}
/**
@@ -532,14 +552,21 @@
@Nullable
private final Drawable mIcon;
@ColorInt private final int mColor;
+ private final boolean mFaded;
public Point(@Nullable Drawable icon) {
- this(icon, Color.TRANSPARENT);
+ this(icon, Color.TRANSPARENT, false);
}
public Point(@Nullable Drawable icon, @ColorInt int color) {
+ this(icon, color, false);
+
+ }
+
+ public Point(@Nullable Drawable icon, @ColorInt int color, boolean faded) {
mIcon = icon;
mColor = color;
+ mFaded = faded;
}
@Nullable
@@ -547,9 +574,37 @@
return this.mIcon;
}
+ public int getColor() {
+ return this.mColor;
+ }
+
+ public boolean getFaded() {
+ return this.mFaded;
+ }
+
@Override
public String toString() {
- return "Point(icon=" + this.mIcon + ", color=" + this.mColor + ')';
+ return "Point(icon=" + this.mIcon + ", color=" + this.mColor + ", faded=" + this.mFaded
+ + ")";
+ }
+
+ // Needed for unit tests.
+ @Override
+ public boolean equals(@Nullable Object other) {
+ if (this == other) return true;
+
+ if (other == null || getClass() != other.getClass()) return false;
+
+ Point that = (Point) other;
+
+ if (!Objects.equals(this.mIcon, that.mIcon)) return false;
+ if (this.mColor != that.mColor) return false;
+ return this.mFaded == that.mFaded;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mIcon, mColor, mFaded);
}
}
@@ -576,12 +631,14 @@
float mSegPointGap = 0.0f;
int mStrokeWidth = 0;
int mStrokeColor;
+ int mFadedStrokeColor;
float mStrokeDashWidth = 0.0f;
float mStrokeDashGap = 0.0f;
float mPointRadius;
float mPointRectInset;
float mPointRectCornerRadius;
int mPointRectColor;
+ int mFadedPointRectColor;
int[] mThemeAttrs;
int[] mThemeAttrsSegments;
@@ -595,6 +652,7 @@
State(@NonNull State orig, @Nullable Resources res) {
mChangingConfigurations = orig.mChangingConfigurations;
mStrokeColor = orig.mStrokeColor;
+ mFadedStrokeColor = orig.mFadedStrokeColor;
mStrokeWidth = orig.mStrokeWidth;
mStrokeDashWidth = orig.mStrokeDashWidth;
mStrokeDashGap = orig.mStrokeDashGap;
@@ -602,6 +660,7 @@
mPointRectInset = orig.mPointRectInset;
mPointRectCornerRadius = orig.mPointRectCornerRadius;
mPointRectColor = orig.mPointRectColor;
+ mFadedPointRectColor = orig.mFadedPointRectColor;
mThemeAttrs = orig.mThemeAttrs;
mThemeAttrsSegments = orig.mThemeAttrsSegments;
@@ -683,10 +742,30 @@
public void setStroke(int width, int color, float dashWidth, float dashGap) {
mStrokeWidth = width;
- mStrokeColor = color;
mStrokeDashWidth = dashWidth;
mStrokeDashGap = dashGap;
+
+ setStrokeColor(color);
}
+
+ public void setStrokeColor(int color) {
+ mStrokeColor = color;
+ mFadedStrokeColor = getFadedColor(color);
+ }
+
+ public void setPointRectColor(int color) {
+ mPointRectColor = color;
+ mFadedPointRectColor = getFadedColor(color);
+ }
+ }
+
+ /**
+ * Get a color with an opacity that's 50% of the input color.
+ */
+ @ColorInt
+ static int getFadedColor(@ColorInt int color) {
+ return Color.argb(Color.alpha(color) / 2, Color.red(color), Color.green(color),
+ Color.blue(color));
}
@Override
diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java
index e65b4b6..46855c6 100644
--- a/core/java/com/android/internal/widget/PointerLocationView.java
+++ b/core/java/com/android/internal/widget/PointerLocationView.java
@@ -16,14 +16,19 @@
package com.android.internal.widget;
+import static java.lang.Float.NaN;
+
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.Configuration;
+import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.Paint;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.Path;
+import android.graphics.PorterDuff;
import android.graphics.RectF;
import android.graphics.Region;
import android.hardware.input.InputManager;
@@ -40,6 +45,7 @@
import android.view.MotionEvent;
import android.view.MotionEvent.PointerCoords;
import android.view.RoundedCorner;
+import android.view.Surface;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
@@ -65,18 +71,21 @@
private static final PointerState EMPTY_POINTER_STATE = new PointerState();
public static class PointerState {
- // Trace of previous points.
- private float[] mTraceX = new float[32];
- private float[] mTraceY = new float[32];
- private boolean[] mTraceCurrent = new boolean[32];
- private int mTraceCount;
+ private float mCurrentX = NaN;
+ private float mCurrentY = NaN;
+ private float mPreviousX = NaN;
+ private float mPreviousY = NaN;
+ private float mFirstX = NaN;
+ private float mFirstY = NaN;
+ private boolean mPreviousPointIsHistorical;
+ private boolean mCurrentPointIsHistorical;
// True if the pointer is down.
@UnsupportedAppUsage
private boolean mCurDown;
// Most recent coordinates.
- private PointerCoords mCoords = new PointerCoords();
+ private final PointerCoords mCoords = new PointerCoords();
private int mToolType;
// Most recent velocity.
@@ -96,31 +105,20 @@
public PointerState() {
}
- public void clearTrace() {
- mTraceCount = 0;
- }
-
- public void addTrace(float x, float y, boolean current) {
- int traceCapacity = mTraceX.length;
- if (mTraceCount == traceCapacity) {
- traceCapacity *= 2;
- float[] newTraceX = new float[traceCapacity];
- System.arraycopy(mTraceX, 0, newTraceX, 0, mTraceCount);
- mTraceX = newTraceX;
-
- float[] newTraceY = new float[traceCapacity];
- System.arraycopy(mTraceY, 0, newTraceY, 0, mTraceCount);
- mTraceY = newTraceY;
-
- boolean[] newTraceCurrent = new boolean[traceCapacity];
- System.arraycopy(mTraceCurrent, 0, newTraceCurrent, 0, mTraceCount);
- mTraceCurrent= newTraceCurrent;
+ void addTrace(float x, float y, boolean isHistorical) {
+ if (Float.isNaN(mFirstX)) {
+ mFirstX = x;
+ }
+ if (Float.isNaN(mFirstY)) {
+ mFirstY = y;
}
- mTraceX[mTraceCount] = x;
- mTraceY[mTraceCount] = y;
- mTraceCurrent[mTraceCount] = current;
- mTraceCount += 1;
+ mPreviousX = mCurrentX;
+ mPreviousY = mCurrentY;
+ mCurrentX = x;
+ mCurrentY = y;
+ mPreviousPointIsHistorical = mCurrentPointIsHistorical;
+ mCurrentPointIsHistorical = isHistorical;
}
}
@@ -149,6 +147,13 @@
private final SparseArray<PointerState> mPointers = new SparseArray<PointerState>();
private final PointerCoords mTempCoords = new PointerCoords();
+ // Draw the trace of all pointers in the current gesture in a separate layer
+ // that is not cleared on every frame so that we don't have to re-draw the
+ // entire trace on each frame. The trace bitmap is in the coordinate space of the unrotated
+ // display.
+ private Bitmap mTraceBitmap;
+ private final Canvas mTraceCanvas;
+
private final Region mSystemGestureExclusion = new Region();
private final Region mSystemGestureExclusionRejected = new Region();
private final Path mSystemGestureExclusionPath = new Path();
@@ -197,6 +202,9 @@
mPathPaint.setARGB(255, 0, 96, 255);
mPathPaint.setStyle(Paint.Style.STROKE);
+ mTraceCanvas = new Canvas();
+ configureTraceBitmap();
+
configureDensityDependentFactors();
mSystemGestureExclusionPaint = new Paint();
@@ -256,7 +264,7 @@
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mTextPaint.getFontMetricsInt(mTextMetrics);
- mHeaderBottom = mHeaderPaddingTop-mTextMetrics.ascent+mTextMetrics.descent+2;
+ mHeaderBottom = mHeaderPaddingTop - mTextMetrics.ascent + mTextMetrics.descent + 2;
if (false) {
Log.i("foo", "Metrics: ascent=" + mTextMetrics.ascent
+ " descent=" + mTextMetrics.descent
@@ -268,7 +276,8 @@
// Draw an oval. When angle is 0 radians, orients the major axis vertically,
// angles less than or greater than 0 radians rotate the major axis left or right.
- private RectF mReusableOvalRect = new RectF();
+ private final RectF mReusableOvalRect = new RectF();
+
private void drawOval(Canvas canvas, float x, float y, float major, float minor,
float angle, Paint paint) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
@@ -285,6 +294,12 @@
protected void onDraw(Canvas canvas) {
final int NP = mPointers.size();
+ // Pointer trace.
+ canvas.save();
+ rotateCanvasToUnrotatedDisplay(canvas);
+ canvas.drawBitmap(mTraceBitmap, 0, 0, null);
+ canvas.restore();
+
if (!mSystemGestureExclusion.isEmpty()) {
mSystemGestureExclusionPath.reset();
mSystemGestureExclusion.getBoundaryPath(mSystemGestureExclusionPath);
@@ -300,35 +315,14 @@
// Labels
drawLabels(canvas);
- // Pointer trace.
+ // Current pointer states.
+ canvas.save();
+ rotateCanvasToUnrotatedDisplay(canvas);
for (int p = 0; p < NP; p++) {
final PointerState ps = mPointers.valueAt(p);
+ float lastX = ps.mCurrentX, lastY = ps.mCurrentY;
- // Draw path.
- final int N = ps.mTraceCount;
- float lastX = 0, lastY = 0;
- boolean haveLast = false;
- boolean drawn = false;
- mPaint.setARGB(255, 128, 255, 255);
- for (int i=0; i < N; i++) {
- float x = ps.mTraceX[i];
- float y = ps.mTraceY[i];
- if (Float.isNaN(x) || Float.isNaN(y)) {
- haveLast = false;
- continue;
- }
- if (haveLast) {
- canvas.drawLine(lastX, lastY, x, y, mPathPaint);
- final Paint paint = ps.mTraceCurrent[i - 1] ? mCurrentPointPaint : mPaint;
- canvas.drawPoint(lastX, lastY, paint);
- drawn = true;
- }
- lastX = x;
- lastY = y;
- haveLast = true;
- }
-
- if (drawn) {
+ if (!Float.isNaN(lastX) && !Float.isNaN(lastY)) {
// Draw velocity vector.
mPaint.setARGB(255, 255, 64, 128);
float xVel = ps.mXVelocity * (1000 / 60);
@@ -353,7 +347,7 @@
Math.max(getHeight(), getWidth()), mTargetPaint);
// Draw current point.
- int pressureLevel = (int)(ps.mCoords.pressure * 255);
+ int pressureLevel = (int) (ps.mCoords.pressure * 255);
mPaint.setARGB(255, pressureLevel, 255, 255 - pressureLevel);
canvas.drawPoint(ps.mCoords.x, ps.mCoords.y, mPaint);
@@ -406,6 +400,7 @@
}
}
}
+ canvas.restore();
}
private void drawLabels(Canvas canvas) {
@@ -424,8 +419,7 @@
.append(" / ").append(mMaxNumPointers)
.toString(), 1, base, mTextPaint);
- final int count = ps.mTraceCount;
- if ((mCurDown && ps.mCurDown) || count == 0) {
+ if ((mCurDown && ps.mCurDown) || Float.isNaN(ps.mCurrentX)) {
canvas.drawRect(itemW, mHeaderPaddingTop, (itemW * 2) - 1, bottom,
mTextBackgroundPaint);
canvas.drawText(mText.clear()
@@ -437,8 +431,8 @@
.append("Y: ").append(ps.mCoords.y, 1)
.toString(), 1 + itemW * 2, base, mTextPaint);
} else {
- float dx = ps.mTraceX[count - 1] - ps.mTraceX[0];
- float dy = ps.mTraceY[count - 1] - ps.mTraceY[0];
+ float dx = ps.mCurrentX - ps.mFirstX;
+ float dy = ps.mCurrentY - ps.mFirstY;
canvas.drawRect(itemW, mHeaderPaddingTop, (itemW * 2) - 1, bottom,
Math.abs(dx) < mVC.getScaledTouchSlop()
? mTextBackgroundPaint : mTextLevelPaint);
@@ -565,9 +559,9 @@
.append(" TouchMinor=").append(coords.touchMinor, 3)
.append(" ToolMajor=").append(coords.toolMajor, 3)
.append(" ToolMinor=").append(coords.toolMinor, 3)
- .append(" Orientation=").append((float)(coords.orientation * 180 / Math.PI), 1)
+ .append(" Orientation=").append((float) (coords.orientation * 180 / Math.PI), 1)
.append("deg")
- .append(" Tilt=").append((float)(
+ .append(" Tilt=").append((float) (
coords.getAxisValue(MotionEvent.AXIS_TILT) * 180 / Math.PI), 1)
.append("deg")
.append(" Distance=").append(coords.getAxisValue(MotionEvent.AXIS_DISTANCE), 1)
@@ -586,6 +580,11 @@
@Override
public void onPointerEvent(MotionEvent event) {
+ // PointerLocationView stores and draws events in the unrotated display space, so undo the
+ // event's rotation to bring it back to the unrotated display space.
+ event.transform(MotionEvent.createRotateMatrix(inverseRotation(event.getSurfaceRotation()),
+ mTraceBitmap.getWidth(), mTraceBitmap.getHeight()));
+
final int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN
@@ -598,6 +597,7 @@
mCurNumPointers = 0;
mMaxNumPointers = 0;
mVelocity.clear();
+ mTraceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
if (mAltVelocity != null) {
mAltVelocity.clear();
}
@@ -646,7 +646,8 @@
logCoords("Pointer", action, i, coords, id, event);
}
if (ps != null) {
- ps.addTrace(coords.x, coords.y, false);
+ ps.addTrace(coords.x, coords.y, /*isHistorical*/ true);
+ updateDrawTrace(ps);
}
}
}
@@ -659,7 +660,8 @@
logCoords("Pointer", action, i, coords, id, event);
}
if (ps != null) {
- ps.addTrace(coords.x, coords.y, true);
+ ps.addTrace(coords.x, coords.y, /*isHistorical*/ false);
+ updateDrawTrace(ps);
ps.mXVelocity = mVelocity.getXVelocity(id);
ps.mYVelocity = mVelocity.getYVelocity(id);
if (mAltVelocity != null) {
@@ -702,13 +704,27 @@
if (mActivePointerId == id) {
mActivePointerId = event.getPointerId(index == 0 ? 1 : 0);
}
- ps.addTrace(Float.NaN, Float.NaN, false);
+ ps.addTrace(Float.NaN, Float.NaN, true);
}
}
invalidate();
}
+ private void updateDrawTrace(PointerState ps) {
+ mPaint.setARGB(255, 128, 255, 255);
+ float x = ps.mCurrentX;
+ float y = ps.mCurrentY;
+ float lastX = ps.mPreviousX;
+ float lastY = ps.mPreviousY;
+ if (Float.isNaN(x) || Float.isNaN(y) || Float.isNaN(lastX) || Float.isNaN(lastY)) {
+ return;
+ }
+ mTraceCanvas.drawLine(lastX, lastY, x, y, mPathPaint);
+ Paint paint = ps.mPreviousPointIsHistorical ? mPaint : mCurrentPointPaint;
+ mTraceCanvas.drawPoint(lastX, lastY, paint);
+ }
+
@Override
public boolean onTouchEvent(MotionEvent event) {
onPointerEvent(event);
@@ -767,7 +783,7 @@
return true;
default:
return KeyEvent.isGamepadButton(keyCode)
- || KeyEvent.isModifierKey(keyCode);
+ || KeyEvent.isModifierKey(keyCode);
}
}
@@ -887,7 +903,7 @@
public FasterStringBuilder append(int value, int zeroPadWidth) {
final boolean negative = value < 0;
if (negative) {
- value = - value;
+ value = -value;
if (value < 0) {
append("-2147483648");
return this;
@@ -971,32 +987,34 @@
}
}
- private ISystemGestureExclusionListener mSystemGestureExclusionListener =
+ private final ISystemGestureExclusionListener mSystemGestureExclusionListener =
new ISystemGestureExclusionListener.Stub() {
- @Override
- public void onSystemGestureExclusionChanged(int displayId, Region systemGestureExclusion,
- Region systemGestureExclusionUnrestricted) {
- Region exclusion = Region.obtain(systemGestureExclusion);
- Region rejected = Region.obtain();
- if (systemGestureExclusionUnrestricted != null) {
- rejected.set(systemGestureExclusionUnrestricted);
- rejected.op(exclusion, Region.Op.DIFFERENCE);
- }
- Handler handler = getHandler();
- if (handler != null) {
- handler.post(() -> {
- mSystemGestureExclusion.set(exclusion);
- mSystemGestureExclusionRejected.set(rejected);
- exclusion.recycle();
- invalidate();
- });
- }
- }
- };
+ @Override
+ public void onSystemGestureExclusionChanged(int displayId,
+ Region systemGestureExclusion,
+ Region systemGestureExclusionUnrestricted) {
+ Region exclusion = Region.obtain(systemGestureExclusion);
+ Region rejected = Region.obtain();
+ if (systemGestureExclusionUnrestricted != null) {
+ rejected.set(systemGestureExclusionUnrestricted);
+ rejected.op(exclusion, Region.Op.DIFFERENCE);
+ }
+ Handler handler = getHandler();
+ if (handler != null) {
+ handler.post(() -> {
+ mSystemGestureExclusion.set(exclusion);
+ mSystemGestureExclusionRejected.set(rejected);
+ exclusion.recycle();
+ invalidate();
+ });
+ }
+ }
+ };
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
+ configureTraceBitmap();
configureDensityDependentFactors();
}
@@ -1008,4 +1026,58 @@
mCurrentPointPaint.setStrokeWidth(1 * mDensity);
mPathPaint.setStrokeWidth(1 * mDensity);
}
+
+ private void configureTraceBitmap() {
+ final var display = mContext.getDisplay();
+ final boolean rotated = display.getRotation() == Surface.ROTATION_90
+ || display.getRotation() == Surface.ROTATION_270;
+ int unrotatedWidth = rotated ? display.getHeight() : display.getWidth();
+ int unrotatedHeight = rotated ? display.getWidth() : display.getHeight();
+
+ if (mTraceBitmap != null && mTraceBitmap.getWidth() == unrotatedWidth
+ && mTraceBitmap.getHeight() == unrotatedHeight) {
+ return;
+ }
+ if (unrotatedWidth <= 0 || unrotatedHeight <= 0) {
+ Slog.w(TAG, "Ignoring configuration: invalid display size: " + unrotatedWidth + "x"
+ + unrotatedHeight);
+ // Initialize the bitmap to an arbitrary size. It should be reconfigured with a valid
+ // size in the future.
+ unrotatedWidth = 100;
+ unrotatedHeight = 100;
+ }
+ mTraceBitmap = Bitmap.createBitmap(unrotatedWidth, unrotatedHeight,
+ Bitmap.Config.ARGB_8888);
+ mTraceCanvas.setBitmap(mTraceBitmap);
+ }
+
+ private static int inverseRotation(@Surface.Rotation int rotation) {
+ return switch(rotation) {
+ case Surface.ROTATION_0 -> Surface.ROTATION_0;
+ case Surface.ROTATION_90 -> Surface.ROTATION_270;
+ case Surface.ROTATION_180 -> Surface.ROTATION_180;
+ case Surface.ROTATION_270 -> Surface.ROTATION_90;
+ default -> {
+ Slog.e(TAG, "Received unexpected surface rotation: " + rotation);
+ yield Surface.ROTATION_0;
+ }
+ };
+ }
+
+ private void rotateCanvasToUnrotatedDisplay(Canvas c) {
+ switch (inverseRotation(mContext.getDisplay().getRotation())) {
+ case Surface.ROTATION_90 -> {
+ c.rotate(90);
+ c.translate(0, -mTraceBitmap.getHeight());
+ }
+ case Surface.ROTATION_180 -> {
+ c.rotate(180);
+ c.translate(-mTraceBitmap.getWidth(), -mTraceBitmap.getHeight());
+ }
+ case Surface.ROTATION_270 -> {
+ c.rotate(270);
+ c.translate(-mTraceBitmap.getWidth(), 0);
+ }
+ }
+ }
}
diff --git a/core/tests/coretests/src/com/android/internal/widget/NotificationProgressBarTest.java b/core/tests/coretests/src/com/android/internal/widget/NotificationProgressBarTest.java
new file mode 100644
index 0000000..6419c1e0
--- /dev/null
+++ b/core/tests/coretests/src/com/android/internal/widget/NotificationProgressBarTest.java
@@ -0,0 +1,302 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Notification.ProgressStyle;
+import android.graphics.Color;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.internal.widget.NotificationProgressDrawable.Part;
+import com.android.internal.widget.NotificationProgressDrawable.Point;
+import com.android.internal.widget.NotificationProgressDrawable.Segment;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public class NotificationProgressBarTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_segmentsIsEmpty() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ int progress = 50;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_segmentLengthIsNegative() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(-50));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ int progress = 50;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_segmentLengthIsZero() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(0));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ int progress = 50;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_progressIsNegative() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ int progress = -50;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test
+ public void processAndConvertToDrawableParts_progressIsZero() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100).setColor(Color.RED));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ int progress = 0;
+ boolean isStyledByProgress = true;
+
+ List<Part> parts = NotificationProgressBar.processAndConvertToDrawableParts(
+ segments, points, progress, isStyledByProgress);
+
+ int fadedRed = 0x7FFF0000;
+ List<Part> expected = new ArrayList<>(List.of(new Segment(1f, fadedRed, true)));
+
+ assertThat(parts).isEqualTo(expected);
+ }
+
+ @Test
+ public void processAndConvertToDrawableParts_progressAtMax() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100).setColor(Color.RED));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ int progress = 100;
+ boolean isStyledByProgress = true;
+
+ List<Part> parts = NotificationProgressBar.processAndConvertToDrawableParts(
+ segments, points, progress, isStyledByProgress);
+
+ List<Part> expected = new ArrayList<>(List.of(new Segment(1f, Color.RED)));
+
+ assertThat(parts).isEqualTo(expected);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_progressAboveMax() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ int progress = 150;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_pointPositionIsNegative() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ points.add(new ProgressStyle.Point(-50).setColor(Color.RED));
+ int progress = 50;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_pointPositionIsZero() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ points.add(new ProgressStyle.Point(0).setColor(Color.RED));
+ int progress = 50;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_pointPositionAtMax() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ points.add(new ProgressStyle.Point(100).setColor(Color.RED));
+ int progress = 50;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void processAndConvertToDrawableParts_pointPositionAboveMax() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ points.add(new ProgressStyle.Point(150).setColor(Color.RED));
+ int progress = 50;
+ boolean isStyledByProgress = true;
+
+ NotificationProgressBar.processAndConvertToDrawableParts(segments, points, progress,
+ isStyledByProgress);
+ }
+
+ @Test
+ public void processAndConvertToDrawableParts_multipleSegmentsWithoutPoints() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(50).setColor(Color.RED));
+ segments.add(new ProgressStyle.Segment(50).setColor(Color.GREEN));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ int progress = 60;
+ boolean isStyledByProgress = true;
+
+ List<Part> parts = NotificationProgressBar.processAndConvertToDrawableParts(
+ segments, points, progress, isStyledByProgress);
+
+ // Colors with 50% opacity
+ int fadedGreen = 0x7F00FF00;
+
+ List<Part> expected = new ArrayList<>(List.of(
+ new Segment(0.50f, Color.RED),
+ new Segment(0.10f, Color.GREEN),
+ new Segment(0.40f, fadedGreen, true)));
+
+ assertThat(parts).isEqualTo(expected);
+ }
+
+ @Test
+ public void processAndConvertToDrawableParts_singleSegmentWithPoints() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(100).setColor(Color.BLUE));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ points.add(new ProgressStyle.Point(15).setColor(Color.RED));
+ points.add(new ProgressStyle.Point(25).setColor(Color.BLUE));
+ points.add(new ProgressStyle.Point(60).setColor(Color.BLUE));
+ points.add(new ProgressStyle.Point(75).setColor(Color.YELLOW));
+ int progress = 60;
+ boolean isStyledByProgress = true;
+
+ // Colors with 50% opacity
+ int fadedBlue = 0x7F0000FF;
+ int fadedYellow = 0x7FFFFF00;
+
+ List<Part> expected = new ArrayList<>(List.of(
+ new Segment(0.15f, Color.BLUE),
+ new Point(null, Color.RED),
+ new Segment(0.10f, Color.BLUE),
+ new Point(null, Color.BLUE),
+ new Segment(0.35f, Color.BLUE),
+ new Point(null, Color.BLUE),
+ new Segment(0.15f, fadedBlue, true),
+ new Point(null, fadedYellow, true),
+ new Segment(0.25f, fadedBlue, true)));
+
+ List<Part> parts = NotificationProgressBar.processAndConvertToDrawableParts(
+ segments, points, progress, isStyledByProgress);
+
+ assertThat(parts).isEqualTo(expected);
+ }
+
+ @Test
+ public void processAndConvertToDrawableParts_multipleSegmentsWithPoints() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(50).setColor(Color.RED));
+ segments.add(new ProgressStyle.Segment(50).setColor(Color.GREEN));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ points.add(new ProgressStyle.Point(15).setColor(Color.RED));
+ points.add(new ProgressStyle.Point(25).setColor(Color.BLUE));
+ points.add(new ProgressStyle.Point(60).setColor(Color.BLUE));
+ points.add(new ProgressStyle.Point(75).setColor(Color.YELLOW));
+ int progress = 60;
+ boolean isStyledByProgress = true;
+
+ List<Part> parts = NotificationProgressBar.processAndConvertToDrawableParts(
+ segments, points, progress, isStyledByProgress);
+
+ // Colors with 50% opacity
+ int fadedGreen = 0x7F00FF00;
+ int fadedBlue = 0x7F0000FF;
+ int fadedYellow = 0x7FFFFF00;
+
+ List<Part> expected = new ArrayList<>(List.of(
+ new Segment(0.15f, Color.RED),
+ new Point(null, Color.RED),
+ new Segment(0.10f, Color.RED),
+ new Point(null, Color.BLUE),
+ new Segment(0.25f, Color.RED),
+ new Segment(0.10f, Color.GREEN),
+ new Point(null, Color.BLUE),
+ new Segment(0.15f, fadedGreen, true),
+ new Point(null, fadedYellow, true),
+ new Segment(0.25f, fadedGreen, true)));
+
+ assertThat(parts).isEqualTo(expected);
+ }
+
+ @Test
+ public void processAndConvertToDrawableParts_multipleSegmentsWithPoints_notStyledByProgress() {
+ List<ProgressStyle.Segment> segments = new ArrayList<>();
+ segments.add(new ProgressStyle.Segment(50).setColor(Color.RED));
+ segments.add(new ProgressStyle.Segment(50).setColor(Color.GREEN));
+ List<ProgressStyle.Point> points = new ArrayList<>();
+ points.add(new ProgressStyle.Point(15).setColor(Color.RED));
+ points.add(new ProgressStyle.Point(25).setColor(Color.BLUE));
+ points.add(new ProgressStyle.Point(75).setColor(Color.YELLOW));
+ int progress = 60;
+ boolean isStyledByProgress = false;
+
+ List<Part> parts = NotificationProgressBar.processAndConvertToDrawableParts(
+ segments, points, progress, isStyledByProgress);
+
+ List<Part> expected = new ArrayList<>(List.of(
+ new Segment(0.15f, Color.RED),
+ new Point(null, Color.RED),
+ new Segment(0.10f, Color.RED),
+ new Point(null, Color.BLUE),
+ new Segment(0.25f, Color.RED),
+ new Segment(0.25f, Color.GREEN),
+ new Point(null, Color.YELLOW),
+ new Segment(0.25f, Color.GREEN)));
+
+ assertThat(parts).isEqualTo(expected);
+ }
+}
diff --git a/libs/WindowManager/Shell/AndroidManifest.xml b/libs/WindowManager/Shell/AndroidManifest.xml
index 3b739c3..1260796 100644
--- a/libs/WindowManager/Shell/AndroidManifest.xml
+++ b/libs/WindowManager/Shell/AndroidManifest.xml
@@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.WAKEUP_SURFACE_FLINGER" />
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
<uses-permission android:name="android.permission.SUBSCRIBE_TO_KEYGUARD_LOCKED_STATE" />
+ <uses-permission android:name="android.permission.UPDATE_DOMAIN_VERIFICATION_USER_SELECTION" />
<application>
<activity
diff --git a/libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_dismiss_button_background.xml b/libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_confirm_button_background.xml
similarity index 100%
rename from libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_dismiss_button_background.xml
rename to libs/WindowManager/Shell/res/drawable/open_by_default_settings_dialog_confirm_button_background.xml
diff --git a/libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml b/libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml
index 8ff382b..b5bceda 100644
--- a/libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml
+++ b/libs/WindowManager/Shell/res/layout/open_by_default_settings_dialog.xml
@@ -111,7 +111,7 @@
</RadioGroup>
<Button
- android:id="@+id/open_by_default_settings_dialog_dismiss_button"
+ android:id="@+id/open_by_default_settings_dialog_confirm_button"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:text="@string/open_by_default_dialog_dismiss_button_text"
@@ -122,7 +122,7 @@
android:textSize="14sp"
android:textFontWeight="500"
android:textColor="?androidprv:attr/materialColorOnPrimary"
- android:background="@drawable/open_by_default_settings_dialog_dismiss_button_background"/>
+ android:background="@drawable/open_by_default_settings_dialog_confirm_button_background"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt
index 71bcb59..65132fe 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt
@@ -22,7 +22,13 @@
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.pm.PackageManager
+import android.content.pm.verify.domain.DomainVerificationManager
+import android.content.pm.verify.domain.DomainVerificationUserState
import android.net.Uri
+import com.android.internal.protolog.ProtoLog
+import com.android.wm.shell.protolog.ShellProtoLogGroup
+
+private const val TAG = "AppToWebUtils"
private val GenericBrowserIntent = Intent()
.setAction(Intent.ACTION_VIEW)
@@ -58,4 +64,25 @@
val component = intent.resolveActivity(packageManager) ?: return null
intent.setComponent(component)
return intent
-}
\ No newline at end of file
+}
+
+/**
+ * Returns the [DomainVerificationUserState] of the user associated with the given
+ * [DomainVerificationManager] and the given package.
+ */
+fun getDomainVerificationUserState(
+ manager: DomainVerificationManager,
+ packageName: String
+): DomainVerificationUserState? {
+ try {
+ return manager.getDomainVerificationUserState(packageName)
+ } catch (e: PackageManager.NameNotFoundException) {
+ ProtoLog.w(
+ ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
+ "%s: Failed to get domain verification user state: %s",
+ TAG,
+ e.message!!
+ )
+ return null
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt
index 4926cbd..a727b54 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialog.kt
@@ -19,6 +19,7 @@
import android.app.ActivityManager.RunningTaskInfo
import android.app.TaskInfo
import android.content.Context
+import android.content.pm.verify.domain.DomainVerificationManager
import android.graphics.Bitmap
import android.graphics.PixelFormat
import android.view.LayoutInflater
@@ -30,6 +31,7 @@
import android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL
import android.view.WindowlessWindowManager
import android.widget.ImageView
+import android.widget.RadioButton
import android.widget.TextView
import android.window.TaskConstants
import com.android.wm.shell.R
@@ -58,8 +60,17 @@
private lateinit var appIconView: ImageView
private lateinit var appNameView: TextView
+ private lateinit var openInAppButton: RadioButton
+ private lateinit var openInBrowserButton: RadioButton
+
+ private val domainVerificationManager =
+ context.getSystemService(DomainVerificationManager::class.java)!!
+ private val packageName = taskInfo.baseActivity?.packageName!!
+
+
init {
createDialog()
+ initializeRadioButtons()
bindAppInfo(appIconBitmap, appName)
}
@@ -111,9 +122,30 @@
closeMenu()
}
+ dialog.setConfirmButtonClickListener {
+ setDefaultLinkHandlingSetting()
+ closeMenu()
+ }
+
listener.onDialogCreated()
}
+ private fun initializeRadioButtons() {
+ openInAppButton = dialog.requireViewById(R.id.open_in_app_button)
+ openInBrowserButton = dialog.requireViewById(R.id.open_in_browser_button)
+
+ val userState =
+ getDomainVerificationUserState(domainVerificationManager, packageName) ?: return
+ val openInApp = userState.isLinkHandlingAllowed
+ openInAppButton.isChecked = openInApp
+ openInBrowserButton.isChecked = !openInApp
+ }
+
+ private fun setDefaultLinkHandlingSetting() {
+ domainVerificationManager.setDomainVerificationLinkHandlingAllowed(
+ packageName, openInAppButton.isChecked)
+ }
+
private fun closeMenu() {
dialogContainer?.releaseView()
dialogContainer = null
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt
index d03a38e..1b914f4 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/OpenByDefaultDialogView.kt
@@ -36,9 +36,6 @@
private lateinit var backgroundDim: Drawable
fun setDismissOnClickListener(callback: (View) -> Unit) {
- val dismissButton = dialogContainer.requireViewById<Button>(
- R.id.open_by_default_settings_dialog_dismiss_button)
- dismissButton.setOnClickListener(callback)
// Clicks on the background dim should also dismiss the dialog.
setOnClickListener(callback)
// We add a no-op on-click listener to the dialog container so that clicks on it won't
@@ -46,6 +43,13 @@
dialogContainer.setOnClickListener { }
}
+ fun setConfirmButtonClickListener(callback: (View) -> Unit) {
+ val dismissButton = dialogContainer.requireViewById<Button>(
+ R.id.open_by_default_settings_dialog_confirm_button
+ )
+ dismissButton.setOnClickListener(callback)
+ }
+
override fun onFinishInflate() {
super.onFinishInflate()
dialogContainer = requireViewById(R.id.open_by_default_dialog_container)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
index b3491ba..b83b5f3 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
@@ -177,26 +177,84 @@
}
/**
+ * Calculates the transform to apply on a UNTRANSFORMED (config-at-end) Activity surface in
+ * order for it's hint-rect to occupy the same task-relative position/dimensions as it would
+ * have at the end of the transition (post-configuration).
+ *
+ * This is intended to be used in tandem with [calcStartTransform] below applied to the parent
+ * task. Applying both transforms simultaneously should result in the appearance of nothing
+ * having happened yet.
+ *
+ * Only the task should be animated (into it's identity state) and then WMCore will reset the
+ * activity transform in sync with its new configuration upon finish.
+ *
+ * Usage example:
+ * calcEndTransform(pipActivity, pipTask, scale, pos);
+ * t.setScale(pipActivity.getLeash(), scale.x, scale.y);
+ * t.setPosition(pipActivity.getLeash(), pos.x, pos.y);
+ *
+ * @see calcStartTransform
+ */
+ @JvmStatic
+ fun calcEndTransform(pipActivity: TransitionInfo.Change, pipTask: TransitionInfo.Change,
+ outScale: PointF, outPos: PointF) {
+ val actStartBounds = pipActivity.startAbsBounds
+ val actEndBounds = pipActivity.endAbsBounds
+ val taskEndBounds = pipTask.endAbsBounds
+
+ var hintRect = pipTask.taskInfo?.pictureInPictureParams?.sourceRectHint
+ if (hintRect == null) {
+ hintRect = Rect(actStartBounds)
+ hintRect.offsetTo(0, 0)
+ }
+
+ // FA = final activity bounds (absolute)
+ // FT = final task bounds (absolute)
+ // SA = start activity bounds (absolute)
+ // H = source hint (relative to start activity bounds)
+ // We want to transform the activity so that when the task is at FT, H overlaps with FA
+
+ // This scales the activity such that the hint rect has the same dimensions
+ // as the final activity bounds.
+ val hintToEndScaleX = (actEndBounds.width().toFloat()) / (hintRect.width().toFloat())
+ val hintToEndScaleY = (actEndBounds.height().toFloat()) / (hintRect.height().toFloat())
+ // top-left needs to be (FA.tl - FT.tl) - H.tl * hintToEnd . H is relative to the
+ // activity; so, for example, if shrinking H to FA (hintToEnd < 1), then the tl of the
+ // shrunk SA is closer to H than expected, so we need to reduce how much we offset SA
+ // to get H.tl to match.
+ val startActPosInTaskEndX =
+ (actEndBounds.left - taskEndBounds.left) - hintRect.left * hintToEndScaleX
+ val startActPosInTaskEndY =
+ (actEndBounds.top - taskEndBounds.top) - hintRect.top * hintToEndScaleY
+ outScale.set(hintToEndScaleX, hintToEndScaleY)
+ outPos.set(startActPosInTaskEndX, startActPosInTaskEndY)
+ }
+
+ /**
* Calculates the transform and crop to apply on a Task surface in order for the config-at-end
* activity inside it (original-size activity transformed to match it's hint rect to the final
* Task bounds) to occupy the same world-space position/dimensions as it had before the
* transition.
*
+ * Intended to be used in tandem with [calcEndTransform].
+ *
* Usage example:
- * calcStartTransform(pipChange, scale, pos, crop);
- * t.setScale(pipChange.getLeash(), scale.x, scale.y);
- * t.setPosition(pipChange.getLeash(), pos.x, pos.y);
- * t.setCrop(pipChange.getLeash(), crop);
+ * calcStartTransform(pipTask, scale, pos, crop);
+ * t.setScale(pipTask.getLeash(), scale.x, scale.y);
+ * t.setPosition(pipTask.getLeash(), pos.x, pos.y);
+ * t.setCrop(pipTask.getLeash(), crop);
+ *
+ * @see calcEndTransform
*/
@JvmStatic
- fun calcStartTransform(pipChange: TransitionInfo.Change, outScale: PointF,
+ fun calcStartTransform(pipTask: TransitionInfo.Change, outScale: PointF,
outPos: PointF, outCrop: Rect) {
- val startBounds = pipChange.startAbsBounds
- val taskEndBounds = pipChange.endAbsBounds
+ val startBounds = pipTask.startAbsBounds
+ val taskEndBounds = pipTask.endAbsBounds
// For now, pip activity bounds always matches task bounds. If this ever changes, we'll
// need to get the activity offset.
val endBounds = taskEndBounds
- var hintRect = pipChange.taskInfo?.pictureInPictureParams?.sourceRectHint
+ var hintRect = pipTask.taskInfo?.pictureInPictureParams?.sourceRectHint
if (hintRect == null) {
hintRect = Rect(startBounds)
hintRect.offsetTo(0, 0)
@@ -226,8 +284,8 @@
+ startBounds.left + hintRect.left)
val endTaskPosForStartY = (-(endBounds.top - taskEndBounds.top) * endToHintScaleY
+ startBounds.top + hintRect.top)
- outScale[endToHintScaleX] = endToHintScaleY
- outPos[endTaskPosForStartX] = endTaskPosForStartY
+ outScale.set(endToHintScaleX, endToHintScaleY)
+ outPos.set(endTaskPosForStartX, endTaskPosForStartY)
// now need to set crop to reveal the non-hint stuff. Again, hintrect is relative, so
// we must apply outsets to reveal the *activity* content which is *inside* the task
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
index 75adef4..ff32c5e 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
@@ -695,10 +695,16 @@
static Optional<DesktopFullImmersiveTransitionHandler> provideDesktopImmersiveHandler(
Context context,
Transitions transitions,
- @DynamicOverride DesktopRepository desktopRepository) {
+ @DynamicOverride DesktopRepository desktopRepository,
+ DisplayController displayController,
+ ShellTaskOrganizer shellTaskOrganizer) {
if (DesktopModeStatus.canEnterDesktopMode(context)) {
return Optional.of(
- new DesktopFullImmersiveTransitionHandler(transitions, desktopRepository));
+ new DesktopFullImmersiveTransitionHandler(
+ transitions,
+ desktopRepository,
+ displayController,
+ shellTaskOrganizer));
}
return Optional.empty();
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt
index f749aa1..679179a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandler.kt
@@ -27,8 +27,12 @@
import android.window.TransitionRequestInfo
import android.window.WindowContainerTransaction
import androidx.core.animation.addListener
+import com.android.internal.annotations.VisibleForTesting
import com.android.internal.protolog.ProtoLog
-import com.android.wm.shell.protolog.ShellProtoLogGroup
+import com.android.window.flags.Flags
+import com.android.wm.shell.ShellTaskOrganizer
+import com.android.wm.shell.common.DisplayController
+import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.transition.Transitions.TransitionHandler
import com.android.wm.shell.windowdecor.OnTaskResizeAnimationListener
@@ -41,16 +45,29 @@
class DesktopFullImmersiveTransitionHandler(
private val transitions: Transitions,
private val desktopRepository: DesktopRepository,
+ private val displayController: DisplayController,
+ private val shellTaskOrganizer: ShellTaskOrganizer,
private val transactionSupplier: () -> SurfaceControl.Transaction,
) : TransitionHandler {
constructor(
transitions: Transitions,
desktopRepository: DesktopRepository,
- ) : this(transitions, desktopRepository, { SurfaceControl.Transaction() })
+ displayController: DisplayController,
+ shellTaskOrganizer: ShellTaskOrganizer,
+ ) : this(
+ transitions,
+ desktopRepository,
+ displayController,
+ shellTaskOrganizer,
+ { SurfaceControl.Transaction() }
+ )
private var state: TransitionState? = null
+ @VisibleForTesting
+ val pendingExternalExitTransitions = mutableSetOf<ExternalPendingExit>()
+
/** Whether there is an immersive transition that hasn't completed yet. */
private val inProgress: Boolean
get() = state != null
@@ -61,15 +78,15 @@
var onTaskResizeAnimationListener: OnTaskResizeAnimationListener? = null
/** Starts a transition to enter full immersive state inside the desktop. */
- fun enterImmersive(taskInfo: RunningTaskInfo, wct: WindowContainerTransaction) {
+ fun moveTaskToImmersive(taskInfo: RunningTaskInfo) {
if (inProgress) {
- ProtoLog.v(
- ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
- "FullImmersive: cannot start entry because transition already in progress."
- )
+ logV("Cannot start entry because transition already in progress.")
return
}
-
+ val wct = WindowContainerTransaction().apply {
+ setBounds(taskInfo.token, Rect())
+ }
+ logV("Moving task ${taskInfo.taskId} into immersive mode")
val transition = transitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ this)
state = TransitionState(
transition = transition,
@@ -79,15 +96,18 @@
)
}
- fun exitImmersive(taskInfo: RunningTaskInfo, wct: WindowContainerTransaction) {
+ fun moveTaskToNonImmersive(taskInfo: RunningTaskInfo) {
if (inProgress) {
- ProtoLog.v(
- ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
- "$TAG: cannot start exit because transition already in progress."
- )
+ logV("Cannot start exit because transition already in progress.")
return
}
+ val displayLayout = displayController.getDisplayLayout(taskInfo.displayId) ?: return
+ val destinationBounds = calculateMaximizeBounds(displayLayout, taskInfo)
+ val wct = WindowContainerTransaction().apply {
+ setBounds(taskInfo.token, destinationBounds)
+ }
+ logV("Moving task ${taskInfo.taskId} out of immersive mode")
val transition = transitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ this)
state = TransitionState(
transition = transition,
@@ -97,6 +117,82 @@
)
}
+ /**
+ * Bring the immersive app of the given [displayId] out of immersive mode, if applicable.
+ *
+ * @param transition that will apply this transaction
+ * @param wct that will apply these changes
+ * @param displayId of the display that should exit immersive mode
+ */
+ fun exitImmersiveIfApplicable(
+ transition: IBinder,
+ wct: WindowContainerTransaction,
+ displayId: Int
+ ) {
+ if (!Flags.enableFullyImmersiveInDesktop()) return
+ exitImmersiveIfApplicable(wct, displayId)?.invoke(transition)
+ }
+
+ /**
+ * Bring the immersive app of the given [displayId] out of immersive mode, if applicable.
+ *
+ * @param wct that will apply these changes
+ * @param displayId of the display that should exit immersive mode
+ * @return a function to apply once the transition that will apply these changes is started
+ */
+ fun exitImmersiveIfApplicable(
+ wct: WindowContainerTransaction,
+ displayId: Int
+ ): ((IBinder) -> Unit)? {
+ if (!Flags.enableFullyImmersiveInDesktop()) return null
+ val displayLayout = displayController.getDisplayLayout(displayId) ?: return null
+ val immersiveTask = desktopRepository.getTaskInFullImmersiveState(displayId) ?: return null
+ val taskInfo = shellTaskOrganizer.getRunningTaskInfo(immersiveTask) ?: return null
+ logV("Appending immersive exit for task: $immersiveTask in display: $displayId")
+ wct.setBounds(taskInfo.token, calculateMaximizeBounds(displayLayout, taskInfo))
+ return { transition -> addPendingImmersiveExit(immersiveTask, displayId, transition) }
+ }
+
+ /**
+ * Bring the given [taskInfo] out of immersive mode, if applicable.
+ *
+ * @param wct that will apply these changes
+ * @param taskInfo of the task that should exit immersive mode
+ * @return a function to apply once the transition that will apply these changes is started
+ */
+ fun exitImmersiveIfApplicable(
+ wct: WindowContainerTransaction,
+ taskInfo: RunningTaskInfo
+ ): ((IBinder) -> Unit)? {
+ if (!Flags.enableFullyImmersiveInDesktop()) return null
+ if (desktopRepository.isTaskInFullImmersiveState(taskInfo.taskId)) {
+ // A full immersive task is being minimized, make sure the immersive state is broken
+ // (i.e. resize back to max bounds).
+ displayController.getDisplayLayout(taskInfo.displayId)?.let { displayLayout ->
+ wct.setBounds(taskInfo.token, calculateMaximizeBounds(displayLayout, taskInfo))
+ logV("Appending immersive exit for task: ${taskInfo.taskId}")
+ return { transition ->
+ addPendingImmersiveExit(
+ taskId = taskInfo.taskId,
+ displayId = taskInfo.displayId,
+ transition = transition
+ )
+ }
+ }
+ }
+ return null
+ }
+
+ private fun addPendingImmersiveExit(taskId: Int, displayId: Int, transition: IBinder) {
+ pendingExternalExitTransitions.add(
+ ExternalPendingExit(
+ taskId = taskId,
+ displayId = displayId,
+ transition = transition
+ )
+ )
+ }
+
override fun startAnimation(
transition: IBinder,
info: TransitionInfo,
@@ -190,15 +286,31 @@
* Called when any transition in the system is ready to play. This is needed to update the
* repository state before window decorations are drawn (which happens immediately after
* |onTransitionReady|, before this transition actually animates) because drawing decorations
- * depends in whether the task is in full immersive state or not.
+ * depends on whether the task is in full immersive state or not.
*/
- fun onTransitionReady(transition: IBinder) {
+ fun onTransitionReady(transition: IBinder, info: TransitionInfo) {
+ // Check if this is a pending external exit transition.
+ val pendingExit = pendingExternalExitTransitions
+ .firstOrNull { pendingExit -> pendingExit.transition == transition }
+ if (pendingExit != null) {
+ pendingExternalExitTransitions.remove(pendingExit)
+ if (info.hasTaskChange(taskId = pendingExit.taskId)) {
+ if (desktopRepository.isTaskInFullImmersiveState(pendingExit.taskId)) {
+ logV("Pending external exit for task ${pendingExit.taskId} verified")
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = pendingExit.displayId,
+ taskId = pendingExit.taskId,
+ immersive = false
+ )
+ }
+ }
+ return
+ }
+
+ // Check if this is a direct immersive enter/exit transition.
val state = this.state ?: return
- // TODO: b/369443668 - this assumes invoking the exit transition is the only way to exit
- // immersive, which isn't realistic. The app could crash, the user could dismiss it from
- // overview, etc. This (or its caller) should search all transitions to look for any
- // immersive task exiting that state to keep the repository properly updated.
if (transition == state.transition) {
+ logV("Direct move for task ${state.taskId} in ${state.direction} direction verified")
when (state.direction) {
Direction.ENTER -> {
desktopRepository.setTaskInFullImmersiveState(
@@ -225,6 +337,9 @@
private fun requireState(): TransitionState =
state ?: error("Expected non-null transition state")
+ private fun TransitionInfo.hasTaskChange(taskId: Int): Boolean =
+ changes.any { c -> c.taskInfo?.taskId == taskId }
+
/** The state of the currently running transition. */
private data class TransitionState(
val transition: IBinder,
@@ -233,12 +348,28 @@
val direction: Direction
)
+ /**
+ * Tracks state of a transition involving an immersive exit that is external to this class' own
+ * transitions. This usually means transitions that exit immersive mode as a side-effect and
+ * not the primary action (for example, minimizing the immersive task or launching a new task
+ * on top of the immersive task).
+ */
+ data class ExternalPendingExit(
+ val taskId: Int,
+ val displayId: Int,
+ val transition: IBinder,
+ )
+
private enum class Direction {
ENTER, EXIT
}
+ private fun logV(msg: String, vararg arguments: Any?) {
+ ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
+ }
+
private companion object {
- private const val TAG = "FullImmersiveHandler"
+ private const val TAG = "DesktopImmersive"
private const val FULL_IMMERSIVE_ANIM_DURATION_MS = 336L
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
index bd61722..6d47922 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
@@ -123,6 +123,29 @@
}
/**
+ * Calculates the maximized bounds of a task given in the given [DisplayLayout], taking
+ * resizability into consideration.
+ */
+fun calculateMaximizeBounds(
+ displayLayout: DisplayLayout,
+ taskInfo: RunningTaskInfo,
+): Rect {
+ val stableBounds = Rect()
+ displayLayout.getStableBounds(stableBounds)
+ if (taskInfo.isResizeable) {
+ // if resizable then expand to entire stable bounds (full display minus insets)
+ return Rect(stableBounds)
+ } else {
+ // if non-resizable then calculate max bounds according to aspect ratio
+ val activityAspectRatio = calculateAspectRatio(taskInfo)
+ val newSize = maximizeSizeGivenAspectRatio(taskInfo,
+ Size(stableBounds.width(), stableBounds.height()), activityAspectRatio)
+ return centerInArea(
+ newSize, stableBounds, stableBounds.left, stableBounds.top)
+ }
+}
+
+/**
* Calculates the largest size that can fit in a given area while maintaining a specific aspect
* ratio.
*/
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
index c175133..5ac4ef5 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
@@ -328,6 +328,10 @@
return desktopTaskDataSequence().any { taskId == it.fullImmersiveTaskId }
}
+ /** Returns the task that is currently in immersive mode in this display, or null. */
+ fun getTaskInFullImmersiveState(displayId: Int): Int? =
+ desktopTaskDataByDisplayId.getOrCreate(displayId).fullImmersiveTaskId
+
private fun notifyVisibleTaskListeners(displayId: Int, visibleTasksCount: Int) {
visibleTasksListeners.forEach { (listener, executor) ->
executor.execute { listener.onTasksVisibilityChanged(displayId, visibleTasksCount) }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
index 75c795b..3f6dc94 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
@@ -91,6 +91,7 @@
import com.android.wm.shell.shared.TransitionUtil
import com.android.wm.shell.shared.annotations.ExternalThread
import com.android.wm.shell.shared.annotations.ShellMainThread
+import com.android.wm.shell.freeform.FreeformTaskTransitionStarter
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.DESKTOP_DENSITY_OVERRIDE
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus.useDesktopOverrideDensity
@@ -190,6 +191,7 @@
private var recentsAnimationRunning = false
private lateinit var splitScreenController: SplitScreenController
+ lateinit var freeformTaskTransitionStarter: FreeformTaskTransitionStarter
// Launch cookie used to identify a drag and drop transition to fullscreen after it has begun.
// Used to prevent handleRequest from moving the new fullscreen task to freeform.
private var dragAndDropFullscreenCookie: Binder? = null
@@ -354,6 +356,8 @@
// TODO(342378842): Instead of using default display, support multiple displays
val taskToMinimize = bringDesktopAppsToFrontBeforeShowingNewTask(
DEFAULT_DISPLAY, wct, taskId)
+ val runOnTransit = immersiveTransitionHandler
+ .exitImmersiveIfApplicable(wct, DEFAULT_DISPLAY)
wct.startTask(
taskId,
ActivityOptions.makeBasic().apply {
@@ -363,6 +367,7 @@
// TODO(343149901): Add DPI changes for task launch
val transition = enterDesktopTaskTransitionHandler.moveToDesktop(wct, transitionSource)
addPendingMinimizeTransition(transition, taskToMinimize)
+ runOnTransit?.invoke(transition)
return true
}
@@ -379,6 +384,7 @@
}
logV("moveRunningTaskToDesktop taskId=%d", task.taskId)
exitSplitIfApplicable(wct, task)
+ val runOnTransit = immersiveTransitionHandler.exitImmersiveIfApplicable(wct, task.displayId)
// Bring other apps to front first
val taskToMinimize =
bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
@@ -386,6 +392,7 @@
val transition = enterDesktopTaskTransitionHandler.moveToDesktop(wct, transitionSource)
addPendingMinimizeTransition(transition, taskToMinimize)
+ runOnTransit?.invoke(transition)
}
/**
@@ -422,8 +429,13 @@
val taskToMinimize =
bringDesktopAppsToFrontBeforeShowingNewTask(taskInfo.displayId, wct, taskInfo.taskId)
addMoveToDesktopChanges(wct, taskInfo)
+ val runOnTransit = immersiveTransitionHandler.exitImmersiveIfApplicable(
+ wct, taskInfo.displayId)
val transition = dragToDesktopTransitionHandler.finishDragToDesktopTransition(wct)
- transition?.let { addPendingMinimizeTransition(it, taskToMinimize) }
+ transition?.let {
+ addPendingMinimizeTransition(it, taskToMinimize)
+ runOnTransit?.invoke(transition)
+ }
}
/**
@@ -455,18 +467,28 @@
taskRepository.addClosingTask(displayId, taskId)
}
- /**
- * Perform clean up of the desktop wallpaper activity if the minimized window task is the last
- * active task.
- *
- * @param wct transaction to modify if the last active task is minimized
- * @param taskId task id of the window that's being minimized
- */
- fun onDesktopWindowMinimize(wct: WindowContainerTransaction, taskId: Int) {
+ fun minimizeTask(taskInfo: RunningTaskInfo) {
+ val taskId = taskInfo.taskId
+ val displayId = taskInfo.displayId
+ val wct = WindowContainerTransaction()
if (taskRepository.isOnlyVisibleNonClosingTask(taskId)) {
+ // Perform clean up of the desktop wallpaper activity if the minimized window task is
+ // the last active task.
removeWallpaperActivity(wct)
}
- // Do not call taskRepository.minimizeTask because it will be called by DekstopTasksLimiter.
+ // Notify immersive handler as it might need to exit immersive state.
+ val runOnTransit = immersiveTransitionHandler.exitImmersiveIfApplicable(wct, taskInfo)
+
+ wct.reorder(taskInfo.token, false)
+ val transition = freeformTaskTransitionStarter.startMinimizedModeTransition(wct)
+ desktopTasksLimiter.ifPresent {
+ it.addPendingMinimizeChange(
+ transition = transition,
+ displayId = displayId,
+ taskId = taskId
+ )
+ }
+ runOnTransit?.invoke(transition)
}
/** Move a task with given `taskId` to fullscreen */
@@ -552,6 +574,8 @@
// TODO: b/342378842 - Instead of using default display, support multiple displays
val taskToMinimize: RunningTaskInfo? =
addAndGetMinimizeChangesIfNeeded(DEFAULT_DISPLAY, wct, taskId)
+ val runOnTransit = immersiveTransitionHandler
+ .exitImmersiveIfApplicable(wct, DEFAULT_DISPLAY)
wct.startTask(
taskId,
ActivityOptions.makeBasic().apply {
@@ -560,6 +584,7 @@
)
val transition = transitions.startTransition(TRANSIT_OPEN, wct, null /* handler */)
addPendingMinimizeTransition(transition, taskToMinimize)
+ runOnTransit?.invoke(transition)
}
/** Move a task to the front */
@@ -567,11 +592,14 @@
logV("moveTaskToFront taskId=%s", taskInfo.taskId)
val wct = WindowContainerTransaction()
wct.reorder(taskInfo.token, true /* onTop */, true /* includingParents */)
+ val runOnTransit = immersiveTransitionHandler.exitImmersiveIfApplicable(
+ wct, taskInfo.displayId)
val taskToMinimize =
addAndGetMinimizeChangesIfNeeded(taskInfo.displayId, wct, taskInfo.taskId)
val transition = transitions.startTransition(TRANSIT_TO_FRONT, wct, null /* handler */)
addPendingMinimizeTransition(transition, taskToMinimize)
+ runOnTransit?.invoke(transition)
}
/**
@@ -643,22 +671,12 @@
private fun moveDesktopTaskToFullImmersive(taskInfo: RunningTaskInfo) {
check(taskInfo.isFreeform) { "Task must already be in freeform" }
- val wct = WindowContainerTransaction().apply {
- setBounds(taskInfo.token, Rect())
- }
- immersiveTransitionHandler.enterImmersive(taskInfo, wct)
+ immersiveTransitionHandler.moveTaskToImmersive(taskInfo)
}
private fun exitDesktopTaskFromFullImmersive(taskInfo: RunningTaskInfo) {
check(taskInfo.isFreeform) { "Task must already be in freeform" }
- val displayLayout = displayController.getDisplayLayout(taskInfo.displayId) ?: return
- val stableBounds = Rect().apply { displayLayout.getStableBounds(this) }
- val destinationBounds = getMaximizeBounds(taskInfo, stableBounds)
-
- val wct = WindowContainerTransaction().apply {
- setBounds(taskInfo.token, destinationBounds)
- }
- immersiveTransitionHandler.exitImmersive(taskInfo, wct)
+ immersiveTransitionHandler.moveTaskToNonImmersive(taskInfo)
}
/**
@@ -697,7 +715,7 @@
// and toggle to the stable bounds.
taskRepository.saveBoundsBeforeMaximize(taskInfo.taskId, currentTaskBounds)
- destinationBounds.set(getMaximizeBounds(taskInfo, stableBounds))
+ destinationBounds.set(calculateMaximizeBounds(displayLayout, taskInfo))
}
@@ -1285,8 +1303,10 @@
if (useDesktopOverrideDensity()) {
wct.setDensityDpi(task.token, DESKTOP_DENSITY_OVERRIDE)
}
- // Desktop Mode is showing and we're launching a new Task - we might need to minimize
- // a Task.
+ // Desktop Mode is showing and we're launching a new Task:
+ // 1) Exit immersive if needed.
+ immersiveTransitionHandler.exitImmersiveIfApplicable(transition, wct, task.displayId)
+ // 2) minimize a Task if needed.
val taskToMinimize = addAndGetMinimizeChangesIfNeeded(task.displayId, wct, task.taskId)
if (taskToMinimize != null) {
addPendingMinimizeTransition(transition, taskToMinimize)
@@ -1316,6 +1336,9 @@
val taskToMinimize =
addAndGetMinimizeChangesIfNeeded(task.displayId, wct, task.taskId)
addPendingMinimizeTransition(transition, taskToMinimize)
+ immersiveTransitionHandler.exitImmersiveIfApplicable(
+ transition, wct, task.displayId
+ )
}
}
return null
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl
index 1090a46..86351e3 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/IDesktopMode.aidl
@@ -51,5 +51,5 @@
void moveToDesktop(int taskId, in DesktopModeTransitionSource transitionSource);
/** Remove desktop on the given display */
- void removeDesktop(int displayId);
+ oneway void removeDesktop(int displayId);
}
\ No newline at end of file
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
index ae65892..a16446ff 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskListener.java
@@ -126,6 +126,7 @@
|| repository.isClosingTask(taskInfo.taskId)) {
// A task that's vanishing should be removed:
// - If it's closed by the X button which means it's marked as a closing task.
+ repository.removeClosingTask(taskInfo.taskId);
repository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId);
} else {
repository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId, false);
@@ -150,8 +151,6 @@
mDesktopRepository.ifPresent(repository -> {
if (taskInfo.isVisible) {
repository.addActiveTask(taskInfo.displayId, taskInfo.taskId);
- } else if (repository.isClosingTask(taskInfo.taskId)) {
- repository.removeClosingTask(taskInfo.taskId);
}
repository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId,
taskInfo.isVisible);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java
index 4106a10..771573d 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserver.java
@@ -89,7 +89,7 @@
// TODO(b/367268953): Remove when DesktopTaskListener is introduced and the repository
// is updated from there **before** the |mWindowDecorViewModel| methods are invoked.
// Otherwise window decoration relayout won't run with the immersive state up to date.
- mImmersiveTransitionHandler.ifPresent(h -> h.onTransitionReady(transition));
+ mImmersiveTransitionHandler.ifPresent(h -> h.onTransitionReady(transition, info));
}
// Update focus state first to ensure the correct state can be queried from listeners.
// TODO(371503964): Remove this once the unified task repository is ready.
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
index e55bc67..c7feac5 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java
@@ -56,7 +56,6 @@
import android.graphics.Region;
import android.hardware.input.InputManager;
import android.os.Handler;
-import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -407,6 +406,7 @@
@Override
public void setFreeformTaskTransitionStarter(FreeformTaskTransitionStarter transitionStarter) {
mTaskOperations = new TaskOperations(transitionStarter, mContext, mSyncQueue);
+ mDesktopTasksController.setFreeformTaskTransitionStarter(transitionStarter);
}
@Override
@@ -774,11 +774,7 @@
onMaximizeOrRestore(decoration.mTaskInfo.taskId, "caption_bar_button");
}
} else if (id == R.id.minimize_window) {
- final WindowContainerTransaction wct = new WindowContainerTransaction();
- mDesktopTasksController.onDesktopWindowMinimize(wct, mTaskId);
- final IBinder transition = mTaskOperations.minimizeTask(mTaskToken, wct);
- mDesktopTasksLimiter.ifPresent(limiter ->
- limiter.addPendingMinimizeChange(transition, mDisplayId, mTaskId));
+ mDesktopTasksController.minimizeTask(decoration.mTaskInfo);
}
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt
index cae6095..2e9effb4 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopFullImmersiveTransitionHandlerTest.kt
@@ -15,23 +15,39 @@
*/
package com.android.wm.shell.desktopmode
+import android.app.WindowConfiguration.WINDOW_CONFIG_BOUNDS
+import android.os.Binder
import android.os.IBinder
+import android.platform.test.annotations.EnableFlags
+import android.platform.test.flag.junit.SetFlagsRule
import android.testing.AndroidTestingRunner
+import android.view.Display.DEFAULT_DISPLAY
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CHANGE
+import android.view.WindowManager.TransitionFlags
+import android.view.WindowManager.TransitionType
+import android.window.TransitionInfo
+import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import androidx.test.filters.SmallTest
+import com.android.window.flags.Flags
+import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.TestShellExecutor
+import com.android.wm.shell.common.DisplayController
+import com.android.wm.shell.common.DisplayLayout
import com.android.wm.shell.desktopmode.DesktopTestHelpers.Companion.createFreeformTask
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.Transitions
import com.google.common.truth.Truth.assertThat
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.mock
+import org.mockito.kotlin.any
+import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
@@ -40,14 +56,18 @@
/**
* Tests for [DesktopFullImmersiveTransitionHandler].
*
- * Usage: atest WMShellUnitTests:DesktopFullImmersiveTransitionHandler
+ * Usage: atest WMShellUnitTests:DesktopFullImmersiveTransitionHandlerTest
*/
@SmallTest
@RunWith(AndroidTestingRunner::class)
class DesktopFullImmersiveTransitionHandlerTest : ShellTestCase() {
+ @JvmField @Rule val setFlagsRule = SetFlagsRule()
+
@Mock private lateinit var mockTransitions: Transitions
private lateinit var desktopRepository: DesktopRepository
+ @Mock private lateinit var mockDisplayController: DisplayController
+ @Mock private lateinit var mockShellTaskOrganizer: ShellTaskOrganizer
private val transactionSupplier = { SurfaceControl.Transaction() }
private lateinit var immersiveHandler: DesktopFullImmersiveTransitionHandler
@@ -57,19 +77,22 @@
desktopRepository = DesktopRepository(
context, ShellInit(TestShellExecutor()), mock(), mock()
)
+ whenever(mockDisplayController.getDisplayLayout(DEFAULT_DISPLAY))
+ .thenReturn(DisplayLayout())
immersiveHandler = DesktopFullImmersiveTransitionHandler(
transitions = mockTransitions,
desktopRepository = desktopRepository,
- transactionSupplier = transactionSupplier
+ displayController = mockDisplayController,
+ shellTaskOrganizer = mockShellTaskOrganizer,
+ transactionSupplier = transactionSupplier,
)
}
@Test
fun enterImmersive_transitionReady_updatesRepository() {
val task = createFreeformTask()
- val wct = WindowContainerTransaction()
val mockBinder = mock(IBinder::class.java)
- whenever(mockTransitions.startTransition(TRANSIT_CHANGE, wct, immersiveHandler))
+ whenever(mockTransitions.startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler)))
.thenReturn(mockBinder)
desktopRepository.setTaskInFullImmersiveState(
displayId = task.displayId,
@@ -77,8 +100,8 @@
immersive = false
)
- immersiveHandler.enterImmersive(task, wct)
- immersiveHandler.onTransitionReady(mockBinder)
+ immersiveHandler.moveTaskToImmersive(task)
+ immersiveHandler.onTransitionReady(mockBinder, createTransitionInfo())
assertThat(desktopRepository.isTaskInFullImmersiveState(task.taskId)).isTrue()
}
@@ -86,9 +109,8 @@
@Test
fun exitImmersive_transitionReady_updatesRepository() {
val task = createFreeformTask()
- val wct = WindowContainerTransaction()
val mockBinder = mock(IBinder::class.java)
- whenever(mockTransitions.startTransition(TRANSIT_CHANGE, wct, immersiveHandler))
+ whenever(mockTransitions.startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler)))
.thenReturn(mockBinder)
desktopRepository.setTaskInFullImmersiveState(
displayId = task.displayId,
@@ -96,8 +118,8 @@
immersive = true
)
- immersiveHandler.exitImmersive(task, wct)
- immersiveHandler.onTransitionReady(mockBinder)
+ immersiveHandler.moveTaskToNonImmersive(task)
+ immersiveHandler.onTransitionReady(mockBinder, createTransitionInfo())
assertThat(desktopRepository.isTaskInFullImmersiveState(task.taskId)).isFalse()
}
@@ -105,28 +127,251 @@
@Test
fun enterImmersive_inProgress_ignores() {
val task = createFreeformTask()
- val wct = WindowContainerTransaction()
val mockBinder = mock(IBinder::class.java)
- whenever(mockTransitions.startTransition(TRANSIT_CHANGE, wct, immersiveHandler))
+ whenever(mockTransitions.startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler)))
.thenReturn(mockBinder)
- immersiveHandler.enterImmersive(task, wct)
- immersiveHandler.enterImmersive(task, wct)
+ immersiveHandler.moveTaskToImmersive(task)
+ immersiveHandler.moveTaskToImmersive(task)
- verify(mockTransitions, times(1)).startTransition(TRANSIT_CHANGE, wct, immersiveHandler)
+ verify(mockTransitions, times(1))
+ .startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler))
}
@Test
fun exitImmersive_inProgress_ignores() {
val task = createFreeformTask()
- val wct = WindowContainerTransaction()
val mockBinder = mock(IBinder::class.java)
- whenever(mockTransitions.startTransition(TRANSIT_CHANGE, wct, immersiveHandler))
+ whenever(mockTransitions.startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler)))
.thenReturn(mockBinder)
- immersiveHandler.exitImmersive(task, wct)
- immersiveHandler.exitImmersive(task, wct)
+ immersiveHandler.moveTaskToNonImmersive(task)
+ immersiveHandler.moveTaskToNonImmersive(task)
- verify(mockTransitions, times(1)).startTransition(TRANSIT_CHANGE, wct, immersiveHandler)
+ verify(mockTransitions, times(1))
+ .startTransition(eq(TRANSIT_CHANGE), any(), eq(immersiveHandler))
}
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_inImmersive_addsPendingExit() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isTrue()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_notInImmersive_doesNotAddPendingExit() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = false
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byDisplay_inImmersive_changesTaskBounds() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ assertThat(wct.hasBoundsChange(task.token)).isTrue()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byDisplay_notInImmersive_doesNotChangeTaskBounds() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = false
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ assertThat(wct.hasBoundsChange(task.token)).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byTask_inImmersive_changesTaskBounds() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(wct = wct, taskInfo = task)
+
+ assertThat(wct.hasBoundsChange(task.token)).isTrue()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byTask_notInImmersive_doesNotChangeTaskBounds() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = false
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(wct, task.taskId)
+
+ assertThat(wct.hasBoundsChange(task.token)).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byTask_inImmersive_addsPendingExitOnRun() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(wct, task.taskId)?.invoke(transition)
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun exitImmersiveIfApplicable_byTask_notInImmersive_doesNotAddPendingExitOnRun() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = false
+ )
+
+ immersiveHandler.exitImmersiveIfApplicable(wct, task.taskId)?.invoke(transition)
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun onTransitionReady_pendingExit_removesPendingExit() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ immersiveHandler.onTransitionReady(
+ transition = transition,
+ info = createTransitionInfo(
+ changes = listOf(
+ TransitionInfo.Change(task.token, SurfaceControl()).apply { taskInfo = task }
+ )
+ )
+ )
+
+ assertThat(immersiveHandler.pendingExternalExitTransitions.any { exit ->
+ exit.transition == transition && exit.displayId == DEFAULT_DISPLAY
+ && exit.taskId == task.taskId
+ }).isFalse()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
+ fun onTransitionReady_pendingExit_updatesRepository() {
+ val task = createFreeformTask()
+ whenever(mockShellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ val wct = WindowContainerTransaction()
+ val transition = Binder()
+ desktopRepository.setTaskInFullImmersiveState(
+ displayId = DEFAULT_DISPLAY,
+ taskId = task.taskId,
+ immersive = true
+ )
+ immersiveHandler.exitImmersiveIfApplicable(transition, wct, DEFAULT_DISPLAY)
+
+ immersiveHandler.onTransitionReady(
+ transition = transition,
+ info = createTransitionInfo(
+ changes = listOf(
+ TransitionInfo.Change(task.token, SurfaceControl()).apply { taskInfo = task }
+ )
+ )
+ )
+
+ assertThat(desktopRepository.isTaskInFullImmersiveState(task.taskId)).isFalse()
+ }
+
+ private fun createTransitionInfo(
+ @TransitionType type: Int = TRANSIT_CHANGE,
+ @TransitionFlags flags: Int = 0,
+ changes: List<TransitionInfo.Change> = emptyList()
+ ): TransitionInfo = TransitionInfo(type, flags).apply {
+ changes.forEach { change -> addChange(change) }
+ }
+
+ private fun WindowContainerTransaction.hasBoundsChange(token: WindowContainerToken): Boolean =
+ this.changes.any { change ->
+ change.key == token.asBinder()
+ && (change.value.windowSetMask and WINDOW_CONFIG_BOUNDS) != 0
+ }
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt
index 1308114..e20f0ec 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopRepositoryTest.kt
@@ -957,6 +957,15 @@
assertThat(repo.getActiveTasks(displayId = DEFAULT_DISPLAY)).isEmpty()
}
+ @Test
+ fun getTaskInFullImmersiveState_byDisplay() {
+ repo.setTaskInFullImmersiveState(DEFAULT_DESKTOP_ID, taskId = 1, immersive = true)
+ repo.setTaskInFullImmersiveState(DEFAULT_DESKTOP_ID + 1, taskId = 2, immersive = true)
+
+ assertThat(repo.getTaskInFullImmersiveState(DEFAULT_DESKTOP_ID)).isEqualTo(1)
+ assertThat(repo.getTaskInFullImmersiveState(DEFAULT_DESKTOP_ID + 1)).isEqualTo(2)
+ }
+
class TestListener : DesktopRepository.ActiveTasksListener {
var activeChangesOnDefaultDisplay = 0
var activeChangesOnSecondaryDisplay = 0
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
index 27deb0b..b3c10d6 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
@@ -42,6 +42,7 @@
import android.os.Binder
import android.os.Bundle
import android.os.Handler
+import android.os.IBinder
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
@@ -99,6 +100,7 @@
import com.android.wm.shell.desktopmode.persistence.Desktop
import com.android.wm.shell.desktopmode.persistence.DesktopPersistentRepository
import com.android.wm.shell.draganddrop.DragAndDropController
+import com.android.wm.shell.freeform.FreeformTaskTransitionStarter
import com.android.wm.shell.recents.RecentTasksController
import com.android.wm.shell.recents.RecentsTransitionHandler
import com.android.wm.shell.recents.RecentsTransitionStateListener
@@ -144,13 +146,11 @@
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.clearInvocations
import org.mockito.Mockito.mock
-import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify
import org.mockito.Mockito.times
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
-import org.mockito.kotlin.argThat
import org.mockito.kotlin.atLeastOnce
import org.mockito.kotlin.capture
import org.mockito.kotlin.eq
@@ -201,6 +201,7 @@
private lateinit var mockInteractionJankMonitor: InteractionJankMonitor
@Mock private lateinit var mockSurface: SurfaceControl
@Mock private lateinit var taskbarDesktopTaskListener: TaskbarDesktopTaskListener
+ @Mock private lateinit var freeformTaskTransitionStarter: FreeformTaskTransitionStarter
@Mock private lateinit var mockHandler: Handler
@Mock lateinit var persistentRepository: DesktopPersistentRepository
@@ -266,6 +267,7 @@
controller = createController()
controller.setSplitScreenController(splitScreenController)
+ controller.freeformTaskTransitionStarter = freeformTaskTransitionStarter
shellInit.init()
@@ -1542,75 +1544,142 @@
}
@Test
- fun onDesktopWindowMinimize_noActiveTask_doesntUpdateTransaction() {
- val wct = WindowContainerTransaction()
- controller.onDesktopWindowMinimize(wct, taskId = 1)
- // Nothing happens.
- assertThat(wct.hierarchyOps).isEmpty()
+ fun onDesktopWindowMinimize_noActiveTask_doesntRemoveWallpaper() {
+ val task = setUpFreeformTask(active = false)
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
+ val wallpaperToken = MockToken().token()
+ taskRepository.wallpaperActivityToken = wallpaperToken
+
+ controller.minimizeTask(task)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ captor.value.hierarchyOps.none { hop ->
+ hop.type == HIERARCHY_OP_TYPE_REMOVE_TASK && hop.container == wallpaperToken.asBinder()
+ }
}
@Test
- fun onDesktopWindowMinimize_singleActiveTask_noWallpaperActivityToken_doesntUpdateTransaction() {
- val task = setUpFreeformTask()
- val wct = WindowContainerTransaction()
- controller.onDesktopWindowMinimize(wct, taskId = task.taskId)
- // Nothing happens.
- assertThat(wct.hierarchyOps).isEmpty()
+ fun onDesktopWindowMinimize_singleActiveTask_noWallpaperActivityToken_doesntRemoveWallpaper() {
+ val task = setUpFreeformTask(active = true)
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
+
+ controller.minimizeTask(task)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ captor.value.hierarchyOps.none { hop ->
+ hop.type == HIERARCHY_OP_TYPE_REMOVE_TASK
+ }
}
@Test
fun onDesktopWindowMinimize_singleActiveTask_hasWallpaperActivityToken_removesWallpaper() {
val task = setUpFreeformTask()
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
val wallpaperToken = MockToken().token()
taskRepository.wallpaperActivityToken = wallpaperToken
- val wct = WindowContainerTransaction()
// The only active task is being minimized.
- controller.onDesktopWindowMinimize(wct, taskId = task.taskId)
+ controller.minimizeTask(task)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
// Adds remove wallpaper operation
- wct.assertRemoveAt(index = 0, wallpaperToken)
+ captor.value.assertRemoveAt(index = 0, wallpaperToken)
}
@Test
- fun onDesktopWindowMinimize_singleActiveTask_alreadyMinimized_doesntUpdateTransaction() {
+ fun onDesktopWindowMinimize_singleActiveTask_alreadyMinimized_doesntRemoveWallpaper() {
val task = setUpFreeformTask()
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
val wallpaperToken = MockToken().token()
taskRepository.wallpaperActivityToken = wallpaperToken
taskRepository.minimizeTask(DEFAULT_DISPLAY, task.taskId)
- val wct = WindowContainerTransaction()
// The only active task is already minimized.
- controller.onDesktopWindowMinimize(wct, taskId = task.taskId)
- // Doesn't modify transaction
- assertThat(wct.hierarchyOps).isEmpty()
+ controller.minimizeTask(task)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ captor.value.hierarchyOps.none { hop ->
+ hop.type == HIERARCHY_OP_TYPE_REMOVE_TASK && hop.container == wallpaperToken.asBinder()
+ }
}
@Test
- fun onDesktopWindowMinimize_multipleActiveTasks_doesntUpdateTransaction() {
- val task1 = setUpFreeformTask()
- setUpFreeformTask()
+ fun onDesktopWindowMinimize_multipleActiveTasks_doesntRemoveWallpaper() {
+ val task1 = setUpFreeformTask(active = true)
+ setUpFreeformTask(active = true)
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
val wallpaperToken = MockToken().token()
taskRepository.wallpaperActivityToken = wallpaperToken
- val wct = WindowContainerTransaction()
- controller.onDesktopWindowMinimize(wct, taskId = task1.taskId)
- // Doesn't modify transaction
- assertThat(wct.hierarchyOps).isEmpty()
+ controller.minimizeTask(task1)
+
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ captor.value.hierarchyOps.none { hop ->
+ hop.type == HIERARCHY_OP_TYPE_REMOVE_TASK && hop.container == wallpaperToken.asBinder()
+ }
}
@Test
fun onDesktopWindowMinimize_multipleActiveTasks_minimizesTheOnlyVisibleTask_removesWallpaper() {
- val task1 = setUpFreeformTask()
- val task2 = setUpFreeformTask()
+ val task1 = setUpFreeformTask(active = true)
+ val task2 = setUpFreeformTask(active = true)
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
val wallpaperToken = MockToken().token()
taskRepository.wallpaperActivityToken = wallpaperToken
taskRepository.minimizeTask(DEFAULT_DISPLAY, task2.taskId)
- val wct = WindowContainerTransaction()
// task1 is the only visible task as task2 is minimized.
- controller.onDesktopWindowMinimize(wct, taskId = task1.taskId)
+ controller.minimizeTask(task1)
// Adds remove wallpaper operation
- wct.assertRemoveAt(index = 0, wallpaperToken)
+ val captor = ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
+ verify(freeformTaskTransitionStarter).startMinimizedModeTransition(captor.capture())
+ // Adds remove wallpaper operation
+ captor.value.assertRemoveAt(index = 0, wallpaperToken)
+ }
+
+ @Test
+ fun onDesktopWindowMinimize_triesToExitImmersive() {
+ val task = setUpFreeformTask()
+ val transition = Binder()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
+
+ controller.minimizeTask(task)
+
+ verify(mockDesktopFullImmersiveTransitionHandler).exitImmersiveIfApplicable(any(), eq(task))
+ }
+
+ @Test
+ fun onDesktopWindowMinimize_invokesImmersiveTransitionStartCallback() {
+ val task = setUpFreeformTask()
+ val transition = Binder()
+ val runOnTransit = RunOnStartTransitionCallback()
+ whenever(freeformTaskTransitionStarter.startMinimizedModeTransition(any()))
+ .thenReturn(transition)
+ whenever(mockDesktopFullImmersiveTransitionHandler.exitImmersiveIfApplicable(any(), eq(task)))
+ .thenReturn(runOnTransit)
+
+ controller.minimizeTask(task)
+
+ assertThat(runOnTransit.invocations).isEqualTo(1)
+ assertThat(runOnTransit.lastInvoked).isEqualTo(transition)
}
@Test
@@ -3166,27 +3235,23 @@
}
@Test
- fun toggleImmersive_enter_resizesToDisplayBounds() {
+ fun toggleImmersive_enter_movesToImmersive() {
val task = setUpFreeformTask(DEFAULT_DISPLAY)
taskRepository.setTaskInFullImmersiveState(DEFAULT_DISPLAY, task.taskId, false /* immersive */)
controller.toggleDesktopTaskFullImmersiveState(task)
- verify(mockDesktopFullImmersiveTransitionHandler).enterImmersive(eq(task), argThat { wct ->
- wct.hasBoundsChange(task.token, Rect())
- })
+ verify(mockDesktopFullImmersiveTransitionHandler).moveTaskToImmersive(task)
}
@Test
- fun toggleImmersive_exit_resizesToStableBounds() {
+ fun toggleImmersive_exit_movesToNonImmersive() {
val task = setUpFreeformTask(DEFAULT_DISPLAY)
taskRepository.setTaskInFullImmersiveState(DEFAULT_DISPLAY, task.taskId, true /* immersive */)
controller.toggleDesktopTaskFullImmersiveState(task)
- verify(mockDesktopFullImmersiveTransitionHandler).exitImmersive(eq(task), argThat { wct ->
- wct.hasBoundsChange(task.token, STABLE_BOUNDS)
- })
+ verify(mockDesktopFullImmersiveTransitionHandler).moveTaskToNonImmersive(task)
}
@Test
@@ -3198,7 +3263,7 @@
task.requestedVisibleTypes = WindowInsets.Type.statusBars()
controller.onTaskInfoChanged(task)
- verify(mockDesktopFullImmersiveTransitionHandler).exitImmersive(eq(task), any())
+ verify(mockDesktopFullImmersiveTransitionHandler).moveTaskToNonImmersive(task)
}
@Test
@@ -3210,7 +3275,113 @@
task.requestedVisibleTypes = WindowInsets.Type.statusBars()
controller.onTaskInfoChanged(task)
- verify(mockDesktopFullImmersiveTransitionHandler, never()).exitImmersive(eq(task), any())
+ verify(mockDesktopFullImmersiveTransitionHandler, never()).moveTaskToNonImmersive(task)
+ }
+
+ @Test
+ fun moveTaskToDesktop_background_attemptsImmersiveExit() {
+ val task = setUpFreeformTask(background = true)
+ val wct = WindowContainerTransaction()
+ val runOnStartTransit = RunOnStartTransitionCallback()
+ val transition = Binder()
+ whenever(mockDesktopFullImmersiveTransitionHandler
+ .exitImmersiveIfApplicable(wct, task.displayId)).thenReturn(runOnStartTransit)
+ whenever(enterDesktopTransitionHandler.moveToDesktop(wct, UNKNOWN)).thenReturn(transition)
+
+ controller.moveTaskToDesktop(taskId = task.taskId, wct = wct, transitionSource = UNKNOWN)
+
+ verify(mockDesktopFullImmersiveTransitionHandler).exitImmersiveIfApplicable(wct, task.displayId)
+ runOnStartTransit.assertOnlyInvocation(transition)
+ }
+
+ @Test
+ fun moveTaskToDesktop_foreground_attemptsImmersiveExit() {
+ val task = setUpFreeformTask(background = false)
+ val wct = WindowContainerTransaction()
+ val runOnStartTransit = RunOnStartTransitionCallback()
+ val transition = Binder()
+ whenever(mockDesktopFullImmersiveTransitionHandler
+ .exitImmersiveIfApplicable(wct, task.displayId)).thenReturn(runOnStartTransit)
+ whenever(enterDesktopTransitionHandler.moveToDesktop(wct, UNKNOWN)).thenReturn(transition)
+
+ controller.moveTaskToDesktop(taskId = task.taskId, wct = wct, transitionSource = UNKNOWN)
+
+ verify(mockDesktopFullImmersiveTransitionHandler).exitImmersiveIfApplicable(wct, task.displayId)
+ runOnStartTransit.assertOnlyInvocation(transition)
+ }
+
+ @Test
+ fun moveTaskToFront_background_attemptsImmersiveExit() {
+ val task = setUpFreeformTask(background = true)
+ val runOnStartTransit = RunOnStartTransitionCallback()
+ val transition = Binder()
+ whenever(mockDesktopFullImmersiveTransitionHandler
+ .exitImmersiveIfApplicable(any(), eq(task.displayId))).thenReturn(runOnStartTransit)
+ whenever(transitions.startTransition(any(), any(), anyOrNull())).thenReturn(transition)
+
+ controller.moveTaskToFront(task.taskId)
+
+ verify(mockDesktopFullImmersiveTransitionHandler)
+ .exitImmersiveIfApplicable(any(), eq(task.displayId))
+ runOnStartTransit.assertOnlyInvocation(transition)
+ }
+
+ @Test
+ fun moveTaskToFront_foreground_attemptsImmersiveExit() {
+ val task = setUpFreeformTask(background = false)
+ val runOnStartTransit = RunOnStartTransitionCallback()
+ val transition = Binder()
+ whenever(mockDesktopFullImmersiveTransitionHandler
+ .exitImmersiveIfApplicable(any(), eq(task.displayId))).thenReturn(runOnStartTransit)
+ whenever(transitions.startTransition(any(), any(), anyOrNull())).thenReturn(transition)
+
+ controller.moveTaskToFront(task.taskId)
+
+ verify(mockDesktopFullImmersiveTransitionHandler)
+ .exitImmersiveIfApplicable(any(), eq(task.displayId))
+ runOnStartTransit.assertOnlyInvocation(transition)
+ }
+
+ @Test
+ fun handleRequest_freeformLaunchToDesktop_attemptsImmersiveExit() {
+ markTaskVisible(setUpFreeformTask())
+ val task = setUpFreeformTask()
+ markTaskVisible(task)
+ val binder = Binder()
+
+ controller.handleRequest(binder, createTransition(task))
+
+ verify(mockDesktopFullImmersiveTransitionHandler)
+ .exitImmersiveIfApplicable(eq(binder), any(), eq(task.displayId))
+ }
+
+ @Test
+ fun handleRequest_fullscreenLaunchToDesktop_attemptsImmersiveExit() {
+ setUpFreeformTask()
+ val task = setUpFullscreenTask()
+ val binder = Binder()
+
+ controller.handleRequest(binder, createTransition(task))
+
+ verify(mockDesktopFullImmersiveTransitionHandler)
+ .exitImmersiveIfApplicable(eq(binder), any(), eq(task.displayId))
+ }
+
+ private class RunOnStartTransitionCallback : ((IBinder) -> Unit) {
+ var invocations = 0
+ private set
+ var lastInvoked: IBinder? = null
+ private set
+
+ override fun invoke(transition: IBinder) {
+ invocations++
+ lastInvoked = transition
+ }
+ }
+
+ private fun RunOnStartTransitionCallback.assertOnlyInvocation(transition: IBinder) {
+ assertThat(invocations).isEqualTo(1)
+ assertThat(lastInvoked).isEqualTo(transition)
}
/**
@@ -3291,18 +3462,27 @@
private fun setUpFreeformTask(
displayId: Int = DEFAULT_DISPLAY,
bounds: Rect? = null,
- active: Boolean = true
+ active: Boolean = true,
+ background: Boolean = false,
): RunningTaskInfo {
val task = createFreeformTask(displayId, bounds)
val activityInfo = ActivityInfo()
task.topActivityInfo = activityInfo
- whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ if (background) {
+ whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(null)
+ whenever(recentTasksController.findTaskInBackground(task.taskId))
+ .thenReturn(createTaskInfo(task.taskId))
+ } else {
+ whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
+ }
if (active) {
taskRepository.addActiveTask(displayId, task.taskId)
taskRepository.updateTaskVisibility(displayId, task.taskId, visible = true)
}
taskRepository.addOrMoveFreeformTaskToTop(displayId, task.taskId)
- runningTasks.add(task)
+ if (!background) {
+ runningTasks.add(task)
+ }
return task
}
@@ -3556,6 +3736,21 @@
assertThat(op.container).isEqualTo(token.asBinder())
}
+private fun WindowContainerTransaction.assertNoRemoveAt(index: Int, token: WindowContainerToken) {
+ assertIndexInBounds(index)
+ val op = hierarchyOps[index]
+ assertThat(op.type).isEqualTo(HIERARCHY_OP_TYPE_REMOVE_TASK)
+ assertThat(op.container).isEqualTo(token.asBinder())
+}
+
+private fun WindowContainerTransaction.hasRemoveAt(index: Int, token: WindowContainerToken) {
+
+ assertIndexInBounds(index)
+ val op = hierarchyOps[index]
+ assertThat(op.type).isEqualTo(HIERARCHY_OP_TYPE_REMOVE_TASK)
+ assertThat(op.container).isEqualTo(token.asBinder())
+}
+
private fun WindowContainerTransaction.assertPendingIntentAt(index: Int, intent: Intent) {
assertIndexInBounds(index)
val op = hierarchyOps[index]
@@ -3578,13 +3773,6 @@
.isEqualTo(windowingMode)
}
-private fun WindowContainerTransaction.hasBoundsChange(
- token: WindowContainerToken,
- bounds: Rect
-): Boolean = this.changes.any { change ->
- change.key == token.asBinder() && change.value.configuration.windowConfiguration.bounds == bounds
-}
-
private fun WindowContainerTransaction?.anyDensityConfigChange(
token: WindowContainerToken
): Boolean {
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java
index 36e0427..f95b0d1 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskListenerTests.java
@@ -178,6 +178,7 @@
mFreeformTaskListener.onTaskVanished(task);
verify(mDesktopRepository, never()).minimizeTask(task.displayId, task.taskId);
+ verify(mDesktopRepository).removeClosingTask(task.taskId);
verify(mDesktopRepository).removeFreeformTask(task.displayId, task.taskId);
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java
index 145819f3..7ae0bcd 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/freeform/FreeformTaskTransitionObserverTest.java
@@ -329,7 +329,7 @@
mTransitionObserver.onTransitionReady(transition, info, startT, finishT);
- verify(mDesktopFullImmersiveTransitionHandler).onTransitionReady(transition);
+ verify(mDesktopFullImmersiveTransitionHandler).onTransitionReady(transition, info);
}
private static TransitionInfo.Change createChange(int mode, int taskId, int windowingMode) {
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
index 4aa7e18..e3e817c 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt
@@ -126,7 +126,6 @@
import org.mockito.Mockito.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.any
-import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.argThat
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.doNothing
@@ -455,18 +454,7 @@
onClickListenerCaptor.value.onClick(view)
- val transactionCaptor = argumentCaptor<WindowContainerTransaction>()
- verify(mockFreeformTaskTransitionStarter)
- .startMinimizedModeTransition(transactionCaptor.capture())
- val wct = transactionCaptor.firstValue
-
- verify(mockTasksLimiter).addPendingMinimizeChange(
- anyOrNull(), eq(DEFAULT_DISPLAY), eq(decor.mTaskInfo.taskId))
-
- assertEquals(1, wct.getHierarchyOps().size)
- assertEquals(HierarchyOp.HIERARCHY_OP_TYPE_REORDER, wct.getHierarchyOps().get(0).getType())
- assertFalse(wct.getHierarchyOps().get(0).getToTop())
- assertEquals(decor.mTaskInfo.token.asBinder(), wct.getHierarchyOps().get(0).getContainer())
+ verify(mockDesktopTasksController).minimizeTask(decor.mTaskInfo)
}
@Test
diff --git a/media/java/android/media/MediaMuxer.java b/media/java/android/media/MediaMuxer.java
index 80b606c..5e55f64 100644
--- a/media/java/android/media/MediaMuxer.java
+++ b/media/java/android/media/MediaMuxer.java
@@ -34,7 +34,7 @@
/**
* MediaMuxer facilitates muxing elementary streams. Currently MediaMuxer supports MP4, Webm
- * and 3GP file as the output. It also supports muxing B-frames in MP4 since Android Nougat.
+ * and 3GP file as the output. It also supports muxing B-frames in MP4 since Android Nougat MR1.
* <p>
* It is generally used like this:
*
@@ -191,14 +191,14 @@
<td>○</td>
<td>●</td>
</tr>
- <td align="center">Muxing B-Frames(bi-directional predicted frames)</td>
+ <td align="center">Muxing B-Frames (bi-directional predicted frames)</td>
<td>○</td>
<td>○</td>
<td>○</td>
<td>○</td>
<td>○</td>
<td>○</td>
- <td>⁕</td>
+ <td>○</td>
<td>⁕</td>
<td>⁕</td>
</tr>
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java
index 39bbc25..50419f7 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java
@@ -263,8 +263,8 @@
}
@Override
- protected void onStop() {
- super.onStop();
+ protected void onDestroy() {
+ super.onDestroy();
// TODO: handle config changes without cancelling.
if (!isDone()) {
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/BottomSheet.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/BottomSheet.kt
index c48e7e4..8df8a07 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/BottomSheet.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/BottomSheet.kt
@@ -33,7 +33,6 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.android.compose.rememberSystemUiController
-import com.android.compose.theme.LocalAndroidColorScheme
import androidx.compose.ui.unit.dp
import com.android.credentialmanager.common.material.ModalBottomSheetLayout
import com.android.credentialmanager.common.material.ModalBottomSheetValue
@@ -57,7 +56,7 @@
)
androidx.compose.material3.ModalBottomSheet(
onDismissRequest = onDismiss,
- containerColor = LocalAndroidColorScheme.current.surfaceBright,
+ containerColor = MaterialTheme.colorScheme.surfaceBright,
sheetState = state,
content = {
Box(
@@ -91,7 +90,7 @@
setBottomSheetSystemBarsColor(sysUiController)
}
ModalBottomSheetLayout(
- sheetBackgroundColor = LocalAndroidColorScheme.current.surfaceBright,
+ sheetBackgroundColor = MaterialTheme.colorScheme.surfaceBright,
modifier = Modifier.background(Color.Transparent),
sheetState = state,
sheetContent = { sheetContent() },
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Cards.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Cards.kt
index 006a2d9..426fec2 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Cards.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Cards.kt
@@ -29,12 +29,12 @@
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
+import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.credentialmanager.ui.theme.Shapes
/**
@@ -54,7 +54,7 @@
modifier = modifier.fillMaxWidth().wrapContentHeight(),
border = null,
colors = CardDefaults.cardColors(
- containerColor = LocalAndroidColorScheme.current.surfaceBright,
+ containerColor = MaterialTheme.colorScheme.surfaceBright,
),
) {
if (topAppBar != null) {
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
index 2c3c63b..84078c4 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
@@ -31,6 +31,7 @@
import androidx.compose.material.icons.outlined.Lock
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SuggestionChip
import androidx.compose.material3.SuggestionChipDefaults
import androidx.compose.runtime.Composable
@@ -52,7 +53,6 @@
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.credentialmanager.ui.theme.EntryShape
import com.android.credentialmanager.ui.theme.Shapes
@@ -172,7 +172,7 @@
// Decorative purpose only.
contentDescription = null,
modifier = Modifier.size(24.dp),
- tint = LocalAndroidColorScheme.current.onSurfaceVariant,
+ tint = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}
@@ -186,7 +186,7 @@
Icon(
modifier = iconSize,
bitmap = iconImageBitmap,
- tint = LocalAndroidColorScheme.current.onSurfaceVariant,
+ tint = MaterialTheme.colorScheme.onSurfaceVariant,
// Decorative purpose only.
contentDescription = null,
)
@@ -210,7 +210,7 @@
Icon(
modifier = iconSize,
imageVector = iconImageVector,
- tint = LocalAndroidColorScheme.current.onSurfaceVariant,
+ tint = MaterialTheme.colorScheme.onSurfaceVariant,
// Decorative purpose only.
contentDescription = null,
)
@@ -222,7 +222,7 @@
Icon(
modifier = iconSize,
painter = iconPainter,
- tint = LocalAndroidColorScheme.current.onSurfaceVariant,
+ tint = MaterialTheme.colorScheme.onSurfaceVariant,
// Decorative purpose only.
contentDescription = null,
)
@@ -233,9 +233,9 @@
},
border = null,
colors = SuggestionChipDefaults.suggestionChipColors(
- containerColor = LocalAndroidColorScheme.current.surfaceContainerHigh,
- labelColor = LocalAndroidColorScheme.current.onSurfaceVariant,
- iconContentColor = LocalAndroidColorScheme.current.onSurfaceVariant,
+ containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
+ labelColor = MaterialTheme.colorScheme.onSurfaceVariant,
+ iconContentColor = MaterialTheme.colorScheme.onSurfaceVariant,
),
)
}
@@ -338,7 +338,7 @@
imageVector = navigationIcon,
contentDescription = navigationIconContentDescription,
modifier = Modifier.size(24.dp).autoMirrored(),
- tint = LocalAndroidColorScheme.current.onSurfaceVariant,
+ tint = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/SectionHeader.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/SectionHeader.kt
index 342af3b..37268ad 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/SectionHeader.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/SectionHeader.kt
@@ -21,23 +21,23 @@
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
+import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
-import com.android.compose.theme.LocalAndroidColorScheme
@Composable
fun CredentialListSectionHeader(text: String, isFirstSection: Boolean) {
InternalSectionHeader(
text = text,
- color = LocalAndroidColorScheme.current.onSurfaceVariant,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
applyTopPadding = !isFirstSection
)
}
@Composable
fun MoreAboutPasskeySectionHeader(text: String) {
- InternalSectionHeader(text, LocalAndroidColorScheme.current.onSurface)
+ InternalSectionHeader(text, MaterialTheme.colorScheme.onSurface)
}
@Composable
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/SystemUiControllerUtils.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/SystemUiControllerUtils.kt
index b4075f1..d325ebb 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/SystemUiControllerUtils.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/SystemUiControllerUtils.kt
@@ -17,9 +17,9 @@
package com.android.credentialmanager.common.ui
import androidx.compose.runtime.Composable
+import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.graphics.Color
import com.android.compose.SystemUiController
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.credentialmanager.common.material.ModalBottomSheetDefaults
@Composable
@@ -34,7 +34,7 @@
darkIcons = false
)
sysUiController.setNavigationBarColor(
- color = LocalAndroidColorScheme.current.surfaceBright,
+ color = MaterialTheme.colorScheme.surfaceBright,
darkIcons = false
)
}
\ No newline at end of file
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
index 68c2244..3e999cb 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
@@ -26,7 +26,6 @@
import androidx.compose.ui.text.style.Hyphens
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
-import com.android.compose.theme.LocalAndroidColorScheme
/**
* The headline for a screen. E.g. "Create a passkey for X", "Choose a saved sign-in for X".
@@ -38,7 +37,7 @@
Text(
modifier = modifier.wrapContentSize(),
text = text,
- color = LocalAndroidColorScheme.current.onSurface,
+ color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.headlineSmall.copy(hyphens = Hyphens.Auto),
)
@@ -52,7 +51,7 @@
Text(
modifier = modifier.wrapContentSize(),
text = text,
- color = LocalAndroidColorScheme.current.onSurfaceVariant,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium.copy(hyphens = Hyphens.Auto),
)
}
@@ -70,7 +69,7 @@
Text(
modifier = modifier.wrapContentSize(),
text = text,
- color = LocalAndroidColorScheme.current.onSurfaceVariant,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall.copy(hyphens = Hyphens.Auto),
overflow = TextOverflow.Ellipsis,
maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE,
@@ -86,7 +85,7 @@
Text(
modifier = modifier.wrapContentSize(),
text = text,
- color = LocalAndroidColorScheme.current.onSurface,
+ color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleLarge.copy(hyphens = Hyphens.Auto),
)
}
@@ -104,7 +103,7 @@
Text(
modifier = modifier.wrapContentSize(),
text = text,
- color = LocalAndroidColorScheme.current.onSurface,
+ color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleSmall.copy(hyphens = Hyphens.Auto),
overflow = TextOverflow.Ellipsis,
maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE,
@@ -160,7 +159,7 @@
modifier = modifier.wrapContentSize(),
text = text,
textAlign = TextAlign.Center,
- color = LocalAndroidColorScheme.current.onSurfaceVariant,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.labelLarge.copy(hyphens = Hyphens.Auto),
)
}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
index 4993a1f..d788891 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
@@ -30,6 +30,7 @@
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.Divider
+import androidx.compose.material3.MaterialTheme
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.NewReleases
import androidx.compose.material.icons.filled.Add
@@ -46,7 +47,6 @@
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toBitmap
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.credentialmanager.CredentialSelectorViewModel
import com.android.credentialmanager.R
import com.android.credentialmanager.common.BiometricError
@@ -448,7 +448,7 @@
item {
Divider(
thickness = 1.dp,
- color = LocalAndroidColorScheme.current.outlineVariant,
+ color = MaterialTheme.colorScheme.outlineVariant,
modifier = Modifier.padding(vertical = 16.dp)
)
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
index feaf7fb..b94e906 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
@@ -15,6 +15,7 @@
*/
package com.android.settingslib.media;
+import static android.content.pm.PackageManager.FEATURE_PC;
import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER;
import static android.media.MediaRoute2Info.TYPE_DOCK;
import static android.media.MediaRoute2Info.TYPE_HDMI;
@@ -29,8 +30,6 @@
import static com.android.settingslib.media.MediaDevice.SelectionBehavior.SELECTION_BEHAVIOR_TRANSFER;
import android.Manifest;
-import android.annotation.NonNull;
-import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
@@ -43,6 +42,8 @@
import android.util.Log;
import androidx.annotation.VisibleForTesting;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import com.android.settingslib.R;
import com.android.settingslib.media.flags.Flags;
@@ -72,7 +73,7 @@
return context.getString(R.string.media_transfer_this_device_name_tv);
} else if (isTablet()) {
return context.getString(R.string.media_transfer_this_device_name_tablet);
- } else if (inputRoutingEnabledAndIsDesktop()) {
+ } else if (inputRoutingEnabledAndIsDesktop(context)) {
return context.getString(R.string.media_transfer_this_device_name_desktop);
} else {
return context.getString(R.string.media_transfer_this_device_name);
@@ -88,7 +89,7 @@
case TYPE_WIRED_HEADSET:
case TYPE_WIRED_HEADPHONES:
name =
- inputRoutingEnabledAndIsDesktop()
+ inputRoutingEnabledAndIsDesktop(context)
? context.getString(R.string.media_transfer_headphone_name)
: context.getString(R.string.media_transfer_wired_headphone_name);
break;
@@ -96,7 +97,7 @@
case TYPE_USB_HEADSET:
case TYPE_USB_ACCESSORY:
name =
- inputRoutingEnabledAndIsDesktop()
+ inputRoutingEnabledAndIsDesktop(context)
? context.getString(R.string.media_transfer_usb_audio_name)
: context.getString(R.string.media_transfer_wired_headphone_name);
break;
@@ -149,14 +150,13 @@
.contains("tablet");
}
- static boolean isDesktop() {
- return Arrays.asList(SystemProperties.get("ro.build.characteristics").split(","))
- .contains("desktop");
+ public static boolean isDesktop(@NonNull Context context) {
+ return context.getPackageManager().hasSystemFeature(FEATURE_PC);
}
- static boolean inputRoutingEnabledAndIsDesktop() {
+ public static boolean inputRoutingEnabledAndIsDesktop(@NonNull Context context) {
return com.android.media.flags.Flags.enableAudioInputDeviceRoutingAndVolumeControl()
- && isDesktop();
+ && isDesktop(context);
}
// MediaRoute2Info.getType was made public on API 34, but exists since API 30.
diff --git a/packages/SettingsProvider/Android.bp b/packages/SettingsProvider/Android.bp
index 65b2275..1a99d25 100644
--- a/packages/SettingsProvider/Android.bp
+++ b/packages/SettingsProvider/Android.bp
@@ -39,7 +39,6 @@
"configinfra_framework_flags_java_lib",
"device_config_service_flags_java",
"libaconfig_java_proto_lite",
- "notification_flags_lib",
"SettingsLibDeviceStateRotationLock",
"SettingsLibDisplayUtils",
],
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index ec3bd90..6c31831 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -29,7 +29,6 @@
import android.icu.util.ULocale;
import android.media.AudioManager;
import android.media.RingtoneManager;
-import android.media.Utils;
import android.net.Uri;
import android.os.LocaleList;
import android.os.RemoteException;
@@ -310,13 +309,6 @@
return SILENT_RINGTONE;
}
} else {
- // If the ringtone/notification support the vibration, use the original value.
- final int ringtoneType = getRingtoneType(name);
- if ((Settings.System.RINGTONE.equals(name)
- || Settings.System.NOTIFICATION_SOUND.equals(name))
- && hasVibrationSettings(value, ringtoneType)) {
- return value;
- }
return getCanonicalRingtoneValue(value);
}
}
@@ -370,15 +362,6 @@
return;
}
- // If the ringtone/notification has vibration, we backup original value in onBackupValue.
- // So use the value directly for restoring.
- if ((ringtoneType == RingtoneManager.TYPE_RINGTONE
- || ringtoneType == RingtoneManager.TYPE_NOTIFICATION)
- && hasVibrationSettings(value, ringtoneType)) {
- RingtoneManager.setActualDefaultRingtoneUri(mContext, ringtoneType, Uri.parse(value));
- return;
- }
-
Uri ringtoneUri = null;
try {
ringtoneUri =
@@ -634,19 +617,6 @@
return allLocales.remove(toFullLocale(filteredLocale));
}
- private boolean hasVibrationSettings(String value, int type) {
- if (Utils.hasVibration(Uri.parse(value)) && mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported)) {
- if (type == RingtoneManager.TYPE_RINGTONE) {
- return android.media.audio.Flags.enableRingtoneHapticsCustomization();
- }
- if (type == RingtoneManager.TYPE_NOTIFICATION) {
- return com.android.server.notification.Flags.notificationVibrationInSoundUri();
- }
- }
- return false;
- }
-
/**
* Sets the locale specified. Input data is the byte representation of comma separated
* multiple BCP-47 language tags. For backwards compatibility, strings of the form
diff --git a/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java b/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java
index babc1a3..4b10b56 100644
--- a/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java
+++ b/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java
@@ -37,12 +37,9 @@
import android.database.Cursor;
import android.database.MatrixCursor;
import android.media.AudioManager;
-import android.media.Utils;
import android.net.Uri;
import android.os.Bundle;
import android.os.LocaleList;
-import android.platform.test.annotations.EnableFlags;
-import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.provider.Settings;
@@ -57,7 +54,6 @@
import org.junit.After;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -78,13 +74,9 @@
"content://media/internal/audio/media/20?title=DefaultNotification&canonical=1";
private static final String DEFAULT_ALARM_VALUE =
"content://media/internal/audio/media/30?title=DefaultAlarm&canonical=1";
- private static final String VIBRATION_FILE_NAME = "haptics.xml";
private SettingsHelper mSettingsHelper;
- @Rule
- public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
-
@Mock private Context mContext;
@Mock private Resources mResources;
@Mock private AudioManager mAudioManager;
@@ -128,22 +120,6 @@
}
@Test
- @EnableFlags({android.media.audio.Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION,
- com.android.server.notification.Flags.FLAG_NOTIFICATION_VIBRATION_IN_SOUND_URI})
- public void testOnBackupValue_ringtoneVibrationSupport_returnsSameValue() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported)).thenReturn(
- true);
- String testRingtoneVibrationValue = createUriWithVibration(DEFAULT_RINGTONE_VALUE);
- String testNotificationVibrationValue = createUriWithVibration(DEFAULT_NOTIFICATION_VALUE);
-
- assertEquals(testRingtoneVibrationValue, mSettingsHelper.onBackupValue(
- Settings.System.RINGTONE, testRingtoneVibrationValue));
- assertEquals(testNotificationVibrationValue, mSettingsHelper.onBackupValue(
- Settings.System.NOTIFICATION_SOUND, testNotificationVibrationValue));
- }
-
- @Test
public void testGetRealValue_settingNotReplaced_returnsSameValue() {
when(mSettingsHelper.isReplacedSystemSetting(eq(SETTING_KEY))).thenReturn(false);
@@ -699,30 +675,6 @@
.isEqualTo(null);
}
- @Test
- @EnableFlags({android.media.audio.Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION,
- com.android.server.notification.Flags.FLAG_NOTIFICATION_VIBRATION_IN_SOUND_URI})
- public void testRestoreValue_ringtoneVibrationSupport_restoreValue() {
- when(mResources.getBoolean(
- com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported)).thenReturn(
- true);
- String testRingtoneVibrationValue = createUriWithVibration(DEFAULT_RINGTONE_VALUE);
- String testNotificationVibrationValue = createUriWithVibration(DEFAULT_NOTIFICATION_VALUE);
- ContentProvider mockMediaContentProvider =
- new MockContentProvider(mContext) {
- @Override
- public String getType(Uri url) {
- return "audio/ogg";
- }
- };
- mContentResolver.addProvider(MediaStore.AUTHORITY, mockMediaContentProvider);
- resetRingtoneSettingsToDefault();
-
- assertRingtoneSettingsRestoring(Settings.System.RINGTONE, testRingtoneVibrationValue);
- assertRingtoneSettingsRestoring(
- Settings.System.NOTIFICATION_SOUND, testNotificationVibrationValue);
- }
-
private static class MockSettingsProvider extends MockContentProvider {
private final ArrayMap<String, String> mKeyValueStore = new ArrayMap<>();
MockSettingsProvider(Context context) {
@@ -814,25 +766,4 @@
assertThat(Settings.System.getString(mContentResolver, Settings.System.ALARM_ALERT))
.isEqualTo(DEFAULT_ALARM_VALUE);
}
-
- private String createUriWithVibration(String defaultUriString) {
- return Uri.parse(defaultUriString).buildUpon()
- .appendQueryParameter(
- Utils.VIBRATION_URI_PARAM, VIBRATION_FILE_NAME).build().toString();
- }
-
- private void assertRingtoneSettingsRestoring(
- String settings, String testRingtoneSettingsValue) {
- mSettingsHelper.restoreValue(
- mContext,
- mContentResolver,
- new ContentValues(),
- Uri.EMPTY,
- settings,
- testRingtoneSettingsValue,
- 0);
-
- assertThat(Settings.System.getString(mContentResolver, settings))
- .isEqualTo(testRingtoneSettingsValue);
- }
}
diff --git a/packages/SystemUI/compose/core/src/com/android/compose/theme/AndroidColorScheme.kt b/packages/SystemUI/compose/core/src/com/android/compose/theme/AndroidColorScheme.kt
index 37c37b0..6b3223d 100644
--- a/packages/SystemUI/compose/core/src/com/android/compose/theme/AndroidColorScheme.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/theme/AndroidColorScheme.kt
@@ -16,8 +16,8 @@
package com.android.compose.theme
-import android.annotation.ColorInt
import android.content.Context
+import androidx.annotation.ColorRes
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import com.android.internal.R
@@ -34,62 +34,27 @@
/**
* The Android color scheme.
*
- * Important: Use M3 colors from MaterialTheme.colorScheme whenever possible instead. In the future,
- * most of the colors in this class will be removed in favor of their M3 counterpart.
+ * This scheme contains the Material3 colors that are not available on
+ * [androidx.compose.material3.MaterialTheme]. For other colors (e.g. primary), use
+ * `MaterialTheme.colorScheme` instead.
*/
-class AndroidColorScheme(context: Context) {
- val onSecondaryFixedVariant = getColor(context, R.attr.materialColorOnSecondaryFixedVariant)
- val onTertiaryFixedVariant = getColor(context, R.attr.materialColorOnTertiaryFixedVariant)
- val surfaceContainerLowest = getColor(context, R.attr.materialColorSurfaceContainerLowest)
- val onPrimaryFixedVariant = getColor(context, R.attr.materialColorOnPrimaryFixedVariant)
- val onSecondaryContainer = getColor(context, R.attr.materialColorOnSecondaryContainer)
- val onTertiaryContainer = getColor(context, R.attr.materialColorOnTertiaryContainer)
- val surfaceContainerLow = getColor(context, R.attr.materialColorSurfaceContainerLow)
- val onPrimaryContainer = getColor(context, R.attr.materialColorOnPrimaryContainer)
- val secondaryFixedDim = getColor(context, R.attr.materialColorSecondaryFixedDim)
- val onErrorContainer = getColor(context, R.attr.materialColorOnErrorContainer)
- val onSecondaryFixed = getColor(context, R.attr.materialColorOnSecondaryFixed)
- val onSurfaceInverse = getColor(context, R.attr.materialColorOnSurfaceInverse)
- val tertiaryFixedDim = getColor(context, R.attr.materialColorTertiaryFixedDim)
- val onTertiaryFixed = getColor(context, R.attr.materialColorOnTertiaryFixed)
- val primaryFixedDim = getColor(context, R.attr.materialColorPrimaryFixedDim)
- val secondaryContainer = getColor(context, R.attr.materialColorSecondaryContainer)
- val errorContainer = getColor(context, R.attr.materialColorErrorContainer)
- val onPrimaryFixed = getColor(context, R.attr.materialColorOnPrimaryFixed)
- val primaryInverse = getColor(context, R.attr.materialColorPrimaryInverse)
- val secondaryFixed = getColor(context, R.attr.materialColorSecondaryFixed)
- val surfaceInverse = getColor(context, R.attr.materialColorSurfaceInverse)
- val surfaceVariant = getColor(context, R.attr.materialColorSurfaceVariant)
- val tertiaryContainer = getColor(context, R.attr.materialColorTertiaryContainer)
- val tertiaryFixed = getColor(context, R.attr.materialColorTertiaryFixed)
- val primaryContainer = getColor(context, R.attr.materialColorPrimaryContainer)
- val onBackground = getColor(context, R.attr.materialColorOnBackground)
- val primaryFixed = getColor(context, R.attr.materialColorPrimaryFixed)
- val onSecondary = getColor(context, R.attr.materialColorOnSecondary)
- val onTertiary = getColor(context, R.attr.materialColorOnTertiary)
- val surfaceDim = getColor(context, R.attr.materialColorSurfaceDim)
- val surfaceBright = getColor(context, R.attr.materialColorSurfaceBright)
- val error = getColor(context, R.attr.materialColorError)
- val onError = getColor(context, R.attr.materialColorOnError)
- val surface = getColor(context, R.attr.materialColorSurface)
- val surfaceContainerHigh = getColor(context, R.attr.materialColorSurfaceContainerHigh)
- val surfaceContainerHighest = getColor(context, R.attr.materialColorSurfaceContainerHighest)
- val onSurfaceVariant = getColor(context, R.attr.materialColorOnSurfaceVariant)
- val outline = getColor(context, R.attr.materialColorOutline)
- val outlineVariant = getColor(context, R.attr.materialColorOutlineVariant)
- val onPrimary = getColor(context, R.attr.materialColorOnPrimary)
- val onSurface = getColor(context, R.attr.materialColorOnSurface)
- val surfaceContainer = getColor(context, R.attr.materialColorSurfaceContainer)
- val primary = getColor(context, R.attr.materialColorPrimary)
- val secondary = getColor(context, R.attr.materialColorSecondary)
- val tertiary = getColor(context, R.attr.materialColorTertiary)
+class AndroidColorScheme(val context: Context) {
+ val primaryFixed = color(context, R.color.system_primary_fixed)
+ val primaryFixedDim = color(context, R.color.system_primary_fixed_dim)
+ val onPrimaryFixed = color(context, R.color.system_on_primary_fixed)
+ val onPrimaryFixedVariant = color(context, R.color.system_on_primary_fixed_variant)
+ val secondaryFixed = color(context, R.color.system_secondary_fixed)
+ val secondaryFixedDim = color(context, R.color.system_secondary_fixed_dim)
+ val onSecondaryFixed = color(context, R.color.system_on_secondary_fixed)
+ val onSecondaryFixedVariant = color(context, R.color.system_on_secondary_fixed_variant)
+ val tertiaryFixed = color(context, R.color.system_tertiary_fixed)
+ val tertiaryFixedDim = color(context, R.color.system_tertiary_fixed_dim)
+ val onTertiaryFixed = color(context, R.color.system_on_tertiary_fixed)
+ val onTertiaryFixedVariant = color(context, R.color.system_on_tertiary_fixed_variant)
companion object {
- internal fun getColor(context: Context, attr: Int): Color {
- val ta = context.obtainStyledAttributes(intArrayOf(attr))
- @ColorInt val color = ta.getColor(0, 0)
- ta.recycle()
- return Color(color)
+ internal fun color(context: Context, @ColorRes id: Int): Color {
+ return Color(context.resources.getColor(id, context.theme))
}
}
}
diff --git a/packages/SystemUI/compose/core/src/com/android/compose/theme/Color.kt b/packages/SystemUI/compose/core/src/com/android/compose/theme/Color.kt
index 5dbaff6..a499447 100644
--- a/packages/SystemUI/compose/core/src/com/android/compose/theme/Color.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/theme/Color.kt
@@ -17,6 +17,8 @@
package com.android.compose.theme
import android.annotation.AttrRes
+import android.annotation.ColorInt
+import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.Color
@@ -26,5 +28,13 @@
@Composable
@ReadOnlyComposable
fun colorAttr(@AttrRes attribute: Int): Color {
- return AndroidColorScheme.getColor(LocalContext.current, attribute)
+ return colorAttr(LocalContext.current, attribute)
+}
+
+/** Return the [Color] from the given [attribute]. */
+fun colorAttr(context: Context, @AttrRes attr: Int): Color {
+ val ta = context.obtainStyledAttributes(intArrayOf(attr))
+ @ColorInt val color = ta.getColor(0, 0)
+ ta.recycle()
+ return Color(color)
}
diff --git a/packages/SystemUI/compose/core/src/com/android/compose/theme/PlatformTheme.kt b/packages/SystemUI/compose/core/src/com/android/compose/theme/PlatformTheme.kt
index 0661870..d31d7aa 100644
--- a/packages/SystemUI/compose/core/src/com/android/compose/theme/PlatformTheme.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/theme/PlatformTheme.kt
@@ -16,7 +16,9 @@
package com.android.compose.theme
+import android.content.Context
import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
@@ -24,6 +26,7 @@
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
+import com.android.compose.theme.AndroidColorScheme.Companion.color
import com.android.compose.theme.typography.TypeScaleTokens
import com.android.compose.theme.typography.TypefaceNames
import com.android.compose.theme.typography.TypefaceTokens
@@ -31,23 +34,15 @@
import com.android.compose.theme.typography.platformTypography
import com.android.compose.windowsizeclass.LocalWindowSizeClass
import com.android.compose.windowsizeclass.calculateWindowSizeClass
+import com.android.internal.R
/** The Material 3 theme that should wrap all Platform Composables. */
@Composable
-fun PlatformTheme(
- isDarkTheme: Boolean = isSystemInDarkTheme(),
- content: @Composable () -> Unit,
-) {
+fun PlatformTheme(isDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
val context = LocalContext.current
- // TODO(b/230605885): Define our color scheme.
- val colorScheme =
- if (isDarkTheme) {
- dynamicDarkColorScheme(context)
- } else {
- dynamicLightColorScheme(context)
- }
- val androidColorScheme = AndroidColorScheme(context)
+ val colorScheme = remember(context, isDarkTheme) { platformColorScheme(isDarkTheme, context) }
+ val androidColorScheme = remember(context) { AndroidColorScheme(context) }
val typefaceNames = remember(context) { TypefaceNames.get(context) }
val typography =
remember(typefaceNames) {
@@ -55,12 +50,31 @@
}
val windowSizeClass = calculateWindowSizeClass()
- MaterialTheme(colorScheme, typography = typography) {
+ MaterialTheme(colorScheme = colorScheme, typography = typography) {
CompositionLocalProvider(
LocalAndroidColorScheme provides androidColorScheme,
LocalWindowSizeClass provides windowSizeClass,
- ) {
- content()
- }
+ content = content,
+ )
+ }
+}
+
+private fun platformColorScheme(isDarkTheme: Boolean, context: Context): ColorScheme {
+ return if (isDarkTheme) {
+ dynamicDarkColorScheme(context)
+ .copy(
+ error = color(context, R.color.system_error_dark),
+ onError = color(context, R.color.system_on_error_dark),
+ errorContainer = color(context, R.color.system_error_container_dark),
+ onErrorContainer = color(context, R.color.system_on_error_container_dark),
+ )
+ } else {
+ dynamicLightColorScheme(context)
+ .copy(
+ error = color(context, R.color.system_error_light),
+ onError = color(context, R.color.system_on_error_light),
+ errorContainer = color(context, R.color.system_error_container_light),
+ onErrorContainer = color(context, R.color.system_on_error_container_light),
+ )
}
}
diff --git a/packages/SystemUI/compose/core/tests/Android.bp b/packages/SystemUI/compose/core/tests/Android.bp
index 6e7a142..6a824d8 100644
--- a/packages/SystemUI/compose/core/tests/Android.bp
+++ b/packages/SystemUI/compose/core/tests/Android.bp
@@ -27,7 +27,6 @@
name: "PlatformComposeCoreTests",
manifest: "AndroidManifest.xml",
test_suites: ["device-tests"],
- sdk_version: "current",
certificate: "platform",
srcs: [
diff --git a/packages/SystemUI/compose/core/tests/AndroidManifest.xml b/packages/SystemUI/compose/core/tests/AndroidManifest.xml
index 1016340..28f80d4 100644
--- a/packages/SystemUI/compose/core/tests/AndroidManifest.xml
+++ b/packages/SystemUI/compose/core/tests/AndroidManifest.xml
@@ -19,6 +19,11 @@
<application>
<uses-library android:name="android.test.runner" />
+
+ <activity
+ android:name="androidx.activity.ComponentActivity"
+ android:theme="@android:style/Theme.DeviceDefault.DayNight"
+ android:exported="true" />
</application>
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
diff --git a/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/PlatformThemeTest.kt b/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/PlatformThemeTest.kt
index 23538e3..de021a0 100644
--- a/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/PlatformThemeTest.kt
+++ b/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/PlatformThemeTest.kt
@@ -16,11 +16,21 @@
package com.android.compose.theme
+import android.content.Context
+import androidx.annotation.AttrRes
+import androidx.compose.material3.ColorScheme
+import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.internal.R
+import com.google.common.truth.Truth.assertThat
+import com.google.common.truth.Truth.assertWithMessage
import org.junit.Assert.assertThrows
import org.junit.Rule
import org.junit.Test
@@ -54,4 +64,145 @@
}
}
}
+
+ @Test
+ fun testMaterialColorsMatchAttributeValue() {
+ val colorValues = mutableListOf<ColorValue>()
+
+ fun onLaunch(colorScheme: ColorScheme, context: Context) {
+ fun addValue(name: String, materialValue: Color, @AttrRes attr: Int) {
+ colorValues.add(ColorValue(name, materialValue, colorAttr(context, attr)))
+ }
+
+ addValue("primary", colorScheme.primary, R.attr.materialColorPrimary)
+ addValue("onPrimary", colorScheme.onPrimary, R.attr.materialColorOnPrimary)
+ addValue(
+ "primaryContainer",
+ colorScheme.primaryContainer,
+ R.attr.materialColorPrimaryContainer,
+ )
+ addValue(
+ "onPrimaryContainer",
+ colorScheme.onPrimaryContainer,
+ R.attr.materialColorOnPrimaryContainer,
+ )
+ addValue(
+ "inversePrimary",
+ colorScheme.inversePrimary,
+ R.attr.materialColorPrimaryInverse,
+ )
+ addValue("secondary", colorScheme.secondary, R.attr.materialColorSecondary)
+ addValue("onSecondary", colorScheme.onSecondary, R.attr.materialColorOnSecondary)
+ addValue(
+ "secondaryContainer",
+ colorScheme.secondaryContainer,
+ R.attr.materialColorSecondaryContainer,
+ )
+ addValue(
+ "onSecondaryContainer",
+ colorScheme.onSecondaryContainer,
+ R.attr.materialColorOnSecondaryContainer,
+ )
+ addValue("tertiary", colorScheme.tertiary, R.attr.materialColorTertiary)
+ addValue("onTertiary", colorScheme.onTertiary, R.attr.materialColorOnTertiary)
+ addValue(
+ "tertiaryContainer",
+ colorScheme.tertiaryContainer,
+ R.attr.materialColorTertiaryContainer,
+ )
+ addValue(
+ "onTertiaryContainer",
+ colorScheme.onTertiaryContainer,
+ R.attr.materialColorOnTertiaryContainer,
+ )
+ addValue("onBackground", colorScheme.onBackground, R.attr.materialColorOnBackground)
+ addValue("surface", colorScheme.surface, R.attr.materialColorSurface)
+ addValue("onSurface", colorScheme.onSurface, R.attr.materialColorOnSurface)
+ addValue(
+ "surfaceVariant",
+ colorScheme.surfaceVariant,
+ R.attr.materialColorSurfaceVariant,
+ )
+ addValue(
+ "onSurfaceVariant",
+ colorScheme.onSurfaceVariant,
+ R.attr.materialColorOnSurfaceVariant,
+ )
+ addValue(
+ "inverseSurface",
+ colorScheme.inverseSurface,
+ R.attr.materialColorSurfaceInverse,
+ )
+ addValue(
+ "inverseOnSurface",
+ colorScheme.inverseOnSurface,
+ R.attr.materialColorOnSurfaceInverse,
+ )
+ addValue("error", colorScheme.error, R.attr.materialColorError)
+ addValue("onError", colorScheme.onError, R.attr.materialColorOnError)
+ addValue(
+ "errorContainer",
+ colorScheme.errorContainer,
+ R.attr.materialColorErrorContainer,
+ )
+ addValue(
+ "onErrorContainer",
+ colorScheme.onErrorContainer,
+ R.attr.materialColorOnErrorContainer,
+ )
+ addValue("outline", colorScheme.outline, R.attr.materialColorOutline)
+ addValue(
+ "outlineVariant",
+ colorScheme.outlineVariant,
+ R.attr.materialColorOutlineVariant,
+ )
+ addValue("surfaceBright", colorScheme.surfaceBright, R.attr.materialColorSurfaceBright)
+ addValue("surfaceDim", colorScheme.surfaceDim, R.attr.materialColorSurfaceDim)
+ addValue(
+ "surfaceContainer",
+ colorScheme.surfaceContainer,
+ R.attr.materialColorSurfaceContainer,
+ )
+ addValue(
+ "surfaceContainerHigh",
+ colorScheme.surfaceContainerHigh,
+ R.attr.materialColorSurfaceContainerHigh,
+ )
+ addValue(
+ "surfaceContainerHighest",
+ colorScheme.surfaceContainerHighest,
+ R.attr.materialColorSurfaceContainerHighest,
+ )
+ addValue(
+ "surfaceContainerLow",
+ colorScheme.surfaceContainerLow,
+ R.attr.materialColorSurfaceContainerLow,
+ )
+ addValue(
+ "surfaceContainerLowest",
+ colorScheme.surfaceContainerLowest,
+ R.attr.materialColorSurfaceContainerLowest,
+ )
+ }
+
+ composeRule.setContent {
+ PlatformTheme {
+ val colorScheme = MaterialTheme.colorScheme
+ val context = LocalContext.current
+
+ LaunchedEffect(Unit) { onLaunch(colorScheme, context) }
+ }
+ }
+
+ assertThat(colorValues).hasSize(33)
+ colorValues.forEach { colorValue ->
+ assertWithMessage(
+ "MaterialTheme.colorScheme.${colorValue.name} matches attribute color"
+ )
+ .that(colorValue.materialValue)
+ .isEqualTo(colorValue.attrValue)
+ }
+ }
+
+ private data class ColorValue(val name: String, val materialValue: Color, val attrValue: Color)
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
index 571b366..6d30398 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
@@ -13,6 +13,7 @@
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
@@ -44,8 +45,6 @@
import com.android.compose.animation.scene.SwipeDirection
import com.android.compose.animation.scene.observableTransitionState
import com.android.compose.animation.scene.transitions
-import com.android.compose.theme.LocalAndroidColorScheme
-import com.android.internal.R.attr.focusable
import com.android.systemui.communal.shared.model.CommunalBackgroundType
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.CommunalTransitionKeys
@@ -270,7 +269,7 @@
/** Experimental hub background, static linear gradient */
@Composable
private fun BoxScope.StaticLinearGradient() {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
Box(
Modifier.matchParentSize()
.background(
@@ -283,7 +282,7 @@
/** Experimental hub background, animated linear gradient */
@Composable
private fun BoxScope.AnimatedLinearGradient() {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
Box(
Modifier.matchParentSize()
.background(colors.primary)
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContent.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContent.kt
index 6fca178..9392b1a 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContent.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContent.kt
@@ -19,12 +19,12 @@
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.IntRect
import com.android.compose.animation.scene.SceneScope
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.systemui.communal.smartspace.SmartspaceInteractionHandler
import com.android.systemui.communal.ui.compose.section.AmbientStatusBarSection
import com.android.systemui.communal.ui.compose.section.CommunalPopupSection
@@ -71,7 +71,7 @@
}
with(lockSection) {
LockIcon(
- overrideColor = LocalAndroidColorScheme.current.onPrimaryContainer,
+ overrideColor = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier.element(Communal.Elements.LockIcon)
)
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
index 7fb4c53..96c47cc 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
@@ -161,7 +161,6 @@
import androidx.window.layout.WindowMetricsCalculator
import com.android.compose.animation.Easings.Emphasized
import com.android.compose.modifiers.thenIf
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.compose.ui.graphics.painter.rememberDrawablePainter
import com.android.internal.R.dimen.system_app_widget_background_radius
import com.android.systemui.Flags
@@ -473,7 +472,7 @@
if (showBottomSheet) {
val scope = rememberCoroutineScope()
val sheetState = rememberModalBottomSheetState()
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
ModalBottomSheet(
onDismissRequest = viewModel::onDisclaimerDismissed,
@@ -501,7 +500,7 @@
@Composable
private fun DisclaimerBottomSheetContent(onButtonClicked: () -> Unit) {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
Column(
modifier = Modifier.fillMaxWidth().padding(horizontal = 32.dp, vertical = 24.dp),
@@ -817,7 +816,7 @@
*/
@Composable
private fun EmptyStateCta(contentPadding: PaddingValues, viewModel: BaseCommunalViewModel) {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
Card(
modifier = Modifier.height(hubDimensions.GridHeight).padding(contentPadding),
colors = CardDefaults.cardColors(containerColor = Color.Transparent),
@@ -963,7 +962,7 @@
modifier: Modifier = Modifier,
content: @Composable RowScope.() -> Unit,
) {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
AnimatedVisibility(
visible = isPrimary,
modifier = modifier,
@@ -1010,7 +1009,7 @@
@Composable
private fun filledButtonColors(): ButtonColors {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
return ButtonDefaults.buttonColors(
containerColor = colors.primary,
contentColor = colors.onPrimary,
@@ -1058,7 +1057,7 @@
/** Creates an empty card used to highlight a particular spot on the grid. */
@Composable
fun HighlightedItem(modifier: Modifier = Modifier, alpha: Float = 1.0f) {
- val brush = SolidColor(LocalAndroidColorScheme.current.primary)
+ val brush = SolidColor(MaterialTheme.colorScheme.primary)
Box(
modifier =
// drawBehind lets us draw outside the bounds of the widgets so that we don't need to
@@ -1085,7 +1084,7 @@
viewModel: BaseCommunalViewModel,
modifier: Modifier = Modifier,
) {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
Card(
modifier = modifier,
colors =
@@ -1301,7 +1300,7 @@
modifier: Modifier = Modifier,
widgetConfigurator: WidgetConfigurator,
) {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
val scope = rememberCoroutineScope()
AnimatedVisibility(
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/EnableWidgetDialog.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/EnableWidgetDialog.kt
index df11206..b2407fa 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/EnableWidgetDialog.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/EnableWidgetDialog.kt
@@ -41,7 +41,6 @@
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.systemui.res.R
import com.android.systemui.statusbar.phone.ComponentSystemUIDialog
import com.android.systemui.statusbar.phone.SystemUIDialogFactory
@@ -93,7 +92,7 @@
Box(
Modifier.fillMaxWidth()
.padding(top = 18.dp, bottom = 8.dp)
- .background(LocalAndroidColorScheme.current.surfaceBright, RoundedCornerShape(28.dp))
+ .background(MaterialTheme.colorScheme.surfaceBright, RoundedCornerShape(28.dp))
) {
Column(
modifier = Modifier.fillMaxWidth(),
@@ -106,7 +105,7 @@
Text(
text = title,
style = MaterialTheme.typography.titleMedium,
- color = LocalAndroidColorScheme.current.onSurface,
+ color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
maxLines = 1,
)
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ResizeableItemFrame.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ResizeableItemFrame.kt
index ef62eb7..97ad4f1 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ResizeableItemFrame.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ResizeableItemFrame.kt
@@ -28,6 +28,7 @@
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.grid.LazyGridState
+import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
@@ -47,7 +48,6 @@
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastIsFinite
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.systemui.communal.ui.viewmodel.DragHandle
import com.android.systemui.communal.ui.viewmodel.ResizeInfo
import com.android.systemui.communal.ui.viewmodel.ResizeableItemFrameViewModel
@@ -169,7 +169,7 @@
modifier: Modifier = Modifier,
enabled: Boolean = true,
outlinePadding: Dp = 8.dp,
- outlineColor: Color = LocalAndroidColorScheme.current.primary,
+ outlineColor: Color = MaterialTheme.colorScheme.primary,
cornerRadius: Dp = 37.dp,
strokeWidth: Dp = 3.dp,
alpha: () -> Float = { 1f },
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/section/CommunalPopupSection.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/section/CommunalPopupSection.kt
index b4c1a2e..868e136 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/section/CommunalPopupSection.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/section/CommunalPopupSection.kt
@@ -55,7 +55,6 @@
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import androidx.lifecycle.compose.collectAsStateWithLifecycle
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.communal.ui.viewmodel.PopupType
import com.android.systemui.res.R
@@ -112,7 +111,7 @@
offset = IntOffset(0, 40),
onDismissRequest = onDismissRequest,
) {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
Button(
modifier =
Modifier.height(56.dp)
@@ -182,7 +181,7 @@
offset = IntOffset(0, 40),
onDismissRequest = onDismissRequest
) {
- val colors = LocalAndroidColorScheme.current
+ val colors = MaterialTheme.colorScheme
Row(
modifier =
Modifier.height(56.dp)
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt b/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt
index 3d8ca1e..b5d7839 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarousel.kt
@@ -34,7 +34,6 @@
import com.android.compose.animation.scene.MovableElementKey
import com.android.compose.animation.scene.SceneScope
import com.android.compose.windowsizeclass.LocalWindowSizeClass
-import com.android.internal.R.attr.layout
import com.android.systemui.media.controls.ui.composable.MediaCarouselStateLoader.stateForMediaCarouselContent
import com.android.systemui.media.controls.ui.controller.MediaCarouselController
import com.android.systemui.media.controls.ui.view.MediaHost
@@ -60,12 +59,12 @@
carouselController: MediaCarouselController,
offsetProvider: (() -> IntOffset)? = null,
usingCollapsedLandscapeMedia: Boolean = false,
+ isInSplitShade: Boolean = false,
) {
if (!isVisible || carouselController.isLockedAndHidden()) {
return
}
-
- val carouselState = remember { { stateForMediaCarouselContent() } }
+ val carouselState = remember { { stateForMediaCarouselContent(isInSplitShade) } }
val isCollapsed = usingCollapsedLandscapeMedia && isLandscape()
val mediaHeight =
if (isCollapsed && mediaHost.expansion == MediaHostState.COLLAPSED) {
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarouselStateLoader.kt b/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarouselStateLoader.kt
index 4a0136c..bad7405 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarouselStateLoader.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/media/controls/ui/composable/MediaCarouselStateLoader.kt
@@ -43,10 +43,13 @@
/** Returns the corresponding media location for the given [scene] */
@MediaLocation
- private fun getMediaLocation(scene: SceneKey): Int {
+ private fun getMediaLocation(scene: SceneKey, isSplitShade: Boolean): Int {
return when (scene) {
Scenes.QuickSettings -> MediaHierarchyManager.LOCATION_QS
- Scenes.Shade -> MediaHierarchyManager.LOCATION_QQS
+ Scenes.Shade -> {
+ if (isSplitShade) MediaHierarchyManager.LOCATION_QS
+ else MediaHierarchyManager.LOCATION_QQS
+ }
Scenes.Lockscreen -> MediaHierarchyManager.LOCATION_LOCKSCREEN
Scenes.Communal -> MediaHierarchyManager.LOCATION_COMMUNAL_HUB
else -> MediaHierarchyManager.LOCATION_UNKNOWN
@@ -97,11 +100,11 @@
}
/** Returns the state of media carousel */
- fun SceneScope.stateForMediaCarouselContent(): State {
+ fun SceneScope.stateForMediaCarouselContent(isInSplitShade: Boolean): State {
return when (val transitionState = layoutState.transitionState) {
is TransitionState.Idle -> {
if (MediaContentPicker.contents.contains(transitionState.currentScene)) {
- State.Idle(getMediaLocation(transitionState.currentScene))
+ State.Idle(getMediaLocation(transitionState.currentScene, isInSplitShade))
} else {
State.Gone
}
@@ -114,14 +117,14 @@
) {
State.InProgress(
min(progress, 1.0F),
- getMediaLocation(fromScene),
- getMediaLocation(toScene),
+ getMediaLocation(fromScene, isInSplitShade),
+ getMediaLocation(toScene, isInSplitShade),
)
} else if (MediaContentPicker.contents.contains(toScene)) {
State.InProgress(
transitionProgress = 1.0F,
startLocation = MediaHierarchyManager.LOCATION_UNKNOWN,
- getMediaLocation(toScene),
+ getMediaLocation(toScene, isInSplitShade),
)
} else {
State.Gone
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt b/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt
index e8da4bd..e382e16 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt
@@ -73,7 +73,6 @@
import com.android.compose.animation.Expandable
import com.android.compose.animation.scene.SceneScope
import com.android.compose.modifiers.background
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.compose.theme.colorAttr
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.Icon
@@ -163,7 +162,7 @@
}
val backgroundColor = colorAttr(R.attr.underSurface)
- val contentColor = LocalAndroidColorScheme.current.onSurface
+ val contentColor = MaterialTheme.colorScheme.onSurface
val backgroundTopRadius = dimensionResource(R.dimen.qs_corner_radius)
val backgroundModifier =
remember(
@@ -344,7 +343,7 @@
@Composable
private fun NewChangesDot(modifier: Modifier = Modifier) {
val contentDescription = stringResource(R.string.fgs_dot_content_description)
- val color = LocalAndroidColorScheme.current.tertiary
+ val color = MaterialTheme.colorScheme.tertiary
Canvas(modifier.size(12.dp).semantics { this.contentDescription = contentDescription }) {
drawCircle(color)
@@ -363,7 +362,7 @@
Expandable(
shape = CircleShape,
color = colorAttr(R.attr.underSurface),
- contentColor = LocalAndroidColorScheme.current.onSurfaceVariant,
+ contentColor = MaterialTheme.colorScheme.onSurfaceVariant,
borderStroke = BorderStroke(1.dp, colorAttr(R.attr.shadeInactive)),
modifier = modifier.padding(horizontal = 4.dp),
onClick = onClick,
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/qs/ui/composable/QuickSettings.kt b/packages/SystemUI/compose/features/src/com/android/systemui/qs/ui/composable/QuickSettings.kt
index edc4cba..58801e0 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/qs/ui/composable/QuickSettings.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/qs/ui/composable/QuickSettings.kt
@@ -24,7 +24,9 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.layout.layout
@@ -38,6 +40,7 @@
import com.android.compose.animation.scene.MovableElementContentPicker
import com.android.compose.animation.scene.MovableElementKey
import com.android.compose.animation.scene.SceneScope
+import com.android.compose.animation.scene.SceneTransitionLayoutState
import com.android.compose.animation.scene.ValueKey
import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.modifiers.thenIf
@@ -158,12 +161,10 @@
squishiness: () -> Float = { QuickSettings.SharedValues.SquishinessValues.Default },
) {
val contentState = { stateForQuickSettingsContent(isSplitShade, squishiness) }
- val transitionState = layoutState.transitionState
- val isClosing =
- transitionState is TransitionState.Transition &&
- transitionState.progress >= 0.9f && // almost done closing
- !(layoutState.isTransitioning(to = Scenes.Shade) ||
- layoutState.isTransitioning(to = Scenes.QuickSettings))
+
+ // Note: We use derivedStateOf {} here because isClosing() is reading the current transition
+ // progress and we don't want to recompose this scene each time the progress has changed.
+ val isClosing by remember(layoutState) { derivedStateOf { isClosing(layoutState) } }
if (isClosing) {
DisposableEffect(Unit) {
@@ -188,6 +189,14 @@
}
}
+private fun isClosing(layoutState: SceneTransitionLayoutState): Boolean {
+ val transitionState = layoutState.transitionState
+ return transitionState is TransitionState.Transition &&
+ !(layoutState.isTransitioning(to = Scenes.Shade) ||
+ layoutState.isTransitioning(to = Scenes.QuickSettings)) &&
+ transitionState.progress >= 0.9f // almost done closing
+}
+
@Composable
private fun QuickSettingsContent(
qsSceneAdapter: QSSceneAdapter,
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt b/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt
index 3ec057b..491221f 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/ShadeScene.kt
@@ -361,6 +361,7 @@
carouselController = mediaCarouselController,
modifier = Modifier.layoutId(SingleShadeMeasurePolicy.LayoutId.Media),
usingCollapsedLandscapeMedia = usingCollapsedLandscapeMedia,
+ isInSplitShade = false,
)
NotificationScrollingStack(
@@ -565,6 +566,7 @@
Modifier.zIndex(1f)
},
carouselController = mediaCarouselController,
+ isInSplitShade = true,
)
}
FooterActionsWithAnimatedVisibility(
@@ -619,6 +621,7 @@
mediaOffsetProvider: ShadeMediaOffsetProvider,
modifier: Modifier = Modifier,
usingCollapsedLandscapeMedia: Boolean = false,
+ isInSplitShade: Boolean,
) {
MediaCarousel(
modifier = modifier.fillMaxWidth(),
@@ -632,5 +635,6 @@
{ mediaOffsetProvider.offset }
},
usingCollapsedLandscapeMedia = usingCollapsedLandscapeMedia,
+ isInSplitShade = isInSplitShade,
)
}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/state/TransitionState.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/state/TransitionState.kt
index 9d3f25e..3bd59df 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/state/TransitionState.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/state/TransitionState.kt
@@ -21,6 +21,7 @@
import androidx.compose.animation.core.spring
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.runtime.Stable
+import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import com.android.compose.animation.scene.ContentKey
@@ -249,18 +250,29 @@
private var fromOverscrollSpec: OverscrollSpecImpl? = null
private var toOverscrollSpec: OverscrollSpecImpl? = null
- /** The current [OverscrollSpecImpl], if this transition is currently overscrolling. */
- internal val currentOverscrollSpec: OverscrollSpecImpl?
- get() {
- if (this !is HasOverscrollProperties) return null
- val progress = progress
- val bouncingContent = bouncingContent
- return when {
- progress < 0f || bouncingContent == fromContent -> fromOverscrollSpec
- progress > 1f || bouncingContent == toContent -> toOverscrollSpec
- else -> null
+ /**
+ * The current [OverscrollSpecImpl], if this transition is currently overscrolling.
+ *
+ * Note: This is backed by a State<OverscrollSpecImpl?> because the overscroll spec is
+ * derived from progress, and we don't want readers of currentOverscrollSpec to recompose
+ * every time progress is changed.
+ */
+ private val _currentOverscrollSpec: State<OverscrollSpecImpl?>? =
+ if (this !is HasOverscrollProperties) {
+ null
+ } else {
+ derivedStateOf {
+ val progress = progress
+ val bouncingContent = bouncingContent
+ when {
+ progress < 0f || bouncingContent == fromContent -> fromOverscrollSpec
+ progress > 1f || bouncingContent == toContent -> toOverscrollSpec
+ else -> null
+ }
}
}
+ internal val currentOverscrollSpec: OverscrollSpecImpl?
+ get() = _currentOverscrollSpec?.value
/**
* An animatable that animates from 1f to 0f. This will be used to nicely animate the sudden
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt
index a2c2729..39d4699 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt
@@ -46,6 +46,7 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.approachLayout
+import androidx.compose.ui.layout.layout
import androidx.compose.ui.platform.LocalViewConfiguration
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assertIsDisplayed
@@ -70,11 +71,13 @@
import com.android.compose.animation.scene.TestScenes.SceneA
import com.android.compose.animation.scene.TestScenes.SceneB
import com.android.compose.animation.scene.TestScenes.SceneC
+import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.animation.scene.subjects.assertThat
import com.android.compose.test.assertSizeIsEqualTo
import com.android.compose.test.setContentAndCreateMainScope
import com.android.compose.test.transition
import com.google.common.truth.Truth.assertThat
+import com.google.common.truth.Truth.assertWithMessage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.junit.Assert.assertThrows
@@ -2581,4 +2584,61 @@
}
}
}
+
+ @Test
+ fun staticSharedElementShouldNotRemeasureOrReplaceDuringOverscrollableTransition() {
+ val size = 30.dp
+ var numberOfMeasurements = 0
+ var numberOfPlacements = 0
+
+ // Foo is a simple element that does not move or resize during the transition.
+ @Composable
+ fun SceneScope.Foo(modifier: Modifier = Modifier) {
+ Box(
+ modifier
+ .element(TestElements.Foo)
+ .layout { measurable, constraints ->
+ numberOfMeasurements++
+ measurable.measure(constraints).run {
+ numberOfPlacements++
+ layout(width, height) { place(0, 0) }
+ }
+ }
+ .size(size)
+ )
+ }
+
+ val state = rule.runOnUiThread { MutableSceneTransitionLayoutState(SceneA) }
+ val scope =
+ rule.setContentAndCreateMainScope {
+ SceneTransitionLayout(state) {
+ scene(SceneA) { Box(Modifier.fillMaxSize()) { Foo() } }
+ scene(SceneB) { Box(Modifier.fillMaxSize()) { Foo() } }
+ }
+ }
+
+ // Start an overscrollable transition driven by progress.
+ var progress by mutableFloatStateOf(0f)
+ val transition = transition(from = SceneA, to = SceneB, progress = { progress })
+ assertThat(transition).isInstanceOf(TransitionState.HasOverscrollProperties::class.java)
+ scope.launch { state.startTransition(transition) }
+
+ // Reset the counters after the first animation frame.
+ rule.waitForIdle()
+ numberOfMeasurements = 0
+ numberOfPlacements = 0
+
+ // Change the progress a bunch of times.
+ val nFrames = 20
+ repeat(nFrames) { i ->
+ progress = i / nFrames.toFloat()
+ rule.waitForIdle()
+
+ // We shouldn't have remeasured or replaced Foo.
+ assertWithMessage("Frame $i didn't remeasure Foo")
+ .that(numberOfMeasurements)
+ .isEqualTo(0)
+ assertWithMessage("Frame $i didn't replace Foo").that(numberOfPlacements).isEqualTo(0)
+ }
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt
index 13f30f5..945e44a 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt
@@ -46,6 +46,7 @@
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnit
+import org.mockito.kotlin.isNull
@ExperimentalCoroutinesApi
@SmallTest
@@ -96,7 +97,7 @@
.sendVolumeKeyEvent(
eq(actionDownVolumeDownKeyEvent),
eq(AudioManager.USE_DEFAULT_STREAM_TYPE),
- eq(true)
+ eq(true),
)
assertThat(underTest.dispatchKeyEvent(actionDownVolumeUpKeyEvent)).isTrue()
@@ -104,7 +105,7 @@
.sendVolumeKeyEvent(
eq(actionDownVolumeUpKeyEvent),
eq(AudioManager.USE_DEFAULT_STREAM_TYPE),
- eq(true)
+ eq(true),
)
}
@@ -117,7 +118,7 @@
.sendVolumeKeyEvent(
eq(actionDownVolumeDownKeyEvent),
eq(AudioManager.USE_DEFAULT_STREAM_TYPE),
- eq(true)
+ eq(true),
)
assertThat(underTest.dispatchKeyEvent(actionDownVolumeUpKeyEvent)).isFalse()
@@ -125,7 +126,7 @@
.sendVolumeKeyEvent(
eq(actionDownVolumeUpKeyEvent),
eq(AudioManager.USE_DEFAULT_STREAM_TYPE),
- eq(true)
+ eq(true),
)
}
@@ -135,7 +136,9 @@
whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED)
whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true)
- verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_MENU)
+ val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU)
+ assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue()
+ verify(statusBarKeyguardViewManager).dismissWithAction(any(), isNull(), eq(false))
}
@Test
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractorTest.kt
index 12039c1..e079619 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractorTest.kt
@@ -118,11 +118,11 @@
LOCKSCREEN,
0f,
STARTED,
- ownerName = "KeyguardTransitionRepository(boot)"
+ ownerName = "KeyguardTransitionRepository(boot)",
),
steps[0],
steps[3],
- steps[6]
+ steps[6],
)
)
}
@@ -253,51 +253,20 @@
true, // The repo is seeded with a transition from OFF to LOCKSCREEN.
false,
),
- inTransition
+ inTransition,
)
- sendSteps(
- TransitionStep(LOCKSCREEN, GONE, 0f, STARTED),
- )
+ sendSteps(TransitionStep(LOCKSCREEN, GONE, 0f, STARTED))
- assertEquals(
- listOf(
- false,
- true,
- false,
- true,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false, true), inTransition)
- sendSteps(
- TransitionStep(LOCKSCREEN, GONE, 0.5f, RUNNING),
- )
+ sendSteps(TransitionStep(LOCKSCREEN, GONE, 0.5f, RUNNING))
- assertEquals(
- listOf(
- false,
- true,
- false,
- true,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false, true), inTransition)
- sendSteps(
- TransitionStep(LOCKSCREEN, GONE, 1f, FINISHED),
- )
+ sendSteps(TransitionStep(LOCKSCREEN, GONE, 1f, FINISHED))
- assertEquals(
- listOf(
- false,
- true,
- false,
- true,
- false,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false, true, false), inTransition)
}
@Test
@@ -312,33 +281,16 @@
true, // The repo is seeded with a transition from OFF to LOCKSCREEN.
false,
),
- inTransition
+ inTransition,
)
kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Bouncer))
- assertEquals(
- listOf(
- false,
- true,
- false,
- true,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false, true), inTransition)
kosmos.setSceneTransition(Idle(Scenes.Bouncer))
- assertEquals(
- listOf(
- false,
- true,
- false,
- true,
- false,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false, true, false), inTransition)
}
@Test
@@ -346,14 +298,7 @@
testScope.runTest {
val inTransition by collectValues(underTest.isInTransition)
- assertEquals(
- listOf(
- false,
- true,
- false,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false), inTransition)
// Start FINISHED in GONE.
sendSteps(
@@ -362,32 +307,11 @@
TransitionStep(LOCKSCREEN, GONE, 1f, FINISHED),
)
- assertEquals(
- listOf(
- false,
- true,
- false,
- true,
- false,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false, true, false), inTransition)
- sendSteps(
- TransitionStep(GONE, DOZING, 0f, STARTED),
- )
+ sendSteps(TransitionStep(GONE, DOZING, 0f, STARTED))
- assertEquals(
- listOf(
- false,
- true,
- false,
- true,
- false,
- true,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false, true, false, true), inTransition)
sendSteps(
TransitionStep(GONE, DOZING, 0.5f, RUNNING),
@@ -410,7 +334,7 @@
// transitioning to GONE, the state we're also FINISHED in.
true,
),
- inTransition
+ inTransition,
)
sendSteps(
@@ -418,18 +342,7 @@
TransitionStep(LOCKSCREEN, GONE, 1f, FINISHED),
)
- assertEquals(
- listOf(
- false,
- true,
- false,
- true,
- false,
- true,
- false,
- ),
- inTransition
- )
+ assertEquals(listOf(false, true, false, true, false, true, false), inTransition)
}
@Test
@@ -440,7 +353,7 @@
collectValues(
underTest.isInTransition(
edge = Edge.create(OFF, OFF),
- edgeWithoutSceneContainer = Edge.create(to = LOCKSCREEN)
+ edgeWithoutSceneContainer = Edge.create(to = LOCKSCREEN),
)
)
@@ -450,49 +363,19 @@
TransitionStep(AOD, DOZING, 1f, FINISHED),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
- sendSteps(
- TransitionStep(DOZING, LOCKSCREEN, 0f, STARTED),
- )
+ sendSteps(TransitionStep(DOZING, LOCKSCREEN, 0f, STARTED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
- sendSteps(
- TransitionStep(DOZING, LOCKSCREEN, 0f, RUNNING),
- )
+ sendSteps(TransitionStep(DOZING, LOCKSCREEN, 0f, RUNNING))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
- sendSteps(
- TransitionStep(DOZING, LOCKSCREEN, 0f, FINISHED),
- )
+ sendSteps(TransitionStep(DOZING, LOCKSCREEN, 0f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(LOCKSCREEN, DOZING, 0f, STARTED),
@@ -500,29 +383,14 @@
TransitionStep(LOCKSCREEN, DOZING, 1f, FINISHED),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(DOZING, LOCKSCREEN, 0f, STARTED),
TransitionStep(DOZING, LOCKSCREEN, 0f, RUNNING),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false, true))
}
@Test
@@ -535,33 +403,15 @@
kosmos.setSceneTransition(Transition(from = Scenes.Gone, to = Scenes.Lockscreen))
kosmos.setSceneTransition(Idle(Scenes.Lockscreen))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
kosmos.setSceneTransition(Transition(from = Scenes.Lockscreen, to = Scenes.Shade))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
kosmos.setSceneTransition(Idle(Scenes.Shade))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
}
@Test
@@ -575,14 +425,7 @@
kosmos.setSceneTransition(Idle(Scenes.Lockscreen))
kosmos.setSceneTransition(Transition(from = Scenes.Lockscreen, to = Scenes.Gone))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
}
@Test
@@ -602,14 +445,7 @@
kosmos.setSceneTransition(Idle(Scenes.Gone))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
}
@Test
@@ -623,49 +459,19 @@
TransitionStep(AOD, DOZING, 1f, FINISHED),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
- sendSteps(
- TransitionStep(DOZING, LOCKSCREEN, 0f, STARTED),
- )
+ sendSteps(TransitionStep(DOZING, LOCKSCREEN, 0f, STARTED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
- sendSteps(
- TransitionStep(DOZING, LOCKSCREEN, 0f, RUNNING),
- )
+ sendSteps(TransitionStep(DOZING, LOCKSCREEN, 0f, RUNNING))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
- sendSteps(
- TransitionStep(DOZING, LOCKSCREEN, 0f, FINISHED),
- )
+ sendSteps(TransitionStep(DOZING, LOCKSCREEN, 0f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(LOCKSCREEN, DOZING, 0f, STARTED),
@@ -673,29 +479,14 @@
TransitionStep(LOCKSCREEN, DOZING, 1f, FINISHED),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(DOZING, LOCKSCREEN, 0f, STARTED),
TransitionStep(DOZING, LOCKSCREEN, 0f, RUNNING),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false, true))
}
@Test
@@ -715,49 +506,19 @@
TransitionStep(AOD, DOZING, 1f, FINISHED),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
- sendSteps(
- TransitionStep(DOZING, GONE, 0f, STARTED),
- )
+ sendSteps(TransitionStep(DOZING, GONE, 0f, STARTED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
- sendSteps(
- TransitionStep(DOZING, GONE, 0f, RUNNING),
- )
+ sendSteps(TransitionStep(DOZING, GONE, 0f, RUNNING))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
- sendSteps(
- TransitionStep(DOZING, GONE, 0f, FINISHED),
- )
+ sendSteps(TransitionStep(DOZING, GONE, 0f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(GONE, DOZING, 0f, STARTED),
@@ -765,29 +526,14 @@
TransitionStep(GONE, DOZING, 1f, FINISHED),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(DOZING, GONE, 0f, STARTED),
TransitionStep(DOZING, GONE, 0f, RUNNING),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false, true))
}
@Test
@@ -807,48 +553,19 @@
TransitionStep(AOD, DOZING, 1f, FINISHED),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
- sendSteps(
- TransitionStep(DOZING, GONE, 0f, STARTED),
- )
+ sendSteps(TransitionStep(DOZING, GONE, 0f, STARTED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
- sendSteps(
- TransitionStep(DOZING, GONE, 0f, RUNNING),
- )
+ sendSteps(TransitionStep(DOZING, GONE, 0f, RUNNING))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
- sendSteps(
- TransitionStep(DOZING, GONE, 0f, CANCELED),
- )
+ sendSteps(TransitionStep(DOZING, GONE, 0f, CANCELED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
sendSteps(
TransitionStep(GONE, DOZING, 0f, STARTED),
@@ -856,29 +573,14 @@
TransitionStep(GONE, DOZING, 1f, FINISHED),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(DOZING, GONE, 0f, STARTED),
TransitionStep(DOZING, GONE, 0f, RUNNING),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false, true))
}
@Test
@@ -895,87 +597,43 @@
assertThat(results)
.isEqualTo(
listOf(
- false, // Finished in DOZING, not GONE.
+ false // Finished in DOZING, not GONE.
)
)
sendSteps(TransitionStep(DOZING, GONE, 0f, STARTED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
sendSteps(TransitionStep(DOZING, GONE, 0f, RUNNING))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
sendSteps(TransitionStep(DOZING, GONE, 1f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
sendSteps(
TransitionStep(GONE, DOZING, 0f, STARTED),
TransitionStep(GONE, DOZING, 0f, RUNNING),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
sendSteps(TransitionStep(GONE, DOZING, 1f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(DOZING, GONE, 0f, STARTED),
TransitionStep(DOZING, GONE, 0f, RUNNING),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(TransitionStep(DOZING, GONE, 1f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false, true))
}
@Test
@@ -993,87 +651,43 @@
assertThat(results)
.isEqualTo(
listOf(
- false, // Finished in DOZING, not GONE.
+ false // Finished in DOZING, not GONE.
)
)
sendSteps(TransitionStep(DOZING, GONE, 0f, STARTED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
sendSteps(TransitionStep(DOZING, GONE, 0f, RUNNING))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
sendSteps(TransitionStep(DOZING, GONE, 1f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
sendSteps(
TransitionStep(GONE, DOZING, 0f, STARTED),
TransitionStep(GONE, DOZING, 0f, RUNNING),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
sendSteps(TransitionStep(GONE, DOZING, 1f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(
TransitionStep(DOZING, GONE, 0f, STARTED),
TransitionStep(DOZING, GONE, 0f, RUNNING),
)
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
sendSteps(TransitionStep(DOZING, GONE, 1f, FINISHED))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false, true))
}
@Test
@@ -1091,72 +705,33 @@
assertThat(results)
.isEqualTo(
listOf(
- false, // Finished in DOZING, not GONE.
+ false // Finished in DOZING, not GONE.
)
)
kosmos.setSceneTransition(Transition(from = Scenes.Lockscreen, to = Scenes.Gone))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false))
kosmos.setSceneTransition(Idle(Scenes.Gone))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
kosmos.setSceneTransition(Transition(from = Scenes.Gone, to = Scenes.Lockscreen))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true))
kosmos.setSceneTransition(Idle(Scenes.Lockscreen))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
kosmos.setSceneTransition(Transition(from = Scenes.Lockscreen, to = Scenes.Gone))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false))
kosmos.setSceneTransition(Idle(Scenes.Gone))
- assertThat(results)
- .isEqualTo(
- listOf(
- false,
- true,
- false,
- true,
- )
- )
+ assertThat(results).isEqualTo(listOf(false, true, false, true))
}
@Test
@@ -1165,68 +740,29 @@
val currentStates by collectValues(underTest.currentKeyguardState)
// We init the repo with a transition from OFF -> LOCKSCREEN.
- assertEquals(
- listOf(
- OFF,
- LOCKSCREEN,
- ),
- currentStates
- )
+ assertEquals(listOf(OFF, LOCKSCREEN), currentStates)
- sendSteps(
- TransitionStep(LOCKSCREEN, AOD, 0f, STARTED),
- )
+ sendSteps(TransitionStep(LOCKSCREEN, AOD, 0f, STARTED))
// The current state should continue to be LOCKSCREEN as we transition to AOD.
- assertEquals(
- listOf(
- OFF,
- LOCKSCREEN,
- ),
- currentStates
- )
+ assertEquals(listOf(OFF, LOCKSCREEN), currentStates)
- sendSteps(
- TransitionStep(LOCKSCREEN, AOD, 0.5f, RUNNING),
- )
+ sendSteps(TransitionStep(LOCKSCREEN, AOD, 0.5f, RUNNING))
// The current state should continue to be LOCKSCREEN as we transition to AOD.
- assertEquals(
- listOf(
- OFF,
- LOCKSCREEN,
- ),
- currentStates
- )
+ assertEquals(listOf(OFF, LOCKSCREEN), currentStates)
- sendSteps(
- TransitionStep(LOCKSCREEN, AOD, 0.6f, CANCELED),
- )
+ sendSteps(TransitionStep(LOCKSCREEN, AOD, 0.6f, CANCELED))
// Once CANCELED, we're still currently in LOCKSCREEN...
- assertEquals(
- listOf(
- OFF,
- LOCKSCREEN,
- ),
- currentStates
- )
+ assertEquals(listOf(OFF, LOCKSCREEN), currentStates)
- sendSteps(
- TransitionStep(AOD, LOCKSCREEN, 0.6f, STARTED),
- )
+ sendSteps(TransitionStep(AOD, LOCKSCREEN, 0.6f, STARTED))
// ...until STARTING back to LOCKSCREEN, at which point the "current" state should be
// the
// one we're transitioning from, despite never FINISHING in that state.
- assertEquals(
- listOf(
- OFF,
- LOCKSCREEN,
- AOD,
- ),
- currentStates
- )
+ assertEquals(listOf(OFF, LOCKSCREEN, AOD), currentStates)
sendSteps(
TransitionStep(AOD, LOCKSCREEN, 0.8f, RUNNING),
@@ -1234,15 +770,7 @@
)
// FINSHING in LOCKSCREEN should update the current state to LOCKSCREEN.
- assertEquals(
- listOf(
- OFF,
- LOCKSCREEN,
- AOD,
- LOCKSCREEN,
- ),
- currentStates
- )
+ assertEquals(listOf(OFF, LOCKSCREEN, AOD, LOCKSCREEN), currentStates)
}
@Test
@@ -1251,13 +779,7 @@
val currentStates by collectValues(underTest.currentKeyguardState)
// We init the repo with a transition from OFF -> LOCKSCREEN.
- assertEquals(
- listOf(
- OFF,
- LOCKSCREEN,
- ),
- currentStates
- )
+ assertEquals(listOf(OFF, LOCKSCREEN), currentStates)
sendSteps(
TransitionStep(LOCKSCREEN, GONE, 0f, STARTED),
@@ -1273,7 +795,7 @@
// Transitioned to GONE
GONE,
),
- currentStates
+ currentStates,
)
sendSteps(
@@ -1290,12 +812,10 @@
// Current state should not be DOZING until the post-cancelation transition is
// STARTED
),
- currentStates
+ currentStates,
)
- sendSteps(
- TransitionStep(DOZING, LOCKSCREEN, 0f, STARTED),
- )
+ sendSteps(TransitionStep(DOZING, LOCKSCREEN, 0f, STARTED))
assertEquals(
listOf(
@@ -1305,7 +825,7 @@
// DOZING -> LS STARTED, DOZING is now the current state.
DOZING,
),
- currentStates
+ currentStates,
)
sendSteps(
@@ -1313,19 +833,9 @@
TransitionStep(DOZING, LOCKSCREEN, 0.6f, CANCELED),
)
- assertEquals(
- listOf(
- OFF,
- LOCKSCREEN,
- GONE,
- DOZING,
- ),
- currentStates
- )
+ assertEquals(listOf(OFF, LOCKSCREEN, GONE, DOZING), currentStates)
- sendSteps(
- TransitionStep(LOCKSCREEN, GONE, 0f, STARTED),
- )
+ sendSteps(TransitionStep(LOCKSCREEN, GONE, 0f, STARTED))
assertEquals(
listOf(
@@ -1336,7 +846,7 @@
// LS -> GONE STARTED, LS is now the current state.
LOCKSCREEN,
),
- currentStates
+ currentStates,
)
sendSteps(
@@ -1354,7 +864,7 @@
// FINISHED in GONE, GONE is now the current state.
GONE,
),
- currentStates
+ currentStates,
)
}
@@ -1504,6 +1014,126 @@
}
}
+ @Test
+ @EnableSceneContainer
+ fun simulateTransitionStepsForSceneTransitions_emits_correct_values_for_wildcard_from_edge() =
+ testScope.runTest {
+ val sceneToSceneSteps by
+ collectValues(underTest.transition(Edge.create(from = Scenes.Gone)))
+ val progress = MutableSharedFlow<Float>()
+
+ kosmos.setSceneTransition(
+ Transition(Scenes.Gone, Scenes.Lockscreen, progress = progress)
+ )
+
+ progress.emit(0.2f)
+ runCurrent()
+ progress.emit(0.6f)
+ runCurrent()
+
+ kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Bouncer, progress = progress))
+
+ progress.emit(0.1f)
+ runCurrent()
+
+ kosmos.setSceneTransition(
+ Transition(Scenes.Bouncer, Scenes.Lockscreen, progress = progress)
+ )
+
+ progress.emit(0.3f)
+ runCurrent()
+
+ kosmos.setSceneTransition(Idle(Scenes.Gone))
+
+ assertEquals(
+ listOf(
+ TransitionStep(UNDEFINED, UNDEFINED, 0f, STARTED),
+ TransitionStep(UNDEFINED, UNDEFINED, 0.2f, RUNNING),
+ TransitionStep(UNDEFINED, UNDEFINED, 0.6f, RUNNING),
+ TransitionStep(UNDEFINED, UNDEFINED, 1f, FINISHED),
+ TransitionStep(UNDEFINED, UNDEFINED, 0f, STARTED),
+ TransitionStep(UNDEFINED, UNDEFINED, 0.1f, RUNNING),
+ TransitionStep(UNDEFINED, UNDEFINED, 1f, FINISHED),
+ ),
+ sceneToSceneSteps,
+ )
+ }
+
+ @Test
+ @EnableSceneContainer
+ fun simulateTransitionStepsForSceneTransitions_emits_correct_values_for_wildcard_to_edge() =
+ testScope.runTest {
+ val sceneToSceneSteps by
+ collectValues(underTest.transition(Edge.create(to = Scenes.Gone)))
+ val progress = MutableSharedFlow<Float>()
+
+ kosmos.setSceneTransition(
+ Transition(Scenes.Gone, Scenes.Lockscreen, progress = progress)
+ )
+
+ progress.emit(0.2f)
+ runCurrent()
+
+ kosmos.setSceneTransition(Idle(Scenes.Gone))
+
+ kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Bouncer, progress = progress))
+
+ progress.emit(0.1f)
+ runCurrent()
+
+ kosmos.setSceneTransition(Transition(Scenes.Bouncer, Scenes.Gone, progress = progress))
+
+ progress.emit(0.3f)
+ runCurrent()
+
+ kosmos.setSceneTransition(Idle(Scenes.Gone))
+
+ assertEquals(
+ listOf(
+ TransitionStep(UNDEFINED, UNDEFINED, 0f, STARTED),
+ TransitionStep(UNDEFINED, UNDEFINED, 0.3f, RUNNING),
+ TransitionStep(UNDEFINED, UNDEFINED, 1f, FINISHED),
+ ),
+ sceneToSceneSteps,
+ )
+ }
+
+ @Test
+ @EnableSceneContainer
+ fun flatMapLatestWithFinished_emission_of_previous_progress_flow_is_not_interleaving() =
+ testScope.runTest {
+ val sceneToSceneSteps by
+ collectValues(underTest.transition(Edge.create(from = Scenes.Gone)))
+ val progress1 = MutableSharedFlow<Float>()
+ val progress2 = MutableSharedFlow<Float>()
+
+ kosmos.setSceneTransition(
+ Transition(Scenes.Gone, Scenes.Lockscreen, progress = progress1)
+ )
+
+ progress1.emit(0.1f)
+ runCurrent()
+
+ kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Bouncer, progress = progress2))
+
+ progress2.emit(0.3f)
+ runCurrent()
+
+ progress1.emit(0.2f)
+ runCurrent()
+
+ assertEquals(
+ listOf(
+ TransitionStep(UNDEFINED, UNDEFINED, 0f, STARTED),
+ TransitionStep(UNDEFINED, UNDEFINED, 0.1f, RUNNING),
+ TransitionStep(UNDEFINED, UNDEFINED, 1f, FINISHED),
+ TransitionStep(UNDEFINED, UNDEFINED, 0f, STARTED),
+ TransitionStep(UNDEFINED, UNDEFINED, 0.3f, RUNNING),
+ ),
+ sceneToSceneSteps,
+ )
+ }
+
private suspend fun sendSteps(vararg steps: TransitionStep) {
steps.forEach {
repository.sendTransitionStep(it)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractorTest.kt
index de3dc57..1d80826 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractorTest.kt
@@ -28,6 +28,7 @@
import com.android.settingslib.notification.modes.TestModeBuilder
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestableContext
+import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.asIcon
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
@@ -144,13 +145,13 @@
// Tile starts with the generic Modes icon.
runCurrent()
- assertThat(tileData?.icon).isEqualTo(MODES_ICON)
+ assertThat(tileData?.icon).isEqualTo(MODES_RESOURCE_ICON)
assertThat(tileData?.iconResId).isEqualTo(MODES_DRAWABLE_ID)
// Add an inactive mode -> Still modes icon
zenModeRepository.addMode(id = "Mode", active = false)
runCurrent()
- assertThat(tileData?.icon).isEqualTo(MODES_ICON)
+ assertThat(tileData?.icon).isEqualTo(MODES_RESOURCE_ICON)
assertThat(tileData?.iconResId).isEqualTo(MODES_DRAWABLE_ID)
// Add an active mode with a default icon: icon should be the mode icon, and the
@@ -158,7 +159,7 @@
zenModeRepository.addMode(
id = "Bedtime with default icon",
type = AutomaticZenRule.TYPE_BEDTIME,
- active = true
+ active = true,
)
runCurrent()
assertThat(tileData?.icon).isEqualTo(BEDTIME_ICON)
@@ -189,7 +190,7 @@
// Deactivate remaining mode: back to the default modes icon
zenModeRepository.deactivateMode("Driving with custom icon")
runCurrent()
- assertThat(tileData?.icon).isEqualTo(MODES_ICON)
+ assertThat(tileData?.icon).isEqualTo(MODES_RESOURCE_ICON)
assertThat(tileData?.iconResId).isEqualTo(MODES_DRAWABLE_ID)
}
@@ -204,18 +205,18 @@
)
runCurrent()
- assertThat(tileData?.icon).isEqualTo(MODES_ICON)
+ assertThat(tileData?.icon).isEqualTo(MODES_RESOURCE_ICON)
assertThat(tileData?.iconResId).isEqualTo(MODES_DRAWABLE_ID)
// Activate a Mode -> Icon doesn't change.
zenModeRepository.addMode(id = "Mode", active = true)
runCurrent()
- assertThat(tileData?.icon).isEqualTo(MODES_ICON)
+ assertThat(tileData?.icon).isEqualTo(MODES_RESOURCE_ICON)
assertThat(tileData?.iconResId).isEqualTo(MODES_DRAWABLE_ID)
zenModeRepository.deactivateMode(id = "Mode")
runCurrent()
- assertThat(tileData?.icon).isEqualTo(MODES_ICON)
+ assertThat(tileData?.icon).isEqualTo(MODES_RESOURCE_ICON)
assertThat(tileData?.iconResId).isEqualTo(MODES_DRAWABLE_ID)
}
@@ -263,7 +264,7 @@
val BEDTIME_DRAWABLE = TestStubDrawable("bedtime")
val CUSTOM_DRAWABLE = TestStubDrawable("custom")
- val MODES_ICON = MODES_DRAWABLE.asIcon()
+ val MODES_RESOURCE_ICON = Icon.Resource(MODES_DRAWABLE_ID, null)
val BEDTIME_ICON = BEDTIME_DRAWABLE.asIcon()
val CUSTOM_ICON = CUSTOM_DRAWABLE.asIcon()
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/modes/ui/ModesTileMapperTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/modes/ui/ModesTileMapperTest.kt
index c3d45db..a58cb9c 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/modes/ui/ModesTileMapperTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/modes/ui/ModesTileMapperTest.kt
@@ -22,7 +22,9 @@
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
+import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.asIcon
+import com.android.systemui.qs.tiles.ModesTile
import com.android.systemui.qs.tiles.impl.modes.domain.model.ModesTileModel
import com.android.systemui.qs.tiles.viewmodel.QSTileConfigTestBuilder
import com.android.systemui.qs.tiles.viewmodel.QSTileState
@@ -51,6 +53,11 @@
.apply {
addOverride(R.drawable.qs_dnd_icon_on, TestStubDrawable())
addOverride(R.drawable.qs_dnd_icon_off, TestStubDrawable())
+ addOverride(
+ ModesTile.ICON_RES_ID,
+ TestStubDrawable(ModesTile.ICON_RES_ID.toString()),
+ )
+ addOverride(123, TestStubDrawable("123"))
}
.resources,
context.theme,
@@ -59,12 +66,7 @@
@Test
fun inactiveState() {
val icon = TestStubDrawable("res123").asIcon()
- val model =
- ModesTileModel(
- isActivated = false,
- activeModes = emptyList(),
- icon = icon,
- )
+ val model = ModesTileModel(isActivated = false, activeModes = emptyList(), icon = icon)
val state = underTest.map(config, model)
@@ -76,12 +78,7 @@
@Test
fun activeState_oneMode() {
val icon = TestStubDrawable("res123").asIcon()
- val model =
- ModesTileModel(
- isActivated = true,
- activeModes = listOf("DND"),
- icon = icon,
- )
+ val model = ModesTileModel(isActivated = true, activeModes = listOf("DND"), icon = icon)
val state = underTest.map(config, model)
@@ -108,19 +105,36 @@
}
@Test
- fun state_modelHasIconResId_includesIconResId() {
- val icon = TestStubDrawable("res123").asIcon()
+ fun resourceIconModel_whenResIdsIdentical_mapsToLoadedIconWithInputResId() {
+ val icon = Icon.Resource(123, null)
val model =
ModesTileModel(
isActivated = false,
activeModes = emptyList(),
icon = icon,
- iconResId = 123
+ iconResId = 123,
)
val state = underTest.map(config, model)
- assertThat(state.icon()).isEqualTo(icon)
+ assertThat(state.icon()).isEqualTo(TestStubDrawable("123").asIcon())
+ assertThat(state.iconRes).isEqualTo(123)
+ }
+
+ @Test
+ fun resourceIconModel_whenResIdsNonIdentical_mapsToLoadedIconWithIconResourceId() {
+ val icon = Icon.Resource(123, null)
+ val model =
+ ModesTileModel(
+ isActivated = false,
+ activeModes = emptyList(),
+ icon = icon,
+ iconResId = 321, // Note: NOT 123. This will be ignored.
+ )
+
+ val state = underTest.map(config, model)
+
+ assertThat(state.icon()).isEqualTo(TestStubDrawable("123").asIcon())
assertThat(state.iconRes).isEqualTo(123)
}
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModelTest.kt
index 9d93a9c..39836e2 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/ui/dialog/viewmodel/ModesDialogViewModelTest.kt
@@ -19,6 +19,7 @@
package com.android.systemui.statusbar.policy.ui.dialog.viewmodel
import android.content.Intent
+import android.content.applicationContext
import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -38,9 +39,11 @@
import kotlinx.coroutines.Job
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
+import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.clearInvocations
+import org.mockito.MockitoAnnotations
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
@@ -55,14 +58,20 @@
private val mockDialogDelegate = kosmos.mockModesDialogDelegate
private val mockDialogEventLogger = kosmos.mockModesDialogEventLogger
- private val underTest =
- ModesDialogViewModel(
- context,
- interactor,
- kosmos.testDispatcher,
- mockDialogDelegate,
- mockDialogEventLogger,
- )
+ private lateinit var underTest: ModesDialogViewModel
+
+ @Before
+ fun setUp() {
+ MockitoAnnotations.initMocks(this)
+ underTest =
+ ModesDialogViewModel(
+ kosmos.applicationContext,
+ interactor,
+ kosmos.testDispatcher,
+ kosmos.mockModesDialogDelegate,
+ kosmos.mockModesDialogEventLogger,
+ )
+ }
@Test
fun tiles_filtersOutUserDisabledModes() =
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorTest.kt
index fa7f37c..449dc20 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorTest.kt
@@ -16,11 +16,16 @@
package com.android.systemui.volume.panel.component.mediaoutput.domain.interactor
+import android.content.mockedContext
+import android.content.packageManager
+import android.content.pm.PackageManager.FEATURE_PC
import android.graphics.drawable.TestStubDrawable
import android.media.AudioManager
+import android.platform.test.annotations.EnableFlags
import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
+import com.android.media.flags.Flags;
import com.android.settingslib.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
@@ -42,6 +47,7 @@
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+import org.mockito.kotlin.whenever
private const val builtInDeviceName = "This phone"
@@ -79,6 +85,8 @@
fun inCall_stateIs_Calling() =
with(kosmos) {
testScope.runTest {
+ whenever(mockedContext.getPackageManager()).thenReturn(packageManager)
+ whenever(packageManager.hasSystemFeature(FEATURE_PC)).thenReturn(false)
with(audioRepository) {
setMode(AudioManager.MODE_IN_CALL)
setCommunicationDevice(TestAudioDevicesFactory.builtInDevice())
@@ -98,6 +106,33 @@
}
}
+ @EnableFlags(Flags.FLAG_ENABLE_AUDIO_INPUT_DEVICE_ROUTING_AND_VOLUME_CONTROL)
+ @Test
+ fun inCall_stateIs_Calling_enableInputRouting_desktop() =
+ with(kosmos) {
+ testScope.runTest {
+ whenever(mockedContext.getPackageManager()).thenReturn(packageManager)
+ whenever(packageManager.hasSystemFeature(FEATURE_PC)).thenReturn(true)
+
+ with(audioRepository) {
+ setMode(AudioManager.MODE_IN_CALL)
+ setCommunicationDevice(TestAudioDevicesFactory.builtInDevice())
+ }
+
+ val model by collectLastValue(underTest.mediaOutputModel.filterData())
+ runCurrent()
+
+ assertThat(model)
+ .isEqualTo(
+ MediaOutputComponentModel.Calling(
+ device = AudioOutputDevice.BuiltIn(builtInDeviceName, testIcon),
+ isInAudioSharing = false,
+ canOpenAudioSwitcher = true,
+ )
+ )
+ }
+ }
+
@Test
fun hasSession_stateIs_MediaSession() =
with(kosmos) {
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuController.java b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuController.java
index 275147e..41b9d33 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuController.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuController.java
@@ -226,7 +226,11 @@
mBtnTargets =
mAccessibilityButtonTargetsObserver.getCurrentAccessibilityButtonTargets();
mHandler.post(
- () -> handleFloatingMenuVisibility(mIsKeyguardVisible, mBtnMode, mBtnTargets));
+ () -> {
+ // Force a refresh by destroying the menu if it exists.
+ destroyFloatingMenu();
+ handleFloatingMenuVisibility(mIsKeyguardVisible, mBtnMode, mBtnTargets);
+ });
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt b/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt
index 13b4aa9..6228ac5 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt
@@ -32,9 +32,9 @@
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.Modifier
import androidx.lifecycle.lifecycleScope
-import com.android.compose.theme.LocalAndroidColorScheme
import com.android.compose.theme.PlatformTheme
import com.android.internal.logging.UiEventLogger
import com.android.systemui.Flags.communalEditWidgetsActivityFinishFix
@@ -227,7 +227,7 @@
Box(
modifier =
Modifier.fillMaxSize()
- .background(LocalAndroidColorScheme.current.surfaceDim),
+ .background(MaterialTheme.colorScheme.surfaceDim),
) {
CommunalHub(
viewModel = communalViewModel,
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 2052459..d28b08f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -2460,6 +2460,12 @@
android.util.Log.i(TAG, "Ignoring request to dismiss (user switch in progress?)");
return;
}
+
+ if (mKeyguardStateController.isKeyguardGoingAway()) {
+ Log.i(TAG, "Ignoring dismiss because we're already going away.");
+ return;
+ }
+
mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
}
@@ -3428,6 +3434,12 @@
return;
}
+ if (mIsKeyguardExitAnimationCanceled) {
+ Log.d(TAG, "Ignoring exitKeyguardAndFinishSurfaceBehindRemoteAnimation. "
+ + "mIsKeyguardExitAnimationCanceled==true");
+ return;
+ }
+
// Block the panel from expanding, in case we were doing a swipe to dismiss gesture.
mKeyguardViewControllerLazy.get().blockPanelExpansionFromCurrentTouch();
final boolean wasShowing = mShowing;
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt
index 65b42e6..fcf486b 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt
@@ -23,6 +23,7 @@
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyevent.domain.interactor.SysUIKeyEventHandler.Companion.handleAction
import com.android.systemui.media.controls.util.MediaSessionLegacyHelperWrapper
+import com.android.systemui.plugins.ActivityStarter.OnDismissAction
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.shade.ShadeController
@@ -105,7 +106,15 @@
(statusBarStateController.state != StatusBarState.SHADE) &&
statusBarKeyguardViewManager.shouldDismissOnMenuPressed()
if (shouldUnlockOnMenuPressed) {
- shadeController.animateCollapseShadeForced()
+ statusBarKeyguardViewManager.dismissWithAction(
+ object : OnDismissAction {
+ override fun onDismiss(): Boolean {
+ return false
+ }
+ },
+ null,
+ false,
+ )
return true
}
return false
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt
index c4f231d..a0000f3 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt
@@ -19,6 +19,7 @@
import android.annotation.SuppressLint
import android.util.Log
+import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
@@ -37,15 +38,22 @@
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.channels.BufferOverflow
+import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.flow
+import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onStart
@@ -206,44 +214,155 @@
)
}
- return if (SceneContainerFlag.isEnabled) {
- flow.filter { step ->
- val fromScene =
- when (edge) {
- is Edge.StateToState -> edge.from?.mapToSceneContainerScene()
- is Edge.StateToScene -> edge.from?.mapToSceneContainerScene()
- is Edge.SceneToState -> edge.from
+ if (!SceneContainerFlag.isEnabled) {
+ return flow
+ }
+ if (edge.isSceneWildcardEdge()) {
+ return simulateTransitionStepsForSceneTransitions(edge)
+ }
+ return flow.filter { step ->
+ val fromScene =
+ when (edge) {
+ is Edge.StateToState -> edge.from?.mapToSceneContainerScene()
+ is Edge.StateToScene -> edge.from?.mapToSceneContainerScene()
+ is Edge.SceneToState -> edge.from
+ }
+
+ val toScene =
+ when (edge) {
+ is Edge.StateToState -> edge.to?.mapToSceneContainerScene()
+ is Edge.StateToScene -> edge.to
+ is Edge.SceneToState -> edge.to?.mapToSceneContainerScene()
+ }
+
+ val isTransitioningBetweenLockscreenStates =
+ fromScene.isLockscreenOrNull() && toScene.isLockscreenOrNull()
+ val isTransitioningBetweenDesiredScenes =
+ sceneInteractor.transitionState.value.isTransitioning(fromScene, toScene)
+
+ // We can't compare the terminal step with the current sceneTransition because
+ // a) STL has no guarantee that it will settle in Idle() when finished/canceled
+ // b) Comparing to Idle(toScene) would make any other FINISHED step settling in
+ // toScene pass as well
+ val terminalStepBelongsToPreviousTransition =
+ (step.transitionState == TransitionState.FINISHED ||
+ step.transitionState == TransitionState.CANCELED) &&
+ sceneTransitionPair.value.previousValue.isTransitioning(fromScene, toScene)
+
+ return@filter isTransitioningBetweenLockscreenStates ||
+ isTransitioningBetweenDesiredScenes ||
+ terminalStepBelongsToPreviousTransition
+ }
+ }
+
+ private fun SceneKey?.isLockscreenOrNull() = this == Scenes.Lockscreen || this == null
+
+ /**
+ * This function will return a flow that simulates TransitionSteps based on STL movements
+ * filtered by [edge].
+ *
+ * STL transitions outside of Lockscreen Transitions are not tracked in KTI. This is an issue
+ * for wildcard edges, as this means that Scenes.Bouncer -> Scenes.Gone would not appear while
+ * AOD -> Scenes.Bouncer would appear.
+ *
+ * This function will track STL transitions only when a wildcard edge is provided and emit a
+ * RUNNING step for each update to [Transition.progress]. It will also emit a STARTED and
+ * FINISHED step when the transitions starts and finishes.
+ *
+ * All TransitionSteps will have UNDEFINED as to and from state even when one of them is the
+ * Lockscreen Scene. It indicates that both are scenes but it should not be relevant to
+ * consumers of the [transition] API as usually all viewModels are just interested in the
+ * progress value. The correct filtering based on the provided [edge] is always the
+ * responsibility of KTI and therefore only proper [TransitionStep]s are emitted. The filter is
+ * applied within this function.
+ */
+ private fun simulateTransitionStepsForSceneTransitions(edge: Edge) =
+ sceneInteractor.transitionState.flatMapLatestWithFinished {
+ when (it) {
+ is ObservableTransitionState.Idle -> {
+ flowOf()
+ }
+ is ObservableTransitionState.Transition -> {
+ val isMatchingTransition =
+ when (edge) {
+ is Edge.StateToState ->
+ throw IllegalStateException("Should not be reachable.")
+ is Edge.SceneToState -> it.isTransitioning(from = edge.from)
+ is Edge.StateToScene -> it.isTransitioning(to = edge.to)
+ }
+ if (!isMatchingTransition) {
+ return@flatMapLatestWithFinished flowOf()
}
-
- val toScene =
- when (edge) {
- is Edge.StateToState -> edge.to?.mapToSceneContainerScene()
- is Edge.StateToScene -> edge.to
- is Edge.SceneToState -> edge.to?.mapToSceneContainerScene()
+ flow {
+ emit(
+ TransitionStep(
+ from = UNDEFINED,
+ to = UNDEFINED,
+ value = 0f,
+ transitionState = TransitionState.STARTED,
+ )
+ )
+ emitAll(
+ it.progress.map { progress ->
+ TransitionStep(
+ from = UNDEFINED,
+ to = UNDEFINED,
+ value = progress,
+ transitionState = TransitionState.RUNNING,
+ )
+ }
+ )
}
-
- fun SceneKey?.isLockscreenOrNull() = this == Scenes.Lockscreen || this == null
-
- val isTransitioningBetweenLockscreenStates =
- fromScene.isLockscreenOrNull() && toScene.isLockscreenOrNull()
- val isTransitioningBetweenDesiredScenes =
- sceneInteractor.transitionState.value.isTransitioning(fromScene, toScene)
-
- // We can't compare the terminal step with the current sceneTransition because
- // a) STL has no guarantee that it will settle in Idle() when finished/canceled
- // b) Comparing to Idle(toScene) would make any other FINISHED step settling in
- // toScene pass as well
- val terminalStepBelongsToPreviousTransition =
- (step.transitionState == TransitionState.FINISHED ||
- step.transitionState == TransitionState.CANCELED) &&
- sceneTransitionPair.value.previousValue.isTransitioning(fromScene, toScene)
-
- return@filter isTransitioningBetweenLockscreenStates ||
- isTransitioningBetweenDesiredScenes ||
- terminalStepBelongsToPreviousTransition
+ }
}
- } else {
- flow
+ }
+
+ /**
+ * This function is similar to flatMapLatest but it will additionally emit a FINISHED
+ * TransitionStep whenever the flattened innerFlow emitted a STARTED step and is now being
+ * replaced by a new innerFlow.
+ *
+ * This is to make sure that every STARTED step will receive a corresponding FINISHED step.
+ *
+ * We can't simply write this into a flow {} block because Transition.progress doesn't complete.
+ * We also can't emit the FINISHED step simply when an Idle state is reached because a)
+ * Transitions are not guaranteed to finish in Idle and b) There can be multiple Idle
+ * transitions after another
+ */
+ private fun <T> Flow<T>.flatMapLatestWithFinished(
+ transform: suspend (T) -> Flow<TransitionStep>
+ ): Flow<TransitionStep> = channelFlow {
+ var job: Job? = null
+ var startedEmitted = false
+
+ coroutineScope {
+ collect { value ->
+ job?.cancelAndJoin()
+
+ job = launch {
+ val innerFlow = transform(value)
+ try {
+ innerFlow.collect { step ->
+ if (step.transitionState == TransitionState.STARTED) {
+ startedEmitted = true
+ }
+ send(step)
+ }
+ } finally {
+ if (startedEmitted) {
+ send(
+ TransitionStep(
+ from = UNDEFINED,
+ to = UNDEFINED,
+ value = 1f,
+ transitionState = TransitionState.FINISHED,
+ )
+ )
+ startedEmitted = false
+ }
+ }
+ }
+ }
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTileIcon.kt b/packages/SystemUI/src/com/android/systemui/qs/QSTileIcon.kt
index ef7e7eb..62694ce 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSTileIcon.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSTileIcon.kt
@@ -22,13 +22,18 @@
/**
* Creates a [QSTile.Icon] from an [Icon].
- * * [Icon.Loaded] -> [QSTileImpl.DrawableIcon]
+ * * [Icon.Loaded] && [resId] null -> [QSTileImpl.DrawableIcon]
+ * * [Icon.Loaded] && [resId] available -> [QSTileImpl.DrawableIconWithRes]
* * [Icon.Resource] -> [QSTileImpl.ResourceIcon]
*/
-fun Icon.asQSTileIcon(): QSTile.Icon {
+fun Icon.asQSTileIcon(resId: Int?): QSTile.Icon {
return when (this) {
is Icon.Loaded -> {
- QSTileImpl.DrawableIcon(this.drawable)
+ if (resId != null) {
+ QSTileImpl.DrawableIconWithRes(this.drawable, resId)
+ } else {
+ QSTileImpl.DrawableIcon(this.drawable)
+ }
}
is Icon.Resource -> {
QSTileImpl.ResourceIcon.get(this.res)
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/ModesTile.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/ModesTile.kt
index cf2db6c..3bbe624 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/ModesTile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/ModesTile.kt
@@ -121,7 +121,7 @@
state?.apply {
this.state = tileState.activationState.legacyState
val tileStateIcon = tileState.icon()
- icon = tileStateIcon?.asQSTileIcon() ?: ResourceIcon.get(ICON_RES_ID)
+ icon = tileStateIcon?.asQSTileIcon(tileState.iconRes) ?: ResourceIcon.get(ICON_RES_ID)
label = tileLabel
secondaryLabel = tileState.secondaryLabel
contentDescription = tileState.contentDescription
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractor.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractor.kt
index 5d44ead..40591bf 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/interactor/ModesTileDataInteractor.kt
@@ -76,14 +76,14 @@
} else {
return ModesTileModel(
isActivated = activeModes.isAnyActive(),
- icon = context.getDrawable(ModesTile.ICON_RES_ID)!!.asIcon(),
+ icon = Icon.Resource(ModesTile.ICON_RES_ID, null),
iconResId = ModesTile.ICON_RES_ID,
activeModes = activeModes.modeNames,
)
}
}
- private data class TileIcon(val icon: Icon.Loaded, val resId: Int?)
+ private data class TileIcon(val icon: Icon, val resId: Int?)
private fun getTileIcon(activeMode: ZenModeInfo?): TileIcon {
return if (activeMode != null) {
@@ -94,7 +94,7 @@
TileIcon(activeMode.icon.drawable.asIcon(), null)
}
} else {
- TileIcon(context.getDrawable(ModesTile.ICON_RES_ID)!!.asIcon(), ModesTile.ICON_RES_ID)
+ TileIcon(Icon.Resource(ModesTile.ICON_RES_ID, null), ModesTile.ICON_RES_ID)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/model/ModesTileModel.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/model/ModesTileModel.kt
index db48123..9c31e32 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/model/ModesTileModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/domain/model/ModesTileModel.kt
@@ -21,12 +21,12 @@
data class ModesTileModel(
val isActivated: Boolean,
val activeModes: List<String>,
- val icon: Icon.Loaded,
+ val icon: Icon,
/**
* Resource id corresponding to [icon]. Will only be present if it's know to correspond to a
* resource with a known id in SystemUI (such as resources from `android.R`,
* `com.android.internal.R`, or `com.android.systemui.res` itself).
*/
- val iconResId: Int? = null
+ val iconResId: Int? = null,
)
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/ui/ModesTileMapper.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/ui/ModesTileMapper.kt
index 69da313..801a0ce 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/ui/ModesTileMapper.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/modes/ui/ModesTileMapper.kt
@@ -18,7 +18,9 @@
import android.content.res.Resources
import android.icu.text.MessageFormat
+import android.util.Log
import android.widget.Button
+import com.android.systemui.common.shared.model.Icon
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.qs.tiles.base.interactor.QSTileDataToStateMapper
import com.android.systemui.qs.tiles.impl.modes.domain.model.ModesTileModel
@@ -30,14 +32,30 @@
class ModesTileMapper
@Inject
-constructor(
- @Main private val resources: Resources,
- val theme: Resources.Theme,
-) : QSTileDataToStateMapper<ModesTileModel> {
+constructor(@Main private val resources: Resources, val theme: Resources.Theme) :
+ QSTileDataToStateMapper<ModesTileModel> {
override fun map(config: QSTileConfig, data: ModesTileModel): QSTileState =
QSTileState.build(resources, theme, config.uiConfig) {
- iconRes = data.iconResId
- icon = { data.icon }
+ val loadedIcon: Icon.Loaded =
+ when (val dataIcon = data.icon) {
+ is Icon.Resource -> {
+ if (iconRes != dataIcon.res) {
+ Log.wtf(
+ "ModesTileMapper",
+ "Icon.Resource.res & iconResId are not identical",
+ )
+ }
+ iconRes = dataIcon.res
+ Icon.Loaded(resources.getDrawable(dataIcon.res, theme), null)
+ }
+ is Icon.Loaded -> {
+ iconRes = data.iconResId
+ dataIcon
+ }
+ }
+
+ icon = { loadedIcon }
+
activationState =
if (data.isActivated) {
QSTileState.ActivationState.ACTIVE
@@ -47,10 +65,7 @@
secondaryLabel = getModesStatus(data, resources)
contentDescription = "$label. $secondaryLabel"
supportedActions =
- setOf(
- QSTileState.UserAction.CLICK,
- QSTileState.UserAction.LONG_CLICK,
- )
+ setOf(QSTileState.UserAction.CLICK, QSTileState.UserAction.LONG_CLICK)
sideViewIcon = QSTileState.SideViewIcon.Chevron
expandedAccessibilityClass = Button::class
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/satellite/data/prod/DeviceBasedSatelliteRepositoryImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/satellite/data/prod/DeviceBasedSatelliteRepositoryImpl.kt
index 03ec41d..470abe6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/satellite/data/prod/DeviceBasedSatelliteRepositoryImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/pipeline/satellite/data/prod/DeviceBasedSatelliteRepositoryImpl.kt
@@ -182,7 +182,7 @@
.stateIn(
scope,
SharingStarted.WhileSubscribed(),
- TelephonyManager.RADIO_POWER_UNAVAILABLE
+ TelephonyManager.RADIO_POWER_UNAVAILABLE,
)
/**
@@ -265,9 +265,10 @@
var registered = false
try {
+ logBuffer.i { "registerForCommunicationAllowedStateChanged" }
sm.registerForCommunicationAllowedStateChanged(
bgDispatcher.asExecutor(),
- callback
+ callback,
)
registered = true
} catch (e: Exception) {
@@ -276,6 +277,7 @@
awaitClose {
if (registered) {
+ logBuffer.i { "unRegisterForCommunicationAllowedStateChanged" }
sm.unregisterForCommunicationAllowedStateChanged(callback)
}
}
@@ -321,9 +323,10 @@
var registered = false
try {
+ logBuffer.i { "registerForSupportedStateChanged" }
satelliteManager.registerForSupportedStateChanged(
bgDispatcher.asExecutor(),
- callback
+ callback,
)
registered = true
} catch (e: Exception) {
@@ -332,6 +335,7 @@
awaitClose {
if (registered) {
+ logBuffer.i { "unregisterForSupportedStateChanged" }
satelliteManager.unregisterForSupportedStateChanged(callback)
}
}
@@ -366,10 +370,7 @@
var registered = false
try {
logBuffer.i { "registerForProvisionStateChanged" }
- sm.registerForProvisionStateChanged(
- bgDispatcher.asExecutor(),
- callback,
- )
+ sm.registerForProvisionStateChanged(bgDispatcher.asExecutor(), callback)
registered = true
} catch (e: Exception) {
logBuffer.e("error registering for provisioning state callback", e)
@@ -377,6 +378,7 @@
awaitClose {
if (registered) {
+ logBuffer.i { "unregisterForProvisionStateChanged" }
sm.unregisterForProvisionStateChanged(callback)
}
}
@@ -526,17 +528,10 @@
uptime - (clock.uptimeMillis() - android.os.Process.getStartUptimeMillis())
/** A couple of convenience logging methods rather than a whole class */
- private fun LogBuffer.i(
- initializer: MessageInitializer = {},
- printer: MessagePrinter,
- ) = this.log(TAG, LogLevel.INFO, initializer, printer)
+ private fun LogBuffer.i(initializer: MessageInitializer = {}, printer: MessagePrinter) =
+ this.log(TAG, LogLevel.INFO, initializer, printer)
private fun LogBuffer.e(message: String, exception: Throwable? = null) =
- this.log(
- tag = TAG,
- level = LogLevel.ERROR,
- message = message,
- exception = exception,
- )
+ this.log(tag = TAG, level = LogLevel.ERROR, message = message, exception = exception)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/BackGestureTutorialScreen.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/BackGestureTutorialScreen.kt
index 411ff8b..bfc5429 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/BackGestureTutorialScreen.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/BackGestureTutorialScreen.kt
@@ -16,6 +16,7 @@
package com.android.systemui.touchpad.tutorial.ui.composable
+import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.airbnb.lottie.compose.rememberLottieDynamicProperties
@@ -57,7 +58,7 @@
@Composable
private fun rememberScreenColors(): TutorialScreenConfig.Colors {
- val onTertiary = LocalAndroidColorScheme.current.onTertiary
+ val onTertiary = MaterialTheme.colorScheme.onTertiary
val onTertiaryFixed = LocalAndroidColorScheme.current.onTertiaryFixed
val onTertiaryFixedVariant = LocalAndroidColorScheme.current.onTertiaryFixedVariant
val tertiaryFixedDim = LocalAndroidColorScheme.current.tertiaryFixedDim
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureMonitor.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureMonitor.kt
index 084da2c..ecb5574 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureMonitor.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureMonitor.kt
@@ -16,26 +16,24 @@
package com.android.systemui.touchpad.tutorial.ui.gesture
+import android.view.MotionEvent
import kotlin.math.abs
/** Monitors for touchpad back gesture, that is three fingers swiping left or right */
class BackGestureMonitor(
- override val gestureDistanceThresholdPx: Int,
- override val gestureStateChangedCallback: (GestureState) -> Unit
-) :
- TouchpadGestureMonitor by ThreeFingerDistanceBasedGestureMonitor(
- gestureDistanceThresholdPx = gestureDistanceThresholdPx,
- gestureStateChangedCallback = gestureStateChangedCallback,
- donePredicate =
- object : GestureDonePredicate {
- override fun wasGestureDone(
- startX: Float,
- startY: Float,
- endX: Float,
- endY: Float
- ): Boolean {
- val distance = abs(endX - startX)
- return distance >= gestureDistanceThresholdPx
- }
- }
- )
+ private val gestureDistanceThresholdPx: Int,
+ override val gestureStateChangedCallback: (GestureState) -> Unit,
+) : TouchpadGestureMonitor {
+ private val distanceTracker = DistanceTracker()
+
+ override fun processTouchpadEvent(event: MotionEvent) {
+ if (!isThreeFingerTouchpadSwipe(event)) return
+ val distanceState = distanceTracker.processEvent(event)
+ updateGestureStateBasedOnDistance(
+ gestureStateChangedCallback,
+ distanceState,
+ isFinished = { abs(it.deltaX) >= gestureDistanceThresholdPx },
+ progress = { 0f },
+ )
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/DistanceTracker.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/DistanceTracker.kt
new file mode 100644
index 0000000..70d9366
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/DistanceTracker.kt
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2024 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.systemui.touchpad.tutorial.ui.gesture
+
+import android.view.MotionEvent
+
+/**
+ * Tracks distance change for processed MotionEvents. Useful for recognizing gestures based on
+ * distance travelled instead of specific position on the screen.
+ */
+class DistanceTracker(var startX: Float = 0f, var startY: Float = 0f) {
+ fun processEvent(event: MotionEvent): DistanceGestureState? {
+ val action = event.actionMasked
+ return when (action) {
+ MotionEvent.ACTION_DOWN -> {
+ startX = event.x
+ startY = event.y
+ Started(event.x, event.y)
+ }
+ MotionEvent.ACTION_MOVE -> Moving(event.x - startX, event.y - startY)
+ MotionEvent.ACTION_UP -> Finished(event.x - startX, event.y - startY)
+ else -> null
+ }
+ }
+}
+
+sealed interface DistanceGestureState
+
+class Started(val deltaX: Float, val deltaY: Float) : DistanceGestureState
+
+class Moving(val deltaX: Float, val deltaY: Float) : DistanceGestureState
+
+class Finished(val deltaX: Float, val deltaY: Float) : DistanceGestureState
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureStateUpdates.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureStateUpdates.kt
new file mode 100644
index 0000000..c1caeb3
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureStateUpdates.kt
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2024 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.systemui.touchpad.tutorial.ui.gesture
+
+/**
+ * Helper function for gesture recognizers to have common state triggering logic based on distance
+ * only.
+ */
+inline fun updateGestureStateBasedOnDistance(
+ gestureStateChangedCallback: (GestureState) -> Unit,
+ gestureState: DistanceGestureState?,
+ isFinished: (Finished) -> Boolean,
+ progress: (Moving) -> Float,
+) {
+ when (gestureState) {
+ is Finished -> {
+ if (isFinished(gestureState)) {
+ gestureStateChangedCallback(GestureState.Finished)
+ } else {
+ gestureStateChangedCallback(GestureState.NotStarted)
+ }
+ }
+ is Moving -> {
+ gestureStateChangedCallback(GestureState.InProgress(progress(gestureState)))
+ }
+ is Started -> gestureStateChangedCallback(GestureState.InProgress())
+ else -> {}
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureMonitor.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureMonitor.kt
index a9aa5c8..fdcf9de 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureMonitor.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureMonitor.kt
@@ -16,24 +16,23 @@
package com.android.systemui.touchpad.tutorial.ui.gesture
+import android.view.MotionEvent
+
/** Monitors for touchpad home gesture, that is three fingers swiping up */
class HomeGestureMonitor(
- override val gestureDistanceThresholdPx: Int,
- override val gestureStateChangedCallback: (GestureState) -> Unit
-) :
- TouchpadGestureMonitor by ThreeFingerDistanceBasedGestureMonitor(
- gestureDistanceThresholdPx = gestureDistanceThresholdPx,
- gestureStateChangedCallback = gestureStateChangedCallback,
- donePredicate =
- object : GestureDonePredicate {
- override fun wasGestureDone(
- startX: Float,
- startY: Float,
- endX: Float,
- endY: Float
- ): Boolean {
- val distance = startY - endY
- return distance >= gestureDistanceThresholdPx
- }
- }
- )
+ private val gestureDistanceThresholdPx: Int,
+ override val gestureStateChangedCallback: (GestureState) -> Unit,
+) : TouchpadGestureMonitor {
+ private val distanceTracker = DistanceTracker()
+
+ override fun processTouchpadEvent(event: MotionEvent) {
+ if (!isThreeFingerTouchpadSwipe(event)) return
+ val distanceState = distanceTracker.processEvent(event)
+ updateGestureStateBasedOnDistance(
+ gestureStateChangedCallback,
+ distanceState,
+ isFinished = { -it.deltaY >= gestureDistanceThresholdPx },
+ progress = { 0f },
+ )
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureMonitor.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureMonitor.kt
index ca3880a..dd31ce3 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureMonitor.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureMonitor.kt
@@ -26,7 +26,7 @@
* is based on [com.android.quickstep.util.TriggerSwipeUpTouchTracker]
*/
class RecentAppsGestureMonitor(
- override val gestureDistanceThresholdPx: Int,
+ private val gestureDistanceThresholdPx: Int,
override val gestureStateChangedCallback: (GestureState) -> Unit,
private val velocityThresholdPxPerMs: Float,
private val velocityTracker: VelocityTracker1D = VelocityTracker1D(isDataDifferential = false),
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/ThreeFingerDistanceBasedGestureMonitor.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/ThreeFingerDistanceBasedGestureMonitor.kt
deleted file mode 100644
index 12bcaea..0000000
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/ThreeFingerDistanceBasedGestureMonitor.kt
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2024 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.systemui.touchpad.tutorial.ui.gesture
-
-import android.view.MotionEvent
-
-interface GestureDonePredicate {
- /**
- * Should return if gesture was finished. The only events this predicate receives are ACTION_UP.
- */
- fun wasGestureDone(startX: Float, startY: Float, endX: Float, endY: Float): Boolean
-}
-
-/**
- * Common implementation for three-finger gesture monitors that are only distance-based. E.g. recent
- * apps gesture is not only distance-based because it requires going over threshold distance and
- * slowing down the movement.
- */
-class ThreeFingerDistanceBasedGestureMonitor(
- override val gestureDistanceThresholdPx: Int,
- override val gestureStateChangedCallback: (GestureState) -> Unit,
- private val donePredicate: GestureDonePredicate
-) : TouchpadGestureMonitor {
-
- private var xStart = 0f
- private var yStart = 0f
-
- override fun processTouchpadEvent(event: MotionEvent) {
- val action = event.actionMasked
- when (action) {
- MotionEvent.ACTION_DOWN -> {
- if (isThreeFingerTouchpadSwipe(event)) {
- xStart = event.x
- yStart = event.y
- gestureStateChangedCallback(GestureState.InProgress())
- }
- }
- MotionEvent.ACTION_UP -> {
- if (isThreeFingerTouchpadSwipe(event)) {
- if (donePredicate.wasGestureDone(xStart, yStart, event.x, event.y)) {
- gestureStateChangedCallback(GestureState.Finished)
- } else {
- gestureStateChangedCallback(GestureState.NotStarted)
- }
- }
- }
- }
- }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/TouchpadGestureMonitor.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/TouchpadGestureMonitor.kt
index 8774a92..4655c98 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/TouchpadGestureMonitor.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/TouchpadGestureMonitor.kt
@@ -23,8 +23,6 @@
* changes. All tracked motion events should be passed to [processTouchpadEvent]
*/
interface TouchpadGestureMonitor {
-
- val gestureDistanceThresholdPx: Int
val gestureStateChangedCallback: (GestureState) -> Unit
fun processTouchpadEvent(event: MotionEvent)
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractor.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractor.kt
index f94cbda..609ba02 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractor.kt
@@ -16,7 +16,10 @@
package com.android.systemui.volume.panel.component.mediaoutput.domain.interactor
+import com.android.settingslib.media.PhoneMediaDevice.inputRoutingEnabledAndIsDesktop
+import android.content.Context
import com.android.settingslib.volume.domain.interactor.AudioModeInteractor
+import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.volume.domain.interactor.AudioOutputInteractor
import com.android.systemui.volume.domain.interactor.AudioSharingInteractor
import com.android.systemui.volume.domain.model.AudioOutputDevice
@@ -46,6 +49,7 @@
class MediaOutputComponentInteractor
@Inject
constructor(
+ @Application private val context: Context,
@VolumePanelScope private val coroutineScope: CoroutineScope,
private val mediaDeviceSessionInteractor: MediaDeviceSessionInteractor,
audioOutputInteractor: AudioOutputInteractor,
@@ -91,7 +95,8 @@
MediaOutputComponentModel.Calling(
device = currentAudioDevice,
isInAudioSharing = isInAudioSharing,
- canOpenAudioSwitcher = false,
+ /* allow open switcher when input routing is enabled in desktop */
+ canOpenAudioSwitcher = inputRoutingEnabledAndIsDesktop(context),
)
)
} else {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuControllerTest.java
index 5e37d4c..51a7b5f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/floatingmenu/AccessibilityFloatingMenuControllerTest.java
@@ -338,6 +338,25 @@
assertThat(mController.mFloatingMenu).isInstanceOf(MenuViewLayerController.class);
}
+ @Test
+ public void onUserInitializationComplete_destroysOldWidget() {
+ enableAccessibilityFloatingMenuConfig();
+ mController = setUpController();
+
+ captureKeyguardUpdateMonitorCallback();
+ mKeyguardCallback.onUserUnlocked();
+ mKeyguardCallback.onKeyguardVisibilityChanged(false);
+
+ IAccessibilityFloatingMenu floatingMenu = mController.mFloatingMenu;
+
+ mController.mUserInitializationCompleteCallback
+ .onUserInitializationComplete(mContext.getUserId());
+ mTestableLooper.processAllMessages();
+
+ assertThat(mController.mFloatingMenu).isNotNull();
+ assertThat(mController.mFloatingMenu).isNotSameInstanceAs(floatingMenu);
+ }
+
private AccessibilityFloatingMenuController setUpController() {
final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
final ViewCaptureAwareWindowManager viewCaptureAwareWindowManager =
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
index 6608542..b3cccea 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java
@@ -26,6 +26,7 @@
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT;
import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
import static com.android.systemui.Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR;
+import static com.android.systemui.Flags.FLAG_RELOCK_WITH_POWER_BUTTON_IMMEDIATELY;
import static com.android.systemui.Flags.FLAG_SIM_PIN_BOUNCER_RESET;
import static com.android.systemui.keyguard.KeyguardViewMediator.DELAYED_KEYGUARD_ACTION;
import static com.android.systemui.keyguard.KeyguardViewMediator.KEYGUARD_LOCK_AFTER_DELAY_DEFAULT;
@@ -63,6 +64,7 @@
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.RemoteException;
+import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.telephony.TelephonyManager;
import android.testing.AndroidTestingRunner;
@@ -841,6 +843,32 @@
@Test
@TestableLooper.RunWithLooper(setAsMainLooper = true)
+ @EnableFlags(FLAG_RELOCK_WITH_POWER_BUTTON_IMMEDIATELY)
+ public void testCancelKeyguardExitAnimationDueToSleep_withPendingLockAndRelockFlag_keyguardWillBeShowing() {
+ startMockKeyguardExitAnimation();
+
+ mViewMediator.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON);
+ mViewMediator.onFinishedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, false);
+
+ cancelMockKeyguardExitAnimation();
+
+ mViewMediator.maybeHandlePendingLock();
+ TestableLooper.get(this).processAllMessages();
+
+ assertTrue(mViewMediator.isShowingAndNotOccluded());
+
+ verify(mKeyguardUnlockAnimationController).notifyFinishedKeyguardExitAnimation(true);
+
+ // Unlock animators call `exitKeyguardAndFinishSurfaceBehindRemoteAnimation` when canceled
+ mViewMediator.exitKeyguardAndFinishSurfaceBehindRemoteAnimation(false);
+ TestableLooper.get(this).processAllMessages();
+
+ verify(mUpdateMonitor, never()).dispatchKeyguardDismissAnimationFinished();
+ }
+
+ @Test
+ @TestableLooper.RunWithLooper(setAsMainLooper = true)
+ @DisableFlags(FLAG_RELOCK_WITH_POWER_BUTTON_IMMEDIATELY)
public void testCancelKeyguardExitAnimationDueToSleep_withPendingLock_keyguardWillBeShowing() {
startMockKeyguardExitAnimation();
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorKosmos.kt
index 99cd830..68d08e2 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorKosmos.kt
@@ -16,7 +16,7 @@
package com.android.systemui.statusbar.policy.domain.interactor
-import android.content.testableContext
+import android.content.applicationContext
import com.android.settingslib.notification.modes.zenIconLoader
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
@@ -28,7 +28,7 @@
val Kosmos.zenModeInteractor by Fixture {
ZenModeInteractor(
- context = testableContext,
+ context = applicationContext,
zenModeRepository = zenModeRepository,
notificationSettingsRepository = notificationSettingsRepository,
bgDispatcher = testDispatcher,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorKosmos.kt
index 63a1325..db66c3e 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorKosmos.kt
@@ -16,6 +16,7 @@
package com.android.systemui.volume.panel.component.mediaoutput.domain.interactor
+import android.content.mockedContext
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.volume.domain.interactor.audioModeInteractor
@@ -27,6 +28,7 @@
val Kosmos.mediaOutputComponentInteractor by
Kosmos.Fixture {
MediaOutputComponentInteractor(
+ mockedContext,
testScope.backgroundScope,
mediaDeviceSessionInteractor,
audioOutputInteractor,
diff --git a/ravenwood/Android.bp b/ravenwood/Android.bp
index 11b66fc..9629a87 100644
--- a/ravenwood/Android.bp
+++ b/ravenwood/Android.bp
@@ -154,6 +154,8 @@
"framework-annotations-lib",
"ravenwood-helper-framework-runtime",
"ravenwood-helper-libcore-runtime",
+ "hoststubgen-helper-runtime.ravenwood",
+ "mockito-ravenwood-prebuilt",
],
visibility: ["//frameworks/base"],
jarjar_rules: ":ravenwood-services-jarjar-rules",
diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
index 644babb..908e590 100644
--- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
+++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
@@ -22,10 +22,14 @@
import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERSION_JAVA_SYSPROP;
import static org.junit.Assert.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
import android.app.ActivityManager;
import android.app.Instrumentation;
import android.app.ResourcesManager;
+import android.app.UiAutomation;
import android.content.res.Resources;
import android.os.Binder;
import android.os.Build;
@@ -40,6 +44,7 @@
import androidx.test.platform.app.InstrumentationRegistry;
+import com.android.hoststubgen.hosthelper.HostTestUtils;
import com.android.internal.os.RuntimeInit;
import com.android.ravenwood.RavenwoodRuntimeNative;
import com.android.ravenwood.common.RavenwoodCommonUtils;
@@ -52,8 +57,10 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import java.util.Collections;
import java.util.Map;
import java.util.Objects;
+import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
@@ -125,6 +132,9 @@
private static RavenwoodConfig sConfig;
private static RavenwoodSystemProperties sProps;
+ // TODO: use the real UiAutomation class instead of a mock
+ private static UiAutomation sMockUiAutomation;
+ private static Set<String> sAdoptedPermissions = Collections.emptySet();
private static boolean sInitialized = false;
/**
@@ -171,6 +181,7 @@
"androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner");
assertMockitoVersion();
+ sMockUiAutomation = createMockUiAutomation();
}
/**
@@ -261,7 +272,7 @@
// Prepare other fields.
config.mInstrumentation = new Instrumentation();
- config.mInstrumentation.basicInit(config.mInstContext, config.mTargetContext);
+ config.mInstrumentation.basicInit(instContext, targetContext, sMockUiAutomation);
InstrumentationRegistry.registerInstance(config.mInstrumentation, Bundle.EMPTY);
RavenwoodSystemServer.init(config);
@@ -300,12 +311,13 @@
config.mInstrumentation = null;
if (config.mInstContext != null) {
((RavenwoodContext) config.mInstContext).cleanUp();
+ config.mInstContext = null;
}
if (config.mTargetContext != null) {
((RavenwoodContext) config.mTargetContext).cleanUp();
+ config.mTargetContext = null;
}
- config.mInstContext = null;
- config.mTargetContext = null;
+ sMockUiAutomation.dropShellPermissionIdentity();
if (config.mProvideMainThread) {
Looper.getMainLooper().quit();
@@ -403,6 +415,31 @@
() -> Class.forName("org.mockito.Matchers"));
}
+ private static UiAutomation createMockUiAutomation() {
+ var mock = mock(UiAutomation.class, inv -> {
+ HostTestUtils.onThrowMethodCalled();
+ return null;
+ });
+ doAnswer(inv -> {
+ sAdoptedPermissions = UiAutomation.ALL_PERMISSIONS;
+ return null;
+ }).when(mock).adoptShellPermissionIdentity();
+ doAnswer(inv -> {
+ if (inv.getArgument(0) == null) {
+ sAdoptedPermissions = UiAutomation.ALL_PERMISSIONS;
+ } else {
+ sAdoptedPermissions = (Set) Set.of(inv.getArguments());
+ }
+ return null;
+ }).when(mock).adoptShellPermissionIdentity(any());
+ doAnswer(inv -> {
+ sAdoptedPermissions = Collections.emptySet();
+ return null;
+ }).when(mock).dropShellPermissionIdentity();
+ doAnswer(inv -> sAdoptedPermissions).when(mock).getAdoptedShellPermissions();
+ return mock;
+ }
+
@SuppressWarnings("unused") // Called from native code (ravenwood_sysprop.cpp)
private static void checkSystemPropertyAccess(String key, boolean write) {
boolean result = write ? sProps.isKeyWritable(key) : sProps.isKeyReadable(key);
diff --git a/ravenwood/tests/bivalenttest/test/com/android/ravenwoodtest/bivalenttest/RavenwoodUiAutomationTest.java b/ravenwood/tests/bivalenttest/test/com/android/ravenwoodtest/bivalenttest/RavenwoodUiAutomationTest.java
new file mode 100644
index 0000000..eb94827
--- /dev/null
+++ b/ravenwood/tests/bivalenttest/test/com/android/ravenwoodtest/bivalenttest/RavenwoodUiAutomationTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2024 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.ravenwoodtest.bivalenttest;
+
+import static android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG;
+import static android.Manifest.permission.READ_COMPAT_CHANGE_CONFIG;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import android.app.Instrumentation;
+import android.app.UiAutomation;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.ravenwood.common.RavenwoodCommonUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Set;
+
+@RunWith(AndroidJUnit4.class)
+public class RavenwoodUiAutomationTest {
+
+ private Instrumentation mInstrumentation;
+
+ @Before
+ public void setup() {
+ mInstrumentation = InstrumentationRegistry.getInstrumentation();
+ }
+
+ @Test
+ public void testGetUiAutomation() {
+ assertNotNull(mInstrumentation.getUiAutomation());
+ }
+
+ @Test
+ public void testGetUiAutomationWithFlags() {
+ assertNotNull(mInstrumentation.getUiAutomation(UiAutomation.FLAG_DONT_USE_ACCESSIBILITY));
+ }
+
+ @Test
+ public void testShellPermissionApis() {
+ var uiAutomation = mInstrumentation.getUiAutomation();
+ assertTrue(uiAutomation.getAdoptedShellPermissions().isEmpty());
+ uiAutomation.adoptShellPermissionIdentity();
+ assertEquals(uiAutomation.getAdoptedShellPermissions(), UiAutomation.ALL_PERMISSIONS);
+ uiAutomation.adoptShellPermissionIdentity((String[]) null);
+ assertEquals(uiAutomation.getAdoptedShellPermissions(), UiAutomation.ALL_PERMISSIONS);
+ uiAutomation.adoptShellPermissionIdentity(
+ OVERRIDE_COMPAT_CHANGE_CONFIG, READ_COMPAT_CHANGE_CONFIG);
+ assertEquals(uiAutomation.getAdoptedShellPermissions(),
+ Set.of(OVERRIDE_COMPAT_CHANGE_CONFIG, READ_COMPAT_CHANGE_CONFIG));
+ uiAutomation.dropShellPermissionIdentity();
+ assertTrue(uiAutomation.getAdoptedShellPermissions().isEmpty());
+ }
+
+ @Test
+ public void testUnsupportedMethod() {
+ // Only unsupported on Ravenwood
+ assumeTrue(RavenwoodCommonUtils.isOnRavenwood());
+ assertThrows(RuntimeException.class,
+ () -> mInstrumentation.getUiAutomation().executeShellCommand("echo ok"));
+ }
+}
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index d595d02..1451dfa 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -3653,6 +3653,12 @@
return;
}
+ // Magnification connection should not be requested for visible background users.
+ // (b/332222893)
+ if (mUmi.isVisibleBackgroundFullUser(userState.mUserId)) {
+ return;
+ }
+
final boolean shortcutEnabled = (userState.isShortcutMagnificationEnabledLocked()
|| userState.isMagnificationSingleFingerTripleTapEnabledLocked()
|| (Flags.enableMagnificationMultipleFingerMultipleTapGesture()
diff --git a/services/accessibility/java/com/android/server/accessibility/MouseKeysInterceptor.java b/services/accessibility/java/com/android/server/accessibility/MouseKeysInterceptor.java
index 4b97745..1df5d1a 100644
--- a/services/accessibility/java/com/android/server/accessibility/MouseKeysInterceptor.java
+++ b/services/accessibility/java/com/android/server/accessibility/MouseKeysInterceptor.java
@@ -138,8 +138,8 @@
DIAGONAL_UP_LEFT_MOVE(KeyEvent.KEYCODE_7),
UP_MOVE_OR_SCROLL(KeyEvent.KEYCODE_8),
DIAGONAL_UP_RIGHT_MOVE(KeyEvent.KEYCODE_9),
- LEFT_MOVE(KeyEvent.KEYCODE_U),
- RIGHT_MOVE(KeyEvent.KEYCODE_O),
+ LEFT_MOVE_OR_SCROLL(KeyEvent.KEYCODE_U),
+ RIGHT_MOVE_OR_SCROLL(KeyEvent.KEYCODE_O),
DIAGONAL_DOWN_LEFT_MOVE(KeyEvent.KEYCODE_J),
DOWN_MOVE_OR_SCROLL(KeyEvent.KEYCODE_K),
DIAGONAL_DOWN_RIGHT_MOVE(KeyEvent.KEYCODE_L),
@@ -267,6 +267,16 @@
);
}
+ @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
+ private void sendVirtualMouseScrollEvent(float x, float y) {
+ waitForVirtualMouseCreation();
+ mVirtualMouse.sendScrollEvent(new VirtualMouseScrollEvent.Builder()
+ .setXAxisMovement(x)
+ .setYAxisMovement(y)
+ .build()
+ );
+ }
+
/**
* Performs a mouse scroll action based on the provided key code.
* The scroll action will only be performed if the scroll toggle is on.
@@ -284,19 +294,31 @@
private void performMouseScrollAction(int keyCode) {
MouseKeyEvent mouseKeyEvent = MouseKeyEvent.from(
keyCode, mActiveInputDeviceId, mDeviceKeyCodeMap);
- float y = switch (mouseKeyEvent) {
- case UP_MOVE_OR_SCROLL -> MOUSE_SCROLL_STEP;
- case DOWN_MOVE_OR_SCROLL -> -MOUSE_SCROLL_STEP;
- default -> 0.0f;
- };
- waitForVirtualMouseCreation();
- mVirtualMouse.sendScrollEvent(new VirtualMouseScrollEvent.Builder()
- .setYAxisMovement(y)
- .build()
- );
+ float x = 0f;
+ float y = 0f;
+
+ switch (mouseKeyEvent) {
+ case UP_MOVE_OR_SCROLL -> {
+ y = MOUSE_SCROLL_STEP;
+ }
+ case DOWN_MOVE_OR_SCROLL -> {
+ y = -MOUSE_SCROLL_STEP;
+ }
+ case LEFT_MOVE_OR_SCROLL -> {
+ x = MOUSE_SCROLL_STEP;
+ }
+ case RIGHT_MOVE_OR_SCROLL -> {
+ x = -MOUSE_SCROLL_STEP;
+ }
+ default -> {
+ x = 0.0f;
+ y = 0.0f;
+ }
+ }
+ sendVirtualMouseScrollEvent(x, y);
if (DEBUG) {
Slog.d(LOG_TAG, "Performed mouse key event: " + mouseKeyEvent.name()
- + " for scroll action with axis movement (y=" + y + ")");
+ + " for scroll action with axis movement (x=" + x + ", y=" + y + ")");
}
}
@@ -344,8 +366,8 @@
* The method calculates the relative movement of the mouse pointer
* and sends the corresponding event to the virtual mouse.
*
- * The UP and DOWN pointer actions will only take place for their respective keys
- * if the scroll toggle is off.
+ * The UP, DOWN, LEFT, RIGHT pointer actions will only take place for their
+ * respective keys if the scroll toggle is off.
*
* @param keyCode The key code representing the direction or button press.
* Supported keys are:
@@ -353,8 +375,8 @@
* <li>{@link MouseKeysInterceptor.MouseKeyEvent#DIAGONAL_DOWN_LEFT_MOVE}
* <li>{@link MouseKeysInterceptor.MouseKeyEvent#DOWN_MOVE_OR_SCROLL}
* <li>{@link MouseKeysInterceptor.MouseKeyEvent#DIAGONAL_DOWN_RIGHT_MOVE}
- * <li>{@link MouseKeysInterceptor.MouseKeyEvent#LEFT_MOVE}
- * <li>{@link MouseKeysInterceptor.MouseKeyEvent#RIGHT_MOVE}
+ * <li>{@link MouseKeysInterceptor.MouseKeyEvent#LEFT_MOVE_OR_SCROLL}
+ * <li>{@link MouseKeysInterceptor.MouseKeyEvent#RIGHT_MOVE_OR_SCROLL}
* <li>{@link MouseKeysInterceptor.MouseKeyEvent#DIAGONAL_UP_LEFT_MOVE}
* <li>{@link MouseKeysInterceptor.MouseKeyEvent#UP_MOVE_OR_SCROLL}
* <li>{@link MouseKeysInterceptor.MouseKeyEvent#DIAGONAL_UP_RIGHT_MOVE}
@@ -381,10 +403,10 @@
x = MOUSE_POINTER_MOVEMENT_STEP / sqrt(2);
y = MOUSE_POINTER_MOVEMENT_STEP / sqrt(2);
}
- case LEFT_MOVE -> {
+ case LEFT_MOVE_OR_SCROLL -> {
x = -MOUSE_POINTER_MOVEMENT_STEP;
}
- case RIGHT_MOVE -> {
+ case RIGHT_MOVE_OR_SCROLL -> {
x = MOUSE_POINTER_MOVEMENT_STEP;
}
case DIAGONAL_UP_LEFT_MOVE -> {
@@ -424,7 +446,9 @@
private boolean isMouseScrollKey(int keyCode, InputDevice inputDevice) {
return keyCode == MouseKeyEvent.UP_MOVE_OR_SCROLL.getKeyCode(inputDevice)
- || keyCode == MouseKeyEvent.DOWN_MOVE_OR_SCROLL.getKeyCode(inputDevice);
+ || keyCode == MouseKeyEvent.DOWN_MOVE_OR_SCROLL.getKeyCode(inputDevice)
+ || keyCode == MouseKeyEvent.LEFT_MOVE_OR_SCROLL.getKeyCode(inputDevice)
+ || keyCode == MouseKeyEvent.RIGHT_MOVE_OR_SCROLL.getKeyCode(inputDevice);
}
/**
diff --git a/services/accessibility/java/com/android/server/accessibility/magnification/MagnificationConnectionManager.java b/services/accessibility/java/com/android/server/accessibility/magnification/MagnificationConnectionManager.java
index 19e3e69..fe06406 100644
--- a/services/accessibility/java/com/android/server/accessibility/magnification/MagnificationConnectionManager.java
+++ b/services/accessibility/java/com/android/server/accessibility/magnification/MagnificationConnectionManager.java
@@ -19,6 +19,7 @@
import static android.accessibilityservice.AccessibilityTrace.FLAGS_MAGNIFICATION_CONNECTION;
import static android.accessibilityservice.AccessibilityTrace.FLAGS_MAGNIFICATION_CONNECTION_CALLBACK;
import static android.os.Build.HW_TIMEOUT_MULTIPLIER;
+import static android.os.UserHandle.getCallingUserId;
import static android.view.accessibility.MagnificationAnimationCallback.STUB_ANIMATION_CALLBACK;
import static com.android.server.accessibility.AccessibilityManagerService.INVALID_SERVICE_ID;
@@ -54,6 +55,7 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.LocalServices;
import com.android.server.accessibility.AccessibilityTraceManager;
+import com.android.server.pm.UserManagerInternal;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.wm.WindowManagerInternal;
@@ -209,6 +211,7 @@
private final Callback mCallback;
private final AccessibilityTraceManager mTrace;
private final MagnificationScaleProvider mScaleProvider;
+ private final UserManagerInternal mUserManagerInternal;
public MagnificationConnectionManager(Context context, Object lock, @NonNull Callback callback,
AccessibilityTraceManager trace, MagnificationScaleProvider scaleProvider) {
@@ -217,6 +220,7 @@
mCallback = callback;
mTrace = trace;
mScaleProvider = scaleProvider;
+ mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
}
/**
@@ -280,12 +284,18 @@
* Requests {@link IMagnificationConnection} through
* {@link StatusBarManagerInternal#requestMagnificationConnection(boolean)} and
* destroys all window magnifications if necessary.
+ * NOTE: Currently, this is not allowed to call from visible background users.(b/332222893)
*
* @param connect {@code true} if needs connection, otherwise set the connection to null and
* destroy all window magnifications.
* @return {@code true} if {@link IMagnificationConnection} state is going to change.
*/
public boolean requestConnection(boolean connect) {
+ final int callingUserId = getCallingUserId();
+ if (mUserManagerInternal.isVisibleBackgroundFullUser(callingUserId)) {
+ throw new SecurityException("Visible background user(u" + callingUserId
+ + " is not permitted to request magnification connection.");
+ }
if (DBG) {
Slog.d(TAG, "requestConnection :" + connect);
}
diff --git a/services/appfunctions/java/com/android/server/appfunctions/AppFunctionDumpHelper.java b/services/appfunctions/java/com/android/server/appfunctions/AppFunctionDumpHelper.java
new file mode 100644
index 0000000..9fc413f
--- /dev/null
+++ b/services/appfunctions/java/com/android/server/appfunctions/AppFunctionDumpHelper.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2024 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.appfunctions;
+
+import static android.app.appfunctions.AppFunctionRuntimeMetadata.PROPERTY_APP_FUNCTION_STATIC_METADATA_QUALIFIED_ID;
+import static android.app.appfunctions.AppFunctionStaticMetadataHelper.APP_FUNCTION_INDEXER_PACKAGE;
+import static android.app.appfunctions.AppFunctionStaticMetadataHelper.PROPERTY_FUNCTION_ID;
+
+import android.Manifest;
+import android.annotation.BinderThread;
+import android.annotation.RequiresPermission;
+import android.annotation.NonNull;
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserManager;
+import android.util.IndentingPrintWriter;
+import android.app.appfunctions.AppFunctionRuntimeMetadata;
+import android.app.appfunctions.AppFunctionStaticMetadataHelper;
+import android.app.appsearch.AppSearchManager;
+import android.app.appsearch.AppSearchManager.SearchContext;
+import android.app.appsearch.JoinSpec;
+import android.app.appsearch.GenericDocument;
+import android.app.appsearch.SearchResult;
+import android.app.appsearch.SearchSpec;
+
+import java.io.PrintWriter;
+import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+public final class AppFunctionDumpHelper {
+ private static final String TAG = AppFunctionDumpHelper.class.getSimpleName();
+
+ private AppFunctionDumpHelper() {}
+
+ /** Dumps the state of all app functions for all users. */
+ @BinderThread
+ @RequiresPermission(
+ anyOf = {Manifest.permission.CREATE_USERS, Manifest.permission.MANAGE_USERS})
+ public static void dumpAppFunctionsState(@NonNull Context context, @NonNull PrintWriter w) {
+ UserManager userManager = context.getSystemService(UserManager.class);
+ if (userManager == null) {
+ w.println("Couldn't retrieve UserManager.");
+ return;
+ }
+
+ IndentingPrintWriter pw = new IndentingPrintWriter(w);
+
+ List<UserInfo> userInfos = userManager.getAliveUsers();
+ for (UserInfo userInfo : userInfos) {
+ pw.println(
+ "AppFunction state for user " + userInfo.getUserHandle().getIdentifier() + ":");
+ pw.increaseIndent();
+ dumpAppFunctionsStateForUser(
+ context.createContextAsUser(userInfo.getUserHandle(), /* flags= */ 0), pw);
+ pw.decreaseIndent();
+ }
+ }
+
+ private static void dumpAppFunctionsStateForUser(
+ @NonNull Context context, @NonNull IndentingPrintWriter pw) {
+ AppSearchManager appSearchManager = context.getSystemService(AppSearchManager.class);
+ if (appSearchManager == null) {
+ pw.println("Couldn't retrieve AppSearchManager.");
+ return;
+ }
+
+ try (FutureGlobalSearchSession searchSession =
+ new FutureGlobalSearchSession(appSearchManager, Runnable::run)) {
+ pw.println();
+
+ FutureSearchResults futureSearchResults =
+ searchSession.search("", buildAppFunctionMetadataSearchSpec()).get();
+ List<SearchResult> searchResultsList;
+ do {
+ searchResultsList = futureSearchResults.getNextPage().get();
+ for (SearchResult searchResult : searchResultsList) {
+ dumpAppFunctionMetadata(pw, searchResult);
+ }
+ } while (!searchResultsList.isEmpty());
+ } catch (Exception e) {
+ pw.println("Failed to dump AppFunction state: " + e);
+ }
+ }
+
+ private static SearchSpec buildAppFunctionMetadataSearchSpec() {
+ SearchSpec runtimeMetadataSearchSpec =
+ new SearchSpec.Builder()
+ .addFilterPackageNames(APP_FUNCTION_INDEXER_PACKAGE)
+ .addFilterSchemas(AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE)
+ .build();
+ JoinSpec joinSpec =
+ new JoinSpec.Builder(PROPERTY_APP_FUNCTION_STATIC_METADATA_QUALIFIED_ID)
+ .setNestedSearch(/* queryExpression= */ "", runtimeMetadataSearchSpec)
+ .build();
+
+ return new SearchSpec.Builder()
+ .addFilterPackageNames(APP_FUNCTION_INDEXER_PACKAGE)
+ .addFilterSchemas(AppFunctionStaticMetadataHelper.STATIC_SCHEMA_TYPE)
+ .setJoinSpec(joinSpec)
+ .build();
+ }
+
+ private static void dumpAppFunctionMetadata(
+ IndentingPrintWriter pw, SearchResult joinedSearchResult) {
+ pw.println(
+ "AppFunctionMetadata for: "
+ + joinedSearchResult
+ .getGenericDocument()
+ .getPropertyString(PROPERTY_FUNCTION_ID));
+ pw.increaseIndent();
+
+ pw.println("Static Metadata:");
+ pw.increaseIndent();
+ writeGenericDocumentProperties(pw, joinedSearchResult.getGenericDocument());
+ pw.decreaseIndent();
+
+ pw.println("Runtime Metadata:");
+ pw.increaseIndent();
+ if (!joinedSearchResult.getJoinedResults().isEmpty()) {
+ writeGenericDocumentProperties(
+ pw, joinedSearchResult.getJoinedResults().getFirst().getGenericDocument());
+ } else {
+ pw.println("No runtime metadata found.");
+ }
+ pw.decreaseIndent();
+
+ pw.decreaseIndent();
+ }
+
+ private static void writeGenericDocumentProperties(
+ IndentingPrintWriter pw, GenericDocument genericDocument) {
+ Set<String> propertyNames = genericDocument.getPropertyNames();
+ pw.println("{");
+ pw.increaseIndent();
+ for (String propertyName : propertyNames) {
+ Object propertyValue = genericDocument.getProperty(propertyName);
+ pw.print("\"" + propertyName + "\"" + ": [");
+
+ if (propertyValue instanceof GenericDocument[]) {
+ GenericDocument[] documentValues = (GenericDocument[]) propertyValue;
+ for (int i = 0; i < documentValues.length; i++) {
+ GenericDocument documentValue = documentValues[i];
+ writeGenericDocumentProperties(pw, documentValue);
+ if (i != documentValues.length - 1) {
+ pw.print(", ");
+ }
+ pw.println();
+ }
+ } else {
+ int propertyArrLength = Array.getLength(propertyValue);
+ for (int i = 0; i < propertyArrLength; i++) {
+ Object propertyElement = Array.get(propertyValue, i);
+ if (propertyElement instanceof String) {
+ pw.print("\"" + propertyElement + "\"");
+ } else if (propertyElement instanceof byte[]) {
+ pw.print(Arrays.toString((byte[]) propertyElement));
+ } else if (propertyElement != null) {
+ pw.print(propertyElement.toString());
+ }
+ if (i != propertyArrLength - 1) {
+ pw.print(", ");
+ }
+ }
+ }
+ pw.println("]");
+ }
+ pw.decreaseIndent();
+ pw.println("}");
+ }
+}
diff --git a/services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java b/services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java
index d31ced3..6d350e6 100644
--- a/services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java
+++ b/services/appfunctions/java/com/android/server/appfunctions/AppFunctionManagerServiceImpl.java
@@ -63,10 +63,13 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.infra.AndroidFuture;
+import com.android.internal.util.DumpUtils;
import com.android.server.SystemService.TargetUser;
import com.android.server.appfunctions.RemoteServiceCaller.RunServiceCallCallback;
import com.android.server.appfunctions.RemoteServiceCaller.ServiceUsageCompleteListener;
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
import java.util.Objects;
import java.util.concurrent.CompletionException;
import java.util.concurrent.Executor;
@@ -122,6 +125,20 @@
}
@Override
+ public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
+ if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) {
+ return;
+ }
+
+ final long token = Binder.clearCallingIdentity();
+ try {
+ AppFunctionDumpHelper.dumpAppFunctionsState(mContext, pw);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
public ICancellationSignal executeAppFunction(
@NonNull ExecuteAppFunctionAidlRequest requestInternal,
@NonNull IExecuteAppFunctionCallback executeAppFunctionCallback) {
diff --git a/services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSession.java b/services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSession.java
index de2034b..b89348c 100644
--- a/services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSession.java
+++ b/services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSession.java
@@ -39,20 +39,6 @@
/** A future API wrapper of {@link AppSearchSession} APIs. */
public interface FutureAppSearchSession extends Closeable {
- /** Converts a failed app search result codes into an exception. */
- @NonNull
- static Exception failedResultToException(@NonNull AppSearchResult<?> appSearchResult) {
- return switch (appSearchResult.getResultCode()) {
- case AppSearchResult.RESULT_INVALID_ARGUMENT ->
- new IllegalArgumentException(appSearchResult.getErrorMessage());
- case AppSearchResult.RESULT_IO_ERROR ->
- new IOException(appSearchResult.getErrorMessage());
- case AppSearchResult.RESULT_SECURITY_ERROR ->
- new SecurityException(appSearchResult.getErrorMessage());
- default -> new IllegalStateException(appSearchResult.getErrorMessage());
- };
- }
-
/**
* Sets the schema that represents the organizational structure of data within the AppSearch
* database.
@@ -86,17 +72,4 @@
@Override
void close();
-
- /** A future API wrapper of {@link android.app.appsearch.SearchResults}. */
- interface FutureSearchResults {
-
- /**
- * Retrieves the next page of {@link SearchResult} objects from the {@link AppSearchSession}
- * database.
- *
- * <p>Continue calling this method to access results until it returns an empty list,
- * signifying there are no more results.
- */
- AndroidFuture<List<SearchResult>> getNextPage();
- }
}
diff --git a/services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSessionImpl.java b/services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSessionImpl.java
index d24bb87..87589f5 100644
--- a/services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSessionImpl.java
+++ b/services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSessionImpl.java
@@ -16,7 +16,7 @@
package com.android.server.appfunctions;
-import static com.android.server.appfunctions.FutureAppSearchSession.failedResultToException;
+import static com.android.server.appfunctions.FutureSearchResults.failedResultToException;
import android.annotation.NonNull;
import android.app.appsearch.AppSearchBatchResult;
@@ -192,33 +192,6 @@
});
}
- private static final class FutureSearchResultsImpl implements FutureSearchResults {
- private final SearchResults mSearchResults;
- private final Executor mExecutor;
-
- private FutureSearchResultsImpl(
- @NonNull SearchResults searchResults, @NonNull Executor executor) {
- this.mSearchResults = searchResults;
- this.mExecutor = executor;
- }
-
- @Override
- public AndroidFuture<List<SearchResult>> getNextPage() {
- AndroidFuture<AppSearchResult<List<SearchResult>>> nextPageFuture =
- new AndroidFuture<>();
-
- mSearchResults.getNextPage(mExecutor, nextPageFuture::complete);
- return nextPageFuture.thenApply(
- result -> {
- if (result.isSuccess()) {
- return result.getResultValue();
- } else {
- throw new RuntimeException(failedResultToException(result));
- }
- });
- }
- }
-
private static final class BatchResultCallbackAdapter<K, V>
implements BatchResultCallback<K, V> {
private final AndroidFuture<AppSearchBatchResult<K, V>> mFuture;
diff --git a/services/appfunctions/java/com/android/server/appfunctions/FutureGlobalSearchSession.java b/services/appfunctions/java/com/android/server/appfunctions/FutureGlobalSearchSession.java
index 874c5da..4cc0817 100644
--- a/services/appfunctions/java/com/android/server/appfunctions/FutureGlobalSearchSession.java
+++ b/services/appfunctions/java/com/android/server/appfunctions/FutureGlobalSearchSession.java
@@ -20,6 +20,7 @@
import android.app.appsearch.AppSearchManager;
import android.app.appsearch.AppSearchResult;
import android.app.appsearch.GlobalSearchSession;
+import android.app.appsearch.SearchSpec;
import android.app.appsearch.exceptions.AppSearchException;
import android.app.appsearch.observer.ObserverCallback;
import android.app.appsearch.observer.ObserverSpec;
@@ -49,12 +50,23 @@
return result.getResultValue();
} else {
throw new RuntimeException(
- FutureAppSearchSession.failedResultToException(result));
+ FutureSearchResults.failedResultToException(result));
}
});
}
/**
+ * Retrieves documents from the open {@link GlobalSearchSession} that match a given query string
+ * and type of search provided.
+ */
+ public AndroidFuture<FutureSearchResults> search(
+ String queryExpression, SearchSpec searchSpec) {
+ return getSessionAsync()
+ .thenApply(session -> session.search(queryExpression, searchSpec))
+ .thenApply(result -> new FutureSearchResultsImpl(result, mExecutor));
+ }
+
+ /**
* Registers an observer callback for the given target package name.
*
* @param targetPackageName The package name of the target app.
diff --git a/services/appfunctions/java/com/android/server/appfunctions/FutureSearchResults.java b/services/appfunctions/java/com/android/server/appfunctions/FutureSearchResults.java
new file mode 100644
index 0000000..45cbdb4
--- /dev/null
+++ b/services/appfunctions/java/com/android/server/appfunctions/FutureSearchResults.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2024 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.appfunctions;
+
+import android.annotation.NonNull;
+import android.app.appsearch.AppSearchResult;
+import android.app.appsearch.AppSearchSession;
+import android.app.appsearch.SearchResult;
+import android.app.appsearch.SearchResults;
+
+import com.android.internal.infra.AndroidFuture;
+
+import java.io.IOException;
+import java.util.List;
+
+/** A future API wrapper of {@link android.app.appsearch.SearchResults}. */
+public interface FutureSearchResults {
+
+ /** Converts a failed app search result codes into an exception. */
+ @NonNull
+ public static Exception failedResultToException(@NonNull AppSearchResult<?> appSearchResult) {
+ return switch (appSearchResult.getResultCode()) {
+ case AppSearchResult.RESULT_INVALID_ARGUMENT ->
+ new IllegalArgumentException(appSearchResult.getErrorMessage());
+ case AppSearchResult.RESULT_IO_ERROR ->
+ new IOException(appSearchResult.getErrorMessage());
+ case AppSearchResult.RESULT_SECURITY_ERROR ->
+ new SecurityException(appSearchResult.getErrorMessage());
+ default -> new IllegalStateException(appSearchResult.getErrorMessage());
+ };
+ }
+
+ /**
+ * Retrieves the next page of {@link SearchResult} objects from the {@link AppSearchSession}
+ * database.
+ *
+ * <p>Continue calling this method to access results until it returns an empty list, signifying
+ * there are no more results.
+ */
+ AndroidFuture<List<SearchResult>> getNextPage();
+}
diff --git a/services/appfunctions/java/com/android/server/appfunctions/FutureSearchResultsImpl.java b/services/appfunctions/java/com/android/server/appfunctions/FutureSearchResultsImpl.java
new file mode 100644
index 0000000..c3be342
--- /dev/null
+++ b/services/appfunctions/java/com/android/server/appfunctions/FutureSearchResultsImpl.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2024 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.appfunctions;
+
+import android.annotation.NonNull;
+import android.app.appsearch.AppSearchResult;
+import android.app.appsearch.AppSearchSession;
+import android.app.appsearch.SearchResult;
+import android.app.appsearch.SearchResults;
+
+import com.android.internal.infra.AndroidFuture;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.Executor;
+
+public class FutureSearchResultsImpl implements FutureSearchResults {
+ private final SearchResults mSearchResults;
+ private final Executor mExecutor;
+
+ public FutureSearchResultsImpl(
+ @NonNull SearchResults searchResults, @NonNull Executor executor) {
+ this.mSearchResults = searchResults;
+ this.mExecutor = executor;
+ }
+
+ @Override
+ public AndroidFuture<List<SearchResult>> getNextPage() {
+ AndroidFuture<AppSearchResult<List<SearchResult>>> nextPageFuture = new AndroidFuture<>();
+
+ mSearchResults.getNextPage(mExecutor, nextPageFuture::complete);
+ return nextPageFuture
+ .thenApply(
+ result -> {
+ if (result.isSuccess()) {
+ return result.getResultValue();
+ } else {
+ throw new RuntimeException(
+ FutureSearchResults.failedResultToException(result));
+ }
+ });
+ }
+}
diff --git a/services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java b/services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java
index d84b205..bbf6c0b 100644
--- a/services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java
+++ b/services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java
@@ -45,7 +45,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.infra.AndroidFuture;
-import com.android.server.appfunctions.FutureAppSearchSession.FutureSearchResults;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 1563a62..d206b20 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -2748,6 +2748,11 @@
}
}
+ @Override
+ protected void onUnhandledException(int code, int flags, Exception e) {
+ Slog.wtf(TAG, "Uncaught exception in AudioService: " + code + ", " + flags, e);
+ }
+
@Override // Binder call
public void onShellCommand(FileDescriptor in, FileDescriptor out,
FileDescriptor err, String[] args, ShellCallback callback,
diff --git a/services/core/java/com/android/server/audio/LoudnessCodecHelper.java b/services/core/java/com/android/server/audio/LoudnessCodecHelper.java
index 01f770b..9fa5da4 100644
--- a/services/core/java/com/android/server/audio/LoudnessCodecHelper.java
+++ b/services/core/java/com/android/server/audio/LoudnessCodecHelper.java
@@ -133,6 +133,9 @@
private static final EventLogger sLogger = new EventLogger(
AudioService.LOG_NB_EVENTS_LOUDNESS_CODEC, "Loudness updates");
+ private final Object mDispatcherLock = new Object();
+
+ @GuardedBy("mDispatcherLock")
private final LoudnessRemoteCallbackList mLoudnessUpdateDispatchers =
new LoudnessRemoteCallbackList(this);
@@ -339,12 +342,16 @@
}
void registerLoudnessCodecUpdatesDispatcher(ILoudnessCodecUpdatesDispatcher dispatcher) {
- mLoudnessUpdateDispatchers.register(dispatcher, Binder.getCallingPid());
+ synchronized (mDispatcherLock) {
+ mLoudnessUpdateDispatchers.register(dispatcher, Binder.getCallingPid());
+ }
}
void unregisterLoudnessCodecUpdatesDispatcher(
ILoudnessCodecUpdatesDispatcher dispatcher) {
- mLoudnessUpdateDispatchers.unregister(dispatcher);
+ synchronized (mDispatcherLock) {
+ mLoudnessUpdateDispatchers.unregister(dispatcher);
+ }
}
void startLoudnessCodecUpdates(int sessionId) {
@@ -640,17 +647,20 @@
Log.d(TAG,
"dispatchNewLoudnessParameters: sessionId " + sessionId + " bundle: " + bundle);
}
- final int nbDispatchers = mLoudnessUpdateDispatchers.beginBroadcast();
- for (int i = 0; i < nbDispatchers; ++i) {
- try {
- mLoudnessUpdateDispatchers.getBroadcastItem(i)
- .dispatchLoudnessCodecParameterChange(sessionId, bundle);
- } catch (RemoteException e) {
- Log.e(TAG, "Error dispatching for sessionId " + sessionId + " bundle: " + bundle,
- e);
+ synchronized (mDispatcherLock) {
+ final int nbDispatchers = mLoudnessUpdateDispatchers.beginBroadcast();
+ for (int i = 0; i < nbDispatchers; ++i) {
+ try {
+ mLoudnessUpdateDispatchers.getBroadcastItem(i)
+ .dispatchLoudnessCodecParameterChange(sessionId, bundle);
+ } catch (RemoteException e) {
+ Log.e(TAG,
+ "Error dispatching for sessionId " + sessionId + " bundle: " + bundle,
+ e);
+ }
}
+ mLoudnessUpdateDispatchers.finishBroadcast();
}
- mLoudnessUpdateDispatchers.finishBroadcast();
}
@GuardedBy("mLock")
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubService.java b/services/core/java/com/android/server/location/contexthub/ContextHubService.java
index 3f4a9bb..ed69f7a 100644
--- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java
+++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java
@@ -444,8 +444,17 @@
mSupportedContextHubPerms = hubInfo.second;
mContextHubInfoList = new ArrayList<>(mContextHubIdToInfoMap.values());
mClientManager = new ContextHubClientManager(mContext, mContextHubWrapper);
- mTransactionManager = new ContextHubTransactionManager(
- mContextHubWrapper, mClientManager, mNanoAppStateManager);
+
+ if (Flags.reduceLockingContextHubTransactionManager()) {
+ mTransactionManager =
+ new ContextHubTransactionManager(
+ mContextHubWrapper, mClientManager, mNanoAppStateManager);
+ } else {
+ mTransactionManager =
+ new ContextHubTransactionManagerOld(
+ mContextHubWrapper, mClientManager, mNanoAppStateManager);
+ }
+
mSensorPrivacyManagerInternal =
LocalServices.getService(SensorPrivacyManagerInternal.class);
return true;
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java
index 2a0b1af..da31bf2 100644
--- a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java
+++ b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java
@@ -26,6 +26,8 @@
import android.os.SystemClock;
import android.util.Log;
+import com.android.internal.annotations.GuardedBy;
+
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.Collections;
@@ -43,8 +45,8 @@
/**
* Manages transactions at the Context Hub Service.
- * <p>
- * This class maintains a queue of transaction requests made to the ContextHubService by clients,
+ *
+ * <p>This class maintains a queue of transaction requests made to the ContextHubService by clients,
* and executes them through the Context Hub. At any point in time, either the transaction queue is
* empty, or there is a pending transaction that is waiting for an asynchronous response from the
* hub. This class also handles synchronous errors and timeouts of each transaction.
@@ -52,66 +54,80 @@
* @hide
*/
/* package */ class ContextHubTransactionManager {
- private static final String TAG = "ContextHubTransactionManager";
+ protected static final String TAG = "ContextHubTransactionManager";
public static final Duration RELIABLE_MESSAGE_TIMEOUT = Duration.ofSeconds(1);
public static final Duration RELIABLE_MESSAGE_DUPLICATE_DETECTION_TIMEOUT =
RELIABLE_MESSAGE_TIMEOUT.multipliedBy(3);
- private static final int MAX_PENDING_REQUESTS = 10000;
+ // TODO: b/362299144: When cleaning up the flag
+ // reduce_locking_context_hub_transaction_manager, change these to private
+ protected static final int MAX_PENDING_REQUESTS = 10000;
- private static final int RELIABLE_MESSAGE_MAX_NUM_RETRY = 3;
+ protected static final int RELIABLE_MESSAGE_MAX_NUM_RETRY = 3;
- private static final Duration RELIABLE_MESSAGE_RETRY_WAIT_TIME = Duration.ofMillis(250);
+ protected static final Duration RELIABLE_MESSAGE_RETRY_WAIT_TIME = Duration.ofMillis(250);
- private static final Duration RELIABLE_MESSAGE_MIN_WAIT_TIME = Duration.ofNanos(1000);
+ protected static final Duration RELIABLE_MESSAGE_MIN_WAIT_TIME = Duration.ofNanos(1000);
- private final IContextHubWrapper mContextHubProxy;
+ protected final IContextHubWrapper mContextHubProxy;
- private final ContextHubClientManager mClientManager;
+ protected final ContextHubClientManager mClientManager;
- private final NanoAppStateManager mNanoAppStateManager;
+ protected final NanoAppStateManager mNanoAppStateManager;
- private final ArrayDeque<ContextHubServiceTransaction> mTransactionQueue = new ArrayDeque<>();
+ @GuardedBy("mTransactionLock")
+ protected final ArrayDeque<ContextHubServiceTransaction> mTransactionQueue = new ArrayDeque<>();
- private final Map<Integer, ContextHubServiceTransaction> mReliableMessageTransactionMap =
+ @GuardedBy("mReliableMessageLock")
+ protected final Map<Integer, ContextHubServiceTransaction> mReliableMessageTransactionMap =
new HashMap<>();
/** A set of host endpoint IDs that have an active pending transaction. */
- private final Set<Short> mReliableMessageHostEndpointIdActiveSet = new HashSet<>();
+ @GuardedBy("mReliableMessageLock")
+ protected final Set<Short> mReliableMessageHostEndpointIdActiveSet = new HashSet<>();
- private final AtomicInteger mNextAvailableId = new AtomicInteger();
+ protected final AtomicInteger mNextAvailableId = new AtomicInteger();
/**
- * The next available message sequence number. We choose a random
- * number to start with to avoid collisions and limit the bound to
- * half of the max value to avoid overflow.
+ * The next available message sequence number. We choose a random number to start with to avoid
+ * collisions and limit the bound to half of the max value to avoid overflow.
*/
- private final AtomicInteger mNextAvailableMessageSequenceNumber =
+ protected final AtomicInteger mNextAvailableMessageSequenceNumber =
new AtomicInteger(new Random().nextInt(Integer.MAX_VALUE / 2));
/*
- * An executor and the future object for scheduling timeout timers and
+ * An executor and the future objects for scheduling timeout timers and
* for scheduling the processing of reliable message transactions.
*/
- private final ScheduledThreadPoolExecutor mExecutor = new ScheduledThreadPoolExecutor(1);
- private ScheduledFuture<?> mTimeoutFuture = null;
- private ScheduledFuture<?> mReliableMessageTransactionFuture = null;
+ protected final ScheduledThreadPoolExecutor mExecutor = new ScheduledThreadPoolExecutor(2);
+
+ @GuardedBy("mTransactionLock")
+ protected ScheduledFuture<?> mTimeoutFuture = null;
+
+ @GuardedBy("mReliableMessageLock")
+ protected ScheduledFuture<?> mReliableMessageTransactionFuture = null;
/*
* The list of previous transaction records.
*/
- private static final int NUM_TRANSACTION_RECORDS = 20;
- private final ConcurrentLinkedEvictingDeque<TransactionRecord> mTransactionRecordDeque =
+ protected static final int NUM_TRANSACTION_RECORDS = 20;
+ protected final ConcurrentLinkedEvictingDeque<TransactionRecord> mTransactionRecordDeque =
new ConcurrentLinkedEvictingDeque<>(NUM_TRANSACTION_RECORDS);
- /**
- * A container class to store a record of transactions.
+ /*
+ * Locks for synchronization of normal transactions separately from reliable message
+ * transactions.
*/
- private class TransactionRecord {
- private final String mTransaction;
- private final long mTimestamp;
+ protected final Object mTransactionLock = new Object();
+ protected final Object mReliableMessageLock = new Object();
+ protected final Object mTransactionRecordLock = new Object();
+
+ /** A container class to store a record of transactions. */
+ protected static class TransactionRecord {
+ protected final String mTransaction;
+ protected final long mTimestamp;
TransactionRecord(String transaction) {
mTransaction = transaction;
@@ -126,8 +142,18 @@
}
}
+ /** Used when finishing a transaction. */
+ interface TransactionAcceptConditions {
+ /**
+ * Returns whether to accept the found transaction when receiving a response from the
+ * Context Hub.
+ */
+ boolean acceptTransaction(ContextHubServiceTransaction transaction);
+ }
+
/* package */ ContextHubTransactionManager(
- IContextHubWrapper contextHubProxy, ContextHubClientManager clientManager,
+ IContextHubWrapper contextHubProxy,
+ ContextHubClientManager clientManager,
NanoAppStateManager nanoAppStateManager) {
mContextHubProxy = contextHubProxy;
mClientManager = clientManager;
@@ -409,34 +435,47 @@
/**
* Adds a new transaction to the queue.
- * <p>
- * If there was no pending transaction at the time, the transaction that was added will be
+ *
+ * <p>If there was no pending transaction at the time, the transaction that was added will be
* started in this method. If there were too many transactions in the queue, an exception will
* be thrown.
*
* @param transaction the transaction to add
- * @throws IllegalStateException if the queue is full
*/
/* package */
- synchronized void addTransaction(
- ContextHubServiceTransaction transaction) throws IllegalStateException {
+ void addTransaction(ContextHubServiceTransaction transaction) {
if (transaction == null) {
return;
}
- if (mTransactionQueue.size() >= MAX_PENDING_REQUESTS
- || mReliableMessageTransactionMap.size() >= MAX_PENDING_REQUESTS) {
- throw new IllegalStateException("Transaction queue is full (capacity = "
- + MAX_PENDING_REQUESTS + ")");
+ synchronized (mTransactionRecordLock) {
+ mTransactionRecordDeque.add(new TransactionRecord(transaction.toString()));
}
- mTransactionRecordDeque.add(new TransactionRecord(transaction.toString()));
if (Flags.reliableMessageRetrySupportService()
&& transaction.getTransactionType()
== ContextHubTransaction.TYPE_RELIABLE_MESSAGE) {
- mReliableMessageTransactionMap.put(transaction.getMessageSequenceNumber(), transaction);
+ synchronized (mReliableMessageLock) {
+ if (mReliableMessageTransactionMap.size() >= MAX_PENDING_REQUESTS) {
+ throw new IllegalStateException(
+ "Reliable message transaction queue is full "
+ + "(capacity = "
+ + MAX_PENDING_REQUESTS
+ + ")");
+ }
+ mReliableMessageTransactionMap.put(
+ transaction.getMessageSequenceNumber(), transaction);
+ }
mExecutor.execute(() -> processMessageTransactions());
- } else {
+ return;
+ }
+
+ synchronized (mTransactionLock) {
+ if (mTransactionQueue.size() >= MAX_PENDING_REQUESTS) {
+ throw new IllegalStateException(
+ "Transaction queue is full (capacity = " + MAX_PENDING_REQUESTS + ")");
+ }
+
mTransactionQueue.add(transaction);
if (mTransactionQueue.size() == 1) {
startNextTransaction();
@@ -448,62 +487,85 @@
* Handles a transaction response from a Context Hub.
*
* @param transactionId the transaction ID of the response
- * @param success true if the transaction succeeded
+ * @param success true if the transaction succeeded
*/
/* package */
- synchronized void onTransactionResponse(int transactionId, boolean success) {
- ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ void onTransactionResponse(int transactionId, boolean success) {
+ TransactionAcceptConditions conditions =
+ transaction -> transaction.getTransactionId() == transactionId;
+ ContextHubServiceTransaction transaction = getTransactionAndHandleNext(conditions);
if (transaction == null) {
- Log.w(TAG, "Received unexpected transaction response (no transaction pending)");
- return;
- }
- if (transaction.getTransactionId() != transactionId) {
Log.w(TAG, "Received unexpected transaction response (expected ID = "
- + transaction.getTransactionId() + ", received ID = " + transactionId + ")");
+ + transactionId
+ + ", received ID = "
+ + transaction.getTransactionId()
+ + ")");
return;
}
- transaction.onTransactionComplete(success ? ContextHubTransaction.RESULT_SUCCESS :
- ContextHubTransaction.RESULT_FAILED_AT_HUB);
- removeTransactionAndStartNext();
+ synchronized (transaction) {
+ transaction.onTransactionComplete(
+ success
+ ? ContextHubTransaction.RESULT_SUCCESS
+ : ContextHubTransaction.RESULT_FAILED_AT_HUB);
+ transaction.setComplete();
+ }
}
+ /**
+ * Handles a message delivery response from a Context Hub.
+ *
+ * @param messageSequenceNumber the message sequence number of the response
+ * @param success true if the message was delivered successfully
+ */
/* package */
- synchronized void onMessageDeliveryResponse(int messageSequenceNumber, boolean success) {
+ void onMessageDeliveryResponse(int messageSequenceNumber, boolean success) {
if (!Flags.reliableMessageRetrySupportService()) {
- ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ TransactionAcceptConditions conditions =
+ transaction -> transaction.getTransactionType()
+ == ContextHubTransaction.TYPE_RELIABLE_MESSAGE
+ && transaction.getMessageSequenceNumber()
+ == messageSequenceNumber;
+ ContextHubServiceTransaction transaction = getTransactionAndHandleNext(conditions);
if (transaction == null) {
- Log.w(TAG, "Received unexpected transaction response (no transaction pending)");
+ Log.w(TAG, "Received unexpected message delivery response (expected"
+ + " message sequence number = "
+ + messageSequenceNumber
+ + ", received messageSequenceNumber = "
+ + messageSequenceNumber
+ + ")");
return;
}
- int transactionMessageSequenceNumber = transaction.getMessageSequenceNumber();
- if (transaction.getTransactionType() != ContextHubTransaction.TYPE_RELIABLE_MESSAGE
- || transactionMessageSequenceNumber != messageSequenceNumber) {
- Log.w(TAG, "Received unexpected message transaction response (expected message "
- + "sequence number = "
- + transaction.getMessageSequenceNumber()
- + ", received messageSequenceNumber = " + messageSequenceNumber + ")");
+ synchronized (transaction) {
+ transaction.onTransactionComplete(
+ success
+ ? ContextHubTransaction.RESULT_SUCCESS
+ : ContextHubTransaction.RESULT_FAILED_AT_HUB);
+ transaction.setComplete();
+ }
+ return;
+ }
+
+ ContextHubServiceTransaction transaction = null;
+ synchronized (mReliableMessageLock) {
+ transaction = mReliableMessageTransactionMap.get(messageSequenceNumber);
+ if (transaction == null) {
+ Log.w(
+ TAG,
+ "Could not find reliable message transaction with "
+ + "message sequence number = "
+ + messageSequenceNumber);
return;
}
- transaction.onTransactionComplete(success ? ContextHubTransaction.RESULT_SUCCESS :
- ContextHubTransaction.RESULT_FAILED_AT_HUB);
- removeTransactionAndStartNext();
- return;
+ removeMessageTransaction(transaction);
}
- ContextHubServiceTransaction transaction =
- mReliableMessageTransactionMap.get(messageSequenceNumber);
- if (transaction == null) {
- Log.w(TAG, "Could not find reliable message transaction with "
- + "message sequence number = "
- + messageSequenceNumber);
- return;
- }
-
- completeMessageTransaction(transaction,
- success ? ContextHubTransaction.RESULT_SUCCESS
+ completeMessageTransaction(
+ transaction,
+ success
+ ? ContextHubTransaction.RESULT_SUCCESS
: ContextHubTransaction.RESULT_FAILED_AT_HUB);
mExecutor.execute(() -> processMessageTransactions());
}
@@ -514,77 +576,116 @@
* @param nanoAppStateList the list of nanoapps included in the response
*/
/* package */
- synchronized void onQueryResponse(List<NanoAppState> nanoAppStateList) {
- ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ void onQueryResponse(List<NanoAppState> nanoAppStateList) {
+ TransactionAcceptConditions conditions = transaction ->
+ transaction.getTransactionType() == ContextHubTransaction.TYPE_QUERY_NANOAPPS;
+ ContextHubServiceTransaction transaction = getTransactionAndHandleNext(conditions);
if (transaction == null) {
- Log.w(TAG, "Received unexpected query response (no transaction pending)");
- return;
- }
- if (transaction.getTransactionType() != ContextHubTransaction.TYPE_QUERY_NANOAPPS) {
Log.w(TAG, "Received unexpected query response (expected " + transaction + ")");
return;
}
- transaction.onQueryResponse(ContextHubTransaction.RESULT_SUCCESS, nanoAppStateList);
- removeTransactionAndStartNext();
+ synchronized (transaction) {
+ transaction.onQueryResponse(ContextHubTransaction.RESULT_SUCCESS, nanoAppStateList);
+ transaction.setComplete();
+ }
}
- /**
- * Handles a hub reset event by stopping a pending transaction and starting the next.
- */
+ /** Handles a hub reset event by stopping a pending transaction and starting the next. */
/* package */
- synchronized void onHubReset() {
+ void onHubReset() {
if (Flags.reliableMessageRetrySupportService()) {
- Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter =
- mReliableMessageTransactionMap.entrySet().iterator();
- while (iter.hasNext()) {
- completeMessageTransaction(iter.next().getValue(),
- ContextHubTransaction.RESULT_FAILED_AT_HUB, iter);
+ synchronized (mReliableMessageLock) {
+ Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter =
+ mReliableMessageTransactionMap.entrySet().iterator();
+ while (iter.hasNext()) {
+ removeAndCompleteMessageTransaction(
+ iter.next().getValue(),
+ ContextHubTransaction.RESULT_FAILED_AT_HUB,
+ iter);
+ }
}
}
- ContextHubServiceTransaction transaction = mTransactionQueue.peek();
- if (transaction == null) {
- return;
- }
+ synchronized (mTransactionLock) {
+ ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ if (transaction == null) {
+ return;
+ }
- removeTransactionAndStartNext();
+ removeTransactionAndStartNext();
+ }
+ }
+
+ /**
+ * This function also starts the next transaction and removes the active transaction from the
+ * queue. The caller should complete the transaction.
+ *
+ * <p>Returns the active transaction if the transaction queue is not empty, the transaction is
+ * not null, and the transaction matches the conditions.
+ */
+ private ContextHubServiceTransaction getTransactionAndHandleNext(
+ TransactionAcceptConditions conditions) {
+ ContextHubServiceTransaction transaction = null;
+ synchronized (mTransactionLock) {
+ transaction = mTransactionQueue.peek();
+ if (transaction == null
+ || (conditions != null && !conditions.acceptTransaction(transaction))) {
+ return null;
+ }
+
+ cancelTimeoutFuture();
+ mTransactionQueue.remove();
+ if (!mTransactionQueue.isEmpty()) {
+ startNextTransaction();
+ }
+ }
+ return transaction;
}
/**
* Pops the front transaction from the queue and starts the next pending transaction request.
- * <p>
- * Removing elements from the transaction queue must only be done through this method. When a
+ *
+ * <p>Removing elements from the transaction queue must only be done through this method. When a
* pending transaction is removed, the timeout timer is cancelled and the transaction is marked
* complete.
- * <p>
- * It is assumed that the transaction queue is non-empty when this method is invoked, and that
- * the caller has obtained a lock on this ContextHubTransactionManager object.
+ *
+ * <p>It is assumed that the transaction queue is non-empty when this method is invoked, and
+ * that the caller has obtained mTransactionLock.
*/
+ @GuardedBy("mTransactionLock")
private void removeTransactionAndStartNext() {
- if (mTimeoutFuture != null) {
- mTimeoutFuture.cancel(/* mayInterruptIfRunning= */ false);
- mTimeoutFuture = null;
- }
+ cancelTimeoutFuture();
ContextHubServiceTransaction transaction = mTransactionQueue.remove();
- transaction.setComplete();
+ synchronized (transaction) {
+ transaction.setComplete();
+ }
if (!mTransactionQueue.isEmpty()) {
startNextTransaction();
}
}
+ /** Cancels the timeout future. */
+ @GuardedBy("mTransactionLock")
+ private void cancelTimeoutFuture() {
+ if (mTimeoutFuture != null) {
+ mTimeoutFuture.cancel(/* mayInterruptIfRunning= */ false);
+ mTimeoutFuture = null;
+ }
+ }
+
/**
* Starts the next pending transaction request.
- * <p>
- * Starting new transactions must only be done through this method. This method continues to
+ *
+ * <p>Starting new transactions must only be done through this method. This method continues to
* process the transaction queue as long as there are pending requests, and no transaction is
* pending.
- * <p>
- * It is assumed that the caller has obtained a lock on this ContextHubTransactionManager
- * object.
+ *
+ * <p>It is assumed that the caller has obtained a lock on mTransactionLock.
*/
+ @GuardedBy("mTransactionLock")
private void startNextTransaction() {
int result = ContextHubTransaction.RESULT_FAILED_UNKNOWN;
while (result != ContextHubTransaction.RESULT_SUCCESS && !mTransactionQueue.isEmpty()) {
@@ -592,28 +693,36 @@
result = transaction.onTransact();
if (result == ContextHubTransaction.RESULT_SUCCESS) {
- Runnable onTimeoutFunc = () -> {
- synchronized (this) {
- if (!transaction.isComplete()) {
- Log.d(TAG, transaction + " timed out");
- transaction.onTransactionComplete(
- ContextHubTransaction.RESULT_FAILED_TIMEOUT);
+ Runnable onTimeoutFunc =
+ () -> {
+ synchronized (transaction) {
+ if (!transaction.isComplete()) {
+ Log.d(TAG, transaction + " timed out");
+ transaction.onTransactionComplete(
+ ContextHubTransaction.RESULT_FAILED_TIMEOUT);
+ transaction.setComplete();
+ }
+ }
- removeTransactionAndStartNext();
- }
- }
- };
+ synchronized (mTransactionLock) {
+ removeTransactionAndStartNext();
+ }
+ };
long timeoutMs = transaction.getTimeout(TimeUnit.MILLISECONDS);
try {
- mTimeoutFuture = mExecutor.schedule(
- onTimeoutFunc, timeoutMs, TimeUnit.MILLISECONDS);
+ mTimeoutFuture =
+ mExecutor.schedule(onTimeoutFunc, timeoutMs, TimeUnit.MILLISECONDS);
} catch (Exception e) {
Log.e(TAG, "Error when schedule a timer", e);
}
} else {
- transaction.onTransactionComplete(
- ContextHubServiceUtil.toTransactionResult(result));
+ synchronized (transaction) {
+ transaction.onTransactionComplete(
+ ContextHubServiceUtil.toTransactionResult(result));
+ transaction.setComplete();
+ }
+
mTransactionQueue.remove();
}
}
@@ -621,81 +730,97 @@
/**
* Processes message transactions, starting and completing them as needed.
- * <p>
- * This function is called when adding a message transaction or when a timer
- * expires for an existing message transaction's retry or timeout. The
- * internal processing loop will iterate at most twice as if one iteration
- * completes a transaction, the next iteration can only start new transactions.
- * If the first iteration does not complete any transaction, the loop will
- * only iterate once.
+ *
+ * <p>This function is called when adding a message transaction or when a timer expires for an
+ * existing message transaction's retry or timeout. The internal processing loop will iterate at
+ * most twice as if one iteration completes a transaction, the next iteration can only start new
+ * transactions. If the first iteration does not complete any transaction, the loop will only
+ * iterate once.
+ *
* <p>
*/
- private synchronized void processMessageTransactions() {
- if (!Flags.reliableMessageRetrySupportService()) {
- return;
- }
+ private void processMessageTransactions() {
+ synchronized (mReliableMessageLock) {
+ if (!Flags.reliableMessageRetrySupportService()) {
+ return;
+ }
- if (mReliableMessageTransactionFuture != null) {
- mReliableMessageTransactionFuture.cancel(/* mayInterruptIfRunning= */ false);
- mReliableMessageTransactionFuture = null;
- }
+ if (mReliableMessageTransactionFuture != null) {
+ mReliableMessageTransactionFuture.cancel(/* mayInterruptIfRunning= */ false);
+ mReliableMessageTransactionFuture = null;
+ }
- long now = SystemClock.elapsedRealtimeNanos();
- long nextExecutionTime = Long.MAX_VALUE;
- boolean continueProcessing;
- do {
- continueProcessing = false;
- Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter =
- mReliableMessageTransactionMap.entrySet().iterator();
- while (iter.hasNext()) {
- ContextHubServiceTransaction transaction = iter.next().getValue();
- short hostEndpointId = transaction.getHostEndpointId();
- int numCompletedStartCalls = transaction.getNumCompletedStartCalls();
- if (numCompletedStartCalls == 0
- && mReliableMessageHostEndpointIdActiveSet.contains(hostEndpointId)) {
- continue;
- }
-
- long nextRetryTime = transaction.getNextRetryTime();
- long timeoutTime = transaction.getTimeoutTime();
- boolean transactionTimedOut = timeoutTime <= now;
- boolean transactionHitMaxRetries = nextRetryTime <= now
- && numCompletedStartCalls > RELIABLE_MESSAGE_MAX_NUM_RETRY;
- if (transactionTimedOut || transactionHitMaxRetries) {
- completeMessageTransaction(transaction,
- ContextHubTransaction.RESULT_FAILED_TIMEOUT, iter);
- continueProcessing = true;
- } else {
- if (nextRetryTime <= now || numCompletedStartCalls <= 0) {
- startMessageTransaction(transaction, now);
+ long now = SystemClock.elapsedRealtimeNanos();
+ long nextExecutionTime = Long.MAX_VALUE;
+ boolean continueProcessing;
+ do {
+ continueProcessing = false;
+ Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter =
+ mReliableMessageTransactionMap.entrySet().iterator();
+ while (iter.hasNext()) {
+ ContextHubServiceTransaction transaction = iter.next().getValue();
+ short hostEndpointId = transaction.getHostEndpointId();
+ int numCompletedStartCalls = transaction.getNumCompletedStartCalls();
+ if (numCompletedStartCalls == 0
+ && mReliableMessageHostEndpointIdActiveSet.contains(hostEndpointId)) {
+ continue;
}
- nextExecutionTime = Math.min(nextExecutionTime,
- transaction.getNextRetryTime());
- nextExecutionTime = Math.min(nextExecutionTime,
- transaction.getTimeoutTime());
- }
- }
- } while (continueProcessing);
+ long nextRetryTime = transaction.getNextRetryTime();
+ long timeoutTime = transaction.getTimeoutTime();
+ boolean transactionTimedOut = timeoutTime <= now;
+ boolean transactionHitMaxRetries =
+ nextRetryTime <= now
+ && numCompletedStartCalls > RELIABLE_MESSAGE_MAX_NUM_RETRY;
+ if (transactionTimedOut || transactionHitMaxRetries) {
+ removeAndCompleteMessageTransaction(
+ transaction, ContextHubTransaction.RESULT_FAILED_TIMEOUT, iter);
+ continueProcessing = true;
+ } else {
+ if (nextRetryTime <= now || numCompletedStartCalls <= 0) {
+ startMessageTransaction(transaction, now);
+ }
- if (nextExecutionTime < Long.MAX_VALUE) {
- mReliableMessageTransactionFuture = mExecutor.schedule(
- () -> processMessageTransactions(),
- Math.max(nextExecutionTime - SystemClock.elapsedRealtimeNanos(),
- RELIABLE_MESSAGE_MIN_WAIT_TIME.toNanos()),
- TimeUnit.NANOSECONDS);
+ nextExecutionTime =
+ Math.min(nextExecutionTime, transaction.getNextRetryTime());
+ nextExecutionTime =
+ Math.min(nextExecutionTime, transaction.getTimeoutTime());
+ }
+ }
+ } while (continueProcessing);
+
+ if (nextExecutionTime < Long.MAX_VALUE) {
+ mReliableMessageTransactionFuture =
+ mExecutor.schedule(
+ () -> processMessageTransactions(),
+ Math.max(
+ nextExecutionTime - SystemClock.elapsedRealtimeNanos(),
+ RELIABLE_MESSAGE_MIN_WAIT_TIME.toNanos()),
+ TimeUnit.NANOSECONDS);
+ }
}
}
/**
- * Completes a message transaction and removes it from the reliable message map.
+ * Completes a message transaction.
*
* @param transaction The transaction to complete.
* @param result The result code.
*/
- private void completeMessageTransaction(ContextHubServiceTransaction transaction,
- @ContextHubTransaction.Result int result) {
- completeMessageTransaction(transaction, result, /* iter= */ null);
+ private void completeMessageTransaction(
+ ContextHubServiceTransaction transaction, @ContextHubTransaction.Result int result) {
+ synchronized (transaction) {
+ transaction.onTransactionComplete(result);
+ transaction.setComplete();
+ }
+
+ Log.d(
+ TAG,
+ "Successfully completed reliable message transaction with "
+ + "message sequence number = "
+ + transaction.getMessageSequenceNumber()
+ + " and result = "
+ + result);
}
/**
@@ -705,25 +830,41 @@
* @param result The result code.
* @param iter The iterator for the reliable message map - used to remove the message directly.
*/
- private void completeMessageTransaction(ContextHubServiceTransaction transaction,
+ @GuardedBy("mReliableMessageLock")
+ private void removeAndCompleteMessageTransaction(
+ ContextHubServiceTransaction transaction,
@ContextHubTransaction.Result int result,
Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter) {
- transaction.onTransactionComplete(result);
+ removeMessageTransaction(transaction, iter);
+ completeMessageTransaction(transaction, result);
+ }
+ /**
+ * Removes a message transaction from the reliable message map.
+ *
+ * @param transaction The transaction to remove.
+ */
+ @GuardedBy("mReliableMessageLock")
+ private void removeMessageTransaction(ContextHubServiceTransaction transaction) {
+ removeMessageTransaction(transaction, /* iter= */ null);
+ }
+
+ /**
+ * Removes a message transaction from the reliable message map.
+ *
+ * @param transaction The transaction to remove.
+ * @param iter The iterator for the reliable message map - used to remove the message directly.
+ */
+ @GuardedBy("mReliableMessageLock")
+ private void removeMessageTransaction(
+ ContextHubServiceTransaction transaction,
+ Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter) {
if (iter == null) {
mReliableMessageTransactionMap.remove(transaction.getMessageSequenceNumber());
} else {
iter.remove();
}
mReliableMessageHostEndpointIdActiveSet.remove(transaction.getHostEndpointId());
-
- Log.d(
- TAG,
- "Successfully completed reliable message transaction with "
- + "message sequence number = "
- + transaction.getMessageSequenceNumber()
- + " and result = "
- + result);
}
/**
@@ -732,24 +873,25 @@
* @param transaction The transaction to start.
* @param now The now time.
*/
+ @GuardedBy("mReliableMessageLock")
private void startMessageTransaction(ContextHubServiceTransaction transaction, long now) {
int numCompletedStartCalls = transaction.getNumCompletedStartCalls();
@ContextHubTransaction.Result int result = transaction.onTransact();
if (result == ContextHubTransaction.RESULT_SUCCESS) {
- Log.d(
- TAG,
- "Successfully "
- + (numCompletedStartCalls == 0 ? "started" : "retried")
- + " reliable message transaction with message sequence number = "
- + transaction.getMessageSequenceNumber());
+ Log.d(
+ TAG,
+ "Successfully "
+ + (numCompletedStartCalls == 0 ? "started" : "retried")
+ + " reliable message transaction with message sequence number = "
+ + transaction.getMessageSequenceNumber());
} else {
- Log.w(
- TAG,
- "Could not start reliable message transaction with "
- + "message sequence number = "
- + transaction.getMessageSequenceNumber()
- + ", result = "
- + result);
+ Log.w(
+ TAG,
+ "Could not start reliable message transaction with "
+ + "message sequence number = "
+ + transaction.getMessageSequenceNumber()
+ + ", result = "
+ + result);
}
transaction.setNextRetryTime(now + RELIABLE_MESSAGE_RETRY_WAIT_TIME.toNanos());
@@ -788,17 +930,19 @@
public String toString() {
StringBuilder sb = new StringBuilder();
int i = 0;
- synchronized (this) {
- for (ContextHubServiceTransaction transaction: mTransactionQueue) {
+ synchronized (mTransactionLock) {
+ for (ContextHubServiceTransaction transaction : mTransactionQueue) {
sb.append(i);
sb.append(": ");
sb.append(transaction.toString());
sb.append("\n");
++i;
}
+ }
- if (Flags.reliableMessageRetrySupportService()) {
- for (ContextHubServiceTransaction transaction:
+ if (Flags.reliableMessageRetrySupportService()) {
+ synchronized (mReliableMessageLock) {
+ for (ContextHubServiceTransaction transaction :
mReliableMessageTransactionMap.values()) {
sb.append(i);
sb.append(": ");
@@ -807,7 +951,9 @@
++i;
}
}
+ }
+ synchronized (mTransactionRecordLock) {
sb.append("Transaction History:\n");
Iterator<TransactionRecord> iterator = mTransactionRecordDeque.descendingIterator();
while (iterator.hasNext()) {
@@ -815,6 +961,7 @@
sb.append("\n");
}
}
+
return sb.toString();
}
}
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManagerOld.java b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManagerOld.java
new file mode 100644
index 0000000..a67fa30
--- /dev/null
+++ b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManagerOld.java
@@ -0,0 +1,475 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.location.contexthub;
+
+import android.chre.flags.Flags;
+import android.hardware.location.ContextHubTransaction;
+import android.hardware.location.IContextHubTransactionCallback;
+import android.hardware.location.NanoAppBinary;
+import android.hardware.location.NanoAppMessage;
+import android.hardware.location.NanoAppState;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.util.Log;
+
+import java.time.Duration;
+import java.util.ArrayDeque;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Manages transactions at the Context Hub Service.
+ *
+ * <p>This class maintains a queue of transaction requests made to the ContextHubService by clients,
+ * and executes them through the Context Hub. At any point in time, either the transaction queue is
+ * empty, or there is a pending transaction that is waiting for an asynchronous response from the
+ * hub. This class also handles synchronous errors and timeouts of each transaction.
+ *
+ * <p>This is the old version of ContextHubTransactionManager that uses global synchronization
+ * instead of individual locks. This will be deleted when the
+ * reduce_locking_context_hub_transaction_manager flag is cleaned up.
+ *
+ * @hide
+ */
+/* package */ class ContextHubTransactionManagerOld extends ContextHubTransactionManager {
+ /* package */ ContextHubTransactionManagerOld(
+ IContextHubWrapper contextHubProxy,
+ ContextHubClientManager clientManager,
+ NanoAppStateManager nanoAppStateManager) {
+ super(contextHubProxy, clientManager, nanoAppStateManager);
+ }
+
+ /**
+ * Adds a new transaction to the queue.
+ *
+ * <p>If there was no pending transaction at the time, the transaction that was added will be
+ * started in this method. If there were too many transactions in the queue, an exception will
+ * be thrown.
+ *
+ * @param transaction the transaction to add
+ * @throws IllegalStateException if the queue is full
+ */
+ /* package */
+ @Override
+ synchronized void addTransaction(ContextHubServiceTransaction transaction)
+ throws IllegalStateException {
+ if (transaction == null) {
+ return;
+ }
+
+ if (mTransactionQueue.size() >= MAX_PENDING_REQUESTS
+ || mReliableMessageTransactionMap.size() >= MAX_PENDING_REQUESTS) {
+ throw new IllegalStateException(
+ "Transaction queue is full (capacity = " + MAX_PENDING_REQUESTS + ")");
+ }
+
+ mTransactionRecordDeque.add(new TransactionRecord(transaction.toString()));
+ if (Flags.reliableMessageRetrySupportService()
+ && transaction.getTransactionType()
+ == ContextHubTransaction.TYPE_RELIABLE_MESSAGE) {
+ mReliableMessageTransactionMap.put(transaction.getMessageSequenceNumber(), transaction);
+ mExecutor.execute(() -> processMessageTransactions());
+ } else {
+ mTransactionQueue.add(transaction);
+ if (mTransactionQueue.size() == 1) {
+ startNextTransaction();
+ }
+ }
+ }
+
+ /**
+ * Handles a transaction response from a Context Hub.
+ *
+ * @param transactionId the transaction ID of the response
+ * @param success true if the transaction succeeded
+ */
+ /* package */
+ @Override
+ synchronized void onTransactionResponse(int transactionId, boolean success) {
+ ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ if (transaction == null) {
+ Log.w(TAG, "Received unexpected transaction response (no transaction pending)");
+ return;
+ }
+ if (transaction.getTransactionId() != transactionId) {
+ Log.w(
+ TAG,
+ "Received unexpected transaction response (expected ID = "
+ + transaction.getTransactionId()
+ + ", received ID = "
+ + transactionId
+ + ")");
+ return;
+ }
+
+ transaction.onTransactionComplete(
+ success
+ ? ContextHubTransaction.RESULT_SUCCESS
+ : ContextHubTransaction.RESULT_FAILED_AT_HUB);
+ removeTransactionAndStartNext();
+ }
+
+ /* package */
+ @Override
+ synchronized void onMessageDeliveryResponse(int messageSequenceNumber, boolean success) {
+ if (!Flags.reliableMessageRetrySupportService()) {
+ ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ if (transaction == null) {
+ Log.w(TAG, "Received unexpected transaction response (no transaction pending)");
+ return;
+ }
+
+ int transactionMessageSequenceNumber = transaction.getMessageSequenceNumber();
+ if (transaction.getTransactionType() != ContextHubTransaction.TYPE_RELIABLE_MESSAGE
+ || transactionMessageSequenceNumber != messageSequenceNumber) {
+ Log.w(
+ TAG,
+ "Received unexpected message transaction response (expected message "
+ + "sequence number = "
+ + transaction.getMessageSequenceNumber()
+ + ", received messageSequenceNumber = "
+ + messageSequenceNumber
+ + ")");
+ return;
+ }
+
+ transaction.onTransactionComplete(
+ success
+ ? ContextHubTransaction.RESULT_SUCCESS
+ : ContextHubTransaction.RESULT_FAILED_AT_HUB);
+ removeTransactionAndStartNext();
+ return;
+ }
+
+ ContextHubServiceTransaction transaction =
+ mReliableMessageTransactionMap.get(messageSequenceNumber);
+ if (transaction == null) {
+ Log.w(
+ TAG,
+ "Could not find reliable message transaction with "
+ + "message sequence number = "
+ + messageSequenceNumber);
+ return;
+ }
+
+ completeMessageTransaction(
+ transaction,
+ success
+ ? ContextHubTransaction.RESULT_SUCCESS
+ : ContextHubTransaction.RESULT_FAILED_AT_HUB);
+ mExecutor.execute(() -> processMessageTransactions());
+ }
+
+ /**
+ * Handles a query response from a Context Hub.
+ *
+ * @param nanoAppStateList the list of nanoapps included in the response
+ */
+ /* package */
+ @Override
+ synchronized void onQueryResponse(List<NanoAppState> nanoAppStateList) {
+ ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ if (transaction == null) {
+ Log.w(TAG, "Received unexpected query response (no transaction pending)");
+ return;
+ }
+ if (transaction.getTransactionType() != ContextHubTransaction.TYPE_QUERY_NANOAPPS) {
+ Log.w(TAG, "Received unexpected query response (expected " + transaction + ")");
+ return;
+ }
+
+ transaction.onQueryResponse(ContextHubTransaction.RESULT_SUCCESS, nanoAppStateList);
+ removeTransactionAndStartNext();
+ }
+
+ /** Handles a hub reset event by stopping a pending transaction and starting the next. */
+ /* package */
+ @Override
+ synchronized void onHubReset() {
+ if (Flags.reliableMessageRetrySupportService()) {
+ Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter =
+ mReliableMessageTransactionMap.entrySet().iterator();
+ while (iter.hasNext()) {
+ completeMessageTransaction(
+ iter.next().getValue(), ContextHubTransaction.RESULT_FAILED_AT_HUB, iter);
+ }
+ }
+
+ ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ if (transaction == null) {
+ return;
+ }
+
+ removeTransactionAndStartNext();
+ }
+
+ /**
+ * Pops the front transaction from the queue and starts the next pending transaction request.
+ *
+ * <p>Removing elements from the transaction queue must only be done through this method. When a
+ * pending transaction is removed, the timeout timer is cancelled and the transaction is marked
+ * complete.
+ *
+ * <p>It is assumed that the transaction queue is non-empty when this method is invoked, and
+ * that the caller has obtained a lock on this ContextHubTransactionManager object.
+ */
+ private void removeTransactionAndStartNext() {
+ if (mTimeoutFuture != null) {
+ mTimeoutFuture.cancel(/* mayInterruptIfRunning= */ false);
+ mTimeoutFuture = null;
+ }
+
+ ContextHubServiceTransaction transaction = mTransactionQueue.remove();
+ transaction.setComplete();
+
+ if (!mTransactionQueue.isEmpty()) {
+ startNextTransaction();
+ }
+ }
+
+ /**
+ * Starts the next pending transaction request.
+ *
+ * <p>Starting new transactions must only be done through this method. This method continues to
+ * process the transaction queue as long as there are pending requests, and no transaction is
+ * pending.
+ *
+ * <p>It is assumed that the caller has obtained a lock on this ContextHubTransactionManager
+ * object.
+ */
+ private void startNextTransaction() {
+ int result = ContextHubTransaction.RESULT_FAILED_UNKNOWN;
+ while (result != ContextHubTransaction.RESULT_SUCCESS && !mTransactionQueue.isEmpty()) {
+ ContextHubServiceTransaction transaction = mTransactionQueue.peek();
+ result = transaction.onTransact();
+
+ if (result == ContextHubTransaction.RESULT_SUCCESS) {
+ Runnable onTimeoutFunc =
+ () -> {
+ synchronized (this) {
+ if (!transaction.isComplete()) {
+ Log.d(TAG, transaction + " timed out");
+ transaction.onTransactionComplete(
+ ContextHubTransaction.RESULT_FAILED_TIMEOUT);
+
+ removeTransactionAndStartNext();
+ }
+ }
+ };
+
+ long timeoutMs = transaction.getTimeout(TimeUnit.MILLISECONDS);
+ try {
+ mTimeoutFuture =
+ mExecutor.schedule(onTimeoutFunc, timeoutMs, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ Log.e(TAG, "Error when schedule a timer", e);
+ }
+ } else {
+ transaction.onTransactionComplete(
+ ContextHubServiceUtil.toTransactionResult(result));
+ mTransactionQueue.remove();
+ }
+ }
+ }
+
+ /**
+ * Processes message transactions, starting and completing them as needed.
+ *
+ * <p>This function is called when adding a message transaction or when a timer expires for an
+ * existing message transaction's retry or timeout. The internal processing loop will iterate at
+ * most twice as if one iteration completes a transaction, the next iteration can only start new
+ * transactions. If the first iteration does not complete any transaction, the loop will only
+ * iterate once.
+ *
+ * <p>
+ */
+ private synchronized void processMessageTransactions() {
+ if (!Flags.reliableMessageRetrySupportService()) {
+ return;
+ }
+
+ if (mReliableMessageTransactionFuture != null) {
+ mReliableMessageTransactionFuture.cancel(/* mayInterruptIfRunning= */ false);
+ mReliableMessageTransactionFuture = null;
+ }
+
+ long now = SystemClock.elapsedRealtimeNanos();
+ long nextExecutionTime = Long.MAX_VALUE;
+ boolean continueProcessing;
+ do {
+ continueProcessing = false;
+ Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter =
+ mReliableMessageTransactionMap.entrySet().iterator();
+ while (iter.hasNext()) {
+ ContextHubServiceTransaction transaction = iter.next().getValue();
+ short hostEndpointId = transaction.getHostEndpointId();
+ int numCompletedStartCalls = transaction.getNumCompletedStartCalls();
+ if (numCompletedStartCalls == 0
+ && mReliableMessageHostEndpointIdActiveSet.contains(hostEndpointId)) {
+ continue;
+ }
+
+ long nextRetryTime = transaction.getNextRetryTime();
+ long timeoutTime = transaction.getTimeoutTime();
+ boolean transactionTimedOut = timeoutTime <= now;
+ boolean transactionHitMaxRetries =
+ nextRetryTime <= now
+ && numCompletedStartCalls > RELIABLE_MESSAGE_MAX_NUM_RETRY;
+ if (transactionTimedOut || transactionHitMaxRetries) {
+ completeMessageTransaction(
+ transaction, ContextHubTransaction.RESULT_FAILED_TIMEOUT, iter);
+ continueProcessing = true;
+ } else {
+ if (nextRetryTime <= now || numCompletedStartCalls <= 0) {
+ startMessageTransaction(transaction, now);
+ }
+
+ nextExecutionTime = Math.min(nextExecutionTime, transaction.getNextRetryTime());
+ nextExecutionTime = Math.min(nextExecutionTime, transaction.getTimeoutTime());
+ }
+ }
+ } while (continueProcessing);
+
+ if (nextExecutionTime < Long.MAX_VALUE) {
+ mReliableMessageTransactionFuture =
+ mExecutor.schedule(
+ () -> processMessageTransactions(),
+ Math.max(
+ nextExecutionTime - SystemClock.elapsedRealtimeNanos(),
+ RELIABLE_MESSAGE_MIN_WAIT_TIME.toNanos()),
+ TimeUnit.NANOSECONDS);
+ }
+ }
+
+ /**
+ * Completes a message transaction and removes it from the reliable message map.
+ *
+ * @param transaction The transaction to complete.
+ * @param result The result code.
+ */
+ private void completeMessageTransaction(
+ ContextHubServiceTransaction transaction, @ContextHubTransaction.Result int result) {
+ completeMessageTransaction(transaction, result, /* iter= */ null);
+ }
+
+ /**
+ * Completes a message transaction and removes it from the reliable message map using iter.
+ *
+ * @param transaction The transaction to complete.
+ * @param result The result code.
+ * @param iter The iterator for the reliable message map - used to remove the message directly.
+ */
+ private void completeMessageTransaction(
+ ContextHubServiceTransaction transaction,
+ @ContextHubTransaction.Result int result,
+ Iterator<Map.Entry<Integer, ContextHubServiceTransaction>> iter) {
+ transaction.onTransactionComplete(result);
+
+ if (iter == null) {
+ mReliableMessageTransactionMap.remove(transaction.getMessageSequenceNumber());
+ } else {
+ iter.remove();
+ }
+ mReliableMessageHostEndpointIdActiveSet.remove(transaction.getHostEndpointId());
+
+ Log.d(
+ TAG,
+ "Successfully completed reliable message transaction with "
+ + "message sequence number = "
+ + transaction.getMessageSequenceNumber()
+ + " and result = "
+ + result);
+ }
+
+ /**
+ * Starts a message transaction.
+ *
+ * @param transaction The transaction to start.
+ * @param now The now time.
+ */
+ private void startMessageTransaction(ContextHubServiceTransaction transaction, long now) {
+ int numCompletedStartCalls = transaction.getNumCompletedStartCalls();
+ @ContextHubTransaction.Result int result = transaction.onTransact();
+ if (result == ContextHubTransaction.RESULT_SUCCESS) {
+ Log.d(
+ TAG,
+ "Successfully "
+ + (numCompletedStartCalls == 0 ? "started" : "retried")
+ + " reliable message transaction with message sequence number = "
+ + transaction.getMessageSequenceNumber());
+ } else {
+ Log.w(
+ TAG,
+ "Could not start reliable message transaction with "
+ + "message sequence number = "
+ + transaction.getMessageSequenceNumber()
+ + ", result = "
+ + result);
+ }
+
+ transaction.setNextRetryTime(now + RELIABLE_MESSAGE_RETRY_WAIT_TIME.toNanos());
+ if (transaction.getTimeoutTime() == Long.MAX_VALUE) { // first time starting transaction
+ transaction.setTimeoutTime(now + RELIABLE_MESSAGE_TIMEOUT.toNanos());
+ }
+ transaction.setNumCompletedStartCalls(numCompletedStartCalls + 1);
+ mReliableMessageHostEndpointIdActiveSet.add(transaction.getHostEndpointId());
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ int i = 0;
+ synchronized (this) {
+ for (ContextHubServiceTransaction transaction : mTransactionQueue) {
+ sb.append(i);
+ sb.append(": ");
+ sb.append(transaction.toString());
+ sb.append("\n");
+ ++i;
+ }
+
+ if (Flags.reliableMessageRetrySupportService()) {
+ for (ContextHubServiceTransaction transaction :
+ mReliableMessageTransactionMap.values()) {
+ sb.append(i);
+ sb.append(": ");
+ sb.append(transaction.toString());
+ sb.append("\n");
+ ++i;
+ }
+ }
+
+ sb.append("Transaction History:\n");
+ Iterator<TransactionRecord> iterator = mTransactionRecordDeque.descendingIterator();
+ while (iterator.hasNext()) {
+ sb.append(iterator.next());
+ sb.append("\n");
+ }
+ }
+ return sb.toString();
+ }
+}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 6c2d4f7..88334eb 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -12577,18 +12577,31 @@
// Checks if this is a request to notify system UI about a notification that
// has been lifetime extended.
- // (We only need to check old for the flag, because in both cancellation and
- // update cases, old should have the flag, whereas in update cases the
- // new will NOT have the flag.)
- // If it is such a request, and this is system UI, we send the post request
- // only to System UI, and break as we don't need to continue checking other
- // Managed Services.
- if (info.isSystemUi() && old != null && old.getNotification() != null
+ // We check both old and new for the flag, to avoid catching updates
+ // (where new will not have the flag).
+ // If it is such a request, and this is the system UI listener, we send
+ // the post request. If it's any other listener, we skip it.
+ if (old != null && old.getNotification() != null
&& (old.getNotification().flags
+ & FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY) > 0
+ && sbn != null && sbn.getNotification() != null
+ && (sbn.getNotification().flags
& FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY) > 0) {
- final NotificationRankingUpdate update = makeRankingUpdateLocked(info);
- listenerCalls.add(() -> notifyPosted(info, sbnToPost, update));
- break;
+ if (info.isSystemUi()) {
+ final NotificationRankingUpdate update =
+ makeRankingUpdateLocked(info);
+ listenerCalls.add(() -> notifyPosted(info, sbnToPost, update));
+ break;
+ } else {
+ // Skipping because this is the direct-reply "update" and we only
+ // need to send it to sysui, so we immediately continue, before it
+ // can get sent to other listeners below.
+ if (DBG) {
+ Slog.d(TAG, "prepareNotifyPostedLocked: direct reply update, "
+ + "skipping post to " + info.toString());
+ }
+ continue;
+ }
}
}
diff --git a/services/core/java/com/android/server/os/NativeTombstoneManager.java b/services/core/java/com/android/server/os/NativeTombstoneManager.java
index 3bcaf58..f23d782 100644
--- a/services/core/java/com/android/server/os/NativeTombstoneManager.java
+++ b/services/core/java/com/android/server/os/NativeTombstoneManager.java
@@ -96,12 +96,15 @@
mHandler = thread.getThreadHandler();
mWatcher = new TombstoneWatcher();
- mWatcher.startWatching();
}
void onSystemReady() {
registerForUserRemoval();
registerForPackageRemoval();
+ // TombstoneWatcher depends on DropboxManagerService.
+ // DropboxManagerService started before systemReady.
+ // So it is good to call startWatching here.
+ mWatcher.startWatching();
BootReceiver.initDropboxRateLimiter();
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java
index 897ee431..eb7c243 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerSession.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java
@@ -109,6 +109,7 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.PackageInfoFlags;
import android.content.pm.PackageManagerInternal;
+import android.content.pm.SharedLibraryInfo;
import android.content.pm.SigningDetails;
import android.content.pm.SigningInfo;
import android.content.pm.dex.DexMetadataHelper;
@@ -2880,19 +2881,38 @@
// since installation is in progress.
activate();
}
+ try {
+ List<PackageInstallerSession> children = getChildSessions();
+ if (isMultiPackage()) {
+ for (PackageInstallerSession child : children) {
+ child.prepareInheritedFiles();
+ child.parseApk();
+ }
+ } else {
+ prepareInheritedFiles();
+ parseApk();
+ }
+ } catch (PackageManagerException e) {
+ final String completeMsg = ExceptionUtils.getCompleteMessage(e);
+ final String errorMsg = PackageManager.installStatusToString(e.error, completeMsg);
+ setSessionFailed(e.error, errorMsg);
+ onSessionVerificationFailure(e.error, errorMsg);
+ }
if (Flags.verificationService()) {
final Supplier<Computer> snapshotSupplier = mPm::snapshotComputer;
if (mVerifierController.isVerifierInstalled(snapshotSupplier, userId)) {
- // TODO: extract shared library declarations
final SigningInfo signingInfo;
+ final List<SharedLibraryInfo> declaredLibraries;
synchronized (mLock) {
signingInfo = new SigningInfo(mSigningDetails);
+ declaredLibraries =
+ mPackageLite == null ? null : mPackageLite.getDeclaredLibraries();
}
// Send the request to the verifier and wait for its response before the rest of
// the installation can proceed.
if (!mVerifierController.startVerificationSession(snapshotSupplier, userId,
- sessionId, params.appPackageName, Uri.fromFile(stageDir), signingInfo,
- /* declaredLibraries= */null, /* extensionParams= */ null,
+ sessionId, getPackageName(), Uri.fromFile(stageDir), signingInfo,
+ declaredLibraries, /* extensionParams= */ null,
new VerifierCallback(), /* retry= */ false)) {
// A verifier is installed but cannot be connected. Installation disallowed.
onSessionVerificationFailure(INSTALL_FAILED_INTERNAL_ERROR,
@@ -2927,12 +2947,10 @@
List<PackageInstallerSession> children = getChildSessions();
if (isMultiPackage()) {
for (PackageInstallerSession child : children) {
- child.prepareInheritedFiles();
- child.parseApkAndExtractNativeLibraries();
+ child.extractNativeLibraries();
}
} else {
- prepareInheritedFiles();
- parseApkAndExtractNativeLibraries();
+ extractNativeLibraries();
}
verifyNonStaged();
} catch (PackageManagerException e) {
@@ -3109,7 +3127,7 @@
mStageDirInUse = true;
}
- private void parseApkAndExtractNativeLibraries() throws PackageManagerException {
+ private void parseApk() throws PackageManagerException {
synchronized (mLock) {
if (mStageDirInUse) {
throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
@@ -3142,12 +3160,16 @@
// stage dir here.
// Besides, PackageLite may be null for staged sessions that don't complete
// pre-reboot verification.
- result = getOrParsePackageLiteLocked(stageDir, /* flags */ 0);
+ mPackageLite = getOrParsePackageLiteLocked(stageDir, /* flags */ 0);
} else {
- result = getOrParsePackageLiteLocked(mResolvedBaseFile, /* flags */ 0);
+ mPackageLite = getOrParsePackageLiteLocked(mResolvedBaseFile, /* flags */ 0);
}
- if (result != null) {
- mPackageLite = result;
+ }
+ }
+
+ private void extractNativeLibraries() throws PackageManagerException {
+ synchronized (mLock) {
+ if (mPackageLite != null) {
if (!isApexSession()) {
synchronized (mProgressLock) {
mInternalProgress = 0.5f;
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index e47b4c2..ad5c840 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -731,7 +731,10 @@
KeyEvent.KEYCODE_ASSIST,
KeyEvent.KEYCODE_VOICE_ASSIST,
KeyEvent.KEYCODE_MUTE,
- KeyEvent.KEYCODE_VOLUME_MUTE
+ KeyEvent.KEYCODE_VOLUME_MUTE,
+ KeyEvent.KEYCODE_RECENT_APPS,
+ KeyEvent.KEYCODE_APP_SWITCH,
+ KeyEvent.KEYCODE_NOTIFICATION
));
private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
@@ -2082,12 +2085,21 @@
}
switch (mDoubleTapOnHomeBehavior) {
case DOUBLE_TAP_HOME_RECENT_SYSTEM_UI:
+ if (!isKeyEventForCurrentUser(
+ event.getDisplayId(), event.getKeyCode(), "toggleRecentApps")) {
+ break;
+ }
notifyKeyGestureCompleted(event,
KeyGestureEvent.KEY_GESTURE_TYPE_APP_SWITCH);
mHomeConsumed = true;
toggleRecentApps();
break;
case DOUBLE_TAP_HOME_PIP_MENU:
+ if (!isKeyEventForCurrentUser(
+ event.getDisplayId(), event.getKeyCode(),
+ "showPictureInPictureMenu")) {
+ break;
+ }
mHomeConsumed = true;
showPictureInPictureMenuInternal();
break;
@@ -2116,12 +2128,20 @@
}
break;
case LONG_PRESS_HOME_ASSIST:
+ if (!isKeyEventForCurrentUser(
+ event.getDisplayId(), event.getKeyCode(), "launchAssistAction")) {
+ break;
+ }
notifyKeyGestureCompleted(event,
KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT);
launchAssistAction(null, event.getDeviceId(), event.getEventTime(),
AssistUtils.INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS);
break;
case LONG_PRESS_HOME_NOTIFICATION_PANEL:
+ if (!isKeyEventForCurrentUser(
+ event.getDisplayId(), event.getKeyCode(), "toggleNotificationPanel")) {
+ break;
+ }
notifyKeyGestureCompleted(event,
KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL);
toggleNotificationPanel();
@@ -3497,7 +3517,11 @@
if (isUserSetupComplete() && !keyguardOn) {
if (mModifierShortcutManager.interceptKey(event)) {
- dismissKeyboardShortcutsMenu();
+ if (isKeyEventForCurrentUser(
+ event.getDisplayId(), event.getKeyCode(),
+ "dismissKeyboardShortcutsMenu")) {
+ dismissKeyboardShortcutsMenu();
+ }
mPendingMetaAction = false;
mPendingCapsLockToggle = false;
return true;
@@ -4820,7 +4844,10 @@
}
// no keyguard stuff to worry about, just launch home!
- if (mRecentsVisible) {
+ // If Recents is visible and the action is not from visible background users,
+ // hide Recents and notify it to launch Home.
+ if (mRecentsVisible
+ && (!mVisibleBackgroundUsersEnabled || displayId == DEFAULT_DISPLAY)) {
try {
ActivityManager.getService().stopAppSwitches();
} catch (RemoteException e) {}
@@ -5570,6 +5597,9 @@
* Notify the StatusBar that a system key was pressed.
*/
private void sendSystemKeyToStatusBar(KeyEvent key) {
+ if (!isKeyEventForCurrentUser(key.getDisplayId(), key.getKeyCode(), "handleSystemKey")) {
+ return;
+ }
IStatusBarService statusBar = getStatusBarService();
if (statusBar != null) {
try {
diff --git a/services/core/java/com/android/server/search/SearchManagerService.java b/services/core/java/com/android/server/search/SearchManagerService.java
index 9b39fa1..a49a9fd 100644
--- a/services/core/java/com/android/server/search/SearchManagerService.java
+++ b/services/core/java/com/android/server/search/SearchManagerService.java
@@ -46,6 +46,7 @@
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.SystemService.TargetUser;
+import com.android.server.pm.UserManagerInternal;
import com.android.server.statusbar.StatusBarManagerInternal;
import java.io.FileDescriptor;
@@ -89,6 +90,8 @@
@GuardedBy("mSearchables")
private final SparseArray<Searchables> mSearchables = new SparseArray<>();
+ private final UserManagerInternal mUserManagerInternal;
+
/**
* Initializes the Search Manager service in the provided system context.
* Only one instance of this object should be created!
@@ -101,6 +104,7 @@
mMyPackageMonitor.register(context, null, UserHandle.ALL, true);
new GlobalSearchProviderObserver(context.getContentResolver());
mHandler = BackgroundThread.getHandler();
+ mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
}
private Searchables getSearchables(int userId) {
@@ -336,6 +340,14 @@
@Override
public void launchAssist(int userHandle, Bundle args) {
+ // Currently, visible background users are not allowed to launch assist.(b/332222893)
+ // TODO(b/368715893): Consider indirect calls from system service when checking the
+ // calling user.
+ final int callingUserId = UserHandle.getCallingUserId();
+ if (mUserManagerInternal.isVisibleBackgroundFullUser(callingUserId)) {
+ throw new SecurityException("Visible background user(u" + callingUserId
+ + ") is not permitted to launch assist.");
+ }
StatusBarManagerInternal statusBarManager =
LocalServices.getService(StatusBarManagerInternal.class);
if (statusBarManager != null) {
diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java
index 1659f7b..585537b 100644
--- a/services/core/java/com/android/server/wm/Transition.java
+++ b/services/core/java/com/android/server/wm/Transition.java
@@ -547,13 +547,12 @@
if (!ar.isVisible() || !ar.isVisibleRequested()) return;
if (mConfigAtEndActivities == null) {
mConfigAtEndActivities = new ArrayList<>();
- }
- if (mConfigAtEndActivities.contains(ar)) {
+ } else if (mConfigAtEndActivities.contains(ar)) {
return;
}
mConfigAtEndActivities.add(ar);
ar.pauseConfigurationDispatch();
- snapshotStartState(ar);
+ collect(ar);
mChanges.get(ar).mFlags |= ChangeInfo.FLAG_CHANGE_CONFIG_AT_END;
});
}
@@ -1705,54 +1704,6 @@
change.mFlags |= ChangeInfo.FLAG_CHANGE_NO_ANIMATION;
}
- void prepareConfigAtEnd(SurfaceControl.Transaction transact, ArrayList<ChangeInfo> targets) {
- if (mConfigAtEndActivities == null) return;
- for (int i = 0; i < mConfigAtEndActivities.size(); ++i) {
- final ActivityRecord ar = mConfigAtEndActivities.get(i);
- if (!ar.isVisibleRequested()) continue;
- final SurfaceControl sc = ar.getSurfaceControl();
- if (sc == null) continue;
- final Task task = ar.getTask();
- if (task == null) continue;
- // If task isn't animating, then it means shell is animating activity directly (within
- // task), so don't do any setup.
- if (!containsChangeFor(task, targets)) continue;
- final ChangeInfo change = mChanges.get(ar);
- final Rect startBounds = change.mAbsoluteBounds;
- Rect hintRect = null;
- if (ar.getWindowingMode() == WINDOWING_MODE_PINNED && ar.pictureInPictureArgs != null
- && ar.pictureInPictureArgs.getSourceRectHint() != null) {
- hintRect = ar.pictureInPictureArgs.getSourceRectHint();
- }
- if (hintRect == null) {
- hintRect = new Rect(startBounds);
- hintRect.offsetTo(0, 0);
- }
- final Rect endBounds = ar.getBounds();
- final Rect taskEndBounds = task.getBounds();
- // FA = final activity bounds (absolute)
- // FT = final task bounds (absolute)
- // SA = start activity bounds (absolute)
- // H = source hint (relative to start activity bounds)
- // We want to transform the activity so that when the task is at FT, H overlaps with FA
-
- // This scales the activity such that the hint rect has the same dimensions
- // as the final activity bounds.
- float hintToEndScaleX = ((float) endBounds.width()) / ((float) hintRect.width());
- float hintToEndScaleY = ((float) endBounds.height()) / ((float) hintRect.height());
- // top-left needs to be (FA.tl - FT.tl) - H.tl * hintToEnd . H is relative to the
- // activity; so, for example, if shrinking H to FA (hintToEnd < 1), then the tl of the
- // shrunk SA is closer to H than expected, so we need to reduce how much we offset SA
- // to get H.tl to match.
- float startActPosInTaskEndX =
- (endBounds.left - taskEndBounds.left) - hintRect.left * hintToEndScaleX;
- float startActPosInTaskEndY =
- (endBounds.top - taskEndBounds.top) - hintRect.top * hintToEndScaleY;
- transact.setScale(sc, hintToEndScaleX, hintToEndScaleY);
- transact.setPosition(sc, startActPosInTaskEndX, startActPosInTaskEndY);
- }
- }
-
static boolean containsChangeFor(WindowContainer wc, ArrayList<ChangeInfo> list) {
for (int i = list.size() - 1; i >= 0; --i) {
if (list.get(i).mContainer == wc) return true;
@@ -1833,7 +1784,6 @@
// Resolve the animating targets from the participants.
mTargets = calculateTargets(mParticipants, mChanges);
- prepareConfigAtEnd(transaction, mTargets);
// Check whether the participants were animated from back navigation.
mController.mAtm.mBackNavigationController.onTransactionReady(this, mTargets,
@@ -2669,6 +2619,11 @@
if (reportIfNotTop(target)) {
ProtoLog.v(WmProtoLogGroups.WM_DEBUG_WINDOW_TRANSITIONS,
" keep as target %s", target);
+ } else if ((targetChange.mFlags & ChangeInfo.FLAG_CHANGE_CONFIG_AT_END) != 0) {
+ // config-at-end activities do not match the end-state, so they should be treated
+ // as independent.
+ ProtoLog.v(WmProtoLogGroups.WM_DEBUG_WINDOW_TRANSITIONS,
+ " keep as cfg-at-end target %s", target);
} else {
ProtoLog.v(WmProtoLogGroups.WM_DEBUG_WINDOW_TRANSITIONS,
" remove from targets %s", target);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 2be999f..7e450dd 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -11874,75 +11874,51 @@
throw new IllegalArgumentException("Invalid package name: " + validationResult);
}
- if (Flags.setApplicationRestrictionsCoexistence()) {
- EnforcingAdmin enforcingAdmin = enforcePermissionAndGetEnforcingAdmin(
- who,
- MANAGE_DEVICE_POLICY_APP_RESTRICTIONS,
- caller.getPackageName(),
- caller.getUserId()
- );
-
+ final boolean isRoleHolder;
+ if (who != null) {
+ // DO or PO
+ Preconditions.checkCallAuthorization(
+ (isProfileOwner(caller) || isDefaultDeviceOwner(caller)));
+ Preconditions.checkCallAuthorization(!parent,
+ "DO or PO cannot call this on parent");
+ // Caller has opted to be treated as DPC (by passing a non-null who), so don't
+ // consider it as the DMRH, even if the caller is both the DPC and the DMRH.
+ isRoleHolder = false;
+ } else {
+ // Delegates, or the DMRH. Only DMRH can call this on COPE parent
+ isRoleHolder = isCallerDevicePolicyManagementRoleHolder(caller);
+ if (parent) {
+ Preconditions.checkCallAuthorization(isRoleHolder);
+ Preconditions.checkState(isOrganizationOwnedDeviceWithManagedProfile(),
+ "Role Holder can only operate parent app restriction on COPE devices");
+ } else {
+ Preconditions.checkCallAuthorization(isRoleHolder
+ || isCallerDelegate(caller, DELEGATION_APP_RESTRICTIONS));
+ }
+ }
+ // DMRH caller uses policy engine, others still use legacy code path
+ if (isRoleHolder) {
+ EnforcingAdmin enforcingAdmin = getEnforcingAdminForCaller(/* who */ null,
+ caller.getPackageName());
+ int affectedUserId = parent
+ ? getProfileParentId(caller.getUserId()) : caller.getUserId();
if (restrictions == null || restrictions.isEmpty()) {
mDevicePolicyEngine.removeLocalPolicy(
PolicyDefinition.APPLICATION_RESTRICTIONS(packageName),
enforcingAdmin,
- caller.getUserId());
+ affectedUserId);
} else {
mDevicePolicyEngine.setLocalPolicy(
PolicyDefinition.APPLICATION_RESTRICTIONS(packageName),
enforcingAdmin,
new BundlePolicyValue(restrictions),
- caller.getUserId());
+ affectedUserId);
}
- setBackwardsCompatibleAppRestrictions(
- caller, packageName, restrictions, caller.getUserHandle());
} else {
- final boolean isRoleHolder;
- if (who != null) {
- // DO or PO
- Preconditions.checkCallAuthorization(
- (isProfileOwner(caller) || isDefaultDeviceOwner(caller)));
- Preconditions.checkCallAuthorization(!parent,
- "DO or PO cannot call this on parent");
- // Caller has opted to be treated as DPC (by passing a non-null who), so don't
- // consider it as the DMRH, even if the caller is both the DPC and the DMRH.
- isRoleHolder = false;
- } else {
- // Delegates, or the DMRH. Only DMRH can call this on COPE parent
- isRoleHolder = isCallerDevicePolicyManagementRoleHolder(caller);
- if (parent) {
- Preconditions.checkCallAuthorization(isRoleHolder);
- Preconditions.checkState(isOrganizationOwnedDeviceWithManagedProfile(),
- "Role Holder can only operate parent app restriction on COPE devices");
- } else {
- Preconditions.checkCallAuthorization(isRoleHolder
- || isCallerDelegate(caller, DELEGATION_APP_RESTRICTIONS));
- }
- }
- // DMRH caller uses policy engine, others still use legacy code path
- if (isRoleHolder) {
- EnforcingAdmin enforcingAdmin = getEnforcingAdminForCaller(/* who */ null,
- caller.getPackageName());
- int affectedUserId = parent
- ? getProfileParentId(caller.getUserId()) : caller.getUserId();
- if (restrictions == null || restrictions.isEmpty()) {
- mDevicePolicyEngine.removeLocalPolicy(
- PolicyDefinition.APPLICATION_RESTRICTIONS(packageName),
- enforcingAdmin,
- affectedUserId);
- } else {
- mDevicePolicyEngine.setLocalPolicy(
- PolicyDefinition.APPLICATION_RESTRICTIONS(packageName),
- enforcingAdmin,
- new BundlePolicyValue(restrictions),
- affectedUserId);
- }
- } else {
- mInjector.binderWithCleanCallingIdentity(() -> {
- mUserManager.setApplicationRestrictions(packageName, restrictions,
- caller.getUserHandle());
- });
- }
+ mInjector.binderWithCleanCallingIdentity(() -> {
+ mUserManager.setApplicationRestrictions(packageName, restrictions,
+ caller.getUserHandle());
+ });
}
DevicePolicyEventLogger
@@ -11953,31 +11929,6 @@
.write();
}
- /**
- * Set app restrictions in user manager for DPC callers only to keep backwards compatibility
- * for the old getApplicationRestrictions API.
- */
- private void setBackwardsCompatibleAppRestrictions(
- CallerIdentity caller, String packageName, Bundle restrictions, UserHandle userHandle) {
- if ((caller.hasAdminComponent() && (isProfileOwner(caller) || isDefaultDeviceOwner(caller)))
- || (caller.hasPackage() && isCallerDelegate(caller, DELEGATION_APP_RESTRICTIONS))) {
- Bundle restrictionsToApply = restrictions == null || restrictions.isEmpty()
- ? getAppRestrictionsSetByAnyAdmin(packageName, userHandle)
- : restrictions;
- mInjector.binderWithCleanCallingIdentity(() -> {
- mUserManager.setApplicationRestrictions(packageName, restrictionsToApply,
- userHandle);
- });
- } else {
- // Notify package of changes via an intent - only sent to explicitly registered
- // receivers. Sending here because For DPCs, this is being sent in UMS.
- final Intent changeIntent = new Intent(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
- changeIntent.setPackage(packageName);
- changeIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
- mContext.sendBroadcastAsUser(changeIntent, userHandle);
- }
- }
-
private Bundle getAppRestrictionsSetByAnyAdmin(String packageName, UserHandle userHandle) {
LinkedHashMap<EnforcingAdmin, PolicyValue<Bundle>> policies =
mDevicePolicyEngine.getLocalPoliciesSetByAdmins(
@@ -13257,68 +13208,47 @@
String packageName, boolean parent) {
final CallerIdentity caller = getCallerIdentity(who, callerPackage);
- // IMPORTANT: The code behind the if branch is OUTDATED and requires additional work before
- // enabling the feature flag below.
- // TODO(b/369141952): Update DPM.getApplicationRestrictions coexistence code
- if (Flags.setApplicationRestrictionsCoexistence()) {
- EnforcingAdmin enforcingAdmin = enforceCanQueryAndGetEnforcingAdmin(
- who,
- MANAGE_DEVICE_POLICY_APP_RESTRICTIONS,
- caller.getPackageName(),
- caller.getUserId()
- );
-
+ final boolean isRoleHolder;
+ if (who != null) {
+ // Caller is DO or PO. They cannot call this on parent
+ Preconditions.checkCallAuthorization(!parent
+ && (isProfileOwner(caller) || isDefaultDeviceOwner(caller)));
+ // Caller has opted to be treated as DPC (by passing a non-null who), so don't
+ // consider it as the DMRH, even if the caller is both the DPC and the DMRH.
+ isRoleHolder = false;
+ } else {
+ // Caller is delegates or the DMRH. Only DMRH can call this on parent
+ isRoleHolder = isCallerDevicePolicyManagementRoleHolder(caller);
+ if (parent) {
+ Preconditions.checkCallAuthorization(isRoleHolder);
+ Preconditions.checkState(isOrganizationOwnedDeviceWithManagedProfile(),
+ "Role Holder can only operate parent app restriction on COPE devices");
+ } else {
+ Preconditions.checkCallAuthorization(isRoleHolder
+ || isCallerDelegate(caller, DELEGATION_APP_RESTRICTIONS));
+ }
+ }
+ if (isRoleHolder) {
+ EnforcingAdmin enforcingAdmin = getEnforcingAdminForCaller(/* who */ null,
+ caller.getPackageName());
+ int affectedUserId = parent
+ ? getProfileParentId(caller.getUserId()) : caller.getUserId();
LinkedHashMap<EnforcingAdmin, PolicyValue<Bundle>> policies =
mDevicePolicyEngine.getLocalPoliciesSetByAdmins(
PolicyDefinition.APPLICATION_RESTRICTIONS(packageName),
- caller.getUserId());
- if (policies.isEmpty() || !policies.containsKey(enforcingAdmin)) {
+ affectedUserId);
+ if (!policies.containsKey(enforcingAdmin)) {
return Bundle.EMPTY;
}
return policies.get(enforcingAdmin).getValue();
} else {
- final boolean isRoleHolder;
- if (who != null) {
- // Caller is DO or PO. They cannot call this on parent
- Preconditions.checkCallAuthorization(!parent
- && (isProfileOwner(caller) || isDefaultDeviceOwner(caller)));
- // Caller has opted to be treated as DPC (by passing a non-null who), so don't
- // consider it as the DMRH, even if the caller is both the DPC and the DMRH.
- isRoleHolder = false;
- } else {
- // Caller is delegates or the DMRH. Only DMRH can call this on parent
- isRoleHolder = isCallerDevicePolicyManagementRoleHolder(caller);
- if (parent) {
- Preconditions.checkCallAuthorization(isRoleHolder);
- Preconditions.checkState(isOrganizationOwnedDeviceWithManagedProfile(),
- "Role Holder can only operate parent app restriction on COPE devices");
- } else {
- Preconditions.checkCallAuthorization(isRoleHolder
- || isCallerDelegate(caller, DELEGATION_APP_RESTRICTIONS));
- }
- }
- if (isRoleHolder) {
- EnforcingAdmin enforcingAdmin = getEnforcingAdminForCaller(/* who */ null,
- caller.getPackageName());
- int affectedUserId = parent
- ? getProfileParentId(caller.getUserId()) : caller.getUserId();
- LinkedHashMap<EnforcingAdmin, PolicyValue<Bundle>> policies =
- mDevicePolicyEngine.getLocalPoliciesSetByAdmins(
- PolicyDefinition.APPLICATION_RESTRICTIONS(packageName),
- affectedUserId);
- if (!policies.containsKey(enforcingAdmin)) {
- return Bundle.EMPTY;
- }
- return policies.get(enforcingAdmin).getValue();
- } else {
- return mInjector.binderWithCleanCallingIdentity(() -> {
- Bundle bundle = mUserManager.getApplicationRestrictions(packageName,
- caller.getUserHandle());
- // if no restrictions were saved, mUserManager.getApplicationRestrictions
- // returns null, but DPM method should return an empty Bundle as per JavaDoc
- return bundle != null ? bundle : Bundle.EMPTY;
- });
- }
+ return mInjector.binderWithCleanCallingIdentity(() -> {
+ Bundle bundle = mUserManager.getApplicationRestrictions(packageName,
+ caller.getUserHandle());
+ // if no restrictions were saved, mUserManager.getApplicationRestrictions
+ // returns null, but DPM method should return an empty Bundle as per JavaDoc
+ return bundle != null ? bundle : Bundle.EMPTY;
+ });
}
}
diff --git a/services/tests/appfunctions/src/com/android/server/appfunctions/MetadataSyncAdapterTest.kt b/services/tests/appfunctions/src/com/android/server/appfunctions/MetadataSyncAdapterTest.kt
index bc64e15..5758da8 100644
--- a/services/tests/appfunctions/src/com/android/server/appfunctions/MetadataSyncAdapterTest.kt
+++ b/services/tests/appfunctions/src/com/android/server/appfunctions/MetadataSyncAdapterTest.kt
@@ -34,7 +34,6 @@
import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import com.android.internal.infra.AndroidFuture
-import com.android.server.appfunctions.FutureAppSearchSession.FutureSearchResults
import com.google.common.truth.Truth.assertThat
import java.util.concurrent.atomic.AtomicBoolean
import org.junit.Test
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/MouseKeysInterceptorTest.kt b/services/tests/servicestests/src/com/android/server/accessibility/MouseKeysInterceptorTest.kt
index c76392b..5134737 100644
--- a/services/tests/servicestests/src/com/android/server/accessibility/MouseKeysInterceptorTest.kt
+++ b/services/tests/servicestests/src/com/android/server/accessibility/MouseKeysInterceptorTest.kt
@@ -236,6 +236,27 @@
}
@Test
+ fun whenScrollToggleOn_ScrollRightKeyIsPressed_scrollEventIsSent() {
+ // There should be some delay between the downTime of the key event and calling onKeyEvent
+ val downTime = clock.now() - KEYBOARD_POST_EVENT_DELAY_MILLIS
+ val keyCodeScrollToggle = MouseKeysInterceptor.MouseKeyEvent.SCROLL_TOGGLE.keyCodeValue
+ val keyCodeScroll = MouseKeysInterceptor.MouseKeyEvent.RIGHT_MOVE_OR_SCROLL.keyCodeValue
+
+ val scrollToggleDownEvent = KeyEvent(downTime, downTime, KeyEvent.ACTION_DOWN,
+ keyCodeScrollToggle, 0, 0, DEVICE_ID, 0)
+ val scrollDownEvent = KeyEvent(downTime, downTime, KeyEvent.ACTION_DOWN,
+ keyCodeScroll, 0, 0, DEVICE_ID, 0)
+
+ mouseKeysInterceptor.onKeyEvent(scrollToggleDownEvent, 0)
+ mouseKeysInterceptor.onKeyEvent(scrollDownEvent, 0)
+ testLooper.dispatchAll()
+
+ // Verify the sendScrollEvent method is called once and capture the arguments
+ verifyScrollEvents(arrayOf<Float>(-MouseKeysInterceptor.MOUSE_SCROLL_STEP),
+ arrayOf<Float>(0f))
+ }
+
+ @Test
fun whenScrollToggleOff_DirectionalUpKeyIsPressed_RelativeEventIsSent() {
// There should be some delay between the downTime of the key event and calling onKeyEvent
val downTime = clock.now() - KEYBOARD_POST_EVENT_DELAY_MILLIS
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/magnification/MagnificationConnectionManagerTest.java b/services/tests/servicestests/src/com/android/server/accessibility/magnification/MagnificationConnectionManagerTest.java
index 6aa8a32..06ebe6e 100644
--- a/services/tests/servicestests/src/com/android/server/accessibility/magnification/MagnificationConnectionManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/accessibility/magnification/MagnificationConnectionManagerTest.java
@@ -62,6 +62,7 @@
import com.android.internal.util.test.FakeSettingsProvider;
import com.android.server.LocalServices;
import com.android.server.accessibility.AccessibilityTraceManager;
+import com.android.server.pm.UserManagerInternal;
import com.android.server.statusbar.StatusBarManagerInternal;
import org.junit.Before;
@@ -92,12 +93,16 @@
private MagnificationConnectionManager.Callback mMockCallback;
private MockContentResolver mResolver;
private MagnificationConnectionManager mMagnificationConnectionManager;
+ @Mock
+ private UserManagerInternal mMockUserManagerInternal;
@Before
public void setUp() throws RemoteException {
MockitoAnnotations.initMocks(this);
LocalServices.removeServiceForTest(StatusBarManagerInternal.class);
+ LocalServices.removeServiceForTest(UserManagerInternal.class);
LocalServices.addService(StatusBarManagerInternal.class, mMockStatusBarManagerInternal);
+ LocalServices.addService(UserManagerInternal.class, mMockUserManagerInternal);
mResolver = new MockContentResolver();
mMockConnection = new MockMagnificationConnection();
mMagnificationConnectionManager = new MagnificationConnectionManager(mContext, new Object(),
@@ -110,6 +115,8 @@
Settings.Secure.putFloatForUser(mResolver,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 2.5f,
CURRENT_USER_ID);
+
+ when(mMockUserManagerInternal.isVisibleBackgroundFullUser(anyInt())).thenReturn(false);
}
private void stubSetConnection(boolean needDelay) {
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationListenersTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationListenersTest.java
index 983e694..b34b1fb 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationListenersTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationListenersTest.java
@@ -835,7 +835,7 @@
}
@Test
- public void testListenerPost_UpdateLifetimeExtended() throws Exception {
+ public void testListenerPostLifetimeExtended_UpdatesOnlySysui() throws Exception {
mSetFlagsRule.enableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR);
// Create original notification, with FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY.
@@ -856,31 +856,51 @@
Notification.Builder nb2 = new Notification.Builder(mContext, channel.getId())
.setContentTitle("new title")
.setSmallIcon(android.R.drawable.sym_def_app_icon)
- .setFlag(Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, false);
+ .setFlag(Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, true);
StatusBarNotification sbn2 = new StatusBarNotification(pkg, pkg, 8, "tag", uid, 0,
nb2.build(), userHandle, null, 0);
NotificationRecord toPost = new NotificationRecord(mContext, sbn2, channel);
// Create system ui-like service.
- ManagedServices.ManagedServiceInfo info = mListeners.new ManagedServiceInfo(
+ ManagedServices.ManagedServiceInfo sysuiInfo = mListeners.new ManagedServiceInfo(
null, new ComponentName("a", "a"), sbn2.getUserId(), false, null, 33, 33);
- info.isSystemUi = true;
- INotificationListener l1 = mock(INotificationListener.class);
- info.service = l1;
- List<ManagedServices.ManagedServiceInfo> services = ImmutableList.of(info);
+ sysuiInfo.isSystemUi = true;
+ INotificationListener sysuiListener = mock(INotificationListener.class);
+ sysuiInfo.service = sysuiListener;
+
+ // Create two non-system ui-like services.
+ ManagedServices.ManagedServiceInfo otherInfo1 = mListeners.new ManagedServiceInfo(
+ null, new ComponentName("b", "b"), sbn2.getUserId(), false, null, 33, 33);
+ otherInfo1.isSystemUi = false;
+ INotificationListener otherListener1 = mock(INotificationListener.class);
+ otherInfo1.service = otherListener1;
+
+ ManagedServices.ManagedServiceInfo otherInfo2 = mListeners.new ManagedServiceInfo(
+ null, new ComponentName("c", "c"), sbn2.getUserId(), false, null, 33, 33);
+ otherInfo2.isSystemUi = false;
+ INotificationListener otherListener2 = mock(INotificationListener.class);
+ otherInfo2.service = otherListener2;
+
+ List<ManagedServices.ManagedServiceInfo> services = ImmutableList.of(otherInfo1, sysuiInfo,
+ otherInfo2);
when(mListeners.getServices()).thenReturn(services);
FieldSetter.setField(mNm,
NotificationManagerService.class.getDeclaredField("mHandler"),
mock(NotificationManagerService.WorkerHandler.class));
doReturn(true).when(mNm).isVisibleToListener(any(), anyInt(), any());
- doReturn(mock(NotificationRankingUpdate.class)).when(mNm).makeRankingUpdateLocked(info);
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(sysuiInfo);
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(otherInfo1);
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(otherInfo2);
doReturn(false).when(mNm).isInLockDownMode(anyInt());
doNothing().when(mNm).updateUriPermissions(any(), any(), any(), anyInt());
doReturn(sbn2).when(mListeners).redactStatusBarNotification(sbn2);
doReturn(sbn2).when(mListeners).redactStatusBarNotification(any());
- // The notification change is posted to the service listener.
+ // Post notification change to the service listeners.
mListeners.notifyPostedLocked(toPost, old);
// Verify that the post occcurs with the updated notification value.
@@ -889,11 +909,190 @@
runnableCaptor.getValue().run();
ArgumentCaptor<IStatusBarNotificationHolder> sbnCaptor =
ArgumentCaptor.forClass(IStatusBarNotificationHolder.class);
- verify(l1, times(1)).onNotificationPosted(sbnCaptor.capture(), any());
+ verify(sysuiListener, times(1)).onNotificationPosted(sbnCaptor.capture(), any());
StatusBarNotification sbnResult = sbnCaptor.getValue().get();
assertThat(sbnResult.getNotification()
.extras.getCharSequence(Notification.EXTRA_TITLE).toString())
.isEqualTo("new title");
+
+ verify(otherListener1, never()).onNotificationPosted(any(), any());
+ verify(otherListener2, never()).onNotificationPosted(any(), any());
+ }
+
+ @Test
+ public void testListenerPostLifeimteExtension_postsToAppropriateListeners() throws Exception {
+ mSetFlagsRule.enableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR);
+
+ // Create original notification, with FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY.
+ String pkg = "pkg";
+ int uid = 9;
+ UserHandle userHandle = UserHandle.getUserHandleForUid(uid);
+ NotificationChannel channel = new NotificationChannel("id", "name",
+ NotificationManager.IMPORTANCE_HIGH);
+ Notification.Builder nb = new Notification.Builder(mContext, channel.getId())
+ .setContentTitle("foo")
+ .setSmallIcon(android.R.drawable.sym_def_app_icon)
+ .setFlag(Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, true);
+ StatusBarNotification sbn = new StatusBarNotification(pkg, pkg, 8, "tag", uid, 0,
+ nb.build(), userHandle, null, 0);
+ NotificationRecord leRecord = new NotificationRecord(mContext, sbn, channel);
+
+ // Creates updated notification (without FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY)
+ Notification.Builder nb2 = new Notification.Builder(mContext, channel.getId())
+ .setContentTitle("new title")
+ .setSmallIcon(android.R.drawable.sym_def_app_icon)
+ .setFlag(Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, false);
+ StatusBarNotification sbn2 = new StatusBarNotification(pkg, pkg, 8, "tag", uid, 0,
+ nb2.build(), userHandle, null, 0);
+ NotificationRecord nonLeRecord = new NotificationRecord(mContext, sbn2, channel);
+
+ // Create system ui-like service.
+ ManagedServices.ManagedServiceInfo sysuiInfo = mListeners.new ManagedServiceInfo(
+ null, new ComponentName("a", "a"), sbn2.getUserId(), false, null, 33, 33);
+ sysuiInfo.isSystemUi = true;
+ INotificationListener sysuiListener = mock(INotificationListener.class);
+ sysuiInfo.service = sysuiListener;
+
+ // Create two non-system ui-like services.
+ ManagedServices.ManagedServiceInfo otherInfo1 = mListeners.new ManagedServiceInfo(
+ null, new ComponentName("b", "b"), sbn2.getUserId(), false, null, 33, 33);
+ otherInfo1.isSystemUi = false;
+ INotificationListener otherListener1 = mock(INotificationListener.class);
+ otherInfo1.service = otherListener1;
+
+ ManagedServices.ManagedServiceInfo otherInfo2 = mListeners.new ManagedServiceInfo(
+ null, new ComponentName("c", "c"), sbn2.getUserId(), false, null, 33, 33);
+ otherInfo2.isSystemUi = false;
+ INotificationListener otherListener2 = mock(INotificationListener.class);
+ otherInfo2.service = otherListener2;
+
+ List<ManagedServices.ManagedServiceInfo> services = ImmutableList.of(otherInfo1, sysuiInfo,
+ otherInfo2);
+ when(mListeners.getServices()).thenReturn(services);
+
+ FieldSetter.setField(mNm,
+ NotificationManagerService.class.getDeclaredField("mHandler"),
+ mock(NotificationManagerService.WorkerHandler.class));
+ doReturn(true).when(mNm).isVisibleToListener(any(), anyInt(), any());
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(sysuiInfo);
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(otherInfo1);
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(otherInfo2);
+ doReturn(false).when(mNm).isInLockDownMode(anyInt());
+ doNothing().when(mNm).updateUriPermissions(any(), any(), any(), anyInt());
+ doReturn(sbn2).when(mListeners).redactStatusBarNotification(sbn2);
+ doReturn(sbn2).when(mListeners).redactStatusBarNotification(any());
+
+ // The notification change is posted to the service listener.
+ // NonLE to LE should never happen, as LE can't be set in an update by the app.
+ // So we just want to test LE to NonLE.
+ mListeners.notifyPostedLocked(nonLeRecord /*=toPost*/, leRecord /*=old*/);
+
+ // Verify that the post occcurs with the updated notification value.
+ ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
+ verify(mNm.mHandler, times(3)).post(runnableCaptor.capture());
+ List<Runnable> capturedRunnable = runnableCaptor.getAllValues();
+ for (Runnable r : capturedRunnable) {
+ r.run();
+ }
+
+ ArgumentCaptor<IStatusBarNotificationHolder> sbnCaptor =
+ ArgumentCaptor.forClass(IStatusBarNotificationHolder.class);
+ verify(sysuiListener, times(1)).onNotificationPosted(sbnCaptor.capture(), any());
+ StatusBarNotification sbnResult = sbnCaptor.getValue().get();
+ assertThat(sbnResult.getNotification()
+ .extras.getCharSequence(Notification.EXTRA_TITLE).toString())
+ .isEqualTo("new title");
+
+ verify(otherListener1, times(1)).onNotificationPosted(any(), any());
+ verify(otherListener2, times(1)).onNotificationPosted(any(), any());
+ }
+
+ @Test
+ public void testNotifyPostedLocked_postsToAppropriateListeners() throws Exception {
+ // Create original notification
+ String pkg = "pkg";
+ int uid = 9;
+ UserHandle userHandle = UserHandle.getUserHandleForUid(uid);
+ NotificationChannel channel = new NotificationChannel("id", "name",
+ NotificationManager.IMPORTANCE_HIGH);
+ Notification.Builder nb = new Notification.Builder(mContext, channel.getId())
+ .setContentTitle("foo")
+ .setSmallIcon(android.R.drawable.sym_def_app_icon);
+ StatusBarNotification sbn = new StatusBarNotification(pkg, pkg, 8, "tag", uid, 0,
+ nb.build(), userHandle, null, 0);
+ NotificationRecord oldRecord = new NotificationRecord(mContext, sbn, channel);
+
+ // Creates updated notification
+ Notification.Builder nb2 = new Notification.Builder(mContext, channel.getId())
+ .setContentTitle("new title")
+ .setSmallIcon(android.R.drawable.sym_def_app_icon);
+ StatusBarNotification sbn2 = new StatusBarNotification(pkg, pkg, 8, "tag", uid, 0,
+ nb2.build(), userHandle, null, 0);
+ NotificationRecord newRecord = new NotificationRecord(mContext, sbn2, channel);
+
+ // Create system ui-like service.
+ ManagedServices.ManagedServiceInfo sysuiInfo = mListeners.new ManagedServiceInfo(
+ null, new ComponentName("a", "a"), sbn2.getUserId(), false, null, 33, 33);
+ sysuiInfo.isSystemUi = true;
+ INotificationListener sysuiListener = mock(INotificationListener.class);
+ sysuiInfo.service = sysuiListener;
+
+ // Create two non-system ui-like services.
+ ManagedServices.ManagedServiceInfo otherInfo1 = mListeners.new ManagedServiceInfo(
+ null, new ComponentName("b", "b"), sbn2.getUserId(), false, null, 33, 33);
+ otherInfo1.isSystemUi = false;
+ INotificationListener otherListener1 = mock(INotificationListener.class);
+ otherInfo1.service = otherListener1;
+
+ ManagedServices.ManagedServiceInfo otherInfo2 = mListeners.new ManagedServiceInfo(
+ null, new ComponentName("c", "c"), sbn2.getUserId(), false, null, 33, 33);
+ otherInfo2.isSystemUi = false;
+ INotificationListener otherListener2 = mock(INotificationListener.class);
+ otherInfo2.service = otherListener2;
+
+ List<ManagedServices.ManagedServiceInfo> services = ImmutableList.of(otherInfo1, sysuiInfo,
+ otherInfo2);
+ when(mListeners.getServices()).thenReturn(services);
+
+ FieldSetter.setField(mNm,
+ NotificationManagerService.class.getDeclaredField("mHandler"),
+ mock(NotificationManagerService.WorkerHandler.class));
+ doReturn(true).when(mNm).isVisibleToListener(any(), anyInt(), any());
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(sysuiInfo);
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(otherInfo1);
+ doReturn(mock(NotificationRankingUpdate.class)).when(mNm)
+ .makeRankingUpdateLocked(otherInfo2);
+ doReturn(false).when(mNm).isInLockDownMode(anyInt());
+ doNothing().when(mNm).updateUriPermissions(any(), any(), any(), anyInt());
+ doReturn(sbn2).when(mListeners).redactStatusBarNotification(sbn2);
+ doReturn(sbn2).when(mListeners).redactStatusBarNotification(any());
+
+ // The notification change is posted to the service listeners.
+ mListeners.notifyPostedLocked(newRecord, oldRecord);
+
+ // Verify that the post occcurs with the updated notification value.
+ ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
+ verify(mNm.mHandler, times(3)).post(runnableCaptor.capture());
+ List<Runnable> capturedRunnable = runnableCaptor.getAllValues();
+ for (Runnable r : capturedRunnable) {
+ r.run();
+ }
+
+ ArgumentCaptor<IStatusBarNotificationHolder> sbnCaptor =
+ ArgumentCaptor.forClass(IStatusBarNotificationHolder.class);
+ verify(sysuiListener, times(1)).onNotificationPosted(sbnCaptor.capture(), any());
+ StatusBarNotification sbnResult = sbnCaptor.getValue().get();
+ assertThat(sbnResult.getNotification()
+ .extras.getCharSequence(Notification.EXTRA_TITLE).toString())
+ .isEqualTo("new title");
+
+ verify(otherListener1, times(1)).onNotificationPosted(any(), any());
+ verify(otherListener2, times(1)).onNotificationPosted(any(), any());
}
/**
diff --git a/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java
index 5b3fd53..7196acc 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java
@@ -2933,6 +2933,11 @@
controller.requestStartTransition(transit, task, null, null);
player.start();
+ // always include config-at-end activity since it is considered "independent" due to
+ // changing at a different time.
+ assertTrue(player.mLastReady.getChanges().stream()
+ .anyMatch((change -> change.getActivityComponent() != null
+ && (change.getFlags() & TransitionInfo.FLAG_CONFIG_AT_END) != 0)));
assertTrue(activity.isConfigurationDispatchPaused());
player.finish();
assertFalse(activity.isConfigurationDispatchPaused());
@@ -2962,6 +2967,11 @@
controller.requestStartTransition(transit, task, null, null);
player.start();
+ // always include config-at-end activity since it is considered "independent" due to
+ // changing at a different time.
+ assertTrue(player.mLastReady.getChanges().stream()
+ .anyMatch((change -> change.getActivityComponent() != null
+ && (change.getFlags() & TransitionInfo.FLAG_CONFIG_AT_END) != 0)));
assertTrue(activity.isConfigurationDispatchPaused());
player.finish();
assertFalse(activity.isConfigurationDispatchPaused());