Merge "Update tutorial state based on the transition state to the communal scene" into main
diff --git a/AconfigFlags.bp b/AconfigFlags.bp
index c211b02..76377e7 100644
--- a/AconfigFlags.bp
+++ b/AconfigFlags.bp
@@ -29,6 +29,7 @@
":android.service.notification.flags-aconfig-java{.generated_srcjars}",
":android.view.flags-aconfig-java{.generated_srcjars}",
":android.view.accessibility.flags-aconfig-java{.generated_srcjars}",
+ ":audio-framework-aconfig",
":camera_platform_flags_core_java_lib{.generated_srcjars}",
":com.android.window.flags.window-aconfig-java{.generated_srcjars}",
":android.hardware.biometrics.flags-aconfig-java{.generated_srcjars}",
@@ -39,7 +40,6 @@
":android.companion.virtual.flags-aconfig-java{.generated_srcjars}",
":android.view.inputmethod.flags-aconfig-java{.generated_srcjars}",
":android.widget.flags-aconfig-java{.generated_srcjars}",
- ":com.android.media.audio.flags-aconfig-java{.generated_srcjars}",
":com.android.media.flags.bettertogether-aconfig-java{.generated_srcjars}",
":sdk_sandbox_flags_lib{.generated_srcjars}",
":android.permission.flags-aconfig-java{.generated_srcjars}",
@@ -54,7 +54,6 @@
":android.view.contentprotection.flags-aconfig-java{.generated_srcjars}",
":android.service.voice.flags-aconfig-java{.generated_srcjars}",
":android.media.tv.flags-aconfig-java{.generated_srcjars}",
- ":aconfig_midi_flags_java_lib{.generated_srcjars}",
":android.service.autofill.flags-aconfig-java{.generated_srcjars}",
":com.android.net.flags-aconfig-java{.generated_srcjars}",
":device_policy_aconfig_flags_lib{.generated_srcjars}",
@@ -393,13 +392,6 @@
defaults: ["framework-minus-apex-aconfig-java-defaults"],
}
-// Media Audio
-java_aconfig_library {
- name: "com.android.media.audio.flags-aconfig-java",
- aconfig_declarations: "aconfig_audio_flags",
- defaults: ["framework-minus-apex-aconfig-java-defaults"],
-}
-
// Permissions
aconfig_declarations {
name: "android.permission.flags-aconfig",
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/IdleController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/IdleController.java
index a25af71..47d3fd5 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/IdleController.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/IdleController.java
@@ -18,13 +18,16 @@
import static com.android.server.job.JobSchedulerService.sElapsedRealtimeClock;
+import android.annotation.NonNull;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserHandle;
+import android.provider.DeviceConfig;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.proto.ProtoOutputStream;
+import com.android.internal.annotations.GuardedBy;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.StateControllerProto;
import com.android.server.job.controllers.idle.CarIdlenessTracker;
@@ -89,6 +92,19 @@
}
}
+ @Override
+ public void processConstantLocked(@NonNull DeviceConfig.Properties properties,
+ @NonNull String key) {
+ mIdleTracker.processConstant(properties, key);
+ }
+
+ @Override
+ @GuardedBy("mLock")
+ public void onBatteryStateChangedLocked() {
+ mIdleTracker.onBatteryStateChanged(
+ mService.isBatteryCharging(), mService.isBatteryNotLow());
+ }
+
/**
* State-change notifications from the idleness tracker
*/
@@ -119,7 +135,16 @@
} else {
mIdleTracker = new DeviceIdlenessTracker();
}
- mIdleTracker.startTracking(ctx, this);
+ mIdleTracker.startTracking(ctx, mService, this);
+ }
+
+ @Override
+ public void dumpConstants(IndentingPrintWriter pw) {
+ pw.println();
+ pw.println("IdleController:");
+ pw.increaseIndent();
+ mIdleTracker.dumpConstants(pw);
+ pw.decreaseIndent();
}
@Override
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/CarIdlenessTracker.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/CarIdlenessTracker.java
index c458cae..ba0e633 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/CarIdlenessTracker.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/CarIdlenessTracker.java
@@ -16,10 +16,13 @@
package com.android.server.job.controllers.idle;
+import android.annotation.NonNull;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.provider.DeviceConfig;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
@@ -73,7 +76,8 @@
}
@Override
- public void startTracking(Context context, IdlenessListener listener) {
+ public void startTracking(Context context, JobSchedulerService service,
+ IdlenessListener listener) {
mIdleListener = listener;
IntentFilter filter = new IntentFilter();
@@ -94,6 +98,15 @@
context.registerReceiver(this, filter, null, AppSchedulingModuleThread.getHandler());
}
+ /** Process the specified constant and update internal constants if relevant. */
+ public void processConstant(@NonNull DeviceConfig.Properties properties,
+ @NonNull String key) {
+ }
+
+ @Override
+ public void onBatteryStateChanged(boolean isCharging, boolean isBatteryNotLow) {
+ }
+
@Override
public void dump(PrintWriter pw) {
pw.print(" mIdle: "); pw.println(mIdle);
@@ -119,6 +132,10 @@
}
@Override
+ public void dumpConstants(IndentingPrintWriter pw) {
+ }
+
+ @Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
logIfDebug("Received action: " + action);
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java
index c943e73..7dd3d13 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java
@@ -17,9 +17,12 @@
package com.android.server.job.controllers.idle;
import static android.app.UiModeManager.PROJECTION_TYPE_NONE;
+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 android.annotation.NonNull;
import android.app.AlarmManager;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
@@ -27,10 +30,13 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.PowerManager;
+import android.provider.DeviceConfig;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.server.AppSchedulingModuleThread;
import com.android.server.am.ActivityManagerService;
import com.android.server.job.JobSchedulerService;
@@ -45,17 +51,38 @@
private static final boolean DEBUG = JobSchedulerService.DEBUG
|| Log.isLoggable(TAG, Log.DEBUG);
+ /** Prefix to use with all constant keys in order to "sub-namespace" the keys. */
+ private static final String IC_DIT_CONSTANT_PREFIX = "ic_dit_";
+ @VisibleForTesting
+ static final String KEY_INACTIVITY_IDLE_THRESHOLD_MS =
+ IC_DIT_CONSTANT_PREFIX + "inactivity_idle_threshold_ms";
+ @VisibleForTesting
+ static final String KEY_INACTIVITY_STABLE_POWER_IDLE_THRESHOLD_MS =
+ IC_DIT_CONSTANT_PREFIX + "inactivity_idle_stable_power_threshold_ms";
+ private static final String KEY_IDLE_WINDOW_SLOP_MS =
+ IC_DIT_CONSTANT_PREFIX + "idle_window_slop_ms";
+
private AlarmManager mAlarm;
private PowerManager mPowerManager;
// After construction, mutations of idle/screen-on/projection states will only happen
// on the JobScheduler thread, either in onReceive(), in an alarm callback, or in on.*Changed.
private long mInactivityIdleThreshold;
+ private long mInactivityStablePowerIdleThreshold;
private long mIdleWindowSlop;
+ /** Stable power is defined as "charging + battery not low." */
+ private boolean mIsStablePower;
private boolean mIdle;
private boolean mScreenOn;
private boolean mDockIdle;
private boolean mProjectionActive;
+
+ /**
+ * Time (in the elapsed realtime timebase) when the idleness check was scheduled. This should
+ * be a negative value if the device is not in state to be considered idle.
+ */
+ private long mIdlenessCheckScheduledElapsed = -1;
+
private IdlenessListener mIdleListener;
private final UiModeManager.OnProjectionStateChangedListener mOnProjectionStateChangedListener =
this::onProjectionStateChanged;
@@ -76,10 +103,14 @@
}
@Override
- public void startTracking(Context context, IdlenessListener listener) {
+ public void startTracking(Context context, JobSchedulerService service,
+ IdlenessListener listener) {
mIdleListener = listener;
mInactivityIdleThreshold = context.getResources().getInteger(
com.android.internal.R.integer.config_jobSchedulerInactivityIdleThreshold);
+ mInactivityStablePowerIdleThreshold = context.getResources().getInteger(
+ com.android.internal.R.integer
+ .config_jobSchedulerInactivityIdleThresholdOnStablePower);
mIdleWindowSlop = context.getResources().getInteger(
com.android.internal.R.integer.config_jobSchedulerIdleWindowSlop);
mAlarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
@@ -107,6 +138,46 @@
context.getSystemService(UiModeManager.class).addOnProjectionStateChangedListener(
UiModeManager.PROJECTION_TYPE_ALL, AppSchedulingModuleThread.getExecutor(),
mOnProjectionStateChangedListener);
+
+ mIsStablePower = service.isBatteryCharging() && service.isBatteryNotLow();
+ }
+
+ /** Process the specified constant and update internal constants if relevant. */
+ public void processConstant(@NonNull DeviceConfig.Properties properties,
+ @NonNull String key) {
+ switch (key) {
+ case KEY_INACTIVITY_IDLE_THRESHOLD_MS:
+ // Keep the threshold in the range [1 minute, 4 hours].
+ mInactivityIdleThreshold = Math.max(MINUTE_IN_MILLIS, Math.min(4 * HOUR_IN_MILLIS,
+ properties.getLong(key, mInactivityIdleThreshold)));
+ // Don't bother updating any pending alarms. Just wait until the next time we
+ // attempt to check for idle state to use the new value.
+ break;
+ case KEY_INACTIVITY_STABLE_POWER_IDLE_THRESHOLD_MS:
+ // Keep the threshold in the range [1 minute, 4 hours].
+ mInactivityStablePowerIdleThreshold = Math.max(MINUTE_IN_MILLIS,
+ Math.min(4 * HOUR_IN_MILLIS,
+ properties.getLong(key, mInactivityStablePowerIdleThreshold)));
+ // Don't bother updating any pending alarms. Just wait until the next time we
+ // attempt to check for idle state to use the new value.
+ break;
+ case KEY_IDLE_WINDOW_SLOP_MS:
+ // Keep the slop in the range [1 minute, 15 minutes].
+ mIdleWindowSlop = Math.max(MINUTE_IN_MILLIS, Math.min(15 * MINUTE_IN_MILLIS,
+ properties.getLong(key, mIdleWindowSlop)));
+ // Don't bother updating any pending alarms. Just wait until the next time we
+ // attempt to check for idle state to use the new value.
+ break;
+ }
+ }
+
+ @Override
+ public void onBatteryStateChanged(boolean isCharging, boolean isBatteryNotLow) {
+ final boolean isStablePower = isCharging && isBatteryNotLow;
+ if (mIsStablePower != isStablePower) {
+ mIsStablePower = isStablePower;
+ maybeScheduleIdlenessCheck("stable power changed");
+ }
}
private void onProjectionStateChanged(@UiModeManager.ProjectionType int activeProjectionTypes,
@@ -134,8 +205,10 @@
public void dump(PrintWriter pw) {
pw.print(" mIdle: "); pw.println(mIdle);
pw.print(" mScreenOn: "); pw.println(mScreenOn);
+ pw.print(" mIsStablePower: "); pw.println(mIsStablePower);
pw.print(" mDockIdle: "); pw.println(mDockIdle);
pw.print(" mProjectionActive: "); pw.println(mProjectionActive);
+ pw.print(" mIdlenessCheckScheduledElapsed: "); pw.println(mIdlenessCheckScheduledElapsed);
}
@Override
@@ -162,6 +235,17 @@
}
@Override
+ public void dumpConstants(IndentingPrintWriter pw) {
+ pw.println("DeviceIdlenessTracker:");
+ pw.increaseIndent();
+ pw.print(KEY_INACTIVITY_IDLE_THRESHOLD_MS, mInactivityIdleThreshold).println();
+ pw.print(KEY_INACTIVITY_STABLE_POWER_IDLE_THRESHOLD_MS, mInactivityStablePowerIdleThreshold)
+ .println();
+ pw.print(KEY_IDLE_WINDOW_SLOP_MS, mIdleWindowSlop).println();
+ pw.decreaseIndent();
+ }
+
+ @Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (DEBUG) {
@@ -220,9 +304,24 @@
private void maybeScheduleIdlenessCheck(String reason) {
if ((!mScreenOn || mDockIdle) && !mProjectionActive) {
final long nowElapsed = sElapsedRealtimeClock.millis();
- final long when = nowElapsed + mInactivityIdleThreshold;
+ final long inactivityThresholdMs = mIsStablePower
+ ? mInactivityStablePowerIdleThreshold : mInactivityIdleThreshold;
+ if (mIdlenessCheckScheduledElapsed >= 0) {
+ if (mIdlenessCheckScheduledElapsed + inactivityThresholdMs <= nowElapsed) {
+ if (DEBUG) {
+ Slog.v(TAG, "Previous idle check @ " + mIdlenessCheckScheduledElapsed
+ + " allows device to be idle now");
+ }
+ handleIdleTrigger();
+ return;
+ }
+ } else {
+ mIdlenessCheckScheduledElapsed = nowElapsed;
+ }
+ final long when = mIdlenessCheckScheduledElapsed + inactivityThresholdMs;
if (DEBUG) {
- Slog.v(TAG, "Scheduling idle : " + reason + " now:" + nowElapsed + " when=" + when);
+ Slog.v(TAG, "Scheduling idle : " + reason + " now:" + nowElapsed
+ + " checkElapsed=" + mIdlenessCheckScheduledElapsed + " when=" + when);
}
mAlarm.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,
when, mIdleWindowSlop, "JS idleness",
@@ -232,6 +331,7 @@
private void cancelIdlenessCheck() {
mAlarm.cancel(mIdleAlarmListener);
+ mIdlenessCheckScheduledElapsed = -1;
}
private void handleIdleTrigger() {
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/IdlenessTracker.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/IdlenessTracker.java
index cdab7e5..92ad4df 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/IdlenessTracker.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/IdlenessTracker.java
@@ -16,9 +16,14 @@
package com.android.server.job.controllers.idle;
+import android.annotation.NonNull;
import android.content.Context;
+import android.provider.DeviceConfig;
+import android.util.IndentingPrintWriter;
import android.util.proto.ProtoOutputStream;
+import com.android.server.job.JobSchedulerService;
+
import java.io.PrintWriter;
public interface IdlenessTracker {
@@ -29,7 +34,7 @@
* non-interacting state. When the idle state changes thereafter, the given
* listener must be called to report the new state.
*/
- void startTracking(Context context, IdlenessListener listener);
+ void startTracking(Context context, JobSchedulerService service, IdlenessListener listener);
/**
* Report whether the device is currently considered "idle" for purposes of
@@ -40,6 +45,12 @@
*/
boolean isIdle();
+ /** Process the specified constant and update internal constants if relevant. */
+ void processConstant(@NonNull DeviceConfig.Properties properties, @NonNull String key);
+
+ /** Called when the battery state changes. */
+ void onBatteryStateChanged(boolean isCharging, boolean isBatteryNotLow);
+
/**
* Dump useful information about tracked idleness-related state in plaintext.
*/
@@ -49,4 +60,7 @@
* Dump useful information about tracked idleness-related state to proto.
*/
void dump(ProtoOutputStream proto, long fieldId);
+
+ /** Dump any internal constants the tracker may have. */
+ void dumpConstants(IndentingPrintWriter pw);
}
diff --git a/core/api/current.txt b/core/api/current.txt
index e02803d..1b0311d 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -9321,6 +9321,21 @@
field public static final int USER_INTERACTION = 7; // 0x7
}
+ @FlaggedApi("android.app.usage.filter_based_event_query_api") public final class UsageEventsQuery implements android.os.Parcelable {
+ method public int describeContents();
+ method public long getBeginTimeMillis();
+ method public long getEndTimeMillis();
+ method @NonNull public java.util.Set<java.lang.Integer> getEventTypes();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.app.usage.UsageEventsQuery> CREATOR;
+ }
+
+ public static final class UsageEventsQuery.Builder {
+ ctor public UsageEventsQuery.Builder(long, long);
+ method @NonNull public android.app.usage.UsageEventsQuery.Builder addEventTypes(@NonNull int...);
+ method @NonNull public android.app.usage.UsageEventsQuery build();
+ }
+
public final class UsageStats implements android.os.Parcelable {
ctor public UsageStats(android.app.usage.UsageStats);
method public void add(android.app.usage.UsageStats);
@@ -9345,6 +9360,7 @@
method public java.util.List<android.app.usage.ConfigurationStats> queryConfigurations(int, long, long);
method public java.util.List<android.app.usage.EventStats> queryEventStats(int, long, long);
method public android.app.usage.UsageEvents queryEvents(long, long);
+ method @FlaggedApi("android.app.usage.filter_based_event_query_api") @NonNull @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public android.app.usage.UsageEvents queryEvents(@NonNull android.app.usage.UsageEventsQuery);
method public android.app.usage.UsageEvents queryEventsForSelf(long, long);
method public java.util.List<android.app.usage.UsageStats> queryUsageStats(int, long, long);
field public static final int INTERVAL_BEST = 4; // 0x4
@@ -25850,15 +25866,15 @@
method public abstract void onDisconnect(android.media.midi.MidiReceiver);
}
- @FlaggedApi("com.android.media.midi.flags.virtual_ump") public abstract class MidiUmpDeviceService extends android.app.Service {
+ @FlaggedApi("android.media.midi.virtual_ump") public abstract class MidiUmpDeviceService extends android.app.Service {
ctor public MidiUmpDeviceService();
- method @FlaggedApi("com.android.media.midi.flags.virtual_ump") @Nullable public final android.media.midi.MidiDeviceInfo getDeviceInfo();
- method @FlaggedApi("com.android.media.midi.flags.virtual_ump") @NonNull public final java.util.List<android.media.midi.MidiReceiver> getOutputPortReceivers();
- method @FlaggedApi("com.android.media.midi.flags.virtual_ump") @Nullable public android.os.IBinder onBind(@NonNull android.content.Intent);
- method @FlaggedApi("com.android.media.midi.flags.virtual_ump") public void onClose();
- method @FlaggedApi("com.android.media.midi.flags.virtual_ump") public void onDeviceStatusChanged(@NonNull android.media.midi.MidiDeviceStatus);
- method @FlaggedApi("com.android.media.midi.flags.virtual_ump") @NonNull public abstract java.util.List<android.media.midi.MidiReceiver> onGetInputPortReceivers();
- field @FlaggedApi("com.android.media.midi.flags.virtual_ump") public static final String SERVICE_INTERFACE = "android.media.midi.MidiUmpDeviceService";
+ method @FlaggedApi("android.media.midi.virtual_ump") @Nullable public final android.media.midi.MidiDeviceInfo getDeviceInfo();
+ method @FlaggedApi("android.media.midi.virtual_ump") @NonNull public final java.util.List<android.media.midi.MidiReceiver> getOutputPortReceivers();
+ method @FlaggedApi("android.media.midi.virtual_ump") @Nullable public android.os.IBinder onBind(@NonNull android.content.Intent);
+ method @FlaggedApi("android.media.midi.virtual_ump") public void onClose();
+ method @FlaggedApi("android.media.midi.virtual_ump") public void onDeviceStatusChanged(@NonNull android.media.midi.MidiDeviceStatus);
+ method @FlaggedApi("android.media.midi.virtual_ump") @NonNull public abstract java.util.List<android.media.midi.MidiReceiver> onGetInputPortReceivers();
+ field @FlaggedApi("android.media.midi.virtual_ump") public static final String SERVICE_INTERFACE = "android.media.midi.MidiUmpDeviceService";
}
}
@@ -49813,6 +49829,7 @@
method public default void removeOnBufferTransformHintChangedListener(@NonNull android.view.AttachedSurfaceControl.OnBufferTransformHintChangedListener);
method public default void setChildBoundingInsets(@NonNull android.graphics.Rect);
method public default void setTouchableRegion(@Nullable android.graphics.Region);
+ method @FlaggedApi("com.android.window.flags.transfer_gesture_to_embedded") public default boolean transferHostTouchGestureToEmbedded(@NonNull android.view.SurfaceControlViewHost.SurfacePackage);
}
@UiThread public static interface AttachedSurfaceControl.OnBufferTransformHintChangedListener {
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 6a5d07b..814be2f 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -261,6 +261,7 @@
field public static final String PROVIDE_RESOLVER_RANKER_SERVICE = "android.permission.PROVIDE_RESOLVER_RANKER_SERVICE";
field public static final String PROVIDE_TRUST_AGENT = "android.permission.PROVIDE_TRUST_AGENT";
field public static final String PROVISION_DEMO_DEVICE = "android.permission.PROVISION_DEMO_DEVICE";
+ field @FlaggedApi("android.content.pm.quarantined_enabled") public static final String QUARANTINE_APPS = "android.permission.QUARANTINE_APPS";
field public static final String QUERY_ADMIN_POLICY = "android.permission.QUERY_ADMIN_POLICY";
field public static final String QUERY_CLONED_APPS = "android.permission.QUERY_CLONED_APPS";
field @Deprecated public static final String QUERY_TIME_ZONE_RULES = "android.permission.QUERY_TIME_ZONE_RULES";
@@ -6750,7 +6751,7 @@
method public boolean setUidDeviceAffinity(int, @NonNull java.util.List<android.media.AudioDeviceInfo>);
method public boolean setUserIdDeviceAffinity(int, @NonNull java.util.List<android.media.AudioDeviceInfo>);
method public String toLogFriendlyString();
- method @FlaggedApi("com.android.media.audio.flags.audio_policy_update_mixing_rules_api") @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public int updateMixingRules(@NonNull java.util.List<android.util.Pair<android.media.audiopolicy.AudioMix,android.media.audiopolicy.AudioMixingRule>>);
+ method @FlaggedApi("android.media.audiopolicy.audio_policy_update_mixing_rules_api") @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public int updateMixingRules(@NonNull java.util.List<android.util.Pair<android.media.audiopolicy.AudioMix,android.media.audiopolicy.AudioMixingRule>>);
field public static final int FOCUS_POLICY_DUCKING_DEFAULT = 0; // 0x0
field public static final int FOCUS_POLICY_DUCKING_IN_APP = 0; // 0x0
field public static final int FOCUS_POLICY_DUCKING_IN_POLICY = 1; // 0x1
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index a3ebe6e..6643663 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -575,7 +575,6 @@
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwnerOnly(@NonNull android.content.ComponentName, int);
method public void setDeviceOwnerType(@NonNull android.content.ComponentName, int);
method @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS) public void setNextOperationSafety(int, int);
- method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void setOverrideKeepProfilesRunning(boolean);
method @RequiresPermission(anyOf={android.Manifest.permission.MARK_DEVICE_ORGANIZATION_OWNED, android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS}, conditional=true) public void setProfileOwnerOnOrganizationOwnedDevice(@NonNull android.content.ComponentName, boolean);
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean triggerDevicePolicyEngineMigration(boolean);
field public static final String ACTION_DATA_SHARING_RESTRICTION_APPLIED = "android.app.action.DATA_SHARING_RESTRICTION_APPLIED";
@@ -1802,8 +1801,8 @@
public class AudioManager {
method @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public int abandonAudioFocusForTest(@NonNull android.media.AudioFocusRequest, @NonNull String);
- method @FlaggedApi("com.android.media.audio.flags.focus_freeze_test_api") @RequiresPermission("Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED") public boolean enterAudioFocusFreezeForTest(@NonNull java.util.List<java.lang.Integer>);
- method @FlaggedApi("com.android.media.audio.flags.focus_freeze_test_api") @RequiresPermission("Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED") public boolean exitAudioFocusFreezeForTest();
+ method @FlaggedApi("android.media.audio.focus_freeze_test_api") @RequiresPermission("Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED") public boolean enterAudioFocusFreezeForTest(@NonNull java.util.List<java.lang.Integer>);
+ method @FlaggedApi("android.media.audio.focus_freeze_test_api") @RequiresPermission("Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED") public boolean exitAudioFocusFreezeForTest();
method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED) public void forceComputeCsdOnAllDevices(boolean);
method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED) public void forceUseFrameworkMel(boolean);
method @NonNull @RequiresPermission(android.Manifest.permission.CALL_AUDIO_INTERCEPTION) public android.media.AudioRecord getCallDownlinkExtractionAudioRecord(@NonNull android.media.AudioFormat);
@@ -1811,9 +1810,9 @@
method @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_SETTINGS_PRIVILEGED) public float getCsd();
method @Nullable public static android.media.AudioDeviceInfo getDeviceInfoFromType(int);
method @IntRange(from=0) @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public long getFadeOutDurationOnFocusLossMillis(@NonNull android.media.AudioAttributes);
- method @FlaggedApi("com.android.media.audio.flags.focus_freeze_test_api") @NonNull @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public java.util.List<java.lang.Integer> getFocusDuckedUidsForTest();
- method @FlaggedApi("com.android.media.audio.flags.focus_freeze_test_api") @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public long getFocusFadeOutDurationForTest();
- method @FlaggedApi("com.android.media.audio.flags.focus_freeze_test_api") @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public long getFocusUnmuteDelayAfterFadeOutForTest();
+ method @FlaggedApi("android.media.audio.focus_freeze_test_api") @NonNull @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public java.util.List<java.lang.Integer> getFocusDuckedUidsForTest();
+ method @FlaggedApi("android.media.audio.focus_freeze_test_api") @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public long getFocusFadeOutDurationForTest();
+ method @FlaggedApi("android.media.audio.focus_freeze_test_api") @RequiresPermission("android.permission.QUERY_AUDIO_STATE") public long getFocusUnmuteDelayAfterFadeOutForTest();
method @Nullable public static android.media.AudioHalVersionInfo getHalVersion();
method public static final int[] getPublicStreamTypes();
method @NonNull public java.util.List<java.lang.Integer> getReportedSurroundFormats();
@@ -1935,7 +1934,7 @@
field public static final int VIBRATION_SOURCE_URI = 2; // 0x2
}
- public static final class RingtoneSelection.Builder {
+ @FlaggedApi("android.os.vibrator.haptics_customization_enabled") public static final class RingtoneSelection.Builder {
ctor public RingtoneSelection.Builder();
ctor public RingtoneSelection.Builder(@NonNull android.media.RingtoneSelection);
method @NonNull public android.media.RingtoneSelection build();
@@ -3573,8 +3572,8 @@
method public default void holdLock(android.os.IBinder, int);
method public default boolean isGlobalKey(int);
method public default boolean isTaskSnapshotSupported();
- method @FlaggedApi("REPLACE_CONTENT_WITH_MIRROR") @RequiresPermission(android.Manifest.permission.ACCESS_SURFACE_FLINGER) public default boolean replaceContentOnDisplayWithMirror(int, @NonNull android.view.Window);
- method @FlaggedApi("REPLACE_CONTENT_WITH_MIRROR") @RequiresPermission(android.Manifest.permission.ACCESS_SURFACE_FLINGER) public default boolean replaceContentOnDisplayWithSc(int, @NonNull android.view.SurfaceControl);
+ method @RequiresPermission(android.Manifest.permission.ACCESS_SURFACE_FLINGER) public default boolean replaceContentOnDisplayWithMirror(int, @NonNull android.view.Window);
+ method @RequiresPermission(android.Manifest.permission.ACCESS_SURFACE_FLINGER) public default boolean replaceContentOnDisplayWithSc(int, @NonNull android.view.SurfaceControl);
method public default void setDisplayImePolicy(int, int);
method public default void setShouldShowSystemDecors(int, boolean);
method public default void setShouldShowWithInsecureKeyguard(int, boolean);
diff --git a/core/java/android/app/BackgroundStartPrivileges.java b/core/java/android/app/BackgroundStartPrivileges.java
index 76c0ccf..20278ea 100644
--- a/core/java/android/app/BackgroundStartPrivileges.java
+++ b/core/java/android/app/BackgroundStartPrivileges.java
@@ -174,6 +174,15 @@
@Override
public String toString() {
+ if (this == ALLOW_BAL) {
+ return "BSP.ALLOW_BAL";
+ }
+ if (this == ALLOW_FGS) {
+ return "BSP.ALLOW_FGS";
+ }
+ if (this == NONE) {
+ return "BSP.NONE";
+ }
return "BackgroundStartPrivileges["
+ "allowsBackgroundActivityStarts=" + mAllowsBackgroundActivityStarts
+ ", allowsBackgroundForegroundServiceStarts="
diff --git a/core/java/android/app/IActivityTaskManager.aidl b/core/java/android/app/IActivityTaskManager.aidl
index 2c428ef..1f8784b 100644
--- a/core/java/android/app/IActivityTaskManager.aidl
+++ b/core/java/android/app/IActivityTaskManager.aidl
@@ -259,12 +259,10 @@
* @param taskId the id of the task to retrieve the sAutoapshots for
* @param isLowResolution if set, if the snapshot needs to be loaded from disk, this will load
* a reduced resolution of it, which is much faster
- * @param takeSnapshotIfNeeded if set, call {@link #takeTaskSnapshot} to trigger the snapshot
- if no cache exists.
* @return a graphic buffer representing a screenshot of a task
*/
android.window.TaskSnapshot getTaskSnapshot(
- int taskId, boolean isLowResolution, boolean takeSnapshotIfNeeded);
+ int taskId, boolean isLowResolution);
/**
* Requests for a new snapshot to be taken for the task with the given id, storing it in the
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index a46c100..4c70c91 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -17048,23 +17048,6 @@
}
/**
- * Overrides the effective cached value of enable_keep_profiles_running for testing purposes.
- *
- * @hide
- */
- @TestApi
- @RequiresPermission(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
- public void setOverrideKeepProfilesRunning(boolean enabled) {
- if (mService != null) {
- try {
- mService.setOverrideKeepProfilesRunning(enabled);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- }
- }
- }
-
- /**
* Triggers the data migration of device policies for existing DPCs to the Device Policy Engine.
* If {@code forceMigration} is set to {@code true} it skips the prerequisite checks before
* triggering the migration.
diff --git a/core/java/android/app/admin/DevicePolicyManagerInternal.java b/core/java/android/app/admin/DevicePolicyManagerInternal.java
index 8dd50f0..304359b 100644
--- a/core/java/android/app/admin/DevicePolicyManagerInternal.java
+++ b/core/java/android/app/admin/DevicePolicyManagerInternal.java
@@ -312,21 +312,11 @@
int targetUserId);
/**
- * Returns whether new "turn off work" behavior is enabled via feature flag.
- */
- public abstract boolean isKeepProfilesRunningEnabled();
-
- /**
* True if either the entire device or the user is organization managed.
*/
public abstract boolean isUserOrganizationManaged(@UserIdInt int userId);
/**
- * Returns the list of packages suspended by admin on a given user.
- */
- public abstract Set<String> getPackagesSuspendedByAdmin(@UserIdInt int userId);
-
- /**
* Returns whether the application exemptions feature flag is enabled.
*/
public abstract boolean isApplicationExemptionsFlagEnabled();
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 58f9d57..6fe40be 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -603,8 +603,6 @@
DevicePolicyState getDevicePolicyState();
- void setOverrideKeepProfilesRunning(boolean enabled);
-
boolean triggerDevicePolicyEngineMigration(boolean forceMigration);
boolean isDeviceFinanced(String callerPackageName);
diff --git a/core/java/android/app/usage/IUsageStatsManager.aidl b/core/java/android/app/usage/IUsageStatsManager.aidl
index 49543a1..ebd5d64 100644
--- a/core/java/android/app/usage/IUsageStatsManager.aidl
+++ b/core/java/android/app/usage/IUsageStatsManager.aidl
@@ -20,10 +20,9 @@
import android.app.usage.BroadcastResponseStats;
import android.app.usage.BroadcastResponseStatsList;
import android.app.usage.UsageEvents;
+import android.app.usage.UsageEventsQuery;
import android.content.pm.ParceledListSlice;
-import java.util.Map;
-
/**
* System private API for talking with the UsageStatsManagerService.
*
@@ -42,6 +41,8 @@
UsageEvents queryEventsForPackage(long beginTime, long endTime, String callingPackage);
UsageEvents queryEventsForUser(long beginTime, long endTime, int userId, String callingPackage);
UsageEvents queryEventsForPackageForUser(long beginTime, long endTime, int userId, String pkg, String callingPackage);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)")
+ UsageEvents queryEventsWithFilter(in UsageEventsQuery query, String callingPackage);
@UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
void setAppInactive(String packageName, boolean inactive, int userId);
boolean isAppStandbyEnabled();
diff --git a/core/java/android/app/usage/UsageEvents.java b/core/java/android/app/usage/UsageEvents.java
index c188686..1eb452c 100644
--- a/core/java/android/app/usage/UsageEvents.java
+++ b/core/java/android/app/usage/UsageEvents.java
@@ -349,6 +349,47 @@
*/
public static final int MAX_EVENT_TYPE = 31;
+ /**
+ * Keep in sync with the event types defined above.
+ * @hide
+ */
+ @IntDef(flag = false, value = {
+ NONE,
+ ACTIVITY_RESUMED,
+ ACTIVITY_PAUSED,
+ END_OF_DAY,
+ CONTINUE_PREVIOUS_DAY,
+ CONFIGURATION_CHANGE,
+ SYSTEM_INTERACTION,
+ USER_INTERACTION,
+ SHORTCUT_INVOCATION,
+ CHOOSER_ACTION,
+ NOTIFICATION_SEEN,
+ STANDBY_BUCKET_CHANGED,
+ NOTIFICATION_INTERRUPTION,
+ SLICE_PINNED_PRIV,
+ SLICE_PINNED,
+ SCREEN_INTERACTIVE,
+ SCREEN_NON_INTERACTIVE,
+ KEYGUARD_SHOWN,
+ KEYGUARD_HIDDEN,
+ FOREGROUND_SERVICE_START,
+ FOREGROUND_SERVICE_STOP,
+ CONTINUING_FOREGROUND_SERVICE,
+ ROLLOVER_FOREGROUND_SERVICE,
+ ACTIVITY_STOPPED,
+ ACTIVITY_DESTROYED,
+ FLUSH_TO_DISK,
+ DEVICE_SHUTDOWN,
+ DEVICE_STARTUP,
+ USER_UNLOCKED,
+ USER_STOPPED,
+ LOCUS_ID_SET,
+ APP_COMPONENT_USED,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface EventType {}
+
/** @hide */
public static final int FLAG_IS_PACKAGE_INSTANT_APP = 1 << 0;
diff --git a/core/java/android/app/usage/UsageEventsQuery.aidl b/core/java/android/app/usage/UsageEventsQuery.aidl
new file mode 100644
index 0000000..5ed370d
--- /dev/null
+++ b/core/java/android/app/usage/UsageEventsQuery.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.app.usage;
+
+parcelable UsageEventsQuery;
\ No newline at end of file
diff --git a/core/java/android/app/usage/UsageEventsQuery.java b/core/java/android/app/usage/UsageEventsQuery.java
new file mode 100644
index 0000000..8c63d18
--- /dev/null
+++ b/core/java/android/app/usage/UsageEventsQuery.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.app.usage;
+
+import android.annotation.CurrentTimeMillisLong;
+import android.annotation.FlaggedApi;
+import android.annotation.NonNull;
+import android.app.usage.UsageEvents.Event;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.ArraySet;
+
+import com.android.internal.util.ArrayUtils;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * An Object-Oriented representation for a {@link UsageEvents} query.
+ * Used by {@link UsageStatsManager#queryEvents(UsageEventsQuery)} call.
+ */
+@FlaggedApi(Flags.FLAG_FILTER_BASED_EVENT_QUERY_API)
+public final class UsageEventsQuery implements Parcelable {
+ private final @CurrentTimeMillisLong long mBeginTimeMillis;
+ private final @CurrentTimeMillisLong long mEndTimeMillis;
+ private final @Event.EventType int[] mEventTypes;
+
+ private UsageEventsQuery(@NonNull Builder builder) {
+ mBeginTimeMillis = builder.mBeginTimeMillis;
+ mEndTimeMillis = builder.mEndTimeMillis;
+ mEventTypes = ArrayUtils.convertToIntArray(builder.mEventTypes);
+ }
+
+ private UsageEventsQuery(Parcel in) {
+ mBeginTimeMillis = in.readLong();
+ mEndTimeMillis = in.readLong();
+ int eventTypesLength = in.readInt();
+ mEventTypes = new int[eventTypesLength];
+ in.readIntArray(mEventTypes);
+ }
+
+ /**
+ * Returns the inclusive timestamp to indicate the beginning of the range of events.
+ * Defined in terms of "Unix time", see {@link java.lang.System#currentTimeMillis}.
+ */
+ public @CurrentTimeMillisLong long getBeginTimeMillis() {
+ return mBeginTimeMillis;
+ }
+
+ /**
+ * Returns the exclusive timpstamp to indicate the end of the range of events.
+ * Defined in terms of "Unix time", see {@link java.lang.System#currentTimeMillis}.
+ */
+ public @CurrentTimeMillisLong long getEndTimeMillis() {
+ return mEndTimeMillis;
+ }
+
+ /**
+ * Returns the set of usage event types for the query.
+ * <em>Note: An empty set indicates query for all usage events. </em>
+ */
+ public @NonNull Set<Integer> getEventTypes() {
+ if (ArrayUtils.isEmpty(mEventTypes)) {
+ return Collections.emptySet();
+ }
+
+ HashSet<Integer> eventTypeSet = new HashSet<>();
+ for (int eventType : mEventTypes) {
+ eventTypeSet.add(eventType);
+ }
+ return eventTypeSet;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeLong(mBeginTimeMillis);
+ dest.writeLong(mEndTimeMillis);
+ dest.writeInt(mEventTypes.length);
+ dest.writeIntArray(mEventTypes);
+ }
+
+ @NonNull
+ public static final Creator<UsageEventsQuery> CREATOR =
+ new Creator<UsageEventsQuery>() {
+ @Override
+ public UsageEventsQuery createFromParcel(Parcel in) {
+ return new UsageEventsQuery(in);
+ }
+
+ @Override
+ public UsageEventsQuery[] newArray(int size) {
+ return new UsageEventsQuery[size];
+ }
+ };
+
+ /** @hide */
+ public int[] getEventTypeFilter() {
+ return Arrays.copyOf(mEventTypes, mEventTypes.length);
+ }
+
+ /**
+ * Builder for UsageEventsQuery.
+ */
+ public static final class Builder {
+ private final @CurrentTimeMillisLong long mBeginTimeMillis;
+ private final @CurrentTimeMillisLong long mEndTimeMillis;
+ private final ArraySet<Integer> mEventTypes = new ArraySet<>();
+
+ /**
+ * Constructor that specifies the period for which to return events.
+ * @param beginTimeMillis Inclusive beginning timestamp, as per
+ * {@link java.lang.System#currentTimeMillis()}
+ * @param endTimeMillis Exclusive ending timestamp, as per
+ * {@link java.lang.System#currentTimeMillis()}
+ *
+ * @throws IllegalArgumentException if {@code beginTimeMillis} <
+ * {@code endTimeMillis}
+ */
+ public Builder(@CurrentTimeMillisLong long beginTimeMillis,
+ @CurrentTimeMillisLong long endTimeMillis) {
+ if (beginTimeMillis < 0 || endTimeMillis < beginTimeMillis) {
+ throw new IllegalArgumentException("Invalid period");
+ }
+ mBeginTimeMillis = beginTimeMillis;
+ mEndTimeMillis = endTimeMillis;
+ }
+
+ /**
+ * Builds a read-only UsageEventsQuery object.
+ */
+ public @NonNull UsageEventsQuery build() {
+ return new UsageEventsQuery(this);
+ }
+
+ /**
+ * Specifies the list of usage event types to be included in the query.
+ * @param eventTypes List of the usage event types. See {@link UsageEvents.Event}
+ *
+ * @throws llegalArgumentException if the event type is not valid.
+ */
+ public @NonNull Builder addEventTypes(@NonNull @Event.EventType int... eventTypes) {
+ for (int i = 0; i < eventTypes.length; i++) {
+ final int eventType = eventTypes[i];
+ if (eventType < Event.NONE || eventType > Event.MAX_EVENT_TYPE) {
+ throw new IllegalArgumentException("Invalid usage event type: " + eventType);
+ }
+ mEventTypes.add(eventType);
+ }
+ return this;
+ }
+ }
+}
diff --git a/core/java/android/app/usage/UsageStatsManager.java b/core/java/android/app/usage/UsageStatsManager.java
index 2a10ed1..4f1c993 100644
--- a/core/java/android/app/usage/UsageStatsManager.java
+++ b/core/java/android/app/usage/UsageStatsManager.java
@@ -18,6 +18,7 @@
import android.Manifest;
import android.annotation.CurrentTimeMillisLong;
+import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
@@ -581,6 +582,29 @@
}
/**
+ * Query for events with specific UsageEventsQuery object.
+ * <em>Note: if the user's device is not in an unlocked state (as defined by
+ * {@link UserManager#isUserUnlocked()}), then {@code null} will be returned.</em>
+ *
+ * @param query The query object used to specify the query parameters.
+ * @return A {@link UsageEvents}.
+ */
+ @FlaggedApi(Flags.FLAG_FILTER_BASED_EVENT_QUERY_API)
+ @NonNull
+ @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS)
+ public UsageEvents queryEvents(@NonNull UsageEventsQuery query) {
+ try {
+ UsageEvents iter = mService.queryEventsWithFilter(query, mContext.getOpPackageName());
+ if (iter != null) {
+ return iter;
+ }
+ } catch (RemoteException e) {
+ // fallthrough and return empty result.
+ }
+ return sEmptyResults;
+ }
+
+ /**
* Like {@link #queryEvents(long, long)}, but only returns events for the calling package.
* <em>Note: Starting from {@link android.os.Build.VERSION_CODES#R Android R}, if the user's
* device is not in an unlocked state (as defined by {@link UserManager#isUserUnlocked()}),
diff --git a/core/java/android/app/usage/flags.aconfig b/core/java/android/app/usage/flags.aconfig
index 0b8e29f..a611255 100644
--- a/core/java/android/app/usage/flags.aconfig
+++ b/core/java/android/app/usage/flags.aconfig
@@ -28,3 +28,10 @@
description: "Flag for parcelable usage event list"
bug: "301254110"
}
+
+flag {
+ name: "filter_based_event_query_api"
+ namespace: "backstage_power"
+ description: " Feature flag to support filter based event query API"
+ bug: "194321117"
+}
diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java
index a3b836a..d4688f8 100644
--- a/core/java/android/os/RecoverySystem.java
+++ b/core/java/android/os/RecoverySystem.java
@@ -933,6 +933,12 @@
rebootWipeUserData(context, shutdown, reason, force, false /* wipeEuicc */);
}
+ /** {@hide} */
+ public static void rebootWipeUserData(Context context, boolean shutdown, String reason,
+ boolean force, boolean wipeEuicc) throws IOException {
+ rebootWipeUserData(context, shutdown, reason, force, wipeEuicc, false /* keepMemtagMode */);
+ }
+
/**
* Reboots the device and wipes the user data and cache
* partitions. This is sometimes called a "factory reset", which
@@ -948,6 +954,7 @@
* @param force whether the {@link UserManager.DISALLOW_FACTORY_RESET} user restriction
* should be ignored
* @param wipeEuicc whether wipe the euicc data
+ * @param keepMemtagMode whether to tell recovery to keep currently configured memtag mode
*
* @throws IOException if writing the recovery command file
* fails, or if the reboot itself fails.
@@ -956,7 +963,7 @@
* @hide
*/
public static void rebootWipeUserData(Context context, boolean shutdown, String reason,
- boolean force, boolean wipeEuicc) throws IOException {
+ boolean force, boolean wipeEuicc, boolean keepMemtagMode) throws IOException {
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
if (!force && um.hasUserRestriction(UserManager.DISALLOW_FACTORY_RESET)) {
throw new SecurityException("Wiping data is not allowed for this user.");
@@ -996,8 +1003,13 @@
reasonArg = "--reason=" + sanitizeArg(reason + "," + timeStamp);
}
+ String memtagArg = null;
+ if (keepMemtagMode) {
+ memtagArg = "--keep_memtag_mode";
+ }
+
final String localeArg = "--locale=" + Locale.getDefault().toLanguageTag() ;
- bootCommand(context, shutdownArg, "--wipe_data", reasonArg, localeArg);
+ bootCommand(context, shutdownArg, "--wipe_data", reasonArg, localeArg, memtagArg);
}
/**
diff --git a/core/java/android/service/notification/flags.aconfig b/core/java/android/service/notification/flags.aconfig
index 52d4d47..2a05c84 100644
--- a/core/java/android/service/notification/flags.aconfig
+++ b/core/java/android/service/notification/flags.aconfig
@@ -4,7 +4,7 @@
name: "ranking_update_ashmem"
namespace: "systemui"
description: "This flag controls moving ranking update contents into ashmem"
- bug: "284297289"
+ bug: "249848655"
}
flag {
diff --git a/core/java/android/speech/tts/BlockingAudioTrack.java b/core/java/android/speech/tts/BlockingAudioTrack.java
index be5851c..d84cc2c 100644
--- a/core/java/android/speech/tts/BlockingAudioTrack.java
+++ b/core/java/android/speech/tts/BlockingAudioTrack.java
@@ -194,17 +194,22 @@
audioTrack.play();
}
- int count = 0;
- while (count < bytes.length) {
- // Note that we don't take bufferCopy.mOffset into account because
- // it is guaranteed to be 0.
- int written = audioTrack.write(bytes, count, bytes.length);
+ int offset = 0;
+ while (offset < bytes.length) {
+ // Although it requests to write the entire bytes at once, it might fail when the track
+ // got stopped or the thread is interrupted. In that case, it needs to carry on from
+ // last offset.
+ int sizeToWrite = bytes.length - offset;
+ int written = audioTrack.write(bytes, offset, sizeToWrite);
if (written <= 0) {
+ if (written < 0) {
+ Log.e(TAG, "An error occurred while writing to audio track: " + written);
+ }
break;
}
- count += written;
+ offset += written;
}
- return count;
+ return offset;
}
private AudioTrack createStreamingAudioTrack() {
diff --git a/core/java/android/view/AttachedSurfaceControl.java b/core/java/android/view/AttachedSurfaceControl.java
index d545751..fd5517d 100644
--- a/core/java/android/view/AttachedSurfaceControl.java
+++ b/core/java/android/view/AttachedSurfaceControl.java
@@ -231,4 +231,19 @@
default void removeTrustedPresentationCallback(@NonNull SurfaceControl.Transaction t,
@NonNull Consumer<Boolean> listener) {
}
+
+ /**
+ * Transfer the currently in progress touch gesture from the host to the requested
+ * {@link SurfaceControlViewHost.SurfacePackage}. This requires that the
+ * SurfaceControlViewHost was created with the current host's inputToken.
+ *
+ * @param surfacePackage The SurfacePackage to transfer the gesture to.
+ * @return Whether the touch stream was transferred.
+ */
+ @FlaggedApi(Flags.FLAG_TRANSFER_GESTURE_TO_EMBEDDED)
+ default boolean transferHostTouchGestureToEmbedded(
+ @NonNull SurfaceControlViewHost.SurfacePackage surfacePackage) {
+ throw new UnsupportedOperationException(
+ "transferHostTouchGestureToEmbedded is unimplemented");
+ }
}
diff --git a/core/java/android/view/IWindowSession.aidl b/core/java/android/view/IWindowSession.aidl
index 7acf2f8..02e97da 100644
--- a/core/java/android/view/IWindowSession.aidl
+++ b/core/java/android/view/IWindowSession.aidl
@@ -357,4 +357,6 @@
boolean cancelDraw(IWindow window);
boolean transferEmbeddedTouchFocusToHost(IWindow embeddedWindow);
+
+ boolean transferHostTouchGestureToEmbedded(IWindow hostWindow, IBinder transferTouchToken);
}
diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java
index 57b19a8..4056531 100644
--- a/core/java/android/view/SurfaceControlViewHost.java
+++ b/core/java/android/view/SurfaceControlViewHost.java
@@ -287,7 +287,8 @@
}
/**
- * Returns an input token used which can be used to request focus on the embedded surface.
+ * Returns an input token used which can be used to request focus on the embedded surface
+ * or to transfer touch gesture to the embedded surface.
*
* @hide
*/
@@ -526,7 +527,8 @@
}
/**
- * Returns an input token used which can be used to request focus on the embedded surface.
+ * Returns an input token used which can be used to request focus on the embedded surface
+ * or to transfer touch gesture to the embedded surface.
*
* @hide
*/
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 2422369..1ee303c 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -11893,4 +11893,17 @@
}
Log.d(mTag, msg);
}
+
+ @Override
+ public boolean transferHostTouchGestureToEmbedded(
+ @NonNull SurfaceControlViewHost.SurfacePackage surfacePackage) {
+ final IWindowSession realWm = WindowManagerGlobal.getWindowSession();
+ try {
+ return realWm.transferHostTouchGestureToEmbedded(mWindow,
+ surfacePackage.getInputToken());
+ } catch (RemoteException e) {
+ e.rethrowAsRuntimeException();
+ }
+ return false;
+ }
}
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 4f03ce9..cfec081 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -90,6 +90,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
+import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
@@ -5872,7 +5873,7 @@
*
* @hide
*/
- @FlaggedApi("REPLACE_CONTENT_WITH_MIRROR")
+ @SuppressLint("UnflaggedApi") // The API is only used for tests.
@TestApi
@RequiresPermission(permission.ACCESS_SURFACE_FLINGER)
default boolean replaceContentOnDisplayWithMirror(int displayId, @NonNull Window window) {
@@ -5888,7 +5889,7 @@
*
* @hide
*/
- @FlaggedApi("REPLACE_CONTENT_WITH_MIRROR")
+ @SuppressLint("UnflaggedApi") // The API is only used for tests.
@TestApi
@RequiresPermission(permission.ACCESS_SURFACE_FLINGER)
default boolean replaceContentOnDisplayWithSc(int displayId, @NonNull SurfaceControl sc) {
diff --git a/core/java/android/view/WindowlessWindowManager.java b/core/java/android/view/WindowlessWindowManager.java
index 7c3b6ae..652fe24 100644
--- a/core/java/android/view/WindowlessWindowManager.java
+++ b/core/java/android/view/WindowlessWindowManager.java
@@ -656,6 +656,14 @@
return false;
}
+ @Override
+ public boolean transferHostTouchGestureToEmbedded(IWindow hostWindow,
+ IBinder embeddedInputToken) {
+ Log.e(TAG, "Received request to transferHostTouchGestureToEmbedded on"
+ + " WindowlessWindowManager. We shouldn't get here!");
+ return false;
+ }
+
void setParentInterface(@Nullable ISurfaceControlViewHostParent parentInterface) {
IBinder oldInterface = mParentInterface == null ? null : mParentInterface.asBinder();
IBinder newInterface = parentInterface == null ? null : parentInterface.asBinder();
diff --git a/core/java/android/window/flags/window_surfaces.aconfig b/core/java/android/window/flags/window_surfaces.aconfig
index 5ad5c79..68eddff 100644
--- a/core/java/android/window/flags/window_surfaces.aconfig
+++ b/core/java/android/window/flags/window_surfaces.aconfig
@@ -25,3 +25,10 @@
is_fixed_read_only: true
bug: "304508760"
}
+
+flag {
+ namespace: "window_surfaces"
+ name: "transfer_gesture_to_embedded"
+ description: "Enable public API for Window Surfaces"
+ bug: "287076178"
+}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index c75f996..ec302e7 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -2358,6 +2358,15 @@
<permission android:name="android.permission.SUSPEND_APPS"
android:protectionLevel="signature|role" />
+ <!-- @SystemApi
+ @hide
+ @FlaggedApi("android.content.pm.quarantined_enabled")
+ Allows an application to quarantine other apps, which will prevent
+ them from running without explicit user action.
+ -->
+ <permission android:name="android.permission.QUARANTINE_APPS"
+ android:protectionLevel="internal|verifier" />
+
<!-- Allows applications to discover and pair bluetooth devices.
<p>Protection level: normal
-->
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index dbce054..862e537 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -4177,6 +4177,10 @@
<!-- Inactivity threshold (in milliseconds) used in JobScheduler. JobScheduler will consider
the device to be "idle" after being inactive for this long. -->
<integer name="config_jobSchedulerInactivityIdleThreshold">1860000</integer>
+ <!-- Inactivity threshold (in milliseconds) used in JobScheduler. JobScheduler will consider
+ the device to be "idle" after being inactive for this long if the device is on stable
+ power. Stable power is defined as "charging + battery not low". -->
+ <integer name="config_jobSchedulerInactivityIdleThresholdOnStablePower">1860000</integer>
<!-- The alarm window (in milliseconds) that JobScheduler uses to enter the idle state -->
<integer name="config_jobSchedulerIdleWindowSlop">300000</integer>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index a2f0086..e646548 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2882,6 +2882,7 @@
<java-symbol type="integer" name="config_defaultNightMode" />
<java-symbol type="integer" name="config_jobSchedulerInactivityIdleThreshold" />
+ <java-symbol type="integer" name="config_jobSchedulerInactivityIdleThresholdOnStablePower" />
<java-symbol type="integer" name="config_jobSchedulerIdleWindowSlop" />
<java-symbol type="bool" name="config_jobSchedulerRestrictBackgroundUser" />
<java-symbol type="integer" name="config_jobSchedulerUserGracePeriod" />
diff --git a/core/tests/coretests/src/android/app/usage/UsageEventsQueryTest.java b/core/tests/coretests/src/android/app/usage/UsageEventsQueryTest.java
new file mode 100644
index 0000000..839b645
--- /dev/null
+++ b/core/tests/coretests/src/android/app/usage/UsageEventsQueryTest.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.app.usage;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import android.app.usage.UsageEvents.Event;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Random;
+import java.util.Set;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class UsageEventsQueryTest {
+ @Test
+ public void testQueryDuration() {
+ // Test with negative beginTimeMillis.
+ long beginTimeMillis = -100;
+ long endTimeMillis = 100;
+ try {
+ UsageEventsQuery query = new UsageEventsQuery.Builder(beginTimeMillis, endTimeMillis)
+ .build();
+ fail("beginTimeMillis should be a non-negative timestamp measured as the number of"
+ + " milliseconds since 1970-01-01T00:00:00Z.");
+ } catch (IllegalArgumentException e) {
+ // Expected, fall through;
+ }
+
+ // Test with negative endTimeMillis.
+ beginTimeMillis = 1001;
+ endTimeMillis = -1;
+ try {
+ UsageEventsQuery query = new UsageEventsQuery.Builder(beginTimeMillis, endTimeMillis)
+ .build();
+ fail("endTimeMillis should be a non-negative timestamp measured as the number of"
+ + " milliseconds since 1970-01-01T00:00:00Z.");
+ } catch (IllegalArgumentException e) {
+ // Expected, fall through;
+ }
+
+ // Test with beginTimeMillis < endTimeMillis;
+ beginTimeMillis = 2001;
+ endTimeMillis = 1000;
+ try {
+ UsageEventsQuery query = new UsageEventsQuery.Builder(beginTimeMillis, endTimeMillis)
+ .build();
+ fail("beginTimeMillis should be smaller than endTimeMillis");
+ } catch (IllegalArgumentException e) {
+ // Expected, fall through;
+ }
+
+ // Test with beginTimeMillis == endTimeMillis, valid.
+ beginTimeMillis = 1001;
+ endTimeMillis = 1001;
+ try {
+ UsageEventsQuery query = new UsageEventsQuery.Builder(beginTimeMillis, endTimeMillis)
+ .build();
+ assertEquals(query.getBeginTimeMillis(), query.getEndTimeMillis());
+ } catch (IllegalArgumentException e) {
+ // Not expected for valid duration.
+ fail("Valid duration for beginTimeMillis=" + beginTimeMillis
+ + ", endTimeMillis=" + endTimeMillis);
+ }
+
+ beginTimeMillis = 2001;
+ endTimeMillis = 3001;
+ try {
+ UsageEventsQuery query = new UsageEventsQuery.Builder(beginTimeMillis, endTimeMillis)
+ .build();
+ assertEquals(query.getBeginTimeMillis(), 2001);
+ assertEquals(query.getEndTimeMillis(), 3001);
+ } catch (IllegalArgumentException e) {
+ // Not expected for valid duration.
+ fail("Valid duration for beginTimeMillis=" + beginTimeMillis
+ + ", endTimeMillis=" + endTimeMillis);
+ }
+ }
+
+ @Test
+ public void testQueryEventTypes() {
+ Random rnd = new Random();
+ UsageEventsQuery.Builder queryBuilder = new UsageEventsQuery.Builder(1000, 2000);
+
+ // Test with invalid event type.
+ int eventType = Event.NONE - 1;
+ try {
+ queryBuilder.addEventTypes(eventType);
+ fail("Invalid event type: " + eventType);
+ } catch (IllegalArgumentException e) {
+ // Expected, fall through.
+ }
+
+ eventType = Event.MAX_EVENT_TYPE + 1;
+ try {
+ queryBuilder.addEventTypes(eventType);
+ fail("Invalid event type: " + eventType);
+ } catch (IllegalArgumentException e) {
+ // Expected, fall through.
+ }
+
+ // Test with valid and duplicate event types.
+ eventType = rnd.nextInt(Event.MAX_EVENT_TYPE + 1);
+ try {
+ UsageEventsQuery query = queryBuilder.addEventTypes(eventType, eventType, eventType)
+ .build();
+ Set<Integer> eventTypeSet = query.getEventTypes();
+ assertEquals(eventTypeSet.size(), 1);
+ int type = eventTypeSet.iterator().next();
+ assertEquals(type, eventType);
+ } catch (IllegalArgumentException e) {
+ fail("Valid event type: " + eventType);
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
index 84feb03..108aa82 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipUtils.kt
@@ -129,9 +129,7 @@
@JvmStatic
fun getTaskSnapshot(taskId: Int, isLowResolution: Boolean): TaskSnapshot? {
return if (taskId <= 0) null else try {
- ActivityTaskManager.getService().getTaskSnapshot(
- taskId, isLowResolution, false /* takeSnapshotIfNeeded */
- )
+ ActivityTaskManager.getService().getTaskSnapshot(taskId, isLowResolution)
} catch (e: RemoteException) {
Log.e(TAG, "Failed to get task snapshot, taskId=$taskId", e)
null
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeFocusedWindowDecorationViewHolder.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeFocusedWindowDecorationViewHolder.kt
index 9dc86db..b1fb0f1 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeFocusedWindowDecorationViewHolder.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeFocusedWindowDecorationViewHolder.kt
@@ -42,11 +42,11 @@
}
override fun onHandleMenuOpened() {
- animateCaptionHandleAlpha(startValue = 0f, endValue = 1f)
+ animateCaptionHandleAlpha(startValue = 1f, endValue = 0f)
}
override fun onHandleMenuClosed() {
- animateCaptionHandleAlpha(startValue = 1f, endValue = 0f)
+ animateCaptionHandleAlpha(startValue = 0f, endValue = 1f)
}
private fun getCaptionHandleBarColor(taskInfo: RunningTaskInfo): Int {
diff --git a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/apps/AppsEnterPipTransition.kt b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/apps/AppsEnterPipTransition.kt
index be5a27a..bd8b005 100644
--- a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/apps/AppsEnterPipTransition.kt
+++ b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/apps/AppsEnterPipTransition.kt
@@ -20,6 +20,8 @@
import android.tools.common.Rotation
import android.tools.common.traces.component.ComponentNameMatcher
import android.tools.device.apphelpers.StandardAppHelper
+import android.tools.device.flicker.junit.FlickerBuilderProvider
+import android.tools.device.flicker.legacy.FlickerBuilder
import android.tools.device.flicker.legacy.LegacyFlickerTest
import android.tools.device.flicker.legacy.LegacyFlickerTestFactory
import com.android.wm.shell.flicker.pip.common.EnterPipTransition
@@ -29,6 +31,15 @@
abstract class AppsEnterPipTransition(flicker: LegacyFlickerTest) : EnterPipTransition(flicker) {
protected abstract val standardAppHelper: StandardAppHelper
+ @FlickerBuilderProvider
+ override fun buildFlicker(): FlickerBuilder {
+ return FlickerBuilder(instrumentation).apply {
+ withoutScreenRecorder()
+ setup { flicker.scenario.setIsTablet(tapl.isTablet) }
+ transition()
+ }
+ }
+
/** Checks [standardAppHelper] window remains visible throughout the animation */
@Postsubmit
@Test
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/BaseBenchmarkTest.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/BaseBenchmarkTest.kt
index 0f3e0f5..e9363f7 100644
--- a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/BaseBenchmarkTest.kt
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/BaseBenchmarkTest.kt
@@ -38,7 +38,7 @@
* executions
*/
@FlickerBuilderProvider
- fun buildFlicker(): FlickerBuilder {
+ open fun buildFlicker(): FlickerBuilder {
return FlickerBuilder(instrumentation).apply {
setup { flicker.scenario.setIsTablet(tapl.isTablet) }
transition()
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/SplitScreenUtils.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/SplitScreenUtils.kt
index c31b9e2..3244ebc 100644
--- a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/SplitScreenUtils.kt
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/utils/SplitScreenUtils.kt
@@ -135,19 +135,29 @@
// second task to split.
val home = tapl.workspace.switchToOverview()
ChangeDisplayOrientationRule.setRotation(rotation)
- home.overviewActions.clickSplit()
+ val isGridOnlyOverviewEnabled = tapl.isGridOnlyOverviewEnabled
+ if (isGridOnlyOverviewEnabled) {
+ home.currentTask.tapMenu().tapSplitMenuItem()
+ } else {
+ home.overviewActions.clickSplit()
+ }
val snapshots = device.wait(Until.findObjects(overviewSnapshotSelector), TIMEOUT_MS)
if (snapshots == null || snapshots.size < 1) {
error("Fail to find a overview snapshot to split.")
}
- // Find the second task in the upper right corner in split select mode by sorting
- // 'left' in descending order and 'top' in ascending order.
+ // Find the second task in the upper (or bottom for grid only Overview) right corner in
+ // split select mode by sorting 'left' in descending order and 'top' in ascending (or
+ // descending for grid only Overview) order.
snapshots.sortWith { t1: UiObject2, t2: UiObject2 ->
t2.getVisibleBounds().left - t1.getVisibleBounds().left
}
snapshots.sortWith { t1: UiObject2, t2: UiObject2 ->
- t1.getVisibleBounds().top - t2.getVisibleBounds().top
+ if (isGridOnlyOverviewEnabled) {
+ t2.getVisibleBounds().top - t1.getVisibleBounds().top
+ } else {
+ t1.getVisibleBounds().top - t2.getVisibleBounds().top
+ }
}
snapshots[0].click()
} else {
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index eea6357..5d211f4 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -20,8 +20,8 @@
import static android.companion.virtual.VirtualDeviceParams.POLICY_TYPE_AUDIO;
import static android.content.Context.DEVICE_ID_DEFAULT;
-import static com.android.media.audio.flags.Flags.autoPublicVolumeApiHardening;
-import static com.android.media.audio.flags.Flags.FLAG_FOCUS_FREEZE_TEST_API;
+import static android.media.audio.Flags.autoPublicVolumeApiHardening;
+import static android.media.audio.Flags.FLAG_FOCUS_FREEZE_TEST_API;
import android.Manifest;
import android.annotation.CallbackExecutor;
@@ -686,6 +686,7 @@
FLAG_ABSOLUTE_VOLUME,
})
@Retention(RetentionPolicy.SOURCE)
+ // TODO(308698465) remove due to potential conflict with the new flags class
public @interface Flags {}
/**
diff --git a/media/java/android/media/RingtoneSelection.java b/media/java/android/media/RingtoneSelection.java
index b74b6a3..b7c3721 100644
--- a/media/java/android/media/RingtoneSelection.java
+++ b/media/java/android/media/RingtoneSelection.java
@@ -642,6 +642,7 @@
* allowing the user to configure their selection. Once a selection is stored as a Uri, then
* the RingtoneSelection can be loaded directly using {@link RingtoneSelection#fromUri}.
*/
+ @FlaggedApi(Flags.FLAG_HAPTICS_CUSTOMIZATION_ENABLED)
public static final class Builder {
private Uri mSoundUri;
private Uri mVibrationUri;
diff --git a/media/java/android/media/audiopolicy/AudioPolicy.java b/media/java/android/media/audiopolicy/AudioPolicy.java
index 9ced2a4..e168498 100644
--- a/media/java/android/media/audiopolicy/AudioPolicy.java
+++ b/media/java/android/media/audiopolicy/AudioPolicy.java
@@ -49,7 +49,6 @@
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
-import com.android.media.audio.flags.Flags;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/media/java/android/media/midi/MidiUmpDeviceService.java b/media/java/android/media/midi/MidiUmpDeviceService.java
index c54bfce..bbbef47 100644
--- a/media/java/android/media/midi/MidiUmpDeviceService.java
+++ b/media/java/android/media/midi/MidiUmpDeviceService.java
@@ -16,8 +16,6 @@
package android.media.midi;
-import static com.android.media.midi.flags.Flags.FLAG_VIRTUAL_UMP;
-
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -57,11 +55,11 @@
* android:resource="@xml/device_info" />
* </service></pre>
*/
-@FlaggedApi(FLAG_VIRTUAL_UMP)
+@FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
public abstract class MidiUmpDeviceService extends Service {
private static final String TAG = "MidiUmpDeviceService";
- @FlaggedApi(FLAG_VIRTUAL_UMP)
+ @FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
public static final String SERVICE_INTERFACE = "android.media.midi.MidiUmpDeviceService";
private IMidiManager mMidiManager;
@@ -80,7 +78,7 @@
}
};
- @FlaggedApi(FLAG_VIRTUAL_UMP)
+ @FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
@Override
public void onCreate() {
mMidiManager = IMidiManager.Stub.asInterface(
@@ -118,7 +116,7 @@
* The number of input and output ports must be equal and non-zero.
* @return list of MidiReceivers
*/
- @FlaggedApi(FLAG_VIRTUAL_UMP)
+ @FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
public abstract @NonNull List<MidiReceiver> onGetInputPortReceivers();
/**
@@ -127,7 +125,7 @@
* The number of input and output ports must be equal and non-zero.
* @return the list of MidiReceivers
*/
- @FlaggedApi(FLAG_VIRTUAL_UMP)
+ @FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
public final @NonNull List<MidiReceiver> getOutputPortReceivers() {
if (mServer == null) {
return new ArrayList<MidiReceiver>();
@@ -140,7 +138,7 @@
* Returns the {@link MidiDeviceInfo} instance for this service
* @return the MidiDeviceInfo of the virtual MIDI device if it was successfully created
*/
- @FlaggedApi(FLAG_VIRTUAL_UMP)
+ @FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
public final @Nullable MidiDeviceInfo getDeviceInfo() {
return mDeviceInfo;
}
@@ -149,7 +147,7 @@
* Called to notify when the {@link MidiDeviceStatus} has changed
* @param status the current status of the MIDI device
*/
- @FlaggedApi(FLAG_VIRTUAL_UMP)
+ @FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
public void onDeviceStatusChanged(@NonNull MidiDeviceStatus status) {
}
@@ -157,11 +155,11 @@
* Called to notify when the virtual MIDI device running in this service has been closed by
* all its clients
*/
- @FlaggedApi(FLAG_VIRTUAL_UMP)
+ @FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
public void onClose() {
}
- @FlaggedApi(FLAG_VIRTUAL_UMP)
+ @FlaggedApi(Flags.FLAG_VIRTUAL_UMP)
@Override
public @Nullable IBinder onBind(@NonNull Intent intent) {
if (SERVICE_INTERFACE.equals(intent.getAction()) && mServer != null) {
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/ArgumentPageModel.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/ArgumentPageModel.kt
index 5d6aa03..d763f77 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/ArgumentPageModel.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/ArgumentPageModel.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
import com.android.settingslib.spa.framework.common.PageModel
import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
import com.android.settingslib.spa.framework.compose.navigator
-import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.framework.util.getIntArg
import com.android.settingslib.spa.framework.util.getStringArg
import com.android.settingslib.spa.framework.util.navLink
@@ -110,7 +109,7 @@
fun genStringParamPreferenceModel(): PreferenceModel {
return object : PreferenceModel {
override val title = STRING_PARAM_TITLE
- override val summary = stateOf(stringParam!!)
+ override val summary = { stringParam!! }
}
}
@@ -118,7 +117,7 @@
fun genIntParamPreferenceModel(): PreferenceModel {
return object : PreferenceModel {
override val title = INT_PARAM_TITLE
- override val summary = stateOf(intParam!!.toString())
+ override val summary = { intParam!!.toString() }
}
}
@@ -130,7 +129,7 @@
)
return object : PreferenceModel {
override val title = PAGE_TITLE
- override val summary = stateOf(summaryArray.joinToString(", "))
+ override val summary = { summaryArray.joinToString(", ") }
override val onClick = navigator(
SettingsPageProviderEnum.ARGUMENT.name + parameter.navLink(arguments)
)
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/FooterPageProvider.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/FooterPageProvider.kt
index 50c0eb7..345b47a 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/FooterPageProvider.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/FooterPageProvider.kt
@@ -26,7 +26,6 @@
import com.android.settingslib.spa.framework.common.SettingsPageProvider
import com.android.settingslib.spa.framework.common.createSettingsPage
import com.android.settingslib.spa.framework.compose.navigator
-import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.gallery.R
import com.android.settingslib.spa.widget.preference.Preference
@@ -50,7 +49,7 @@
Preference(remember {
object : PreferenceModel {
override val title = "Some Preference"
- override val summary = stateOf("Some summary")
+ override val summary = { "Some summary" }
}
})
}.build()
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/ListPreferencePageProvider.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/ListPreferencePageProvider.kt
index 43b6d0b..d7de9b4 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/ListPreferencePageProvider.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/ListPreferencePageProvider.kt
@@ -99,7 +99,7 @@
ListPreference(remember {
object : ListPreferenceModel {
override val title = "Preferred network type"
- override val enabled = enabled
+ override val enabled = { enabled.value }
override val options = listOf(
ListPreferenceOption(id = 1, text = "5G (recommended)"),
ListPreferenceOption(id = 2, text = "LTE"),
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePage.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePageProvider.kt
similarity index 94%
rename from packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePage.kt
rename to packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePageProvider.kt
index 238204a..96de1a7 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePage.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePageProvider.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,6 @@
import com.android.settingslib.spa.framework.common.SettingsPageProvider
import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
import com.android.settingslib.spa.framework.common.createSettingsPage
-import com.android.settingslib.spa.framework.compose.toState
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.framework.util.createIntent
import com.android.settingslib.spa.gallery.R
@@ -136,8 +135,8 @@
Preference(
object : PreferenceModel {
override val title = ASYNC_PREFERENCE_TITLE
- override val summary = model.asyncSummary
- override val enabled = model.asyncEnable
+ override val summary = { model.asyncSummary.value }
+ override val enabled = { model.asyncEnable.value }
}
)
}
@@ -170,7 +169,7 @@
Preference(
object : PreferenceModel {
override val title = MANUAL_UPDATE_PREFERENCE_TITLE
- override val summary = manualUpdaterSummary
+ override val summary = { manualUpdaterSummary.value }
override val onClick = { model.manualUpdaterOnClick() }
override val icon = @Composable {
SettingsIcon(imageVector = Icons.Outlined.TouchApp)
@@ -205,11 +204,13 @@
createEntry(EntryEnum.AUTO_UPDATE_PREFERENCE)
.setUiLayoutFn {
val model = PreferencePageModel.create()
- val autoUpdaterSummary = remember { model.getAutoUpdaterSummary() }
+ val autoUpdaterSummary = remember {
+ model.getAutoUpdaterSummary()
+ }.observeAsState(" ")
Preference(
object : PreferenceModel {
override val title = AUTO_UPDATE_PREFERENCE_TITLE
- override val summary = autoUpdaterSummary.observeAsState(" ")
+ override val summary = { autoUpdaterSummary.value }
override val icon = @Composable {
SettingsIcon(imageVector = Icons.Outlined.Autorenew)
}
@@ -250,12 +251,12 @@
private fun singleLineSummaryEntry() = createEntry(EntryEnum.SINGLE_LINE_SUMMARY_PREFERENCE)
.setUiLayoutFn {
+ val summary = stringResource(R.string.single_line_summary_preference_summary)
Preference(
model = object : PreferenceModel {
override val title: String =
stringResource(R.string.single_line_summary_preference_title)
- override val summary =
- stringResource(R.string.single_line_summary_preference_summary).toState()
+ override val summary = { summary }
},
singleLineSummary = true,
)
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/SwitchPreferencePage.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/SwitchPreferencePageProvider.kt
similarity index 96%
rename from packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/SwitchPreferencePage.kt
rename to packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/SwitchPreferencePageProvider.kt
index b67e066..ce0ee18 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/SwitchPreferencePage.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/SwitchPreferencePageProvider.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -114,7 +114,7 @@
SwitchPreference(remember {
object : SwitchPreferenceModel {
override val title = "SwitchPreference"
- override val summary = stateOf("With summary")
+ override val summary = { "With summary" }
override val checked = checked
override val onCheckedChange = { newChecked: Boolean -> checked.value = newChecked }
}
@@ -131,7 +131,7 @@
SwitchPreference(remember {
object : SwitchPreferenceModel {
override val title = "SwitchPreference"
- override val summary = summary
+ override val summary = { summary.value }
override val checked = checked
override val onCheckedChange = { newChecked: Boolean -> checked.value = newChecked }
}
@@ -144,7 +144,7 @@
SwitchPreference(remember {
object : SwitchPreferenceModel {
override val title = "SwitchPreference"
- override val summary = stateOf("Not changeable")
+ override val summary = { "Not changeable" }
override val changeable = stateOf(false)
override val checked = checked
override val onCheckedChange = { newChecked: Boolean -> checked.value = newChecked }
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/TwoTargetSwitchPreferencePage.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/TwoTargetSwitchPreferencePageProvider.kt
similarity index 95%
rename from packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/TwoTargetSwitchPreferencePage.kt
rename to packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/TwoTargetSwitchPreferencePageProvider.kt
index a2cd283..fc50745 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/TwoTargetSwitchPreferencePage.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/TwoTargetSwitchPreferencePageProvider.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,7 +105,7 @@
TwoTargetSwitchPreference(remember {
object : SwitchPreferenceModel {
override val title = "TwoTargetSwitchPreference"
- override val summary = stateOf("With summary")
+ override val summary = { "With summary" }
override val checked = checked
override val onCheckedChange = { newChecked: Boolean -> checked.value = newChecked }
}
@@ -122,7 +122,7 @@
TwoTargetSwitchPreference(remember {
object : SwitchPreferenceModel {
override val title = "TwoTargetSwitchPreference"
- override val summary = summary
+ override val summary = { summary.value }
override val checked = checked
override val onCheckedChange = { newChecked: Boolean -> checked.value = newChecked }
}
@@ -135,7 +135,7 @@
TwoTargetSwitchPreference(remember {
object : SwitchPreferenceModel {
override val title = "TwoTargetSwitchPreference"
- override val summary = stateOf("Not changeable")
+ override val summary = { "Not changeable" }
override val changeable = stateOf(false)
override val checked = checked
override val onCheckedChange = { newChecked: Boolean -> checked.value = newChecked }
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/ui/SpinnerPage.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/ui/SpinnerPageProvider.kt
similarity index 87%
rename from packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/ui/SpinnerPage.kt
rename to packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/ui/SpinnerPageProvider.kt
index aeba6ea..5c5c504 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/ui/SpinnerPage.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/ui/SpinnerPageProvider.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,10 +18,8 @@
import android.os.Bundle
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
+import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.tooling.preview.Preview
@@ -58,7 +56,7 @@
@Composable
override fun Page(arguments: Bundle?) {
RegularScaffold(title = getTitle(arguments)) {
- var selectedId by rememberSaveable { mutableStateOf(1) }
+ var selectedId by rememberSaveable { mutableIntStateOf(1) }
Spinner(
options = (1..3).map { SpinnerOption(id = it, text = "Option $it") },
selectedId = selectedId,
@@ -66,9 +64,7 @@
)
Preference(object : PreferenceModel {
override val title = "Selected id"
- override val summary = remember {
- derivedStateOf { selectedId.toString() }
- }
+ override val summary = { selectedId.toString() }
})
}
}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/Bitmap.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/Bitmap.kt
index 814d4a1..fb65d65 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/Bitmap.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/Bitmap.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.util
import android.graphics.Bitmap
import android.graphics.Canvas
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/DefaultDeviceEmulationSpec.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/DefaultDeviceEmulationSpec.kt
deleted file mode 100644
index d7f42b3..0000000
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/DefaultDeviceEmulationSpec.kt
+++ /dev/null
@@ -1,66 +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.settingslib.spa.screenshot
-
-import platform.test.screenshot.DeviceEmulationSpec
-import platform.test.screenshot.DisplaySpec
-
-/**
- * The emulations specs for all 8 permutations of:
- * - phone or tablet.
- * - dark of light mode.
- * - portrait or landscape.
- */
-val DeviceEmulationSpec.Companion.PhoneAndTabletFull
- get() = PhoneAndTabletFullSpec
-
-private val PhoneAndTabletFullSpec =
- DeviceEmulationSpec.forDisplays(Displays.Phone, Displays.Tablet)
-
-/**
- * The emulations specs of:
- * - phone + light mode + portrait.
- * - phone + light mode + landscape.
- * - tablet + dark mode + portrait.
- *
- * This allows to test the most important permutations of a screen/layout with only 3
- * configurations.
- */
-val DeviceEmulationSpec.Companion.PhoneAndTabletMinimal
- get() = PhoneAndTabletMinimalSpec
-
-private val PhoneAndTabletMinimalSpec =
- DeviceEmulationSpec.forDisplays(Displays.Phone, isDarkTheme = false) +
- DeviceEmulationSpec.forDisplays(Displays.Tablet, isDarkTheme = true, isLandscape = false)
-
-object Displays {
- val Phone =
- DisplaySpec(
- "phone",
- width = 1440,
- height = 3120,
- densityDpi = 560,
- )
-
- val Tablet =
- DisplaySpec(
- "tablet",
- width = 2560,
- height = 1600,
- densityDpi = 320,
- )
-}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsGoldenImagePathManager.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsGoldenImagePathManager.kt
index 25bc098..f5fba7f 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsGoldenImagePathManager.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsGoldenImagePathManager.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.util
import androidx.test.platform.app.InstrumentationRegistry
import platform.test.screenshot.GoldenImagePathManager
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsScreenshotTestRule.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsScreenshotTestRule.kt
index 7a7cf31..3dcefe9 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsScreenshotTestRule.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/util/SettingsScreenshotTestRule.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.util
import androidx.activity.ComponentActivity
import androidx.compose.material3.MaterialTheme
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/button/ActionButtonsScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/button/ActionButtonsScreenshotTest.kt
index b2e0b18..b74a243 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/button/ActionButtonsScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/button/ActionButtonsScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,12 +14,13 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.button
import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.outlined.Launch
import androidx.compose.material.icons.outlined.Delete
-import androidx.compose.material.icons.outlined.Launch
import androidx.compose.material.icons.outlined.WarningAmber
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.button.ActionButton
import com.android.settingslib.spa.widget.button.ActionButtons
import org.junit.Rule
@@ -27,6 +28,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
@@ -48,7 +50,7 @@
fun test() {
screenshotRule.screenshotTest("actionButtons") {
val actionButtons = listOf(
- ActionButton(text = "Open", imageVector = Icons.Outlined.Launch) {},
+ ActionButton(text = "Open", imageVector = Icons.AutoMirrored.Outlined.Launch) {},
ActionButton(text = "Uninstall", imageVector = Icons.Outlined.Delete) {},
ActionButton(text = "Force stop", imageVector = Icons.Outlined.WarningAmber) {},
)
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/BarChartScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/BarChartScreenshotTest.kt
index e6decb1..051ef77 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/BarChartScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/BarChartScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.chart
import androidx.compose.material3.MaterialTheme
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.chart.BarChart
import com.android.settingslib.spa.widget.chart.BarChartData
import com.android.settingslib.spa.widget.chart.BarChartModel
@@ -26,6 +27,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
@@ -61,7 +63,7 @@
override val colors = listOf(color)
override val xValueFormatter =
IAxisValueFormatter { value, _ ->
- "${WeekDay.values()[value.toInt()]}"
+ "${WeekDay.entries[value.toInt()]}"
}
override val yValueFormatter =
IAxisValueFormatter { value, _ ->
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/LineChartScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/LineChartScreenshotTest.kt
index f9d93f8..3822571 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/LineChartScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/LineChartScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.chart
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.chart.LineChart
import com.android.settingslib.spa.widget.chart.LineChartData
import com.android.settingslib.spa.widget.chart.LineChartModel
@@ -26,6 +27,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
@@ -59,7 +61,7 @@
)
override val xValueFormatter =
IAxisValueFormatter { value, _ ->
- "${WeekDay.values()[value.toInt()]}"
+ "${WeekDay.entries[value.toInt()]}"
}
override val yValueFormatter =
IAxisValueFormatter { value, _ ->
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/PieChartScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/PieChartScreenshotTest.kt
index 34ded3c..6dd62ec 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/PieChartScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/chart/PieChartScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.chart
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.chart.PieChart
import com.android.settingslib.spa.widget.chart.PieChartData
import com.android.settingslib.spa.widget.chart.PieChartModel
@@ -24,6 +25,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
@@ -56,4 +58,4 @@
)
}
}
-}
\ No newline at end of file
+}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/illustration/ImageIllustrationScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/illustration/ImageIllustrationScreenshotTest.kt
index 91aca05..0ccfc0b 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/illustration/ImageIllustrationScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/illustration/ImageIllustrationScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,8 +14,10 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.illustration
+import com.android.settingslib.spa.screenshot.R
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.illustration.Illustration
import com.android.settingslib.spa.widget.illustration.IllustrationModel
import com.android.settingslib.spa.widget.illustration.ResourceType
@@ -24,6 +26,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/MainSwitchPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/MainSwitchPreferenceScreenshotTest.kt
index a366b9e..c1d7188 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/MainSwitchPreferenceScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/MainSwitchPreferenceScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import com.android.settingslib.spa.framework.compose.stateOf
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.MainSwitchPreference
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
import org.junit.Rule
@@ -25,6 +26,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/PreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/PreferenceScreenshotTest.kt
index d72152c..dd6b553 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/PreferenceScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/PreferenceScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Autorenew
import androidx.compose.material.icons.outlined.DisabledByDefault
import androidx.compose.runtime.Composable
-import com.android.settingslib.spa.framework.compose.toState
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.ui.SettingsIcon
@@ -30,6 +30,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
@@ -61,18 +62,18 @@
Preference(object : PreferenceModel {
override val title = TITLE
- override val summary = SUMMARY.toState()
+ override val summary = { SUMMARY }
})
Preference(object : PreferenceModel {
override val title = TITLE
- override val summary = LONG_SUMMARY.toState()
+ override val summary = { LONG_SUMMARY }
})
Preference(object : PreferenceModel {
override val title = TITLE
- override val summary = SUMMARY.toState()
- override val enabled = false.toState()
+ override val summary = { SUMMARY }
+ override val enabled = { false }
override val icon = @Composable {
SettingsIcon(imageVector = Icons.Outlined.DisabledByDefault)
}
@@ -80,7 +81,7 @@
Preference(object : PreferenceModel {
override val title = TITLE
- override val summary = SUMMARY.toState()
+ override val summary = { SUMMARY }
override val icon = @Composable {
SettingsIcon(imageVector = Icons.Outlined.Autorenew)
}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/ProgressBarPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/ProgressBarPreferenceScreenshotTest.kt
index 5fcaf85..357d815 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/ProgressBarPreferenceScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/ProgressBarPreferenceScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.SystemUpdate
import androidx.compose.runtime.Composable
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.ProgressBarPreference
import com.android.settingslib.spa.widget.preference.ProgressBarPreferenceModel
import com.android.settingslib.spa.widget.preference.ProgressBarWithDataPreference
@@ -30,6 +31,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SliderPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SliderPreferenceScreenshotTest.kt
index 48c922d..fdee7ee 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SliderPreferenceScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SliderPreferenceScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.AccessAlarm
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.SliderPreference
import com.android.settingslib.spa.widget.preference.SliderPreferenceModel
import org.junit.Rule
@@ -26,6 +27,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SwitchPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SwitchPreferenceScreenshotTest.kt
index 2c84a8e..a688e11 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SwitchPreferenceScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/SwitchPreferenceScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.AirplanemodeActive
import androidx.compose.runtime.Composable
import com.android.settingslib.spa.framework.compose.stateOf
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.SwitchPreference
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
import com.android.settingslib.spa.widget.ui.SettingsIcon
@@ -29,6 +30,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
@@ -72,7 +74,7 @@
private fun SampleSwitchPreferenceWithSummary() {
SwitchPreference(object : SwitchPreferenceModel {
override val title = "SwitchPreference"
- override val summary = stateOf("With summary")
+ override val summary = { "With summary" }
override val checked = stateOf(true)
override val onCheckedChange = null
})
@@ -82,7 +84,7 @@
private fun SampleNotChangeableSwitchPreference() {
SwitchPreference(object : SwitchPreferenceModel {
override val title = "SwitchPreference"
- override val summary = stateOf("Not changeable")
+ override val summary = { "Not changeable" }
override val changeable = stateOf(false)
override val checked = stateOf(true)
override val onCheckedChange = null
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/TwoTargetSwitchPreferenceScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/TwoTargetSwitchPreferenceScreenshotTest.kt
index 2c37212..8f0abc0 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/TwoTargetSwitchPreferenceScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/preference/TwoTargetSwitchPreferenceScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,17 +14,19 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.preference
import androidx.compose.foundation.layout.Column
import com.android.settingslib.spa.framework.compose.stateOf
-import com.android.settingslib.spa.widget.preference.TwoTargetSwitchPreference
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
+import com.android.settingslib.spa.widget.preference.TwoTargetSwitchPreference
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
@@ -54,7 +56,7 @@
TwoTargetSwitchPreference(object : SwitchPreferenceModel {
override val title = "TwoTargetSwitchPreference"
- override val summary = stateOf("With summary")
+ override val summary = { "With summary" }
override val checked = stateOf(true)
override val onCheckedChange = null
}) {}
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/FooterScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/FooterScreenshotTest.kt
index 0a0faf6..fb01f77 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/FooterScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/FooterScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,14 +14,16 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.ui
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.ui.Footer
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
diff --git a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/SpinnerScreenshotTest.kt b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/SpinnerScreenshotTest.kt
index 0b4d5e4..2867741 100644
--- a/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/SpinnerScreenshotTest.kt
+++ b/packages/SettingsLib/Spa/screenshot/src/com/android/settingslib/spa/screenshot/widget/ui/SpinnerScreenshotTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-package com.android.settingslib.spa.screenshot
+package com.android.settingslib.spa.screenshot.widget.ui
+import com.android.settingslib.spa.screenshot.util.SettingsScreenshotTestRule
import com.android.settingslib.spa.widget.ui.Spinner
import com.android.settingslib.spa.widget.ui.SpinnerOption
import org.junit.Rule
@@ -23,6 +24,7 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import platform.test.screenshot.DeviceEmulationSpec
+import platform.test.screenshot.PhoneAndTabletMinimal
/** A screenshot test for ExampleFeature. */
@RunWith(Parameterized::class)
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugActivity.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugActivity.kt
index 078c925..14af508 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugActivity.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/debug/DebugActivity.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,6 @@
import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
import com.android.settingslib.spa.framework.compose.localNavController
import com.android.settingslib.spa.framework.compose.navigator
-import com.android.settingslib.spa.framework.compose.toState
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.framework.util.SESSION_BROWSE
import com.android.settingslib.spa.framework.util.SESSION_SEARCH
@@ -137,7 +136,7 @@
val page = pageWithEntry.page
Preference(object : PreferenceModel {
override val title = "${page.debugBrief()} (${pageWithEntry.entries.size})"
- override val summary = page.debugArguments().toState()
+ override val summary = { page.debugArguments() }
override val onClick = navigator(route = ROUTE_PAGE + "/${page.id}")
})
}
@@ -179,8 +178,9 @@
Text(text = "Entry size: ${pageWithEntry.entries.size}")
Preference(model = object : PreferenceModel {
override val title = "open page"
- override val enabled = (spaEnvironment.browseActivityClass != null &&
- page.isBrowsable()).toState()
+ override val enabled = {
+ spaEnvironment.browseActivityClass != null && page.isBrowsable()
+ }
override val onClick = openPage(page)
})
EntryList(pageWithEntry.entries)
@@ -196,9 +196,10 @@
RegularScaffold(title = "Entry - ${entry.debugBrief()}") {
Preference(model = object : PreferenceModel {
override val title = "open entry"
- override val enabled = (spaEnvironment.browseActivityClass != null &&
- entry.containerPage().isBrowsable())
- .toState()
+ override val enabled = {
+ spaEnvironment.browseActivityClass != null &&
+ entry.containerPage().isBrowsable()
+ }
override val onClick = openEntry(entry)
})
Text(text = entryContent)
@@ -210,8 +211,9 @@
for (entry in entries) {
Preference(object : PreferenceModel {
override val title = entry.debugBrief()
- override val summary =
- "${entry.fromPage?.displayName} -> ${entry.toPage?.displayName}".toState()
+ override val summary = {
+ "${entry.fromPage?.displayName} -> ${entry.toPage?.displayName}"
+ }
override val onClick = navigator(route = ROUTE_ENTRY + "/${entry.id}")
})
}
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/ListPreference.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/ListPreference.kt
index 74f9c9d..a0149da 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/ListPreference.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/ListPreference.kt
@@ -27,8 +27,6 @@
import androidx.compose.material3.RadioButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.IntState
-import androidx.compose.runtime.State
-import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -37,7 +35,6 @@
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
-import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.widget.dialog.SettingsDialog
import com.android.settingslib.spa.widget.ui.SettingsDialogItem
@@ -69,8 +66,8 @@
*
* Disabled [ListPreference] will be displayed in disabled style.
*/
- val enabled: State<Boolean>
- get() = stateOf(true)
+ val enabled: () -> Boolean
+ get() = { true }
val options: List<ListPreferenceOption>
@@ -89,7 +86,7 @@
) {
Column(modifier = Modifier.selectableGroup()) {
for (option in model.options) {
- Radio(option, model.selectedId.intValue, model.enabled.value) {
+ Radio(option, model.selectedId.intValue, model.enabled()) {
dialogOpened = false
model.onIdSelected(it)
}
@@ -100,7 +97,7 @@
Preference(model = remember(model) {
object : PreferenceModel {
override val title = model.title
- override val summary = derivedStateOf {
+ override val summary = {
model.options.find { it.id == model.selectedId.intValue }?.text ?: ""
}
override val icon = model.icon
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/Preference.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/Preference.kt
index 7ecbec7..bb7e857 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/Preference.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/Preference.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,14 +18,12 @@
import androidx.compose.foundation.clickable
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.State
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import com.android.settingslib.spa.framework.common.EntryMacro
import com.android.settingslib.spa.framework.common.EntrySearchData
import com.android.settingslib.spa.framework.compose.navigator
-import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.framework.util.EntryHighlight
import com.android.settingslib.spa.framework.util.wrapOnClickWithLog
import com.android.settingslib.spa.widget.ui.createSettingsIcon
@@ -42,9 +40,9 @@
override fun UiLayout() {
Preference(model = object : PreferenceModel {
override val title: String = this@SimplePreferenceMacro.title
- override val summary = stateOf(this@SimplePreferenceMacro.summary ?: "")
+ override val summary = { this@SimplePreferenceMacro.summary ?: "" }
override val icon = createSettingsIcon(this@SimplePreferenceMacro.icon)
- override val enabled = stateOf(!this@SimplePreferenceMacro.disabled)
+ override val enabled = { !disabled }
override val onClick = navigator(clickRoute)
})
}
@@ -69,8 +67,8 @@
/**
* The summary of this [Preference].
*/
- val summary: State<String>
- get() = stateOf("")
+ val summary: () -> String
+ get() = { "" }
/**
* The icon of this [Preference].
@@ -85,8 +83,8 @@
*
* Disabled [Preference] will be displayed in disabled style.
*/
- val enabled: State<Boolean>
- get() = stateOf(true)
+ val enabled: () -> Boolean
+ get() = { true }
/**
* The on click handler of this [Preference].
@@ -108,10 +106,11 @@
singleLineSummary: Boolean = false,
) {
val onClickWithLog = wrapOnClickWithLog(model.onClick)
- val modifier = remember(model.enabled.value) {
+ val enabled = model.enabled()
+ val modifier = remember(enabled) {
if (onClickWithLog != null) {
Modifier.clickable(
- enabled = model.enabled.value,
+ enabled = enabled,
onClick = onClickWithLog
)
} else Modifier
@@ -119,11 +118,11 @@
EntryHighlight {
BasePreference(
title = model.title,
- summary = { model.summary.value },
+ summary = model.summary,
singleLineSummary = singleLineSummary,
modifier = modifier,
icon = model.icon,
- enabled = { model.enabled.value },
+ enabled = model.enabled,
)
}
}
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/SwitchPreference.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/SwitchPreference.kt
index f14f68c..12afe92 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/SwitchPreference.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/SwitchPreference.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,8 +51,8 @@
/**
* The summary of this [SwitchPreference].
*/
- val summary: State<String>
- get() = stateOf("")
+ val summary: () -> String
+ get() = { "" }
/**
* The icon of this [Preference].
@@ -95,7 +95,7 @@
EntryHighlight {
InternalSwitchPreference(
title = model.title,
- summary = { model.summary.value },
+ summary = model.summary,
icon = model.icon,
checked = model.checked.value,
changeable = model.changeable.value,
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/TwoTargetButtonPreference.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/TwoTargetButtonPreference.kt
index b8db63c..9866023 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/TwoTargetButtonPreference.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/TwoTargetButtonPreference.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,32 +16,32 @@
package com.android.settingslib.spa.widget.preference
-import com.android.settingslib.spa.framework.util.EntryHighlight
+import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
-import androidx.compose.runtime.State
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
-import androidx.compose.material3.Icon
+import com.android.settingslib.spa.framework.util.EntryHighlight
@Composable
fun TwoTargetButtonPreference(
- title: String,
- summary: State<String>,
- icon: @Composable (() -> Unit)? = null,
- onClick: () -> Unit,
- buttonIcon: ImageVector,
- buttonIconDescription: String,
- onButtonClick: () -> Unit
+ title: String,
+ summary: () -> String,
+ icon: @Composable (() -> Unit)? = null,
+ onClick: () -> Unit,
+ buttonIcon: ImageVector,
+ buttonIconDescription: String,
+ onButtonClick: () -> Unit
) {
EntryHighlight {
TwoTargetPreference(
- title = title,
- summary = summary,
- onClick = onClick,
- icon = icon) {
+ title = title,
+ summary = summary,
+ onClick = onClick,
+ icon = icon,
+ ) {
IconButton(onClick = onButtonClick) {
Icon(imageVector = buttonIcon, contentDescription = buttonIconDescription)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/TwoTargetPreference.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/TwoTargetPreference.kt
index 5663610..e36572f 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/TwoTargetPreference.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/preference/TwoTargetPreference.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.State
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -35,7 +34,7 @@
@Composable
internal fun TwoTargetPreference(
title: String,
- summary: State<String>,
+ summary: () -> String,
onClick: () -> Unit,
icon: @Composable (() -> Unit)? = null,
widget: @Composable () -> Unit,
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ListPreferenceTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ListPreferenceTest.kt
index 997a023..796ac48 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ListPreferenceTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ListPreferenceTest.kt
@@ -25,7 +25,6 @@
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.testutils.onDialogText
import org.junit.Rule
import org.junit.Test
@@ -92,7 +91,7 @@
ListPreference(remember {
object : ListPreferenceModel {
override val title = TITLE
- override val enabled = stateOf(false)
+ override val enabled = { false }
override val options = listOf(ListPreferenceOption(id = 1, text = "A"))
override val selectedId = mutableIntStateOf(1)
override val onIdSelected: (Int) -> Unit = {}
@@ -154,7 +153,7 @@
ListPreference(remember {
object : ListPreferenceModel {
override val title = TITLE
- override val enabled = enabledState
+ override val enabled = { enabledState.value }
override val options = listOf(
ListPreferenceOption(id = 1, text = "A"),
ListPreferenceOption(id = 2, text = "B"),
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/PreferenceTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/PreferenceTest.kt
index 06936e1..8c363db 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/PreferenceTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/PreferenceTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
-import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -34,7 +33,6 @@
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.settingslib.spa.framework.compose.toState
import com.google.common.truth.Truth.assertThat
import org.junit.Assert.fail
import org.junit.Rule
@@ -65,7 +63,7 @@
Box(Modifier.width(BOX_WIDTH)) {
Preference(object : PreferenceModel {
override val title = TITLE
- override val summary = LONG_SUMMARY.toState()
+ override val summary = { LONG_SUMMARY }
})
}
lineHeightDp = with(LocalDensity.current) {
@@ -85,7 +83,7 @@
Preference(
model = object : PreferenceModel {
override val title = TITLE
- override val summary = LONG_SUMMARY.toState()
+ override val summary = { LONG_SUMMARY }
},
singleLineSummary = true,
)
@@ -113,7 +111,7 @@
var count by remember { mutableStateOf(0) }
Preference(object : PreferenceModel {
override val title = TITLE
- override val summary = derivedStateOf { count.toString() }
+ override val summary = { count.toString() }
override val onClick: (() -> Unit) = { count++ }
})
}
@@ -128,8 +126,8 @@
var count by remember { mutableStateOf(0) }
Preference(object : PreferenceModel {
override val title = TITLE
- override val summary = derivedStateOf { count.toString() }
- override val enabled = false.toState()
+ override val summary = { count.toString() }
+ override val enabled = { false }
override val onClick: (() -> Unit) = { count++ }
})
}
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ProgressBarPreferenceTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ProgressBarPreferenceTest.kt
index 2140c07..e6d2401 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ProgressBarPreferenceTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/ProgressBarPreferenceTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,7 @@
package com.android.settingslib.spa.widget.preference
import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.outlined.Launch
-import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.material.icons.automirrored.outlined.Launch
import androidx.compose.ui.semantics.ProgressBarRangeInfo
import androidx.compose.ui.semantics.SemanticsProperties.ProgressBarRangeInfo
import androidx.compose.ui.test.SemanticsMatcher
@@ -49,11 +48,14 @@
@Test
fun data_displayed() {
composeTestRule.setContent {
- ProgressBarWithDataPreference(model = object : ProgressBarPreferenceModel {
- override val title = "Title"
- override val progress = 0.2f
- override val icon: ImageVector = Icons.Outlined.Launch
- }, data = "Data")
+ ProgressBarWithDataPreference(
+ model = object : ProgressBarPreferenceModel {
+ override val title = "Title"
+ override val progress = 0.2f
+ override val icon = Icons.AutoMirrored.Outlined.Launch
+ },
+ data = "Data",
+ )
}
composeTestRule.onNodeWithText("Title").assertIsDisplayed()
composeTestRule.onNodeWithText("Data").assertIsDisplayed()
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/TwoTargetButtonPreferenceTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/TwoTargetButtonPreferenceTest.kt
index 3a2b445..6de1933 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/TwoTargetButtonPreferenceTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/preference/TwoTargetButtonPreferenceTest.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.android.settingslib.spa.widget.preference
import androidx.compose.material.icons.Icons
@@ -9,7 +25,6 @@
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.settingslib.spa.framework.compose.toState
import com.google.common.truth.Truth
import org.junit.Rule
import org.junit.Test
@@ -64,10 +79,10 @@
) {
TwoTargetButtonPreference(
title = TEST_MODEL_TITLE,
- summary = TEST_MODEL_SUMMARY.toState(),
+ summary = { TEST_MODEL_SUMMARY },
onClick = onClick,
buttonIcon = TEST_BUTTON_ICON,
buttonIconDescription = TEST_BUTTON_ICON_DESCRIPTION,
onButtonClick = onButtonClick
)
-}
\ No newline at end of file
+}
diff --git a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt
index 16e09ee..09a6e6d 100644
--- a/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt
+++ b/packages/SettingsLib/Spa/tests/src/com/android/settingslib/spa/widget/ui/CategoryTest.kt
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2022 The Android Open Source Project
+ * Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import org.junit.Rule
@@ -50,7 +49,7 @@
Preference(remember {
object : PreferenceModel {
override val title = "Some Preference"
- override val summary = stateOf("Some summary")
+ override val summary = { "Some summary" }
}
})
}
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListModel.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListModel.kt
index f3ab80c7..9eee6ad 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListModel.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListModel.kt
@@ -19,7 +19,6 @@
import android.content.pm.ApplicationInfo
import android.icu.text.CollationKey
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.State
import com.android.settingslib.spa.widget.ui.SpinnerOption
import com.android.settingslib.spaprivileged.template.app.AppListItem
import com.android.settingslib.spaprivileged.template.app.AppListItemModel
@@ -89,7 +88,7 @@
* @return null if no summary should be displayed.
*/
@Composable
- fun getSummary(option: Int, record: T): State<String>? = null
+ fun getSummary(option: Int, record: T): (() -> String)? = null
@Composable
fun AppListItemModel<T>.AppItem() {
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppList.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppList.kt
index 066db34..7c45b64 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppList.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppList.kt
@@ -36,7 +36,6 @@
import com.android.settingslib.spa.framework.compose.LogCompositions
import com.android.settingslib.spa.framework.compose.TimeMeasurer.Companion.rememberTimeMeasurer
import com.android.settingslib.spa.framework.compose.rememberLazyListStateAndHideKeyboardWhenStartScroll
-import com.android.settingslib.spa.framework.compose.toState
import com.android.settingslib.spa.widget.ui.CategoryTitle
import com.android.settingslib.spa.widget.ui.PlaceholderTitle
import com.android.settingslib.spa.widget.ui.Spinner
@@ -150,7 +149,7 @@
?.let { group -> CategoryTitle(title = group) }
val appEntry = list[it]
- val summary = getSummary(option, appEntry.record) ?: "".toState()
+ val summary = getSummary(option, appEntry.record) ?: { "" }
remember(appEntry) {
AppListItemModel(appEntry.record, appEntry.label, summary)
}.AppItem()
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListItem.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListItemModel.kt
similarity index 89%
rename from packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListItem.kt
rename to packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListItemModel.kt
index 6d0d7d6..a7c5036 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListItem.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppListItemModel.kt
@@ -17,11 +17,9 @@
package com.android.settingslib.spaprivileged.template.app
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.State
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
-import com.android.settingslib.spa.framework.compose.toState
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.widget.preference.Preference
@@ -31,7 +29,7 @@
data class AppListItemModel<T : AppRecord>(
val record: T,
val label: String,
- val summary: State<String>,
+ val summary: () -> String,
)
@Composable
@@ -55,6 +53,6 @@
val record = object : AppRecord {
override val app = LocalContext.current.applicationInfo
}
- AppListItemModel<AppRecord>(record, "Chrome", "Allowed".toState()).AppListItem {}
+ AppListItemModel<AppRecord>(record, "Chrome", { "Allowed" }).AppListItem {}
}
}
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPage.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPage.kt
index 17e9708..3ab27367 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPage.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPage.kt
@@ -20,8 +20,7 @@
import android.content.pm.ApplicationInfo
import android.os.Bundle
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.State
-import androidx.compose.runtime.derivedStateOf
+import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
@@ -149,33 +148,27 @@
override fun getSummary(option: Int, record: T) = getSummary(record)
@Composable
- fun getSummary(record: T): State<String> {
+ fun getSummary(record: T): () -> String {
val restrictions = remember(record.app.userId) {
Restrictions(
userId = record.app.userId,
keys = listModel.switchRestrictionKeys,
)
}
- val restrictedMode = restrictionsProviderFactory.rememberRestrictedMode(restrictions)
- val allowed = listModel.isAllowed(record)
- return remember {
- derivedStateOf {
- RestrictedSwitchPreference.getSummary(
- context = context,
- restrictedMode = restrictedMode.value,
- summaryIfNoRestricted = getSummaryIfNoRestricted(allowed),
- checked = allowed,
- ).value
- }
- }
+ val restrictedMode by restrictionsProviderFactory.rememberRestrictedMode(restrictions)
+ val allowed by listModel.isAllowed(record)
+ return RestrictedSwitchPreference.getSummary(
+ context = context,
+ restrictedModeSupplier = { restrictedMode },
+ summaryIfNoRestricted = { getSummaryIfNoRestricted(allowed) },
+ checked = { allowed },
+ )
}
- private fun getSummaryIfNoRestricted(allowed: State<Boolean?>) = derivedStateOf {
- when (allowed.value) {
- true -> context.getString(R.string.app_permission_summary_allowed)
- false -> context.getString(R.string.app_permission_summary_not_allowed)
- null -> context.getPlaceholder()
- }
+ private fun getSummaryIfNoRestricted(allowed: Boolean?): String = when (allowed) {
+ true -> context.getString(R.string.app_permission_summary_allowed)
+ false -> context.getString(R.string.app_permission_summary_not_allowed)
+ null -> context.getPlaceholder()
}
@Composable
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/preference/RestrictedPreference.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/preference/RestrictedPreference.kt
index 50490c0..ac85dd4 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/preference/RestrictedPreference.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/preference/RestrictedPreference.kt
@@ -23,7 +23,6 @@
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
-import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spaprivileged.model.enterprise.BaseUserRestricted
@@ -73,7 +72,7 @@
override val enabled = when (restrictedMode) {
NoRestricted -> model.enabled
- else -> stateOf(false)
+ else -> ({ false })
}
override val onClick = when (restrictedMode) {
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/preference/RestrictedSwitchPreference.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/preference/RestrictedSwitchPreference.kt
index 2129403..d17e0c7 100644
--- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/preference/RestrictedSwitchPreference.kt
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/preference/RestrictedSwitchPreference.kt
@@ -21,8 +21,6 @@
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.State
-import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
@@ -75,17 +73,16 @@
internal object RestrictedSwitchPreference {
fun getSummary(
context: Context,
- restrictedMode: RestrictedMode?,
- summaryIfNoRestricted: State<String>,
- checked: State<Boolean?>,
- ): State<String> = when (restrictedMode) {
- is NoRestricted -> summaryIfNoRestricted
- is BaseUserRestricted -> stateOf(
- context.getString(com.android.settingslib.R.string.disabled)
- )
-
- is BlockedByAdmin -> derivedStateOf { restrictedMode.getSummary(checked.value) }
- null -> stateOf(context.getPlaceholder())
+ restrictedModeSupplier: () -> RestrictedMode?,
+ summaryIfNoRestricted: () -> String,
+ checked: () -> Boolean?,
+ ): () -> String = {
+ when (val restrictedMode = restrictedModeSupplier()) {
+ is NoRestricted -> summaryIfNoRestricted()
+ is BaseUserRestricted -> context.getString(com.android.settingslib.R.string.disabled)
+ is BlockedByAdmin -> restrictedMode.getSummary(checked())
+ null -> context.getPlaceholder()
+ }
}
}
@@ -98,9 +95,9 @@
override val summary = RestrictedSwitchPreference.getSummary(
context = context,
- restrictedMode = restrictedMode,
+ restrictedModeSupplier = { restrictedMode },
summaryIfNoRestricted = model.summary,
- checked = model.checked,
+ checked = { model.checked.value },
)
override val checked = when (restrictedMode) {
diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListSwitchItemTest.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListSwitchItemTest.kt
index 2fd1b10..c29d7c2 100644
--- a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListSwitchItemTest.kt
+++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListSwitchItemTest.kt
@@ -158,7 +158,7 @@
override val app = APP
},
label = LABEL,
- summary = stateOf(SUMMARY),
+ summary = { SUMMARY },
)
}
}
diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListTwoTargetSwitchItemTest.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListTwoTargetSwitchItemTest.kt
index 6e7fc8e..644a2d7 100644
--- a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListTwoTargetSwitchItemTest.kt
+++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/AppListTwoTargetSwitchItemTest.kt
@@ -183,7 +183,7 @@
override val app = APP
},
label = LABEL,
- summary = stateOf(SUMMARY),
+ summary = { SUMMARY },
)
}
}
diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt
index 457b810..bf0ad0b 100644
--- a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt
+++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt
@@ -19,7 +19,6 @@
import android.content.Context
import android.content.pm.ApplicationInfo
import androidx.compose.runtime.CompositionLocalProvider
-import androidx.compose.runtime.State
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
@@ -27,7 +26,6 @@
import androidx.compose.ui.test.performClick
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.testutils.FakeNavControllerWrapper
import com.android.settingslib.spaprivileged.R
import com.android.settingslib.spaprivileged.framework.compose.getPlaceholder
@@ -72,10 +70,9 @@
fakeRestrictionsProvider.restrictedMode = NoRestricted
val listModel = TestTogglePermissionAppListModel(isAllowed = true)
- val summaryState = getSummary(listModel)
+ val summary = getSummary(listModel)
- assertThat(summaryState.value)
- .isEqualTo(context.getString(R.string.app_permission_summary_allowed))
+ assertThat(summary).isEqualTo(context.getString(R.string.app_permission_summary_allowed))
}
@Test
@@ -83,9 +80,9 @@
fakeRestrictionsProvider.restrictedMode = NoRestricted
val listModel = TestTogglePermissionAppListModel(isAllowed = false)
- val summaryState = getSummary(listModel)
+ val summary = getSummary(listModel)
- assertThat(summaryState.value)
+ assertThat(summary)
.isEqualTo(context.getString(R.string.app_permission_summary_not_allowed))
}
@@ -94,9 +91,9 @@
fakeRestrictionsProvider.restrictedMode = NoRestricted
val listModel = TestTogglePermissionAppListModel(isAllowed = null)
- val summaryState = getSummary(listModel)
+ val summary = getSummary(listModel)
- assertThat(summaryState.value).isEqualTo(context.getPlaceholder())
+ assertThat(summary).isEqualTo(context.getPlaceholder())
}
@Test
@@ -108,7 +105,7 @@
AppListItemModel(
record = listModel.transformItem(APP),
label = LABEL,
- summary = stateOf(SUMMARY),
+ summary = { SUMMARY },
).AppItem()
}
}
@@ -152,12 +149,12 @@
restrictionsProviderFactory = { _, _ -> fakeRestrictionsProvider },
)
- private fun getSummary(listModel: TestTogglePermissionAppListModel): State<String> {
- lateinit var summary: State<String>
+ private fun getSummary(listModel: TestTogglePermissionAppListModel): String {
+ lateinit var summary: () -> String
composeTestRule.setContent {
summary = createInternalAppListModel(listModel).getSummary(record = TestAppRecord(APP))
}
- return summary
+ return summary()
}
private companion object {
diff --git a/packages/SettingsLib/res/drawable/ic_hdmi.xml b/packages/SettingsLib/res/drawable/ic_hdmi.xml
new file mode 100644
index 0000000..c7a553b
--- /dev/null
+++ b/packages/SettingsLib/res/drawable/ic_hdmi.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ Copyright (C) 2023 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="48dp"
+ android:height="48dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960"
+ android:tint="?attr/colorControlNormal">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M320,880L320,760L200,521L200,280L240,280L240,140Q240,117 258.5,98.5Q277,80 300,80L660,80Q683,80 701.5,98.5Q720,117 720,140L720,280L760,280L760,521L640,760L640,880L320,880ZM300,280L398,280L398,198L432,198L432,280L528,280L528,198L562,198L562,280L660,280L660,140Q660,140 660,140Q660,140 660,140L300,140Q300,140 300,140Q300,140 300,140L300,280ZM378,743L378,743L582,743L582,743L582,743L378,743L378,743ZM378,743L582,743L700,504L700,340L260,340L260,504L378,743Z"/>
+</vector>
diff --git a/packages/SettingsLib/res/drawable/ic_tv.xml b/packages/SettingsLib/res/drawable/ic_tv.xml
new file mode 100644
index 0000000..87abaf4
--- /dev/null
+++ b/packages/SettingsLib/res/drawable/ic_tv.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ Copyright (C) 2023 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960"
+ android:tint="?attr/colorControlNormal">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M320,840L320,760L160,760Q127,760 103.5,736.5Q80,713 80,680L80,200Q80,167 103.5,143.5Q127,120 160,120L800,120Q833,120 856.5,143.5Q880,167 880,200L880,680Q880,713 856.5,736.5Q833,760 800,760L640,760L640,840L320,840ZM160,680L800,680Q800,680 800,680Q800,680 800,680L800,200Q800,200 800,200Q800,200 800,200L160,200Q160,200 160,200Q160,200 160,200L160,680Q160,680 160,680Q160,680 160,680ZM160,680Q160,680 160,680Q160,680 160,680L160,200Q160,200 160,200Q160,200 160,200L160,200Q160,200 160,200Q160,200 160,200L160,680Q160,680 160,680Q160,680 160,680L160,680Z"/>
+</vector>
\ No newline at end of file
diff --git a/packages/SettingsLib/res/drawable/ic_usb.xml b/packages/SettingsLib/res/drawable/ic_usb.xml
new file mode 100644
index 0000000..b5f15ea
--- /dev/null
+++ b/packages/SettingsLib/res/drawable/ic_usb.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ Copyright (C) 2023 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="48dp"
+ android:height="48dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960"
+ android:tint="?attr/colorControlNormal">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M480,880Q448,880 428,860Q408,840 408,808Q408,786 419,768Q430,750 450,739L450,628L302,628Q278,628 260,610Q242,592 242,568L242,459Q222,450 211,432.39Q200,414.78 200,392.28Q200,360 220,340Q240,320 272,320Q304,320 324,340Q344,360 344,392.41Q344,415 333,432.5Q322,450 302,459L302,568Q302,568 302,568Q302,568 302,568L450,568L450,228L370,228L480,79L590,228L510,228L510,568L658,568Q658,568 658,568Q658,568 658,568L658,464L616,464L616,320L760,320L760,464L718,464L718,568Q718,592 700,610Q682,628 658,628L510,628L510,739Q529.95,749.65 540.97,768.83Q552,788 552,808Q552,840 532,860Q512,880 480,880Z"/>
+</vector>
\ No newline at end of file
diff --git a/packages/SettingsLib/res/drawable/ic_wired_device.xml b/packages/SettingsLib/res/drawable/ic_wired_device.xml
new file mode 100644
index 0000000..7964c9f
--- /dev/null
+++ b/packages/SettingsLib/res/drawable/ic_wired_device.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright (C) 2020 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="48dp"
+ android:height="48dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960"
+ android:tint="?attr/colorControlNormal">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M123,920L123,750Q89,737 64.5,707.5Q40,678 40,643L40,245L123,245L123,70Q123,56 131,48Q139,40 153,40Q167,40 175,48Q183,56 183,70L183,245L266,245L266,643Q266,678 242,707.5Q218,737 183,750L183,920L123,920ZM450,920L450,750Q416,737 391.5,707.5Q367,678 367,643L367,245L450,245L450,70Q450,56 458,48Q466,40 480,40Q494,40 502,48Q510,56 510,70L510,245L593,245L593,643Q593,678 569,707.5Q545,737 510,750L510,920L450,920ZM777,920L777,750Q743,737 718.5,707.5Q694,678 694,643L694,245L777,245L777,70Q777,56 785,48Q793,40 807,40Q821,40 829,48Q837,56 837,70L837,245L920,245L920,643Q920,678 895.5,707.5Q871,737 837,750L837,920L777,920ZM100,489L206,489L206,305L100,305L100,489ZM427,489L533,489L533,305L427,305L427,489ZM754,489L860,489L860,305L754,305L754,489ZM153,489L153,489L153,489L153,489L153,489ZM480,489L480,489L480,489L480,489L480,489ZM807,489L807,489L807,489L807,489L807,489ZM100,489L100,489L206,489L206,489L100,489ZM427,489L427,489L533,489L533,489L427,489ZM754,489L754,489L860,489L860,489L754,489Z"/>
+</vector>
\ No newline at end of file
diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml
index 96029c8..1a5acf6 100644
--- a/packages/SettingsLib/res/values/strings.xml
+++ b/packages/SettingsLib/res/values/strings.xml
@@ -1334,6 +1334,8 @@
<string name="media_transfer_this_device_name" product="default">This phone</string>
<!-- Name of the tablet device. [CHAR LIMIT=30] -->
<string name="media_transfer_this_device_name" product="tablet">This tablet</string>
+ <!-- Name of the default media output of the TV. [CHAR LIMIT=30] -->
+ <string name="media_transfer_this_device_name" product="tv">@string/tv_media_transfer_default</string>
<!-- Name of the dock device. [CHAR LIMIT=30] -->
<string name="media_transfer_dock_speaker_device_name">Dock speaker</string>
<!-- Default name of the external device. [CHAR LIMIT=30] -->
@@ -1357,6 +1359,26 @@
<!-- Sub status indicates the device does not support the current media track. [CHAR LIMIT=NONE] -->
<string name="media_output_status_track_unsupported">Can\’t play this media here</string>
+ <!-- Media output switcher. Default subtitle for any output option that is connected if no more information is known [CHAR LIMIT=NONE] -->
+ <string name="tv_media_transfer_connected">Connected</string>
+
+ <!-- TV media output switcher. Title for devices connected through HDMI ARC if no device name is available. [CHAR LIMIT=NONE] -->
+ <string name="tv_media_transfer_arc_fallback_title">HDMI ARC</string>
+ <!-- TV media output switcher. Title for devices connected through HDMI EARC if no device name is available. [CHAR LIMIT=NONE] -->
+ <string name="tv_media_transfer_earc_fallback_title">HDMI eARC</string>
+
+ <!-- TV media output switcher. Subtitle for devices connected through HDMI ARC if a device name is available. [CHAR LIMIT=NONE] -->
+ <string name="tv_media_transfer_arc_subtitle">Connected via ARC</string>
+ <!-- Media output switcher. Subtitle for devices connected through HDMI EARC if a device name is available. [CHAR LIMIT=NONE] -->
+ <string name="tv_media_transfer_earc_subtitle">Connected via eARC</string>
+
+ <!-- TV media output switcher. Title for the default audio output of the device [CHAR LIMIT=NONE] -->
+ <string name="tv_media_transfer_default">TV Default</string>
+ <!-- TV media output switcher. Subtitle for default audio output which is HDMI, e.g. TV dongle [CHAR LIMIT=NONE] -->
+ <string name="tv_media_transfer_hdmi">HDMI Output</string>
+ <!-- TV media output switcher. Subtitle for default audio output which is internal speaker, i.e. panel VTs [CHAR LIMIT=NONE] -->
+ <string name="tv_media_transfer_internal_speakers">Internal Speakers</string>
+
<!-- Warning message to tell user is have problem during profile connect, it need to turn off device and back on. [CHAR_LIMIT=NONE] -->
<string name="profile_connect_timeout_subtext">Problem connecting. Turn device off & back on</string>
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/DeviceIconUtil.java b/packages/SettingsLib/src/com/android/settingslib/media/DeviceIconUtil.java
index 2a28417..cf224dc 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/DeviceIconUtil.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/DeviceIconUtil.java
@@ -18,11 +18,13 @@
import android.annotation.DrawableRes;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.media.AudioDeviceInfo;
import android.media.MediaRoute2Info;
import com.android.settingslib.R;
+import com.android.settingslib.media.flags.Flags;
import java.util.Arrays;
import java.util.HashMap;
@@ -31,16 +33,25 @@
/** A util class to get the appropriate icon for different device types. */
public class DeviceIconUtil {
+
+ // A default icon to use if the type is not present in the map.
+ @DrawableRes private static final int DEFAULT_ICON = R.drawable.ic_smartphone;
+ @DrawableRes private static final int DEFAULT_ICON_TV = R.drawable.ic_media_speaker_device;
+
// A map from a @AudioDeviceInfo.AudioDeviceType to full device information.
private final Map<Integer, Device> mAudioDeviceTypeToIconMap = new HashMap<>();
// A map from a @MediaRoute2Info.Type to full device information.
private final Map<Integer, Device> mMediaRouteTypeToIconMap = new HashMap<>();
- // A default icon to use if the type is not present in the map.
- @DrawableRes private static final int DEFAULT_ICON = R.drawable.ic_smartphone;
- public DeviceIconUtil() {
- List<Device> deviceList =
- Arrays.asList(
+ private final boolean mIsTv;
+
+ public DeviceIconUtil(Context context) {
+ this(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK));
+ }
+
+ public DeviceIconUtil(boolean isTv) {
+ mIsTv = isTv && Flags.enableTvMediaOutputDialog();
+ List<Device> deviceList = Arrays.asList(
new Device(
AudioDeviceInfo.TYPE_USB_DEVICE,
MediaRoute2Info.TYPE_USB_DEVICE,
@@ -52,7 +63,7 @@
new Device(
AudioDeviceInfo.TYPE_USB_ACCESSORY,
MediaRoute2Info.TYPE_USB_ACCESSORY,
- R.drawable.ic_headphone),
+ mIsTv ? R.drawable.ic_usb : R.drawable.ic_headphone),
new Device(
AudioDeviceInfo.TYPE_DOCK,
MediaRoute2Info.TYPE_DOCK,
@@ -60,29 +71,27 @@
new Device(
AudioDeviceInfo.TYPE_HDMI,
MediaRoute2Info.TYPE_HDMI,
- R.drawable.ic_headphone),
- // TODO: b/306359110 - Put proper iconography for HDMI_ARC type.
+ mIsTv ? R.drawable.ic_tv : R.drawable.ic_headphone),
new Device(
AudioDeviceInfo.TYPE_HDMI_ARC,
MediaRoute2Info.TYPE_HDMI_ARC,
- R.drawable.ic_headphone),
- // TODO: b/306359110 - Put proper iconography for HDMI_EARC type.
+ mIsTv ? R.drawable.ic_hdmi : R.drawable.ic_headphone),
new Device(
AudioDeviceInfo.TYPE_HDMI_EARC,
MediaRoute2Info.TYPE_HDMI_EARC,
- R.drawable.ic_headphone),
+ mIsTv ? R.drawable.ic_hdmi : R.drawable.ic_headphone),
new Device(
AudioDeviceInfo.TYPE_WIRED_HEADSET,
MediaRoute2Info.TYPE_WIRED_HEADSET,
- R.drawable.ic_headphone),
+ mIsTv ? R.drawable.ic_wired_device : R.drawable.ic_headphone),
new Device(
AudioDeviceInfo.TYPE_WIRED_HEADPHONES,
MediaRoute2Info.TYPE_WIRED_HEADPHONES,
- R.drawable.ic_headphone),
+ mIsTv ? R.drawable.ic_wired_device : R.drawable.ic_headphone),
new Device(
AudioDeviceInfo.TYPE_BUILTIN_SPEAKER,
MediaRoute2Info.TYPE_BUILTIN_SPEAKER,
- R.drawable.ic_smartphone));
+ mIsTv ? R.drawable.ic_tv : R.drawable.ic_smartphone));
for (int i = 0; i < deviceList.size(); i++) {
Device device = deviceList.get(i);
mAudioDeviceTypeToIconMap.put(device.mAudioDeviceType, device);
@@ -90,6 +99,10 @@
}
}
+ private int getDefaultIcon() {
+ return mIsTv ? DEFAULT_ICON_TV : DEFAULT_ICON;
+ }
+
/** Returns a drawable for an icon representing the given audioDeviceType. */
public Drawable getIconFromAudioDeviceType(
@AudioDeviceInfo.AudioDeviceType int audioDeviceType, Context context) {
@@ -103,7 +116,7 @@
if (mAudioDeviceTypeToIconMap.containsKey(audioDeviceType)) {
return mAudioDeviceTypeToIconMap.get(audioDeviceType).mIconDrawableRes;
}
- return DEFAULT_ICON;
+ return getDefaultIcon();
}
/** Returns a drawable res ID for an icon representing the given mediaRouteType. */
@@ -113,7 +126,7 @@
if (mMediaRouteTypeToIconMap.containsKey(mediaRouteType)) {
return mMediaRouteTypeToIconMap.get(mediaRouteType).mIconDrawableRes;
}
- return DEFAULT_ICON;
+ return getDefaultIcon();
}
private static class Device {
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
index c44f66e..80eeab5 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/PhoneMediaDevice.java
@@ -28,15 +28,24 @@
import static com.android.settingslib.media.MediaDevice.SelectionBehavior.SELECTION_BEHAVIOR_TRANSFER;
+import android.Manifest;
import android.annotation.NonNull;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
+import android.hardware.hdmi.HdmiControlManager;
+import android.hardware.hdmi.HdmiDeviceInfo;
+import android.hardware.hdmi.HdmiPortInfo;
import android.media.MediaRoute2Info;
import android.media.RouteListingPreference;
+import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settingslib.R;
+import com.android.settingslib.media.flags.Flags;
+
+import java.util.List;
/**
* PhoneMediaDevice extends MediaDevice to represents Phone device.
@@ -58,6 +67,7 @@
public static String getSystemRouteNameFromType(
@NonNull Context context, @NonNull MediaRoute2Info routeInfo) {
CharSequence name;
+ boolean isTv = isTv(context);
switch (routeInfo.getType()) {
case TYPE_WIRED_HEADSET:
case TYPE_WIRED_HEADPHONES:
@@ -73,9 +83,32 @@
name = context.getString(R.string.media_transfer_this_device_name);
break;
case TYPE_HDMI:
+ name = context.getString(isTv ? R.string.tv_media_transfer_default :
+ R.string.media_transfer_external_device_name);
+ break;
case TYPE_HDMI_ARC:
+ if (isTv) {
+ String deviceName = getHdmiOutDeviceName(context);
+ if (deviceName != null) {
+ name = deviceName;
+ } else {
+ name = context.getString(R.string.tv_media_transfer_arc_fallback_title);
+ }
+ } else {
+ name = context.getString(R.string.media_transfer_external_device_name);
+ }
+ break;
case TYPE_HDMI_EARC:
- name = context.getString(R.string.media_transfer_external_device_name);
+ if (isTv) {
+ String deviceName = getHdmiOutDeviceName(context);
+ if (deviceName != null) {
+ name = deviceName;
+ } else {
+ name = context.getString(R.string.tv_media_transfer_arc_fallback_title);
+ }
+ } else {
+ name = context.getString(R.string.media_transfer_external_device_name);
+ }
break;
default:
name = context.getString(R.string.media_transfer_default_device_name);
@@ -94,10 +127,15 @@
String packageName,
RouteListingPreference.Item item) {
super(context, info, packageName, item);
- mDeviceIconUtil = new DeviceIconUtil();
+ mDeviceIconUtil = new DeviceIconUtil(mContext);
initDeviceRecord();
}
+ static boolean isTv(Context context) {
+ return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)
+ && Flags.enableTvMediaOutputDialog();
+ }
+
// MediaRoute2Info.getType was made public on API 34, but exists since API 30.
@SuppressWarnings("NewApi")
@Override
@@ -111,9 +149,64 @@
return SELECTION_BEHAVIOR_TRANSFER;
}
+ private static String getHdmiOutDeviceName(Context context) {
+ HdmiControlManager hdmiControlManager;
+ if (context.checkCallingOrSelfPermission(Manifest.permission.HDMI_CEC)
+ == PackageManager.PERMISSION_GRANTED) {
+ hdmiControlManager = context.getSystemService(HdmiControlManager.class);
+ } else {
+ Log.w(TAG, "Could not get HDMI device name, android.permission.HDMI_CEC denied");
+ return null;
+ }
+
+ HdmiPortInfo hdmiOutputPortInfo = null;
+ for (HdmiPortInfo hdmiPortInfo : hdmiControlManager.getPortInfo()) {
+ if (hdmiPortInfo.getType() == HdmiPortInfo.PORT_OUTPUT) {
+ hdmiOutputPortInfo = hdmiPortInfo;
+ break;
+ }
+ }
+ if (hdmiOutputPortInfo == null) {
+ return null;
+ }
+ List<HdmiDeviceInfo> connectedDevices = hdmiControlManager.getConnectedDevices();
+ for (HdmiDeviceInfo deviceInfo : connectedDevices) {
+ if (deviceInfo.getPortId() == hdmiOutputPortInfo.getId()) {
+ String deviceName = deviceInfo.getDisplayName();
+ if (deviceName != null && !deviceName.isEmpty()) {
+ return deviceName;
+ }
+ }
+ }
+ return null;
+ }
+
@Override
public String getSummary() {
- return mSummary;
+ if (!isTv(mContext)) {
+ return mSummary;
+ }
+ switch (mRouteInfo.getType()) {
+ case TYPE_BUILTIN_SPEAKER:
+ return mContext.getString(R.string.tv_media_transfer_internal_speakers);
+ case TYPE_HDMI:
+ return mContext.getString(R.string.tv_media_transfer_hdmi);
+ case TYPE_HDMI_ARC:
+ if (getHdmiOutDeviceName(mContext) == null) {
+ // Connection type is already part of the title.
+ return mContext.getString(R.string.tv_media_transfer_connected);
+ }
+ return mContext.getString(R.string.tv_media_transfer_arc_subtitle);
+ case TYPE_HDMI_EARC:
+ if (getHdmiOutDeviceName(mContext) == null) {
+ // Connection type is already part of the title.
+ return mContext.getString(R.string.tv_media_transfer_connected);
+ }
+ return mContext.getString(R.string.tv_media_transfer_earc_subtitle);
+ default:
+ return null;
+ }
+
}
@Override
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/DeviceIconUtilTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/DeviceIconUtilTest.java
index 72dfc17..5669276 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/DeviceIconUtilTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/DeviceIconUtilTest.java
@@ -20,131 +20,309 @@
import android.media.AudioDeviceInfo;
import android.media.MediaRoute2Info;
+import android.platform.test.flag.junit.SetFlagsRule;
import com.android.settingslib.R;
+import com.android.settingslib.media.flags.Flags;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class DeviceIconUtilTest {
- private final DeviceIconUtil mDeviceIconUtil = new DeviceIconUtil();
+
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
+ @Before
+ public void setup() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TV_MEDIA_OUTPUT_DIALOG);
+ }
@Test
public void getIconResIdFromMediaRouteType_usbDevice_isHeadphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_DEVICE))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_DEVICE))
+ .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_DEVICE))
+ .isEqualTo(R.drawable.ic_headphone);
}
@Test
public void getIconResIdFromMediaRouteType_usbHeadset_isHeadphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_HEADSET))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_HEADSET))
+ .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_HEADSET))
+ .isEqualTo(R.drawable.ic_headphone);
}
@Test
public void getIconResIdFromMediaRouteType_usbAccessory_isHeadphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_ACCESSORY))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_ACCESSORY))
+ .isEqualTo(R.drawable.ic_headphone);
}
@Test
- public void getIconResIdFromMediaRouteType_dock_isHeadphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_DOCK))
- .isEqualTo(R.drawable.ic_headphone);
+ public void getIconResIdFromMediaRouteType_tv_usbAccessory_isUsb() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_USB_ACCESSORY))
+ .isEqualTo(R.drawable.ic_usb);
}
@Test
- public void getIconResIdFromMediaRouteType_hdmi_isHeadphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI))
- .isEqualTo(R.drawable.ic_headphone);
+ public void getIconResIdFromMediaRouteType_dock_isDock() {
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_DOCK))
+ .isEqualTo(R.drawable.ic_dock_device);
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_DOCK))
+ .isEqualTo(R.drawable.ic_dock_device);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_hdmi() {
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_tv_hdmi_isTv() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI))
+ .isEqualTo(R.drawable.ic_tv);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_hdmiArc_isHeadphone() {
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI_ARC))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_tv_hdmiArc_isHdmi() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI_ARC))
+ .isEqualTo(R.drawable.ic_hdmi);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_hdmiEarc_isHeadphone() {
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI_EARC))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_tv_hdmiEarc_isHdmi() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_HDMI_EARC))
+ .isEqualTo(R.drawable.ic_hdmi);
}
@Test
public void getIconResIdFromMediaRouteType_wiredHeadset_isHeadphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADSET))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADSET))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_tv_wiredHeadset_isWiredDevice() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADSET))
+ .isEqualTo(R.drawable.ic_wired_device);
}
@Test
public void getIconResIdFromMediaRouteType_wiredHeadphones_isHeadphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADPHONES))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADPHONES))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_tv_wiredHeadphones_isWiredDevice() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_WIRED_HEADPHONES))
+ .isEqualTo(R.drawable.ic_wired_device);
}
@Test
public void getIconResIdFromMediaRouteType_builtinSpeaker_isSmartphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER))
- .isEqualTo(R.drawable.ic_smartphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER))
+ .isEqualTo(R.drawable.ic_smartphone);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_tv_builtinSpeaker_isTv() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_BUILTIN_SPEAKER))
+ .isEqualTo(R.drawable.ic_tv);
}
@Test
public void getIconResIdFromMediaRouteType_unsupportedType_isSmartphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_UNKNOWN))
- .isEqualTo(R.drawable.ic_smartphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_UNKNOWN))
+ .isEqualTo(R.drawable.ic_smartphone);
+ }
+
+ @Test
+ public void getIconResIdFromMediaRouteType_tv_unsupportedType_isSpeaker() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromMediaRouteType(MediaRoute2Info.TYPE_UNKNOWN))
+ .isEqualTo(R.drawable.ic_media_speaker_device);
}
@Test
public void getIconResIdFromAudioDeviceType_usbDevice_isHeadphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_DEVICE))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_DEVICE))
+ .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_DEVICE))
+ .isEqualTo(R.drawable.ic_headphone);
}
@Test
public void getIconResIdFromAudioDeviceType_usbHeadset_isHeadphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_HEADSET))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_HEADSET))
+ .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_HEADSET))
+ .isEqualTo(R.drawable.ic_headphone);
}
@Test
public void getIconResIdFromAudioDeviceType_usbAccessory_isHeadphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_ACCESSORY))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_ACCESSORY))
+ .isEqualTo(R.drawable.ic_headphone);
}
@Test
- public void getIconResIdFromAudioDeviceType_dock_isHeadphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_DOCK))
- .isEqualTo(R.drawable.ic_headphone);
+ public void getIconResIdFromAudioDeviceType_tv_usbAccessory_isUsb() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_USB_ACCESSORY))
+ .isEqualTo(R.drawable.ic_usb);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_dock_isDock() {
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_DOCK))
+ .isEqualTo(R.drawable.ic_dock_device);
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_DOCK))
+ .isEqualTo(R.drawable.ic_dock_device);
}
@Test
public void getIconResIdFromAudioDeviceType_hdmi_isHeadphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_tv_hdmi_isTv() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI))
+ .isEqualTo(R.drawable.ic_tv);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_hdmiArc_isHeadphone() {
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI_ARC))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_hdmiArc_isHdmi() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI_ARC))
+ .isEqualTo(R.drawable.ic_hdmi);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_hdmiEarc_isHeadphone() {
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI_EARC))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_tv_hdmiEarc() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_HDMI_EARC))
+ .isEqualTo(R.drawable.ic_hdmi);
}
@Test
public void getIconResIdFromAudioDeviceType_wiredHeadset_isHeadphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADSET))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADSET))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_tv_wiredHeadset_isWiredDevice() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADSET))
+ .isEqualTo(R.drawable.ic_wired_device);
}
@Test
public void getIconResIdFromAudioDeviceType_wiredHeadphones_isHeadphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADPHONES))
- .isEqualTo(R.drawable.ic_headphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADPHONES))
+ .isEqualTo(R.drawable.ic_headphone);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_tv_wiredHeadphones_isWiredDevice() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_WIRED_HEADPHONES))
+ .isEqualTo(R.drawable.ic_wired_device);
}
@Test
public void getIconResIdFromAudioDeviceType_builtinSpeaker_isSmartphone() {
- assertThat(
- mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER))
- .isEqualTo(R.drawable.ic_smartphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER))
+ .isEqualTo(R.drawable.ic_smartphone);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_tv_builtinSpeaker_isTv() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER))
+ .isEqualTo(R.drawable.ic_tv);
}
@Test
public void getIconResIdFromAudioDeviceType_unsupportedType_isSmartphone() {
- assertThat(mDeviceIconUtil.getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_UNKNOWN))
- .isEqualTo(R.drawable.ic_smartphone);
+ assertThat(new DeviceIconUtil(/* isTv */ false)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_UNKNOWN))
+ .isEqualTo(R.drawable.ic_smartphone);
+ }
+
+ @Test
+ public void getIconResIdFromAudioDeviceType_tv_unsupportedType_isSpeaker() {
+ assertThat(new DeviceIconUtil(/* isTv */ true)
+ .getIconResIdFromAudioDeviceType(AudioDeviceInfo.TYPE_UNKNOWN))
+ .isEqualTo(R.drawable.ic_media_speaker_device);
}
}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/EdgeDetector.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/EdgeDetector.kt
new file mode 100644
index 0000000..82d4239
--- /dev/null
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/EdgeDetector.kt
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.compose.animation.scene
+
+import androidx.compose.foundation.gestures.Orientation
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.IntOffset
+import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.unit.dp
+
+interface EdgeDetector {
+ /**
+ * Return the [Edge] associated to [position] inside a layout of size [layoutSize], given
+ * [density] and [orientation].
+ */
+ fun edge(
+ layoutSize: IntSize,
+ position: IntOffset,
+ density: Density,
+ orientation: Orientation,
+ ): Edge?
+}
+
+val DefaultEdgeDetector = FixedSizeEdgeDetector(40.dp)
+
+/** An [EdgeDetector] that detects edges assuming a fixed edge size of [size]. */
+class FixedSizeEdgeDetector(val size: Dp) : EdgeDetector {
+ override fun edge(
+ layoutSize: IntSize,
+ position: IntOffset,
+ density: Density,
+ orientation: Orientation,
+ ): Edge? {
+ val axisSize: Int
+ val axisPosition: Int
+ val topOrLeft: Edge
+ val bottomOrRight: Edge
+ when (orientation) {
+ Orientation.Horizontal -> {
+ axisSize = layoutSize.width
+ axisPosition = position.x
+ topOrLeft = Edge.Left
+ bottomOrRight = Edge.Right
+ }
+ Orientation.Vertical -> {
+ axisSize = layoutSize.height
+ axisPosition = position.y
+ topOrLeft = Edge.Top
+ bottomOrRight = Edge.Bottom
+ }
+ }
+
+ val sizePx = with(density) { size.toPx() }
+ return when {
+ axisPosition <= sizePx -> topOrLeft
+ axisPosition >= axisSize - sizePx -> bottomOrRight
+ else -> null
+ }
+ }
+}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/GestureHandler.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/GestureHandler.kt
index d005413..ae7d8f5 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/GestureHandler.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/GestureHandler.kt
@@ -2,7 +2,6 @@
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
-import kotlinx.coroutines.CoroutineScope
interface GestureHandler {
val draggable: DraggableHandler
@@ -10,9 +9,9 @@
}
interface DraggableHandler {
- suspend fun onDragStarted(coroutineScope: CoroutineScope, startedPosition: Offset)
+ fun onDragStarted(startedPosition: Offset, pointersDown: Int = 1)
fun onDelta(pixels: Float)
- suspend fun onDragStopped(coroutineScope: CoroutineScope, velocity: Float)
+ fun onDragStopped(velocity: Float)
}
interface NestedScrollHandler {
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt
new file mode 100644
index 0000000..97d3fff
--- /dev/null
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/MultiPointerDraggable.kt
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.compose.animation.scene
+
+import androidx.compose.foundation.gestures.Orientation
+import androidx.compose.foundation.gestures.awaitEachGesture
+import androidx.compose.foundation.gestures.awaitFirstDown
+import androidx.compose.foundation.gestures.awaitHorizontalTouchSlopOrCancellation
+import androidx.compose.foundation.gestures.awaitVerticalTouchSlopOrCancellation
+import androidx.compose.foundation.gestures.horizontalDrag
+import androidx.compose.foundation.gestures.verticalDrag
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberUpdatedState
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.input.pointer.PointerEventPass
+import androidx.compose.ui.input.pointer.PointerId
+import androidx.compose.ui.input.pointer.PointerInputChange
+import androidx.compose.ui.input.pointer.PointerInputScope
+import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.input.pointer.positionChange
+import androidx.compose.ui.input.pointer.util.VelocityTracker
+import androidx.compose.ui.input.pointer.util.addPointerInputChange
+import androidx.compose.ui.platform.LocalViewConfiguration
+import androidx.compose.ui.unit.Velocity
+import androidx.compose.ui.util.fastForEach
+
+/**
+ * Make an element draggable in the given [orientation].
+ *
+ * The main difference with [multiPointerDraggable] and
+ * [androidx.compose.foundation.gestures.draggable] is that [onDragStarted] also receives the number
+ * of pointers that are down when the drag is started. If you don't need this information, you
+ * should use `draggable` instead.
+ *
+ * Note that the current implementation is trivial: we wait for the touch slope on the *first* down
+ * pointer, then we count the number of distinct pointers that are down right before calling
+ * [onDragStarted]. This means that the drag won't start when a first pointer is down (but not
+ * dragged) and a second pointer is down and dragged. This is an implementation detail that might
+ * change in the future.
+ */
+// TODO(b/291055080): Migrate to the Modifier.Node API.
+@Composable
+internal fun Modifier.multiPointerDraggable(
+ orientation: Orientation,
+ enabled: Boolean,
+ startDragImmediately: Boolean,
+ onDragStarted: (startedPosition: Offset, pointersDown: Int) -> Unit,
+ onDragDelta: (Float) -> Unit,
+ onDragStopped: (velocity: Float) -> Unit,
+): Modifier {
+ val onDragStarted by rememberUpdatedState(onDragStarted)
+ val onDragStopped by rememberUpdatedState(onDragStopped)
+ val onDragDelta by rememberUpdatedState(onDragDelta)
+ val startDragImmediately by rememberUpdatedState(startDragImmediately)
+
+ val velocityTracker = remember { VelocityTracker() }
+ val maxFlingVelocity =
+ LocalViewConfiguration.current.maximumFlingVelocity.let { max ->
+ val maxF = max.toFloat()
+ Velocity(maxF, maxF)
+ }
+
+ return this.pointerInput(enabled, orientation, maxFlingVelocity) {
+ if (!enabled) {
+ return@pointerInput
+ }
+
+ val onDragStart: (Offset, Int) -> Unit = { startedPosition, pointersDown ->
+ velocityTracker.resetTracking()
+ onDragStarted(startedPosition, pointersDown)
+ }
+
+ val onDragCancel: () -> Unit = { onDragStopped(/* velocity= */ 0f) }
+
+ val onDragEnd: () -> Unit = {
+ val velocity = velocityTracker.calculateVelocity(maxFlingVelocity)
+ onDragStopped(
+ when (orientation) {
+ Orientation.Horizontal -> velocity.x
+ Orientation.Vertical -> velocity.y
+ }
+ )
+ }
+
+ val onDrag: (change: PointerInputChange, dragAmount: Float) -> Unit = { change, amount ->
+ velocityTracker.addPointerInputChange(change)
+ onDragDelta(amount)
+ }
+
+ detectDragGestures(
+ orientation = orientation,
+ startDragImmediately = { startDragImmediately },
+ onDragStart = onDragStart,
+ onDragEnd = onDragEnd,
+ onDragCancel = onDragCancel,
+ onDrag = onDrag,
+ )
+ }
+}
+
+/**
+ * Detect drag gestures in the given [orientation].
+ *
+ * This function is a mix of [androidx.compose.foundation.gestures.awaitDownAndSlop] and
+ * [androidx.compose.foundation.gestures.detectVerticalDragGestures] to add support for:
+ * 1) starting the gesture immediately without requiring a drag >= touch slope;
+ * 2) passing the number of pointers down to [onDragStart].
+ */
+private suspend fun PointerInputScope.detectDragGestures(
+ orientation: Orientation,
+ startDragImmediately: () -> Boolean,
+ onDragStart: (startedPosition: Offset, pointersDown: Int) -> Unit,
+ onDragEnd: () -> Unit,
+ onDragCancel: () -> Unit,
+ onDrag: (change: PointerInputChange, dragAmount: Float) -> Unit,
+) {
+ awaitEachGesture {
+ val initialDown = awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Initial)
+ var overSlop = 0f
+ val drag =
+ if (startDragImmediately()) {
+ initialDown.consume()
+ initialDown
+ } else {
+ val down = awaitFirstDown(requireUnconsumed = false)
+ val onSlopReached = { change: PointerInputChange, over: Float ->
+ change.consume()
+ overSlop = over
+ }
+
+ // TODO(b/291055080): Replace by await[Orientation]PointerSlopOrCancellation once
+ // it is public.
+ when (orientation) {
+ Orientation.Horizontal ->
+ awaitHorizontalTouchSlopOrCancellation(down.id, onSlopReached)
+ Orientation.Vertical ->
+ awaitVerticalTouchSlopOrCancellation(down.id, onSlopReached)
+ }
+ }
+
+ if (drag != null) {
+ // Count the number of pressed pointers.
+ val pressed = mutableSetOf<PointerId>()
+ currentEvent.changes.fastForEach { change ->
+ if (change.pressed) {
+ pressed.add(change.id)
+ }
+ }
+
+ onDragStart(drag.position, pressed.size)
+ onDrag(drag, overSlop)
+
+ val successful =
+ when (orientation) {
+ Orientation.Horizontal ->
+ horizontalDrag(drag.id) {
+ onDrag(it, it.positionChange().x)
+ it.consume()
+ }
+ Orientation.Vertical ->
+ verticalDrag(drag.id) {
+ onDrag(it, it.positionChange().y)
+ it.consume()
+ }
+ }
+
+ if (successful) {
+ onDragEnd()
+ } else {
+ onDragCancel()
+ }
+ }
+ }
+}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Scene.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Scene.kt
index 9c799b28..3fd6828 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Scene.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Scene.kt
@@ -16,7 +16,6 @@
package com.android.compose.animation.scene
-import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
@@ -101,19 +100,3 @@
MovableElement(layoutImpl, scene, key, modifier, content)
}
}
-
-/** The destination scene when swiping up or left from [upOrLeft]. */
-internal fun Scene.upOrLeft(orientation: Orientation): SceneKey? {
- return when (orientation) {
- Orientation.Vertical -> userActions[Swipe.Up]
- Orientation.Horizontal -> userActions[Swipe.Left]
- }
-}
-
-/** The destination scene when swiping down or right from [downOrRight]. */
-internal fun Scene.downOrRight(orientation: Orientation): SceneKey? {
- return when (orientation) {
- Orientation.Vertical -> userActions[Swipe.Down]
- Orientation.Horizontal -> userActions[Swipe.Right]
- }
-}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayout.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayout.kt
index 74e66d2..1f38e70 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayout.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayout.kt
@@ -16,6 +16,7 @@
package com.android.compose.animation.scene
+import androidx.compose.foundation.gestures.Orientation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.remember
@@ -37,6 +38,7 @@
* instance by triggering back navigation or by swiping to a new scene.
* @param transitions the definition of the transitions used to animate a change of scene.
* @param state the observable state of this layout.
+ * @param edgeDetector the edge detector used to detect which edge a swipe is started from, if any.
* @param scenes the configuration of the different scenes of this layout.
*/
@Composable
@@ -46,6 +48,7 @@
transitions: SceneTransitions,
modifier: Modifier = Modifier,
state: SceneTransitionLayoutState = remember { SceneTransitionLayoutState(currentScene) },
+ edgeDetector: EdgeDetector = DefaultEdgeDetector,
scenes: SceneTransitionLayoutScope.() -> Unit,
) {
val density = LocalDensity.current
@@ -56,15 +59,17 @@
transitions,
state,
density,
+ edgeDetector,
)
}
layoutImpl.onChangeScene = onChangeScene
layoutImpl.transitions = transitions
layoutImpl.density = density
+ layoutImpl.edgeDetector = edgeDetector
+
layoutImpl.setScenes(scenes)
layoutImpl.setCurrentScene(currentScene)
-
layoutImpl.Content(modifier)
}
@@ -191,9 +196,9 @@
}
}
-enum class SwipeDirection {
- Up,
- Down,
- Left,
- Right,
+enum class SwipeDirection(val orientation: Orientation) {
+ Up(Orientation.Vertical),
+ Down(Orientation.Vertical),
+ Left(Orientation.Horizontal),
+ Right(Orientation.Horizontal),
}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayoutImpl.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayoutImpl.kt
index a40b299..fd62659 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayoutImpl.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayoutImpl.kt
@@ -37,7 +37,7 @@
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntSize
-import com.android.compose.ui.util.fastForEach
+import androidx.compose.ui.util.fastForEach
import kotlinx.coroutines.channels.Channel
@VisibleForTesting
@@ -47,6 +47,7 @@
transitions: SceneTransitions,
internal val state: SceneTransitionLayoutState,
density: Density,
+ edgeDetector: EdgeDetector,
) {
internal val scenes = SnapshotStateMap<SceneKey, Scene>()
internal val elements = SnapshotStateMap<ElementKey, Element>()
@@ -57,6 +58,7 @@
internal var onChangeScene by mutableStateOf(onChangeScene)
internal var transitions by mutableStateOf(transitions)
internal var density: Density by mutableStateOf(density)
+ internal var edgeDetector by mutableStateOf(edgeDetector)
/**
* The size of this layout. Note that this could be [IntSize.Zero] if this layour does not have
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitions.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitions.kt
index 75dcb2e..b163a2a 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitions.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitions.kt
@@ -21,6 +21,8 @@
import androidx.compose.animation.core.snap
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.util.fastForEach
+import androidx.compose.ui.util.fastMap
import com.android.compose.animation.scene.transformation.AnchoredSize
import com.android.compose.animation.scene.transformation.AnchoredTranslate
import com.android.compose.animation.scene.transformation.EdgeTranslate
@@ -32,8 +34,6 @@
import com.android.compose.animation.scene.transformation.SharedElementTransformation
import com.android.compose.animation.scene.transformation.Transformation
import com.android.compose.animation.scene.transformation.Translate
-import com.android.compose.ui.util.fastForEach
-import com.android.compose.ui.util.fastMap
/** The transitions configuration of a [SceneTransitionLayout]. */
class SceneTransitions(
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeToScene.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeToScene.kt
index 2dc53ab..8b79c28 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeToScene.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SwipeToScene.kt
@@ -22,8 +22,6 @@
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.gestures.Orientation
-import androidx.compose.foundation.gestures.draggable
-import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
@@ -37,6 +35,7 @@
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.round
import com.android.compose.nestedscroll.PriorityNestedScrollConnection
import kotlin.math.absoluteValue
import kotlinx.coroutines.CoroutineScope
@@ -55,7 +54,7 @@
/** Whether swipe should be enabled in the given [orientation]. */
fun Scene.shouldEnableSwipes(orientation: Orientation): Boolean =
- upOrLeft(orientation) != null || downOrRight(orientation) != null
+ userActions.keys.any { it is Swipe && it.direction.orientation == orientation }
val currentScene = gestureHandler.currentScene
val canSwipe = currentScene.shouldEnableSwipes(orientation)
@@ -68,8 +67,7 @@
)
return nestedScroll(connection = gestureHandler.nestedScroll.connection)
- .draggable(
- state = rememberDraggableState(onDelta = gestureHandler.draggable::onDelta),
+ .multiPointerDraggable(
orientation = orientation,
enabled = gestureHandler.isDrivingTransition || canSwipe,
// Immediately start the drag if this our [transition] is currently animating to a scene
@@ -80,6 +78,7 @@
gestureHandler.isAnimatingOffset &&
!canOppositeSwipe,
onDragStarted = gestureHandler.draggable::onDragStarted,
+ onDragDelta = gestureHandler.draggable::onDelta,
onDragStopped = gestureHandler.draggable::onDragStopped,
)
}
@@ -159,7 +158,7 @@
internal var gestureWithPriority: Any? = null
- internal fun onDragStarted() {
+ internal fun onDragStarted(pointersDown: Int, startedPosition: Offset?) {
if (isDrivingTransition) {
// This [transition] was already driving the animation: simply take over it.
// Stop animating and start from where the current offset.
@@ -199,6 +198,48 @@
Orientation.Vertical -> layoutImpl.size.height
}.toFloat()
+ val fromEdge =
+ startedPosition?.let { position ->
+ layoutImpl.edgeDetector.edge(
+ layoutImpl.size,
+ position.round(),
+ layoutImpl.density,
+ orientation,
+ )
+ }
+
+ swipeTransition.actionUpOrLeft =
+ Swipe(
+ direction =
+ when (orientation) {
+ Orientation.Horizontal -> SwipeDirection.Left
+ Orientation.Vertical -> SwipeDirection.Up
+ },
+ pointerCount = pointersDown,
+ fromEdge = fromEdge,
+ )
+
+ swipeTransition.actionDownOrRight =
+ Swipe(
+ direction =
+ when (orientation) {
+ Orientation.Horizontal -> SwipeDirection.Right
+ Orientation.Vertical -> SwipeDirection.Down
+ },
+ pointerCount = pointersDown,
+ fromEdge = fromEdge,
+ )
+
+ if (fromEdge == null) {
+ swipeTransition.actionUpOrLeftNoEdge = null
+ swipeTransition.actionDownOrRightNoEdge = null
+ } else {
+ swipeTransition.actionUpOrLeftNoEdge =
+ (swipeTransition.actionUpOrLeft as Swipe).copy(fromEdge = null)
+ swipeTransition.actionDownOrRightNoEdge =
+ (swipeTransition.actionDownOrRight as Swipe).copy(fromEdge = null)
+ }
+
if (swipeTransition.absoluteDistance > 0f) {
transitionState = swipeTransition
}
@@ -246,11 +287,11 @@
// to the next screen or go back to the previous one.
val offset = swipeTransition.dragOffset
val absoluteDistance = swipeTransition.absoluteDistance
- if (offset <= -absoluteDistance && fromScene.upOrLeft(orientation) == toScene.key) {
+ if (offset <= -absoluteDistance && swipeTransition.upOrLeft(fromScene) == toScene.key) {
swipeTransition.dragOffset += absoluteDistance
swipeTransition._fromScene = toScene
} else if (
- offset >= absoluteDistance && fromScene.downOrRight(orientation) == toScene.key
+ offset >= absoluteDistance && swipeTransition.downOrRight(fromScene) == toScene.key
) {
swipeTransition.dragOffset -= absoluteDistance
swipeTransition._fromScene = toScene
@@ -266,27 +307,21 @@
)
private fun Scene.findTargetSceneAndDistance(directionOffset: Float): TargetScene {
- val maxDistance =
- when (orientation) {
- Orientation.Horizontal -> layoutImpl.size.width
- Orientation.Vertical -> layoutImpl.size.height
- }.toFloat()
-
- val upOrLeft = upOrLeft(orientation)
- val downOrRight = downOrRight(orientation)
+ val upOrLeft = swipeTransition.upOrLeft(this)
+ val downOrRight = swipeTransition.downOrRight(this)
// Compute the target scene depending on the current offset.
return when {
directionOffset < 0f && upOrLeft != null -> {
TargetScene(
sceneKey = upOrLeft,
- distance = -maxDistance,
+ distance = -swipeTransition.absoluteDistance,
)
}
directionOffset > 0f && downOrRight != null -> {
TargetScene(
sceneKey = downOrRight,
- distance = maxDistance,
+ distance = swipeTransition.absoluteDistance,
)
}
else -> {
@@ -516,6 +551,22 @@
var _distance by mutableFloatStateOf(0f)
val distance: Float
get() = _distance
+
+ /** The [UserAction]s associated to this swipe. */
+ var actionUpOrLeft: UserAction = Back
+ var actionDownOrRight: UserAction = Back
+ var actionUpOrLeftNoEdge: UserAction? = null
+ var actionDownOrRightNoEdge: UserAction? = null
+
+ fun upOrLeft(scene: Scene): SceneKey? {
+ return scene.userActions[actionUpOrLeft]
+ ?: actionUpOrLeftNoEdge?.let { scene.userActions[it] }
+ }
+
+ fun downOrRight(scene: Scene): SceneKey? {
+ return scene.userActions[actionDownOrRight]
+ ?: actionDownOrRightNoEdge?.let { scene.userActions[it] }
+ }
}
companion object {
@@ -526,9 +577,9 @@
private class SceneDraggableHandler(
private val gestureHandler: SceneGestureHandler,
) : DraggableHandler {
- override suspend fun onDragStarted(coroutineScope: CoroutineScope, startedPosition: Offset) {
+ override fun onDragStarted(startedPosition: Offset, pointersDown: Int) {
gestureHandler.gestureWithPriority = this
- gestureHandler.onDragStarted()
+ gestureHandler.onDragStarted(pointersDown, startedPosition)
}
override fun onDelta(pixels: Float) {
@@ -537,7 +588,7 @@
}
}
- override suspend fun onDragStopped(coroutineScope: CoroutineScope, velocity: Float) {
+ override fun onDragStopped(velocity: Float) {
if (gestureHandler.gestureWithPriority == this) {
gestureHandler.gestureWithPriority = null
gestureHandler.onDragStopped(velocity = velocity, canChangeScene = true)
@@ -580,11 +631,31 @@
// moving on to the next scene.
var gestureStartedOnNestedChild = false
+ val actionUpOrLeft =
+ Swipe(
+ direction =
+ when (gestureHandler.orientation) {
+ Orientation.Horizontal -> SwipeDirection.Left
+ Orientation.Vertical -> SwipeDirection.Up
+ },
+ pointerCount = 1,
+ )
+
+ val actionDownOrRight =
+ Swipe(
+ direction =
+ when (gestureHandler.orientation) {
+ Orientation.Horizontal -> SwipeDirection.Right
+ Orientation.Vertical -> SwipeDirection.Down
+ },
+ pointerCount = 1,
+ )
+
fun findNextScene(amount: Float): SceneKey? {
val fromScene = gestureHandler.currentScene
return when {
- amount < 0f -> fromScene.upOrLeft(gestureHandler.orientation)
- amount > 0f -> fromScene.downOrRight(gestureHandler.orientation)
+ amount < 0f -> fromScene.userActions[actionUpOrLeft]
+ amount > 0f -> fromScene.userActions[actionDownOrRight]
else -> null
}
}
@@ -625,7 +696,7 @@
onStart = {
gestureHandler.gestureWithPriority = this
priorityScene = nextScene
- gestureHandler.onDragStarted()
+ gestureHandler.onDragStarted(pointersDown = 1, startedPosition = null)
},
onScroll = { offsetAvailable ->
if (gestureHandler.gestureWithPriority != this) {
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/ui/util/ListUtils.kt b/packages/SystemUI/compose/scene/src/com/android/compose/ui/util/ListUtils.kt
deleted file mode 100644
index 741f00d..0000000
--- a/packages/SystemUI/compose/scene/src/com/android/compose/ui/util/ListUtils.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.compose.ui.util
-
-import kotlin.contracts.ExperimentalContracts
-import kotlin.contracts.contract
-
-/**
- * Iterates through a [List] using the index and calls [action] for each item. This does not
- * allocate an iterator like [Iterable.forEach].
- *
- * **Do not use for collections that come from public APIs**, since they may not support random
- * access in an efficient way, and this method may actually be a lot slower. Only use for
- * collections that are created by code we control and are known to support random access.
- */
-@Suppress("BanInlineOptIn")
-@OptIn(ExperimentalContracts::class)
-internal inline fun <T> List<T>.fastForEach(action: (T) -> Unit) {
- contract { callsInPlace(action) }
- for (index in indices) {
- val item = get(index)
- action(item)
- }
-}
-
-/**
- * Returns a list containing the results of applying the given [transform] function to each element
- * in the original collection.
- *
- * **Do not use for collections that come from public APIs**, since they may not support random
- * access in an efficient way, and this method may actually be a lot slower. Only use for
- * collections that are created by code we control and are known to support random access.
- */
-@Suppress("BanInlineOptIn")
-@OptIn(ExperimentalContracts::class)
-internal inline fun <T, R> List<T>.fastMap(transform: (T) -> R): List<R> {
- contract { callsInPlace(transform) }
- val target = ArrayList<R>(size)
- fastForEach { target += transform(it) }
- return target
-}
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/FixedSizeEdgeDetectorTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/FixedSizeEdgeDetectorTest.kt
new file mode 100644
index 0000000..a68282a
--- /dev/null
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/FixedSizeEdgeDetectorTest.kt
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.compose.animation.scene
+
+import androidx.compose.foundation.gestures.Orientation
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.IntOffset
+import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.unit.dp
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class FixedSizeEdgeDetectorTest {
+ private val detector = FixedSizeEdgeDetector(30.dp)
+ private val layoutSize = IntSize(100, 100)
+ private val density = Density(1f)
+
+ @Test
+ fun horizontalEdges() {
+ fun horizontalEdge(position: Int): Edge? =
+ detector.edge(
+ layoutSize,
+ position = IntOffset(position, 0),
+ density,
+ Orientation.Horizontal,
+ )
+
+ assertThat(horizontalEdge(0)).isEqualTo(Edge.Left)
+ assertThat(horizontalEdge(30)).isEqualTo(Edge.Left)
+ assertThat(horizontalEdge(31)).isEqualTo(null)
+ assertThat(horizontalEdge(69)).isEqualTo(null)
+ assertThat(horizontalEdge(70)).isEqualTo(Edge.Right)
+ assertThat(horizontalEdge(100)).isEqualTo(Edge.Right)
+ }
+
+ @Test
+ fun verticalEdges() {
+ fun verticalEdge(position: Int): Edge? =
+ detector.edge(
+ layoutSize,
+ position = IntOffset(0, position),
+ density,
+ Orientation.Vertical,
+ )
+
+ assertThat(verticalEdge(0)).isEqualTo(Edge.Top)
+ assertThat(verticalEdge(30)).isEqualTo(Edge.Top)
+ assertThat(verticalEdge(31)).isEqualTo(null)
+ assertThat(verticalEdge(69)).isEqualTo(null)
+ assertThat(verticalEdge(70)).isEqualTo(Edge.Bottom)
+ assertThat(verticalEdge(100)).isEqualTo(Edge.Bottom)
+ }
+}
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneGestureHandlerTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneGestureHandlerTest.kt
index 6791a85..1eb3392 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneGestureHandlerTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneGestureHandlerTest.kt
@@ -55,7 +55,8 @@
builder = scenesBuilder,
transitions = EmptyTestTransitions,
state = layoutState,
- density = Density(1f)
+ density = Density(1f),
+ edgeDetector = DefaultEdgeDetector,
)
.also { it.size = IntSize(SCREEN_SIZE.toInt(), SCREEN_SIZE.toInt()) },
orientation = Orientation.Vertical,
@@ -104,13 +105,13 @@
@Test
fun onDragStarted_shouldStartATransition() = runGestureTest {
- draggable.onDragStarted(coroutineScope = coroutineScope, startedPosition = Offset.Zero)
+ draggable.onDragStarted(startedPosition = Offset.Zero)
assertScene(currentScene = SceneA, isIdle = false)
}
@Test
fun afterSceneTransitionIsStarted_interceptDragEvents() = runGestureTest {
- draggable.onDragStarted(coroutineScope = coroutineScope, startedPosition = Offset.Zero)
+ draggable.onDragStarted(startedPosition = Offset.Zero)
assertScene(currentScene = SceneA, isIdle = false)
val transition = transitionState as Transition
@@ -123,14 +124,13 @@
@Test
fun onDragStoppedAfterDrag_velocityLowerThanThreshold_remainSameScene() = runGestureTest {
- draggable.onDragStarted(coroutineScope = coroutineScope, startedPosition = Offset.Zero)
+ draggable.onDragStarted(startedPosition = Offset.Zero)
assertScene(currentScene = SceneA, isIdle = false)
draggable.onDelta(pixels = deltaInPixels10)
assertScene(currentScene = SceneA, isIdle = false)
draggable.onDragStopped(
- coroutineScope = coroutineScope,
velocity = velocityThreshold - 0.01f,
)
assertScene(currentScene = SceneA, isIdle = false)
@@ -142,14 +142,13 @@
@Test
fun onDragStoppedAfterDrag_velocityAtLeastThreshold_goToNextScene() = runGestureTest {
- draggable.onDragStarted(coroutineScope = coroutineScope, startedPosition = Offset.Zero)
+ draggable.onDragStarted(startedPosition = Offset.Zero)
assertScene(currentScene = SceneA, isIdle = false)
draggable.onDelta(pixels = deltaInPixels10)
assertScene(currentScene = SceneA, isIdle = false)
draggable.onDragStopped(
- coroutineScope = coroutineScope,
velocity = velocityThreshold,
)
assertScene(currentScene = SceneC, isIdle = false)
@@ -161,23 +160,22 @@
@Test
fun onDragStoppedAfterStarted_returnImmediatelyToIdle() = runGestureTest {
- draggable.onDragStarted(coroutineScope = coroutineScope, startedPosition = Offset.Zero)
+ draggable.onDragStarted(startedPosition = Offset.Zero)
assertScene(currentScene = SceneA, isIdle = false)
- draggable.onDragStopped(coroutineScope = coroutineScope, velocity = 0f)
+ draggable.onDragStopped(velocity = 0f)
assertScene(currentScene = SceneA, isIdle = true)
}
@Test
fun startGestureDuringAnimatingOffset_shouldImmediatelyStopTheAnimation() = runGestureTest {
- draggable.onDragStarted(coroutineScope = coroutineScope, startedPosition = Offset.Zero)
+ draggable.onDragStarted(startedPosition = Offset.Zero)
assertScene(currentScene = SceneA, isIdle = false)
draggable.onDelta(pixels = deltaInPixels10)
assertScene(currentScene = SceneA, isIdle = false)
draggable.onDragStopped(
- coroutineScope = coroutineScope,
velocity = velocityThreshold,
)
@@ -191,7 +189,7 @@
assertScene(currentScene = SceneC, isIdle = false)
// Start a new gesture while the offset is animating
- draggable.onDragStarted(coroutineScope = coroutineScope, startedPosition = Offset.Zero)
+ draggable.onDragStarted(startedPosition = Offset.Zero)
assertThat(sceneGestureHandler.isAnimatingOffset).isFalse()
}
@@ -320,7 +318,7 @@
}
@Test
fun beforeDraggableStart_stop_shouldBeIgnored() = runGestureTest {
- draggable.onDragStopped(coroutineScope, velocityThreshold)
+ draggable.onDragStopped(velocityThreshold)
assertScene(currentScene = SceneA, isIdle = true)
}
@@ -332,7 +330,7 @@
@Test
fun startNestedScrollWhileDragging() = runGestureTest {
- draggable.onDragStarted(coroutineScope, Offset.Zero)
+ draggable.onDragStarted(Offset.Zero)
assertScene(currentScene = SceneA, isIdle = false)
val transition = transitionState as Transition
@@ -344,7 +342,7 @@
assertThat(transition.progress).isEqualTo(0.2f)
// this should be ignored, we are scrolling now!
- draggable.onDragStopped(coroutineScope, velocityThreshold)
+ draggable.onDragStopped(velocityThreshold)
assertScene(currentScene = SceneA, isIdle = false)
nestedScrollEvents(available = offsetY10)
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SwipeToSceneTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SwipeToSceneTest.kt
index df3b72a..4a6066f 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SwipeToSceneTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SwipeToSceneTest.kt
@@ -48,6 +48,14 @@
/** The middle of the layout, in pixels. */
private val Density.middle: Offset
get() = Offset((LayoutWidth / 2).toPx(), (LayoutHeight / 2).toPx())
+
+ /** The middle-top of the layout, in pixels. */
+ private val Density.middleTop: Offset
+ get() = Offset((LayoutWidth / 2).toPx(), 0f)
+
+ /** The middle-left of the layout, in pixels. */
+ private val Density.middleLeft: Offset
+ get() = Offset(0f, (LayoutHeight / 2).toPx())
}
private var currentScene by mutableStateOf(TestScenes.SceneA)
@@ -83,7 +91,13 @@
}
scene(
TestScenes.SceneC,
- userActions = mapOf(Swipe.Down to TestScenes.SceneA),
+ userActions =
+ mapOf(
+ Swipe.Down to TestScenes.SceneA,
+ Swipe(SwipeDirection.Down, pointerCount = 2) to TestScenes.SceneB,
+ Swipe(SwipeDirection.Right, fromEdge = Edge.Left) to TestScenes.SceneB,
+ Swipe(SwipeDirection.Down, fromEdge = Edge.Top) to TestScenes.SceneB,
+ ),
) {
Box(Modifier.fillMaxSize())
}
@@ -242,4 +256,100 @@
assertThat(layoutState.transitionState).isInstanceOf(TransitionState.Idle::class.java)
assertThat(layoutState.transitionState.currentScene).isEqualTo(TestScenes.SceneC)
}
+
+ @Test
+ fun multiPointerSwipe() {
+ // Start at scene C.
+ currentScene = TestScenes.SceneC
+
+ // The draggable touch slop, i.e. the min px distance a touch pointer must move before it is
+ // detected as a drag event.
+ var touchSlop = 0f
+ rule.setContent {
+ touchSlop = LocalViewConfiguration.current.touchSlop
+ TestContent()
+ }
+
+ assertThat(layoutState.transitionState).isInstanceOf(TransitionState.Idle::class.java)
+ assertThat(layoutState.transitionState.currentScene).isEqualTo(TestScenes.SceneC)
+
+ // Swipe down with two fingers.
+ rule.onRoot().performTouchInput {
+ repeat(2) { i -> down(pointerId = i, middle) }
+ repeat(2) { i ->
+ moveBy(pointerId = i, Offset(0f, touchSlop + 10.dp.toPx()), delayMillis = 1_000)
+ }
+ }
+
+ // We are transitioning to B because we used 2 fingers.
+ val transition = layoutState.transitionState
+ assertThat(transition).isInstanceOf(TransitionState.Transition::class.java)
+ assertThat((transition as TransitionState.Transition).fromScene)
+ .isEqualTo(TestScenes.SceneC)
+ assertThat(transition.toScene).isEqualTo(TestScenes.SceneB)
+
+ // Release the fingers and wait for the animation to end. We are back to C because we only
+ // swiped 10dp.
+ rule.onRoot().performTouchInput { repeat(2) { i -> up(pointerId = i) } }
+ rule.waitForIdle()
+ assertThat(layoutState.transitionState).isInstanceOf(TransitionState.Idle::class.java)
+ assertThat(layoutState.transitionState.currentScene).isEqualTo(TestScenes.SceneC)
+ }
+
+ @Test
+ fun defaultEdgeSwipe() {
+ // Start at scene C.
+ currentScene = TestScenes.SceneC
+
+ // The draggable touch slop, i.e. the min px distance a touch pointer must move before it is
+ // detected as a drag event.
+ var touchSlop = 0f
+ rule.setContent {
+ touchSlop = LocalViewConfiguration.current.touchSlop
+ TestContent()
+ }
+
+ assertThat(layoutState.transitionState).isInstanceOf(TransitionState.Idle::class.java)
+ assertThat(layoutState.transitionState.currentScene).isEqualTo(TestScenes.SceneC)
+
+ // Swipe down from the top edge.
+ rule.onRoot().performTouchInput {
+ down(middleTop)
+ moveBy(Offset(0f, touchSlop + 10.dp.toPx()), delayMillis = 1_000)
+ }
+
+ // We are transitioning to B (and not A) because we started from the top edge.
+ var transition = layoutState.transitionState
+ assertThat(transition).isInstanceOf(TransitionState.Transition::class.java)
+ assertThat((transition as TransitionState.Transition).fromScene)
+ .isEqualTo(TestScenes.SceneC)
+ assertThat(transition.toScene).isEqualTo(TestScenes.SceneB)
+
+ // Release the fingers and wait for the animation to end. We are back to C because we only
+ // swiped 10dp.
+ rule.onRoot().performTouchInput { up() }
+ rule.waitForIdle()
+ assertThat(layoutState.transitionState).isInstanceOf(TransitionState.Idle::class.java)
+ assertThat(layoutState.transitionState.currentScene).isEqualTo(TestScenes.SceneC)
+
+ // Swipe right from the left edge.
+ rule.onRoot().performTouchInput {
+ down(middleLeft)
+ moveBy(Offset(touchSlop + 10.dp.toPx(), 0f), delayMillis = 1_000)
+ }
+
+ // We are transitioning to B (and not A) because we started from the left edge.
+ transition = layoutState.transitionState
+ assertThat(transition).isInstanceOf(TransitionState.Transition::class.java)
+ assertThat((transition as TransitionState.Transition).fromScene)
+ .isEqualTo(TestScenes.SceneC)
+ assertThat(transition.toScene).isEqualTo(TestScenes.SceneB)
+
+ // Release the fingers and wait for the animation to end. We are back to C because we only
+ // swiped 10dp.
+ rule.onRoot().performTouchInput { up() }
+ rule.waitForIdle()
+ assertThat(layoutState.transitionState).isInstanceOf(TransitionState.Idle::class.java)
+ assertThat(layoutState.transitionState.currentScene).isEqualTo(TestScenes.SceneC)
+ }
}
diff --git a/packages/SystemUI/res-keyguard/layout/sidefps_progress_bar.xml b/packages/SystemUI/res-keyguard/layout/sidefps_progress_bar.xml
index 183f0e5..9d74677 100644
--- a/packages/SystemUI/res-keyguard/layout/sidefps_progress_bar.xml
+++ b/packages/SystemUI/res-keyguard/layout/sidefps_progress_bar.xml
@@ -15,18 +15,18 @@
~
-->
-<LinearLayout android:layout_height="match_parent"
+<RelativeLayout
android:layout_width="match_parent"
- android:orientation="vertical"
- android:layoutDirection="ltr"
- android:gravity="center"
+ android:layout_height="match_parent"
+ android:gravity="left|top"
+ android:background="@android:color/transparent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ProgressBar
android:id="@+id/side_fps_progress_bar"
- android:layout_width="55dp"
- android:layout_height="10dp"
+ android:layout_width="0dp"
+ android:layout_height="@dimen/sfps_progress_bar_thickness"
android:indeterminateOnly="false"
android:min="0"
android:max="100"
android:progressDrawable="@drawable/progress_bar" />
-</LinearLayout>
+</RelativeLayout>
diff --git a/packages/SystemUI/res-keyguard/values/dimens.xml b/packages/SystemUI/res-keyguard/values/dimens.xml
index d1067a9..0628c3e 100644
--- a/packages/SystemUI/res-keyguard/values/dimens.xml
+++ b/packages/SystemUI/res-keyguard/values/dimens.xml
@@ -157,4 +157,11 @@
<dimen name="weather_clock_smartspace_translateX">0dp</dimen>
<dimen name="weather_clock_smartspace_translateY">0dp</dimen>
+ <!-- Additional length to add to the SFPS sensor length we get from framework so that the length
+ of the progress bar matches the length of the power button -->
+ <dimen name="sfps_progress_bar_length_extra_padding">12dp</dimen>
+ <!-- Thickness of the progress bar we show for the SFPS based authentication. -->
+ <dimen name="sfps_progress_bar_thickness">6dp</dimen>
+ <!-- Padding from the edge of the screen for the progress bar -->
+ <dimen name="sfps_progress_bar_padding_from_edge">7dp</dimen>
</resources>
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java
index 631423e..10393cf 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java
@@ -137,14 +137,12 @@
}
/**
- * @return a {@link ThumbnailData} with {@link TaskSnapshot} for the given {@param taskId}.
- * The snapshot will be triggered if no cached {@link TaskSnapshot} exists.
+ * @return the task snapshot for the given {@param taskId}.
*/
public @NonNull ThumbnailData getTaskThumbnail(int taskId, boolean isLowResolution) {
TaskSnapshot snapshot = null;
try {
- snapshot = getService().getTaskSnapshot(taskId, isLowResolution,
- true /* takeSnapshotIfNeeded */);
+ snapshot = getService().getTaskSnapshot(taskId, isLowResolution);
} catch (RemoteException e) {
Log.w(TAG, "Failed to retrieve task snapshot", e);
}
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractor.kt b/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractor.kt
index 0567ea2..2bb19cd 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractor.kt
@@ -34,9 +34,11 @@
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.onEach
@SysUISingleton
class SideFpsSensorInteractor
@@ -51,7 +53,7 @@
private val logger: SideFpsLogger,
) {
- private val sensorForCurrentDisplay =
+ private val sensorLocationForCurrentDisplay =
combine(
displayStateInteractor.displayChanges,
fingerprintPropertyRepository.sensorLocations,
@@ -77,77 +79,89 @@
isAvailable,
fingerprintInteractiveToAuthProvider.get().enabledForCurrentUser
) { sfpsAvailable, isSettingEnabled ->
- logger.logStateChange(sfpsAvailable, isSettingEnabled)
sfpsAvailable && isSettingEnabled
}
}
val sensorLocation: Flow<SideFpsSensorLocation> =
- combine(displayStateInteractor.currentRotation, sensorForCurrentDisplay, ::Pair).map {
- (rotation, sensorLocation: SensorLocationInternal) ->
- val isSensorVerticalInDefaultOrientation = sensorLocation.sensorLocationY != 0
- // device dimensions in the current rotation
- val size = windowManager.maximumWindowMetrics.bounds
- val isDefaultOrientation = rotation.isDefaultOrientation()
- // Width and height are flipped is device is not in rotation_0 or rotation_180
- // Flipping it to the width and height of the device in default orientation.
- val displayWidth = if (isDefaultOrientation) size.width() else size.height()
- val displayHeight = if (isDefaultOrientation) size.height() else size.width()
- val sensorWidth = context.resources?.getInteger(R.integer.config_sfpsSensorWidth) ?: 0
+ combine(displayStateInteractor.currentRotation, sensorLocationForCurrentDisplay, ::Pair)
+ .map { (rotation, sensorLocation: SensorLocationInternal) ->
+ val isSensorVerticalInDefaultOrientation = sensorLocation.sensorLocationY != 0
+ // device dimensions in the current rotation
+ val windowMetrics = windowManager.maximumWindowMetrics
+ val size = windowMetrics.bounds
+ val isDefaultOrientation = rotation.isDefaultOrientation()
+ // Width and height are flipped is device is not in rotation_0 or rotation_180
+ // Flipping it to the width and height of the device in default orientation.
+ val displayWidth = if (isDefaultOrientation) size.width() else size.height()
+ val displayHeight = if (isDefaultOrientation) size.height() else size.width()
+ val sensorLengthInPx = sensorLocation.sensorRadius * 2
- val (sensorLeft, sensorTop) =
- if (isSensorVerticalInDefaultOrientation) {
- when (rotation) {
- DisplayRotation.ROTATION_0 -> {
- Pair(displayWidth, sensorLocation.sensorLocationY)
+ val (sensorLeft, sensorTop) =
+ if (isSensorVerticalInDefaultOrientation) {
+ when (rotation) {
+ DisplayRotation.ROTATION_0 -> {
+ Pair(displayWidth, sensorLocation.sensorLocationY)
+ }
+ DisplayRotation.ROTATION_90 -> {
+ Pair(sensorLocation.sensorLocationY, 0)
+ }
+ DisplayRotation.ROTATION_180 -> {
+ Pair(
+ 0,
+ displayHeight -
+ sensorLocation.sensorLocationY -
+ sensorLengthInPx
+ )
+ }
+ DisplayRotation.ROTATION_270 -> {
+ Pair(
+ displayHeight -
+ sensorLocation.sensorLocationY -
+ sensorLengthInPx,
+ displayWidth
+ )
+ }
}
- DisplayRotation.ROTATION_90 -> {
- Pair(sensorLocation.sensorLocationY, 0)
- }
- DisplayRotation.ROTATION_180 -> {
- Pair(0, displayHeight - sensorLocation.sensorLocationY - sensorWidth)
- }
- DisplayRotation.ROTATION_270 -> {
- Pair(
- displayHeight - sensorLocation.sensorLocationY - sensorWidth,
- displayWidth
- )
+ } else {
+ when (rotation) {
+ DisplayRotation.ROTATION_0 -> {
+ Pair(sensorLocation.sensorLocationX, 0)
+ }
+ DisplayRotation.ROTATION_90 -> {
+ Pair(
+ 0,
+ displayWidth - sensorLocation.sensorLocationX - sensorLengthInPx
+ )
+ }
+ DisplayRotation.ROTATION_180 -> {
+ Pair(
+ displayWidth -
+ sensorLocation.sensorLocationX -
+ sensorLengthInPx,
+ displayHeight
+ )
+ }
+ DisplayRotation.ROTATION_270 -> {
+ Pair(displayHeight, sensorLocation.sensorLocationX)
+ }
}
}
- } else {
- when (rotation) {
- DisplayRotation.ROTATION_0 -> {
- Pair(sensorLocation.sensorLocationX, 0)
- }
- DisplayRotation.ROTATION_90 -> {
- Pair(0, displayWidth - sensorLocation.sensorLocationX - sensorWidth)
- }
- DisplayRotation.ROTATION_180 -> {
- Pair(
- displayWidth - sensorLocation.sensorLocationX - sensorWidth,
- displayHeight
- )
- }
- DisplayRotation.ROTATION_270 -> {
- Pair(displayHeight, sensorLocation.sensorLocationX)
- }
- }
- }
- logger.sensorLocationStateChanged(
- size,
- rotation,
- displayWidth,
- displayHeight,
- sensorWidth,
- isSensorVerticalInDefaultOrientation
- )
-
- SideFpsSensorLocation(
- left = sensorLeft,
- top = sensorTop,
- width = sensorWidth,
- isSensorVerticalInDefaultOrientation = isSensorVerticalInDefaultOrientation
- )
- }
+ SideFpsSensorLocation(
+ left = sensorLeft,
+ top = sensorTop,
+ length = sensorLengthInPx,
+ isSensorVerticalInDefaultOrientation = isSensorVerticalInDefaultOrientation
+ )
+ }
+ .distinctUntilChanged()
+ .onEach {
+ logger.sensorLocationStateChanged(
+ it.left,
+ it.top,
+ it.length,
+ it.isSensorVerticalInDefaultOrientation
+ )
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/domain/model/SideFpsSensorLocation.kt b/packages/SystemUI/src/com/android/systemui/biometrics/domain/model/SideFpsSensorLocation.kt
index 35f8e3b..12f374f 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/domain/model/SideFpsSensorLocation.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/domain/model/SideFpsSensorLocation.kt
@@ -21,8 +21,8 @@
val left: Int,
/** Pixel offset from the top of the screen */
val top: Int,
- /** Width in pixels of the SFPS sensor */
- val width: Int,
+ /** Length of the SFPS sensor in pixels in current display density */
+ val length: Int,
/**
* Whether the sensor is vertical when the device is in its default orientation (Rotation_0 or
* Rotation_180)
diff --git a/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt b/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
index 9e54b5c..26c5ea6 100644
--- a/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
@@ -23,9 +23,9 @@
import android.hardware.display.DisplayManager.EVENT_FLAG_DISPLAY_CHANGED
import android.hardware.display.DisplayManager.EVENT_FLAG_DISPLAY_REMOVED
import android.os.Handler
-import android.os.Trace
import android.util.Log
import android.view.Display
+import com.android.app.tracing.FlowTracing.traceEach
import com.android.app.tracing.traceSection
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
@@ -43,10 +43,9 @@
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
-import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.stateIn
@@ -97,7 +96,6 @@
@Application applicationScope: CoroutineScope,
@Background backgroundCoroutineDispatcher: CoroutineDispatcher
) : DisplayRepository {
- // Displays are enabled only after receiving them in [onDisplayAdded]
private val allDisplayEvents: Flow<DisplayEvent> =
conflatedCallbackFlow {
val callback =
@@ -124,16 +122,22 @@
awaitClose { displayManager.unregisterDisplayListener(callback) }
}
.onStart { emit(DisplayEvent.Changed(Display.DEFAULT_DISPLAY)) }
+ .debugLog("allDisplayEvents")
.flowOn(backgroundCoroutineDispatcher)
override val displayChangeEvent: Flow<Int> =
- allDisplayEvents.filter { it is DisplayEvent.Changed }.map { it.displayId }
+ allDisplayEvents.filterIsInstance<DisplayEvent.Changed>().map { event -> event.displayId }
override val displayAdditionEvent: Flow<Display?> =
- allDisplayEvents
- .filter { it is DisplayEvent.Added }
- .map { displayManager.getDisplay(it.displayId) }
+ allDisplayEvents.filterIsInstance<DisplayEvent.Added>().map {
+ displayManager.getDisplay(it.displayId)
+ }
+ /**
+ * Represents displays that went though the [DisplayListener.onDisplayAdded] callback.
+ *
+ * Those are commonly the ones provided by [DisplayManager.getDisplays] by default.
+ */
private val enabledDisplays =
allDisplayEvents
.map { getDisplays() }
@@ -143,9 +147,7 @@
override val displays: Flow<Set<Display>> = enabledDisplays
private fun getDisplays(): Set<Display> =
- traceSection("DisplayRepository#getDisplays()") {
- displayManager.displays?.toSet() ?: emptySet()
- }
+ traceSection("$TAG#getDisplays()") { displayManager.displays?.toSet() ?: emptySet() }
/** Propagate to the listeners only enabled displays */
private val enabledDisplayIds: Flow<Set<Int>> =
@@ -153,7 +155,8 @@
.map { enabledDisplaysSet -> enabledDisplaysSet.map { it.displayId }.toSet() }
.debugLog("enabledDisplayIds")
- private val ignoredDisplayIds = MutableStateFlow<Set<Int>>(emptySet())
+ private val _ignoredDisplayIds = MutableStateFlow<Set<Int>>(emptySet())
+ private val ignoredDisplayIds: Flow<Set<Int>> = _ignoredDisplayIds.debugLog("ignoredDisplayIds")
private fun getInitialConnectedDisplays(): Set<Int> =
displayManager
@@ -177,7 +180,7 @@
Log.d(TAG, "display with id=$id connected.")
}
connectedIds += id
- ignoredDisplayIds.value -= id
+ _ignoredDisplayIds.value -= id
trySend(connectedIds.toSet())
}
@@ -186,7 +189,7 @@
if (DEBUG) {
Log.d(TAG, "display with id=$id disconnected.")
}
- ignoredDisplayIds.value -= id
+ _ignoredDisplayIds.value -= id
trySend(connectedIds.toSet())
}
}
@@ -214,17 +217,23 @@
private val connectedExternalDisplayIds: Flow<Set<Int>> =
connectedDisplayIds
.map { connectedDisplayIds ->
- connectedDisplayIds
- .filter { id -> displayManager.getDisplay(id)?.type == Display.TYPE_EXTERNAL }
- .toSet()
+ traceSection("$TAG#filteringExternalDisplays") {
+ connectedDisplayIds
+ .filter { id -> getDisplayType(id) == Display.TYPE_EXTERNAL }
+ .toSet()
+ }
}
.flowOn(backgroundCoroutineDispatcher)
.debugLog("connectedExternalDisplayIds")
+ private fun getDisplayType(displayId: Int): Int? =
+ traceSection("$TAG#getDisplayType") { displayManager.getDisplay(displayId)?.type }
+
/**
- * Pending displays are the ones connected, but not enabled and not ignored. A connected display
- * is ignored after the user makes the decision to use it or not. For now, the initial decision
- * from the user is final and not reversible.
+ * Pending displays are the ones connected, but not enabled and not ignored.
+ *
+ * A connected display is ignored after the user makes the decision to use it or not. For now,
+ * the initial decision from the user is final and not reversible.
*/
private val pendingDisplayIds: Flow<Set<Int>> =
combine(enabledDisplayIds, connectedExternalDisplayIds, ignoredDisplayIds) {
@@ -241,12 +250,16 @@
}
connectedExternalDisplayIds - enabledDisplaysIds - ignoredDisplayIds
}
- .debugLog("pendingDisplayIds")
+ .debugLog("allPendingDisplayIds")
+
+ /** Which display id should be enabled among the pending ones. */
+ private val pendingDisplayId: Flow<Int?> =
+ pendingDisplayIds.map { it.maxOrNull() }.distinctUntilChanged().debugLog("pendingDisplayId")
override val pendingDisplay: Flow<DisplayRepository.PendingDisplay?> =
- pendingDisplayIds
- .map { pendingDisplayIds ->
- val id = pendingDisplayIds.maxOrNull() ?: return@map null
+ pendingDisplayId
+ .map { displayId ->
+ val id = displayId ?: return@map null
object : DisplayRepository.PendingDisplay {
override val id = id
@@ -263,7 +276,7 @@
override suspend fun ignore() {
traceSection("DisplayRepository#ignore($id)") {
- ignoredDisplayIds.value += id
+ _ignoredDisplayIds.value += id
}
}
@@ -282,11 +295,7 @@
private fun <T> Flow<T>.debugLog(flowName: String): Flow<T> {
return if (DEBUG) {
- this.onEach {
- Log.d(TAG, "$flowName: $it")
- Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_APP, "$TAG#$flowName", 0)
- Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, "$TAG#$flowName", "$it", 0)
- }
+ traceEach(flowName, logcat = true)
} else {
this
}
diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
index fa98661..c1106b3 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
@@ -258,7 +258,7 @@
// TODO(b/290652751): Tracking bug.
@JvmField
val MIGRATE_SPLIT_KEYGUARD_BOTTOM_AREA =
- unreleasedFlag("migrate_split_keyguard_bottom_area", teamfood = true)
+ unreleasedFlag("migrate_split_keyguard_bottom_area")
// TODO(b/297037052): Tracking bug.
@JvmField
@@ -273,7 +273,7 @@
/** Migrate the lock icon view to the new keyguard root view. */
// TODO(b/286552209): Tracking bug.
- @JvmField val MIGRATE_LOCK_ICON = unreleasedFlag("migrate_lock_icon", teamfood = true)
+ @JvmField val MIGRATE_LOCK_ICON = unreleasedFlag("migrate_lock_icon")
// TODO(b/288276738): Tracking bug.
@JvmField val WIDGET_ON_KEYGUARD = unreleasedFlag("widget_on_keyguard")
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/SideFpsProgressBarViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/SideFpsProgressBarViewBinder.kt
index 1acea5c..ba4876f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/SideFpsProgressBarViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/SideFpsProgressBarViewBinder.kt
@@ -16,19 +16,27 @@
package com.android.systemui.keyguard.ui.binder
+import android.animation.ValueAnimator
+import android.graphics.Point
import com.android.systemui.CoreStartable
import com.android.systemui.biometrics.SideFpsController
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.ui.view.SideFpsProgressBar
import com.android.systemui.keyguard.ui.viewmodel.SideFpsProgressBarViewModel
+import com.android.systemui.log.SideFpsLogger
+import com.android.systemui.statusbar.commandline.Command
+import com.android.systemui.statusbar.commandline.CommandRegistry
import com.android.systemui.util.kotlin.Quint
+import java.io.PrintWriter
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
+private const val spfsProgressBarCommand = "sfps-progress-bar"
+
@SysUISingleton
class SideFpsProgressBarViewBinder
@Inject
@@ -37,38 +45,112 @@
private val view: SideFpsProgressBar,
@Application private val applicationScope: CoroutineScope,
private val sfpsController: dagger.Lazy<SideFpsController>,
+ private val logger: SideFpsLogger,
+ private val commandRegistry: CommandRegistry,
) : CoreStartable {
override fun start() {
+ commandRegistry.registerCommand(spfsProgressBarCommand) { SfpsProgressBarCommand() }
applicationScope.launch {
viewModel.isProlongedTouchRequiredForAuthentication.collectLatest { enabled ->
+ logger.isProlongedTouchRequiredForAuthenticationChanged(enabled)
if (enabled) {
launch {
combine(
viewModel.isVisible,
- viewModel.sensorLocation,
- viewModel.shouldRotate90Degrees,
+ viewModel.progressBarLocation,
+ viewModel.rotation,
viewModel.isFingerprintAuthRunning,
- viewModel.sensorWidth,
+ viewModel.progressBarLength,
::Quint
)
- .collectLatest {
- (visible, location, shouldRotate, fpDetectRunning, sensorWidth) ->
- view.updateView(visible, location, shouldRotate, sensorWidth)
- // We have to hide the SFPS indicator as the progress bar will
- // be shown at the same location
- if (visible) {
- sfpsController.get().hideIndicator()
- } else if (fpDetectRunning) {
- sfpsController.get().showIndicator()
- }
+ .collectLatest { (visible, location, rotation, fpDetectRunning, length)
+ ->
+ updateView(
+ visible,
+ location,
+ fpDetectRunning,
+ length,
+ viewModel.progressBarThickness,
+ rotation,
+ )
}
}
launch { viewModel.progress.collectLatest { view.setProgress(it) } }
} else {
- view.hideOverlay()
+ view.hide()
}
}
}
}
+
+ private fun updateView(
+ visible: Boolean,
+ location: Point,
+ fpDetectRunning: Boolean,
+ length: Int,
+ thickness: Int,
+ rotation: Float,
+ ) {
+ logger.sfpsProgressBarStateChanged(visible, location, fpDetectRunning, length, rotation)
+ view.updateView(visible, location, length, thickness, rotation)
+ // We have to hide the SFPS indicator as the progress bar will
+ // be shown at the same location
+ if (visible) {
+ logger.hidingSfpsIndicator()
+ sfpsController.get().hideIndicator()
+ } else if (fpDetectRunning) {
+ logger.showingSfpsIndicator()
+ sfpsController.get().showIndicator()
+ }
+ }
+
+ inner class SfpsProgressBarCommand : Command {
+ private var animator: ValueAnimator? = null
+ override fun execute(pw: PrintWriter, args: List<String>) {
+ if (args.isEmpty() || args[0] == "show" && args.size != 6) {
+ pw.println("invalid command")
+ help(pw)
+ } else {
+ when (args[0]) {
+ "show" -> {
+ animator?.cancel()
+ updateView(
+ visible = true,
+ location = Point(Integer.parseInt(args[1]), Integer.parseInt(args[2])),
+ fpDetectRunning = true,
+ length = Integer.parseInt(args[3]),
+ thickness = Integer.parseInt(args[4]),
+ rotation = Integer.parseInt(args[5]).toFloat(),
+ )
+ animator =
+ ValueAnimator.ofFloat(0.0f, 1.0f).apply {
+ repeatMode = ValueAnimator.REVERSE
+ repeatCount = ValueAnimator.INFINITE
+ addUpdateListener { view.setProgress(it.animatedValue as Float) }
+ }
+ animator?.start()
+ }
+ "hide" -> {
+ animator?.cancel()
+ updateView(
+ visible = false,
+ location = Point(0, 0),
+ fpDetectRunning = false,
+ length = 0,
+ thickness = 0,
+ rotation = 0.0f,
+ )
+ }
+ }
+ }
+ }
+
+ override fun help(pw: PrintWriter) {
+ pw.println("Usage: adb shell cmd statusbar $spfsProgressBarCommand <command>")
+ pw.println("Available commands:")
+ pw.println(" show x y width height rotation")
+ pw.println(" hide")
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/SideFpsProgressBar.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/SideFpsProgressBar.kt
index f7ab1ee..853f176 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/SideFpsProgressBar.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/SideFpsProgressBar.kt
@@ -22,17 +22,16 @@
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
+import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.WindowManager
import android.widget.ProgressBar
-import com.android.systemui.biometrics.Utils
+import androidx.core.view.isGone
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.res.R
import javax.inject.Inject
private const val TAG = "SideFpsProgressBar"
-const val progressBarHeight = 100
-
@SysUISingleton
class SideFpsProgressBar
@Inject
@@ -40,31 +39,36 @@
private val layoutInflater: LayoutInflater,
private val windowManager: WindowManager,
) {
- private var progressBarWidth = 200
+ private var overlayView: View? = null
+
fun updateView(
visible: Boolean,
- location: Point,
- shouldRotate90Degrees: Boolean,
- progressBarWidth: Int
+ viewLeftTopLocation: Point,
+ progressBarWidth: Int,
+ progressBarHeight: Int,
+ rotation: Float,
) {
if (visible) {
- this.progressBarWidth = progressBarWidth
- createAndShowOverlay(location, shouldRotate90Degrees)
+ createAndShowOverlay(viewLeftTopLocation, rotation, progressBarWidth, progressBarHeight)
} else {
- hideOverlay()
+ hide()
}
}
- fun hideOverlay() {
- overlayView = null
+ fun hide() {
+ progressBar?.isGone = true
}
private val overlayViewParams =
WindowManager.LayoutParams(
- progressBarHeight,
- progressBarWidth,
+ // overlay is always full screen
+ MATCH_PARENT,
+ MATCH_PARENT,
WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
- Utils.FINGERPRINT_OVERLAY_LAYOUT_PARAM_FLAGS,
+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
+ WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSPARENT
)
.apply {
@@ -78,37 +82,31 @@
WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION
}
- private var overlayView: View? = null
- set(value) {
- field?.let { oldView -> windowManager.removeView(oldView) }
- field = value
- field?.let { newView -> windowManager.addView(newView, overlayViewParams) }
- }
-
private fun createAndShowOverlay(
- fingerprintSensorLocation: Point,
- shouldRotate90Degrees: Boolean
+ viewLeftTop: Point,
+ rotation: Float,
+ progressBarLength: Int,
+ progressBarThickness: Int,
) {
if (overlayView == null) {
overlayView = layoutInflater.inflate(R.layout.sidefps_progress_bar, null, false)
+ windowManager.addView(overlayView, overlayViewParams)
+ progressBar?.pivotX = 0.0f
+ progressBar?.pivotY = 0.0f
}
- overlayViewParams.x = fingerprintSensorLocation.x
- overlayViewParams.y = fingerprintSensorLocation.y
- if (shouldRotate90Degrees) {
- overlayView?.rotation = 270.0f
- overlayViewParams.width = progressBarHeight
- overlayViewParams.height = progressBarWidth
- } else {
- overlayView?.rotation = 0.0f
- overlayViewParams.width = progressBarWidth
- overlayViewParams.height = progressBarHeight
- }
- windowManager.updateViewLayout(overlayView, overlayViewParams)
+ progressBar?.layoutParams?.width = progressBarLength
+ progressBar?.layoutParams?.height = progressBarThickness
+ progressBar?.translationX = viewLeftTop.x.toFloat()
+ progressBar?.translationY = viewLeftTop.y.toFloat()
+ progressBar?.rotation = rotation
+ progressBar?.isGone = false
+ overlayView?.requestLayout()
}
fun setProgress(value: Float) {
- overlayView
- ?.findViewById<ProgressBar?>(R.id.side_fps_progress_bar)
- ?.setProgress((value * 100).toInt(), false)
+ progressBar?.setProgress((value * 100).toInt(), false)
}
+
+ private val progressBar: ProgressBar?
+ get() = overlayView?.findViewById(R.id.side_fps_progress_bar)
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/SideFpsProgressBarViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/SideFpsProgressBarViewModel.kt
index 2c3b431..f8996b7 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/SideFpsProgressBarViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/SideFpsProgressBarViewModel.kt
@@ -17,10 +17,12 @@
package com.android.systemui.keyguard.ui.viewmodel
import android.animation.ValueAnimator
+import android.content.Context
import android.graphics.Point
import androidx.core.animation.doOnEnd
import com.android.systemui.biometrics.domain.interactor.DisplayStateInteractor
import com.android.systemui.biometrics.domain.interactor.SideFpsSensorInteractor
+import com.android.systemui.biometrics.shared.model.DisplayRotation
import com.android.systemui.biometrics.shared.model.isDefaultOrientation
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
@@ -29,6 +31,7 @@
import com.android.systemui.keyguard.shared.model.ErrorFingerprintAuthenticationStatus
import com.android.systemui.keyguard.shared.model.FailFingerprintAuthenticationStatus
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
+import com.android.systemui.res.R
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
@@ -36,6 +39,7 @@
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
@@ -43,6 +47,7 @@
class SideFpsProgressBarViewModel
@Inject
constructor(
+ private val context: Context,
private val fpAuthRepository: DeviceEntryFingerprintAuthRepository,
private val sfpsSensorInteractor: SideFpsSensorInteractor,
displayStateInteractor: DisplayStateInteractor,
@@ -57,24 +62,84 @@
_progress.value = 0.0f
}
+ private val additionalSensorLengthPadding =
+ context.resources.getDimension(R.dimen.sfps_progress_bar_length_extra_padding).toInt()
+
val isVisible: Flow<Boolean> = _visible.asStateFlow()
val progress: Flow<Float> = _progress.asStateFlow()
- val sensorWidth: Flow<Int> = sfpsSensorInteractor.sensorLocation.map { it.width }
+ val progressBarLength: Flow<Int> =
+ sfpsSensorInteractor.sensorLocation
+ .map { it.length + additionalSensorLengthPadding }
+ .distinctUntilChanged()
- val sensorLocation: Flow<Point> =
- sfpsSensorInteractor.sensorLocation.map { Point(it.left, it.top) }
+ val progressBarThickness =
+ context.resources.getDimension(R.dimen.sfps_progress_bar_thickness).toInt()
+
+ val progressBarLocation =
+ combine(displayStateInteractor.currentRotation, sfpsSensorInteractor.sensorLocation, ::Pair)
+ .map { (rotation, sensorLocation) ->
+ val paddingFromEdge =
+ context.resources
+ .getDimension(R.dimen.sfps_progress_bar_padding_from_edge)
+ .toInt()
+ val lengthOfTheProgressBar = sensorLocation.length + additionalSensorLengthPadding
+ val viewLeftTop = Point(sensorLocation.left, sensorLocation.top)
+ val totalDistanceFromTheEdge = paddingFromEdge + progressBarThickness
+
+ val isSensorVerticalNow =
+ sensorLocation.isSensorVerticalInDefaultOrientation ==
+ rotation.isDefaultOrientation()
+ if (isSensorVerticalNow) {
+ // Sensor is vertical to the current orientation, we rotate it 270 deg
+ // around the (left,top) point as the pivot. We need to push it down the
+ // length of the progress bar so that it is still aligned to the sensor
+ viewLeftTop.y += lengthOfTheProgressBar
+ val isSensorOnTheNearEdge =
+ rotation == DisplayRotation.ROTATION_180 ||
+ rotation == DisplayRotation.ROTATION_90
+ if (isSensorOnTheNearEdge) {
+ // Add just the padding from the edge to push the progress bar right
+ viewLeftTop.x += paddingFromEdge
+ } else {
+ // View left top is pushed left from the edge by the progress bar thickness
+ // and the padding.
+ viewLeftTop.x -= totalDistanceFromTheEdge
+ }
+ } else {
+ // Sensor is horizontal to the current orientation.
+ val isSensorOnTheNearEdge =
+ rotation == DisplayRotation.ROTATION_0 ||
+ rotation == DisplayRotation.ROTATION_90
+ if (isSensorOnTheNearEdge) {
+ // Add just the padding from the edge to push the progress bar down
+ viewLeftTop.y += paddingFromEdge
+ } else {
+ // Sensor is now at the bottom edge of the device in the current rotation.
+ // We want to push it up from the bottom edge by the padding and
+ // the thickness of the progressbar.
+ viewLeftTop.y -= totalDistanceFromTheEdge
+ viewLeftTop.x -= additionalSensorLengthPadding
+ }
+ }
+ viewLeftTop
+ }
val isFingerprintAuthRunning: Flow<Boolean> = fpAuthRepository.isRunning
- val shouldRotate90Degrees: Flow<Boolean> =
+ val rotation: Flow<Float> =
combine(displayStateInteractor.currentRotation, sfpsSensorInteractor.sensorLocation, ::Pair)
.map { (rotation, sensorLocation) ->
- if (rotation.isDefaultOrientation()) {
- sensorLocation.isSensorVerticalInDefaultOrientation
+ if (
+ rotation.isDefaultOrientation() ==
+ sensorLocation.isSensorVerticalInDefaultOrientation
+ ) {
+ // We should rotate the progress bar 270 degrees in the clockwise direction with
+ // the left top point as the pivot so that it fills up from bottom to top
+ 270.0f
} else {
- !sensorLocation.isSensorVerticalInDefaultOrientation
+ 0.0f
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/log/SideFpsLogger.kt b/packages/SystemUI/src/com/android/systemui/log/SideFpsLogger.kt
index 74923ee..919072a 100644
--- a/packages/SystemUI/src/com/android/systemui/log/SideFpsLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/log/SideFpsLogger.kt
@@ -17,8 +17,6 @@
package com.android.systemui.log
import android.graphics.Point
-import android.graphics.Rect
-import com.android.systemui.biometrics.shared.model.DisplayRotation
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.BouncerLog
@@ -40,9 +38,9 @@
fun sfpsProgressBarStateChanged(
visible: Boolean,
location: Point,
- shouldRotate: Boolean,
fpDetectRunning: Boolean,
- sensorWidth: Int
+ sensorWidth: Int,
+ rotation: Float,
) {
buffer.log(
TAG,
@@ -51,14 +49,14 @@
bool1 = visible
int1 = location.x
int2 = location.y
- bool2 = shouldRotate
+ str1 = "$rotation"
bool3 = fpDetectRunning
long1 = sensorWidth.toLong()
},
{
"SFPS progress bar state changed: visible: $bool1, " +
"sensorLocation (x, y): ($int1, $int2), " +
- "shouldRotate = $bool2, " +
+ "rotation = $str1, " +
"fpDetectRunning: $bool3, " +
"sensorWidth: $long1"
}
@@ -87,44 +85,25 @@
)
}
- fun logStateChange(sfpsAvailable: Boolean, settingEnabled: Boolean) {
- buffer.log(
- TAG,
- LogLevel.DEBUG,
- {
- bool1 = sfpsAvailable
- bool2 = settingEnabled
- },
- { "SFPS rest to unlock state changed: sfpsAvailable: $bool1, settingEnabled: $bool2" }
- )
- }
-
fun sensorLocationStateChanged(
- windowSize: Rect?,
- rotation: DisplayRotation,
- displayWidth: Int,
- displayHeight: Int,
- sensorWidth: Int,
- sensorVerticalInDefaultOrientation: Boolean
+ pointOnScreenX: Int,
+ pointOnScreenY: Int,
+ sensorLength: Int,
+ isSensorVerticalInDefaultOrientation: Boolean
) {
buffer.log(
TAG,
LogLevel.DEBUG,
{
- str1 = "$windowSize"
- str2 = rotation.name
- int1 = displayWidth
- int2 = displayHeight
- long1 = sensorWidth.toLong()
- bool1 = sensorVerticalInDefaultOrientation
+ int1 = pointOnScreenX
+ int2 = pointOnScreenY
+ str2 = "$sensorLength"
+ bool1 = isSensorVerticalInDefaultOrientation
},
{
- "sensorLocation state changed: " +
- "windowSize: $str1, " +
- "rotation: $str2, " +
- "widthInRotation0: $int1, " +
- "heightInRotation0: $int2, " +
- "sensorWidth: $long1, " +
+ "SideFpsSensorLocation state changed: " +
+ "pointOnScreen: ($int1, $int2), " +
+ "sensorLength: $str2, " +
"sensorVerticalInDefaultOrientation: $bool1"
}
)
diff --git a/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitConnectionManagerFactory.kt b/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitConnectionManagerFactory.kt
index 97ec654..6e3b7b8 100644
--- a/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitConnectionManagerFactory.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/muteawait/MediaMuteAwaitConnectionManagerFactory.kt
@@ -31,7 +31,7 @@
private val logger: MediaMuteAwaitLogger,
@Main private val mainExecutor: Executor
) {
- private val deviceIconUtil = DeviceIconUtil()
+ private val deviceIconUtil = DeviceIconUtil(context)
/** Creates a [MediaMuteAwaitConnectionManager]. */
fun create(localMediaManager: LocalMediaManager): MediaMuteAwaitConnectionManager {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/data/repository/CustomTilePackageUpdatesRepository.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/data/repository/CustomTilePackageUpdatesRepository.kt
new file mode 100644
index 0000000..6d7d88f
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/data/repository/CustomTilePackageUpdatesRepository.kt
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.qs.tiles.impl.custom.data.repository
+
+import android.os.UserHandle
+import com.android.systemui.common.coroutine.ConflatedCallbackFlow
+import com.android.systemui.qs.external.TileServiceManager
+import com.android.systemui.qs.pipeline.shared.TileSpec
+import com.android.systemui.qs.tiles.impl.custom.di.bound.CustomTileBoundScope
+import com.android.systemui.qs.tiles.impl.custom.di.bound.CustomTileUser
+import javax.inject.Inject
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.channels.awaitClose
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.onEach
+import kotlinx.coroutines.flow.shareIn
+
+interface CustomTilePackageUpdatesRepository {
+
+ val packageChanges: Flow<Unit>
+}
+
+@CustomTileBoundScope
+class CustomTilePackageUpdatesRepositoryImpl
+@Inject
+constructor(
+ tileSpec: TileSpec.CustomTileSpec,
+ @CustomTileUser user: UserHandle,
+ serviceManager: TileServiceManager,
+ defaultsRepository: CustomTileDefaultsRepository,
+ @CustomTileBoundScope boundScope: CoroutineScope,
+) : CustomTilePackageUpdatesRepository {
+
+ override val packageChanges: Flow<Unit> =
+ ConflatedCallbackFlow.conflatedCallbackFlow {
+ serviceManager.setTileChangeListener { changedComponentName ->
+ if (changedComponentName == tileSpec.componentName) {
+ trySend(Unit)
+ }
+ }
+
+ awaitClose { serviceManager.setTileChangeListener(null) }
+ }
+ .onEach { defaultsRepository.requestNewDefaults(user, tileSpec.componentName, true) }
+ .shareIn(boundScope, SharingStarted.WhileSubscribed())
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/di/bound/CustomTileBoundComponent.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/di/bound/CustomTileBoundComponent.kt
index e33b3e9..d382d20 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/di/bound/CustomTileBoundComponent.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/di/bound/CustomTileBoundComponent.kt
@@ -23,7 +23,7 @@
/** @see CustomTileBoundScope */
@CustomTileBoundScope
-@Subcomponent
+@Subcomponent(modules = [CustomTileBoundModule::class])
interface CustomTileBoundComponent {
@Subcomponent.Builder
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/di/bound/CustomTileBoundModule.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/di/bound/CustomTileBoundModule.kt
new file mode 100644
index 0000000..889424a
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/di/bound/CustomTileBoundModule.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.qs.tiles.impl.custom.di.bound
+
+import com.android.systemui.qs.tiles.impl.custom.data.repository.CustomTilePackageUpdatesRepository
+import com.android.systemui.qs.tiles.impl.custom.data.repository.CustomTilePackageUpdatesRepositoryImpl
+import dagger.Binds
+import dagger.Module
+
+@Module
+interface CustomTileBoundModule {
+
+ @Binds
+ fun bindCustomTilePackageUpdatesRepository(
+ impl: CustomTilePackageUpdatesRepositoryImpl
+ ): CustomTilePackageUpdatesRepository
+}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java
index a2627ed..a2ca49d 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java
@@ -113,6 +113,7 @@
private final SysUIKeyEventHandler mSysUIKeyEventHandler;
private final PrimaryBouncerInteractor mPrimaryBouncerInteractor;
private final AlternateBouncerInteractor mAlternateBouncerInteractor;
+ private final QuickSettingsController mQuickSettingsController;
private GestureDetector mPulsingWakeupGestureHandler;
private GestureDetector mDreamingWakeupGestureHandler;
private View mBrightnessMirror;
@@ -188,6 +189,7 @@
BouncerMessageInteractor bouncerMessageInteractor,
BouncerLogger bouncerLogger,
SysUIKeyEventHandler sysUIKeyEventHandler,
+ QuickSettingsController quickSettingsController,
PrimaryBouncerInteractor primaryBouncerInteractor,
AlternateBouncerInteractor alternateBouncerInteractor,
SelectedUserInteractor selectedUserInteractor) {
@@ -220,6 +222,7 @@
mSysUIKeyEventHandler = sysUIKeyEventHandler;
mPrimaryBouncerInteractor = primaryBouncerInteractor;
mAlternateBouncerInteractor = alternateBouncerInteractor;
+ mQuickSettingsController = quickSettingsController;
// This view is not part of the newly inflated expanded status bar.
mBrightnessMirror = mView.findViewById(R.id.brightness_mirror_container);
@@ -454,6 +457,16 @@
&& !bouncerShowing
&& !mStatusBarStateController.isDozing()) {
if (mDragDownHelper.isDragDownEnabled()) {
+ if (mFeatureFlagsClassic.isEnabled(Flags.MIGRATE_NSSL)) {
+ // When on lockscreen, if the touch originates at the top of the screen
+ // go directly to QS and not the shade
+ if (mQuickSettingsController.shouldQuickSettingsIntercept(
+ ev.getX(), ev.getY(), 0)) {
+ mShadeLogger.d("NSWVC: QS intercepted");
+ return true;
+ }
+ }
+
// This handles drag down over lockscreen
boolean result = mDragDownHelper.onInterceptTouchEvent(ev);
if (mFeatureFlagsClassic.isEnabled(Flags.MIGRATE_NSSL)) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationAnimationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationAnimationControllerTest.java
index 728102d..0b38c4a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationAnimationControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationAnimationControllerTest.java
@@ -43,6 +43,7 @@
import android.view.animation.AccelerateInterpolator;
import androidx.test.InstrumentationRegistry;
+import androidx.test.filters.FlakyTest;
import androidx.test.filters.LargeTest;
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
@@ -67,6 +68,7 @@
@LargeTest
@RunWith(AndroidTestingRunner.class)
+@FlakyTest(bugId = 308501761)
public class WindowMagnificationAnimationControllerTest extends SysuiTestCase {
@Rule
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractorTest.kt
index 1e7a3d3..3fbdeec 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractorTest.kt
@@ -165,7 +165,7 @@
assertThat(sensorLocation!!.left).isEqualTo(1000)
assertThat(sensorLocation!!.top).isEqualTo(200)
assertThat(sensorLocation!!.isSensorVerticalInDefaultOrientation).isEqualTo(true)
- assertThat(sensorLocation!!.width).isEqualTo(100)
+ assertThat(sensorLocation!!.length).isEqualTo(100)
}
@Test
@@ -193,7 +193,7 @@
assertThat(sensorLocation!!.left).isEqualTo(500)
assertThat(sensorLocation!!.top).isEqualTo(1000)
assertThat(sensorLocation!!.isSensorVerticalInDefaultOrientation).isEqualTo(true)
- assertThat(sensorLocation!!.width).isEqualTo(100)
+ assertThat(sensorLocation!!.length).isEqualTo(100)
}
@Test
@@ -221,7 +221,7 @@
assertThat(sensorLocation!!.left).isEqualTo(200)
assertThat(sensorLocation!!.top).isEqualTo(0)
assertThat(sensorLocation!!.isSensorVerticalInDefaultOrientation).isEqualTo(true)
- assertThat(sensorLocation!!.width).isEqualTo(100)
+ assertThat(sensorLocation!!.length).isEqualTo(100)
}
@Test
@@ -274,7 +274,7 @@
assertThat(sensorLocation!!.left).isEqualTo(500)
assertThat(sensorLocation!!.top).isEqualTo(0)
assertThat(sensorLocation!!.isSensorVerticalInDefaultOrientation).isEqualTo(false)
- assertThat(sensorLocation!!.width).isEqualTo(100)
+ assertThat(sensorLocation!!.length).isEqualTo(100)
}
@Test
@@ -301,7 +301,7 @@
assertThat(sensorLocation!!.left).isEqualTo(0)
assertThat(sensorLocation!!.top).isEqualTo(400)
assertThat(sensorLocation!!.isSensorVerticalInDefaultOrientation).isEqualTo(false)
- assertThat(sensorLocation!!.width).isEqualTo(100)
+ assertThat(sensorLocation!!.length).isEqualTo(100)
}
@Test
@@ -328,7 +328,7 @@
assertThat(sensorLocation!!.left).isEqualTo(400)
assertThat(sensorLocation!!.top).isEqualTo(800)
assertThat(sensorLocation!!.isSensorVerticalInDefaultOrientation).isEqualTo(false)
- assertThat(sensorLocation!!.width).isEqualTo(100)
+ assertThat(sensorLocation!!.length).isEqualTo(100)
}
@Test
@@ -355,7 +355,7 @@
assertThat(sensorLocation!!.left).isEqualTo(800)
assertThat(sensorLocation!!.top).isEqualTo(500)
assertThat(sensorLocation!!.isSensorVerticalInDefaultOrientation).isEqualTo(false)
- assertThat(sensorLocation!!.width).isEqualTo(100)
+ assertThat(sensorLocation!!.length).isEqualTo(100)
}
@Test
@@ -381,10 +381,14 @@
rotation: DisplayRotation,
sensorWidth: Int
) {
- overrideResource(R.integer.config_sfpsSensorWidth, sensorWidth)
setupDisplayDimensions(width, height)
currentRotation.value = rotation
- setupFingerprint(x = sensorLocationX, y = sensorLocationY, displayId = "expanded_display")
+ setupFingerprint(
+ x = sensorLocationX,
+ y = sensorLocationY,
+ displayId = "expanded_display",
+ sensorRadius = sensorWidth / 2
+ )
}
private fun setupDisplayDimensions(displayWidth: Int, displayHeight: Int) {
@@ -392,7 +396,7 @@
.thenReturn(
WindowMetrics(
Rect(0, 0, displayWidth, displayHeight),
- mock(WindowInsets::class.java)
+ mock(WindowInsets::class.java),
)
)
}
@@ -401,7 +405,8 @@
fingerprintSensorType: FingerprintSensorType = FingerprintSensorType.POWER_BUTTON,
x: Int = 0,
y: Int = 0,
- displayId: String = "display_id_1"
+ displayId: String = "display_id_1",
+ sensorRadius: Int = 150
) {
contextDisplayInfo.uniqueId = displayId
fingerprintRepository.setProperties(
@@ -415,14 +420,14 @@
"someOtherDisplayId",
x + 100,
y + 100,
- 0,
+ sensorRadius,
),
displayId to
SensorLocationInternal(
displayId,
x,
y,
- 0,
+ sensorRadius,
)
)
)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
index d80dd76..806930d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
@@ -380,6 +380,32 @@
}
@Test
+ fun pendingDisplay_afterConfigChanged_doesNotChange() =
+ testScope.runTest {
+ val pendingDisplay by lastPendingDisplay()
+
+ sendOnDisplayConnected(1, TYPE_EXTERNAL)
+ val initialPendingDisplay: DisplayRepository.PendingDisplay? = pendingDisplay
+ assertThat(pendingDisplay).isNotNull()
+ sendOnDisplayChanged(1)
+
+ assertThat(initialPendingDisplay).isEqualTo(pendingDisplay)
+ }
+
+ @Test
+ fun pendingDisplay_afterNewHigherDisplayConnected_changes() =
+ testScope.runTest {
+ val pendingDisplay by lastPendingDisplay()
+
+ sendOnDisplayConnected(1, TYPE_EXTERNAL)
+ val initialPendingDisplay: DisplayRepository.PendingDisplay? = pendingDisplay
+ assertThat(pendingDisplay).isNotNull()
+ sendOnDisplayConnected(2, TYPE_EXTERNAL)
+
+ assertThat(initialPendingDisplay).isNotEqualTo(pendingDisplay)
+ }
+
+ @Test
fun onPendingDisplay_OneInternalAndOneExternalDisplay_internalIgnored() =
testScope.runTest {
val pendingDisplay by lastPendingDisplay()
@@ -466,6 +492,10 @@
connectedDisplayListener.value.onDisplayConnected(id)
}
+ private fun sendOnDisplayChanged(id: Int) {
+ connectedDisplayListener.value.onDisplayChanged(id)
+ }
+
private fun setDisplays(displays: List<Display>) {
whenever(displayManager.displays).thenReturn(displays.toTypedArray())
displays.forEach { display ->
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/impl/custom/CustomTilePackageUpdatesRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/impl/custom/CustomTilePackageUpdatesRepositoryTest.kt
new file mode 100644
index 0000000..4a22113
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/impl/custom/CustomTilePackageUpdatesRepositoryTest.kt
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.qs.tiles.impl.custom
+
+import android.content.ComponentName
+import android.os.UserHandle
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.qs.external.TileLifecycleManager
+import com.android.systemui.qs.external.TileServiceManager
+import com.android.systemui.qs.pipeline.shared.TileSpec
+import com.android.systemui.qs.tiles.impl.custom.data.repository.CustomTilePackageUpdatesRepository
+import com.android.systemui.qs.tiles.impl.custom.data.repository.CustomTilePackageUpdatesRepositoryImpl
+import com.android.systemui.qs.tiles.impl.custom.data.repository.FakeCustomTileDefaultsRepository
+import com.android.systemui.qs.tiles.impl.custom.data.repository.FakeCustomTileDefaultsRepository.DefaultsRequest
+import com.android.systemui.util.mockito.capture
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.launchIn
+import kotlinx.coroutines.flow.onEach
+import kotlinx.coroutines.test.StandardTestDispatcher
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.runTest
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentCaptor
+import org.mockito.Captor
+import org.mockito.Mock
+import org.mockito.Mockito.verify
+import org.mockito.MockitoAnnotations
+
+@OptIn(ExperimentalCoroutinesApi::class)
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class CustomTilePackageUpdatesRepositoryTest : SysuiTestCase() {
+
+ @Mock private lateinit var tileServiceManager: TileServiceManager
+
+ @Captor
+ private lateinit var listenerCaptor: ArgumentCaptor<TileLifecycleManager.TileChangeListener>
+
+ private val defaultsRepository = FakeCustomTileDefaultsRepository()
+ private val testDispatcher = StandardTestDispatcher()
+ private val testScope = TestScope(testDispatcher)
+
+ private lateinit var underTest: CustomTilePackageUpdatesRepository
+
+ @Before
+ fun setup() {
+ MockitoAnnotations.initMocks(this)
+
+ underTest =
+ CustomTilePackageUpdatesRepositoryImpl(
+ TileSpec.create(COMPONENT_1),
+ USER,
+ tileServiceManager,
+ defaultsRepository,
+ testScope.backgroundScope,
+ )
+ }
+
+ @Test
+ fun packageChangesUpdatesDefaults() =
+ testScope.runTest {
+ val events = mutableListOf<Unit>()
+ underTest.packageChanges.onEach { events.add(it) }.launchIn(backgroundScope)
+ runCurrent()
+ verify(tileServiceManager).setTileChangeListener(capture(listenerCaptor))
+
+ emitPackageChange()
+ runCurrent()
+
+ assertThat(events).hasSize(1)
+ assertThat(defaultsRepository.defaultsRequests).isNotEmpty()
+ assertThat(defaultsRepository.defaultsRequests.last())
+ .isEqualTo(DefaultsRequest(USER, COMPONENT_1, true))
+ }
+
+ @Test
+ fun packageChangesEmittedOnlyForTheTile() =
+ testScope.runTest {
+ val events = mutableListOf<Unit>()
+ underTest.packageChanges.onEach { events.add(it) }.launchIn(backgroundScope)
+ runCurrent()
+ verify(tileServiceManager).setTileChangeListener(capture(listenerCaptor))
+
+ emitPackageChange(COMPONENT_2)
+ runCurrent()
+
+ assertThat(events).isEmpty()
+ }
+
+ private fun emitPackageChange(componentName: ComponentName = COMPONENT_1) {
+ listenerCaptor.value.onTileChanged(componentName)
+ }
+
+ private companion object {
+ val USER = UserHandle(0)
+ val COMPONENT_1 = ComponentName("pkg.test.1", "cls.test")
+ val COMPONENT_2 = ComponentName("pkg.test.2", "cls.test")
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt
index 4e3e165..5459779 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt
@@ -97,6 +97,7 @@
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
+import java.util.Optional
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.test.TestScope
@@ -111,9 +112,8 @@
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
-import org.mockito.MockitoAnnotations
-import java.util.Optional
import org.mockito.Mockito.`when` as whenever
+import org.mockito.MockitoAnnotations
@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@@ -140,6 +140,7 @@
@Mock private lateinit var stackScrollLayoutController: NotificationStackScrollLayoutController
@Mock private lateinit var statusBarKeyguardViewManager: StatusBarKeyguardViewManager
@Mock private lateinit var statusBarWindowStateController: StatusBarWindowStateController
+ @Mock private lateinit var quickSettingsController: QuickSettingsController
@Mock
private lateinit var lockscreenShadeTransitionController: LockscreenShadeTransitionController
@Mock private lateinit var lockIconViewController: LockIconViewController
@@ -166,7 +167,7 @@
@Mock lateinit var alternateBouncerInteractor: AlternateBouncerInteractor
private val notificationLaunchAnimationRepository = NotificationLaunchAnimationRepository()
private val notificationLaunchAnimationInteractor =
- NotificationLaunchAnimationInteractor(notificationLaunchAnimationRepository)
+ NotificationLaunchAnimationInteractor(notificationLaunchAnimationRepository)
private lateinit var fakeClock: FakeSystemClock
private lateinit var interactionEventHandlerCaptor: ArgumentCaptor<InteractionEventHandler>
@@ -274,6 +275,7 @@
),
BouncerLogger(logcatLogBuffer("BouncerLog")),
sysUIKeyEventHandler,
+ quickSettingsController,
primaryBouncerInteractor,
alternateBouncerInteractor,
mSelectedUserInteractor,
@@ -460,9 +462,11 @@
// AND alternate bouncer doesn't want the touch
whenever(statusBarKeyguardViewManager.shouldInterceptTouchEvent(DOWN_EVENT))
.thenReturn(false)
+ // AND quick settings controller doesn't want it
+ whenever(quickSettingsController.shouldQuickSettingsIntercept(any(), any(), any()))
+ .thenReturn(false)
// AND the lock icon wants the touch
- whenever(lockIconViewController.willHandleTouchWhileDozing(DOWN_EVENT))
- .thenReturn(true)
+ whenever(lockIconViewController.willHandleTouchWhileDozing(DOWN_EVENT)).thenReturn(true)
featureFlagsClassic.set(MIGRATE_NSSL, true)
@@ -476,10 +480,31 @@
whenever(sysuiStatusBarStateController.isDozing).thenReturn(true)
// AND alternate bouncer doesn't want the touch
whenever(statusBarKeyguardViewManager.shouldInterceptTouchEvent(DOWN_EVENT))
- .thenReturn(false)
+ .thenReturn(false)
// AND the lock icon does NOT want the touch
- whenever(lockIconViewController.willHandleTouchWhileDozing(DOWN_EVENT))
- .thenReturn(false)
+ whenever(lockIconViewController.willHandleTouchWhileDozing(DOWN_EVENT)).thenReturn(false)
+ // AND quick settings controller doesn't want it
+ whenever(quickSettingsController.shouldQuickSettingsIntercept(any(), any(), any()))
+ .thenReturn(false)
+
+ featureFlagsClassic.set(MIGRATE_NSSL, true)
+
+ // THEN touch should NOT be intercepted by NotificationShade
+ assertThat(interactionEventHandler.shouldInterceptTouchEvent(DOWN_EVENT)).isTrue()
+ }
+
+ @Test
+ fun shouldInterceptTouchEvent_dozing_touchInStatusBar_touchIntercepted() {
+ // GIVEN dozing
+ whenever(sysuiStatusBarStateController.isDozing).thenReturn(true)
+ // AND alternate bouncer doesn't want the touch
+ whenever(statusBarKeyguardViewManager.shouldInterceptTouchEvent(DOWN_EVENT))
+ .thenReturn(false)
+ // AND the lock icon does NOT want the touch
+ whenever(lockIconViewController.willHandleTouchWhileDozing(DOWN_EVENT)).thenReturn(false)
+ // AND quick settings controller DOES want it
+ whenever(quickSettingsController.shouldQuickSettingsIntercept(any(), any(), any()))
+ .thenReturn(true)
featureFlagsClassic.set(MIGRATE_NSSL, true)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewTest.kt
index 3d5d26a..a6ab6a5 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewTest.kt
@@ -121,6 +121,7 @@
@Mock private lateinit var notificationStackScrollLayout: NotificationStackScrollLayout
@Mock private lateinit var notificationShadeDepthController: NotificationShadeDepthController
@Mock private lateinit var notificationShadeWindowController: NotificationShadeWindowController
+ @Mock private lateinit var quickSettingsController: QuickSettingsController
@Mock
private lateinit var notificationStackScrollLayoutController:
NotificationStackScrollLayoutController
@@ -264,6 +265,7 @@
),
BouncerLogger(logcatLogBuffer("BouncerLog")),
Mockito.mock(SysUIKeyEventHandler::class.java),
+ quickSettingsController,
primaryBouncerInteractor,
alternateBouncerInteractor,
mSelectedUserInteractor,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/impl/custom/data/repository/FakeCustomTilePackageUpdatesRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/impl/custom/data/repository/FakeCustomTilePackageUpdatesRepository.kt
new file mode 100644
index 0000000..8f972f5
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/impl/custom/data/repository/FakeCustomTilePackageUpdatesRepository.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.qs.tiles.impl.custom.data.repository
+
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableSharedFlow
+
+class FakeCustomTilePackageUpdatesRepository : CustomTilePackageUpdatesRepository {
+
+ private val mutablePackageChanges = MutableSharedFlow<Unit>()
+
+ override val packageChanges: Flow<Unit>
+ get() = mutablePackageChanges
+
+ suspend fun emitPackageChange() {
+ mutablePackageChanges.emit(Unit)
+ }
+}
diff --git a/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationGestureHandler.java b/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationGestureHandler.java
index cfe2af9..5953d0d 100644
--- a/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationGestureHandler.java
+++ b/services/accessibility/java/com/android/server/accessibility/magnification/WindowMagnificationGestureHandler.java
@@ -39,9 +39,12 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.accessibility.AccessibilityTraceManager;
import com.android.server.accessibility.EventStreamTransformation;
+import com.android.server.accessibility.Flags;
+import com.android.server.accessibility.gestures.GestureMatcher;
import com.android.server.accessibility.gestures.MultiTap;
import com.android.server.accessibility.gestures.MultiTapAndHold;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -453,20 +456,45 @@
private final MagnificationGesturesObserver mGesturesObserver;
DetectingState(@UiContext Context context) {
- final MultiTap multiTap = new MultiTap(context, mDetectSingleFingerTripleTap ? 3 : 1,
- mDetectSingleFingerTripleTap
- ? MagnificationGestureMatcher.GESTURE_TRIPLE_TAP
- : MagnificationGestureMatcher.GESTURE_SINGLE_TAP, null);
- final MultiTapAndHold multiTapAndHold = new MultiTapAndHold(context,
- mDetectSingleFingerTripleTap ? 3 : 1,
- mDetectSingleFingerTripleTap
- ? MagnificationGestureMatcher.GESTURE_TRIPLE_TAP_AND_HOLD
- : MagnificationGestureMatcher.GESTURE_SINGLE_TAP_AND_HOLD, null);
- mGesturesObserver = new MagnificationGesturesObserver(this,
- new SimpleSwipe(context),
- multiTap,
- multiTapAndHold,
- new TwoFingersDownOrSwipe(context));
+ if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
+ final List<GestureMatcher> mGestureMatchers = new ArrayList<>();
+
+ mGestureMatchers.add(new SimpleSwipe(context));
+ // Observe single tap and single tap and hold to reduce response time when the
+ // user performs these two gestures inside the window magnifier.
+ mGestureMatchers.add(new MultiTap(context,
+ mDetectSingleFingerTripleTap ? 3 : 1,
+ mDetectSingleFingerTripleTap
+ ? MagnificationGestureMatcher.GESTURE_TRIPLE_TAP
+ : MagnificationGestureMatcher.GESTURE_SINGLE_TAP,
+ null));
+ mGestureMatchers.add(new MultiTapAndHold(context,
+ mDetectSingleFingerTripleTap ? 3 : 1,
+ mDetectSingleFingerTripleTap
+ ? MagnificationGestureMatcher.GESTURE_TRIPLE_TAP_AND_HOLD
+ : MagnificationGestureMatcher.GESTURE_SINGLE_TAP_AND_HOLD,
+ null));
+ mGestureMatchers.add(new TwoFingersDownOrSwipe(context));
+
+ mGesturesObserver = new MagnificationGesturesObserver(this,
+ mGestureMatchers.toArray(new GestureMatcher[mGestureMatchers.size()]));
+ } else {
+ final MultiTap multiTap = new MultiTap(context,
+ mDetectSingleFingerTripleTap ? 3 : 1,
+ mDetectSingleFingerTripleTap
+ ? MagnificationGestureMatcher.GESTURE_TRIPLE_TAP
+ : MagnificationGestureMatcher.GESTURE_SINGLE_TAP, null);
+ final MultiTapAndHold multiTapAndHold = new MultiTapAndHold(context,
+ mDetectSingleFingerTripleTap ? 3 : 1,
+ mDetectSingleFingerTripleTap
+ ? MagnificationGestureMatcher.GESTURE_TRIPLE_TAP_AND_HOLD
+ : MagnificationGestureMatcher.GESTURE_SINGLE_TAP_AND_HOLD, null);
+ mGesturesObserver = new MagnificationGesturesObserver(this,
+ new SimpleSwipe(context),
+ multiTap,
+ multiTapAndHold,
+ new TwoFingersDownOrSwipe(context));
+ }
}
@Override
diff --git a/services/core/Android.bp b/services/core/Android.bp
index 7dbf61b..a14f3fe 100644
--- a/services/core/Android.bp
+++ b/services/core/Android.bp
@@ -183,6 +183,7 @@
"android.hardware.power.stats-V2-java",
"android.hidl.manager-V1.2-java",
"cbor-java",
+ "com.android.media.audio-aconfig-java",
"dropbox_flags_lib",
"icu4j_calendar_astronomer",
"android.security.aaid_aidl-java",
diff --git a/services/core/java/android/content/pm/PackageManagerInternal.java b/services/core/java/android/content/pm/PackageManagerInternal.java
index 638abdb..4f32220 100644
--- a/services/core/java/android/content/pm/PackageManagerInternal.java
+++ b/services/core/java/android/content/pm/PackageManagerInternal.java
@@ -300,14 +300,6 @@
@UserIdInt int userId, @NonNull String[] packageNames, boolean suspended);
/**
- * Suspend or unsuspend packages in a profile when quiet mode is toggled.
- *
- * @param userId The target user.
- * @param suspended Whether the packages should be suspended or unsuspended.
- */
- public abstract void setPackagesSuspendedForQuietMode(@UserIdInt int userId, boolean suspended);
-
- /**
* Get the information describing the dialog to be shown to the user when they try to launch a
* suspended application.
*
diff --git a/services/core/java/com/android/server/EventLogTags.logtags b/services/core/java/com/android/server/EventLogTags.logtags
index db89cac..c4cb816 100644
--- a/services/core/java/com/android/server/EventLogTags.logtags
+++ b/services/core/java/com/android/server/EventLogTags.logtags
@@ -179,6 +179,15 @@
3130 pm_snapshot_stats (build_count|1|1),(reuse_count|1|1),(big_builds|1|1),(short_lived|1|1),(max_build_time|1|3),(cumm_build_time|2|3)
# Snapshot rebuild instance
3131 pm_snapshot_rebuild (build_time|1|3),(lifetime|1|3)
+# Caller information to clear application data
+1003160 pm_clear_app_data_caller (pid|1),(uid|1),(package|3)
+# ---------------------------
+# Installer.java
+# ---------------------------
+# Caller Information to clear application data
+1003200 installer_clear_app_data_caller (pid|1),(uid|1),(package|3),(flags|1)
+# Call stack to clear application data
+1003201 installer_clear_app_data_call_stack (method|3),(class|3),(file|3),(line|1)
# ---------------------------
# InputMethodManagerService.java
diff --git a/services/core/java/com/android/server/MasterClearReceiver.java b/services/core/java/com/android/server/MasterClearReceiver.java
index 5a15f17..2b30c01 100644
--- a/services/core/java/com/android/server/MasterClearReceiver.java
+++ b/services/core/java/com/android/server/MasterClearReceiver.java
@@ -88,6 +88,9 @@
mWipeEsims = intent.getBooleanExtra(Intent.EXTRA_WIPE_ESIMS, false);
final boolean forceWipe = intent.getBooleanExtra(Intent.EXTRA_FORCE_MASTER_CLEAR, false)
|| intent.getBooleanExtra(Intent.EXTRA_FORCE_FACTORY_RESET, false);
+ // This is ONLY used by TestHarnessService within System Server, so we don't add a proper
+ // API constant in Intent for this.
+ final boolean keepMemtagMode = intent.getBooleanExtra("keep_memtag_mode", false);
// TODO(b/189938391): properly handle factory reset on headless system user mode.
final int sendingUserId = getSendingUserId();
@@ -110,9 +113,11 @@
try {
Slog.i(TAG, "Calling RecoverySystem.rebootWipeUserData(context, "
+ "shutdown=" + shutdown + ", reason=" + reason
- + ", forceWipe=" + forceWipe + ", wipeEsims=" + mWipeEsims + ")");
+ + ", forceWipe=" + forceWipe + ", wipeEsims=" + mWipeEsims
+ + ", keepMemtagMode=" + keepMemtagMode + ")");
RecoverySystem
- .rebootWipeUserData(context, shutdown, reason, forceWipe, mWipeEsims);
+ .rebootWipeUserData(
+ context, shutdown, reason, forceWipe, mWipeEsims, keepMemtagMode);
Slog.wtf(TAG, "Still running after master clear?!");
} catch (IOException e) {
Slog.e(TAG, "Can't perform master clear/factory reset", e);
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 88bb66f..1566113 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1886,7 +1886,7 @@
int exitInfoReason = (int) args.arg3;
args.recycle();
forceStopPackageLocked(pkg, appId, false, false, true, false,
- false, userId, reason, exitInfoReason);
+ false, false, userId, reason, exitInfoReason);
}
} break;
@@ -3548,6 +3548,7 @@
enforceNotIsolatedCaller("clearApplicationUserData");
int uid = Binder.getCallingUid();
int pid = Binder.getCallingPid();
+ EventLog.writeEvent(EventLogTags.AM_CLEAR_APP_DATA_CALLER, pid, uid, packageName);
final int resolvedUserId = mUserController.handleIncomingUser(pid, uid, userId, false,
ALLOW_FULL_ONLY, "clearApplicationUserData", null);
@@ -3914,7 +3915,10 @@
+ packageName + ": " + e);
}
if (mUserController.isUserRunning(user, userRunningFlags)) {
- forceStopPackageLocked(packageName, pkgUid,
+ forceStopPackageLocked(packageName, UserHandle.getAppId(pkgUid),
+ false /* callerWillRestart */, false /* purgeCache */,
+ true /* doIt */, false /* evenPersistent */,
+ false /* uninstalling */, true /* packageStateStopped */, user,
reason == null ? ("from pid " + callingPid) : reason);
finishForceStopPackageLocked(packageName, pkgUid);
}
@@ -4163,7 +4167,7 @@
@GuardedBy("this")
private void forceStopPackageLocked(final String packageName, int uid, String reason) {
forceStopPackageLocked(packageName, UserHandle.getAppId(uid), false,
- false, true, false, false, UserHandle.getUserId(uid), reason);
+ false, true, false, false, false, UserHandle.getUserId(uid), reason);
}
@GuardedBy("this")
@@ -4349,20 +4353,20 @@
@GuardedBy("this")
final boolean forceStopPackageLocked(String packageName, int appId,
boolean callerWillRestart, boolean purgeCache, boolean doit,
- boolean evenPersistent, boolean uninstalling, int userId, String reasonString) {
-
+ boolean evenPersistent, boolean uninstalling, boolean packageStateStopped,
+ int userId, String reasonString) {
int reason = packageName == null ? ApplicationExitInfo.REASON_USER_STOPPED
: ApplicationExitInfo.REASON_USER_REQUESTED;
return forceStopPackageLocked(packageName, appId, callerWillRestart, purgeCache, doit,
- evenPersistent, uninstalling, userId, reasonString, reason);
+ evenPersistent, uninstalling, packageStateStopped, userId, reasonString, reason);
}
@GuardedBy("this")
final boolean forceStopPackageLocked(String packageName, int appId,
boolean callerWillRestart, boolean purgeCache, boolean doit,
- boolean evenPersistent, boolean uninstalling, int userId, String reasonString,
- int reason) {
+ boolean evenPersistent, boolean uninstalling, boolean packageStateStopped,
+ int userId, String reasonString, int reason) {
int i;
if (userId == UserHandle.USER_ALL && packageName == null) {
@@ -4443,7 +4447,7 @@
}
}
- if (packageName == null || uninstalling) {
+ if (packageName == null || uninstalling || packageStateStopped) {
didSomething |= mPendingIntentController.removePendingIntentsForPackage(
packageName, userId, appId, doit);
}
@@ -5148,7 +5152,7 @@
for (String pkg : pkgs) {
synchronized (ActivityManagerService.this) {
if (forceStopPackageLocked(pkg, -1, false, false, false, false, false,
- 0, "query restart")) {
+ false, 0, "query restart")) {
setResultCode(Activity.RESULT_OK);
return;
}
@@ -7342,7 +7346,7 @@
mDebugTransient = !persistent;
if (packageName != null) {
forceStopPackageLocked(packageName, -1, false, false, true, true,
- false, UserHandle.USER_ALL, "set debug app");
+ false, false, UserHandle.USER_ALL, "set debug app");
}
}
} finally {
@@ -14918,7 +14922,7 @@
if (list != null && list.length > 0) {
for (int i = 0; i < list.length; i++) {
forceStopPackageLocked(list[i], -1, false, true, true,
- false, false, userId, "storage unmount");
+ false, false, false, userId, "storage unmount");
}
mAtmInternal.cleanupRecentTasksForUser(UserHandle.USER_ALL);
sendPackageBroadcastLocked(
@@ -14945,8 +14949,8 @@
if (killProcess) {
forceStopPackageLocked(ssp, UserHandle.getAppId(
intent.getIntExtra(Intent.EXTRA_UID, -1)),
- false, true, true, false, fullUninstall, userId,
- "pkg removed");
+ false, true, true, false, fullUninstall, false,
+ userId, "pkg removed");
getPackageManagerInternal()
.onPackageProcessKilledForUninstall(ssp);
} else {
@@ -15864,7 +15868,7 @@
} else {
// Instrumentation can kill and relaunch even persistent processes
forceStopPackageLocked(ii.targetPackage, -1, true, false, true, true, false,
- userId, "start instr");
+ false, userId, "start instr");
// Inform usage stats to make the target package active
if (mUsageStatsService != null) {
mUsageStatsService.reportEvent(ii.targetPackage, userId,
@@ -15993,6 +15997,7 @@
/* doIt= */ true,
/* evenPersistent= */ true,
/* uninstalling= */ false,
+ /* packageStateStopped= */ false,
userId,
"start instr");
@@ -16163,8 +16168,7 @@
}
} else if (!instr.mNoRestart) {
forceStopPackageLocked(app.info.packageName, -1, false, false, true, true, false,
- app.userId,
- "finished inst");
+ false, app.userId, "finished inst");
}
} finally {
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
diff --git a/services/core/java/com/android/server/am/EventLogTags.logtags b/services/core/java/com/android/server/am/EventLogTags.logtags
index 9e9db6a..931914f 100644
--- a/services/core/java/com/android/server/am/EventLogTags.logtags
+++ b/services/core/java/com/android/server/am/EventLogTags.logtags
@@ -129,3 +129,6 @@
# Intent Sender redirect for UserHandle.USER_CURRENT
30110 am_intent_sender_redirect_user (userId|1|5)
+
+# Caller information to clear application data
+1030002 am_clear_app_data_caller (pid|1),(uid|1),(package|3)
diff --git a/services/core/java/com/android/server/am/LmkdStatsReporter.java b/services/core/java/com/android/server/am/LmkdStatsReporter.java
index 1e4dd64..507fd9e 100644
--- a/services/core/java/com/android/server/am/LmkdStatsReporter.java
+++ b/services/core/java/com/android/server/am/LmkdStatsReporter.java
@@ -107,6 +107,8 @@
return FrameworkStatsLog.LMK_KILL_OCCURRED__REASON__LOW_MEM_AND_SWAP_UTIL;
case LOW_FILECACHE_AFTER_THRASHING:
return FrameworkStatsLog.LMK_KILL_OCCURRED__REASON__LOW_FILECACHE_AFTER_THRASHING;
+ case LOW_MEM:
+ return FrameworkStatsLog.LMK_KILL_OCCURRED__REASON__LOW_MEM;
default:
return FrameworkStatsLog.LMK_KILL_OCCURRED__REASON__UNKNOWN;
}
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 7c079702..2efac12 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -2040,7 +2040,7 @@
// the package was initially frozen through KILL_APPLICATION_MSG, so
// it doesn't hurt to use it again.)
mService.forceStopPackageLocked(app.info.packageName, UserHandle.getAppId(app.uid),
- false, false, true, false, false, app.userId, "start failure");
+ false, false, true, false, false, false, app.userId, "start failure");
return false;
}
}
@@ -2115,7 +2115,7 @@
+ app.processName, e);
app.setPendingStart(false);
mService.forceStopPackageLocked(app.info.packageName, UserHandle.getAppId(app.uid),
- false, false, true, false, false, app.userId, "start failure");
+ false, false, true, false, false, false, app.userId, "start failure");
}
return app.getPid() > 0;
}
@@ -2148,7 +2148,7 @@
app.setPendingStart(false);
mService.forceStopPackageLocked(app.info.packageName,
UserHandle.getAppId(app.uid),
- false, false, true, false, false, app.userId, "start failure");
+ false, false, true, false, false, false, app.userId, "start failure");
}
}
};
diff --git a/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java b/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
index c1a2482..e6cdbb5 100644
--- a/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
+++ b/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
@@ -128,6 +128,7 @@
"biometrics",
"biometrics_framework",
"biometrics_integration",
+ "camera_hal",
"camera_platform",
"car_framework",
"car_perception",
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index c5dd01f..87633e9 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -76,7 +76,6 @@
import android.app.IStopUserCallback;
import android.app.IUserSwitchObserver;
import android.app.KeyguardManager;
-import android.app.admin.DevicePolicyManagerInternal;
import android.app.usage.UsageEvents;
import android.appwidget.AppWidgetManagerInternal;
import android.content.Context;
@@ -1497,10 +1496,8 @@
private boolean shouldStartWithParent(UserInfo user) {
final UserProperties properties = getUserProperties(user.id);
- DevicePolicyManagerInternal dpmi =
- LocalServices.getService(DevicePolicyManagerInternal.class);
return (properties != null && properties.getStartWithParent())
- && (!user.isQuietModeEnabled() || dpmi.isKeepProfilesRunningEnabled());
+ && !user.isQuietModeEnabled();
}
/**
@@ -3629,7 +3626,7 @@
void activityManagerForceStopPackage(@UserIdInt int userId, String reason) {
synchronized (mService) {
- mService.forceStopPackageLocked(null, -1, false, false, true, false, false,
+ mService.forceStopPackageLocked(null, -1, false, false, true, false, false, false,
userId, reason);
}
};
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index a8fa313..b209fb0 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -37,6 +37,7 @@
import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
+import static com.android.media.audio.Flags.bluetoothMacAddressAnonymization;
import static com.android.server.audio.SoundDoseHelper.ACTION_CHECK_MUSIC_ACTIVE;
import static com.android.server.utils.EventLogger.Event.ALOGE;
import static com.android.server.utils.EventLogger.Event.ALOGI;
@@ -203,7 +204,6 @@
import com.android.internal.os.SomeArgs;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.Preconditions;
-import com.android.media.audio.flags.Flags;
import com.android.server.EventLogTags;
import com.android.server.LocalServices;
import com.android.server.SystemService;
@@ -10509,7 +10509,7 @@
}
private boolean isBluetoothPrividged() {
- if (!Flags.bluetoothMacAddressAnonymization()) {
+ if (!bluetoothMacAddressAnonymization()) {
return true;
}
return PackageManager.PERMISSION_GRANTED == mContext.checkCallingOrSelfPermission(
diff --git a/services/core/java/com/android/server/audio/HardeningEnforcer.java b/services/core/java/com/android/server/audio/HardeningEnforcer.java
index c7556da..4ceb83b2 100644
--- a/services/core/java/com/android/server/audio/HardeningEnforcer.java
+++ b/services/core/java/com/android/server/audio/HardeningEnforcer.java
@@ -15,7 +15,7 @@
*/
package com.android.server.audio;
-import static com.android.media.audio.flags.Flags.autoPublicVolumeApiHardening;
+import static android.media.audio.Flags.autoPublicVolumeApiHardening;
import android.Manifest;
import android.content.Context;
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index e475fe6..ff12ca2 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -102,6 +102,7 @@
import android.media.projection.IMediaProjectionManager;
import android.net.Uri;
import android.os.Binder;
+import android.os.Build;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.IBinder;
@@ -239,6 +240,10 @@
private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable";
private static final String PROP_DEFAULT_DISPLAY_TOP_INSET = "persist.sys.displayinset.top";
+
+ @VisibleForTesting
+ static final String ENABLE_ON_CONNECT =
+ "persist.sys.display.enable_on_connect.external";
private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000;
// This value needs to be in sync with the threshold
// in RefreshRateConfigs::getFrameRateDivisor.
@@ -1530,8 +1535,8 @@
throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or "
+ "CAPTURE_SECURE_VIDEO_OUTPUT permission, or an appropriate "
+ "MediaProjection token in order to create a screen sharing virtual "
- + "display. In order to create a virtual display that does not perform"
- + "screen sharing (mirroring), please use the flag"
+ + "display. In order to create a virtual display that does not perform "
+ + "screen sharing (mirroring), please use the flag "
+ "VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY.");
}
}
@@ -1942,10 +1947,14 @@
}
setupLogicalDisplay(display);
-
// TODO(b/292196201) Remove when the display can be disabled before DPC is created.
if (display.getDisplayInfoLocked().type == Display.TYPE_EXTERNAL) {
- display.setEnabledLocked(false);
+ if ((Build.IS_ENG || Build.IS_USERDEBUG)
+ && SystemProperties.getBoolean(ENABLE_ON_CONNECT, false)) {
+ Slog.w(TAG, "External display is enabled by default, bypassing user consent.");
+ } else {
+ display.setEnabledLocked(false);
+ }
}
sendDisplayEventLocked(display, DisplayManagerGlobal.EVENT_DISPLAY_CONNECTED);
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index b2f00a2..1bdd402 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -128,12 +128,12 @@
import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER;
import static com.android.server.am.PendingIntentRecord.FLAG_BROADCAST_SENDER;
import static com.android.server.am.PendingIntentRecord.FLAG_SERVICE_SENDER;
+import static com.android.server.notification.Flags.expireBitmaps;
import static com.android.server.policy.PhoneWindowManager.TOAST_WINDOW_ANIM_BUFFER;
import static com.android.server.policy.PhoneWindowManager.TOAST_WINDOW_TIMEOUT;
import static com.android.server.utils.PriorityDump.PRIORITY_ARG;
import static com.android.server.utils.PriorityDump.PRIORITY_ARG_CRITICAL;
import static com.android.server.utils.PriorityDump.PRIORITY_ARG_NORMAL;
-import static com.android.server.notification.Flags.expireBitmaps;
import android.Manifest;
import android.Manifest.permission;
@@ -178,7 +178,6 @@
import android.app.role.OnRoleHoldersChangedListener;
import android.app.role.RoleManager;
import android.app.usage.UsageEvents;
-import android.app.usage.UsageStatsManager;
import android.app.usage.UsageStatsManagerInternal;
import android.companion.ICompanionDeviceManager;
import android.compat.annotation.ChangeId;
@@ -206,8 +205,6 @@
import android.content.pm.VersionedPackage;
import android.content.res.Resources;
import android.database.ContentObserver;
-import android.graphics.Bitmap;
-import android.graphics.drawable.Icon;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioManagerInternal;
@@ -320,7 +317,6 @@
import com.android.server.job.JobSchedulerInternal;
import com.android.server.lights.LightsManager;
import com.android.server.lights.LogicalLight;
-import com.android.server.notification.Flags;
import com.android.server.notification.ManagedServices.ManagedServiceInfo;
import com.android.server.notification.ManagedServices.UserProfiles;
import com.android.server.notification.toast.CustomToastRecord;
@@ -1935,7 +1931,7 @@
} else if (
isProfileUnavailable(action)) {
int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
- if (userHandle >= 0 && !mDpm.isKeepProfilesRunningEnabled()) {
+ if (userHandle >= 0) {
cancelAllNotificationsInt(MY_UID, MY_PID, null, null, 0, 0, userHandle,
REASON_PROFILE_TURNED_OFF);
mSnoozeHelper.clearData(userHandle);
diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java
index 4ed3163..d5471cb0 100644
--- a/services/core/java/com/android/server/pm/Installer.java
+++ b/services/core/java/com/android/server/pm/Installer.java
@@ -24,6 +24,7 @@
import android.annotation.UserIdInt;
import android.content.Context;
import android.content.pm.PackageStats;
+import android.os.Binder;
import android.os.Build;
import android.os.CreateAppDataArgs;
import android.os.CreateAppDataResult;
@@ -35,9 +36,11 @@
import android.os.ServiceManager;
import android.os.storage.CrateMetadata;
import android.text.format.DateUtils;
+import android.util.EventLog;
import android.util.Slog;
import com.android.internal.os.BackgroundThread;
+import com.android.server.EventLogTags;
import com.android.server.SystemService;
import dalvik.system.BlockGuard;
@@ -441,6 +444,26 @@
if (!checkBeforeRemote()) return;
try {
mInstalld.clearAppData(uuid, packageName, userId, flags, ceDataInode);
+
+ final StackTraceElement[] elements = Thread.currentThread().getStackTrace();
+ String className;
+ String methodName;
+ String fileName;
+ int lineNumber;
+ final int pid = Binder.getCallingPid();
+ final int uid = Binder.getCallingUid();
+ EventLog.writeEvent(EventLogTags.INSTALLER_CLEAR_APP_DATA_CALLER, pid, uid, packageName,
+ flags);
+ // Skip the first two elements since they are always the same, ie
+ // Thread#getStackTrace() and VMStack#getThreadStackTrace()
+ for (int i = 2; i < elements.length; i++) {
+ className = elements[i].getClassName();
+ methodName = elements[i].getMethodName();
+ fileName = elements[i].getFileName();
+ lineNumber = elements[i].getLineNumber();
+ EventLog.writeEvent(EventLogTags.INSTALLER_CLEAR_APP_DATA_CALL_STACK, methodName,
+ className, fileName, lineNumber);
+ }
} catch (Exception e) {
throw InstallerException.from(e);
}
diff --git a/services/core/java/com/android/server/pm/PackageInstallerService.java b/services/core/java/com/android/server/pm/PackageInstallerService.java
index 305e353..a4d8632 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerService.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerService.java
@@ -58,6 +58,7 @@
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.VersionedPackage;
+import android.content.pm.parsing.FrameworkParsingPackageUtils;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Binder;
@@ -666,17 +667,22 @@
// App package name and label length is restricted so that really long strings aren't
// written to disk.
- if (params.appPackageName != null
- && params.appPackageName.length() > SessionParams.MAX_PACKAGE_NAME_LENGTH) {
+ if (params.appPackageName != null && !isValidPackageName(params.appPackageName)) {
params.appPackageName = null;
}
params.appLabel = TextUtils.trimToSize(params.appLabel,
PackageItemInfo.MAX_SAFE_LABEL_LENGTH);
- String requestedInstallerPackageName = (params.installerPackageName != null
- && params.installerPackageName.length() < SessionParams.MAX_PACKAGE_NAME_LENGTH)
- ? params.installerPackageName : installerPackageName;
+ // Validate installer package name.
+ if (params.installerPackageName != null && !isValidPackageName(
+ params.installerPackageName)) {
+ params.installerPackageName = null;
+ }
+
+ var requestedInstallerPackageName =
+ params.installerPackageName != null ? params.installerPackageName
+ : installerPackageName;
if (PackageManagerServiceUtils.isRootOrShell(callingUid)
|| PackageInstallerSession.isSystemDataLoaderInstallation(params)
@@ -1105,6 +1111,19 @@
return Integer.parseInt(sessionId);
}
+ private static boolean isValidPackageName(@NonNull String packageName) {
+ if (packageName.length() > SessionParams.MAX_PACKAGE_NAME_LENGTH) {
+ return false;
+ }
+ // "android" is a valid package name
+ var errorMessage = FrameworkParsingPackageUtils.validateName(
+ packageName, /* requireSeparator= */ false, /* requireFilename */ true);
+ if (errorMessage != null) {
+ return false;
+ }
+ return true;
+ }
+
private File getTmpSessionDir(String volumeUuid) {
return Environment.getDataAppDirectory(volumeUuid);
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 638bcbe..e5f7962 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -2085,8 +2085,8 @@
mUserNeedsBadging, () -> mResolveInfo, () -> mInstantAppInstallerActivity,
injector.getBackgroundHandler());
mDexOptHelper = new DexOptHelper(this);
- mSuspendPackageHelper = new SuspendPackageHelper(this, mInjector, mUserManager,
- mBroadcastHelper, mProtectedPackages);
+ mSuspendPackageHelper = new SuspendPackageHelper(this, mInjector, mBroadcastHelper,
+ mProtectedPackages);
mDistractingPackageHelper = new DistractingPackageHelper(this, mBroadcastHelper,
mSuspendPackageHelper);
mStorageEventHelper = new StorageEventHelper(this, mDeletePackageHelper,
@@ -4658,6 +4658,9 @@
throw new SecurityException("Cannot clear data for a protected package: "
+ packageName);
}
+ final int callingPid = Binder.getCallingPid();
+ EventLog.writeEvent(EventLogTags.PM_CLEAR_APP_DATA_CALLER, callingPid, callingUid,
+ packageName);
// Queue up an async operation since the package deletion may take a little while.
mHandler.post(new Runnable() {
@@ -4791,6 +4794,9 @@
/* checkShell= */ false, "delete application cache files");
final int hasAccessInstantApps = mContext.checkCallingOrSelfPermission(
android.Manifest.permission.ACCESS_INSTANT_APPS);
+ final int callingPid = Binder.getCallingPid();
+ EventLog.writeEvent(EventLogTags.PM_CLEAR_APP_DATA_CALLER, callingPid, callingUid,
+ packageName);
// Queue up an async operation since the package deletion may take a little while.
mHandler.post(() -> {
@@ -6145,7 +6151,7 @@
}
return mSuspendPackageHelper.setPackagesSuspended(snapshot, packageNames, suspended,
appExtras, launcherExtras, dialogInfo, callingPackage, userId, callingUid,
- false /* forQuietMode */, quarantined);
+ quarantined);
}
@Override
@@ -6602,12 +6608,6 @@
}
@Override
- public void setPackagesSuspendedForQuietMode(int userId, boolean suspended) {
- mSuspendPackageHelper.setPackagesSuspendedForQuietMode(
- snapshotComputer(), userId, suspended);
- }
-
- @Override
public void setDeviceAndProfileOwnerPackages(
int deviceOwnerUserId, String deviceOwnerPackage,
SparseArray<String> profileOwnerPackages) {
diff --git a/services/core/java/com/android/server/pm/SuspendPackageHelper.java b/services/core/java/com/android/server/pm/SuspendPackageHelper.java
index e8cebef..71f6c0d 100644
--- a/services/core/java/com/android/server/pm/SuspendPackageHelper.java
+++ b/services/core/java/com/android/server/pm/SuspendPackageHelper.java
@@ -16,8 +16,6 @@
package com.android.server.pm;
-import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
-import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
import static android.os.Process.SYSTEM_UID;
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
@@ -27,9 +25,7 @@
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.AppOpsManager;
-import android.app.admin.DevicePolicyManagerInternal;
import android.content.Intent;
-import android.content.pm.PackageInfo;
import android.content.pm.SuspendDialogInfo;
import android.os.Binder;
import android.os.Bundle;
@@ -45,7 +41,6 @@
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CollectionUtils;
-import com.android.server.LocalServices;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.PackageUserStateInternal;
@@ -54,10 +49,8 @@
import com.android.server.utils.WatchedArrayMap;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.Objects;
-import java.util.Set;
import java.util.function.Predicate;
public final class SuspendPackageHelper {
@@ -68,7 +61,6 @@
private final PackageManagerService mPm;
private final PackageManagerServiceInjector mInjector;
- private final UserManagerService mUserManager;
private final BroadcastHelper mBroadcastHelper;
private final ProtectedPackages mProtectedPackages;
@@ -76,10 +68,8 @@
* Constructor for {@link PackageManagerService}.
*/
SuspendPackageHelper(PackageManagerService pm, PackageManagerServiceInjector injector,
- UserManagerService userManager, BroadcastHelper broadcastHelper,
- ProtectedPackages protectedPackages) {
+ BroadcastHelper broadcastHelper, ProtectedPackages protectedPackages) {
mPm = pm;
- mUserManager = userManager;
mInjector = injector;
mBroadcastHelper = broadcastHelper;
mProtectedPackages = protectedPackages;
@@ -102,7 +92,6 @@
* @param callingPackage The caller's package name.
* @param userId The user where packages reside.
* @param callingUid The caller's uid.
- * @param forQuietMode Whether suspension is for quiet mode, in which case no apps are exempt.
* @return The names of failed packages.
*/
@Nullable
@@ -110,11 +99,11 @@
boolean suspended, @Nullable PersistableBundle appExtras,
@Nullable PersistableBundle launcherExtras, @Nullable SuspendDialogInfo dialogInfo,
@NonNull String callingPackage, @UserIdInt int userId, int callingUid,
- boolean forQuietMode, boolean quarantined) {
+ boolean quarantined) {
if (ArrayUtils.isEmpty(packageNames)) {
return packageNames;
}
- if (suspended && !quarantined && !forQuietMode && !isSuspendAllowedForUser(snapshot, userId,
+ if (suspended && !quarantined && !isSuspendAllowedForUser(snapshot, userId,
callingUid)) {
Slog.w(TAG, "Cannot suspend due to restrictions on user " + userId);
return packageNames;
@@ -130,7 +119,7 @@
final ArraySet<String> changedPackagesList = new ArraySet<>(packageNames.length);
final IntArray changedUids = new IntArray(packageNames.length);
- final boolean[] canSuspend = suspended && !forQuietMode
+ final boolean[] canSuspend = suspended
? canSuspendPackageForUser(snapshot, packageNames, userId, callingUid)
: null;
for (int i = 0; i < packageNames.length; i++) {
@@ -620,92 +609,10 @@
*/
public String[] setPackagesSuspendedByAdmin(
Computer snapshot, int userId, String[] packageNames, boolean suspend) {
- final Set<String> toSuspend = new ArraySet<>(packageNames);
- List<String> unsuspendable = new ArrayList<>();
-
- if (mUserManager.isQuietModeEnabled(userId)) {
- // If the user is in quiet mode, most apps will already be suspended, we shouldn't
- // re-suspend or unsuspend them.
- final Set<String> quiet = packagesToSuspendInQuietMode(snapshot, userId);
- quiet.retainAll(toSuspend);
- if (!quiet.isEmpty()) {
- Slog.i(TAG, "Ignoring quiet packages: " + String.join(", ", quiet));
- toSuspend.removeAll(quiet);
- }
-
- // Some of the already suspended packages might not be suspendable by the admin
- // (e.g. current dialer package), we need to report it back as unsuspendable the same
- // way as if quiet mode wasn't enabled. In that latter case they'd be returned by
- // setPackagesSuspended below after unsuccessful attempt to suspend them.
- if (suspend) {
- unsuspendable = getUnsuspendablePackages(snapshot, userId, quiet);
- }
- }
- if (!toSuspend.isEmpty()) {
- unsuspendable.addAll(Arrays.asList(
- setPackagesSuspended(
- snapshot, toSuspend.toArray(new String[0]), suspend,
- null /* appExtras */, null /* launcherExtras */, null /* dialogInfo */,
- PackageManagerService.PLATFORM_PACKAGE_NAME, userId, Process.SYSTEM_UID,
- false /* forQuietMode */, false /* quarantined */)));
- }
- return unsuspendable.toArray(String[]::new);
- }
-
- private List<String> getUnsuspendablePackages(
- Computer snapshot, int userId, Set<String> packages) {
- final String[] toSuspendArray = packages.toArray(String[]::new);
- final boolean[] mask =
- canSuspendPackageForUser(snapshot, toSuspendArray, userId, Process.SYSTEM_UID);
- final List<String> result = new ArrayList<>();
- for (int i = 0; i < mask.length; i++) {
- if (!mask[i]) {
- result.add(toSuspendArray[i]);
- }
- }
- return result;
- }
-
- /**
- * Suspends or unsuspends all packages in the given user when quiet mode is toggled to prevent
- * usage while quiet mode is enabled.
- */
- public void setPackagesSuspendedForQuietMode(
- Computer snapshot, int userId, boolean suspend) {
- final Set<String> toSuspend = packagesToSuspendInQuietMode(snapshot, userId);
- if (!suspend) {
- final DevicePolicyManagerInternal dpm =
- LocalServices.getService(DevicePolicyManagerInternal.class);
- if (dpm != null) {
- toSuspend.removeAll(dpm.getPackagesSuspendedByAdmin(userId));
- } else {
- Slog.wtf(TAG,
- "DevicePolicyManager unavailable while suspending apps for quiet mode");
- }
- }
-
- if (toSuspend.isEmpty()) {
- return;
- }
-
- setPackagesSuspended(snapshot, toSuspend.toArray(new String[0]),
- suspend, null /* appExtras */, null /* launcherExtras */, null /* dialogInfo */,
+ return setPackagesSuspended(snapshot, packageNames, suspend,
+ null /* appExtras */, null /* launcherExtras */, null /* dialogInfo */,
PackageManagerService.PLATFORM_PACKAGE_NAME, userId, Process.SYSTEM_UID,
- true /* forQuietMode */, false /* quarantined */);
- }
-
- private Set<String> packagesToSuspendInQuietMode(Computer snapshot, int userId) {
- final List<PackageInfo> pkgInfos = snapshot.getInstalledPackages(
- MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, userId).getList();
- final Set<String> result = new ArraySet<>();
- for (PackageInfo info : pkgInfos) {
- result.add(info.packageName);
- }
-
- // Role holder may be null, but ArraySet handles it correctly.
- result.remove(mPm.getDevicePolicyManagementRoleHolderPackageName(userId));
-
- return result;
+ false /* quarantined */);
}
private String getKnownPackageName(@NonNull Computer snapshot,
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index c97fbda..81a570f 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -46,7 +46,6 @@
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.ActivityManagerNative;
-import android.app.AppOpsManager;
import android.app.BroadcastOptions;
import android.app.IActivityManager;
import android.app.IStopUserCallback;
@@ -55,7 +54,6 @@
import android.app.StatsManager;
import android.app.admin.DevicePolicyEventLogger;
import android.app.admin.DevicePolicyManagerInternal;
-import android.app.trust.TrustManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IIntentReceiver;
@@ -302,19 +300,6 @@
private static final String TRON_USER_CREATED = "users_user_created";
private static final String TRON_DEMO_CREATED = "users_demo_created";
- // App ops that should be restricted in quiet mode
- private static final int[] QUIET_MODE_RESTRICTED_APP_OPS = {
- AppOpsManager.OP_COARSE_LOCATION,
- AppOpsManager.OP_FINE_LOCATION,
- AppOpsManager.OP_GPS,
- AppOpsManager.OP_BODY_SENSORS,
- AppOpsManager.OP_ACTIVITY_RECOGNITION,
- AppOpsManager.OP_BLUETOOTH_SCAN,
- AppOpsManager.OP_NEARBY_WIFI_DEVICES,
- AppOpsManager.OP_RECORD_AUDIO,
- AppOpsManager.OP_CAMERA,
- };
-
private final Context mContext;
private final PackageManagerService mPm;
@@ -339,7 +324,6 @@
private final File mUserListFile;
private final IBinder mUserRestrictionToken = new Binder();
- private final IBinder mQuietModeToken = new Binder();
/** Installs system packages based on user-type. */
private final UserSystemPackageInstaller mSystemPackageInstaller;
@@ -702,7 +686,6 @@
@Override
public void onUserStarting(@NonNull TargetUser targetUser) {
- boolean isProfileInQuietMode = false;
synchronized (mUms.mUsersLock) {
final UserData user = mUms.getUserDataLU(targetUser.getUserIdentifier());
if (user != null) {
@@ -710,14 +693,9 @@
if (targetUser.getUserIdentifier() == UserHandle.USER_SYSTEM
&& targetUser.isFull()) {
mUms.setLastEnteredForegroundTimeToNow(user);
- } else if (user.info.isManagedProfile() && user.info.isQuietModeEnabled()) {
- isProfileInQuietMode = true;
}
}
}
- if (isProfileInQuietMode) {
- mUms.setAppOpsRestrictedForQuietMode(targetUser.getUserIdentifier(), true);
- }
}
@Override
@@ -1516,43 +1494,21 @@
synchronized (mPackagesLock) {
writeUserLP(profileUserData);
}
- if (getDevicePolicyManagerInternal().isKeepProfilesRunningEnabled()) {
- // New behavior: when quiet mode is enabled, profile user is running, but apps are
- // suspended.
- getPackageManagerInternal().setPackagesSuspendedForQuietMode(userId, enableQuietMode);
- setAppOpsRestrictedForQuietMode(userId, enableQuietMode);
- if (enableQuietMode
- && !mLockPatternUtils.isManagedProfileWithUnifiedChallenge(userId)) {
- mContext.getSystemService(TrustManager.class).setDeviceLockedForUser(userId, true);
+ try {
+ if (enableQuietMode) {
+ ActivityManager.getService().stopUser(userId, /* force= */ true, null);
+ LocalServices.getService(ActivityManagerInternal.class)
+ .killForegroundAppsForUser(userId);
+ } else {
+ IProgressListener callback = target != null
+ ? new DisableQuietModeUserUnlockedCallback(target)
+ : null;
+ ActivityManager.getService().startProfileWithListener(userId, callback);
}
-
- if (!enableQuietMode && target != null) {
- try {
- mContext.startIntentSender(target, null, 0, 0, 0);
- } catch (IntentSender.SendIntentException e) {
- Slog.e(LOG_TAG, "Failed to start intent after disabling quiet mode", e);
- }
- }
- } else {
- // Old behavior: when quiet is enabled, profile user is stopped.
- // Old quiet mode behavior: profile user is stopped.
- // TODO(b/265683382) Remove once rollout complete.
- try {
- if (enableQuietMode) {
- ActivityManager.getService().stopUser(userId, /* force= */ true, null);
- LocalServices.getService(ActivityManagerInternal.class)
- .killForegroundAppsForUser(userId);
- } else {
- IProgressListener callback = target != null
- ? new DisableQuietModeUserUnlockedCallback(target)
- : null;
- ActivityManager.getService().startProfileWithListener(userId, callback);
- }
- } catch (RemoteException e) {
- // Should not happen, same process.
- e.rethrowAsRuntimeException();
- }
+ } catch (RemoteException e) {
+ // Should not happen, same process.
+ e.rethrowAsRuntimeException();
}
logQuietModeEnabled(userId, enableQuietMode, callingPackage);
@@ -1569,17 +1525,6 @@
}
}
- private void setAppOpsRestrictedForQuietMode(@UserIdInt int userId, boolean restrict) {
- for (int opCode : QUIET_MODE_RESTRICTED_APP_OPS) {
- try {
- mAppOpsService.setUserRestriction(
- opCode, restrict, mQuietModeToken, userId, /* excludedPackageTags= */ null);
- } catch (RemoteException e) {
- Slog.w(LOG_TAG, "Unable to limit app ops", e);
- }
- }
- }
-
private void logQuietModeEnabled(@UserIdInt int userId, boolean enableQuietMode,
@Nullable String callingPackage) {
Slogf.i(LOG_TAG,
diff --git a/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java b/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java
index 2ad8bcf..9e20805 100644
--- a/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java
+++ b/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java
@@ -379,10 +379,7 @@
ai.privateFlags |= flag(state.isInstantApp(), ApplicationInfo.PRIVATE_FLAG_INSTANT)
| flag(state.isVirtualPreload(), ApplicationInfo.PRIVATE_FLAG_VIRTUAL_PRELOAD)
| flag(state.isHidden(), ApplicationInfo.PRIVATE_FLAG_HIDDEN);
- if ((flags & PackageManager.MATCH_QUARANTINED_COMPONENTS) == 0
- && state.isQuarantined()) {
- ai.enabled = false;
- } else if (state.getEnabledState() == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
+ if (state.getEnabledState() == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
ai.enabled = true;
} else if (state.getEnabledState()
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
diff --git a/services/core/java/com/android/server/testharness/TestHarnessModeService.java b/services/core/java/com/android/server/testharness/TestHarnessModeService.java
index 9a9b836..1f884ba 100644
--- a/services/core/java/com/android/server/testharness/TestHarnessModeService.java
+++ b/services/core/java/com/android/server/testharness/TestHarnessModeService.java
@@ -71,6 +71,7 @@
public class TestHarnessModeService extends SystemService {
public static final String TEST_HARNESS_MODE_PROPERTY = "persist.sys.test_harness";
private static final String TAG = TestHarnessModeService.class.getSimpleName();
+ private boolean mEnableKeepMemtagMode = false;
private PersistentDataBlockManagerInternal mPersistentDataBlockManagerInternal;
@@ -298,6 +299,18 @@
switch (cmd) {
case "enable":
case "restore":
+ String opt;
+ while ((opt = getNextOption()) != null) {
+ switch (opt) {
+ case "--keep-memtag":
+ mEnableKeepMemtagMode = true;
+ break;
+ default:
+ getErrPrintWriter().println("Invalid option: " + opt);
+ return 1;
+ }
+ }
+
checkPermissions();
final long originalId = Binder.clearCallingIdentity();
try {
@@ -357,6 +370,7 @@
i.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
i.putExtra(Intent.EXTRA_REASON, TAG);
i.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, true);
+ i.putExtra("keep_memtag_mode", mEnableKeepMemtagMode);
getContext().sendBroadcastAsUser(i, UserHandle.SYSTEM);
return 0;
}
diff --git a/services/core/java/com/android/server/wm/ActivityStartInterceptor.java b/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
index 25c42b4..f9d344b 100644
--- a/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
+++ b/services/core/java/com/android/server/wm/ActivityStartInterceptor.java
@@ -285,10 +285,6 @@
return false;
}
- if (isKeepProfilesRunningEnabled() && !isPackageSuspended()) {
- return false;
- }
-
IntentSender target = createIntentSenderForOriginalIntent(mCallingUid,
FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT);
@@ -521,12 +517,6 @@
&& (mAInfo.applicationInfo.flags & FLAG_SUSPENDED) != 0;
}
- private static boolean isKeepProfilesRunningEnabled() {
- DevicePolicyManagerInternal dpmi =
- LocalServices.getService(DevicePolicyManagerInternal.class);
- return dpmi == null || dpmi.isKeepProfilesRunningEnabled();
- }
-
/**
* Called when an activity is successfully launched.
*/
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index c021785..f462efc 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -69,6 +69,7 @@
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.view.WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_LAUNCHER_CLEAR_SNAPSHOT;
import static android.window.TransitionInfo.FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY;
+
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_CONFIGURATION;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_DREAM;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_FOCUS;
@@ -3825,8 +3826,7 @@
}
@Override
- public TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution,
- boolean takeSnapshotIfNeeded) {
+ public TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution) {
mAmInternal.enforceCallingPermission(READ_FRAME_BUFFER, "getTaskSnapshot()");
final long ident = Binder.clearCallingIdentity();
try {
@@ -3840,12 +3840,8 @@
}
}
// Don't call this while holding the lock as this operation might hit the disk.
- TaskSnapshot taskSnapshot = mWindowManager.mTaskSnapshotController.getSnapshot(taskId,
+ return mWindowManager.mTaskSnapshotController.getSnapshot(taskId,
task.mUserId, true /* restoreFromDisk */, isLowResolution);
- if (taskSnapshot == null && takeSnapshotIfNeeded) {
- taskSnapshot = takeTaskSnapshot(taskId, false /* updateCache */);
- }
- return taskSnapshot;
} finally {
Binder.restoreCallingIdentity(ident);
}
@@ -7064,8 +7060,7 @@
@Override
public TaskSnapshot getTaskSnapshotBlocking(
int taskId, boolean isLowResolution) {
- return ActivityTaskManagerService.this.getTaskSnapshot(taskId, isLowResolution,
- false /* takeSnapshotIfNeeded */);
+ return ActivityTaskManagerService.this.getTaskSnapshot(taskId, isLowResolution);
}
@Override
diff --git a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
index 9f3e162..668cd87 100644
--- a/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
+++ b/services/core/java/com/android/server/wm/BackgroundActivityStartController.java
@@ -28,6 +28,7 @@
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_ALLOW;
import static com.android.server.wm.ActivityTaskManagerService.APP_SWITCH_FG_ONLY;
import static com.android.server.wm.ActivityTaskSupervisor.getApplicationLabel;
+import static com.android.window.flags.Flags.balShowToasts;
import static com.android.server.wm.PendingRemoteAnimationRegistry.TIMEOUT_MS;
import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -459,6 +460,7 @@
"With Android 15 BAL hardening this activity start would be blocked"
+ " (missing opt in by PI creator)! "
+ state.dump(resultForCaller, resultForRealCaller));
+ showBalToast("BAL would be blocked", state);
// return the realCaller result for backwards compatibility
return statsLog(resultForRealCaller, state);
}
@@ -470,6 +472,7 @@
"With Android 15 BAL hardening this activity start would be blocked"
+ " (missing opt in by PI creator)! "
+ state.dump(resultForCaller, resultForRealCaller));
+ showBalToast("BAL would be blocked", state);
return statsLog(resultForCaller, state);
}
if (resultForRealCaller.allows()
@@ -481,6 +484,7 @@
"With Android 14 BAL hardening this activity start would be blocked"
+ " (missing opt in by PI sender)! "
+ state.dump(resultForCaller, resultForRealCaller));
+ showBalToast("BAL would be blocked", state);
return statsLog(resultForRealCaller, state);
}
Slog.wtf(TAG, "Without Android 14 BAL hardening this activity start would be allowed"
@@ -488,6 +492,7 @@
+ state.dump(resultForCaller, resultForRealCaller));
// fall through
}
+ showBalToast("BAL blocked", state);
// anything that has fallen through would currently be aborted
Slog.w(TAG, "Background activity launch blocked"
+ state.dump(resultForCaller, resultForRealCaller));
@@ -862,8 +867,7 @@
+ (blockActivityStartAndFeatureEnabled ? " blocked " : " would block ")
+ getApplicationLabel(mService.mContext.getPackageManager(),
launchedFromPackageName);
- UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
- toastText, Toast.LENGTH_LONG).show());
+ showToast(toastText);
Slog.i(TAG, asmDebugInfo);
}
@@ -882,6 +886,19 @@
return true;
}
+ private void showBalToast(String toastText, BalState state) {
+ if (balShowToasts()) {
+ showToast(toastText
+ + " caller:" + state.mCallingPackage
+ + " realCaller:" + state.mRealCallingPackage);
+ }
+ }
+
+ private void showToast(String toastText) {
+ UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
+ toastText, Toast.LENGTH_LONG).show());
+ }
+
/**
* If the top activity uid does not match the launching or launched activity, and the launch was
* not requested from the top uid, we want to clear out all non matching activities to prevent
@@ -930,12 +947,10 @@
if (ActivitySecurityModelFeatureFlags.shouldShowToast(callingUid)
&& (!shouldBlockActivityStart || finishCount[0] > 0)) {
- UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
- (shouldBlockActivityStart
- ? "Top activities cleared by "
- : "Top activities would be cleared by ")
- + ActivitySecurityModelFeatureFlags.DOC_LINK,
- Toast.LENGTH_LONG).show());
+ showToast((shouldBlockActivityStart
+ ? "Top activities cleared by "
+ : "Top activities would be cleared by ")
+ + ActivitySecurityModelFeatureFlags.DOC_LINK);
Slog.i(TAG, getDebugInfoForActivitySecurity("Clear Top", sourceRecord, targetRecord,
targetTask, targetTaskTop, realCallingUid, balCode, shouldBlockActivityStart,
@@ -1013,11 +1028,10 @@
}
if (ActivitySecurityModelFeatureFlags.shouldShowToast(callingUid)) {
- UiThread.getHandler().post(() -> Toast.makeText(mService.mContext,
- (ActivitySecurityModelFeatureFlags.DOC_LINK
- + (restrictActivitySwitch ? " returned home due to "
- : " would return home due to ")
- + callingLabel), Toast.LENGTH_LONG).show());
+ showToast((ActivitySecurityModelFeatureFlags.DOC_LINK
+ + (restrictActivitySwitch ? " returned home due to "
+ : " would return home due to ")
+ + callingLabel));
}
// If the activity switch should be restricted, return home rather than the
diff --git a/services/core/java/com/android/server/wm/EmbeddedWindowController.java b/services/core/java/com/android/server/wm/EmbeddedWindowController.java
index 275396f..1462878 100644
--- a/services/core/java/com/android/server/wm/EmbeddedWindowController.java
+++ b/services/core/java/com/android/server/wm/EmbeddedWindowController.java
@@ -150,8 +150,8 @@
/**
* A unique token associated with the embedded window that can be used by the host window
- * to request focus transfer to the embedded. This is not the input token since we don't
- * want to give clients access to each others input token.
+ * to request focus transfer and gesture transfer to the embedded. This is not the input
+ * token since we don't want to give clients access to each others input token.
*/
private final IBinder mInputTransferToken;
diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java
index a756847..0c55d8a 100644
--- a/services/core/java/com/android/server/wm/Session.java
+++ b/services/core/java/com/android/server/wm/Session.java
@@ -964,6 +964,23 @@
}
@Override
+ public boolean transferHostTouchGestureToEmbedded(IWindow hostWindow,
+ IBinder inputTransferToken) {
+ if (hostWindow == null) {
+ return false;
+ }
+
+ final long identity = Binder.clearCallingIdentity();
+ boolean didTransfer;
+ try {
+ didTransfer = mService.transferHostTouchGestureToEmbedded(this, hostWindow,
+ inputTransferToken);
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ return didTransfer;
+ }
+ @Override
public void generateDisplayHash(IWindow window, Rect boundsInWindow, String hashAlgorithm,
RemoteCallback callback) {
final long origId = Binder.clearCallingIdentity();
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 5c5a1e1..f348928 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -3508,10 +3508,13 @@
top.mLetterboxUiController.getLetterboxPositionForVerticalReachability();
}
}
- // User Aspect Ratio Settings is enabled if the app is not in SCM
+ // User Aspect Ratio Settings button is enabled if the app is not in SCM and has
+ // launchable activities
info.topActivityEligibleForUserAspectRatioButton = top != null
&& !info.topActivityInSizeCompat
- && top.mLetterboxUiController.shouldEnableUserAspectRatioSettings();
+ && top.mLetterboxUiController.shouldEnableUserAspectRatioSettings()
+ && mAtmService.mContext.getPackageManager()
+ .getLaunchIntentForPackage(getBasePackageName()) != null;
info.topActivityBoundsLetterboxed = top != null && top.areBoundsLetterboxed();
}
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 9eb3389..6e3d24b 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -8960,6 +8960,43 @@
}
}
+ boolean transferHostTouchGestureToEmbedded(Session session, IWindow hostWindow,
+ IBinder inputTransferToken) {
+ final IBinder hostInputChannel, embeddedInputChannel;
+ synchronized (mGlobalLock) {
+ final WindowState hostWindowState = windowForClientLocked(session, hostWindow, false);
+ if (hostWindowState == null) {
+ Slog.w(TAG, "Attempt to transfer touch gesture with invalid host window");
+ return false;
+ }
+
+ final EmbeddedWindowController.EmbeddedWindow ew =
+ mEmbeddedWindowController.getByInputTransferToken(inputTransferToken);
+ if (ew == null || ew.mHostWindowState == null) {
+ Slog.w(TAG, "Attempt to transfer touch gesture to non-existent embedded window");
+ return false;
+ }
+ if (ew.mHostWindowState.mClient.asBinder() != hostWindow.asBinder()) {
+ Slog.w(TAG, "Attempt to transfer touch gesture to embedded window not associated"
+ + " with host window");
+ return false;
+ }
+ embeddedInputChannel = ew.getInputChannelToken();
+ if (embeddedInputChannel == null) {
+ Slog.w(TAG, "Attempt to transfer touch focus from embedded window with no input"
+ + " channel");
+ return false;
+ }
+ hostInputChannel = hostWindowState.mInputChannelToken;
+ if (hostInputChannel == null) {
+ Slog.w(TAG,
+ "Attempt to transfer touch focus to a host window with no input channel");
+ return false;
+ }
+ return mInputManager.transferTouchFocus(hostInputChannel, embeddedInputChannel);
+ }
+ }
+
private void updateInputChannel(IBinder channelToken, int callingUid, int callingPid,
int displayId, SurfaceControl surface, String name,
InputApplicationHandle applicationHandle, int flags,
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyData.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyData.java
index d960439..395ea91 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyData.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyData.java
@@ -16,8 +16,6 @@
package com.android.server.devicepolicy;
-import static com.android.server.devicepolicy.DevicePolicyManagerService.DEFAULT_KEEP_PROFILES_RUNNING_FLAG;
-
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -200,7 +198,7 @@
* Effective state of the feature flag. It is updated to the current configuration value
* during boot and doesn't change value after than unless overridden by test code.
*/
- boolean mEffectiveKeepProfilesRunning = DEFAULT_KEEP_PROFILES_RUNNING_FLAG;
+ boolean mEffectiveKeepProfilesRunning = false;
DevicePolicyData(@UserIdInt int userId) {
mUserId = userId;
@@ -401,7 +399,7 @@
out.endTag(null, TAG_BYPASS_ROLE_QUALIFICATIONS);
}
- if (policyData.mEffectiveKeepProfilesRunning != DEFAULT_KEEP_PROFILES_RUNNING_FLAG) {
+ if (policyData.mEffectiveKeepProfilesRunning) {
out.startTag(null, TAG_KEEP_PROFILES_RUNNING);
out.attributeBoolean(null, ATTR_VALUE, policyData.mEffectiveKeepProfilesRunning);
out.endTag(null, TAG_KEEP_PROFILES_RUNNING);
@@ -592,7 +590,7 @@
policy.mCurrentRoleHolder = parser.getAttributeValue(null, ATTR_VALUE);
} else if (TAG_KEEP_PROFILES_RUNNING.equals(tag)) {
policy.mEffectiveKeepProfilesRunning = parser.getAttributeBoolean(
- null, ATTR_VALUE, DEFAULT_KEEP_PROFILES_RUNNING_FLAG);
+ null, ATTR_VALUE, false);
// Deprecated tags below
} else if (TAG_PROTECTED_PACKAGES.equals(tag)) {
if (policy.mUserControlDisabledPackages == null) {
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 1ff117e..93dc219 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -873,9 +873,6 @@
"enable_permission_based_access";
private static final boolean DEFAULT_VALUE_PERMISSION_BASED_ACCESS_FLAG = false;
- // TODO(b/265683382) remove the flag after rollout.
- public static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = false;
-
// TODO(b/266831522) remove the flag after rollout.
private static final String APPLICATION_EXEMPTIONS_FLAG = "application_exemptions";
private static final boolean DEFAULT_APPLICATION_EXEMPTIONS_FLAG = true;
@@ -2178,13 +2175,29 @@
return packageNameAndSignature;
}
- private void suspendAppsForQuietProfiles(boolean toSuspend) {
+ private void unsuspendAppsForQuietProfiles() {
PackageManagerInternal pmi = mInjector.getPackageManagerInternal();
List<UserInfo> users = mUserManagerInternal.getUsers(true /* excludeDying */);
+
for (UserInfo user : users) {
- if (user.isManagedProfile() && user.isQuietModeEnabled()) {
- pmi.setPackagesSuspendedForQuietMode(user.id, toSuspend);
+ if (!user.isManagedProfile() || !user.isQuietModeEnabled()) {
+ continue;
}
+ int userId = user.id;
+ var suspendedByAdmin = getPackagesSuspendedByAdmin(userId);
+ var packagesToUnsuspend = mInjector.getPackageManager(userId)
+ .getInstalledPackages(PackageManager.PackageInfoFlags.of(
+ MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE))
+ .stream()
+ .map(packageInfo -> packageInfo.packageName)
+ .filter(pkg -> !suspendedByAdmin.contains(pkg))
+ .toArray(String[]::new);
+
+ Slogf.i(LOG_TAG, "Unsuspending work apps for user %d", userId);
+ // When app suspension was used for quiet mode, the apps were suspended by platform
+ // package, just like when admin suspends them. So although it wasn't admin who
+ // suspended, this method will remove the right suspension record.
+ pmi.setPackagesSuspendedByAdmin(userId, packagesToUnsuspend, false /* suspended */);
}
}
@@ -3436,9 +3449,9 @@
}
}
- // In case flag value has changed, we apply it during boot to avoid doing it concurrently
- // with user toggling quiet mode.
- setKeepProfileRunningEnabledUnchecked(isKeepProfilesRunningFlagEnabled());
+ // Check whether work apps were paused via suspension and unsuspend if necessary.
+ // TODO: move it into PolicyVersionUpgrader so that it is executed only once.
+ unsuspendWorkAppsIfNecessary();
}
// TODO(b/230841522) Make it static.
@@ -11039,9 +11052,6 @@
(size == 1 ? "" : "s"));
}
pw.println();
- pw.println("Keep profiles running: "
- + getUserData(UserHandle.USER_SYSTEM).mEffectiveKeepProfilesRunning);
- pw.println();
mPolicyCache.dump(pw);
pw.println();
@@ -15539,11 +15549,6 @@
}
@Override
- public Set<String> getPackagesSuspendedByAdmin(@UserIdInt int userId) {
- return DevicePolicyManagerService.this.getPackagesSuspendedByAdmin(userId);
- }
-
- @Override
public void notifyUnsafeOperationStateChanged(DevicePolicySafetyChecker checker, int reason,
boolean isSafe) {
// TODO(b/178494483): use EventLog instead
@@ -15571,11 +15576,6 @@
}
}
- @Override
- public boolean isKeepProfilesRunningEnabled() {
- return getUserDataUnchecked(UserHandle.USER_SYSTEM).mEffectiveKeepProfilesRunning;
- }
-
private @Mode int findInteractAcrossProfilesResetMode(String packageName) {
return getDefaultCrossProfilePackages().contains(packageName)
? AppOpsManager.MODE_ALLOWED
@@ -23028,32 +23028,22 @@
DEFAULT_VALUE_PERMISSION_BASED_ACCESS_FLAG);
}
- private static boolean isKeepProfilesRunningFlagEnabled() {
- return DEFAULT_KEEP_PROFILES_RUNNING_FLAG;
- }
-
private boolean isUnicornFlagEnabled() {
return false;
}
- private void setKeepProfileRunningEnabledUnchecked(boolean keepProfileRunning) {
+ private void unsuspendWorkAppsIfNecessary() {
synchronized (getLockObject()) {
DevicePolicyData policyData = getUserDataUnchecked(UserHandle.USER_SYSTEM);
- if (policyData.mEffectiveKeepProfilesRunning == keepProfileRunning) {
+ if (!policyData.mEffectiveKeepProfilesRunning) {
return;
}
- policyData.mEffectiveKeepProfilesRunning = keepProfileRunning;
+ policyData.mEffectiveKeepProfilesRunning = false;
saveSettingsLocked(UserHandle.USER_SYSTEM);
}
- suspendAppsForQuietProfiles(keepProfileRunning);
- }
- @Override
- public void setOverrideKeepProfilesRunning(boolean enabled) {
- Preconditions.checkCallAuthorization(
- hasCallingOrSelfPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS));
- setKeepProfileRunningEnabledUnchecked(enabled);
- Slog.i(LOG_TAG, "Keep profiles running overridden to: " + enabled);
+ Slog.w(LOG_TAG, "Work apps may have been paused via suspension previously.");
+ unsuspendAppsForQuietProfiles();
}
public void setMtePolicy(int flags, String callerPackageName) {
diff --git a/services/midi/Android.bp b/services/midi/Android.bp
index a385fe3..2ea28a31 100644
--- a/services/midi/Android.bp
+++ b/services/midi/Android.bp
@@ -20,6 +20,5 @@
srcs: [":services.midi-sources"],
libs: [
"services.core",
- "aconfig_midi_flags_java_lib",
],
}
diff --git a/services/midi/java/com/android/server/midi/MidiService.java b/services/midi/java/com/android/server/midi/MidiService.java
index 2f47cc7..39aaab2 100644
--- a/services/midi/java/com/android/server/midi/MidiService.java
+++ b/services/midi/java/com/android/server/midi/MidiService.java
@@ -16,7 +16,7 @@
package com.android.server.midi;
-import static com.android.media.midi.flags.Flags.virtualUmp;
+import static android.media.midi.Flags.virtualUmp;
import android.Manifest;
import android.annotation.NonNull;
diff --git a/services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java b/services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java
index 163d248..c7b1abf 100644
--- a/services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java
+++ b/services/tests/displayservicetests/src/com/android/server/display/DisplayManagerServiceTest.java
@@ -28,6 +28,8 @@
import static android.view.ContentRecordingSession.RECORD_CONTENT_DISPLAY;
import static android.view.ContentRecordingSession.RECORD_CONTENT_TASK;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
+import static com.android.server.display.DisplayManagerService.ENABLE_ON_CONNECT;
import static com.android.server.display.VirtualDisplayAdapter.UNIQUE_ID_PREFIX;
import static com.google.common.truth.Truth.assertThat;
@@ -90,12 +92,14 @@
import android.media.projection.IMediaProjection;
import android.media.projection.IMediaProjectionManager;
import android.os.Binder;
+import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.MessageQueue;
import android.os.Process;
import android.os.RemoteException;
+import android.os.SystemProperties;
import android.platform.test.flag.junit.SetFlagsRule;
import android.view.ContentRecordingSession;
import android.view.Display;
@@ -113,6 +117,7 @@
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.R;
+import com.android.modules.utils.testing.ExtendedMockitoRule;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.companion.virtual.VirtualDeviceManagerInternal;
@@ -130,6 +135,7 @@
import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges;
import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;
+import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -141,6 +147,8 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.mockito.quality.Strictness;
+import org.mockito.stubbing.Answer;
import java.time.Duration;
import java.util.ArrayList;
@@ -322,6 +330,12 @@
@Captor ArgumentCaptor<ContentRecordingSession> mContentRecordingSessionCaptor;
@Mock DisplayManagerFlags mMockFlags;
+ @Rule
+ public final ExtendedMockitoRule mExtendedMockitoRule =
+ new ExtendedMockitoRule.Builder(this)
+ .setStrictness(Strictness.LENIENT)
+ .spyStatic(SystemProperties.class)
+ .build();
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
@@ -2406,6 +2420,39 @@
}
@Test
+ public void testConnectExternalDisplay_withDisplayManagementAndSysprop_shouldEnableDisplay() {
+ Assume.assumeTrue(Build.IS_ENG || Build.IS_USERDEBUG);
+ when(mMockFlags.isConnectedDisplayManagementEnabled()).thenReturn(true);
+ doAnswer((Answer<Boolean>) invocationOnMock -> true)
+ .when(() -> SystemProperties.getBoolean(ENABLE_ON_CONNECT, false));
+ manageDisplaysPermission(/* granted= */ true);
+ DisplayManagerService displayManager = new DisplayManagerService(mContext, mBasicInjector);
+ DisplayManagerInternal localService = displayManager.new LocalService();
+ DisplayManagerService.BinderService bs = displayManager.new BinderService();
+ LogicalDisplayMapper logicalDisplayMapper = displayManager.getLogicalDisplayMapper();
+ FakeDisplayManagerCallback callback = new FakeDisplayManagerCallback();
+ bs.registerCallbackWithEventMask(callback, STANDARD_AND_CONNECTION_DISPLAY_EVENTS);
+ localService.registerDisplayGroupListener(callback);
+ callback.expectsEvent(EVENT_DISPLAY_ADDED);
+
+ // Create default display device
+ createFakeDisplayDevice(displayManager, new float[]{60f}, Display.TYPE_INTERNAL);
+ callback.waitForExpectedEvent();
+ callback.clear();
+
+ callback.expectsEvent(EVENT_DISPLAY_CONNECTED);
+ FakeDisplayDevice displayDevice =
+ createFakeDisplayDevice(displayManager, new float[]{60f}, Display.TYPE_EXTERNAL);
+ callback.waitForExpectedEvent();
+
+ LogicalDisplay display =
+ logicalDisplayMapper.getDisplayLocked(displayDevice, /* includeDisabled= */ false);
+ assertThat(display.isEnabledLocked()).isTrue();
+ assertThat(callback.receivedEvents()).containsExactly(DISPLAY_GROUP_EVENT_ADDED,
+ EVENT_DISPLAY_CONNECTED, EVENT_DISPLAY_ADDED).inOrder();
+ }
+
+ @Test
public void testConnectInternalDisplay_withDisplayManagement_shouldConnectAndAddDisplay() {
when(mMockFlags.isConnectedDisplayManagementEnabled()).thenReturn(true);
manageDisplaysPermission(/* granted= */ true);
diff --git a/services/tests/mockingservicestests/src/com/android/server/MasterClearReceiverTest.java b/services/tests/mockingservicestests/src/com/android/server/MasterClearReceiverTest.java
index cc97b8f..76a1c3c 100644
--- a/services/tests/mockingservicestests/src/com/android/server/MasterClearReceiverTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/MasterClearReceiverTest.java
@@ -154,10 +154,11 @@
intent.putExtra(Intent.EXTRA_REASON, "Self destruct");
intent.putExtra(Intent.EXTRA_FORCE_FACTORY_RESET, true);
intent.putExtra(Intent.EXTRA_WIPE_ESIMS, true);
+ intent.putExtra("keep_memtag_mode", true);
mReceiver.onReceive(mContext, intent);
verifyRebootWipeUserData(/* shutdown= */ true, /* reason= */ "Self destruct",
- /* force= */ true, /* wipeEuicc= */ true);
+ /* force= */ true, /* wipeEuicc= */ true, /* keepMemtagMode= */ true);
verifyWipeExternalData();
}
@@ -211,7 +212,7 @@
mRebootWipeUserDataLatch.countDown();
return null;
}).when(() -> RecoverySystem
- .rebootWipeUserData(any(), anyBoolean(), any(), anyBoolean(), anyBoolean()));
+ .rebootWipeUserData(any(), anyBoolean(), any(), anyBoolean(), anyBoolean(), anyBoolean()));
}
private void expectWipeExternalData() {
@@ -244,11 +245,16 @@
private void verifyRebootWipeUserData(boolean shutdown, String reason, boolean force,
boolean wipeEuicc) throws Exception {
+ verifyRebootWipeUserData(shutdown, reason, force, wipeEuicc, /* keepMemtagMode= */ false);
+ }
+
+ private void verifyRebootWipeUserData(boolean shutdown, String reason, boolean force,
+ boolean wipeEuicc, boolean keepMemtagMode) throws Exception {
boolean called = mRebootWipeUserDataLatch.await(5, TimeUnit.SECONDS);
assertWithMessage("rebootWipeUserData not called in 5s").that(called).isTrue();
verify(()-> RecoverySystem.rebootWipeUserData(same(mContext), eq(shutdown), eq(reason),
- eq(force), eq(wipeEuicc)));
+ eq(force), eq(wipeEuicc), eq(keepMemtagMode)));
}
private void verifyNoRebootWipeUserData() {
diff --git a/services/tests/mockingservicestests/src/com/android/server/devicepolicy/FactoryResetterTest.java b/services/tests/mockingservicestests/src/com/android/server/devicepolicy/FactoryResetterTest.java
index 4ffa0fb..5f9a17c 100644
--- a/services/tests/mockingservicestests/src/com/android/server/devicepolicy/FactoryResetterTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/devicepolicy/FactoryResetterTest.java
@@ -88,7 +88,7 @@
Log.d(TAG, "Mocking " + inv);
return null;
}).when(() -> RecoverySystem.rebootWipeUserData(any(), anyBoolean(), any(),
- anyBoolean(), anyBoolean()));
+ anyBoolean(), anyBoolean(), anyBoolean()));
}
@After
@@ -270,17 +270,20 @@
private void verifyRebootWipeUserDataMinimumArgsCalled() {
verify(() -> RecoverySystem.rebootWipeUserData(mContext, /* shutdown= */ false,
- /* reason= */ null, /* force= */ false, /* wipeEuicc= */ false));
+ /* reason= */ null, /* force= */ false, /* wipeEuicc= */ false,
+ /* keepMemtagMode= */ false));
}
private void verifyRebootWipeUserDataMinimumArgsButForceCalled() {
verify(() -> RecoverySystem.rebootWipeUserData(mContext, /* shutdown= */ false,
- /* reason= */ null, /* force= */ true, /* wipeEuicc= */ false));
+ /* reason= */ null, /* force= */ true, /* wipeEuicc= */ false,
+ /* keepMemtagMode= */ false));
}
private void verifyRebootWipeUserDataAllArgsCalled() {
verify(() -> RecoverySystem.rebootWipeUserData(mContext, /* shutdown= */ true,
- /* reason= */ REASON, /* force= */ true, /* wipeEuicc= */ true));
+ /* reason= */ REASON, /* force= */ true, /* wipeEuicc= */ true,
+ /* keepMemtagMode= */ false));
}
private void verifyWipeAdoptableStorageNotCalled() {
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/idle/DeviceIdlenessTrackerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/idle/DeviceIdlenessTrackerTest.java
new file mode 100644
index 0000000..09935f2
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/idle/DeviceIdlenessTrackerTest.java
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.job.controllers.idle;
+
+import static android.text.format.DateUtils.HOUR_IN_MILLIS;
+import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.inOrder;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
+import static com.android.server.job.JobSchedulerService.sElapsedRealtimeClock;
+import static com.android.server.job.controllers.idle.DeviceIdlenessTracker.KEY_INACTIVITY_IDLE_THRESHOLD_MS;
+import static com.android.server.job.controllers.idle.DeviceIdlenessTracker.KEY_INACTIVITY_STABLE_POWER_IDLE_THRESHOLD_MS;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import android.app.AlarmManager;
+import android.app.UiModeManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.os.PowerManager;
+import android.os.SystemClock;
+import android.provider.DeviceConfig;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.server.AppSchedulingModuleThread;
+import com.android.server.LocalServices;
+import com.android.server.job.JobSchedulerService;
+
+import org.junit.After;
+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.MockitoSession;
+import org.mockito.quality.Strictness;
+
+import java.time.Clock;
+import java.time.Duration;
+import java.time.ZoneOffset;
+
+@RunWith(AndroidJUnit4.class)
+public class DeviceIdlenessTrackerTest {
+ private DeviceIdlenessTracker mDeviceIdlenessTracker;
+ private JobSchedulerService.Constants mConstants = new JobSchedulerService.Constants();
+ private BroadcastReceiver mBroadcastReceiver;
+ private DeviceConfig.Properties.Builder mDeviceConfigPropertiesBuilder =
+ new DeviceConfig.Properties.Builder(DeviceConfig.NAMESPACE_JOB_SCHEDULER);;
+
+ private MockitoSession mMockingSession;
+ @Mock
+ private AlarmManager mAlarmManager;
+ @Mock
+ private Context mContext;
+ @Mock
+ private JobSchedulerService mJobSchedulerService;
+ @Mock
+ private PowerManager mPowerManager;
+ @Mock
+ private Resources mResources;
+
+ @Before
+ public void setUp() {
+ mMockingSession = mockitoSession()
+ .initMocks(this)
+ .strictness(Strictness.LENIENT)
+ .spyStatic(DeviceConfig.class)
+ .mockStatic(LocalServices.class)
+ .startMocking();
+
+ // Called in StateController constructor.
+ when(mJobSchedulerService.getTestableContext()).thenReturn(mContext);
+ when(mJobSchedulerService.getLock()).thenReturn(mJobSchedulerService);
+ when(mJobSchedulerService.getConstants()).thenReturn(mConstants);
+ // Called in DeviceIdlenessTracker.startTracking.
+ when(mContext.getSystemService(Context.ALARM_SERVICE)).thenReturn(mAlarmManager);
+ when(mContext.getSystemService(UiModeManager.class)).thenReturn(mock(UiModeManager.class));
+ when(mContext.getResources()).thenReturn(mResources);
+ doReturn((int) (31 * MINUTE_IN_MILLIS)).when(mResources).getInteger(
+ com.android.internal.R.integer.config_jobSchedulerInactivityIdleThreshold);
+ doReturn((int) (17 * MINUTE_IN_MILLIS)).when(mResources).getInteger(
+ com.android.internal.R.integer
+ .config_jobSchedulerInactivityIdleThresholdOnStablePower);
+ doReturn(mPowerManager).when(() -> LocalServices.getService(PowerManager.class));
+
+ // Freeze the clocks at 24 hours after this moment in time. Several tests create sessions
+ // in the past, and QuotaController sometimes floors values at 0, so if the test time
+ // causes sessions with negative timestamps, they will fail.
+ JobSchedulerService.sSystemClock =
+ getAdvancedClock(Clock.fixed(Clock.systemUTC().instant(), ZoneOffset.UTC),
+ 24 * HOUR_IN_MILLIS);
+ JobSchedulerService.sUptimeMillisClock = getAdvancedClock(
+ Clock.fixed(SystemClock.uptimeClock().instant(), ZoneOffset.UTC),
+ 24 * HOUR_IN_MILLIS);
+ JobSchedulerService.sElapsedRealtimeClock = getAdvancedClock(
+ Clock.fixed(SystemClock.elapsedRealtimeClock().instant(), ZoneOffset.UTC),
+ 24 * HOUR_IN_MILLIS);
+
+ // Initialize real objects.
+ // Capture the listeners.
+ ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor =
+ ArgumentCaptor.forClass(BroadcastReceiver.class);
+ mDeviceIdlenessTracker = new DeviceIdlenessTracker();
+ mDeviceIdlenessTracker.startTracking(mContext,
+ mJobSchedulerService, mock(IdlenessListener.class));
+
+ verify(mContext).registerReceiver(broadcastReceiverCaptor.capture(), any(), any(), any());
+ mBroadcastReceiver = broadcastReceiverCaptor.getValue();
+ }
+
+ @After
+ public void tearDown() {
+ if (mMockingSession != null) {
+ mMockingSession.finishMocking();
+ }
+ }
+
+ private Clock getAdvancedClock(Clock clock, long incrementMs) {
+ return Clock.offset(clock, Duration.ofMillis(incrementMs));
+ }
+
+ private void advanceElapsedClock(long incrementMs) {
+ JobSchedulerService.sElapsedRealtimeClock = getAdvancedClock(
+ JobSchedulerService.sElapsedRealtimeClock, incrementMs);
+ }
+
+ private void setBatteryState(boolean isCharging, boolean isBatteryNotLow) {
+ doReturn(isCharging).when(mJobSchedulerService).isBatteryCharging();
+ doReturn(isBatteryNotLow).when(mJobSchedulerService).isBatteryNotLow();
+ mDeviceIdlenessTracker.onBatteryStateChanged(isCharging, isBatteryNotLow);
+ }
+
+ private void setDeviceConfigLong(String key, long val) {
+ mDeviceConfigPropertiesBuilder.setLong(key, val);
+ mDeviceIdlenessTracker.processConstant(mDeviceConfigPropertiesBuilder.build(), key);
+ }
+
+ @Test
+ public void testThresholdChangeWithStablePowerChange() {
+ setDeviceConfigLong(KEY_INACTIVITY_IDLE_THRESHOLD_MS, 10 * MINUTE_IN_MILLIS);
+ setDeviceConfigLong(KEY_INACTIVITY_STABLE_POWER_IDLE_THRESHOLD_MS, 5 * MINUTE_IN_MILLIS);
+ setBatteryState(false, false);
+
+ Intent screenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF);
+ mBroadcastReceiver.onReceive(mContext, screenOffIntent);
+
+ final long nowElapsed = sElapsedRealtimeClock.millis();
+ long expectedUnstableAlarmElapsed = nowElapsed + 10 * MINUTE_IN_MILLIS;
+ long expectedStableAlarmElapsed = nowElapsed + 5 * MINUTE_IN_MILLIS;
+
+ InOrder inOrder = inOrder(mAlarmManager);
+ inOrder.verify(mAlarmManager)
+ .setWindow(anyInt(), eq(expectedUnstableAlarmElapsed), anyLong(), anyString(),
+ eq(AppSchedulingModuleThread.getExecutor()), any());
+
+ // Advanced the clock a little to make sure the tracker continues to use the original time.
+ advanceElapsedClock(MINUTE_IN_MILLIS);
+
+ // Charging isn't enough for stable power.
+ setBatteryState(true, false);
+ inOrder.verify(mAlarmManager, never())
+ .setWindow(anyInt(), anyLong(), anyLong(), anyString(),
+ eq(AppSchedulingModuleThread.getExecutor()), any());
+
+ // Now on stable power.
+ setBatteryState(true, true);
+ inOrder.verify(mAlarmManager)
+ .setWindow(anyInt(), eq(expectedStableAlarmElapsed), anyLong(), anyString(),
+ eq(AppSchedulingModuleThread.getExecutor()), any());
+
+ // Battery-not-low isn't enough for stable power. Go back to unstable timing.
+ setBatteryState(false, true);
+ inOrder.verify(mAlarmManager)
+ .setWindow(anyInt(), eq(expectedUnstableAlarmElapsed), anyLong(), anyString(),
+ eq(AppSchedulingModuleThread.getExecutor()), any());
+
+ // Still not on stable power.
+ setBatteryState(false, false);
+ inOrder.verify(mAlarmManager, never())
+ .setWindow(anyInt(), anyLong(), anyLong(), anyString(),
+ eq(AppSchedulingModuleThread.getExecutor()), any());
+ }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/PackageHelperTestBase.kt b/services/tests/mockingservicestests/src/com/android/server/pm/PackageHelperTestBase.kt
index eb00164..a6ba5d4 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/PackageHelperTestBase.kt
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/PackageHelperTestBase.kt
@@ -87,8 +87,8 @@
TEST_PACKAGE_1, TEST_PACKAGE_2, DEVICE_OWNER_PACKAGE, DEVICE_ADMIN_PACKAGE,
DEFAULT_HOME_PACKAGE, DIALER_PACKAGE, INSTALLER_PACKAGE, UNINSTALLER_PACKAGE,
VERIFIER_PACKAGE, PERMISSION_CONTROLLER_PACKAGE))
- suspendPackageHelper = SuspendPackageHelper(pms, rule.mocks().injector,
- rule.mocks().userManagerService, broadcastHelper, protectedPackages)
+ suspendPackageHelper = SuspendPackageHelper(
+ pms, rule.mocks().injector, broadcastHelper, protectedPackages)
defaultAppProvider = rule.mocks().defaultAppProvider
testHandler = rule.mocks().handler
packageSetting1 = pms.snapshotComputer().getPackageStateInternal(TEST_PACKAGE_1)!!
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/SuspendPackageHelperTest.kt b/services/tests/mockingservicestests/src/com/android/server/pm/SuspendPackageHelperTest.kt
index 4240373..7b381ce 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/SuspendPackageHelperTest.kt
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/SuspendPackageHelperTest.kt
@@ -39,7 +39,7 @@
val failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
targetPackages, true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)
testHandler.flush()
verify(pms).scheduleWritePackageRestrictions(eq(TEST_USER_ID))
@@ -56,14 +56,14 @@
var failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
null /* packageNames */, true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)
assertThat(failedNames).isNull()
failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOfNulls(0), true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)
assertThat(failedNames).isEmpty()
}
@@ -73,7 +73,7 @@
val failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOf(TEST_PACKAGE_2), true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, TEST_PACKAGE_1, TEST_USER_ID,
- Binder.getCallingUid(), false /* forQuietMode */, false /* quarantined */)
+ Binder.getCallingUid(), false /* quarantined */)
assertThat(failedNames).asList().hasSize(1)
assertThat(failedNames).asList().contains(TEST_PACKAGE_2)
@@ -84,7 +84,7 @@
val failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOf(DEVICE_OWNER_PACKAGE), true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)
assertThat(failedNames).asList().hasSize(1)
assertThat(failedNames).asList().contains(DEVICE_OWNER_PACKAGE)
@@ -95,7 +95,7 @@
val failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOf(NONEXISTENT_PACKAGE), true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)
assertThat(failedNames).asList().hasSize(1)
assertThat(failedNames).asList().contains(NONEXISTENT_PACKAGE)
@@ -108,7 +108,7 @@
val failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
knownPackages, true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)!!
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)!!
assertThat(failedNames.size).isEqualTo(knownPackages.size)
for (pkg in knownPackages) {
@@ -117,33 +117,19 @@
}
@Test
- fun setPackagesSuspended_forQuietMode() {
- val knownPackages = arrayOf(DEVICE_ADMIN_PACKAGE, DEFAULT_HOME_PACKAGE, DIALER_PACKAGE,
- INSTALLER_PACKAGE, UNINSTALLER_PACKAGE, VERIFIER_PACKAGE,
- PERMISSION_CONTROLLER_PACKAGE, MGMT_ROLE_HOLDER_PACKAGE)
- val failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
- knownPackages, true /* suspended */, null /* appExtras */,
- null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, true /* forQuietMode */, false /* quarantined */)!!
-
- assertThat(failedNames.size).isEqualTo(1)
- assertThat(failedNames[0]).isEqualTo(MGMT_ROLE_HOLDER_PACKAGE)
- }
-
- @Test
fun setPackagesUnsuspended() {
val targetPackages = arrayOf(TEST_PACKAGE_1, TEST_PACKAGE_2)
var failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
targetPackages, true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)
testHandler.flush()
Mockito.clearInvocations(broadcastHelper)
assertThat(failedNames).isEmpty()
failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
targetPackages, false /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)
testHandler.flush()
verify(pms, times(2)).scheduleWritePackageRestrictions(eq(TEST_USER_ID))
@@ -191,7 +177,7 @@
var failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOf(TEST_PACKAGE_1), true /* suspended */, appExtras, null /* launcherExtras */,
null /* dialogInfo */, DEVICE_OWNER_PACKAGE, TEST_USER_ID, deviceOwnerUid,
- false /* forQuietMode */, false /* quarantined */)
+ false /* quarantined */)
testHandler.flush()
assertThat(failedNames).isEmpty()
@@ -209,7 +195,7 @@
var failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
targetPackages, true /* suspended */, appExtras, null /* launcherExtras */,
null /* dialogInfo */, DEVICE_OWNER_PACKAGE, TEST_USER_ID, deviceOwnerUid,
- false /* forQuietMode */, false /* quarantined */)
+ false /* quarantined */)
testHandler.flush()
Mockito.clearInvocations(broadcastHelper)
assertThat(failedNames).isEmpty()
@@ -250,7 +236,7 @@
var failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOf(TEST_PACKAGE_2), true /* suspended */, null /* appExtras */, launcherExtras,
null /* dialogInfo */, DEVICE_OWNER_PACKAGE, TEST_USER_ID, deviceOwnerUid,
- false /* forQuietMode */, false /* quarantined */)
+ false /* quarantined */)
testHandler.flush()
assertThat(failedNames).isEmpty()
@@ -265,7 +251,7 @@
var failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOf(TEST_PACKAGE_1), true /* suspended */, null /* appExtras */,
null /* launcherExtras */, null /* dialogInfo */, DEVICE_OWNER_PACKAGE,
- TEST_USER_ID, deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ TEST_USER_ID, deviceOwnerUid, false /* quarantined */)
testHandler.flush()
assertThat(failedNames).isEmpty()
@@ -280,7 +266,7 @@
var failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOf(TEST_PACKAGE_2), true /* suspended */, null /* appExtras */, launcherExtras,
null /* dialogInfo */, DEVICE_OWNER_PACKAGE, TEST_USER_ID, deviceOwnerUid,
- false /* forQuietMode */, false /* quarantined */)
+ false /* quarantined */)
testHandler.flush()
assertThat(failedNames).isEmpty()
@@ -295,7 +281,7 @@
var failedNames = suspendPackageHelper.setPackagesSuspended(pms.snapshotComputer(),
arrayOf(TEST_PACKAGE_1), true /* suspended */, null /* appExtras */,
null /* launcherExtras */, dialogInfo, DEVICE_OWNER_PACKAGE, TEST_USER_ID,
- deviceOwnerUid, false /* forQuietMode */, false /* quarantined */)
+ deviceOwnerUid, false /* quarantined */)
testHandler.flush()
assertThat(failedNames).isEmpty()
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 461d637..2598a6b 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
@@ -347,6 +347,8 @@
final DisplayInfo displayInfo = new DisplayInfo();
displayInfo.uniqueId = UNIQUE_ID;
doReturn(displayInfo).when(mDisplayManagerInternalMock).getDisplayInfo(anyInt());
+ doReturn(Display.INVALID_DISPLAY).when(mDisplayManagerInternalMock)
+ .getDisplayIdToMirror(anyInt());
LocalServices.removeServiceForTest(DisplayManagerInternal.class);
LocalServices.addService(DisplayManagerInternal.class, mDisplayManagerInternalMock);
@@ -1627,6 +1629,7 @@
@Test
public void openNonBlockedAppOnMirrorDisplay_flagDisabled_launchesActivity() {
+ mSetFlagsRule.disableFlags(Flags.FLAG_INTERACTIVE_SCREEN_MIRROR);
when(mDisplayManagerInternalMock.getDisplayIdToMirror(anyInt()))
.thenReturn(Display.DEFAULT_DISPLAY);
addVirtualDisplay(mDeviceImpl, DISPLAY_ID_1);
diff --git a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceRule.java b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceRule.java
index af633cc..dbd6c88 100644
--- a/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceRule.java
+++ b/services/tests/servicestests/src/com/android/server/companion/virtual/VirtualDeviceRule.java
@@ -37,6 +37,7 @@
import android.os.Binder;
import android.testing.TestableContext;
import android.util.ArraySet;
+import android.view.Display;
import android.view.DisplayInfo;
import android.view.WindowManager;
@@ -137,6 +138,8 @@
final DisplayInfo displayInfo = new DisplayInfo();
displayInfo.uniqueId = "uniqueId";
doReturn(displayInfo).when(mDisplayManagerInternalMock).getDisplayInfo(anyInt());
+ doReturn(Display.INVALID_DISPLAY).when(mDisplayManagerInternalMock)
+ .getDisplayIdToMirror(anyInt());
LocalServices.removeServiceForTest(DisplayManagerInternal.class);
LocalServices.addService(DisplayManagerInternal.class, mDisplayManagerInternalMock);
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
index 568471d..526201f 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStartInterceptorTest.java
@@ -247,39 +247,9 @@
}
@Test
- public void testInterceptQuietProfile_keepProfilesRunningEnabled() {
- // GIVEN that the user the activity is starting as is currently in quiet mode and
- // profiles are kept running when in quiet mode.
+ public void testInterceptQuietProfile() {
+ // GIVEN that the user the activity is starting as is currently in quiet mode
when(mUserManager.isQuietModeEnabled(eq(UserHandle.of(TEST_USER_ID)))).thenReturn(true);
- when(mDevicePolicyManager.isKeepProfilesRunningEnabled()).thenReturn(true);
-
- // THEN calling intercept returns false because package also has to be suspended.
- assertFalse(
- mInterceptor.intercept(null, null, mAInfo, null, null, null, 0, 0, null, null));
- }
-
- @Test
- public void testInterceptQuietProfile_keepProfilesRunningDisabled() {
- // GIVEN that the user the activity is starting as is currently in quiet mode and
- // profiles are stopped when in quiet mode (pre-U behavior, no profile app suspension).
- when(mUserManager.isQuietModeEnabled(eq(UserHandle.of(TEST_USER_ID)))).thenReturn(true);
- when(mDevicePolicyManager.isKeepProfilesRunningEnabled()).thenReturn(false);
-
- // THEN calling intercept returns true
- assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, null, 0, 0, null, null));
-
- // THEN the returned intent is the quiet mode intent
- assertTrue(UnlaunchableAppActivity.createInQuietModeDialogIntent(TEST_USER_ID)
- .filterEquals(mInterceptor.mIntent));
- }
-
- @Test
- public void testInterceptQuietProfileWhenPackageSuspended_keepProfilesRunningEnabled() {
- // GIVEN that the user the activity is starting as is currently in quiet mode,
- // the package is suspended and profiles are kept running while in quiet mode.
- suspendPackage("com.test.suspending.package");
- when(mUserManager.isQuietModeEnabled(eq(UserHandle.of(TEST_USER_ID)))).thenReturn(true);
- when(mDevicePolicyManager.isKeepProfilesRunningEnabled()).thenReturn(true);
// THEN calling intercept returns true
assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, null, 0, 0, null, null));
@@ -290,12 +260,10 @@
}
@Test
- public void testInterceptQuietProfileWhenPackageSuspended_keepProfilesRunningDisabled() {
- // GIVEN that the user the activity is starting as is currently in quiet mode,
- // the package is suspended and profiles are stopped while in quiet mode.
+ public void testInterceptQuietProfileWhenPackageSuspended() {
suspendPackage("com.test.suspending.package");
+ // GIVEN that the user the activity is starting as is currently in quiet mode
when(mUserManager.isQuietModeEnabled(eq(UserHandle.of(TEST_USER_ID)))).thenReturn(true);
- when(mDevicePolicyManager.isKeepProfilesRunningEnabled()).thenReturn(false);
// THEN calling intercept returns true
assertTrue(mInterceptor.intercept(null, null, mAInfo, null, null, null, 0, 0, null, null));
diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
index 4c25a4b..3b4b220 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
@@ -1444,7 +1444,7 @@
});
assertSecurityException(expectCallable,
() -> mAtm.startActivityFromRecents(0, new Bundle()));
- assertSecurityException(expectCallable, () -> mAtm.getTaskSnapshot(0, true, false));
+ assertSecurityException(expectCallable, () -> mAtm.getTaskSnapshot(0, true));
assertSecurityException(expectCallable, () -> mAtm.registerTaskStackListener(null));
assertSecurityException(expectCallable,
() -> mAtm.unregisterTaskStackListener(null));
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
index 435a835..0639deb 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskTests.java
@@ -73,6 +73,7 @@
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.Rect;
@@ -570,12 +571,15 @@
.setWindowingMode(WINDOWING_MODE_FULLSCREEN).setDisplay(display).build();
final Task task = rootTask.getBottomMostTask();
final ActivityRecord root = task.getTopNonFinishingActivity();
+ final PackageManager pm = mContext.getPackageManager();
+ spyOn(pm);
spyOn(mWm.mLetterboxConfiguration);
spyOn(root);
spyOn(root.mLetterboxUiController);
doReturn(true).when(root.mLetterboxUiController)
.shouldEnableUserAspectRatioSettings();
+ doReturn(new Intent()).when(pm).getLaunchIntentForPackage(anyString());
doReturn(false).when(root).inSizeCompatMode();
doReturn(task).when(root).getOrganizedTask();
@@ -593,6 +597,10 @@
doReturn(true).when(root).inSizeCompatMode();
assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);
doReturn(false).when(root).inSizeCompatMode();
+
+ // When app doesn't have any launchable activities the button is not enabled
+ doReturn(null).when(pm).getLaunchIntentForPackage(anyString());
+ assertFalse(task.getTaskInfo().topActivityEligibleForUserAspectRatioButton);
}
/**
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index e413663..f64ab22 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -57,6 +57,7 @@
import android.app.usage.IUsageStatsManager;
import android.app.usage.UsageEvents;
import android.app.usage.UsageEvents.Event;
+import android.app.usage.UsageEventsQuery;
import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import android.app.usage.UsageStatsManager.StandbyBuckets;
@@ -113,6 +114,8 @@
import com.android.server.usage.AppStandbyInternal.AppIdleStateChangeListener;
import com.android.server.utils.AlarmQueue;
+import libcore.util.EmptyArray;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -1478,6 +1481,14 @@
* Called by the Binder stub.
*/
UsageEvents queryEvents(int userId, long beginTime, long endTime, int flags) {
+ return queryEventsWithTypes(userId, beginTime, endTime, flags, EmptyArray.INT);
+ }
+
+ /**
+ * Called by the Binder stub.
+ */
+ UsageEvents queryEventsWithTypes(int userId, long beginTime, long endTime, int flags,
+ int[] eventTypeFilter) {
synchronized (mLock) {
if (!mUserUnlockedStates.contains(userId)) {
Slog.w(TAG, "Failed to query events for locked user " + userId);
@@ -1488,7 +1499,7 @@
if (service == null) {
return null; // user was stopped or removed
}
- return service.queryEvents(beginTime, endTime, flags);
+ return service.queryEvents(beginTime, endTime, flags, eventTypeFilter);
}
}
@@ -2123,7 +2134,7 @@
private final class BinderService extends IUsageStatsManager.Stub {
- private boolean hasPermission(String callingPackage) {
+ private boolean hasQueryPermission(String callingPackage) {
final int callingUid = Binder.getCallingUid();
if (callingUid == Process.SYSTEM_UID) {
return true;
@@ -2203,10 +2214,37 @@
return uid == Process.SYSTEM_UID;
}
+ private UsageEvents queryEventsHelper(int userId, long beginTime, long endTime,
+ String callingPackage, int[] eventTypeFilter) {
+ final int callingUid = Binder.getCallingUid();
+ final int callingPid = Binder.getCallingPid();
+ final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
+ callingUid, userId);
+
+ final long token = Binder.clearCallingIdentity();
+ try {
+ final boolean hideShortcutInvocationEvents = shouldHideShortcutInvocationEvents(
+ userId, callingPackage, callingPid, callingUid);
+ final boolean hideLocusIdEvents = shouldHideLocusIdEvents(callingPid, callingUid);
+ final boolean obfuscateNotificationEvents = shouldObfuscateNotificationEvents(
+ callingPid, callingUid);
+ int flags = UsageEvents.SHOW_ALL_EVENT_DATA;
+ if (obfuscateInstantApps) flags |= UsageEvents.OBFUSCATE_INSTANT_APPS;
+ if (hideShortcutInvocationEvents) flags |= UsageEvents.HIDE_SHORTCUT_EVENTS;
+ if (hideLocusIdEvents) flags |= UsageEvents.HIDE_LOCUS_EVENTS;
+ if (obfuscateNotificationEvents) flags |= UsageEvents.OBFUSCATE_NOTIFICATION_EVENTS;
+
+ return UsageStatsService.this.queryEventsWithTypes(userId, beginTime, endTime,
+ flags, eventTypeFilter);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
@Override
public ParceledListSlice<UsageStats> queryUsageStats(int bucketType, long beginTime,
long endTime, String callingPackage, int userId) {
- if (!hasPermission(callingPackage)) {
+ if (!hasQueryPermission(callingPackage)) {
return null;
}
@@ -2234,7 +2272,7 @@
@Override
public ParceledListSlice<ConfigurationStats> queryConfigurationStats(int bucketType,
long beginTime, long endTime, String callingPackage) throws RemoteException {
- if (!hasPermission(callingPackage)) {
+ if (!hasQueryPermission(callingPackage)) {
return null;
}
@@ -2256,7 +2294,7 @@
@Override
public ParceledListSlice<EventStats> queryEventStats(int bucketType,
long beginTime, long endTime, String callingPackage) throws RemoteException {
- if (!hasPermission(callingPackage)) {
+ if (!hasQueryPermission(callingPackage)) {
return null;
}
@@ -2277,32 +2315,25 @@
@Override
public UsageEvents queryEvents(long beginTime, long endTime, String callingPackage) {
- if (!hasPermission(callingPackage)) {
+ if (!hasQueryPermission(callingPackage)) {
return null;
}
- final int userId = UserHandle.getCallingUserId();
- final int callingUid = Binder.getCallingUid();
- final int callingPid = Binder.getCallingPid();
- final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
- callingUid, userId);
+ return queryEventsHelper(UserHandle.getCallingUserId(), beginTime, endTime,
+ callingPackage, /* eventTypeFilter= */ EmptyArray.INT);
+ }
- final long token = Binder.clearCallingIdentity();
- try {
- final boolean hideShortcutInvocationEvents = shouldHideShortcutInvocationEvents(
- userId, callingPackage, callingPid, callingUid);
- final boolean hideLocusIdEvents = shouldHideLocusIdEvents(callingPid, callingUid);
- final boolean obfuscateNotificationEvents = shouldObfuscateNotificationEvents(
- callingPid, callingUid);
- int flags = UsageEvents.SHOW_ALL_EVENT_DATA;
- if (obfuscateInstantApps) flags |= UsageEvents.OBFUSCATE_INSTANT_APPS;
- if (hideShortcutInvocationEvents) flags |= UsageEvents.HIDE_SHORTCUT_EVENTS;
- if (hideLocusIdEvents) flags |= UsageEvents.HIDE_LOCUS_EVENTS;
- if (obfuscateNotificationEvents) flags |= UsageEvents.OBFUSCATE_NOTIFICATION_EVENTS;
- return UsageStatsService.this.queryEvents(userId, beginTime, endTime, flags);
- } finally {
- Binder.restoreCallingIdentity(token);
+ @Override
+ public UsageEvents queryEventsWithFilter(@NonNull UsageEventsQuery query,
+ @NonNull String callingPackage) {
+ Objects.requireNonNull(query);
+ Objects.requireNonNull(callingPackage);
+
+ if (!hasQueryPermission(callingPackage)) {
+ return null;
}
+ return queryEventsHelper(UserHandle.getCallingUserId(), query.getBeginTimeMillis(),
+ query.getEndTimeMillis(), callingPackage, query.getEventTypeFilter());
}
@Override
@@ -2312,7 +2343,7 @@
final int callingUserId = UserHandle.getUserId(callingUid);
checkCallerIsSameApp(callingPackage);
- final boolean includeTaskRoot = hasPermission(callingPackage);
+ final boolean includeTaskRoot = hasQueryPermission(callingPackage);
final long token = Binder.clearCallingIdentity();
try {
@@ -2326,7 +2357,7 @@
@Override
public UsageEvents queryEventsForUser(long beginTime, long endTime, int userId,
String callingPackage) {
- if (!hasPermission(callingPackage)) {
+ if (!hasQueryPermission(callingPackage)) {
return null;
}
@@ -2337,33 +2368,14 @@
"No permission to query usage stats for this user");
}
- final int callingUid = Binder.getCallingUid();
- final int callingPid = Binder.getCallingPid();
- final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
- callingUid, callingUserId);
-
- final long token = Binder.clearCallingIdentity();
- try {
- final boolean hideShortcutInvocationEvents = shouldHideShortcutInvocationEvents(
- userId, callingPackage, callingPid, callingUid);
- final boolean obfuscateNotificationEvents = shouldObfuscateNotificationEvents(
- callingPid, callingUid);
- boolean hideLocusIdEvents = shouldHideLocusIdEvents(callingPid, callingUid);
- int flags = UsageEvents.SHOW_ALL_EVENT_DATA;
- if (obfuscateInstantApps) flags |= UsageEvents.OBFUSCATE_INSTANT_APPS;
- if (hideShortcutInvocationEvents) flags |= UsageEvents.HIDE_SHORTCUT_EVENTS;
- if (hideLocusIdEvents) flags |= UsageEvents.HIDE_LOCUS_EVENTS;
- if (obfuscateNotificationEvents) flags |= UsageEvents.OBFUSCATE_NOTIFICATION_EVENTS;
- return UsageStatsService.this.queryEvents(userId, beginTime, endTime, flags);
- } finally {
- Binder.restoreCallingIdentity(token);
- }
+ return queryEventsHelper(userId, beginTime, endTime, callingPackage,
+ /* eventTypeFilter= */ EmptyArray.INT);
}
@Override
public UsageEvents queryEventsForPackageForUser(long beginTime, long endTime,
int userId, String pkg, String callingPackage) {
- if (!hasPermission(callingPackage)) {
+ if (!hasQueryPermission(callingPackage)) {
return null;
}
if (userId != UserHandle.getCallingUserId()) {
@@ -2404,7 +2416,7 @@
if (actualCallingUid != callingUid) {
return false;
}
- } else if (!hasPermission(callingPackage)) {
+ } else if (!hasQueryPermission(callingPackage)) {
return false;
}
final boolean obfuscateInstantApps = shouldObfuscateInstantAppsForCaller(
@@ -2454,7 +2466,7 @@
final int packageUid = mPackageManagerInternal.getPackageUid(packageName, 0, userId);
// If the calling app is asking about itself, continue, else check for permission.
final boolean sameApp = packageUid == callingUid;
- if (!sameApp && !hasPermission(callingPackage)) {
+ if (!sameApp && !hasQueryPermission(callingPackage)) {
throw new SecurityException("Don't have permission to query app standby bucket");
}
@@ -2502,7 +2514,7 @@
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
- if (!hasPermission(callingPackageName)) {
+ if (!hasQueryPermission(callingPackageName)) {
throw new SecurityException(
"Don't have permission to query app standby bucket");
}
@@ -2556,7 +2568,7 @@
final int packageUid = mPackageManagerInternal.getPackageUid(packageName, 0, userId);
// If the calling app is asking about itself, continue, else check for permission.
if (packageUid != callingUid) {
- if (!hasPermission(callingPackage)) {
+ if (!hasQueryPermission(callingPackage)) {
throw new SecurityException(
"Don't have permission to query min app standby bucket");
}
@@ -2900,7 +2912,7 @@
if (!hasPermissions(android.Manifest.permission.INTERACT_ACROSS_USERS)) {
throw new SecurityException("Caller doesn't have INTERACT_ACROSS_USERS permission");
}
- if (!hasPermission(callingPackage)) {
+ if (!hasQueryPermission(callingPackage)) {
throw new SecurityException("Don't have permission to query usage stats");
}
synchronized (mLock) {
diff --git a/services/usage/java/com/android/server/usage/UserUsageStatsService.java b/services/usage/java/com/android/server/usage/UserUsageStatsService.java
index ddb2796..9b67ab6 100644
--- a/services/usage/java/com/android/server/usage/UserUsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UserUsageStatsService.java
@@ -70,7 +70,7 @@
* in UsageStatsService.
*/
class UserUsageStatsService {
- private static final String TAG = "UsageStatsService";
+ private static final String TAG = UsageStatsService.TAG;
private static final boolean DEBUG = UsageStatsService.DEBUG;
private static final SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final int sDateFormatFlags =
@@ -535,10 +535,23 @@
return queryStats(bucketType, beginTime, endTime, sEventStatsCombiner, true);
}
- UsageEvents queryEvents(final long beginTime, final long endTime, int flags) {
+ UsageEvents queryEvents(final long beginTime, final long endTime, int flags,
+ int[] eventTypeFilter) {
if (!validRange(checkAndGetTimeLocked(), beginTime, endTime)) {
return null;
}
+
+ // Ensure valid event type filter.
+ final boolean isQueryForAllEvents = ArrayUtils.isEmpty(eventTypeFilter);
+ final boolean[] queryEventFilter = new boolean[Event.MAX_EVENT_TYPE + 1];
+ if (!isQueryForAllEvents) {
+ for (int eventType : eventTypeFilter) {
+ if (eventType < Event.NONE || eventType > Event.MAX_EVENT_TYPE) {
+ throw new IllegalArgumentException("invalid event type: " + eventType);
+ }
+ queryEventFilter[eventType] = true;
+ }
+ }
final ArraySet<String> names = new ArraySet<>();
List<Event> results = queryStats(INTERVAL_DAILY,
beginTime, endTime, new StatCombiner<Event>() {
@@ -547,6 +560,7 @@
List<Event> accumulatedResult) {
final int startIndex = stats.events.firstIndexOnOrAfter(beginTime);
final int size = stats.events.size();
+
for (int i = startIndex; i < size; i++) {
Event event = stats.events.get(i);
if (event.mTimeStamp >= endTime) {
@@ -554,6 +568,10 @@
}
final int eventType = event.mEventType;
+ if (!isQueryForAllEvents && !queryEventFilter[eventType]) {
+ continue;
+ }
+
if (eventType == Event.SHORTCUT_INVOCATION
&& (flags & HIDE_SHORTCUT_EVENTS) == HIDE_SHORTCUT_EVENTS) {
continue;
diff --git a/tests/FlickerTests/AndroidTestTemplate.xml b/tests/FlickerTests/AndroidTestTemplate.xml
index 85709c9..ed71531 100644
--- a/tests/FlickerTests/AndroidTestTemplate.xml
+++ b/tests/FlickerTests/AndroidTestTemplate.xml
@@ -28,7 +28,13 @@
<option name="run-command" value="su root service call SurfaceFlinger 1029 i32 81920"/>
<!-- b/307664397 - Ensure camera has the correct permissions and doesn't show a dialog -->
<option name="run-command"
+ value="pm grant com.google.android.GoogleCamera android.permission.CAMERA"/>
+ <option name="run-command"
+ value="pm grant com.google.android.GoogleCamera android.permission.RECORD_AUDIO"/>
+ <option name="run-command"
value="pm grant com.google.android.GoogleCamera android.permission.ACCESS_FINE_LOCATION"/>
+ <option name="run-command"
+ value="pm grant com.google.android.GoogleCamera android.permission.ACCESS_COARSE_LOCATION"/>
</target_preparer>
<target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
<option name="test-user-token" value="%TEST_USER%"/>