Merge "Create a new settings - Settings.Secure.ACCESSIBILITY_QS_TARGETS" into main
diff --git a/AconfigFlags.bp b/AconfigFlags.bp
index b8538fb..705a4df 100644
--- a/AconfigFlags.bp
+++ b/AconfigFlags.bp
@@ -26,6 +26,7 @@
":android.os.flags-aconfig-java{.generated_srcjars}",
":android.os.vibrator.flags-aconfig-java{.generated_srcjars}",
":android.security.flags-aconfig-java{.generated_srcjars}",
+ ":android.server.app.flags-aconfig-java{.generated_srcjars}",
":android.service.chooser.flags-aconfig-java{.generated_srcjars}",
":android.service.dreams.flags-aconfig-java{.generated_srcjars}",
":android.service.notification.flags-aconfig-java{.generated_srcjars}",
@@ -853,6 +854,19 @@
defaults: ["framework-minus-apex-aconfig-java-defaults"],
}
+// App
+aconfig_declarations {
+ name: "android.server.app.flags-aconfig",
+ package: "android.server.app",
+ srcs: ["services/core/java/com/android/server/app/flags.aconfig"],
+}
+
+java_aconfig_library {
+ name: "android.server.app.flags-aconfig-java",
+ aconfig_declarations: "android.server.app.flags-aconfig",
+ defaults: ["framework-minus-apex-aconfig-java-defaults"],
+}
+
// WebView
aconfig_declarations {
name: "android.webkit.flags-aconfig",
diff --git a/core/api/current.txt b/core/api/current.txt
index d490c3f..f245b5c 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -44721,12 +44721,12 @@
field public static final int SCAN_TYPE_PERIODIC = 1; // 0x1
}
- public class PhoneNumberFormattingTextWatcher implements android.text.TextWatcher {
- ctor public PhoneNumberFormattingTextWatcher();
- ctor public PhoneNumberFormattingTextWatcher(String);
- method public void afterTextChanged(android.text.Editable);
- method public void beforeTextChanged(CharSequence, int, int, int);
- method public void onTextChanged(CharSequence, int, int, int);
+ @Deprecated public class PhoneNumberFormattingTextWatcher implements android.text.TextWatcher {
+ ctor @Deprecated public PhoneNumberFormattingTextWatcher();
+ ctor @Deprecated @WorkerThread public PhoneNumberFormattingTextWatcher(String);
+ method @Deprecated public void afterTextChanged(android.text.Editable);
+ method @Deprecated public void beforeTextChanged(CharSequence, int, int, int);
+ method @Deprecated public void onTextChanged(CharSequence, int, int, int);
}
public class PhoneNumberUtils {
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 9a65388..9f56933 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -656,6 +656,7 @@
field public static final String OPSTR_PLAY_AUDIO = "android:play_audio";
field public static final String OPSTR_POST_NOTIFICATION = "android:post_notification";
field public static final String OPSTR_PROJECT_MEDIA = "android:project_media";
+ field @FlaggedApi("android.view.contentprotection.flags.rapid_clear_notifications_by_listener_app_op_enabled") public static final String OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER = "android:rapid_clear_notifications_by_listener";
field public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard";
field public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms";
field public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio";
@@ -14522,6 +14523,7 @@
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void clearRadioPowerOffForReason(int);
method public void dial(String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean disableDataConnectivity();
+ method @FlaggedApi("com.android.internal.telephony.flags.enable_identifier_disclosure_transparency") @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void enableCellularIdentifierDisclosureNotifications(boolean);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean enableDataConnectivity();
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean enableModemForSlot(int, boolean);
method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void enableVideoCalling(boolean);
@@ -14594,6 +14596,7 @@
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isAnyRadioPoweredOn();
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isApnMetered(int);
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isApplicationOnUicc(int);
+ method @FlaggedApi("com.android.internal.telephony.flags.enable_identifier_disclosure_transparency") @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isCellularIdentifierDisclosureNotificationEnabled();
method public boolean isDataConnectivityPossible();
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isDataEnabledForApn(int);
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isEmergencyAssistanceEnabled();
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index ec43184..4b24b1f 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -18,6 +18,7 @@
import static android.permission.flags.Flags.FLAG_OP_ENABLE_MOBILE_DATA_BY_USER;
import static android.view.contentprotection.flags.Flags.FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED;
+import static android.view.contentprotection.flags.Flags.FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED;
import static java.lang.Long.max;
@@ -1508,6 +1509,7 @@
*/
public static final int OP_CREATE_ACCESSIBILITY_OVERLAY =
AppProtoEnums.APP_OP_CREATE_ACCESSIBILITY_OVERLAY;
+
/**
* Indicate that the user has enabled or disabled mobile data
* @hide
@@ -1529,9 +1531,17 @@
*/
public static final int OP_RESERVED_FOR_TESTING = AppProtoEnums.APP_OP_RESERVED_FOR_TESTING;
+ /**
+ * Rapid clearing of notifications by a notification listener, see b/289080543 for details
+ *
+ * @hide
+ */
+ public static final int OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER =
+ AppProtoEnums.APP_OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER;
+
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
- public static final int _NUM_OP = 142;
+ public static final int _NUM_OP = 143;
/**
* All app ops represented as strings.
@@ -1680,6 +1690,7 @@
OPSTR_MEDIA_ROUTING_CONTROL,
OPSTR_ENABLE_MOBILE_DATA_BY_USER,
OPSTR_RESERVED_FOR_TESTING,
+ OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER,
})
public @interface AppOpString {}
@@ -2330,6 +2341,7 @@
@FlaggedApi(FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED)
public static final String OPSTR_CREATE_ACCESSIBILITY_OVERLAY =
"android:create_accessibility_overlay";
+
/**
* Indicate that the user has enabled or disabled mobile data
* @hide
@@ -2350,6 +2362,16 @@
public static final String OPSTR_RESERVED_FOR_TESTING =
"android:reserved_for_testing";
+ /**
+ * Rapid clearing of notifications by a notification listener, see b/289080543 for details
+ *
+ * @hide
+ */
+ @SystemApi
+ @FlaggedApi(FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED)
+ public static final String OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER =
+ "android:rapid_clear_notifications_by_listener";
+
/** {@link #sAppOpsToNote} not initialized yet for this op */
private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0;
/** Should not collect noting of this app-op in {@link #sAppOpsToNote} */
@@ -2909,6 +2931,10 @@
"ENABLE_MOBILE_DATA_BY_USER").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
new AppOpInfo.Builder(OP_RESERVED_FOR_TESTING, OPSTR_RESERVED_FOR_TESTING,
"OP_RESERVED_FOR_TESTING").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
+ new AppOpInfo.Builder(OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER,
+ OPSTR_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER,
+ "RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER")
+ .setDefaultMode(AppOpsManager.MODE_ALLOWED).build(),
};
// The number of longs needed to form a full bitmask of app ops
diff --git a/core/java/android/app/IGameManagerService.aidl b/core/java/android/app/IGameManagerService.aidl
index 9a818e4..bfec9430 100644
--- a/core/java/android/app/IGameManagerService.aidl
+++ b/core/java/android/app/IGameManagerService.aidl
@@ -52,4 +52,6 @@
void removeGameModeListener(IGameModeListener gameModeListener);
void addGameStateListener(IGameStateListener gameStateListener);
void removeGameStateListener(IGameStateListener gameStateListener);
+ @EnforcePermission("MANAGE_GAME_MODE")
+ void toggleGameDefaultFrameRate(boolean isEnabled);
}
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 013bcdd..a510c77 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -2205,6 +2205,9 @@
private void visitUris(@NonNull Consumer<Uri> visitor) {
visitIconUri(visitor, getIcon());
+ if (actionIntent != null) {
+ actionIntent.visitUris(visitor);
+ }
}
@Override
@@ -2898,6 +2901,21 @@
}
}
+ // allPendingIntents should contain all associated intents after parcelling, but it may also
+ // contain intents added by the app to extras for their own purposes. We only care about
+ // checking the intents known and used by system_server, to avoid the confused deputy issue.
+ List<PendingIntent> pendingIntents = Arrays.asList(contentIntent, deleteIntent,
+ fullScreenIntent);
+ for (PendingIntent intent : pendingIntents) {
+ if (intent != null) {
+ intent.visitUris(visitor);
+ }
+ }
+
+ if (mBubbleMetadata != null) {
+ mBubbleMetadata.visitUris(visitor);
+ }
+
if (extras != null) {
visitIconUri(visitor, extras.getParcelable(EXTRA_LARGE_ICON_BIG, Icon.class));
visitIconUri(visitor, extras.getParcelable(EXTRA_PICTURE_ICON, Icon.class));
@@ -2969,15 +2987,28 @@
callPerson.visitUris(visitor);
}
visitIconUri(visitor, extras.getParcelable(EXTRA_VERIFICATION_ICON, Icon.class));
- }
- if (mBubbleMetadata != null) {
- visitIconUri(visitor, mBubbleMetadata.getIcon());
- }
+ // Extras for MediaStyle.
+ PendingIntent deviceIntent = extras.getParcelable(EXTRA_MEDIA_REMOTE_INTENT,
+ PendingIntent.class);
+ if (deviceIntent != null) {
+ deviceIntent.visitUris(visitor);
+ }
- if (extras != null && extras.containsKey(WearableExtender.EXTRA_WEARABLE_EXTENSIONS)) {
- WearableExtender extender = new WearableExtender(this);
- extender.visitUris(visitor);
+ if (extras.containsKey(WearableExtender.EXTRA_WEARABLE_EXTENSIONS)) {
+ WearableExtender extender = new WearableExtender(this);
+ extender.visitUris(visitor);
+ }
+
+ if (extras.containsKey(TvExtender.EXTRA_TV_EXTENDER)) {
+ TvExtender extender = new TvExtender(this);
+ extender.visitUris(visitor);
+ }
+
+ if (extras.containsKey(CarExtender.EXTRA_CAR_EXTENDER)) {
+ CarExtender extender = new CarExtender(this);
+ extender.visitUris(visitor);
+ }
}
}
@@ -10558,6 +10589,16 @@
}
}
+ private void visitUris(@NonNull Consumer<Uri> visitor) {
+ visitIconUri(visitor, getIcon());
+ if (mPendingIntent != null) {
+ mPendingIntent.visitUris(visitor);
+ }
+ if (mDeleteIntent != null) {
+ mDeleteIntent.visitUris(visitor);
+ }
+ }
+
/**
* Builder to construct a {@link BubbleMetadata} object.
*/
@@ -11756,6 +11797,9 @@
}
private void visitUris(@NonNull Consumer<Uri> visitor) {
+ if (mDisplayIntent != null) {
+ mDisplayIntent.visitUris(visitor);
+ }
for (Action action : mActions) {
action.visitUris(visitor);
}
@@ -11908,12 +11952,19 @@
/**
* Returns the unread conversation conveyed by this notification.
+ *
* @see #setUnreadConversation(UnreadConversation)
*/
public UnreadConversation getUnreadConversation() {
return mUnreadConversation;
}
+ private void visitUris(@NonNull Consumer<Uri> visitor) {
+ if (mUnreadConversation != null) {
+ mUnreadConversation.visitUris(visitor);
+ }
+ }
+
/**
* A class which holds the unread messages from a conversation.
*/
@@ -12065,7 +12116,16 @@
onRead,
participants, b.getLong(KEY_TIMESTAMP));
}
- };
+
+ private void visitUris(@NonNull Consumer<Uri> visitor) {
+ if (mReadPendingIntent != null) {
+ mReadPendingIntent.visitUris(visitor);
+ }
+ if (mReplyPendingIntent != null) {
+ mReplyPendingIntent.visitUris(visitor);
+ }
+ }
+ }
/**
* Builder class for {@link CarExtender.UnreadConversation} objects.
@@ -12388,6 +12448,15 @@
public boolean isSuppressShowOverApps() {
return mSuppressShowOverApps;
}
+
+ private void visitUris(@NonNull Consumer<Uri> visitor) {
+ if (mContentIntent != null) {
+ mContentIntent.visitUris(visitor);
+ }
+ if (mDeleteIntent != null) {
+ mDeleteIntent.visitUris(visitor);
+ }
+ }
}
/**
diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java
index 62209b0..0261f0a 100644
--- a/core/java/android/app/PendingIntent.java
+++ b/core/java/android/app/PendingIntent.java
@@ -44,6 +44,8 @@
import android.content.pm.PackageManager.ResolveInfoFlagsBits;
import android.content.pm.ParceledListSlice;
import android.content.pm.ResolveInfo;
+import android.net.Uri;
+import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -69,6 +71,7 @@
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
+import java.util.function.Consumer;
/**
* A description of an Intent and target action to perform with it. Instances
@@ -1460,6 +1463,21 @@
return sb.toString();
}
+ /**
+ * See {@link Intent#visitUris(Consumer)}.
+ *
+ * @hide
+ */
+ public void visitUris(@NonNull Consumer<Uri> visitor) {
+ if (android.app.Flags.visitRiskyUris()) {
+ Intent intent = Binder.withCleanCallingIdentity(this::getIntent);
+
+ if (intent != null) {
+ intent.visitUris(visitor);
+ }
+ }
+ }
+
/** @hide */
public void dumpDebug(ProtoOutputStream proto, long fieldId) {
final long token = proto.start(fieldId);
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 23a5d4d..183b9b0 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -101,6 +101,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;
+import java.util.function.Consumer;
/**
* An intent is an abstract description of an operation to be performed. It
@@ -2888,7 +2889,7 @@
* <p class="note">This is a protected intent that can only be sent
* by the system.
* <p>
- * Starting in {@link Build.VERSION_CODES#VANILLA_ICE_CREAM Android V}, an extra timestamp
+ * Starting in Android V, an extra timestamp
* {@link #EXTRA_TIME} is included with this broadcast to indicate the exact time the package
* was restarted, in {@link SystemClock#elapsedRealtime() elapsed realtime}.
* </p>
@@ -8147,6 +8148,27 @@
}
}
+ /**
+ * Note all {@link Uri} that are referenced internally, with the expectation that Uri permission
+ * grants will need to be issued to ensure the recipient of this object is able to render its
+ * contents.
+ * See b/281044385 for more context and examples about what happens when this isn't done
+ * correctly.
+ *
+ * @hide
+ */
+ public void visitUris(@NonNull Consumer<Uri> visitor) {
+ if (android.app.Flags.visitRiskyUris()) {
+ visitor.accept(mData);
+ if (mSelector != null) {
+ mSelector.visitUris(visitor);
+ }
+ if (mOriginalIntent != null) {
+ mOriginalIntent.visitUris(visitor);
+ }
+ }
+ }
+
public static Intent getIntentOld(String uri) throws URISyntaxException {
Intent intent = getIntentOld(uri, 0);
intent.mLocalFlags |= LOCAL_FLAG_FROM_URI;
diff --git a/core/java/android/hardware/input/InputSettings.java b/core/java/android/hardware/input/InputSettings.java
index 33960c0..145dbf2 100644
--- a/core/java/android/hardware/input/InputSettings.java
+++ b/core/java/android/hardware/input/InputSettings.java
@@ -16,6 +16,8 @@
package android.hardware.input;
+import static com.android.hardware.input.Flags.keyboardA11yBounceKeysFlag;
+
import android.Manifest;
import android.annotation.FloatRange;
import android.annotation.NonNull;
@@ -58,6 +60,11 @@
*/
public static final float DEFAULT_MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH = .8f;
+ /**
+ * The maximum allowed Accessibility bounce keys threshold.
+ * @hide
+ */
+ public static final int MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS = 5000;
private InputSettings() {
}
@@ -328,4 +335,70 @@
.getBoolean(com.android.internal.R.bool.config_enableStylusPointerIcon)
|| InputProperties.force_enable_stylus_pointer_icon().orElse(false);
}
+
+ /**
+ * Whether Accessibility bounce keys is enabled.
+ *
+ * <p>
+ * ‘Bounce keys’ is an accessibility feature to aid users who have physical disabilities,
+ * that allows the user to configure the device to ignore rapid, repeated keypresses of the
+ * same key.
+ * </p>
+ *
+ * @hide
+ */
+ public static boolean isAccessibilityBounceKeysEnabled(@NonNull Context context) {
+ return getAccessibilityBounceKeysThreshold(context) != 0;
+ }
+
+ /**
+ * Get Accessibility bounce keys threshold duration in milliseconds.
+ *
+ * <p>
+ * ‘Bounce keys’ is an accessibility feature to aid users who have physical disabilities,
+ * that allows the user to configure the device to ignore rapid, repeated keypresses of the
+ * same key.
+ * </p>
+ *
+ * @hide
+ */
+ public static int getAccessibilityBounceKeysThreshold(@NonNull Context context) {
+ if (!keyboardA11yBounceKeysFlag()) {
+ return 0;
+ }
+ return Settings.System.getIntForUser(context.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS, 0, UserHandle.USER_CURRENT);
+ }
+
+ /**
+ * Set Accessibility bounce keys threshold duration in milliseconds.
+ * @param thresholdTimeMillis time duration for which a key down will be ignored after a
+ * previous key up for the same key on the same device between 0 and
+ * {@link MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS}
+ *
+ * <p>
+ * ‘Bounce keys’ is an accessibility feature to aid users who have physical disabilities,
+ * that allows the user to configure the device to ignore rapid, repeated keypresses of the
+ * same key.
+ * </p>
+ *
+ * @hide
+ */
+ @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
+ public static void setAccessibilityBounceKeysThreshold(@NonNull Context context,
+ int thresholdTimeMillis) {
+ if (!keyboardA11yBounceKeysFlag()) {
+ return;
+ }
+ if (thresholdTimeMillis < 0
+ || thresholdTimeMillis > MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS) {
+ throw new IllegalArgumentException(
+ "Provided Bounce keys threshold should be in range [0, "
+ + MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS + "]");
+ }
+ Settings.System.putIntForUser(context.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS, thresholdTimeMillis,
+ UserHandle.USER_CURRENT);
+ }
+
}
diff --git a/core/java/android/hardware/input/input_framework.aconfig b/core/java/android/hardware/input/input_framework.aconfig
index 97c45a7..362fe78 100644
--- a/core/java/android/hardware/input/input_framework.aconfig
+++ b/core/java/android/hardware/input/input_framework.aconfig
@@ -17,6 +17,12 @@
bug: "294546335"
}
+flag {
+ namespace: "input_native"
+ name: "keyboard_a11y_bounce_keys_flag"
+ description: "Controls if the bounce keys accessibility feature for physical keyboard is available to the user"
+ bug: "294546335"
+}
flag {
namespace: "input_native"
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index 0ccc485..02e40cf 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -396,6 +396,7 @@
* This is Test API which will be used to override output of isDirectlyHandlingTransactionNative
* @hide
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public static void setIsDirectlyHandlingTransactionOverride(boolean isInTransaction) {
sIsHandlingBinderTransaction = isInTransaction;
}
@@ -1068,6 +1069,7 @@
*
* @hide
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public @Nullable String getTransactionName(int transactionCode) {
return null;
}
@@ -1076,6 +1078,7 @@
* @hide
*/
@VisibleForTesting
+ @android.ravenwood.annotation.RavenwoodKeep
public final @Nullable String getTransactionTraceName(int transactionCode) {
final boolean isInterfaceUserDefined = getMaxTransactionId() == 0;
if (mTransactionTraceNames == null) {
@@ -1113,6 +1116,7 @@
return transactionTraceName;
}
+ @android.ravenwood.annotation.RavenwoodKeep
private @NonNull String getSimpleDescriptor() {
String descriptor = mDescriptor;
if (descriptor == null) {
@@ -1132,6 +1136,7 @@
* @return The highest user-defined transaction id of all transactions.
* @hide
*/
+ @android.ravenwood.annotation.RavenwoodKeep
public int getMaxTransactionId() {
return 0;
}
diff --git a/core/java/android/os/Broadcaster.java b/core/java/android/os/Broadcaster.java
index 88760b0..17cf692 100644
--- a/core/java/android/os/Broadcaster.java
+++ b/core/java/android/os/Broadcaster.java
@@ -19,6 +19,7 @@
import android.compat.annotation.UnsupportedAppUsage;
/** @hide */
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class Broadcaster
{
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
diff --git a/core/java/android/os/BundleMerger.java b/core/java/android/os/BundleMerger.java
index 857aaf5..dc243a5 100644
--- a/core/java/android/os/BundleMerger.java
+++ b/core/java/android/os/BundleMerger.java
@@ -48,6 +48,7 @@
*
* @hide
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class BundleMerger implements Parcelable {
private static final String TAG = "BundleMerger";
diff --git a/core/java/android/os/DropBoxManager.java b/core/java/android/os/DropBoxManager.java
index a1d2dcc..2aab2b4 100644
--- a/core/java/android/os/DropBoxManager.java
+++ b/core/java/android/os/DropBoxManager.java
@@ -81,10 +81,8 @@
/**
* Broadcast Action: This is broadcast when a new entry is added in the dropbox.
- * For apps targeting {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM} and later, you
- * must hold the {@link android.Manifest.permission#READ_DROPBOX_DATA} permission
- * in order to receive this broadcast. For apps targeting Android versions lower
- * than {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM}, you must hold
+ * For apps targeting 35 and later, For apps targeting Android versions lower
+ * than 35, you must hold
* {@link android.Manifest.permission#READ_LOGS}.
* This broadcast can be rate limited for low priority entries
*
@@ -385,11 +383,8 @@
/**
* Gets the next entry from the drop box <em>after</em> the specified time.
* You must always call {@link Entry#close()} on the return value!
- * {@link android.Manifest.permission#READ_DROPBOX_DATA} permission is
- * required for apps targeting {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM}
- * and later. {@link android.Manifest.permission#READ_LOGS} permission is
- * required for apps targeting Android versions lower than
- * {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM}.
+ * {@link android.Manifest.permission#READ_LOGS} permission is
+ * required for apps targeting Android versions lower than 35.
*
* @param tag of entry to look for, null for all tags
* @param msec time of the last entry seen
diff --git a/core/java/android/os/PackageTagsList.java b/core/java/android/os/PackageTagsList.java
index df99074..cbc4272 100644
--- a/core/java/android/os/PackageTagsList.java
+++ b/core/java/android/os/PackageTagsList.java
@@ -41,6 +41,7 @@
*/
@TestApi
@Immutable
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public final class PackageTagsList implements Parcelable {
// an empty set value matches any attribution tag (ie, wildcard)
diff --git a/core/java/android/os/TimestampedValue.java b/core/java/android/os/TimestampedValue.java
index 3d8a550..e514d63 100644
--- a/core/java/android/os/TimestampedValue.java
+++ b/core/java/android/os/TimestampedValue.java
@@ -35,6 +35,7 @@
* @param <T> the type of the value with an associated timestamp
* @hide
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public final class TimestampedValue<T> implements Parcelable {
private final long mReferenceTimeMillis;
@Nullable
diff --git a/core/java/android/os/WorkSource.java b/core/java/android/os/WorkSource.java
index bc80c8b..6d4e284 100644
--- a/core/java/android/os/WorkSource.java
+++ b/core/java/android/os/WorkSource.java
@@ -23,6 +23,7 @@
* Currently the public representation of what a work source is not
* defined; this is an opaque container.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class WorkSource implements Parcelable {
static final String TAG = "WorkSource";
static final boolean DEBUG = false;
@@ -141,11 +142,17 @@
*
* @hide
*/
+ @android.ravenwood.annotation.RavenwoodReplace
public static boolean isChainedBatteryAttributionEnabled(Context context) {
return Settings.Global.getInt(context.getContentResolver(),
Global.CHAINED_BATTERY_ATTRIBUTION_ENABLED, 0) == 1;
}
+ /** @hide */
+ public static boolean isChainedBatteryAttributionEnabled$ravenwood(Context context) {
+ return false;
+ }
+
/**
* Returns the number of uids in this work source.
* @hide
diff --git a/core/java/android/os/storage/OWNERS b/core/java/android/os/storage/OWNERS
index bf22dcc..6941857 100644
--- a/core/java/android/os/storage/OWNERS
+++ b/core/java/android/os/storage/OWNERS
@@ -1,6 +1,6 @@
# Bug component: 95221
-# Please assign new bugs to android-storage-triage@, not to individual people
+# PLEASE ASSIGN NEW BUGS TO android-storage-triage@, NOT TO INDIVIDUAL PEOPLE
# Android Storage Team
alukin@google.com
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index e036b78..2cc56d8 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -7791,6 +7791,16 @@
public static final String SHOW_IME_WITH_HARD_KEYBOARD = "show_ime_with_hard_keyboard";
/**
+ * Whether to enable bounce keys for Physical Keyboard accessibility.
+ *
+ * If set to non-zero value, any key press on physical keyboard within the provided
+ * threshold duration (in milliseconds) of the same key, will be ignored.
+ *
+ * @hide
+ */
+ public static final String ACCESSIBILITY_BOUNCE_KEYS = "accessibility_bounce_keys";
+
+ /**
* Whether stylus button presses are disabled. This is a boolean that
* determines if stylus buttons are ignored.
*
@@ -12137,6 +12147,7 @@
CLONE_TO_MANAGED_PROFILE.add(LOCATION_CHANGER);
CLONE_TO_MANAGED_PROFILE.add(LOCATION_MODE);
CLONE_TO_MANAGED_PROFILE.add(SHOW_IME_WITH_HARD_KEYBOARD);
+ CLONE_TO_MANAGED_PROFILE.add(ACCESSIBILITY_BOUNCE_KEYS);
CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_BUBBLES);
}
diff --git a/core/java/android/view/ViewTreeObserver.java b/core/java/android/view/ViewTreeObserver.java
index c9526fd..3b444c4 100644
--- a/core/java/android/view/ViewTreeObserver.java
+++ b/core/java/android/view/ViewTreeObserver.java
@@ -75,7 +75,7 @@
private boolean mWindowShown;
// The reason that the last call to dispatchOnPreDraw() returned true to cancel and redraw
- private String mLastDispatchOnPreDrawCanceledReason;
+ private StringBuilder mLastDispatchOnPreDrawCanceledReason;
private boolean mAlive = true;
@@ -1173,9 +1173,15 @@
int count = access.size();
for (int i = 0; i < count; i++) {
final OnPreDrawListener preDrawListener = access.get(i);
- cancelDraw |= !(preDrawListener.onPreDraw());
- if (cancelDraw) {
- mLastDispatchOnPreDrawCanceledReason = preDrawListener.getClass().getName();
+ final boolean listenerCanceledDraw = !(preDrawListener.onPreDraw());
+ cancelDraw |= listenerCanceledDraw;
+ if (listenerCanceledDraw) {
+ final String className = preDrawListener.getClass().getName();
+ if (mLastDispatchOnPreDrawCanceledReason == null) {
+ mLastDispatchOnPreDrawCanceledReason = new StringBuilder(className);
+ } else {
+ mLastDispatchOnPreDrawCanceledReason.append("|").append(className);
+ }
}
}
} finally {
@@ -1191,7 +1197,10 @@
* @hide
*/
final String getLastDispatchOnPreDrawCanceledReason() {
- return mLastDispatchOnPreDrawCanceledReason;
+ if (mLastDispatchOnPreDrawCanceledReason != null) {
+ return mLastDispatchOnPreDrawCanceledReason.toString();
+ }
+ return null;
}
/**
diff --git a/core/java/android/view/contentprotection/flags/content_protection_flags.aconfig b/core/java/android/view/contentprotection/flags/content_protection_flags.aconfig
index f3dc33c..2a3008a 100644
--- a/core/java/android/view/contentprotection/flags/content_protection_flags.aconfig
+++ b/core/java/android/view/contentprotection/flags/content_protection_flags.aconfig
@@ -27,3 +27,10 @@
description: "If true, an appop is logged on creation of accessibility overlays."
bug: "289081465"
}
+
+flag {
+ name: "rapid_clear_notifications_by_listener_app_op_enabled"
+ namespace: "content_protection"
+ description: "If true, an appop is logged when a notification is rapidly cleared by a notification listener."
+ bug: "289080543"
+}
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index da31348..a31a610 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -1015,6 +1015,11 @@
public int getActionTag() {
return SET_PENDING_INTENT_TEMPLATE_TAG;
}
+
+ @Override
+ public void visitUris(@NonNull Consumer<Uri> visitor) {
+ mPendingIntentTemplate.visitUris(visitor);
+ }
}
/**
@@ -1429,9 +1434,7 @@
@Override
public void visitUris(@NonNull Consumer<Uri> visitor) {
- // TODO(b/281044385): Maybe visit intent URIs. This may require adding a dedicated
- // visitUris method in the Intent class, since it can contain other intents. Otherwise,
- // the basic thing to do here would be just visitor.accept(intent.getData()).
+ mIntent.visitUris(visitor);
}
}
@@ -1511,7 +1514,7 @@
@Override
public void visitUris(@NonNull Consumer<Uri> visitor) {
- // TODO(b/281044385): Maybe visit intent URIs in the RemoteResponse.
+ mResponse.visitUris(visitor);
}
}
@@ -1560,6 +1563,11 @@
public int getActionTag() {
return SET_ON_STYLUS_HANDWRITING_RESPONSE_TAG;
}
+
+ @Override
+ public void visitUris(@NonNull Consumer<Uri> visitor) {
+ mPendingIntent.visitUris(visitor);
+ }
}
/**
@@ -1633,7 +1641,7 @@
@Override
public void visitUris(@NonNull Consumer<Uri> visitor) {
- // TODO(b/281044385): Maybe visit intent URIs in the RemoteResponse.
+ mResponse.visitUris(visitor);
}
}
@@ -2194,6 +2202,10 @@
final Icon icon = (Icon) getParameterValue(null);
if (icon != null) visitIconUri(icon, visitor);
break;
+ case INTENT:
+ final Intent intent = (Intent) getParameterValue(null);
+ if (intent != null) intent.visitUris(visitor);
+ break;
// TODO(b/281044385): Should we do anything about type BUNDLE?
}
}
@@ -6983,6 +6995,20 @@
mElementNames = parcel.createStringArrayList();
}
+ /**
+ * See {@link RemoteViews#visitUris(Consumer)}.
+ *
+ * @hide
+ */
+ public void visitUris(@NonNull Consumer<Uri> visitor) {
+ if (mPendingIntent != null) {
+ mPendingIntent.visitUris(visitor);
+ }
+ if (mFillIntent != null) {
+ mFillIntent.visitUris(visitor);
+ }
+ }
+
private void handleViewInteraction(
View v,
InteractionHandler handler) {
diff --git a/core/java/android/window/flags/windowing_frontend.aconfig b/core/java/android/window/flags/windowing_frontend.aconfig
index 31a3ebd..7f65c52 100644
--- a/core/java/android/window/flags/windowing_frontend.aconfig
+++ b/core/java/android/window/flags/windowing_frontend.aconfig
@@ -44,11 +44,18 @@
bug: "294925498"
}
-
flag {
name: "wallpaper_offset_async"
namespace: "windowing_frontend"
description: "Do not synchronise the wallpaper offset"
bug: "293248754"
is_fixed_read_only: true
+}
+
+flag {
+ name: "predictive_back_system_animations"
+ namespace: "systemui"
+ description: "Predictive back for system animations"
+ bug: "309545085"
+ is_fixed_read_only: true
}
\ No newline at end of file
diff --git a/core/java/com/android/internal/os/BinderCallHeavyHitterWatcher.java b/core/java/com/android/internal/os/BinderCallHeavyHitterWatcher.java
index 7701761..00043cf 100644
--- a/core/java/com/android/internal/os/BinderCallHeavyHitterWatcher.java
+++ b/core/java/com/android/internal/os/BinderCallHeavyHitterWatcher.java
@@ -33,6 +33,7 @@
* A watcher which makes stats on the incoming binder transaction, if the amount of some type of
* transactions exceeds the threshold, the listener will be notified.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public final class BinderCallHeavyHitterWatcher {
private static final String TAG = "BinderCallHeavyHitterWatcher";
diff --git a/core/java/com/android/internal/os/BinderDeathDispatcher.java b/core/java/com/android/internal/os/BinderDeathDispatcher.java
index 8ca6241..e7abe2a 100644
--- a/core/java/com/android/internal/os/BinderDeathDispatcher.java
+++ b/core/java/com/android/internal/os/BinderDeathDispatcher.java
@@ -36,6 +36,7 @@
*
* test with: atest FrameworksCoreTests:BinderDeathDispatcherTest
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class BinderDeathDispatcher<T extends IInterface> {
private static final String TAG = "BinderDeathDispatcher";
diff --git a/core/java/com/android/internal/os/BinderLatencyBuckets.java b/core/java/com/android/internal/os/BinderLatencyBuckets.java
index d7d2d6a..5679bc7 100644
--- a/core/java/com/android/internal/os/BinderLatencyBuckets.java
+++ b/core/java/com/android/internal/os/BinderLatencyBuckets.java
@@ -26,6 +26,7 @@
* Generates the bucket thresholds (with a custom logarithmic scale) for a histogram to store
* latency samples in.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class BinderLatencyBuckets {
private static final String TAG = "BinderLatencyBuckets";
private final int[] mBuckets;
diff --git a/core/java/com/android/internal/os/BinderfsStatsReader.java b/core/java/com/android/internal/os/BinderfsStatsReader.java
index 9cc4a35..66f91e1 100644
--- a/core/java/com/android/internal/os/BinderfsStatsReader.java
+++ b/core/java/com/android/internal/os/BinderfsStatsReader.java
@@ -43,6 +43,7 @@
* free async space 520192
* ...
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class BinderfsStatsReader {
private final String mPath;
diff --git a/core/java/com/android/internal/os/CachedDeviceState.java b/core/java/com/android/internal/os/CachedDeviceState.java
index 334cca3..ac92f86 100644
--- a/core/java/com/android/internal/os/CachedDeviceState.java
+++ b/core/java/com/android/internal/os/CachedDeviceState.java
@@ -30,6 +30,7 @@
*
* @hide
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class CachedDeviceState {
private volatile boolean mScreenInteractive;
private volatile boolean mCharging;
diff --git a/core/java/com/android/internal/os/Clock.java b/core/java/com/android/internal/os/Clock.java
index 45007c4..c2403d1 100644
--- a/core/java/com/android/internal/os/Clock.java
+++ b/core/java/com/android/internal/os/Clock.java
@@ -21,6 +21,7 @@
/**
* A wrapper for SystemClock, intended for mocking in unit tests.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public abstract class Clock {
/** Elapsed Realtime, see SystemClock.elapsedRealtime() */
public long elapsedRealtime() {
diff --git a/core/java/com/android/internal/os/CpuScalingPolicies.java b/core/java/com/android/internal/os/CpuScalingPolicies.java
index 6dbe8ab..f61cf97 100644
--- a/core/java/com/android/internal/os/CpuScalingPolicies.java
+++ b/core/java/com/android/internal/os/CpuScalingPolicies.java
@@ -27,6 +27,7 @@
* CPU scaling policies: the policy IDs and corresponding supported scaling for those
* policies.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class CpuScalingPolicies {
private final SparseArray<int[]> mCpusByPolicy;
private final SparseArray<int[]> mFreqsByPolicy;
diff --git a/core/java/com/android/internal/os/CpuScalingPolicyReader.java b/core/java/com/android/internal/os/CpuScalingPolicyReader.java
index c96089a..0d272fd 100644
--- a/core/java/com/android/internal/os/CpuScalingPolicyReader.java
+++ b/core/java/com/android/internal/os/CpuScalingPolicyReader.java
@@ -40,6 +40,7 @@
* href="https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html
* #policy-interface-in-sysfs">Policy Interface in sysfs</a>
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class CpuScalingPolicyReader {
private static final String TAG = "CpuScalingPolicyReader";
private static final String CPUFREQ_DIR = "/sys/devices/system/cpu/cpufreq";
diff --git a/core/java/com/android/internal/os/KernelCpuThreadReader.java b/core/java/com/android/internal/os/KernelCpuThreadReader.java
index 0843741..5b6d1b6 100644
--- a/core/java/com/android/internal/os/KernelCpuThreadReader.java
+++ b/core/java/com/android/internal/os/KernelCpuThreadReader.java
@@ -244,7 +244,8 @@
}
/** Set the UID predicate for {@link #getProcessCpuUsage} */
- void setUidPredicate(Predicate<Integer> uidPredicate) {
+ @VisibleForTesting
+ public void setUidPredicate(Predicate<Integer> uidPredicate) {
mUidPredicate = uidPredicate;
}
diff --git a/core/java/com/android/internal/os/LoggingPrintStream.java b/core/java/com/android/internal/os/LoggingPrintStream.java
index d27874c..4bf92bb 100644
--- a/core/java/com/android/internal/os/LoggingPrintStream.java
+++ b/core/java/com/android/internal/os/LoggingPrintStream.java
@@ -36,6 +36,7 @@
* {@hide}
*/
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public abstract class LoggingPrintStream extends PrintStream {
private final StringBuilder builder = new StringBuilder();
diff --git a/core/java/com/android/internal/os/LooperStats.java b/core/java/com/android/internal/os/LooperStats.java
index 0645eb7..bbcea8a 100644
--- a/core/java/com/android/internal/os/LooperStats.java
+++ b/core/java/com/android/internal/os/LooperStats.java
@@ -36,6 +36,7 @@
*
* @hide Only for use within the system server.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class LooperStats implements Looper.Observer {
public static final String DEBUG_ENTRY_PREFIX = "__DEBUG_";
private static final int SESSION_POOL_SIZE = 50;
diff --git a/core/java/com/android/internal/os/MonotonicClock.java b/core/java/com/android/internal/os/MonotonicClock.java
index 661628a..c3bcfa6 100644
--- a/core/java/com/android/internal/os/MonotonicClock.java
+++ b/core/java/com/android/internal/os/MonotonicClock.java
@@ -40,6 +40,7 @@
* A clock that is similar to SystemClock#elapsedRealtime(), except that it is not reset
* on reboot, but keeps going.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class MonotonicClock {
private static final String TAG = "MonotonicClock";
diff --git a/core/java/com/android/internal/os/ProcLocksReader.java b/core/java/com/android/internal/os/ProcLocksReader.java
index 9ddb8c7..6b85e08 100644
--- a/core/java/com/android/internal/os/ProcLocksReader.java
+++ b/core/java/com/android/internal/os/ProcLocksReader.java
@@ -34,6 +34,7 @@
* 3: POSIX ADVISORY READ 3888 fd:09:13992 128 128
* 4: POSIX ADVISORY READ 3888 fd:09:14230 1073741826 1073742335
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class ProcLocksReader {
private final String mPath;
private ProcFileReader mReader = null;
diff --git a/core/java/com/android/internal/os/ProcStatsUtil.java b/core/java/com/android/internal/os/ProcStatsUtil.java
index 0002447f..b67190b 100644
--- a/core/java/com/android/internal/os/ProcStatsUtil.java
+++ b/core/java/com/android/internal/os/ProcStatsUtil.java
@@ -30,6 +30,7 @@
* Utility functions for reading {@code proc} files
*/
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public final class ProcStatsUtil {
private static final boolean DEBUG = false;
@@ -92,10 +93,24 @@
* seen, or at the end of the file
*/
@Nullable
+ @android.ravenwood.annotation.RavenwoodReplace
public static String readTerminatedProcFile(String path, byte terminator) {
// Permit disk reads here, as /proc isn't really "on disk" and should be fast.
// TODO: make BlockGuard ignore /proc/ and /sys/ files perhaps?
final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
+ try {
+ return readTerminatedProcFileInternal(path, terminator);
+ } finally {
+ StrictMode.setThreadPolicy(savedPolicy);
+ }
+ }
+
+ public static String readTerminatedProcFile$ravenwood(String path, byte terminator) {
+ // No StrictMode under Ravenwood
+ return readTerminatedProcFileInternal(path, terminator);
+ }
+
+ private static String readTerminatedProcFileInternal(String path, byte terminator) {
try (FileInputStream is = new FileInputStream(path)) {
ByteArrayOutputStream byteStream = null;
final byte[] buffer = new byte[READ_SIZE];
@@ -147,8 +162,6 @@
Slog.d(TAG, "Failed to open proc file", e);
}
return null;
- } finally {
- StrictMode.setThreadPolicy(savedPolicy);
}
}
}
diff --git a/core/java/com/android/internal/os/StoragedUidIoStatsReader.java b/core/java/com/android/internal/os/StoragedUidIoStatsReader.java
index 9b03469..2d485da 100644
--- a/core/java/com/android/internal/os/StoragedUidIoStatsReader.java
+++ b/core/java/com/android/internal/os/StoragedUidIoStatsReader.java
@@ -38,6 +38,7 @@
* This provides the number of bytes/chars read/written in foreground/background for each uid.
* The file contains a monotonically increasing count of bytes/chars for a single boot.
*/
+@android.ravenwood.annotation.RavenwoodKeepWholeClass
public class StoragedUidIoStatsReader {
private static final String TAG = StoragedUidIoStatsReader.class.getSimpleName();
@@ -73,8 +74,21 @@
*
* @param callback The callback to invoke for each line of the proc file.
*/
+ @android.ravenwood.annotation.RavenwoodReplace
public void readAbsolute(Callback callback) {
final int oldMask = StrictMode.allowThreadDiskReadsMask();
+ try {
+ readAbsoluteInternal(callback);
+ } finally {
+ StrictMode.setThreadPolicyMask(oldMask);
+ }
+ }
+
+ public void readAbsolute$ravenwood(Callback callback) {
+ readAbsoluteInternal(callback);
+ }
+
+ private void readAbsoluteInternal(Callback callback) {
File file = new File(sUidIoFile);
try (BufferedReader reader = Files.newBufferedReader(file.toPath())) {
String line;
@@ -106,8 +120,6 @@
}
} catch (IOException e) {
Slog.e(TAG, "Failed to read " + sUidIoFile + ": " + e.getMessage());
- } finally {
- StrictMode.setThreadPolicyMask(oldMask);
}
}
}
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 387a108..bf8e55f 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -6856,4 +6856,7 @@
<!-- Whether the View-based scroll haptic feedback implementation is enabled for
{@link InputDevice#SOURCE_ROTARY_ENCODER}s. -->
<bool name="config_viewBasedRotaryEncoderHapticsEnabled">false</bool>
+
+ <!-- Whether the media player is shown on the quick settings -->
+ <bool name="config_quickSettingsShowMediaPlayer">true</bool>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index a5b1028..5791ddb 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -5298,4 +5298,6 @@
<java-symbol type="array" name="config_tvExternalInputLoggingDeviceBrandNames" />
<java-symbol type="bool" name="config_viewRotaryEncoderHapticScrollFedbackEnabled" />
<java-symbol type="bool" name="config_viewBasedRotaryEncoderHapticsEnabled" />
+
+ <java-symbol type="bool" name="config_quickSettingsShowMediaPlayer" />
</resources>
diff --git a/core/tests/coretests/Android.bp b/core/tests/coretests/Android.bp
index 6706c91..1a3ec27 100644
--- a/core/tests/coretests/Android.bp
+++ b/core/tests/coretests/Android.bp
@@ -7,19 +7,35 @@
default_applicable_licenses: ["frameworks_base_license"],
}
+filegroup {
+ name: "FrameworksCoreTests-aidl",
+ srcs: [
+ "src/**/I*.aidl",
+ "aidl/**/I*.aidl",
+ ],
+ visibility: ["//visibility:private"],
+}
+
+filegroup {
+ name: "FrameworksCoreTests-helpers",
+ srcs: [
+ "DisabledTestApp/src/**/*.java",
+ "EnabledTestApp/src/**/*.java",
+ "BinderProxyCountingTestApp/src/**/*.java",
+ "BinderProxyCountingTestService/src/**/*.java",
+ "BinderDeathRecipientHelperApp/src/**/*.java",
+ ],
+ visibility: ["//visibility:private"],
+}
+
android_test {
name: "FrameworksCoreTests",
srcs: [
"src/**/*.java",
"src/**/*.kt",
- "src/**/I*.aidl",
- "DisabledTestApp/src/**/*.java",
- "EnabledTestApp/src/**/*.java",
- "BinderProxyCountingTestApp/src/**/*.java",
- "BinderProxyCountingTestService/src/**/*.java",
- "BinderDeathRecipientHelperApp/src/**/*.java",
- "aidl/**/I*.aidl",
+ ":FrameworksCoreTests-aidl",
+ ":FrameworksCoreTests-helpers",
":FrameworksCoreTestDoubles-sources",
],
@@ -177,17 +193,29 @@
"androidx.annotation_annotation",
"androidx.test.rules",
"androidx.test.ext.junit",
+ "androidx.test.uiautomator_uiautomator",
+ "compatibility-device-util-axt",
+ "flag-junit",
"mockito_ravenwood",
"platform-test-annotations",
"flag-junit",
+ "testng",
],
srcs: [
- "src/android/os/BuildTest.java",
- "src/android/os/FileUtilsTest.java",
+ "src/android/os/**/*.java",
+ "src/com/android/internal/os/**/*.java",
"src/android/util/**/*.java",
"src/com/android/internal/os/LongArrayMultiStateCounterTest.java",
"src/com/android/internal/util/**/*.java",
- "testdoubles/src/com/android/internal/util/**/*.java",
+ "src/com/android/internal/power/EnergyConsumerStatsTest.java",
+ ":FrameworksCoreTests{.aapt.srcjar}",
+ ":FrameworksCoreTests-aidl",
+ ":FrameworksCoreTests-helpers",
+ ":FrameworksCoreTestDoubles-sources",
],
+ aidl: {
+ generate_get_transaction_name: true,
+ local_include_dirs: ["aidl"],
+ },
auto_gen_config: true,
}
diff --git a/core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java b/core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java
index 3768063..cd6abdd 100644
--- a/core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java
+++ b/core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java
@@ -20,9 +20,13 @@
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
import androidx.test.filters.SmallTest;
import org.junit.After;
+import org.junit.Rule;
import org.junit.Test;
/**
@@ -35,7 +39,10 @@
* atest FrameworksCoreTests:PropertyInvalidatedCacheTests
*/
@SmallTest
+@IgnoreUnderRavenwood(blockedBy = PropertyInvalidatedCache.class)
public class PropertyInvalidatedCacheTests {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
// Configuration for creating caches
private static final String MODULE = PropertyInvalidatedCache.MODULE_TEST;
diff --git a/core/tests/coretests/src/android/os/AidlTest.java b/core/tests/coretests/src/android/os/AidlTest.java
index d0c3470..006828f 100644
--- a/core/tests/coretests/src/android/os/AidlTest.java
+++ b/core/tests/coretests/src/android/os/AidlTest.java
@@ -16,23 +16,36 @@
package android.os;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
import androidx.test.filters.SmallTest;
import com.google.android.collect.Lists;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import java.util.List;
-public class AidlTest extends TestCase {
+@IgnoreUnderRavenwood(blockedBy = Parcel.class)
+public class AidlTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private IAidlTest mRemote;
private AidlObject mLocal;
private NonAutoGeneratedObject mNonAutoGenerated;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
mLocal = new AidlObject();
mRemote = IAidlTest.Stub.asInterface(mLocal);
mNonAutoGenerated = new NonAutoGeneratedObject("NonAutoGeneratedObject");
@@ -212,12 +225,14 @@
}
}
+ @Test
@SmallTest
public void testInt() throws Exception {
int result = mRemote.intMethod(42);
assertEquals(42, result);
}
+ @Test
@SmallTest
public void testParcelableIn() throws Exception {
TestParcelable arg = new TestParcelable(43, "hi");
@@ -228,6 +243,7 @@
assertEquals(44, result.mAnInt);
}
+ @Test
@SmallTest
public void testParcelableOut() throws Exception {
TestParcelable arg = new TestParcelable(43, "hi");
@@ -236,6 +252,7 @@
assertEquals(44, arg.mAnInt);
}
+ @Test
@SmallTest
public void testParcelableInOut() throws Exception {
TestParcelable arg = new TestParcelable(43, "hi");
@@ -244,6 +261,7 @@
assertEquals(44, arg.mAnInt);
}
+ @Test
@SmallTest
public void testListParcelableLonger() throws Exception {
List<TestParcelable> list = Lists.newArrayList();
@@ -268,6 +286,7 @@
assertNotSame(list.get(1), list.get(2));
}
+ @Test
@SmallTest
public void testListParcelableShorter() throws Exception {
List<TestParcelable> list = Lists.newArrayList();
@@ -290,6 +309,7 @@
assertNotSame(list.get(0), list.get(1));
}
+ @Test
@SmallTest
public void testArrays() throws Exception {
// boolean
@@ -363,14 +383,14 @@
float[] fr = mRemote.floatArray(f0, f1, f2);
assertEquals(1, fr.length);
- assertEquals(90.1f, fr[0]);
+ assertEquals(90.1f, fr[0], 0.0f);
- assertEquals(90.1f, f1[0]);
+ assertEquals(90.1f, f1[0], 0.0f);
assertEquals(0f, f1[1], 0.0f);
- assertEquals(90.1f, f2[0]);
- assertEquals(90.5f, f2[1]);
- assertEquals(90.6f, f2[2]);
+ assertEquals(90.1f, f2[0], 0.0f);
+ assertEquals(90.5f, f2[1], 0.0f);
+ assertEquals(90.6f, f2[2], 0.0f);
// double
double[] d0 = new double[]{100.1};
@@ -379,14 +399,14 @@
double[] dr = mRemote.doubleArray(d0, d1, d2);
assertEquals(1, dr.length);
- assertEquals(100.1, dr[0]);
+ assertEquals(100.1, dr[0], 0.0);
- assertEquals(100.1, d1[0]);
+ assertEquals(100.1, d1[0], 0.0);
assertEquals(0, d1[1], 0.0);
- assertEquals(100.1, d2[0]);
- assertEquals(100.5, d2[1]);
- assertEquals(100.6, d2[2]);
+ assertEquals(100.1, d2[0], 0.0);
+ assertEquals(100.5, d2[1], 0.0);
+ assertEquals(100.6, d2[2], 0.0);
// String
String[] s0 = new String[]{"s0[0]"};
@@ -405,6 +425,7 @@
assertEquals("s2[2]", s2[2]);
}
+ @Test
@SmallTest
public void testVoidSecurityException() throws Exception {
boolean good = false;
@@ -416,6 +437,7 @@
assertEquals(good, true);
}
+ @Test
@SmallTest
public void testIntSecurityException() throws Exception {
boolean good = false;
@@ -427,6 +449,7 @@
assertEquals(good, true);
}
+ @Test
@SmallTest
public void testGetTransactionNameAutoGenerated() throws Exception {
assertEquals(15, mLocal.getMaxTransactionId());
@@ -446,6 +469,7 @@
mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_parcelableIn));
}
+ @Test
@SmallTest
public void testGetTransactionNameNonAutoGenerated() throws Exception {
assertEquals(0, mNonAutoGenerated.getMaxTransactionId());
diff --git a/core/tests/coretests/src/android/os/BinderDeathRecipientTest.java b/core/tests/coretests/src/android/os/BinderDeathRecipientTest.java
index 2cce43f..eff52f0 100644
--- a/core/tests/coretests/src/android/os/BinderDeathRecipientTest.java
+++ b/core/tests/coretests/src/android/os/BinderDeathRecipientTest.java
@@ -25,6 +25,8 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.ArraySet;
import android.util.Log;
import android.util.Pair;
@@ -36,6 +38,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,6 +55,7 @@
* Tests functionality of {@link android.os.IBinder.DeathRecipient} callbacks.
*/
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = ActivityManager.class)
public class BinderDeathRecipientTest {
private static final String TAG = BinderDeathRecipientTest.class.getSimpleName();
private static final String TEST_PACKAGE_NAME_1 =
@@ -59,6 +63,9 @@
private static final String TEST_PACKAGE_NAME_2 =
"com.android.frameworks.coretests.bdr_helper_app2";
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private Context mContext;
private Handler mHandler;
private ActivityManager mActivityManager;
diff --git a/core/tests/coretests/src/android/os/BinderProxyCountingTest.java b/core/tests/coretests/src/android/os/BinderProxyCountingTest.java
index 2089c6c..bcd9521 100644
--- a/core/tests/coretests/src/android/os/BinderProxyCountingTest.java
+++ b/core/tests/coretests/src/android/os/BinderProxyCountingTest.java
@@ -24,6 +24,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.Log;
import androidx.test.InstrumentationRegistry;
@@ -35,7 +37,8 @@
import com.android.frameworks.coretests.aidl.IBpcTestAppCmdService;
import com.android.frameworks.coretests.aidl.IBpcTestServiceCmdService;
-import org.junit.BeforeClass;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -71,6 +74,7 @@
*/
@LargeTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = ActivityManager.class)
public class BinderProxyCountingTest {
private static final String TAG = BinderProxyCountingTest.class.getSimpleName();
@@ -107,11 +111,14 @@
};
private static int sTestPkgUid;
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
/**
* Setup any common data for the upcoming tests.
*/
- @BeforeClass
- public static void setUpOnce() throws Exception {
+ @Before
+ public void setUp() throws Exception {
sContext = InstrumentationRegistry.getContext();
sTestPkgUid = sContext.getPackageManager().getPackageUid(TEST_APP_PKG, 0);
((ActivityManager) sContext.getSystemService(Context.ACTIVITY_SERVICE)).killUid(sTestPkgUid,
diff --git a/core/tests/coretests/src/android/os/BinderProxyTest.java b/core/tests/coretests/src/android/os/BinderProxyTest.java
index 3567d17..a903ed9 100644
--- a/core/tests/coretests/src/android/os/BinderProxyTest.java
+++ b/core/tests/coretests/src/android/os/BinderProxyTest.java
@@ -16,19 +16,34 @@
package android.os;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
-import android.test.AndroidTestCase;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.MediumTest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-public class BinderProxyTest extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = PowerManager.class)
+public class BinderProxyTest {
private static class CountingListener implements Binder.ProxyTransactListener {
int mStartedCount;
int mEndedCount;
@@ -43,17 +58,22 @@
}
};
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
+ private Context mContext;
private PowerManager mPowerManager;
/**
* Setup any common data for the upcoming tests.
*/
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
+ mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
}
+ @Test
@MediumTest
public void testNoListener() throws Exception {
CountingListener listener = new CountingListener();
@@ -66,6 +86,7 @@
assertEquals(0, listener.mEndedCount);
}
+ @Test
@MediumTest
public void testListener() throws Exception {
CountingListener listener = new CountingListener();
@@ -77,6 +98,7 @@
assertEquals(1, listener.mEndedCount);
}
+ @Test
@MediumTest
public void testSessionPropagated() throws Exception {
Binder.setProxyTransactListener(new Binder.ProxyTransactListener() {
@@ -95,6 +117,7 @@
private IBinder mRemoteBinder = null;
+ @Test
@MediumTest
public void testGetExtension() throws Exception {
final CountDownLatch bindLatch = new CountDownLatch(1);
diff --git a/core/tests/coretests/src/android/os/BinderTest.java b/core/tests/coretests/src/android/os/BinderTest.java
index 02f8790..6c8b69f 100644
--- a/core/tests/coretests/src/android/os/BinderTest.java
+++ b/core/tests/coretests/src/android/os/BinderTest.java
@@ -16,21 +16,35 @@
package android.os;
-import androidx.test.filters.SmallTest;
-
-import junit.framework.TestCase;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.testng.Assert.assertThrows;
-public class BinderTest extends TestCase {
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
+import androidx.test.filters.SmallTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+@IgnoreUnderRavenwood(blockedBy = WorkSource.class)
+public class BinderTest {
private static final int UID = 100;
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
+ @Test
@SmallTest
public void testSetWorkSource() throws Exception {
Binder.setCallingWorkSourceUid(UID);
assertEquals(UID, Binder.getCallingWorkSourceUid());
}
+ @Test
@SmallTest
public void testClearWorkSource() throws Exception {
Binder.setCallingWorkSourceUid(UID);
@@ -38,6 +52,7 @@
assertEquals(-1, Binder.getCallingWorkSourceUid());
}
+ @Test
@SmallTest
public void testRestoreWorkSource() throws Exception {
Binder.setCallingWorkSourceUid(UID);
@@ -46,11 +61,13 @@
assertEquals(UID, Binder.getCallingWorkSourceUid());
}
+ @Test
@SmallTest
public void testGetCallingUidOrThrow_throws() throws Exception {
assertThrows(IllegalStateException.class, () -> Binder.getCallingUidOrThrow());
}
+ @Test
@SmallTest
public void testGetExtension() throws Exception {
Binder binder = new Binder();
diff --git a/core/tests/coretests/src/android/os/BinderThreadPriorityTest.java b/core/tests/coretests/src/android/os/BinderThreadPriorityTest.java
index 48c9df6..4172bff 100644
--- a/core/tests/coretests/src/android/os/BinderThreadPriorityTest.java
+++ b/core/tests/coretests/src/android/os/BinderThreadPriorityTest.java
@@ -16,21 +16,42 @@
package android.os;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
-import android.test.AndroidTestCase;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.Log;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.io.File;
import java.io.IOException;
/**
* Test whether Binder calls inherit thread priorities correctly.
*/
-public class BinderThreadPriorityTest extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = ActivityManager.class)
+public class BinderThreadPriorityTest {
private static final String TAG = "BinderThreadPriorityTest";
+
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
+ private Context mContext;
private IBinderThreadPriorityService mService;
private int mSavedPriority;
@@ -55,12 +76,11 @@
private static void fail() { throw new RuntimeException("unimplemented"); }
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- getContext().bindService(
- new Intent(getContext(), BinderThreadPriorityService.class),
+ @Before
+ public void setUp() throws Exception {
+ mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ mContext.bindService(
+ new Intent(mContext, BinderThreadPriorityService.class),
mConnection, Context.BIND_AUTO_CREATE);
synchronized (this) {
@@ -80,8 +100,8 @@
Log.i(TAG, "Saved priority: " + mSavedPriority);
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
// HACK -- see bug 2665914 -- setThreadPriority() doesn't always set the
// scheduler group reliably unless we start out with background priority.
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
@@ -89,8 +109,7 @@
assertEquals(mSavedPriority, Process.getThreadPriority(Process.myTid()));
assertEquals(expectedSchedulerGroup(mSavedPriority), getSchedulerGroup());
- getContext().unbindService(mConnection);
- super.tearDown();
+ mContext.unbindService(mConnection);
}
public static String getSchedulerGroup() {
@@ -111,6 +130,7 @@
return "/";
}
+ @Test
public void testPassPriorityToService() throws Exception {
for (int prio = 19; prio >= -20; prio--) {
Process.setThreadPriority(prio);
@@ -125,6 +145,7 @@
}
}
+ @Test
public void testCallBackFromServiceWithPriority() throws Exception {
for (int prio = -20; prio <= 19; prio++) {
final int expected = prio;
diff --git a/core/tests/coretests/src/android/os/BinderWorkSourceTest.java b/core/tests/coretests/src/android/os/BinderWorkSourceTest.java
index b14c88f..552066c 100644
--- a/core/tests/coretests/src/android/os/BinderWorkSourceTest.java
+++ b/core/tests/coretests/src/android/os/BinderWorkSourceTest.java
@@ -19,11 +19,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
@@ -33,6 +36,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -42,12 +46,16 @@
@LargeTest
@Presubmit
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = ActivityManager.class)
public class BinderWorkSourceTest {
private static Context sContext;
private static final int UID = 100;
private static final int SECOND_UID = 200;
private static final int UID_NONE = ThreadLocalWorkSource.UID_NONE;
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private IBinderWorkSourceService mService;
private IBinderWorkSourceNestedService mNestedService;
@@ -71,13 +79,9 @@
}
};
- @BeforeClass
- public static void setUpOnce() throws Exception {
- sContext = InstrumentationRegistry.getContext();
- }
-
@Before
public void setUp() throws Exception {
+ sContext = InstrumentationRegistry.getContext();
sContext.bindService(
new Intent(sContext, BinderWorkSourceService.class),
mConnection, Context.BIND_AUTO_CREATE);
diff --git a/core/tests/coretests/src/android/os/BroadcasterTest.java b/core/tests/coretests/src/android/os/BroadcasterTest.java
index b4c47af9..7829457 100644
--- a/core/tests/coretests/src/android/os/BroadcasterTest.java
+++ b/core/tests/coretests/src/android/os/BroadcasterTest.java
@@ -16,16 +16,26 @@
package android.os;
+import android.platform.test.ravenwood.RavenwoodRule;
+
import androidx.test.filters.MediumTest;
+import androidx.test.runner.AndroidJUnit4;
-import junit.framework.TestCase;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
-public class BroadcasterTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class BroadcasterTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private static final int MESSAGE_A = 23234;
private static final int MESSAGE_B = 3;
private static final int MESSAGE_C = 14;
private static final int MESSAGE_D = 95;
+ @Test
@MediumTest
public void test1() throws Exception {
/*
@@ -103,6 +113,7 @@
}
}
+ @Test
@MediumTest
public void test2() throws Exception {
/*
@@ -112,6 +123,7 @@
tester.doTest(1000);
}
+ @Test
@MediumTest
public void test3() throws Exception {
/*
@@ -121,6 +133,7 @@
tester.doTest(1000);
}
+ @Test
@MediumTest
public void test4() throws Exception {
/*
@@ -156,6 +169,7 @@
tester.doTest(1000);
}
+ @Test
@MediumTest
public void test5() throws Exception {
/*
@@ -191,6 +205,7 @@
tester.doTest(1000);
}
+ @Test
@MediumTest
public void test6() throws Exception {
/*
diff --git a/core/tests/coretests/src/android/os/BundleTest.java b/core/tests/coretests/src/android/os/BundleTest.java
index a3bda8b..8c231de 100644
--- a/core/tests/coretests/src/android/os/BundleTest.java
+++ b/core/tests/coretests/src/android/os/BundleTest.java
@@ -23,13 +23,16 @@
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.Log;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -45,6 +48,9 @@
@Presubmit
@RunWith(AndroidJUnit4.class)
public class BundleTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private Log.TerribleFailureHandler mWtfHandler;
@After
@@ -115,6 +121,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = ParcelFileDescriptor.class)
public void testCreateFromParcel() throws Exception {
boolean withFd;
Parcel p;
@@ -190,6 +197,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void kindofEquals_bothParcelled_same() {
Bundle bundle1 = new Bundle();
bundle1.putString("StringKey", "S");
@@ -207,6 +215,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void kindofEquals_bothParcelled_different() {
Bundle bundle1 = new Bundle();
bundle1.putString("StringKey", "S");
@@ -238,6 +247,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void kindofEquals_lazyValues() {
Parcelable p1 = new CustomParcelable(13, "Tiramisu");
Parcelable p2 = new CustomParcelable(13, "Tiramisu");
@@ -271,6 +281,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void kindofEquals_lazyValuesWithIdenticalParcels_returnsTrue() {
Parcelable p1 = new CustomParcelable(13, "Tiramisu");
Parcelable p2 = new CustomParcelable(13, "Tiramisu");
@@ -295,6 +306,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void kindofEquals_lazyValuesAndDifferentClassLoaders_returnsFalse() {
Parcelable p1 = new CustomParcelable(13, "Tiramisu");
Parcelable p2 = new CustomParcelable(13, "Tiramisu");
@@ -350,6 +362,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void readWriteLengthMismatch_logsWtf() throws Exception {
mWtfHandler = Log.setWtfHandler((tag, e, system) -> {
throw new RuntimeException(e);
@@ -364,6 +377,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void getParcelable_whenThrowingAndNotDefusing_throws() throws Exception {
Bundle.setShouldDefuse(false);
Bundle bundle = new Bundle();
@@ -376,6 +390,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void getParcelable_whenThrowingAndDefusing_returnsNull() throws Exception {
Bundle.setShouldDefuse(true);
Bundle bundle = new Bundle();
@@ -391,6 +406,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void getParcelable_whenThrowingAndDefusing_leavesElement() throws Exception {
Bundle.setShouldDefuse(true);
Bundle bundle = new Bundle();
diff --git a/core/tests/coretests/src/android/os/CancellationSignalBeamerTest.java b/core/tests/coretests/src/android/os/CancellationSignalBeamerTest.java
index 42c97f3..c2cea0a 100644
--- a/core/tests/coretests/src/android/os/CancellationSignalBeamerTest.java
+++ b/core/tests/coretests/src/android/os/CancellationSignalBeamerTest.java
@@ -22,6 +22,8 @@
import android.content.Context;
import android.os.CancellationSignalBeamer.Receiver;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.PollingCheck;
import android.util.PollingCheck.PollingCheckCondition;
@@ -29,6 +31,8 @@
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,11 +44,20 @@
@RunWith(AndroidJUnit4.class)
@SmallTest
+@IgnoreUnderRavenwood(blockedBy = CancellationSignalBeamer.class)
public class CancellationSignalBeamerTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
- private CancellationSignal mSenderSignal = new CancellationSignal();
+ private CancellationSignal mSenderSignal;
private CancellationSignal mReceivedSignal;
- private Context mContext = InstrumentationRegistry.getInstrumentation().getContext();
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ mSenderSignal = new CancellationSignal();
+ mContext = InstrumentationRegistry.getInstrumentation().getContext();
+ }
@Test
public void testBeam_null() {
@@ -208,17 +221,22 @@
mReceivedSignal = mReceiver.unbeam(cancellationSignalToken);
}
- private final Sender mSender = new Sender() {
- @Override
- public void onCancel(IBinder token) {
- mReceiver.cancel(token);
- }
+ private Sender mSender;
+ private Receiver mReceiver;
- @Override
- public void onForget(IBinder token) {
- mReceiver.forget(token);
- }
- };
+ @Before
+ public void setUpSenderReceiver() {
+ mSender = new Sender() {
+ @Override
+ public void onCancel(IBinder token) {
+ mReceiver.cancel(token);
+ }
- private final Receiver mReceiver = new Receiver(false);
+ @Override
+ public void onForget(IBinder token) {
+ mReceiver.forget(token);
+ }
+ };
+ mReceiver = new Receiver(false);
+ }
}
diff --git a/core/tests/coretests/src/android/os/EnvironmentTest.java b/core/tests/coretests/src/android/os/EnvironmentTest.java
index ef38cde..1aa263f 100644
--- a/core/tests/coretests/src/android/os/EnvironmentTest.java
+++ b/core/tests/coretests/src/android/os/EnvironmentTest.java
@@ -28,12 +28,15 @@
import android.content.Context;
import android.os.storage.StorageManager;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,7 +46,11 @@
import java.util.function.BiFunction;
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = Environment.class)
public class EnvironmentTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private File dir;
private static Context getContext() {
diff --git a/core/tests/coretests/src/android/os/FileBridgeTest.java b/core/tests/coretests/src/android/os/FileBridgeTest.java
index 708bfa6..726670b 100644
--- a/core/tests/coretests/src/android/os/FileBridgeTest.java
+++ b/core/tests/coretests/src/android/os/FileBridgeTest.java
@@ -19,12 +19,25 @@
import static android.os.ParcelFileDescriptor.MODE_CREATE;
import static android.os.ParcelFileDescriptor.MODE_READ_WRITE;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import android.os.FileBridge.FileBridgeOutputStream;
-import android.test.AndroidTestCase;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.test.MoreAsserts;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
import libcore.io.Streams;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -32,18 +45,20 @@
import java.nio.charset.StandardCharsets;
import java.util.Random;
-public class FileBridgeTest extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = ParcelFileDescriptor.class)
+public class FileBridgeTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private File file;
private ParcelFileDescriptor outputFile;
private FileBridge bridge;
private FileBridgeOutputStream client;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- file = getContext().getFileStreamPath("meow.dat");
+ @Before
+ public void setUp() throws Exception {
+ file = File.createTempFile("meow", "dat");
file.delete();
outputFile = ParcelFileDescriptor.open(file, MODE_CREATE | MODE_READ_WRITE);
@@ -54,8 +69,8 @@
client = new FileBridgeOutputStream(bridge.getClientSocket());
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
outputFile.close();
file.delete();
}
@@ -76,17 +91,20 @@
MoreAsserts.assertEquals(expected, Streams.readFully(new FileInputStream(file)));
}
+ @Test
public void testNoWriteNoSync() throws Exception {
assertOpen();
closeAndAssertClosed();
}
+ @Test
public void testNoWriteSync() throws Exception {
assertOpen();
client.flush();
closeAndAssertClosed();
}
+ @Test
public void testWriteNoSync() throws Exception {
assertOpen();
client.write("meow".getBytes(StandardCharsets.UTF_8));
@@ -94,6 +112,7 @@
assertContents("meow".getBytes(StandardCharsets.UTF_8));
}
+ @Test
public void testWriteSync() throws Exception {
assertOpen();
client.write("cake".getBytes(StandardCharsets.UTF_8));
@@ -102,6 +121,7 @@
assertContents("cake".getBytes(StandardCharsets.UTF_8));
}
+ @Test
public void testWriteSyncWrite() throws Exception {
assertOpen();
client.write("meow".getBytes(StandardCharsets.UTF_8));
@@ -111,6 +131,7 @@
assertContents("meowcake".getBytes(StandardCharsets.UTF_8));
}
+ @Test
public void testEmptyWrite() throws Exception {
assertOpen();
client.write(new byte[0]);
@@ -118,6 +139,7 @@
assertContents(new byte[0]);
}
+ @Test
public void testWriteAfterClose() throws Exception {
assertOpen();
client.write("meow".getBytes(StandardCharsets.UTF_8));
@@ -130,6 +152,7 @@
assertContents("meow".getBytes(StandardCharsets.UTF_8));
}
+ @Test
public void testRandomWrite() throws Exception {
final Random r = new Random();
final ByteArrayOutputStream result = new ByteArrayOutputStream();
@@ -146,6 +169,7 @@
assertContents(result.toByteArray());
}
+ @Test
public void testGiantWrite() throws Exception {
final byte[] test = new byte[263401];
new Random().nextBytes(test);
diff --git a/core/tests/coretests/src/android/os/FileObserverTest.java b/core/tests/coretests/src/android/os/FileObserverTest.java
index ece7645..3cd8045 100644
--- a/core/tests/coretests/src/android/os/FileObserverTest.java
+++ b/core/tests/coretests/src/android/os/FileObserverTest.java
@@ -16,21 +16,37 @@
package android.os;
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.Log;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.MediumTest;
import com.google.android.collect.Lists;
import com.google.android.collect.Maps;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.io.File;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-public class FileObserverTest extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = FileObserver.class)
+public class FileObserverTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private Observer mObserver;
private File mTestFile;
@@ -57,18 +73,19 @@
}
}
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
mTestFile = File.createTempFile(".file_observer_test", ".txt");
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
if (mTestFile != null && mTestFile.exists()) {
mTestFile.delete();
}
}
+ @Test
@MediumTest
public void testRun() throws Exception {
// make file changes and wait for them
diff --git a/core/tests/coretests/src/android/os/HandlerThreadTest.java b/core/tests/coretests/src/android/os/HandlerThreadTest.java
index 93cfc40..0bac1c7 100644
--- a/core/tests/coretests/src/android/os/HandlerThreadTest.java
+++ b/core/tests/coretests/src/android/os/HandlerThreadTest.java
@@ -16,18 +16,35 @@
package android.os;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import android.platform.test.ravenwood.RavenwoodRule;
+
import androidx.test.filters.MediumTest;
+import androidx.test.runner.AndroidJUnit4;
-import junit.framework.TestCase;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
-public class HandlerThreadTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class HandlerThreadTest {
private static final int TEST_WHAT = 1;
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private boolean mGotMessage = false;
private int mGotMessageWhat = -1;
private volatile boolean mDidSetup = false;
private volatile int mLooperTid = -1;
-
+
+ @Test
@MediumTest
public void testHandlerThread() throws Exception {
HandlerThread th1 = new HandlerThread("HandlerThreadTest") {
diff --git a/core/tests/coretests/src/android/os/IdleHandlerTest.java b/core/tests/coretests/src/android/os/IdleHandlerTest.java
index d8886c9..8644663 100644
--- a/core/tests/coretests/src/android/os/IdleHandlerTest.java
+++ b/core/tests/coretests/src/android/os/IdleHandlerTest.java
@@ -17,12 +17,19 @@
package android.os;
import android.os.MessageQueue.IdleHandler;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.MediumTest;
+import androidx.test.runner.AndroidJUnit4;
-import junit.framework.TestCase;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
-public class IdleHandlerTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class IdleHandlerTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private static class BaseTestHandler extends TestHandlerThread {
Handler mHandler;
@@ -54,6 +61,7 @@
}
}
+ @Test
@MediumTest
public void testOneShotFirst() throws Exception {
TestHandlerThread tester = new BaseTestHandler() {
@@ -88,6 +96,7 @@
tester.doTest(1000);
}
+ @Test
@MediumTest
public void testOneShotLater() throws Exception {
TestHandlerThread tester = new BaseTestHandler() {
@@ -125,6 +134,7 @@
}
+ @Test
@MediumTest
public void testRepeatedFirst() throws Exception {
TestHandlerThread tester = new BaseTestHandler() {
@@ -159,6 +169,7 @@
tester.doTest(1000);
}
+ @Test
@MediumTest
public void testRepeatedLater() throws Exception {
TestHandlerThread tester = new BaseTestHandler() {
diff --git a/core/tests/coretests/src/android/os/IpcDataCacheTest.java b/core/tests/coretests/src/android/os/IpcDataCacheTest.java
index 34712ce..b03fd64 100644
--- a/core/tests/coretests/src/android/os/IpcDataCacheTest.java
+++ b/core/tests/coretests/src/android/os/IpcDataCacheTest.java
@@ -17,12 +17,14 @@
package android.os;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;
import org.junit.After;
+import org.junit.Rule;
import org.junit.Test;
/**
@@ -35,7 +37,10 @@
* atest FrameworksCoreTests:IpcDataCacheTest
*/
@SmallTest
+@IgnoreUnderRavenwood(blockedBy = IpcDataCache.class)
public class IpcDataCacheTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
// Configuration for creating caches
private static final String MODULE = IpcDataCache.MODULE_TEST;
diff --git a/core/tests/coretests/src/android/os/LocaleListTest.java b/core/tests/coretests/src/android/os/LocaleListTest.java
index 88fc826..0025e3a 100644
--- a/core/tests/coretests/src/android/os/LocaleListTest.java
+++ b/core/tests/coretests/src/android/os/LocaleListTest.java
@@ -16,13 +16,29 @@
package android.os;
-import androidx.test.filters.SmallTest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.Locale;
-public class LocaleListTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = LocaleList.class)
+public class LocaleListTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
+ @Test
@SmallTest
public void testConstructor() throws Exception {
LocaleList ll;
@@ -51,6 +67,7 @@
assertEquals("fr,de", ll.toLanguageTags());
}
+ @Test
@SmallTest
public void testConstructor_nullThrows() throws Exception {
try {
@@ -61,6 +78,7 @@
}
}
+ @Test
@SmallTest
public void testGetDefault_localeSetDefaultCalledButNoChangeNecessary() throws Exception {
final Locale originalLocale = Locale.getDefault();
@@ -82,6 +100,7 @@
LocaleList.setDefault(originalLocaleList, originalLocaleIndex);
}
+ @Test
@SmallTest
public void testIntersection() {
LocaleList localesWithN = new LocaleList(
diff --git a/core/tests/coretests/src/android/os/MemoryFileTest.java b/core/tests/coretests/src/android/os/MemoryFileTest.java
index 05c2995..a695424 100644
--- a/core/tests/coretests/src/android/os/MemoryFileTest.java
+++ b/core/tests/coretests/src/android/os/MemoryFileTest.java
@@ -16,11 +16,21 @@
package android.os;
-import android.test.AndroidTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.filters.SmallTest;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -29,7 +39,11 @@
import java.util.Arrays;
import java.util.List;
-public class MemoryFileTest extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = MemoryFile.class)
+public class MemoryFileTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private void compareBuffers(byte[] buffer1, byte[] buffer2, int length) throws Exception {
for (int i = 0; i < length; i++) {
@@ -44,6 +58,8 @@
*/
// Flaky test - temporarily suppress from large suite for now
// @LargeTest
+ @Test
+ @Ignore("Flaky test")
public void testPurge() throws Exception {
List<MemoryFile> files = new ArrayList<MemoryFile>();
try {
@@ -70,6 +86,7 @@
}
}
+ @Test
@SmallTest
public void testRun() throws Exception {
MemoryFile file = new MemoryFile("MemoryFileTest", 1000000);
@@ -102,6 +119,7 @@
}
// http://code.google.com/p/android/issues/detail?id=11415
+ @Test
public void testOutputStreamAdvances() throws IOException {
MemoryFile file = new MemoryFile("MemoryFileTest", 10);
@@ -142,24 +160,28 @@
}
}
+ @Test
@SmallTest
public void testReadNegativeOffset() throws Exception {
readIndexOutOfBoundsException(-1, 5,
"read() with negative offset should throw IndexOutOfBoundsException");
}
+ @Test
@SmallTest
public void testReadNegativeCount() throws Exception {
readIndexOutOfBoundsException(5, -1,
"read() with negative length should throw IndexOutOfBoundsException");
}
+ @Test
@SmallTest
public void testReadOffsetOverflow() throws Exception {
readIndexOutOfBoundsException(testString.length + 10, 5,
"read() with offset outside buffer should throw IndexOutOfBoundsException");
}
+ @Test
@SmallTest
public void testReadOffsetCountOverflow() throws Exception {
readIndexOutOfBoundsException(testString.length, 11,
@@ -167,6 +189,7 @@
}
// Test behavior of read() at end of file
+ @Test
@SmallTest
public void testReadEOF() throws Exception {
MemoryFile file = new MemoryFile("MemoryFileTest", testString.length);
@@ -189,6 +212,7 @@
}
// Tests that close() is idempotent
+ @Test
@SmallTest
public void testCloseClose() throws Exception {
MemoryFile file = new MemoryFile("MemoryFileTest", 1000000);
@@ -199,6 +223,7 @@
}
// Tests that we can't read from a closed memory file
+ @Test
@SmallTest
public void testCloseRead() throws Exception {
MemoryFile file = new MemoryFile("MemoryFileTest", 1000000);
@@ -214,6 +239,7 @@
}
// Tests that we can't write to a closed memory file
+ @Test
@SmallTest
public void testCloseWrite() throws Exception {
MemoryFile file = new MemoryFile("MemoryFileTest", 1000000);
@@ -229,6 +255,7 @@
}
// Tests that we can't call allowPurging() after close()
+ @Test
@SmallTest
public void testCloseAllowPurging() throws Exception {
MemoryFile file = new MemoryFile("MemoryFileTest", 1000000);
@@ -245,6 +272,7 @@
}
// Tests that we don't leak file descriptors or mmap areas
+ @Test
@LargeTest
public void testCloseLeak() throws Exception {
// open enough memory files that we should run out of
diff --git a/core/tests/coretests/src/android/os/MessageQueueTest.java b/core/tests/coretests/src/android/os/MessageQueueTest.java
index 2c5588e..8cd6773 100644
--- a/core/tests/coretests/src/android/os/MessageQueueTest.java
+++ b/core/tests/coretests/src/android/os/MessageQueueTest.java
@@ -16,13 +16,21 @@
package android.os;
+import android.platform.test.ravenwood.RavenwoodRule;
+
import androidx.test.filters.MediumTest;
import androidx.test.filters.Suppress;
+import androidx.test.runner.AndroidJUnit4;
-import junit.framework.TestCase;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
@Suppress // Failing.
-public class MessageQueueTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class MessageQueueTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private static class BaseTestHandler extends TestHandlerThread {
Handler mHandler;
@@ -61,6 +69,7 @@
}
}
+ @Test
@MediumTest
public void testMessageOrder() throws Exception {
TestHandlerThread tester = new BaseTestHandler() {
@@ -80,6 +89,7 @@
tester.doTest(1000);
}
+ @Test
@MediumTest
public void testAtFrontOfQueue() throws Exception {
TestHandlerThread tester = new BaseTestHandler() {
@@ -141,6 +151,7 @@
}
}
+ @Test
@MediumTest
public void testFieldIntegrity() throws Exception {
@@ -157,7 +168,7 @@
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 0) {
- msg.flags = -1;
+ msg.flags = Message.FLAGS_TO_CLEAR_ON_COPY_FROM;
msg.what = 1;
msg.arg1 = 456;
msg.arg2 = 789;
diff --git a/core/tests/coretests/src/android/os/MessengerTest.java b/core/tests/coretests/src/android/os/MessengerTest.java
index 9143ff1..eb6263f 100644
--- a/core/tests/coretests/src/android/os/MessengerTest.java
+++ b/core/tests/coretests/src/android/os/MessengerTest.java
@@ -16,15 +16,31 @@
package android.os;
+import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
-import android.test.AndroidTestCase;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.MediumTest;
-public class MessengerTest extends AndroidTestCase {
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = ActivityManager.class)
+public class MessengerTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
+ private Context mContext;
private Messenger mServiceMessenger;
private ServiceConnection mConnection = new ServiceConnection() {
@@ -86,10 +102,10 @@
}
};
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- getContext().bindService(new Intent(mContext, MessengerService.class),
+ @Before
+ public void setUp() throws Exception {
+ mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ mContext.bindService(new Intent(mContext, MessengerService.class),
mConnection, Context.BIND_AUTO_CREATE);
synchronized (this) {
while (mServiceMessenger == null) {
@@ -101,15 +117,14 @@
}
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- getContext().unbindService(mConnection);
+ @After
+ public void tearDown() throws Exception {
+ mContext.unbindService(mConnection);
}
+ @Test
@MediumTest
public void testSend() {
(new TestThread()).doTest(1000);
-
}
}
diff --git a/core/tests/coretests/src/android/os/OsTests.java b/core/tests/coretests/src/android/os/OsTests.java
deleted file mode 100644
index 08fb945..0000000
--- a/core/tests/coretests/src/android/os/OsTests.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.os;
-
-import junit.framework.TestSuite;
-
-public class OsTests {
- public static TestSuite suite() {
- TestSuite suite = new TestSuite(OsTests.class.getName());
-
- suite.addTestSuite(AidlTest.class);
- suite.addTestSuite(BroadcasterTest.class);
- suite.addTestSuite(FileObserverTest.class);
- suite.addTestSuite(IdleHandlerTest.class);
- suite.addTestSuite(MessageQueueTest.class);
- suite.addTestSuite(MessengerTest.class);
- suite.addTestSuite(PatternMatcherTest.class);
-
- return suite;
- }
-}
diff --git a/core/tests/coretests/src/android/os/ParcelNullabilityTest.java b/core/tests/coretests/src/android/os/ParcelNullabilityTest.java
index b4e180c..ffeab29 100644
--- a/core/tests/coretests/src/android/os/ParcelNullabilityTest.java
+++ b/core/tests/coretests/src/android/os/ParcelNullabilityTest.java
@@ -20,11 +20,14 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.ArrayMap;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,6 +39,9 @@
@SmallTest
@RunWith(AndroidJUnit4.class)
public final class ParcelNullabilityTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
@Test
public void nullByteArray() {
Parcel p = Parcel.obtain();
@@ -61,6 +67,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void nullCharSequence() {
Parcel p = Parcel.obtain();
p.writeCharSequence(null);
@@ -69,6 +76,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void nullStrongBinder() {
Parcel p = Parcel.obtain();
p.writeStrongBinder(null);
@@ -77,6 +85,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void nullStringInterface() {
Parcel p = Parcel.obtain();
p.writeStrongInterface(null);
diff --git a/core/tests/coretests/src/android/os/ParcelTest.java b/core/tests/coretests/src/android/os/ParcelTest.java
index 4b993fa..5bbd221 100644
--- a/core/tests/coretests/src/android/os/ParcelTest.java
+++ b/core/tests/coretests/src/android/os/ParcelTest.java
@@ -21,22 +21,29 @@
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.runner.AndroidJUnit4;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@Presubmit
@RunWith(AndroidJUnit4.class)
public class ParcelTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private static final int WORK_SOURCE_1 = 1000;
private static final int WORK_SOURCE_2 = 1002;
private static final String INTERFACE_TOKEN_1 = "IBinder interface token";
private static final String INTERFACE_TOKEN_2 = "Another IBinder interface token";
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testIsForRpc() {
Parcel p = Parcel.obtain();
assertEquals(false, p.isForRpc());
@@ -44,6 +51,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCallingWorkSourceUidAfterWrite() {
Parcel p = Parcel.obtain();
// Method does not throw if replaceCallingWorkSourceUid is called before requests headers
@@ -64,6 +72,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCallingWorkSourceUidAfterEnforce() {
Parcel p = Parcel.obtain();
p.writeInterfaceToken(INTERFACE_TOKEN_1);
@@ -81,6 +90,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testParcelWithMultipleHeaders() {
Parcel p = Parcel.obtain();
Binder.setCallingWorkSourceUid(WORK_SOURCE_1);
@@ -122,6 +132,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCompareDataInRange_whenSameData() {
Parcel pA = Parcel.obtain();
int iA = pA.dataPosition();
@@ -138,6 +149,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCompareDataInRange_whenSameDataWithBinder() {
Binder binder = new Binder();
Parcel pA = Parcel.obtain();
@@ -157,6 +169,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCompareDataInRange_whenDifferentData() {
Parcel pA = Parcel.obtain();
int iA = pA.dataPosition();
@@ -173,6 +186,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCompareDataInRange_whenLimitOutOfBounds_throws() {
Parcel pA = Parcel.obtain();
int iA = pA.dataPosition();
@@ -199,6 +213,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCompareDataInRange_whenLengthZero() {
Parcel pA = Parcel.obtain();
int iA = pA.dataPosition();
@@ -217,6 +232,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCompareDataInRange_whenNegativeLength_throws() {
Parcel pA = Parcel.obtain();
int iA = pA.dataPosition();
@@ -232,6 +248,7 @@
}
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testCompareDataInRange_whenNegativeOffset_throws() {
Parcel pA = Parcel.obtain();
int iA = pA.dataPosition();
@@ -297,6 +314,7 @@
* and 1M length for complex objects are allowed.
*/
@Test
+ @IgnoreUnderRavenwood(blockedBy = Parcel.class)
public void testAllocations_whenWithinLimit() {
Binder.setIsDirectlyHandlingTransactionOverride(true);
Parcel p = Parcel.obtain();
diff --git a/core/tests/coretests/src/android/os/PatternMatcherTest.java b/core/tests/coretests/src/android/os/PatternMatcherTest.java
index 82350cd..a5e036d 100644
--- a/core/tests/coretests/src/android/os/PatternMatcherTest.java
+++ b/core/tests/coretests/src/android/os/PatternMatcherTest.java
@@ -16,9 +16,10 @@
package android.os;
-import androidx.test.filters.SmallTest;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import androidx.test.filters.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -26,7 +27,7 @@
@RunWith(JUnit4.class)
@SmallTest
-public class PatternMatcherTest extends TestCase{
+public class PatternMatcherTest {
@Test
public void testAdvancedPatternMatchesAnyToken() {
diff --git a/core/tests/coretests/src/android/os/PerformanceCollectorTest.java b/core/tests/coretests/src/android/os/PerformanceCollectorTest.java
index 38ad90f..46f1706 100644
--- a/core/tests/coretests/src/android/os/PerformanceCollectorTest.java
+++ b/core/tests/coretests/src/android/os/PerformanceCollectorTest.java
@@ -16,33 +16,48 @@
package android.os;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import android.os.PerformanceCollector.PerformanceResultsWriter;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Random;
-public class PerformanceCollectorTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = PerformanceCollector.class)
+public class PerformanceCollectorTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private PerformanceCollector mPerfCollector;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
mPerfCollector = new PerformanceCollector();
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
mPerfCollector = null;
}
+ @Test
@SmallTest
public void testBeginSnapshotNoWriter() throws Exception {
mPerfCollector.beginSnapshot("testBeginSnapshotNoWriter");
@@ -54,6 +69,7 @@
assertEquals(2, snapshot.size());
}
+ @Test
@MediumTest
public void testEndSnapshotNoWriter() throws Exception {
mPerfCollector.beginSnapshot("testEndSnapshotNoWriter");
@@ -63,6 +79,7 @@
verifySnapshotBundle(snapshot);
}
+ @Test
@SmallTest
public void testStartTimingNoWriter() throws Exception {
mPerfCollector.startTiming("testStartTimingNoWriter");
@@ -74,6 +91,7 @@
verifyTimingBundle(measurement, new ArrayList<String>());
}
+ @Test
@SmallTest
public void testAddIterationNoWriter() throws Exception {
mPerfCollector.startTiming("testAddIterationNoWriter");
@@ -83,6 +101,7 @@
verifyIterationBundle(iteration, "timing1");
}
+ @Test
@SmallTest
public void testStopTimingNoWriter() throws Exception {
mPerfCollector.startTiming("testStopTimingNoWriter");
@@ -100,6 +119,7 @@
verifyTimingBundle(timing, labels);
}
+ @Test
@SmallTest
public void testBeginSnapshot() throws Exception {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
@@ -114,6 +134,7 @@
assertEquals(2, snapshot.size());
}
+ @Test
@MediumTest
public void testEndSnapshot() throws Exception {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
@@ -127,6 +148,7 @@
verifySnapshotBundle(snapshot1);
}
+ @Test
@SmallTest
public void testStartTiming() throws Exception {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
@@ -141,6 +163,7 @@
verifyTimingBundle(measurement, new ArrayList<String>());
}
+ @Test
@SmallTest
public void testAddIteration() throws Exception {
mPerfCollector.startTiming("testAddIteration");
@@ -150,6 +173,7 @@
verifyIterationBundle(iteration, "timing5");
}
+ @Test
@SmallTest
public void testStopTiming() throws Exception {
mPerfCollector.startTiming("testStopTiming");
@@ -167,6 +191,7 @@
verifyTimingBundle(timing, labels);
}
+ @Test
@SmallTest
public void testAddMeasurementLong() throws Exception {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
@@ -188,6 +213,7 @@
assertEquals(-19354, results.getLong("testAddMeasurementLongNeg"));
}
+ @Test
@SmallTest
public void testAddMeasurementFloat() throws Exception {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
@@ -202,13 +228,14 @@
Bundle results = writer.timingResults;
assertEquals(4, results.size());
assertTrue(results.containsKey("testAddMeasurementFloatZero"));
- assertEquals(0.0f, results.getFloat("testAddMeasurementFloatZero"));
+ assertEquals(0.0f, results.getFloat("testAddMeasurementFloatZero"), 0.0f);
assertTrue(results.containsKey("testAddMeasurementFloatPos"));
- assertEquals(348573.345f, results.getFloat("testAddMeasurementFloatPos"));
+ assertEquals(348573.345f, results.getFloat("testAddMeasurementFloatPos"), 0.0f);
assertTrue(results.containsKey("testAddMeasurementFloatNeg"));
- assertEquals(-19354.093f, results.getFloat("testAddMeasurementFloatNeg"));
+ assertEquals(-19354.093f, results.getFloat("testAddMeasurementFloatNeg"), 0.0f);
}
+ @Test
@SmallTest
public void testAddMeasurementString() throws Exception {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
@@ -230,6 +257,7 @@
assertEquals("Hello World", results.getString("testAddMeasurementStringNonEmpty"));
}
+ @Test
@MediumTest
public void testSimpleSequence() throws Exception {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
@@ -262,6 +290,7 @@
verifyTimingBundle(timing, labels);
}
+ @Test
@MediumTest
public void testLongSequence() throws Exception {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
@@ -348,6 +377,7 @@
* Verify that snapshotting and timing do not interfere w/ each other,
* by staggering calls to snapshot and timing functions.
*/
+ @Test
@MediumTest
public void testOutOfOrderSequence() {
MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter();
diff --git a/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java b/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java
index 9b4dec4..12a2844 100644
--- a/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java
+++ b/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java
@@ -24,18 +24,25 @@
import static org.junit.Assume.assumeNotNull;
import android.os.PerformanceHintManager.Session;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = PerformanceHintManager.class)
public class PerformanceHintManagerTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private static final long RATE_1000 = 1000L;
private static final long TARGET_166 = 166L;
private static final long DEFAULT_TARGET_NS = 16666666L;
diff --git a/core/tests/coretests/src/android/os/PowerManagerTest.java b/core/tests/coretests/src/android/os/PowerManagerTest.java
index 5d213ca..cb281ff 100644
--- a/core/tests/coretests/src/android/os/PowerManagerTest.java
+++ b/core/tests/coretests/src/android/os/PowerManagerTest.java
@@ -17,7 +17,9 @@
package android.os;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@@ -26,28 +28,34 @@
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.os.Flags;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
-import android.test.AndroidTestCase;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
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;
import org.mockito.MockitoAnnotations;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
-public class PowerManagerTest extends AndroidTestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = PowerManager.class)
+public class PowerManagerTest {
private static final String TAG = "PowerManagerTest";
+ private Context mContext;
private PowerManager mPm;
private UiDevice mUiDevice;
private Executor mExec = Executors.newSingleThreadExecutor();
@@ -68,21 +76,27 @@
String[] keys, String[] values);
static {
- System.loadLibrary("powermanagertest_jni");
+ if (!RavenwoodRule.isUnderRavenwood()) {
+ System.loadLibrary("powermanagertest_jni");
+ }
}
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
// Required for RequiresFlagsEnabled and RequiresFlagsDisabled annotations to take effect.
@Rule
- public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+ public final CheckFlagsRule mCheckFlagsRule = RavenwoodRule.isUnderRavenwood() ? null
+ : DeviceFlagsValueProvider.createCheckFlagsRule();
/**
* Setup any common data for the upcoming tests.
*/
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
MockitoAnnotations.initMocks(this);
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mUiDevice.executeShellCommand("cmd thermalservice override-status 0");
}
@@ -100,6 +114,7 @@
*
* @throws Exception
*/
+ @Test
@SmallTest
public void testPreconditions() throws Exception {
assertNotNull(mPm);
@@ -110,6 +125,7 @@
*
* @throws Exception
*/
+ @Test
@SmallTest
public void testNewWakeLock() throws Exception {
PowerManager.WakeLock wl = mPm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "FULL_WAKE_LOCK");
@@ -133,6 +149,7 @@
*
* @throws Exception
*/
+ @Test
@SmallTest
public void testBadNewWakeLock() throws Exception {
final int badFlags = PowerManager.SCREEN_BRIGHT_WAKE_LOCK
@@ -152,6 +169,7 @@
*
* @throws Exception
*/
+ @Test
@SmallTest
public void testWakeLockWithWorkChains() throws Exception {
PowerManager.WakeLock wakeLock = mPm.newWakeLock(
diff --git a/core/tests/coretests/src/android/os/ProcessTest.java b/core/tests/coretests/src/android/os/ProcessTest.java
index b2ffdc0..310baa3 100644
--- a/core/tests/coretests/src/android/os/ProcessTest.java
+++ b/core/tests/coretests/src/android/os/ProcessTest.java
@@ -17,12 +17,23 @@
package android.os;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
-public class ProcessTest extends TestCase {
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+@IgnoreUnderRavenwood(blockedBy = Process.class)
+public class ProcessTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private static final int BAD_PID = 0;
+ @Test
public void testProcessGetUidFromName() throws Exception {
assertEquals(android.os.Process.SYSTEM_UID, Process.getUidForName("system"));
assertEquals(Process.BLUETOOTH_UID, Process.getUidForName("bluetooth"));
@@ -36,6 +47,7 @@
Process.getUidForName("u3_a100"));
}
+ @Test
public void testProcessGetUidFromNameFailure() throws Exception {
// Failure cases
assertEquals(-1, Process.getUidForName("u2a_foo"));
@@ -51,6 +63,7 @@
* Tests getUidForPid() by ensuring that it returns the correct value when the process queried
* doesn't exist.
*/
+ @Test
public void testGetUidForPidInvalidPid() {
assertEquals(-1, Process.getUidForPid(BAD_PID));
}
@@ -59,6 +72,7 @@
* Tests getParentPid() by ensuring that it returns the correct value when the process queried
* doesn't exist.
*/
+ @Test
public void testGetParentPidInvalidPid() {
assertEquals(-1, Process.getParentPid(BAD_PID));
}
@@ -67,11 +81,13 @@
* Tests getThreadGroupLeader() by ensuring that it returns the correct value when the
* thread queried doesn't exist.
*/
+ @Test
public void testGetThreadGroupLeaderInvalidTid() {
// This function takes a TID instead of a PID but BAD_PID should also be a bad TID.
assertEquals(-1, Process.getThreadGroupLeader(BAD_PID));
}
+ @Test
public void testGetAdvertisedMem() {
assertTrue(Process.getAdvertisedMem() > 0);
assertTrue(Process.getTotalMemory() <= Process.getAdvertisedMem());
diff --git a/core/tests/coretests/src/android/os/RedactingFileDescriptorTest.java b/core/tests/coretests/src/android/os/RedactingFileDescriptorTest.java
index eff4826..25ce240 100644
--- a/core/tests/coretests/src/android/os/RedactingFileDescriptorTest.java
+++ b/core/tests/coretests/src/android/os/RedactingFileDescriptorTest.java
@@ -24,6 +24,8 @@
import static org.junit.Assert.assertEquals;
import android.content.Context;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.system.Os;
import androidx.test.InstrumentationRegistry;
@@ -31,6 +33,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,7 +44,11 @@
import java.util.Arrays;
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = RedactingFileDescriptor.class)
public class RedactingFileDescriptorTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private Context mContext;
private File mFile;
diff --git a/core/tests/coretests/src/android/os/TraceTest.java b/core/tests/coretests/src/android/os/TraceTest.java
index d07187c..593833ec 100644
--- a/core/tests/coretests/src/android/os/TraceTest.java
+++ b/core/tests/coretests/src/android/os/TraceTest.java
@@ -16,24 +16,36 @@
package android.os;
-import android.test.AndroidTestCase;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.Log;
import androidx.test.filters.LargeTest;
import androidx.test.filters.SmallTest;
import androidx.test.filters.Suppress;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* This class is used to test the native tracing support. Run this test
* while tracing on the emulator and then run traceview to view the trace.
*/
-public class TraceTest extends AndroidTestCase
-{
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = Trace.class)
+public class TraceTest {
private static final String TAG = "TraceTest";
+
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private int eMethodCalls = 0;
private int fMethodCalls = 0;
private int gMethodCalls = 0;
+ @Test
public void testNullStrings() {
Trace.traceCounter(Trace.TRACE_TAG_ACTIVITY_MANAGER, null, 42);
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, null);
@@ -48,6 +60,7 @@
Trace.instantForTrack(Trace.TRACE_TAG_ACTIVITY_MANAGER, null, null);
}
+ @Test
@SmallTest
public void testNativeTracingFromJava()
{
@@ -80,7 +93,8 @@
native void nativeMethod();
native void nativeMethodAndStartTracing();
-
+
+ @Test
@LargeTest
@Suppress // Failing.
public void testMethodTracing()
diff --git a/core/tests/coretests/src/android/os/VintfObjectTest.java b/core/tests/coretests/src/android/os/VintfObjectTest.java
index ae6e79a..f34b8fd 100644
--- a/core/tests/coretests/src/android/os/VintfObjectTest.java
+++ b/core/tests/coretests/src/android/os/VintfObjectTest.java
@@ -16,12 +16,27 @@
package android.os;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertTrue;
-public class VintfObjectTest extends TestCase {
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = VintfObject.class)
+public class VintfObjectTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
/**
* Quick check for {@link VintfObject#report VintfObject.report()}.
*/
+ @Test
public void testReport() {
String[] xmls = VintfObject.report();
assertTrue(xmls.length > 0);
diff --git a/core/tests/coretests/src/android/os/WorkSourceParcelTest.java b/core/tests/coretests/src/android/os/WorkSourceParcelTest.java
index 4831606..5f49186 100644
--- a/core/tests/coretests/src/android/os/WorkSourceParcelTest.java
+++ b/core/tests/coretests/src/android/os/WorkSourceParcelTest.java
@@ -16,17 +16,25 @@
package android.os;
+import static org.junit.Assert.assertEquals;
+
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
-import static org.junit.Assert.assertEquals;
-
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
+@IgnoreUnderRavenwood(reason = "JNI")
public class WorkSourceParcelTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
/**
* END_OF_PARCEL_MARKER is added at the end of Parcel on native or java side on write and
* then read on java or native side on read. This way we can ensure that no extra data
@@ -41,8 +49,11 @@
String[] names, int parcelEndMarker);
static {
- System.loadLibrary("worksourceparceltest_jni");
+ if (!RavenwoodRule.isUnderRavenwood()) {
+ System.loadLibrary("worksourceparceltest_jni");
+ }
}
+
/**
* Confirm that we can pass WorkSource from native to Java.
*/
diff --git a/core/tests/coretests/src/android/os/WorkSourceTest.java b/core/tests/coretests/src/android/os/WorkSourceTest.java
index 4206fd2..85dc127 100644
--- a/core/tests/coretests/src/android/os/WorkSourceTest.java
+++ b/core/tests/coretests/src/android/os/WorkSourceTest.java
@@ -16,9 +16,19 @@
package android.os;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import android.os.WorkSource.WorkChain;
-import junit.framework.TestCase;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.List;
@@ -28,7 +38,9 @@
*
* These tests will be moved to CTS when finalized.
*/
-public class WorkSourceTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class WorkSourceTest {
+ @Test
public void testWorkChain_add() {
WorkChain wc1 = new WorkChain();
wc1.addNode(56, null);
@@ -46,6 +58,7 @@
assertEquals(2, wc1.getSize());
}
+ @Test
public void testWorkChain_equalsHashCode() {
WorkChain wc1 = new WorkChain();
WorkChain wc2 = new WorkChain();
@@ -78,6 +91,7 @@
assertFalse(wc1.hashCode() == wc2.hashCode());
}
+ @Test
public void testWorkChain_constructor() {
WorkChain wc1 = new WorkChain();
wc1.addNode(1, "foo")
@@ -91,6 +105,7 @@
assertFalse(wc1.equals(wc2));
}
+ @Test
public void testDiff_workChains() {
WorkSource ws1 = new WorkSource();
ws1.add(50);
@@ -104,6 +119,7 @@
assertFalse(ws2.diff(ws1));
}
+ @Test
public void testEquals_workChains() {
WorkSource ws1 = new WorkSource();
ws1.add(50);
@@ -128,6 +144,7 @@
assertFalse(ws3.equals(ws1));
}
+ @Test
public void testEquals_workChains_nullEmptyAreEquivalent() {
// Construct a WorkSource that has no WorkChains, but whose workChains list
// is non-null.
@@ -145,6 +162,7 @@
assertFalse(ws1.equals(ws2));
}
+ @Test
public void testWorkSourceParcelling() {
WorkSource ws = new WorkSource();
@@ -164,6 +182,7 @@
assertEquals(unparcelled, ws);
}
+ @Test
public void testSet_workChains() {
WorkSource ws1 = new WorkSource();
ws1.add(50);
@@ -193,6 +212,7 @@
assertEquals(1, ws1.getWorkChains().get(0).getSize());
}
+ @Test
public void testSet_nullWorkChain() {
WorkSource ws = new WorkSource();
ws.add(60);
@@ -203,6 +223,7 @@
assertEquals(0, ws.getWorkChains().size());
}
+ @Test
public void testAdd_workChains() {
WorkSource ws = new WorkSource();
ws.createWorkChain().addNode(70, "foo");
@@ -224,6 +245,7 @@
assertEquals(2, workChains.size());
}
+ @Test
public void testSet_noWorkChains() {
WorkSource ws = new WorkSource();
ws.set(10);
@@ -237,6 +259,7 @@
assertEquals("foo", ws2.getPackageName(0));
}
+ @Test
public void testDiffChains_noChanges() {
// WorkSources with no chains.
assertEquals(null, WorkSource.diffChains(new WorkSource(), new WorkSource()));
@@ -254,6 +277,7 @@
assertEquals(null, WorkSource.diffChains(ws2, ws1));
}
+ @Test
public void testDiffChains_noChains() {
// Diffs against a worksource with no chains.
WorkSource ws1 = new WorkSource();
@@ -276,6 +300,7 @@
assertEquals(ws2.getWorkChains(), diffs[1]);
}
+ @Test
public void testDiffChains_onlyAdditionsOrRemovals() {
WorkSource ws1 = new WorkSource();
WorkSource ws2 = new WorkSource();
@@ -302,6 +327,7 @@
}
+ @Test
public void testDiffChains_generalCase() {
WorkSource ws1 = new WorkSource();
WorkSource ws2 = new WorkSource();
@@ -340,6 +366,7 @@
assertEquals(new WorkChain().addNode(2, "tag2"), diffs[1].get(1));
}
+ @Test
public void testGetAttributionId() {
WorkSource ws = new WorkSource();
WorkChain wc1 = ws.createWorkChain();
@@ -355,6 +382,7 @@
assertEquals(100, ws.getAttributionUid());
}
+ @Test
public void testGetAttributionIdWithoutWorkChain() {
WorkSource ws1 = new WorkSource(100);
ws1.add(200);
@@ -365,6 +393,7 @@
assertEquals(100, ws2.getAttributionUid());
}
+ @Test
public void testGetAttributionWhenEmpty() {
WorkSource ws = new WorkSource();
assertEquals(-1, ws.getAttributionUid());
@@ -374,6 +403,7 @@
assertNull(wc.getAttributionTag());
}
+ @Test
public void testGetAttributionTag() {
WorkSource ws1 = new WorkSource();
WorkChain wc = ws1.createWorkChain();
@@ -383,6 +413,7 @@
assertEquals("tag", wc.getAttributionTag());
}
+ @Test
public void testRemove_fromChainedWorkSource() {
WorkSource ws1 = new WorkSource();
ws1.createWorkChain().addNode(50, "foo");
@@ -403,6 +434,7 @@
assertEquals(75, ws1.getWorkChains().get(0).getAttributionUid());
}
+ @Test
public void testRemove_fromSameWorkSource() {
WorkSource ws1 = new WorkSource(50, "foo");
WorkSource ws2 = ws1;
@@ -414,6 +446,7 @@
assertEquals("foo", ws1.getPackageName(0));
}
+ @Test
public void testTransferWorkChains() {
WorkSource ws1 = new WorkSource();
WorkChain wc1 = ws1.createWorkChain().addNode(100, "tag");
diff --git a/core/tests/coretests/src/android/widget/RemoteViewsTest.java b/core/tests/coretests/src/android/widget/RemoteViewsTest.java
index c8ea374..15c9047 100644
--- a/core/tests/coretests/src/android/widget/RemoteViewsTest.java
+++ b/core/tests/coretests/src/android/widget/RemoteViewsTest.java
@@ -34,9 +34,6 @@
import android.appwidget.AppWidgetHostView;
import android.content.Context;
import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.AsyncTask;
@@ -837,6 +834,33 @@
}
@Test
+ public void visitUris_intents() {
+ RemoteViews views = new RemoteViews(mPackage, R.layout.remote_views_test);
+
+ Uri fillIntentUri = Uri.parse("content://intent/fill");
+ views.setOnCheckedChangeResponse(
+ R.id.layout,
+ RemoteViews.RemoteResponse.fromFillInIntent(new Intent("action", fillIntentUri)));
+
+ Uri pendingIntentUri = Uri.parse("content://intent/pending");
+ PendingIntent pendingIntent = getPendingIntentWithUri(pendingIntentUri);
+ views.setOnClickResponse(
+ R.id.layout,
+ RemoteViews.RemoteResponse.fromPendingIntent(pendingIntent));
+
+ Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
+ views.visitUris(visitor);
+ verify(visitor, times(1)).accept(eq(fillIntentUri));
+ verify(visitor, times(1)).accept(eq(pendingIntentUri));
+ }
+
+ private PendingIntent getPendingIntentWithUri(Uri uri) {
+ return PendingIntent.getActivity(mContext, 0,
+ new Intent("action", uri),
+ PendingIntent.FLAG_IMMUTABLE);
+ }
+
+ @Test
public void layoutInflaterFactory_nothingSet_returnsNull() {
final RemoteViews rv = new RemoteViews(mPackage, R.layout.remote_views_test);
assertNull(rv.getLayoutInflaterFactory());
diff --git a/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java b/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java
index 8207c9e..b70f290 100644
--- a/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java
@@ -29,7 +29,9 @@
import android.os.Message;
import android.os.Process;
import android.os.SystemClock;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.ArrayMap;
import android.util.SparseArray;
@@ -39,6 +41,8 @@
import com.android.internal.os.BinderInternal.CallSession;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,13 +59,22 @@
@SmallTest
@RunWith(AndroidJUnit4.class)
@Presubmit
+@IgnoreUnderRavenwood(blockedBy = BinderCallsStats.class)
public class BinderCallsStatsTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private static final int WORKSOURCE_UID = Process.FIRST_APPLICATION_UID;
private static final int CALLING_UID = 2;
private static final int REQUEST_SIZE = 2;
private static final int REPLY_SIZE = 3;
private final CachedDeviceState mDeviceState = new CachedDeviceState(false, true);
- private final TestHandler mHandler = new TestHandler();
+ private TestHandler mHandler;
+
+ @Before
+ public void setUp() {
+ mHandler = new TestHandler();
+ }
@Test
public void testDetailedOff() {
diff --git a/core/tests/coretests/src/com/android/internal/os/BinderHeavyHitterTest.java b/core/tests/coretests/src/com/android/internal/os/BinderHeavyHitterTest.java
index e4597b5..a1b80d2 100644
--- a/core/tests/coretests/src/com/android/internal/os/BinderHeavyHitterTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/BinderHeavyHitterTest.java
@@ -16,11 +16,19 @@
package com.android.internal.os;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import android.os.Binder;
+import androidx.test.runner.AndroidJUnit4;
+
import com.android.internal.os.BinderCallHeavyHitterWatcher.HeavyHitterContainer;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.List;
@@ -29,7 +37,8 @@
/**
* Tests for {@link BinderCallHeavyHitterWatcher}.
*/
-public final class BinderHeavyHitterTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public final class BinderHeavyHitterTest {
private boolean mListenerNotified = false;
@@ -114,6 +123,7 @@
}
}
+ @Test
public void testPositive() throws Exception {
BinderCallHeavyHitterWatcher watcher = BinderCallHeavyHitterWatcher.getInstance();
try {
@@ -142,6 +152,7 @@
}
}
+ @Test
public void testNegative() throws Exception {
BinderCallHeavyHitterWatcher watcher = BinderCallHeavyHitterWatcher.getInstance();
try {
diff --git a/core/tests/coretests/src/com/android/internal/os/BinderLatencyObserverTest.java b/core/tests/coretests/src/com/android/internal/os/BinderLatencyObserverTest.java
index 7bd53b9..31b55e6 100644
--- a/core/tests/coretests/src/com/android/internal/os/BinderLatencyObserverTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/BinderLatencyObserverTest.java
@@ -23,7 +23,9 @@
import static org.junit.Assert.assertEquals;
import android.os.Binder;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.ArrayMap;
import android.util.proto.ProtoOutputStream;
@@ -36,6 +38,7 @@
import com.android.internal.os.BinderLatencyProto.Dims;
import com.android.internal.os.BinderLatencyProto.RepeatedApiStats;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,7 +50,11 @@
@SmallTest
@RunWith(AndroidJUnit4.class)
@Presubmit
+@IgnoreUnderRavenwood(blockedBy = BinderLatencyObserver.class)
public class BinderLatencyObserverTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
@Test
public void testLatencyCollectionWithMultipleClasses() {
TestBinderLatencyObserver blo = new TestBinderLatencyObserver();
diff --git a/core/tests/coretests/src/com/android/internal/os/BinderfsStatsReaderTest.java b/core/tests/coretests/src/com/android/internal/os/BinderfsStatsReaderTest.java
index e9f6450..5f02f04 100644
--- a/core/tests/coretests/src/com/android/internal/os/BinderfsStatsReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/BinderfsStatsReaderTest.java
@@ -20,11 +20,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import android.content.Context;
import android.os.FileUtils;
import android.util.IntArray;
-import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -102,9 +100,8 @@
private boolean mHasError;
@Before
- public void setUp() {
- Context context = InstrumentationRegistry.getContext();
- mStatsDirectory = context.getDir("binder_logs", Context.MODE_PRIVATE);
+ public void setUp() throws Exception {
+ mStatsDirectory = Files.createTempDirectory("BinderfsStatsReaderTest").toFile();
mFreezerBinderAsyncThreshold = 1024;
mValidPids = IntArray.fromArray(new int[]{14505, 14461, 542, 540}, 4);
mStatsPids = new IntArray();
diff --git a/core/tests/coretests/src/com/android/internal/os/CpuScalingPolicyReaderTest.java b/core/tests/coretests/src/com/android/internal/os/CpuScalingPolicyReaderTest.java
index 7f054d1..2da3873 100644
--- a/core/tests/coretests/src/com/android/internal/os/CpuScalingPolicyReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/CpuScalingPolicyReaderTest.java
@@ -16,11 +16,8 @@
package com.android.internal.os;
-import static androidx.test.InstrumentationRegistry.getContext;
-
import static com.google.common.truth.Truth.assertThat;
-import android.content.Context;
import android.os.FileUtils;
import androidx.test.runner.AndroidJUnit4;
@@ -31,6 +28,7 @@
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
@RunWith(AndroidJUnit4.class)
public class CpuScalingPolicyReaderTest {
@@ -38,7 +36,7 @@
@Before
public void setup() throws IOException {
- File testDir = getContext().getDir("test", Context.MODE_PRIVATE);
+ File testDir = Files.createTempDirectory("CpuScalingPolicyReaderTest").toFile();
FileUtils.deleteContents(testDir);
File policy0 = new File(testDir, "policy0");
diff --git a/core/tests/coretests/src/com/android/internal/os/DebugTest.java b/core/tests/coretests/src/com/android/internal/os/DebugTest.java
index 2a8a857..4371f26 100644
--- a/core/tests/coretests/src/com/android/internal/os/DebugTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/DebugTest.java
@@ -16,14 +16,22 @@
package com.android.internal.os;
+import static org.junit.Assert.assertTrue;
+
import android.os.Debug;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;
-import junit.framework.TestCase;
+import org.junit.Rule;
+import org.junit.Test;
@SmallTest
-public class DebugTest extends TestCase {
+@IgnoreUnderRavenwood(reason = "Requires ART support")
+public class DebugTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private final static String EXPECTED_GET_CALLER =
"com\\.android\\.internal\\.os\\.DebugTest\\.testGetCaller:\\d\\d";
@@ -39,6 +47,7 @@
return Debug.getCaller();
}
+ @Test
public void testGetCaller() {
assertTrue(callDepth0().matches(EXPECTED_GET_CALLER));
}
@@ -62,6 +71,7 @@
return callDepth2();
}
+ @Test
public void testGetCallers() {
assertTrue(callDepth1().matches(EXPECTED_GET_CALLERS));
}
@@ -69,6 +79,7 @@
/**
* Regression test for b/31943543. Note: must be run under CheckJNI to detect the issue.
*/
+ @Test
public void testGetMemoryInfo() {
Debug.MemoryInfo info = new Debug.MemoryInfo();
Debug.getMemoryInfo(-1, info);
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuProcStringReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuProcStringReaderTest.java
index cbd2ba4..1d8628d 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuProcStringReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuProcStringReaderTest.java
@@ -24,6 +24,8 @@
import android.content.Context;
import android.os.FileUtils;
import android.os.SystemClock;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -31,6 +33,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,7 +60,11 @@
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuProcStringReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private File mRoot;
private File mTestDir;
private File mTestFile;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderDiffTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderDiffTest.java
index b45f8d2..a57a400 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderDiffTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderDiffTest.java
@@ -24,13 +24,16 @@
import static java.util.stream.Collectors.toList;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
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;
@@ -44,7 +47,10 @@
@Presubmit
@SmallTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuThreadReaderDiffTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private MockitoSession mMockingSessions;
@Mock KernelCpuThreadReader mMockReader;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java
index d43989c..8c5e3d0 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java
@@ -22,6 +22,8 @@
import android.os.Process;
import android.os.SystemClock;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
@@ -29,6 +31,7 @@
import com.android.internal.os.KernelCpuThreadReader.ProcessCpuUsage;
import com.android.internal.os.KernelCpuThreadReader.ThreadCpuUsage;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,7 +50,10 @@
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuThreadReaderEndToEndTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private static final int TIMED_NUM_SAMPLES = 5;
private static final int TIMED_START_MILLIS = 500;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java
index c3e4014..7eac2a3 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java
@@ -25,7 +25,9 @@
import android.content.Context;
import android.os.FileUtils;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -33,6 +35,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -48,7 +51,11 @@
@Presubmit
@SmallTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuThreadReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private File mProcDirectory;
@Before
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidActiveTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidActiveTimeReaderTest.java
index 2ccd74e..d35e0fc 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidActiveTimeReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidActiveTimeReaderTest.java
@@ -21,6 +21,8 @@
import android.content.Context;
import android.os.FileUtils;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.SparseArray;
import android.util.SparseLongArray;
@@ -31,6 +33,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -51,7 +54,11 @@
*/
@SmallTest
@RunWith(Parameterized.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuUidActiveTimeReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private File mTestDir;
private File mTestFile;
private KernelCpuUidActiveTimeReader mReader;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidBpfMapReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidBpfMapReaderTest.java
index bda21c6..610e6ae 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidBpfMapReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidBpfMapReaderTest.java
@@ -23,11 +23,15 @@
import static org.junit.Assert.assertTrue;
import android.content.Context;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.SparseArray;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
import org.junit.runner.RunWith;
import com.android.internal.os.KernelCpuUidBpfMapReader.BpfMapIterator;
@@ -50,7 +54,11 @@
@SmallTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuUidBpfMapReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private Random mRand = new Random(12345);
private KernelCpuUidTestBpfMapReader mReader;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidClusterTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidClusterTimeReaderTest.java
index a0dab28..8807de0 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidClusterTimeReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidClusterTimeReaderTest.java
@@ -23,6 +23,8 @@
import android.content.Context;
import android.os.FileUtils;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.SparseArray;
import androidx.test.InstrumentationRegistry;
@@ -32,6 +34,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -52,7 +55,11 @@
*/
@SmallTest
@RunWith(Parameterized.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuUidClusterTimeReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private File mTestDir;
private File mTestFile;
private KernelCpuUidClusterTimeReader mReader;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidFreqTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidFreqTimeReaderTest.java
index 783f264..b730344 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidFreqTimeReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidFreqTimeReaderTest.java
@@ -24,6 +24,8 @@
import android.content.Context;
import android.os.FileUtils;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.SparseArray;
import androidx.test.InstrumentationRegistry;
@@ -33,6 +35,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -55,7 +58,11 @@
*/
@SmallTest
@RunWith(Parameterized.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuUidFreqTimeReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private File mTestDir;
private File mTestFile;
private KernelCpuUidFreqTimeReader mReader;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java
index 1da1a90..6507226 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java
@@ -23,6 +23,8 @@
import android.content.Context;
import android.os.FileUtils;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.SparseArray;
import androidx.test.InstrumentationRegistry;
@@ -33,6 +35,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -49,7 +52,11 @@
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelCpuUidUserSysTimeReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private File mTestDir;
private File mTestFile;
private KernelCpuUidTimeReader.KernelCpuUidUserSysTimeReader mReader;
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelMemoryBandwidthStatsTest.java b/core/tests/coretests/src/com/android/internal/os/KernelMemoryBandwidthStatsTest.java
index 60dac85..ad5186e 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelMemoryBandwidthStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelMemoryBandwidthStatsTest.java
@@ -16,12 +16,18 @@
package com.android.internal.os;
+import static org.junit.Assert.assertEquals;
+
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.LongSparseLongArray;
import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
-import junit.framework.TestCase;
-
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
import java.io.BufferedReader;
@@ -29,12 +35,17 @@
/**
* Tests for KernelMemoryBandwidthStats parsing and delta calculation, based on memory_state_time.
*/
-public class KernelMemoryBandwidthStatsTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
+public class KernelMemoryBandwidthStatsTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
/**
* Standard example of parsing stats.
* @throws Exception
*/
+ @Test
@SmallTest
public void testParseStandard() throws Exception {
KernelMemoryBandwidthStats stats = new KernelMemoryBandwidthStats();
@@ -68,6 +79,7 @@
* zero.
* @throws Exception
*/
+ @Test
@SmallTest
public void testParseBackwards() throws Exception {
KernelMemoryBandwidthStats zeroStats = new KernelMemoryBandwidthStats();
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelSingleProcessCpuThreadReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelSingleProcessCpuThreadReaderTest.java
index 2de800b..f42d26d 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelSingleProcessCpuThreadReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelSingleProcessCpuThreadReaderTest.java
@@ -19,9 +19,13 @@
import static com.google.common.truth.Truth.assertThat;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,7 +35,10 @@
@SmallTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelSingleProcessCpuThreadReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
@Test
public void getProcessCpuUsage() throws IOException {
diff --git a/core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java
index 74ab644..120a4de 100644
--- a/core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java
@@ -23,6 +23,8 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.util.SparseArray;
import androidx.test.filters.SmallTest;
@@ -30,6 +32,7 @@
import com.android.internal.os.KernelSingleUidTimeReader.Injector;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -43,7 +46,11 @@
@SmallTest
@RunWith(Parameterized.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class KernelSingleUidTimeReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private final static int TEST_UID = 2222;
private final static int TEST_FREQ_COUNT = 5;
diff --git a/core/tests/coretests/src/com/android/internal/os/LoggingPrintStreamTest.java b/core/tests/coretests/src/com/android/internal/os/LoggingPrintStreamTest.java
index cb8a62c..632dce0 100644
--- a/core/tests/coretests/src/com/android/internal/os/LoggingPrintStreamTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/LoggingPrintStreamTest.java
@@ -16,9 +16,13 @@
package com.android.internal.os;
-import androidx.test.filters.Suppress;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -28,11 +32,12 @@
import java.util.List;
// this test causes a IllegalAccessError: superclass not accessible
-@Suppress
-public class LoggingPrintStreamTest extends TestCase {
+@RunWith(AndroidJUnit4.class)
+public class LoggingPrintStreamTest {
TestPrintStream out = new TestPrintStream();
+ @Test
public void testPrintException() {
@SuppressWarnings("ThrowableInstanceNeverThrown")
Throwable t = new Throwable("Ignore me.");
@@ -47,6 +52,7 @@
assertEquals(Arrays.asList(lines), out.lines);
}
+ @Test
public void testPrintObject() {
Object o = new Object();
out.print(4);
@@ -56,6 +62,7 @@
assertEquals(Arrays.asList("4" + o + "2"), out.lines);
}
+ @Test
public void testPrintlnObject() {
Object o = new Object();
out.print(4);
@@ -65,6 +72,7 @@
assertEquals(Arrays.asList("4" + o, "2"), out.lines);
}
+ @Test
public void testPrintf() {
out.printf("Name: %s\nEmployer: %s", "Bob", "Google");
assertEquals(Arrays.asList("Name: Bob"), out.lines);
@@ -72,6 +80,7 @@
assertEquals(Arrays.asList("Name: Bob", "Employer: Google"), out.lines);
}
+ @Test
public void testPrintInt() {
out.print(4);
out.print(2);
@@ -80,12 +89,14 @@
assertEquals(Collections.singletonList("42"), out.lines);
}
+ @Test
public void testPrintlnInt() {
out.println(4);
out.println(2);
assertEquals(Arrays.asList("4", "2"), out.lines);
}
+ @Test
public void testPrintCharArray() {
out.print("Foo\nBar\nTee".toCharArray());
assertEquals(Arrays.asList("Foo", "Bar"), out.lines);
@@ -93,6 +104,7 @@
assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines);
}
+ @Test
public void testPrintString() {
out.print("Foo\nBar\nTee");
assertEquals(Arrays.asList("Foo", "Bar"), out.lines);
@@ -100,22 +112,26 @@
assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines);
}
+ @Test
public void testPrintlnCharArray() {
out.println("Foo\nBar\nTee".toCharArray());
assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines);
}
+ @Test
public void testPrintlnString() {
out.println("Foo\nBar\nTee");
assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines);
}
+ @Test
public void testPrintlnStringWithBufferedData() {
out.print(5);
out.println("Foo\nBar\nTee");
assertEquals(Arrays.asList("5Foo", "Bar", "Tee"), out.lines);
}
+ @Test
public void testAppend() {
out.append("Foo\n")
.append('4')
@@ -125,6 +141,7 @@
assertEquals(Arrays.asList("Foo", "4", "a"), out.lines);
}
+ @Test
public void testMultiByteCharactersSpanningBuffers() throws Exception {
// assume 3*1000 bytes won't fit in LoggingPrintStream's internal buffer
StringBuilder builder = new StringBuilder();
@@ -138,6 +155,7 @@
assertEquals(Arrays.asList(expected), out.lines);
}
+ @Test
public void testWriteOneByteAtATimeMultibyteCharacters() throws Exception {
String expected = " \u20AC \u20AC \u20AC \u20AC ";
for (byte b : expected.getBytes()) {
@@ -147,6 +165,7 @@
assertEquals(Arrays.asList(expected), out.lines);
}
+ @Test
public void testWriteByteArrayAtATimeMultibyteCharacters() throws Exception {
String expected = " \u20AC \u20AC \u20AC \u20AC ";
out.write(expected.getBytes());
@@ -154,6 +173,7 @@
assertEquals(Arrays.asList(expected), out.lines);
}
+ @Test
public void testWriteWithOffsetsMultibyteCharacters() throws Exception {
String expected = " \u20AC \u20AC \u20AC \u20AC ";
byte[] bytes = expected.getBytes();
@@ -167,6 +187,7 @@
assertEquals(Arrays.asList(expected), out.lines);
}
+ @Test
public void testWriteFlushesOnNewlines() throws Exception {
String a = " \u20AC \u20AC ";
String b = " \u20AC \u20AC ";
diff --git a/core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java b/core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java
index faccf1a..f34b185 100644
--- a/core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java
@@ -22,16 +22,22 @@
import android.os.BadParcelableException;
import android.os.Parcel;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
+@IgnoreUnderRavenwood(blockedBy = LongArrayMultiStateCounter.class)
public class LongArrayMultiStateCounterTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
@Test
public void setStateAndUpdateValue() {
diff --git a/core/tests/coretests/src/com/android/internal/os/LongMultiStateCounterTest.java b/core/tests/coretests/src/com/android/internal/os/LongMultiStateCounterTest.java
index 3413753..e064e74 100644
--- a/core/tests/coretests/src/com/android/internal/os/LongMultiStateCounterTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/LongMultiStateCounterTest.java
@@ -22,16 +22,22 @@
import android.os.BadParcelableException;
import android.os.Parcel;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
+@IgnoreUnderRavenwood(blockedBy = LongMultiStateCounterTest.class)
public class LongMultiStateCounterTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
@Test
public void setStateAndUpdateValue() {
diff --git a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java
index 48baf09..dfb5cc3 100644
--- a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java
@@ -23,6 +23,7 @@
import android.os.Looper;
import android.os.Message;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -30,6 +31,7 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,6 +42,9 @@
@RunWith(AndroidJUnit4.class)
@Presubmit
public final class LooperStatsTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
private HandlerThread mThreadFirst;
private HandlerThread mThreadSecond;
private Handler mHandlerFirst;
diff --git a/core/tests/coretests/src/com/android/internal/os/MonotonicClockTest.java b/core/tests/coretests/src/com/android/internal/os/MonotonicClockTest.java
index 7951270..0742052 100644
--- a/core/tests/coretests/src/com/android/internal/os/MonotonicClockTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/MonotonicClockTest.java
@@ -43,14 +43,12 @@
assertThat(monotonicClock.monotonicTime()).isEqualTo(1234);
ByteArrayOutputStream out = new ByteArrayOutputStream();
- monotonicClock.writeXml(out, Xml.newFastSerializer());
- String xml = out.toString();
- assertThat(xml).contains("timeshift=\"1234\"");
+ monotonicClock.writeXml(out, Xml.newBinarySerializer());
mClock.realtime = 42;
MonotonicClock newMonotonicClock = new MonotonicClock(0, mClock);
- newMonotonicClock.readXml(new ByteArrayInputStream(out.toByteArray()),
- Xml.newFastPullParser());
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ newMonotonicClock.readXml(in, Xml.newBinaryPullParser());
mClock.realtime = 2000;
assertThat(newMonotonicClock.monotonicTime()).isEqualTo(1234 - 42 + 2000);
diff --git a/core/tests/coretests/src/com/android/internal/os/PowerProfileTest.java b/core/tests/coretests/src/com/android/internal/os/PowerProfileTest.java
index 77202d1..c0f0714 100644
--- a/core/tests/coretests/src/com/android/internal/os/PowerProfileTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/PowerProfileTest.java
@@ -27,6 +27,8 @@
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -38,6 +40,7 @@
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,7 +53,10 @@
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = PowerProfile.class)
public class PowerProfileTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
static final String TAG_TEST_MODEM = "test-modem";
static final String ATTR_NAME = "name";
diff --git a/core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java b/core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java
index 29da231..b99e202 100644
--- a/core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java
@@ -21,17 +21,23 @@
import android.os.BatteryConsumer;
import android.os.Parcel;
import android.os.PersistableBundle;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class PowerStatsTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private PowerStats.DescriptorRegistry mRegistry;
private PowerStats.Descriptor mDescriptor;
diff --git a/core/tests/coretests/src/com/android/internal/os/ProcLocksReaderTest.java b/core/tests/coretests/src/com/android/internal/os/ProcLocksReaderTest.java
index c3d40eb..f61fc7c 100644
--- a/core/tests/coretests/src/com/android/internal/os/ProcLocksReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/ProcLocksReaderTest.java
@@ -18,11 +18,9 @@
import static org.junit.Assert.assertTrue;
-import android.content.Context;
import android.os.FileUtils;
import android.util.IntArray;
-import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -45,9 +43,8 @@
private ArrayList<int[]> mPids = new ArrayList<>();
@Before
- public void setUp() {
- Context context = InstrumentationRegistry.getContext();
- mProcDirectory = context.getDir("proc", Context.MODE_PRIVATE);
+ public void setUp() throws Exception {
+ mProcDirectory = Files.createTempDirectory("ProcLocksReaderTest").toFile();
}
@After
diff --git a/core/tests/coretests/src/com/android/internal/os/ProcStatsUtilTest.java b/core/tests/coretests/src/com/android/internal/os/ProcStatsUtilTest.java
index e97caf8..3e4f34d 100644
--- a/core/tests/coretests/src/com/android/internal/os/ProcStatsUtilTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/ProcStatsUtilTest.java
@@ -18,10 +18,8 @@
import static org.junit.Assert.assertEquals;
-import android.content.Context;
import android.os.FileUtils;
-import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -41,9 +39,8 @@
private File mProcDirectory;
@Before
- public void setUp() {
- Context context = InstrumentationRegistry.getContext();
- mProcDirectory = context.getDir("proc", Context.MODE_PRIVATE);
+ public void setUp() throws Exception {
+ mProcDirectory = Files.createTempDirectory("ProcStatsUtilTest").toFile();
}
@After
diff --git a/core/tests/coretests/src/com/android/internal/os/ProcTimeInStateReaderTest.java b/core/tests/coretests/src/com/android/internal/os/ProcTimeInStateReaderTest.java
index 9db3f8a..a706350 100644
--- a/core/tests/coretests/src/com/android/internal/os/ProcTimeInStateReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/ProcTimeInStateReaderTest.java
@@ -20,15 +20,16 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import android.content.Context;
import android.os.FileUtils;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
-import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,14 +40,16 @@
@SmallTest
@RunWith(AndroidJUnit4.class)
+@IgnoreUnderRavenwood(blockedBy = ProcTimeInStateReader.class)
public class ProcTimeInStateReaderTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
private File mProcDirectory;
@Before
- public void setUp() {
- Context context = InstrumentationRegistry.getContext();
- mProcDirectory = context.getDir("proc", Context.MODE_PRIVATE);
+ public void setUp() throws Exception {
+ mProcDirectory = Files.createTempDirectory("ProcTimeInStateReaderTest").toFile();
}
@After
diff --git a/core/tests/coretests/src/com/android/internal/os/ProcessCpuTrackerTest.java b/core/tests/coretests/src/com/android/internal/os/ProcessCpuTrackerTest.java
index 81cc9d8..d11c500 100644
--- a/core/tests/coretests/src/com/android/internal/os/ProcessCpuTrackerTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/ProcessCpuTrackerTest.java
@@ -18,15 +18,23 @@
import static com.google.common.truth.Truth.assertThat;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
+
import androidx.test.filters.SmallTest;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@SmallTest
@RunWith(JUnit4.class)
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class ProcessCpuTrackerTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
+
@Test
public void testGetCpuTime() throws Exception {
final ProcessCpuTracker tracker = new ProcessCpuTracker(false);
diff --git a/core/tests/coretests/src/com/android/internal/os/StoragedUidIoStatsReaderTest.java b/core/tests/coretests/src/com/android/internal/os/StoragedUidIoStatsReaderTest.java
index 85eafc5..84c93c2 100644
--- a/core/tests/coretests/src/com/android/internal/os/StoragedUidIoStatsReaderTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/StoragedUidIoStatsReaderTest.java
@@ -20,10 +20,8 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
-import android.content.Context;
import android.os.FileUtils;
-import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -48,7 +46,6 @@
@RunWith(AndroidJUnit4.class)
public class StoragedUidIoStatsReaderTest {
- private File mRoot;
private File mTestDir;
private File mTestFile;
// private Random mRand = new Random();
@@ -57,15 +54,10 @@
@Mock
private StoragedUidIoStatsReader.Callback mCallback;
- private Context getContext() {
- return InstrumentationRegistry.getContext();
- }
-
@Before
- public void setUp() {
+ public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mTestDir = getContext().getDir("test", Context.MODE_PRIVATE);
- mRoot = getContext().getFilesDir();
+ mTestDir = Files.createTempDirectory("StoragedUidIoStatsReaderTest").toFile();
mTestFile = new File(mTestDir, "test.file");
mStoragedUidIoStatsReader = new StoragedUidIoStatsReader(mTestFile.getAbsolutePath());
}
@@ -73,10 +65,8 @@
@After
public void tearDown() throws Exception {
FileUtils.deleteContents(mTestDir);
- FileUtils.deleteContents(mRoot);
}
-
/**
* Tests that reading will never call the callback.
*/
diff --git a/core/tests/coretests/src/com/android/internal/power/EnergyConsumerStatsTest.java b/core/tests/coretests/src/com/android/internal/power/EnergyConsumerStatsTest.java
index e09cfd2..ae2ef0cb 100644
--- a/core/tests/coretests/src/com/android/internal/power/EnergyConsumerStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/power/EnergyConsumerStatsTest.java
@@ -34,10 +34,13 @@
import static org.junit.Assert.assertTrue;
import android.os.Parcel;
+import android.platform.test.annotations.IgnoreUnderRavenwood;
+import android.platform.test.ravenwood.RavenwoodRule;
import android.view.Display;
import androidx.test.filters.SmallTest;
+import org.junit.Rule;
import org.junit.Test;
import java.util.Arrays;
@@ -46,7 +49,10 @@
* Test class for {@link EnergyConsumerStats}.
*/
@SmallTest
+@IgnoreUnderRavenwood(reason = "Needs kernel support")
public class EnergyConsumerStatsTest {
+ @Rule
+ public final RavenwoodRule mRavenwood = new RavenwoodRule();
@Test
public void testConstruction() {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
index 5843635..cf858dc 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
@@ -17,6 +17,7 @@
package com.android.wm.shell.back;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_PREDICTIVE_BACK_HOME;
+import static com.android.window.flags.Flags.predictiveBackSystemAnimations;
import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW;
import static com.android.wm.shell.sysui.ShellSharedConstants.KEY_EXTRA_SHELL_BACK_ANIMATION;
@@ -221,6 +222,7 @@
private void onInit() {
setupAnimationDeveloperSettingsObserver(mContentResolver, mBgHandler);
+ updateEnableAnimationFromFlags();
createAdapter();
mShellController.addExternalInterface(KEY_EXTRA_SHELL_BACK_ANIMATION,
this::createExternalInterface, this);
@@ -229,28 +231,39 @@
private void setupAnimationDeveloperSettingsObserver(
@NonNull ContentResolver contentResolver,
@NonNull @ShellBackgroundThread final Handler backgroundHandler) {
+ if (predictiveBackSystemAnimations()) {
+ ProtoLog.d(WM_SHELL_BACK_PREVIEW, "Back animation aconfig flag is enabled, therefore "
+ + "developer settings flag is ignored and no content observer registered");
+ return;
+ }
ContentObserver settingsObserver = new ContentObserver(backgroundHandler) {
@Override
public void onChange(boolean selfChange, Uri uri) {
- updateEnableAnimationFromSetting();
+ updateEnableAnimationFromFlags();
}
};
contentResolver.registerContentObserver(
Global.getUriFor(Global.ENABLE_BACK_ANIMATION),
false, settingsObserver, UserHandle.USER_SYSTEM
);
- updateEnableAnimationFromSetting();
}
+ /**
+ * Updates {@link BackAnimationController#mEnableAnimations} based on the current values of the
+ * aconfig flag and the developer settings flag
+ */
@ShellBackgroundThread
- private void updateEnableAnimationFromSetting() {
- int settingValue = Global.getInt(mContext.getContentResolver(),
- Global.ENABLE_BACK_ANIMATION, SETTING_VALUE_OFF);
- boolean isEnabled = settingValue == SETTING_VALUE_ON;
+ private void updateEnableAnimationFromFlags() {
+ boolean isEnabled = predictiveBackSystemAnimations() || isDeveloperSettingEnabled();
mEnableAnimations.set(isEnabled);
ProtoLog.d(WM_SHELL_BACK_PREVIEW, "Back animation enabled=%s", isEnabled);
}
+ private boolean isDeveloperSettingEnabled() {
+ return Global.getInt(mContext.getContentResolver(),
+ Global.ENABLE_BACK_ANIMATION, SETTING_VALUE_OFF) == SETTING_VALUE_ON;
+ }
+
public BackAnimation getBackAnimationImpl() {
return mBackAnimation;
}
diff --git a/packages/PackageInstaller/res/values/strings.xml b/packages/PackageInstaller/res/values/strings.xml
index 1c8a8d5..e3b93ba 100644
--- a/packages/PackageInstaller/res/values/strings.xml
+++ b/packages/PackageInstaller/res/values/strings.xml
@@ -85,6 +85,8 @@
<!-- [CHAR LIMIT=15] -->
<string name="ok">OK</string>
+ <!-- Confirmation text label for button to archive an application. Archiving means uninstalling the app without deleting user's personal data and replacing the app with a stub app with minimum size. So, the user can unarchive the app later and not lose any personal data. -->
+ <string name="archive">Archive</string>
<!-- [CHAR LIMIT=30] -->
<string name="update_anyway">Update anyway</string>
<!-- [CHAR LIMIT=15] -->
@@ -115,6 +117,16 @@
<!-- [CHAR LIMIT=none] -->
<string name="uninstall_application_text">Do you want to uninstall this app?</string>
<!-- [CHAR LIMIT=none] -->
+ <string name="archive_application_text">Your personal data will be saved</string>
+ <!-- [CHAR LIMIT=none] -->
+ <string name="archive_application_text_all_users">Archive this app for all users? Your personal data will be saved</string>
+ <!-- [CHAR LIMIT=none] -->
+ <string name="archive_application_text_current_user_work_profile">Archive this app on your work profile? Your personal data will be saved</string>
+ <!-- [CHAR LIMIT=none] -->
+ <string name="archive_application_text_user">Archive this app for <xliff:g id="username">%1$s</xliff:g>? Your personal data will be saved</string>
+ <!-- [CHAR LIMIT=none] -->
+ <string name="archive_application_text_current_user_private_profile">Do you want to archive this app from your private space? Your personal data will be saved</string>
+ <!-- [CHAR LIMIT=none] -->
<string name="uninstall_application_text_all_users">Do you want to uninstall this app for <b>all</b>
users? The application and its data will be removed from <b>all</b> users on the device.</string>
<!-- [CHAR LIMIT=none] -->
@@ -239,6 +251,8 @@
<!-- Label for cloned app in uninstall dialogue [CHAR LIMIT=40] -->
<string name="cloned_app_label"><xliff:g id="package_label">%1$s</xliff:g> Clone</string>
+ <!-- Label for archiving an app in uninstall dialogue -->
+ <string name="archiving_app_label">Archive <xliff:g id="package_label">%1$s</xliff:g>?</string>
<!-- Label for button to continue install of an app whose source cannot be identified [CHAR LIMIT=40] -->
<string name="anonymous_source_continue">Continue</string>
diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java b/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java
index e889050..e07e942 100644
--- a/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java
+++ b/packages/PackageInstaller/src/com/android/packageinstaller/handheld/UninstallAlertDialogFragment.java
@@ -130,6 +130,9 @@
final boolean isUpdate =
((dialogInfo.appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
+ final boolean isArchive =
+ android.content.pm.Flags.archiving() && (
+ (dialogInfo.deleteFlags & PackageManager.DELETE_ARCHIVE) != 0);
final UserHandle myUserHandle = Process.myUserHandle();
UserManager userManager = getContext().getSystemService(UserManager.class);
if (isUpdate) {
@@ -140,7 +143,9 @@
}
} else {
if (dialogInfo.allUsers && !isSingleUser(userManager)) {
- messageBuilder.append(getString(R.string.uninstall_application_text_all_users));
+ messageBuilder.append(
+ isArchive ? getString(R.string.archive_application_text_all_users)
+ : getString(R.string.uninstall_application_text_all_users));
} else if (!dialogInfo.user.equals(myUserHandle)) {
int userId = dialogInfo.user.getIdentifier();
UserManager customUserManager = getContext()
@@ -150,9 +155,11 @@
if (customUserManager.isUserOfType(USER_TYPE_PROFILE_MANAGED)
&& customUserManager.isSameProfileGroup(dialogInfo.user, myUserHandle)) {
- messageBuilder.append(
- getString(R.string.uninstall_application_text_current_user_work_profile,
- userName));
+ messageBuilder.append(isArchive
+ ? getString(R.string.archive_application_text_current_user_work_profile,
+ userName) : getString(
+ R.string.uninstall_application_text_current_user_work_profile,
+ userName));
} else if (customUserManager.isUserOfType(USER_TYPE_PROFILE_CLONE)
&& customUserManager.isSameProfileGroup(dialogInfo.user, myUserHandle)) {
mIsClonedApp = true;
@@ -161,9 +168,14 @@
} else if (Flags.allowPrivateProfile()
&& customUserManager.isPrivateProfile()
&& customUserManager.isSameProfileGroup(dialogInfo.user, myUserHandle)) {
- messageBuilder.append(getString(
+ messageBuilder.append(isArchive ? getString(
+ R.string.archive_application_text_current_user_private_profile,
+ userName) : getString(
R.string.uninstall_application_text_current_user_private_profile,
userName));
+ } else if (isArchive) {
+ messageBuilder.append(
+ getString(R.string.archive_application_text_user, userName));
} else {
messageBuilder.append(
getString(R.string.uninstall_application_text_user, userName));
@@ -172,24 +184,27 @@
mIsClonedApp = true;
messageBuilder.append(getString(
R.string.uninstall_application_text_current_user_clone_profile));
+ } else if (Process.myUserHandle().equals(UserHandle.SYSTEM)
+ && hasClonedInstance(dialogInfo.appInfo.packageName)) {
+ messageBuilder.append(getString(
+ R.string.uninstall_application_text_with_clone_instance,
+ appLabel));
+ } else if (isArchive) {
+ messageBuilder.append(getString(R.string.archive_application_text));
} else {
- if (Process.myUserHandle().equals(UserHandle.SYSTEM)
- && hasClonedInstance(dialogInfo.appInfo.packageName)) {
- messageBuilder.append(getString(
- R.string.uninstall_application_text_with_clone_instance,
- appLabel));
- } else {
- messageBuilder.append(getString(R.string.uninstall_application_text));
- }
+ messageBuilder.append(getString(R.string.uninstall_application_text));
}
}
if (mIsClonedApp) {
dialogBuilder.setTitle(getString(R.string.cloned_app_label, appLabel));
+ } else if (isArchive) {
+ dialogBuilder.setTitle(getString(R.string.archiving_app_label, appLabel));
} else {
dialogBuilder.setTitle(appLabel);
}
- dialogBuilder.setPositiveButton(android.R.string.ok, this);
+ dialogBuilder.setPositiveButton(isArchive ? R.string.archive : android.R.string.ok,
+ this);
dialogBuilder.setNegativeButton(android.R.string.cancel, this);
String pkg = dialogInfo.appInfo.packageName;
@@ -199,7 +214,7 @@
PackageInfo pkgInfo = pm.getPackageInfo(pkg,
PackageManager.PackageInfoFlags.of(PackageManager.MATCH_ARCHIVED_PACKAGES));
- suggestToKeepAppData = pkgInfo.applicationInfo.hasFragileUserData();
+ suggestToKeepAppData = pkgInfo.applicationInfo.hasFragileUserData() && !isArchive;
} catch (PackageManager.NameNotFoundException e) {
Log.e(LOG_TAG, "Cannot check hasFragileUserData for " + pkg, e);
suggestToKeepAppData = false;
diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
index 8795fb1..ec456e0 100644
--- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
+++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
@@ -73,6 +73,7 @@
Settings.Secure.TTS_ENABLED_PLUGINS,
Settings.Secure.TTS_DEFAULT_LOCALE,
Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD,
+ Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS,
Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, // moved to global
Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, // moved to global
Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, // moved to global
diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
index 067fcc1..5ad14ce 100644
--- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
+++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
@@ -119,6 +119,7 @@
VALIDATORS.put(Secure.TTS_ENABLED_PLUGINS, new PackageNameListValidator(" "));
VALIDATORS.put(Secure.TTS_DEFAULT_LOCALE, TTS_LIST_VALIDATOR);
VALIDATORS.put(Secure.SHOW_IME_WITH_HARD_KEYBOARD, BOOLEAN_VALIDATOR);
+ VALIDATORS.put(Secure.ACCESSIBILITY_BOUNCE_KEYS, ANY_INTEGER_VALIDATOR);
VALIDATORS.put(Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, NON_NEGATIVE_INTEGER_VALIDATOR);
VALIDATORS.put(Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, NON_NEGATIVE_INTEGER_VALIDATOR);
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/BouncerContent.kt b/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/BouncerContent.kt
index 47f5663..1d7c7d63 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/BouncerContent.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/BouncerContent.kt
@@ -33,7 +33,6 @@
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
@@ -311,15 +310,21 @@
Row(
modifier =
- modifier.pointerInput(Unit) {
- detectTapGestures(
- onDoubleTap = { offset ->
- // Depending on where the user double tapped, switch the elements such that
- // the endContent is closer to the side that was double tapped.
- setSwapped(offset.x < size.width / 2)
- }
- )
- },
+ modifier
+ .pointerInput(Unit) {
+ detectTapGestures(
+ onDoubleTap = { offset ->
+ // Depending on where the user double tapped, switch the elements such
+ // that the non-swapped element is closer to the side that was double
+ // tapped.
+ setSwapped(offset.x < size.width / 2)
+ }
+ )
+ }
+ .padding(
+ top = if (isHeightExpanded) 128.dp else 96.dp,
+ bottom = if (isHeightExpanded) 128.dp else 48.dp,
+ ),
) {
val animatedOffset by
animateFloatAsState(
@@ -359,20 +364,11 @@
UserSwitcher(
viewModel = viewModel,
- modifier = Modifier.weight(1f).align(Alignment.CenterVertically).swappable(),
+ modifier = Modifier.weight(1f).swappable(),
)
FoldAware(
- modifier =
- Modifier.weight(1f)
- .padding(
- if (isHeightExpanded) {
- PaddingValues(vertical = 128.dp)
- } else {
- PaddingValues(top = 94.dp, bottom = 48.dp)
- }
- )
- .swappable(inversed = true),
+ modifier = Modifier.weight(1f).swappable(inversed = true),
viewModel = viewModel,
aboveFold = {
Column(
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Element.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Element.kt
index 2b11952..31604a6 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Element.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Element.kt
@@ -213,22 +213,11 @@
override fun onDetach() {
super.onDetach()
removeNodeFromSceneValues()
+ maybePruneMaps(layoutImpl, element, sceneValues)
}
private fun removeNodeFromSceneValues() {
sceneValues.nodes.remove(this)
-
- // If element is not composed from this scene anymore, remove the scene values. This works
- // because [onAttach] is called before [onDetach], so if an element is moved from the UI
- // tree we will first add the new code location then remove the old one.
- if (sceneValues.nodes.isEmpty()) {
- element.sceneValues.remove(sceneValues.scene)
- }
-
- // If the element is not composed in any scene, remove it from the elements map.
- if (element.sceneValues.isEmpty()) {
- layoutImpl.elements.remove(element.key)
- }
}
fun update(
@@ -237,12 +226,16 @@
element: Element,
sceneValues: Element.TargetValues,
) {
+ check(layoutImpl == this.layoutImpl && scene == this.scene)
removeNodeFromSceneValues()
- this.layoutImpl = layoutImpl
- this.scene = scene
+
+ val prevElement = this.element
+ val prevSceneValues = this.sceneValues
this.element = element
this.sceneValues = sceneValues
+
addNodeToSceneValues()
+ maybePruneMaps(layoutImpl, prevElement, prevSceneValues)
}
override fun ContentDrawScope.draw() {
@@ -261,6 +254,28 @@
}
}
}
+
+ companion object {
+ private fun maybePruneMaps(
+ layoutImpl: SceneTransitionLayoutImpl,
+ element: Element,
+ sceneValues: Element.TargetValues,
+ ) {
+ // If element is not composed from this scene anymore, remove the scene values. This
+ // works because [onAttach] is called before [onDetach], so if an element is moved from
+ // the UI tree we will first add the new code location then remove the old one.
+ if (
+ sceneValues.nodes.isEmpty() && element.sceneValues[sceneValues.scene] == sceneValues
+ ) {
+ element.sceneValues.remove(sceneValues.scene)
+
+ // If the element is not composed in any scene, remove it from the elements map.
+ if (element.sceneValues.isEmpty() && layoutImpl.elements[element.key] == element) {
+ layoutImpl.elements.remove(element.key)
+ }
+ }
+ }
+ }
}
private fun shouldDrawElement(
@@ -615,7 +630,9 @@
val toValues = element.sceneValues[toScene]
if (fromValues == null && toValues == null) {
- error("This should not happen, element $element is neither in $fromScene or $toScene")
+ // TODO(b/311600838): Throw an exception instead once layers of disposed elements are not
+ // run anymore.
+ return lastValue()
}
// The element is shared: interpolate between the value in fromScene and the value in toScene.
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneGestureHandler.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneGestureHandler.kt
index 212c9eb6..01179d3 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneGestureHandler.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneGestureHandler.kt
@@ -604,6 +604,7 @@
behavior.canStartOnPostFling && hasNextScene(velocityAvailable)
},
canContinueScroll = { true },
+ canScrollOnFling = false,
onStart = { offsetAvailable ->
gestureHandler.gestureWithPriority = this
gestureHandler.onDragStarted(
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDsl.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDsl.kt
index f820074..dfa2a9a 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDsl.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDsl.kt
@@ -226,12 +226,17 @@
)
/**
- * Scale the element(s) matching [matcher] so that it grows/shrinks to the same size as [anchor]
- * .
+ * Scale the element(s) matching [matcher] so that it grows/shrinks to the same size as
+ * [anchor].
*
* Note: This currently only works if [anchor] is a shared element of this transition.
*/
- fun anchoredSize(matcher: ElementMatcher, anchor: ElementKey)
+ fun anchoredSize(
+ matcher: ElementMatcher,
+ anchor: ElementKey,
+ anchorWidth: Boolean = true,
+ anchorHeight: Boolean = true,
+ )
}
/** The edge of a [SceneTransitionLayout]. */
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDslImpl.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDslImpl.kt
index 8c0a5a3..8f4a36e 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDslImpl.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDslImpl.kt
@@ -178,7 +178,12 @@
transformation(DrawScale(matcher, scaleX, scaleY, pivot))
}
- override fun anchoredSize(matcher: ElementMatcher, anchor: ElementKey) {
- transformation(AnchoredSize(matcher, anchor))
+ override fun anchoredSize(
+ matcher: ElementMatcher,
+ anchor: ElementKey,
+ anchorWidth: Boolean,
+ anchorHeight: Boolean,
+ ) {
+ transformation(AnchoredSize(matcher, anchor, anchorWidth, anchorHeight))
}
}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transformation/AnchoredSize.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transformation/AnchoredSize.kt
index 95385d5..40c814e 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transformation/AnchoredSize.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/transformation/AnchoredSize.kt
@@ -29,6 +29,8 @@
internal class AnchoredSize(
override val matcher: ElementMatcher,
private val anchor: ElementKey,
+ private val anchorWidth: Boolean,
+ private val anchorHeight: Boolean,
) : PropertyTransformation<IntSize> {
override fun transform(
layoutImpl: SceneTransitionLayoutImpl,
@@ -41,7 +43,10 @@
fun anchorSizeIn(scene: SceneKey): IntSize {
val size = layoutImpl.elements[anchor]?.sceneValues?.get(scene)?.targetSize
return if (size != null && size != Element.SizeUnspecified) {
- size
+ IntSize(
+ width = if (anchorWidth) size.width else value.width,
+ height = if (anchorHeight) size.height else value.height,
+ )
} else {
value
}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt b/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt
index cea8d9a..2c96d0e 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt
@@ -16,9 +16,8 @@
package com.android.compose.nestedscroll
-import androidx.compose.ui.geometry.Offset
+import androidx.compose.foundation.gestures.Orientation
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
-import androidx.compose.ui.input.nestedscroll.NestedScrollSource
/**
* A [NestedScrollConnection] that listens for all vertical scroll events and responds in the
@@ -34,59 +33,44 @@
*
* @sample com.android.compose.animation.scene.demo.Shade
*/
-class LargeTopAppBarNestedScrollConnection(
- private val height: () -> Float,
- private val onChangeHeight: (Float) -> Unit,
- private val minHeight: Float,
- private val maxHeight: Float,
-) : NestedScrollConnection {
-
- constructor(
- height: () -> Float,
- onHeightChanged: (Float) -> Unit,
- heightRange: ClosedFloatingPointRange<Float>,
- ) : this(
- height = height,
- onChangeHeight = onHeightChanged,
- minHeight = heightRange.start,
- maxHeight = heightRange.endInclusive,
+fun LargeTopAppBarNestedScrollConnection(
+ height: () -> Float,
+ onHeightChanged: (Float) -> Unit,
+ heightRange: ClosedFloatingPointRange<Float>,
+): PriorityNestedScrollConnection {
+ val minHeight = heightRange.start
+ val maxHeight = heightRange.endInclusive
+ return PriorityNestedScrollConnection(
+ orientation = Orientation.Vertical,
+ // When swiping up, the LargeTopAppBar will shrink (to [minHeight]) and the content will
+ // expand. Then, you can then scroll down the content.
+ canStartPreScroll = { offsetAvailable, offsetBeforeStart ->
+ offsetAvailable < 0 && offsetBeforeStart == 0f && height() > minHeight
+ },
+ // When swiping down, the content will scroll up until it reaches the top. Then, the
+ // LargeTopAppBar will expand until it reaches its [maxHeight].
+ canStartPostScroll = { offsetAvailable, _ -> offsetAvailable > 0 && height() < maxHeight },
+ canStartPostFling = { false },
+ canContinueScroll = {
+ val currentHeight = height()
+ minHeight < currentHeight && currentHeight < maxHeight
+ },
+ canScrollOnFling = true,
+ onStart = { /* do nothing */},
+ onScroll = { offsetAvailable ->
+ val currentHeight = height()
+ val amountConsumed =
+ if (offsetAvailable > 0) {
+ val amountLeft = maxHeight - currentHeight
+ offsetAvailable.coerceAtMost(amountLeft)
+ } else {
+ val amountLeft = minHeight - currentHeight
+ offsetAvailable.coerceAtLeast(amountLeft)
+ }
+ onHeightChanged(currentHeight + amountConsumed)
+ amountConsumed
+ },
+ // Don't consume the velocity on pre/post fling
+ onStop = { 0f },
)
-
- /**
- * When swiping up, the LargeTopAppBar will shrink (to [minHeight]) and the content will expand.
- * Then, you can then scroll down the content.
- */
- override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
- val y = available.y
- val currentHeight = height()
- if (y >= 0 || currentHeight <= minHeight) {
- return Offset.Zero
- }
-
- val amountLeft = minHeight - currentHeight
- val amountConsumed = y.coerceAtLeast(amountLeft)
- onChangeHeight(currentHeight + amountConsumed)
- return Offset(0f, amountConsumed)
- }
-
- /**
- * When swiping down, the content will scroll up until it reaches the top. Then, the
- * LargeTopAppBar will expand until it reaches its [maxHeight].
- */
- override fun onPostScroll(
- consumed: Offset,
- available: Offset,
- source: NestedScrollSource
- ): Offset {
- val y = available.y
- val currentHeight = height()
- if (y <= 0 || currentHeight >= maxHeight) {
- return Offset.Zero
- }
-
- val amountLeft = maxHeight - currentHeight
- val amountConsumed = y.coerceAtMost(amountLeft)
- onChangeHeight(currentHeight + amountConsumed)
- return Offset(0f, amountConsumed)
- }
}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt b/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt
index c49a2b8..2841bcf 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/PriorityNestedScrollConnection.kt
@@ -38,6 +38,7 @@
private val canStartPostScroll: (offsetAvailable: Offset, offsetBeforeStart: Offset) -> Boolean,
private val canStartPostFling: (velocityAvailable: Velocity) -> Boolean,
private val canContinueScroll: () -> Boolean,
+ private val canScrollOnFling: Boolean,
private val onStart: (offsetAvailable: Offset) -> Unit,
private val onScroll: (offsetAvailable: Offset) -> Offset,
private val onStop: (velocityAvailable: Velocity) -> Velocity,
@@ -59,7 +60,7 @@
if (
isPriorityMode ||
- source == NestedScrollSource.Fling ||
+ (source == NestedScrollSource.Fling && !canScrollOnFling) ||
!canStartPostScroll(available, offsetBeforeStart)
) {
// The priority mode cannot start so we won't consume the available offset.
@@ -71,7 +72,7 @@
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
if (!isPriorityMode) {
- if (source != NestedScrollSource.Fling) {
+ if (source != NestedScrollSource.Fling || canScrollOnFling) {
if (canStartPreScroll(available, offsetScrolledBeforePriorityMode)) {
return onPriorityStart(available)
}
@@ -98,12 +99,20 @@
}
override suspend fun onPreFling(available: Velocity): Velocity {
+ if (isPriorityMode && canScrollOnFling) {
+ // We don't want to consume the velocity, we prefer to continue receiving scroll events.
+ return Velocity.Zero
+ }
// Step 3b: The finger is lifted, we can stop intercepting scroll events and use the speed
// of the fling gesture.
return onPriorityStop(velocity = available)
}
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
+ if (isPriorityMode) {
+ return onPriorityStop(velocity = available)
+ }
+
if (!canStartPostFling(available)) {
return Velocity.Zero
}
@@ -156,6 +165,7 @@
canStartPostScroll: (offsetAvailable: Float, offsetBeforeStart: Float) -> Boolean,
canStartPostFling: (velocityAvailable: Float) -> Boolean,
canContinueScroll: () -> Boolean,
+ canScrollOnFling: Boolean,
onStart: (offsetAvailable: Float) -> Unit,
onScroll: (offsetAvailable: Float) -> Float,
onStop: (velocityAvailable: Float) -> Float,
@@ -172,6 +182,7 @@
canStartPostFling(velocityAvailable.toFloat())
},
canContinueScroll = canContinueScroll,
+ canScrollOnFling = canScrollOnFling,
onStart = { offsetAvailable -> onStart(offsetAvailable.toFloat()) },
onScroll = { offsetAvailable: Offset ->
onScroll(offsetAvailable.toFloat()).toOffset()
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 ce3e1db..439dc00 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
@@ -17,16 +17,21 @@
package com.android.compose.animation.scene
import androidx.compose.animation.core.tween
+import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.pager.HorizontalPager
+import androidx.compose.foundation.pager.PagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
@@ -36,6 +41,9 @@
import androidx.compose.ui.unit.dp
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertThrows
import org.junit.Rule
import org.junit.Test
@@ -430,6 +438,97 @@
}
@Test
+ @OptIn(ExperimentalFoundationApi::class)
+ fun elementModifierNodeIsRecycledInLazyLayouts() = runTest {
+ val nPages = 2
+ val pagerState = PagerState(currentPage = 0) { nPages }
+ var nullableLayoutImpl: SceneTransitionLayoutImpl? = null
+
+ // This is how we scroll a pager inside a test, as explained in b/315457147#comment2.
+ lateinit var scrollScope: CoroutineScope
+ fun scrollToPage(page: Int) {
+ var animationFinished by mutableStateOf(false)
+ rule.runOnIdle {
+ scrollScope.launch {
+ pagerState.scrollToPage(page)
+ animationFinished = true
+ }
+ }
+ rule.waitUntil(timeoutMillis = 10_000) { animationFinished }
+ }
+
+ rule.setContent {
+ scrollScope = rememberCoroutineScope()
+
+ SceneTransitionLayoutForTesting(
+ currentScene = TestScenes.SceneA,
+ onChangeScene = {},
+ transitions = remember { transitions {} },
+ state = remember { SceneTransitionLayoutState(TestScenes.SceneA) },
+ edgeDetector = DefaultEdgeDetector,
+ modifier = Modifier,
+ transitionInterceptionThreshold = 0f,
+ onLayoutImpl = { nullableLayoutImpl = it },
+ ) {
+ scene(TestScenes.SceneA) {
+ // The pages are full-size and beyondBoundsPageCount is 0, so at rest only one
+ // page should be composed.
+ HorizontalPager(
+ pagerState,
+ beyondBoundsPageCount = 0,
+ ) { page ->
+ when (page) {
+ 0 -> Box(Modifier.element(TestElements.Foo).fillMaxSize())
+ 1 -> Box(Modifier.fillMaxSize())
+ else -> error("page $page < nPages $nPages")
+ }
+ }
+ }
+ }
+ }
+
+ assertThat(nullableLayoutImpl).isNotNull()
+ val layoutImpl = nullableLayoutImpl!!
+
+ // There is only Foo in the elements map.
+ assertThat(layoutImpl.elements.keys).containsExactly(TestElements.Foo)
+ val element = layoutImpl.elements.getValue(TestElements.Foo)
+ val sceneValues = element.sceneValues
+ assertThat(sceneValues.keys).containsExactly(TestScenes.SceneA)
+
+ // Get the ElementModifier node that should be reused later on when coming back to this
+ // page.
+ val nodes = sceneValues.getValue(TestScenes.SceneA).nodes
+ assertThat(nodes).hasSize(1)
+ val node = nodes.single()
+
+ // Go to the second page.
+ scrollToPage(1)
+ rule.waitForIdle()
+
+ assertThat(nodes).isEmpty()
+ assertThat(sceneValues).isEmpty()
+ assertThat(layoutImpl.elements).isEmpty()
+
+ // Go back to the first page.
+ scrollToPage(0)
+ rule.waitForIdle()
+
+ assertThat(layoutImpl.elements.keys).containsExactly(TestElements.Foo)
+ val newElement = layoutImpl.elements.getValue(TestElements.Foo)
+ val newSceneValues = newElement.sceneValues
+ assertThat(newElement).isNotEqualTo(element)
+ assertThat(newSceneValues).isNotEqualTo(sceneValues)
+ assertThat(newSceneValues.keys).containsExactly(TestScenes.SceneA)
+
+ // The ElementModifier node should be the same as before.
+ val newNodes = newSceneValues.getValue(TestScenes.SceneA).nodes
+ assertThat(newNodes).hasSize(1)
+ val newNode = newNodes.single()
+ assertThat(newNode).isSameInstanceAs(node)
+ }
+
+ @Test
fun existingElementsDontRecomposeWhenTransitionStateChanges() {
var fooCompositions = 0
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/transformation/AnchoredSizeTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/transformation/AnchoredSizeTest.kt
index 8ef6757..e555a01 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/transformation/AnchoredSizeTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/transformation/AnchoredSizeTest.kt
@@ -85,4 +85,50 @@
after { onElement(TestElements.Bar).assertDoesNotExist() }
}
}
+
+ @Test
+ fun testAnchoredWidthOnly() {
+ rule.testTransition(
+ fromSceneContent = { Box(Modifier.size(100.dp, 100.dp).element(TestElements.Foo)) },
+ toSceneContent = {
+ Box(Modifier.size(50.dp, 50.dp).element(TestElements.Foo))
+ Box(Modifier.size(200.dp, 60.dp).element(TestElements.Bar))
+ },
+ transition = {
+ spec = tween(16 * 4, easing = LinearEasing)
+ anchoredSize(TestElements.Bar, TestElements.Foo, anchorHeight = false)
+ },
+ ) {
+ before { onElement(TestElements.Bar).assertDoesNotExist() }
+ at(0) { onElement(TestElements.Bar).assertSizeIsEqualTo(100.dp, 60.dp) }
+ at(16) { onElement(TestElements.Bar).assertSizeIsEqualTo(125.dp, 60.dp) }
+ at(32) { onElement(TestElements.Bar).assertSizeIsEqualTo(150.dp, 60.dp) }
+ at(48) { onElement(TestElements.Bar).assertSizeIsEqualTo(175.dp, 60.dp) }
+ at(64) { onElement(TestElements.Bar).assertSizeIsEqualTo(200.dp, 60.dp) }
+ after { onElement(TestElements.Bar).assertSizeIsEqualTo(200.dp, 60.dp) }
+ }
+ }
+
+ @Test
+ fun testAnchoredHeightOnly() {
+ rule.testTransition(
+ fromSceneContent = { Box(Modifier.size(100.dp, 100.dp).element(TestElements.Foo)) },
+ toSceneContent = {
+ Box(Modifier.size(50.dp, 50.dp).element(TestElements.Foo))
+ Box(Modifier.size(200.dp, 60.dp).element(TestElements.Bar))
+ },
+ transition = {
+ spec = tween(16 * 4, easing = LinearEasing)
+ anchoredSize(TestElements.Bar, TestElements.Foo, anchorWidth = false)
+ },
+ ) {
+ before { onElement(TestElements.Bar).assertDoesNotExist() }
+ at(0) { onElement(TestElements.Bar).assertSizeIsEqualTo(200.dp, 100.dp) }
+ at(16) { onElement(TestElements.Bar).assertSizeIsEqualTo(200.dp, 90.dp) }
+ at(32) { onElement(TestElements.Bar).assertSizeIsEqualTo(200.dp, 80.dp) }
+ at(48) { onElement(TestElements.Bar).assertSizeIsEqualTo(200.dp, 70.dp) }
+ at(64) { onElement(TestElements.Bar).assertSizeIsEqualTo(200.dp, 60.dp) }
+ after { onElement(TestElements.Bar).assertSizeIsEqualTo(200.dp, 60.dp) }
+ }
+ }
}
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt
index 03d231a..e2974cd 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt
@@ -17,6 +17,7 @@
package com.android.compose.nestedscroll
import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import com.google.common.truth.Truth.assertThat
import org.junit.Test
@@ -36,6 +37,15 @@
heightRange = heightRange,
)
+ private fun NestedScrollConnection.scroll(
+ available: Offset,
+ consumedByScroll: Offset = Offset.Zero,
+ ) {
+ val consumedByPreScroll = onPreScroll(available = available, source = scrollSource)
+ val consumed = consumedByPreScroll + consumedByScroll
+ onPostScroll(consumed = consumed, available = available - consumed, source = scrollSource)
+ }
+
@Test
fun onScrollUp_consumeHeightFirst() {
val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
@@ -50,6 +60,41 @@
}
@Test
+ fun onScrollUpAfterContentScrolled_ignoreUpEvent() {
+ val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
+ height = 1f
+
+ // scroll down consumed by a child
+ scrollConnection.scroll(available = Offset(0f, 1f), consumedByScroll = Offset(0f, 1f))
+
+ val offsetConsumed =
+ scrollConnection.onPreScroll(available = Offset(x = 0f, y = -1f), source = scrollSource)
+
+ // It should ignore all onPreScroll events
+ assertThat(offsetConsumed).isEqualTo(Offset.Zero)
+ assertThat(height).isEqualTo(1f)
+ }
+
+ @Test
+ fun onScrollUpAfterContentReturnedToZero_consumeHeight() {
+ val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
+ height = 1f
+
+ // scroll down consumed by a child
+ scrollConnection.scroll(available = Offset(0f, 1f), consumedByScroll = Offset(0f, 1f))
+
+ // scroll up consumed by a child, the child is in its original position
+ scrollConnection.scroll(available = Offset(0f, -1f), consumedByScroll = Offset(0f, -1f))
+
+ val offsetConsumed =
+ scrollConnection.onPreScroll(available = Offset(x = 0f, y = -1f), source = scrollSource)
+
+ // It should ignore all onPreScroll events
+ assertThat(offsetConsumed).isEqualTo(Offset(0f, -1f))
+ assertThat(height).isEqualTo(0f)
+ }
+
+ @Test
fun onScrollUp_consumeDownToMin() {
val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
height = 0f
@@ -110,6 +155,27 @@
}
@Test
+ fun onScrollDownAfterPostScroll_consumeHeightPreScroll() {
+ val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
+ height = 1f
+ scrollConnection.onPostScroll(
+ consumed = Offset.Zero,
+ available = Offset(x = 0f, y = 0.5f),
+ source = scrollSource
+ )
+
+ val offsetConsumed =
+ scrollConnection.onPreScroll(
+ available = Offset(x = 0f, y = 0.5f),
+ source = scrollSource
+ )
+ assertThat(offsetConsumed).isEqualTo(Offset(0f, 0.5f))
+
+ // It can increase by 1 (0.5f + 0.5f) the height
+ assertThat(height).isEqualTo(2f)
+ }
+
+ @Test
fun onScrollDown_consumeUpToMax() {
val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
height = 2f
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt
index 122774b..8a9a92e 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/PriorityNestedScrollConnectionTest.kt
@@ -46,6 +46,7 @@
canStartPostScroll = { _, _ -> canStartPostScroll },
canStartPostFling = { canStartPostFling },
canContinueScroll = { canContinueScroll },
+ canScrollOnFling = false,
onStart = { isStarted = true },
onScroll = {
lastScroll = it
diff --git a/packages/SystemUI/res/layout/privacy_dialog_card_button.xml b/packages/SystemUI/res/layout/privacy_dialog_card_button.xml
index e297b93..bcbe2c43 100644
--- a/packages/SystemUI/res/layout/privacy_dialog_card_button.xml
+++ b/packages/SystemUI/res/layout/privacy_dialog_card_button.xml
@@ -17,6 +17,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
+ android:paddingTop="4dp"
+ android:paddingBottom="4dp"
android:layout_marginBottom="4dp"
android:ellipsize="end"
android:maxLines="1"
diff --git a/packages/SystemUI/res/layout/privacy_dialog_v2.xml b/packages/SystemUI/res/layout/privacy_dialog_v2.xml
index 843dad0..76098a1 100644
--- a/packages/SystemUI/res/layout/privacy_dialog_v2.xml
+++ b/packages/SystemUI/res/layout/privacy_dialog_v2.xml
@@ -16,7 +16,7 @@
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
- android:layout_width="@dimen/large_dialog_width"
+ android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java
index fec96c6..317201d 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java
@@ -16,8 +16,6 @@
package com.android.systemui.shared.rotation;
-import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
-
import android.annotation.DimenRes;
import android.annotation.IdRes;
import android.annotation.LayoutRes;
@@ -89,8 +87,7 @@
@DimenRes int roundedContentPadding, @DimenRes int taskbarLeftMargin,
@DimenRes int taskbarBottomMargin, @DimenRes int buttonDiameter,
@DimenRes int rippleMaxWidth, @BoolRes int floatingRotationBtnPositionLeftResource) {
- mContext = context.createWindowContext(context.getDisplay(), TYPE_NAVIGATION_BAR_PANEL,
- null);
+ mContext = context;
mWindowManager = mContext.getSystemService(WindowManager.class);
mKeyButtonContainer = (ViewGroup) LayoutInflater.from(mContext).inflate(layout, null);
mKeyButtonView = mKeyButtonContainer.findViewById(keyButtonId);
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
index bf68869..d8c1e41 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
@@ -103,8 +103,6 @@
public static final int SYSUI_STATE_BACK_DISABLED = 1 << 22;
// The bubble stack is expanded AND the mange menu for bubbles is expanded on top of it.
public static final int SYSUI_STATE_BUBBLES_MANAGE_MENU_EXPANDED = 1 << 23;
- // The current app is in immersive mode
- public static final int SYSUI_STATE_IMMERSIVE_MODE = 1 << 24;
// The voice interaction session window is showing
public static final int SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING = 1 << 25;
// Freeform windows are showing in desktop mode
@@ -162,7 +160,6 @@
SYSUI_STATE_DEVICE_DOZING,
SYSUI_STATE_BACK_DISABLED,
SYSUI_STATE_BUBBLES_MANAGE_MENU_EXPANDED,
- SYSUI_STATE_IMMERSIVE_MODE,
SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING,
SYSUI_STATE_FREEFORM_ACTIVE_IN_DESKTOP_MODE,
SYSUI_STATE_DEVICE_DREAMING,
@@ -247,9 +244,6 @@
if ((flags & SYSUI_STATE_BUBBLES_MANAGE_MENU_EXPANDED) != 0) {
str.add("bubbles_mange_menu_expanded");
}
- if ((flags & SYSUI_STATE_IMMERSIVE_MODE) != 0) {
- str.add("immersive_mode");
- }
if ((flags & SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING) != 0) {
str.add("vis_win_showing");
}
diff --git a/packages/SystemUI/src/com/android/systemui/StatusBarInsetsCommand.kt b/packages/SystemUI/src/com/android/systemui/StatusBarInsetsCommand.kt
new file mode 100644
index 0000000..7e2a1e1
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/StatusBarInsetsCommand.kt
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2023 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
+
+import android.view.Surface
+import android.view.Surface.Rotation
+import com.android.systemui.statusbar.commandline.ParseableCommand
+import com.android.systemui.statusbar.commandline.Type
+import java.io.PrintWriter
+
+class StatusBarInsetsCommand(
+ private val callback: Callback,
+) : ParseableCommand(NAME) {
+
+ val bottomMargin: BottomMarginCommand? by subCommand(BottomMarginCommand())
+
+ override fun execute(pw: PrintWriter) {
+ callback.onExecute(command = this, pw)
+ }
+
+ interface Callback {
+ fun onExecute(command: StatusBarInsetsCommand, printWriter: PrintWriter)
+ }
+
+ companion object {
+ const val NAME = "status-bar-insets"
+ }
+}
+
+class BottomMarginCommand : ParseableCommand(NAME) {
+
+ private val rotationDegrees: Int? by
+ param(
+ longName = "rotation",
+ shortName = "r",
+ description = "For which rotation the margin should be set. One of 0, 90, 180, 270",
+ valueParser = Type.Int,
+ )
+
+ @Rotation
+ val rotationValue: Int?
+ get() = ROTATION_DEGREES_TO_VALUE_MAPPING[rotationDegrees]
+
+ val marginBottomDp: Float? by
+ param(
+ longName = "margin",
+ shortName = "m",
+ description = "Margin amount, in dp. Can be a fractional value, such as 10.5",
+ valueParser = Type.Float,
+ )
+
+ override fun execute(pw: PrintWriter) {
+ // Not needed for a subcommand
+ }
+
+ companion object {
+ const val NAME = "bottom-margin"
+ private val ROTATION_DEGREES_TO_VALUE_MAPPING =
+ mapOf(
+ 0 to Surface.ROTATION_0,
+ 90 to Surface.ROTATION_90,
+ 180 to Surface.ROTATION_180,
+ 270 to Surface.ROTATION_270,
+ )
+
+ val ROTATION_DEGREES_OPTIONS: Set<Int> = ROTATION_DEGREES_TO_VALUE_MAPPING.keys
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
index 5a763b1..b753ff7 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
@@ -437,11 +437,6 @@
// 1200 - predictive back
@Keep
@JvmField
- val WM_ENABLE_PREDICTIVE_BACK =
- sysPropBooleanFlag("persist.wm.debug.predictive_back", default = true)
-
- @Keep
- @JvmField
val WM_ENABLE_PREDICTIVE_BACK_ANIM =
sysPropBooleanFlag("persist.wm.debug.predictive_back_anim", default = true)
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
index 9cdf857..992eeca 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
@@ -40,6 +40,7 @@
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Dumpable
import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dump.DumpManager
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
@@ -76,6 +77,7 @@
import java.io.PrintWriter
import java.util.Locale
import java.util.TreeMap
+import java.util.concurrent.Executor
import javax.inject.Inject
import javax.inject.Provider
import kotlinx.coroutines.CoroutineScope
@@ -102,6 +104,7 @@
private val activityStarter: ActivityStarter,
private val systemClock: SystemClock,
@Main executor: DelayableExecutor,
+ @Background private val bgExecutor: Executor,
private val mediaManager: MediaDataManager,
configurationController: ConfigurationController,
falsingManager: FalsingManager,
@@ -1030,7 +1033,7 @@
desiredHostState?.let {
if (this.desiredLocation != desiredLocation) {
// Only log an event when location changes
- logger.logCarouselPosition(desiredLocation)
+ bgExecutor.execute { logger.logCarouselPosition(desiredLocation) }
}
// This is a hosting view, let's remeasure our players
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java b/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java
index 8d1ff98a..62c7343 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/TaskbarDelegate.java
@@ -31,7 +31,6 @@
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_HOME_DISABLED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IME_SHOWING;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IME_SWITCHER_SHOWING;
-import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IMMERSIVE_MODE;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NAV_BAR_HIDDEN;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_OVERVIEW_DISABLED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;
@@ -322,7 +321,6 @@
.setFlag(SYSUI_STATE_NAV_BAR_HIDDEN, !isWindowVisible())
.setFlag(SYSUI_STATE_ALLOW_GESTURE_IGNORING_BAR_VISIBILITY,
allowSystemGestureIgnoringBarVisibility())
- .setFlag(SYSUI_STATE_IMMERSIVE_MODE, isImmersiveMode())
.commitUpdate(mDisplayId);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
index d23c85a..cfbd015 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
@@ -18,16 +18,16 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
-import android.os.Handler;
import android.util.ArrayMap;
import android.util.ArraySet;
+import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
-import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
+import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.time.SystemClock;
import java.util.stream.Stream;
@@ -46,13 +46,12 @@
protected int mMinimumDisplayTime;
protected int mStickyForSomeTimeAutoDismissTime;
protected int mAutoDismissTime;
- @VisibleForTesting
- public Handler mHandler;
+ private DelayableExecutor mExecutor;
- public AlertingNotificationManager(HeadsUpManagerLogger logger, @Main Handler handler,
- SystemClock systemClock) {
+ public AlertingNotificationManager(HeadsUpManagerLogger logger,
+ SystemClock systemClock, @Main DelayableExecutor executor) {
mLogger = logger;
- mHandler = handler;
+ mExecutor = executor;
mSystemClock = systemClock;
}
@@ -264,6 +263,7 @@
public long mEarliestRemovalTime;
@Nullable protected Runnable mRemoveAlertRunnable;
+ @Nullable private Runnable mCancelRemoveAlertRunnable;
public void setEntry(@NonNull final NotificationEntry entry) {
setEntry(entry, () -> removeAlertEntry(entry.getKey()));
@@ -291,13 +291,15 @@
if (updatePostTime) {
mPostTime = Math.max(mPostTime, now);
}
- removeAutoRemovalCallbacks("updateEntry (will be rescheduled)");
- if (!isSticky()) {
- final long finishTime = calculateFinishTime();
- final long timeLeft = Math.max(finishTime - now, mMinimumDisplayTime);
- mHandler.postDelayed(mRemoveAlertRunnable, timeLeft);
+ if (isSticky()) {
+ removeAutoRemovalCallbacks("updateEntry (sticky)");
+ return;
}
+
+ final long finishTime = calculateFinishTime();
+ final long timeLeft = Math.max(finishTime - now, mMinimumDisplayTime);
+ scheduleAutoRemovalCallback(timeLeft, "updateEntry (not sticky)");
}
/**
@@ -340,21 +342,50 @@
* Clear any pending removal runnables.
*/
public void removeAutoRemovalCallbacks(@Nullable String reason) {
- if (mRemoveAlertRunnable != null) {
+ final boolean removed = removeAutoRemovalCallbackInternal();
+
+ if (removed) {
mLogger.logAutoRemoveCanceled(mEntry, reason);
- mHandler.removeCallbacks(mRemoveAlertRunnable);
}
}
+ private void scheduleAutoRemovalCallback(long delayMillis, @NonNull String reason) {
+ if (mRemoveAlertRunnable == null) {
+ Log.wtf(TAG, "scheduleAutoRemovalCallback with no callback set");
+ return;
+ }
+
+ final boolean removed = removeAutoRemovalCallbackInternal();
+
+ if (removed) {
+ mLogger.logAutoRemoveRescheduled(mEntry, delayMillis, reason);
+ } else {
+ mLogger.logAutoRemoveScheduled(mEntry, delayMillis, reason);
+ }
+
+
+ mCancelRemoveAlertRunnable = mExecutor.executeDelayed(mRemoveAlertRunnable,
+ delayMillis);
+ }
+
+ private boolean removeAutoRemovalCallbackInternal() {
+ final boolean scheduled = (mCancelRemoveAlertRunnable != null);
+
+ if (scheduled) {
+ mCancelRemoveAlertRunnable.run();
+ mCancelRemoveAlertRunnable = null;
+ }
+
+ return scheduled;
+ }
+
/**
* Remove the alert at the earliest allowed removal time.
*/
public void removeAsSoonAsPossible() {
if (mRemoveAlertRunnable != null) {
- removeAutoRemovalCallbacks("removeAsSoonAsPossible (will be rescheduled)");
-
final long timeLeft = mEarliestRemovalTime - mSystemClock.elapsedRealtime();
- mHandler.postDelayed(mRemoveAlertRunnable, timeLeft);
+ scheduleAutoRemovalCallback(timeLeft, "removeAsSoonAsPossible");
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
index e486457..05c3839 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
@@ -18,6 +18,7 @@
import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
+import static android.os.UserHandle.USER_ALL;
import static android.os.UserHandle.USER_NULL;
import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS;
import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS;
@@ -46,6 +47,7 @@
import android.os.UserManager;
import android.provider.Settings;
import android.util.Log;
+import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
@@ -155,8 +157,22 @@
if (ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) {
if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
- boolean changed = updateDpcSettings(getSendingUserId());
- if (mCurrentUserId == getSendingUserId()) {
+ boolean changed = false;
+ int sendingUserId = getSendingUserId();
+ if (sendingUserId == USER_ALL) {
+ // When a Device Owner triggers changes it's sent as USER_ALL. Normalize
+ // the user before calling into DPM
+ sendingUserId = mCurrentUserId;
+ @SuppressLint("MissingPermission")
+ List<UserInfo> users = mUserManager.getUsers();
+ for (int i = users.size() - 1; i >= 0; i--) {
+ changed |= updateDpcSettings(users.get(i).id);
+ }
+ } else {
+ changed |= updateDpcSettings(sendingUserId);
+ }
+
+ if (mCurrentUserId == sendingUserId) {
changed |= updateLockscreenNotificationSetting();
}
if (changed) {
@@ -374,13 +390,13 @@
mContext.getContentResolver().registerContentObserver(
SHOW_LOCKSCREEN, false,
mLockscreenSettingsObserver,
- UserHandle.USER_ALL);
+ USER_ALL);
mContext.getContentResolver().registerContentObserver(
SHOW_PRIVATE_LOCKSCREEN,
true,
mLockscreenSettingsObserver,
- UserHandle.USER_ALL);
+ USER_ALL);
if (!mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
mContext.getContentResolver().registerContentObserver(
@@ -441,7 +457,7 @@
public boolean isCurrentProfile(int userId) {
synchronized (mLock) {
- return userId == UserHandle.USER_ALL || mCurrentProfiles.get(userId) != null;
+ return userId == USER_ALL || mCurrentProfiles.get(userId) != null;
}
}
@@ -526,7 +542,7 @@
*/
public boolean userAllowsPrivateNotificationsInPublic(int userHandle) {
if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
- if (userHandle == UserHandle.USER_ALL) {
+ if (userHandle == USER_ALL) {
userHandle = mCurrentUserId;
}
if (mUsersUsersAllowingPrivateNotifications.indexOfKey(userHandle) < 0) {
@@ -540,7 +556,7 @@
return mUsersUsersAllowingPrivateNotifications.get(userHandle)
&& mUsersDpcAllowingPrivateNotifications.get(userHandle);
} else {
- if (userHandle == UserHandle.USER_ALL) {
+ if (userHandle == USER_ALL) {
return true;
}
@@ -574,7 +590,7 @@
}
private boolean adminAllowsKeyguardFeature(int userHandle, int feature) {
- if (userHandle == UserHandle.USER_ALL) {
+ if (userHandle == USER_ALL) {
return true;
}
final int dpmFlags =
@@ -591,7 +607,7 @@
}
public boolean isLockscreenPublicMode(int userId) {
- if (userId == UserHandle.USER_ALL) {
+ if (userId == USER_ALL) {
return mLockscreenPublicMode.get(mCurrentUserId, false);
}
return mLockscreenPublicMode.get(userId, false);
@@ -610,7 +626,7 @@
if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
// Unlike 'show private', settings does not show a copy of this setting for each
// profile, so it inherits from the parent user.
- if (userHandle == UserHandle.USER_ALL || mCurrentManagedProfiles.contains(userHandle)) {
+ if (userHandle == USER_ALL || mCurrentManagedProfiles.contains(userHandle)) {
userHandle = mCurrentUserId;
}
if (mUsersUsersAllowingNotifications.indexOfKey(userHandle) < 0) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
index 644c896..e66d9e8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
@@ -48,6 +48,7 @@
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import com.android.systemui.statusbar.policy.OnHeadsUpPhoneListenerChange;
+import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.kotlin.JavaAdapter;
import com.android.systemui.util.settings.GlobalSettings;
import com.android.systemui.util.time.SystemClock;
@@ -119,12 +120,13 @@
@Main Handler handler,
GlobalSettings globalSettings,
SystemClock systemClock,
+ @Main DelayableExecutor executor,
AccessibilityManagerWrapper accessibilityManagerWrapper,
UiEventLogger uiEventLogger,
JavaAdapter javaAdapter,
ShadeInteractor shadeInteractor) {
- super(context, logger, handler, globalSettings, systemClock, accessibilityManagerWrapper,
- uiEventLogger);
+ super(context, logger, handler, globalSettings, systemClock, executor,
+ accessibilityManagerWrapper, uiEventLogger);
Resources resources = mContext.getResources();
mExtensionTime = resources.getInteger(R.integer.ambient_notification_extension_time);
statusBarStateController.addCallback(mStatusBarStateListener);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt
index 3b96f57..877bd7c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt
@@ -42,6 +42,9 @@
import com.android.systemui.util.leak.RotationUtils.getExactRotation
import com.android.systemui.util.leak.RotationUtils.getResourcesForRotation
import com.android.app.tracing.traceSection
+import com.android.systemui.BottomMarginCommand
+import com.android.systemui.StatusBarInsetsCommand
+import com.android.systemui.statusbar.commandline.CommandRegistry
import java.io.PrintWriter
import java.lang.Math.max
import javax.inject.Inject
@@ -64,7 +67,8 @@
class StatusBarContentInsetsProvider @Inject constructor(
val context: Context,
val configurationController: ConfigurationController,
- val dumpManager: DumpManager
+ val dumpManager: DumpManager,
+ val commandRegistry: CommandRegistry,
) : CallbackController<StatusBarContentInsetsChangedListener>,
ConfigurationController.ConfigurationListener,
Dumpable {
@@ -80,6 +84,13 @@
init {
configurationController.addCallback(this)
dumpManager.registerDumpable(TAG, this)
+ commandRegistry.registerCommand(StatusBarInsetsCommand.NAME) {
+ StatusBarInsetsCommand(object : StatusBarInsetsCommand.Callback {
+ override fun onExecute(command: StatusBarInsetsCommand, printWriter: PrintWriter) {
+ executeCommand(command, printWriter)
+ }
+ })
+ }
}
override fun addCallback(listener: StatusBarContentInsetsChangedListener) {
@@ -271,8 +282,41 @@
statusBarContentHeight)
}
+ private fun executeCommand(command: StatusBarInsetsCommand, printWriter: PrintWriter) {
+ command.bottomMargin?.let { executeBottomMarginCommand(it, printWriter) }
+ }
+
+ private fun executeBottomMarginCommand(command: BottomMarginCommand, printWriter: PrintWriter) {
+ val rotation = command.rotationValue
+ if (rotation == null) {
+ printWriter.println(
+ "Rotation should be one of ${BottomMarginCommand.ROTATION_DEGREES_OPTIONS}"
+ )
+ return
+ }
+ val marginBottomDp = command.marginBottomDp
+ if (marginBottomDp == null) {
+ printWriter.println("Margin bottom not set.")
+ return
+ }
+ setBottomMarginOverride(rotation, marginBottomDp)
+ }
+
+ private val marginBottomOverrides = mutableMapOf<Int, Int>()
+
+ private fun setBottomMarginOverride(rotation: Int, marginBottomDp: Float) {
+ insetsCache.evictAll()
+ val marginBottomPx = (marginBottomDp * context.resources.displayMetrics.density).toInt()
+ marginBottomOverrides[rotation] = marginBottomPx
+ notifyInsetsChanged()
+ }
+
@Px
private fun getBottomAlignedMargin(targetRotation: Int, resources: Resources): Int {
+ val override = marginBottomOverrides[targetRotation]
+ if (override != null) {
+ return override
+ }
val dimenRes =
when (targetRotation) {
Surface.ROTATION_0 -> R.dimen.status_bar_bottom_aligned_margin_rotation_0
@@ -294,6 +338,7 @@
pw.println("$key -> $rect")
}
pw.println(insetsCache)
+ pw.println("Bottom margin overrides: $marginBottomOverrides")
}
private fun getCacheKey(
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
index daadedb..4999123 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
@@ -36,6 +36,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewRootImpl;
+import android.view.WindowInsetsController;
import android.window.BackEvent;
import android.window.OnBackAnimationCallback;
import android.window.OnBackInvokedDispatcher;
@@ -859,10 +860,19 @@
}
}
+ private void setRootViewAnimationDisabled(boolean disabled) {
+ ViewGroup windowRootView = mNotificationShadeWindowController.getWindowRootView();
+ if (windowRootView != null) {
+ WindowInsetsController insetsController = windowRootView.getWindowInsetsController();
+ if (insetsController != null) {
+ insetsController.setAnimationsDisabled(disabled);
+ }
+ }
+ }
+
@Override
public void onStartedWakingUp() {
- mNotificationShadeWindowController.getWindowRootView().getWindowInsetsController()
- .setAnimationsDisabled(false);
+ setRootViewAnimationDisabled(false);
NavigationBarView navBarView = mCentralSurfaces.getNavigationBarView();
if (navBarView != null) {
navBarView.forEachView(view ->
@@ -875,8 +885,7 @@
@Override
public void onStartedGoingToSleep() {
- mNotificationShadeWindowController.getWindowRootView().getWindowInsetsController()
- .setAnimationsDisabled(true);
+ setRootViewAnimationDisabled(true);
NavigationBarView navBarView = mCentralSurfaces.getNavigationBarView();
if (navBarView != null) {
navBarView.forEachView(view ->
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseHeadsUpManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseHeadsUpManager.java
index 8054b04..e971128 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseHeadsUpManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseHeadsUpManager.java
@@ -38,6 +38,7 @@
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
import com.android.systemui.util.ListenerSet;
+import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.settings.GlobalSettings;
import com.android.systemui.util.time.SystemClock;
@@ -87,9 +88,10 @@
@Main Handler handler,
GlobalSettings globalSettings,
SystemClock systemClock,
+ @Main DelayableExecutor executor,
AccessibilityManagerWrapper accessibilityManagerWrapper,
UiEventLogger uiEventLogger) {
- super(logger, handler, systemClock);
+ super(logger, systemClock, executor);
mContext = context;
mAccessibilityMgr = accessibilityManagerWrapper;
mUiEventLogger = uiEventLogger;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManagerLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManagerLogger.kt
index ef07eed..f6154afe 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManagerLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManagerLogger.kt
@@ -66,6 +66,26 @@
})
}
+ fun logAutoRemoveScheduled(entry: NotificationEntry, delayMillis: Long, reason: String) {
+ buffer.log(TAG, INFO, {
+ str1 = entry.logKey
+ long1 = delayMillis
+ str2 = reason
+ }, {
+ "schedule auto remove of $str1 in $long1 ms reason: $str2"
+ })
+ }
+
+ fun logAutoRemoveRescheduled(entry: NotificationEntry, delayMillis: Long, reason: String) {
+ buffer.log(TAG, INFO, {
+ str1 = entry.logKey
+ long1 = delayMillis
+ str2 = reason
+ }, {
+ "reschedule auto remove of $str1 in $long1 ms reason: $str2"
+ })
+ }
+
fun logAutoRemoveCanceled(entry: NotificationEntry, reason: String?) {
buffer.log(TAG, INFO, {
str1 = entry.logKey
diff --git a/packages/SystemUI/src/com/android/systemui/util/Utils.java b/packages/SystemUI/src/com/android/systemui/util/Utils.java
index f5edb7b..fa6d055 100644
--- a/packages/SystemUI/src/com/android/systemui/util/Utils.java
+++ b/packages/SystemUI/src/com/android/systemui/util/Utils.java
@@ -83,17 +83,19 @@
/**
* Allow the media player to be shown in the QS area, controlled by 2 flags.
- * Off by default, but can be disabled by setting to 0
+ * On by default, but can be disabled by setting either flag to 0/false.
*/
public static boolean useQsMediaPlayer(Context context) {
- // TODO(b/192412820): Replace SHOW_MEDIA_ON_QUICK_SETTINGS with compile-time value
// Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS can't be toggled at runtime, so simply
// cache the first result we fetch and use that going forward. Do this to avoid unnecessary
// binder calls which may happen on the critical path.
if (sUseQsMediaPlayer == null) {
- int flag = Settings.Global.getInt(context.getContentResolver(),
+ // TODO(b/192412820): Consolidate SHOW_MEDIA_ON_QUICK_SETTINGS into compile-time value.
+ final int settingsFlag = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1);
- sUseQsMediaPlayer = flag > 0;
+ final boolean configFlag = context.getResources()
+ .getBoolean(com.android.internal.R.bool.config_quickSettingsShowMediaPlayer);
+ sUseQsMediaPlayer = settingsFlag > 0 && configFlag;
}
return sUseQsMediaPlayer;
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt
index 3bfdb84..310e0b8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt
@@ -54,6 +54,7 @@
import com.android.systemui.statusbar.notification.collection.provider.VisualStabilityProvider
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.concurrency.DelayableExecutor
+import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.mockito.eq
@@ -124,6 +125,7 @@
@Captor lateinit var settingsObserverCaptor: ArgumentCaptor<ContentObserver>
private val clock = FakeSystemClock()
+ private lateinit var bgExecutor: FakeExecutor
private lateinit var mediaCarouselController: MediaCarouselController
@Before
@@ -131,6 +133,7 @@
MockitoAnnotations.initMocks(this)
context.resources.configuration.setLocales(LocaleList(Locale.US, Locale.UK))
transitionRepository = FakeKeyguardTransitionRepository()
+ bgExecutor = FakeExecutor(clock)
mediaCarouselController =
MediaCarouselController(
context,
@@ -140,6 +143,7 @@
activityStarter,
clock,
executor,
+ bgExecutor,
mediaDataManager,
configurationController,
falsingManager,
@@ -458,6 +462,7 @@
mediaHostState,
animate = false
)
+ bgExecutor.runAllReady()
verify(logger).logCarouselPosition(LOCATION_QS)
}
@@ -468,6 +473,7 @@
mediaHostState,
animate = false
)
+ bgExecutor.runAllReady()
verify(logger).logCarouselPosition(MediaHierarchyManager.LOCATION_QQS)
}
@@ -478,6 +484,7 @@
mediaHostState,
animate = false
)
+ bgExecutor.runAllReady()
verify(logger).logCarouselPosition(MediaHierarchyManager.LOCATION_LOCKSCREEN)
}
@@ -488,6 +495,7 @@
mediaHostState,
animate = false
)
+ bgExecutor.runAllReady()
verify(logger).logCarouselPosition(MediaHierarchyManager.LOCATION_DREAM_OVERLAY)
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java
index a3cff87e6..76c4015 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java
@@ -30,8 +30,6 @@
import android.app.ActivityManager;
import android.app.Notification;
-import android.os.Handler;
-import android.os.Looper;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.testing.AndroidTestingRunner;
@@ -45,12 +43,12 @@
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
+import com.android.systemui.util.concurrency.DelayableExecutor;
+import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.settings.FakeGlobalSettings;
+import com.android.systemui.util.time.FakeSystemClock;
import com.android.systemui.util.time.SystemClock;
-import com.android.systemui.util.time.SystemClockImpl;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -73,27 +71,24 @@
protected static final int TEST_STICKY_AUTO_DISMISS_TIME = 800;
// Number of notifications to use in tests requiring multiple notifications
private static final int TEST_NUM_NOTIFICATIONS = 4;
- protected static final int TEST_TIMEOUT_TIME = 2_000;
- protected final Runnable mTestTimeoutRunnable = () -> mTimedOut = true;
- protected Handler mTestHandler;
protected final FakeGlobalSettings mGlobalSettings = new FakeGlobalSettings();
- protected final SystemClock mSystemClock = new SystemClockImpl();
- protected boolean mTimedOut = false;
+ protected final FakeSystemClock mSystemClock = new FakeSystemClock();
+ protected final FakeExecutor mExecutor = new FakeExecutor(mSystemClock);
@Mock protected ExpandableNotificationRow mRow;
static {
assertThat(TEST_MINIMUM_DISPLAY_TIME).isLessThan(TEST_AUTO_DISMISS_TIME);
assertThat(TEST_AUTO_DISMISS_TIME).isLessThan(TEST_STICKY_AUTO_DISMISS_TIME);
- assertThat(TEST_STICKY_AUTO_DISMISS_TIME).isLessThan(TEST_TIMEOUT_TIME);
}
private static class TestableAlertingNotificationManager extends AlertingNotificationManager {
private AlertEntry mLastCreatedEntry;
- private TestableAlertingNotificationManager(Handler handler, SystemClock systemClock) {
- super(new HeadsUpManagerLogger(logcatLogBuffer()), handler, systemClock);
+ private TestableAlertingNotificationManager(SystemClock systemClock,
+ DelayableExecutor executor) {
+ super(new HeadsUpManagerLogger(logcatLogBuffer()), systemClock, executor);
mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME;
mAutoDismissTime = TEST_AUTO_DISMISS_TIME;
mStickyForSomeTimeAutoDismissTime = TEST_STICKY_AUTO_DISMISS_TIME;
@@ -118,7 +113,7 @@
}
protected AlertingNotificationManager createAlertingNotificationManager() {
- return new TestableAlertingNotificationManager(mTestHandler, mSystemClock);
+ return new TestableAlertingNotificationManager(mSystemClock, mExecutor);
}
protected StatusBarNotification createSbn(int id, Notification n) {
@@ -155,35 +150,6 @@
return new NotificationEntryBuilder().setSbn(createSbn(id)).build();
}
- protected void verifyAlertingAtTime(AlertingNotificationManager anm, NotificationEntry entry,
- boolean shouldBeAlerting, int whenToCheckAlertingMillis, String whenCondition) {
- final Boolean[] wasAlerting = {null};
- final Runnable checkAlerting =
- () -> wasAlerting[0] = anm.isAlerting(entry.getKey());
-
- mTestHandler.postDelayed(checkAlerting, whenToCheckAlertingMillis);
- mTestHandler.postDelayed(mTestTimeoutRunnable, TEST_TIMEOUT_TIME);
- TestableLooper.get(this).processMessages(2);
-
- assertFalse("Test timed out", mTimedOut);
- if (shouldBeAlerting) {
- assertTrue("Should still be alerting after " + whenCondition, wasAlerting[0]);
- } else {
- assertFalse("Should not still be alerting after " + whenCondition, wasAlerting[0]);
- }
- assertFalse("Should not still be alerting after processing",
- anm.isAlerting(entry.getKey()));
- }
-
- @Before
- public void setUp() {
- mTestHandler = Handler.createAsync(Looper.myLooper());
- }
-
- @After
- public void tearDown() {
- mTestHandler.removeCallbacksAndMessages(null);
- }
@Test
public void testShowNotification_addsEntry() {
@@ -203,9 +169,7 @@
final NotificationEntry entry = createEntry(/* id = */ 0);
alm.showNotification(entry);
-
- verifyAlertingAtTime(alm, entry, false, TEST_AUTO_DISMISS_TIME * 3 / 2,
- "auto dismiss time");
+ mSystemClock.advanceTime(TEST_AUTO_DISMISS_TIME * 3 / 2);
assertFalse(alm.isAlerting(entry.getKey()));
}
@@ -217,10 +181,8 @@
alm.showNotification(entry);
- // Try to remove but defer, since the notification has not been shown long enough.
- final boolean removedImmediately = alm.removeNotification(entry.getKey(),
- false /* releaseImmediately */);
-
+ final boolean removedImmediately = alm.removeNotification(
+ entry.getKey(), /* releaseImmediately = */ false);
assertFalse(removedImmediately);
assertTrue(alm.isAlerting(entry.getKey()));
}
@@ -232,10 +194,8 @@
alm.showNotification(entry);
- // Remove forcibly with releaseImmediately = true.
- final boolean removedImmediately = alm.removeNotification(entry.getKey(),
- true /* releaseImmediately */);
-
+ final boolean removedImmediately = alm.removeNotification(
+ entry.getKey(), /* releaseImmediately = */ true);
assertTrue(removedImmediately);
assertFalse(alm.isAlerting(entry.getKey()));
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
index 34c7b09..42c7375 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
@@ -515,6 +515,29 @@
}
@Test
+ public void testDevicePolicyDoesNotAllowNotifications_deviceOwnerSetsForUserAll() {
+ // User allows them
+ mSettings.putIntForUser(LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, mCurrentUser.id);
+ mSettings.putIntForUser(LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, mSecondaryUser.id);
+ changeSetting(LOCK_SCREEN_SHOW_NOTIFICATIONS);
+
+ // DevicePolicy hides notifs on lockscreen
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(null, mCurrentUser.id))
+ .thenReturn(KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(null, mSecondaryUser.id))
+ .thenReturn(KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
+
+ BroadcastReceiver.PendingResult pr = new BroadcastReceiver.PendingResult(
+ 0, null, null, 0, true, false, null, USER_ALL, 0);
+ mLockscreenUserManager.mAllUsersReceiver.setPendingResult(pr);
+ mLockscreenUserManager.mAllUsersReceiver.onReceive(mContext,
+ new Intent(ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED));
+
+ assertFalse(mLockscreenUserManager.userAllowsNotificationsInPublic(mCurrentUser.id));
+ assertFalse(mLockscreenUserManager.userAllowsNotificationsInPublic(mSecondaryUser.id));
+ }
+
+ @Test
public void testDevicePolicyDoesNotAllowNotifications_userAll() {
// User allows them
mSettings.putIntForUser(LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, mCurrentUser.id);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java
index 37ee322..e1bd89f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.phone;
import static com.android.systemui.dump.LogBufferHelperKt.logcatLogBuffer;
+import static com.android.systemui.util.concurrency.MockExecutorHandlerKt.mockExecutorHandler;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
@@ -25,7 +26,6 @@
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.os.Handler;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -45,11 +45,11 @@
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
+import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.kotlin.JavaAdapter;
import com.android.systemui.util.settings.GlobalSettings;
import com.android.systemui.util.time.SystemClock;
-import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
@@ -88,9 +88,9 @@
StatusBarStateController statusBarStateController,
KeyguardBypassController keyguardBypassController,
ConfigurationController configurationController,
- Handler handler,
GlobalSettings globalSettings,
SystemClock systemClock,
+ DelayableExecutor executor,
AccessibilityManagerWrapper accessibilityManagerWrapper,
UiEventLogger uiEventLogger,
JavaAdapter javaAdapter,
@@ -104,9 +104,10 @@
groupManager,
visualStabilityProvider,
configurationController,
- handler,
+ mockExecutorHandler(executor),
globalSettings,
systemClock,
+ executor,
accessibilityManagerWrapper,
uiEventLogger,
javaAdapter,
@@ -126,9 +127,9 @@
mStatusBarStateController,
mBypassController,
mConfigurationController,
- mTestHandler,
mGlobalSettings,
mSystemClock,
+ mExecutor,
mAccessibilityManagerWrapper,
mUiEventLogger,
mJavaAdapter,
@@ -142,7 +143,6 @@
}
@Before
- @Override
public void setUp() {
when(mShadeInteractor.isAnyExpanded()).thenReturn(StateFlowKt.MutableStateFlow(false));
final AccessibilityManagerWrapper accessibilityMgr =
@@ -153,14 +153,6 @@
mDependency.injectMockDependency(NotificationShadeWindowController.class);
mContext.getOrCreateTestableResources().addOverride(
R.integer.ambient_notification_extension_time, 500);
-
- super.setUp();
- }
-
- @After
- @Override
- public void tearDown() {
- super.tearDown();
}
@Test
@@ -224,8 +216,8 @@
hmp.showNotification(entry);
hmp.extendHeadsUp();
+ mSystemClock.advanceTime(TEST_AUTO_DISMISS_TIME + hmp.mExtensionTime / 2);
- final int pastNormalTimeMillis = TEST_AUTO_DISMISS_TIME + hmp.mExtensionTime / 2;
- verifyAlertingAtTime(hmp, entry, true, pastNormalTimeMillis, "normal time");
+ assertTrue(hmp.isAlerting(entry.getKey()));
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt
index 5c56246..84b2c4b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt
@@ -24,6 +24,7 @@
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.dump.DumpManager
+import com.android.systemui.statusbar.commandline.CommandRegistry
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.leak.RotationUtils
import com.android.systemui.util.leak.RotationUtils.ROTATION_LANDSCAPE
@@ -31,6 +32,7 @@
import com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE
import com.android.systemui.util.leak.RotationUtils.ROTATION_UPSIDE_DOWN
import com.android.systemui.util.leak.RotationUtils.Rotation
+import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import junit.framework.Assert.assertTrue
@@ -39,7 +41,6 @@
import org.mockito.ArgumentMatchers.any
import org.mockito.Mock
import org.mockito.Mockito.`when`
-import org.mockito.Mockito.mock
import org.mockito.MockitoAnnotations
@SmallTest
@@ -556,7 +557,7 @@
fun testDisplayChanged_returnsUpdatedInsets() {
// GIVEN: get insets on the first display and switch to the second display
val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
- mock(DumpManager::class.java))
+ mock<DumpManager>(), mock<CommandRegistry>())
configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 1080, 2160))
val firstDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
@@ -575,7 +576,7 @@
// GIVEN: get insets on the first display, switch to the second display,
// get insets and switch back
val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
- mock(DumpManager::class.java))
+ mock<DumpManager>(), mock<CommandRegistry>())
configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 1080, 2160))
val firstDisplayInsetsFirstCall = provider
@@ -601,7 +602,7 @@
configuration.windowConfiguration.setMaxBounds(0, 0, 100, 100)
configurationController.onConfigurationChanged(configuration)
val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
- mock(DumpManager::class.java))
+ mock<DumpManager>(), mock<CommandRegistry>())
val listener = object : StatusBarContentInsetsChangedListener {
var triggered = false
@@ -623,7 +624,7 @@
fun onDensityOrFontScaleChanged_listenerNotified() {
configuration.densityDpi = 12
val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
- mock(DumpManager::class.java))
+ mock<DumpManager>(), mock<CommandRegistry>())
val listener = object : StatusBarContentInsetsChangedListener {
var triggered = false
@@ -644,7 +645,7 @@
@Test
fun onThemeChanged_listenerNotified() {
val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
- mock(DumpManager::class.java))
+ mock<DumpManager>(), mock<CommandRegistry>())
val listener = object : StatusBarContentInsetsChangedListener {
var triggered = false
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BaseHeadsUpManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BaseHeadsUpManagerTest.java
index 2940c39..4c893e3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BaseHeadsUpManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BaseHeadsUpManagerTest.java
@@ -19,6 +19,7 @@
import static android.app.Notification.FLAG_FSI_REQUESTED_BUT_DENIED;
import static com.android.systemui.dump.LogBufferHelperKt.logcatLogBuffer;
+import static com.android.systemui.util.concurrency.MockExecutorHandlerKt.mockExecutorHandler;
import static com.google.common.truth.Truth.assertThat;
@@ -41,7 +42,6 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Region;
-import android.os.Handler;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -56,11 +56,10 @@
import com.android.systemui.statusbar.AlertingNotificationManagerTest;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
+import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.settings.GlobalSettings;
import com.android.systemui.util.time.SystemClock;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -77,7 +76,6 @@
private static final int TEST_TOUCH_ACCEPTANCE_TIME = 200;
private static final int TEST_A11Y_AUTO_DISMISS_TIME = 1_000;
- private static final int TEST_A11Y_TIMEOUT_TIME = 3_000;
private UiEventLoggerFake mUiEventLoggerFake = new UiEventLoggerFake();
private final HeadsUpManagerLogger mLogger = spy(new HeadsUpManagerLogger(logcatLogBuffer()));
@@ -87,25 +85,18 @@
assertThat(TEST_MINIMUM_DISPLAY_TIME).isLessThan(TEST_AUTO_DISMISS_TIME);
assertThat(TEST_AUTO_DISMISS_TIME).isLessThan(TEST_STICKY_AUTO_DISMISS_TIME);
assertThat(TEST_STICKY_AUTO_DISMISS_TIME).isLessThan(TEST_A11Y_AUTO_DISMISS_TIME);
-
- assertThat(TEST_TOUCH_ACCEPTANCE_TIME + TEST_AUTO_DISMISS_TIME).isLessThan(
- TEST_TIMEOUT_TIME);
- assertThat(TEST_TOUCH_ACCEPTANCE_TIME + TEST_STICKY_AUTO_DISMISS_TIME).isLessThan(
- TEST_TIMEOUT_TIME);
- assertThat(TEST_TOUCH_ACCEPTANCE_TIME + TEST_A11Y_AUTO_DISMISS_TIME).isLessThan(
- TEST_A11Y_TIMEOUT_TIME);
}
private final class TestableHeadsUpManager extends BaseHeadsUpManager {
TestableHeadsUpManager(Context context,
HeadsUpManagerLogger logger,
- Handler handler,
+ DelayableExecutor executor,
GlobalSettings globalSettings,
SystemClock systemClock,
AccessibilityManagerWrapper accessibilityManagerWrapper,
UiEventLogger uiEventLogger) {
- super(context, logger, handler, globalSettings, systemClock,
- accessibilityManagerWrapper, uiEventLogger);
+ super(context, logger, mockExecutorHandler(executor), globalSettings, systemClock,
+ executor, accessibilityManagerWrapper, uiEventLogger);
mTouchAcceptanceDelay = TEST_TOUCH_ACCEPTANCE_TIME;
mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME;
mAutoDismissTime = TEST_AUTO_DISMISS_TIME;
@@ -183,7 +174,7 @@
}
private BaseHeadsUpManager createHeadsUpManager() {
- return new TestableHeadsUpManager(mContext, mLogger, mTestHandler, mGlobalSettings,
+ return new TestableHeadsUpManager(mContext, mLogger, mExecutor, mGlobalSettings,
mSystemClock, mAccessibilityMgr, mUiEventLoggerFake);
}
@@ -234,18 +225,6 @@
}
- @Before
- @Override
- public void setUp() {
- super.setUp();
- }
-
- @After
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
@Test
public void testHunRemovedLogging() {
final BaseHeadsUpManager hum = createHeadsUpManager();
@@ -305,10 +284,9 @@
useAccessibilityTimeout(false);
hum.showNotification(entry);
+ mSystemClock.advanceTime(TEST_TOUCH_ACCEPTANCE_TIME / 2 + TEST_AUTO_DISMISS_TIME);
- final int pastJustAutoDismissMillis =
- TEST_TOUCH_ACCEPTANCE_TIME / 2 + TEST_AUTO_DISMISS_TIME;
- verifyAlertingAtTime(hum, entry, true, pastJustAutoDismissMillis, "just auto dismiss");
+ assertTrue(hum.isAlerting(entry.getKey()));
}
@@ -319,10 +297,10 @@
useAccessibilityTimeout(false);
hum.showNotification(entry);
+ mSystemClock.advanceTime(TEST_TOUCH_ACCEPTANCE_TIME
+ + (TEST_AUTO_DISMISS_TIME + TEST_A11Y_AUTO_DISMISS_TIME) / 2);
- final int pastDefaultTimeoutMillis = TEST_TOUCH_ACCEPTANCE_TIME
- + (TEST_AUTO_DISMISS_TIME + TEST_A11Y_AUTO_DISMISS_TIME) / 2;
- verifyAlertingAtTime(hum, entry, false, pastDefaultTimeoutMillis, "default timeout");
+ assertFalse(hum.isAlerting(entry.getKey()));
}
@@ -333,10 +311,10 @@
useAccessibilityTimeout(false);
hum.showNotification(entry);
+ mSystemClock.advanceTime(TEST_TOUCH_ACCEPTANCE_TIME
+ + (TEST_AUTO_DISMISS_TIME + TEST_STICKY_AUTO_DISMISS_TIME) / 2);
- final int pastDefaultTimeoutMillis = TEST_TOUCH_ACCEPTANCE_TIME
- + (TEST_AUTO_DISMISS_TIME + TEST_STICKY_AUTO_DISMISS_TIME) / 2;
- verifyAlertingAtTime(hum, entry, true, pastDefaultTimeoutMillis, "default timeout");
+ assertTrue(hum.isAlerting(entry.getKey()));
}
@@ -347,18 +325,9 @@
useAccessibilityTimeout(false);
hum.showNotification(entry);
+ mSystemClock.advanceTime(TEST_TOUCH_ACCEPTANCE_TIME + 2 * TEST_A11Y_AUTO_DISMISS_TIME);
- final int pastLongestAutoDismissMillis =
- TEST_TOUCH_ACCEPTANCE_TIME + 2 * TEST_A11Y_AUTO_DISMISS_TIME;
- final Boolean[] wasAlerting = {null};
- final Runnable checkAlerting =
- () -> wasAlerting[0] = hum.isAlerting(entry.getKey());
- mTestHandler.postDelayed(checkAlerting, pastLongestAutoDismissMillis);
- TestableLooper.get(this).processMessages(1);
-
- assertTrue("Should still be alerting past longest auto-dismiss", wasAlerting[0]);
- assertTrue("Should still be alerting after processing",
- hum.isAlerting(entry.getKey()));
+ assertTrue(hum.isAlerting(entry.getKey()));
}
@@ -369,10 +338,10 @@
useAccessibilityTimeout(true);
hum.showNotification(entry);
+ mSystemClock.advanceTime(TEST_TOUCH_ACCEPTANCE_TIME
+ + (TEST_AUTO_DISMISS_TIME + TEST_A11Y_AUTO_DISMISS_TIME) / 2);
- final int pastDefaultTimeoutMillis = TEST_TOUCH_ACCEPTANCE_TIME
- + (TEST_AUTO_DISMISS_TIME + TEST_A11Y_AUTO_DISMISS_TIME) / 2;
- verifyAlertingAtTime(hum, entry, true, pastDefaultTimeoutMillis, "default timeout");
+ assertTrue(hum.isAlerting(entry.getKey()));
}
@@ -383,10 +352,10 @@
useAccessibilityTimeout(true);
hum.showNotification(entry);
+ mSystemClock.advanceTime(TEST_TOUCH_ACCEPTANCE_TIME
+ + (TEST_STICKY_AUTO_DISMISS_TIME + TEST_A11Y_AUTO_DISMISS_TIME) / 2);
- final int pastStickyTimeoutMillis = TEST_TOUCH_ACCEPTANCE_TIME
- + (TEST_STICKY_AUTO_DISMISS_TIME + TEST_A11Y_AUTO_DISMISS_TIME) / 2;
- verifyAlertingAtTime(hum, entry, true, pastStickyTimeoutMillis, "sticky timeout");
+ assertTrue(hum.isAlerting(entry.getKey()));
}
@@ -398,18 +367,14 @@
hum.showNotification(entry);
- // Try to remove but defer, since the notification has not been shown long enough.
final boolean removedImmediately = hum.removeNotification(
- entry.getKey(), false /* releaseImmediately */);
+ entry.getKey(), /* releaseImmediately = */ false);
+ assertFalse(removedImmediately);
+ assertTrue(hum.isAlerting(entry.getKey()));
- assertFalse("HUN should not be removed before minimum display time", removedImmediately);
- assertTrue("HUN should still be alerting before minimum display time",
- hum.isAlerting(entry.getKey()));
+ mSystemClock.advanceTime((TEST_MINIMUM_DISPLAY_TIME + TEST_AUTO_DISMISS_TIME) / 2);
- final int pastMinimumDisplayTimeMillis =
- (TEST_MINIMUM_DISPLAY_TIME + TEST_AUTO_DISMISS_TIME) / 2;
- verifyAlertingAtTime(hum, entry, false, pastMinimumDisplayTimeMillis,
- "minimum display time");
+ assertFalse(hum.isAlerting(entry.getKey()));
}
@@ -420,32 +385,13 @@
useAccessibilityTimeout(false);
hum.showNotification(entry);
+ mSystemClock.advanceTime((TEST_MINIMUM_DISPLAY_TIME + TEST_AUTO_DISMISS_TIME) / 2);
- // After the minimum display time:
- // 1. Check whether the notification is still alerting.
- // 2. Try to remove it and check whether the remove succeeded.
- // 3. Check whether it is still alerting after trying to remove it.
- final Boolean[] livedPastMinimumDisplayTime = {null};
- final Boolean[] removedAfterMinimumDisplayTime = {null};
- final Boolean[] livedPastRemoveAfterMinimumDisplayTime = {null};
- final Runnable pastMinimumDisplayTimeRunnable = () -> {
- livedPastMinimumDisplayTime[0] = hum.isAlerting(entry.getKey());
- removedAfterMinimumDisplayTime[0] = hum.removeNotification(
- entry.getKey(), /* releaseImmediately = */ false);
- livedPastRemoveAfterMinimumDisplayTime[0] = hum.isAlerting(entry.getKey());
- };
- final int pastMinimumDisplayTimeMillis =
- (TEST_MINIMUM_DISPLAY_TIME + TEST_AUTO_DISMISS_TIME) / 2;
- mTestHandler.postDelayed(pastMinimumDisplayTimeRunnable, pastMinimumDisplayTimeMillis);
- // Wait until the minimum display time has passed before attempting removal.
- TestableLooper.get(this).processMessages(1);
+ assertTrue(hum.isAlerting(entry.getKey()));
- assertTrue("HUN should live past minimum display time",
- livedPastMinimumDisplayTime[0]);
- assertTrue("HUN should be removed immediately past minimum display time",
- removedAfterMinimumDisplayTime[0]);
- assertFalse("HUN should not live after being removed past minimum display time",
- livedPastRemoveAfterMinimumDisplayTime[0]);
+ final boolean removedImmediately = hum.removeNotification(
+ entry.getKey(), /* releaseImmediately = */ false);
+ assertTrue(removedImmediately);
assertFalse(hum.isAlerting(entry.getKey()));
}
@@ -457,10 +403,8 @@
hum.showNotification(entry);
- // Remove forcibly with releaseImmediately = true.
final boolean removedImmediately = hum.removeNotification(
entry.getKey(), /* releaseImmediately = */ true);
-
assertTrue(removedImmediately);
assertFalse(hum.isAlerting(entry.getKey()));
}
diff --git a/ravenwood/api-maintainers.md b/ravenwood/api-maintainers.md
index 30e899c..d84cb67 100644
--- a/ravenwood/api-maintainers.md
+++ b/ravenwood/api-maintainers.md
@@ -71,3 +71,24 @@
The “replace” strategy described above is quite powerful, and can be used in creative ways to sidestep tricky underlying dependencies that aren’t ready yet.
For example, consider a constructor or static initializer that relies on unsupported functionality from another team. By factoring the unsupported logic into a dedicated method, that method can then be replaced under Ravenwood to offer baseline functionality.
+
+## Strategies for JNI
+
+At the moment, JNI isn't yet supported under Ravenwood, but you may still want to support APIs that are partially implemented with JNI. The current approach is to use the “replace” strategy to offer a pure-Java alternative implementation for any JNI-provided logic.
+
+Since this approach requires potentially complex re-implementation, it should only be considered for core infrastructure that is critical to unblocking widespread testing use-cases. Other less-common usages of JNI should instead wait for offical JNI support in the Ravenwood environment.
+
+When a pure-Java implementation grows too large or complex to host within the original class, the `@RavenwoodNativeSubstitutionClass` annotation can be used to host it in a separate source file:
+
+```
+@RavenwoodKeepWholeClass
+@RavenwoodNativeSubstitutionClass("com.android.hoststubgen.nativesubstitution.MyComplexClass_host")
+public class MyComplexClass {
+ private static native void nativeDoThing(long nativePtr);
+...
+
+public class MyComplexClass_host {
+ public static void nativeDoThing(long nativePtr) {
+ // ...
+ }
+```
diff --git a/ravenwood/ravenwood-annotation-allowed-classes.txt b/ravenwood/ravenwood-annotation-allowed-classes.txt
index 2ba5f6b..9fcabd6 100644
--- a/ravenwood/ravenwood-annotation-allowed-classes.txt
+++ b/ravenwood/ravenwood-annotation-allowed-classes.txt
@@ -27,6 +27,8 @@
android.os.BatteryConsumer
android.os.Binder
android.os.Binder$IdentitySupplier
+android.os.Broadcaster
+android.os.BundleMerger
android.os.FileUtils
android.os.FileUtils$MemoryPipe
android.os.Handler
@@ -36,12 +38,15 @@
android.os.Looper
android.os.Message
android.os.MessageQueue
+android.os.PackageTagsList
android.os.Parcel
android.os.Parcelable
android.os.Process
android.os.SystemClock
android.os.ThreadLocalWorkSource
+android.os.TimestampedValue
android.os.UserHandle
+android.os.WorkSource
android.content.ClipData
android.content.ClipData$Item
@@ -95,8 +100,6 @@
com.android.server.LocalServices
-com.android.internal.os.SomeArgs
-
com.android.internal.util.BitUtils
com.android.internal.util.BitwiseInputStream
com.android.internal.util.BitwiseOutputStream
@@ -118,6 +121,23 @@
com.android.internal.util.RingBuffer
com.android.internal.util.StringPool
+com.android.internal.os.BinderCallHeavyHitterWatcher
+com.android.internal.os.BinderDeathDispatcher
+com.android.internal.os.BinderfsStatsReader
+com.android.internal.os.BinderLatencyBuckets
+com.android.internal.os.CachedDeviceState
+com.android.internal.os.Clock
+com.android.internal.os.CpuScalingPolicies
+com.android.internal.os.CpuScalingPolicyReader
+com.android.internal.os.KernelCpuThreadReader
+com.android.internal.os.LoggingPrintStream
+com.android.internal.os.LooperStats
+com.android.internal.os.MonotonicClock
+com.android.internal.os.ProcLocksReader
+com.android.internal.os.ProcStatsUtil
+com.android.internal.os.SomeArgs
+com.android.internal.os.StoragedUidIoStatsReader
+
com.google.android.collect.Lists
com.google.android.collect.Maps
com.google.android.collect.Sets
diff --git a/ravenwood/test-authors.md b/ravenwood/test-authors.md
index de05777..5df827f 100644
--- a/ravenwood/test-authors.md
+++ b/ravenwood/test-authors.md
@@ -74,7 +74,7 @@
$ atest --host MyTestsRavenwood
```
-> **Note:** There's a known bug where `atest` currently requires a connected device to run Ravenwood tests, but that device isn't used for testing. Using the `--host` argument above is a way to bypass this requirement until bug #312525698 is fixed.
+> **Note:** There's a known bug #312525698 where `atest` currently requires a connected device to run Ravenwood tests, but that device isn't used for testing. Using the `--host` argument above is a way to bypass this requirement until the bug is fixed.
You can also run your new tests automatically via `TEST_MAPPING` rules like this:
@@ -89,6 +89,8 @@
}
```
+> **Note:** There's a known bug #308854804 where `TEST_MAPPING` is not being applied, so we're currently planning to run all Ravenwood tests unconditionally in presubmit for changes to `frameworks/base/` and `cts/` until there is a better path forward.
+
## Strategies for feature flags
Ravenwood supports writing tests against logic that uses feature flags through the existing `SetFlagsRule` infrastructure maintained by the feature flagging team:
@@ -112,9 +114,9 @@
## Strategies for migration/bivalent tests
-Ravenwood aims to support tests that are written in a “bivalent” way, where the same test code can run on both a real Android device and under a Ravenwood environment.
+Ravenwood aims to support tests that are written in a “bivalent” way, where the same test code can be dual-compiled to run on both a real Android device and under a Ravenwood environment.
-In situations where a test method depends on API functionality not yet available under Ravenwood, we provide an annotation to quietly “ignore” that test under Ravenwood, while continuing to validate that test on real devices. Please note that your test must declare a `RavenwoodRule` for the annotation to take effect.
+In situations where a test method depends on API functionality not yet available under Ravenwood, we provide an annotation to quietly “ignore” that test under Ravenwood, while continuing to validate that test on real devices. The annotation can be applied to either individual methods or to an entire test class. Please note that your test class must declare a `RavenwoodRule` for the annotation to take effect.
Test authors are encouraged to provide a `blockedBy` or `reason` argument to help future maintainers understand why a test is being ignored, and under what conditions it might be supported in the future.
@@ -137,11 +139,39 @@
}
```
+At the moment, the `android.content.res.Resources` subsystem isn't yet supported under Ravenwood, but you may still want to dual-compile test suites that depend on references to resources. Below is a strategy for supporting dual-compiliation, where you can "borrow" the generated resource symbols from your traditional `android_test` target:
+
+```
+android_test {
+ name: "MyTestsDevice",
+ resource_dirs: ["res"],
+...
+
+android_ravenwood_test {
+ name: "MyTestsRavenwood",
+ srcs: [
+ ":MyTestsDevice{.aapt.srcjar}",
+...
+```
+
## Strategies for unsupported APIs
As you write tests against Ravenwood, you’ll likely discover API dependencies that aren’t supported yet. Here’s a few strategies that can help you make progress:
-* Your code-under-test may benefit from subtle dependency refactoring to reduce coupling. (For example, providing a specific `File` argument instead of deriving it internally from a `Context`.)
+* Your code-under-test may benefit from subtle dependency refactoring to reduce coupling. (For example, providing a specific `File` argument instead of deriving paths internally from a `Context` or `Environment`.)
+ * One common use-case is providing a directory for your test to store temporary files, which can easily be accomplished using the `Files.createTempDirectory()` API which works on both physical devices and under Ravenwood:
+
+```
+import java.nio.file.Files;
+
+@RunWith(AndroidJUnit4.class)
+public class MyTest {
+ @Before
+ public void setUp() throws Exception {
+ File tempDir = Files.createTempDirectory("MyTest").toFile();
+...
+```
+
* Although mocking code that your team doesn’t own is a generally discouraged testing practice, it can be a valuable pressure relief valve when a dependency isn’t yet supported.
## Strategies for debugging test development
diff --git a/services/core/java/android/content/pm/PackageManagerInternal.java b/services/core/java/android/content/pm/PackageManagerInternal.java
index 31c9348..09e7986 100644
--- a/services/core/java/android/content/pm/PackageManagerInternal.java
+++ b/services/core/java/android/content/pm/PackageManagerInternal.java
@@ -222,6 +222,14 @@
int callingUid);
/**
+ * Like {@link #getInstalledApplications}, but allows the fetching of apps
+ * cross user.
+ */
+ public abstract List<ApplicationInfo> getInstalledApplicationsCrossUser(
+ @PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
+ int callingUid);
+
+ /**
* Retrieve launcher extras for a suspended package provided to the system in
* {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
* PersistableBundle, String)}.
diff --git a/services/core/java/com/android/server/TEST_MAPPING b/services/core/java/com/android/server/TEST_MAPPING
index 708da19..5e9d1cb 100644
--- a/services/core/java/com/android/server/TEST_MAPPING
+++ b/services/core/java/com/android/server/TEST_MAPPING
@@ -110,6 +110,9 @@
},
{
"name": "FrameworksNetTests"
+ },
+ {
+ "name": "CtsSuspendAppsTestCases"
}
],
"presubmit-large": [
@@ -150,9 +153,6 @@
"name": "CtsPackageManagerTestCases"
},
{
- "name": "CtsSuspendAppsTestCases"
- },
- {
"name": "FrameworksServicesTests",
"options": [
{
diff --git a/services/core/java/com/android/server/app/GameManagerService.java b/services/core/java/com/android/server/app/GameManagerService.java
index 824bdd4..b182538 100644
--- a/services/core/java/com/android/server/app/GameManagerService.java
+++ b/services/core/java/com/android/server/app/GameManagerService.java
@@ -19,6 +19,7 @@
import static android.content.Intent.ACTION_PACKAGE_ADDED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
import static android.content.Intent.EXTRA_REPLACING;
+import static android.server.app.Flags.gameDefaultFrameRate;
import static com.android.internal.R.styleable.GameModeConfig_allowGameAngleDriver;
import static com.android.internal.R.styleable.GameModeConfig_allowGameDownscaling;
@@ -28,6 +29,7 @@
import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;
import android.Manifest;
+import android.annotation.EnforcePermission;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -66,11 +68,13 @@
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
+import android.os.PermissionEnforcer;
import android.os.PowerManagerInternal;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ShellCallback;
+import android.os.SystemProperties;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig.Properties;
@@ -138,12 +142,17 @@
static final int WRITE_GAME_MODE_INTERVENTION_LIST_FILE = 6;
static final int WRITE_DELAY_MILLIS = 10 * 1000; // 10 seconds
static final int LOADING_BOOST_MAX_DURATION = 5 * 1000; // 5 seconds
+ static final String PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED =
+ "persist.graphics.game_default_frame_rate.enabled";
+ static final String PROPERTY_RO_SURFACEFLINGER_GAME_DEFAULT_FRAME_RATE =
+ "ro.surface_flinger.game_default_frame_rate_override";
private static final String PACKAGE_NAME_MSG_KEY = "packageName";
private static final String USER_ID_MSG_KEY = "userId";
private static final String GAME_MODE_INTERVENTION_LIST_FILE_NAME =
"game_mode_intervention.list";
+
private final Context mContext;
private final Object mLock = new Object();
private final Object mDeviceConfigLock = new Object();
@@ -154,7 +163,6 @@
private final PackageManager mPackageManager;
private final UserManager mUserManager;
private final PowerManagerInternal mPowerManagerInternal;
- private final File mSystemDir;
@VisibleForTesting
final AtomicFile mGameModeInterventionListFile;
private DeviceConfigListener mDeviceConfigListener;
@@ -175,28 +183,56 @@
final MyUidObserver mUidObserver;
@GuardedBy("mUidObserverLock")
private final Set<Integer> mForegroundGameUids = new HashSet<>();
+ private final GameManagerServiceSystemPropertiesWrapper mSysProps;
+
+ @VisibleForTesting
+ static class Injector {
+ public GameManagerServiceSystemPropertiesWrapper createSystemPropertiesWrapper() {
+ return new GameManagerServiceSystemPropertiesWrapper() {
+ @Override
+ public String get(String key, String def) {
+ return SystemProperties.get(key, def);
+ }
+ @Override
+ public boolean getBoolean(String key, boolean def) {
+ return SystemProperties.getBoolean(key, def);
+ }
+
+ @Override
+ public int getInt(String key, int def) {
+ return SystemProperties.getInt(key, def);
+ }
+
+ @Override
+ public void set(String key, String val) {
+ SystemProperties.set(key, val);
+ }
+ };
+ }
+ }
public GameManagerService(Context context) {
this(context, createServiceThread().getLooper());
}
GameManagerService(Context context, Looper looper) {
- this(context, looper, Environment.getDataDirectory());
+ this(context, looper, Environment.getDataDirectory(), new Injector());
}
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
- GameManagerService(Context context, Looper looper, File dataDir) {
+ GameManagerService(Context context, Looper looper, File dataDir, Injector injector) {
+ super(PermissionEnforcer.fromContext(context));
mContext = context;
mHandler = new SettingsHandler(looper);
mPackageManager = mContext.getPackageManager();
mUserManager = mContext.getSystemService(UserManager.class);
mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
- mSystemDir = new File(dataDir, "system");
- mSystemDir.mkdirs();
- FileUtils.setPermissions(mSystemDir.toString(),
+ File systemDir = new File(dataDir, "system");
+ systemDir.mkdirs();
+ FileUtils.setPermissions(systemDir.toString(),
FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IROTH | FileUtils.S_IXOTH,
-1, -1);
- mGameModeInterventionListFile = new AtomicFile(new File(mSystemDir,
+ mGameModeInterventionListFile = new AtomicFile(new File(systemDir,
GAME_MODE_INTERVENTION_LIST_FILE_NAME));
FileUtils.setPermissions(mGameModeInterventionListFile.getBaseFile().getAbsolutePath(),
FileUtils.S_IRUSR | FileUtils.S_IWUSR
@@ -220,6 +256,8 @@
} catch (RemoteException e) {
Slog.w(TAG, "Could not register UidObserver");
}
+
+ mSysProps = injector.createSystemPropertiesWrapper();
}
@Override
@@ -1588,7 +1626,7 @@
try {
final float fps = 0.0f;
final int uid = mPackageManager.getPackageUidAsUser(packageName, userId);
- setOverrideFrameRate(uid, fps);
+ setGameModeFrameRateOverride(uid, fps);
} catch (PackageManager.NameNotFoundException e) {
return;
}
@@ -1620,7 +1658,7 @@
try {
final float fps = modeConfig.getFps();
final int uid = mPackageManager.getPackageUidAsUser(packageName, userId);
- setOverrideFrameRate(uid, fps);
+ setGameModeFrameRateOverride(uid, fps);
} catch (PackageManager.NameNotFoundException e) {
return;
}
@@ -2159,14 +2197,70 @@
}
@VisibleForTesting
- void setOverrideFrameRate(int uid, float frameRate) {
- nativeSetOverrideFrameRate(uid, frameRate);
+ void setGameModeFrameRateOverride(int uid, float frameRate) {
+ nativeSetGameModeFrameRateOverride(uid, frameRate);
+ }
+
+ @VisibleForTesting
+ void setGameDefaultFrameRateOverride(int uid, float frameRate) {
+ Slog.v(TAG, "setDefaultFrameRateOverride : " + uid + " , " + frameRate);
+ nativeSetGameDefaultFrameRateOverride(uid, frameRate);
+ }
+
+ private float getGameDefaultFrameRate() {
+ final boolean isGameDefaultFrameRateEnabled;
+ float gameDefaultFrameRate = 0.0f;
+ synchronized (mLock) {
+ isGameDefaultFrameRateEnabled =
+ mSysProps.getBoolean(
+ PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED, true);
+ }
+ if (gameDefaultFrameRate()) {
+ gameDefaultFrameRate = isGameDefaultFrameRateEnabled
+ ? (float) mSysProps.getInt(
+ PROPERTY_RO_SURFACEFLINGER_GAME_DEFAULT_FRAME_RATE, 0) : 0.0f;
+ }
+ return gameDefaultFrameRate;
+ }
+
+ @Override
+ @EnforcePermission(Manifest.permission.MANAGE_GAME_MODE)
+ public void toggleGameDefaultFrameRate(boolean isEnabled) {
+ toggleGameDefaultFrameRate_enforcePermission();
+ if (gameDefaultFrameRate()) {
+ Slog.v(TAG, "toggleGameDefaultFrameRate : " + isEnabled);
+ this.toggleGameDefaultFrameRateUnchecked(isEnabled);
+ }
+ }
+
+ private void toggleGameDefaultFrameRateUnchecked(boolean isEnabled) {
+ // Update system properties.
+ // Here we only need to immediately update games that are in the foreground.
+ // We will update game default frame rate when a game comes into foreground in
+ // MyUidObserver.
+ synchronized (mLock) {
+ if (isEnabled) {
+ mSysProps.set(
+ PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED, "true");
+ } else {
+ mSysProps.set(
+ PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED, "false");
+ }
+ }
+
+ // Update all foreground games' frame rate.
+ synchronized (mUidObserverLock) {
+ for (int uid : mForegroundGameUids) {
+ setGameDefaultFrameRateOverride(uid, getGameDefaultFrameRate());
+ }
+ }
}
/**
* load dynamic library for frame rate overriding JNI calls
*/
- private static native void nativeSetOverrideFrameRate(int uid, float frameRate);
+ private static native void nativeSetGameModeFrameRateOverride(int uid, float frameRate);
+ private static native void nativeSetGameDefaultFrameRateOverride(int uid, float frameRate);
final class MyUidObserver extends UidObserver {
@Override
@@ -2179,6 +2273,7 @@
@Override
public void onUidStateChanged(int uid, int procState, long procStateSeq, int capability) {
synchronized (mUidObserverLock) {
+
if (procState != ActivityManager.PROCESS_STATE_TOP) {
disableGameMode(uid);
return;
@@ -2198,6 +2293,7 @@
Slog.v(TAG, "Game power mode ON (process state was changed to foreground)");
mPowerManagerInternal.setPowerMode(Mode.GAME, true);
}
+ setGameDefaultFrameRateOverride(uid, getGameDefaultFrameRate());
mForegroundGameUids.add(uid);
}
}
diff --git a/services/core/java/com/android/server/app/GameManagerServiceSystemPropertiesWrapper.java b/services/core/java/com/android/server/app/GameManagerServiceSystemPropertiesWrapper.java
new file mode 100644
index 0000000..afaceda
--- /dev/null
+++ b/services/core/java/com/android/server/app/GameManagerServiceSystemPropertiesWrapper.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2023 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.app;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.SystemProperties;
+/**
+ * Wrapper interface to access {@link SystemProperties}.
+ *
+ * @hide
+ */
+interface GameManagerServiceSystemPropertiesWrapper {
+ /**
+ * Get the String value for the given {@code key}.
+ *
+ * @param key the key to lookup
+ * @param def the default value in case the property is not set or empty
+ * @return if the {@code key} isn't found, return {@code def} if it isn't null, or an empty
+ * string otherwise
+ */
+ @NonNull
+ String get(@NonNull String key, @Nullable String def);
+ /**
+ * Get the Boolean value for the given {@code key}.
+ *
+ * @param key the key to lookup
+ * @param def the default value in case the property is not set or empty
+ * @return if the {@code key} isn't found, return {@code def} if it isn't null, not parsable
+ * or an empty string otherwise
+ */
+ @NonNull
+ boolean getBoolean(@NonNull String key, boolean def);
+
+ /**
+ * Get the Integer value for the given {@code key}.
+ *
+ * @param key the key to lookup
+ * @param def the default value in case the property is not set or empty
+ * @return if the {@code key} isn't found, return {@code def} if it isn't null, not parsable
+ * or an empty string otherwise
+ */
+ @NonNull
+ int getInt(@NonNull String key, int def);
+ /**
+ * Set the value for the given {@code key} to {@code val}.
+ *
+ * @throws IllegalArgumentException if the {@code val} exceeds 91 characters
+ * @throws RuntimeException if the property cannot be set, for example, if it was blocked by
+ * SELinux. libc will log the underlying reason.
+ */
+ void set(@NonNull String key, @Nullable String val);
+}
diff --git a/services/core/java/com/android/server/app/flags.aconfig b/services/core/java/com/android/server/app/flags.aconfig
new file mode 100644
index 0000000..f2e4783
--- /dev/null
+++ b/services/core/java/com/android/server/app/flags.aconfig
@@ -0,0 +1,9 @@
+package: "android.server.app"
+
+flag {
+ name: "game_default_frame_rate"
+ namespace: "game"
+ description: "This flag guards the new behavior with the addition of Game Default Frame Rate feature."
+ bug: "286084594"
+ is_fixed_read_only: true
+}
\ No newline at end of file
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 3fc9594..972f857 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -3504,6 +3504,13 @@
wm.addView(view, lp);
}
+ /**
+ * Sets Accessibility bounce keys threshold in milliseconds.
+ */
+ public void setAccessibilityBounceKeysThreshold(int thresholdTimeMs) {
+ mNative.setAccessibilityBounceKeysThreshold(thresholdTimeMs);
+ }
+
interface KeyboardBacklightControllerInterface {
default void incrementKeyboardBacklight(int deviceId) {}
default void decrementKeyboardBacklight(int deviceId) {}
diff --git a/services/core/java/com/android/server/input/InputSettingsObserver.java b/services/core/java/com/android/server/input/InputSettingsObserver.java
index 8e0289e..0012eab1 100644
--- a/services/core/java/com/android/server/input/InputSettingsObserver.java
+++ b/services/core/java/com/android/server/input/InputSettingsObserver.java
@@ -85,7 +85,9 @@
Map.entry(Settings.Secure.getUriFor(Settings.Secure.KEY_REPEAT_DELAY_MS),
(reason) -> updateKeyRepeatInfo()),
Map.entry(Settings.System.getUriFor(Settings.System.SHOW_ROTARY_INPUT),
- (reason) -> updateShowRotaryInput()));
+ (reason) -> updateShowRotaryInput()),
+ Map.entry(Settings.System.getUriFor(Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS),
+ (reason) -> updateAccessibilityBounceKeys()));
}
/**
@@ -216,4 +218,9 @@
}
mNative.setMaximumObscuringOpacityForTouch(opacity);
}
+
+ private void updateAccessibilityBounceKeys() {
+ mService.setAccessibilityBounceKeysThreshold(
+ InputSettings.getAccessibilityBounceKeysThreshold(mContext));
+ }
}
diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java
index 620cde5..49bbe9a 100644
--- a/services/core/java/com/android/server/input/NativeInputManagerService.java
+++ b/services/core/java/com/android/server/input/NativeInputManagerService.java
@@ -246,6 +246,11 @@
*/
void sysfsNodeChanged(String sysfsNodePath);
+ /**
+ * Notify if Accessibility bounce keys threshold is changed from InputSettings.
+ */
+ void setAccessibilityBounceKeysThreshold(int thresholdTimeMs);
+
/** The native implementation of InputManagerService methods. */
class NativeImpl implements NativeInputManagerService {
/** Pointer to native input manager service object, used by native code. */
@@ -500,5 +505,8 @@
@Override
public native void sysfsNodeChanged(String sysfsNodePath);
+
+ @Override
+ public native void setAccessibilityBounceKeysThreshold(int thresholdTimeMs);
}
}
diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
index 10b6052..e5807e8 100644
--- a/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
+++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
@@ -82,6 +82,7 @@
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -272,9 +273,10 @@
CertPath certPath;
X509Certificate rootCert =
mTestCertHelper.getRootCertificate(rootCertificateAlias);
+ Date validationDate = mTestCertHelper.getValidationDate(rootCertificateAlias);
try {
Log.d(TAG, "Getting and validating a random endpoint certificate");
- certPath = certXml.getRandomEndpointCert(rootCert);
+ certPath = certXml.getRandomEndpointCert(rootCert, validationDate);
} catch (CertValidationException e) {
Log.e(TAG, "Invalid endpoint cert", e);
throw new ServiceSpecificException(ERROR_INVALID_CERTIFICATE, e.getMessage());
@@ -348,10 +350,11 @@
X509Certificate rootCert =
mTestCertHelper.getRootCertificate(rootCertificateAlias);
+ Date validationDate = mTestCertHelper.getValidationDate(rootCertificateAlias);
try {
- sigXml.verifyFileSignature(rootCert, recoveryServiceCertFile);
+ sigXml.verifyFileSignature(rootCert, recoveryServiceCertFile, validationDate);
} catch (CertValidationException e) {
- Log.d(TAG, "The signature over the cert file is invalid."
+ Log.e(TAG, "The signature over the cert file is invalid."
+ " Cert: " + HexDump.toHexString(recoveryServiceCertFile)
+ " Sig: " + HexDump.toHexString(recoveryServiceSigFile));
throw new ServiceSpecificException(ERROR_INVALID_CERTIFICATE, e.getMessage());
@@ -601,8 +604,9 @@
}
try {
- CertUtils.validateCertPath(
- mTestCertHelper.getRootCertificate(rootCertificateAlias), certPath);
+ Date validationDate = mTestCertHelper.getValidationDate(rootCertificateAlias);
+ CertUtils.validateCertPath(mTestCertHelper.getRootCertificate(rootCertificateAlias),
+ certPath, validationDate);
} catch (CertValidationException e) {
Log.e(TAG, "Failed to validate the given cert path", e);
throw new ServiceSpecificException(ERROR_INVALID_CERTIFICATE, e.getMessage());
diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/TestOnlyInsecureCertificateHelper.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/TestOnlyInsecureCertificateHelper.java
index c963f79..4a1cae2 100644
--- a/services/core/java/com/android/server/locksettings/recoverablekeystore/TestOnlyInsecureCertificateHelper.java
+++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/TestOnlyInsecureCertificateHelper.java
@@ -29,6 +29,7 @@
import com.android.internal.widget.LockPatternUtils;
import java.security.cert.X509Certificate;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -67,6 +68,18 @@
return rootCertificate;
}
+ /**
+ * Returns hardcoded validation date for e2e tests.
+ */
+ public @Nullable Date getValidationDate(String rootCertificateAlias) {
+ if (isTestOnlyCertificateAlias(rootCertificateAlias)) {
+ // Certificate used for e2e test is expired.
+ return new Date(2019 - 1900, 1, 30);
+ } else {
+ return null; // Use current time
+ }
+ }
+
public @NonNull String getDefaultCertificateAliasIfEmpty(
@Nullable String rootCertificateAlias) {
if (rootCertificateAlias == null || rootCertificateAlias.isEmpty()) {
diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/CertUtils.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/CertUtils.java
index 26e8270..0881275 100644
--- a/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/CertUtils.java
+++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/CertUtils.java
@@ -305,12 +305,13 @@
*
* @param trustedRoot the trusted root certificate
* @param certPath the certificate path to be validated
+ * @param validationDate use null for current time
* @throws CertValidationException if the given certificate path is invalid, e.g., is expired,
* or does not have a valid signature
*/
- public static void validateCertPath(X509Certificate trustedRoot, CertPath certPath)
- throws CertValidationException {
- validateCertPath(/*validationDate=*/ null, trustedRoot, certPath);
+ public static void validateCertPath(X509Certificate trustedRoot, CertPath certPath,
+ @Nullable Date validationDate) throws CertValidationException {
+ validateCertPath(validationDate, trustedRoot, certPath);
}
/**
diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/CertXml.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/CertXml.java
index ff22a8d..d159a84 100644
--- a/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/CertXml.java
+++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/CertXml.java
@@ -76,15 +76,16 @@
* and returns the certificate path including the chosen certificate if it is valid.
*
* @param trustedRoot the trusted root certificate
+ * @param validationDate use null for current time
* @return the certificate path including the chosen certificate if the certificate is valid
* @throws CertValidationException if the chosen certificate cannot be validated based on the
* trusted root certificate
*/
- public CertPath getRandomEndpointCert(X509Certificate trustedRoot)
- throws CertValidationException {
+ public CertPath getRandomEndpointCert(X509Certificate trustedRoot,
+ @Nullable Date validationDate)throws CertValidationException {
return getEndpointCert(
new SecureRandom().nextInt(this.endpointCerts.size()),
- /*validationDate=*/ null,
+ validationDate,
trustedRoot);
}
diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/SigXml.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/SigXml.java
index e75be85..c3f4f55 100644
--- a/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/SigXml.java
+++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/certificate/SigXml.java
@@ -18,7 +18,7 @@
import android.annotation.Nullable;
-import com.android.internal.annotations.VisibleForTesting;
+import org.w3c.dom.Element;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
@@ -26,8 +26,6 @@
import java.util.Date;
import java.util.List;
-import org.w3c.dom.Element;
-
/**
* Parses and holds the XML file containing the signature of the XML file containing the list of THM
* public-key certificates.
@@ -58,17 +56,13 @@
*
* @param trustedRoot the trusted root certificate
* @param signedFileBytes the original file content that has been signed
+ * @param validationDate use null for current time
+ *
* @throws CertValidationException if the signature verification fails, or the signer's
* certificate contained in this XML file cannot be validated
* based on the trusted root certificate
*/
- public void verifyFileSignature(X509Certificate trustedRoot, byte[] signedFileBytes)
- throws CertValidationException {
- verifyFileSignature(trustedRoot, signedFileBytes, /*validationDate=*/ null);
- }
-
- @VisibleForTesting
- void verifyFileSignature(
+ public void verifyFileSignature(
X509Certificate trustedRoot, byte[] signedFileBytes, @Nullable Date validationDate)
throws CertValidationException {
CertUtils.validateCert(validationDate, trustedRoot, intermediateCerts, signerCert);
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index c2a145d..a62d8b8 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -119,6 +119,7 @@
import static android.service.notification.NotificationListenerService.Ranking.RANKING_UNCHANGED;
import static android.service.notification.NotificationListenerService.TRIM_FULL;
import static android.service.notification.NotificationListenerService.TRIM_LIGHT;
+import static android.view.contentprotection.flags.Flags.rapidClearNotificationsByListenerAppOpEnabled;
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
import static com.android.internal.util.FrameworkStatsLog.DND_MODE_RULE;
@@ -414,6 +415,12 @@
static final long SNOOZE_UNTIL_UNSPECIFIED = -1;
+ /**
+ * The threshold, in milliseconds, to determine whether a notification has been
+ * cleared too quickly.
+ */
+ private static final int NOTIFICATION_RAPID_CLEAR_THRESHOLD_MS = 5000;
+
static final int INVALID_UID = -1;
static final String ROOT_PKG = "root";
@@ -4817,9 +4824,12 @@
final int callingUid = Binder.getCallingUid();
final int callingPid = Binder.getCallingPid();
final long identity = Binder.clearCallingIdentity();
+ boolean notificationsRapidlyCleared = false;
+ final String pkg;
try {
synchronized (mNotificationLock) {
final ManagedServiceInfo info = mListeners.checkServiceTokenLocked(token);
+ pkg = info.component.getPackageName();
// Cancellation reason. If the token comes from assistant, label the
// cancellation as coming from the assistant; default to LISTENER_CANCEL.
@@ -4838,11 +4848,19 @@
!mUserProfiles.isCurrentProfile(userId)) {
continue;
}
+ notificationsRapidlyCleared = notificationsRapidlyCleared
+ || isNotificationRecent(r);
cancelNotificationFromListenerLocked(info, callingUid, callingPid,
r.getSbn().getPackageName(), r.getSbn().getTag(),
r.getSbn().getId(), userId, reason);
}
} else {
+ for (NotificationRecord notificationRecord : mNotificationList) {
+ if (isNotificationRecent(notificationRecord)) {
+ notificationsRapidlyCleared = true;
+ break;
+ }
+ }
if (lifetimeExtensionRefactor()) {
cancelAllLocked(callingUid, callingPid, info.userid,
REASON_LISTENER_CANCEL_ALL, info, info.supportsProfiles(),
@@ -4855,11 +4873,23 @@
}
}
}
+ if (notificationsRapidlyCleared) {
+ mAppOps.noteOpNoThrow(AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER,
+ callingUid, pkg, /* attributionTag= */ null, /* message= */ null);
+ }
} finally {
Binder.restoreCallingIdentity(identity);
}
}
+ private boolean isNotificationRecent(@NonNull NotificationRecord notificationRecord) {
+ if (!rapidClearNotificationsByListenerAppOpEnabled()) {
+ return false;
+ }
+ return notificationRecord.getFreshnessMs(System.currentTimeMillis())
+ < NOTIFICATION_RAPID_CLEAR_THRESHOLD_MS;
+ }
+
/**
* Handle request from an approved listener to re-enable itself.
*
@@ -5334,14 +5364,7 @@
@Override
public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String pkg) {
- Objects.requireNonNull(automaticZenRule, "automaticZenRule is null");
- Objects.requireNonNull(automaticZenRule.getName(), "Name is null");
- if (automaticZenRule.getOwner() == null
- && automaticZenRule.getConfigurationActivity() == null) {
- throw new NullPointerException(
- "Rule must have a conditionproviderservice and/or configuration activity");
- }
- Objects.requireNonNull(automaticZenRule.getConditionId(), "ConditionId is null");
+ validateAutomaticZenRule(automaticZenRule);
checkCallerIsSameApp(pkg);
if (automaticZenRule.getZenPolicy() != null
&& automaticZenRule.getInterruptionFilter() != INTERRUPTION_FILTER_PRIORITY) {
@@ -5368,16 +5391,8 @@
}
@Override
- public boolean updateAutomaticZenRule(String id, AutomaticZenRule automaticZenRule)
- throws RemoteException {
- Objects.requireNonNull(automaticZenRule, "automaticZenRule is null");
- Objects.requireNonNull(automaticZenRule.getName(), "Name is null");
- if (automaticZenRule.getOwner() == null
- && automaticZenRule.getConfigurationActivity() == null) {
- throw new NullPointerException(
- "Rule must have a conditionproviderservice and/or configuration activity");
- }
- Objects.requireNonNull(automaticZenRule.getConditionId(), "ConditionId is null");
+ public boolean updateAutomaticZenRule(String id, AutomaticZenRule automaticZenRule) {
+ validateAutomaticZenRule(automaticZenRule);
enforcePolicyAccess(Binder.getCallingUid(), "updateAutomaticZenRule");
// TODO: b/308670715: Distinguish origin properly (e.g. USER if updating a rule
@@ -5388,6 +5403,29 @@
"updateAutomaticZenRule", Binder.getCallingUid());
}
+ private void validateAutomaticZenRule(AutomaticZenRule rule) {
+ Objects.requireNonNull(rule, "automaticZenRule is null");
+ Objects.requireNonNull(rule.getName(), "Name is null");
+ if (rule.getOwner() == null
+ && rule.getConfigurationActivity() == null) {
+ throw new NullPointerException(
+ "Rule must have a conditionproviderservice and/or configuration activity");
+ }
+ Objects.requireNonNull(rule.getConditionId(), "ConditionId is null");
+
+ if (android.app.Flags.modesApi()) {
+ if (rule.getType() == AutomaticZenRule.TYPE_MANAGED) {
+ int uid = Binder.getCallingUid();
+ boolean isDeviceOwner = Binder.withCleanCallingIdentity(
+ () -> mDpm.isActiveDeviceOwner(uid));
+ if (!isDeviceOwner) {
+ throw new IllegalArgumentException(
+ "Only Device Owners can use AutomaticZenRules with TYPE_MANAGED");
+ }
+ }
+ }
+ }
+
@Override
public boolean removeAutomaticZenRule(String id) throws RemoteException {
Objects.requireNonNull(id, "Id is null");
diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java
index fd86870..1bafcfe 100644
--- a/services/core/java/com/android/server/notification/PreferencesHelper.java
+++ b/services/core/java/com/android/server/notification/PreferencesHelper.java
@@ -161,7 +161,6 @@
static final boolean DEFAULT_BUBBLES_ENABLED = true;
@VisibleForTesting
static final int DEFAULT_BUBBLE_PREFERENCE = BUBBLE_PREFERENCE_NONE;
- static final boolean DEFAULT_MEDIA_NOTIFICATION_FILTERING = true;
private static final int NOTIFICATION_UPDATE_LOG_SUBTYPE_FROM_APP = 0;
private static final int NOTIFICATION_UPDATE_LOG_SUBTYPE_FROM_USER = 1;
@@ -200,7 +199,7 @@
private SparseBooleanArray mBubblesEnabled;
private SparseBooleanArray mLockScreenShowNotifications;
private SparseBooleanArray mLockScreenPrivateNotifications;
- private boolean mIsMediaNotificationFilteringEnabled = DEFAULT_MEDIA_NOTIFICATION_FILTERING;
+ private boolean mIsMediaNotificationFilteringEnabled;
// When modes_api flag is enabled, this value only tracks whether the current user has any
// channels marked as "priority channels", but not necessarily whether they are permitted
// to bypass DND by current zen policy.
@@ -224,6 +223,8 @@
mAppOps = appOpsManager;
mUserProfiles = userProfiles;
mShowReviewPermissionsNotification = showReviewPermissionsNotification;
+ mIsMediaNotificationFilteringEnabled = context.getResources()
+ .getBoolean(R.bool.config_quickSettingsShowMediaPlayer);
XML_VERSION = 4;
@@ -2692,8 +2693,11 @@
/** Requests check of the feature setting for showing media notifications in quick settings. */
public void updateMediaNotificationFilteringEnabled() {
+ // TODO(b/192412820): Consolidate SHOW_MEDIA_ON_QUICK_SETTINGS into compile-time value.
final boolean newValue = Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1) > 0;
+ Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1) > 0
+ && mContext.getResources().getBoolean(
+ R.bool.config_quickSettingsShowMediaPlayer);
if (newValue != mIsMediaNotificationFilteringEnabled) {
mIsMediaNotificationFilteringEnabled = newValue;
updateConfig();
diff --git a/services/core/java/com/android/server/pm/Computer.java b/services/core/java/com/android/server/pm/Computer.java
index c36c8ca..bd725ed 100644
--- a/services/core/java/com/android/server/pm/Computer.java
+++ b/services/core/java/com/android/server/pm/Computer.java
@@ -477,7 +477,7 @@
@NonNull
List<ApplicationInfo> getInstalledApplications(
@PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
- int callingUid);
+ int callingUid, boolean forceAllowCrossUser);
@Nullable
ProviderInfo resolveContentProvider(@NonNull String name,
diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java
index 2ae1005..2dc3fb7 100644
--- a/services/core/java/com/android/server/pm/ComputerEngine.java
+++ b/services/core/java/com/android/server/pm/ComputerEngine.java
@@ -4640,7 +4640,7 @@
@Override
public List<ApplicationInfo> getInstalledApplications(
@PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
- int callingUid) {
+ int callingUid, boolean forceAllowCrossUser) {
if (getInstantAppPackageName(callingUid) != null) {
return Collections.emptyList();
}
@@ -4650,12 +4650,14 @@
final boolean listApex = (flags & MATCH_APEX) != 0;
final boolean listArchivedOnly = !listUninstalled && (flags & MATCH_ARCHIVED_PACKAGES) != 0;
- enforceCrossUserPermission(
- callingUid,
- userId,
- false /* requireFullPermission */,
- false /* checkShell */,
- "get installed application info");
+ if (!forceAllowCrossUser) {
+ enforceCrossUserPermission(
+ callingUid,
+ userId,
+ false /* requireFullPermission */,
+ false /* checkShell */,
+ "get installed application info");
+ }
ArrayList<ApplicationInfo> list;
final ArrayMap<String, ? extends PackageStateInternal> packageStates =
diff --git a/services/core/java/com/android/server/pm/IPackageManagerBase.java b/services/core/java/com/android/server/pm/IPackageManagerBase.java
index 9a0306b..24a33f1 100644
--- a/services/core/java/com/android/server/pm/IPackageManagerBase.java
+++ b/services/core/java/com/android/server/pm/IPackageManagerBase.java
@@ -476,7 +476,8 @@
@PackageManager.ApplicationInfoFlagsBits long flags, int userId) {
final int callingUid = Binder.getCallingUid();
return new ParceledListSlice<>(
- snapshot().getInstalledApplications(flags, userId, callingUid));
+ snapshot().getInstalledApplications(flags, userId, callingUid,
+ /* forceAllowCrossUser= */ false));
}
@Override
diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java
index b80c009..58c1c05 100644
--- a/services/core/java/com/android/server/pm/LauncherAppsService.java
+++ b/services/core/java/com/android/server/pm/LauncherAppsService.java
@@ -769,6 +769,9 @@
@NonNull
private List<LauncherActivityInfoInternal> generateLauncherActivitiesForArchivedApp(
@Nullable String packageName, UserHandle user) {
+ if (!canAccessProfile(user.getIdentifier(), "Cannot retrieve activities")) {
+ return List.of();
+ }
List<ApplicationInfo> applicationInfoList =
(packageName == null)
? getApplicationInfoListForAllArchivedApps(user)
@@ -827,7 +830,7 @@
private List<ApplicationInfo> getApplicationInfoListForAllArchivedApps(UserHandle user) {
final int callingUid = injectBinderCallingUid();
List<ApplicationInfo> installedApplicationInfoList =
- mPackageManagerInternal.getInstalledApplications(
+ mPackageManagerInternal.getInstalledApplicationsCrossUser(
PackageManager.MATCH_ARCHIVED_PACKAGES,
user.getIdentifier(),
callingUid);
@@ -845,11 +848,12 @@
private List<ApplicationInfo> getApplicationInfoForArchivedApp(
@NonNull String packageName, UserHandle user) {
final int callingUid = injectBinderCallingUid();
- ApplicationInfo applicationInfo = mPackageManagerInternal.getApplicationInfo(
- packageName,
- PackageManager.MATCH_ARCHIVED_PACKAGES,
- callingUid,
- user.getIdentifier());
+ ApplicationInfo applicationInfo = Binder.withCleanCallingIdentity(() ->
+ mPackageManagerInternal.getApplicationInfo(
+ packageName,
+ PackageManager.MATCH_ARCHIVED_PACKAGES,
+ callingUid,
+ user.getIdentifier()));
if (applicationInfo == null || !applicationInfo.isArchived) {
return Collections.EMPTY_LIST;
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerInternalBase.java b/services/core/java/com/android/server/pm/PackageManagerInternalBase.java
index b281808..1e7d043 100644
--- a/services/core/java/com/android/server/pm/PackageManagerInternalBase.java
+++ b/services/core/java/com/android/server/pm/PackageManagerInternalBase.java
@@ -97,7 +97,16 @@
@Deprecated
public final List<ApplicationInfo> getInstalledApplications(
@PackageManager.ApplicationInfoFlagsBits long flags, int userId, int callingUid) {
- return snapshot().getInstalledApplications(flags, userId, callingUid);
+ return snapshot().getInstalledApplications(flags, userId, callingUid,
+ /* forceAllowCrossUser= */ false);
+ }
+
+ @Override
+ @Deprecated
+ public final List<ApplicationInfo> getInstalledApplicationsCrossUser(
+ @PackageManager.ApplicationInfoFlagsBits long flags, int userId, int callingUid) {
+ return snapshot().getInstalledApplications(flags, userId, callingUid,
+ /* forceAllowCrossUser= */ true);
}
@Override
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 0d06f5b..04ac9fb 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -562,7 +562,6 @@
boolean mClientVisibilityDeferred;// was the visibility change message to client deferred?
boolean idle; // has the activity gone idle?
boolean hasBeenLaunched;// has this activity ever been launched?
- boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
boolean immersive; // immersive mode (don't interrupt if possible)
boolean forceNewConfig; // force re-create with new config next time
boolean supportsEnterPipOnTaskSwitch; // This flag is set by the system to indicate that the
@@ -1201,8 +1200,6 @@
pw.print(" noDisplay="); pw.print(noDisplay);
pw.print(" immersive="); pw.print(immersive);
pw.print(" launchMode="); pw.println(launchMode);
- pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
- pw.print(" forceNewConfig="); pw.println(forceNewConfig);
pw.print(prefix); pw.print("mActivityType=");
pw.println(activityTypeToString(getActivityType()));
pw.print(prefix); pw.print("mImeInsetsFrozenUntilStartInput=");
@@ -3848,7 +3845,7 @@
// updated for restoring original orientation of the display.
if (next == null) {
mRootWindowContainer.ensureVisibilityAndConfig(next, getDisplayId(),
- false /* markFrozenIfConfigChanged */, true /* deferResume */);
+ true /* deferResume */);
}
if (activityRemoved) {
mRootWindowContainer.resumeFocusedTasksTopActivities();
@@ -4090,7 +4087,6 @@
cleanUpSplashScreen();
deferRelaunchUntilPaused = false;
- frozenBeforeDestroy = false;
if (setState) {
setState(DESTROYED, "cleanUp");
@@ -6276,7 +6272,6 @@
}
void handleAlreadyVisible() {
- stopFreezingScreenLocked(false);
try {
if (returningOptions != null) {
app.getThread().scheduleOnNewActivityOptions(token, returningOptions.toBundle());
@@ -6710,19 +6705,6 @@
stopFreezingScreen(true, true);
}
- void stopFreezingScreenLocked(boolean force) {
- if (force || frozenBeforeDestroy) {
- frozenBeforeDestroy = false;
- if (getParent() == null) {
- return;
- }
- ProtoLog.v(WM_DEBUG_ORIENTATION,
- "Clear freezing of %s: visible=%b freezing=%b", token,
- isVisible(), isFreezingScreen());
- stopFreezingScreen(true, force);
- }
- }
-
void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
if (!mFreezingScreen) {
return;
@@ -9569,7 +9551,6 @@
if (finishing) {
ProtoLog.v(WM_DEBUG_CONFIGURATION, "Configuration doesn't matter "
+ "in finishing %s", this);
- stopFreezingScreenLocked(false);
return true;
}
@@ -9660,7 +9641,6 @@
// pick that up next time it starts.
if (!attachedToProcess()) {
ProtoLog.v(WM_DEBUG_CONFIGURATION, "Configuration doesn't matter not running %s", this);
- stopFreezingScreenLocked(false);
forceNewConfig = false;
return true;
}
@@ -9723,9 +9703,6 @@
}
notifyDisplayCompatPolicyAboutConfigurationChange(
mLastReportedConfiguration.getMergedConfiguration(), mTmpConfig);
-
- stopFreezingScreenLocked(false);
-
return true;
}
diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java
index dfb2a5f..4b0177a 100644
--- a/services/core/java/com/android/server/wm/ActivityStarter.java
+++ b/services/core/java/com/android/server/wm/ActivityStarter.java
@@ -1549,8 +1549,7 @@
final ActivityRecord currentTop = startedActivityRootTask.topRunningActivity();
if (currentTop != null && currentTop.shouldUpdateConfigForDisplayChanged()) {
mRootWindowContainer.ensureVisibilityAndConfig(
- currentTop, currentTop.getDisplayId(),
- true /* markFrozenIfConfigChanged */, false /* deferResume */);
+ currentTop, currentTop.getDisplayId(), false /* deferResume */);
}
if (!mAvoidMoveToFront && mDoResume && mRootWindowContainer
diff --git a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
index 4a479aa..e59601c 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
@@ -843,7 +843,7 @@
// We don't want to perform a redundant launch of the same record while ensuring
// configurations and trying to resume top activity of focused root task.
mRootWindowContainer.ensureVisibilityAndConfig(r, r.getDisplayId(),
- false /* markFrozenIfConfigChanged */, true /* deferResume */);
+ true /* deferResume */);
}
if (mKeyguardController.checkKeyguardVisibility(r) && r.allowMoveToFront()) {
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index 3f20624..03d6c2c 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -1710,7 +1710,6 @@
final ActivityRecord activityRecord = (ActivityRecord) requestingContainer;
final boolean kept = updateDisplayOverrideConfigurationLocked(config, activityRecord,
false /* deferResume */, null /* result */);
- activityRecord.frozenBeforeDestroy = true;
if (!kept) {
mRootWindowContainer.resumeFocusedTasksTopActivities();
}
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index 522e7d2..d5aa276 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -1741,14 +1741,11 @@
* @param starting The currently starting activity or {@code null} if there is
* none.
* @param displayId The id of the display where operation is executed.
- * @param markFrozenIfConfigChanged Whether to set {@link ActivityRecord#frozenBeforeDestroy} to
- * {@code true} if config changed.
* @param deferResume Whether to defer resume while updating config.
* @return 'true' if starting activity was kept or wasn't provided, 'false' if it was relaunched
* because of configuration update.
*/
- boolean ensureVisibilityAndConfig(ActivityRecord starting, int displayId,
- boolean markFrozenIfConfigChanged, boolean deferResume) {
+ boolean ensureVisibilityAndConfig(ActivityRecord starting, int displayId, boolean deferResume) {
// First ensure visibility without updating the config just yet. We need this to know what
// activities are affecting configuration now.
// Passing null here for 'starting' param value, so that visibility of actual starting
@@ -1774,9 +1771,6 @@
if (starting != null) {
starting.reportDescendantOrientationChangeIfNeeded();
}
- if (starting != null && markFrozenIfConfigChanged && config != null) {
- starting.frozenBeforeDestroy = true;
- }
if (displayContent != null) {
// Update the configuration of the activities on the display.
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 5f08212..671acfc 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -5815,8 +5815,7 @@
}
mRootWindowContainer.ensureVisibilityAndConfig(null /* starting */,
- mDisplayContent.mDisplayId, false /* markFrozenIfConfigChanged */,
- false /* deferResume */);
+ mDisplayContent.mDisplayId, false /* deferResume */);
} finally {
if (mTransitionController.isShellTransitionsEnabled()) {
mAtmService.continueWindowLayout();
diff --git a/services/core/java/com/android/server/wm/TaskFragment.java b/services/core/java/com/android/server/wm/TaskFragment.java
index 39b4480..fc92755 100644
--- a/services/core/java/com/android/server/wm/TaskFragment.java
+++ b/services/core/java/com/android/server/wm/TaskFragment.java
@@ -1485,7 +1485,7 @@
// TODO: Remove this once visibilities are set correctly immediately when
// starting an activity.
notUpdated = !mRootWindowContainer.ensureVisibilityAndConfig(next, getDisplayId(),
- true /* markFrozenIfConfigChanged */, false /* deferResume */);
+ false /* deferResume */);
}
if (notUpdated) {
@@ -1856,7 +1856,7 @@
// In that case go ahead and remove the freeze this activity has on the screen
// since it is no longer visible.
if (prev != null) {
- prev.stopFreezingScreenLocked(true /*force*/);
+ prev.stopFreezingScreen(true /* unfreezeNow */, true /* force */);
}
mPausingActivity = null;
}
diff --git a/services/core/java/com/android/server/wm/WindowProcessController.java b/services/core/java/com/android/server/wm/WindowProcessController.java
index 2b18f07..fd5f7a3 100644
--- a/services/core/java/com/android/server/wm/WindowProcessController.java
+++ b/services/core/java/com/android/server/wm/WindowProcessController.java
@@ -915,7 +915,7 @@
int i = mActivities.size();
while (i > 0) {
i--;
- mActivities.get(i).stopFreezingScreenLocked(true);
+ mActivities.get(i).stopFreezingScreen(true /* unfreezeNow */, true /* force */);
}
}
}
diff --git a/services/core/jni/com_android_server_app_GameManagerService.cpp b/services/core/jni/com_android_server_app_GameManagerService.cpp
index 3028813..f593f40 100644
--- a/services/core/jni/com_android_server_app_GameManagerService.cpp
+++ b/services/core/jni/com_android_server_app_GameManagerService.cpp
@@ -25,15 +25,21 @@
namespace android {
-static void android_server_app_GameManagerService_nativeSetOverrideFrameRate(JNIEnv* env,
- jclass clazz, jint uid,
- jfloat frameRate) {
- SurfaceComposerClient::setOverrideFrameRate(uid, frameRate);
+static void android_server_app_GameManagerService_nativeSetGameModeFrameRateOverride(
+ JNIEnv* env, jclass clazz, jint uid, jfloat frameRate) {
+ SurfaceComposerClient::setGameModeFrameRateOverride(uid, frameRate);
+}
+
+static void android_server_app_GameManagerService_nativeSetGameDefaultFrameRateOverride(
+ JNIEnv* env, jclass clazz, jint uid, jfloat frameRate) {
+ SurfaceComposerClient::setGameDefaultFrameRateOverride(uid, frameRate);
}
static const JNINativeMethod gMethods[] = {
- {"nativeSetOverrideFrameRate", "(IF)V",
- (void*)android_server_app_GameManagerService_nativeSetOverrideFrameRate},
+ {"nativeSetGameModeFrameRateOverride", "(IF)V",
+ (void*)android_server_app_GameManagerService_nativeSetGameModeFrameRateOverride},
+ {"nativeSetGameDefaultFrameRateOverride", "(IF)V",
+ (void*)android_server_app_GameManagerService_nativeSetGameDefaultFrameRateOverride},
};
int register_android_server_app_GameManagerService(JNIEnv* env) {
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index 6f65965..bc05e77 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -88,6 +88,7 @@
namespace android {
static const bool ENABLE_POINTER_CHOREOGRAPHER = input_flags::enable_pointer_choreographer();
+static const bool ENABLE_INPUT_FILTER_RUST = input_flags::enable_input_filter_rust_impl();
// The exponent used to calculate the pointer speed scaling factor.
// The scaling factor is calculated as 2 ^ (speed * exponent),
@@ -2737,6 +2738,15 @@
im->setStylusPointerIconEnabled(enabled);
}
+static void nativeSetAccessibilityBounceKeysThreshold(JNIEnv* env, jobject nativeImplObj,
+ jint thresholdTimeMs) {
+ NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
+ if (ENABLE_INPUT_FILTER_RUST) {
+ im->getInputManager()->getInputFilter().setAccessibilityBounceKeysThreshold(
+ static_cast<nsecs_t>(thresholdTimeMs) * 1000000);
+ }
+}
+
// ----------------------------------------------------------------------------
static const JNINativeMethod gInputManagerMethods[] = {
@@ -2836,6 +2846,8 @@
(void*)nativeSetStylusButtonMotionEventsEnabled},
{"getMouseCursorPosition", "()[F", (void*)nativeGetMouseCursorPosition},
{"setStylusPointerIconEnabled", "(Z)V", (void*)nativeSetStylusPointerIconEnabled},
+ {"setAccessibilityBounceKeysThreshold", "(I)V",
+ (void*)nativeSetAccessibilityBounceKeysThreshold},
};
#define FIND_CLASS(var, className) \
diff --git a/services/permission/java/com/android/server/permission/access/permission/DevicePermissionPolicy.kt b/services/permission/java/com/android/server/permission/access/permission/DevicePermissionPolicy.kt
index ea5fb5d6..a0fb013 100644
--- a/services/permission/java/com/android/server/permission/access/permission/DevicePermissionPolicy.kt
+++ b/services/permission/java/com/android/server/permission/access/permission/DevicePermissionPolicy.kt
@@ -16,9 +16,7 @@
package com.android.server.permission.access.permission
-import android.Manifest
import android.permission.PermissionManager
-import android.permission.flags.Flags
import android.util.Slog
import com.android.modules.utils.BinaryXmlPullParser
import com.android.modules.utils.BinaryXmlSerializer
@@ -61,7 +59,7 @@
}
}
- fun MutateStateScope.removeInactiveDevicesPermission(activePersistentDeviceIds: Set<String>) {
+ fun MutateStateScope.trimDevicePermissionStates(deviceIds: Set<String>) {
newState.userStates.forEachIndexed { _, userId, userState ->
userState.appIdDevicePermissionFlags.forEachReversedIndexed { _, appId, _ ->
val appIdDevicePermissionFlags =
@@ -69,14 +67,11 @@
val devicePermissionFlags =
appIdDevicePermissionFlags.mutate(appId) ?: return@forEachReversedIndexed
- val removePersistentDeviceIds = mutableSetOf<String>()
- devicePermissionFlags.forEachIndexed { _, deviceId, _ ->
- if (!activePersistentDeviceIds.contains(deviceId)) {
- removePersistentDeviceIds.add(deviceId)
+ devicePermissionFlags.forEachReversedIndexed { _, deviceId, _ ->
+ if (deviceId !in deviceIds) {
+ devicePermissionFlags -= deviceId
}
}
-
- removePersistentDeviceIds.forEach { deviceId -> devicePermissionFlags -= deviceId }
}
}
}
@@ -122,6 +117,10 @@
resetRuntimePermissions(packageName, userId)
}
+ /**
+ * Reset permission states for all permissions requested by the given package, if no other
+ * package (sharing the App ID) request these permissions.
+ */
fun MutateStateScope.resetRuntimePermissions(packageName: String, userId: Int) {
// It's okay to skip resetting permissions for packages that are removed,
// because their states will be trimmed in onPackageRemoved()/onAppIdRemoved()
@@ -144,6 +143,7 @@
}
}
+ // Trims permission state for permissions not requested by the App ID anymore.
private fun MutateStateScope.trimPermissionStates(appId: Int) {
val requestedPermissions = MutableIndexedSet<String>()
forEachPackageInAppId(appId) {
@@ -245,10 +245,6 @@
flagMask: Int,
flagValues: Int
): Boolean {
- if (!isDeviceAwarePermission(permissionName)) {
- Slog.w(LOG_TAG, "$permissionName is not a device aware permission.")
- return false
- }
val oldFlags =
newState.userStates[userId]!!
.appIdDevicePermissionFlags[appId]
@@ -295,20 +291,8 @@
synchronized(listenersLock) { listeners = listeners + listener }
}
- private fun isDeviceAwarePermission(permissionName: String): Boolean =
- DEVICE_AWARE_PERMISSIONS.contains(permissionName)
-
companion object {
private val LOG_TAG = DevicePermissionPolicy::class.java.simpleName
-
- /** These permissions are supported for virtual devices. */
- // TODO: b/298661870 - Use new API to get the list of device aware permissions.
- val DEVICE_AWARE_PERMISSIONS =
- if (Flags.deviceAwarePermissionApisEnabled()) {
- setOf(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)
- } else {
- emptySet<String>()
- }
}
/** Listener for permission flags changes. */
diff --git a/services/permission/java/com/android/server/permission/access/permission/PermissionService.kt b/services/permission/java/com/android/server/permission/access/permission/PermissionService.kt
index 0f65494..f469ab5 100644
--- a/services/permission/java/com/android/server/permission/access/permission/PermissionService.kt
+++ b/services/permission/java/com/android/server/permission/access/permission/PermissionService.kt
@@ -1555,7 +1555,7 @@
deviceId == Context.DEVICE_ID_DEFAULT) {
with(policy) { getPermissionFlags(appId, userId, permissionName) }
} else {
- if (permissionName !in DevicePermissionPolicy.DEVICE_AWARE_PERMISSIONS) {
+ if (permissionName !in DEVICE_AWARE_PERMISSIONS) {
Slog.i(
LOG_TAG,
"$permissionName is not device aware permission, " +
@@ -1591,7 +1591,7 @@
deviceId == Context.DEVICE_ID_DEFAULT) {
with(policy) { setPermissionFlags(appId, userId, permissionName, flags) }
} else {
- if (permissionName !in DevicePermissionPolicy.DEVICE_AWARE_PERMISSIONS) {
+ if (permissionName !in DEVICE_AWARE_PERMISSIONS) {
Slog.i(
LOG_TAG,
"$permissionName is not device aware permission, " +
@@ -2314,20 +2314,19 @@
override fun onSystemReady() {
service.onSystemReady()
+
virtualDeviceManagerInternal =
LocalServices.getService(VirtualDeviceManagerInternal::class.java)
-
virtualDeviceManagerInternal?.allPersistentDeviceIds?.let { persistentDeviceIds ->
service.mutateState {
- with(devicePolicy) { removeInactiveDevicesPermission(persistentDeviceIds) }
+ with(devicePolicy) { trimDevicePermissionStates(persistentDeviceIds) }
}
}
-
- // trim permission states for the external devices, when they are removed.
virtualDeviceManagerInternal?.registerPersistentDeviceIdRemovedListener { persistentDeviceId
->
service.mutateState { with(devicePolicy) { onDeviceIdRemoved(persistentDeviceId) } }
}
+
permissionControllerManager =
PermissionControllerManager(context, PermissionThread.getHandler())
}
@@ -2862,5 +2861,14 @@
PackageManager.FLAG_PERMISSION_WHITELIST_UPGRADE or
PackageManager.FLAG_PERMISSION_WHITELIST_SYSTEM or
PackageManager.FLAG_PERMISSION_WHITELIST_INSTALLER
+
+ /** These permissions are supported for virtual devices. */
+ // TODO: b/298661870 - Use new API to get the list of device aware permissions.
+ val DEVICE_AWARE_PERMISSIONS =
+ if (Flags.deviceAwarePermissionApisEnabled()) {
+ setOf(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)
+ } else {
+ emptySet<String>()
+ }
}
}
diff --git a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionDefinitionsTest.kt b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionDefinitionsTest.kt
index 832136c..925dad8 100644
--- a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionDefinitionsTest.kt
+++ b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionDefinitionsTest.kt
@@ -38,7 +38,7 @@
* AppIdPermissionPolicyPermissionStatesTest because these concepts don't apply to onUserAdded().
*/
@RunWith(Parameterized::class)
-class AppIdPermissionPolicyPermissionDefinitionsTest : BaseAppIdPermissionPolicyTest() {
+class AppIdPermissionPolicyPermissionDefinitionsTest : BasePermissionPolicyTest() {
@Parameterized.Parameter(0) lateinit var action: Action
@Test
diff --git a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionResetTest.kt b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionResetTest.kt
index 0547719..1237095 100644
--- a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionResetTest.kt
+++ b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionResetTest.kt
@@ -29,7 +29,7 @@
* and resetRuntimePermissions() in AppIdPermissionPolicy
*/
@RunWith(Parameterized::class)
-class AppIdPermissionPolicyPermissionResetTest : BaseAppIdPermissionPolicyTest() {
+class AppIdPermissionPolicyPermissionResetTest : BasePermissionPolicyTest() {
@Parameterized.Parameter(0) lateinit var action: Action
@Test
diff --git a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionStatesTest.kt b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionStatesTest.kt
index c44b2c5..6b9c9c2 100644
--- a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionStatesTest.kt
+++ b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyPermissionStatesTest.kt
@@ -39,7 +39,7 @@
* states for onUserAdded(), onStorageVolumeAdded() and onPackageAdded() in AppIdPermissionPolicy
*/
@RunWith(Parameterized::class)
-class AppIdPermissionPolicyPermissionStatesTest : BaseAppIdPermissionPolicyTest() {
+class AppIdPermissionPolicyPermissionStatesTest : BasePermissionPolicyTest() {
@Parameterized.Parameter(0) lateinit var action: Action
@Before
diff --git a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyTest.kt b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyTest.kt
index e4e3368..cde46ab 100644
--- a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyTest.kt
+++ b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/AppIdPermissionPolicyTest.kt
@@ -30,7 +30,7 @@
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
-class AppIdPermissionPolicyTest : BaseAppIdPermissionPolicyTest() {
+class AppIdPermissionPolicyTest : BasePermissionPolicyTest() {
@Test
fun testOnAppIdRemoved_appIdIsRemoved_permissionFlagsCleared() {
val parsedPermission = mockParsedPermission(PERMISSION_NAME_0, PACKAGE_NAME_0)
diff --git a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/BaseAppIdPermissionPolicyTest.kt b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/BasePermissionPolicyTest.kt
similarity index 99%
rename from services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/BaseAppIdPermissionPolicyTest.kt
rename to services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/BasePermissionPolicyTest.kt
index 316f338..7b3f216 100644
--- a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/BaseAppIdPermissionPolicyTest.kt
+++ b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/BasePermissionPolicyTest.kt
@@ -53,7 +53,7 @@
* Mocking unit test for AppIdPermissionPolicy.
*/
@RunWith(AndroidJUnit4::class)
-abstract class BaseAppIdPermissionPolicyTest {
+abstract class BasePermissionPolicyTest {
protected lateinit var oldState: MutableAccessState
protected lateinit var newState: MutableAccessState
diff --git a/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/DevicePermissionPolicyTest.kt b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/DevicePermissionPolicyTest.kt
new file mode 100644
index 0000000..996dd9d
--- /dev/null
+++ b/services/tests/PermissionServiceMockingTests/src/com/android/server/permission/test/DevicePermissionPolicyTest.kt
@@ -0,0 +1,282 @@
+/*
+ * Copyright (C) 2023 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.permission.test
+
+import com.android.server.permission.access.GetStateScope
+import com.android.server.permission.access.MutableAccessState
+import com.android.server.permission.access.MutableDevicePermissionFlags
+import com.android.server.permission.access.immutable.* // ktlint-disable no-wildcard-imports
+import com.android.server.permission.access.permission.DevicePermissionPolicy
+import com.android.server.permission.access.permission.PermissionFlags
+import com.android.server.testutils.mock
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.mockito.Mockito.times
+import org.mockito.Mockito.verify
+
+/**
+ * This class tests permissions for external devices, we have separate policy to
+ * manage external device permissions.
+ */
+class DevicePermissionPolicyTest : BasePermissionPolicyTest() {
+ private val devicePermissionPolicy = DevicePermissionPolicy()
+
+ @Test
+ fun testOnAppIdRemoved_clearPermissionFlags() {
+ val packageState = mockPackageState(
+ APP_ID_1,
+ mockAndroidPackage(PACKAGE_NAME_1, requestedPermissions = setOf(PERMISSION_NAME_0))
+ )
+ addPackageState(packageState)
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, PermissionFlags.RUNTIME_GRANTED
+ )
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+
+ mutateState {
+ with(devicePermissionPolicy) {
+ onAppIdRemoved(APP_ID_1)
+ }
+ }
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0))
+ .isEqualTo(0)
+ }
+
+ @Test
+ fun testOnDeviceIdRemoved_clearPermissionFlags() {
+ val requestingPackageState = mockPackageState(
+ APP_ID_1,
+ mockAndroidPackage(PACKAGE_NAME_1, requestedPermissions = setOf(PERMISSION_NAME_0))
+ )
+ addPackageState(requestingPackageState)
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, PermissionFlags.RUNTIME_GRANTED
+ )
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_2, USER_ID_0, PERMISSION_NAME_0, PermissionFlags.RUNTIME_GRANTED
+ )
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_2, USER_ID_0, PERMISSION_NAME_0, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+
+ mutateState {
+ with(devicePermissionPolicy) {
+ onDeviceIdRemoved(DEVICE_ID_1)
+ }
+ }
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0))
+ .isEqualTo(0)
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_2, USER_ID_0, PERMISSION_NAME_0))
+ .isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+ }
+
+ @Test
+ fun testRemoveInactiveDevicesPermission_clearPermissionFlags() {
+ val requestingPackageState = mockPackageState(
+ APP_ID_1,
+ mockAndroidPackage(PACKAGE_NAME_1, requestedPermissions = setOf(PERMISSION_NAME_0))
+ )
+ addPackageState(requestingPackageState)
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, PermissionFlags.RUNTIME_GRANTED
+ )
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_2, USER_ID_0, PERMISSION_NAME_0, PermissionFlags.RUNTIME_GRANTED
+ )
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_2, USER_ID_0, PERMISSION_NAME_0, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+
+ mutateState {
+ with(devicePermissionPolicy) {
+ trimDevicePermissionStates(setOf(DEVICE_ID_2))
+ }
+ }
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0))
+ .isEqualTo(0)
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_2, USER_ID_0, PERMISSION_NAME_0))
+ .isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+ }
+
+ @Test
+ fun testOnStateMutated_notEmpty_isCalledForEachListener() {
+ val mockListener =
+ mock<DevicePermissionPolicy.OnDevicePermissionFlagsChangedListener> {}
+ devicePermissionPolicy.addOnPermissionFlagsChangedListener(mockListener)
+
+ GetStateScope(oldState).apply {
+ with(devicePermissionPolicy) {
+ onStateMutated()
+ }
+ }
+
+ verify(mockListener, times(1)).onStateMutated()
+ }
+
+ @Test
+ fun testOnStorageVolumeMounted_trimsPermissionsNotRequestAnymore() {
+ val packageState = mockPackageState(
+ APP_ID_1,
+ mockAndroidPackage(
+ PACKAGE_NAME_1, requestedPermissions = setOf(PERMISSION_NAME_1, PERMISSION_NAME_0)
+ )
+ )
+ addPackageState(packageState)
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1, PermissionFlags.RUNTIME_GRANTED
+ )
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, PermissionFlags.RUNTIME_GRANTED
+ )
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+
+ val installedPackageState = mockPackageState(
+ APP_ID_1,
+ mockAndroidPackage(PACKAGE_NAME_1, requestedPermissions = setOf(PERMISSION_NAME_1))
+ )
+ addPackageState(installedPackageState)
+
+ mutateState {
+ with(devicePermissionPolicy) {
+ onStorageVolumeMounted(null, listOf(PACKAGE_NAME_1), false)
+ }
+ }
+
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1))
+ .isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0))
+ .isEqualTo(0)
+ }
+
+
+ @Test
+ fun testResetRuntimePermissions_trimsPermissionStates() {
+ val packageState = mockPackageState(
+ APP_ID_1,
+ mockAndroidPackage(PACKAGE_NAME_1, requestedPermissions = setOf(PERMISSION_NAME_1))
+ )
+ addPackageState(packageState)
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1, PermissionFlags.RUNTIME_GRANTED
+ )
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+
+ mutateState {
+ with(devicePermissionPolicy) {
+ resetRuntimePermissions(PACKAGE_NAME_1, USER_ID_0)
+ }
+ }
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1))
+ .isEqualTo(0)
+ }
+
+ @Test
+ fun testResetRuntimePermissions_keepsPermissionStates() {
+ val packageState = mockPackageState(
+ APP_ID_1,
+ mockAndroidPackage(
+ PACKAGE_NAME_1,
+ requestedPermissions = setOf(PERMISSION_NAME_1, PERMISSION_NAME_0)
+ )
+ )
+ val packageState2 = mockPackageState(
+ APP_ID_1,
+ mockAndroidPackage(PACKAGE_NAME_2, requestedPermissions = setOf(PERMISSION_NAME_0))
+ )
+ addPackageState(packageState)
+ addPackageState(packageState2)
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1, PermissionFlags.RUNTIME_GRANTED
+ )
+ setPermissionFlags(
+ APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, PermissionFlags.RUNTIME_GRANTED
+ )
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+ assertThat(
+ getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0, oldState)
+ ).isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+
+ mutateState {
+ with(devicePermissionPolicy) {
+ resetRuntimePermissions(PACKAGE_NAME_1, USER_ID_0)
+ }
+ }
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_1))
+ .isEqualTo(0)
+ assertThat(getPermissionFlags(APP_ID_1, DEVICE_ID_1, USER_ID_0, PERMISSION_NAME_0))
+ .isEqualTo(PermissionFlags.RUNTIME_GRANTED)
+ }
+
+ private fun getPermissionFlags(
+ appId: Int,
+ deviceId: String,
+ userId: Int,
+ permissionName: String,
+ state: MutableAccessState = newState
+ ): Int = state.userStates[userId]
+ ?.appIdDevicePermissionFlags
+ ?.get(appId)
+ ?.get(deviceId)
+ ?.getWithDefault(permissionName, 0)
+ ?: 0
+
+
+ private fun setPermissionFlags(
+ appId: Int,
+ deviceId: String,
+ userId: Int,
+ permissionName: String,
+ newFlags: Int,
+ state: MutableAccessState = oldState
+ ) {
+ val appIdDevicePermissionFlags =
+ state.mutateUserState(userId)!!.mutateAppIdDevicePermissionFlags()
+ val devicePermissionFlags =
+ appIdDevicePermissionFlags.mutateOrPut(appId) { MutableDevicePermissionFlags() }
+ val permissionFlags =
+ devicePermissionFlags.mutateOrPut(deviceId) { MutableIndexedMap() }
+ permissionFlags.putWithDefault(permissionName, newFlags, 0)
+ if (permissionFlags.isEmpty()) {
+ devicePermissionFlags -= deviceId
+ if (devicePermissionFlags.isEmpty()) {
+ appIdDevicePermissionFlags -= appId
+ }
+ }
+ }
+
+ companion object {
+ private const val DEVICE_ID_1 = "cdm:1"
+ private const val DEVICE_ID_2 = "cdm:2"
+ }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java b/services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java
index 6906dec..76d4d55 100644
--- a/services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java
+++ b/services/tests/mockingservicestests/src/com/android/server/app/GameManagerServiceTests.java
@@ -18,7 +18,10 @@
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
import static com.android.server.app.GameManagerService.CANCEL_GAME_LOADING_MODE;
+import static com.android.server.app.GameManagerService.Injector;
import static com.android.server.app.GameManagerService.LOADING_BOOST_MAX_DURATION;
+import static com.android.server.app.GameManagerService.PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED;
+import static com.android.server.app.GameManagerService.PROPERTY_RO_SURFACEFLINGER_GAME_DEFAULT_FRAME_RATE;
import static com.android.server.app.GameManagerService.SET_GAME_STATE;
import static com.android.server.app.GameManagerService.WRITE_DELAY_MILLIS;
import static com.android.server.app.GameManagerService.WRITE_GAME_MODE_INTERVENTION_LIST_FILE;
@@ -33,6 +36,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.any;
@@ -72,9 +76,12 @@
import android.os.PowerManagerInternal;
import android.os.RemoteException;
import android.os.UserManager;
+import android.os.test.FakePermissionEnforcer;
import android.os.test.TestLooper;
import android.platform.test.annotations.Presubmit;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.DeviceConfig;
+import android.server.app.Flags;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -85,6 +92,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -108,6 +116,7 @@
@Presubmit
public class GameManagerServiceTests {
@Mock MockContext mMockContext;
+ @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String TAG = "GameManagerServiceTests";
private static final String PACKAGE_NAME_INVALID = "com.android.app";
private static final int USER_ID_1 = 1001;
@@ -126,6 +135,11 @@
private UserManager mMockUserManager;
private BroadcastReceiver mShutDownActionReceiver;
+ private FakePermissionEnforcer mFakePermissionEnforcer = new FakePermissionEnforcer();
+
+ @Mock
+ private GameManagerServiceSystemPropertiesWrapper mSysPropsMock;
+
@Captor
ArgumentCaptor<IBinder.DeathRecipient> mDeathRecipientCaptor;
@@ -193,6 +207,8 @@
switch (name) {
case Context.USER_SERVICE:
return mMockUserManager;
+ case Context.PERMISSION_ENFORCER_SERVICE:
+ return mFakePermissionEnforcer;
}
throw new UnsupportedOperationException("Couldn't find system service: " + name);
}
@@ -222,6 +238,8 @@
when(mMockPackageManager.getPackageUidAsUser(mPackageName, USER_ID_1)).thenReturn(
DEFAULT_PACKAGE_UID);
LocalServices.addService(PowerManagerInternal.class, mMockPowerManager);
+
+ mSetFlagsRule.enableFlags(Flags.FLAG_GAME_DEFAULT_FRAME_RATE);
}
private void mockAppCategory(String packageName, @ApplicationInfo.Category int category)
@@ -1695,9 +1713,8 @@
mockModifyGameModeGranted();
final Context context = InstrumentationRegistry.getContext();
GameManagerService gameManagerService =
- new GameManagerService(mMockContext,
- mTestLooper.getLooper(),
- context.getFilesDir());
+ new GameManagerService(mMockContext, mTestLooper.getLooper(), context.getFilesDir(),
+ new Injector());
startUser(gameManagerService, USER_ID_1);
startUser(gameManagerService, USER_ID_2);
@@ -1786,7 +1803,7 @@
mockDeviceConfigBattery();
final Context context = InstrumentationRegistry.getContext();
GameManagerService gameManagerService = new GameManagerService(mMockContext,
- mTestLooper.getLooper(), context.getFilesDir());
+ mTestLooper.getLooper(), context.getFilesDir(), new Injector());
startUser(gameManagerService, USER_ID_1);
startUser(gameManagerService, USER_ID_2);
gameManagerService.setGameMode(mPackageName, GameManager.GAME_MODE_BATTERY, USER_ID_1);
@@ -1962,7 +1979,7 @@
assertTrue(
gameManagerService.mHandler.hasEqualMessages(WRITE_GAME_MODE_INTERVENTION_LIST_FILE,
USER_ID_1));
- Mockito.verify(gameManagerService).setOverrideFrameRate(
+ Mockito.verify(gameManagerService).setGameModeFrameRateOverride(
ArgumentMatchers.eq(DEFAULT_PACKAGE_UID),
ArgumentMatchers.eq(60.0f));
checkFps(gameManagerService, GameManager.GAME_MODE_CUSTOM, 60);
@@ -2035,7 +2052,7 @@
mTestLooper.getLooper()));
startUser(gameManagerService, USER_ID_1);
gameManagerService.setGameMode(mPackageName, GameManager.GAME_MODE_PERFORMANCE, USER_ID_1);
- Mockito.verify(gameManagerService).setOverrideFrameRate(
+ Mockito.verify(gameManagerService).setGameModeFrameRateOverride(
ArgumentMatchers.eq(DEFAULT_PACKAGE_UID),
ArgumentMatchers.eq(90.0f));
checkFps(gameManagerService, GameManager.GAME_MODE_PERFORMANCE, 90);
@@ -2044,7 +2061,7 @@
when(DeviceConfig.getProperty(anyString(), anyString()))
.thenReturn(configStringAfter);
gameManagerService.updateConfigsForUser(USER_ID_1, false, mPackageName);
- Mockito.verify(gameManagerService).setOverrideFrameRate(
+ Mockito.verify(gameManagerService).setGameModeFrameRateOverride(
ArgumentMatchers.eq(DEFAULT_PACKAGE_UID),
ArgumentMatchers.eq(0.0f));
}
@@ -2061,14 +2078,14 @@
mTestLooper.getLooper()));
startUser(gameManagerService, USER_ID_1);
gameManagerService.setGameMode(mPackageName, GameManager.GAME_MODE_PERFORMANCE, USER_ID_1);
- Mockito.verify(gameManagerService).setOverrideFrameRate(
+ Mockito.verify(gameManagerService).setGameModeFrameRateOverride(
ArgumentMatchers.eq(DEFAULT_PACKAGE_UID),
ArgumentMatchers.eq(90.0f));
checkFps(gameManagerService, GameManager.GAME_MODE_PERFORMANCE, 90);
mockInterventionsDisabledNoOptInFromXml();
gameManagerService.updateConfigsForUser(USER_ID_1, false, mPackageName);
- Mockito.verify(gameManagerService).setOverrideFrameRate(
+ Mockito.verify(gameManagerService).setGameModeFrameRateOverride(
ArgumentMatchers.eq(DEFAULT_PACKAGE_UID),
ArgumentMatchers.eq(0.0f));
checkFps(gameManagerService, GameManager.GAME_MODE_PERFORMANCE, 0);
@@ -2087,14 +2104,14 @@
startUser(gameManagerService, USER_ID_1);
gameManagerService.setGameMode(mPackageName, GameManager.GAME_MODE_PERFORMANCE, USER_ID_1);
- Mockito.verify(gameManagerService).setOverrideFrameRate(
+ Mockito.verify(gameManagerService).setGameModeFrameRateOverride(
ArgumentMatchers.eq(DEFAULT_PACKAGE_UID),
ArgumentMatchers.eq(90.0f));
checkFps(gameManagerService, GameManager.GAME_MODE_PERFORMANCE, 90);
mockInterventionsEnabledAllOptInFromXml();
gameManagerService.updateConfigsForUser(USER_ID_1, false, mPackageName);
- Mockito.verify(gameManagerService).setOverrideFrameRate(
+ Mockito.verify(gameManagerService).setGameModeFrameRateOverride(
ArgumentMatchers.eq(DEFAULT_PACKAGE_UID),
ArgumentMatchers.eq(0.0f));
}
@@ -2390,4 +2407,138 @@
DEFAULT_PACKAGE_UID, ActivityManager.PROCESS_STATE_TRANSIENT_BACKGROUND, 0, 0);
verify(mMockPowerManager, times(0)).setPowerMode(Mode.GAME, false);
}
+
+ @Test
+ public void testGameDefaultFrameRate_FlagOn() throws Exception {
+ mFakePermissionEnforcer.grant(Manifest.permission.MANAGE_GAME_MODE);
+
+ GameManagerService gameManagerService = Mockito.spy(
+ new GameManagerService(mMockContext, mTestLooper.getLooper(),
+ InstrumentationRegistry.getContext().getFilesDir(),
+ new Injector(){
+ @Override
+ public GameManagerServiceSystemPropertiesWrapper
+ createSystemPropertiesWrapper() {
+ return mSysPropsMock;
+ }
+ }));
+
+ // Set up a game in the foreground.
+ String[] packages = {mPackageName};
+ when(mMockPackageManager.getPackagesForUid(DEFAULT_PACKAGE_UID)).thenReturn(packages);
+ gameManagerService.mUidObserver.onUidStateChanged(
+ DEFAULT_PACKAGE_UID, ActivityManager.PROCESS_STATE_TOP, 0, 0);
+
+ // Toggle game default frame rate on.
+ when(mSysPropsMock.getInt(
+ ArgumentMatchers.eq(PROPERTY_RO_SURFACEFLINGER_GAME_DEFAULT_FRAME_RATE),
+ anyInt())).thenReturn(60);
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED),
+ ArgumentMatchers.eq(true))).thenReturn(true);
+ gameManagerService.toggleGameDefaultFrameRate(true);
+
+ // Verify that:
+ // 1) The system property is set correctly
+ // 2) setDefaultFrameRateOverride is called with correct arguments
+ Mockito.verify(mSysPropsMock).set(
+ ArgumentMatchers.eq(PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED),
+ ArgumentMatchers.eq("true"));
+ Mockito.verify(gameManagerService, times(1))
+ .setGameDefaultFrameRateOverride(ArgumentMatchers.eq(DEFAULT_PACKAGE_UID),
+ ArgumentMatchers.eq(60.0f));
+
+ // Adding another game to the foreground.
+ String anotherGamePkg = "another.game";
+ String[] packages2 = {anotherGamePkg};
+ mockAppCategory(anotherGamePkg, ApplicationInfo.CATEGORY_GAME);
+ int somePackageId = DEFAULT_PACKAGE_UID + 1;
+ when(mMockPackageManager.getPackagesForUid(somePackageId)).thenReturn(packages2);
+
+ gameManagerService.mUidObserver.onUidStateChanged(
+ somePackageId, ActivityManager.PROCESS_STATE_TOP, 0, 0);
+
+ // Toggle game default frame rate off.
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED),
+ ArgumentMatchers.eq(true))).thenReturn(false);
+ gameManagerService.toggleGameDefaultFrameRate(false);
+
+ // Verify that:
+ // 1) The system property is set correctly
+ // 2) setDefaultFrameRateOverride is called with correct arguments
+ Mockito.verify(mSysPropsMock).set(
+ ArgumentMatchers.eq(PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED),
+ ArgumentMatchers.eq("false"));
+ Mockito.verify(gameManagerService).setGameDefaultFrameRateOverride(
+ ArgumentMatchers.eq(DEFAULT_PACKAGE_UID), ArgumentMatchers.eq(0.0f));
+ Mockito.verify(gameManagerService).setGameDefaultFrameRateOverride(
+ ArgumentMatchers.eq(somePackageId), ArgumentMatchers.eq(0.0f));
+ }
+
+ @Test
+ public void testGameDefaultFrameRate_FlagOff() throws Exception {
+ mSetFlagsRule.disableFlags(Flags.FLAG_GAME_DEFAULT_FRAME_RATE);
+ mFakePermissionEnforcer.grant(Manifest.permission.MANAGE_GAME_MODE);
+
+ GameManagerService gameManagerService = Mockito.spy(
+ new GameManagerService(mMockContext, mTestLooper.getLooper(),
+ InstrumentationRegistry.getContext().getFilesDir(),
+ new Injector(){
+ @Override
+ public GameManagerServiceSystemPropertiesWrapper
+ createSystemPropertiesWrapper() {
+ return mSysPropsMock;
+ }
+ }));
+
+ // Set up a game in the foreground.
+ String[] packages = {mPackageName};
+ when(mMockPackageManager.getPackagesForUid(DEFAULT_PACKAGE_UID)).thenReturn(packages);
+ gameManagerService.mUidObserver.onUidStateChanged(
+ DEFAULT_PACKAGE_UID, ActivityManager.PROCESS_STATE_TOP, 0, 0);
+
+ // Toggle game default frame rate on.
+ when(mSysPropsMock.getInt(
+ ArgumentMatchers.eq(PROPERTY_RO_SURFACEFLINGER_GAME_DEFAULT_FRAME_RATE),
+ anyInt())).thenReturn(60);
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED),
+ ArgumentMatchers.eq(true))).thenReturn(true);
+
+ gameManagerService.toggleGameDefaultFrameRate(true);
+
+ // Verify that:
+ // 1) System property is never set
+ // 2) setGameDefaultFrameRateOverride() should never be called if the flag is disabled.
+ Mockito.verify(mSysPropsMock, never()).set(
+ ArgumentMatchers.eq(PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED),
+ anyString());
+ Mockito.verify(gameManagerService, never())
+ .setGameDefaultFrameRateOverride(anyInt(), anyFloat());
+
+ // Toggle game default frame rate off.
+ String anotherGamePkg = "another.game";
+ String[] packages2 = {anotherGamePkg};
+ mockAppCategory(anotherGamePkg, ApplicationInfo.CATEGORY_GAME);
+ int somePackageId = DEFAULT_PACKAGE_UID + 1;
+ when(mMockPackageManager.getPackagesForUid(somePackageId)).thenReturn(packages2);
+ gameManagerService.mUidObserver.onUidStateChanged(
+ somePackageId, ActivityManager.PROCESS_STATE_TOP, 0, 0);
+ gameManagerService.mUidObserver.onUidStateChanged(
+ somePackageId, ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE, 0, 0);
+ when(mSysPropsMock.getBoolean(
+ ArgumentMatchers.eq(PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED),
+ ArgumentMatchers.eq(true))).thenReturn(false);
+
+ gameManagerService.toggleGameDefaultFrameRate(false);
+ // Verify that:
+ // 1) System property is never set
+ // 2) setGameDefaultFrameRateOverride() should never be called if the flag is disabled.
+ Mockito.verify(mSysPropsMock, never()).set(
+ ArgumentMatchers.eq(PROPERTY_PERSISTENT_GFX_GAME_DEFAULT_FRAME_RATE_ENABLED),
+ anyString());
+ Mockito.verify(gameManagerService, never())
+ .setGameDefaultFrameRateOverride(anyInt(), anyFloat());
+ }
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 8bb11a4..4a537df 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -209,6 +209,7 @@
import android.os.UserManager;
import android.os.WorkSource;
import android.permission.PermissionManager;
+import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.DeviceConfig;
import android.provider.MediaStore;
@@ -620,8 +621,10 @@
});
// TODO (b/291907312): remove feature flag
+ mSetFlagsRule.enableFlags(android.app.Flags.FLAG_VISIT_RISKY_URIS);
+ mSetFlagsRule.disableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR);
mSetFlagsRule.disableFlags(Flags.FLAG_REFACTOR_ATTENTION_HELPER,
- Flags.FLAG_POLITE_NOTIFICATIONS);
+ Flags.FLAG_POLITE_NOTIFICATIONS, android.app.Flags.FLAG_MODES_API);
initNMS();
}
@@ -971,6 +974,12 @@
return new NotificationRecord(mContext, sbn, channel);
}
+ private NotificationRecord generateNotificationRecord(NotificationChannel channel,
+ long postTime) {
+ final StatusBarNotification sbn = generateSbn(PKG, mUid, postTime, 0);
+ return new NotificationRecord(mContext, sbn, channel);
+ }
+
private NotificationRecord generateNotificationRecord(NotificationChannel channel, int userId) {
return generateNotificationRecord(channel, 1, userId);
}
@@ -6265,15 +6274,21 @@
verify(visitor, times(1)).accept(eq(personIcon3.getUri()));
}
+ private PendingIntent getPendingIntentWithUri(Uri uri) {
+ return PendingIntent.getActivity(mContext, 0,
+ new Intent("action", uri),
+ PendingIntent.FLAG_IMMUTABLE);
+ }
+
@Test
- public void testVisitUris_callStyle() {
+ public void testVisitUris_callStyle_ongoingCall() {
Icon personIcon = Icon.createWithContentUri("content://media/person");
Icon verificationIcon = Icon.createWithContentUri("content://media/verification");
Person callingPerson = new Person.Builder().setName("Someone")
.setIcon(personIcon)
.build();
- PendingIntent hangUpIntent = PendingIntent.getActivity(mContext, 0, new Intent(),
- PendingIntent.FLAG_IMMUTABLE);
+ Uri hangUpUri = Uri.parse("content://intent/hangup");
+ PendingIntent hangUpIntent = getPendingIntentWithUri(hangUpUri);
Notification n = new Notification.Builder(mContext, "a")
.setStyle(Notification.CallStyle.forOngoingCall(callingPerson, hangUpIntent)
.setVerificationIcon(verificationIcon))
@@ -6286,6 +6301,35 @@
verify(visitor, times(1)).accept(eq(personIcon.getUri()));
verify(visitor, times(1)).accept(eq(verificationIcon.getUri()));
+ verify(visitor, times(1)).accept(eq(hangUpUri));
+ }
+
+ @Test
+ public void testVisitUris_callStyle_incomingCall() {
+ Icon personIcon = Icon.createWithContentUri("content://media/person");
+ Icon verificationIcon = Icon.createWithContentUri("content://media/verification");
+ Person callingPerson = new Person.Builder().setName("Someone")
+ .setIcon(personIcon)
+ .build();
+ Uri answerUri = Uri.parse("content://intent/answer");
+ PendingIntent answerIntent = getPendingIntentWithUri(answerUri);
+ Uri declineUri = Uri.parse("content://intent/decline");
+ PendingIntent declineIntent = getPendingIntentWithUri(declineUri);
+ Notification n = new Notification.Builder(mContext, "a")
+ .setStyle(Notification.CallStyle.forIncomingCall(callingPerson, declineIntent,
+ answerIntent)
+ .setVerificationIcon(verificationIcon))
+ .setContentTitle("Calling...")
+ .setSmallIcon(android.R.drawable.sym_def_app_icon)
+ .build();
+
+ Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
+ n.visitUris(visitor);
+
+ verify(visitor, times(1)).accept(eq(personIcon.getUri()));
+ verify(visitor, times(1)).accept(eq(verificationIcon.getUri()));
+ verify(visitor, times(1)).accept(eq(answerIntent.getIntent().getData()));
+ verify(visitor, times(1)).accept(eq(declineUri));
}
@Test
@@ -6337,20 +6381,74 @@
public void testVisitUris_wearableExtender() {
Icon actionIcon = Icon.createWithContentUri("content://media/action");
Icon wearActionIcon = Icon.createWithContentUri("content://media/wearAction");
- PendingIntent intent = PendingIntent.getActivity(mContext, 0, new Intent(),
- PendingIntent.FLAG_IMMUTABLE);
+ Uri displayIntentUri = Uri.parse("content://intent/display");
+ PendingIntent displayIntent = getPendingIntentWithUri(displayIntentUri);
+ Uri actionIntentUri = Uri.parse("content://intent/action");
+ PendingIntent actionIntent = getPendingIntentWithUri(actionIntentUri);
+ Uri wearActionIntentUri = Uri.parse("content://intent/wear");
+ PendingIntent wearActionIntent = getPendingIntentWithUri(wearActionIntentUri);
Notification n = new Notification.Builder(mContext, "a")
.setSmallIcon(android.R.drawable.sym_def_app_icon)
- .addAction(new Notification.Action.Builder(actionIcon, "Hey!", intent).build())
- .extend(new Notification.WearableExtender().addAction(
- new Notification.Action.Builder(wearActionIcon, "Wear!", intent).build()))
+ .addAction(
+ new Notification.Action.Builder(actionIcon, "Hey!", actionIntent).build())
+ .extend(new Notification.WearableExtender()
+ .setDisplayIntent(displayIntent)
+ .addAction(new Notification.Action.Builder(wearActionIcon, "Wear!",
+ wearActionIntent)
+ .build()))
.build();
Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
n.visitUris(visitor);
verify(visitor).accept(eq(actionIcon.getUri()));
+ verify(visitor, times(1)).accept(eq(actionIntentUri));
verify(visitor).accept(eq(wearActionIcon.getUri()));
+ verify(visitor, times(1)).accept(eq(wearActionIntentUri));
+ }
+
+ @Test
+ public void testVisitUris_tvExtender() {
+ Uri contentIntentUri = Uri.parse("content://intent/content");
+ PendingIntent contentIntent = getPendingIntentWithUri(contentIntentUri);
+ Uri deleteIntentUri = Uri.parse("content://intent/delete");
+ PendingIntent deleteIntent = getPendingIntentWithUri(deleteIntentUri);
+ Notification n = new Notification.Builder(mContext, "a")
+ .extend(
+ new Notification.TvExtender()
+ .setContentIntent(contentIntent)
+ .setDeleteIntent(deleteIntent))
+ .build();
+
+ Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
+ n.visitUris(visitor);
+
+ verify(visitor, times(1)).accept(eq(contentIntentUri));
+ verify(visitor, times(1)).accept(eq(deleteIntentUri));
+ }
+
+ @Test
+ public void testVisitUris_carExtender() {
+ final String testParticipant = "testParticipant";
+ Uri readPendingIntentUri = Uri.parse("content://intent/read");
+ PendingIntent readPendingIntent = getPendingIntentWithUri(readPendingIntentUri);
+ Uri replyPendingIntentUri = Uri.parse("content://intent/reply");
+ PendingIntent replyPendingIntent = getPendingIntentWithUri(replyPendingIntentUri);
+ final RemoteInput testRemoteInput = new RemoteInput.Builder("key").build();
+
+ Notification n = new Notification.Builder(mContext, "a")
+ .extend(new Notification.CarExtender().setUnreadConversation(
+ new Notification.CarExtender.Builder(testParticipant)
+ .setReadPendingIntent(readPendingIntent)
+ .setReplyAction(replyPendingIntent, testRemoteInput)
+ .build()))
+ .build();
+
+ Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
+ n.visitUris(visitor);
+
+ verify(visitor, times(1)).accept(eq(readPendingIntentUri));
+ verify(visitor, times(1)).accept(eq(replyPendingIntentUri));
}
@Test
@@ -8978,6 +9076,42 @@
}
@Test
+ @EnableFlags(android.app.Flags.FLAG_MODES_API)
+ public void testAddAutomaticZenRule_typeManagedCanBeUsedByDeviceOwners() throws Exception {
+ mService.setCallerIsNormalPackage();
+ mService.setZenHelper(mock(ZenModeHelper.class));
+ when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
+ .thenReturn(true);
+
+ AutomaticZenRule rule = new AutomaticZenRule.Builder("rule", Uri.parse("uri"))
+ .setType(AutomaticZenRule.TYPE_MANAGED)
+ .setOwner(new ComponentName("pkg", "cls"))
+ .build();
+ when(mDevicePolicyManager.isActiveDeviceOwner(anyInt())).thenReturn(true);
+
+ mBinderService.addAutomaticZenRule(rule, "pkg");
+ // No exception!
+ }
+
+ @Test
+ @EnableFlags(android.app.Flags.FLAG_MODES_API)
+ public void testAddAutomaticZenRule_typeManagedCannotBeUsedByRegularApps() throws Exception {
+ mService.setCallerIsNormalPackage();
+ mService.setZenHelper(mock(ZenModeHelper.class));
+ when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
+ .thenReturn(true);
+
+ AutomaticZenRule rule = new AutomaticZenRule.Builder("rule", Uri.parse("uri"))
+ .setType(AutomaticZenRule.TYPE_MANAGED)
+ .setOwner(new ComponentName("pkg", "cls"))
+ .build();
+ when(mDevicePolicyManager.isActiveDeviceOwner(anyInt())).thenReturn(false);
+
+ assertThrows(IllegalArgumentException.class,
+ () -> mBinderService.addAutomaticZenRule(rule, "pkg"));
+ }
+
+ @Test
public void onZenModeChanged_sendsBroadcasts() throws Exception {
when(mAmi.getCurrentUserId()).thenReturn(100);
when(mUmInternal.getProfileIds(eq(100), anyBoolean())).thenReturn(new int[]{100, 101, 102});
@@ -13312,6 +13446,175 @@
assertThat(n.flags & FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY).isEqualTo(0);
}
+ @Test
+ public void cancelNotificationsFromListener_rapidClear_oldNew_cancelOne()
+ throws RemoteException {
+ mSetFlagsRule.enableFlags(android.view.contentprotection.flags.Flags
+ .FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED);
+
+ // Create recent notification.
+ final NotificationRecord nr1 = generateNotificationRecord(mTestNotificationChannel,
+ System.currentTimeMillis());
+ mService.addNotification(nr1);
+
+ // Create old notification.
+ final NotificationRecord nr2 = generateNotificationRecord(mTestNotificationChannel, 0);
+ mService.addNotification(nr2);
+
+ // Cancel specific notifications via listener.
+ String[] keys = {nr1.getSbn().getKey(), nr2.getSbn().getKey()};
+ mService.getBinderService().cancelNotificationsFromListener(null, keys);
+ waitForIdle();
+
+ // Notifications should not be active anymore.
+ StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG);
+ assertThat(notifications).isEmpty();
+ assertEquals(0, mService.getNotificationRecordCount());
+ // Ensure cancel event is logged.
+ verify(mAppOpsManager).noteOpNoThrow(
+ AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER, mUid, PKG, null, null);
+ }
+
+ @Test
+ public void cancelNotificationsFromListener_rapidClear_old_cancelOne() throws RemoteException {
+ mSetFlagsRule.enableFlags(android.view.contentprotection.flags.Flags
+ .FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED);
+
+ // Create old notifications.
+ final NotificationRecord nr1 = generateNotificationRecord(mTestNotificationChannel, 0);
+ mService.addNotification(nr1);
+
+ final NotificationRecord nr2 = generateNotificationRecord(mTestNotificationChannel, 0);
+ mService.addNotification(nr2);
+
+ // Cancel specific notifications via listener.
+ String[] keys = {nr1.getSbn().getKey(), nr2.getSbn().getKey()};
+ mService.getBinderService().cancelNotificationsFromListener(null, keys);
+ waitForIdle();
+
+ // Notifications should not be active anymore.
+ StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG);
+ assertThat(notifications).isEmpty();
+ assertEquals(0, mService.getNotificationRecordCount());
+ // Ensure cancel event is not logged.
+ verify(mAppOpsManager, never()).noteOpNoThrow(
+ eq(AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER), anyInt(), anyString(),
+ any(), any());
+ }
+
+ @Test
+ public void cancelNotificationsFromListener_rapidClear_oldNew_cancelOne_flagDisabled()
+ throws RemoteException {
+ mSetFlagsRule.disableFlags(android.view.contentprotection.flags.Flags
+ .FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED);
+
+ // Create recent notification.
+ final NotificationRecord nr1 = generateNotificationRecord(mTestNotificationChannel,
+ System.currentTimeMillis());
+ mService.addNotification(nr1);
+
+ // Create old notification.
+ final NotificationRecord nr2 = generateNotificationRecord(mTestNotificationChannel, 0);
+ mService.addNotification(nr2);
+
+ // Cancel specific notifications via listener.
+ String[] keys = {nr1.getSbn().getKey(), nr2.getSbn().getKey()};
+ mService.getBinderService().cancelNotificationsFromListener(null, keys);
+ waitForIdle();
+
+ // Notifications should not be active anymore.
+ StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG);
+ assertThat(notifications).isEmpty();
+ assertEquals(0, mService.getNotificationRecordCount());
+ // Ensure cancel event is not logged due to flag being disabled.
+ verify(mAppOpsManager, never()).noteOpNoThrow(
+ eq(AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER), anyInt(), anyString(),
+ any(), any());
+ }
+
+ @Test
+ public void cancelNotificationsFromListener_rapidClear_oldNew_cancelAll()
+ throws RemoteException {
+ mSetFlagsRule.enableFlags(android.view.contentprotection.flags.Flags
+ .FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED);
+
+ // Create recent notification.
+ final NotificationRecord nr1 = generateNotificationRecord(mTestNotificationChannel,
+ System.currentTimeMillis());
+ mService.addNotification(nr1);
+
+ // Create old notification.
+ final NotificationRecord nr2 = generateNotificationRecord(mTestNotificationChannel, 0);
+ mService.addNotification(nr2);
+
+ // Cancel all notifications via listener.
+ mService.getBinderService().cancelNotificationsFromListener(null, null);
+ waitForIdle();
+
+ // Notifications should not be active anymore.
+ StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG);
+ assertThat(notifications).isEmpty();
+ assertEquals(0, mService.getNotificationRecordCount());
+ // Ensure cancel event is logged.
+ verify(mAppOpsManager).noteOpNoThrow(
+ AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER, mUid, PKG, null, null);
+ }
+
+ @Test
+ public void cancelNotificationsFromListener_rapidClear_old_cancelAll() throws RemoteException {
+ mSetFlagsRule.enableFlags(android.view.contentprotection.flags.Flags
+ .FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED);
+
+ // Create old notifications.
+ final NotificationRecord nr1 = generateNotificationRecord(mTestNotificationChannel, 0);
+ mService.addNotification(nr1);
+
+ final NotificationRecord nr2 = generateNotificationRecord(mTestNotificationChannel, 0);
+ mService.addNotification(nr2);
+
+ // Cancel all notifications via listener.
+ mService.getBinderService().cancelNotificationsFromListener(null, null);
+ waitForIdle();
+
+ // Notifications should not be active anymore.
+ StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG);
+ assertThat(notifications).isEmpty();
+ assertEquals(0, mService.getNotificationRecordCount());
+ // Ensure cancel event is not logged.
+ verify(mAppOpsManager, never()).noteOpNoThrow(
+ eq(AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER), anyInt(), anyString(),
+ any(), any());
+ }
+
+ @Test
+ public void cancelNotificationsFromListener_rapidClear_oldNew_cancelAll_flagDisabled()
+ throws RemoteException {
+ mSetFlagsRule.disableFlags(android.view.contentprotection.flags.Flags
+ .FLAG_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER_APP_OP_ENABLED);
+
+ // Create recent notification.
+ final NotificationRecord nr1 = generateNotificationRecord(mTestNotificationChannel,
+ System.currentTimeMillis());
+ mService.addNotification(nr1);
+
+ // Create old notification.
+ final NotificationRecord nr2 = generateNotificationRecord(mTestNotificationChannel, 0);
+ mService.addNotification(nr2);
+
+ // Cancel all notifications via listener.
+ mService.getBinderService().cancelNotificationsFromListener(null, null);
+ waitForIdle();
+
+ // Notifications should not be active anymore.
+ StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG);
+ assertThat(notifications).isEmpty();
+ assertEquals(0, mService.getNotificationRecordCount());
+ // Ensure cancel event is not logged due to flag being disabled.
+ verify(mAppOpsManager, never()).noteOpNoThrow(
+ eq(AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER), anyInt(), anyString(),
+ any(), any());
+ }
+
private NotificationRecord createAndPostNotification(Notification.Builder nb, String testName)
throws RemoteException {
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, testName, mUid, 0,
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationVisitUrisTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationVisitUrisTest.java
index 44dbe385..ea948ca 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationVisitUrisTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationVisitUrisTest.java
@@ -146,6 +146,10 @@
.put(Notification.Action.Builder.class, "extend")
// Overwrites icon supplied to constructor.
.put(Notification.BubbleMetadata.Builder.class, "setIcon")
+ // Overwrites intent supplied to constructor.
+ .put(Notification.BubbleMetadata.Builder.class, "setIntent")
+ // Overwrites intent supplied to constructor.
+ .put(Notification.BubbleMetadata.Builder.class, "setDeleteIntent")
// Discards previously-added actions.
.put(RemoteViews.class, "mergeRemoteViews")
.build();
@@ -680,14 +684,14 @@
}
if (clazz == Intent.class) {
- // TODO(b/281044385): Are Intent Uris (new Intent(String,Uri)) relevant?
- return new Intent("action");
+ return new Intent("action", generateUri(where.plus(Intent.class)));
}
if (clazz == PendingIntent.class) {
- // PendingIntent can have an Intent with a Uri but those are inaccessible and
- // not inspected.
- return PendingIntent.getActivity(mContext, 0, new Intent("action"),
+ // PendingIntent can have an Intent with a Uri.
+ Uri intentUri = generateUri(where.plus(PendingIntent.class));
+ return PendingIntent.getActivity(mContext, 0,
+ new Intent("action", intentUri),
PendingIntent.FLAG_IMMUTABLE);
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/RootTaskTests.java b/services/tests/wmtests/src/com/android/server/wm/RootTaskTests.java
index 7eab06a..89cd726 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RootTaskTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RootTaskTests.java
@@ -1240,7 +1240,7 @@
final ActivityRecord activity1 = finishTopActivity(rootTask1);
assertEquals(DESTROYING, activity1.getState());
verify(mRootWindowContainer).ensureVisibilityAndConfig(eq(null) /* starting */,
- eq(display.mDisplayId), anyBoolean(), anyBoolean());
+ eq(display.mDisplayId), anyBoolean());
}
private ActivityRecord finishTopActivity(Task task) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
index 0608cf4..28fecd6 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
@@ -838,7 +838,7 @@
.setSystemDecorations(true).build();
doReturn(true).when(mRootWindowContainer)
- .ensureVisibilityAndConfig(any(), anyInt(), anyBoolean(), anyBoolean());
+ .ensureVisibilityAndConfig(any(), anyInt(), anyBoolean());
doReturn(true).when(mRootWindowContainer).canStartHomeOnDisplayArea(any(), any(),
anyBoolean());
diff --git a/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java b/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
index a004cc3..2506360 100644
--- a/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
+++ b/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
@@ -16,6 +16,7 @@
package android.telephony;
+import android.annotation.WorkerThread;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.text.Editable;
@@ -39,6 +40,9 @@
* </ul>
* <p>
* The formatting will be restarted once the text is cleared.
+ *
+ * @deprecated This is a thin wrapper on a `libphonenumber` `AsYouTypeFormatter`; it is recommended
+ * to use that instead.
*/
public class PhoneNumberFormattingTextWatcher implements TextWatcher {
@@ -69,6 +73,7 @@
* @param countryCode the ISO 3166-1 two-letter country code that indicates the country/region
* where the phone number is being entered.
*/
+ @WorkerThread
public PhoneNumberFormattingTextWatcher(String countryCode) {
if (countryCode == null) throw new IllegalArgumentException();
mFormatter = PhoneNumberUtil.getInstance().getAsYouTypeFormatter(countryCode);
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index b96914e..f206987 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -18009,6 +18009,64 @@
}
/**
+ * Enable or disable notifications sent for cellular identifier disclosure events.
+ *
+ * Disclosure events are defined as instances where a device has sent a cellular identifier
+ * on the Non-access stratum (NAS) before a security context is established. As a result the
+ * identifier is sent in the clear, which has privacy implications for the user.
+ *
+ * @param enable if notifications about disclosure events should be enabled
+ * @throws IllegalStateException if the Telephony process is not currently available
+ * @throws SecurityException if the caller does not have the required privileges
+ * @throws UnsupportedOperationException if the modem does not support this feature.
+ *
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_ENABLE_IDENTIFIER_DISCLOSURE_TRANSPARENCY)
+ @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
+ @SystemApi
+ public void enableCellularIdentifierDisclosureNotifications(boolean enable) {
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null) {
+ telephony.enableCellularIdentifierDisclosureNotifications(enable);
+ } else {
+ throw new IllegalStateException("telephony service is null.");
+ }
+ } catch (RemoteException ex) {
+ Rlog.e(TAG, "enableCellularIdentifierDisclosureNotifications RemoteException", ex);
+ ex.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Get whether or not cellular identifier disclosure notifications are enabled.
+ *
+ * @throws IllegalStateException if the Telephony process is not currently available
+ * @throws SecurityException if the caller does not have the required privileges
+ * @throws UnsupportedOperationException if the modem does not support this feature.
+ *
+ * @hide
+ */
+ @FlaggedApi(Flags.FLAG_ENABLE_IDENTIFIER_DISCLOSURE_TRANSPARENCY)
+ @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
+ @SystemApi
+ public boolean isCellularIdentifierDisclosureNotificationEnabled() {
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null) {
+ return telephony.isCellularIdentifierDisclosureNotificationEnabled();
+ } else {
+ throw new IllegalStateException("telephony service is null.");
+ }
+ } catch (RemoteException ex) {
+ Rlog.e(TAG, "isCellularIdentifierDisclosureNotificationEnabled RemoteException", ex);
+ ex.rethrowFromSystemServer();
+ }
+ return false;
+ }
+
+ /**
* Get current cell broadcast message identifier ranges.
*
* @throws SecurityException if the caller does not have the required permission
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 4c53f8a..d7d28a1 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -3159,4 +3159,37 @@
* @return {@code true} if the operation is successful, {@code false} otherwise.
*/
boolean setShouldSendDatagramToModemInDemoMode(boolean shouldSendToModemInDemoMode);
+
+ /**
+ * Enable or disable notifications sent for cellular identifier disclosure events.
+ *
+ * Disclosure events are defined as instances where a device has sent a cellular identifier
+ * on the Non-access stratum (NAS) before a security context is established. As a result the
+ * identifier is sent in the clear, which has privacy implications for the user.
+ *
+ * <p>Requires permission: android.Manifest.MODIFY_PHONE_STATE</p>
+ *
+ * @param enabled if notifications about disclosure events should be enabled
+ * @throws IllegalStateException if the Telephony process is not currently available
+ * @throws SecurityException if the caller does not have the required privileges
+ * @throws UnsupportedOperationException if the modem does not support this feature.
+ * @hide
+ */
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
+ + "android.Manifest.permission.MODIFY_PHONE_STATE)")
+ void enableCellularIdentifierDisclosureNotifications(boolean enable);
+
+ /**
+ * Get whether or not cellular identifier disclosure notifications are enabled.
+ *
+ * <p>Requires permission: android.Manifest.READ_PRIVILEGED_PHONE_STATE</p>
+ *
+ * @throws IllegalStateException if the Telephony process is not currently available
+ * @throws SecurityException if the caller does not have the required privileges
+ * @throws UnsupportedOperationException if the modem does not support this feature.
+ * @hide
+ */
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
+ + "android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)")
+ boolean isCellularIdentifierDisclosureNotificationEnabled();
}