Merge "Add DeviceConfig flag for enforcing receiver restrictions" into tm-dev
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java
index afe36b5..d5a7f28 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobConcurrencyManager.java
@@ -959,7 +959,7 @@
for (int i = 0; i < mActiveServices.size(); i++) {
JobServiceContext jsc = mActiveServices.get(i);
final JobStatus executing = jsc.getRunningJobLocked();
- if (executing != null && executing.matches(job.getUid(), job.getJobId())) {
+ if (executing == job) {
jsc.cancelExecutingJobLocked(reason, internalReasonCode, debugReason);
return true;
}
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/PrefetchController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/PrefetchController.java
index 428f2cb..0f385ef 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/PrefetchController.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/PrefetchController.java
@@ -17,6 +17,7 @@
package com.android.server.job.controllers;
import static android.text.format.DateUtils.HOUR_IN_MILLIS;
+import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static com.android.server.job.JobSchedulerService.sElapsedRealtimeClock;
import static com.android.server.job.JobSchedulerService.sSystemClock;
@@ -90,6 +91,14 @@
@CurrentTimeMillisLong
private long mLaunchTimeThresholdMs = PcConstants.DEFAULT_LAUNCH_TIME_THRESHOLD_MS;
+ /**
+ * The additional time we'll add to a launch time estimate before considering it obsolete and
+ * try to get a new estimate. This will help make prefetch jobs more viable in case an estimate
+ * is a few minutes early.
+ */
+ @GuardedBy("mLock")
+ private long mLaunchTimeAllowanceMs = PcConstants.DEFAULT_LAUNCH_TIME_ALLOWANCE_MS;
+
@SuppressWarnings("FieldCanBeLocal")
private final EstimatedLaunchTimeChangedListener mEstimatedLaunchTimeChangedListener =
new EstimatedLaunchTimeChangedListener() {
@@ -204,7 +213,8 @@
private long getNextEstimatedLaunchTimeLocked(int userId, @NonNull String pkgName,
@CurrentTimeMillisLong long now) {
final Long nextEstimatedLaunchTime = mEstimatedLaunchTimes.get(userId, pkgName);
- if (nextEstimatedLaunchTime == null || nextEstimatedLaunchTime < now) {
+ if (nextEstimatedLaunchTime == null
+ || nextEstimatedLaunchTime < now - mLaunchTimeAllowanceMs) {
// Don't query usage stats here because it may have to read from disk.
mHandler.obtainMessage(MSG_RETRIEVE_ESTIMATED_LAUNCH_TIME, userId, 0, pkgName)
.sendToTarget();
@@ -335,7 +345,9 @@
}
final long nextEstimatedLaunchTime = getNextEstimatedLaunchTimeLocked(userId, pkgName, now);
- if (nextEstimatedLaunchTime - now > mLaunchTimeThresholdMs) {
+ // Avoid setting an alarm for the end of time.
+ if (nextEstimatedLaunchTime != Long.MAX_VALUE
+ && nextEstimatedLaunchTime - now > mLaunchTimeThresholdMs) {
// Set alarm to be notified when this crosses the threshold.
final long timeToCrossThresholdMs =
nextEstimatedLaunchTime - (now + mLaunchTimeThresholdMs);
@@ -354,7 +366,7 @@
private boolean willBeLaunchedSoonLocked(int userId, @NonNull String pkgName,
@CurrentTimeMillisLong long now) {
return getNextEstimatedLaunchTimeLocked(userId, pkgName, now)
- <= now + mLaunchTimeThresholdMs;
+ <= now + mLaunchTimeThresholdMs - mLaunchTimeAllowanceMs;
}
@Override
@@ -494,16 +506,37 @@
@VisibleForTesting
static final String KEY_LAUNCH_TIME_THRESHOLD_MS =
PC_CONSTANT_PREFIX + "launch_time_threshold_ms";
+ @VisibleForTesting
+ static final String KEY_LAUNCH_TIME_ALLOWANCE_MS =
+ PC_CONSTANT_PREFIX + "launch_time_allowance_ms";
private static final long DEFAULT_LAUNCH_TIME_THRESHOLD_MS = 7 * HOUR_IN_MILLIS;
+ private static final long DEFAULT_LAUNCH_TIME_ALLOWANCE_MS = 20 * MINUTE_IN_MILLIS;
/** How much time each app will have to run jobs within their standby bucket window. */
public long LAUNCH_TIME_THRESHOLD_MS = DEFAULT_LAUNCH_TIME_THRESHOLD_MS;
+ /**
+ * How much additional time to add to an estimated launch time before considering it
+ * unusable.
+ */
+ public long LAUNCH_TIME_ALLOWANCE_MS = DEFAULT_LAUNCH_TIME_ALLOWANCE_MS;
+
@GuardedBy("mLock")
public void processConstantLocked(@NonNull DeviceConfig.Properties properties,
@NonNull String key) {
switch (key) {
+ case KEY_LAUNCH_TIME_ALLOWANCE_MS:
+ LAUNCH_TIME_ALLOWANCE_MS =
+ properties.getLong(key, DEFAULT_LAUNCH_TIME_ALLOWANCE_MS);
+ // Limit the allowance to the range [0 minutes, 2 hours].
+ long newLaunchTimeAllowanceMs = Math.min(2 * HOUR_IN_MILLIS,
+ Math.max(0, LAUNCH_TIME_ALLOWANCE_MS));
+ if (mLaunchTimeAllowanceMs != newLaunchTimeAllowanceMs) {
+ mLaunchTimeAllowanceMs = newLaunchTimeAllowanceMs;
+ mShouldReevaluateConstraints = true;
+ }
+ break;
case KEY_LAUNCH_TIME_THRESHOLD_MS:
LAUNCH_TIME_THRESHOLD_MS =
properties.getLong(key, DEFAULT_LAUNCH_TIME_THRESHOLD_MS);
@@ -528,6 +561,7 @@
pw.increaseIndent();
pw.print(KEY_LAUNCH_TIME_THRESHOLD_MS, LAUNCH_TIME_THRESHOLD_MS).println();
+ pw.print(KEY_LAUNCH_TIME_ALLOWANCE_MS, LAUNCH_TIME_ALLOWANCE_MS).println();
pw.decreaseIndent();
}
@@ -536,6 +570,11 @@
//////////////////////// TESTING HELPERS /////////////////////////////
@VisibleForTesting
+ long getLaunchTimeAllowanceMs() {
+ return mLaunchTimeAllowanceMs;
+ }
+
+ @VisibleForTesting
long getLaunchTimeThresholdMs() {
return mLaunchTimeThresholdMs;
}
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index a216021..cb64173 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -2709,7 +2709,7 @@
AppOpsManager.MODE_ALLOWED, // READ_ICC_SMS
AppOpsManager.MODE_ALLOWED, // WRITE_ICC_SMS
AppOpsManager.MODE_DEFAULT, // WRITE_SETTINGS
- AppOpsManager.MODE_DEFAULT, // SYSTEM_ALERT_WINDOW /*Overridden in opToDefaultMode()*/
+ getSystemAlertWindowDefault(), // SYSTEM_ALERT_WINDOW
AppOpsManager.MODE_ALLOWED, // ACCESS_NOTIFICATIONS
AppOpsManager.MODE_ALLOWED, // CAMERA
AppOpsManager.MODE_ALLOWED, // RECORD_AUDIO
@@ -3163,8 +3163,6 @@
private static final String DEBUG_LOGGING_OPS_PROP = "appops.logging_ops";
private static final String DEBUG_LOGGING_TAG = "AppOpsManager";
- private static volatile Integer sOpSystemAlertWindowDefaultMode;
-
/**
* Retrieve the op switch that controls the given operation.
* @hide
@@ -3263,9 +3261,6 @@
* @hide
*/
public static @Mode int opToDefaultMode(int op) {
- if (op == OP_SYSTEM_ALERT_WINDOW) {
- return getSystemAlertWindowDefault();
- }
return sOpDefaultMode[op];
}
@@ -10283,11 +10278,6 @@
}
private static int getSystemAlertWindowDefault() {
- // This is indeed racy but we aren't expecting the result to change so it's not worth
- // the synchronization.
- if (sOpSystemAlertWindowDefaultMode != null) {
- return sOpSystemAlertWindowDefaultMode;
- }
final Context context = ActivityThread.currentApplication();
if (context == null) {
return AppOpsManager.MODE_DEFAULT;
@@ -10298,11 +10288,10 @@
// TVs are constantly plugged in and has less concern for memory/power
if (ActivityManager.isLowRamDeviceStatic()
&& !pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK, 0)) {
- sOpSystemAlertWindowDefaultMode = AppOpsManager.MODE_IGNORED;
- } else {
- sOpSystemAlertWindowDefaultMode = AppOpsManager.MODE_DEFAULT;
+ return AppOpsManager.MODE_IGNORED;
}
- return sOpSystemAlertWindowDefaultMode;
+
+ return AppOpsManager.MODE_DEFAULT;
}
/**
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 63cdfe6..8647b9a 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -11210,7 +11210,9 @@
* for enterprise use.
*
* An example of a supported preferential network service is the Enterprise
- * slice on 5G networks.
+ * slice on 5G networks. For devices on 4G networks, the profile owner needs to additionally
+ * configure enterprise APN to set up data call for the preferential network service.
+ * These APNs can be added using {@link #addOverrideApn}.
*
* By default, preferential network service is disabled on the work profile and
* fully managed devices, on supported carriers and devices.
@@ -11260,7 +11262,9 @@
* {@see PreferentialNetworkServiceConfig}
*
* An example of a supported preferential network service is the Enterprise
- * slice on 5G networks.
+ * slice on 5G networks. For devices on 4G networks, the profile owner needs to additionally
+ * configure enterprise APN to set up data call for the preferential network service.
+ * These APNs can be added using {@link #addOverrideApn}.
*
* By default, preferential network service is disabled on the work profile and fully managed
* devices, on supported carriers and devices. Admins can explicitly enable it with this API.
@@ -13782,18 +13786,13 @@
}
/**
- * Called by device owner or profile owner to add an override APN.
+ * Called by device owner or managed profile owner to add an override APN.
*
* <p>This method may returns {@code -1} if {@code apnSetting} conflicts with an existing
* override APN. Update the existing conflicted APN with
* {@link #updateOverrideApn(ComponentName, int, ApnSetting)} instead of adding a new entry.
* <p>Two override APNs are considered to conflict when all the following APIs return
* the same values on both override APNs:
- * <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
- * Only device owners can add APNs.
- * <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
- * Device and profile owners can add enterprise APNs
- * ({@link ApnSetting#TYPE_ENTERPRISE}), while only device owners can add other type of APNs.
* <ul>
* <li>{@link ApnSetting#getOperatorNumeric()}</li>
* <li>{@link ApnSetting#getApnName()}</li>
@@ -13808,6 +13807,15 @@
* <li>{@link ApnSetting#getRoamingProtocol()}</li>
* </ul>
*
+ * <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
+ * Only device owners can add APNs.
+ * <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
+ * Both device owners and managed profile owners can add enterprise APNs
+ * ({@link ApnSetting#TYPE_ENTERPRISE}), while only device owners can add other type of APNs.
+ * Enterprise APNs are specific to the managed profile and do not override any user-configured
+ * VPNs. They are prerequisites for enabling preferential network service on the managed
+ * profile on 4G networks ({@link #setPreferentialNetworkServiceConfigs}).
+ *
* @param admin which {@link DeviceAdminReceiver} this request is associated with
* @param apnSetting the override APN to insert
* @return The {@code id} of inserted override APN. Or {@code -1} when failed to insert into
@@ -13830,7 +13838,7 @@
}
/**
- * Called by device owner or profile owner to update an override APN.
+ * Called by device owner or managed profile owner to update an override APN.
*
* <p>This method may returns {@code false} if there is no override APN with the given
* {@code apnId}.
@@ -13840,7 +13848,7 @@
* <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
* Only device owners can update APNs.
* <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
- * Device and profile owners can update enterprise APNs
+ * Both device owners and managed profile owners can update enterprise APNs
* ({@link ApnSetting#TYPE_ENTERPRISE}), while only device owners can update other type of APNs.
*
* @param admin which {@link DeviceAdminReceiver} this request is associated with
@@ -13867,14 +13875,14 @@
}
/**
- * Called by device owner or profile owner to remove an override APN.
+ * Called by device owner or managed profile owner to remove an override APN.
*
* <p>This method may returns {@code false} if there is no override APN with the given
* {@code apnId}.
* <p> Before Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
* Only device owners can remove APNs.
* <p> Starting from Android version {@link android.os.Build.VERSION_CODES#TIRAMISU}:
- * Device and profile owners can remove enterprise APNs
+ * Both device owners and managed profile owners can remove enterprise APNs
* ({@link ApnSetting#TYPE_ENTERPRISE}), while only device owners can remove other type of APNs.
*
* @param admin which {@link DeviceAdminReceiver} this request is associated with
@@ -13899,7 +13907,8 @@
}
/**
- * Called by device owner to get all override APNs inserted by device owner.
+ * Called by device owner or managed profile owner to get all override APNs inserted by
+ * device owner or managed profile owner previously using {@link #addOverrideApn}.
*
* @param admin which {@link DeviceAdminReceiver} this request is associated with
* @return A list of override APNs inserted by device owner.
@@ -13924,6 +13933,9 @@
* <p> Override APNs are separated from other APNs on the device, and can only be inserted or
* modified by the device owner. When enabled, only override APNs are in use, any other APNs
* are ignored.
+ * <p>Note: Enterprise APNs added by managed profile owners do not need to be enabled by
+ * this API. They are part of the preferential network service config and is controlled by
+ * {@link #setPreferentialNetworkServiceConfigs}.
*
* @param admin which {@link DeviceAdminReceiver} this request is associated with
* @param enabled {@code true} if override APNs should be enabled, {@code false} otherwise
diff --git a/core/java/android/content/res/AssetFileDescriptor.java b/core/java/android/content/res/AssetFileDescriptor.java
index dd00c3a..ac65933 100644
--- a/core/java/android/content/res/AssetFileDescriptor.java
+++ b/core/java/android/content/res/AssetFileDescriptor.java
@@ -21,8 +21,6 @@
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
-import android.system.ErrnoException;
-import android.system.Os;
import java.io.Closeable;
import java.io.FileDescriptor;
@@ -54,11 +52,11 @@
/**
* Create a new AssetFileDescriptor from the given values.
*
- * @param fd The underlying file descriptor.
+ * @param fd The underlying file descriptor.
* @param startOffset The location within the file that the asset starts.
- * This must be 0 if length is UNKNOWN_LENGTH.
- * @param length The number of bytes of the asset, or
- * {@link #UNKNOWN_LENGTH} if it extends to the end of the file.
+ * This must be 0 if length is UNKNOWN_LENGTH.
+ * @param length The number of bytes of the asset, or
+ * {@link #UNKNOWN_LENGTH} if it extends to the end of the file.
*/
public AssetFileDescriptor(ParcelFileDescriptor fd, long startOffset,
long length) {
@@ -68,13 +66,13 @@
/**
* Create a new AssetFileDescriptor from the given values.
*
- * @param fd The underlying file descriptor.
+ * @param fd The underlying file descriptor.
* @param startOffset The location within the file that the asset starts.
- * This must be 0 if length is UNKNOWN_LENGTH.
- * @param length The number of bytes of the asset, or
- * {@link #UNKNOWN_LENGTH} if it extends to the end of the file.
- * @param extras additional details that can be used to interpret the
- * underlying file descriptor. May be null.
+ * This must be 0 if length is UNKNOWN_LENGTH.
+ * @param length The number of bytes of the asset, or
+ * {@link #UNKNOWN_LENGTH} if it extends to the end of the file.
+ * @param extras additional details that can be used to interpret the
+ * underlying file descriptor. May be null.
*/
public AssetFileDescriptor(ParcelFileDescriptor fd, long startOffset,
long length, Bundle extras) {
@@ -205,24 +203,19 @@
*/
public static class AutoCloseInputStream
extends ParcelFileDescriptor.AutoCloseInputStream {
- private final long mSizeFromStartOffset;
- private final long mStartOffset;
- private long mPosFromStartOffset;
+ private long mRemaining;
public AutoCloseInputStream(AssetFileDescriptor fd) throws IOException {
super(fd.getParcelFileDescriptor());
- // this skip is necessary if getChannel() is called
super.skip(fd.getStartOffset());
- mSizeFromStartOffset = fd.getLength();
- mStartOffset = fd.getStartOffset();
+ mRemaining = (int) fd.getLength();
}
@Override
public int available() throws IOException {
- long available = mSizeFromStartOffset - mPosFromStartOffset;
- return available >= 0
- ? (available < 0x7fffffff ? (int) available : 0x7fffffff)
- : 0;
+ return mRemaining >= 0
+ ? (mRemaining < 0x7fffffff ? (int) mRemaining : 0x7fffffff)
+ : super.available();
}
@Override
@@ -234,24 +227,15 @@
@Override
public int read(byte[] buffer, int offset, int count) throws IOException {
- int available = available();
-
- if (available <= 0) {
- return -1;
- } else {
- if (count > available) count = available;
- try {
- int res = Os.pread(getFD(), buffer, offset, count,
- mStartOffset + mPosFromStartOffset);
- // pread returns 0 at end of file, while java's InputStream interface
- // requires -1
- if (res == 0) res = -1;
- if (res >= 0) mPosFromStartOffset += res;
- return res;
- } catch (ErrnoException e) {
- throw new IOException(e);
- }
+ if (mRemaining >= 0) {
+ if (mRemaining == 0) return -1;
+ if (count > mRemaining) count = (int) mRemaining;
+ int res = super.read(buffer, offset, count);
+ if (res >= 0) mRemaining -= res;
+ return res;
}
+
+ return super.read(buffer, offset, count);
}
@Override
@@ -261,31 +245,41 @@
@Override
public long skip(long count) throws IOException {
- int available = available();
- if (available <= 0) {
- return -1;
- } else {
- if (count > available) count = available;
- mPosFromStartOffset += count;
- return count;
+ if (mRemaining >= 0) {
+ if (mRemaining == 0) return -1;
+ if (count > mRemaining) count = mRemaining;
+ long res = super.skip(count);
+ if (res >= 0) mRemaining -= res;
+ return res;
}
+
+ return super.skip(count);
}
@Override
public void mark(int readlimit) {
- // Not supported.
- return;
+ if (mRemaining >= 0) {
+ // Not supported.
+ return;
+ }
+ super.mark(readlimit);
}
@Override
public boolean markSupported() {
- return false;
+ if (mRemaining >= 0) {
+ return false;
+ }
+ return super.markSupported();
}
@Override
public synchronized void reset() throws IOException {
- // Not supported.
- return;
+ if (mRemaining >= 0) {
+ // Not supported.
+ return;
+ }
+ super.reset();
}
}
@@ -381,7 +375,6 @@
public AssetFileDescriptor createFromParcel(Parcel in) {
return new AssetFileDescriptor(in);
}
-
public AssetFileDescriptor[] newArray(int size) {
return new AssetFileDescriptor[size];
}
diff --git a/core/java/android/hardware/Sensor.java b/core/java/android/hardware/Sensor.java
index 0d3aaf5..10c3730 100644
--- a/core/java/android/hardware/Sensor.java
+++ b/core/java/android/hardware/Sensor.java
@@ -712,14 +712,16 @@
public static final String STRING_TYPE_HINGE_ANGLE = "android.sensor.hinge_angle";
/**
- * A constant describing a head tracker sensor.
+ * A constant describing a head tracker sensor. Note that this sensor type is typically not
+ * available for apps to use.
*
* See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
*/
public static final int TYPE_HEAD_TRACKER = 37;
/**
- * A constant string describing a head tracker sensor.
+ * A constant string describing a head tracker sensor. Note that this sensor type is typically
+ * not available for apps to use.
*
* See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
*/
diff --git a/core/java/android/hardware/camera2/params/OutputConfiguration.java b/core/java/android/hardware/camera2/params/OutputConfiguration.java
index bb0caa7..4a25177 100644
--- a/core/java/android/hardware/camera2/params/OutputConfiguration.java
+++ b/core/java/android/hardware/camera2/params/OutputConfiguration.java
@@ -166,7 +166,16 @@
* {@link #TIMESTAMP_BASE_MONOTONIC}, which is roughly the same time base as
* {@link android.os.SystemClock#uptimeMillis}.</li>
* <li> For all other cases, the timestamp base is {@link #TIMESTAMP_BASE_SENSOR}, the same
- * as what's specified by {@link CameraCharacteristics#SENSOR_INFO_TIMESTAMP_SOURCE}.</li>
+ * as what's specified by {@link CameraCharacteristics#SENSOR_INFO_TIMESTAMP_SOURCE}.
+ * <ul><li> For a SurfaceTexture output surface, the camera system re-spaces the delivery
+ * of output frames based on image readout intervals, reducing viewfinder jitter. The timestamps
+ * of images remain to be {@link #TIMESTAMP_BASE_SENSOR}.</li></ul></li>
+ *
+ * <p>Note that the reduction of frame jitter for SurfaceView and SurfaceTexture comes with
+ * slight increase in photon-to-photon latency, which is the time from when photons hit the
+ * scene to when the corresponding pixels show up on the screen. If the photon-to-photon latency
+ * is more important than the smoothness of viewfinder, {@link #TIMESTAMP_BASE_SENSOR} should be
+ * used instead.</p>
*
* @see #TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED
* @see #TIMESTAMP_BASE_MONOTONIC
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 200fe22..21ecf8b 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -592,7 +592,7 @@
private InlineSuggestionSessionController mInlineSuggestionSessionController;
- private boolean mAutomotiveHideNavBarForKeyboard;
+ private boolean mHideNavBarForKeyboard;
private boolean mIsAutomotive;
private @NonNull OptionalInt mHandwritingRequestId = OptionalInt.empty();
private InputEventReceiver mHandwritingEventReceiver;
@@ -1498,9 +1498,8 @@
// shown the first time (cold start).
mSettingsObserver.shouldShowImeWithHardKeyboard();
- mIsAutomotive = isAutomotive();
- mAutomotiveHideNavBarForKeyboard = getApplicationContext().getResources().getBoolean(
- com.android.internal.R.bool.config_automotiveHideNavBarForKeyboard);
+ mHideNavBarForKeyboard = getApplicationContext().getResources().getBoolean(
+ com.android.internal.R.bool.config_hideNavBarForKeyboard);
// TODO(b/111364446) Need to address context lifecycle issue if need to re-create
// for update resources & configuration correctly when show soft input
@@ -1539,11 +1538,11 @@
window.setFlags(windowFlags, windowFlagsMask);
// Automotive devices may request the navigation bar to be hidden when the IME shows up
- // (controlled via config_automotiveHideNavBarForKeyboard) in order to maximize the
- // visible screen real estate. When this happens, the IME window should animate from the
+ // (controlled via config_hideNavBarForKeyboard) in order to maximize the visible
+ // screen real estate. When this happens, the IME window should animate from the
// bottom of the screen to reduce the jank that happens from the lack of synchronization
// between the bottom system window and the IME window.
- if (mIsAutomotive && mAutomotiveHideNavBarForKeyboard) {
+ if (mHideNavBarForKeyboard) {
window.setDecorFitsSystemWindows(false);
}
}
diff --git a/core/java/android/speech/RecognitionService.java b/core/java/android/speech/RecognitionService.java
index 6a65efb..6b59f54 100644
--- a/core/java/android/speech/RecognitionService.java
+++ b/core/java/android/speech/RecognitionService.java
@@ -129,8 +129,9 @@
@NonNull AttributionSource attributionSource) {
try {
if (mCurrentCallback == null) {
- boolean preflightPermissionCheckPassed = checkPermissionForPreflightNotHardDenied(
- attributionSource);
+ boolean preflightPermissionCheckPassed =
+ intent.hasExtra(RecognizerIntent.EXTRA_AUDIO_SOURCE)
+ || checkPermissionForPreflightNotHardDenied(attributionSource);
if (preflightPermissionCheckPassed) {
if (DBG) {
Log.d(TAG, "created new mCurrentCallback, listener = "
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java
index 2ad1b38..7cc37f7 100644
--- a/core/java/com/android/internal/app/ChooserActivity.java
+++ b/core/java/com/android/internal/app/ChooserActivity.java
@@ -190,6 +190,7 @@
private static final String SHORTCUT_TARGET = "shortcut_target";
private static final int APP_PREDICTION_SHARE_TARGET_QUERY_PACKAGE_LIMIT = 20;
public static final String APP_PREDICTION_INTENT_FILTER_KEY = "intent_filter";
+ private static final String SHARED_TEXT_KEY = "shared_text";
private static final String PLURALS_COUNT = "count";
private static final String PLURALS_FILE_NAME = "file_name";
@@ -2201,6 +2202,7 @@
final IntentFilter filter = getTargetIntentFilter();
Bundle extras = new Bundle();
extras.putParcelable(APP_PREDICTION_INTENT_FILTER_KEY, filter);
+ populateTextContent(extras);
AppPredictionContext appPredictionContext = new AppPredictionContext.Builder(contextAsUser)
.setUiSurface(APP_PREDICTION_SHARE_UI_SURFACE)
.setPredictedTargetCount(APP_PREDICTION_SHARE_TARGET_QUERY_PACKAGE_LIMIT)
@@ -2219,6 +2221,12 @@
return appPredictionSession;
}
+ private void populateTextContent(Bundle extras) {
+ final Intent intent = getTargetIntent();
+ String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
+ extras.putString(SHARED_TEXT_KEY, sharedText);
+ }
+
/**
* This will return an app predictor if it is enabled for direct share sorting
* and if one exists. Otherwise, it returns null.
diff --git a/core/java/com/android/internal/jank/InteractionJankMonitor.java b/core/java/com/android/internal/jank/InteractionJankMonitor.java
index 2e4860a..2dcc585 100644
--- a/core/java/com/android/internal/jank/InteractionJankMonitor.java
+++ b/core/java/com/android/internal/jank/InteractionJankMonitor.java
@@ -74,6 +74,7 @@
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__TAKE_SCREENSHOT;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__UNFOLD_ANIM;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__USER_SWITCH;
+import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__VOLUME_CONTROL;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__WALLPAPER_TRANSITION;
import android.annotation.IntDef;
@@ -196,6 +197,7 @@
public static final int CUJ_SPLIT_SCREEN_RESIZE = 52;
public static final int CUJ_SETTINGS_SLIDER = 53;
public static final int CUJ_TAKE_SCREENSHOT = 54;
+ public static final int CUJ_VOLUME_CONTROL = 55;
private static final int NO_STATSD_LOGGING = -1;
@@ -259,6 +261,7 @@
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLIT_SCREEN_RESIZE,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SETTINGS_SLIDER,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__TAKE_SCREENSHOT,
+ UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__VOLUME_CONTROL,
};
private static volatile InteractionJankMonitor sInstance;
@@ -334,6 +337,7 @@
CUJ_SPLIT_SCREEN_RESIZE,
CUJ_SETTINGS_SLIDER,
CUJ_TAKE_SCREENSHOT,
+ CUJ_VOLUME_CONTROL,
})
@Retention(RetentionPolicy.SOURCE)
public @interface CujType {
@@ -762,6 +766,8 @@
return "SETTINGS_SLIDER";
case CUJ_TAKE_SCREENSHOT:
return "TAKE_SCREENSHOT";
+ case CUJ_VOLUME_CONTROL:
+ return "VOLUME_CONTROL";
}
return "UNKNOWN";
}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index f20b824..8db5f9a 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -7044,7 +7044,7 @@
android:permission="android.permission.BIND_JOB_SERVICE">
</service>
- <service android:name="com.android.server.companion.AssociationCleanUpService"
+ <service android:name="com.android.server.companion.InactiveAssociationsRemovalService"
android:permission="android.permission.BIND_JOB_SERVICE">
</service>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 2b0d01f..b139e47 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -4894,7 +4894,7 @@
<!-- Whether or not to hide the navigation bar when the soft keyboard is visible in order to
create additional screen real estate outside beyond the keyboard. Note that the user needs
to have a confirmed way to dismiss the keyboard when desired. -->
- <bool name="config_automotiveHideNavBarForKeyboard">false</bool>
+ <bool name="config_hideNavBarForKeyboard">false</bool>
<!-- Whether or not to show the built-in charging animation when the device begins charging
wirelessly. -->
@@ -5754,6 +5754,14 @@
-->
<integer name="config_bg_current_drain_location_min_duration">1800</integer>
+ <!-- The behavior when the system detects it has abusive current drains, whether or not to
+ move the app to the restricted standby bucket level.
+ True - we'll move the app to restricted standby bucket as long as its bg battery usage
+ goes beyond the threshold, False - we'll not move it.
+ Note: This should be only enabled on devices with high confidence on power measurement.
+ -->
+ <bool name="config_bg_current_drain_auto_restrict_abusive_apps">false</bool>
+
<!-- The behavior for an app with a FGS and its notification is still showing, when the system
detects it's abusive and should be put into bg restricted level. True - we'll
show the prompt to user, False - we'll not show it.
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index c9eb101..e5d90f0 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -6313,5 +6313,5 @@
<string name="vdm_camera_access_denied" product="tablet">Can’t access the tablet’s camera from your <xliff:g id="device" example="Chromebook">%1$s</xliff:g></string>
<!-- Title for preference of the system default locale. [CHAR LIMIT=50]-->
- <string name="system_locale_title">System language</string>
+ <string name="system_locale_title">System default</string>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index b385ac9..77007afc 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -4154,7 +4154,7 @@
<java-symbol type="bool" name="config_disable_all_cb_messages" />
<java-symbol type="drawable" name="ic_close" />
- <java-symbol type="bool" name="config_automotiveHideNavBarForKeyboard" />
+ <java-symbol type="bool" name="config_hideNavBarForKeyboard" />
<java-symbol type="bool" name="config_showBuiltinWirelessChargingAnim" />
@@ -4774,6 +4774,7 @@
<java-symbol type="array" name="config_bg_current_drain_high_threshold_to_bg_restricted" />
<java-symbol type="integer" name="config_bg_current_drain_media_playback_min_duration" />
<java-symbol type="integer" name="config_bg_current_drain_location_min_duration" />
+ <java-symbol type="bool" name="config_bg_current_drain_auto_restrict_abusive_apps" />
<java-symbol type="bool" name="config_bg_prompt_fgs_with_noti_to_bg_restricted" />
<java-symbol type="bool" name="config_bg_prompt_abusive_apps_to_bg_restricted" />
<java-symbol type="integer" name="config_bg_current_drain_exempted_types" />
diff --git a/keystore/java/android/security/keystore2/AndroidKeyStoreKeyPairGeneratorSpi.java b/keystore/java/android/security/keystore2/AndroidKeyStoreKeyPairGeneratorSpi.java
index 40659f5..cdc1085 100644
--- a/keystore/java/android/security/keystore2/AndroidKeyStoreKeyPairGeneratorSpi.java
+++ b/keystore/java/android/security/keystore2/AndroidKeyStoreKeyPairGeneratorSpi.java
@@ -712,7 +712,7 @@
case KeymasterDefs.KM_ERROR_HARDWARE_TYPE_UNAVAILABLE:
throw new StrongBoxUnavailableException("Failed to generated key pair.", e);
case ResponseCode.OUT_OF_KEYS:
- throw makeOutOfKeysException(e, securityLevel);
+ return checkIfRetryableOrThrow(e, securityLevel);
default:
ProviderException p = new ProviderException("Failed to generate key pair.", e);
if ((mSpec.getPurposes() & KeyProperties.PURPOSE_WRAP_KEY) != 0) {
@@ -740,7 +740,7 @@
// In case keystore reports OUT_OF_KEYS, call this handler in an attempt to remotely provision
// some keys.
- private ProviderException makeOutOfKeysException(KeyStoreException e, int securityLevel) {
+ GenerateKeyPairHelperResult checkIfRetryableOrThrow(KeyStoreException e, int securityLevel) {
GenerateRkpKey keyGen = new GenerateRkpKey(ActivityThread
.currentApplication());
KeyStoreException ksException;
@@ -757,8 +757,11 @@
rkpStatus = KeyStoreException.RKP_SERVER_REFUSED_ISSUANCE;
break;
case IGenerateRkpKeyService.Status.OK:
- // This will actually retry once immediately, so on "OK" go ahead and return
- // "temporarily unavailable". @see generateKeyPair
+ // Explicitly return not-OK here so we retry in generateKeyPair. All other cases
+ // should throw because a retry doesn't make sense if we didn't actually
+ // provision fresh keys.
+ return new GenerateKeyPairHelperResult(
+ KeyStoreException.RKP_TEMPORARILY_UNAVAILABLE, null);
case IGenerateRkpKeyService.Status.NETWORK_COMMUNICATION_ERROR:
case IGenerateRkpKeyService.Status.HTTP_CLIENT_ERROR:
case IGenerateRkpKeyService.Status.HTTP_SERVER_ERROR:
@@ -781,7 +784,7 @@
KeyStoreException.RKP_TEMPORARILY_UNAVAILABLE);
}
ksException.initCause(e);
- return new ProviderException("Failed to talk to RemoteProvisioner", ksException);
+ throw new ProviderException("Failed to provision new attestation keys.", ksException);
}
private void addAttestationParameters(@NonNull List<KeyParameter> params)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java
index f407bdc..a459319 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java
@@ -96,6 +96,8 @@
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.common.TaskStackListenerCallback;
import com.android.wm.shell.common.TaskStackListenerImpl;
+import com.android.wm.shell.common.annotations.ShellBackgroundThread;
+import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.draganddrop.DragAndDropController;
import com.android.wm.shell.onehanded.OneHandedController;
import com.android.wm.shell.onehanded.OneHandedTransitionCallback;
@@ -158,6 +160,8 @@
private final ShellExecutor mMainExecutor;
private final Handler mMainHandler;
+ private final ShellExecutor mBackgroundExecutor;
+
private BubbleLogger mLogger;
private BubbleData mBubbleData;
@Nullable private BubbleStackView mStackView;
@@ -234,8 +238,9 @@
DisplayController displayController,
Optional<OneHandedController> oneHandedOptional,
DragAndDropController dragAndDropController,
- ShellExecutor mainExecutor,
- Handler mainHandler,
+ @ShellMainThread ShellExecutor mainExecutor,
+ @ShellMainThread Handler mainHandler,
+ @ShellBackgroundThread ShellExecutor bgExecutor,
TaskViewTransitions taskViewTransitions,
SyncTransactionQueue syncQueue) {
BubbleLogger logger = new BubbleLogger(uiEventLogger);
@@ -245,7 +250,7 @@
new BubbleDataRepository(context, launcherApps, mainExecutor),
statusBarService, windowManager, windowManagerShellWrapper, launcherApps,
logger, taskStackListener, organizer, positioner, displayController,
- oneHandedOptional, dragAndDropController, mainExecutor, mainHandler,
+ oneHandedOptional, dragAndDropController, mainExecutor, mainHandler, bgExecutor,
taskViewTransitions, syncQueue);
}
@@ -269,8 +274,9 @@
DisplayController displayController,
Optional<OneHandedController> oneHandedOptional,
DragAndDropController dragAndDropController,
- ShellExecutor mainExecutor,
- Handler mainHandler,
+ @ShellMainThread ShellExecutor mainExecutor,
+ @ShellMainThread Handler mainHandler,
+ @ShellBackgroundThread ShellExecutor bgExecutor,
TaskViewTransitions taskViewTransitions,
SyncTransactionQueue syncQueue) {
mContext = context;
@@ -286,6 +292,7 @@
mLogger = bubbleLogger;
mMainExecutor = mainExecutor;
mMainHandler = mainHandler;
+ mBackgroundExecutor = bgExecutor;
mTaskStackListener = taskStackListener;
mTaskOrganizer = organizer;
mSurfaceSynchronizer = synchronizer;
@@ -725,7 +732,8 @@
try {
mAddedToWindowManager = false;
- mContext.unregisterReceiver(mBroadcastReceiver);
+ // Put on background for this binder call, was causing jank
+ mBackgroundExecutor.execute(() -> mContext.unregisterReceiver(mBroadcastReceiver));
if (mStackView != null) {
mWindowManager.removeView(mStackView);
mBubbleData.getOverflow().cleanUpExpandedState();
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java
index 3b83f15..6a2acf4 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java
@@ -498,6 +498,11 @@
dispatchVisibilityChanged(mDisplayId, isShowing);
}
}
+
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ public InsetsSourceControl getImeSourceControl() {
+ return mImeSourceControl;
+ }
}
void removeImeSurface() {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
index 1bc9e31..98de60c 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
@@ -43,6 +43,7 @@
import com.android.wm.shell.common.TaskStackListenerImpl;
import com.android.wm.shell.common.TransactionPool;
import com.android.wm.shell.common.annotations.ChoreographerSfVsync;
+import com.android.wm.shell.common.annotations.ShellBackgroundThread;
import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.draganddrop.DragAndDropController;
import com.android.wm.shell.freeform.FreeformTaskListener;
@@ -114,13 +115,15 @@
DragAndDropController dragAndDropController,
@ShellMainThread ShellExecutor mainExecutor,
@ShellMainThread Handler mainHandler,
+ @ShellBackgroundThread ShellExecutor bgExecutor,
TaskViewTransitions taskViewTransitions,
SyncTransactionQueue syncQueue) {
return BubbleController.create(context, null /* synchronizer */,
floatingContentCoordinator, statusBarService, windowManager,
windowManagerShellWrapper, launcherApps, taskStackListener,
uiEventLogger, organizer, displayController, oneHandedOptional,
- dragAndDropController, mainExecutor, mainHandler, taskViewTransitions, syncQueue);
+ dragAndDropController, mainExecutor, mainHandler, bgExecutor,
+ taskViewTransitions, syncQueue);
}
//
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index 86ae399..5a67eb9 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -134,7 +134,7 @@
skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
SkAndroidFrameworkTraceUtil::setEnableTracing(
- base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, true));
+ base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false));
runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
diff --git a/media/java/android/media/tv/interactive/ITvInteractiveAppManagerCallback.aidl b/media/java/android/media/tv/interactive/ITvInteractiveAppManagerCallback.aidl
index fed86dc..2e792b3 100644
--- a/media/java/android/media/tv/interactive/ITvInteractiveAppManagerCallback.aidl
+++ b/media/java/android/media/tv/interactive/ITvInteractiveAppManagerCallback.aidl
@@ -22,10 +22,10 @@
* Interface to receive callbacks from ITvInteractiveAppManager regardless of sessions.
* @hide
*/
-interface ITvInteractiveAppManagerCallback {
+oneway interface ITvInteractiveAppManagerCallback {
void onInteractiveAppServiceAdded(in String iAppServiceId);
void onInteractiveAppServiceRemoved(in String iAppServiceId);
void onInteractiveAppServiceUpdated(in String iAppServiceId);
void onTvInteractiveAppServiceInfoUpdated(in TvInteractiveAppServiceInfo tvIAppInfo);
void onStateChanged(in String iAppServiceId, int type, int state, int err);
-}
\ No newline at end of file
+}
diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp
index c8d2d1e..5850a81 100644
--- a/media/jni/android_media_MediaCodec.cpp
+++ b/media/jni/android_media_MediaCodec.cpp
@@ -1294,45 +1294,46 @@
std::string defaultMsg = "Unknown Error";
/* translate OS errors to Java API CryptoException errorCodes (which are positive) */
+ jint jerr = 0;
switch (err) {
case ERROR_DRM_NO_LICENSE:
- err = gCryptoErrorCodes.cryptoErrorNoKey;
+ jerr = gCryptoErrorCodes.cryptoErrorNoKey;
defaultMsg = "Crypto key not available";
break;
case ERROR_DRM_LICENSE_EXPIRED:
- err = gCryptoErrorCodes.cryptoErrorKeyExpired;
+ jerr = gCryptoErrorCodes.cryptoErrorKeyExpired;
defaultMsg = "License expired";
break;
case ERROR_DRM_RESOURCE_BUSY:
- err = gCryptoErrorCodes.cryptoErrorResourceBusy;
+ jerr = gCryptoErrorCodes.cryptoErrorResourceBusy;
defaultMsg = "Resource busy or unavailable";
break;
case ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION:
- err = gCryptoErrorCodes.cryptoErrorInsufficientOutputProtection;
+ jerr = gCryptoErrorCodes.cryptoErrorInsufficientOutputProtection;
defaultMsg = "Required output protections are not active";
break;
case ERROR_DRM_SESSION_NOT_OPENED:
- err = gCryptoErrorCodes.cryptoErrorSessionNotOpened;
+ jerr = gCryptoErrorCodes.cryptoErrorSessionNotOpened;
defaultMsg = "Attempted to use a closed session";
break;
case ERROR_DRM_INSUFFICIENT_SECURITY:
- err = gCryptoErrorCodes.cryptoErrorInsufficientSecurity;
+ jerr = gCryptoErrorCodes.cryptoErrorInsufficientSecurity;
defaultMsg = "Required security level is not met";
break;
case ERROR_DRM_CANNOT_HANDLE:
- err = gCryptoErrorCodes.cryptoErrorUnsupportedOperation;
+ jerr = gCryptoErrorCodes.cryptoErrorUnsupportedOperation;
defaultMsg = "Operation not supported in this configuration";
break;
case ERROR_DRM_FRAME_TOO_LARGE:
- err = gCryptoErrorCodes.cryptoErrorFrameTooLarge;
+ jerr = gCryptoErrorCodes.cryptoErrorFrameTooLarge;
defaultMsg = "Decrytped frame exceeds size of output buffer";
break;
case ERROR_DRM_SESSION_LOST_STATE:
- err = gCryptoErrorCodes.cryptoErrorLostState;
+ jerr = gCryptoErrorCodes.cryptoErrorLostState;
defaultMsg = "Session state was lost, open a new session and retry";
break;
default: /* Other negative DRM error codes go out best-effort. */
- err = MediaErrorToJavaError(err);
+ jerr = MediaErrorToJavaError(err);
defaultMsg = StrCryptoError(err);
break;
}
@@ -1344,7 +1345,7 @@
jstring msgObj = env->NewStringUTF(msgStr.c_str());
jthrowable exception =
- (jthrowable)env->NewObject(clazz.get(), constructID, err, msgObj);
+ (jthrowable)env->NewObject(clazz.get(), constructID, jerr, msgObj);
env->Throw(exception);
}
diff --git a/packages/CompanionDeviceManager/res/values/strings.xml b/packages/CompanionDeviceManager/res/values/strings.xml
index 3d6bf15..a389bfc 100644
--- a/packages/CompanionDeviceManager/res/values/strings.xml
+++ b/packages/CompanionDeviceManager/res/values/strings.xml
@@ -20,7 +20,7 @@
<string name="app_label">Companion Device Manager</string>
<!-- Title of the device association confirmation dialog. -->
- <string name="confirmation_title">Allow <strong><xliff:g id="app_name" example="Android Wear">%1$s</xliff:g></strong> to manage your <strong><xliff:g id="device_name" example="ASUS ZenWatch 2">%2$s</xliff:g></strong></string>
+ <string name="confirmation_title">Allow <strong><xliff:g id="app_name" example="Android Wear">%1$s</xliff:g></strong> to access your <strong><xliff:g id="device_name" example="ASUS ZenWatch 2">%2$s</xliff:g></strong></string>
<!-- ================= DEVICE_PROFILE_WATCH and null profile ================= -->
@@ -31,10 +31,7 @@
<string name="chooser_title">Choose a <xliff:g id="profile_name" example="watch">%1$s</xliff:g> to be managed by <strong><xliff:g id="app_name" example="Android Wear">%2$s</xliff:g></strong></string>
<!-- Description of the privileges the application will get if associated with the companion device of WATCH profile (type) [CHAR LIMIT=NONE] -->
- <string name="summary_watch" product="default"><xliff:g id="app_name" example="Wear">%1$s</xliff:g> will be allowed to interact with your notifications and access your Phone, SMS, Contacts and Calendar permissions.</string>
-
- <!-- Description of the privileges the application will get if associated with the companion device of WATCH profile (type) [CHAR LIMIT=NONE] -->
- <string name="summary_watch" product="tablet"><xliff:g id="app_name" example="Wear">%1$s</xliff:g> will be allowed to interact with your notifications and access your Phone, SMS, Contacts and Calendar permissions.</string>
+ <string name="summary_watch">This app is needed to manage your <xliff:g id="device_name" example="My Watch">%1$s</xliff:g>. <xliff:g id="app_name" example="Android Wear">%2$s</xliff:g> will be allowed to interact with your notifications and access your Phone, SMS, Contacts, Calendar, Call logs and Nearby devices permissions.</string>
<!-- ================= DEVICE_PROFILE_APP_STREAMING ================= -->
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
index 9e9ec04..a3aa010 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java
@@ -497,17 +497,19 @@
}
final String deviceName = mSelectedDevice.getDisplayName();
- final Spanned title = getHtmlFromResources(
- this, R.string.confirmation_title, appLabel, deviceName);
+ final String profileName = getString(R.string.profile_name_watch);
+ final Spanned title;
final Spanned summary;
final Drawable profileIcon;
if (deviceProfile == null) {
+ title = getHtmlFromResources(this, R.string.confirmation_title, appLabel, deviceName);
summary = getHtmlFromResources(this, R.string.summary_generic);
profileIcon = getIcon(this, R.drawable.ic_device_other);
mSummary.setVisibility(View.GONE);
} else if (deviceProfile.equals(DEVICE_PROFILE_WATCH)) {
- summary = getHtmlFromResources(this, R.string.summary_watch, appLabel, deviceName);
+ title = getHtmlFromResources(this, R.string.confirmation_title, appLabel, profileName);
+ summary = getHtmlFromResources(this, R.string.summary_watch, deviceName, appLabel);
profileIcon = getIcon(this, R.drawable.ic_watch);
} else {
throw new RuntimeException("Unsupported profile " + deviceProfile);
@@ -535,7 +537,7 @@
mSummary.setVisibility(View.GONE);
} else if (deviceProfile.equals(DEVICE_PROFILE_WATCH)) {
profileName = getString(R.string.profile_name_watch);
- summary = getHtmlFromResources(this, R.string.summary_watch, appLabel);
+ summary = getHtmlFromResources(this, R.string.summary_watch, profileName, appLabel);
profileIcon = getIcon(this, R.drawable.ic_watch);
} else {
throw new RuntimeException("Unsupported profile " + deviceProfile);
diff --git a/packages/SettingsLib/AppPreference/res/layout/preference_app_header.xml b/packages/SettingsLib/AppPreference/res/layout/preference_app_header.xml
new file mode 100644
index 0000000..e0d01f9
--- /dev/null
+++ b/packages/SettingsLib/AppPreference/res/layout/preference_app_header.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:paddingBottom="16dp"
+ android:paddingTop="8dp"
+ android:clickable="false">
+
+ <TextView
+ android:id="@+id/apps_top_intro_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textDirection="locale"
+ android:clickable="false"
+ android:longClickable="false"
+ android:textAppearance="@style/TextAppearance.TopIntroText" />
+
+</LinearLayout>
diff --git a/packages/SettingsLib/SettingsTheme/res/values/styles.xml b/packages/SettingsLib/SettingsTheme/res/values/styles.xml
index aaab0f0..00bd141 100644
--- a/packages/SettingsLib/SettingsTheme/res/values/styles.xml
+++ b/packages/SettingsLib/SettingsTheme/res/values/styles.xml
@@ -26,4 +26,11 @@
<style name="TextAppearance.CategoryTitle.SettingsLib"
parent="@android:style/TextAppearance.DeviceDefault.Medium">
</style>
+
+ <style name="TextAppearance.TopIntroText"
+ parent="@android:style/TextAppearance.DeviceDefault">
+ <item name="android:textSize">14sp</item>
+ <item name="android:textColor">?android:attr/textColorSecondary</item>
+ </style>
+
</resources>
diff --git a/packages/SettingsLib/TopIntroPreference/Android.bp b/packages/SettingsLib/TopIntroPreference/Android.bp
index cd0bdea..ecf2a72 100644
--- a/packages/SettingsLib/TopIntroPreference/Android.bp
+++ b/packages/SettingsLib/TopIntroPreference/Android.bp
@@ -16,6 +16,7 @@
static_libs: [
"androidx.annotation_annotation",
"androidx.preference_preference",
+ "SettingsLibSettingsTheme",
],
sdk_version: "system_current",
min_sdk_version: "21",
diff --git a/packages/SettingsLib/TopIntroPreference/res/values/styles.xml b/packages/SettingsLib/TopIntroPreference/res/values/styles.xml
deleted file mode 100644
index b6ca41f..0000000
--- a/packages/SettingsLib/TopIntroPreference/res/values/styles.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2021 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.
- -->
-<resources>
- <style name="TextAppearance.TopIntroText"
- parent="@android:style/TextAppearance.DeviceDefault">
- <item name="android:textSize">14sp</item>
- <item name="android:textColor">?android:attr/textColorSecondary</item>
- </style>
-</resources>
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
index c9af4d5..fea7475 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
@@ -30,6 +30,9 @@
import java.io.IOException;
import java.util.List;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class BluetoothUtils {
private static final String TAG = "BluetoothUtils";
@@ -39,6 +42,8 @@
public static final int META_INT_ERROR = -1;
public static final String BT_ADVANCED_HEADER_ENABLED = "bt_advanced_header_enabled";
+ private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25;
+ private static final String KEY_HEARABLE_CONTROL_SLICE = "HEARABLE_CONTROL_SLICE_WITH_WIDTH";
private static ErrorListener sErrorListener;
@@ -384,8 +389,43 @@
return Uri.parse(data);
}
+ /**
+ * Get URI Bluetooth metadata for extra control
+ *
+ * @param bluetoothDevice the BluetoothDevice to get metadata
+ * @return the URI metadata
+ */
+ public static String getControlUriMetaData(BluetoothDevice bluetoothDevice) {
+ String data = getStringMetaData(bluetoothDevice, METADATA_FAST_PAIR_CUSTOMIZED_FIELDS);
+ return extraTagValue(KEY_HEARABLE_CONTROL_SLICE, data);
+ }
+
@SuppressLint("NewApi") // Hidden API made public
private static boolean doesClassMatch(BluetoothClass btClass, int classId) {
return btClass.doesClassMatch(classId);
}
+
+ private static String extraTagValue(String tag, String metaData) {
+ if (TextUtils.isEmpty(metaData)) {
+ return null;
+ }
+ Pattern pattern = Pattern.compile(generateExpressionWithTag(tag, "(.*?)"));
+ Matcher matcher = pattern.matcher(metaData);
+ if (matcher.find()) {
+ return matcher.group(1);
+ }
+ return null;
+ }
+
+ private static String getTagStart(String tag) {
+ return String.format(Locale.ENGLISH, "<%s>", tag);
+ }
+
+ private static String getTagEnd(String tag) {
+ return String.format(Locale.ENGLISH, "</%s>", tag);
+ }
+
+ private static String generateExpressionWithTag(String tag, String value) {
+ return getTagStart(tag) + value + getTagEnd(tag);
+ }
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
index 6919cf2..4229b68 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
@@ -77,6 +77,8 @@
private final LocalBluetoothProfileManager mProfileManager;
private final Object mProfileLock = new Object();
BluetoothDevice mDevice;
+ private int mDeviceSide;
+ private int mDeviceMode;
private long mHiSyncId;
private int mGroupId;
// Need this since there is no method for getting RSSI
@@ -335,6 +337,22 @@
connectDevice();
}
+ public int getDeviceSide() {
+ return mDeviceSide;
+ }
+
+ public void setDeviceSide(int side) {
+ mDeviceSide = side;
+ }
+
+ public int getDeviceMode() {
+ return mDeviceMode;
+ }
+
+ public void setDeviceMode(int mode) {
+ mDeviceMode = mode;
+ }
+
public long getHiSyncId() {
return mHiSyncId;
}
@@ -1111,7 +1129,8 @@
stringRes = R.string.bluetooth_battery_level;
}
- // Set active string in following device connected situation.
+ // Set active string in following device connected situation, also show battery
+ // information if they have.
// 1. Hearing Aid device active.
// 2. Headset device active with in-calling state.
// 3. A2DP device active without in-calling state.
@@ -1130,6 +1149,24 @@
stringRes = R.string.bluetooth_active_no_battery_level;
}
}
+
+ // Try to show left/right information if can not get it from battery for hearing
+ // aids specifically.
+ if (mIsActiveDeviceHearingAid
+ && stringRes == R.string.bluetooth_active_no_battery_level) {
+ final CachedBluetoothDevice subDevice = getSubDevice();
+ if (subDevice != null && subDevice.isConnected()) {
+ stringRes = R.string.bluetooth_hearing_aid_left_and_right_active;
+ } else {
+ if (mDeviceSide == HearingAidProfile.DeviceSide.SIDE_LEFT) {
+ stringRes = R.string.bluetooth_hearing_aid_left_active;
+ } else if (mDeviceSide == HearingAidProfile.DeviceSide.SIDE_RIGHT) {
+ stringRes = R.string.bluetooth_hearing_aid_right_active;
+ } else {
+ stringRes = R.string.bluetooth_active_no_battery_level;
+ }
+ }
+ }
}
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java
index 6f2d4de..a491455 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java
@@ -29,13 +29,48 @@
import android.content.Context;
import android.util.Log;
+import androidx.annotation.IntDef;
+import androidx.annotation.NonNull;
+
import com.android.settingslib.R;
import com.android.settingslib.Utils;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class HearingAidProfile implements LocalBluetoothProfile {
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ DeviceSide.SIDE_INVALID,
+ DeviceSide.SIDE_LEFT,
+ DeviceSide.SIDE_RIGHT
+ })
+
+ /** Side definition for hearing aids. See {@link BluetoothHearingAid}. */
+ public @interface DeviceSide {
+ int SIDE_INVALID = -1;
+ int SIDE_LEFT = 0;
+ int SIDE_RIGHT = 1;
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ DeviceMode.MODE_INVALID,
+ DeviceMode.MODE_MONAURAL,
+ DeviceMode.MODE_BINAURAL
+ })
+
+ /** Mode definition for hearing aids. See {@link BluetoothHearingAid}. */
+ public @interface DeviceMode {
+ int MODE_INVALID = -1;
+ int MODE_MONAURAL = 0;
+ int MODE_BINAURAL = 1;
+ }
+
private static final String TAG = "HearingAidProfile";
private static boolean V = true;
@@ -212,6 +247,11 @@
return isEnabled;
}
+ /**
+ * Tells remote device to set an absolute volume.
+ *
+ * @param volume Absolute volume to be set on remote
+ */
public void setVolume(int volume) {
if (mService == null) {
return;
@@ -219,6 +259,12 @@
mService.setVolume(volume);
}
+ /**
+ * Gets the HiSyncId (unique hearing aid device identifier) of the device.
+ *
+ * @param device Bluetooth device
+ * @return the HiSyncId of the device
+ */
public long getHiSyncId(BluetoothDevice device) {
if (mService == null || device == null) {
return BluetoothHearingAid.HI_SYNC_ID_INVALID;
@@ -226,6 +272,59 @@
return mService.getHiSyncId(device);
}
+ /**
+ * Gets the side of the device.
+ *
+ * @param device Bluetooth device.
+ * @return side of the device. See {@link DeviceSide}.
+ */
+ @DeviceSide
+ public int getDeviceSide(@NonNull BluetoothDevice device) {
+ final int defaultValue = DeviceSide.SIDE_INVALID;
+ if (mService == null) {
+ Log.w(TAG, "Proxy not attached to HearingAidService");
+ return defaultValue;
+ }
+
+ try {
+ Method method = mService.getClass().getDeclaredMethod("getDeviceSideInternal",
+ BluetoothDevice.class);
+ method.setAccessible(true);
+ return (int) method.invoke(mService, device);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ Log.e(TAG, "fail to get getDeviceSideInternal\n" + e.toString() + "\n"
+ + Log.getStackTraceString(new Throwable()));
+ return defaultValue;
+ }
+ }
+
+ /**
+ * Gets the mode of the device.
+ *
+ * @param device Bluetooth device
+ * @return mode of the device. See {@link DeviceMode}.
+ */
+ @DeviceMode
+ public int getDeviceMode(@NonNull BluetoothDevice device) {
+ final int defaultValue = DeviceMode.MODE_INVALID;
+ if (mService == null) {
+ Log.w(TAG, "Proxy not attached to HearingAidService");
+ return defaultValue;
+ }
+
+ try {
+ Method method = mService.getClass().getDeclaredMethod("getDeviceModeInternal",
+ BluetoothDevice.class);
+ method.setAccessible(true);
+ return (int) method.invoke(mService, device);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ Log.e(TAG, "fail to get getDeviceModeInternal\n" + e.toString() + "\n"
+ + Log.getStackTraceString(new Throwable()));
+
+ return defaultValue;
+ }
+ }
+
public String toString() {
return NAME;
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
index 0619986..58944f6 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
@@ -340,6 +340,11 @@
if (getHearingAidProfile() != null &&
mProfile instanceof HearingAidProfile &&
(newState == BluetoothProfile.STATE_CONNECTED)) {
+ final int side = getHearingAidProfile().getDeviceSide(cachedDevice.getDevice());
+ final int mode = getHearingAidProfile().getDeviceMode(cachedDevice.getDevice());
+ cachedDevice.setDeviceSide(side);
+ cachedDevice.setDeviceMode(mode);
+
// Check if the HiSyncID has being initialized
if (cachedDevice.getHiSyncId() == BluetoothHearingAid.HI_SYNC_ID_INVALID) {
long newHiSyncId = getHearingAidProfile().getHiSyncId(cachedDevice.getDevice());
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
index 2e85514..1c0ea1a 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
@@ -51,6 +51,11 @@
private static final String STRING_METADATA = "string_metadata";
private static final String BOOL_METADATA = "true";
private static final String INT_METADATA = "25";
+ private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25;
+ private static final String KEY_HEARABLE_CONTROL_SLICE = "HEARABLE_CONTROL_SLICE_WITH_WIDTH";
+ private static final String CONTROL_METADATA =
+ "<HEARABLE_CONTROL_SLICE_WITH_WIDTH>" + STRING_METADATA
+ + "</HEARABLE_CONTROL_SLICE_WITH_WIDTH>";
@Before
public void setUp() {
@@ -152,6 +157,15 @@
}
@Test
+ public void getControlUriMetaData_hasMetaData_returnsCorrectMetaData() {
+ when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)).thenReturn(
+ CONTROL_METADATA.getBytes());
+
+ assertThat(BluetoothUtils.getControlUriMetaData(mBluetoothDevice)).isEqualTo(
+ STRING_METADATA);
+ }
+
+ @Test
public void isAdvancedDetailsHeader_untetheredHeadset_returnTrue() {
when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
index 55d125e..be2a55e 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
@@ -78,6 +78,7 @@
@Mock
private BluetoothDevice mSubDevice;
private CachedBluetoothDevice mCachedDevice;
+ private CachedBluetoothDevice mSubCachedDevice;
private AudioManager mAudioManager;
private Context mContext;
private int mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
@@ -95,7 +96,9 @@
when(mPanProfile.isProfileReady()).thenReturn(true);
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
mCachedDevice = spy(new CachedBluetoothDevice(mContext, mProfileManager, mDevice));
+ mSubCachedDevice = spy(new CachedBluetoothDevice(mContext, mProfileManager, mSubDevice));
doAnswer((invocation) -> mBatteryLevel).when(mCachedDevice).getBatteryLevel();
+ doAnswer((invocation) -> mBatteryLevel).when(mSubCachedDevice).getBatteryLevel();
}
@Test
@@ -351,8 +354,9 @@
assertThat(mCachedDevice.getConnectionSummary()).isNull();
// Set device as Active for Hearing Aid and test connection state summary
+ mCachedDevice.setDeviceSide(HearingAidProfile.DeviceSide.SIDE_LEFT);
mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID);
- assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active");
+ assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active, left only");
// Set Hearing Aid profile to be disconnected and test connection state summary
mCachedDevice.onActiveDeviceChanged(false, BluetoothProfile.HEARING_AID);
@@ -390,17 +394,36 @@
}
@Test
- public void getConnectionSummary_testHearingAidInCall_returnActive() {
+ public void getConnectionSummary_testHearingAidRightEarInCall_returnActiveRightEar() {
// Arrange:
- // 1. Profile: {HEARING_AID, Connected, Active}
+ // 1. Profile: {HEARING_AID, Connected, Active, Right ear}
// 2. Audio Manager: In Call
updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED);
+ mCachedDevice.setDeviceSide(HearingAidProfile.DeviceSide.SIDE_RIGHT);
mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
// Act & Assert:
// Get "Active" result without Battery Level.
- assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active");
+ assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active, right only");
+ }
+
+ @Test
+ public void getConnectionSummary_testHearingAidBothEarInCall_returnActiveBothEar() {
+ // Arrange:
+ // 1. Profile: {HEARING_AID, Connected, Active, Both ear}
+ // 2. Audio Manager: In Call
+ mCachedDevice.setDeviceSide(HearingAidProfile.DeviceSide.SIDE_RIGHT);
+ updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED);
+ mSubCachedDevice.setDeviceSide(HearingAidProfile.DeviceSide.SIDE_LEFT);
+ updateSubDeviceProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED);
+ mCachedDevice.setSubDevice(mSubCachedDevice);
+ mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID);
+ mAudioManager.setMode(AudioManager.MODE_IN_CALL);
+
+ // Act & Assert:
+ // Get "Active" result without Battery Level.
+ assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active, left and right");
}
@Test
@@ -925,39 +948,41 @@
mCachedDevice.onProfileStateChanged(profile, status);
}
+ private void updateSubDeviceProfileStatus(LocalBluetoothProfile profile, int status) {
+ doReturn(status).when(profile).getConnectionStatus(mSubDevice);
+ mSubCachedDevice.onProfileStateChanged(profile, status);
+ }
+
@Test
public void getSubDevice_setSubDevice() {
- CachedBluetoothDevice subCachedDevice = new CachedBluetoothDevice(mContext, mProfileManager,
- mSubDevice);
- mCachedDevice.setSubDevice(subCachedDevice);
+ mCachedDevice.setSubDevice(mSubCachedDevice);
- assertThat(mCachedDevice.getSubDevice()).isEqualTo(subCachedDevice);
+ assertThat(mCachedDevice.getSubDevice()).isEqualTo(mSubCachedDevice);
}
@Test
public void switchSubDeviceContent() {
- CachedBluetoothDevice subCachedDevice = new CachedBluetoothDevice(mContext, mProfileManager,
- mSubDevice);
+
mCachedDevice.mRssi = RSSI_1;
mCachedDevice.mJustDiscovered = JUSTDISCOVERED_1;
- subCachedDevice.mRssi = RSSI_2;
- subCachedDevice.mJustDiscovered = JUSTDISCOVERED_2;
- mCachedDevice.setSubDevice(subCachedDevice);
+ mSubCachedDevice.mRssi = RSSI_2;
+ mSubCachedDevice.mJustDiscovered = JUSTDISCOVERED_2;
+ mCachedDevice.setSubDevice(mSubCachedDevice);
assertThat(mCachedDevice.mRssi).isEqualTo(RSSI_1);
assertThat(mCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_1);
assertThat(mCachedDevice.mDevice).isEqualTo(mDevice);
- assertThat(subCachedDevice.mRssi).isEqualTo(RSSI_2);
- assertThat(subCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_2);
- assertThat(subCachedDevice.mDevice).isEqualTo(mSubDevice);
+ assertThat(mSubCachedDevice.mRssi).isEqualTo(RSSI_2);
+ assertThat(mSubCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_2);
+ assertThat(mSubCachedDevice.mDevice).isEqualTo(mSubDevice);
mCachedDevice.switchSubDeviceContent();
assertThat(mCachedDevice.mRssi).isEqualTo(RSSI_2);
assertThat(mCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_2);
assertThat(mCachedDevice.mDevice).isEqualTo(mSubDevice);
- assertThat(subCachedDevice.mRssi).isEqualTo(RSSI_1);
- assertThat(subCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_1);
- assertThat(subCachedDevice.mDevice).isEqualTo(mDevice);
+ assertThat(mSubCachedDevice.mRssi).isEqualTo(RSSI_1);
+ assertThat(mSubCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_1);
+ assertThat(mSubCachedDevice.mDevice).isEqualTo(mDevice);
}
@Test
diff --git a/packages/SystemUI/res/drawable/overlay_cancel.xml b/packages/SystemUI/res/drawable/overlay_cancel.xml
index f9786e2..3fa12dd 100644
--- a/packages/SystemUI/res/drawable/overlay_cancel.xml
+++ b/packages/SystemUI/res/drawable/overlay_cancel.xml
@@ -24,6 +24,6 @@
android:fillColor="?androidprv:attr/colorAccentTertiary"
android:pathData="M16,16m-16,0a16,16 0,1 1,32 0a16,16 0,1 1,-32 0"/>
<path
- android:fillColor="?android:attr/textColorPrimary"
+ android:fillColor="?attr/overlayButtonTextColor"
android:pathData="M23,10.41L21.59,9 16,14.59 10.41,9 9,10.41 14.59,16 9,21.59 10.41,23 16,17.41 21.59,23 23,21.59 17.41,16z"/>
</vector>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 2c3d947..7010a28 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -804,6 +804,14 @@
<!-- Message shown when non-bypass face authentication succeeds and UDFPS is supported. Provides extra instructions for how the user can enter their device [CHAR LIMIT=60] -->
<string name="keyguard_face_successful_unlock_press">Unlocked by face. Press the unlock icon to open.</string>
+ <!-- Messages shown when users press outside of udfps region during -->
+ <string-array name="udfps_accessibility_touch_hints">
+ <item>Move left</item>
+ <item>Move down</item>
+ <item>Move right</item>
+ <item>Move up</item>
+ </string-array>
+
<!-- Message shown when face authentication fails and the pin pad is visible. [CHAR LIMIT=60] -->
<string name="keyguard_retry">Swipe up to try again</string>
@@ -2271,6 +2279,8 @@
<string name="media_output_dialog_unknown_launch_app_name">Unknown app</string>
<!-- Button text for stopping casting [CHAR LIMIT=60] -->
<string name="media_output_dialog_button_stop_casting">Stop casting</string>
+ <!-- Accessibility text describing purpose of media output dialog. [CHAR LIMIT=NONE] -->
+ <string name="media_output_dialog_accessibility_title">Available devices for audio output.</string>
<!-- Media Output Broadcast Dialog -->
<!-- Title for Broadcast First Notify Dialog [CHAR LIMIT=60] -->
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
index 5c9f5db..2cc5ccdc 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
@@ -32,6 +32,7 @@
import android.content.Context;
import android.graphics.Insets;
import android.graphics.Rect;
+import android.os.Trace;
import android.util.AttributeSet;
import android.view.WindowInsetsAnimationControlListener;
import android.view.WindowInsetsAnimationController;
@@ -44,6 +45,7 @@
import com.android.internal.widget.LockscreenCredential;
import com.android.internal.widget.TextViewInputDisabler;
+import com.android.systemui.DejankUtils;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
/**
@@ -194,9 +196,17 @@
@Override
public void onAnimationEnd(Animator animation) {
- controller.finish(false);
- runOnFinishImeAnimationRunnable();
- finishRunnable.run();
+ // Run this in the next frame since it results in a slow binder call
+ // to InputMethodManager#hideSoftInput()
+ DejankUtils.postAfterTraversal(() -> {
+ Trace.beginSection("KeyguardPasswordView#onAnimationEnd");
+ // // TODO(b/230620476): Make hideSoftInput oneway
+ // controller.finish() eventually calls hideSoftInput
+ controller.finish(false);
+ runOnFinishImeAnimationRunnable();
+ finishRunnable.run();
+ Trace.endSection();
+ });
}
});
anim.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN);
diff --git a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java
index ab831be0..680b8bd 100644
--- a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java
@@ -188,7 +188,6 @@
protected void onViewAttached() {
updateIsUdfpsEnrolled();
updateConfiguration();
- updateLockIconLocation();
updateKeyguardShowing();
mUserUnlockedWithBiometric = false;
@@ -347,6 +346,7 @@
R.string.accessibility_unlock_button);
mLockedLabel = mView.getContext()
.getResources().getString(R.string.accessibility_lock_icon);
+ updateLockIconLocation();
}
private void updateLockIconLocation() {
@@ -691,7 +691,6 @@
mExecutor.execute(() -> {
updateIsUdfpsEnrolled();
updateConfiguration();
- updateLockIconLocation();
});
}
@@ -708,7 +707,7 @@
@Override
public void onUdfpsLocationChanged() {
- updateLockIconLocation();
+ updateUdfpsConfig();
}
};
diff --git a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
index 3d0c08b..fe6dbe5 100644
--- a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
@@ -46,6 +46,8 @@
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.wm.shell.animation.FlingAnimationUtils;
+import java.util.function.Consumer;
+
public class SwipeHelper implements Gefingerpoken {
static final String TAG = "com.android.systemui.SwipeHelper";
private static final boolean DEBUG = false;
@@ -399,7 +401,7 @@
* @param useAccelerateInterpolator Should an accelerating Interpolator be used
* @param fixedDuration If not 0, this exact duration will be taken
*/
- public void dismissChild(final View animView, float velocity, final Runnable endAction,
+ public void dismissChild(final View animView, float velocity, final Consumer<Boolean> endAction,
long delay, boolean useAccelerateInterpolator, long fixedDuration,
boolean isDismissAll) {
final boolean canBeDismissed = mCallback.canChildBeDismissed(animView);
@@ -487,7 +489,7 @@
resetSwipeState();
}
if (endAction != null) {
- endAction.run();
+ endAction.accept(mCancelled);
}
if (!mDisableHwLayers) {
animView.setLayerType(View.LAYER_TYPE_NONE, null);
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewController.kt
index 5cfbdb0..742c65c 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewController.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewController.kt
@@ -192,4 +192,9 @@
* Called on touches outside of the view if listenForTouchesOutsideView returns true
*/
open fun onTouchOutsideView() {}
+
+ /**
+ * Called when a view should announce an accessibility event.
+ */
+ open fun doAnnounceForAccessibility(str: String) {}
}
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
index 9febaa0..88e467f 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java
@@ -381,6 +381,27 @@
&& mOverlayParams.getSensorBounds().contains((int) x, (int) y);
}
+ private Point getTouchInNativeCoordinates(@NonNull MotionEvent event, int idx) {
+ Point portraitTouch = new Point(
+ (int) event.getRawX(idx),
+ (int) event.getRawY(idx)
+ );
+ final int rot = mOverlayParams.getRotation();
+ if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
+ RotationUtils.rotatePoint(portraitTouch,
+ RotationUtils.deltaRotation(rot, Surface.ROTATION_0),
+ mOverlayParams.getLogicalDisplayWidth(),
+ mOverlayParams.getLogicalDisplayHeight()
+ );
+ }
+
+ // Scale the coordinates to native resolution.
+ final float scale = mOverlayParams.getScaleFactor();
+ portraitTouch.x = (int) (portraitTouch.x / scale);
+ portraitTouch.y = (int) (portraitTouch.y / scale);
+ return portraitTouch;
+ }
+
@VisibleForTesting
boolean onTouch(long requestId, @NonNull MotionEvent event, boolean fromUdfpsView) {
if (mOverlay == null) {
@@ -434,6 +455,7 @@
mKeyguardViewManager.notifyKeyguardAuthenticated(false /* strongAuth */);
mAttemptedToDismissKeyguard = true;
}
+
Trace.endSection();
break;
@@ -457,6 +479,8 @@
mAttemptedToDismissKeyguard = true;
break;
}
+ // Map the touch to portrait mode if the device is in landscape mode.
+ final Point scaledTouch = getTouchInNativeCoordinates(event, idx);
if (actionMoveWithinSensorArea) {
if (mVelocityTracker == null) {
// touches could be injected, so the velocity tracker may not have
@@ -477,28 +501,13 @@
final long sinceLastLog = mSystemClock.elapsedRealtime() - mTouchLogTime;
if (!isIlluminationRequested && !mAcquiredReceived
&& !exceedsVelocityThreshold) {
- // Map the touch to portrait mode if the device is in landscape mode.
- Point portraitTouch = new Point(
- (int) event.getRawX(idx),
- (int) event.getRawY(idx)
- );
- final int rot = mOverlayParams.getRotation();
- if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
- RotationUtils.rotatePoint(portraitTouch,
- RotationUtils.deltaRotation(rot, Surface.ROTATION_0),
- mOverlayParams.getLogicalDisplayWidth(),
- mOverlayParams.getLogicalDisplayHeight()
- );
- }
- // Scale the coordinates to native resolution.
final float scale = mOverlayParams.getScaleFactor();
- int scaledX = (int) (portraitTouch.x / scale);
- int scaledY = (int) (portraitTouch.y / scale);
float scaledMinor = minor / scale;
float scaledMajor = major / scale;
- onFingerDown(requestId, scaledX, scaledY, scaledMinor, scaledMajor);
+ onFingerDown(requestId, scaledTouch.x, scaledTouch.y, scaledMinor,
+ scaledMajor);
Log.v(TAG, "onTouch | finger down: " + touchInfo);
mTouchLogTime = mSystemClock.elapsedRealtime();
mPowerManager.userActivity(mSystemClock.uptimeMillis(),
@@ -511,6 +520,24 @@
} else {
Log.v(TAG, "onTouch | finger outside");
onFingerUp(requestId, udfpsView);
+ // Maybe announce for accessibility.
+ mFgExecutor.execute(() -> {
+ if (mOverlay == null) {
+ Log.e(TAG, "touch outside sensor area received"
+ + "but serverRequest is null");
+ return;
+ }
+ // Scale the coordinates to native resolution.
+ final float scale = mOverlayParams.getScaleFactor();
+ final float scaledSensorX =
+ mOverlayParams.getSensorBounds().centerX() / scale;
+ final float scaledSensorY =
+ mOverlayParams.getSensorBounds().centerY() / scale;
+
+ mOverlay.onTouchOutsideOfSensorArea(
+ scaledTouch.x, scaledTouch.y, scaledSensorX, scaledSensorY,
+ mOverlayParams.getRotation());
+ });
}
}
Trace.endSection();
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsControllerOverlay.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsControllerOverlay.kt
index faa93a5..37db2bd 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsControllerOverlay.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsControllerOverlay.kt
@@ -130,6 +130,8 @@
val animationViewController: UdfpsAnimationViewController<*>?
get() = overlayView?.animationViewController
+ private var touchExplorationEnabled = false
+
/** Show the overlay or return false and do nothing if it is already showing. */
@SuppressLint("ClickableViewAccessibility")
fun show(controller: UdfpsController, params: UdfpsOverlayParams): Boolean {
@@ -154,14 +156,16 @@
}
windowManager.addView(this, coreLayoutParams.updateDimensions(animation))
-
+ touchExplorationEnabled = accessibilityManager.isTouchExplorationEnabled
overlayTouchListener = TouchExplorationStateChangeListener {
if (accessibilityManager.isTouchExplorationEnabled) {
setOnHoverListener { v, event -> onTouch(v, event, true) }
setOnTouchListener(null)
+ touchExplorationEnabled = true
} else {
setOnHoverListener(null)
setOnTouchListener { v, event -> onTouch(v, event, true) }
+ touchExplorationEnabled = false
}
}
accessibilityManager.addTouchExplorationStateChangeListener(
@@ -179,7 +183,7 @@
return false
}
- private fun inflateUdfpsAnimation(
+ fun inflateUdfpsAnimation(
view: UdfpsView,
controller: UdfpsController
): UdfpsAnimationViewController<*>? {
@@ -278,6 +282,88 @@
enrollHelper?.onEnrollmentHelp()
}
+ /**
+ * This function computes the angle of touch relative to the sensor and maps
+ * the angle to a list of help messages which are announced if accessibility is enabled.
+ *
+ */
+ fun onTouchOutsideOfSensorArea(
+ touchX: Float,
+ touchY: Float,
+ sensorX: Float,
+ sensorY: Float,
+ rotation: Int
+ ) {
+
+ if (!touchExplorationEnabled) {
+ return
+ }
+ val touchHints =
+ context.resources.getStringArray(R.array.udfps_accessibility_touch_hints)
+ if (touchHints.size != 4) {
+ Log.e(TAG, "expected exactly 4 touch hints, got $touchHints.size?")
+ return
+ }
+ val theStr = onTouchOutsideOfSensorAreaImpl(touchX, touchY, sensorX, sensorY, rotation)
+ Log.v(TAG, "Announcing touch outside : " + theStr)
+ animationViewController?.doAnnounceForAccessibility(theStr)
+ }
+
+ /**
+ * This function computes the angle of touch relative to the sensor and maps
+ * the angle to a list of help messages which are announced if accessibility is enabled.
+ *
+ * There are 4 quadrants of the circle (90 degree arcs)
+ *
+ * [315, 360] && [0, 45) -> touchHints[0] = "Move Fingerprint to the left"
+ * [45, 135) -> touchHints[1] = "Move Fingerprint down"
+ * And so on.
+ */
+ fun onTouchOutsideOfSensorAreaImpl(
+ touchX: Float,
+ touchY: Float,
+ sensorX: Float,
+ sensorY: Float,
+ rotation: Int
+ ): String {
+ val touchHints =
+ context.resources.getStringArray(R.array.udfps_accessibility_touch_hints)
+
+ val xRelativeToSensor = touchX - sensorX
+ // Touch coordinates are with respect to the upper left corner, so reverse
+ // this calculation
+ val yRelativeToSensor = sensorY - touchY
+
+ var angleInRad =
+ Math.atan2(yRelativeToSensor.toDouble(), xRelativeToSensor.toDouble())
+ // If the radians are negative, that means we are counting clockwise.
+ // So we need to add 360 degrees
+ if (angleInRad < 0.0) {
+ angleInRad += 2.0 * Math.PI
+ }
+ // rad to deg conversion
+ val degrees = Math.toDegrees(angleInRad)
+
+ val degreesPerBucket = 360.0 / touchHints.size
+ val halfBucketDegrees = degreesPerBucket / 2.0
+ // The mapping should be as follows
+ // [315, 360] && [0, 45] -> 0
+ // [45, 135] -> 1
+ var index = (((degrees + halfBucketDegrees) % 360) / degreesPerBucket).toInt()
+ index %= touchHints.size
+
+ // A rotation of 90 degrees corresponds to increasing the index by 1.
+ if (rotation == Surface.ROTATION_90) {
+ index = (index + 1) % touchHints.size
+ }
+
+ if (rotation == Surface.ROTATION_270) {
+ index = (index + 3) % touchHints.size
+ }
+
+ return touchHints[index]
+ }
+
/** Cancel this request. */
fun cancel() {
try {
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsEnrollViewController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsEnrollViewController.java
index 2ed60e5..0b7bdde 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsEnrollViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsEnrollViewController.java
@@ -99,4 +99,10 @@
public int getPaddingY() {
return mEnrollProgressBarRadius;
}
+
+ @Override
+ public void doAnnounceForAccessibility(String str) {
+ mView.announceForAccessibility(str);
+ }
+
}
diff --git a/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt b/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt
index 25effec..db446c3 100644
--- a/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt
+++ b/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt
@@ -19,13 +19,14 @@
import android.os.Trace
import android.util.Log
import com.android.systemui.log.dagger.LogModule
+import com.android.systemui.util.collection.RingBuffer
import java.io.PrintWriter
import java.text.SimpleDateFormat
-import java.util.ArrayDeque
import java.util.Locale
import java.util.concurrent.ArrayBlockingQueue
import java.util.concurrent.BlockingQueue
import kotlin.concurrent.thread
+import kotlin.math.max
/**
* A simple ring buffer of recyclable log messages
@@ -63,29 +64,22 @@
*
* Buffers are provided by [LogModule]. Instances should be created using a [LogBufferFactory].
*
- * @param name The name of this buffer
- * @param maxLogs The maximum number of messages to keep in memory at any one time, including the
- * unused pool. Must be >= [poolSize].
- * @param poolSize The maximum amount that the size of the buffer is allowed to flex in response to
- * sequential calls to [document] that aren't immediately followed by a matching call to [push].
+ * @param name The name of this buffer, printed when the buffer is dumped and in some other
+ * situations.
+ * @param maxSize The maximum number of messages to keep in memory at any one time. Buffers start
+ * out empty and grow up to [maxSize] as new messages are logged. Once the buffer's size reaches
+ * the maximum, it behaves like a ring buffer.
*/
class LogBuffer @JvmOverloads constructor(
private val name: String,
- private val maxLogs: Int,
- private val poolSize: Int,
+ private val maxSize: Int,
private val logcatEchoTracker: LogcatEchoTracker,
private val systrace: Boolean = true
) {
- init {
- if (maxLogs < poolSize) {
- throw IllegalArgumentException("maxLogs must be greater than or equal to poolSize, " +
- "but maxLogs=$maxLogs < $poolSize=poolSize")
- }
- }
+ private val buffer = RingBuffer(maxSize) { LogMessageImpl.create() }
- private val buffer: ArrayDeque<LogMessageImpl> = ArrayDeque()
- private val echoMessageQueue: BlockingQueue<LogMessageImpl>? =
- if (logcatEchoTracker.logInBackgroundThread) ArrayBlockingQueue(poolSize) else null
+ private val echoMessageQueue: BlockingQueue<LogMessage>? =
+ if (logcatEchoTracker.logInBackgroundThread) ArrayBlockingQueue(10) else null
init {
if (logcatEchoTracker.logInBackgroundThread && echoMessageQueue != null) {
@@ -104,6 +98,9 @@
var frozen = false
private set
+ private val mutable
+ get() = !frozen && maxSize > 0
+
/**
* Logs a message to the log buffer
*
@@ -138,34 +135,19 @@
initializer: LogMessage.() -> Unit,
noinline printer: LogMessage.() -> String
) {
- if (!frozen) {
- val message = obtain(tag, level, printer)
- initializer(message)
- push(message)
- }
- }
-
- /**
- * Same as [log], but doesn't push the message to the buffer. Useful if you need to supply a
- * "reason" for doing something (the thing you supply the reason to will presumably call [push]
- * on that message at some point).
- */
- inline fun document(
- tag: String,
- level: LogLevel,
- initializer: LogMessage.() -> Unit,
- noinline printer: LogMessage.() -> String
- ): LogMessage {
val message = obtain(tag, level, printer)
initializer(message)
- return message
+ commit(message)
}
/**
- * Obtains an instance of [LogMessageImpl], usually from the object pool. If the pool has been
- * exhausted, creates a new instance.
+ * You should call [log] instead of this method.
*
- * In general, you should call [log] or [document] instead of this method.
+ * Obtains the next [LogMessage] from the ring buffer. If the buffer is not yet at max size,
+ * grows the buffer by one.
+ *
+ * After calling [obtain], the message will now be at the end of the buffer. The caller must
+ * store any relevant data on the message and then call [commit].
*/
@Synchronized
fun obtain(
@@ -173,28 +155,26 @@
level: LogLevel,
printer: (LogMessage) -> String
): LogMessageImpl {
- val message = when {
- frozen -> LogMessageImpl.create()
- buffer.size > maxLogs - poolSize -> buffer.removeFirst()
- else -> LogMessageImpl.create()
+ if (!mutable) {
+ return FROZEN_MESSAGE
}
+ val message = buffer.advance()
message.reset(tag, level, System.currentTimeMillis(), printer)
return message
}
/**
- * Pushes a message into buffer, possibly evicting an older message if the buffer is full.
+ * You should call [log] instead of this method.
+ *
+ * After acquiring a message via [obtain], call this method to signal to the buffer that you
+ * have finished filling in its data fields. The message will be echoed to logcat if
+ * necessary.
*/
@Synchronized
- fun push(message: LogMessage) {
- if (frozen) {
+ fun commit(message: LogMessage) {
+ if (!mutable) {
return
}
- if (buffer.size == maxLogs) {
- Log.e(TAG, "LogBuffer $name has exceeded its pool size")
- buffer.removeFirst()
- }
- buffer.add(message as LogMessageImpl)
// Log in the background thread only if echoMessageQueue exists and has capacity (checking
// capacity avoids the possibility of blocking this thread)
if (echoMessageQueue != null && echoMessageQueue.remainingCapacity() > 0) {
@@ -210,7 +190,7 @@
}
/** Sends message to echo after determining whether to use Logcat and/or systrace. */
- private fun echoToDesiredEndpoints(message: LogMessageImpl) {
+ private fun echoToDesiredEndpoints(message: LogMessage) {
val includeInLogcat = logcatEchoTracker.isBufferLoggable(name, message.level) ||
logcatEchoTracker.isTagLoggable(message.tag, message.level)
echo(message, toLogcat = includeInLogcat, toSystrace = systrace)
@@ -219,19 +199,17 @@
/** Converts the entire buffer to a newline-delimited string */
@Synchronized
fun dump(pw: PrintWriter, tailLength: Int) {
- val start = if (tailLength <= 0) { 0 } else { buffer.size - tailLength }
+ val iterationStart = if (tailLength <= 0) { 0 } else { max(0, buffer.size - tailLength) }
- for ((i, message) in buffer.withIndex()) {
- if (i >= start) {
- dumpMessage(message, pw)
- }
+ for (i in iterationStart until buffer.size) {
+ dumpMessage(buffer[i], pw)
}
}
/**
- * "Freezes" the contents of the buffer, making them immutable until [unfreeze] is called.
- * Calls to [log], [document], [obtain], and [push] will not affect the buffer and will return
- * dummy values if necessary.
+ * "Freezes" the contents of the buffer, making it immutable until [unfreeze] is called.
+ * Calls to [log], [obtain], and [commit] will not affect the buffer and will return dummy
+ * values if necessary.
*/
@Synchronized
fun freeze() {
@@ -293,3 +271,4 @@
private const val TAG = "LogBuffer"
private val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.US)
+private val FROZEN_MESSAGE = LogMessageImpl.create()
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/log/LogBufferFactory.kt b/packages/SystemUI/src/com/android/systemui/log/LogBufferFactory.kt
index cbfca25..5651399 100644
--- a/packages/SystemUI/src/com/android/systemui/log/LogBufferFactory.kt
+++ b/packages/SystemUI/src/com/android/systemui/log/LogBufferFactory.kt
@@ -27,22 +27,21 @@
private val logcatEchoTracker: LogcatEchoTracker
) {
/* limit the size of maxPoolSize for low ram (Go) devices */
- private fun poolLimit(maxPoolSize_requested: Int): Int {
- if (ActivityManager.isLowRamDeviceStatic()) {
- return minOf(maxPoolSize_requested, 20) /* low ram max log size*/
+ private fun adjustMaxSize(requestedMaxSize: Int): Int {
+ return if (ActivityManager.isLowRamDeviceStatic()) {
+ minOf(requestedMaxSize, 20) /* low ram max log size*/
} else {
- return maxPoolSize_requested
+ requestedMaxSize
}
}
@JvmOverloads
fun create(
name: String,
- maxPoolSize: Int,
- flexSize: Int = 10,
+ maxSize: Int,
systrace: Boolean = true
): LogBuffer {
- val buffer = LogBuffer(name, poolLimit(maxPoolSize), flexSize, logcatEchoTracker, systrace)
+ val buffer = LogBuffer(name, adjustMaxSize(maxSize), logcatEchoTracker, systrace)
dumpManager.registerBuffer(name, buffer)
return buffer
}
diff --git a/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerDebug.kt b/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerDebug.kt
index 91734cc..40b0cdc 100644
--- a/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerDebug.kt
+++ b/packages/SystemUI/src/com/android/systemui/log/LogcatEchoTrackerDebug.kt
@@ -60,7 +60,7 @@
Settings.Global.getUriFor(BUFFER_PATH),
true,
object : ContentObserver(Handler(mainLooper)) {
- override fun onChange(selfChange: Boolean, uri: Uri) {
+ override fun onChange(selfChange: Boolean, uri: Uri?) {
super.onChange(selfChange, uri)
cachedBufferLevels.clear()
}
@@ -70,7 +70,7 @@
Settings.Global.getUriFor(TAG_PATH),
true,
object : ContentObserver(Handler(mainLooper)) {
- override fun onChange(selfChange: Boolean, uri: Uri) {
+ override fun onChange(selfChange: Boolean, uri: Uri?) {
super.onChange(selfChange, uri)
cachedTagLevels.clear()
}
@@ -110,7 +110,7 @@
}
private fun parseProp(propValue: String?): LogLevel {
- return when (propValue?.toLowerCase()) {
+ return when (propValue?.lowercase()) {
"verbose" -> LogLevel.VERBOSE
"v" -> LogLevel.VERBOSE
"debug" -> LogLevel.DEBUG
diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
index 1e7a292..eff025f 100644
--- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
+++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java
@@ -49,8 +49,7 @@
@SysUISingleton
@NotificationLog
public static LogBuffer provideNotificationsLogBuffer(LogBufferFactory factory) {
- return factory.create("NotifLog", 1000 /* maxPoolSize */,
- 10 /* flexSize */, false /* systrace */);
+ return factory.create("NotifLog", 1000 /* maxSize */, false /* systrace */);
}
/** Provides a logging buffer for all logs related to the data layer of notifications. */
@@ -74,8 +73,7 @@
@SysUISingleton
@NotificationSectionLog
public static LogBuffer provideNotificationSectionLogBuffer(LogBufferFactory factory) {
- return factory.create("NotifSectionLog", 1000 /* maxPoolSize */,
- 10 /* flexSize */, false /* systrace */);
+ return factory.create("NotifSectionLog", 1000 /* maxSize */, false /* systrace */);
}
/** Provides a logging buffer for all logs related to the data layer of notifications. */
@@ -91,8 +89,7 @@
@SysUISingleton
@QSLog
public static LogBuffer provideQuickSettingsLogBuffer(LogBufferFactory factory) {
- return factory.create("QSLog", 500 /* maxPoolSize */,
- 10 /* flexSize */, false /* systrace */);
+ return factory.create("QSLog", 500 /* maxSize */, false /* systrace */);
}
/** Provides a logging buffer for {@link com.android.systemui.broadcast.BroadcastDispatcher} */
@@ -100,8 +97,8 @@
@SysUISingleton
@BroadcastDispatcherLog
public static LogBuffer provideBroadcastDispatcherLogBuffer(LogBufferFactory factory) {
- return factory.create("BroadcastDispatcherLog", 500 /* maxPoolSize */,
- 10 /* flexSize */, false /* systrace */);
+ return factory.create("BroadcastDispatcherLog", 500 /* maxSize */,
+ false /* systrace */);
}
/** Provides a logging buffer for all logs related to Toasts shown by SystemUI. */
@@ -139,8 +136,8 @@
@SysUISingleton
@QSFragmentDisableLog
public static LogBuffer provideQSFragmentDisableLogBuffer(LogBufferFactory factory) {
- return factory.create("QSFragmentDisableFlagsLog", 10 /* maxPoolSize */,
- 10 /* flexSize */, false /* systrace */);
+ return factory.create("QSFragmentDisableFlagsLog", 10 /* maxSize */,
+ false /* systrace */);
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java
index 1a727f8..fa6db01 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java
@@ -227,9 +227,7 @@
lp.setFitInsetsIgnoringVisibility(true);
window.setAttributes(lp);
window.setContentView(mDialogView);
- // Sets window to a blank string to avoid talkback announce app label first when pop up,
- // which doesn't make sense.
- window.setTitle(EMPTY_TITLE);
+ window.setTitle(mContext.getString(R.string.media_output_dialog_accessibility_title));
mHeaderTitle = mDialogView.requireViewById(R.id.header_title);
mHeaderSubtitle = mDialogView.requireViewById(R.id.header_subtitle);
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java
index 58b6ad3..9329b1b 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java
@@ -573,6 +573,7 @@
}
boolean addDeviceToPlayMedia(MediaDevice device) {
+ mMetricLogger.logInteractionExpansion(device);
return mLocalMediaManager.addDeviceToPlayMedia(device);
}
@@ -613,6 +614,7 @@
}
void releaseSession() {
+ mMetricLogger.logInteractionStopCasting();
mLocalMediaManager.releaseSession();
}
@@ -627,6 +629,7 @@
}
void adjustVolume(MediaDevice device, int volume) {
+ mMetricLogger.logInteractionAdjustVolume(device);
ThreadUtils.postOnBackgroundThread(() -> {
device.requestSetVolume(volume);
});
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputMetricLogger.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputMetricLogger.java
index ac0295e..5d7af52 100644
--- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputMetricLogger.java
+++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputMetricLogger.java
@@ -96,6 +96,49 @@
}
/**
+ * Do the metric logging of volume adjustment.
+ * @param source the device been adjusted
+ */
+ public void logInteractionAdjustVolume(MediaDevice source) {
+ if (DEBUG) {
+ Log.d(TAG, "logInteraction - AdjustVolume");
+ }
+
+ SysUiStatsLog.write(
+ SysUiStatsLog.MEDIAOUTPUT_OP_INTERACTION_REPORT,
+ SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__INTERACTION_TYPE__ADJUST_VOLUME,
+ getInteractionDeviceType(source));
+ }
+
+ /**
+ * Do the metric logging of stop casting.
+ */
+ public void logInteractionStopCasting() {
+ if (DEBUG) {
+ Log.d(TAG, "logInteraction - Stop casting");
+ }
+
+ SysUiStatsLog.write(
+ SysUiStatsLog.MEDIAOUTPUT_OP_INTERACTION_REPORT,
+ SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__INTERACTION_TYPE__STOP_CASTING,
+ SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__UNKNOWN_TYPE);
+ }
+
+ /**
+ * Do the metric logging of device expansion.
+ */
+ public void logInteractionExpansion(MediaDevice source) {
+ if (DEBUG) {
+ Log.d(TAG, "logInteraction - Expansion");
+ }
+
+ SysUiStatsLog.write(
+ SysUiStatsLog.MEDIAOUTPUT_OP_INTERACTION_REPORT,
+ SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__INTERACTION_TYPE__EXPANSION,
+ getInteractionDeviceType(source));
+ }
+
+ /**
* Do the metric logging of content switching failure.
* @param deviceList media device list for device count updating
* @param reason the reason of content switching failure
@@ -185,6 +228,27 @@
}
}
+ private int getInteractionDeviceType(MediaDevice device) {
+ switch (device.getDeviceType()) {
+ case MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE:
+ return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__BUILTIN_SPEAKER;
+ case MediaDevice.MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE:
+ return SysUiStatsLog
+ .MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__WIRED_3POINT5_MM_AUDIO;
+ case MediaDevice.MediaDeviceType.TYPE_USB_C_AUDIO_DEVICE:
+ return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__USB_C_AUDIO;
+ case MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE:
+ return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__BLUETOOTH;
+ case MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE:
+ return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__REMOTE_SINGLE;
+ case MediaDevice.MediaDeviceType.TYPE_CAST_GROUP_DEVICE:
+ return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__REMOTE_GROUP;
+ default:
+ return SysUiStatsLog.MEDIA_OUTPUT_OP_INTERACTION_REPORTED__TARGET__UNKNOWN_TYPE;
+ }
+ }
+
+
private int getLoggingSwitchOpSubResult(int reason) {
switch (reason) {
case REASON_REJECTED:
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java
index 48bb2af..79939c8 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotView.java
@@ -820,7 +820,7 @@
animateDismissal();
});
actionChip.setAlpha(1);
- mActionsView.addView(actionChip);
+ mActionsView.addView(actionChip, mActionsView.getChildCount() - 1);
mSmartChips.add(actionChip);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/scrim/ScrimView.java b/packages/SystemUI/src/com/android/systemui/scrim/ScrimView.java
index 7530681..f68e042 100644
--- a/packages/SystemUI/src/com/android/systemui/scrim/ScrimView.java
+++ b/packages/SystemUI/src/com/android/systemui/scrim/ScrimView.java
@@ -58,6 +58,7 @@
private Drawable mDrawable;
private PorterDuffColorFilter mColorFilter;
private int mTintColor;
+ private boolean mBlendWithMainColor = true;
private Runnable mChangeRunnable;
private Executor mChangeRunnableExecutor;
private Executor mExecutor;
@@ -192,6 +193,19 @@
}
/**
+ * The call to {@link #setTint} will blend with the main color, with the amount
+ * determined by the alpha of the tint. Set to false to avoid this blend.
+ */
+ public void setBlendWithMainColor(boolean blend) {
+ mBlendWithMainColor = blend;
+ }
+
+ /** @return true if blending tint color with main color */
+ public boolean shouldBlendWithMainColor() {
+ return mBlendWithMainColor;
+ }
+
+ /**
* Tints this view, optionally animating it.
* @param color The color.
* @param animated If we should animate.
@@ -211,8 +225,11 @@
// Optimization to blend colors and avoid a color filter
ScrimDrawable drawable = (ScrimDrawable) mDrawable;
float tintAmount = Color.alpha(mTintColor) / 255f;
- int mainTinted = ColorUtils.blendARGB(mColors.getMainColor(), mTintColor,
- tintAmount);
+
+ int mainTinted = mTintColor;
+ if (mBlendWithMainColor) {
+ mainTinted = ColorUtils.blendARGB(mColors.getMainColor(), mTintColor, tintAmount);
+ }
drawable.setColor(mainTinted, animated);
} else {
boolean hasAlpha = Color.alpha(mTintColor) != 0;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationActivityStarter.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationActivityStarter.java
index 129fa5a..0c341cc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationActivityStarter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationActivityStarter.java
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.notification;
import android.content.Intent;
-import android.service.notification.StatusBarNotification;
import android.view.View;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -29,7 +28,7 @@
*/
public interface NotificationActivityStarter {
/** Called when the user clicks on the surface of a notification. */
- void onNotificationClicked(StatusBarNotification sbn, ExpandableNotificationRow row);
+ void onNotificationClicked(NotificationEntry entry, ExpandableNotificationRow row);
/** Called when the user clicks on a button in the notification guts which fires an intent. */
void startNotificationGutsIntent(Intent intent, int appUid,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClicker.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClicker.java
index 392145a..c3ce593 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClicker.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClicker.java
@@ -104,7 +104,7 @@
mBubblesOptional.get().collapseStack();
}
- mNotificationActivityStarter.onNotificationClicked(entry.getSbn(), row);
+ mNotificationActivityStarter.onNotificationClicked(entry, row);
}
private boolean isMenuVisible(ExpandableNotificationRow row) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClickerLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClickerLogger.kt
index fbf033b..ad3dfed 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClickerLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationClickerLogger.kt
@@ -27,7 +27,7 @@
) {
fun logOnClick(entry: NotificationEntry) {
buffer.log(TAG, LogLevel.DEBUG, {
- str1 = entry.key
+ str1 = entry.logKey
str2 = entry.ranking.channel.id
}, {
"CLICK $str1 (channel=$str2)"
@@ -36,7 +36,7 @@
fun logMenuVisible(entry: NotificationEntry) {
buffer.log(TAG, LogLevel.DEBUG, {
- str1 = entry.key
+ str1 = entry.logKey
}, {
"Ignoring click on $str1; menu is visible"
})
@@ -44,7 +44,7 @@
fun logParentMenuVisible(entry: NotificationEntry) {
buffer.log(TAG, LogLevel.DEBUG, {
- str1 = entry.key
+ str1 = entry.logKey
}, {
"Ignoring click on $str1; parent menu is visible"
})
@@ -52,7 +52,7 @@
fun logChildrenExpanded(entry: NotificationEntry) {
buffer.log(TAG, LogLevel.DEBUG, {
- str1 = entry.key
+ str1 = entry.logKey
}, {
"Ignoring click on $str1; children are expanded"
})
@@ -60,7 +60,7 @@
fun logGutsExposed(entry: NotificationEntry) {
buffer.log(TAG, LogLevel.DEBUG, {
- str1 = entry.key
+ str1 = entry.logKey
}, {
"Ignoring click on $str1; guts are exposed"
})
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationUtils.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationUtils.java
index c3cc97b..7cfb157 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationUtils.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationUtils.java
@@ -24,7 +24,8 @@
import com.android.internal.util.ContrastColorUtil;
import com.android.systemui.R;
-import com.android.systemui.statusbar.notification.collection.NotificationEntry;
+import com.android.systemui.statusbar.notification.collection.ListEntry;
+import com.android.systemui.util.Compile;
/**
* A util class for various reusable functions
@@ -74,12 +75,18 @@
return (int) (dimensionPixelSize * factor);
}
+ private static final boolean INCLUDE_HASH_CODE_IN_LIST_ENTRY_LOG_KEY = false;
+
/** Get the notification key, reformatted for logging, for the (optional) entry */
- public static String logKey(NotificationEntry entry) {
+ public static String logKey(ListEntry entry) {
if (entry == null) {
return "null";
}
- return logKey(entry.getKey());
+ if (Compile.IS_DEBUG && INCLUDE_HASH_CODE_IN_LIST_ENTRY_LOG_KEY) {
+ return logKey(entry.getKey()) + "@" + Integer.toHexString(entry.hashCode());
+ } else {
+ return logKey(entry.getKey());
+ }
}
/** Removes newlines from the notification key to prettify apps that have these in the tag */
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationUtils.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationUtils.kt
new file mode 100644
index 0000000..432bac4
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationUtils.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.systemui.statusbar.notification
+
+import android.service.notification.StatusBarNotification
+import com.android.systemui.statusbar.notification.collection.ListEntry
+
+/** Get the notification key, reformatted for logging, for the (optional) entry */
+val ListEntry?.logKey: String?
+ get() = this?.let { NotificationUtils.logKey(it) }
+
+/** Get the notification key, reformatted for logging, for the (optional) sbn */
+val StatusBarNotification?.logKey: String?
+ get() = this?.key?.let { NotificationUtils.logKey(it) }
+
+/** Removes newlines from the notification key to prettify apps that have these in the tag */
+fun logKey(key: String?): String? = NotificationUtils.logKey(key)
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
index bcd8e59..6085096 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
@@ -18,9 +18,12 @@
import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL;
import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL;
+import static android.service.notification.NotificationListenerService.REASON_ASSISTANT_CANCEL;
import static android.service.notification.NotificationListenerService.REASON_CANCEL;
import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL;
import static android.service.notification.NotificationListenerService.REASON_CHANNEL_BANNED;
+import static android.service.notification.NotificationListenerService.REASON_CHANNEL_REMOVED;
+import static android.service.notification.NotificationListenerService.REASON_CLEAR_DATA;
import static android.service.notification.NotificationListenerService.REASON_CLICK;
import static android.service.notification.NotificationListenerService.REASON_ERROR;
import static android.service.notification.NotificationListenerService.REASON_GROUP_OPTIMIZATION;
@@ -36,9 +39,11 @@
import static android.service.notification.NotificationListenerService.REASON_UNAUTOBUNDLED;
import static android.service.notification.NotificationListenerService.REASON_USER_STOPPED;
+import static com.android.systemui.statusbar.notification.NotificationUtils.logKey;
import static com.android.systemui.statusbar.notification.collection.NotificationEntry.DismissState.DISMISSED;
import static com.android.systemui.statusbar.notification.collection.NotificationEntry.DismissState.NOT_DISMISSED;
import static com.android.systemui.statusbar.notification.collection.NotificationEntry.DismissState.PARENT_DISMISSED;
+import static com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionLoggerKt.cancellationReasonDebugString;
import static java.util.Objects.requireNonNull;
@@ -99,6 +104,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -143,6 +149,7 @@
private final Map<String, NotificationEntry> mNotificationSet = new ArrayMap<>();
private final Collection<NotificationEntry> mReadOnlyNotificationSet =
Collections.unmodifiableCollection(mNotificationSet.values());
+ private final HashMap<String, FutureDismissal> mFutureDismissals = new HashMap<>();
@Nullable private CollectionReadyForBuildListener mBuildListener;
private final List<NotifCollectionListener> mNotifCollectionListeners = new ArrayList<>();
@@ -511,6 +518,7 @@
cancelDismissInterception(entry);
mEventQueue.add(new EntryRemovedEvent(entry, entry.mCancellationReason));
mEventQueue.add(new CleanUpEntryEvent(entry));
+ handleFutureDismissal(entry);
return true;
} else {
return false;
@@ -519,31 +527,32 @@
/**
* Get the group summary entry
- * @param group
+ * @param groupKey
* @return
*/
@Nullable
- public NotificationEntry getGroupSummary(String group) {
+ public NotificationEntry getGroupSummary(String groupKey) {
return mNotificationSet
.values()
.stream()
- .filter(it -> Objects.equals(it.getSbn().getGroup(), group))
+ .filter(it -> Objects.equals(it.getSbn().getGroupKey(), groupKey))
.filter(it -> it.getSbn().getNotification().isGroupSummary())
.findFirst().orElse(null);
}
/**
- * Checks if the entry is the only child in the logical group
- * @param entry
- * @return
+ * Checks if the entry is the only child in the logical group;
+ * it need not have a summary to qualify
+ *
+ * @param entry the entry to check
*/
public boolean isOnlyChildInGroup(NotificationEntry entry) {
- String group = entry.getSbn().getGroup();
+ String groupKey = entry.getSbn().getGroupKey();
return mNotificationSet.get(entry.getKey()) == entry
&& mNotificationSet
.values()
.stream()
- .filter(it -> Objects.equals(it.getSbn().getGroup(), group))
+ .filter(it -> Objects.equals(it.getSbn().getGroupKey(), groupKey))
.filter(it -> !it.getSbn().getNotification().isGroupSummary())
.count() == 1;
}
@@ -916,10 +925,139 @@
dispatchEventsAndRebuildList();
}
+ /**
+ * A method to alert the collection that an async operation is happening, at the end of which a
+ * dismissal request will be made. This method has the additional guarantee that if a parent
+ * notification exists for a single child, then that notification will also be dismissed.
+ *
+ * The runnable returned must be run at the end of the async operation to enact the cancellation
+ *
+ * @param entry the notification we want to dismiss
+ * @param cancellationReason the reason for the cancellation
+ * @param statsCreator the callback for generating the stats for an entry
+ * @return the runnable to be run when the dismissal is ready to happen
+ */
+ public Runnable registerFutureDismissal(NotificationEntry entry, int cancellationReason,
+ DismissedByUserStatsCreator statsCreator) {
+ FutureDismissal dismissal = mFutureDismissals.get(entry.getKey());
+ if (dismissal != null) {
+ mLogger.logFutureDismissalReused(dismissal);
+ return dismissal;
+ }
+ dismissal = new FutureDismissal(entry, cancellationReason, statsCreator);
+ mFutureDismissals.put(entry.getKey(), dismissal);
+ mLogger.logFutureDismissalRegistered(dismissal);
+ return dismissal;
+ }
+
+ private void handleFutureDismissal(NotificationEntry entry) {
+ final FutureDismissal futureDismissal = mFutureDismissals.remove(entry.getKey());
+ if (futureDismissal != null) {
+ futureDismissal.onSystemServerCancel(entry.mCancellationReason);
+ }
+ }
+
+ /** A single method interface that callers can pass in when registering future dismissals */
+ public interface DismissedByUserStatsCreator {
+ DismissedByUserStats createDismissedByUserStats(NotificationEntry entry);
+ }
+
+ /** A class which tracks the double dismissal events coming in from both the system server and
+ * the ui */
+ public class FutureDismissal implements Runnable {
+ private final NotificationEntry mEntry;
+ private final DismissedByUserStatsCreator mStatsCreator;
+ @Nullable
+ private final NotificationEntry mSummaryToDismiss;
+ private final String mLabel;
+
+ private boolean mDidRun;
+ private boolean mDidSystemServerCancel;
+
+ private FutureDismissal(NotificationEntry entry, @CancellationReason int cancellationReason,
+ DismissedByUserStatsCreator statsCreator) {
+ mEntry = entry;
+ mStatsCreator = statsCreator;
+ mSummaryToDismiss = fetchSummaryToDismiss(entry);
+ mLabel = "<FutureDismissal@" + Integer.toHexString(hashCode())
+ + " entry=" + logKey(mEntry)
+ + " reason=" + cancellationReasonDebugString(cancellationReason)
+ + " summary=" + logKey(mSummaryToDismiss)
+ + ">";
+ }
+
+ @Nullable
+ private NotificationEntry fetchSummaryToDismiss(NotificationEntry entry) {
+ if (isOnlyChildInGroup(entry)) {
+ String group = entry.getSbn().getGroupKey();
+ NotificationEntry summary = getGroupSummary(group);
+ if (summary != null && summary.isDismissable()) return summary;
+ }
+ return null;
+ }
+
+ /** called when the entry has been removed from the collection */
+ public void onSystemServerCancel(@CancellationReason int cancellationReason) {
+ Assert.isMainThread();
+ if (mDidSystemServerCancel) {
+ mLogger.logFutureDismissalDoubleCancelledByServer(this);
+ return;
+ }
+ mLogger.logFutureDismissalGotSystemServerCancel(this, cancellationReason);
+ mDidSystemServerCancel = true;
+ // TODO: Internally dismiss the summary now instead of waiting for onUiCancel
+ }
+
+ private void onUiCancel() {
+ mFutureDismissals.remove(mEntry.getKey());
+ final NotificationEntry currentEntry = getEntry(mEntry.getKey());
+ // generate stats for the entry before dismissing summary, which could affect state
+ final DismissedByUserStats stats = mStatsCreator.createDismissedByUserStats(mEntry);
+ // dismiss the summary (if it exists)
+ if (mSummaryToDismiss != null) {
+ final NotificationEntry currentSummary = getEntry(mSummaryToDismiss.getKey());
+ if (currentSummary == mSummaryToDismiss) {
+ mLogger.logFutureDismissalDismissing(this, "summary");
+ dismissNotification(mSummaryToDismiss,
+ mStatsCreator.createDismissedByUserStats(mSummaryToDismiss));
+ } else {
+ mLogger.logFutureDismissalMismatchedEntry(this, "summary", currentSummary);
+ }
+ }
+ // dismiss this entry (if it is still around)
+ if (mDidSystemServerCancel) {
+ mLogger.logFutureDismissalAlreadyCancelledByServer(this);
+ } else if (currentEntry == mEntry) {
+ mLogger.logFutureDismissalDismissing(this, "entry");
+ dismissNotification(mEntry, stats);
+ } else {
+ mLogger.logFutureDismissalMismatchedEntry(this, "entry", currentEntry);
+ }
+ }
+
+ /** called when the dismissal should be completed */
+ @Override
+ public void run() {
+ Assert.isMainThread();
+ if (mDidRun) {
+ mLogger.logFutureDismissalDoubleRun(this);
+ return;
+ }
+ mDidRun = true;
+ onUiCancel();
+ }
+
+ /** provides a debug label for this instance */
+ public String getLabel() {
+ return mLabel;
+ }
+ }
+
@IntDef(prefix = { "REASON_" }, value = {
REASON_NOT_CANCELED,
REASON_UNKNOWN,
REASON_CLICK,
+ REASON_CANCEL,
REASON_CANCEL_ALL,
REASON_ERROR,
REASON_PACKAGE_CHANGED,
@@ -937,6 +1075,9 @@
REASON_CHANNEL_BANNED,
REASON_SNOOZED,
REASON_TIMEOUT,
+ REASON_CHANNEL_REMOVED,
+ REASON_CLEAR_DATA,
+ REASON_ASSISTANT_CANCEL,
})
@Retention(RetentionPolicy.SOURCE)
public @interface CancellationReason {}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ActivityLaunchAnimCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ActivityLaunchAnimCoordinator.kt
deleted file mode 100644
index b54163d..0000000
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ActivityLaunchAnimCoordinator.kt
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.statusbar.notification.collection.coordinator
-
-import com.android.systemui.statusbar.notification.collection.NotifPipeline
-import com.android.systemui.statusbar.notification.collection.NotificationEntry
-import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
-import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender
-import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender.OnEndLifetimeExtensionCallback
-import com.android.systemui.statusbar.phone.NotifActivityLaunchEvents
-import dagger.Binds
-import dagger.Module
-import javax.inject.Inject
-
-/** Extends the lifetime of notifications while their activity launch animation is playing. */
-interface ActivityLaunchAnimCoordinator : Coordinator
-
-/** Provides an [ActivityLaunchAnimCoordinator] to [CoordinatorScope]. */
-@Module(includes = [PrivateActivityStarterCoordinatorModule::class])
-object ActivityLaunchAnimCoordinatorModule
-
-@Module
-private interface PrivateActivityStarterCoordinatorModule {
- @Binds
- fun bindCoordinator(impl: ActivityLaunchAnimCoordinatorImpl): ActivityLaunchAnimCoordinator
-}
-
-/**
- * Listens for [NotifActivityLaunchEvents], and then extends the lifetimes of any notifs while their
- * launch animation is playing.
- */
-@CoordinatorScope
-private class ActivityLaunchAnimCoordinatorImpl @Inject constructor(
- private val activityLaunchEvents: NotifActivityLaunchEvents
-) : ActivityLaunchAnimCoordinator {
- // Tracks notification launches, and whether or not their lifetimes are extended.
- private val notifsLaunchingActivities = mutableMapOf<String, Boolean>()
-
- private var onEndLifetimeExtensionCallback: OnEndLifetimeExtensionCallback? = null
-
- override fun attach(pipeline: NotifPipeline) {
- activityLaunchEvents.registerListener(activityStartEventListener)
- pipeline.addNotificationLifetimeExtender(extender)
- }
-
- private val activityStartEventListener = object : NotifActivityLaunchEvents.Listener {
- override fun onStartLaunchNotifActivity(entry: NotificationEntry) {
- notifsLaunchingActivities[entry.key] = false
- }
-
- override fun onFinishLaunchNotifActivity(entry: NotificationEntry) {
- if (notifsLaunchingActivities.remove(entry.key) == true) {
- // If we were extending the lifetime of this notification, stop.
- onEndLifetimeExtensionCallback?.onEndLifetimeExtension(extender, entry)
- }
- }
- }
-
- private val extender = object : NotifLifetimeExtender {
- override fun getName(): String = "ActivityStarterCoordinator"
-
- override fun setCallback(callback: OnEndLifetimeExtensionCallback) {
- onEndLifetimeExtensionCallback = callback
- }
-
- override fun maybeExtendLifetime(entry: NotificationEntry, reason: Int): Boolean {
- if (entry.key in notifsLaunchingActivities) {
- // Track that we're now extending this notif
- notifsLaunchingActivities[entry.key] = true
- return true
- }
- return false
- }
-
- override fun cancelLifetimeExtension(entry: NotificationEntry) {
- if (entry.key in notifsLaunchingActivities) {
- notifsLaunchingActivities[entry.key] = false
- }
- }
- }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt
index b24d292..0b3a0dc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt
@@ -56,7 +56,6 @@
smartspaceDedupingCoordinator: SmartspaceDedupingCoordinator,
viewConfigCoordinator: ViewConfigCoordinator,
visualStabilityCoordinator: VisualStabilityCoordinator,
- activityLaunchAnimCoordinator: ActivityLaunchAnimCoordinator
) : NotifCoordinators {
private val mCoordinators: MutableList<Coordinator> = ArrayList()
@@ -93,7 +92,6 @@
mCoordinators.add(shadeEventCoordinator)
mCoordinators.add(viewConfigCoordinator)
mCoordinators.add(visualStabilityCoordinator)
- mCoordinators.add(activityLaunchAnimCoordinator)
if (notifPipelineFlags.isSmartspaceDedupingEnabled()) {
mCoordinators.add(smartspaceDedupingCoordinator)
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/dagger/CoordinatorsModule.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/dagger/CoordinatorsModule.kt
index 8ecffcb..839cf0d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/dagger/CoordinatorsModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/dagger/CoordinatorsModule.kt
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.notification.collection.coordinator.dagger
import com.android.systemui.dagger.SysUISingleton
-import com.android.systemui.statusbar.notification.collection.coordinator.ActivityLaunchAnimCoordinatorModule
import com.android.systemui.statusbar.notification.collection.coordinator.NotifCoordinators
import com.android.systemui.statusbar.notification.collection.coordinator.NotifCoordinatorsImpl
import dagger.Binds
@@ -48,7 +47,6 @@
}
@Module(includes = [
- ActivityLaunchAnimCoordinatorModule::class,
])
private abstract class InternalCoordinatorsModule {
@Binds
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/inflation/OnUserInteractionCallbackImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/inflation/OnUserInteractionCallbackImpl.java
index 3bd91b5..7dd3672 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/inflation/OnUserInteractionCallbackImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/inflation/OnUserInteractionCallbackImpl.java
@@ -18,17 +18,17 @@
import static android.service.notification.NotificationStats.DISMISS_SENTIMENT_NEUTRAL;
-import android.annotation.Nullable;
import android.os.SystemClock;
-import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationStats;
+import androidx.annotation.NonNull;
+
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.collection.NotifCollection;
+import com.android.systemui.statusbar.notification.collection.NotifCollection.CancellationReason;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.coordinator.VisualStabilityCoordinator;
import com.android.systemui.statusbar.notification.collection.notifcollection.DismissedByUserStats;
-import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager;
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
import com.android.systemui.statusbar.notification.row.OnUserInteractionCallback;
import com.android.systemui.statusbar.policy.HeadsUpManager;
@@ -43,54 +43,33 @@
private final HeadsUpManager mHeadsUpManager;
private final StatusBarStateController mStatusBarStateController;
private final VisualStabilityCoordinator mVisualStabilityCoordinator;
- private final GroupMembershipManager mGroupMembershipManager;
public OnUserInteractionCallbackImpl(
NotificationVisibilityProvider visibilityProvider,
NotifCollection notifCollection,
HeadsUpManager headsUpManager,
StatusBarStateController statusBarStateController,
- VisualStabilityCoordinator visualStabilityCoordinator,
- GroupMembershipManager groupMembershipManager
+ VisualStabilityCoordinator visualStabilityCoordinator
) {
mVisibilityProvider = visibilityProvider;
mNotifCollection = notifCollection;
mHeadsUpManager = headsUpManager;
mStatusBarStateController = statusBarStateController;
mVisualStabilityCoordinator = visualStabilityCoordinator;
- mGroupMembershipManager = groupMembershipManager;
}
- /**
- * Callback triggered when a user:
- * 1. Manually dismisses a notification {@see ExpandableNotificationRow}.
- * 2. Clicks on a notification with flag {@link android.app.Notification#FLAG_AUTO_CANCEL}.
- * {@see StatusBarNotificationActivityStarter}
- */
- @Override
- public void onDismiss(
- NotificationEntry entry,
- @NotificationListenerService.NotificationCancelReason int cancellationReason,
- @Nullable NotificationEntry groupSummaryToDismiss
- ) {
+ @NonNull
+ private DismissedByUserStats getDismissedByUserStats(NotificationEntry entry) {
int dismissalSurface = NotificationStats.DISMISSAL_SHADE;
if (mHeadsUpManager.isAlerting(entry.getKey())) {
dismissalSurface = NotificationStats.DISMISSAL_PEEK;
} else if (mStatusBarStateController.isDozing()) {
dismissalSurface = NotificationStats.DISMISSAL_AOD;
}
-
- if (groupSummaryToDismiss != null) {
- onDismiss(groupSummaryToDismiss, cancellationReason, null);
- }
-
- mNotifCollection.dismissNotification(
- entry,
- new DismissedByUserStats(
- dismissalSurface,
- DISMISS_SENTIMENT_NEUTRAL,
- mVisibilityProvider.obtain(entry, true))
- );
+ return new DismissedByUserStats(
+ dismissalSurface,
+ DISMISS_SENTIMENT_NEUTRAL,
+ mVisibilityProvider.obtain(entry, true));
}
@Override
@@ -100,19 +79,11 @@
SystemClock.uptimeMillis());
}
- /**
- * @param entry that is being dismissed
- * @return the group summary to dismiss along with this entry if this is the last entry in
- * the group. Else, returns null.
- */
+ @NonNull
@Override
- @Nullable
- public NotificationEntry getGroupSummaryToDismiss(NotificationEntry entry) {
- String group = entry.getSbn().getGroup();
- if (mNotifCollection.isOnlyChildInGroup(entry)) {
- NotificationEntry summary = mNotifCollection.getGroupSummary(group);
- if (summary != null && summary.isDismissable()) return summary;
- }
- return null;
+ public Runnable registerFutureDismissal(@NonNull NotificationEntry entry,
+ @CancellationReason int cancellationReason) {
+ return mNotifCollection.registerFutureDismissal(
+ entry, cancellationReason, this::getDismissedByUserStats);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/legacy/OnUserInteractionCallbackImplLegacy.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/legacy/OnUserInteractionCallbackImplLegacy.java
index 8daf8be..103b14b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/legacy/OnUserInteractionCallbackImplLegacy.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/legacy/OnUserInteractionCallbackImplLegacy.java
@@ -18,12 +18,15 @@
import static android.service.notification.NotificationStats.DISMISS_SENTIMENT_NEUTRAL;
-import android.annotation.Nullable;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationStats;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
+import com.android.systemui.statusbar.notification.collection.NotifCollection.CancellationReason;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.notifcollection.DismissedByUserStats;
import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager;
@@ -68,8 +71,7 @@
* along with this dismissal. If null, does not additionally
* dismiss any notifications.
*/
- @Override
- public void onDismiss(
+ private void onDismiss(
NotificationEntry entry,
@NotificationListenerService.NotificationCancelReason int cancellationReason,
@Nullable NotificationEntry groupSummaryToDismiss
@@ -106,14 +108,21 @@
* @return the group summary to dismiss along with this entry if this is the last entry in
* the group. Else, returns null.
*/
- @Override
@Nullable
- public NotificationEntry getGroupSummaryToDismiss(NotificationEntry entry) {
+ private NotificationEntry getGroupSummaryToDismiss(NotificationEntry entry) {
if (mGroupMembershipManager.isOnlyChildInGroup(entry)) {
NotificationEntry groupSummary = mGroupMembershipManager.getLogicalGroupSummary(entry);
return groupSummary.isDismissable() ? groupSummary : null;
}
return null;
}
+
+ @Override
+ @NonNull
+ public Runnable registerFutureDismissal(@NonNull NotificationEntry entry,
+ @CancellationReason int cancellationReason) {
+ NotificationEntry groupSummaryToDismiss = getGroupSummaryToDismiss(entry);
+ return () -> onDismiss(entry, cancellationReason, groupSummaryToDismiss);
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt
index 7302de5..7e79367 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt
@@ -28,7 +28,9 @@
import com.android.systemui.log.dagger.NotificationLog
import com.android.systemui.statusbar.notification.collection.NotifCollection
import com.android.systemui.statusbar.notification.collection.NotifCollection.CancellationReason
+import com.android.systemui.statusbar.notification.collection.NotifCollection.FutureDismissal
import com.android.systemui.statusbar.notification.collection.NotificationEntry
+import com.android.systemui.statusbar.notification.logKey
import javax.inject.Inject
fun cancellationReasonDebugString(@CancellationReason reason: Int) =
@@ -36,6 +38,7 @@
-1 -> "REASON_NOT_CANCELED" // NotifCollection.REASON_NOT_CANCELED
NotifCollection.REASON_UNKNOWN -> "REASON_UNKNOWN"
NotificationListenerService.REASON_CLICK -> "REASON_CLICK"
+ NotificationListenerService.REASON_CANCEL -> "REASON_CANCEL"
NotificationListenerService.REASON_CANCEL_ALL -> "REASON_CANCEL_ALL"
NotificationListenerService.REASON_ERROR -> "REASON_ERROR"
NotificationListenerService.REASON_PACKAGE_CHANGED -> "REASON_PACKAGE_CHANGED"
@@ -53,6 +56,9 @@
NotificationListenerService.REASON_CHANNEL_BANNED -> "REASON_CHANNEL_BANNED"
NotificationListenerService.REASON_SNOOZED -> "REASON_SNOOZED"
NotificationListenerService.REASON_TIMEOUT -> "REASON_TIMEOUT"
+ NotificationListenerService.REASON_CHANNEL_REMOVED -> "REASON_CHANNEL_REMOVED"
+ NotificationListenerService.REASON_CLEAR_DATA -> "REASON_CLEAR_DATA"
+ NotificationListenerService.REASON_ASSISTANT_CANCEL -> "REASON_ASSISTANT_CANCEL"
else -> "unknown"
}
@@ -241,6 +247,81 @@
"ERROR suppressed due to initialization forgiveness: $str1"
})
}
+
+ fun logFutureDismissalReused(dismissal: FutureDismissal) {
+ buffer.log(TAG, INFO, {
+ str1 = dismissal.label
+ }, {
+ "Reusing existing registration: $str1"
+ })
+ }
+
+ fun logFutureDismissalRegistered(dismissal: FutureDismissal) {
+ buffer.log(TAG, DEBUG, {
+ str1 = dismissal.label
+ }, {
+ "Registered: $str1"
+ })
+ }
+
+ fun logFutureDismissalDoubleCancelledByServer(dismissal: FutureDismissal) {
+ buffer.log(TAG, WARNING, {
+ str1 = dismissal.label
+ }, {
+ "System server double cancelled: $str1"
+ })
+ }
+
+ fun logFutureDismissalDoubleRun(dismissal: FutureDismissal) {
+ buffer.log(TAG, WARNING, {
+ str1 = dismissal.label
+ }, {
+ "Double run: $str1"
+ })
+ }
+
+ fun logFutureDismissalAlreadyCancelledByServer(dismissal: FutureDismissal) {
+ buffer.log(TAG, DEBUG, {
+ str1 = dismissal.label
+ }, {
+ "Ignoring: entry already cancelled by server: $str1"
+ })
+ }
+
+ fun logFutureDismissalGotSystemServerCancel(
+ dismissal: FutureDismissal,
+ @CancellationReason cancellationReason: Int
+ ) {
+ buffer.log(TAG, DEBUG, {
+ str1 = dismissal.label
+ int1 = cancellationReason
+ }, {
+ "SystemServer cancelled: $str1 reason=${cancellationReasonDebugString(int1)}"
+ })
+ }
+
+ fun logFutureDismissalDismissing(dismissal: FutureDismissal, type: String) {
+ buffer.log(TAG, DEBUG, {
+ str1 = dismissal.label
+ str2 = type
+ }, {
+ "Dismissing $str2 for: $str1"
+ })
+ }
+
+ fun logFutureDismissalMismatchedEntry(
+ dismissal: FutureDismissal,
+ type: String,
+ latestEntry: NotificationEntry?
+ ) {
+ buffer.log(TAG, WARNING, {
+ str1 = dismissal.label
+ str2 = type
+ str3 = latestEntry.logKey
+ }, {
+ "Mismatch: current $str2 is $str3 for: $str1"
+ })
+ }
}
private const val TAG = "NotifCollection"
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
index d96590a..c9c7fe9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
@@ -88,7 +88,6 @@
import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm;
import com.android.systemui.statusbar.phone.CentralSurfaces;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
-import com.android.systemui.statusbar.phone.NotifActivityLaunchEventsModule;
import com.android.systemui.statusbar.phone.NotifPanelEventsModule;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
@@ -111,7 +110,6 @@
@Module(includes = {
CoordinatorsModule.class,
KeyguardNotificationVisibilityProviderModule.class,
- NotifActivityLaunchEventsModule.class,
NotifPanelEventsModule.class,
NotifPipelineChoreographerModule.class,
NotificationSectionHeadersModule.class,
@@ -350,8 +348,7 @@
notifCollection.get(),
headsUpManager,
statusBarStateController,
- visualStabilityCoordinator.get(),
- groupMembershipManagerLazy.get())
+ visualStabilityCoordinator.get())
: new OnUserInteractionCallbackImplLegacy(
entryManager,
visibilityProvider.get(),
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
index f975799..d5088ac 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.notification.row;
import static android.app.Notification.Action.SEMANTIC_ACTION_MARK_CONVERSATION_AS_PRIORITY;
-import static android.os.UserHandle.USER_SYSTEM;
import static android.service.notification.NotificationListenerService.REASON_CANCEL;
import static com.android.systemui.statusbar.notification.row.NotificationContentView.VISIBLE_TYPE_HEADSUP;
@@ -34,8 +33,6 @@
import android.app.NotificationChannel;
import android.app.role.RoleManager;
import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Canvas;
@@ -51,7 +48,6 @@
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Trace;
-import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.ArraySet;
import android.util.AttributeSet;
@@ -113,7 +109,6 @@
import com.android.systemui.statusbar.notification.stack.NotificationChildrenContainer;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.notification.stack.SwipeableView;
-import com.android.systemui.statusbar.phone.CentralSurfaces;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.InflatedSmartReplyState;
@@ -1428,8 +1423,7 @@
dismiss(fromAccessibility);
if (mEntry.isDismissable()) {
if (mOnUserInteractionCallback != null) {
- mOnUserInteractionCallback.onDismiss(mEntry, REASON_CANCEL,
- mOnUserInteractionCallback.getGroupSummaryToDismiss(mEntry));
+ mOnUserInteractionCallback.registerFutureDismissal(mEntry, REASON_CANCEL).run();
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/OnUserInteractionCallback.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/OnUserInteractionCallback.java
index 94c5507..98d4353 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/OnUserInteractionCallback.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/OnUserInteractionCallback.java
@@ -16,8 +16,9 @@
package com.android.systemui.statusbar.notification.row;
-import android.service.notification.NotificationListenerService;
+import androidx.annotation.NonNull;
+import com.android.systemui.statusbar.notification.collection.NotifCollection.CancellationReason;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
/**
@@ -26,29 +27,23 @@
public interface OnUserInteractionCallback {
/**
- * Handle a user interaction that triggers a notification dismissal. Called when a user clicks
- * on an auto-cancelled notification or manually swipes to dismiss the notification.
- *
- * @param entry notification being dismissed
- * @param cancellationReason reason for the cancellation
- * @param groupSummaryToDismiss group summary to dismiss with `entry`.
- */
- void onDismiss(
- NotificationEntry entry,
- @NotificationListenerService.NotificationCancelReason int cancellationReason,
- NotificationEntry groupSummaryToDismiss);
-
- /**
* Triggered after a user has changed the importance of the notification via its
* {@link NotificationGuts}.
*/
void onImportanceChanged(NotificationEntry entry);
-
/**
- * @param entry being dismissed by the user
- * @return group summary that should be dismissed along with `entry`. Can be null if no
- * relevant group summary exists or the group summary should not be dismissed with `entry`.
+ * Called once it is known that a dismissal will take place for the given reason.
+ * This returns a Runnable which MUST be invoked when the dismissal is ready to be completed.
+ *
+ * Registering for future dismissal is typically done before notifying the NMS that a
+ * notification was clicked or dismissed, but the local dismissal may happen later.
+ *
+ * @param entry the entry being cancelled
+ * @param cancellationReason the reason for the cancellation
+ * @return the runnable to call when the dismissal can happen
*/
- NotificationEntry getGroupSummaryToDismiss(NotificationEntry entry);
+ @NonNull
+ Runnable registerFutureDismissal(@NonNull NotificationEntry entry,
+ @CancellationReason int cancellationReason);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/StackScrollerDecorView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/StackScrollerDecorView.java
index aa3e027..7414bdc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/StackScrollerDecorView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/StackScrollerDecorView.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.notification.row;
+import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.util.AttributeSet;
@@ -25,6 +26,8 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.animation.Interpolators;
+import java.util.function.Consumer;
+
/**
* A common base class for all views in the notification stack scroller which don't have a
* background.
@@ -48,7 +51,7 @@
};
private boolean mSecondaryAnimating = false;
- private final Runnable mSecondaryVisibilityEndRunnable = () -> {
+ private final Consumer<Boolean> mSecondaryVisibilityEndRunnable = (cancelled) -> {
mSecondaryAnimating = false;
// If we were on screen, become GONE to avoid touches
if (mSecondaryView == null) return;
@@ -96,18 +99,20 @@
* @param animate True if we should fade to new visibility
* @param runAfter Runnable to run after visibility updates
*/
- public void setContentVisible(boolean visible, boolean animate, Runnable runAfter) {
+ public void setContentVisible(boolean visible, boolean animate, Consumer<Boolean> runAfter) {
if (mContentVisible != visible) {
mContentAnimating = animate;
mContentVisible = visible;
- Runnable endRunnable = runAfter == null ? mContentVisibilityEndRunnable : () -> {
+ Consumer<Boolean> endRunnable = (cancelled) -> {
mContentVisibilityEndRunnable.run();
- runAfter.run();
+ if (runAfter != null) {
+ runAfter.accept(cancelled);
+ }
};
setViewVisible(mContent, visible, animate, endRunnable);
} else if (runAfter != null) {
// Execute the runAfter runnable immediately if there's no animation to perform.
- runAfter.run();
+ runAfter.accept(true);
}
if (!mContentAnimating) {
@@ -119,10 +124,6 @@
return mContentVisible;
}
- public void setVisible(boolean nowVisible, boolean animate) {
- setVisible(nowVisible, animate, null);
- }
-
/**
* Make this view visible. If {@code false} is passed, the view will fade out it's content
* and set the view Visibility to GONE. If only the content should be changed
@@ -131,7 +132,7 @@
* @param nowVisible should the view be visible
* @param animate should the change be animated.
*/
- public void setVisible(boolean nowVisible, boolean animate, Runnable runAfter) {
+ public void setVisible(boolean nowVisible, boolean animate) {
if (mIsVisible != nowVisible) {
mIsVisible = nowVisible;
if (animate) {
@@ -142,10 +143,10 @@
} else {
setWillBeGone(true);
}
- setContentVisible(nowVisible, true /* animate */, runAfter);
+ setContentVisible(nowVisible, true /* animate */, null /* runAfter */);
} else {
setVisibility(nowVisible ? VISIBLE : GONE);
- setContentVisible(nowVisible, false /* animate */, runAfter);
+ setContentVisible(nowVisible, false /* animate */, null /* runAfter */);
setWillBeGone(false);
notifyHeightChanged(false /* needsAnimation */);
}
@@ -166,7 +167,7 @@
}
if (!mSecondaryAnimating) {
- mSecondaryVisibilityEndRunnable.run();
+ mSecondaryVisibilityEndRunnable.accept(true /* cancelled */);
}
}
@@ -195,7 +196,7 @@
* @param endRunnable A runnable that is run when the animation is done.
*/
private void setViewVisible(View view, boolean nowVisible,
- boolean animate, Runnable endRunnable) {
+ boolean animate, Consumer<Boolean> endRunnable) {
if (view == null) {
return;
}
@@ -211,7 +212,7 @@
if (!animate) {
view.setAlpha(endValue);
if (endRunnable != null) {
- endRunnable.run();
+ endRunnable.accept(true);
}
return;
}
@@ -222,7 +223,19 @@
.alpha(endValue)
.setInterpolator(interpolator)
.setDuration(mDuration)
- .withEndAction(endRunnable);
+ .setListener(new AnimatorListenerAdapter() {
+ boolean mCancelled;
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mCancelled = true;
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ endRunnable.accept(mCancelled);
+ }
+ });
}
@Override
@@ -231,7 +244,7 @@
Runnable onFinishedRunnable,
AnimatorListenerAdapter animationListener) {
// TODO: Use duration
- setContentVisible(false, true /* animate */, onFinishedRunnable);
+ setContentVisible(false, true /* animate */, (cancelled) -> onFinishedRunnable.run());
return 0;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
index 24369e7..4d325e1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@@ -1805,13 +1805,20 @@
}
@ShadeViewRefactor(RefactorComponent.STATE_RESOLVER)
- public void dismissViewAnimated(View child, Runnable endRunnable, int delay, long duration) {
+ public void dismissViewAnimated(
+ View child, Consumer<Boolean> endRunnable, int delay, long duration) {
if (child instanceof SectionHeaderView) {
((StackScrollerDecorView) child).setContentVisible(
false /* visible */, true /* animate */, endRunnable);
return;
}
- mSwipeHelper.dismissChild(child, 0, endRunnable, delay, true, duration,
+ mSwipeHelper.dismissChild(
+ child,
+ 0 /* velocity */,
+ endRunnable,
+ delay,
+ true /* useAccelerateInterpolator */,
+ duration,
true /* isClearAll */);
}
@@ -5196,11 +5203,15 @@
if (mClearAllListener != null) {
mClearAllListener.onClearAll(selection);
}
- final Runnable dismissInBackend = () -> {
- onClearAllAnimationsEnd(rowsToDismissInBackend, selection);
+ final Consumer<Boolean> dismissInBackend = (cancelled) -> {
+ if (cancelled) {
+ post(() -> onClearAllAnimationsEnd(rowsToDismissInBackend, selection));
+ } else {
+ onClearAllAnimationsEnd(rowsToDismissInBackend, selection);
+ }
};
if (viewsToAnimateAway.isEmpty()) {
- dismissInBackend.run();
+ dismissInBackend.accept(true);
return;
}
// Disable normal animations
@@ -5215,7 +5226,7 @@
final int numItems = viewsToAnimateAway.size();
for (int i = numItems - 1; i >= 0; i--) {
View view = viewsToAnimateAway.get(i);
- Runnable endRunnable = null;
+ Consumer<Boolean> endRunnable = null;
if (i == 0) {
endRunnable = dismissInBackend;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NPVCDownEventState.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NPVCDownEventState.kt
index 0623507..d44a569 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NPVCDownEventState.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NPVCDownEventState.kt
@@ -14,9 +14,9 @@
package com.android.systemui.statusbar.phone
import android.view.MotionEvent
-import com.android.internal.util.RingBuffer
import com.android.systemui.dump.DumpsysTableLogger
import com.android.systemui.dump.Row
+import com.android.systemui.util.collection.RingBuffer
import java.text.SimpleDateFormat
import java.util.Locale
@@ -67,16 +67,9 @@
* Do not use [append] to add new elements. Instead use [insert], as it will recycle if
* necessary.
*/
- class Buffer(
- capacity: Int
- ) : RingBuffer<NPVCDownEventState>(NPVCDownEventState::class.java, capacity) {
- override fun append(t: NPVCDownEventState?) {
- throw UnsupportedOperationException("Not supported, use insert instead")
- }
+ class Buffer(capacity: Int) {
- override fun createNewItem(): NPVCDownEventState {
- return NPVCDownEventState()
- }
+ private val buffer = RingBuffer(capacity) { NPVCDownEventState() }
/**
* Insert a new element in the buffer.
@@ -94,7 +87,7 @@
touchSlopExceededBeforeDown: Boolean,
lastEventSynthesized: Boolean
) {
- nextSlot.apply {
+ buffer.advance().apply {
this.timeStamp = timeStamp
this.x = x
this.y = y
@@ -115,7 +108,7 @@
* @see NPVCDownEventState.asStringList
*/
fun toList(): List<Row> {
- return toArray().map { it.asStringList }
+ return buffer.asSequence().map { it.asStringList }.toList()
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotifActivityLaunchEvents.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotifActivityLaunchEvents.kt
deleted file mode 100644
index f46d073..0000000
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotifActivityLaunchEvents.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.statusbar.phone
-
-import com.android.systemui.statusbar.notification.collection.NotificationEntry
-
-/** Provides events about [android.app.Activity] launches from Notifications. */
-interface NotifActivityLaunchEvents {
-
- /** Registers a [Listener] to be invoked when notification activity launch events occur. */
- fun registerListener(listener: Listener)
-
- /** Unregisters a [Listener] previously registered via [registerListener] */
- fun unregisterListener(listener: Listener)
-
- /** Listener for events about [android.app.Activity] launches from Notifications. */
- interface Listener {
-
- /** Invoked when an activity has started launching from a notification. */
- fun onStartLaunchNotifActivity(entry: NotificationEntry)
-
- /** Invoked when an activity has finished launching. */
- fun onFinishLaunchNotifActivity(entry: NotificationEntry)
- }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotifActivityLaunchEventsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotifActivityLaunchEventsModule.java
deleted file mode 100644
index 84ff538..0000000
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotifActivityLaunchEventsModule.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.statusbar.phone;
-
-import com.android.systemui.dagger.SysUISingleton;
-
-import dagger.Binds;
-import dagger.Module;
-
-/** Provides a {@link NotifActivityLaunchEvents} in {@link SysUISingleton} scope. */
-@Module
-public abstract class NotifActivityLaunchEventsModule {
- @Binds
- abstract NotifActivityLaunchEvents bindLaunchEvents(
- StatusBarNotificationActivityStarter.LaunchEventsEmitter impl);
-}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
index f15ea62..314ab22 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
@@ -3377,9 +3377,9 @@
@Override
public void setIsLaunchAnimationRunning(boolean running) {
- boolean wasRunning = isLaunchTransitionRunning();
+ boolean wasRunning = mIsLaunchAnimationRunning;
super.setIsLaunchAnimationRunning(running);
- if (wasRunning != isLaunchTransitionRunning()) {
+ if (wasRunning != mIsLaunchAnimationRunning) {
mPanelEventsEmitter.notifyLaunchingActivityChanged(running);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
index f9e17da..0e77866 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
@@ -402,6 +402,8 @@
mScrimBehind.setFocusable(!state.isLowPowerState());
mNotificationsScrim.setFocusable(!state.isLowPowerState());
+ mScrimInFront.setBlendWithMainColor(state.shouldBlendWithMainColor());
+
// Cancel blanking transitions that were pending before we requested a new state
if (mPendingFrameCallback != null) {
mScrimBehind.removeCallbacks(mPendingFrameCallback);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimState.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimState.java
index 47b7058..4a5f712 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimState.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimState.java
@@ -203,6 +203,11 @@
public boolean isLowPowerState() {
return true;
}
+
+ @Override
+ public boolean shouldBlendWithMainColor() {
+ return false;
+ }
},
/**
@@ -325,6 +330,13 @@
public void prepare(ScrimState previousState) {
}
+ /**
+ * Whether a particular state should enable blending with extracted theme colors.
+ */
+ public boolean shouldBlendWithMainColor() {
+ return true;
+ }
+
public float getFrontAlpha() {
return mFrontAlpha;
}
@@ -422,4 +434,4 @@
public void setClipQsScrim(boolean clipsQsScrim) {
mClipQsScrim = clipsQsScrim;
}
-}
\ No newline at end of file
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarLaunchAnimatorController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarLaunchAnimatorController.kt
index 56b6dfc..c092216 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarLaunchAnimatorController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarLaunchAnimatorController.kt
@@ -20,7 +20,9 @@
override fun onIntentStarted(willAnimate: Boolean) {
delegate.onIntentStarted(willAnimate)
- if (!willAnimate) {
+ if (willAnimate) {
+ centralSurfaces.notificationPanelViewController.setIsLaunchAnimationRunning(true)
+ } else {
centralSurfaces.collapsePanelOnMainThread()
}
}
@@ -51,6 +53,7 @@
override fun onLaunchAnimationCancelled() {
delegate.onLaunchAnimationCancelled()
+ centralSurfaces.notificationPanelViewController.setIsLaunchAnimationRunning(false)
centralSurfaces.onLaunchAnimationCancelled(isLaunchForActivity)
}
}
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
index 87ca942..cf776e3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
@@ -41,7 +41,6 @@
import android.util.EventLog;
import android.view.View;
-import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.android.internal.jank.InteractionJankMonitor;
@@ -52,7 +51,6 @@
import com.android.systemui.EventLogTags;
import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.assist.AssistManager;
-import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.CommandQueue;
@@ -77,7 +75,6 @@
import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent;
import com.android.systemui.statusbar.policy.HeadsUpUtil;
import com.android.systemui.statusbar.policy.KeyguardStateController;
-import com.android.systemui.util.ListenerSet;
import com.android.systemui.wmshell.BubblesManager;
import java.util.Optional;
@@ -131,7 +128,6 @@
private final ActivityLaunchAnimator mActivityLaunchAnimator;
private final NotificationLaunchAnimatorControllerProvider mNotificationAnimationProvider;
private final OnUserInteractionCallback mOnUserInteractionCallback;
- private final LaunchEventsEmitter mLaunchEventsEmitter;
private boolean mIsCollapsingToShowActivityOverLockscreen;
@@ -170,8 +166,7 @@
NotificationPresenter presenter,
NotificationPanelViewController panel,
ActivityLaunchAnimator activityLaunchAnimator,
- NotificationLaunchAnimatorControllerProvider notificationAnimationProvider,
- LaunchEventsEmitter launchEventsEmitter) {
+ NotificationLaunchAnimatorControllerProvider notificationAnimationProvider) {
mContext = context;
mCommandQueue = commandQueue;
mMainThreadHandler = mainThreadHandler;
@@ -207,7 +202,6 @@
mNotificationPanel = panel;
mActivityLaunchAnimator = activityLaunchAnimator;
mNotificationAnimationProvider = notificationAnimationProvider;
- mLaunchEventsEmitter = launchEventsEmitter;
if (!mNotifPipelineFlags.isNewPipelineEnabled()) {
mEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
@@ -229,14 +223,13 @@
/**
* Called when a notification is clicked.
*
- * @param sbn notification that was clicked
+ * @param entry notification that was clicked
* @param row row for that notification
*/
@Override
- public void onNotificationClicked(StatusBarNotification sbn, ExpandableNotificationRow row) {
- mLogger.logStartingActivityFromClick(sbn.getKey());
+ public void onNotificationClicked(NotificationEntry entry, ExpandableNotificationRow row) {
+ mLogger.logStartingActivityFromClick(entry);
- final NotificationEntry entry = row.getEntry();
if (mRemoteInputManager.isRemoteInputActive(entry)
&& !TextUtils.isEmpty(row.getActiveRemoteInputText())) {
// We have an active remote input typed and the user clicked on the notification.
@@ -244,7 +237,7 @@
mRemoteInputManager.closeRemoteInputs();
return;
}
- Notification notification = sbn.getNotification();
+ Notification notification = entry.getSbn().getNotification();
final PendingIntent intent = notification.contentIntent != null
? notification.contentIntent
: notification.fullScreenIntent;
@@ -254,12 +247,10 @@
// The only valid case is Bubble notifications. Guard against other cases
// entering here.
if (intent == null && !isBubble) {
- mLogger.logNonClickableNotification(sbn.getKey());
+ mLogger.logNonClickableNotification(entry);
return;
}
- mLaunchEventsEmitter.notifyStartLaunchNotifActivity(entry);
-
boolean isActivityIntent = intent != null && intent.isActivity() && !isBubble;
final boolean willLaunchResolverActivity = isActivityIntent
&& mActivityIntentHelper.wouldLaunchResolverActivity(intent.getIntent(),
@@ -287,7 +278,7 @@
} else {
mActivityStarter.dismissKeyguardThenExecute(
postKeyguardAction,
- () -> mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry),
+ null,
willLaunchResolverActivity);
}
}
@@ -299,7 +290,7 @@
boolean isActivityIntent,
boolean animate,
boolean showOverLockscreen) {
- mLogger.logHandleClickAfterKeyguardDismissed(entry.getKey());
+ mLogger.logHandleClickAfterKeyguardDismissed(entry);
final Runnable runnable = () -> handleNotificationClickAfterPanelCollapsed(
entry, row, intent, isActivityIntent, animate);
@@ -326,7 +317,7 @@
boolean isActivityIntent,
boolean animate) {
String notificationKey = entry.getKey();
- mLogger.logHandleClickAfterPanelCollapsed(notificationKey);
+ mLogger.logHandleClickAfterPanelCollapsed(entry);
try {
// The intent we are sending is for the application, which
@@ -367,11 +358,9 @@
}
final boolean canBubble = entry.canBubble();
if (canBubble) {
- mLogger.logExpandingBubble(notificationKey);
+ mLogger.logExpandingBubble(entry);
removeHunAfterClick(row);
expandBubbleStackOnMainThread(entry);
- mMainThreadHandler.post(
- () -> mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry));
} else {
startNotificationIntent(intent, fillInIntent, entry, row, animate, isActivityIntent);
}
@@ -381,30 +370,13 @@
final NotificationVisibility nv = mVisibilityProvider.obtain(entry, true);
- // retrieve the group summary to remove with this entry before we tell NMS the
- // notification was clicked to avoid a race condition
- final boolean shouldAutoCancel = shouldAutoCancel(entry.getSbn());
- final NotificationEntry summaryToRemove = shouldAutoCancel
- ? mOnUserInteractionCallback.getGroupSummaryToDismiss(entry) : null;
-
- // inform NMS that the notification was clicked
- mClickNotifier.onNotificationClick(notificationKey, nv);
-
- if (!canBubble && (shouldAutoCancel
+ if (!canBubble && (shouldAutoCancel(entry.getSbn())
|| mRemoteInputManager.isNotificationKeptForRemoteInputHistory(notificationKey))) {
+ final Runnable removeNotification =
+ mOnUserInteractionCallback.registerFutureDismissal(entry, REASON_CLICK);
// Immediately remove notification from visually showing.
// We have to post the removal to the UI thread for synchronization.
mMainThreadHandler.post(() -> {
- final Runnable removeNotification = () -> {
- mOnUserInteractionCallback.onDismiss(entry, REASON_CLICK, summaryToRemove);
- if (!animate) {
- // If we're animating, this would be invoked after the activity launch
- // animation completes. Since we're not animating, the launch already
- // happened synchronously, so we notify the launch is complete here after
- // onDismiss.
- mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry);
- }
- };
if (mPresenter.isCollapsing()) {
// To avoid lags we're only performing the remove after the shade is collapsed
mShadeController.addPostCollapseAction(removeNotification);
@@ -412,12 +384,11 @@
removeNotification.run();
}
});
- } else if (!canBubble && !animate) {
- // Not animating, this is the end of the launch flow (see above comment for more info).
- mMainThreadHandler.post(
- () -> mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry));
}
+ // inform NMS that the notification was clicked
+ mClickNotifier.onNotificationClick(notificationKey, nv);
+
mIsCollapsingToShowActivityOverLockscreen = false;
}
@@ -434,24 +405,14 @@
// will focus follow operation only after drag-and-drop that notification.
final NotificationVisibility nv = mVisibilityProvider.obtain(entry, true);
- // retrieve the group summary to remove with this entry before we tell NMS the
- // notification was clicked to avoid a race condition
- final boolean shouldAutoCancel = shouldAutoCancel(entry.getSbn());
- final NotificationEntry summaryToRemove = shouldAutoCancel
- ? mOnUserInteractionCallback.getGroupSummaryToDismiss(entry) : null;
-
String notificationKey = entry.getKey();
- // inform NMS that the notification was clicked
- mClickNotifier.onNotificationClick(notificationKey, nv);
-
- if (shouldAutoCancel || mRemoteInputManager.isNotificationKeptForRemoteInputHistory(
- notificationKey)) {
+ if (shouldAutoCancel(entry.getSbn())
+ || mRemoteInputManager.isNotificationKeptForRemoteInputHistory(notificationKey)) {
+ final Runnable removeNotification =
+ mOnUserInteractionCallback.registerFutureDismissal(entry, REASON_CLICK);
// Immediately remove notification from visually showing.
// We have to post the removal to the UI thread for synchronization.
mMainThreadHandler.post(() -> {
- final Runnable removeNotification = () ->
- mOnUserInteractionCallback.onDismiss(
- entry, REASON_CLICK, summaryToRemove);
if (mPresenter.isCollapsing()) {
// To avoid lags we're only performing the remove
// after the shade is collapsed
@@ -462,6 +423,9 @@
});
}
+ // inform NMS that the notification was clicked
+ mClickNotifier.onNotificationClick(notificationKey, nv);
+
mIsCollapsingToShowActivityOverLockscreen = false;
}
@@ -489,15 +453,11 @@
ExpandableNotificationRow row,
boolean animate,
boolean isActivityIntent) {
- mLogger.logStartNotificationIntent(entry.getKey());
+ mLogger.logStartNotificationIntent(entry);
try {
- Runnable onFinishAnimationCallback = animate
- ? () -> mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry)
- : null;
ActivityLaunchAnimator.Controller animationController =
new StatusBarLaunchAnimatorController(
- mNotificationAnimationProvider
- .getAnimatorController(row, onFinishAnimationCallback),
+ mNotificationAnimationProvider.getAnimatorController(row, null),
mCentralSurfaces,
isActivityIntent);
mActivityLaunchAnimator.startPendingIntentWithAnimation(
@@ -515,7 +475,7 @@
: getActivityOptions(mCentralSurfaces.getDisplayId(), adapter);
int result = intent.sendAndReturnResult(mContext, 0, fillInIntent, null,
null, null, options);
- mLogger.logSendPendingIntent(entry.getKey(), intent, result);
+ mLogger.logSendPendingIntent(entry, intent, result);
return result;
});
} catch (PendingIntent.CanceledException e) {
@@ -622,9 +582,9 @@
void handleFullScreenIntent(NotificationEntry entry) {
if (mNotificationInterruptStateProvider.shouldLaunchFullScreenIntentWhenAdded(entry)) {
if (shouldSuppressFullScreenIntent(entry)) {
- mLogger.logFullScreenIntentSuppressedByDnD(entry.getKey());
+ mLogger.logFullScreenIntentSuppressedByDnD(entry);
} else if (entry.getImportance() < NotificationManager.IMPORTANCE_HIGH) {
- mLogger.logFullScreenIntentNotImportantEnough(entry.getKey());
+ mLogger.logFullScreenIntentNotImportantEnough(entry);
} else {
// Stop screensaver if the notification has a fullscreen intent.
// (like an incoming phone call)
@@ -639,7 +599,7 @@
// not immersive & a fullscreen alert should be shown
final PendingIntent fullscreenIntent =
entry.getSbn().getNotification().fullScreenIntent;
- mLogger.logSendingFullScreenIntent(entry.getKey(), fullscreenIntent);
+ mLogger.logSendingFullScreenIntent(entry, fullscreenIntent);
try {
EventLog.writeEvent(EventLogTags.SYSUI_FULLSCREEN_NOTIFICATION,
entry.getKey());
@@ -685,35 +645,4 @@
return entry.shouldSuppressFullScreenIntent();
}
-
- @SysUISingleton
- static class LaunchEventsEmitter implements NotifActivityLaunchEvents {
-
- private final ListenerSet<Listener> mListeners = new ListenerSet<>();
-
- @Inject
- LaunchEventsEmitter() {}
-
- @Override
- public void registerListener(@NonNull Listener listener) {
- mListeners.addIfAbsent(listener);
- }
-
- @Override
- public void unregisterListener(@NonNull Listener listener) {
- mListeners.remove(listener);
- }
-
- private void notifyStartLaunchNotifActivity(NotificationEntry entry) {
- for (Listener listener : mListeners) {
- listener.onStartLaunchNotifActivity(entry);
- }
- }
-
- private void notifyFinishLaunchNotifActivity(NotificationEntry entry) {
- for (Listener listener : mListeners) {
- listener.onFinishLaunchNotifActivity(entry);
- }
- }
- }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterLogger.kt
index 2fbe520..b9a1413 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterLogger.kt
@@ -23,46 +23,48 @@
import com.android.systemui.log.LogLevel.INFO
import com.android.systemui.log.LogLevel.WARNING
import com.android.systemui.log.dagger.NotifInteractionLog
+import com.android.systemui.statusbar.notification.collection.NotificationEntry
+import com.android.systemui.statusbar.notification.logKey
import javax.inject.Inject
class StatusBarNotificationActivityStarterLogger @Inject constructor(
@NotifInteractionLog private val buffer: LogBuffer
) {
- fun logStartingActivityFromClick(key: String) {
+ fun logStartingActivityFromClick(entry: NotificationEntry) {
buffer.log(TAG, DEBUG, {
- str1 = key
+ str1 = entry.logKey
}, {
"(1/5) onNotificationClicked: $str1"
})
}
- fun logHandleClickAfterKeyguardDismissed(key: String) {
+ fun logHandleClickAfterKeyguardDismissed(entry: NotificationEntry) {
buffer.log(TAG, DEBUG, {
- str1 = key
+ str1 = entry.logKey
}, {
"(2/5) handleNotificationClickAfterKeyguardDismissed: $str1"
})
}
- fun logHandleClickAfterPanelCollapsed(key: String) {
+ fun logHandleClickAfterPanelCollapsed(entry: NotificationEntry) {
buffer.log(TAG, DEBUG, {
- str1 = key
+ str1 = entry.logKey
}, {
"(3/5) handleNotificationClickAfterPanelCollapsed: $str1"
})
}
- fun logStartNotificationIntent(key: String) {
+ fun logStartNotificationIntent(entry: NotificationEntry) {
buffer.log(TAG, INFO, {
- str1 = key
+ str1 = entry.logKey
}, {
"(4/5) startNotificationIntent: $str1"
})
}
- fun logSendPendingIntent(key: String, pendingIntent: PendingIntent, result: Int) {
+ fun logSendPendingIntent(entry: NotificationEntry, pendingIntent: PendingIntent, result: Int) {
buffer.log(TAG, INFO, {
- str1 = key
+ str1 = entry.logKey
str2 = pendingIntent.intent.toString()
int1 = result
}, {
@@ -70,9 +72,9 @@
})
}
- fun logExpandingBubble(key: String) {
+ fun logExpandingBubble(entry: NotificationEntry) {
buffer.log(TAG, DEBUG, {
- str1 = key
+ str1 = entry.logKey
}, {
"Expanding bubble for $str1 (rather than firing intent)"
})
@@ -86,33 +88,33 @@
})
}
- fun logNonClickableNotification(key: String) {
+ fun logNonClickableNotification(entry: NotificationEntry) {
buffer.log(TAG, ERROR, {
- str1 = key
+ str1 = entry.logKey
}, {
"onNotificationClicked called for non-clickable notification! $str1"
})
}
- fun logFullScreenIntentSuppressedByDnD(key: String) {
+ fun logFullScreenIntentSuppressedByDnD(entry: NotificationEntry) {
buffer.log(TAG, DEBUG, {
- str1 = key
+ str1 = entry.logKey
}, {
"No Fullscreen intent: suppressed by DND: $str1"
})
}
- fun logFullScreenIntentNotImportantEnough(key: String) {
+ fun logFullScreenIntentNotImportantEnough(entry: NotificationEntry) {
buffer.log(TAG, DEBUG, {
- str1 = key
+ str1 = entry.logKey
}, {
"No Fullscreen intent: not important enough: $str1"
})
}
- fun logSendingFullScreenIntent(key: String, pendingIntent: PendingIntent) {
+ fun logSendingFullScreenIntent(entry: NotificationEntry, pendingIntent: PendingIntent) {
buffer.log(TAG, INFO, {
- str1 = key
+ str1 = entry.logKey
str2 = pendingIntent.intent.toString()
}, {
"Notification $str1 has fullScreenIntent; sending fullScreenIntent $str2"
diff --git a/packages/SystemUI/src/com/android/systemui/util/collection/RingBuffer.kt b/packages/SystemUI/src/com/android/systemui/util/collection/RingBuffer.kt
new file mode 100644
index 0000000..97dc842
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/util/collection/RingBuffer.kt
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.util.collection
+
+import kotlin.math.max
+
+/**
+ * A simple ring buffer implementation
+ *
+ * Use [advance] to get the least recent item in the buffer (and then presumably fill it with
+ * appropriate data). This will cause it to become the most recent item.
+ *
+ * As the buffer is used, it will grow, allocating new instances of T using [factory] until it
+ * reaches [maxSize]. After this point, no new instances will be created. Instead, the "oldest"
+ * instances will be recycled from the back of the buffer and placed at the front.
+ *
+ * @param maxSize The maximum size the buffer can grow to before it begins functioning as a ring.
+ * @param factory A function that creates a fresh instance of T. Used by the buffer while it's
+ * growing to [maxSize].
+ */
+class RingBuffer<T>(
+ private val maxSize: Int,
+ private val factory: () -> T
+) : Iterable<T> {
+
+ private val buffer = MutableList<T?>(maxSize) { null }
+
+ /**
+ * An abstract representation that points to the "end" of the buffer. Increments every time
+ * [advance] is called and never wraps. Use [indexOf] to calculate the associated index into
+ * the backing array. Always points to the "next" available slot in the buffer. Before the
+ * buffer has completely filled, the value pointed to will be null. Afterward, it will be the
+ * value at the "beginning" of the buffer.
+ *
+ * This value is unlikely to overflow. Assuming [advance] is called at rate of 100 calls/ms,
+ * omega will overflow after a little under three million years of continuous operation.
+ */
+ private var omega: Long = 0
+
+ /**
+ * The number of items currently stored in the buffer. Calls to [advance] will cause this value
+ * to increase by one until it reaches [maxSize].
+ */
+ val size: Int
+ get() = if (omega < maxSize) omega.toInt() else maxSize
+
+ /**
+ * Advances the buffer's position by one and returns the value that is now present at the "end"
+ * of the buffer. If the buffer is not yet full, uses [factory] to create a new item.
+ * Otherwise, reuses the value that was previously at the "beginning" of the buffer.
+ *
+ * IMPORTANT: The value is returned as-is, without being reset. It will retain any data that
+ * was previously stored on it.
+ */
+ fun advance(): T {
+ val index = indexOf(omega)
+ omega += 1
+ val entry = buffer[index] ?: factory().also {
+ buffer[index] = it
+ }
+ return entry
+ }
+
+ /**
+ * Returns the value stored at [index], which can range from 0 (the "start", or oldest element
+ * of the buffer) to [size] - 1 (the "end", or newest element of the buffer).
+ */
+ operator fun get(index: Int): T {
+ if (index < 0 || index >= size) {
+ throw IndexOutOfBoundsException("Index $index is out of bounds")
+ }
+
+ // If omega is larger than the maxSize, then the buffer is full, and omega is equivalent
+ // to the "start" of the buffer. If omega is smaller than the maxSize, then the buffer is
+ // not yet full and our start should be 0. However, in modspace, maxSize and 0 are
+ // equivalent, so we can get away with using it as the start value instead.
+ val start = max(omega, maxSize.toLong())
+
+ return buffer[indexOf(start + index)]!!
+ }
+
+ inline fun forEach(action: (T) -> Unit) {
+ for (i in 0 until size) {
+ action(get(i))
+ }
+ }
+
+ override fun iterator(): Iterator<T> {
+ return object : Iterator<T> {
+ private var position: Int = 0
+
+ override fun next(): T {
+ if (position >= size) {
+ throw NoSuchElementException()
+ }
+ return get(position).also { position += 1 }
+ }
+
+ override fun hasNext(): Boolean {
+ return position < size
+ }
+ }
+ }
+
+ private fun indexOf(position: Long): Int {
+ return (position % maxSize).toInt()
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
index bfdcbd6..cf0d023 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
@@ -32,6 +32,8 @@
import static android.view.View.VISIBLE;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+import static com.android.internal.jank.InteractionJankMonitor.CUJ_VOLUME_CONTROL;
+import static com.android.internal.jank.InteractionJankMonitor.Configuration.Builder;
import static com.android.systemui.volume.Events.DISMISS_REASON_SETTINGS_CLICKED;
import android.animation.Animator;
@@ -68,6 +70,7 @@
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
+import android.os.Trace;
import android.os.VibrationEffect;
import android.provider.Settings;
import android.provider.Settings.Global;
@@ -101,9 +104,11 @@
import android.widget.TextView;
import android.widget.Toast;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.internal.graphics.drawable.BackgroundBlurDrawable;
+import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.view.RotationPolicy;
import com.android.settingslib.Utils;
import com.android.systemui.Prefs;
@@ -149,6 +154,13 @@
private static final int DRAWER_ANIMATION_DURATION_SHORT = 175;
private static final int DRAWER_ANIMATION_DURATION = 250;
+ /** Shows volume dialog show animation. */
+ private static final String TYPE_SHOW = "show";
+ /** Dismiss volume dialog animation. */
+ private static final String TYPE_DISMISS = "dismiss";
+ /** Volume dialog slider animation. */
+ private static final String TYPE_UPDATE = "update";
+
private final int mDialogShowAnimationDurationMs;
private final int mDialogHideAnimationDurationMs;
private int mDialogWidth;
@@ -258,6 +270,7 @@
private final boolean mUseBackgroundBlur;
private Consumer<Boolean> mCrossWindowBlurEnabledListener;
private BackgroundBlurDrawable mDialogRowsViewBackground;
+ private final InteractionJankMonitor mInteractionJankMonitor;
public VolumeDialogImpl(
Context context,
@@ -266,7 +279,8 @@
DeviceProvisionedController deviceProvisionedController,
ConfigurationController configurationController,
MediaOutputDialogFactory mediaOutputDialogFactory,
- ActivityStarter activityStarter) {
+ ActivityStarter activityStarter,
+ InteractionJankMonitor interactionJankMonitor) {
mContext =
new ContextThemeWrapper(context, R.style.volume_dialog_theme);
mController = volumeDialogController;
@@ -290,6 +304,7 @@
mContext.getResources().getInteger(R.integer.config_dialogHideAnimationDurationMs);
mUseBackgroundBlur =
mContext.getResources().getBoolean(R.bool.config_volumeDialogUseBackgroundBlur);
+ mInteractionJankMonitor = interactionJankMonitor;
if (mUseBackgroundBlur) {
final int dialogRowsViewColorAboveBlur = mContext.getColor(
@@ -422,6 +437,7 @@
.alpha(1)
.translationX(0)
.setDuration(mDialogShowAnimationDurationMs)
+ .setListener(getJankListener(getDialogView(), TYPE_SHOW, DIALOG_TIMEOUT_MILLIS))
.setInterpolator(new SystemUIInterpolators.LogDecelerateInterpolator())
.withEndAction(() -> {
if (!Prefs.getBoolean(mContext, Prefs.Key.TOUCHED_RINGER_TOGGLE, false)) {
@@ -692,7 +708,7 @@
final int m = seekBar.getMax();
final int n = m / 100 - 1;
final int level = progress == 0 ? 0
- : progress == m ? (m / 100) : (1 + (int)((progress / (float) m) * n));
+ : progress == m ? (m / 100) : (1 + (int) ((progress / (float) m) * n));
return level;
}
@@ -1251,7 +1267,33 @@
mHandler.obtainMessage(H.DISMISS, reason, 0).sendToTarget();
}
+ private Animator.AnimatorListener getJankListener(View v, String type, long timeout) {
+ return new Animator.AnimatorListener() {
+ @Override
+ public void onAnimationStart(@NonNull Animator animation) {
+ mInteractionJankMonitor.begin(Builder.withView(CUJ_VOLUME_CONTROL, v).setTag(type)
+ .setTimeout(timeout));
+ }
+
+ @Override
+ public void onAnimationEnd(@NonNull Animator animation) {
+ mInteractionJankMonitor.end(CUJ_VOLUME_CONTROL);
+ }
+
+ @Override
+ public void onAnimationCancel(@NonNull Animator animation) {
+ mInteractionJankMonitor.cancel(CUJ_VOLUME_CONTROL);
+ }
+
+ @Override
+ public void onAnimationRepeat(@NonNull Animator animation) {
+ // no-op
+ }
+ };
+ }
+
private void showH(int reason) {
+ Trace.beginSection("VolumeDialogImpl#showH");
if (D.BUG) Log.d(TAG, "showH r=" + Events.SHOW_REASONS[reason]);
mHandler.removeMessages(H.SHOW);
mHandler.removeMessages(H.DISMISS);
@@ -1272,6 +1314,7 @@
mController.getCaptionsComponentState(false);
checkODICaptionsTooltip(false);
updateBackgroundForDrawerClosedAmount();
+ Trace.endSection();
}
protected void rescheduleTimeoutH() {
@@ -1305,6 +1348,7 @@
}
protected void dismissH(int reason) {
+ Trace.beginSection("VolumeDialogImpl#dismissH");
if (D.BUG) {
Log.d(TAG, "mDialog.dismiss() reason: " + Events.DISMISS_REASONS[reason]
+ " from: " + Debug.getCaller());
@@ -1335,7 +1379,8 @@
hideRingerDrawer();
}, 50));
if (!shouldSlideInVolumeTray()) animator.translationX(mDialogView.getWidth() / 2.0f);
- animator.start();
+ animator.setListener(getJankListener(getDialogView(), TYPE_DISMISS,
+ mDialogHideAnimationDurationMs)).start();
checkODICaptionsTooltip(true);
mController.notifyVisible(false);
synchronized (mSafetyWarningLock) {
@@ -1344,6 +1389,7 @@
mSafetyWarning.dismiss();
}
}
+ Trace.endSection();
}
private boolean showActiveStreamOnly() {
@@ -1383,6 +1429,7 @@
}
private void updateRowsH(final VolumeRow activeRow) {
+ Trace.beginSection("VolumeDialogImpl#updateRowsH");
if (D.BUG) Log.d(TAG, "updateRowsH");
if (!mShowing) {
trimObsoleteH();
@@ -1446,6 +1493,7 @@
}
updateBackgroundForDrawerClosedAmount();
+ Trace.endSection();
}
protected void updateRingerH() {
@@ -1730,7 +1778,9 @@
final boolean enableSlider = !zenMuted;
final int vlevel = row.ss.muted && (!isRingStream && !zenMuted) ? 0
: row.ss.level;
+ Trace.beginSection("VolumeDialogImpl#updateVolumeRowSliderH");
updateVolumeRowSliderH(row, enableSlider, vlevel);
+ Trace.endSection();
if (row.number != null) row.number.setText(Integer.toString(vlevel));
}
@@ -1824,6 +1874,8 @@
}
row.animTargetProgress = newProgress;
row.anim.setDuration(UPDATE_ANIMATION_DURATION);
+ row.anim.addListener(
+ getJankListener(row.view, TYPE_UPDATE, UPDATE_ANIMATION_DURATION));
row.anim.start();
} else {
// update slider directly to clamped value
diff --git a/packages/SystemUI/src/com/android/systemui/volume/dagger/VolumeModule.java b/packages/SystemUI/src/com/android/systemui/volume/dagger/VolumeModule.java
index 79aa643..f3855bd 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/dagger/VolumeModule.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/dagger/VolumeModule.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.media.AudioManager;
+import com.android.internal.jank.InteractionJankMonitor;
import com.android.systemui.media.dialog.MediaOutputDialogFactory;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.VolumeDialog;
@@ -51,7 +52,8 @@
DeviceProvisionedController deviceProvisionedController,
ConfigurationController configurationController,
MediaOutputDialogFactory mediaOutputDialogFactory,
- ActivityStarter activityStarter) {
+ ActivityStarter activityStarter,
+ InteractionJankMonitor interactionJankMonitor) {
VolumeDialogImpl impl = new VolumeDialogImpl(
context,
volumeDialogController,
@@ -59,7 +61,8 @@
deviceProvisionedController,
configurationController,
mediaOutputDialogFactory,
- activityStarter);
+ activityStarter,
+ interactionJankMonitor);
impl.setStreamImportant(AudioManager.STREAM_SYSTEM, false);
impl.setAutomute(true);
impl.setSilentMode(false);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt
index 6eba215..431739b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsControllerOverlayTest.kt
@@ -367,6 +367,73 @@
assertThat(controllerOverlay.matchesRequestId(REQUEST_ID)).isTrue()
assertThat(controllerOverlay.matchesRequestId(REQUEST_ID + 1)).isFalse()
}
+
+ @Test
+ fun testTouchOutsideAreaNoRotation() = withReason(REASON_ENROLL_ENROLLING) {
+ val touchHints =
+ context.resources.getStringArray(R.array.udfps_accessibility_touch_hints)
+ val rotation = Surface.ROTATION_0
+ // touch at 0 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, 0.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[0])
+ // touch at 90 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, -1.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[1])
+ // touch at 180 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(-1.0f /* x */, 0.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[2])
+ // touch at 270 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, 1.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[3])
+ }
+
+ fun testTouchOutsideAreaNoRotation90Degrees() = withReason(REASON_ENROLL_ENROLLING) {
+ val touchHints =
+ context.resources.getStringArray(R.array.udfps_accessibility_touch_hints)
+ val rotation = Surface.ROTATION_90
+ // touch at 0 degrees -> 90 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, 0.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[1])
+ // touch at 90 degrees -> 180 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, -1.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[2])
+ // touch at 180 degrees -> 270 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(-1.0f /* x */, 0.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[3])
+ // touch at 270 degrees -> 0 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, 1.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[0])
+ }
+
+ fun testTouchOutsideAreaNoRotation270Degrees() = withReason(REASON_ENROLL_ENROLLING) {
+ val touchHints =
+ context.resources.getStringArray(R.array.udfps_accessibility_touch_hints)
+ val rotation = Surface.ROTATION_270
+ // touch at 0 degrees -> 270 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, 0.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[3])
+ // touch at 90 degrees -> 0 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, -1.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[0])
+ // touch at 180 degrees -> 90 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(-1.0f /* x */, 0.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[1])
+ // touch at 270 degrees -> 180 degrees
+ assertThat(controllerOverlay.onTouchOutsideOfSensorAreaImpl(0.0f /* x */, 1.0f /* y */,
+ 0.0f /* sensorX */, 0.0f /* sensorY */, rotation))
+ .isEqualTo(touchHints[2])
+ }
}
private class EnrollListener(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/dump/LogBufferHelper.kt b/packages/SystemUI/tests/src/com/android/systemui/dump/LogBufferHelper.kt
index 0720bdb..bd029a7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/dump/LogBufferHelper.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/dump/LogBufferHelper.kt
@@ -24,7 +24,7 @@
* Creates a LogBuffer that will echo everything to logcat, which is useful for debugging tests.
*/
fun logcatLogBuffer(name: String = "EchoToLogcatLogBuffer") =
- LogBuffer(name, 50, 50, LogcatEchoTrackerAlways())
+ LogBuffer(name, 50, LogcatEchoTrackerAlways())
/**
* A [LogcatEchoTracker] that always allows echoing to the logcat.
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java
index c532ed5..24d0515 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java
@@ -135,8 +135,7 @@
.startMocking();
MockitoAnnotations.initMocks(this);
- when(mLockIconView.getResources()).thenReturn(mResources);
- when(mLockIconView.getContext()).thenReturn(mContext);
+ setupLockIconViewMocks();
when(mContext.getResources()).thenReturn(mResources);
when(mContext.getSystemService(WindowManager.class)).thenReturn(mWindowManager);
Rect windowBounds = new Rect(0, 0, 800, 1200);
@@ -206,13 +205,14 @@
}
@Test
- public void testUpdateFingerprintLocationOnAuthenticatorsRegistered() {
+ public void testUpdateLockIconLocationOnAuthenticatorsRegistered() {
// GIVEN fp sensor location is not available pre-init
when(mKeyguardUpdateMonitor.isUdfpsSupported()).thenReturn(false);
when(mAuthController.getFingerprintSensorLocation()).thenReturn(null);
mLockIconViewController.init();
captureAttachListener();
mAttachListener.onViewAttachedToWindow(mLockIconView);
+ resetLockIconView(); // reset any method call counts for when we verify method calls later
// GIVEN fp sensor location is available post-attached
captureAuthControllerCallback();
@@ -228,6 +228,29 @@
}
@Test
+ public void testUpdateLockIconLocationOnUdfpsLocationChanged() {
+ // GIVEN fp sensor location is not available pre-init
+ when(mKeyguardUpdateMonitor.isUdfpsSupported()).thenReturn(false);
+ when(mAuthController.getFingerprintSensorLocation()).thenReturn(null);
+ mLockIconViewController.init();
+ captureAttachListener();
+ mAttachListener.onViewAttachedToWindow(mLockIconView);
+ resetLockIconView(); // reset any method call counts for when we verify method calls later
+
+ // GIVEN fp sensor location is available post-attached
+ captureAuthControllerCallback();
+ Pair<Float, PointF> udfps = setupUdfps();
+
+ // WHEN udfps location changes
+ mAuthControllerCallback.onUdfpsLocationChanged();
+ mDelayableExecutor.runAllReady();
+
+ // THEN lock icon view location is updated with the same coordinates as auth controller vals
+ verify(mLockIconView).setCenterLocation(eq(udfps.second), eq(udfps.first),
+ eq(PADDING));
+ }
+
+ @Test
public void testLockIconViewBackgroundEnabledWhenUdfpsIsSupported() {
// GIVEN Udpfs sensor location is available
setupUdfps();
@@ -440,4 +463,14 @@
mKeyguardUpdateMonitorCallbackCaptor.capture());
mKeyguardUpdateMonitorCallback = mKeyguardUpdateMonitorCallbackCaptor.getValue();
}
+
+ private void setupLockIconViewMocks() {
+ when(mLockIconView.getResources()).thenReturn(mResources);
+ when(mLockIconView.getContext()).thenReturn(mContext);
+ }
+
+ private void resetLockIconView() {
+ reset(mLockIconView);
+ setupLockIconViewMocks();
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/LSShadeTransitionLoggerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/LSShadeTransitionLoggerTest.kt
index 6971c63..8cb530c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/LSShadeTransitionLoggerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/LSShadeTransitionLoggerTest.kt
@@ -30,7 +30,7 @@
@Before
fun setup() {
logger = LSShadeTransitionLogger(
- LogBuffer("Test", 10, 10, mock()),
+ LogBuffer("Test", 10, mock()),
gestureLogger,
displayMetrics)
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java
index 7068009..958d542 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java
@@ -32,6 +32,8 @@
import static com.android.systemui.statusbar.notification.collection.NotificationEntry.DismissState.NOT_DISMISSED;
import static com.android.systemui.statusbar.notification.collection.NotificationEntry.DismissState.PARENT_DISMISSED;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -47,6 +49,7 @@
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static java.util.Collections.singletonList;
@@ -180,13 +183,14 @@
@Test
public void testGetGroupSummary() {
- assertEquals(null, mCollection.getGroupSummary("group"));
- NotifEvent summary = mNoMan.postNotif(
- buildNotif(TEST_PACKAGE, 0)
- .setGroup(mContext, "group")
- .setGroupSummary(mContext, true));
+ final NotificationEntryBuilder entryBuilder = buildNotif(TEST_PACKAGE, 0)
+ .setGroup(mContext, "group")
+ .setGroupSummary(mContext, true);
+ final String groupKey = entryBuilder.build().getSbn().getGroupKey();
+ assertEquals(null, mCollection.getGroupSummary(groupKey));
+ NotifEvent summary = mNoMan.postNotif(entryBuilder);
- final NotificationEntry entry = mCollection.getGroupSummary("group");
+ final NotificationEntry entry = mCollection.getGroupSummary(groupKey);
assertEquals(summary.key, entry.getKey());
assertEquals(summary.sbn, entry.getSbn());
assertEquals(summary.ranking, entry.getRanking());
@@ -194,9 +198,9 @@
@Test
public void testIsOnlyChildInGroup() {
- NotifEvent notif1 = mNoMan.postNotif(
- buildNotif(TEST_PACKAGE, 1)
- .setGroup(mContext, "group"));
+ final NotificationEntryBuilder entryBuilder = buildNotif(TEST_PACKAGE, 1)
+ .setGroup(mContext, "group");
+ NotifEvent notif1 = mNoMan.postNotif(entryBuilder);
final NotificationEntry entry = mCollection.getEntry(notif1.key);
assertTrue(mCollection.isOnlyChildInGroup(entry));
@@ -1488,6 +1492,55 @@
}
@Test
+ public void testRegisterFutureDismissal() throws RemoteException {
+ // GIVEN a pipeline with one notification
+ NotifEvent notifEvent = mNoMan.postNotif(buildNotif(TEST_PACKAGE, 47, "myTag"));
+ NotificationEntry entry = requireNonNull(mCollection.getEntry(notifEvent.key));
+ clearInvocations(mCollectionListener);
+
+ // WHEN registering a future dismissal, nothing happens right away
+ final Runnable onDismiss = mCollection.registerFutureDismissal(entry, REASON_CLICK,
+ NotifCollectionTest::defaultStats);
+ verifyNoMoreInteractions(mCollectionListener);
+
+ // WHEN finally dismissing
+ onDismiss.run();
+ verify(mStatusBarService).onNotificationClear(any(), anyInt(), eq(notifEvent.key),
+ anyInt(), anyInt(), any());
+ verifyNoMoreInteractions(mStatusBarService);
+ verifyNoMoreInteractions(mCollectionListener);
+ }
+
+ @Test
+ public void testRegisterFutureDismissalWithRetractionAndRepost() {
+ // GIVEN a pipeline with one notification
+ NotifEvent notifEvent = mNoMan.postNotif(buildNotif(TEST_PACKAGE, 47, "myTag"));
+ NotificationEntry entry = requireNonNull(mCollection.getEntry(notifEvent.key));
+ clearInvocations(mCollectionListener);
+
+ // WHEN registering a future dismissal, nothing happens right away
+ final Runnable onDismiss = mCollection.registerFutureDismissal(entry, REASON_CLICK,
+ NotifCollectionTest::defaultStats);
+ verifyNoMoreInteractions(mCollectionListener);
+
+ // WHEN retracting the notification, and then reposting
+ mNoMan.retractNotif(notifEvent.sbn, REASON_CLICK);
+ mNoMan.postNotif(buildNotif(TEST_PACKAGE, 47, "myTag"));
+ clearInvocations(mCollectionListener);
+
+ // KNOWING that the entry in the collection is different now
+ assertThat(mCollection.getEntry(notifEvent.key)).isNotSameInstanceAs(entry);
+
+ // WHEN finally dismissing
+ onDismiss.run();
+
+ // VERIFY that nothing happens; the notification should not be removed
+ verifyNoMoreInteractions(mCollectionListener);
+ assertThat(mCollection.getEntry(notifEvent.key)).isNotNull();
+ verifyNoMoreInteractions(mStatusBarService);
+ }
+
+ @Test
public void testCannotDismissOngoingNotificationChildren() {
// GIVEN an ongoing notification
final NotificationEntry container = new NotificationEntryBuilder()
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ActivityLaunchAnimCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ActivityLaunchAnimCoordinatorTest.kt
deleted file mode 100644
index c6c043a..0000000
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ActivityLaunchAnimCoordinatorTest.kt
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.statusbar.notification.collection.coordinator
-
-import androidx.test.filters.SmallTest
-import com.android.systemui.SysuiTestCase
-import com.android.systemui.statusbar.notification.collection.NotifPipeline
-import com.android.systemui.statusbar.notification.collection.NotificationEntry
-import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
-import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender
-import com.android.systemui.statusbar.phone.NotifActivityLaunchEvents
-import com.android.systemui.util.mockito.mock
-import com.android.systemui.util.mockito.withArgCaptor
-import dagger.BindsInstance
-import dagger.Component
-import org.junit.Assert.assertFalse
-import org.junit.Assert.assertTrue
-import org.junit.Test
-import org.mockito.Mockito.never
-import org.mockito.Mockito.verify
-import org.mockito.Mockito.`when` as whenever
-
-@SmallTest
-class ActivityLaunchAnimCoordinatorTest : SysuiTestCase() {
-
- val activityLaunchEvents: NotifActivityLaunchEvents = mock()
- val pipeline: NotifPipeline = mock()
-
- val coordinator: ActivityLaunchAnimCoordinator =
- DaggerTestActivityStarterCoordinatorComponent
- .factory()
- .create(activityLaunchEvents)
- .coordinator
-
- @Test
- fun testNoLifetimeExtensionIfNoAssociatedActivityLaunch() {
- coordinator.attach(pipeline)
- val lifetimeExtender = withArgCaptor<NotifLifetimeExtender> {
- verify(pipeline).addNotificationLifetimeExtender(capture())
- }
- val fakeEntry = mock<NotificationEntry>().also {
- whenever(it.key).thenReturn("0")
- }
- assertFalse(lifetimeExtender.maybeExtendLifetime(fakeEntry, 0))
- }
-
- @Test
- fun testNoLifetimeExtensionIfAssociatedActivityLaunchAlreadyEnded() {
- coordinator.attach(pipeline)
- val lifetimeExtender = withArgCaptor<NotifLifetimeExtender> {
- verify(pipeline).addNotificationLifetimeExtender(capture())
- }
- val eventListener = withArgCaptor<NotifActivityLaunchEvents.Listener> {
- verify(activityLaunchEvents).registerListener(capture())
- }
- val fakeEntry = mock<NotificationEntry>().also {
- whenever(it.key).thenReturn("0")
- }
- eventListener.onStartLaunchNotifActivity(fakeEntry)
- eventListener.onFinishLaunchNotifActivity(fakeEntry)
- assertFalse(lifetimeExtender.maybeExtendLifetime(fakeEntry, 0))
- }
-
- @Test
- fun testLifetimeExtensionWhileActivityLaunchInProgress() {
- coordinator.attach(pipeline)
- val lifetimeExtender = withArgCaptor<NotifLifetimeExtender> {
- verify(pipeline).addNotificationLifetimeExtender(capture())
- }
- val eventListener = withArgCaptor<NotifActivityLaunchEvents.Listener> {
- verify(activityLaunchEvents).registerListener(capture())
- }
- val onEndLifetimeExtensionCallback =
- mock<NotifLifetimeExtender.OnEndLifetimeExtensionCallback>()
- lifetimeExtender.setCallback(onEndLifetimeExtensionCallback)
-
- val fakeEntry = mock<NotificationEntry>().also {
- whenever(it.key).thenReturn("0")
- }
- eventListener.onStartLaunchNotifActivity(fakeEntry)
- assertTrue(lifetimeExtender.maybeExtendLifetime(fakeEntry, 0))
-
- eventListener.onFinishLaunchNotifActivity(fakeEntry)
- verify(onEndLifetimeExtensionCallback).onEndLifetimeExtension(lifetimeExtender, fakeEntry)
- }
-
- @Test
- fun testCancelLifetimeExtensionDoesNotInvokeCallback() {
- coordinator.attach(pipeline)
- val lifetimeExtender = withArgCaptor<NotifLifetimeExtender> {
- verify(pipeline).addNotificationLifetimeExtender(capture())
- }
- val eventListener = withArgCaptor<NotifActivityLaunchEvents.Listener> {
- verify(activityLaunchEvents).registerListener(capture())
- }
- val onEndLifetimeExtensionCallback =
- mock<NotifLifetimeExtender.OnEndLifetimeExtensionCallback>()
- lifetimeExtender.setCallback(onEndLifetimeExtensionCallback)
-
- val fakeEntry = mock<NotificationEntry>().also {
- whenever(it.key).thenReturn("0")
- }
- eventListener.onStartLaunchNotifActivity(fakeEntry)
- assertTrue(lifetimeExtender.maybeExtendLifetime(fakeEntry, 0))
-
- lifetimeExtender.cancelLifetimeExtension(fakeEntry)
- eventListener.onFinishLaunchNotifActivity(fakeEntry)
- verify(onEndLifetimeExtensionCallback, never())
- .onEndLifetimeExtension(lifetimeExtender, fakeEntry)
- }
-}
-
-@CoordinatorScope
-@Component(modules = [ActivityLaunchAnimCoordinatorModule::class])
-interface TestActivityStarterCoordinatorComponent {
- val coordinator: ActivityLaunchAnimCoordinator
-
- @Component.Factory
- interface Factory {
- fun create(
- @BindsInstance activityLaunchEvents: NotifActivityLaunchEvents
- ): TestActivityStarterCoordinatorComponent
- }
-}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
index 1f9af81..f5a0e2d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
@@ -346,7 +346,7 @@
.build();
row.performDismiss(false);
verify(mNotificationTestHelper.mOnUserInteractionCallback)
- .onDismiss(any(), anyInt(), any());
+ .registerFutureDismissal(any(), anyInt());
}
@Test
@@ -358,6 +358,6 @@
.build();
row.performDismiss(false);
verify(mNotificationTestHelper.mOnUserInteractionCallback, never())
- .onDismiss(any(), anyInt(), any());
+ .registerFutureDismissal(any(), anyInt());
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java
index d5ed37a..7a8b329 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationTestHelper.java
@@ -23,8 +23,11 @@
import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.annotation.Nullable;
import android.app.ActivityManager;
@@ -121,6 +124,7 @@
private StatusBarStateController mStatusBarStateController;
private final PeopleNotificationIdentifier mPeopleNotificationIdentifier;
public final OnUserInteractionCallback mOnUserInteractionCallback;
+ public final Runnable mFutureDismissalRunnable;
public NotificationTestHelper(
Context context,
@@ -182,6 +186,9 @@
mBindPipelineEntryListener = collectionListenerCaptor.getValue();
mPeopleNotificationIdentifier = mock(PeopleNotificationIdentifier.class);
mOnUserInteractionCallback = mock(OnUserInteractionCallback.class);
+ mFutureDismissalRunnable = mock(Runnable.class);
+ when(mOnUserInteractionCallback.registerFutureDismissal(any(), anyInt()))
+ .thenReturn(mFutureDismissalRunnable);
}
/**
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
index dce520c..5f8dda3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
@@ -1490,6 +1490,13 @@
assertAlphaAfterExpansion(mNotificationsScrim, 0f, expansion);
}
+ @Test
+ public void aodStateSetsFrontScrimToNotBlend() {
+ mScrimController.transitionTo(ScrimState.AOD);
+ Assert.assertFalse("Front scrim should not blend with main color",
+ mScrimInFront.shouldBlendWithMainColor());
+ }
+
private void assertAlphaAfterExpansion(ScrimView scrim, float expectedAlpha, float expansion) {
mScrimController.setRawPanelExpansionFraction(expansion);
finishAnimationsImmediately();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterTest.java
index fa867e2..ecea14c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterTest.java
@@ -85,7 +85,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -93,6 +92,7 @@
import org.mockito.stubbing.Answer;
import java.util.ArrayList;
+import java.util.List;
import java.util.Optional;
@SmallTest
@@ -141,12 +141,13 @@
@Mock
private OnUserInteractionCallback mOnUserInteractionCallback;
@Mock
+ private Runnable mFutureDismissalRunnable;
+ @Mock
private StatusBarNotificationActivityStarter mNotificationActivityStarter;
@Mock
private ActivityLaunchAnimator mActivityLaunchAnimator;
@Mock
private InteractionJankMonitor mJankMonitor;
- private StatusBarNotificationActivityStarter.LaunchEventsEmitter mLaunchEventsEmitter;
private FakeExecutor mUiBgExecutor = new FakeExecutor(new FakeSystemClock());
private NotificationTestHelper mNotificationTestHelper;
private ExpandableNotificationRow mNotificationRow;
@@ -187,8 +188,8 @@
when(mEntryManager.getVisibleNotifications()).thenReturn(mActiveNotifications);
when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE);
when(mNotifPipelineFlags.isNewPipelineEnabled()).thenReturn(false);
- when(mOnUserInteractionCallback.getGroupSummaryToDismiss(mNotificationRow.getEntry()))
- .thenReturn(null);
+ when(mOnUserInteractionCallback.registerFutureDismissal(eq(mNotificationRow.getEntry()),
+ anyInt())).thenReturn(mFutureDismissalRunnable);
when(mVisibilityProvider.obtain(anyString(), anyBoolean()))
.thenAnswer(invocation -> NotificationVisibility.obtain(
invocation.getArgument(0), 0, 1, false));
@@ -203,7 +204,6 @@
NotificationListContainer.class),
headsUpManager,
mJankMonitor);
- mLaunchEventsEmitter = new StatusBarNotificationActivityStarter.LaunchEventsEmitter();
mNotificationActivityStarter =
new StatusBarNotificationActivityStarter(
getContext(),
@@ -239,8 +239,7 @@
mock(NotificationPresenter.class),
mock(NotificationPanelViewController.class),
mActivityLaunchAnimator,
- notificationAnimationProvider,
- mLaunchEventsEmitter
+ notificationAnimationProvider
);
// set up dismissKeyguardThenExecute to synchronously invoke the OnDismissAction arg
@@ -264,16 +263,23 @@
@Test
public void testOnNotificationClicked_keyGuardShowing()
throws PendingIntent.CanceledException, RemoteException {
+ // To get the order right, collect posted runnables and run them later
+ List<Runnable> runnables = new ArrayList<>();
+ doAnswer(answerVoid(r -> runnables.add((Runnable) r)))
+ .when(mHandler).post(any(Runnable.class));
// Given
- StatusBarNotification sbn = mNotificationRow.getEntry().getSbn();
- sbn.getNotification().contentIntent = mContentIntent;
- sbn.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
+ NotificationEntry entry = mNotificationRow.getEntry();
+ Notification notification = entry.getSbn().getNotification();
+ notification.contentIntent = mContentIntent;
+ notification.flags |= Notification.FLAG_AUTO_CANCEL;
when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mCentralSurfaces.isOccluded()).thenReturn(true);
// When
- mNotificationActivityStarter.onNotificationClicked(sbn, mNotificationRow);
+ mNotificationActivityStarter.onNotificationClicked(entry, mNotificationRow);
+ // Run the collected runnables in fifo order, the way post() really does.
+ while (!runnables.isEmpty()) runnables.remove(0).run();
// Then
verify(mShadeController, atLeastOnce()).collapsePanel();
@@ -283,24 +289,27 @@
verify(mAssistManager).hideAssist();
- InOrder orderVerifier = Mockito.inOrder(mClickNotifier, mOnUserInteractionCallback);
- orderVerifier.verify(mClickNotifier).onNotificationClick(
- eq(sbn.getKey()), any(NotificationVisibility.class));
+ InOrder orderVerifier = Mockito.inOrder(mClickNotifier, mOnUserInteractionCallback,
+ mFutureDismissalRunnable);
// Notification calls dismiss callback to remove notification due to FLAG_AUTO_CANCEL
- orderVerifier.verify(mOnUserInteractionCallback).onDismiss(mNotificationRow.getEntry(),
- REASON_CLICK, null);
+ orderVerifier.verify(mOnUserInteractionCallback)
+ .registerFutureDismissal(eq(entry), eq(REASON_CLICK));
+ orderVerifier.verify(mClickNotifier).onNotificationClick(
+ eq(entry.getKey()), any(NotificationVisibility.class));
+ orderVerifier.verify(mFutureDismissalRunnable).run();
}
@Test
public void testOnNotificationClicked_bubble_noContentIntent_noKeyGuard()
throws RemoteException {
- StatusBarNotification sbn = mBubbleNotificationRow.getEntry().getSbn();
+ NotificationEntry entry = mBubbleNotificationRow.getEntry();
+ StatusBarNotification sbn = entry.getSbn();
// Given
sbn.getNotification().contentIntent = null;
// When
- mNotificationActivityStarter.onNotificationClicked(sbn, mBubbleNotificationRow);
+ mNotificationActivityStarter.onNotificationClicked(entry, mBubbleNotificationRow);
// Then
verify(mBubblesManager).expandStackAndSelectBubble(eq(mBubbleNotificationRow.getEntry()));
@@ -311,20 +320,22 @@
verify(mAssistManager).hideAssist();
verify(mClickNotifier).onNotificationClick(
- eq(sbn.getKey()), any(NotificationVisibility.class));
+ eq(entry.getKey()), any(NotificationVisibility.class));
// The content intent should NOT be sent on click.
verifyZeroInteractions(mContentIntent);
// Notification should not be cancelled.
- verify(mOnUserInteractionCallback, never()).onDismiss(eq(mNotificationRow.getEntry()),
- anyInt(), eq(null));
+ verify(mOnUserInteractionCallback, never())
+ .registerFutureDismissal(eq(mNotificationRow.getEntry()), anyInt());
+ verify(mFutureDismissalRunnable, never()).run();
}
@Test
public void testOnNotificationClicked_bubble_noContentIntent_keyGuardShowing()
throws RemoteException {
- StatusBarNotification sbn = mBubbleNotificationRow.getEntry().getSbn();
+ NotificationEntry entry = mBubbleNotificationRow.getEntry();
+ StatusBarNotification sbn = entry.getSbn();
// Given
sbn.getNotification().contentIntent = null;
@@ -332,7 +343,7 @@
when(mCentralSurfaces.isOccluded()).thenReturn(true);
// When
- mNotificationActivityStarter.onNotificationClicked(sbn, mBubbleNotificationRow);
+ mNotificationActivityStarter.onNotificationClicked(entry, mBubbleNotificationRow);
// Then
verify(mBubblesManager).expandStackAndSelectBubble(eq(mBubbleNotificationRow.getEntry()));
@@ -342,7 +353,7 @@
verify(mAssistManager).hideAssist();
verify(mClickNotifier).onNotificationClick(
- eq(sbn.getKey()), any(NotificationVisibility.class));
+ eq(entry.getKey()), any(NotificationVisibility.class));
// The content intent should NOT be sent on click.
verifyZeroInteractions(mContentIntent);
@@ -354,7 +365,8 @@
@Test
public void testOnNotificationClicked_bubble_withContentIntent_keyGuardShowing()
throws RemoteException {
- StatusBarNotification sbn = mBubbleNotificationRow.getEntry().getSbn();
+ NotificationEntry entry = mBubbleNotificationRow.getEntry();
+ StatusBarNotification sbn = entry.getSbn();
// Given
sbn.getNotification().contentIntent = mContentIntent;
@@ -362,7 +374,7 @@
when(mCentralSurfaces.isOccluded()).thenReturn(true);
// When
- mNotificationActivityStarter.onNotificationClicked(sbn, mBubbleNotificationRow);
+ mNotificationActivityStarter.onNotificationClicked(entry, mBubbleNotificationRow);
// Then
verify(mBubblesManager).expandStackAndSelectBubble(mBubbleNotificationRow.getEntry());
@@ -372,7 +384,7 @@
verify(mAssistManager).hideAssist();
verify(mClickNotifier).onNotificationClick(
- eq(sbn.getKey()), any(NotificationVisibility.class));
+ eq(entry.getKey()), any(NotificationVisibility.class));
// The content intent should NOT be sent on click.
verify(mContentIntent).getIntent();
@@ -405,57 +417,4 @@
// THEN display should try wake up for the full screen intent
verify(mCentralSurfaces).wakeUpForFullScreenIntent();
}
-
- @Test
- public void testNotifActivityStarterEventSourceStartEvent_onNotificationClicked() {
- NotifActivityLaunchEvents.Listener listener =
- mock(NotifActivityLaunchEvents.Listener.class);
- mLaunchEventsEmitter.registerListener(listener);
- mNotificationActivityStarter
- .onNotificationClicked(mNotificationRow.getEntry().getSbn(), mNotificationRow);
- verify(listener).onStartLaunchNotifActivity(mNotificationRow.getEntry());
- }
-
- @Test
- public void testNotifActivityStarterEventSourceFinishEvent_dismissKeyguardCancelled() {
- NotifActivityLaunchEvents.Listener listener =
- mock(NotifActivityLaunchEvents.Listener.class);
- mLaunchEventsEmitter.registerListener(listener);
- // set up dismissKeyguardThenExecute to synchronously invoke the cancel runnable arg
- doAnswer(answerVoid(
- (OnDismissAction dismissAction, Runnable cancel, Boolean afterKeyguardGone) ->
- cancel.run()))
- .when(mActivityStarter)
- .dismissKeyguardThenExecute(any(OnDismissAction.class), any(), anyBoolean());
- mNotificationActivityStarter
- .onNotificationClicked(mNotificationRow.getEntry().getSbn(), mNotificationRow);
- verify(listener).onFinishLaunchNotifActivity(mNotificationRow.getEntry());
- }
-
- @Test
- public void testNotifActivityStarterEventSourceFinishEvent_postPanelCollapse()
- throws Exception {
- NotifActivityLaunchEvents.Listener listener =
- mock(NotifActivityLaunchEvents.Listener.class);
- mLaunchEventsEmitter.registerListener(listener);
- mNotificationActivityStarter
- .onNotificationClicked(mNotificationRow.getEntry().getSbn(), mNotificationRow);
- ArgumentCaptor<ActivityLaunchAnimator.Controller> controllerCaptor =
- ArgumentCaptor.forClass(ActivityLaunchAnimator.Controller.class);
- verify(mActivityLaunchAnimator).startPendingIntentWithAnimation(
- controllerCaptor.capture(), anyBoolean(), any(), any());
- controllerCaptor.getValue().onIntentStarted(false);
- verify(listener).onFinishLaunchNotifActivity(mNotificationRow.getEntry());
- }
-
- @Test
- public void testNotifActivityStarterEventSourceFinishEvent_postPanelCollapse_noAnimate() {
- NotifActivityLaunchEvents.Listener listener =
- mock(NotifActivityLaunchEvents.Listener.class);
- mLaunchEventsEmitter.registerListener(listener);
- when(mCentralSurfaces.shouldAnimateLaunch(anyBoolean())).thenReturn(false);
- mNotificationActivityStarter
- .onNotificationClicked(mNotificationRow.getEntry().getSbn(), mNotificationRow);
- verify(listener).onFinishLaunchNotifActivity(mNotificationRow.getEntry());
- }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java
index 98397fb..6abc687 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/fragment/CollapsedStatusBarFragmentTest.java
@@ -379,7 +379,7 @@
mCommandQueue,
mCarrierConfigTracker,
new CollapsedStatusBarFragmentLogger(
- new LogBuffer("TEST", 1, 1, mock(LogcatEchoTracker.class)),
+ new LogBuffer("TEST", 1, mock(LogcatEchoTracker.class)),
new DisableFlagsLogger()
),
mOperatorNameViewControllerFactory,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/collection/RingBufferTest.kt b/packages/SystemUI/tests/src/com/android/systemui/util/collection/RingBufferTest.kt
new file mode 100644
index 0000000..5e09b81
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/util/collection/RingBufferTest.kt
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.util.collection
+
+import android.testing.AndroidTestingRunner
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertSame
+import org.junit.Assert.assertThrows
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.MockitoAnnotations
+
+@SmallTest
+@RunWith(AndroidTestingRunner::class)
+class RingBufferTest : SysuiTestCase() {
+
+ private val buffer = RingBuffer(5) { TestElement() }
+
+ private val history = mutableListOf<TestElement>()
+
+ @Before
+ fun setUp() {
+ MockitoAnnotations.initMocks(this)
+ }
+
+ @Test
+ fun testBarelyFillBuffer() {
+ fillBuffer(5)
+
+ assertEquals(0, buffer[0].id)
+ assertEquals(1, buffer[1].id)
+ assertEquals(2, buffer[2].id)
+ assertEquals(3, buffer[3].id)
+ assertEquals(4, buffer[4].id)
+ }
+
+ @Test
+ fun testPartiallyFillBuffer() {
+ fillBuffer(3)
+
+ assertEquals(3, buffer.size)
+
+ assertEquals(0, buffer[0].id)
+ assertEquals(1, buffer[1].id)
+ assertEquals(2, buffer[2].id)
+
+ assertThrows(IndexOutOfBoundsException::class.java) { buffer[3] }
+ assertThrows(IndexOutOfBoundsException::class.java) { buffer[4] }
+ }
+
+ @Test
+ fun testSpinBuffer() {
+ fillBuffer(277)
+
+ assertEquals(272, buffer[0].id)
+ assertEquals(273, buffer[1].id)
+ assertEquals(274, buffer[2].id)
+ assertEquals(275, buffer[3].id)
+ assertEquals(276, buffer[4].id)
+ assertThrows(IndexOutOfBoundsException::class.java) { buffer[5] }
+
+ assertEquals(5, buffer.size)
+ }
+
+ @Test
+ fun testElementsAreRecycled() {
+ fillBuffer(23)
+
+ assertSame(history[4], buffer[1])
+ assertSame(history[9], buffer[1])
+ assertSame(history[14], buffer[1])
+ assertSame(history[19], buffer[1])
+ }
+
+ @Test
+ fun testIterator() {
+ fillBuffer(13)
+
+ val iterator = buffer.iterator()
+
+ for (i in 0 until 5) {
+ assertEquals(history[8 + i], iterator.next())
+ }
+ assertFalse(iterator.hasNext())
+ assertThrows(NoSuchElementException::class.java) { iterator.next() }
+ }
+
+ @Test
+ fun testForEach() {
+ fillBuffer(13)
+ var i = 8
+
+ buffer.forEach {
+ assertEquals(history[i], it)
+ i++
+ }
+ assertEquals(13, i)
+ }
+
+ private fun fillBuffer(count: Int) {
+ for (i in 0 until count) {
+ val elem = buffer.advance()
+ elem.id = history.size
+ history.add(elem)
+ }
+ }
+}
+
+private class TestElement(var id: Int = 0) {
+ override fun toString(): String {
+ return "{TestElement $id}"
+ }
+}
\ No newline at end of file
diff --git a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogImplTest.java
index 9493456..312db2d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogImplTest.java
@@ -38,6 +38,7 @@
import androidx.test.filters.SmallTest;
+import com.android.internal.jank.InteractionJankMonitor;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
@@ -85,6 +86,8 @@
MediaOutputDialogFactory mMediaOutputDialogFactory;
@Mock
ActivityStarter mActivityStarter;
+ @Mock
+ InteractionJankMonitor mInteractionJankMonitor;
@Before
public void setup() throws Exception {
@@ -99,7 +102,8 @@
mDeviceProvisionedController,
mConfigurationController,
mMediaOutputDialogFactory,
- mActivityStarter);
+ mActivityStarter,
+ mInteractionJankMonitor);
mDialog.init(0, null);
State state = createShellState();
mDialog.onStateChangedH(state);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/TestableBubbleController.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/TestableBubbleController.java
index 9646edf..9ca6bb0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/TestableBubbleController.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/TestableBubbleController.java
@@ -69,7 +69,7 @@
statusBarService, windowManager, windowManagerShellWrapper, launcherApps,
bubbleLogger, taskStackListener, shellTaskOrganizer, positioner, displayController,
oneHandedOptional, dragAndDropController, shellMainExecutor, shellMainHandler,
- taskViewTransitions, syncQueue);
+ new SyncExecutor(), taskViewTransitions, syncQueue);
setInflateSynchronously(true);
initialize();
}
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 6d3620f..ca0a780 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -1965,15 +1965,6 @@
}
}
}
- final AutofillId[] fieldClassificationIds = lastResponse.getFieldClassificationIds();
-
- if (!hasAtLeastOneDataset && fieldClassificationIds == null) {
- if (sVerbose) {
- Slog.v(TAG, "logContextCommittedLocked(): skipped (no datasets nor fields "
- + "classification ids)");
- }
- return;
- }
for (int i = 0; i < mViewStates.size(); i++) {
final ViewState viewState = mViewStates.valueAt(i);
@@ -2022,6 +2013,7 @@
}
continue;
}
+
// Check if value match a dataset.
if (hasAtLeastOneDataset) {
for (int j = 0; j < responseCount; j++) {
@@ -2078,7 +2070,6 @@
} // else
} // for j
}
-
} // else
} // else
}
diff --git a/services/companion/java/com/android/server/companion/AssociationRequestsProcessor.java b/services/companion/java/com/android/server/companion/AssociationRequestsProcessor.java
index 7a5fa62..570e4e6 100644
--- a/services/companion/java/com/android/server/companion/AssociationRequestsProcessor.java
+++ b/services/companion/java/com/android/server/companion/AssociationRequestsProcessor.java
@@ -182,7 +182,7 @@
// 2b.1. Populate the request with required info.
request.setPackageName(packageName);
request.setUserId(userId);
- request.setSkipPrompt(mayAssociateWithoutPrompt(request, packageName, userId));
+ request.setSkipPrompt(mayAssociateWithoutPrompt(packageName, userId));
// 2b.2. Prepare extras and create an Intent.
final Bundle extras = new Bundle();
@@ -321,18 +321,7 @@
}
};
- private boolean mayAssociateWithoutPrompt(@NonNull AssociationRequest request,
- @NonNull String packageName, @UserIdInt int userId) {
- final String deviceProfile = request.getDeviceProfile();
- if (deviceProfile != null) {
- final boolean isRoleHolder = Binder.withCleanCallingIdentity(
- () -> isRoleHolder(mContext, userId, packageName, deviceProfile));
- if (isRoleHolder) {
- // Don't need to collect user's consent since app already holds the role.
- return true;
- }
- }
-
+ private boolean mayAssociateWithoutPrompt(@NonNull String packageName, @UserIdInt int userId) {
// Below we check if the requesting package is allowlisted (usually by the OEM) for creating
// CDM associations without user confirmation (prompt).
// For this we'll check to config arrays:
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
index 8622ef0..0bfe282 100644
--- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
+++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
@@ -78,6 +78,7 @@
import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.os.ShellCallback;
+import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArraySet;
@@ -121,8 +122,10 @@
private static final String PREF_FILE_NAME = "companion_device_preferences.xml";
private static final String PREF_KEY_AUTO_REVOKE_GRANTS_DONE = "auto_revoke_grants_done";
+ private static final String SYS_PROP_DEBUG_REMOVAL_TIME_WINDOW =
+ "debug.cdm.cdmservice.removal_time_window";
- private static final long ASSOCIATION_CLEAN_UP_TIME_WINDOW = DAYS.toMillis(3 * 30); // 3 months
+ private static final long ASSOCIATION_REMOVAL_TIME_WINDOW_DEFAULT = DAYS.toMillis(90);
private PersistentDataStore mPersistentStore;
private final PersistUserStateHandler mUserPersistenceHandler;
@@ -211,8 +214,8 @@
mPackageMonitor.register(context, FgThread.get().getLooper(), UserHandle.ALL, true);
mDevicePresenceMonitor.init(context);
} else if (phase == PHASE_BOOT_COMPLETED) {
- // Run the Association CleanUp job service daily.
- AssociationCleanUpService.schedule(getContext());
+ // Run the Inactive Association Removal job service daily.
+ InactiveAssociationsRemovalService.schedule(getContext());
}
}
@@ -410,17 +413,20 @@
mCompanionAppController.onPackagesChanged(userId);
}
- // Revoke associations if the selfManaged companion device does not connect for 3
- // months for specific profile.
- private void associationCleanUp(String profile) {
+ // Revoke associations if the selfManaged companion device does not connect for 3 months.
+ void removeInactiveSelfManagedAssociations() {
+ final long currentTime = System.currentTimeMillis();
+ long removalWindow = SystemProperties.getLong(SYS_PROP_DEBUG_REMOVAL_TIME_WINDOW, -1);
+ if (removalWindow <= 0) {
+ // 0 or negative values indicate that the sysprop was never set or should be ignored.
+ removalWindow = ASSOCIATION_REMOVAL_TIME_WINDOW_DEFAULT;
+ }
+
for (AssociationInfo ai : mAssociationStore.getAssociations()) {
- if (ai.isSelfManaged()
- && profile.equals(ai.getDeviceProfile())
- && System.currentTimeMillis() - ai.getLastTimeConnectedMs()
- >= ASSOCIATION_CLEAN_UP_TIME_WINDOW) {
- Slog.i(TAG, "Removing the association for associationId: "
- + ai.getId()
- + " due to the device does not connect for 3 months.");
+ if (!ai.isSelfManaged()) continue;
+ final boolean isInactive = currentTime - ai.getLastTimeConnectedMs() >= removalWindow;
+ if (isInactive) {
+ Slog.i(TAG, "Removing inactive self-managed association: " + ai.getId());
disassociateInternal(ai.getId());
}
}
@@ -1078,10 +1084,10 @@
return ArrayUtils.contains(array, a) || ArrayUtils.contains(array, b);
}
- private class LocalService extends CompanionDeviceManagerServiceInternal {
+ private class LocalService implements CompanionDeviceManagerServiceInternal {
@Override
- public void associationCleanUp(String profile) {
- CompanionDeviceManagerService.this.associationCleanUp(profile);
+ public void removeInactiveSelfManagedAssociations() {
+ CompanionDeviceManagerService.this.removeInactiveSelfManagedAssociations();
}
}
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerServiceInternal.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerServiceInternal.java
index 326fefe..3649240 100644
--- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerServiceInternal.java
+++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerServiceInternal.java
@@ -18,12 +18,10 @@
/**
* Companion Device Manager Local System Service Interface.
- *
- * @hide Only for use within the system server.
*/
-public abstract class CompanionDeviceManagerServiceInternal {
+interface CompanionDeviceManagerServiceInternal {
/**
- * @see CompanionDeviceManagerService#associationCleanUp
+ * @see CompanionDeviceManagerService#removeInactiveSelfManagedAssociations
*/
- public abstract void associationCleanUp(String profile);
+ void removeInactiveSelfManagedAssociations();
}
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java b/services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java
index 6a19a42..434d283 100644
--- a/services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java
+++ b/services/companion/java/com/android/server/companion/CompanionDeviceShellCommand.java
@@ -17,6 +17,7 @@
package com.android.server.companion;
import android.companion.AssociationInfo;
+import android.os.Binder;
import android.os.ShellCommand;
import android.util.Log;
import android.util.Slog;
@@ -96,6 +97,16 @@
mDevicePresenceMonitor.simulateDeviceDisappeared(associationId);
break;
+ case "remove-inactive-associations": {
+ // This command should trigger the same "clean-up" job as performed by the
+ // InactiveAssociationsRemovalService JobService. However, since the
+ // InactiveAssociationsRemovalService run as system, we want to run this
+ // as system (not as shell/root) as well.
+ Binder.withCleanCallingIdentity(
+ mService::removeInactiveSelfManagedAssociations);
+ }
+ break;
+
default:
return handleDefaultCommands(cmd);
}
@@ -142,6 +153,12 @@
pw.println(" invoked for the same device (same ASSOCIATION_ID) no longer than");
pw.println(" 60 seconds ago.");
pw.println(" USE FOR DEBUGGING AND/OR TESTING PURPOSES ONLY.");
+
+ pw.println(" remove-inactive-associations");
+ pw.println(" Remove self-managed associations that have not been active ");
+ pw.println(" for a long time (90 days or as configured via ");
+ pw.println(" \"debug.cdm.cdmservice.cleanup_time_window\" system property). ");
+ pw.println(" USE FOR DEBUGGING AND/OR TESTING PURPOSES ONLY.");
}
private int getNextIntArgRequired() {
diff --git a/services/companion/java/com/android/server/companion/AssociationCleanUpService.java b/services/companion/java/com/android/server/companion/InactiveAssociationsRemovalService.java
similarity index 68%
rename from services/companion/java/com/android/server/companion/AssociationCleanUpService.java
rename to services/companion/java/com/android/server/companion/InactiveAssociationsRemovalService.java
index 55246e1..3482863 100644
--- a/services/companion/java/com/android/server/companion/AssociationCleanUpService.java
+++ b/services/companion/java/com/android/server/companion/InactiveAssociationsRemovalService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 The Android Open Source Project
+ * Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,10 +24,8 @@
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
-import android.companion.AssociationRequest;
import android.content.ComponentName;
import android.content.Context;
-import android.os.AsyncTask;
import android.util.Slog;
import com.android.server.LocalServices;
@@ -37,26 +35,24 @@
* The job will be executed only if the device is charging and in idle mode due to the application
* will be killed if association/role are revoked.
*/
-public class AssociationCleanUpService extends JobService {
- private static final int JOB_ID = AssociationCleanUpService.class.hashCode();
+public class InactiveAssociationsRemovalService extends JobService {
+ private static final int JOB_ID = InactiveAssociationsRemovalService.class.hashCode();
private static final long ONE_DAY_INTERVAL = DAYS.toMillis(1);
@Override
public boolean onStartJob(final JobParameters params) {
- Slog.i(TAG, "Execute the Association CleanUp job");
- // Special policy for APP_STREAMING role that need to revoke associations if the device
- // does not connect for 3 months.
- AsyncTask.execute(() -> {
- LocalServices.getService(CompanionDeviceManagerServiceInternal.class)
- .associationCleanUp(AssociationRequest.DEVICE_PROFILE_APP_STREAMING);
- jobFinished(params, false);
- });
+ Slog.i(TAG, "Execute the Association Removal job");
+ // Special policy for selfManaged that need to revoke associations if the device
+ // does not connect for 90 days.
+ LocalServices.getService(CompanionDeviceManagerServiceInternal.class)
+ .removeInactiveSelfManagedAssociations();
+ jobFinished(params, false);
return true;
}
@Override
public boolean onStopJob(final JobParameters params) {
- Slog.i(TAG, "Association cleanup job stopped; id=" + params.getJobId()
+ Slog.i(TAG, "Association removal job stopped; id=" + params.getJobId()
+ ", reason="
+ JobParameters.getInternalReasonCodeDescription(
params.getInternalStopReasonCode()));
@@ -64,10 +60,10 @@
}
static void schedule(Context context) {
- Slog.i(TAG, "Scheduling the Association Cleanup job");
+ Slog.i(TAG, "Scheduling the Association Removal job");
final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
final JobInfo job = new JobInfo.Builder(JOB_ID,
- new ComponentName(context, AssociationCleanUpService.class))
+ new ComponentName(context, InactiveAssociationsRemovalService.class))
.setRequiresCharging(true)
.setRequiresDeviceIdle(true)
.setPeriodic(ONE_DAY_INTERVAL)
@@ -75,3 +71,4 @@
jobScheduler.schedule(job);
}
}
+
diff --git a/services/companion/java/com/android/server/companion/virtual/InputController.java b/services/companion/java/com/android/server/companion/virtual/InputController.java
index 80182d2..dc7573e 100644
--- a/services/companion/java/com/android/server/companion/virtual/InputController.java
+++ b/services/companion/java/com/android/server/companion/virtual/InputController.java
@@ -37,6 +37,7 @@
import android.util.Slog;
import android.view.Display;
import android.view.InputDevice;
+import android.view.WindowManager;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -83,22 +84,26 @@
private final NativeWrapper mNativeWrapper;
private final DisplayManagerInternal mDisplayManagerInternal;
private final InputManagerInternal mInputManagerInternal;
+ private final WindowManager mWindowManager;
private final DeviceCreationThreadVerifier mThreadVerifier;
- InputController(@NonNull Object lock, @NonNull Handler handler) {
- this(lock, new NativeWrapper(), handler,
+ InputController(@NonNull Object lock, @NonNull Handler handler,
+ @NonNull WindowManager windowManager) {
+ this(lock, new NativeWrapper(), handler, windowManager,
// Verify that virtual devices are not created on the handler thread.
() -> !handler.getLooper().isCurrentThread());
}
@VisibleForTesting
InputController(@NonNull Object lock, @NonNull NativeWrapper nativeWrapper,
- @NonNull Handler handler, @NonNull DeviceCreationThreadVerifier threadVerifier) {
+ @NonNull Handler handler, @NonNull WindowManager windowManager,
+ @NonNull DeviceCreationThreadVerifier threadVerifier) {
mLock = lock;
mHandler = handler;
mNativeWrapper = nativeWrapper;
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
+ mWindowManager = windowManager;
mThreadVerifier = threadVerifier;
}
@@ -209,6 +214,15 @@
mInputManagerInternal.setDisplayEligibilityForPointerCapture(displayId, isEligible);
}
+ void setLocalIme(int displayId) {
+ // WM throws a SecurityException if the display is untrusted.
+ if ((mDisplayManagerInternal.getDisplayInfo(displayId).flags & Display.FLAG_TRUSTED)
+ == Display.FLAG_TRUSTED) {
+ mWindowManager.setDisplayImePolicy(displayId,
+ WindowManager.DISPLAY_IME_POLICY_LOCAL);
+ }
+ }
+
@GuardedBy("mLock")
private void updateActivePointerDisplayIdLocked() {
InputDeviceDescriptor mostRecentlyCreatedMouse = null;
diff --git a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceImpl.java b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceImpl.java
index 9802b97..638b3ae 100644
--- a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceImpl.java
+++ b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceImpl.java
@@ -62,6 +62,7 @@
import android.util.Slog;
import android.util.SparseArray;
import android.view.Display;
+import android.view.WindowManager;
import android.widget.Toast;
import android.window.DisplayWindowPolicyController;
@@ -167,7 +168,9 @@
mParams = params;
if (inputController == null) {
mInputController = new InputController(
- mVirtualDeviceLock, context.getMainThreadHandler());
+ mVirtualDeviceLock,
+ context.getMainThreadHandler(),
+ context.getSystemService(WindowManager.class));
} else {
mInputController = inputController;
}
@@ -537,6 +540,7 @@
mInputController.setPointerAcceleration(1f, displayId);
mInputController.setDisplayEligibilityForPointerCapture(/* isEligible= */ false,
displayId);
+ mInputController.setLocalIme(displayId);
// Since we're being called in the middle of the display being created, we post a
// task to grab the wakelock instead of doing it synchronously here, to avoid
diff --git a/services/core/java/com/android/server/am/AppBatteryTracker.java b/services/core/java/com/android/server/am/AppBatteryTracker.java
index c09bb2d..1a566a9 100644
--- a/services/core/java/com/android/server/am/AppBatteryTracker.java
+++ b/services/core/java/com/android/server/am/AppBatteryTracker.java
@@ -1258,6 +1258,16 @@
+ "current_drain_event_duration_based_threshold_enabled";
/**
+ * Whether or not we should move the app into the restricted bucket level if its background
+ * battery usage goes beyond the threshold. Note this different from the flag
+ * {@link AppRestrictionController.ConstantsObserver#KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS}
+ * which is to control the overall auto bg restrictions.
+ */
+ static final String KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED =
+ DEVICE_CONFIG_SUBNAMESPACE_PREFIX
+ + "current_drain_auto_restrict_abusive_apps_enabled";
+
+ /**
* The types of battery drain we're checking on each app; if the sum of the battery drain
* exceeds the threshold, it'll be moved to restricted standby bucket; the type here
* must be one of, or combination of {@link #BATTERY_USAGE_TYPE_BACKGROUND},
@@ -1353,6 +1363,11 @@
final boolean mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled;
/**
+ * Default value to {@link #mBgCurrentDrainAutoRestrictAbusiveAppsEnabled}.
+ */
+ final boolean mDefaultBgCurrentDrainAutoRestrictAbusiveAppsEnabled;
+
+ /**
* Default value to {@link #mBgCurrentDrainRestrictedBucketTypes}.
*/
final int mDefaultCurrentDrainTypesToRestrictedBucket;
@@ -1430,6 +1445,11 @@
volatile boolean mBgCurrentDrainEventDurationBasedThresholdEnabled;
/**
+ * @see #KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED.
+ */
+ volatile boolean mBgCurrentDrainAutoRestrictAbusiveAppsEnabled;
+
+ /**
* @see #KEY_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET.
*/
volatile int mBgCurrentDrainRestrictedBucketTypes;
@@ -1520,6 +1540,8 @@
R.integer.config_bg_current_drain_location_min_duration) * 1_000;
mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled = resources.getBoolean(
R.bool.config_bg_current_drain_event_duration_based_threshold_enabled);
+ mDefaultBgCurrentDrainAutoRestrictAbusiveAppsEnabled = resources.getBoolean(
+ R.bool.config_bg_current_drain_auto_restrict_abusive_apps);
mDefaultCurrentDrainTypesToRestrictedBucket = resources.getInteger(
R.integer.config_bg_current_drain_types_to_restricted_bucket);
mDefaultBgCurrentDrainTypesToBgRestricted = resources.getInteger(
@@ -1569,6 +1591,9 @@
case KEY_BG_CURRENT_DRAIN_POWER_COMPONENTS:
updateCurrentDrainThreshold();
break;
+ case KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED:
+ updateBgCurrentDrainAutoRestrictAbusiveAppsEnabled();
+ break;
case KEY_BG_CURRENT_DRAIN_WINDOW:
updateCurrentDrainWindow();
break;
@@ -1701,6 +1726,13 @@
DEFAULT_BG_CURRENT_DRAIN_DECOUPLE_THRESHOLD);
}
+ private void updateBgCurrentDrainAutoRestrictAbusiveAppsEnabled() {
+ mBgCurrentDrainAutoRestrictAbusiveAppsEnabled = DeviceConfig.getBoolean(
+ DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
+ KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED,
+ mDefaultBgCurrentDrainAutoRestrictAbusiveAppsEnabled);
+ }
+
@Override
public void onSystemReady() {
mBatteryFullChargeMah =
@@ -1714,6 +1746,7 @@
updateCurrentDrainEventDurationBasedThresholdEnabled();
updateCurrentDrainExemptedTypes();
updateCurrentDrainDecoupleThresholds();
+ updateBgCurrentDrainAutoRestrictAbusiveAppsEnabled();
}
@Override
@@ -1728,9 +1761,12 @@
if (pair != null) {
final long lastInteractionTime = mLastInteractionTime.get(uid, 0L);
final long[] ts = pair.first;
- final int restrictedLevel = ts[TIME_STAMP_INDEX_RESTRICTED_BUCKET]
- > (lastInteractionTime + mBgCurrentDrainInteractionGracePeriodMs)
- && mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled()
+ final boolean noInteractionRecently = ts[TIME_STAMP_INDEX_RESTRICTED_BUCKET]
+ > (lastInteractionTime + mBgCurrentDrainInteractionGracePeriodMs);
+ final boolean canRestrict =
+ mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled()
+ && mBgCurrentDrainAutoRestrictAbusiveAppsEnabled;
+ final int restrictedLevel = noInteractionRecently && canRestrict
? RESTRICTION_LEVEL_RESTRICTED_BUCKET
: RESTRICTION_LEVEL_ADAPTIVE_BUCKET;
if (maxLevel > RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) {
@@ -2066,6 +2102,10 @@
pw.print('=');
pw.println(mBgCurrentDrainEventDurationBasedThresholdEnabled);
pw.print(prefix);
+ pw.print(KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED);
+ pw.print('=');
+ pw.println(mBgCurrentDrainAutoRestrictAbusiveAppsEnabled);
+ pw.print(prefix);
pw.print(KEY_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET);
pw.print('=');
pw.println(batteryUsageTypesToString(mBgCurrentDrainRestrictedBucketTypes));
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index b9da144..b56654f 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -3258,7 +3258,7 @@
return AppOpsManager.MODE_IGNORED;
}
synchronized (this) {
- if (isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass)) {
+ if (isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass, true)) {
return AppOpsManager.MODE_IGNORED;
}
code = AppOpsManager.opToSwitch(code);
@@ -3483,7 +3483,7 @@
final int switchCode = AppOpsManager.opToSwitch(code);
final UidState uidState = ops.uidState;
- if (isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass)) {
+ if (isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass, false)) {
attributedOp.rejected(uidState.state, flags);
scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag, flags,
AppOpsManager.MODE_IGNORED);
@@ -3997,7 +3997,8 @@
final Op op = getOpLocked(ops, code, uid, true);
final AttributedOp attributedOp = op.getOrCreateAttribution(op, attributionTag);
final UidState uidState = ops.uidState;
- isRestricted = isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass);
+ isRestricted = isOpRestrictedLocked(uid, code, packageName, attributionTag, pvr.bypass,
+ false);
final int switchCode = AppOpsManager.opToSwitch(code);
// If there is a non-default per UID policy (we set UID op mode only if
// non-default) it takes over, otherwise use the per package policy.
@@ -4834,7 +4835,7 @@
}
private boolean isOpRestrictedLocked(int uid, int code, String packageName,
- String attributionTag, @Nullable RestrictionBypass appBypass) {
+ String attributionTag, @Nullable RestrictionBypass appBypass, boolean isCheckOp) {
int restrictionSetCount = mOpGlobalRestrictions.size();
for (int i = 0; i < restrictionSetCount; i++) {
@@ -4851,7 +4852,8 @@
// For each client, check that the given op is not restricted, or that the given
// package is exempt from the restriction.
ClientUserRestrictionState restrictionState = mOpUserRestrictions.valueAt(i);
- if (restrictionState.hasRestriction(code, packageName, attributionTag, userHandle)) {
+ if (restrictionState.hasRestriction(code, packageName, attributionTag, userHandle,
+ isCheckOp)) {
RestrictionBypass opBypass = opAllowSystemBypassRestriction(code);
if (opBypass != null) {
// If we are the system, bypass user restrictions for certain codes
@@ -7224,7 +7226,7 @@
}
public boolean hasRestriction(int restriction, String packageName, String attributionTag,
- int userId) {
+ int userId, boolean isCheckOp) {
if (perUserRestrictions == null) {
return false;
}
@@ -7243,6 +7245,9 @@
return true;
}
+ if (isCheckOp) {
+ return !perUserExclusions.includes(packageName);
+ }
return !perUserExclusions.contains(packageName, attributionTag);
}
@@ -7409,7 +7414,8 @@
int numRestrictions = mOpUserRestrictions.size();
for (int i = 0; i < numRestrictions; i++) {
if (mOpUserRestrictions.valueAt(i)
- .hasRestriction(code, pkg, attributionTag, user.getIdentifier())) {
+ .hasRestriction(code, pkg, attributionTag, user.getIdentifier(),
+ false)) {
number++;
}
}
diff --git a/services/core/java/com/android/server/display/color/ColorDisplayService.java b/services/core/java/com/android/server/display/color/ColorDisplayService.java
index 8035526..8de150a 100644
--- a/services/core/java/com/android/server/display/color/ColorDisplayService.java
+++ b/services/core/java/com/android/server/display/color/ColorDisplayService.java
@@ -948,19 +948,15 @@
if (!isColorModeAvailable(colorMode)) {
final int[] mappedColorModes = getContext().getResources().getIntArray(
R.array.config_mappedColorModes);
- if (colorMode == COLOR_MODE_BOOSTED && mappedColorModes.length > COLOR_MODE_NATURAL
- && isColorModeAvailable(mappedColorModes[COLOR_MODE_NATURAL])) {
- colorMode = COLOR_MODE_NATURAL;
- } else if (colorMode == COLOR_MODE_SATURATED
- && mappedColorModes.length > COLOR_MODE_AUTOMATIC
- && isColorModeAvailable(mappedColorModes[COLOR_MODE_AUTOMATIC])) {
- colorMode = COLOR_MODE_AUTOMATIC;
- } else if (colorMode == COLOR_MODE_AUTOMATIC
- && mappedColorModes.length > COLOR_MODE_SATURATED
- && isColorModeAvailable(mappedColorModes[COLOR_MODE_SATURATED])) {
- colorMode = COLOR_MODE_SATURATED;
+ if (colorMode != -1 && mappedColorModes.length > colorMode
+ && isColorModeAvailable(mappedColorModes[colorMode])) {
+ colorMode = mappedColorModes[colorMode];
} else {
- colorMode = -1;
+ final int[] availableColorModes = getContext().getResources().getIntArray(
+ R.array.config_availableColorModes);
+ if (availableColorModes.length > 0) {
+ colorMode = availableColorModes[0];
+ }
}
}
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java
index 1ea1457..9bce471f 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java
@@ -810,35 +810,24 @@
}
}
- /**
- * Change ARC status into the given {@code enabled} status.
- *
- * @return {@code true} if ARC was in "Enabled" status
- */
@ServiceThreadOnly
- boolean setArcStatus(boolean enabled) {
+ void enableArc(List<byte[]> supportedSads) {
assertRunOnServiceThread();
+ HdmiLogger.debug("Set Arc Status[old:%b new:true]", mArcEstablished);
- HdmiLogger.debug("Set Arc Status[old:%b new:%b]", mArcEstablished, enabled);
- boolean oldStatus = mArcEstablished;
- if (enabled) {
- RequestSadAction action = new RequestSadAction(
- this, Constants.ADDR_AUDIO_SYSTEM,
- new RequestSadAction.RequestSadCallback() {
- @Override
- public void onRequestSadDone(List<byte[]> supportedSads) {
- enableAudioReturnChannel(enabled);
- notifyArcStatusToAudioService(enabled, supportedSads);
- mArcEstablished = enabled;
- }
- });
- addAndStartAction(action);
- } else {
- enableAudioReturnChannel(enabled);
- notifyArcStatusToAudioService(enabled, new ArrayList<>());
- mArcEstablished = enabled;
- }
- return oldStatus;
+ enableAudioReturnChannel(true);
+ notifyArcStatusToAudioService(true, supportedSads);
+ mArcEstablished = true;
+ }
+
+ @ServiceThreadOnly
+ void disableArc() {
+ assertRunOnServiceThread();
+ HdmiLogger.debug("Set Arc Status[old:%b new:false]", mArcEstablished);
+
+ enableAudioReturnChannel(false);
+ notifyArcStatusToAudioService(false, new ArrayList<>());
+ mArcEstablished = false;
}
/**
@@ -1066,7 +1055,7 @@
protected int handleTerminateArc(HdmiCecMessage message) {
assertRunOnServiceThread();
if (mService .isPowerStandbyOrTransient()) {
- setArcStatus(false);
+ disableArc();
return Constants.HANDLED;
}
// Do not check ARC configuration since the AVR might have been already removed.
@@ -1353,7 +1342,7 @@
if (avr == null) {
return;
}
- setArcStatus(false);
+ disableArc();
// Seq #44.
removeAllRunningArcAction();
diff --git a/services/core/java/com/android/server/hdmi/RequestArcAction.java b/services/core/java/com/android/server/hdmi/RequestArcAction.java
index c70101c..3d9a290 100644
--- a/services/core/java/com/android/server/hdmi/RequestArcAction.java
+++ b/services/core/java/com/android/server/hdmi/RequestArcAction.java
@@ -63,7 +63,7 @@
finish();
return true;
} else if (originalOpcode == Constants.MESSAGE_REQUEST_ARC_INITIATION) {
- tv().setArcStatus(false);
+ tv().disableArc();
finish();
return true;
}
diff --git a/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java b/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java
index 4eb220f..3b7f1dd 100644
--- a/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java
+++ b/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java
@@ -48,7 +48,7 @@
public void onSendCompleted(int error) {
if (error != SendMessageResult.SUCCESS) {
// Turn off ARC status if <Request ARC Initiation> fails.
- tv().setArcStatus(false);
+ tv().disableArc();
finish();
}
}
diff --git a/services/core/java/com/android/server/hdmi/RequestSadAction.java b/services/core/java/com/android/server/hdmi/RequestSadAction.java
index 702c000..23aaf32 100644
--- a/services/core/java/com/android/server/hdmi/RequestSadAction.java
+++ b/services/core/java/com/android/server/hdmi/RequestSadAction.java
@@ -181,13 +181,20 @@
return true;
}
if (cmd.getOpcode() == Constants.MESSAGE_FEATURE_ABORT
- && (cmd.getParams()[0] & 0xFF) == Constants.MESSAGE_REQUEST_SHORT_AUDIO_DESCRIPTOR
- && (cmd.getParams()[1] & 0xFF) == Constants.ABORT_INVALID_OPERAND) {
- // Queried SADs are not supported
- mQueriedSadCount += MAX_SAD_PER_REQUEST;
- mTimeoutRetry = 0;
- querySad();
- return true;
+ && (cmd.getParams()[0] & 0xFF)
+ == Constants.MESSAGE_REQUEST_SHORT_AUDIO_DESCRIPTOR) {
+ if ((cmd.getParams()[1] & 0xFF) == Constants.ABORT_UNRECOGNIZED_OPCODE) {
+ // SAD feature is not supported
+ wrapUpAndFinish();
+ return true;
+ }
+ if ((cmd.getParams()[1] & 0xFF) == Constants.ABORT_INVALID_OPERAND) {
+ // Queried SADs are not supported
+ mQueriedSadCount += MAX_SAD_PER_REQUEST;
+ mTimeoutRetry = 0;
+ querySad();
+ return true;
+ }
}
return false;
}
@@ -211,9 +218,9 @@
querySad();
return;
}
- mQueriedSadCount += MAX_SAD_PER_REQUEST;
- mTimeoutRetry = 0;
- querySad();
+ // Don't query any other SADs if one of the SAD queries ran into the maximum amount of
+ // retries.
+ wrapUpAndFinish();
}
}
diff --git a/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java b/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java
index db93ad0..32e274e 100644
--- a/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java
+++ b/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java
@@ -20,6 +20,8 @@
import android.hardware.tv.cec.V1_0.SendMessageResult;
import android.util.Slog;
+import java.util.List;
+
/**
* Feature action that handles enabling/disabling of ARC transmission channel.
* Once TV gets <Initiate ARC>, TV sends <Report ARC Initiated> to AV Receiver.
@@ -55,21 +57,31 @@
boolean start() {
// Seq #37.
if (mEnabled) {
- // Enable ARC status immediately before sending <Report Arc Initiated>.
- // If AVR responds with <Feature Abort>, disable ARC status again.
- // This is different from spec that says that turns ARC status to
- // "Enabled" if <Report ARC Initiated> is acknowledged and no
- // <Feature Abort> is received.
- // But implemented this way to save the time having to wait for
- // <Feature Abort>.
- setArcStatus(true);
- // If succeeds to send <Report ARC Initiated>, wait general timeout
- // to check whether there is no <Feature Abort> for <Report ARC Initiated>.
- mState = STATE_WAITING_TIMEOUT;
- addTimer(mState, HdmiConfig.TIMEOUT_MS);
- sendReportArcInitiated();
+ // Request SADs before enabling ARC
+ RequestSadAction action = new RequestSadAction(
+ localDevice(), Constants.ADDR_AUDIO_SYSTEM,
+ new RequestSadAction.RequestSadCallback() {
+ @Override
+ public void onRequestSadDone(List<byte[]> supportedSads) {
+ // Enable ARC status immediately before sending <Report Arc Initiated>.
+ // If AVR responds with <Feature Abort>, disable ARC status again.
+ // This is different from spec that says that turns ARC status to
+ // "Enabled" if <Report ARC Initiated> is acknowledged and no
+ // <Feature Abort> is received.
+ // But implemented this way to save the time having to wait for
+ // <Feature Abort>.
+ Slog.i(TAG, "Enabling ARC");
+ tv().enableArc(supportedSads);
+ // If succeeds to send <Report ARC Initiated>, wait general timeout to
+ // check whether there is no <Feature Abort> for <Report ARC Initiated>.
+ mState = STATE_WAITING_TIMEOUT;
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
+ sendReportArcInitiated();
+ }
+ });
+ addAndStartAction(action);
} else {
- setArcStatus(false);
+ disableArc();
finish();
}
return true;
@@ -92,7 +104,7 @@
case SendMessageResult.NACK:
// If <Report ARC Initiated> is negatively ack'ed, disable ARC and
// send <Report ARC Terminated> directly.
- setArcStatus(false);
+ disableArc();
HdmiLogger.debug("Failed to send <Report Arc Initiated>.");
finish();
break;
@@ -101,16 +113,12 @@
});
}
- private void setArcStatus(boolean enabled) {
- tv().setArcStatus(enabled);
- Slog.i(TAG, "Change arc status to " + enabled);
+ private void disableArc() {
+ Slog.i(TAG, "Disabling ARC");
- // If enabled before and set to "disabled" and send <Report Arc Terminated> to
- // av reciever.
- if (!enabled) {
- sendCommand(HdmiCecMessageBuilder.buildReportArcTerminated(getSourceAddress(),
- mAvrAddress));
- }
+ tv().disableArc();
+ sendCommand(HdmiCecMessageBuilder.buildReportArcTerminated(getSourceAddress(),
+ mAvrAddress));
}
@Override
@@ -124,7 +132,7 @@
int originalOpcode = cmd.getParams()[0] & 0xFF;
if (originalOpcode == Constants.MESSAGE_REPORT_ARC_INITIATED) {
HdmiLogger.debug("Feature aborted for <Report Arc Initiated>");
- setArcStatus(false);
+ disableArc();
finish();
return true;
}
diff --git a/services/core/java/com/android/server/pm/AppsFilterBase.java b/services/core/java/com/android/server/pm/AppsFilterBase.java
index e7bcb0a..7004c73 100644
--- a/services/core/java/com/android/server/pm/AppsFilterBase.java
+++ b/services/core/java/com/android/server/pm/AppsFilterBase.java
@@ -173,7 +173,7 @@
* {@link #shouldFilterApplicationInternal(PackageDataSnapshot, int, Object,
* PackageStateInternal, int)} call.
* NOTE: It can only be relied upon after the system is ready to avoid unnecessary update on
- * initial scam and is empty until {@link #mCacheReady} is true.
+ * initial scam and is empty until {@link #mSystemReady} is true.
*/
@NonNull
@Watched
@@ -181,7 +181,7 @@
@NonNull
protected SnapshotCache<WatchedSparseBooleanMatrix> mShouldFilterCacheSnapshot;
- protected volatile boolean mCacheReady = false;
+ protected volatile boolean mSystemReady = false;
protected boolean isForceQueryable(int callingAppId) {
return mForceQueryable.contains(callingAppId);
@@ -312,7 +312,7 @@
|| callingAppId == targetPkgSetting.getAppId()) {
return false;
}
- if (mCacheReady) { // use cache
+ if (mSystemReady) { // use cache
if (!shouldFilterApplicationUsingCache(callingUid,
targetPkgSetting.getAppId(),
userId)) {
diff --git a/services/core/java/com/android/server/pm/AppsFilterImpl.java b/services/core/java/com/android/server/pm/AppsFilterImpl.java
index c817e24..952711d 100644
--- a/services/core/java/com/android/server/pm/AppsFilterImpl.java
+++ b/services/core/java/com/android/server/pm/AppsFilterImpl.java
@@ -404,8 +404,7 @@
+ recipientUid + " -> " + visibleUid);
}
- // TODO(b/231528435): invalidate cache instead of locking.
- if (true/*mCacheReady*/) {
+ if (mSystemReady) {
synchronized (mCacheLock) {
// update the cache in a one-off manner since we've got all the information we
// need.
@@ -421,6 +420,7 @@
mFeatureConfig.onSystemReady();
updateEntireShouldFilterCacheAsync(pmInternal);
+ mSystemReady = true;
}
/**
@@ -444,8 +444,7 @@
final UserInfo[] users = snapshot.getUserInfos();
final ArraySet<String> additionalChangedPackages =
addPackageInternal(newPkgSetting, settings);
- // TODO(b/231528435): invalidate cache instead of locking.
- if (true/*mCacheReady*/) {
+ if (mSystemReady) {
synchronized (mCacheLock) {
updateShouldFilterCacheForPackage(snapshot, null, newPkgSetting,
settings, users, USER_ALL, settings.size());
@@ -587,7 +586,7 @@
}
private void removeAppIdFromVisibilityCache(int appId) {
- if (!mCacheReady) {
+ if (!mSystemReady) {
return;
}
synchronized (mCacheLock) {
@@ -662,20 +661,18 @@
updateEntireShouldFilterCacheInner(snapshot, settings, usersRef[0], USER_ALL);
onChanged();
-
- mCacheReady = true;
});
}
public void onUserCreated(PackageDataSnapshot snapshot, int newUserId) {
- if (!mCacheReady) {
+ if (!mSystemReady) {
return;
}
updateEntireShouldFilterCache(snapshot, newUserId);
}
public void onUserDeleted(@UserIdInt int userId) {
- if (!mCacheReady) {
+ if (!mSystemReady) {
return;
}
removeShouldFilterCacheForUser(userId);
@@ -684,7 +681,7 @@
private void updateShouldFilterCacheForPackage(PackageDataSnapshot snapshot,
String packageName) {
- if (!mCacheReady) {
+ if (!mSystemReady) {
return;
}
final ArrayMap<String, ? extends PackageStateInternal> settings =
@@ -933,8 +930,7 @@
}
removeAppIdFromVisibilityCache(setting.getAppId());
- // TODO(b/231528435): invalidate cache instead of locking.
- if (/*mCacheReady && */setting.hasSharedUser()) {
+ if (mSystemReady && setting.hasSharedUser()) {
final ArraySet<? extends PackageStateInternal> sharedUserPackages =
getSharedUserPackages(setting.getSharedUserAppId(), sharedUserSettings);
for (int i = sharedUserPackages.size() - 1; i >= 0; i--) {
@@ -951,8 +947,7 @@
}
}
- // TODO(b/231528435): invalidate cache instead of locking.
- if (true/*mCacheReady*/) {
+ if (mSystemReady) {
if (additionalChangedPackages != null) {
for (int index = 0; index < additionalChangedPackages.size(); index++) {
String changedPackage = additionalChangedPackages.valueAt(index);
diff --git a/services/core/java/com/android/server/pm/AppsFilterLocked.java b/services/core/java/com/android/server/pm/AppsFilterLocked.java
index b85bd8f..e8e6cd9 100644
--- a/services/core/java/com/android/server/pm/AppsFilterLocked.java
+++ b/services/core/java/com/android/server/pm/AppsFilterLocked.java
@@ -32,7 +32,7 @@
/**
* Guards the access for {@link AppsFilterBase#mShouldFilterCache};
*/
- protected final Object mCacheLock = new Object();
+ protected Object mCacheLock = new Object();
@Override
protected boolean isForceQueryable(int appId) {
diff --git a/services/core/java/com/android/server/pm/AppsFilterSnapshotImpl.java b/services/core/java/com/android/server/pm/AppsFilterSnapshotImpl.java
index 39b6341..c12aa6d 100644
--- a/services/core/java/com/android/server/pm/AppsFilterSnapshotImpl.java
+++ b/services/core/java/com/android/server/pm/AppsFilterSnapshotImpl.java
@@ -17,7 +17,6 @@
package com.android.server.pm;
import com.android.server.utils.SnapshotCache;
-import com.android.server.utils.WatchedSparseBooleanMatrix;
import java.util.Arrays;
@@ -50,18 +49,12 @@
mFeatureConfig = orig.mFeatureConfig.snapshot();
mOverlayReferenceMapper = orig.mOverlayReferenceMapper;
mSystemSigningDetails = orig.mSystemSigningDetails;
-
- mCacheReady = orig.mCacheReady;
- if (mCacheReady) {
- synchronized (orig.mCacheLock) {
- mShouldFilterCache = orig.mShouldFilterCacheSnapshot.snapshot();
- }
- } else {
- // cache is not ready, use an empty cache for the snapshot
- mShouldFilterCache = new WatchedSparseBooleanMatrix();
+ synchronized (orig.mCacheLock) {
+ mShouldFilterCache = orig.mShouldFilterCacheSnapshot.snapshot();
+ mShouldFilterCacheSnapshot = new SnapshotCache.Sealed<>();
}
- mShouldFilterCacheSnapshot = new SnapshotCache.Sealed<>();
mBackgroundExecutor = null;
+ mSystemReady = orig.mSystemReady;
}
}
diff --git a/services/core/java/com/android/server/pm/BackgroundDexOptService.java b/services/core/java/com/android/server/pm/BackgroundDexOptService.java
index 9ea0192..5a01ccb 100644
--- a/services/core/java/com/android/server/pm/BackgroundDexOptService.java
+++ b/services/core/java/com/android/server/pm/BackgroundDexOptService.java
@@ -17,6 +17,7 @@
package com.android.server.pm;
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
+import static com.android.server.pm.dex.ArtStatsLogUtils.BackgroundDexoptJobStatsLogger;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -77,47 +78,46 @@
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
- @VisibleForTesting
- static final int JOB_IDLE_OPTIMIZE = 800;
- @VisibleForTesting
- static final int JOB_POST_BOOT_UPDATE = 801;
+ @VisibleForTesting static final int JOB_IDLE_OPTIMIZE = 800;
+ @VisibleForTesting static final int JOB_POST_BOOT_UPDATE = 801;
private static final long IDLE_OPTIMIZATION_PERIOD = TimeUnit.DAYS.toMillis(1);
private static final long CANCELLATION_WAIT_CHECK_INTERVAL_MS = 200;
- private static ComponentName sDexoptServiceName = new ComponentName("android",
- BackgroundDexOptJobService.class.getName());
+ private static ComponentName sDexoptServiceName =
+ new ComponentName("android", BackgroundDexOptJobService.class.getName());
// Possible return codes of individual optimization steps.
/** Ok status: Optimizations finished, All packages were processed, can continue */
- /* package */ static final int STATUS_OK = 0;
+ public static final int STATUS_OK = 0;
/** Optimizations should be aborted. Job scheduler requested it. */
- /* package */ static final int STATUS_ABORT_BY_CANCELLATION = 1;
+ public static final int STATUS_ABORT_BY_CANCELLATION = 1;
/** Optimizations should be aborted. No space left on device. */
- /* package */ static final int STATUS_ABORT_NO_SPACE_LEFT = 2;
+ public static final int STATUS_ABORT_NO_SPACE_LEFT = 2;
/** Optimizations should be aborted. Thermal throttling level too high. */
- /* package */ static final int STATUS_ABORT_THERMAL = 3;
+ public static final int STATUS_ABORT_THERMAL = 3;
/** Battery level too low */
- /* package */ static final int STATUS_ABORT_BATTERY = 4;
+ public static final int STATUS_ABORT_BATTERY = 4;
/**
* {@link PackageDexOptimizer#DEX_OPT_FAILED} case. This state means some packages have failed
* compilation during the job. Note that the failure will not be permanent as the next dexopt
* job will exclude those failed packages.
*/
- /* package */ static final int STATUS_DEX_OPT_FAILED = 5;
+ public static final int STATUS_DEX_OPT_FAILED = 5;
- @IntDef(prefix = {"STATUS_"}, value = {
- STATUS_OK,
- STATUS_ABORT_BY_CANCELLATION,
- STATUS_ABORT_NO_SPACE_LEFT,
- STATUS_ABORT_THERMAL,
- STATUS_ABORT_BATTERY,
- STATUS_DEX_OPT_FAILED,
- })
+ @IntDef(prefix = {"STATUS_"},
+ value =
+ {
+ STATUS_OK,
+ STATUS_ABORT_BY_CANCELLATION,
+ STATUS_ABORT_NO_SPACE_LEFT,
+ STATUS_ABORT_THERMAL,
+ STATUS_ABORT_BATTERY,
+ STATUS_DEX_OPT_FAILED,
+ })
@Retention(RetentionPolicy.SOURCE)
- private @interface Status {
- }
+ public @interface Status {}
// Used for calculating space threshold for downgrading unused apps.
private static final int LOW_THRESHOLD_MULTIPLIER_FOR_DOWNGRADE = 2;
@@ -129,33 +129,30 @@
private final DexOptHelper mDexOptHelper;
+ private final BackgroundDexoptJobStatsLogger mStatsLogger =
+ new BackgroundDexoptJobStatsLogger();
+
private final Object mLock = new Object();
// Thread currently running dexopt. This will be null if dexopt is not running.
// The thread running dexopt make sure to set this into null when the pending dexopt is
// completed.
- @GuardedBy("mLock")
- @Nullable
- private Thread mDexOptThread;
+ @GuardedBy("mLock") @Nullable private Thread mDexOptThread;
// Thread currently cancelling dexopt. This thread is in blocked wait state until
// cancellation is done. Only this thread can change states for control. The other threads, if
// need to wait for cancellation, should just wait without doing any control.
- @GuardedBy("mLock")
- @Nullable
- private Thread mDexOptCancellingThread;
+ @GuardedBy("mLock") @Nullable private Thread mDexOptCancellingThread;
// Tells whether post boot update is completed or not.
- @GuardedBy("mLock")
- private boolean mFinishedPostBootUpdate;
+ @GuardedBy("mLock") private boolean mFinishedPostBootUpdate;
- @GuardedBy("mLock")
- @Status private int mLastExecutionStatus = STATUS_OK;
+ @GuardedBy("mLock") @Status private int mLastExecutionStatus = STATUS_OK;
- @GuardedBy("mLock")
- private long mLastExecutionStartTimeMs;
- @GuardedBy("mLock")
- private long mLastExecutionDurationMs;
+ @GuardedBy("mLock") private long mLastExecutionStartTimeMs;
+ @GuardedBy("mLock") private long mLastExecutionDurationIncludingSleepMs;
+ @GuardedBy("mLock") private long mLastExecutionStartUptimeMs;
+ @GuardedBy("mLock") private long mLastExecutionDurationMs;
// Keeps packages cancelled from PDO for last session. This is for debugging.
@GuardedBy("mLock")
@@ -181,8 +178,8 @@
void onPackagesUpdated(ArraySet<String> updatedPackages);
}
- public BackgroundDexOptService(Context context, DexManager dexManager,
- PackageManagerService pm) {
+ public BackgroundDexOptService(
+ Context context, DexManager dexManager, PackageManagerService pm) {
this(new Injector(context, dexManager, pm));
}
@@ -234,6 +231,10 @@
writer.println(mLastExecutionStatus);
writer.print("mLastExecutionStartTimeMs:");
writer.println(mLastExecutionStartTimeMs);
+ writer.print("mLastExecutionDurationIncludingSleepMs:");
+ writer.println(mLastExecutionDurationIncludingSleepMs);
+ writer.print("mLastExecutionStartUptimeMs:");
+ writer.println(mLastExecutionStartUptimeMs);
writer.print("mLastExecutionDurationMs:");
writer.println(mLastExecutionDurationMs);
writer.print("now:");
@@ -361,17 +362,20 @@
resetStatesForNewDexOptRunLocked(mInjector.createAndStartThread(
"BackgroundDexOptService_" + (isPostBootUpdateJob ? "PostBoot" : "Idle"),
() -> {
- TimingsTraceAndSlog tr = new TimingsTraceAndSlog(TAG,
- Trace.TRACE_TAG_PACKAGE_MANAGER);
+ TimingsTraceAndSlog tr =
+ new TimingsTraceAndSlog(TAG, Trace.TRACE_TAG_PACKAGE_MANAGER);
tr.traceBegin("jobExecution");
boolean completed = false;
try {
- completed = runIdleOptimization(pm, pkgs,
- params.getJobId() == JOB_POST_BOOT_UPDATE);
+ completed = runIdleOptimization(
+ pm, pkgs, params.getJobId() == JOB_POST_BOOT_UPDATE);
} finally { // Those cleanup should be done always.
tr.traceEnd();
- Slog.i(TAG, "dexopt finishing. jobid:" + params.getJobId()
- + " completed:" + completed);
+ Slog.i(TAG,
+ "dexopt finishing. jobid:" + params.getJobId()
+ + " completed:" + completed);
+
+ writeStatsLog(params);
if (params.getJobId() == JOB_POST_BOOT_UPDATE) {
if (completed) {
@@ -455,7 +459,7 @@
if (mDexOptThread != Thread.currentThread()) {
throw new IllegalStateException(
"Only mDexOptThread can mark completion, mDexOptThread:" + mDexOptThread
- + " current:" + Thread.currentThread());
+ + " current:" + Thread.currentThread());
}
mDexOptThread = null;
// Other threads may be waiting for completion.
@@ -485,11 +489,10 @@
private void scheduleAJob(int jobId) {
JobScheduler js = mInjector.getJobScheduler();
- JobInfo.Builder builder = new JobInfo.Builder(jobId, sDexoptServiceName)
- .setRequiresDeviceIdle(true);
+ JobInfo.Builder builder =
+ new JobInfo.Builder(jobId, sDexoptServiceName).setRequiresDeviceIdle(true);
if (jobId == JOB_IDLE_OPTIMIZE) {
- builder.setRequiresCharging(true)
- .setPeriodic(IDLE_OPTIMIZATION_PERIOD);
+ builder.setRequiresCharging(true).setPeriodic(IDLE_OPTIMIZATION_PERIOD);
}
js.schedule(builder.build());
}
@@ -533,19 +536,22 @@
* Returns whether we've successfully run the job. Note that it will return true even if some
* packages may have failed compiling.
*/
- private boolean runIdleOptimization(PackageManagerService pm, List<String> pkgs,
- boolean isPostBootUpdate) {
+ private boolean runIdleOptimization(
+ PackageManagerService pm, List<String> pkgs, boolean isPostBootUpdate) {
synchronized (mLock) {
mLastExecutionStartTimeMs = SystemClock.elapsedRealtime();
+ mLastExecutionDurationIncludingSleepMs = -1;
+ mLastExecutionStartUptimeMs = SystemClock.uptimeMillis();
mLastExecutionDurationMs = -1;
}
long lowStorageThreshold = getLowStorageThreshold();
- int status = idleOptimizePackages(pm, pkgs, lowStorageThreshold,
- isPostBootUpdate);
+ int status = idleOptimizePackages(pm, pkgs, lowStorageThreshold, isPostBootUpdate);
logStatus(status);
synchronized (mLock) {
mLastExecutionStatus = status;
- mLastExecutionDurationMs = SystemClock.elapsedRealtime() - mLastExecutionStartTimeMs;
+ mLastExecutionDurationIncludingSleepMs =
+ SystemClock.elapsedRealtime() - mLastExecutionStartTimeMs;
+ mLastExecutionDurationMs = SystemClock.uptimeMillis() - mLastExecutionStartUptimeMs;
}
return status == STATUS_OK || status == STATUS_DEX_OPT_FAILED;
@@ -555,7 +561,7 @@
private long getDirectorySize(File f) {
long size = 0;
if (f.isDirectory()) {
- for (File file: f.listFiles()) {
+ for (File file : f.listFiles()) {
size += getDirectorySize(file);
}
} else {
@@ -606,8 +612,8 @@
// Only downgrade apps when space is low on device.
// Threshold is selected above the lowStorageThreshold so that we can pro-actively clean
// up disk before user hits the actual lowStorageThreshold.
- long lowStorageThresholdForDowngrade = LOW_THRESHOLD_MULTIPLIER_FOR_DOWNGRADE
- * lowStorageThreshold;
+ long lowStorageThresholdForDowngrade =
+ LOW_THRESHOLD_MULTIPLIER_FOR_DOWNGRADE * lowStorageThreshold;
boolean shouldDowngrade = shouldDowngrade(lowStorageThresholdForDowngrade);
if (DEBUG) {
Slog.d(TAG, "Should Downgrade " + shouldDowngrade);
@@ -627,19 +633,20 @@
// Should be aborted by the scheduler.
return abortCode;
}
- @DexOptResult int downgradeResult = downgradePackage(snapshot, pm, pkg,
+ @DexOptResult
+ int downgradeResult = downgradePackage(snapshot, pm, pkg,
/* isForPrimaryDex= */ true, isPostBootUpdate);
if (downgradeResult == PackageDexOptimizer.DEX_OPT_PERFORMED) {
updatedPackages.add(pkg);
}
- @Status int status = convertPackageDexOptimizerStatusToInternal(
- downgradeResult);
+ @Status
+ int status = convertPackageDexOptimizerStatusToInternal(downgradeResult);
if (status != STATUS_OK) {
return status;
}
if (supportSecondaryDex) {
downgradeResult = downgradePackage(snapshot, pm, pkg,
- /* isForPrimaryDex= */false, isPostBootUpdate);
+ /* isForPrimaryDex= */ false, isPostBootUpdate);
status = convertPackageDexOptimizerStatusToInternal(downgradeResult);
if (status != STATUS_OK) {
return status;
@@ -680,8 +687,8 @@
return abortCode;
}
- @DexOptResult int primaryResult =
- optimizePackage(pkg, true /* isForPrimaryDex */, isPostBootUpdate);
+ @DexOptResult
+ int primaryResult = optimizePackage(pkg, true /* isForPrimaryDex */, isPostBootUpdate);
if (primaryResult == PackageDexOptimizer.DEX_OPT_CANCELLED) {
return STATUS_ABORT_BY_CANCELLATION;
}
@@ -695,7 +702,8 @@
continue;
}
- @DexOptResult int secondaryResult =
+ @DexOptResult
+ int secondaryResult =
optimizePackage(pkg, false /* isForPrimaryDex */, isPostBootUpdate);
if (secondaryResult == PackageDexOptimizer.DEX_OPT_CANCELLED) {
return STATUS_ABORT_BY_CANCELLATION;
@@ -748,7 +756,7 @@
if (result == PackageDexOptimizer.DEX_OPT_PERFORMED) {
final Computer newSnapshot = pm.snapshotComputer();
FrameworkStatsLog.write(FrameworkStatsLog.APP_DOWNGRADED, pkg, package_size_before,
- getPackageSize(newSnapshot, pkg), /*aggressive=*/ false);
+ getPackageSize(newSnapshot, pkg), /*aggressive=*/false);
}
return result;
}
@@ -777,7 +785,7 @@
@DexOptResult
private int optimizePackage(String pkg, boolean isForPrimaryDex, boolean isPostBootUpdate) {
int reason = isPostBootUpdate ? PackageManagerService.REASON_POST_BOOT
- : PackageManagerService.REASON_BACKGROUND_DEXOPT;
+ : PackageManagerService.REASON_BACKGROUND_DEXOPT;
int dexoptFlags = DexoptOptions.DEXOPT_BOOT_COMPLETE;
if (!isPostBootUpdate) {
dexoptFlags |= DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES
@@ -794,22 +802,21 @@
}
@DexOptResult
- private int performDexOptPrimary(String pkg, int reason,
- int dexoptFlags) {
+ private int performDexOptPrimary(String pkg, int reason, int dexoptFlags) {
DexoptOptions dexoptOptions = new DexoptOptions(pkg, reason, dexoptFlags);
- return trackPerformDexOpt(pkg, /*isForPrimaryDex=*/ true,
+ return trackPerformDexOpt(pkg, /*isForPrimaryDex=*/true,
() -> mDexOptHelper.performDexOptWithStatus(dexoptOptions));
}
@DexOptResult
- private int performDexOptSecondary(String pkg, int reason,
- int dexoptFlags) {
- DexoptOptions dexoptOptions = new DexoptOptions(pkg, reason,
- dexoptFlags | DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX);
- return trackPerformDexOpt(pkg, /*isForPrimaryDex=*/ false,
- () -> mDexOptHelper.performDexOpt(dexoptOptions)
- ? PackageDexOptimizer.DEX_OPT_PERFORMED : PackageDexOptimizer.DEX_OPT_FAILED
- );
+ private int performDexOptSecondary(String pkg, int reason, int dexoptFlags) {
+ DexoptOptions dexoptOptions = new DexoptOptions(
+ pkg, reason, dexoptFlags | DexoptOptions.DEXOPT_ONLY_SECONDARY_DEX);
+ return trackPerformDexOpt(pkg, /*isForPrimaryDex=*/false,
+ ()
+ -> mDexOptHelper.performDexOpt(dexoptOptions)
+ ? PackageDexOptimizer.DEX_OPT_PERFORMED
+ : PackageDexOptimizer.DEX_OPT_FAILED);
}
/**
@@ -822,8 +829,8 @@
* {@link PackageDexOptimizer#DEX_OPT_FAILED}
*/
@DexOptResult
- private int trackPerformDexOpt(String pkg, boolean isForPrimaryDex,
- Supplier<Integer> performDexOptWrapper) {
+ private int trackPerformDexOpt(
+ String pkg, boolean isForPrimaryDex, Supplier<Integer> performDexOptWrapper) {
ArraySet<String> failedPackageNames;
synchronized (mLock) {
failedPackageNames =
@@ -940,6 +947,19 @@
}
}
+ private void writeStatsLog(JobParameters params) {
+ @Status int status;
+ long durationMs;
+ long durationIncludingSleepMs;
+ synchronized (mLock) {
+ status = mLastExecutionStatus;
+ durationMs = mLastExecutionDurationMs;
+ durationIncludingSleepMs = mLastExecutionDurationIncludingSleepMs;
+ }
+
+ mStatsLogger.write(status, params.getStopReason(), durationMs, durationIncludingSleepMs);
+ }
+
/** Injector pattern for testing purpose */
@VisibleForTesting
static final class Injector {
@@ -979,8 +999,8 @@
}
boolean isBackgroundDexOptDisabled() {
- return SystemProperties.getBoolean("pm.dexopt.disable_bg_dexopt" /* key */,
- false /* default */);
+ return SystemProperties.getBoolean(
+ "pm.dexopt.disable_bg_dexopt" /* key */, false /* default */);
}
boolean isBatteryLevelLow() {
@@ -1010,8 +1030,8 @@
}
int getCurrentThermalStatus() {
- IThermalService thermalService = IThermalService.Stub
- .asInterface(ServiceManager.getService(Context.THERMAL_SERVICE));
+ IThermalService thermalService = IThermalService.Stub.asInterface(
+ ServiceManager.getService(Context.THERMAL_SERVICE));
try {
return thermalService.getCurrentThermalStatus();
} catch (RemoteException e) {
@@ -1020,8 +1040,8 @@
}
int getDexOptThermalCutoff() {
- return SystemProperties.getInt("dalvik.vm.dexopt.thermal-cutoff",
- THERMAL_CUTOFF_DEFAULT);
+ return SystemProperties.getInt(
+ "dalvik.vm.dexopt.thermal-cutoff", THERMAL_CUTOFF_DEFAULT);
}
Thread createAndStartThread(String name, Runnable target) {
diff --git a/services/core/java/com/android/server/pm/DeletePackageHelper.java b/services/core/java/com/android/server/pm/DeletePackageHelper.java
index cb38d52..0cdf7bf 100644
--- a/services/core/java/com/android/server/pm/DeletePackageHelper.java
+++ b/services/core/java/com/android/server/pm/DeletePackageHelper.java
@@ -166,9 +166,10 @@
if (PackageManagerServiceUtils.isSystemApp(uninstalledPs)) {
UserInfo userInfo = mUserManagerInternal.getUserInfo(userId);
- if (userInfo == null || !userInfo.isAdmin()) {
+ if (userInfo == null || (!userInfo.isAdmin() && !mUserManagerInternal.getUserInfo(
+ mUserManagerInternal.getProfileParentId(userId)).isAdmin())) {
Slog.w(TAG, "Not removing package " + packageName
- + " as only admin user may downgrade system apps");
+ + " as only admin user (or their profile) may downgrade system apps");
EventLog.writeEvent(0x534e4554, "170646036", -1, packageName);
return PackageManager.DELETE_FAILED_USER_RESTRICTED;
}
diff --git a/services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java b/services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java
index b26b694..d49227d 100644
--- a/services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java
+++ b/services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java
@@ -22,11 +22,13 @@
import static com.android.internal.art.ArtStatsLog.ART_DATUM_REPORTED__COMPILE_FILTER__ART_COMPILATION_FILTER_FAKE_RUN_FROM_APK_FALLBACK;
import static com.android.internal.art.ArtStatsLog.ART_DATUM_REPORTED__COMPILE_FILTER__ART_COMPILATION_FILTER_FAKE_RUN_FROM_VDEX_FALLBACK;
+import android.app.job.JobParameters;
import android.os.SystemClock;
import android.util.Slog;
import android.util.jar.StrictJarFile;
import com.android.internal.art.ArtStatsLog;
+import com.android.server.pm.BackgroundDexOptService;
import com.android.server.pm.PackageManagerService;
import java.io.IOException;
@@ -299,4 +301,31 @@
ArtStatsLog.ART_DATUM_REPORTED__ISA__ART_ISA_UNKNOWN));
}
}
+
+ private static final Map<Integer, Integer> STATUS_MAP =
+ Map.of(BackgroundDexOptService.STATUS_OK,
+ ArtStatsLog.BACKGROUND_DEXOPT_JOB_ENDED__STATUS__STATUS_JOB_FINISHED,
+ BackgroundDexOptService.STATUS_ABORT_BY_CANCELLATION,
+ ArtStatsLog.BACKGROUND_DEXOPT_JOB_ENDED__STATUS__STATUS_ABORT_BY_CANCELLATION,
+ BackgroundDexOptService.STATUS_ABORT_NO_SPACE_LEFT,
+ ArtStatsLog.BACKGROUND_DEXOPT_JOB_ENDED__STATUS__STATUS_ABORT_NO_SPACE_LEFT,
+ BackgroundDexOptService.STATUS_ABORT_THERMAL,
+ ArtStatsLog.BACKGROUND_DEXOPT_JOB_ENDED__STATUS__STATUS_ABORT_THERMAL,
+ BackgroundDexOptService.STATUS_ABORT_BATTERY,
+ ArtStatsLog.BACKGROUND_DEXOPT_JOB_ENDED__STATUS__STATUS_ABORT_BATTERY,
+ BackgroundDexOptService.STATUS_DEX_OPT_FAILED,
+ ArtStatsLog.BACKGROUND_DEXOPT_JOB_ENDED__STATUS__STATUS_JOB_FINISHED);
+
+ /** Helper class to write background dexopt job stats to statsd. */
+ public static class BackgroundDexoptJobStatsLogger {
+ /** Writes background dexopt job stats to statsd. */
+ public void write(@BackgroundDexOptService.Status int status,
+ @JobParameters.StopReason int cancellationReason, long durationMs,
+ long durationIncludingSleepMs) {
+ ArtStatsLog.write(ArtStatsLog.BACKGROUND_DEXOPT_JOB_ENDED,
+ STATUS_MAP.getOrDefault(status,
+ ArtStatsLog.BACKGROUND_DEXOPT_JOB_ENDED__STATUS__STATUS_UNKNOWN),
+ cancellationReason, durationMs, durationIncludingSleepMs);
+ }
+ }
}
diff --git a/services/core/java/com/android/server/pm/pkg/component/ParsedPermissionUtils.java b/services/core/java/com/android/server/pm/pkg/component/ParsedPermissionUtils.java
index f2e2f4f..281e1bd 100644
--- a/services/core/java/com/android/server/pm/pkg/component/ParsedPermissionUtils.java
+++ b/services/core/java/com/android/server/pm/pkg/component/ParsedPermissionUtils.java
@@ -26,6 +26,7 @@
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.ArrayMap;
+import android.util.EventLog;
import android.util.Slog;
import com.android.internal.R;
@@ -36,6 +37,7 @@
import java.io.IOException;
import java.util.List;
+import java.util.Objects;
/**
* @hide
@@ -277,8 +279,28 @@
}
/**
- * @return {@code true} if the package declares duplicate permissions with different
- * protection levels.
+ * Determines if a duplicate permission is malformed .i.e. defines different protection level
+ * or group.
+ */
+ private static boolean isMalformedDuplicate(ParsedPermission p1, ParsedPermission p2) {
+ // Since a permission tree is also added as a permission with normal protection
+ // level, we need to skip if the parsedPermission is a permission tree.
+ if (p1 == null || p2 == null || p1.isTree() || p2.isTree()) {
+ return false;
+ }
+
+ if (p1.getProtectionLevel() != p2.getProtectionLevel()) {
+ return true;
+ }
+ if (!Objects.equals(p1.getGroup(), p2.getGroup())) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @return {@code true} if the package declares malformed duplicate permissions.
*/
public static boolean declareDuplicatePermission(@NonNull ParsingPackage pkg) {
final List<ParsedPermission> permissions = pkg.getPermissions();
@@ -289,10 +311,10 @@
final ParsedPermission parsedPermission = permissions.get(i);
final String name = parsedPermission.getName();
final ParsedPermission perm = checkDuplicatePerm.get(name);
- // Since a permission tree is also added as a permission with normal protection
- // level, we need to skip if the parsedPermission is a permission tree.
- if (perm != null && !(perm.isTree() || parsedPermission.isTree())
- && perm.getProtectionLevel() != parsedPermission.getProtectionLevel()) {
+ if (isMalformedDuplicate(parsedPermission, perm)) {
+ // Fix for b/213323615
+ EventLog.writeEvent(0x534e4554, "213323615",
+ "The package " + pkg.getPackageName() + " seems malicious");
return true;
}
checkDuplicatePerm.put(name, parsedPermission);
diff --git a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageUtils.java b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageUtils.java
index 6ee9c66..06a54a4 100644
--- a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageUtils.java
+++ b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageUtils.java
@@ -968,7 +968,7 @@
if (ParsedPermissionUtils.declareDuplicatePermission(pkg)) {
return input.error(
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
- "Declare duplicate permissions with different protection levels."
+ "Found duplicate permission with a different attribute value."
);
}
diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java
index 5c8cfff..9e0d7b5 100644
--- a/services/core/java/com/android/server/wm/InsetsPolicy.java
+++ b/services/core/java/com/android/server/wm/InsetsPolicy.java
@@ -46,6 +46,7 @@
import android.app.ActivityTaskManager;
import android.app.StatusBarManager;
import android.app.WindowConfiguration;
+import android.content.res.Resources;
import android.graphics.Rect;
import android.util.ArrayMap;
import android.util.IntArray;
@@ -123,14 +124,17 @@
* Let remote insets controller control system bars regardless of other settings.
*/
private boolean mRemoteInsetsControllerControlsSystemBars;
+ private final boolean mHideNavBarForKeyboard;
private final float[] mTmpFloat9 = new float[9];
InsetsPolicy(InsetsStateController stateController, DisplayContent displayContent) {
mStateController = stateController;
mDisplayContent = displayContent;
mPolicy = displayContent.getDisplayPolicy();
- mRemoteInsetsControllerControlsSystemBars = mPolicy.getContext().getResources().getBoolean(
+ final Resources r = mPolicy.getContext().getResources();
+ mRemoteInsetsControllerControlsSystemBars = r.getBoolean(
R.bool.config_remoteInsetsControllerControlsSystemBars);
+ mHideNavBarForKeyboard = r.getBoolean(R.bool.config_hideNavBarForKeyboard);
}
boolean getRemoteInsetsControllerControlsSystemBars() {
@@ -428,13 +432,15 @@
private InsetsState adjustVisibilityForIme(WindowState w, InsetsState originalState,
boolean copyState) {
if (w.mIsImWindow) {
- // Navigation bar insets is always visible to IME.
+ // If navigation bar is not hidden by IME, IME should always receive visible
+ // navigation bar insets.
+ final boolean navVisible = !mHideNavBarForKeyboard;
final InsetsSource originalNavSource = originalState.peekSource(ITYPE_NAVIGATION_BAR);
- if (originalNavSource != null && !originalNavSource.isVisible()) {
+ if (originalNavSource != null && originalNavSource.isVisible() != navVisible) {
final InsetsState state = copyState ? new InsetsState(originalState)
: originalState;
final InsetsSource navSource = new InsetsSource(originalNavSource);
- navSource.setVisible(true);
+ navSource.setVisible(navVisible);
state.addSource(navSource);
return state;
}
@@ -573,8 +579,9 @@
private @Nullable InsetsControlTarget getNavControlTarget(@Nullable WindowState focusedWin,
boolean fake) {
final WindowState imeWin = mDisplayContent.mInputMethodWindow;
- if (imeWin != null && imeWin.isVisible()) {
- // Force showing navigation bar while IME is visible.
+ if (imeWin != null && imeWin.isVisible() && !mHideNavBarForKeyboard) {
+ // Force showing navigation bar while IME is visible and if navigation bar is not
+ // configured to be hidden by the IME.
return null;
}
if (!fake && isShowingTransientTypes(Type.navigationBars())) {
diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java
index ce406e4..dd1b50f 100644
--- a/services/core/java/com/android/server/wm/TaskDisplayArea.java
+++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java
@@ -654,12 +654,14 @@
}
// Apps and their containers are not allowed to specify an orientation of non floating
- // visible tasks created by organizer. The organizer handles the orientation instead.
+ // visible tasks created by organizer and that has an adjacent task.
final Task nonFloatingTopTask =
- getRootTask(t -> !t.getWindowConfiguration().tasksAreFloating());
- if (nonFloatingTopTask != null && nonFloatingTopTask.mCreatedByOrganizer
- && nonFloatingTopTask.isVisible()) {
- return SCREEN_ORIENTATION_UNSPECIFIED;
+ getTask(t -> !t.getWindowConfiguration().tasksAreFloating());
+ if (nonFloatingTopTask != null) {
+ final Task task = nonFloatingTopTask.getCreatedByOrganizerTask();
+ if (task != null && task.getAdjacentTaskFragment() != null && task.isVisible()) {
+ return SCREEN_ORIENTATION_UNSPECIFIED;
+ }
}
final int orientation = super.getOrientation(candidate);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 1ce2417..8702578 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -1937,6 +1937,9 @@
updatePasswordQualityCacheForUserGroup(userHandle);
mPolicyCache.onUserRemoved(userHandle);
+ if (isManagedProfile(userHandle)) {
+ clearManagedProfileApnUnchecked();
+ }
isOrgOwned = mOwners.isProfileOwnerOfOrganizationOwnedDevice(userHandle);
mOwners.removeProfileOwner(userHandle);
@@ -8760,6 +8763,18 @@
}
}
+ private void clearManagedProfileApnUnchecked() {
+ if (!mHasTelephonyFeature) {
+ return;
+ }
+ final List<ApnSetting> apns = getOverrideApnsUnchecked();
+ for (ApnSetting apn : apns) {
+ if (apn.getApnTypeBitmask() == ApnSetting.TYPE_ENTERPRISE) {
+ removeOverrideApnUnchecked(apn.getId());
+ }
+ }
+ }
+
private void clearDeviceOwnerLocked(ActiveAdmin admin, int userId) {
mDeviceAdminServiceController.stopServiceForOwner(userId, "clear-device-owner");
@@ -12100,6 +12115,10 @@
}
}
+ private boolean isManagedProfileOwner(CallerIdentity caller) {
+ return isProfileOwner(caller) && isManagedProfile(caller.getUserId());
+ }
+
private boolean isDefaultSupervisor(CallerIdentity caller) {
final String supervisor = mContext.getResources().getString(
com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent);
@@ -16300,7 +16319,7 @@
final CallerIdentity caller = getCallerIdentity(who);
if (apnSetting.getApnTypeBitmask() == ApnSetting.TYPE_ENTERPRISE) {
Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller)
- || isProfileOwner(caller));
+ || isManagedProfileOwner(caller));
} else {
Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller));
}
@@ -16328,7 +16347,7 @@
if (apn != null && apn.getApnTypeBitmask() == ApnSetting.TYPE_ENTERPRISE
&& apnSetting.getApnTypeBitmask() == ApnSetting.TYPE_ENTERPRISE) {
Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller)
- || isProfileOwner(caller));
+ || isManagedProfileOwner(caller));
} else {
Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller));
}
@@ -16356,7 +16375,7 @@
ApnSetting apn = getApnSetting(apnId);
if (apn != null && apn.getApnTypeBitmask() == ApnSetting.TYPE_ENTERPRISE) {
Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller)
- || isProfileOwner(caller));
+ || isManagedProfileOwner(caller));
} else {
Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller));
}
@@ -16401,8 +16420,20 @@
}
Objects.requireNonNull(who, "ComponentName is null");
final CallerIdentity caller = getCallerIdentity(who);
- Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller));
- return getOverrideApnsUnchecked();
+ Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller)
+ || isManagedProfileOwner(caller));
+ List<ApnSetting> apnSettings = getOverrideApnsUnchecked();
+ if (isProfileOwner(caller)) {
+ List<ApnSetting> apnSettingList = new ArrayList<>();
+ for (ApnSetting apnSetting : apnSettings) {
+ if (apnSetting.getApnTypeBitmask() == ApnSetting.TYPE_ENTERPRISE) {
+ apnSettingList.add(apnSetting);
+ }
+ }
+ return apnSettingList;
+ } else {
+ return apnSettings;
+ }
}
private List<ApnSetting> getOverrideApnsUnchecked() {
diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
index 009dae5..fa8d569 100644
--- a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
@@ -585,6 +585,7 @@
DeviceConfigSession<Long> bgCurrentDrainInteractionGracePeriod = null;
DeviceConfigSession<Float> bgCurrentDrainRestrictedBucketThreshold = null;
DeviceConfigSession<Float> bgCurrentDrainBgRestrictedThreshold = null;
+ DeviceConfigSession<Boolean> bgCurrentDrainAutoRestrictAbusiveApps = null;
DeviceConfigSession<Boolean> bgPromptFgsWithNotiToBgRestricted = null;
DeviceConfigSession<Boolean> bgPromptAbusiveAppToBgRestricted = null;
DeviceConfigSession<Long> bgNotificationMinInterval = null;
@@ -644,6 +645,14 @@
isLowRamDeviceStatic() ? 1 : 0]);
bgCurrentDrainBgRestrictedThreshold.set(bgRestrictedThreshold);
+ bgCurrentDrainAutoRestrictAbusiveApps = new DeviceConfigSession<>(
+ DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
+ AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED,
+ DeviceConfig::getBoolean,
+ mContext.getResources().getBoolean(
+ R.bool.config_bg_current_drain_auto_restrict_abusive_apps));
+ bgCurrentDrainAutoRestrictAbusiveApps.set(true);
+
bgPromptFgsWithNotiToBgRestricted = new DeviceConfigSession<>(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
ConstantsObserver.KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED,
@@ -1099,6 +1108,7 @@
closeIfNotNull(bgCurrentDrainInteractionGracePeriod);
closeIfNotNull(bgCurrentDrainRestrictedBucketThreshold);
closeIfNotNull(bgCurrentDrainBgRestrictedThreshold);
+ closeIfNotNull(bgCurrentDrainAutoRestrictAbusiveApps);
closeIfNotNull(bgPromptFgsWithNotiToBgRestricted);
closeIfNotNull(bgPromptAbusiveAppToBgRestricted);
closeIfNotNull(bgNotificationMinInterval);
@@ -1651,6 +1661,7 @@
DeviceConfigSession<Float> bgCurrentDrainBgRestrictedThreshold = null;
DeviceConfigSession<Float> bgCurrentDrainRestrictedBucketHighThreshold = null;
DeviceConfigSession<Float> bgCurrentDrainBgRestrictedHighThreshold = null;
+ DeviceConfigSession<Boolean> bgCurrentDrainAutoRestrictAbusiveApps = null;
DeviceConfigSession<Long> bgMediaPlaybackMinDurationThreshold = null;
DeviceConfigSession<Long> bgLocationMinDurationThreshold = null;
DeviceConfigSession<Boolean> bgCurrentDrainEventDurationBasedThresholdEnabled = null;
@@ -1736,6 +1747,14 @@
isLowRamDeviceStatic() ? 1 : 0]);
bgCurrentDrainBgRestrictedHighThreshold.set(bgRestrictedHighThreshold);
+ bgCurrentDrainAutoRestrictAbusiveApps = new DeviceConfigSession<>(
+ DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
+ AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED,
+ DeviceConfig::getBoolean,
+ mContext.getResources().getBoolean(
+ R.bool.config_bg_current_drain_auto_restrict_abusive_apps));
+ bgCurrentDrainAutoRestrictAbusiveApps.set(true);
+
bgMediaPlaybackMinDurationThreshold = new DeviceConfigSession<>(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION,
@@ -2226,6 +2245,7 @@
closeIfNotNull(bgCurrentDrainBgRestrictedThreshold);
closeIfNotNull(bgCurrentDrainRestrictedBucketHighThreshold);
closeIfNotNull(bgCurrentDrainBgRestrictedHighThreshold);
+ closeIfNotNull(bgCurrentDrainAutoRestrictAbusiveApps);
closeIfNotNull(bgMediaPlaybackMinDurationThreshold);
closeIfNotNull(bgLocationMinDurationThreshold);
closeIfNotNull(bgCurrentDrainEventDurationBasedThresholdEnabled);
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/PrefetchControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/PrefetchControllerTest.java
index 8a954ca..5f9f1b2 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/PrefetchControllerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/PrefetchControllerTest.java
@@ -233,27 +233,34 @@
@Test
public void testConstantsUpdating_ValidValues() {
setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 5 * HOUR_IN_MILLIS);
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 5 * MINUTE_IN_MILLIS);
assertEquals(5 * HOUR_IN_MILLIS, mPrefetchController.getLaunchTimeThresholdMs());
+ assertEquals(5 * MINUTE_IN_MILLIS, mPrefetchController.getLaunchTimeAllowanceMs());
}
@Test
public void testConstantsUpdating_InvalidValues() {
// Test negatives/too low.
setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 4 * MINUTE_IN_MILLIS);
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, -MINUTE_IN_MILLIS);
assertEquals(HOUR_IN_MILLIS, mPrefetchController.getLaunchTimeThresholdMs());
+ assertEquals(0, mPrefetchController.getLaunchTimeAllowanceMs());
// Test larger than a day. Controller should cap at one day.
setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 25 * HOUR_IN_MILLIS);
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 5 * HOUR_IN_MILLIS);
assertEquals(24 * HOUR_IN_MILLIS, mPrefetchController.getLaunchTimeThresholdMs());
+ assertEquals(2 * HOUR_IN_MILLIS, mPrefetchController.getLaunchTimeAllowanceMs());
}
@Test
public void testConstantsUpdating_ThresholdChangesAlarms() {
final long launchDelayMs = 11 * HOUR_IN_MILLIS;
setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 7 * HOUR_IN_MILLIS);
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 0);
when(mUsageStatsManagerInternal
.getEstimatedPackageLaunchTime(SOURCE_PACKAGE, SOURCE_USER_ID))
.thenReturn(sSystemClock.millis() + launchDelayMs);
@@ -276,6 +283,7 @@
@Test
public void testConstraintNotSatisfiedWhenLaunchLate() {
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 0);
setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 7 * HOUR_IN_MILLIS);
final JobStatus job = createJobStatus("testConstraintNotSatisfiedWhenLaunchLate", 1);
@@ -290,6 +298,8 @@
@Test
public void testConstraintSatisfiedWhenLaunchSoon() {
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 0);
+
final JobStatus job = createJobStatus("testConstraintSatisfiedWhenLaunchSoon", 2);
when(mUsageStatsManagerInternal
.getEstimatedPackageLaunchTime(SOURCE_PACKAGE, SOURCE_USER_ID))
@@ -338,6 +348,8 @@
@Test
public void testConstraintSatisfiedWhenWidget() {
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 0);
+
final JobStatus jobNonWidget = createJobStatus("testConstraintSatisfiedWhenWidget", 1);
final JobStatus jobWidget = createJobStatus("testConstraintSatisfiedWhenWidget", 2);
@@ -365,6 +377,7 @@
@Test
public void testEstimatedLaunchTimeChangedToLate() {
setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 7 * HOUR_IN_MILLIS);
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 0);
when(mUsageStatsManagerInternal
.getEstimatedPackageLaunchTime(SOURCE_PACKAGE, SOURCE_USER_ID))
.thenReturn(sSystemClock.millis() + HOUR_IN_MILLIS);
@@ -393,6 +406,7 @@
@Test
public void testEstimatedLaunchTimeChangedToSoon() {
setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 7 * HOUR_IN_MILLIS);
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 0);
when(mUsageStatsManagerInternal
.getEstimatedPackageLaunchTime(SOURCE_PACKAGE, SOURCE_USER_ID))
.thenReturn(sSystemClock.millis() + 10 * HOUR_IN_MILLIS);
@@ -413,4 +427,36 @@
verify(mJobSchedulerService, timeout(DEFAULT_WAIT_MS)).onControllerStateChanged(any());
assertTrue(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_PREFETCH));
}
+
+ @Test
+ public void testEstimatedLaunchTimeAllowance() {
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 7 * HOUR_IN_MILLIS);
+ setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_ALLOWANCE_MS, 15 * MINUTE_IN_MILLIS);
+ when(mUsageStatsManagerInternal
+ .getEstimatedPackageLaunchTime(SOURCE_PACKAGE, SOURCE_USER_ID))
+ .thenReturn(sSystemClock.millis() + 10 * HOUR_IN_MILLIS);
+
+ InOrder inOrder = inOrder(mUsageStatsManagerInternal);
+
+ JobStatus jobStatus = createJobStatus("testEstimatedLaunchTimeAllowance", 1);
+ trackJobs(jobStatus);
+ inOrder.verify(mUsageStatsManagerInternal, timeout(DEFAULT_WAIT_MS))
+ .getEstimatedPackageLaunchTime(SOURCE_PACKAGE, SOURCE_USER_ID);
+ // The allowance shouldn't shift the alarm
+ verify(mAlarmManager, timeout(DEFAULT_WAIT_MS).times(1))
+ .setWindow(
+ anyInt(), eq(sElapsedRealtimeClock.millis() + 3 * HOUR_IN_MILLIS),
+ anyLong(), eq(TAG_PREFETCH), any(), any());
+ assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_PREFETCH));
+
+ mEstimatedLaunchTimeChangedListener.onEstimatedLaunchTimeChanged(SOURCE_USER_ID,
+ SOURCE_PACKAGE, sSystemClock.millis() + HOUR_IN_MILLIS);
+
+ inOrder.verify(mUsageStatsManagerInternal, timeout(DEFAULT_WAIT_MS).times(0))
+ .getEstimatedPackageLaunchTime(SOURCE_PACKAGE, SOURCE_USER_ID);
+ verify(mJobSchedulerService, timeout(DEFAULT_WAIT_MS)).onControllerStateChanged(any());
+ assertTrue(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_PREFETCH));
+
+ sSystemClock = getShiftedClock(sSystemClock, HOUR_IN_MILLIS + MINUTE_IN_MILLIS);
+ }
}
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/DeletePackageHelperTest.kt b/services/tests/mockingservicestests/src/com/android/server/pm/DeletePackageHelperTest.kt
index c9598bd..e30f3d2 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/DeletePackageHelperTest.kt
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/DeletePackageHelperTest.kt
@@ -69,13 +69,34 @@
}
@Test
- fun deleteSystemPackageFailsIfNotAdmin() {
+ fun deleteSystemPackageFailsIfNotAdminAndNotProfile() {
val ps = mPms.mSettings.getPackageLPr("a.data.package")
whenever(PackageManagerServiceUtils.isSystemApp(ps)).thenReturn(true)
whenever(mUserManagerInternal.getUserInfo(1)).thenReturn(UserInfo(1, "test", 0))
+ whenever(mUserManagerInternal.getProfileParentId(1)).thenReturn(1)
val dph = DeletePackageHelper(mPms)
- val result = dph.deletePackageX("a.data.package", 1L, 1, 0, false)
+ val result = dph.deletePackageX("a.data.package", 1L, 1,
+ PackageManager.DELETE_SYSTEM_APP, false)
+
+ assertThat(result).isEqualTo(PackageManager.DELETE_FAILED_USER_RESTRICTED)
+ }
+
+ @Test
+ fun deleteSystemPackageFailsIfProfileOfNonAdmin() {
+ val userId = 1
+ val parentId = 5
+ val ps = mPms.mSettings.getPackageLPr("a.data.package")
+ whenever(PackageManagerServiceUtils.isSystemApp(ps)).thenReturn(true)
+ whenever(mUserManagerInternal.getUserInfo(userId)).thenReturn(
+ UserInfo(userId, "test", UserInfo.FLAG_PROFILE))
+ whenever(mUserManagerInternal.getProfileParentId(userId)).thenReturn(parentId)
+ whenever(mUserManagerInternal.getUserInfo(parentId)).thenReturn(
+ UserInfo(userId, "testparent", 0))
+
+ val dph = DeletePackageHelper(mPms)
+ val result = dph.deletePackageX("a.data.package", 1L, userId,
+ PackageManager.DELETE_SYSTEM_APP, false)
assertThat(result).isEqualTo(PackageManager.DELETE_FAILED_USER_RESTRICTED)
}
@@ -93,4 +114,23 @@
assertThat(result).isEqualTo(PackageManager.DELETE_SUCCEEDED)
}
+
+ @Test
+ fun deleteSystemPackageSucceedsIfProfileOfAdmin() {
+ val userId = 1
+ val parentId = 5
+ val ps = mPms.mSettings.getPackageLPr("a.data.package")
+ whenever(PackageManagerServiceUtils.isSystemApp(ps)).thenReturn(true)
+ whenever(mUserManagerInternal.getUserInfo(userId)).thenReturn(
+ UserInfo(userId, "test", UserInfo.FLAG_PROFILE))
+ whenever(mUserManagerInternal.getProfileParentId(userId)).thenReturn(parentId)
+ whenever(mUserManagerInternal.getUserInfo(parentId)).thenReturn(
+ UserInfo(userId, "testparent", UserInfo.FLAG_ADMIN))
+
+ val dph = DeletePackageHelper(mPms)
+ val result = dph.deletePackageX("a.data.package", 1L, userId,
+ PackageManager.DELETE_SYSTEM_APP, false)
+
+ assertThat(result).isEqualTo(PackageManager.DELETE_SUCCEEDED)
+ }
}
\ No newline at end of file
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java
index 77cbb3a..5d9d765 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/InputControllerTest.java
@@ -34,6 +34,9 @@
import android.testing.TestableLooper;
import android.view.Display;
import android.view.DisplayInfo;
+import android.view.WindowManager;
+
+import androidx.test.InstrumentationRegistry;
import com.android.server.LocalServices;
@@ -79,7 +82,9 @@
// Allow virtual devices to be created on the looper thread for testing.
final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
mInputController = new InputController(new Object(), mNativeWrapperMock,
- new Handler(TestableLooper.get(this).getLooper()), threadVerifier);
+ new Handler(TestableLooper.get(this).getLooper()),
+ InstrumentationRegistry.getTargetContext().getSystemService(WindowManager.class),
+ threadVerifier);
}
@Test
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
index cbb9fd7..f9671e5 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceManagerServiceTest.java
@@ -77,6 +77,7 @@
import android.util.ArraySet;
import android.view.DisplayInfo;
import android.view.KeyEvent;
+import android.view.WindowManager;
import androidx.test.InstrumentationRegistry;
@@ -208,7 +209,8 @@
// Allow virtual devices to be created on the looper thread for testing.
final InputController.DeviceCreationThreadVerifier threadVerifier = () -> true;
mInputController = new InputController(new Object(), mNativeWrapperMock,
- new Handler(TestableLooper.get(this).getLooper()), threadVerifier);
+ new Handler(TestableLooper.get(this).getLooper()),
+ mContext.getSystemService(WindowManager.class), threadVerifier);
mAssociationInfo = new AssociationInfo(1, 0, null,
MacAddress.BROADCAST_ADDRESS, "", null, true, false, 0, 0);
diff --git a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java
index f27b8c2..8112ca8 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java
@@ -560,8 +560,19 @@
HdmiCecMessage reportArcInitiated = HdmiCecMessageBuilder.buildReportArcInitiated(
ADDR_TV,
ADDR_AUDIO_SYSTEM);
- assertThat(mNativeWrapper.getResultMessages()).contains(reportArcInitiated);
+ // <Report ARC Initiated> should only be sent after SAD querying is done
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(reportArcInitiated);
+
+ // Finish querying SADs
assertThat(mNativeWrapper.getResultMessages()).contains(SAD_QUERY);
+ mNativeWrapper.clearResultMessages();
+ mTestLooper.moveTimeForward(HdmiConfig.TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ assertThat(mNativeWrapper.getResultMessages()).contains(SAD_QUERY);
+ mTestLooper.moveTimeForward(HdmiConfig.TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+
+ assertThat(mNativeWrapper.getResultMessages()).contains(reportArcInitiated);
}
@Test
diff --git a/services/tests/servicestests/src/com/android/server/hdmi/RequestSadActionTest.java b/services/tests/servicestests/src/com/android/server/hdmi/RequestSadActionTest.java
index f7983ca..3228e82 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/RequestSadActionTest.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/RequestSadActionTest.java
@@ -139,11 +139,12 @@
}
@Test
- public void noResponse_queryAgain_emptyResult() {
+ public void noResponse_queryAgainOnce_emptyResult() {
RequestSadAction action = new RequestSadAction(mHdmiCecLocalDeviceTv, ADDR_AUDIO_SYSTEM,
mCallback);
action.start();
mTestLooper.dispatchAll();
+ assertThat(mSupportedSads).isNull();
HdmiCecMessage expected1 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
@@ -153,45 +154,90 @@
mTestLooper.moveTimeForward(TIMEOUT_MS);
mTestLooper.dispatchAll();
assertThat(mNativeWrapper.getResultMessages()).contains(expected1);
- mNativeWrapper.clearResultMessages();
mTestLooper.moveTimeForward(TIMEOUT_MS);
mTestLooper.dispatchAll();
+ assertThat(mSupportedSads).isNotNull();
+ assertThat(mSupportedSads.size()).isEqualTo(0);
+
HdmiCecMessage expected2 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
CODECS_TO_QUERY_2.stream().mapToInt(i -> i).toArray());
- assertThat(mNativeWrapper.getResultMessages()).contains(expected2);
- mNativeWrapper.clearResultMessages();
- mTestLooper.moveTimeForward(TIMEOUT_MS);
- mTestLooper.dispatchAll();
- assertThat(mNativeWrapper.getResultMessages()).contains(expected2);
- mNativeWrapper.clearResultMessages();
- mTestLooper.moveTimeForward(TIMEOUT_MS);
- mTestLooper.dispatchAll();
-
HdmiCecMessage expected3 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
CODECS_TO_QUERY_3.stream().mapToInt(i -> i).toArray());
- assertThat(mNativeWrapper.getResultMessages()).contains(expected3);
- mNativeWrapper.clearResultMessages();
- mTestLooper.moveTimeForward(TIMEOUT_MS);
- mTestLooper.dispatchAll();
- assertThat(mNativeWrapper.getResultMessages()).contains(expected3);
- mNativeWrapper.clearResultMessages();
- mTestLooper.moveTimeForward(TIMEOUT_MS);
- mTestLooper.dispatchAll();
-
HdmiCecMessage expected4 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
CODECS_TO_QUERY_4.stream().mapToInt(i -> i).toArray());
- assertThat(mNativeWrapper.getResultMessages()).contains(expected4);
- mNativeWrapper.clearResultMessages();
+
mTestLooper.moveTimeForward(TIMEOUT_MS);
mTestLooper.dispatchAll();
- assertThat(mNativeWrapper.getResultMessages()).contains(expected4);
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
mTestLooper.moveTimeForward(TIMEOUT_MS);
mTestLooper.dispatchAll();
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected2);
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected3);
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected4);
+ assertThat(mSupportedSads.size()).isEqualTo(0);
+ }
+
+ @Test
+ public void unrecognizedOpcode_dontQueryAgain_emptyResult() {
+ RequestSadAction action = new RequestSadAction(mHdmiCecLocalDeviceTv, ADDR_AUDIO_SYSTEM,
+ mCallback);
+ action.start();
+ mTestLooper.dispatchAll();
+ assertThat(mSupportedSads).isNull();
+
+ HdmiCecMessage unrecognizedOpcode = HdmiCecMessageBuilder.buildFeatureAbortCommand(
+ Constants.ADDR_AUDIO_SYSTEM, mTvLogicalAddress,
+ Constants.MESSAGE_REQUEST_SHORT_AUDIO_DESCRIPTOR,
+ Constants.ABORT_UNRECOGNIZED_OPCODE);
+
+ HdmiCecMessage expected1 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
+ mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
+ CODECS_TO_QUERY_1.stream().mapToInt(i -> i).toArray());
+ assertThat(mNativeWrapper.getResultMessages()).contains(expected1);
+ action.processCommand(unrecognizedOpcode);
+ mTestLooper.dispatchAll();
+
+ assertThat(mSupportedSads).isNotNull();
+ assertThat(mSupportedSads.size()).isEqualTo(0);
+
+ HdmiCecMessage expected2 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
+ mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
+ CODECS_TO_QUERY_2.stream().mapToInt(i -> i).toArray());
+ HdmiCecMessage expected3 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
+ mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
+ CODECS_TO_QUERY_3.stream().mapToInt(i -> i).toArray());
+ HdmiCecMessage expected4 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
+ mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
+ CODECS_TO_QUERY_4.stream().mapToInt(i -> i).toArray());
+
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected2);
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected3);
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected4);
assertThat(mSupportedSads.size()).isEqualTo(0);
}
@@ -455,11 +501,12 @@
}
@Test
- public void invalidMessageLength_queryAgain() {
+ public void invalidMessageLength_queryAgainOnce() {
RequestSadAction action = new RequestSadAction(mHdmiCecLocalDeviceTv, ADDR_AUDIO_SYSTEM,
mCallback);
action.start();
mTestLooper.dispatchAll();
+ assertThat(mSupportedSads).isNull();
HdmiCecMessage expected1 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
@@ -482,63 +529,35 @@
mTestLooper.moveTimeForward(TIMEOUT_MS);
mTestLooper.dispatchAll();
+ assertThat(mSupportedSads).isNotNull();
+ assertThat(mSupportedSads.size()).isEqualTo(0);
+
HdmiCecMessage expected2 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
CODECS_TO_QUERY_2.stream().mapToInt(i -> i).toArray());
- byte[] sadsToRespond_2 = new byte[]{
- 0x05, 0x18, 0x4A,
- 0x06, 0x64, 0x5A,
- 0x07,
- 0x08, 0x20, 0x0A};
- HdmiCecMessage response2 = HdmiCecMessageBuilder.buildReportShortAudioDescriptor(
- Constants.ADDR_AUDIO_SYSTEM, mTvLogicalAddress, sadsToRespond_2);
- assertThat(mNativeWrapper.getResultMessages()).contains(expected2);
- mNativeWrapper.clearResultMessages();
- action.processCommand(response2);
- mTestLooper.dispatchAll();
- mTestLooper.moveTimeForward(TIMEOUT_MS);
- mTestLooper.dispatchAll();
- assertThat(mNativeWrapper.getResultMessages()).contains(expected2);
- mNativeWrapper.clearResultMessages();
- mTestLooper.moveTimeForward(TIMEOUT_MS);
- mTestLooper.dispatchAll();
-
HdmiCecMessage expected3 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
CODECS_TO_QUERY_3.stream().mapToInt(i -> i).toArray());
- byte[] sadsToRespond_3 = new byte[0];
- HdmiCecMessage response3 = HdmiCecMessageBuilder.buildReportShortAudioDescriptor(
- Constants.ADDR_AUDIO_SYSTEM, mTvLogicalAddress, sadsToRespond_3);
- assertThat(mNativeWrapper.getResultMessages()).contains(expected3);
- mNativeWrapper.clearResultMessages();
- action.processCommand(response3);
- mTestLooper.dispatchAll();
- mTestLooper.moveTimeForward(TIMEOUT_MS);
- mTestLooper.dispatchAll();
- assertThat(mNativeWrapper.getResultMessages()).contains(expected3);
- mNativeWrapper.clearResultMessages();
- mTestLooper.moveTimeForward(TIMEOUT_MS);
- mTestLooper.dispatchAll();
-
HdmiCecMessage expected4 = HdmiCecMessageBuilder.buildRequestShortAudioDescriptor(
mTvLogicalAddress, Constants.ADDR_AUDIO_SYSTEM,
CODECS_TO_QUERY_4.stream().mapToInt(i -> i).toArray());
- byte[] sadsToRespond_4 = new byte[]{
- 0x0D, 0x18, 0x4A,
- 0x0E, 0x64, 0x5A,
- 0x0F, 0x4B};
- HdmiCecMessage response4 = HdmiCecMessageBuilder.buildReportShortAudioDescriptor(
- Constants.ADDR_AUDIO_SYSTEM, mTvLogicalAddress, sadsToRespond_4);
- assertThat(mNativeWrapper.getResultMessages()).contains(expected4);
- mNativeWrapper.clearResultMessages();
- action.processCommand(response4);
+
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
mTestLooper.dispatchAll();
mTestLooper.moveTimeForward(TIMEOUT_MS);
mTestLooper.dispatchAll();
- assertThat(mNativeWrapper.getResultMessages()).contains(expected4);
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
+ mTestLooper.moveTimeForward(TIMEOUT_MS);
+ mTestLooper.dispatchAll();
mTestLooper.moveTimeForward(TIMEOUT_MS);
mTestLooper.dispatchAll();
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected2);
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected3);
+ assertThat(mNativeWrapper.getResultMessages()).doesNotContain(expected4);
assertThat(mSupportedSads.size()).isEqualTo(0);
}
diff --git a/services/usb/java/com/android/server/usb/UsbDirectMidiDevice.java b/services/usb/java/com/android/server/usb/UsbDirectMidiDevice.java
index 2893f80..dc96c66 100644
--- a/services/usb/java/com/android/server/usb/UsbDirectMidiDevice.java
+++ b/services/usb/java/com/android/server/usb/UsbDirectMidiDevice.java
@@ -89,38 +89,36 @@
private final Object mLock = new Object();
private boolean mIsOpen;
+ private boolean mServerAvailable;
private UsbMidiPacketConverter mUsbMidiPacketConverter;
private final MidiDeviceServer.Callback mCallback = new MidiDeviceServer.Callback() {
-
@Override
public void onDeviceStatusChanged(MidiDeviceServer server, MidiDeviceStatus status) {
MidiDeviceInfo deviceInfo = status.getDeviceInfo();
int numInputPorts = deviceInfo.getInputPortCount();
int numOutputPorts = deviceInfo.getOutputPortCount();
- boolean hasOpenPorts = false;
+ int numOpenPorts = 0;
for (int i = 0; i < numInputPorts; i++) {
if (status.isInputPortOpen(i)) {
- hasOpenPorts = true;
- break;
+ numOpenPorts++;
}
}
- if (!hasOpenPorts) {
- for (int i = 0; i < numOutputPorts; i++) {
- if (status.getOutputPortOpenCount(i) > 0) {
- hasOpenPorts = true;
- break;
- }
+ for (int i = 0; i < numOutputPorts; i++) {
+ if (status.getOutputPortOpenCount(i) > 0) {
+ numOpenPorts += status.getOutputPortOpenCount(i);
}
}
synchronized (mLock) {
- if (hasOpenPorts && !mIsOpen) {
+ Log.d(TAG, "numOpenPorts: " + numOpenPorts + " isOpen: " + mIsOpen
+ + " mServerAvailable: " + mServerAvailable);
+ if ((numOpenPorts > 0) && !mIsOpen && mServerAvailable) {
openLocked();
- } else if (!hasOpenPorts && mIsOpen) {
+ } else if ((numOpenPorts == 0) && mIsOpen) {
closeLocked();
}
}
@@ -348,7 +346,7 @@
final UsbRequest response = connectionFinal.requestWait();
if (response != request) {
Log.w(TAG, "Unexpected response");
- continue;
+ break;
}
int bytesRead = byteBuffer.position();
@@ -462,7 +460,7 @@
mContext = context;
MidiManager midiManager = context.getSystemService(MidiManager.class);
if (midiManager == null) {
- Log.e(TAG, "No MidiManager in UsbDirectMidiDevice.create()");
+ Log.e(TAG, "No MidiManager in UsbDirectMidiDevice.register()");
return false;
}
@@ -499,6 +497,7 @@
mUsbDevice.getSerialNumber());
properties.putParcelable(MidiDeviceInfo.PROPERTY_USB_DEVICE, mUsbDevice);
+ mServerAvailable = true;
mServer = midiManager.createDeviceServer(mMidiInputPortReceivers, mNumInputs,
null, null, properties, MidiDeviceInfo.TYPE_USB, mDefaultMidiProtocol, mCallback);
if (mServer == null) {
@@ -514,6 +513,7 @@
if (mIsOpen) {
closeLocked();
}
+ mServerAvailable = false;
}
if (mServer != null) {
diff --git a/services/usb/java/com/android/server/usb/UsbMidiDevice.java b/services/usb/java/com/android/server/usb/UsbMidiDevice.java
index 275f217..67955e1 100644
--- a/services/usb/java/com/android/server/usb/UsbMidiDevice.java
+++ b/services/usb/java/com/android/server/usb/UsbMidiDevice.java
@@ -71,40 +71,38 @@
private final Object mLock = new Object();
private boolean mIsOpen;
+ private boolean mServerAvailable;
// pipe file descriptor for signalling input thread to exit
// only accessed from JNI code
private int mPipeFD = -1;
private final MidiDeviceServer.Callback mCallback = new MidiDeviceServer.Callback() {
-
@Override
public void onDeviceStatusChanged(MidiDeviceServer server, MidiDeviceStatus status) {
MidiDeviceInfo deviceInfo = status.getDeviceInfo();
- int inputPorts = deviceInfo.getInputPortCount();
- int outputPorts = deviceInfo.getOutputPortCount();
- boolean hasOpenPorts = false;
+ int numInputPorts = deviceInfo.getInputPortCount();
+ int numOutputPorts = deviceInfo.getOutputPortCount();
+ int numOpenPorts = 0;
- for (int i = 0; i < inputPorts; i++) {
+ for (int i = 0; i < numInputPorts; i++) {
if (status.isInputPortOpen(i)) {
- hasOpenPorts = true;
- break;
+ numOpenPorts++;
}
}
- if (!hasOpenPorts) {
- for (int i = 0; i < outputPorts; i++) {
- if (status.getOutputPortOpenCount(i) > 0) {
- hasOpenPorts = true;
- break;
- }
+ for (int i = 0; i < numOutputPorts; i++) {
+ if (status.getOutputPortOpenCount(i) > 0) {
+ numOpenPorts += status.getOutputPortOpenCount(i);
}
}
synchronized (mLock) {
- if (hasOpenPorts && !mIsOpen) {
+ Log.d(TAG, "numOpenPorts: " + numOpenPorts + " isOpen: " + mIsOpen
+ + " mServerAvailable: " + mServerAvailable);
+ if ((numOpenPorts > 0) && !mIsOpen && mServerAvailable) {
openLocked();
- } else if (!hasOpenPorts && mIsOpen) {
+ } else if ((numOpenPorts == 0) && mIsOpen) {
closeLocked();
}
}
@@ -298,10 +296,11 @@
private boolean register(Context context, Bundle properties) {
MidiManager midiManager = (MidiManager)context.getSystemService(Context.MIDI_SERVICE);
if (midiManager == null) {
- Log.e(TAG, "No MidiManager in UsbMidiDevice.create()");
+ Log.e(TAG, "No MidiManager in UsbMidiDevice.register()");
return false;
}
+ mServerAvailable = true;
mServer = midiManager.createDeviceServer(mMidiInputPortReceivers, mNumInputs,
null, null, properties, MidiDeviceInfo.TYPE_USB,
MidiDeviceInfo.PROTOCOL_UNKNOWN, mCallback);
@@ -318,6 +317,7 @@
if (mIsOpen) {
closeLocked();
}
+ mServerAvailable = false;
}
if (mServer != null) {
diff --git a/telecomm/java/android/telecom/Call.java b/telecomm/java/android/telecom/Call.java
index 980ea5c..432af3a 100644
--- a/telecomm/java/android/telecom/Call.java
+++ b/telecomm/java/android/telecom/Call.java
@@ -2895,7 +2895,19 @@
if (key != null) {
final Object value = bundle.get(key);
final Object newValue = newBundle.get(key);
- if (!Objects.equals(value, newValue)) {
+ if (!newBundle.containsKey(key)) {
+ return false;
+ }
+ if (value instanceof Bundle && newValue instanceof Bundle) {
+ if (!areBundlesEqual((Bundle) value, (Bundle) newValue)) {
+ return false;
+ }
+ }
+ if (value instanceof byte[] && newValue instanceof byte[]) {
+ if (!Arrays.equals((byte[]) value, (byte[]) newValue)) {
+ return false;
+ }
+ } else if (!Objects.equals(value, newValue)) {
return false;
}
}
diff --git a/telephony/common/android/telephony/LocationAccessPolicy.java b/telephony/common/android/telephony/LocationAccessPolicy.java
index 9dfb0cc..d4b6c91 100644
--- a/telephony/common/android/telephony/LocationAccessPolicy.java
+++ b/telephony/common/android/telephony/LocationAccessPolicy.java
@@ -316,9 +316,11 @@
return LocationPermissionResult.ALLOWED;
}
- // Check the system-wide requirements. If the location main switch is off or
- // the app's profile isn't in foreground, return a soft denial.
- if (!checkSystemLocationAccess(context, query.callingUid, query.callingPid)) {
+ // Check the system-wide requirements. If the location main switch is off and the caller is
+ // not in the allowlist of apps that always have loation access or the app's profile
+ // isn't in the foreground, return a soft denial.
+ if (!checkSystemLocationAccess(context, query.callingUid, query.callingPid,
+ query.callingPackage)) {
return LocationPermissionResult.DENIED_SOFT;
}
@@ -344,15 +346,16 @@
return LocationPermissionResult.ALLOWED;
}
-
private static boolean checkManifestPermission(Context context, int pid, int uid,
String permissionToCheck) {
return context.checkPermission(permissionToCheck, pid, uid)
== PackageManager.PERMISSION_GRANTED;
}
- private static boolean checkSystemLocationAccess(@NonNull Context context, int uid, int pid) {
- if (!isLocationModeEnabled(context, UserHandle.getUserHandleForUid(uid).getIdentifier())) {
+ private static boolean checkSystemLocationAccess(@NonNull Context context, int uid, int pid,
+ @NonNull String callingPackage) {
+ if (!isLocationModeEnabled(context, UserHandle.getUserHandleForUid(uid).getIdentifier())
+ && !isLocationBypassAllowed(context, callingPackage)) {
if (DBG) Log.w(TAG, "Location disabled, failed, (" + uid + ")");
return false;
}
@@ -373,6 +376,16 @@
return locationManager.isLocationEnabledForUser(UserHandle.of(userId));
}
+ private static boolean isLocationBypassAllowed(@NonNull Context context,
+ @NonNull String callingPackage) {
+ for (String bypassPackage : getLocationBypassPackages(context)) {
+ if (callingPackage.equals(bypassPackage)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* @return An array of packages that are always allowed to access location.
*/
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index a6e3bb4..b6f8652 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -17006,4 +17006,41 @@
}
mTelephonyRegistryMgr.removeCarrierPrivilegesCallback(callback);
}
+
+ /**
+ * set removable eSIM as default eUICC.
+ *
+ * @hide
+ */
+ @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
+ @RequiresFeature(PackageManager.FEATURE_TELEPHONY_EUICC)
+ public void setRemovableEsimAsDefaultEuicc(boolean isDefault) {
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null) {
+ telephony.setRemovableEsimAsDefaultEuicc(isDefault, getOpPackageName());
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error in setRemovableEsimAsDefault: " + e);
+ }
+ }
+
+ /**
+ * Returns whether the removable eSIM is default eUICC or not.
+ *
+ * @hide
+ */
+ @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
+ @RequiresFeature(PackageManager.FEATURE_TELEPHONY_EUICC)
+ public boolean isRemovableEsimDefaultEuicc() {
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null) {
+ return telephony.isRemovableEsimDefaultEuicc(getOpPackageName());
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error in isRemovableEsimDefaultEuicc: " + e);
+ }
+ return false;
+ }
}
diff --git a/telephony/java/android/telephony/euicc/EuiccManager.java b/telephony/java/android/telephony/euicc/EuiccManager.java
index eede9dc..a673807 100644
--- a/telephony/java/android/telephony/euicc/EuiccManager.java
+++ b/telephony/java/android/telephony/euicc/EuiccManager.java
@@ -25,18 +25,17 @@
import android.annotation.SystemApi;
import android.app.Activity;
import android.app.PendingIntent;
-import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.PackageManager;
-import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyFrameworkInitializer;
import android.telephony.TelephonyManager;
import android.telephony.UiccCardInfo;
@@ -1209,18 +1208,16 @@
return;
}
try {
- // TODO: Uncomment below compat change code once callers are ported to use
- // switchToSubscription with portIndex for disable operation.
- // if (subscriptionId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
- // && getIEuiccController().isCompatChangeEnabled(mContext.getOpPackageName(),
- // SWITCH_WITHOUT_PORT_INDEX_EXCEPTION_ON_DISABLE)) {
- // // Apps targeting on Android T and beyond will get exception whenever
- // // switchToSubscription without portIndex is called with INVALID_SUBSCRIPTION_ID.
- // Log.e(TAG, "switchToSubscription without portIndex is not allowed for"
- // + " disable operation");
- // throw new IllegalArgumentException("Must use switchToSubscription with portIndex"
- // + " API for disable operation");
- // }
+ if (subscriptionId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
+ && getIEuiccController().isCompatChangeEnabled(mContext.getOpPackageName(),
+ SWITCH_WITHOUT_PORT_INDEX_EXCEPTION_ON_DISABLE)) {
+ // Apps targeting on Android T and beyond will get exception whenever
+ // switchToSubscription without portIndex is called with INVALID_SUBSCRIPTION_ID.
+ Log.e(TAG, "switchToSubscription without portIndex is not allowed for"
+ + " disable operation");
+ throw new IllegalArgumentException("Must use switchToSubscription with portIndex"
+ + " API for disable operation");
+ }
getIEuiccController().switchToSubscription(mCardId,
subscriptionId, mContext.getOpPackageName(), callbackIntent);
} catch (RemoteException e) {
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 7d116f9..0ce6b14 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -2553,4 +2553,18 @@
* for the slot, or {@code null} if none is resolved
*/
String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex);
+
+ /**
+ * set removable eSIM as default eUICC.
+ *
+ * @hide
+ */
+ void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage);
+
+ /**
+ * Returns whether the removable eSIM is default eUICC or not.
+ *
+ * @hide
+ */
+ boolean isRemovableEsimDefaultEuicc(String callingPackage);
}