summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--api/current.txt257
-rw-r--r--api/system-current.txt33
-rw-r--r--core/java/android/app/ContextImpl.java7
-rw-r--r--core/java/android/app/LoadedApk.java13
-rw-r--r--core/java/android/content/ContentProvider.java9
-rw-r--r--core/java/android/content/Context.java5
-rw-r--r--core/java/android/content/Intent.java5
-rw-r--r--core/java/android/content/pm/ApplicationInfo.java2
-rw-r--r--core/java/android/content/pm/PackageItemInfo.java10
-rw-r--r--core/java/android/hardware/camera2/CameraDevice.java30
-rw-r--r--core/java/android/hardware/camera2/impl/CameraDeviceImpl.java11
-rw-r--r--core/java/android/hardware/camera2/impl/ICameraDeviceUserWrapper.java21
-rw-r--r--core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java7
-rw-r--r--core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java26
-rw-r--r--core/java/android/hardware/camera2/params/SessionConfiguration.java110
-rw-r--r--core/java/android/os/Binder.java24
-rw-r--r--core/java/android/os/GraphicsEnvironment.java2
-rw-r--r--core/java/android/os/PowerManager.java162
-rw-r--r--core/java/android/provider/DocumentsContract.java17
-rw-r--r--core/java/android/provider/DocumentsProvider.java1
-rw-r--r--core/java/android/provider/Settings.java1
-rw-r--r--core/java/android/service/intelligence/FillCallback.java8
-rw-r--r--core/java/android/service/intelligence/FillRequest.java9
-rw-r--r--core/java/android/service/intelligence/FillWindow.java38
-rw-r--r--core/java/android/service/intelligence/IIntelligenceService.aidl4
-rw-r--r--core/java/android/service/intelligence/SmartSuggestionsService.java104
-rw-r--r--core/java/android/view/View.java242
-rw-r--r--core/java/android/view/textclassifier/ActionsSuggestionsHelper.java6
-rw-r--r--core/java/android/webkit/TokenBindingService.java86
-rw-r--r--core/java/android/webkit/WebViewFactoryProvider.java3
-rw-r--r--core/java/android/widget/Editor.java15
-rw-r--r--core/java/android/widget/RemoteViews.java10
-rw-r--r--core/java/android/widget/TextView.java57
-rw-r--r--core/java/com/android/internal/os/BinderCallsStats.java8
-rw-r--r--core/java/com/android/internal/os/LooperStats.java2
-rw-r--r--core/java/com/android/internal/widget/ImageMessageConsumer.java28
-rw-r--r--core/java/com/android/internal/widget/ImageResolver.java32
-rw-r--r--core/java/com/android/internal/widget/LocalImageResolver.java1
-rw-r--r--core/java/com/android/internal/widget/MessagingImageMessage.java16
-rw-r--r--core/java/com/android/internal/widget/MessagingLayout.java12
-rw-r--r--core/java/com/android/internal/widget/MessagingMessage.java4
-rw-r--r--core/jni/com_android_internal_os_Zygote.cpp40
-rw-r--r--core/proto/android/app/settings_enums.proto6
-rw-r--r--core/proto/android/server/activitymanagerservice.proto1
-rw-r--r--core/proto/android/server/jobscheduler.proto95
-rw-r--r--core/res/res/layout/notification_material_reply_text.xml6
-rw-r--r--core/res/res/layout/notification_template_ambient_header.xml2
-rw-r--r--core/res/res/layout/notification_template_header.xml2
-rw-r--r--core/res/res/layout/notification_template_material_ambient.xml7
-rw-r--r--core/res/res/layout/notification_template_material_big_text.xml2
-rw-r--r--core/res/res/layout/notification_template_material_inbox.xml14
-rw-r--r--core/res/res/layout/notification_template_messaging_group.xml2
-rw-r--r--core/res/res/layout/notification_template_messaging_text_message.xml2
-rw-r--r--core/res/res/layout/notification_template_part_line1.xml4
-rw-r--r--core/res/res/layout/notification_template_text.xml2
-rw-r--r--core/res/res/values/styles_device_defaults.xml19
-rw-r--r--core/res/res/values/styles_material.xml1
-rw-r--r--core/res/res/values/themes_device_defaults.xml6
-rw-r--r--core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java2
-rw-r--r--core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java22
-rw-r--r--core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java6
-rw-r--r--libs/hwui/Android.bp1
-rw-r--r--libs/hwui/RenderNode.cpp10
-rw-r--r--libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp3
-rw-r--r--libs/hwui/pipeline/skia/VkFunctorDrawable.cpp84
-rw-r--r--libs/hwui/pipeline/skia/VkFunctorDrawable.h66
-rw-r--r--libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp2
-rw-r--r--libs/hwui/private/hwui/DrawVkInfo.h107
-rw-r--r--media/java/android/media/CallbackDataSourceDesc.java1
-rw-r--r--media/java/android/media/DataSourceCallback.java1
-rw-r--r--media/java/android/media/DataSourceDesc.java7
-rw-r--r--media/java/android/media/FileDataSourceDesc.java1
-rw-r--r--media/java/android/media/MediaPlayer2.java165
-rw-r--r--media/java/android/media/SubtitleData.java83
-rw-r--r--media/java/android/media/TimedMetaData.java76
-rw-r--r--media/java/android/media/UriDataSourceDesc.java1
-rw-r--r--media/java/android/media/VideoSize.java4
-rw-r--r--media/jni/android_media_MediaPlayer2.cpp12
-rw-r--r--native/webview/plat_support/Android.bp3
-rw-r--r--native/webview/plat_support/draw_gl_functor.cpp27
-rw-r--r--native/webview/plat_support/draw_vk.h125
-rw-r--r--native/webview/plat_support/draw_vk_functor.cpp141
-rw-r--r--native/webview/plat_support/functor_utils.cpp45
-rw-r--r--native/webview/plat_support/functor_utils.h25
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java9
-rw-r--r--packages/SystemUI/src/com/android/systemui/BatteryMeterView.java46
-rw-r--r--packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java13
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java15
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableView.java18
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInflater.java21
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInlineImageCache.java97
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInlineImageResolver.java197
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java11
-rw-r--r--packages/SystemUI/src/com/android/systemui/util/Assert.java9
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java12
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java17
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java25
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/QSTileHostTest.java47
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java7
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java11
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java37
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java7
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java13
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java26
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java11
-rw-r--r--packages/overlays/AccentColorBlackOverlay/Android.mk30
-rw-r--r--packages/overlays/AccentColorBlackOverlay/AndroidManifest.xml25
-rw-r--r--packages/overlays/AccentColorBlackOverlay/res/values/colors_device_defaults.xml22
-rw-r--r--packages/overlays/AccentColorBlackOverlay/res/values/strings.xml23
-rw-r--r--packages/overlays/AccentColorGreenOverlay/Android.mk30
-rw-r--r--packages/overlays/AccentColorGreenOverlay/AndroidManifest.xml25
-rw-r--r--packages/overlays/AccentColorGreenOverlay/res/values/colors_device_defaults.xml22
-rw-r--r--packages/overlays/AccentColorGreenOverlay/res/values/strings.xml23
-rw-r--r--packages/overlays/AccentColorPurpleOverlay/Android.mk30
-rw-r--r--packages/overlays/AccentColorPurpleOverlay/AndroidManifest.xml25
-rw-r--r--packages/overlays/AccentColorPurpleOverlay/res/values/colors_device_defaults.xml22
-rw-r--r--packages/overlays/AccentColorPurpleOverlay/res/values/strings.xml23
-rw-r--r--services/autofill/java/com/android/server/autofill/AutofillManagerService.java2
-rw-r--r--services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java2
-rw-r--r--services/autofill/java/com/android/server/autofill/RemoteFillService.java2
-rw-r--r--services/autofill/java/com/android/server/autofill/Session.java6
-rw-r--r--services/core/java/com/android/server/BinderCallsStatsService.java144
-rw-r--r--services/core/java/com/android/server/RuntimeService.java2
-rw-r--r--services/core/java/com/android/server/StorageManagerService.java10
-rw-r--r--services/core/java/com/android/server/am/ActiveInstrumentation.java2
-rw-r--r--services/core/java/com/android/server/am/ActiveServices.java31
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java43
-rw-r--r--services/core/java/com/android/server/am/ProcessList.java326
-rw-r--r--services/core/java/com/android/server/am/ProcessRecord.java27
-rw-r--r--services/core/java/com/android/server/am/ServiceRecord.java19
-rw-r--r--services/core/java/com/android/server/am/UserController.java2
-rw-r--r--services/core/java/com/android/server/infra/AbstractMasterSystemService.java (renamed from services/core/java/com/android/server/AbstractMasterSystemService.java)4
-rw-r--r--services/core/java/com/android/server/infra/AbstractMultiplePendingRequestsRemoteService.java (renamed from services/core/java/com/android/server/AbstractMultiplePendingRequestsRemoteService.java)2
-rw-r--r--services/core/java/com/android/server/infra/AbstractPerUserSystemService.java (renamed from services/core/java/com/android/server/AbstractPerUserSystemService.java)2
-rw-r--r--services/core/java/com/android/server/infra/AbstractRemoteService.java (renamed from services/core/java/com/android/server/AbstractRemoteService.java)3
-rw-r--r--services/core/java/com/android/server/infra/AbstractSinglePendingRequestRemoteService.java (renamed from services/core/java/com/android/server/AbstractSinglePendingRequestRemoteService.java)2
-rw-r--r--services/core/java/com/android/server/infra/package.html6
-rw-r--r--services/core/java/com/android/server/intelligence/IntelligenceManagerInternal.java6
-rw-r--r--services/core/java/com/android/server/job/JobSchedulerService.java264
-rw-r--r--services/core/java/com/android/server/job/controllers/JobStatus.java70
-rw-r--r--services/core/java/com/android/server/job/controllers/QuotaController.java1299
-rw-r--r--services/core/java/com/android/server/job/controllers/StateController.java9
-rw-r--r--services/core/java/com/android/server/wm/ActivityRecord.java2
-rw-r--r--services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java3
-rw-r--r--services/core/java/com/android/server/wm/ActivityTaskManagerService.java44
-rw-r--r--services/core/java/com/android/server/wm/DisplayPolicy.java26
-rw-r--r--services/core/java/com/android/server/wm/InputMonitor.java2
-rw-r--r--services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java15
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerInternal.java8
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerService.java24
-rw-r--r--services/core/java/com/android/server/wm/WindowState.java28
-rw-r--r--services/intelligence/java/com/android/server/intelligence/ContentCaptureSession.java10
-rw-r--r--services/intelligence/java/com/android/server/intelligence/IntelligenceManagerService.java8
-rw-r--r--services/intelligence/java/com/android/server/intelligence/IntelligencePerUserService.java9
-rw-r--r--services/intelligence/java/com/android/server/intelligence/RemoteIntelligenceService.java16
-rw-r--r--services/java/com/android/server/SystemServer.java2
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java842
-rw-r--r--services/tests/servicestests/src/com/android/server/BinderCallsStatsServiceTest.java125
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java1
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java67
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java6
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java31
-rw-r--r--telephony/java/android/telephony/euicc/EuiccCardManager.java44
-rw-r--r--telephony/java/com/android/internal/telephony/ITelephony.aidl13
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java14
-rw-r--r--wifi/java/android/net/wifi/WifiScanner.java26
-rw-r--r--wifi/tests/src/android/net/wifi/WifiScannerTest.java27
198 files changed, 6588 insertions, 833 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000000..45884c46ffea
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/.idea
+*.iml
diff --git a/api/current.txt b/api/current.txt
index 2eb90d50c1c8..802e50e5abaf 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -16499,6 +16499,7 @@ package android.hardware.camera2 {
method public abstract void createReprocessableCaptureSession(android.hardware.camera2.params.InputConfiguration, java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
method public abstract void createReprocessableCaptureSessionByConfigurations(android.hardware.camera2.params.InputConfiguration, java.util.List<android.hardware.camera2.params.OutputConfiguration>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
method public abstract java.lang.String getId();
+ method public boolean isSessionConfigurationSupported(android.hardware.camera2.params.SessionConfiguration) throws android.hardware.camera2.CameraAccessException;
field public static final int TEMPLATE_MANUAL = 6; // 0x6
field public static final int TEMPLATE_PREVIEW = 1; // 0x1
field public static final int TEMPLATE_RECORD = 3; // 0x3
@@ -17096,8 +17097,9 @@ package android.hardware.camera2.params {
field public static final int RED = 0; // 0x0
}
- public final class SessionConfiguration {
+ public final class SessionConfiguration implements android.os.Parcelable {
ctor public SessionConfiguration(int, java.util.List<android.hardware.camera2.params.OutputConfiguration>, java.util.concurrent.Executor, android.hardware.camera2.CameraCaptureSession.StateCallback);
+ method public int describeContents();
method public java.util.concurrent.Executor getExecutor();
method public android.hardware.camera2.params.InputConfiguration getInputConfiguration();
method public java.util.List<android.hardware.camera2.params.OutputConfiguration> getOutputConfigurations();
@@ -17106,6 +17108,8 @@ package android.hardware.camera2.params {
method public android.hardware.camera2.CameraCaptureSession.StateCallback getStateCallback();
method public void setInputConfiguration(android.hardware.camera2.params.InputConfiguration);
method public void setSessionParameters(android.hardware.camera2.CaptureRequest);
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.hardware.camera2.params.SessionConfiguration> CREATOR;
field public static final int SESSION_HIGH_SPEED = 1; // 0x1
field public static final int SESSION_REGULAR = 0; // 0x0
}
@@ -23437,6 +23441,17 @@ package android.media {
method public void onTearDown(android.media.AudioTrack);
}
+ public class CallbackDataSourceDesc extends android.media.DataSourceDesc {
+ method public android.media.DataSourceCallback getDataSourceCallback();
+ }
+
+ public static class CallbackDataSourceDesc.Builder extends android.media.DataSourceDesc.BuilderBase {
+ ctor public CallbackDataSourceDesc.Builder();
+ ctor public CallbackDataSourceDesc.Builder(android.media.CallbackDataSourceDesc);
+ method public android.media.CallbackDataSourceDesc build();
+ method public android.media.CallbackDataSourceDesc.Builder setDataSource(android.media.DataSourceCallback);
+ }
+
public class CamcorderProfile {
method public static android.media.CamcorderProfile get(int);
method public static android.media.CamcorderProfile get(int, int);
@@ -23489,6 +23504,26 @@ package android.media {
field public static final int QUALITY_MEDIUM = 1; // 0x1
}
+ public abstract class DataSourceCallback implements java.io.Closeable {
+ ctor public DataSourceCallback();
+ method public abstract long getSize() throws java.io.IOException;
+ method public abstract int readAt(long, byte[], int, int) throws java.io.IOException;
+ }
+
+ public class DataSourceDesc {
+ method public long getEndPosition();
+ method public java.lang.String getMediaId();
+ method public long getStartPosition();
+ field public static final long LONG_MAX_TIME_MS = 576460752303423L; // 0x20c49ba5e353fL
+ field public static final long POSITION_UNKNOWN = 576460752303423L; // 0x20c49ba5e353fL
+ }
+
+ protected static class DataSourceDesc.BuilderBase<T extends android.media.DataSourceDesc.BuilderBase> {
+ method public T setEndPosition(long);
+ method public T setMediaId(java.lang.String);
+ method public T setStartPosition(long);
+ }
+
public final class DeniedByServerException extends android.media.MediaDrmException {
ctor public DeniedByServerException(java.lang.String);
}
@@ -23689,6 +23724,21 @@ package android.media {
field public static final int EULER_Z = 2; // 0x2
}
+ public class FileDataSourceDesc extends android.media.DataSourceDesc {
+ method public long getLength();
+ method public long getOffset();
+ method public android.os.ParcelFileDescriptor getParcelFileDescriptor();
+ field public static final long FD_LENGTH_UNKNOWN = 576460752303423487L; // 0x7ffffffffffffffL
+ }
+
+ public static class FileDataSourceDesc.Builder extends android.media.DataSourceDesc.BuilderBase {
+ ctor public FileDataSourceDesc.Builder();
+ ctor public FileDataSourceDesc.Builder(android.media.FileDataSourceDesc);
+ method public android.media.FileDataSourceDesc build();
+ method public android.media.FileDataSourceDesc.Builder setDataSource(android.os.ParcelFileDescriptor);
+ method public android.media.FileDataSourceDesc.Builder setDataSource(android.os.ParcelFileDescriptor, long, long);
+ }
+
public abstract class Image implements java.lang.AutoCloseable {
method public abstract void close();
method public android.graphics.Rect getCropRect();
@@ -25076,6 +25126,166 @@ package android.media {
field public static final int MEDIA_TRACK_TYPE_VIDEO = 1; // 0x1
}
+ public class MediaPlayer2 implements android.media.AudioRouting java.lang.AutoCloseable {
+ ctor public MediaPlayer2(android.content.Context);
+ method public void addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener, android.os.Handler);
+ method public java.lang.Object attachAuxEffect(int);
+ method public boolean cancelCommand(java.lang.Object);
+ method public java.lang.Object clearNextDataSources();
+ method public void clearPendingCommands();
+ method public void close();
+ method public java.lang.Object deselectTrack(int);
+ method public android.media.AudioAttributes getAudioAttributes();
+ method public int getAudioSessionId();
+ method public long getBufferedPosition();
+ method public android.media.DataSourceDesc getCurrentDataSource();
+ method public long getCurrentPosition();
+ method public long getDuration();
+ method public float getMaxPlayerVolume();
+ method public android.os.PersistableBundle getMetrics();
+ method public android.media.PlaybackParams getPlaybackParams();
+ method public float getPlayerVolume();
+ method public android.media.AudioDeviceInfo getPreferredDevice();
+ method public android.media.AudioDeviceInfo getRoutedDevice();
+ method public int getSelectedTrack(int);
+ method public int getState();
+ method public android.media.SyncParams getSyncParams();
+ method public android.media.MediaTimestamp getTimestamp();
+ method public java.util.List<android.media.MediaPlayer2.TrackInfo> getTrackInfo();
+ method public android.media.VideoSize getVideoSize();
+ method public boolean isLooping();
+ method public java.lang.Object loopCurrent(boolean);
+ method public java.lang.Object notifyWhenCommandLabelReached(java.lang.Object);
+ method public java.lang.Object pause();
+ method public java.lang.Object play();
+ method public java.lang.Object prepare();
+ method public void registerEventCallback(java.util.concurrent.Executor, android.media.MediaPlayer2.EventCallback);
+ method public void removeOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener);
+ method public void reset();
+ method public java.lang.Object seekTo(long);
+ method public java.lang.Object seekTo(long, int);
+ method public java.lang.Object selectTrack(int);
+ method public java.lang.Object setAudioAttributes(android.media.AudioAttributes);
+ method public java.lang.Object setAudioSessionId(int);
+ method public java.lang.Object setAuxEffectSendLevel(float);
+ method public java.lang.Object setDataSource(android.media.DataSourceDesc);
+ method public java.lang.Object setDisplay(android.view.SurfaceHolder);
+ method public java.lang.Object setNextDataSource(android.media.DataSourceDesc);
+ method public java.lang.Object setNextDataSources(java.util.List<android.media.DataSourceDesc>);
+ method public java.lang.Object setPlaybackParams(android.media.PlaybackParams);
+ method public java.lang.Object setPlayerVolume(float);
+ method public boolean setPreferredDevice(android.media.AudioDeviceInfo);
+ method public java.lang.Object setScreenOnWhilePlaying(boolean);
+ method public java.lang.Object setSurface(android.view.Surface);
+ method public java.lang.Object setSyncParams(android.media.SyncParams);
+ method public java.lang.Object setWakeLock(android.os.PowerManager.WakeLock);
+ method public java.lang.Object skipToNext();
+ method public void unregisterEventCallback(android.media.MediaPlayer2.EventCallback);
+ field public static final int CALL_COMPLETED_ATTACH_AUX_EFFECT = 1; // 0x1
+ field public static final int CALL_COMPLETED_CLEAR_NEXT_DATA_SOURCES = 30; // 0x1e
+ field public static final int CALL_COMPLETED_DESELECT_TRACK = 2; // 0x2
+ field public static final int CALL_COMPLETED_LOOP_CURRENT = 3; // 0x3
+ field public static final int CALL_COMPLETED_PAUSE = 4; // 0x4
+ field public static final int CALL_COMPLETED_PLAY = 5; // 0x5
+ field public static final int CALL_COMPLETED_PREPARE = 6; // 0x6
+ field public static final int CALL_COMPLETED_SEEK_TO = 14; // 0xe
+ field public static final int CALL_COMPLETED_SELECT_TRACK = 15; // 0xf
+ field public static final int CALL_COMPLETED_SET_AUDIO_ATTRIBUTES = 16; // 0x10
+ field public static final int CALL_COMPLETED_SET_AUDIO_SESSION_ID = 17; // 0x11
+ field public static final int CALL_COMPLETED_SET_AUX_EFFECT_SEND_LEVEL = 18; // 0x12
+ field public static final int CALL_COMPLETED_SET_DATA_SOURCE = 19; // 0x13
+ field public static final int CALL_COMPLETED_SET_DISPLAY = 33; // 0x21
+ field public static final int CALL_COMPLETED_SET_NEXT_DATA_SOURCE = 22; // 0x16
+ field public static final int CALL_COMPLETED_SET_NEXT_DATA_SOURCES = 23; // 0x17
+ field public static final int CALL_COMPLETED_SET_PLAYBACK_PARAMS = 24; // 0x18
+ field public static final int CALL_COMPLETED_SET_PLAYER_VOLUME = 26; // 0x1a
+ field public static final int CALL_COMPLETED_SET_SCREEN_ON_WHILE_PLAYING = 35; // 0x23
+ field public static final int CALL_COMPLETED_SET_SURFACE = 27; // 0x1b
+ field public static final int CALL_COMPLETED_SET_SYNC_PARAMS = 28; // 0x1c
+ field public static final int CALL_COMPLETED_SET_WAKE_LOCK = 34; // 0x22
+ field public static final int CALL_COMPLETED_SKIP_TO_NEXT = 29; // 0x1d
+ field public static final int CALL_STATUS_BAD_VALUE = 2; // 0x2
+ field public static final int CALL_STATUS_ERROR_IO = 4; // 0x4
+ field public static final int CALL_STATUS_ERROR_UNKNOWN = -2147483648; // 0x80000000
+ field public static final int CALL_STATUS_INVALID_OPERATION = 1; // 0x1
+ field public static final int CALL_STATUS_NO_DRM_SCHEME = 6; // 0x6
+ field public static final int CALL_STATUS_NO_ERROR = 0; // 0x0
+ field public static final int CALL_STATUS_PERMISSION_DENIED = 3; // 0x3
+ field public static final int CALL_STATUS_SKIPPED = 5; // 0x5
+ field public static final int MEDIA_ERROR_IO = -1004; // 0xfffffc14
+ field public static final int MEDIA_ERROR_MALFORMED = -1007; // 0xfffffc11
+ field public static final int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200; // 0xc8
+ field public static final int MEDIA_ERROR_TIMED_OUT = -110; // 0xffffff92
+ field public static final int MEDIA_ERROR_UNKNOWN = 1; // 0x1
+ field public static final int MEDIA_ERROR_UNSUPPORTED = -1010; // 0xfffffc0e
+ field public static final int MEDIA_INFO_AUDIO_NOT_PLAYING = 804; // 0x324
+ field public static final int MEDIA_INFO_AUDIO_RENDERING_START = 4; // 0x4
+ field public static final int MEDIA_INFO_BAD_INTERLEAVING = 800; // 0x320
+ field public static final int MEDIA_INFO_BUFFERING_END = 702; // 0x2be
+ field public static final int MEDIA_INFO_BUFFERING_START = 701; // 0x2bd
+ field public static final int MEDIA_INFO_BUFFERING_UPDATE = 704; // 0x2c0
+ field public static final int MEDIA_INFO_DATA_SOURCE_END = 5; // 0x5
+ field public static final int MEDIA_INFO_DATA_SOURCE_LIST_END = 6; // 0x6
+ field public static final int MEDIA_INFO_DATA_SOURCE_REPEAT = 7; // 0x7
+ field public static final int MEDIA_INFO_DATA_SOURCE_START = 2; // 0x2
+ field public static final int MEDIA_INFO_METADATA_UPDATE = 802; // 0x322
+ field public static final int MEDIA_INFO_NOT_SEEKABLE = 801; // 0x321
+ field public static final int MEDIA_INFO_PREPARED = 100; // 0x64
+ field public static final int MEDIA_INFO_SUBTITLE_TIMED_OUT = 902; // 0x386
+ field public static final int MEDIA_INFO_UNKNOWN = 1; // 0x1
+ field public static final int MEDIA_INFO_UNSUPPORTED_SUBTITLE = 901; // 0x385
+ field public static final int MEDIA_INFO_VIDEO_NOT_PLAYING = 805; // 0x325
+ field public static final int MEDIA_INFO_VIDEO_RENDERING_START = 3; // 0x3
+ field public static final int MEDIA_INFO_VIDEO_TRACK_LAGGING = 700; // 0x2bc
+ field public static final int PLAYER_STATE_ERROR = 1005; // 0x3ed
+ field public static final int PLAYER_STATE_IDLE = 1001; // 0x3e9
+ field public static final int PLAYER_STATE_PAUSED = 1003; // 0x3eb
+ field public static final int PLAYER_STATE_PLAYING = 1004; // 0x3ec
+ field public static final int PLAYER_STATE_PREPARED = 1002; // 0x3ea
+ field public static final int SEEK_CLOSEST = 3; // 0x3
+ field public static final int SEEK_CLOSEST_SYNC = 2; // 0x2
+ field public static final int SEEK_NEXT_SYNC = 1; // 0x1
+ field public static final int SEEK_PREVIOUS_SYNC = 0; // 0x0
+ }
+
+ public static class MediaPlayer2.EventCallback {
+ ctor public MediaPlayer2.EventCallback();
+ method public void onCallCompleted(android.media.MediaPlayer2, android.media.DataSourceDesc, int, int);
+ method public void onCommandLabelReached(android.media.MediaPlayer2, java.lang.Object);
+ method public void onError(android.media.MediaPlayer2, android.media.DataSourceDesc, int, int);
+ method public void onInfo(android.media.MediaPlayer2, android.media.DataSourceDesc, int, int);
+ method public void onMediaTimeDiscontinuity(android.media.MediaPlayer2, android.media.DataSourceDesc, android.media.MediaTimestamp);
+ method public void onSubtitleData(android.media.MediaPlayer2, android.media.DataSourceDesc, android.media.SubtitleData);
+ method public void onTimedMetaDataAvailable(android.media.MediaPlayer2, android.media.DataSourceDesc, android.media.TimedMetaData);
+ method public void onVideoSizeChanged(android.media.MediaPlayer2, android.media.DataSourceDesc, android.media.VideoSize);
+ }
+
+ public static final class MediaPlayer2.MetricsConstants {
+ field public static final java.lang.String CODEC_AUDIO = "android.media.mediaplayer.audio.codec";
+ field public static final java.lang.String CODEC_VIDEO = "android.media.mediaplayer.video.codec";
+ field public static final java.lang.String DURATION = "android.media.mediaplayer.durationMs";
+ field public static final java.lang.String ERRORS = "android.media.mediaplayer.err";
+ field public static final java.lang.String ERROR_CODE = "android.media.mediaplayer.errcode";
+ field public static final java.lang.String FRAMES = "android.media.mediaplayer.frames";
+ field public static final java.lang.String FRAMES_DROPPED = "android.media.mediaplayer.dropped";
+ field public static final java.lang.String HEIGHT = "android.media.mediaplayer.height";
+ field public static final java.lang.String MIME_TYPE_AUDIO = "android.media.mediaplayer.audio.mime";
+ field public static final java.lang.String MIME_TYPE_VIDEO = "android.media.mediaplayer.video.mime";
+ field public static final java.lang.String PLAYING = "android.media.mediaplayer.playingMs";
+ field public static final java.lang.String WIDTH = "android.media.mediaplayer.width";
+ }
+
+ public static class MediaPlayer2.TrackInfo {
+ method public android.media.MediaFormat getFormat();
+ method public java.lang.String getLanguage();
+ method public int getTrackType();
+ field public static final int MEDIA_TRACK_TYPE_AUDIO = 2; // 0x2
+ field public static final int MEDIA_TRACK_TYPE_METADATA = 5; // 0x5
+ field public static final int MEDIA_TRACK_TYPE_SUBTITLE = 4; // 0x4
+ field public static final int MEDIA_TRACK_TYPE_UNKNOWN = 0; // 0x0
+ field public static final int MEDIA_TRACK_TYPE_VIDEO = 1; // 0x1
+ }
+
public class MediaRecorder implements android.media.AudioRouting {
ctor public MediaRecorder();
method public void addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener, android.os.Handler);
@@ -25818,6 +26028,26 @@ package android.media {
ctor public UnsupportedSchemeException(java.lang.String);
}
+ public class UriDataSourceDesc extends android.media.DataSourceDesc {
+ method public android.content.Context getContext();
+ method public java.util.List<java.net.HttpCookie> getCookies();
+ method public java.util.Map<java.lang.String, java.lang.String> getHeaders();
+ method public android.net.Uri getUri();
+ }
+
+ public static class UriDataSourceDesc.Builder extends android.media.DataSourceDesc.BuilderBase {
+ ctor public UriDataSourceDesc.Builder();
+ ctor public UriDataSourceDesc.Builder(android.media.UriDataSourceDesc);
+ method public android.media.UriDataSourceDesc build();
+ method public android.media.UriDataSourceDesc.Builder setDataSource(android.content.Context, android.net.Uri);
+ method public android.media.UriDataSourceDesc.Builder setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>, java.util.List<java.net.HttpCookie>);
+ }
+
+ public final class VideoSize {
+ method public int getHeight();
+ method public int getWidth();
+ }
+
public abstract interface VolumeAutomation {
method public abstract android.media.VolumeShaper createVolumeShaper(android.media.VolumeShaper.Configuration);
}
@@ -29139,10 +29369,11 @@ package android.net.wifi {
field public static final java.lang.String NETWORK_STATE_CHANGED_ACTION = "android.net.wifi.STATE_CHANGE";
field public static final java.lang.String RSSI_CHANGED_ACTION = "android.net.wifi.RSSI_CHANGED";
field public static final java.lang.String SCAN_RESULTS_AVAILABLE_ACTION = "android.net.wifi.SCAN_RESULTS";
- field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE = 2; // 0x2
- field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP = 3; // 0x3
+ field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE = 3; // 0x3
+ field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP = 4; // 0x4
+ field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED = 2; // 0x2
field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL = 1; // 0x1
- field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 4; // 0x4
+ field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 5; // 0x5
field public static final int STATUS_NETWORK_SUGGESTIONS_SUCCESS = 0; // 0x0
field public static final deprecated java.lang.String SUPPLICANT_CONNECTION_CHANGE_ACTION = "android.net.wifi.supplicant.CONNECTION_CHANGE";
field public static final deprecated java.lang.String SUPPLICANT_STATE_CHANGED_ACTION = "android.net.wifi.supplicant.STATE_CHANGE";
@@ -34070,6 +34301,7 @@ package android.os {
}
public final class PowerManager {
+ method public int getCurrentThermalStatus();
method public int getLocationPowerSaveMode();
method public boolean isDeviceIdleMode();
method public boolean isIgnoringBatteryOptimizations(java.lang.String);
@@ -34080,6 +34312,8 @@ package android.os {
method public boolean isWakeLockLevelSupported(int);
method public android.os.PowerManager.WakeLock newWakeLock(int, java.lang.String);
method public void reboot(java.lang.String);
+ method public void registerThermalStatusCallback(android.os.PowerManager.ThermalStatusCallback, java.util.concurrent.Executor);
+ method public void unregisterThermalStatusCallback(android.os.PowerManager.ThermalStatusCallback);
field public static final int ACQUIRE_CAUSES_WAKEUP = 268435456; // 0x10000000
field public static final java.lang.String ACTION_DEVICE_IDLE_MODE_CHANGED = "android.os.action.DEVICE_IDLE_MODE_CHANGED";
field public static final java.lang.String ACTION_POWER_SAVE_MODE_CHANGED = "android.os.action.POWER_SAVE_MODE_CHANGED";
@@ -34094,6 +34328,18 @@ package android.os {
field public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1; // 0x1
field public static final deprecated int SCREEN_BRIGHT_WAKE_LOCK = 10; // 0xa
field public static final deprecated int SCREEN_DIM_WAKE_LOCK = 6; // 0x6
+ field public static final int THERMAL_STATUS_CRITICAL = 4; // 0x4
+ field public static final int THERMAL_STATUS_EMERGENCY = 5; // 0x5
+ field public static final int THERMAL_STATUS_LIGHT = 1; // 0x1
+ field public static final int THERMAL_STATUS_MODERATE = 2; // 0x2
+ field public static final int THERMAL_STATUS_NONE = 0; // 0x0
+ field public static final int THERMAL_STATUS_SEVERE = 3; // 0x3
+ field public static final int THERMAL_STATUS_SHUTDOWN = 6; // 0x6
+ }
+
+ public static abstract class PowerManager.ThermalStatusCallback {
+ ctor public PowerManager.ThermalStatusCallback();
+ method public void onStatusChange(int);
}
public final class PowerManager.WakeLock {
@@ -55714,6 +55960,7 @@ package android.widget {
method public java.lang.CharSequence getText();
method public android.view.textclassifier.TextClassifier getTextClassifier();
method public final android.content.res.ColorStateList getTextColors();
+ method public android.graphics.drawable.Drawable getTextCursorDrawable();
method public android.text.TextDirectionHeuristic getTextDirectionHeuristic();
method public java.util.Locale getTextLocale();
method public android.os.LocaleList getTextLocales();
@@ -55844,6 +56091,8 @@ package android.widget {
method public void setTextClassifier(android.view.textclassifier.TextClassifier);
method public void setTextColor(int);
method public void setTextColor(android.content.res.ColorStateList);
+ method public void setTextCursorDrawable(android.graphics.drawable.Drawable);
+ method public void setTextCursorDrawable(int);
method public void setTextIsSelectable(boolean);
method public final void setTextKeepState(java.lang.CharSequence);
method public final void setTextKeepState(java.lang.CharSequence, android.widget.TextView.BufferType);
diff --git a/api/system-current.txt b/api/system-current.txt
index ca06b07a217d..0b2871325e13 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -2928,6 +2928,20 @@ package android.media {
method public void stop();
}
+ public static class SubtitleData.Builder {
+ ctor public SubtitleData.Builder();
+ ctor public SubtitleData.Builder(android.media.SubtitleData);
+ method public android.media.SubtitleData build();
+ method public android.media.SubtitleData.Builder setSubtitleData(int, long, long, byte[]);
+ }
+
+ public static class TimedMetaData.Builder {
+ ctor public TimedMetaData.Builder();
+ ctor public TimedMetaData.Builder(android.media.TimedMetaData);
+ method public android.media.TimedMetaData build();
+ method public android.media.TimedMetaData.Builder setTimedMetaData(int, byte[]);
+ }
+
}
package android.media.audiopolicy {
@@ -4992,6 +5006,7 @@ package android.service.intelligence {
}
public final class FillRequest {
+ method public android.view.autofill.AutofillValue getFocusedAutofillValue();
method public android.view.autofill.AutofillId getFocusedId();
method public android.service.intelligence.PresentationParams getPresentationParams();
method public android.service.intelligence.InteractionSessionId getSessionId();
@@ -7356,22 +7371,8 @@ package android.webkit {
ctor public SslErrorHandler();
}
- public abstract class TokenBindingService {
+ public abstract deprecated class TokenBindingService {
ctor public TokenBindingService();
- method public abstract void deleteAllKeys(android.webkit.ValueCallback<java.lang.Boolean>);
- method public abstract void deleteKey(android.net.Uri, android.webkit.ValueCallback<java.lang.Boolean>);
- method public abstract void enableTokenBinding();
- method public static android.webkit.TokenBindingService getInstance();
- method public abstract void getKey(android.net.Uri, java.lang.String[], android.webkit.ValueCallback<android.webkit.TokenBindingService.TokenBindingKey>);
- field public static final java.lang.String KEY_ALGORITHM_ECDSAP256 = "ECDSAP256";
- field public static final java.lang.String KEY_ALGORITHM_RSA2048_PKCS_1_5 = "RSA2048_PKCS_1.5";
- field public static final java.lang.String KEY_ALGORITHM_RSA2048_PSS = "RSA2048PSS";
- }
-
- public static abstract class TokenBindingService.TokenBindingKey {
- ctor public TokenBindingService.TokenBindingKey();
- method public abstract java.lang.String getAlgorithm();
- method public abstract java.security.KeyPair getKeyPair();
}
public class WebChromeClient {
@@ -7501,7 +7502,7 @@ package android.webkit {
method public abstract android.webkit.GeolocationPermissions getGeolocationPermissions();
method public abstract android.webkit.ServiceWorkerController getServiceWorkerController();
method public abstract android.webkit.WebViewFactoryProvider.Statics getStatics();
- method public abstract android.webkit.TokenBindingService getTokenBindingService();
+ method public abstract deprecated android.webkit.TokenBindingService getTokenBindingService();
method public abstract android.webkit.TracingController getTracingController();
method public abstract android.webkit.WebIconDatabase getWebIconDatabase();
method public abstract android.webkit.WebStorage getWebStorage();
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 6f0b6c8687db..c7a9d99fe927 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -1731,8 +1731,11 @@ class ContextImpl extends Context {
throw new IllegalArgumentException("connection is null");
}
if (mPackageInfo != null) {
- IServiceConnection sd = mPackageInfo.forgetServiceDispatcher(
- getOuterContext(), conn);
+ IServiceConnection sd = mPackageInfo.lookupServiceDispatcher(conn, getOuterContext());
+ if (sd == null) {
+ throw new IllegalArgumentException("ServiceConnection not currently bound: "
+ + conn);
+ }
try {
ActivityManager.getService().updateServiceGroup(sd, group, importance);
} catch (RemoteException e) {
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index 719bba0a35af..759763b4199a 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -1659,6 +1659,19 @@ public final class LoadedApk {
}
}
+ @UnsupportedAppUsage
+ public IServiceConnection lookupServiceDispatcher(ServiceConnection c,
+ Context context) {
+ synchronized (mServices) {
+ LoadedApk.ServiceDispatcher sd = null;
+ ArrayMap<ServiceConnection, LoadedApk.ServiceDispatcher> map = mServices.get(context);
+ if (map != null) {
+ sd = map.get(c);
+ }
+ return sd != null ? sd.getIServiceConnection() : null;
+ }
+ }
+
public final IServiceConnection forgetServiceDispatcher(Context context,
ServiceConnection c) {
synchronized (mServices) {
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index 145c92731458..d1017c59b963 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -51,6 +51,7 @@ import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.text.TextUtils;
import android.util.Log;
+import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
@@ -586,7 +587,13 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
private int noteProxyOp(String callingPkg, int op) {
if (op != AppOpsManager.OP_NONE) {
int mode = mAppOpsManager.noteProxyOp(op, callingPkg);
- return mode == MODE_DEFAULT ? interpretDefaultAppOpMode(op) : mode;
+ int nonDefaultMode = mode == MODE_DEFAULT ? interpretDefaultAppOpMode(op) : mode;
+ if (mode == MODE_DEFAULT && nonDefaultMode == MODE_IGNORED) {
+ Slog.w(TAG, "Denying access for " + callingPkg + " to " + getClass().getName()
+ + " (" + AppOpsManager.opToName(op)
+ + " = " + AppOpsManager.opToName(mode) + ")");
+ }
+ return mode == MODE_DEFAULT ? nonDefaultMode : mode;
}
return AppOpsManager.MODE_ALLOWED;
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index fe11acbde0bc..e2c7b85b3280 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -3003,6 +3003,11 @@ public abstract class Context {
* how the process will be managed in some cases based on those flags. Currently only
* works on isolated processes (will be ignored for non-isolated processes).
*
+ * <p>Note that this call does not take immediate effect, but will be applied the next
+ * time the impacted process is adjusted for some other reason. Typically you would
+ * call this before then calling a new {@link #bindIsolatedService} on the service
+ * of interest, with that binding causing the process to be shuffled accordingly.</p>
+ *
* @param conn The connection interface previously supplied to bindService(). This
* parameter must not be null.
* @param group A group to put this connection's process in. Upon calling here, this
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index edfb3a72e933..c2907d2ccc1b 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -1916,12 +1916,15 @@ public class Intent implements Parcelable, Cloneable {
/**
* Activity action: Launch UI to review app uses of permissions.
* <p>
- * Input: Nothing
+ * Input: {@link #EXTRA_PERMISSION_NAME} specifies the permission name
+ * that will be displayed by the launched UI.
* </p>
* <p>
* Output: Nothing.
* </p>
*
+ * @see #EXTRA_PERMISSION_NAME
+ *
* @hide
*/
@SystemApi
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 98a135f96d98..07d6e4785759 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -1303,7 +1303,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
/** {@hide} */
public void writeToProto(ProtoOutputStream proto, long fieldId, int dumpFlags) {
long token = proto.start(fieldId);
- super.writeToProto(proto, ApplicationInfoProto.PACKAGE);
+ super.writeToProto(proto, ApplicationInfoProto.PACKAGE, dumpFlags);
proto.write(ApplicationInfoProto.PERMISSION, permission);
proto.write(ApplicationInfoProto.PROCESS_NAME, processName);
proto.write(ApplicationInfoProto.UID, uid);
diff --git a/core/java/android/content/pm/PackageItemInfo.java b/core/java/android/content/pm/PackageItemInfo.java
index cdb781438909..ff7b34773268 100644
--- a/core/java/android/content/pm/PackageItemInfo.java
+++ b/core/java/android/content/pm/PackageItemInfo.java
@@ -433,18 +433,18 @@ public class PackageItemInfo {
/**
* @hide
*/
- public void writeToProto(ProtoOutputStream proto, long fieldId) {
+ public void writeToProto(ProtoOutputStream proto, long fieldId, int dumpFlags) {
long token = proto.start(fieldId);
if (name != null) {
proto.write(PackageItemInfoProto.NAME, name);
}
proto.write(PackageItemInfoProto.PACKAGE_NAME, packageName);
- if (labelRes != 0 || nonLocalizedLabel != null || icon != 0 || banner != 0) {
- proto.write(PackageItemInfoProto.LABEL_RES, labelRes);
+ proto.write(PackageItemInfoProto.LABEL_RES, labelRes);
+ if (nonLocalizedLabel != null) {
proto.write(PackageItemInfoProto.NON_LOCALIZED_LABEL, nonLocalizedLabel.toString());
- proto.write(PackageItemInfoProto.ICON, icon);
- proto.write(PackageItemInfoProto.BANNER, banner);
}
+ proto.write(PackageItemInfoProto.ICON, icon);
+ proto.write(PackageItemInfoProto.BANNER, banner);
proto.end(token);
}
diff --git a/core/java/android/hardware/camera2/CameraDevice.java b/core/java/android/hardware/camera2/CameraDevice.java
index dc6cffc4ebee..448591f2c52a 100644
--- a/core/java/android/hardware/camera2/CameraDevice.java
+++ b/core/java/android/hardware/camera2/CameraDevice.java
@@ -968,6 +968,36 @@ public abstract class CameraDevice implements AutoCloseable {
public abstract void close();
/**
+ * Checks whether a particular {@link SessionConfiguration} is supported by the camera device.
+ *
+ * <p>This method performs a runtime check of a given {@link SessionConfiguration}. The result
+ * confirms whether or not the passed session configuration can be successfully used to
+ * create a camera capture session using
+ * {@link CameraDevice#createCaptureSession(SessionConfiguration)}.
+ * </p>
+ *
+ * <p>The method can be called at any point before, during and after active capture session.
+ * It must not impact normal camera behavior in any way and must complete significantly
+ * faster than creating a regular or constrained capture session.</p>
+ *
+ * <p>Note that session parameters will be ignored and calls to
+ * {@link SessionConfiguration#setSessionParameters} are not required.</p>
+ *
+ * @return {@code true} if the given session configuration is supported by the camera device
+ * {@code false} otherwise.
+ * @throws UnsupportedOperationException if the query operation is not supported by the camera
+ * device
+ * @throws IllegalArgumentException if the session configuration is invalid
+ * @throws CameraAccessException if the camera device is no longer connected or has
+ * encountered a fatal error
+ * @throws IllegalStateException if the camera device has been closed
+ */
+ public boolean isSessionConfigurationSupported(
+ @NonNull SessionConfiguration sessionConfig) throws CameraAccessException {
+ throw new UnsupportedOperationException("Subclasses must override this method");
+ }
+
+ /**
* A callback objects for receiving updates about the state of a camera device.
*
* <p>A callback instance must be provided to the {@link CameraManager#openCamera} method to
diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
index 7810e6c19abe..57b608f0fd84 100644
--- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
@@ -703,6 +703,17 @@ public class CameraDeviceImpl extends CameraDevice
}
}
+ @Override
+ public boolean isSessionConfigurationSupported(
+ @NonNull SessionConfiguration sessionConfig) throws CameraAccessException,
+ UnsupportedOperationException, IllegalArgumentException {
+ synchronized(mInterfaceLock) {
+ checkIfCameraClosedOrInError();
+
+ return mRemoteDevice.isSessionConfigurationSupported(sessionConfig);
+ }
+ }
+
/**
* For use by backwards-compatibility code only.
*/
diff --git a/core/java/android/hardware/camera2/impl/ICameraDeviceUserWrapper.java b/core/java/android/hardware/camera2/impl/ICameraDeviceUserWrapper.java
index 1f4ed13ee09e..c8ded8dde54a 100644
--- a/core/java/android/hardware/camera2/impl/ICameraDeviceUserWrapper.java
+++ b/core/java/android/hardware/camera2/impl/ICameraDeviceUserWrapper.java
@@ -30,9 +30,11 @@ import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.ICameraDeviceUser;
import android.hardware.camera2.impl.CameraMetadataNative;
import android.hardware.camera2.params.OutputConfiguration;
+import android.hardware.camera2.params.SessionConfiguration;
import android.hardware.camera2.utils.SubmitInfo;
import android.os.IBinder;
import android.os.RemoteException;
+import android.os.ServiceSpecificException;
import android.view.Surface;
/**
@@ -181,6 +183,25 @@ public class ICameraDeviceUserWrapper {
}
}
+ public boolean isSessionConfigurationSupported(SessionConfiguration sessionConfig)
+ throws CameraAccessException {
+ try {
+ return mRemoteDevice.isSessionConfigurationSupported(sessionConfig);
+ } catch (ServiceSpecificException e) {
+ if (e.errorCode == ICameraService.ERROR_INVALID_OPERATION) {
+ throw new UnsupportedOperationException("Session configuration query not " +
+ "supported");
+ } else if (e.errorCode == ICameraService.ERROR_ILLEGAL_ARGUMENT) {
+ throw new IllegalArgumentException("Invalid session configuration");
+ }
+
+ throw e;
+ } catch (Throwable t) {
+ CameraManager.throwAsPublicException(t);
+ throw new UnsupportedOperationException("Unexpected exception", t);
+ }
+ }
+
public long flush() throws CameraAccessException {
try {
return mRemoteDevice.flush();
diff --git a/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java b/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
index bc7b1260751e..123eb8ee1431 100644
--- a/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
+++ b/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
@@ -28,6 +28,7 @@ import android.hardware.camera2.impl.CameraMetadataNative;
import android.hardware.camera2.impl.CaptureResultExtras;
import android.hardware.camera2.impl.PhysicalCaptureResultInfo;
import android.hardware.camera2.params.OutputConfiguration;
+import android.hardware.camera2.params.SessionConfiguration;
import android.hardware.camera2.utils.SubmitInfo;
import android.os.ConditionVariable;
import android.os.IBinder;
@@ -480,6 +481,12 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
}
@Override
+ public boolean isSessionConfigurationSupported(SessionConfiguration sessionConfig) {
+ // TODO: Add support for this in legacy mode
+ throw new UnsupportedOperationException("Session configuration query not supported!");
+ }
+
+ @Override
public void beginConfigure() {
if (DEBUG) {
Log.d(TAG, "beginConfigure called.");
diff --git a/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java b/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java
index 83a02285e720..1b28d614a7f2 100644
--- a/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java
+++ b/core/java/android/hardware/camera2/legacy/SurfaceTextureRenderer.java
@@ -521,9 +521,10 @@ public class SurfaceTextureRenderer {
clearState();
}
- private void makeCurrent(EGLSurface surface) {
+ private void makeCurrent(EGLSurface surface)
+ throws LegacyExceptionUtils.BufferQueueAbandonedException {
EGL14.eglMakeCurrent(mEGLDisplay, surface, surface, mEGLContext);
- checkEglError("makeCurrent");
+ checkEglDrawError("makeCurrent");
}
private boolean swapBuffers(EGLSurface surface)
@@ -557,6 +558,17 @@ public class SurfaceTextureRenderer {
}
}
+ private void checkEglDrawError(String msg)
+ throws LegacyExceptionUtils.BufferQueueAbandonedException {
+ int error;
+ if ((error = EGL14.eglGetError()) == EGL14.EGL_BAD_NATIVE_WINDOW) {
+ throw new LegacyExceptionUtils.BufferQueueAbandonedException();
+ }
+ if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) {
+ throw new IllegalStateException(msg + ": EGL error: 0x" + Integer.toHexString(error));
+ }
+ }
+
private void checkEglError(String msg) {
int error;
if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) {
@@ -709,8 +721,14 @@ public class SurfaceTextureRenderer {
if (mConversionSurfaces.size() > 0) {
configureEGLPbufferSurfaces(mConversionSurfaces);
}
- makeCurrent((mSurfaces.size() > 0) ? mSurfaces.get(0).eglSurface :
+
+ try {
+ makeCurrent((mSurfaces.size() > 0) ? mSurfaces.get(0).eglSurface :
mConversionSurfaces.get(0).eglSurface);
+ } catch (LegacyExceptionUtils.BufferQueueAbandonedException e) {
+ Log.w(TAG, "Surface abandoned, skipping configuration... ", e);
+ }
+
initializeGLState();
mSurfaceTexture = new SurfaceTexture(getTextureId());
@@ -798,9 +816,9 @@ public class SurfaceTextureRenderer {
}
for (EGLSurfaceHolder holder : mConversionSurfaces) {
if (LegacyCameraDevice.containsSurfaceId(holder.surface, targetSurfaceIds)) {
- makeCurrent(holder.eglSurface);
// glReadPixels reads from the bottom of the buffer, so add an extra vertical flip
try {
+ makeCurrent(holder.eglSurface);
drawFrame(mSurfaceTexture, holder.width, holder.height,
(mFacing == CameraCharacteristics.LENS_FACING_FRONT) ?
FLIP_TYPE_BOTH : FLIP_TYPE_VERTICAL);
diff --git a/core/java/android/hardware/camera2/params/SessionConfiguration.java b/core/java/android/hardware/camera2/params/SessionConfiguration.java
index 8a8afb24b3f8..3ea58ad83327 100644
--- a/core/java/android/hardware/camera2/params/SessionConfiguration.java
+++ b/core/java/android/hardware/camera2/params/SessionConfiguration.java
@@ -27,6 +27,10 @@ import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.params.InputConfiguration;
import android.hardware.camera2.params.OutputConfiguration;
+import android.hardware.camera2.utils.HashCodeHelpers;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
import java.util.Collections;
import java.util.List;
@@ -40,7 +44,9 @@ import static com.android.internal.util.Preconditions.*;
/**
* A helper class that aggregates all supported arguments for capture session initialization.
*/
-public final class SessionConfiguration {
+public final class SessionConfiguration implements Parcelable {
+ private static final String TAG = "SessionConfiguration";
+
/**
* A regular session type containing instances of {@link OutputConfiguration} running
* at regular non high speed FPS ranges and optionally {@link InputConfiguration} for
@@ -110,6 +116,108 @@ public final class SessionConfiguration {
}
/**
+ * Create a SessionConfiguration from Parcel.
+ * No support for parcelable 'mStateCallback', 'mExecutor' and 'mSessionParameters' yet.
+ */
+ private SessionConfiguration(@NonNull Parcel source) {
+ int sessionType = source.readInt();
+ int inputWidth = source.readInt();
+ int inputHeight = source.readInt();
+ int inputFormat = source.readInt();
+ ArrayList<OutputConfiguration> outConfigs = new ArrayList<OutputConfiguration>();
+ source.readTypedList(outConfigs, OutputConfiguration.CREATOR);
+
+ if ((inputWidth > 0) && (inputHeight > 0) && (inputFormat != -1)) {
+ mInputConfig = new InputConfiguration(inputWidth, inputHeight, inputFormat);
+ }
+ mSessionType = sessionType;
+ mOutputConfigurations = outConfigs;
+ }
+
+ public static final Parcelable.Creator<SessionConfiguration> CREATOR =
+ new Parcelable.Creator<SessionConfiguration> () {
+ @Override
+ public SessionConfiguration createFromParcel(Parcel source) {
+ try {
+ SessionConfiguration sessionConfiguration = new SessionConfiguration(source);
+ return sessionConfiguration;
+ } catch (Exception e) {
+ Log.e(TAG, "Exception creating SessionConfiguration from parcel", e);
+ return null;
+ }
+ }
+
+ @Override
+ public SessionConfiguration[] newArray(int size) {
+ return new SessionConfiguration[size];
+ }
+ };
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ if (dest == null) {
+ throw new IllegalArgumentException("dest must not be null");
+ }
+ dest.writeInt(mSessionType);
+ if (mInputConfig != null) {
+ dest.writeInt(mInputConfig.getWidth());
+ dest.writeInt(mInputConfig.getHeight());
+ dest.writeInt(mInputConfig.getFormat());
+ } else {
+ dest.writeInt(/*inputWidth*/ 0);
+ dest.writeInt(/*inputHeight*/ 0);
+ dest.writeInt(/*inputFormat*/ -1);
+ }
+ dest.writeTypedList(mOutputConfigurations);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * Check if this {@link SessionConfiguration} is equal to another {@link SessionConfiguration}.
+ *
+ * <p>Two output session configurations are only equal if and only if the underlying input
+ * configuration, output configurations, and session type are equal. </p>
+ *
+ * @return {@code true} if the objects were equal, {@code false} otherwise
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ } else if (this == obj) {
+ return true;
+ } else if (obj instanceof SessionConfiguration) {
+ final SessionConfiguration other = (SessionConfiguration) obj;
+ if (mInputConfig != other.mInputConfig || mSessionType != other.mSessionType ||
+ mOutputConfigurations.size() != other.mOutputConfigurations.size()) {
+ return false;
+ }
+
+ for (int i = 0; i < mOutputConfigurations.size(); i++) {
+ if (!mOutputConfigurations.get(i).equals(other.mOutputConfigurations.get(i)))
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return HashCodeHelpers.hashCode(mOutputConfigurations.hashCode(), mInputConfig.hashCode(),
+ mSessionType);
+ }
+
+ /**
* Retrieve the type of the capture session.
*
* @return The capture session type.
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index 64314a7d8060..2ae796c1ec56 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -85,6 +85,15 @@ public class Binder implements IBinder {
public static boolean LOG_RUNTIME_EXCEPTION = false; // DO NOT SUBMIT WITH TRUE
/**
+ * Value to represents that a calling work source is not set.
+ *
+ * This constatnt needs to be kept in sync with IPCThreadState::kUnsetWorkSource.
+ *
+ * @hide
+ */
+ public static final int UNSET_WORKSOURCE = -1;
+
+ /**
* Control whether dump() calls are allowed.
*/
private static volatile String sDumpDisabled = null;
@@ -449,8 +458,6 @@ public class Binder implements IBinder {
* }
* </pre>
*
- * <p>The work source will be propagated for future outgoing binder transactions
- * executed on this thread.
* @hide
**/
@CriticalNative
@@ -912,6 +919,16 @@ public class Binder implements IBinder {
// Entry point from android_util_Binder.cpp's onTransact
private boolean execTransact(int code, long dataObj, long replyObj,
int flags) {
+ final long origWorkSource = ThreadLocalWorkSource.setUid(Binder.getCallingUid());
+ try {
+ return execTransactInternal(code, dataObj, replyObj, flags);
+ } finally {
+ ThreadLocalWorkSource.restore(origWorkSource);
+ }
+ }
+
+ private boolean execTransactInternal(int code, long dataObj, long replyObj,
+ int flags) {
// Make sure the observer won't change while processing a transaction.
final BinderInternal.Observer observer = sObserver;
final CallSession callSession =
@@ -925,7 +942,6 @@ public class Binder implements IBinder {
// Log any exceptions as warnings, don't silently suppress them.
// If the call was FLAG_ONEWAY then these exceptions disappear into the ether.
final boolean tracingEnabled = Binder.isTracingEnabled();
- final long origWorkSource = ThreadLocalWorkSource.setUid(Binder.getCallingUid());
try {
if (tracingEnabled) {
final String transactionName = getTransactionName(code);
@@ -952,7 +968,6 @@ public class Binder implements IBinder {
}
res = true;
} finally {
- ThreadLocalWorkSource.restore(origWorkSource);
if (tracingEnabled) {
Trace.traceEnd(Trace.TRACE_TAG_ALWAYS);
}
@@ -972,7 +987,6 @@ public class Binder implements IBinder {
if (observer != null) {
observer.callEnded(callSession, requestSizeBytes, replySizeBytes);
}
-
return res;
}
}
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java
index 900b62d98bf4..8cafbde8e3eb 100644
--- a/core/java/android/os/GraphicsEnvironment.java
+++ b/core/java/android/os/GraphicsEnvironment.java
@@ -269,7 +269,7 @@ public class GraphicsEnvironment {
}
// If no temp rules, load the real ones from the APK
- if (rulesFd == null) {
+ if (DEBUG && (rulesFd == null)) {
// Pass the rules file to loader for ANGLE decisions
AssetManager angleAssets = null;
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 894015ff5a92..c3e04894c6c9 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -17,7 +17,9 @@
package android.os;
import android.Manifest.permission;
+import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
+import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
@@ -25,11 +27,15 @@ import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.Context;
import android.service.dreams.Sandman;
+import android.util.ArrayMap;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
+import com.android.internal.util.Preconditions;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.concurrent.Executor;
/**
* This class gives you control of the power state of the device.
@@ -643,6 +649,9 @@ public final class PowerManager {
final IPowerManager mService;
final Handler mHandler;
+ IThermalService mThermalService;
+ private ArrayMap<ThermalStatusCallback, IThermalStatusListener> mCallbackMap = new ArrayMap<>();
+
IDeviceIdleController mIDeviceIdleController;
/**
@@ -1443,6 +1452,159 @@ public final class PowerManager {
}
/**
+ * Thermal status code: Not under throttling.
+ */
+ public static final int THERMAL_STATUS_NONE = Temperature.THROTTLING_NONE;
+
+ /**
+ * Thermal status code: Light throttling where UX is not impacted.
+ */
+ public static final int THERMAL_STATUS_LIGHT = Temperature.THROTTLING_LIGHT;
+
+ /**
+ * Thermal status code: Moderate throttling where UX is not largely impacted.
+ */
+ public static final int THERMAL_STATUS_MODERATE = Temperature.THROTTLING_MODERATE;
+
+ /**
+ * Thermal status code: Severe throttling where UX is largely impacted.
+ */
+ public static final int THERMAL_STATUS_SEVERE = Temperature.THROTTLING_SEVERE;
+
+ /**
+ * Thermal status code: Platform has done everything to reduce power.
+ */
+ public static final int THERMAL_STATUS_CRITICAL = Temperature.THROTTLING_CRITICAL;
+
+ /**
+ * Thermal status code: Key components in platform are shutting down due to thermal condition.
+ * Device functionalities will be limited.
+ */
+ public static final int THERMAL_STATUS_EMERGENCY = Temperature.THROTTLING_EMERGENCY;
+
+ /**
+ * Thermal status code: Need shutdown immediately.
+ */
+ public static final int THERMAL_STATUS_SHUTDOWN = Temperature.THROTTLING_SHUTDOWN;
+
+ /** @hide */
+ @IntDef(prefix = { "THERMAL_STATUS_" }, value = {
+ THERMAL_STATUS_NONE,
+ THERMAL_STATUS_LIGHT,
+ THERMAL_STATUS_MODERATE,
+ THERMAL_STATUS_SEVERE,
+ THERMAL_STATUS_CRITICAL,
+ THERMAL_STATUS_EMERGENCY,
+ THERMAL_STATUS_SHUTDOWN,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ThermalStatus {}
+
+ /**
+ * This function returns the current thermal status of the device.
+ *
+ * @return thermal status as int, {@link #THERMAL_STATUS_NONE} if device in not under
+ * thermal throttling.
+ */
+ public @ThermalStatus int getCurrentThermalStatus() {
+ synchronized (this) {
+ if (mThermalService == null) {
+ mThermalService = IThermalService.Stub.asInterface(
+ ServiceManager.getService(Context.THERMAL_SERVICE));
+ }
+ try {
+ return mThermalService.getCurrentThermalStatus();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ }
+
+ /**
+ * Callback passed to
+ * {@link PowerManager#registerThermalStatusCallback} and
+ * {@link PowerManager#unregisterThermalStatusCallback}
+ * to notify caller of thermal status.
+ */
+ public abstract static class ThermalStatusCallback {
+
+ /**
+ * Called when overall thermal throttling status changed.
+ * @param status defined in {@link android.os.Temperature}.
+ */
+ public void onStatusChange(@ThermalStatus int status) {}
+ }
+
+ /**
+ * This function registers a callback for thermal status change.
+ *
+ * @param callback callback to be registered.
+ * @param executor {@link Executor} to handle the callbacks.
+ */
+ public void registerThermalStatusCallback(
+ @NonNull ThermalStatusCallback callback, @NonNull @CallbackExecutor Executor executor) {
+ Preconditions.checkNotNull(callback, "callback cannnot be null");
+ Preconditions.checkNotNull(executor, "executor cannnot be null");
+ synchronized (this) {
+ if (mThermalService == null) {
+ mThermalService = IThermalService.Stub.asInterface(
+ ServiceManager.getService(Context.THERMAL_SERVICE));
+ }
+ try {
+ if (mCallbackMap.containsKey(callback)) {
+ throw new IllegalArgumentException("ThermalStatusCallback already registered");
+ }
+ IThermalStatusListener listener = new IThermalStatusListener.Stub() {
+ @Override
+ public void onStatusChange(int status) {
+ executor.execute(() -> {
+ callback.onStatusChange(status);
+ });
+ }
+ };
+ if (mThermalService.registerThermalStatusListener(listener)) {
+ mCallbackMap.put(callback, listener);
+ } else {
+ throw new RuntimeException("ThermalStatusCallback failed to register");
+ }
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ }
+
+ /**
+ * This function unregisters a callback for thermal status change.
+ *
+ * @param callback to be unregistered.
+ *
+ * see {@link #registerThermalStatusCallback}
+ */
+ public void unregisterThermalStatusCallback(ThermalStatusCallback callback) {
+ Preconditions.checkNotNull(callback, "callback cannnot be null");
+ synchronized (this) {
+ if (mThermalService == null) {
+ mThermalService = IThermalService.Stub.asInterface(
+ ServiceManager.getService(Context.THERMAL_SERVICE));
+ }
+ try {
+ IThermalStatusListener listener = mCallbackMap.get(callback);
+ if (listener == null) {
+ throw new IllegalArgumentException("ThermalStatusCallback not registered");
+ }
+ if (mThermalService.unregisterThermalStatusListener(listener)) {
+ mCallbackMap.remove(callback);
+ } else {
+ throw new RuntimeException("ThermalStatusCallback failed to unregister");
+ }
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ }
+
+ /**
* If true, the doze component is not started until after the screen has been
* turned off and the screen off animation has been performed.
* @hide
diff --git a/core/java/android/provider/DocumentsContract.java b/core/java/android/provider/DocumentsContract.java
index e032c1896a4b..37c84bd74395 100644
--- a/core/java/android/provider/DocumentsContract.java
+++ b/core/java/android/provider/DocumentsContract.java
@@ -152,6 +152,17 @@ public final class DocumentsContract {
"android:query-arg-last-modified-after";
/**
+ * Key for {@link DocumentsProvider} to decide whether the files that
+ * have been added to MediaStore should be excluded. If the value is
+ * true, exclude them. Otherwise, include them.
+ *
+ * @see DocumentsProvider#querySearchDocuments(String, String[],
+ * Bundle)
+ * {@hide}
+ */
+ public static final String QUERY_ARG_EXCLUDE_MEDIA = "android:query-arg-exclude-media";
+
+ /**
* Sets the desired initial location visible to user when file chooser is shown.
*
* <p>Applicable to {@link Intent} with actions:
@@ -1017,6 +1028,7 @@ public final class DocumentsContract {
/**
* Get the handled query arguments from the query bundle. The handled arguments are
+ * {@link DocumentsContract#QUERY_ARG_EXCLUDE_MEDIA},
* {@link DocumentsContract#QUERY_ARG_DISPLAY_NAME},
* {@link DocumentsContract#QUERY_ARG_MIME_TYPES},
* {@link DocumentsContract#QUERY_ARG_FILE_SIZE_OVER} and
@@ -1032,6 +1044,11 @@ public final class DocumentsContract {
}
final ArrayList<String> args = new ArrayList<>();
+
+ if (queryArgs.keySet().contains(QUERY_ARG_EXCLUDE_MEDIA)) {
+ args.add(QUERY_ARG_EXCLUDE_MEDIA);
+ }
+
if (queryArgs.keySet().contains(QUERY_ARG_DISPLAY_NAME)) {
args.add(QUERY_ARG_DISPLAY_NAME);
}
diff --git a/core/java/android/provider/DocumentsProvider.java b/core/java/android/provider/DocumentsProvider.java
index 58f82134ec50..6ab72c7bb372 100644
--- a/core/java/android/provider/DocumentsProvider.java
+++ b/core/java/android/provider/DocumentsProvider.java
@@ -677,6 +677,7 @@ public abstract class DocumentsProvider extends ContentProvider {
* cursor. If {@code null} all supported columns should be
* included.
* @param queryArgs the query arguments.
+ * {@link DocumentsContract#QUERY_ARG_EXCLUDE_MEDIA},
* {@link DocumentsContract#QUERY_ARG_DISPLAY_NAME},
* {@link DocumentsContract#QUERY_ARG_MIME_TYPES},
* {@link DocumentsContract#QUERY_ARG_FILE_SIZE_OVER},
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 74ec0b9c8085..c3217a2189cf 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -4252,6 +4252,7 @@ public final class Settings {
PUBLIC_SETTINGS.add(BLUETOOTH_DISCOVERABILITY_TIMEOUT);
PUBLIC_SETTINGS.add(NEXT_ALARM_FORMATTED);
PUBLIC_SETTINGS.add(FONT_SCALE);
+ PUBLIC_SETTINGS.add(SYSTEM_LOCALES);
PUBLIC_SETTINGS.add(DIM_SCREEN);
PUBLIC_SETTINGS.add(SCREEN_OFF_TIMEOUT);
PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS);
diff --git a/core/java/android/service/intelligence/FillCallback.java b/core/java/android/service/intelligence/FillCallback.java
index af2da79170ef..ddf37f737296 100644
--- a/core/java/android/service/intelligence/FillCallback.java
+++ b/core/java/android/service/intelligence/FillCallback.java
@@ -15,8 +15,10 @@
*/
package android.service.intelligence;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
+import android.service.intelligence.SmartSuggestionsService.AutofillProxy;
/**
* Callback used to indicate at {@link FillRequest} has been fulfilled.
@@ -25,8 +27,11 @@ import android.annotation.SystemApi;
*/
@SystemApi
public final class FillCallback {
+ private final AutofillProxy mProxy;
- FillCallback() {}
+ FillCallback(@NonNull AutofillProxy proxy) {
+ mProxy = proxy;
+ }
/**
* Sets the response associated with the request.
@@ -35,6 +40,7 @@ public final class FillCallback {
* could not provide autofill for the request.
*/
public void onSuccess(@Nullable FillResponse response) {
+ mProxy.report(AutofillProxy.REPORT_EVENT_ON_SUCCESS);
final FillWindow fillWindow = response.getFillWindow();
if (fillWindow != null) {
fillWindow.show();
diff --git a/core/java/android/service/intelligence/FillRequest.java b/core/java/android/service/intelligence/FillRequest.java
index f68db9df6fe3..53e99a5fd3b8 100644
--- a/core/java/android/service/intelligence/FillRequest.java
+++ b/core/java/android/service/intelligence/FillRequest.java
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.service.intelligence.SmartSuggestionsService.AutofillProxy;
import android.view.autofill.AutofillId;
+import android.view.autofill.AutofillValue;
/**
* Represents a request to augment-fill an activity.
@@ -52,6 +53,14 @@ public final class FillRequest {
}
/**
+ * Gets the current value of the field that triggered the request.
+ */
+ @NonNull
+ public AutofillValue getFocusedAutofillValue() {
+ return mProxy.focusedValue;
+ }
+
+ /**
* Gets the Smart Suggestions object used to embed the autofill UI.
*
* @return object used to embed the autofill UI, or {@code null} if not supported.
diff --git a/core/java/android/service/intelligence/FillWindow.java b/core/java/android/service/intelligence/FillWindow.java
index 309f6a1b6f1b..39d7e08a68d9 100644
--- a/core/java/android/service/intelligence/FillWindow.java
+++ b/core/java/android/service/intelligence/FillWindow.java
@@ -23,6 +23,7 @@ import android.annotation.SystemApi;
import android.app.Dialog;
import android.graphics.Rect;
import android.service.intelligence.PresentationParams.Area;
+import android.service.intelligence.SmartSuggestionsService.AutofillProxy;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
@@ -33,6 +34,8 @@ import android.view.WindowManager;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
+import dalvik.system.CloseGuard;
+
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -73,6 +76,7 @@ public final class FillWindow {
@interface Flags{}
private final Object mLock = new Object();
+ private final CloseGuard mCloseGuard = CloseGuard.get();
@GuardedBy("mLock")
private Dialog mDialog;
@@ -80,6 +84,8 @@ public final class FillWindow {
@GuardedBy("mLock")
private boolean mDestroyed;
+ private AutofillProxy mProxy;
+
/**
* Updates the content of the window.
*
@@ -123,6 +129,8 @@ public final class FillWindow {
synchronized (mLock) {
checkNotDestroyedLocked();
+ mProxy = area.proxy;
+
// TODO(b/111330312): once we have the SurfaceControl approach, we should update the
// window instead of destroying. In fact, it might be better to allocate a full window
// initially, which is transparent (and let touches get through) everywhere but in the
@@ -133,6 +141,7 @@ public final class FillWindow {
// etc.
mDialog = new Dialog(rootView.getContext());
+ mCloseGuard.open("destroy");
final Window window = mDialog.getWindow();
window.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
@@ -156,7 +165,7 @@ public final class FillWindow {
Log.d(TAG, "Created FillWindow: params= " + smartSuggestion + " view=" + rootView);
}
- area.proxy.setFillWindow(this);
+ mProxy.setFillWindow(this);
return true;
}
}
@@ -173,6 +182,9 @@ public final class FillWindow {
}
mDialog.show();
+ if (mProxy != null) {
+ mProxy.report(AutofillProxy.REPORT_EVENT_UI_SHOWN);
+ }
}
}
@@ -182,15 +194,29 @@ public final class FillWindow {
* <p>Once destroyed, this window cannot be used anymore
*/
public void destroy() {
- if (DEBUG) Log.d(TAG, "destroy(): mDestroyed = " + mDestroyed);
+ if (DEBUG) Log.d(TAG, "destroy(): mDestroyed=" + mDestroyed + " mDialog=" + mDialog);
synchronized (this) {
- if (mDestroyed) return;
+ if (mDestroyed || mDialog == null) return;
- if (mDialog != null) {
- mDialog.dismiss();
- mDialog = null;
+ mDialog.dismiss();
+ mDialog = null;
+ if (mProxy != null) {
+ mProxy.report(AutofillProxy.REPORT_EVENT_UI_DESTROYED);
}
+ mCloseGuard.close();
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ if (mCloseGuard != null) {
+ mCloseGuard.warnIfOpen();
+ }
+ destroy();
+ } finally {
+ super.finalize();
}
}
diff --git a/core/java/android/service/intelligence/IIntelligenceService.aidl b/core/java/android/service/intelligence/IIntelligenceService.aidl
index d6b31079e34c..2b924fbaadc4 100644
--- a/core/java/android/service/intelligence/IIntelligenceService.aidl
+++ b/core/java/android/service/intelligence/IIntelligenceService.aidl
@@ -23,6 +23,7 @@ import android.service.intelligence.InteractionContext;
import android.service.intelligence.SnapshotData;
import android.view.autofill.AutofillId;
+import android.view.autofill.AutofillValue;
import android.view.intelligence.ContentCaptureEvent;
import java.util.List;
@@ -45,7 +46,8 @@ oneway interface IIntelligenceService {
in SnapshotData snapshotData);
void onAutofillRequest(in InteractionSessionId sessionId, in IBinder autofillManagerClient,
- int autofilSessionId, in AutofillId focusedId);
+ int autofilSessionId, in AutofillId focusedId,
+ in AutofillValue focusedValue, long requestTime);
void onDestroyAutofillWindowsRequest(in InteractionSessionId sessionId);
}
diff --git a/core/java/android/service/intelligence/SmartSuggestionsService.java b/core/java/android/service/intelligence/SmartSuggestionsService.java
index 0e29e70ecc3b..b684b0208d8d 100644
--- a/core/java/android/service/intelligence/SmartSuggestionsService.java
+++ b/core/java/android/service/intelligence/SmartSuggestionsService.java
@@ -18,6 +18,7 @@ package android.service.intelligence;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import android.annotation.CallSuper;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
@@ -30,10 +31,13 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
+import android.os.SystemClock;
import android.service.intelligence.PresentationParams.SystemPopupPresentationParams;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;
+import android.util.Slog;
+import android.util.TimeUtils;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
import android.view.autofill.IAugmentedAutofillManagerClient;
@@ -43,6 +47,8 @@ import com.android.internal.annotations.GuardedBy;
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -110,9 +116,11 @@ public abstract class SmartSuggestionsService extends Service {
@Override
public void onAutofillRequest(InteractionSessionId sessionId, IBinder client,
- int autofilSessionId, AutofillId focusedId) {
+ int autofilSessionId, AutofillId focusedId, AutofillValue focusedValue,
+ long requestTime) {
mHandler.sendMessage(obtainMessage(SmartSuggestionsService::handleOnAutofillRequest,
- SmartSuggestionsService.this, sessionId, client, autofilSessionId, focusedId));
+ SmartSuggestionsService.this, sessionId, client, autofilSessionId, focusedId,
+ focusedValue, requestTime));
}
@Override
@@ -229,13 +237,15 @@ public abstract class SmartSuggestionsService extends Service {
@NonNull ContentCaptureEventsRequest request);
private void handleOnAutofillRequest(@NonNull InteractionSessionId sessionId,
- @NonNull IBinder client, int autofillSessionId, @NonNull AutofillId focusedId) {
+ @NonNull IBinder client, int autofillSessionId, @NonNull AutofillId focusedId,
+ @Nullable AutofillValue focusedValue, long requestTime) {
if (mAutofillProxies == null) {
mAutofillProxies = new ArrayMap<>();
}
AutofillProxy proxy = mAutofillProxies.get(sessionId);
if (proxy == null) {
- proxy = new AutofillProxy(sessionId, client, autofillSessionId, focusedId);
+ proxy = new AutofillProxy(sessionId, client, autofillSessionId, focusedId, focusedValue,
+ requestTime);
mAutofillProxies.put(sessionId, proxy);
} else {
// TODO(b/111330312): figure out if it's ok to reuse the proxy; add logging
@@ -244,7 +254,7 @@ public abstract class SmartSuggestionsService extends Service {
// TODO(b/111330312): set cancellation signal
final CancellationSignal cancellationSignal = null;
onFillRequest(sessionId, new FillRequest(proxy), cancellationSignal,
- new FillController(proxy), new FillCallback());
+ new FillController(proxy), new FillCallback(proxy));
}
/**
@@ -332,11 +342,32 @@ public abstract class SmartSuggestionsService extends Service {
/** @hide */
static final class AutofillProxy {
+
+ static final int REPORT_EVENT_ON_SUCCESS = 1;
+ static final int REPORT_EVENT_UI_SHOWN = 2;
+ static final int REPORT_EVENT_UI_DESTROYED = 3;
+
+ @IntDef(prefix = { "REPORT_EVENT_" }, value = {
+ REPORT_EVENT_ON_SUCCESS,
+ REPORT_EVENT_UI_SHOWN,
+ REPORT_EVENT_UI_DESTROYED
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ @interface ReportEvent{}
+
+
private final Object mLock = new Object();
private final IAugmentedAutofillManagerClient mClient;
private final int mAutofillSessionId;
public final InteractionSessionId sessionId;
public final AutofillId focusedId;
+ public final AutofillValue focusedValue;
+
+ // Objects used to log metrics
+ private final long mRequestTime;
+ private long mOnSuccessTime;
+ private long mUiFirstShownTime;
+ private long mUiFirstDestroyedTime;
@GuardedBy("mLock")
private SystemPopupPresentationParams mSmartSuggestion;
@@ -345,11 +376,14 @@ public abstract class SmartSuggestionsService extends Service {
private FillWindow mFillWindow;
private AutofillProxy(@NonNull InteractionSessionId sessionId, @NonNull IBinder client,
- int autofillSessionId, @NonNull AutofillId focusedId) {
+ int autofillSessionId, @NonNull AutofillId focusedId,
+ @Nullable AutofillValue focusedValue, long requestTime) {
this.sessionId = sessionId;
mClient = IAugmentedAutofillManagerClient.Stub.asInterface(client);
mAutofillSessionId = autofillSessionId;
this.focusedId = focusedId;
+ this.focusedValue = focusedValue;
+ this.mRequestTime = requestTime;
// TODO(b/111330312): linkToDeath
}
@@ -400,9 +434,50 @@ public abstract class SmartSuggestionsService extends Service {
}
}
+ // Used for metrics.
+ public void report(@ReportEvent int event) {
+ switch (event) {
+ case REPORT_EVENT_ON_SUCCESS:
+ if (mOnSuccessTime == 0) {
+ mOnSuccessTime = SystemClock.elapsedRealtime();
+ if (DEBUG) {
+ Slog.d(TAG, "Service responsed in "
+ + TimeUtils.formatDuration(mOnSuccessTime - mRequestTime));
+ }
+ }
+ break;
+ case REPORT_EVENT_UI_SHOWN:
+ if (mUiFirstShownTime == 0) {
+ mUiFirstShownTime = SystemClock.elapsedRealtime();
+ if (DEBUG) {
+ Slog.d(TAG, "UI shown in "
+ + TimeUtils.formatDuration(mUiFirstShownTime - mRequestTime));
+ }
+ }
+ break;
+ case REPORT_EVENT_UI_DESTROYED:
+ if (mUiFirstDestroyedTime == 0) {
+ mUiFirstDestroyedTime = SystemClock.elapsedRealtime();
+ if (DEBUG) {
+ Slog.d(TAG, "UI destroyed in "
+ + TimeUtils.formatDuration(
+ mUiFirstDestroyedTime - mRequestTime));
+ }
+ }
+ break;
+ default:
+ Slog.w(TAG, "invalid event reported: " + event);
+ }
+ // TODO(b/111330312): log metrics as well
+ }
+
+
public void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
pw.print(prefix); pw.print("afSessionId: "); pw.println(mAutofillSessionId);
pw.print(prefix); pw.print("focusedId: "); pw.println(focusedId);
+ if (focusedValue != null) {
+ pw.print(prefix); pw.print("focusedValue: "); pw.println(focusedValue);
+ }
pw.print(prefix); pw.print("client: "); pw.println(mClient);
final String prefix2 = prefix + " ";
if (mFillWindow != null) {
@@ -413,6 +488,23 @@ public abstract class SmartSuggestionsService extends Service {
pw.print(prefix); pw.println("smartSuggestion:");
mSmartSuggestion.dump(prefix2, pw);
}
+ if (mOnSuccessTime > 0) {
+ final long responseTime = mOnSuccessTime - mRequestTime;
+ pw.print(prefix); pw.print("response time: ");
+ TimeUtils.formatDuration(responseTime, pw); pw.println();
+ }
+
+ if (mUiFirstShownTime > 0) {
+ final long uiRenderingTime = mUiFirstShownTime - mRequestTime;
+ pw.print(prefix); pw.print("UI rendering time: ");
+ TimeUtils.formatDuration(uiRenderingTime, pw); pw.println();
+ }
+
+ if (mUiFirstDestroyedTime > 0) {
+ final long uiTotalTime = mUiFirstDestroyedTime - mRequestTime;
+ pw.print(prefix); pw.print("UI life time: ");
+ TimeUtils.formatDuration(uiTotalTime, pw); pw.println();
+ }
}
private void destroy() {
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 4b9cbff8c161..bd2aa64b33a1 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -112,6 +112,9 @@ import android.view.autofill.AutofillValue;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
+import android.view.inspector.InspectableProperty;
+import android.view.inspector.InspectableProperty.EnumMap;
+import android.view.inspector.InspectableProperty.FlagMap;
import android.view.intelligence.ContentCaptureManager;
import android.widget.Checkable;
import android.widget.FrameLayout;
@@ -4895,6 +4898,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
public static final int LAYER_TYPE_HARDWARE = 2;
+ /** @hide */
+ @IntDef(prefix = { "LAYER_TYPE_" }, value = {
+ LAYER_TYPE_NONE,
+ LAYER_TYPE_SOFTWARE,
+ LAYER_TYPE_HARDWARE
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface LayerType {}
+
@ViewDebug.ExportedProperty(category = "drawing", mapping = {
@ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"),
@ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"),
@@ -6516,6 +6528,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return a bitmask representing the enabled scroll indicators
*/
+ @InspectableProperty(flagMapping = {
+ @FlagMap(target = SCROLL_INDICATORS_NONE, mask = 0xffff_ffff, name = "none"),
+ @FlagMap(target = SCROLL_INDICATOR_TOP, name = "top"),
+ @FlagMap(target = SCROLL_INDICATOR_BOTTOM, name = "bottom"),
+ @FlagMap(target = SCROLL_INDICATOR_LEFT, name = "left"),
+ @FlagMap(target = SCROLL_INDICATOR_RIGHT, name = "right"),
+ @FlagMap(target = SCROLL_INDICATOR_START, name = "start"),
+ @FlagMap(target = SCROLL_INDICATOR_END, name = "end")
+ })
@ScrollIndicators
public int getScrollIndicators() {
return (mPrivateFlags3 & SCROLL_INDICATORS_PFLAG3_MASK)
@@ -7582,7 +7603,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* {@see #setAccessibilityPaneTitle}.
*/
- @Nullable public CharSequence getAccessibilityPaneTitle() {
+ @InspectableProperty
+ @Nullable
+ public CharSequence getAccessibilityPaneTitle() {
return mAccessibilityPaneTitle;
}
@@ -8580,6 +8603,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_autofillHints
*/
@ViewDebug.ExportedProperty()
+ @InspectableProperty
@Nullable public String[] getAutofillHints() {
return mAutofillHints;
}
@@ -8624,6 +8648,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
to = "yesExcludeDescendants"),
@ViewDebug.IntToString(from = IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS,
to = "noExcludeDescendants")})
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = IMPORTANT_FOR_AUTOFILL_AUTO, name = "auto"),
+ @EnumMap(value = IMPORTANT_FOR_AUTOFILL_YES, name = "yes"),
+ @EnumMap(value = IMPORTANT_FOR_AUTOFILL_NO, name = "no"),
+ @EnumMap(value = IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS,
+ name = "yesExcludeDescendants"),
+ @EnumMap(value = IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS,
+ name = "noExcludeDescendants"),
+ })
public @AutofillImportance int getImportantForAutofill() {
return (mPrivateFlags3
& PFLAG3_IMPORTANT_FOR_AUTOFILL_MASK) >> PFLAG3_IMPORTANT_FOR_AUTOFILL_SHIFT;
@@ -8808,6 +8841,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
to = "yesExcludeDescendants"),
@ViewDebug.IntToString(from = IMPORTANT_FOR_CONTENT_CAPTURE_NO_EXCLUDE_DESCENDANTS,
to = "noExcludeDescendants")})
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = IMPORTANT_FOR_CONTENT_CAPTURE_AUTO, name = "auto"),
+ @EnumMap(value = IMPORTANT_FOR_CONTENT_CAPTURE_YES, name = "yes"),
+ @EnumMap(value = IMPORTANT_FOR_CONTENT_CAPTURE_NO, name = "no"),
+ @EnumMap(value = IMPORTANT_FOR_CONTENT_CAPTURE_YES_EXCLUDE_DESCENDANTS,
+ name = "yesExcludeDescendants"),
+ @EnumMap(value = IMPORTANT_FOR_CONTENT_CAPTURE_NO_EXCLUDE_DESCENDANTS,
+ name = "noExcludeDescendants"),
+ })
public @ContentCaptureImportance int getImportantForContentCapture() {
// NOTE: the important for content capture values were the first flags added and are set in
// the rightmost position, so we don't need to shift them
@@ -9619,6 +9661,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_contentDescription
*/
@ViewDebug.ExportedProperty(category = "accessibility")
+ @InspectableProperty
public CharSequence getContentDescription() {
return mContentDescription;
}
@@ -9699,6 +9742,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @see #setAccessibilityTraversalBefore(int)
*/
+ @InspectableProperty
public int getAccessibilityTraversalBefore() {
return mAccessibilityTraversalBeforeId;
}
@@ -9743,6 +9787,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @see #setAccessibilityTraversalAfter(int)
*/
+ @InspectableProperty
public int getAccessibilityTraversalAfter() {
return mAccessibilityTraversalAfterId;
}
@@ -9754,6 +9799,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The labeled view id.
*/
@ViewDebug.ExportedProperty(category = "accessibility")
+ @InspectableProperty
public int getLabelFor() {
return mLabelForId;
}
@@ -9817,6 +9863,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return True if this view has focus, false otherwise.
*/
@ViewDebug.ExportedProperty(category = "focus")
+ @InspectableProperty(hasAttributeId = false)
public boolean isFocused() {
return (mPrivateFlags & PFLAG_FOCUSED) != 0;
}
@@ -9841,6 +9888,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_isScrollContainer
*/
+ @InspectableProperty(name = "isScrollContainer")
public boolean isScrollContainer() {
return (mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0;
}
@@ -9896,6 +9944,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
@Deprecated
@DrawingCacheQuality
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = DRAWING_CACHE_QUALITY_LOW, name = "low"),
+ @EnumMap(value = DRAWING_CACHE_QUALITY_HIGH, name = "high"),
+ @EnumMap(value = DRAWING_CACHE_QUALITY_AUTO, name = "auto")
+ })
public int getDrawingCacheQuality() {
return mViewFlags & DRAWING_CACHE_QUALITY_MASK;
}
@@ -9941,6 +9994,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_keepScreenOn
*/
+ @InspectableProperty
public boolean getKeepScreenOn() {
return (mViewFlags & KEEP_SCREEN_ON) != 0;
}
@@ -9965,6 +10019,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_nextFocusLeft
*/
+ @InspectableProperty(name = "nextFocusLeft")
public int getNextFocusLeftId() {
return mNextFocusLeftId;
}
@@ -9986,6 +10041,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_nextFocusRight
*/
+ @InspectableProperty(name = "nextFocusRight")
public int getNextFocusRightId() {
return mNextFocusRightId;
}
@@ -10007,6 +10063,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_nextFocusUp
*/
+ @InspectableProperty(name = "nextFocusUp")
public int getNextFocusUpId() {
return mNextFocusUpId;
}
@@ -10028,6 +10085,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_nextFocusDown
*/
+ @InspectableProperty(name = "nextFocusDown")
public int getNextFocusDownId() {
return mNextFocusDownId;
}
@@ -10049,6 +10107,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_nextFocusForward
*/
+ @InspectableProperty(name = "nextFocusForward")
public int getNextFocusForwardId() {
return mNextFocusForwardId;
}
@@ -10071,6 +10130,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_nextClusterForward
*/
+ @InspectableProperty(name = "nextClusterForward")
public int getNextClusterForwardId() {
return mNextClusterForwardId;
}
@@ -10437,6 +10497,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #setSystemUiVisibility(int)
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty
public boolean getFitsSystemWindows() {
return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS;
}
@@ -10498,6 +10559,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"),
@ViewDebug.IntToString(from = GONE, to = "GONE")
})
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = VISIBLE, name = "visible"),
+ @EnumMap(value = INVISIBLE, name = "invisible"),
+ @EnumMap(value = GONE, name = "gone")
+ })
@Visibility
public int getVisibility() {
return mViewFlags & VISIBILITY_MASK;
@@ -10521,6 +10587,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return True if this view is enabled, false otherwise.
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty
public boolean isEnabled() {
return (mViewFlags & ENABLED_MASK) == ENABLED;
}
@@ -10690,6 +10757,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_soundEffectsEnabled
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty
public boolean isSoundEffectsEnabled() {
return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED);
}
@@ -10719,6 +10787,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_hapticFeedbackEnabled
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty
public boolean isHapticFeedbackEnabled() {
return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED);
}
@@ -10741,6 +10810,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"),
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE")
})
+ @InspectableProperty(hasAttributeId = false, enumMapping = {
+ @EnumMap(value = LAYOUT_DIRECTION_LTR, name = "ltr"),
+ @EnumMap(value = LAYOUT_DIRECTION_RTL, name = "rtl"),
+ @EnumMap(value = LAYOUT_DIRECTION_INHERIT, name = "inherit"),
+ @EnumMap(value = LAYOUT_DIRECTION_LOCALE, name = "locale")
+ })
@LayoutDir
public int getRawLayoutDirection() {
return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
@@ -10794,6 +10869,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"),
@ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL")
})
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = LAYOUT_DIRECTION_LTR, name = "ltr"),
+ @EnumMap(value = LAYOUT_DIRECTION_RTL, name = "rtl")
+ })
@ResolvedLayoutDir
public int getLayoutDirection() {
final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
@@ -10980,6 +11059,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_clickable
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty
public boolean isClickable() {
return (mViewFlags & CLICKABLE) == CLICKABLE;
}
@@ -11007,6 +11087,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #setLongClickable(boolean)
* @attr ref android.R.styleable#View_longClickable
*/
+ @InspectableProperty
public boolean isLongClickable() {
return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE;
}
@@ -11032,6 +11113,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #setContextClickable(boolean)
* @attr ref android.R.styleable#View_contextClickable
*/
+ @InspectableProperty
public boolean isContextClickable() {
return (mViewFlags & CONTEXT_CLICKABLE) == CONTEXT_CLICKABLE;
}
@@ -11111,6 +11193,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return true if the view is currently pressed, false otherwise
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty(hasAttributeId = false)
public boolean isPressed() {
return (mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED;
}
@@ -11126,6 +11209,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #setAssistBlocked(boolean)
* @attr ref android.R.styleable#View_assistBlocked
*/
+ @InspectableProperty
public boolean isAssistBlocked() {
return (mPrivateFlags3 & PFLAG3_ASSIST_BLOCKED) != 0;
}
@@ -11163,6 +11247,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #setSaveEnabled(boolean)
* @attr ref android.R.styleable#View_saveEnabled
*/
+ @InspectableProperty
public boolean isSaveEnabled() {
return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED;
}
@@ -11198,6 +11283,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_filterTouchesWhenObscured
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty
public boolean getFilterTouchesWhenObscured() {
return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0;
}
@@ -11270,6 +11356,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = FOCUSABLE, to = "FOCUSABLE"),
@ViewDebug.IntToString(from = FOCUSABLE_AUTO, to = "FOCUSABLE_AUTO")
}, category = "focus")
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = NOT_FOCUSABLE, name = "false"),
+ @EnumMap(value = FOCUSABLE, name = "true"),
+ @EnumMap(value = FOCUSABLE_AUTO, name = "auto")
+ })
@Focusable
public int getFocusable() {
return (mViewFlags & FOCUSABLE_AUTO) > 0 ? FOCUSABLE_AUTO : mViewFlags & FOCUSABLE;
@@ -11284,6 +11375,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_focusableInTouchMode
*/
@ViewDebug.ExportedProperty(category = "focus")
+ @InspectableProperty
public final boolean isFocusableInTouchMode() {
return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE);
}
@@ -11295,6 +11387,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return Whether the view should be treated as a focusable unit by screen reader.
*/
+ @InspectableProperty
public boolean isScreenReaderFocusable() {
return (mPrivateFlags3 & PFLAG3_SCREEN_READER_FOCUSABLE) != 0;
}
@@ -11323,6 +11416,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_accessibilityHeading
*/
+ @InspectableProperty
public boolean isAccessibilityHeading() {
return (mPrivateFlags3 & PFLAG3_ACCESSIBILITY_HEADING) != 0;
}
@@ -11377,6 +11471,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_keyboardNavigationCluster
*/
@ViewDebug.ExportedProperty(category = "focus")
+ @InspectableProperty
public final boolean isKeyboardNavigationCluster() {
return (mPrivateFlags3 & PFLAG3_CLUSTER) != 0;
}
@@ -11486,6 +11581,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_focusedByDefault
*/
@ViewDebug.ExportedProperty(category = "focus")
+ @InspectableProperty
public final boolean isFocusedByDefault() {
return (mPrivateFlags3 & PFLAG3_FOCUSED_BY_DEFAULT) != 0;
}
@@ -11599,6 +11695,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_defaultFocusHighlightEnabled
*/
@ViewDebug.ExportedProperty(category = "focus")
+ @InspectableProperty
public final boolean getDefaultFocusHighlightEnabled() {
return mDefaultFocusHighlightEnabled;
}
@@ -11817,6 +11914,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return True if this View is accessibility focused.
*/
+ @InspectableProperty(hasAttributeId = false)
public boolean isAccessibilityFocused() {
return (mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0;
}
@@ -12143,6 +12241,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS,
to = "noHideDescendants")
})
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = IMPORTANT_FOR_ACCESSIBILITY_AUTO, name = "auto"),
+ @EnumMap(value = IMPORTANT_FOR_ACCESSIBILITY_YES, name = "yes"),
+ @EnumMap(value = IMPORTANT_FOR_ACCESSIBILITY_NO, name = "no"),
+ @EnumMap(value = IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS,
+ name = "noHideDescendants"),
+ })
public int getImportantForAccessibility() {
return (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK)
>> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT;
@@ -12195,6 +12300,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @see #setAccessibilityLiveRegion(int)
*/
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = ACCESSIBILITY_LIVE_REGION_NONE, name = "none"),
+ @EnumMap(value = ACCESSIBILITY_LIVE_REGION_POLITE, name = "polite"),
+ @EnumMap(value = ACCESSIBILITY_LIVE_REGION_ASSERTIVE, name = "assertive")
+ })
public int getAccessibilityLiveRegion() {
return (mPrivateFlags2 & PFLAG2_ACCESSIBILITY_LIVE_REGION_MASK)
>> PFLAG2_ACCESSIBILITY_LIVE_REGION_SHIFT;
@@ -15042,6 +15152,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return The left edge of the displayed part of your view, in pixels.
*/
+ @InspectableProperty
public final int getScrollX() {
return mScrollX;
}
@@ -15053,6 +15164,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return The top edge of the displayed part of your view, in pixels.
*/
+ @InspectableProperty
public final int getScrollY() {
return mScrollY;
}
@@ -15289,6 +15401,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The degrees of rotation.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getRotation() {
return mRenderNode.getRotation();
}
@@ -15329,6 +15442,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The degrees of Y rotation.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getRotationY() {
return mRenderNode.getRotationY();
}
@@ -15373,6 +15487,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The degrees of X rotation.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getRotationX() {
return mRenderNode.getRotationX();
}
@@ -15418,6 +15533,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The scaling factor.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getScaleX() {
return mRenderNode.getScaleX();
}
@@ -15455,6 +15571,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The scaling factor.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getScaleY() {
return mRenderNode.getScaleY();
}
@@ -15494,6 +15611,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_transformPivotX
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty(name = "transformPivotX")
public float getPivotX() {
return mRenderNode.getPivotX();
}
@@ -15536,6 +15654,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_transformPivotY
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty(name = "transformPivotY")
public float getPivotY() {
return mRenderNode.getPivotY();
}
@@ -15594,6 +15713,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The opacity of the view.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getAlpha() {
return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1;
}
@@ -15816,6 +15936,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return true if force dark is allowed (default), false if it is disabled
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public boolean isForceDarkAllowed() {
return mRenderNode.isForceDarkAllowed();
}
@@ -16187,6 +16308,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The base depth position of the view, in pixels.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getElevation() {
return mRenderNode.getElevation();
}
@@ -16215,6 +16337,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The horizontal position of this view relative to its left position, in pixels.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getTranslationX() {
return mRenderNode.getTranslationX();
}
@@ -16249,6 +16372,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* in pixels.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getTranslationY() {
return mRenderNode.getTranslationY();
}
@@ -16280,6 +16404,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The depth of this view relative to its elevation.
*/
@ViewDebug.ExportedProperty(category = "drawing")
+ @InspectableProperty
public float getTranslationZ() {
return mRenderNode.getTranslationZ();
}
@@ -16324,6 +16449,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return StateListAnimator or null if it does not exists
* @see #setStateListAnimator(android.animation.StateListAnimator)
*/
+ @InspectableProperty
public StateListAnimator getStateListAnimator() {
return mStateListAnimator;
}
@@ -16437,6 +16563,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @see #setOutlineProvider(ViewOutlineProvider)
*/
+ @InspectableProperty
public ViewOutlineProvider getOutlineProvider() {
return mOutlineProvider;
}
@@ -16513,6 +16640,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The shadow color set by {@link #setOutlineSpotShadowColor(int)}, or black if nothing
* was set
*/
+ @InspectableProperty
public @ColorInt int getOutlineSpotShadowColor() {
return mRenderNode.getSpotShadowColor();
}
@@ -16541,6 +16669,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The shadow color set by {@link #setOutlineAmbientShadowColor(int)}, or black if
* nothing was set
*/
+ @InspectableProperty
public @ColorInt int getOutlineAmbientShadowColor() {
return mRenderNode.getAmbientShadowColor();
}
@@ -17720,6 +17849,36 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
+ * Get the fading edge flags, used for inspection.
+ *
+ * @return One of {@link #FADING_EDGE_NONE}, {@link #FADING_EDGE_VERTICAL},
+ * or {@link #FADING_EDGE_HORIZONTAL}
+ * @hide
+ */
+ @InspectableProperty(name = "requiresFadingEdge", flagMapping = {
+ @FlagMap(target = FADING_EDGE_NONE, mask = FADING_EDGE_MASK, name = "none"),
+ @FlagMap(target = FADING_EDGE_VERTICAL, name = "vertical"),
+ @FlagMap(target = FADING_EDGE_HORIZONTAL, name = "horizontal")
+ })
+ int getFadingEdge() {
+ return mViewFlags & FADING_EDGE_MASK;
+ }
+
+ /**
+ * Get the fading edge length, used for inspection
+ *
+ * @return The fading edge length or 0
+ * @hide
+ */
+ @InspectableProperty
+ int getFadingEdgeLength() {
+ if (mScrollCache != null && (mViewFlags & FADING_EDGE_MASK) != FADING_EDGE_NONE) {
+ return mScrollCache.fadingEdgeLength;
+ }
+ return 0;
+ }
+
+ /**
* Returns the strength, or intensity, of the top faded edge. The strength is
* a value between 0.0 (no fade) and 1.0 (full fade). The default implementation
* returns 0.0 or 1.0 but no value in between.
@@ -17883,6 +18042,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade
*/
+ @InspectableProperty
public int getScrollBarDefaultDelayBeforeFade() {
return mScrollCache == null ? ViewConfiguration.getScrollDefaultDelay() :
mScrollCache.scrollBarDefaultDelayBeforeFade;
@@ -17907,6 +18067,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_scrollbarFadeDuration
*/
+ @InspectableProperty
public int getScrollBarFadeDuration() {
return mScrollCache == null ? ViewConfiguration.getScrollBarFadeDuration() :
mScrollCache.scrollBarFadeDuration;
@@ -17931,6 +18092,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_scrollbarSize
*/
+ @InspectableProperty
public int getScrollBarSize() {
return mScrollCache == null ? ViewConfiguration.get(mContext).getScaledScrollBarSize() :
mScrollCache.scrollBarSize;
@@ -17990,6 +18152,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"),
@ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET")
})
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = SCROLLBARS_INSIDE_OVERLAY, name = "insideOverlay"),
+ @EnumMap(value = SCROLLBARS_INSIDE_INSET, name = "insideInset"),
+ @EnumMap(value = SCROLLBARS_OUTSIDE_OVERLAY, name = "outsideOverlay"),
+ @EnumMap(value = SCROLLBARS_OUTSIDE_INSET, name = "outsideInset")
+ })
@ScrollBarStyle
public int getScrollBarStyle() {
return mViewFlags & SCROLLBARS_STYLE_MASK;
@@ -19411,6 +19579,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #getDrawableState()
* @see #setDuplicateParentStateEnabled(boolean)
*/
+ @InspectableProperty(name = "duplicateParentState")
public boolean isDuplicateParentStateEnabled() {
return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE;
}
@@ -19452,7 +19621,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_layerType
*/
- public void setLayerType(int layerType, @Nullable Paint paint) {
+ public void setLayerType(@LayerType int layerType, @Nullable Paint paint) {
if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) {
throw new IllegalArgumentException("Layer type can only be one of: LAYER_TYPE_NONE, "
+ "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE");
@@ -19536,6 +19705,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #LAYER_TYPE_SOFTWARE
* @see #LAYER_TYPE_HARDWARE
*/
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = LAYER_TYPE_NONE, name = "none"),
+ @EnumMap(value = LAYER_TYPE_SOFTWARE, name = "software"),
+ @EnumMap(value = LAYER_TYPE_HARDWARE, name = "hardware")
+ })
+ @LayerType
public int getLayerType() {
return mLayerType;
}
@@ -22312,6 +22487,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_background
*/
+ @InspectableProperty
public Drawable getBackground() {
return mBackground;
}
@@ -22347,6 +22523,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_backgroundTint
* @see #setBackgroundTintList(ColorStateList)
*/
+ @InspectableProperty(name = "backgroundTint")
@Nullable
public ColorStateList getBackgroundTintList() {
return mBackgroundTint != null ? mBackgroundTint.mTintList : null;
@@ -22383,6 +22560,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #setBackgroundTintMode(PorterDuff.Mode)
*/
@Nullable
+ @InspectableProperty
public PorterDuff.Mode getBackgroundTintMode() {
return mBackgroundTint != null ? mBackgroundTint.mTintMode : null;
}
@@ -22418,6 +22596,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @see #onDrawForeground(Canvas)
*/
+ @InspectableProperty
public Drawable getForeground() {
return mForegroundInfo != null ? mForegroundInfo.mDrawable : null;
}
@@ -22496,6 +22675,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_foregroundGravity
*/
+ @InspectableProperty(valueType = InspectableProperty.ValueType.GRAVITY)
public int getForegroundGravity() {
return mForegroundInfo != null ? mForegroundInfo.mGravity
: Gravity.START | Gravity.TOP;
@@ -22563,6 +22743,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_foregroundTint
* @see #setForegroundTintList(ColorStateList)
*/
+ @InspectableProperty(name = "foregroundTint")
@Nullable
public ColorStateList getForegroundTintList() {
return mForegroundInfo != null && mForegroundInfo.mTintInfo != null
@@ -22602,6 +22783,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_foregroundTintMode
* @see #setForegroundTintMode(PorterDuff.Mode)
*/
+ @InspectableProperty
@Nullable
public PorterDuff.Mode getForegroundTintMode() {
return mForegroundInfo != null && mForegroundInfo.mTintInfo != null
@@ -22846,6 +23028,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return the top padding in pixels
*/
+ @InspectableProperty
public int getPaddingTop() {
return mPaddingTop;
}
@@ -22857,6 +23040,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return the bottom padding in pixels
*/
+ @InspectableProperty
public int getPaddingBottom() {
return mPaddingBottom;
}
@@ -22868,6 +23052,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return the left padding in pixels
*/
+ @InspectableProperty
public int getPaddingLeft() {
if (!isPaddingResolved()) {
resolvePadding();
@@ -22897,6 +23082,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return the right padding in pixels
*/
+ @InspectableProperty
public int getPaddingRight() {
if (!isPaddingResolved()) {
resolvePadding();
@@ -23019,6 +23205,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return true if the view is selected, false otherwise
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty(hasAttributeId = false)
public boolean isSelected() {
return (mPrivateFlags & PFLAG_SELECTED) != 0;
}
@@ -23062,6 +23249,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return true if the view is activated, false otherwise
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty(hasAttributeId = false)
public boolean isActivated() {
return (mPrivateFlags & PFLAG_ACTIVATED) != 0;
}
@@ -23560,6 +23748,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
@IdRes
@ViewDebug.CapturedViewProperty
+ @InspectableProperty
public int getId() {
return mID;
}
@@ -23584,6 +23773,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #getTag(int)
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty
public Object getTag() {
return mTag;
}
@@ -23780,6 +23970,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* if baseline alignment is not supported
*/
@ViewDebug.ExportedProperty(category = "layout")
+ @InspectableProperty
public int getBaseline() {
return -1;
}
@@ -24150,6 +24341,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_minHeight
*/
+ @InspectableProperty(name = "minHeight")
public int getMinimumHeight() {
return mMinHeight;
}
@@ -24180,6 +24372,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_minWidth
*/
+ @InspectableProperty(name = "minWidth")
public int getMinimumWidth() {
return mMinWidth;
}
@@ -25199,6 +25392,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @return This view's over-scroll mode.
*/
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = OVER_SCROLL_ALWAYS, name = "always"),
+ @EnumMap(value = OVER_SCROLL_IF_CONTENT_SCROLLS, name = "ifContentScrolls"),
+ @EnumMap(value = OVER_SCROLL_NEVER, name = "never")
+ })
public int getOverScrollMode() {
return mOverScrollMode;
}
@@ -25257,6 +25455,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @see #setNestedScrollingEnabled(boolean)
*/
+ @InspectableProperty
public boolean isNestedScrollingEnabled() {
return (mPrivateFlags3 & PFLAG3_NESTED_SCROLLING_ENABLED) ==
PFLAG3_NESTED_SCROLLING_ENABLED;
@@ -25586,6 +25785,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG_LTR, to = "FIRST_STRONG_LTR"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG_RTL, to = "FIRST_STRONG_RTL")
})
+ @InspectableProperty(hasAttributeId = false, enumMapping = {
+ @EnumMap(value = TEXT_DIRECTION_INHERIT, name = "inherit"),
+ @EnumMap(value = TEXT_DIRECTION_LOCALE, name = "locale"),
+ @EnumMap(value = TEXT_DIRECTION_ANY_RTL, name = "anyRtl"),
+ @EnumMap(value = TEXT_DIRECTION_LTR, name = "ltr"),
+ @EnumMap(value = TEXT_DIRECTION_RTL, name = "rtl"),
+ @EnumMap(value = TEXT_DIRECTION_FIRST_STRONG, name = "firstStrong"),
+ @EnumMap(value = TEXT_DIRECTION_FIRST_STRONG_LTR, name = "firstStrongLtr"),
+ @EnumMap(value = TEXT_DIRECTION_FIRST_STRONG_RTL, name = "firstStrongRtl"),
+ })
@UnsupportedAppUsage
public int getRawTextDirection() {
return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_MASK) >> PFLAG2_TEXT_DIRECTION_MASK_SHIFT;
@@ -25653,6 +25862,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG_LTR, to = "FIRST_STRONG_LTR"),
@ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG_RTL, to = "FIRST_STRONG_RTL")
})
+ @InspectableProperty(hasAttributeId = false, enumMapping = {
+ @EnumMap(value = TEXT_DIRECTION_LOCALE, name = "locale"),
+ @EnumMap(value = TEXT_DIRECTION_ANY_RTL, name = "anyRtl"),
+ @EnumMap(value = TEXT_DIRECTION_LTR, name = "ltr"),
+ @EnumMap(value = TEXT_DIRECTION_RTL, name = "rtl"),
+ @EnumMap(value = TEXT_DIRECTION_FIRST_STRONG, name = "firstStrong"),
+ @EnumMap(value = TEXT_DIRECTION_FIRST_STRONG_LTR, name = "firstStrongLtr"),
+ @EnumMap(value = TEXT_DIRECTION_FIRST_STRONG_RTL, name = "firstStrongRtl"),
+ })
public int getTextDirection() {
return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED_MASK) >> PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT;
}
@@ -25824,6 +26042,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"),
@ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END")
})
+ @InspectableProperty(hasAttributeId = false, enumMapping = {
+ @EnumMap(value = TEXT_ALIGNMENT_INHERIT, name = "inherit"),
+ @EnumMap(value = TEXT_ALIGNMENT_GRAVITY, name = "gravity"),
+ @EnumMap(value = TEXT_ALIGNMENT_TEXT_START, name = "textStart"),
+ @EnumMap(value = TEXT_ALIGNMENT_TEXT_END, name = "textEnd"),
+ @EnumMap(value = TEXT_ALIGNMENT_CENTER, name = "center"),
+ @EnumMap(value = TEXT_ALIGNMENT_VIEW_START, name = "viewStart"),
+ @EnumMap(value = TEXT_ALIGNMENT_VIEW_END, name = "viewEnd")
+ })
@TextAlignment
@UnsupportedAppUsage
public int getRawTextAlignment() {
@@ -25890,6 +26117,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
@ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"),
@ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END")
})
+ @InspectableProperty(enumMapping = {
+ @EnumMap(value = TEXT_ALIGNMENT_GRAVITY, name = "gravity"),
+ @EnumMap(value = TEXT_ALIGNMENT_TEXT_START, name = "textStart"),
+ @EnumMap(value = TEXT_ALIGNMENT_TEXT_END, name = "textEnd"),
+ @EnumMap(value = TEXT_ALIGNMENT_CENTER, name = "center"),
+ @EnumMap(value = TEXT_ALIGNMENT_VIEW_START, name = "viewStart"),
+ @EnumMap(value = TEXT_ALIGNMENT_VIEW_END, name = "viewEnd")
+ })
@TextAlignment
public int getTextAlignment() {
return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK) >>
@@ -26122,6 +26357,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
/**
* Gets the pointer icon for the current view.
*/
+ @InspectableProperty
public PointerIcon getPointerIcon() {
return mPointerIcon;
}
@@ -26672,6 +26908,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* if no name has been given.
*/
@ViewDebug.ExportedProperty
+ @InspectableProperty
public String getTransitionName() {
return mTransitionName;
}
@@ -28277,6 +28514,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #setTooltipText(CharSequence)
* @attr ref android.R.styleable#View_tooltipText
*/
+ @InspectableProperty
@Nullable
public CharSequence getTooltipText() {
return mTooltipInfo != null ? mTooltipInfo.mTooltipText : null;
diff --git a/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java b/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
index 8df83c0e5dff..797b861e9e70 100644
--- a/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
+++ b/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
@@ -76,7 +76,9 @@ public final class ActionsSuggestionsHelper {
return new ActionsSuggestionsModel.ConversationMessage[]{
new ActionsSuggestionsModel.ConversationMessage(
FIRST_NON_LOCAL_USER,
- lastMessage.getText().toString())};
+ lastMessage.getText().toString(),
+ 0,
+ null)};
}
// Encode the messages in the reverse order, stop whenever the Person object is missing.
@@ -89,7 +91,7 @@ public final class ActionsSuggestionsHelper {
}
nativeMessages.push(new ActionsSuggestionsModel.ConversationMessage(
personEncoder.encode(message.getAuthor()),
- message.getText().toString()));
+ message.getText().toString(), 0, null));
}
return nativeMessages.toArray(
new ActionsSuggestionsModel.ConversationMessage[nativeMessages.size()]);
diff --git a/core/java/android/webkit/TokenBindingService.java b/core/java/android/webkit/TokenBindingService.java
index b37e1b8962c5..4d2c04663579 100644
--- a/core/java/android/webkit/TokenBindingService.java
+++ b/core/java/android/webkit/TokenBindingService.java
@@ -16,12 +16,7 @@
package android.webkit;
-import android.annotation.NonNull;
-import android.annotation.Nullable;
import android.annotation.SystemApi;
-import android.net.Uri;
-
-import java.security.KeyPair;
/**
* Enables the token binding procotol, and provides access to the keys. See
@@ -30,86 +25,9 @@ import java.security.KeyPair;
* All methods are required to be called on the UI thread where WebView is
* attached to the View hierarchy.
* @hide
+ * @deprecated this is no longer supported.
*/
@SystemApi
+@Deprecated
public abstract class TokenBindingService {
-
- public static final String KEY_ALGORITHM_RSA2048_PKCS_1_5 = "RSA2048_PKCS_1.5";
- public static final String KEY_ALGORITHM_RSA2048_PSS = "RSA2048PSS";
- public static final String KEY_ALGORITHM_ECDSAP256 = "ECDSAP256";
-
- /**
- * Provides the KeyPair information.
- */
- public static abstract class TokenBindingKey {
- /**
- * The public, private key pair.
- */
- public abstract KeyPair getKeyPair();
-
- /**
- * The algorithm that is used to generate the key pair.
- */
- public abstract String getAlgorithm();
- }
-
- /**
- * Returns the default TokenBinding service instance. At present there is
- * only one token binding service instance for all WebView instances,
- * however this restriction may be relaxed in the future.
- *
- * @return The default TokenBindingService instance.
- */
- public static TokenBindingService getInstance() {
- return WebViewFactory.getProvider().getTokenBindingService();
- }
-
- /**
- * Enables the token binding protocol. The token binding protocol
- * has to be enabled before creating any WebViews.
- *
- * @throws IllegalStateException if a WebView was already created.
- */
- public abstract void enableTokenBinding();
-
- /**
- * Retrieves the key pair for a given origin from the internal
- * TokenBinding key store asynchronously.
- *
- * The user can provide a list of acceptable algorithms for the retrieved
- * key pair. If a key pair exists and it is in the list of algorithms, then
- * the key is returned. If it is not in the list, no key is returned.
- *
- * If no key pair exists, WebView chooses an algorithm from the list, in
- * the order given, to generate a key.
- *
- * The user can pass {@code null} if any algorithm is acceptable.
- *
- * @param origin The origin for the server.
- * @param algorithm The list of algorithms. An IllegalArgumentException is thrown if array is
- * empty.
- * @param callback The callback that will be called when key is available.
- */
- public abstract void getKey(Uri origin,
- @Nullable String[] algorithm,
- @NonNull ValueCallback<TokenBindingKey> callback);
- /**
- * Deletes specified key (for use when associated cookie is cleared).
- *
- * @param origin The origin of the server.
- * @param callback The callback that will be called when key is deleted. The
- * callback parameter (Boolean) will indicate if operation is
- * successful or if failed.
- */
- public abstract void deleteKey(Uri origin,
- @Nullable ValueCallback<Boolean> callback);
-
- /**
- * Deletes all the keys (for use when cookies are cleared).
- *
- * @param callback The callback that will be called when keys are deleted.
- * The callback parameter (Boolean) will indicate if operation is
- * successful or if failed.
- */
- public abstract void deleteAllKeys(@Nullable ValueCallback<Boolean> callback);
}
diff --git a/core/java/android/webkit/WebViewFactoryProvider.java b/core/java/android/webkit/WebViewFactoryProvider.java
index 4ff49ea1bbc3..6a1ed39e25b3 100644
--- a/core/java/android/webkit/WebViewFactoryProvider.java
+++ b/core/java/android/webkit/WebViewFactoryProvider.java
@@ -129,7 +129,8 @@ public interface WebViewFactoryProvider {
* Gets the TokenBindingService instance for this WebView implementation. The
* implementation must return the same instance on subsequent calls.
*
- * @return the TokenBindingService instance
+ * @deprecated this method only returns {@code null}
+ * @return the TokenBindingService instance (which is always {@code null})
*/
TokenBindingService getTokenBindingService();
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index c6155ced9c9f..3c32bb29cf66 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -2051,8 +2051,8 @@ public class Editor {
}
void updateCursorPosition() {
- if (mTextView.mCursorDrawableRes == 0) {
- mDrawableForCursor = null;
+ loadCursorDrawable();
+ if (mDrawableForCursor == null) {
return;
}
@@ -2462,10 +2462,7 @@ public class Editor {
}
private void updateCursorPosition(int top, int bottom, float horizontal) {
- if (mDrawableForCursor == null) {
- mDrawableForCursor = mTextView.getContext().getDrawable(
- mTextView.mCursorDrawableRes);
- }
+ loadCursorDrawable();
final int left = clampHorizontalPosition(mDrawableForCursor, horizontal);
final int width = mDrawableForCursor.getIntrinsicWidth();
mDrawableForCursor.setBounds(left, top - mTempRect.top, left + width,
@@ -5698,6 +5695,12 @@ public class Editor {
public boolean isActive();
}
+ void loadCursorDrawable() {
+ if (mDrawableForCursor == null) {
+ mDrawableForCursor = mTextView.getTextCursorDrawable();
+ }
+ }
+
private class InsertionPointCursorController implements CursorController {
private InsertionHandleView mHandle;
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 3b916d16b2b4..2dec4e87e662 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -3423,6 +3423,12 @@ public class RemoteViews implements Parcelable, Filter {
* @hide
*/
public interface OnViewAppliedListener {
+ /**
+ * Callback when the RemoteView has finished inflating,
+ * but no actions have been applied yet.
+ */
+ default void onViewInflated(View v) {};
+
void onViewApplied(View v);
void onError(Exception e);
@@ -3519,6 +3525,10 @@ public class RemoteViews implements Parcelable, Filter {
@Override
protected void onPostExecute(ViewTree viewTree) {
if (mError == null) {
+ if (mListener != null) {
+ mListener.onViewInflated(viewTree.mRoot);
+ }
+
try {
if (mActions != null) {
OnClickHandler handler = mHandler == null
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 085f8f1d678f..90cf871830fd 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -799,8 +799,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Although these fields are specific to editable text, they are not added to Editor because
// they are defined by the TextView's style and are theme-dependent.
- @UnsupportedAppUsage
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
int mCursorDrawableRes;
+ private Drawable mCursorDrawable;
// Note: this might be stale if setTextSelectHandleLeft is used. We could simplify the code
// by removing it, but we would break apps targeting <= P that use it by reflection.
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
@@ -3640,6 +3641,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
/**
* Returns the Drawable corresponding to the right handle used
* for selecting text.
+ * Note that any change applied to the handle Drawable will not be visible
+ * until the handle is hidden and then drawn again.
*
* @return the right text selection handle drawable
*
@@ -3655,6 +3658,58 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
+ * Sets the Drawable corresponding to the text cursor. The Drawable defaults to the
+ * value of the textCursorDrawable attribute.
+ * Note that any change applied to the cursor Drawable will not be visible
+ * until the cursor is hidden and then drawn again.
+ *
+ * @see #setTextCursorDrawable(int)
+ * @attr ref android.R.styleable#TextView_textCursorDrawable
+ */
+ public void setTextCursorDrawable(@NonNull Drawable textCursorDrawable) {
+ Preconditions.checkNotNull(textCursorDrawable,
+ "The cursor drawable should not be null.");
+ mCursorDrawable = textCursorDrawable;
+ mCursorDrawableRes = 0;
+ if (mEditor != null) {
+ mEditor.loadCursorDrawable();
+ }
+ }
+
+ /**
+ * Sets the Drawable corresponding to the text cursor. The Drawable defaults to the
+ * value of the textCursorDrawable attribute.
+ * Note that any change applied to the cursor Drawable will not be visible
+ * until the cursor is hidden and then drawn again.
+ *
+ * @see #setTextCursorDrawable(Drawable)
+ * @attr ref android.R.styleable#TextView_textCursorDrawable
+ */
+ public void setTextCursorDrawable(@DrawableRes int textCursorDrawable) {
+ Preconditions.checkArgumentPositive(textCursorDrawable,
+ "The cursor drawable should be a valid drawable resource id.");
+ setTextCursorDrawable(mContext.getDrawable(textCursorDrawable));
+ }
+
+ /**
+ * Returns the Drawable corresponding to the text cursor.
+ * Note that any change applied to the cursor Drawable will not be visible
+ * until the cursor is hidden and then drawn again.
+ *
+ * @return the text cursor drawable
+ *
+ * @see #setTextCursorDrawable(Drawable)
+ * @see #setTextCursorDrawable(int)
+ * @attr ref android.R.styleable#TextView_textCursorDrawable
+ */
+ @Nullable public Drawable getTextCursorDrawable() {
+ if (mCursorDrawable == null && mCursorDrawableRes != 0) {
+ mCursorDrawable = mContext.getDrawable(mCursorDrawableRes);
+ }
+ return mCursorDrawable;
+ }
+
+ /**
* Sets the text appearance from the specified style resource.
* <p>
* Use a framework-defined {@code TextAppearance} style like
diff --git a/core/java/com/android/internal/os/BinderCallsStats.java b/core/java/com/android/internal/os/BinderCallsStats.java
index a87bbf33ca9e..ff34036ce7e9 100644
--- a/core/java/com/android/internal/os/BinderCallsStats.java
+++ b/core/java/com/android/internal/os/BinderCallsStats.java
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.os.Binder;
import android.os.Process;
import android.os.SystemClock;
+import android.os.ThreadLocalWorkSource;
import android.os.UserHandle;
import android.text.format.DateFormat;
import android.util.ArrayMap;
@@ -162,8 +163,7 @@ public class BinderCallsStats implements BinderInternal.Observer {
return;
}
- final boolean isWorkSourceSet = workSourceUid >= 0;
- final UidEntry uidEntry = getUidEntry(isWorkSourceSet ? workSourceUid : callingUid);
+ final UidEntry uidEntry = getUidEntry(workSourceUid);
uidEntry.callCount++;
if (recordCall) {
@@ -344,7 +344,7 @@ public class BinderCallsStats implements BinderInternal.Observer {
callStat.recordedCallCount = 1;
callStat.callCount = 1;
callStat.methodName = "__DEBUG_" + variableName;
- callStat.maxReplySizeBytes = value;
+ callStat.latencyMicros = value;
return callStat;
}
@@ -464,7 +464,7 @@ public class BinderCallsStats implements BinderInternal.Observer {
}
protected int getWorkSourceUid() {
- return Binder.getCallingWorkSourceUid();
+ return ThreadLocalWorkSource.getUid();
}
protected long getElapsedRealtimeMicro() {
diff --git a/core/java/com/android/internal/os/LooperStats.java b/core/java/com/android/internal/os/LooperStats.java
index de85c1f35a58..01fd8ba58c74 100644
--- a/core/java/com/android/internal/os/LooperStats.java
+++ b/core/java/com/android/internal/os/LooperStats.java
@@ -167,7 +167,7 @@ public class LooperStats implements Looper.Observer {
final Entry entry = new Entry("__DEBUG_" + variableName);
entry.messageCount = 1;
entry.recordedMessageCount = 1;
- entry.maxDelayMillis = value;
+ entry.totalLatencyMicro = value;
return new ExportedEntry(entry);
}
diff --git a/core/java/com/android/internal/widget/ImageMessageConsumer.java b/core/java/com/android/internal/widget/ImageMessageConsumer.java
new file mode 100644
index 000000000000..01613dcdf3fa
--- /dev/null
+++ b/core/java/com/android/internal/widget/ImageMessageConsumer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+/**
+ * An interface for the class who will use the {@link ImageResolver} to resolve images.
+ */
+public interface ImageMessageConsumer {
+ /**
+ * Set the custom {@link ImageResolver} other than {@link LocalImageResolver}.
+ * @param resolver An image resolver that has custom implementation.
+ */
+ void setImageResolver(ImageResolver resolver);
+}
diff --git a/core/java/com/android/internal/widget/ImageResolver.java b/core/java/com/android/internal/widget/ImageResolver.java
new file mode 100644
index 000000000000..45885257ad8d
--- /dev/null
+++ b/core/java/com/android/internal/widget/ImageResolver.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+
+/**
+ * An interface for image resolvers that have custom implementations like cache mechanisms.
+ */
+public interface ImageResolver {
+ /**
+ * Load an image from specified uri.
+ * @param uri Uri of the target image.
+ * @return Target image in Drawable.
+ */
+ Drawable loadImage(Uri uri);
+}
diff --git a/core/java/com/android/internal/widget/LocalImageResolver.java b/core/java/com/android/internal/widget/LocalImageResolver.java
index 71d3bb5d6b5c..2302de2cd058 100644
--- a/core/java/com/android/internal/widget/LocalImageResolver.java
+++ b/core/java/com/android/internal/widget/LocalImageResolver.java
@@ -17,7 +17,6 @@
package com.android.internal.widget;
import android.annotation.Nullable;
-import android.app.Notification;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
diff --git a/core/java/com/android/internal/widget/MessagingImageMessage.java b/core/java/com/android/internal/widget/MessagingImageMessage.java
index 607a3a9ab542..64650a7ebc2f 100644
--- a/core/java/com/android/internal/widget/MessagingImageMessage.java
+++ b/core/java/com/android/internal/widget/MessagingImageMessage.java
@@ -25,6 +25,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pools;
@@ -57,6 +58,7 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
private int mActualWidth;
private int mActualHeight;
private boolean mIsIsolated;
+ private ImageResolver mImageResolver;
public MessagingImageMessage(@NonNull Context context) {
this(context, null);
@@ -96,11 +98,16 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
MessagingMessage.super.setMessage(message);
Drawable drawable;
try {
- drawable = LocalImageResolver.resolveImage(message.getDataUri(), getContext());
+ Uri uri = message.getDataUri();
+ drawable = mImageResolver != null ? mImageResolver.loadImage(uri) :
+ LocalImageResolver.resolveImage(uri, getContext());
} catch (IOException | SecurityException e) {
e.printStackTrace();
return false;
}
+ if (drawable == null) {
+ return false;
+ }
int intrinsicHeight = drawable.getIntrinsicHeight();
if (intrinsicHeight == 0) {
Log.w(TAG, "Drawable with 0 intrinsic height was returned");
@@ -114,7 +121,7 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
}
static MessagingMessage createMessage(MessagingLayout layout,
- Notification.MessagingStyle.Message m) {
+ Notification.MessagingStyle.Message m, ImageResolver resolver) {
MessagingLinearLayout messagingLinearLayout = layout.getMessagingLinearLayout();
MessagingImageMessage createdMessage = sInstancePool.acquire();
if (createdMessage == null) {
@@ -125,6 +132,7 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
false);
createdMessage.addOnLayoutChangeListener(MessagingLayout.MESSAGING_PROPERTY_ANIMATOR);
}
+ createdMessage.setImageResolver(resolver);
boolean created = createdMessage.setMessage(m);
if (!created) {
createdMessage.recycle();
@@ -133,6 +141,10 @@ public class MessagingImageMessage extends ImageView implements MessagingMessage
return createdMessage;
}
+ private void setImageResolver(ImageResolver resolver) {
+ mImageResolver = resolver;
+ }
+
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
diff --git a/core/java/com/android/internal/widget/MessagingLayout.java b/core/java/com/android/internal/widget/MessagingLayout.java
index 0f2e9c52add0..07d0d7d91997 100644
--- a/core/java/com/android/internal/widget/MessagingLayout.java
+++ b/core/java/com/android/internal/widget/MessagingLayout.java
@@ -57,7 +57,7 @@ import java.util.regex.Pattern;
* messages and adapts the layout accordingly.
*/
@RemoteViews.RemoteView
-public class MessagingLayout extends FrameLayout {
+public class MessagingLayout extends FrameLayout implements ImageMessageConsumer {
private static final float COLOR_SHIFT_AMOUNT = 60;
/**
@@ -95,6 +95,7 @@ public class MessagingLayout extends FrameLayout {
private Person mUser;
private CharSequence mNameReplacement;
private boolean mDisplayImagesAtEnd;
+ private ImageResolver mImageResolver;
public MessagingLayout(@NonNull Context context) {
super(context);
@@ -167,6 +168,11 @@ public class MessagingLayout extends FrameLayout {
bind(newMessages, newHistoricMessages, showSpinner);
}
+ @Override
+ public void setImageResolver(ImageResolver resolver) {
+ mImageResolver = resolver;
+ }
+
private void addRemoteInputHistoryToMessages(
List<Notification.MessagingStyle.Message> newMessages,
CharSequence[] remoteInputHistory) {
@@ -463,12 +469,12 @@ public class MessagingLayout extends FrameLayout {
*/
private List<MessagingMessage> createMessages(
List<Notification.MessagingStyle.Message> newMessages, boolean historic) {
- List<MessagingMessage> result = new ArrayList<>();;
+ List<MessagingMessage> result = new ArrayList<>();
for (int i = 0; i < newMessages.size(); i++) {
Notification.MessagingStyle.Message m = newMessages.get(i);
MessagingMessage message = findAndRemoveMatchingMessage(m);
if (message == null) {
- message = MessagingMessage.createMessage(this, m);
+ message = MessagingMessage.createMessage(this, m, mImageResolver);
}
message.setIsHistoric(historic);
result.add(message);
diff --git a/core/java/com/android/internal/widget/MessagingMessage.java b/core/java/com/android/internal/widget/MessagingMessage.java
index 74d0aae3634b..c32d3705bba7 100644
--- a/core/java/com/android/internal/widget/MessagingMessage.java
+++ b/core/java/com/android/internal/widget/MessagingMessage.java
@@ -33,9 +33,9 @@ public interface MessagingMessage extends MessagingLinearLayout.MessagingChild {
String IMAGE_MIME_TYPE_PREFIX = "image/";
static MessagingMessage createMessage(MessagingLayout layout,
- Notification.MessagingStyle.Message m) {
+ Notification.MessagingStyle.Message m, ImageResolver resolver) {
if (hasImage(m) && !ActivityManager.isLowRamDeviceStatic()) {
- return MessagingImageMessage.createMessage(layout, m);
+ return MessagingImageMessage.createMessage(layout, m, resolver);
} else {
return MessagingTextMessage.createMessage(layout, m);
}
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index 8e9a0bf61517..02867304af36 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -102,6 +102,11 @@ enum MountExternalKind {
MOUNT_EXTERNAL_FULL = 4,
};
+// Must match values in com.android.internal.os.Zygote.
+enum RuntimeFlags : uint32_t {
+ DEBUG_ENABLE_JDWP = 1,
+};
+
static void RuntimeAbort(JNIEnv* env, int line, const char* msg) {
std::ostringstream oss;
oss << __FILE__ << ":" << line << ": " << msg;
@@ -254,6 +259,36 @@ static bool SetRLimits(JNIEnv* env, jobjectArray javaRlimits, std::string* error
return true;
}
+static void EnableDebugger() {
+ // To let a non-privileged gdbserver attach to this
+ // process, we must set our dumpable flag.
+ if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
+ ALOGE("prctl(PR_SET_DUMPABLE) failed");
+ }
+
+ // A non-privileged native debugger should be able to attach to the debuggable app, even if Yama
+ // is enabled (see kernel/Documentation/security/Yama.txt).
+ if (prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0) == -1) {
+ // if Yama is off prctl(PR_SET_PTRACER) returns EINVAL - don't log in this
+ // case since it's expected behaviour.
+ if (errno != EINVAL) {
+ ALOGE("prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY) failed");
+ }
+ }
+
+ // We don't want core dumps, though, so set the soft limit on core dump size
+ // to 0 without changing the hard limit.
+ rlimit rl;
+ if (getrlimit(RLIMIT_CORE, &rl) == -1) {
+ ALOGE("getrlimit(RLIMIT_CORE) failed");
+ } else {
+ rl.rlim_cur = 0;
+ if (setrlimit(RLIMIT_CORE, &rl) == -1) {
+ ALOGE("setrlimit(RLIMIT_CORE) failed");
+ }
+ }
+}
+
// The debug malloc library needs to know whether it's the zygote or a child.
extern "C" int gMallocLeakZygoteChild;
@@ -956,6 +991,11 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids,
}
}
+ // Set process properties to enable debugging if required.
+ if ((runtime_flags & RuntimeFlags::DEBUG_ENABLE_JDWP) != 0) {
+ EnableDebugger();
+ }
+
if (NeedsNoRandomizeWorkaround()) {
// Work around ARM kernel ASLR lossage (http://b/5817320).
int old_personality = personality(0xffffffff);
diff --git a/core/proto/android/app/settings_enums.proto b/core/proto/android/app/settings_enums.proto
index 3a908dc28e4c..8e4eb0018999 100644
--- a/core/proto/android/app/settings_enums.proto
+++ b/core/proto/android/app/settings_enums.proto
@@ -38,6 +38,12 @@ enum PageId {
// Unknown page. Should not be used in production code.
PAGE_UNKNOWN = 0;
+ // OPEN: Settings > Connected Devices > Bluetooth > (click on details link for a paired device)
+ BLUETOOTH_DEVICE_DETAILS = 1009;
+
+ // OPEN: Settings > Connected devices > Bluetooth > Pair new device
+ BLUETOOTH_PAIRING = 1018;
+
// OPEN: Settings homepage
SETTINGS_HOMEPAGE = 1502;
diff --git a/core/proto/android/server/activitymanagerservice.proto b/core/proto/android/server/activitymanagerservice.proto
index ab50ad147107..60561bd9dbc5 100644
--- a/core/proto/android/server/activitymanagerservice.proto
+++ b/core/proto/android/server/activitymanagerservice.proto
@@ -185,6 +185,7 @@ message ProcessRecordProto {
optional int32 app_id = 5;
optional int32 isolated_app_id = 6;
optional bool persistent = 7;
+ optional int32 lru_index = 8;
}
message BroadcastRecordProto {
diff --git a/core/proto/android/server/jobscheduler.proto b/core/proto/android/server/jobscheduler.proto
index e83a2bfac77a..231caabe0335 100644
--- a/core/proto/android/server/jobscheduler.proto
+++ b/core/proto/android/server/jobscheduler.proto
@@ -215,6 +215,34 @@ message ConstantsProto {
// The fraction of a prefetch job's running window that must pass before
// we consider matching it against a metered network.
optional double conn_prefetch_relax_frac = 22;
+ // Whether to use heartbeats or rolling window for quota management. True
+ // will use heartbeats, false will use a rolling window.
+ optional bool use_heartbeats = 23;
+
+ message QuotaController {
+ // How much time each app will have to run jobs within their standby bucket window.
+ optional int64 allowed_time_per_period_ms = 1;
+ // How much time the package should have before transitioning from out-of-quota to in-quota.
+ // This should not affect processing if the package is already in-quota.
+ optional int64 in_quota_buffer_ms = 2;
+ // The quota window size of the particular standby bucket. Apps in this standby bucket are
+ // expected to run only {@link QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS} within the past
+ // WINDOW_SIZE_MS.
+ optional int64 active_window_size_ms = 3;
+ // The quota window size of the particular standby bucket. Apps in this standby bucket are
+ // expected to run only {@link QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS} within the past
+ // WINDOW_SIZE_MS.
+ optional int64 working_window_size_ms = 4;
+ // The quota window size of the particular standby bucket. Apps in this standby bucket are
+ // expected to run only {@link QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS} within the past
+ // WINDOW_SIZE_MS.
+ optional int64 frequent_window_size_ms = 5;
+ // The quota window size of the particular standby bucket. Apps in this standby bucket are
+ // expected to run only {@link QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS} within the past
+ // WINDOW_SIZE_MS.
+ optional int64 rare_window_size_ms = 6;
+ }
+ optional QuotaController quota_controller = 24;
}
message StateControllerProto {
@@ -357,6 +385,65 @@ message StateControllerProto {
}
repeated TrackedJob tracked_jobs = 2;
}
+ message QuotaController {
+ option (.android.msg_privacy).dest = DEST_AUTOMATIC;
+
+ optional bool is_charging = 1;
+ optional bool is_in_parole = 2;
+
+ message TrackedJob {
+ option (.android.msg_privacy).dest = DEST_AUTOMATIC;
+
+ optional JobStatusShortInfoProto info = 1;
+ optional int32 source_uid = 2;
+ optional JobStatusDumpProto.Bucket effective_standby_bucket = 3;
+ optional bool has_quota = 4;
+ // The amount of time that this job has remaining in its quota. This
+ // can be negative if the job is out of quota.
+ optional int64 remaining_quota_ms = 5;
+ }
+ repeated TrackedJob tracked_jobs = 3;
+
+ message Package {
+ option (.android.msg_privacy).dest = DEST_AUTOMATIC;
+
+ optional int32 user_id = 1;
+ optional string name = 2;
+ }
+
+ message TimingSession {
+ option (.android.msg_privacy).dest = DEST_AUTOMATIC;
+
+ optional int64 start_time_elapsed = 1;
+ optional int64 end_time_elapsed = 2;
+ optional int32 job_count = 3;
+ }
+
+ message Timer {
+ option (.android.msg_privacy).dest = DEST_AUTOMATIC;
+
+ optional Package pkg = 1;
+ // True if the Timer is actively tracking jobs.
+ optional bool is_active = 2;
+ // The time this timer last became active. Only valid if is_active is true.
+ optional int64 start_time_elapsed = 3;
+ // How many are currently running. Valid only if the device is_active is true.
+ optional int32 job_count = 4;
+ // All of the jobs that the Timer is currently tracking.
+ repeated JobStatusShortInfoProto running_jobs = 5;
+ }
+
+ message PackageStats {
+ option (.android.msg_privacy).dest = DEST_AUTOMATIC;
+
+ optional Package pkg = 1;
+
+ optional Timer timer = 2;
+
+ repeated TimingSession saved_sessions = 3;
+ }
+ repeated PackageStats package_stats = 4;
+ }
message StorageController {
option (.android.msg_privacy).dest = DEST_AUTOMATIC;
@@ -403,8 +490,10 @@ message StateControllerProto {
ContentObserverController content_observer = 4;
DeviceIdleJobsController device_idle = 5;
IdleController idle = 6;
+ QuotaController quota = 9;
StorageController storage = 7;
TimeController time = 8;
+ // Next tag: 10
}
}
@@ -603,11 +692,13 @@ message JobStatusDumpProto {
CONSTRAINT_CONNECTIVITY = 7;
CONSTRAINT_CONTENT_TRIGGER = 8;
CONSTRAINT_DEVICE_NOT_DOZING = 9;
+ CONSTRAINT_WITHIN_QUOTA = 10;
}
repeated Constraint required_constraints = 7;
repeated Constraint satisfied_constraints = 8;
repeated Constraint unsatisfied_constraints = 9;
optional bool is_doze_whitelisted = 10;
+ optional bool is_uid_active = 26;
message ImplicitConstraints {
// The device isn't Dozing or this job will be in the foreground. This
@@ -627,6 +718,7 @@ message JobStatusDumpProto {
TRACKING_IDLE = 3;
TRACKING_STORAGE = 4;
TRACKING_TIME = 5;
+ TRACKING_QUOTA = 6;
}
// Controllers that are currently tracking the job.
repeated TrackingController tracking_controllers = 11;
@@ -660,6 +752,7 @@ message JobStatusDumpProto {
NEVER = 4;
}
optional Bucket standby_bucket = 17;
+ optional bool is_exempted_from_app_standby = 27;
optional int64 enqueue_duration_ms = 18;
// Can be negative if the earliest runtime deadline has passed.
@@ -674,5 +767,5 @@ message JobStatusDumpProto {
optional int64 internal_flags = 24;
- // Next tag: 26
+ // Next tag: 28
}
diff --git a/core/res/res/layout/notification_material_reply_text.xml b/core/res/res/layout/notification_material_reply_text.xml
index 71632a206e3c..2b15dceeb469 100644
--- a/core/res/res/layout/notification_material_reply_text.xml
+++ b/core/res/res/layout/notification_material_reply_text.xml
@@ -39,7 +39,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/notification_content_margin_end"
android:visibility="gone"
- android:textAppearance="@style/TextAppearance.Material.Notification.Reply"
+ android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Reply"
android:singleLine="true" />
<TextView
@@ -48,7 +48,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/notification_content_margin_end"
android:visibility="gone"
- android:textAppearance="@style/TextAppearance.Material.Notification.Reply"
+ android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Reply"
android:singleLine="true" />
<LinearLayout
@@ -64,7 +64,7 @@
android:layout_weight="1"
android:layout_marginEnd="@dimen/notification_content_margin_end"
android:layout_gravity="center"
- android:textAppearance="@style/TextAppearance.Material.Notification.Reply"
+ android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Reply"
android:singleLine="true" />
<ProgressBar
android:id="@+id/notification_material_reply_progress"
diff --git a/core/res/res/layout/notification_template_ambient_header.xml b/core/res/res/layout/notification_template_ambient_header.xml
index c00acd5bfc60..be5d9b436b79 100644
--- a/core/res/res/layout/notification_template_ambient_header.xml
+++ b/core/res/res/layout/notification_template_ambient_header.xml
@@ -24,5 +24,5 @@
android:layout_height="wrap_content">
<include
layout="@layout/notification_template_header"
- android:theme="@style/Theme.Material.Notification.Ambient"/>
+ android:theme="@style/Theme.DeviceDefault.Notification.Ambient"/>
</FrameLayout>
diff --git a/core/res/res/layout/notification_template_header.xml b/core/res/res/layout/notification_template_header.xml
index 4bf1ad6651ee..5ba1cf259551 100644
--- a/core/res/res/layout/notification_template_header.xml
+++ b/core/res/res/layout/notification_template_header.xml
@@ -17,7 +17,7 @@
<!-- extends ViewGroup -->
<NotificationHeaderView
xmlns:android="http://schemas.android.com/apk/res/android"
- android:theme="@style/Theme.Material.Notification"
+ android:theme="@style/Theme.DeviceDefault.Notification"
android:id="@+id/notification_header"
android:orientation="horizontal"
android:layout_width="wrap_content"
diff --git a/core/res/res/layout/notification_template_material_ambient.xml b/core/res/res/layout/notification_template_material_ambient.xml
index c8864c2f829d..2c6064ea6243 100644
--- a/core/res/res/layout/notification_template_material_ambient.xml
+++ b/core/res/res/layout/notification_template_material_ambient.xml
@@ -24,7 +24,7 @@
android:paddingEnd="@dimen/notification_extra_margin_ambient"
>
<include layout="@layout/notification_template_ambient_header"
- android:theme="@style/Theme.Material.Notification.Ambient" />
+ android:theme="@style/Theme.DeviceDefault.Notification.Ambient" />
<LinearLayout
android:id="@+id/notification_action_list_margin_target"
@@ -51,8 +51,7 @@
android:orientation="vertical"
>
<TextView android:id="@+id/title"
- android:textAppearance="@style/TextAppearance.Material.Notification.Title"
- android:fontFamily="sans-serif"
+ android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center_horizontal"
@@ -65,7 +64,7 @@
<TextView android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="0dp"
- android:textAppearance="@style/TextAppearance.Material.Notification"
+ android:textAppearance="@style/TextAppearance.DeviceDefault.Notification"
android:singleLine="false"
android:layout_weight="1"
android:gravity="top|center_horizontal"
diff --git a/core/res/res/layout/notification_template_material_big_text.xml b/core/res/res/layout/notification_template_material_big_text.xml
index 26eb4e7b2c6c..d5ea96f6bc16 100644
--- a/core/res/res/layout/notification_template_material_big_text.xml
+++ b/core/res/res/layout/notification_template_material_big_text.xml
@@ -53,7 +53,7 @@
android:layout_marginTop="@dimen/notification_progress_margin_top"
android:layout_marginBottom="6dp"/>
<com.android.internal.widget.ImageFloatingTextView android:id="@+id/big_text"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/notification_text_margin_top"
diff --git a/core/res/res/layout/notification_template_material_inbox.xml b/core/res/res/layout/notification_template_material_inbox.xml
index d6f0e1df430e..eb8925819cd3 100644
--- a/core/res/res/layout/notification_template_material_inbox.xml
+++ b/core/res/res/layout/notification_template_material_inbox.xml
@@ -53,7 +53,7 @@
android:layout_marginTop="@dimen/notification_progress_margin_top"
android:layout_marginBottom="2dp"/>
<TextView android:id="@+id/inbox_text0"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:singleLine="true"
@@ -62,7 +62,7 @@
android:layout_weight="1"
/>
<TextView android:id="@+id/inbox_text1"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:singleLine="true"
@@ -71,7 +71,7 @@
android:layout_weight="1"
/>
<TextView android:id="@+id/inbox_text2"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:singleLine="true"
@@ -80,7 +80,7 @@
android:layout_weight="1"
/>
<TextView android:id="@+id/inbox_text3"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:singleLine="true"
@@ -89,7 +89,7 @@
android:layout_weight="1"
/>
<TextView android:id="@+id/inbox_text4"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:singleLine="true"
@@ -98,7 +98,7 @@
android:layout_weight="1"
/>
<TextView android:id="@+id/inbox_text5"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:singleLine="true"
@@ -107,7 +107,7 @@
android:layout_weight="1"
/>
<TextView android:id="@+id/inbox_text6"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:singleLine="true"
diff --git a/core/res/res/layout/notification_template_messaging_group.xml b/core/res/res/layout/notification_template_messaging_group.xml
index 0717d962d69f..483b479538a1 100644
--- a/core/res/res/layout/notification_template_messaging_group.xml
+++ b/core/res/res/layout/notification_template_messaging_group.xml
@@ -34,7 +34,7 @@
android:orientation="vertical">
<com.android.internal.widget.ImageFloatingTextView
android:id="@+id/message_name"
- style="@style/Widget.Material.Notification.MessagingName"
+ style="@style/Widget.DeviceDefault.Notification.MessagingName"
android:layout_width="wrap_content"
android:textAlignment="viewStart"
/>
diff --git a/core/res/res/layout/notification_template_messaging_text_message.xml b/core/res/res/layout/notification_template_messaging_text_message.xml
index 3611186e279b..26c081e1f3d7 100644
--- a/core/res/res/layout/notification_template_messaging_text_message.xml
+++ b/core/res/res/layout/notification_template_messaging_text_message.xml
@@ -18,5 +18,5 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/message_text"
android:textAlignment="viewStart"
- style="@style/Widget.Material.Notification.MessagingText"
+ style="@style/Widget.DeviceDefault.Notification.MessagingText"
/>
diff --git a/core/res/res/layout/notification_template_part_line1.xml b/core/res/res/layout/notification_template_part_line1.xml
index 6459bb8019b4..622f080653a4 100644
--- a/core/res/res/layout/notification_template_part_line1.xml
+++ b/core/res/res/layout/notification_template_part_line1.xml
@@ -22,7 +22,7 @@
android:orientation="horizontal"
>
<TextView android:id="@+id/title"
- android:textAppearance="@style/TextAppearance.Material.Notification.Title"
+ android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
@@ -31,7 +31,7 @@
android:textAlignment="viewStart"
/>
<TextView android:id="@+id/text_line_1"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end|bottom"
diff --git a/core/res/res/layout/notification_template_text.xml b/core/res/res/layout/notification_template_text.xml
index 3b27666ef6ff..01b14ae0592d 100644
--- a/core/res/res/layout/notification_template_text.xml
+++ b/core/res/res/layout/notification_template_text.xml
@@ -15,7 +15,7 @@
~ limitations under the License
-->
<com.android.internal.widget.ImageFloatingTextView xmlns:android="http://schemas.android.com/apk/res/android"
- style="@style/Widget.Material.Notification.Text"
+ style="@style/Widget.DeviceDefault.Notification.Text"
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/core/res/res/values/styles_device_defaults.xml b/core/res/res/values/styles_device_defaults.xml
index d722961981c5..c03d570001d6 100644
--- a/core/res/res/values/styles_device_defaults.xml
+++ b/core/res/res/values/styles_device_defaults.xml
@@ -113,6 +113,15 @@ easier.
<style name="Widget.DeviceDefault.ListView.White" parent="Widget.Material.ListView.White"/>
<style name="Widget.DeviceDefault.MediaRouteButton" parent="Widget.Material.MediaRouteButton" />
<style name="Widget.DeviceDefault.NumberPicker" parent="Widget.Material.NumberPicker"/>
+ <style name="Widget.DeviceDefault.Notification.Text" parent="Widget.Material.Notification.Text">
+ <item name="textAppearance">@style/TextAppearance.DeviceDefault.Notification</item>
+ </style>
+ <style name="Widget.DeviceDefault.Notification.MessagingText" parent="Widget.Material.Notification.MessagingText">
+ <item name="textAppearance">@style/TextAppearance.DeviceDefault.Notification</item>
+ </style>
+ <style name="Widget.DeviceDefault.Notification.MessagingName" parent="Widget.Material.Notification.MessagingName">
+ <item name="textAppearance">@style/TextAppearance.DeviceDefault.Notification.Title</item>
+ </style>
<style name="Widget.DeviceDefault.PreferenceFrameLayout" parent="Widget.Material.PreferenceFrameLayout"/>
<style name="Widget.DeviceDefault.ProgressBar.Inverse" parent="Widget.Material.ProgressBar.Inverse"/>
<style name="Widget.DeviceDefault.ProgressBar.Large.Inverse" parent="Widget.Material.ProgressBar.Large.Inverse"/>
@@ -250,6 +259,16 @@ easier.
<style name="TextAppearance.DeviceDefault.Widget.ActionBar.Title" parent="TextAppearance.Material.Widget.ActionBar.Title">
<item name="fontFamily">@string/config_headlineFontFamilyMedium</item>
</style>
+
+ <!-- Notification Styles -->
+ <style name="TextAppearance.DeviceDefault.Notification" parent="TextAppearance.Material.Notification">
+ <item name="fontFamily">@string/config_headlineFontFamily</item>
+ </style>
+ <style name="TextAppearance.DeviceDefault.Notification.Title" parent="TextAppearance.Material.Notification.Title">
+ <item name="fontFamily">@string/config_headlineFontFamilyMedium</item>
+ </style>
+ <style name="TextAppearance.DeviceDefault.Notification.Reply" parent="TextAppearance.Material.Notification.Reply" />
+
<style name="TextAppearance.DeviceDefault.Widget.ActionBar.Subtitle" parent="TextAppearance.Material.Widget.ActionBar.Subtitle"/>
<style name="TextAppearance.DeviceDefault.Widget.ActionMode.Title" parent="TextAppearance.Material.Widget.ActionMode.Title"/>
<style name="TextAppearance.DeviceDefault.Widget.ActionMode.Subtitle" parent="TextAppearance.Material.Widget.ActionMode.Subtitle"/>
diff --git a/core/res/res/values/styles_material.xml b/core/res/res/values/styles_material.xml
index 67b3c92e69db..5a7199d6f445 100644
--- a/core/res/res/values/styles_material.xml
+++ b/core/res/res/values/styles_material.xml
@@ -1313,4 +1313,5 @@ please see styles_device_defaults.xml.
<item name="gravity">top|center_horizontal</item>
</style>
+
</resources>
diff --git a/core/res/res/values/themes_device_defaults.xml b/core/res/res/values/themes_device_defaults.xml
index fa009bd60c72..fec101a6fff3 100644
--- a/core/res/res/values/themes_device_defaults.xml
+++ b/core/res/res/values/themes_device_defaults.xml
@@ -1724,4 +1724,10 @@ easier.
<item name="layout_gravity">center</item>
</style>
+ <style name="Theme.DeviceDefault.Notification" parent="@style/Theme.Material.Notification">
+ </style>
+
+ <style name="Theme.DeviceDefault.Notification.Ambient" parent="@style/Theme.Material.Notification.Ambient">
+ </style>
+
</resources>
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
index fbcb629f043f..aec4571252e7 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
@@ -373,7 +373,7 @@ public class TextClassifierTest {
public void testSuggestConversationActions_textReplyOnly_maxThree() {
if (isTextClassifierDisabled()) return;
ConversationActions.Message message =
- new ConversationActions.Message.Builder().setText("Hello").build();
+ new ConversationActions.Message.Builder().setText("Where are you?").build();
ConversationActions.TypeConfig typeConfig =
new ConversationActions.TypeConfig.Builder().includeTypesFromTextClassifier(false)
.setIncludedTypes(
diff --git a/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java b/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java
index 02a76f8f78af..e2618191235d 100644
--- a/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java
@@ -528,22 +528,6 @@ public class BinderCallsStatsTest {
}
@Test
- public void testCallingUidUsedWhenWorkSourceNotSet() {
- TestBinderCallsStats bcs = new TestBinderCallsStats();
- bcs.setDetailedTracking(true);
- bcs.workSourceUid = -1;
-
- Binder binder = new Binder();
- CallSession callSession = bcs.callStarted(binder, 1);
- bcs.callEnded(callSession, REQUEST_SIZE, REPLY_SIZE);
-
- assertEquals(1, bcs.getExportedCallStats().size());
- BinderCallsStats.ExportedCallStat stat = bcs.getExportedCallStats().get(0);
- assertEquals(CALLING_UID, stat.workSourceUid);
- assertEquals(CALLING_UID, stat.callingUid);
- }
-
- @Test
public void testGetExportedStatsWithoutCalls() {
TestBinderCallsStats bcs = new TestBinderCallsStats();
Binder binder = new Binder();
@@ -623,15 +607,15 @@ public class BinderCallsStatsTest {
BinderCallsStats.ExportedCallStat debugEntry1 = callStats.get(0);
assertEquals("", debugEntry1.className);
assertEquals("__DEBUG_start_time_millis", debugEntry1.methodName);
- assertTrue(startTime <= debugEntry1.maxReplySizeBytes);
+ assertTrue(startTime <= debugEntry1.latencyMicros);
BinderCallsStats.ExportedCallStat debugEntry2 = callStats.get(1);
assertEquals("", debugEntry2.className);
assertEquals("__DEBUG_end_time_millis", debugEntry2.methodName);
- assertTrue(debugEntry1.maxReplySizeBytes <= debugEntry2.maxReplySizeBytes);
+ assertTrue(debugEntry1.latencyMicros <= debugEntry2.latencyMicros);
BinderCallsStats.ExportedCallStat debugEntry3 = callStats.get(2);
assertEquals("", debugEntry3.className);
assertEquals("__DEBUG_battery_time_millis", debugEntry3.methodName);
- assertTrue(debugEntry3.maxReplySizeBytes >= 0);
+ assertTrue(debugEntry3.latencyMicros >= 0);
}
class TestBinderCallsStats extends BinderCallsStats {
diff --git a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java
index 3d7801cbb531..f26dfad0b037 100644
--- a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java
+++ b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java
@@ -442,15 +442,15 @@ public final class LooperStatsTest {
LooperStats.ExportedEntry debugEntry1 = entries.get(1);
assertThat(debugEntry1.handlerClassName).isEqualTo("");
assertThat(debugEntry1.messageName).isEqualTo("__DEBUG_start_time_millis");
- assertThat(debugEntry1.maxDelayMillis).isEqualTo(looperStats.getStartTimeMillis());
+ assertThat(debugEntry1.totalLatencyMicros).isEqualTo(looperStats.getStartTimeMillis());
LooperStats.ExportedEntry debugEntry2 = entries.get(2);
assertThat(debugEntry2.handlerClassName).isEqualTo("");
assertThat(debugEntry2.messageName).isEqualTo("__DEBUG_end_time_millis");
- assertThat(debugEntry2.maxDelayMillis).isAtLeast(looperStats.getStartTimeMillis());
+ assertThat(debugEntry2.totalLatencyMicros).isAtLeast(looperStats.getStartTimeMillis());
LooperStats.ExportedEntry debugEntry3 = entries.get(3);
assertThat(debugEntry3.handlerClassName).isEqualTo("");
assertThat(debugEntry3.messageName).isEqualTo("__DEBUG_battery_time_millis");
- assertThat(debugEntry3.maxDelayMillis).isAtLeast(0L);
+ assertThat(debugEntry3.totalLatencyMicros).isAtLeast(0L);
}
private static void assertThrows(Class<? extends Exception> exceptionClass, Runnable r) {
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp
index da77b99e6e53..ed7d5e578693 100644
--- a/libs/hwui/Android.bp
+++ b/libs/hwui/Android.bp
@@ -171,6 +171,7 @@ cc_defaults {
"pipeline/skia/SkiaRecordingCanvas.cpp",
"pipeline/skia/SkiaVulkanPipeline.cpp",
"pipeline/skia/VectorDrawableAtlas.cpp",
+ "pipeline/skia/VkFunctorDrawable.cpp",
"pipeline/skia/VkInteropFunctorDrawable.cpp",
"renderstate/RenderState.cpp",
"renderthread/CacheManager.cpp",
diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp
index 4a639102192f..00ce28ad196f 100644
--- a/libs/hwui/RenderNode.cpp
+++ b/libs/hwui/RenderNode.cpp
@@ -454,6 +454,9 @@ const SkPath* RenderNode::getClippedOutline(const SkRect& clipRect) const {
using StringBuffer = FatVector<char, 128>;
template <typename... T>
+// TODO:__printflike(2, 3)
+// Doesn't work because the warning doesn't understand string_view and doesn't like that
+// it's not a C-style variadic function.
static void format(StringBuffer& buffer, const std::string_view& format, T... args) {
buffer.resize(buffer.capacity());
while (1) {
@@ -468,19 +471,20 @@ static void format(StringBuffer& buffer, const std::string_view& format, T... ar
buffer.resize(needed + 1);
return;
}
- buffer.resize(buffer.size() * 2);
+ // If we're doing a heap alloc anyway might as well give it some slop
+ buffer.resize(needed + 100);
}
}
void RenderNode::markDrawStart(SkCanvas& canvas) {
StringBuffer buffer;
- format(buffer, "RenderNode(id=%d, name='%s')", uniqueId(), getName());
+ format(buffer, "RenderNode(id=%" PRId64 ", name='%s')", uniqueId(), getName());
canvas.drawAnnotation(SkRect::MakeWH(getWidth(), getHeight()), buffer.data(), nullptr);
}
void RenderNode::markDrawEnd(SkCanvas& canvas) {
StringBuffer buffer;
- format(buffer, "/RenderNode(id=%d, name='%s')", uniqueId(), getName());
+ format(buffer, "/RenderNode(id=%" PRId64 ", name='%s')", uniqueId(), getName());
canvas.drawAnnotation(SkRect::MakeWH(getWidth(), getHeight()), buffer.data(), nullptr);
}
diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
index b682ab0256dd..b56c3ef94791 100644
--- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
+++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
@@ -25,6 +25,7 @@
#include "pipeline/skia/AnimatedDrawables.h"
#include "pipeline/skia/GLFunctorDrawable.h"
#include "pipeline/skia/VkInteropFunctorDrawable.h"
+#include "pipeline/skia/VkFunctorDrawable.h"
namespace android {
namespace uirenderer {
@@ -124,6 +125,8 @@ void SkiaRecordingCanvas::callDrawGLFunction(Functor* functor,
uirenderer::GlFunctorLifecycleListener* listener) {
FunctorDrawable* functorDrawable;
if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) {
+ // TODO(cblume) use VkFunctorDrawable instead of VkInteropFunctorDrawable here when the
+ // interop is disabled/moved.
functorDrawable = mDisplayList->allocateDrawable<VkInteropFunctorDrawable>(functor,
listener, asSkCanvas());
} else {
diff --git a/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp
new file mode 100644
index 000000000000..71ad5e17301a
--- /dev/null
+++ b/libs/hwui/pipeline/skia/VkFunctorDrawable.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "VkFunctorDrawable.h"
+#include <private/hwui/DrawVkInfo.h>
+
+#include "thread/ThreadBase.h"
+#include "utils/TimeUtils.h"
+#include <GrBackendDrawableInfo.h>
+#include <thread>
+#include <utils/Color.h>
+#include <utils/Trace.h>
+#include <utils/TraceUtils.h>
+#include <SkImage.h>
+#include <vk/GrVkTypes.h>
+
+namespace android {
+namespace uirenderer {
+namespace skiapipeline {
+
+VkFunctorDrawHandler::VkFunctorDrawHandler(Functor *functor)
+ : INHERITED()
+ , mFunctor(functor) {}
+
+VkFunctorDrawHandler::~VkFunctorDrawHandler() {
+ // TODO(cblume) Fill in the DrawVkInfo parameters.
+ (*mFunctor)(DrawVkInfo::kModePostComposite, nullptr);
+}
+
+void VkFunctorDrawHandler::draw(const GrBackendDrawableInfo& info) {
+ ATRACE_CALL();
+
+ GrVkDrawableInfo vulkan_info;
+ if (!info.getVkDrawableInfo(&vulkan_info)) {
+ return;
+ }
+
+ DrawVkInfo draw_vk_info;
+ // TODO(cblume) Fill in the rest of the parameters and test the actual call.
+ draw_vk_info.isLayer = true;
+
+ (*mFunctor)(DrawVkInfo::kModeComposite, &draw_vk_info);
+}
+
+VkFunctorDrawable::VkFunctorDrawable(Functor* functor, GlFunctorLifecycleListener* listener,
+ SkCanvas* canvas)
+ : FunctorDrawable(functor, listener, canvas) {}
+
+VkFunctorDrawable::~VkFunctorDrawable() = default;
+
+void VkFunctorDrawable::syncFunctor() const {
+ (*mFunctor)(DrawVkInfo::kModeSync, nullptr);
+}
+
+void VkFunctorDrawable::onDraw(SkCanvas* /*canvas*/) {
+ LOG_ALWAYS_FATAL("VkFunctorDrawable::onDraw() should never be called.");
+ // Instead of calling onDraw(), the call should come from onSnapGpuDrawHandler.
+}
+
+std::unique_ptr<FunctorDrawable::GpuDrawHandler> VkFunctorDrawable::onSnapGpuDrawHandler(
+ GrBackendApi backendApi, const SkMatrix& matrix) {
+ if (backendApi != GrBackendApi::kVulkan) {
+ return nullptr;
+ }
+ std::unique_ptr<VkFunctorDrawHandler> draw(new VkFunctorDrawHandler(mFunctor));
+ return std::move(draw);
+}
+
+} // namespace skiapipeline
+} // namespace uirenderer
+} // namespace android
diff --git a/libs/hwui/pipeline/skia/VkFunctorDrawable.h b/libs/hwui/pipeline/skia/VkFunctorDrawable.h
new file mode 100644
index 000000000000..5cd131405d15
--- /dev/null
+++ b/libs/hwui/pipeline/skia/VkFunctorDrawable.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#pragma once
+
+#include "FunctorDrawable.h"
+
+#include <utils/RefBase.h>
+#include <ui/GraphicBuffer.h>
+#include <SkImageInfo.h>
+
+namespace android {
+namespace uirenderer {
+namespace skiapipeline {
+
+/**
+ * This draw handler will be returned by VkFunctorDrawable's onSnapGpuDrawHandler. It allows us to
+ * issue Vulkan commands while the command buffer is being flushed.
+ */
+class VkFunctorDrawHandler : public FunctorDrawable::GpuDrawHandler {
+public:
+ explicit VkFunctorDrawHandler(Functor* functor);
+ ~VkFunctorDrawHandler() override;
+
+ void draw(const GrBackendDrawableInfo& info) override;
+private:
+ typedef GpuDrawHandler INHERITED;
+
+ Functor* mFunctor;
+};
+
+/**
+ * This drawable wraps a Vulkan functor enabling it to be recorded into a list of Skia drawing
+ * commands.
+ */
+class VkFunctorDrawable : public FunctorDrawable {
+public:
+ VkFunctorDrawable(Functor* functor, GlFunctorLifecycleListener* listener,
+ SkCanvas* canvas);
+ ~VkFunctorDrawable() override;
+
+ void syncFunctor() const override;
+
+protected:
+ // SkDrawable functions:
+ void onDraw(SkCanvas* canvas) override;
+ std::unique_ptr<FunctorDrawable::GpuDrawHandler> onSnapGpuDrawHandler(GrBackendApi backendApi,
+ const SkMatrix& matrix) override;
+};
+
+} // namespace skiapipeline
+} // namespace uirenderer
+} // namespace android
diff --git a/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp b/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp
index 004a558dd9d0..82285501cb63 100644
--- a/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp
+++ b/libs/hwui/pipeline/skia/VkInteropFunctorDrawable.cpp
@@ -46,7 +46,7 @@ public:
ScopedDrawRequest() { beginDraw(); }
private:
void beginDraw() {
- std::lock_guard{sLock};
+ std::lock_guard _lock{sLock};
if (!sGLDrawThread) {
sGLDrawThread = new ThreadBase{};
diff --git a/libs/hwui/private/hwui/DrawVkInfo.h b/libs/hwui/private/hwui/DrawVkInfo.h
new file mode 100644
index 000000000000..019950fcbc02
--- /dev/null
+++ b/libs/hwui/private/hwui/DrawVkInfo.h
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#ifndef ANDROID_HWUI_DRAW_VK_INFO_H
+#define ANDROID_HWUI_DRAW_VK_INFO_H
+
+#include <vulkan/vulkan.h>
+
+namespace android {
+namespace uirenderer {
+
+/**
+ * Structure used by VulkanRenderer::callDrawVKFunction() to pass and receive data from Vulkan
+ * functors.
+ */
+struct DrawVkInfo {
+ // Input: current width/height of destination surface
+ int width;
+ int height;
+
+ // Input: is the render target an FBO
+ bool isLayer;
+
+ // Input: current transform matrix, in OpenGL format
+ float transform[16];
+
+ // Input: WebView should do its main compositing draws into this. It cannot do anything that
+ // would require stopping the render pass.
+ VkCommandBuffer secondaryCommandBuffer;
+
+ // Input: The main color attachment index where secondaryCommandBuffer will eventually be
+ // submitted.
+ uint32_t colorAttachmentIndex;
+
+ // Input: A render pass which will be compatible to the one which the secondaryCommandBuffer
+ // will be submitted into.
+ VkRenderPass compatibleRenderPass;
+
+ // Input: Format of the destination surface.
+ VkFormat format;
+
+ // Input: Color space transfer params
+ float G;
+ float A;
+ float B;
+ float C;
+ float D;
+ float E;
+ float F;
+
+ // Input: Color space transformation from linear RGB to D50-adapted XYZ
+ float matrix[9];
+
+ // Input: current clip rect
+ int clipLeft;
+ int clipTop;
+ int clipRight;
+ int clipBottom;
+
+ /**
+ * Values used as the "what" parameter of the functor.
+ */
+ enum Mode {
+ // Called once at WebView start
+ kModeInit,
+ // Called when things need to be re-created
+ kModeReInit,
+ // Notifies the app that the composite functor will be called soon. This allows WebView to
+ // begin work early.
+ kModePreComposite,
+ // Do the actual composite work
+ kModeComposite,
+ // This allows WebView to begin using the previously submitted objects in future work.
+ kModePostComposite,
+ // Invoked every time the UI thread pushes over a frame to the render thread and the owning
+ // view has a dirty display list*. This is a signal to sync any data that needs to be
+ // shared between the UI thread and the render thread. During this time the UI thread is
+ // blocked.
+ kModeSync
+ };
+
+ /**
+ * Values used by Vulkan functors to tell the framework what to do next.
+ */
+ enum Status {
+ // The functor is done
+ kStatusDone = 0x0,
+ };
+}; // struct DrawVkInfo
+
+} // namespace uirenderer
+} // namespace android
+
+#endif // ANDROID_HWUI_DRAW_VK_INFO_H
diff --git a/media/java/android/media/CallbackDataSourceDesc.java b/media/java/android/media/CallbackDataSourceDesc.java
index 0e8e6ceeaa15..cb9669bb653d 100644
--- a/media/java/android/media/CallbackDataSourceDesc.java
+++ b/media/java/android/media/CallbackDataSourceDesc.java
@@ -19,7 +19,6 @@ package android.media;
import android.annotation.NonNull;
/**
- * @hide
* Structure of data source descriptor for sources using callback.
*
* Used by {@link MediaPlayer2#setDataSource(DataSourceDesc)},
diff --git a/media/java/android/media/DataSourceCallback.java b/media/java/android/media/DataSourceCallback.java
index 9b27baf32204..0d4d53106c78 100644
--- a/media/java/android/media/DataSourceCallback.java
+++ b/media/java/android/media/DataSourceCallback.java
@@ -21,7 +21,6 @@ import java.io.Closeable;
import java.io.IOException;
/**
- * @hide
* For supplying media data to the framework. Implement this if your app has
* special requirements for the way media data is obtained.
*
diff --git a/media/java/android/media/DataSourceDesc.java b/media/java/android/media/DataSourceDesc.java
index 702034e987ca..9109ea5bdab2 100644
--- a/media/java/android/media/DataSourceDesc.java
+++ b/media/java/android/media/DataSourceDesc.java
@@ -19,7 +19,6 @@ package android.media;
import android.annotation.NonNull;
/**
- * @hide
* Base class of data source descriptor.
*
* Used by {@link MediaPlayer2#setDataSource(DataSourceDesc)},
@@ -36,6 +35,9 @@ public class DataSourceDesc {
// keep consistent with native code
public static final long LONG_MAX_TIME_MS = LONG_MAX / 1000;
+ /**
+ * @hide
+ */
public static final long LONG_MAX_TIME_US = LONG_MAX_TIME_MS * 1000;
public static final long POSITION_UNKNOWN = LONG_MAX_TIME_MS;
@@ -172,7 +174,8 @@ public class DataSourceDesc {
/**
* Sets the end position in milliseconds at which the playback will end.
- * Any negative number is treated as maximum length of the data source.
+ * Any negative number is treated as maximum duration {@link #LONG_MAX_TIME_MS}
+ * of the data source
*
* @param position the end position in milliseconds at which the playback will end
* @return the same Builder instance.
diff --git a/media/java/android/media/FileDataSourceDesc.java b/media/java/android/media/FileDataSourceDesc.java
index 763a81f53765..14ef18029233 100644
--- a/media/java/android/media/FileDataSourceDesc.java
+++ b/media/java/android/media/FileDataSourceDesc.java
@@ -23,7 +23,6 @@ import android.util.Log;
import java.io.IOException;
/**
- * @hide
* Structure of data source descriptor for sources using file descriptor.
*
* Used by {@link MediaPlayer2#setDataSource(DataSourceDesc)},
diff --git a/media/java/android/media/MediaPlayer2.java b/media/java/android/media/MediaPlayer2.java
index a10b2123a70c..e6ad4441401a 100644
--- a/media/java/android/media/MediaPlayer2.java
+++ b/media/java/android/media/MediaPlayer2.java
@@ -21,9 +21,6 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
-import android.annotation.UnsupportedAppUsage;
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
@@ -81,8 +78,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
/**
- * @hide
- *
* MediaPlayer2 class can be used to control playback of audio/video files and streams.
*
* <p>Topics covered here are:
@@ -776,7 +771,7 @@ public class MediaPlayer2 implements AutoCloseable
*
* @return the current DataSourceDesc
*/
- public DataSourceDesc getCurrentDataSource() {
+ public @Nullable DataSourceDesc getCurrentDataSource() {
synchronized (mSrcLock) {
return mCurrentSourceInfo == null ? null : mCurrentSourceInfo.mDSD;
}
@@ -1252,19 +1247,18 @@ public class MediaPlayer2 implements AutoCloseable
*
* <p>This function has the MediaPlayer2 access the low-level power manager
* service to control the device's power usage while playing is occurring.
- * The parameter is a combination of {@link android.os.PowerManager} wake flags.
+ * The parameter is a {@link android.os.PowerManager.WakeLock}.
* Use of this method requires {@link android.Manifest.permission#WAKE_LOCK}
* permission.
* By default, no attempt is made to keep the device awake during playback.
*
- * @param context the Context to use
- * @param mode the power/wake mode to set
+ * @param wakeLock the power wake lock used during playback.
* @return a token which can be used to cancel the operation later with {@link #cancelCommand}.
* @see android.os.PowerManager
*/
// This is an asynchronous call.
- public Object setWakeMode(Context context, int mode) {
- return addTask(new Task(CALL_COMPLETED_SET_WAKE_MODE, false) {
+ public Object setWakeLock(@NonNull PowerManager.WakeLock wakeLock) {
+ return addTask(new Task(CALL_COMPLETED_SET_WAKE_LOCK, false) {
@Override
void process() {
boolean washeld = false;
@@ -1274,28 +1268,15 @@ public class MediaPlayer2 implements AutoCloseable
washeld = true;
mWakeLock.release();
}
- mWakeLock = null;
}
- PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- ActivityManager am =
- (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- List<RunningAppProcessInfo> runningAppsProcInfo = am.getRunningAppProcesses();
- int pid = android.os.Process.myPid();
- String name = "pid " + String.valueOf(pid);
- if (runningAppsProcInfo != null) {
- for (RunningAppProcessInfo procInfo : runningAppsProcInfo) {
- if (procInfo.pid == pid) {
- name = procInfo.processName;
- break;
- }
+ mWakeLock = wakeLock;
+ if (mWakeLock != null) {
+ mWakeLock.setReferenceCounted(false);
+ if (washeld) {
+ mWakeLock.acquire();
}
}
- mWakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE, name);
- mWakeLock.setReferenceCounted(false);
- if (washeld) {
- mWakeLock.acquire();
- }
}
});
}
@@ -1303,7 +1284,7 @@ public class MediaPlayer2 implements AutoCloseable
/**
* Control whether we should use the attached SurfaceHolder to keep the
* screen on while video playback is occurring. This is the preferred
- * method over {@link #setWakeMode} where possible, since it doesn't
+ * method over {@link #setWakeLock} where possible, since it doesn't
* require that the application have permission for low-level wake lock
* access.
*
@@ -1350,9 +1331,13 @@ public class MediaPlayer2 implements AutoCloseable
*
* @param token the command to be canceled. This is the returned Object when command is issued.
* @return {@code false} if the task could not be cancelled; {@code true} otherwise.
+ * @throws IllegalArgumentException if argument token is null.
*/
// This is a synchronous call.
- public boolean cancelCommand(Object token) {
+ public boolean cancelCommand(@NonNull Object token) {
+ if (token == null) {
+ throw new IllegalArgumentException("command token should not be null");
+ }
synchronized (mTaskLock) {
return mPendingTasks.remove(token);
}
@@ -1891,7 +1876,6 @@ public class MediaPlayer2 implements AutoCloseable
* Gets the track type.
* @return TrackType which indicates if the track is video, audio, timed text.
*/
- @UnsupportedAppUsage
public int getTrackType() {
return mTrackType;
}
@@ -1902,7 +1886,6 @@ public class MediaPlayer2 implements AutoCloseable
* When the language is unknown or could not be determined,
* ISO-639-2 language code, "und", is returned.
*/
- @UnsupportedAppUsage
public String getLanguage() {
String language = mFormat.getString(MediaFormat.KEY_LANGUAGE);
return language == null ? "und" : language;
@@ -1933,19 +1916,20 @@ public class MediaPlayer2 implements AutoCloseable
final int mTrackType;
final MediaFormat mFormat;
- TrackInfo(Iterator<Value> in) {
- mTrackType = in.next().getInt32Value();
+ static TrackInfo create(Iterator<Value> in) {
+ int trackType = in.next().getInt32Value();
// TODO: build the full MediaFormat; currently we are using createSubtitleFormat
// even for audio/video tracks, meaning we only set the mime and language.
String mime = in.next().getStringValue();
String language = in.next().getStringValue();
- mFormat = MediaFormat.createSubtitleFormat(mime, language);
+ MediaFormat format = MediaFormat.createSubtitleFormat(mime, language);
- if (mTrackType == MEDIA_TRACK_TYPE_SUBTITLE) {
- mFormat.setInteger(MediaFormat.KEY_IS_AUTOSELECT, in.next().getInt32Value());
- mFormat.setInteger(MediaFormat.KEY_IS_DEFAULT, in.next().getInt32Value());
- mFormat.setInteger(MediaFormat.KEY_IS_FORCED_SUBTITLE, in.next().getInt32Value());
+ if (trackType == MEDIA_TRACK_TYPE_SUBTITLE) {
+ format.setInteger(MediaFormat.KEY_IS_AUTOSELECT, in.next().getInt32Value());
+ format.setInteger(MediaFormat.KEY_IS_DEFAULT, in.next().getInt32Value());
+ format.setInteger(MediaFormat.KEY_IS_FORCED_SUBTITLE, in.next().getInt32Value());
}
+ return new TrackInfo(trackType, format);
}
/** @hide */
@@ -1990,9 +1974,9 @@ public class MediaPlayer2 implements AutoCloseable
* addTimedTextSource method is called.
* @throws IllegalStateException if it is called in an invalid state.
*/
- public List<TrackInfo> getTrackInfo() {
+ public @NonNull List<TrackInfo> getTrackInfo() {
TrackInfo[] trackInfo = getInbandTrackInfo();
- return Arrays.asList(trackInfo);
+ return (trackInfo != null ? Arrays.asList(trackInfo) : new ArrayList<TrackInfo>(0));
}
private TrackInfo[] getInbandTrackInfo() throws IllegalStateException {
@@ -2010,7 +1994,7 @@ public class MediaPlayer2 implements AutoCloseable
}
TrackInfo[] trackInfo = new TrackInfo[size];
for (int i = 0; i < size; ++i) {
- trackInfo[i] = new TrackInfo(in);
+ trackInfo[i] = TrackInfo.create(in);
}
return trackInfo;
}
@@ -2505,7 +2489,7 @@ public class MediaPlayer2 implements AutoCloseable
Log.w(TAG, "MEDIA_DRM_INFO failed to parse msg.obj " + obj);
break;
}
- DrmInfo drmInfo = new DrmInfo(playerMsg);
+ DrmInfo drmInfo = DrmInfo.create(playerMsg);
synchronized (sourceInfo) {
sourceInfo.mDrmInfo = drmInfo;
}
@@ -2556,7 +2540,7 @@ public class MediaPlayer2 implements AutoCloseable
* @param size the size of the video
*/
public void onVideoSizeChanged(
- MediaPlayer2 mp, DataSourceDesc dsd, VideoSize size) { }
+ @NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd, @NonNull VideoSize size) { }
/**
* Called to indicate an avaliable timed text
@@ -2567,7 +2551,8 @@ public class MediaPlayer2 implements AutoCloseable
* needed to be displayed and the display format.
* @hide
*/
- public void onTimedText(MediaPlayer2 mp, DataSourceDesc dsd, TimedText text) { }
+ public void onTimedText(
+ @NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd, @NonNull TimedText text) { }
/**
* Called to indicate avaliable timed metadata
@@ -2588,7 +2573,8 @@ public class MediaPlayer2 implements AutoCloseable
* @param data the timed metadata sample associated with this event
*/
public void onTimedMetaDataAvailable(
- MediaPlayer2 mp, DataSourceDesc dsd, TimedMetaData data) { }
+ @NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd,
+ @NonNull TimedMetaData data) { }
/**
* Called to indicate an error.
@@ -2600,7 +2586,8 @@ public class MediaPlayer2 implements AutoCloseable
* implementation dependent.
*/
public void onError(
- MediaPlayer2 mp, DataSourceDesc dsd, @MediaError int what, int extra) { }
+ @NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd,
+ @MediaError int what, int extra) { }
/**
* Called to indicate an info or a warning.
@@ -2611,7 +2598,9 @@ public class MediaPlayer2 implements AutoCloseable
* @param extra an extra code, specific to the info. Typically
* implementation dependent.
*/
- public void onInfo(MediaPlayer2 mp, DataSourceDesc dsd, @MediaInfo int what, int extra) { }
+ public void onInfo(
+ @NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd,
+ @MediaInfo int what, int extra) { }
/**
* Called to acknowledge an API call.
@@ -2622,7 +2611,7 @@ public class MediaPlayer2 implements AutoCloseable
* @param status the returned status code for the call.
*/
public void onCallCompleted(
- MediaPlayer2 mp, DataSourceDesc dsd, @CallCompleted int what,
+ @NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd, @CallCompleted int what,
@CallStatus int status) { }
/**
@@ -2633,7 +2622,8 @@ public class MediaPlayer2 implements AutoCloseable
* @param timestamp the new media clock.
*/
public void onMediaTimeDiscontinuity(
- MediaPlayer2 mp, DataSourceDesc dsd, MediaTimestamp timestamp) { }
+ @NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd,
+ @NonNull MediaTimestamp timestamp) { }
/**
* Called to indicate {@link #notifyWhenCommandLabelReached(Object)} has been processed.
@@ -2642,7 +2632,7 @@ public class MediaPlayer2 implements AutoCloseable
* @param label the application specific Object given by
* {@link #notifyWhenCommandLabelReached(Object)}.
*/
- public void onCommandLabelReached(MediaPlayer2 mp, @NonNull Object label) { }
+ public void onCommandLabelReached(@NonNull MediaPlayer2 mp, @NonNull Object label) { }
/**
* Called when when a player subtitle track has new subtitle data available.
@@ -2651,7 +2641,8 @@ public class MediaPlayer2 implements AutoCloseable
* @param data the subtitle data
*/
public void onSubtitleData(
- MediaPlayer2 mp, DataSourceDesc dsd, @NonNull SubtitleData data) { }
+ @NonNull MediaPlayer2 mp, @NonNull DataSourceDesc dsd,
+ @NonNull SubtitleData data) { }
}
private final Object mEventCbLock = new Object();
@@ -3046,10 +3037,10 @@ public class MediaPlayer2 implements AutoCloseable
*/
public static final int CALL_COMPLETED_SET_DISPLAY = 33;
- /** The player just completed a call {@link #setWakeMode}.
+ /** The player just completed a call {@link #setWakeLock}.
* @see EventCallback#onCallCompleted
*/
- public static final int CALL_COMPLETED_SET_WAKE_MODE = 34;
+ public static final int CALL_COMPLETED_SET_WAKE_LOCK = 34;
/** The player just completed a call {@link #setScreenOnWhilePlaying}.
* @see EventCallback#onCallCompleted
@@ -3102,7 +3093,7 @@ public class MediaPlayer2 implements AutoCloseable
CALL_COMPLETED_CLEAR_NEXT_DATA_SOURCES,
CALL_COMPLETED_SET_BUFFERING_PARAMS,
CALL_COMPLETED_SET_DISPLAY,
- CALL_COMPLETED_SET_WAKE_MODE,
+ CALL_COMPLETED_SET_WAKE_LOCK,
CALL_COMPLETED_SET_SCREEN_ON_WHILE_PLAYING,
CALL_COMPLETED_NOTIFY_WHEN_COMMAND_LABEL_REACHED,
CALL_COMPLETED_PREPARE_DRM,
@@ -3179,6 +3170,7 @@ public class MediaPlayer2 implements AutoCloseable
* The only allowed DRM calls in this listener are
* {@link MediaPlayer2#getDrmPropertyString(DataSourceDesc, String)}
* and {@link MediaPlayer2#setDrmPropertyString(DataSourceDesc, String, String)}.
+ * @hide
*/
public interface OnDrmConfigHelper {
/**
@@ -3197,6 +3189,7 @@ public class MediaPlayer2 implements AutoCloseable
* of {@link #prepareDrm(DataSourceDesc, UUID)}.
*
* @param listener the callback that will be run
+ * @hide
*/
// This is a synchronous call.
public void setOnDrmConfigHelper(OnDrmConfigHelper listener) {
@@ -3208,6 +3201,7 @@ public class MediaPlayer2 implements AutoCloseable
/**
* Interface definition for callbacks to be invoked when the player has the corresponding
* DRM events.
+ * @hide
*/
public static class DrmEventCallback {
/**
@@ -3241,6 +3235,7 @@ public class MediaPlayer2 implements AutoCloseable
*
* @param eventCallback the callback that will be run
* @param executor the executor through which the callback should be invoked
+ * @hide
*/
// This is a synchronous call.
public void registerDrmEventCallback(@NonNull @CallbackExecutor Executor executor,
@@ -3261,6 +3256,7 @@ public class MediaPlayer2 implements AutoCloseable
* Unregisters the {@link DrmEventCallback}.
*
* @param eventCallback the callback to be unregistered
+ * @hide
*/
// This is a synchronous call.
public void unregisterDrmEventCallback(DrmEventCallback eventCallback) {
@@ -3278,31 +3274,37 @@ public class MediaPlayer2 implements AutoCloseable
* <p>
*
* DRM preparation has succeeded.
+ * @hide
*/
public static final int PREPARE_DRM_STATUS_SUCCESS = 0;
/**
* The device required DRM provisioning but couldn't reach the provisioning server.
+ * @hide
*/
public static final int PREPARE_DRM_STATUS_PROVISIONING_NETWORK_ERROR = 1;
/**
* The device required DRM provisioning but the provisioning server denied the request.
+ * @hide
*/
public static final int PREPARE_DRM_STATUS_PROVISIONING_SERVER_ERROR = 2;
/**
* The DRM preparation has failed .
+ * @hide
*/
public static final int PREPARE_DRM_STATUS_PREPARATION_ERROR = 3;
/**
* The crypto scheme UUID is not supported by the device.
+ * @hide
*/
public static final int PREPARE_DRM_STATUS_UNSUPPORTED_SCHEME = 4;
/**
* The hardware resources are not available, due to being in use.
+ * @hide
*/
public static final int PREPARE_DRM_STATUS_RESOURCE_BUSY = 5;
@@ -3343,6 +3345,7 @@ public class MediaPlayer2 implements AutoCloseable
* @param dsd The DRM protected data source
*
* @throws IllegalStateException if called before being prepared
+ * @hide
*/
public DrmInfo getDrmInfo(@NonNull DataSourceDesc dsd) {
final SourceInfo sourceInfo = getSourceInfo(dsd);
@@ -3398,6 +3401,7 @@ public class MediaPlayer2 implements AutoCloseable
* {@link DrmEventCallback#onDrmInfo}.
*
* @return a token which can be used to cancel the operation later with {@link #cancelCommand}.
+ * @hide
*/
// This is an asynchronous call.
public Object prepareDrm(@NonNull DataSourceDesc dsd, @NonNull UUID uuid) {
@@ -3491,6 +3495,7 @@ public class MediaPlayer2 implements AutoCloseable
* @param dsd The DRM protected data source
*
* @throws NoDrmSchemeException if there is no active DRM session to release
+ * @hide
*/
// This is a synchronous call.
public void releaseDrm(@NonNull DataSourceDesc dsd)
@@ -3501,7 +3506,7 @@ public class MediaPlayer2 implements AutoCloseable
}
}
- private native void native_releaseDrm();
+ private native void native_releaseDrm(long mSrcId);
/**
* A key request/response exchange occurs between the app and a license server
@@ -3541,6 +3546,7 @@ public class MediaPlayer2 implements AutoCloseable
* This may be {@code null} if no additional parameters are to be sent.
*
* @throws NoDrmSchemeException if there is no active DRM session
+ * @hide
*/
public MediaDrm.KeyRequest getDrmKeyRequest(
@NonNull DataSourceDesc dsd,
@@ -3581,6 +3587,7 @@ public class MediaPlayer2 implements AutoCloseable
* @throws NoDrmSchemeException if there is no active DRM session
* @throws DeniedByServerException if the response indicates that the
* server rejected the request
+ * @hide
*/
// This is a synchronous call.
public byte[] provideDrmKeyResponse(
@@ -3606,6 +3613,7 @@ public class MediaPlayer2 implements AutoCloseable
* @param keySetId identifies the saved key set to restore
*
* @throws NoDrmSchemeException if there is no active DRM session
+ * @hide
*/
// This is a synchronous call.
public void restoreDrmKeys(
@@ -3633,6 +3641,7 @@ public class MediaPlayer2 implements AutoCloseable
* {@link MediaDrm#PROPERTY_DESCRIPTION}, {@link MediaDrm#PROPERTY_ALGORITHMS}
*
* @throws NoDrmSchemeException if there is no active DRM session
+ * @hide
*/
public String getDrmPropertyString(
@NonNull DataSourceDesc dsd,
@@ -3659,6 +3668,7 @@ public class MediaPlayer2 implements AutoCloseable
* {@link MediaDrm#PROPERTY_DESCRIPTION}, {@link MediaDrm#PROPERTY_ALGORITHMS}
*
* @throws NoDrmSchemeException if there is no active DRM session
+ * @hide
*/
// This is a synchronous call.
public void setDrmPropertyString(
@@ -3676,6 +3686,7 @@ public class MediaPlayer2 implements AutoCloseable
/**
* Encapsulates the DRM properties of the source.
+ * @hide
*/
public static final class DrmInfo {
private Map<UUID, byte[]> mMapPssh;
@@ -3702,36 +3713,37 @@ public class MediaPlayer2 implements AutoCloseable
mSupportedSchemes = supportedSchemes;
}
- private DrmInfo(PlayerMessage msg) {
- Log.v(TAG, "DrmInfo(" + msg + ")");
+ private static DrmInfo create(PlayerMessage msg) {
+ Log.v(TAG, "DrmInfo.create(" + msg + ")");
Iterator<Value> in = msg.getValuesList().iterator();
byte[] pssh = in.next().getBytesValue().toByteArray();
- Log.v(TAG, "DrmInfo() PSSH: " + arrToHex(pssh));
- mMapPssh = parsePSSH(pssh, pssh.length);
- Log.v(TAG, "DrmInfo() PSSH: " + mMapPssh);
+ Log.v(TAG, "DrmInfo.create() PSSH: " + DrmInfo.arrToHex(pssh));
+ Map<UUID, byte[]> mapPssh = DrmInfo.parsePSSH(pssh, pssh.length);
+ Log.v(TAG, "DrmInfo.create() PSSH: " + mapPssh);
int supportedDRMsCount = in.next().getInt32Value();
- mSupportedSchemes = new UUID[supportedDRMsCount];
+ UUID[] supportedSchemes = new UUID[supportedDRMsCount];
for (int i = 0; i < supportedDRMsCount; i++) {
byte[] uuid = new byte[16];
in.next().getBytesValue().copyTo(uuid, 0);
- mSupportedSchemes[i] = bytesToUUID(uuid);
+ supportedSchemes[i] = DrmInfo.bytesToUUID(uuid);
- Log.v(TAG, "DrmInfo() supportedScheme[" + i + "]: " + mSupportedSchemes[i]);
+ Log.v(TAG, "DrmInfo() supportedScheme[" + i + "]: " + supportedSchemes[i]);
}
- Log.v(TAG, "DrmInfo() psshsize: " + pssh.length
+ Log.v(TAG, "DrmInfo.create() psshsize: " + pssh.length
+ " supportedDRMsCount: " + supportedDRMsCount);
+ return new DrmInfo(mapPssh, supportedSchemes);
}
private DrmInfo makeCopy() {
return new DrmInfo(this.mMapPssh, this.mSupportedSchemes);
}
- private String arrToHex(byte[] bytes) {
+ private static String arrToHex(byte[] bytes) {
String out = "0x";
for (int i = 0; i < bytes.length; i++) {
out += String.format("%02x", bytes[i]);
@@ -3740,7 +3752,7 @@ public class MediaPlayer2 implements AutoCloseable
return out;
}
- private UUID bytesToUUID(byte[] uuid) {
+ private static UUID bytesToUUID(byte[] uuid) {
long msb = 0, lsb = 0;
for (int i = 0; i < 8; i++) {
msb |= (((long) uuid[i] & 0xff) << (8 * (7 - i)));
@@ -3750,7 +3762,7 @@ public class MediaPlayer2 implements AutoCloseable
return new UUID(msb, lsb);
}
- private Map<UUID, byte[]> parsePSSH(byte[] pssh, int psshsize) {
+ private static Map<UUID, byte[]> parsePSSH(byte[] pssh, int psshsize) {
Map<UUID, byte[]> result = new HashMap<UUID, byte[]>();
final int uuidSize = 16;
@@ -3814,6 +3826,7 @@ public class MediaPlayer2 implements AutoCloseable
* Thrown when a DRM method is called before preparing a DRM scheme through
* {@link MediaPlayer2#prepareDrm(DataSourceDesc, UUID)}.
* Extends MediaDrm.MediaDrmException
+ * @hide
*/
public static final class NoDrmSchemeException extends MediaDrmException {
public NoDrmSchemeException(String detailMessage) {
@@ -3821,7 +3834,8 @@ public class MediaPlayer2 implements AutoCloseable
}
}
- private native void native_prepareDrm(@NonNull byte[] uuid, @NonNull byte[] drmSessionId);
+ private native void native_prepareDrm(
+ long srcId, @NonNull byte[] uuid, @NonNull byte[] drmSessionId);
// Instantiated from the native side
@SuppressWarnings("unused")
@@ -4064,6 +4078,7 @@ public class MediaPlayer2 implements AutoCloseable
static final int PROVISION_TIMEOUT_MS = 60000;
final DataSourceDesc mDSD;
+ final long mSrcId;
//--- guarded by |this| start
MediaDrm mDrmObj;
@@ -4075,8 +4090,9 @@ public class MediaPlayer2 implements AutoCloseable
Future<?> mProvisionResult;
//--- guarded by |this| end
- DrmHandle(DataSourceDesc dsd) {
+ DrmHandle(DataSourceDesc dsd, long srcId) {
mDSD = dsd;
+ mSrcId = srcId;
}
void prepare(UUID uuid) throws UnsupportedSchemeException,
@@ -4186,7 +4202,8 @@ public class MediaPlayer2 implements AutoCloseable
// Sending it down to native/mediaserver to create the crypto object
// This call could simply fail due to bad player state, e.g., after play().
- MediaPlayer2.this.native_prepareDrm(getByteArrayFromUUID(uuid), mDrmSessionId);
+ final MediaPlayer2 mp2 = MediaPlayer2.this;
+ mp2.native_prepareDrm(mSrcId, getByteArrayFromUUID(uuid), mDrmSessionId);
Log.v(TAG, "prepareDrm_openSessionStep: native_prepareDrm/Crypto succeeded");
} catch (Exception e) { //ResourceBusyException, NotProvisionedException
@@ -4367,7 +4384,7 @@ public class MediaPlayer2 implements AutoCloseable
// exception if we're in a non-stopped/prepared state.
// for cleaning native/mediaserver crypto object
- native_releaseDrm();
+ native_releaseDrm(mSrcId);
// for cleaning client-side MediaDrm object; only called if above has succeeded
cleanDrmObj();
@@ -4573,7 +4590,7 @@ public class MediaPlayer2 implements AutoCloseable
SourceInfo(DataSourceDesc dsd) {
this.mDSD = dsd;
- mDrmHandle = new DrmHandle(dsd);
+ mDrmHandle = new DrmHandle(dsd, mId);
}
void close() {
diff --git a/media/java/android/media/SubtitleData.java b/media/java/android/media/SubtitleData.java
index ba37b9b66360..852babe1ecea 100644
--- a/media/java/android/media/SubtitleData.java
+++ b/media/java/android/media/SubtitleData.java
@@ -17,8 +17,11 @@
package android.media;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
+import java.util.Arrays;
+
/**
* Class encapsulating subtitle data, as received through the
* {@link MediaPlayer.OnSubtitleDataListener} interface.
@@ -80,11 +83,11 @@ public final class SubtitleData
}
/** @hide */
- public SubtitleData(int trackIndex, long startTimeUs, long durationUs, byte[] data) {
+ public SubtitleData(int trackIndex, long startTimeUs, long durationUs, @NonNull byte[] data) {
mTrackIndex = trackIndex;
mStartTimeUs = startTimeUs;
mDurationUs = durationUs;
- mData = data;
+ mData = (data != null ? data : new byte[0]);
}
/**
@@ -138,4 +141,80 @@ public final class SubtitleData
return true;
}
+
+ /**
+ * Builder class for {@link SubtitleData} objects.
+ * <p> Here is an example where <code>Builder</code> is used to define the
+ * {@link SubtitleData}:
+ *
+ * <pre class="prettyprint">
+ * SubtitleData sd = new SubtitleData.Builder()
+ * .setSubtitleData(trackIndex, startTime, duration, data)
+ * .build();
+ * </pre>
+ * @hide
+ */
+ @SystemApi
+ public static class Builder {
+ private int mTrackIndex;
+ private long mStartTimeUs;
+ private long mDurationUs;
+ private byte[] mData = new byte[0];
+
+ /**
+ * Constructs a new Builder with the defaults.
+ */
+ public Builder() {
+ }
+
+ /**
+ * Constructs a new Builder from a given {@link SubtitleData} instance
+ * @param sd the {@link SubtitleData} object whose data will be reused
+ * in the new Builder. It should not be null. The data array is copied.
+ */
+ public Builder(@NonNull SubtitleData sd) {
+ if (sd == null) {
+ throw new IllegalArgumentException("null SubtitleData is not allowed");
+ }
+ mTrackIndex = sd.mTrackIndex;
+ mStartTimeUs = sd.mStartTimeUs;
+ mDurationUs = sd.mDurationUs;
+ if (sd.mData != null) {
+ mData = Arrays.copyOf(sd.mData, sd.mData.length);
+ }
+ }
+
+ /**
+ * Combines all of the fields that have been set and return a new
+ * {@link SubtitleData} object. <code>IllegalStateException</code> will be
+ * thrown if there is conflict between fields.
+ *
+ * @return a new {@link SubtitleData} object
+ */
+ public @NonNull SubtitleData build() {
+ return new SubtitleData(mTrackIndex, mStartTimeUs, mDurationUs, mData);
+ }
+
+ /**
+ * Sets the info of subtitle data.
+ *
+ * @param trackIndex the ParcelFileDescriptor for the file to play
+ * @param startTimeUs the start time in microsecond for the subtile data
+ * @param durationUs the duration in microsecond for the subtile data
+ * @param data the data array for the subtile data. It should not be null.
+ * No data copying is made.
+ * @return the same Builder instance.
+ */
+ public @NonNull Builder setSubtitleData(
+ int trackIndex, long startTimeUs, long durationUs, @NonNull byte[] data) {
+ if (data == null) {
+ throw new IllegalArgumentException("null data is not allowed");
+ }
+ mTrackIndex = trackIndex;
+ mStartTimeUs = startTimeUs;
+ mDurationUs = durationUs;
+ mData = data;
+ return this;
+ }
+ }
}
diff --git a/media/java/android/media/TimedMetaData.java b/media/java/android/media/TimedMetaData.java
index 97e6bfa170d8..bcc18ef92f94 100644
--- a/media/java/android/media/TimedMetaData.java
+++ b/media/java/android/media/TimedMetaData.java
@@ -16,8 +16,12 @@
package android.media;
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
+import java.util.Arrays;
+
/**
* Class that embodies one timed metadata access unit, including
*
@@ -50,7 +54,10 @@ public final class TimedMetaData {
/**
* @hide
*/
- public TimedMetaData(long timestampUs, byte[] metaData) {
+ public TimedMetaData(long timestampUs, @NonNull byte[] metaData) {
+ if (metaData == null) {
+ throw new IllegalArgumentException("null metaData is not allowed");
+ }
mTimestampUs = timestampUs;
mMetaData = metaData;
}
@@ -83,4 +90,71 @@ public final class TimedMetaData {
return true;
}
+
+ /**
+ * Builder class for {@link TimedMetaData} objects.
+ * <p> Here is an example where <code>Builder</code> is used to define the
+ * {@link TimedMetaData}:
+ *
+ * <pre class="prettyprint">
+ * TimedMetaData tmd = new TimedMetaData.Builder()
+ * .setTimedMetaData(timestamp, metaData)
+ * .build();
+ * </pre>
+ * @hide
+ */
+ @SystemApi
+ public static class Builder {
+ private long mTimestampUs;
+ private byte[] mMetaData = new byte[0];
+
+ /**
+ * Constructs a new Builder with the defaults.
+ */
+ public Builder() {
+ }
+
+ /**
+ * Constructs a new Builder from a given {@link TimedMetaData} instance
+ * @param tmd the {@link TimedMetaData} object whose data will be reused
+ * in the new Builder. It should not be null. The metadata array is copied.
+ */
+ public Builder(@NonNull TimedMetaData tmd) {
+ if (tmd == null) {
+ throw new IllegalArgumentException("null TimedMetaData is not allowed");
+ }
+ mTimestampUs = tmd.mTimestampUs;
+ if (tmd.mMetaData != null) {
+ mMetaData = Arrays.copyOf(tmd.mMetaData, tmd.mMetaData.length);
+ }
+ }
+
+ /**
+ * Combines all of the fields that have been set and return a new
+ * {@link TimedMetaData} object. <code>IllegalStateException</code> will be
+ * thrown if there is conflict between fields.
+ *
+ * @return a new {@link TimedMetaData} object
+ */
+ public @NonNull TimedMetaData build() {
+ return new TimedMetaData(mTimestampUs, mMetaData);
+ }
+
+ /**
+ * Sets the info of timed metadata.
+ *
+ * @param timestamp the timestamp in microsecond for the timed metadata
+ * @param metaData the metadata array for the timed metadata. No data copying is made.
+ * It should not be null.
+ * @return the same Builder instance.
+ */
+ public @NonNull Builder setTimedMetaData(int timestamp, @NonNull byte[] metaData) {
+ if (metaData == null) {
+ throw new IllegalArgumentException("null metaData is not allowed");
+ }
+ mTimestampUs = timestamp;
+ mMetaData = metaData;
+ return this;
+ }
+ }
}
diff --git a/media/java/android/media/UriDataSourceDesc.java b/media/java/android/media/UriDataSourceDesc.java
index 6a83dab14aa4..e39f53c9e19b 100644
--- a/media/java/android/media/UriDataSourceDesc.java
+++ b/media/java/android/media/UriDataSourceDesc.java
@@ -30,7 +30,6 @@ import java.util.List;
import java.util.Map;
/**
- * @hide
* Structure of data source descriptor for sources using URI.
*
* Used by {@link MediaPlayer2#setDataSource(DataSourceDesc)},
diff --git a/media/java/android/media/VideoSize.java b/media/java/android/media/VideoSize.java
index 7e5cb1f457c8..19631e09853d 100644
--- a/media/java/android/media/VideoSize.java
+++ b/media/java/android/media/VideoSize.java
@@ -18,8 +18,6 @@ package android.media;
/**
* Immutable class for describing width and height dimensions.
- *
- * @hide
*/
public final class VideoSize {
/**
@@ -28,7 +26,7 @@ public final class VideoSize {
* @param width The width of the video size
* @param height The height of the video size
*/
- public VideoSize(int width, int height) {
+ VideoSize(int width, int height) {
mWidth = width;
mHeight = height;
}
diff --git a/media/jni/android_media_MediaPlayer2.cpp b/media/jni/android_media_MediaPlayer2.cpp
index 456749279696..8b6009e749ce 100644
--- a/media/jni/android_media_MediaPlayer2.cpp
+++ b/media/jni/android_media_MediaPlayer2.cpp
@@ -1192,7 +1192,7 @@ static Vector<uint8_t> JByteArrayToVector(JNIEnv *env, jbyteArray const &byteArr
}
static void android_media_MediaPlayer2_prepareDrm(JNIEnv *env, jobject thiz,
- jbyteArray uuidObj, jbyteArray drmSessionIdObj)
+ jlong srcId, jbyteArray uuidObj, jbyteArray drmSessionIdObj)
{
sp<MediaPlayer2> mp = getMediaPlayer(env, thiz);
if (mp == NULL) {
@@ -1225,7 +1225,7 @@ static void android_media_MediaPlayer2_prepareDrm(JNIEnv *env, jobject thiz,
return;
}
- status_t err = mp->prepareDrm(uuid.array(), drmSessionId);
+ status_t err = mp->prepareDrm(srcId, uuid.array(), drmSessionId);
if (err != OK) {
if (err == INVALID_OPERATION) {
jniThrowException(
@@ -1243,7 +1243,7 @@ static void android_media_MediaPlayer2_prepareDrm(JNIEnv *env, jobject thiz,
}
}
-static void android_media_MediaPlayer2_releaseDrm(JNIEnv *env, jobject thiz)
+static void android_media_MediaPlayer2_releaseDrm(JNIEnv *env, jobject thiz, jlong srcId)
{
sp<MediaPlayer2> mp = getMediaPlayer(env, thiz);
if (mp == NULL ) {
@@ -1251,7 +1251,7 @@ static void android_media_MediaPlayer2_releaseDrm(JNIEnv *env, jobject thiz)
return;
}
- status_t err = mp->releaseDrm();
+ status_t err = mp->releaseDrm(srcId);
if (err != OK) {
if (err == INVALID_OPERATION) {
jniThrowException(
@@ -1425,8 +1425,8 @@ static const JNINativeMethod gMethods[] = {
{"native_setAuxEffectSendLevel", "(F)V", (void *)android_media_MediaPlayer2_setAuxEffectSendLevel},
{"native_attachAuxEffect", "(I)V", (void *)android_media_MediaPlayer2_attachAuxEffect},
// Modular DRM
- { "native_prepareDrm", "([B[B)V", (void *)android_media_MediaPlayer2_prepareDrm },
- { "native_releaseDrm", "()V", (void *)android_media_MediaPlayer2_releaseDrm },
+ { "native_prepareDrm", "(J[B[B)V", (void *)android_media_MediaPlayer2_prepareDrm },
+ { "native_releaseDrm", "(J)V", (void *)android_media_MediaPlayer2_releaseDrm },
// AudioRouting
{"native_setPreferredDevice", "(Landroid/media/AudioDeviceInfo;)Z", (void *)android_media_MediaPlayer2_setPreferredDevice},
diff --git a/native/webview/plat_support/Android.bp b/native/webview/plat_support/Android.bp
index d8c5ac969128..96c9c1c85a60 100644
--- a/native/webview/plat_support/Android.bp
+++ b/native/webview/plat_support/Android.bp
@@ -23,6 +23,8 @@ cc_library_shared {
srcs: [
"draw_gl_functor.cpp",
+ "draw_vk_functor.cpp",
+ "functor_utils.cpp",
"jni_entry_point.cpp",
"graphics_utils.cpp",
"graphic_buffer_impl.cpp",
@@ -36,6 +38,7 @@ cc_library_shared {
"liblog",
"libui",
"libutils",
+ "libvulkan",
],
// To remove warnings from skia header files
diff --git a/native/webview/plat_support/draw_gl_functor.cpp b/native/webview/plat_support/draw_gl_functor.cpp
index e3e52b1ea1f1..be36b6742037 100644
--- a/native/webview/plat_support/draw_gl_functor.cpp
+++ b/native/webview/plat_support/draw_gl_functor.cpp
@@ -21,15 +21,13 @@
#include "draw_gl.h"
-#include <errno.h>
#include <jni.h>
#include <private/hwui/DrawGlInfo.h>
-#include <string.h>
-#include <sys/resource.h>
-#include <sys/time.h>
#include <utils/Functor.h>
#include <utils/Log.h>
+#include "functor_utils.h"
+
#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
#define COMPILE_ASSERT(expr, err) \
__unused static const char (err)[(expr) ? 1 : -1] = "";
@@ -98,27 +96,6 @@ class DrawGLFunctor : public Functor {
intptr_t view_context_;
};
-// Raise the file handle soft limit to the hard limit since gralloc buffers
-// uses file handles.
-void RaiseFileNumberLimit() {
- static bool have_raised_limit = false;
- if (have_raised_limit)
- return;
-
- have_raised_limit = true;
- struct rlimit limit_struct;
- limit_struct.rlim_cur = 0;
- limit_struct.rlim_max = 0;
- if (getrlimit(RLIMIT_NOFILE, &limit_struct) == 0) {
- limit_struct.rlim_cur = limit_struct.rlim_max;
- if (setrlimit(RLIMIT_NOFILE, &limit_struct) != 0) {
- ALOGE("setrlimit failed: %s", strerror(errno));
- }
- } else {
- ALOGE("getrlimit failed: %s", strerror(errno));
- }
-}
-
jlong CreateGLFunctor(JNIEnv*, jclass, jlong view_context) {
RaiseFileNumberLimit();
return reinterpret_cast<jlong>(new DrawGLFunctor(view_context));
diff --git a/native/webview/plat_support/draw_vk.h b/native/webview/plat_support/draw_vk.h
new file mode 100644
index 000000000000..6b7d8d0b9118
--- /dev/null
+++ b/native/webview/plat_support/draw_vk.h
@@ -0,0 +1,125 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+//******************************************************************************
+// This is a copy of the coresponding android_webview/public/browser header.
+// Any changes to the interface should be made there.
+//
+// The purpose of having the copy is twofold:
+// - it removes the need to have Chromium sources present in the tree in order
+// to build the plat_support library,
+// - it captures API that the corresponding Android release supports.
+//******************************************************************************
+
+#ifndef ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_
+#define ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_
+
+#include <vulkan/vulkan.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static const int kAwDrawVKInfoVersion = 1;
+
+// Holds the information required to trigger initialization of the Vulkan
+// functor.
+struct InitParams {
+ // All params are input
+ VkInstance instance;
+ VkPhysicalDevice physical_device;
+ VkDevice device;
+ VkQueue queue;
+ uint32_t graphics_queue_index;
+ uint32_t instance_version;
+ const char* const* enabled_extension_names;
+ // Only one of device_features and device_features_2 should be non-null.
+ // If both are null then no features are enabled.
+ VkPhysicalDeviceFeatures* device_features;
+ VkPhysicalDeviceFeatures2* device_features_2;
+};
+
+// Holds the information required to trigger an Vulkan composite operation.
+struct CompositeParams {
+ // Input: current width/height of destination surface.
+ int width;
+ int height;
+
+ // Input: is the render target a FBO
+ bool is_layer;
+
+ // Input: current transform matrix
+ float transform[16];
+
+ // Input WebView should do its main compositing draws into this. It cannot do
+ // anything that would require stopping the render pass.
+ VkCommandBuffer secondary_command_buffer;
+
+ // Input: The main color attachment index where secondary_command_buffer will
+ // eventually be submitted.
+ uint32_t color_attachment_index;
+
+ // Input: A render pass which will be compatible to the one which the
+ // secondary_command_buffer will be submitted into.
+ VkRenderPass compatible_render_pass;
+
+ // Input: Format of the destination surface.
+ VkFormat format;
+
+ // Input: Color space transfer params
+ float G;
+ float A;
+ float B;
+ float C;
+ float D;
+ float E;
+ float F;
+
+ // Input: Color space transformation from linear RGB to D50-adapted XYZ
+ float matrix[9];
+
+ // Input: current clip rect
+ int clip_left;
+ int clip_top;
+ int clip_right;
+ int clip_bottom;
+};
+
+// Holds the information for the post-submission callback of main composite
+// draw.
+struct PostCompositeParams {
+ // Input: Fence for the composite command buffer to signal it has finished its
+ // work on the GPU.
+ int fd;
+};
+
+// Holds the information required to trigger an Vulkan operation.
+struct AwDrawVKInfo {
+ int version; // The AwDrawVKInfo this struct was built with.
+
+ // Input: tells the draw function what action to perform.
+ enum Mode {
+ kModeInit = 0,
+ kModeReInit = 1,
+ kModePreComposite = 2,
+ kModeComposite = 3,
+ kModePostComposite = 4,
+ kModeSync = 5,
+ } mode;
+
+ // Input: The parameters for the functor being called
+ union ParamUnion {
+ struct InitParams init_params;
+ struct CompositeParams composite_params;
+ struct PostCompositeParams post_composite_params;
+ } info;
+};
+
+typedef void(AwDrawVKFunction)(long view_context, AwDrawVKInfo* draw_info);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_VK_H_
diff --git a/native/webview/plat_support/draw_vk_functor.cpp b/native/webview/plat_support/draw_vk_functor.cpp
new file mode 100644
index 000000000000..1ba559d9afdf
--- /dev/null
+++ b/native/webview/plat_support/draw_vk_functor.cpp
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+// Provides a webviewchromium glue layer adapter from the internal Android
+// Vulkan Functor data types into the types the chromium stack expects, and
+// back.
+
+#define LOG_TAG "webviewchromium_plat_support"
+
+#include "draw_vk.h"
+
+#include <jni.h>
+#include <private/hwui/DrawVkInfo.h>
+#include <utils/Functor.h>
+#include <utils/Log.h>
+
+#include "functor_utils.h"
+
+#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
+
+namespace android {
+namespace {
+
+AwDrawVKFunction* g_aw_drawvk_function = NULL;
+
+class DrawVKFunctor : public Functor {
+ public:
+ explicit DrawVKFunctor(jlong view_context) : view_context_(view_context) {}
+ ~DrawVKFunctor() override {}
+
+ // Functor
+ status_t operator ()(int what, void* data) override {
+ using uirenderer::DrawVkInfo;
+ if (!g_aw_drawvk_function) {
+ ALOGE("Cannot draw: no DrawVK Function installed");
+ return DrawVkInfo::kStatusDone;
+ }
+
+ AwDrawVKInfo aw_info;
+ aw_info.version = kAwDrawVKInfoVersion;
+ switch (what) {
+ case DrawVkInfo::kModeComposite: {
+ aw_info.mode = AwDrawVKInfo::kModeComposite;
+ DrawVkInfo* vk_info = reinterpret_cast<DrawVkInfo*>(data);
+
+ // Map across the input values.
+ CompositeParams& params = aw_info.info.composite_params;
+ params.width = vk_info->width;
+ params.height = vk_info->height;
+ params.is_layer = vk_info->isLayer;
+ for (size_t i = 0; i < 16; i++) {
+ params.transform[i] = vk_info->transform[i];
+ }
+ params.secondary_command_buffer = vk_info->secondaryCommandBuffer;
+ params.color_attachment_index = vk_info->colorAttachmentIndex;
+ params.compatible_render_pass = vk_info->compatibleRenderPass;
+ params.format = vk_info->format;
+ params.G = vk_info->G;
+ params.A = vk_info->A;
+ params.B = vk_info->B;
+ params.C = vk_info->C;
+ params.D = vk_info->D;
+ params.E = vk_info->E;
+ params.F = vk_info->F;
+ for (size_t i = 0; i < 9; i++) {
+ params.matrix[i] = vk_info->matrix[i];
+ }
+ params.clip_left = vk_info->clipLeft;
+ params.clip_top = vk_info->clipTop;
+ params.clip_right = vk_info->clipRight;
+ params.clip_bottom = vk_info->clipBottom;
+
+ break;
+ }
+ case DrawVkInfo::kModePostComposite:
+ break;
+ case DrawVkInfo::kModeSync:
+ aw_info.mode = AwDrawVKInfo::kModeSync;
+ break;
+ default:
+ ALOGE("Unexpected DrawVKInfo type %d", what);
+ return DrawVkInfo::kStatusDone;
+ }
+
+ // Invoke the DrawVK method.
+ g_aw_drawvk_function(view_context_, &aw_info);
+
+ return DrawVkInfo::kStatusDone;
+ }
+
+ private:
+ intptr_t view_context_;
+};
+
+jlong CreateVKFunctor(JNIEnv*, jclass, jlong view_context) {
+ RaiseFileNumberLimit();
+ return reinterpret_cast<jlong>(new DrawVKFunctor(view_context));
+}
+
+void DestroyVKFunctor(JNIEnv*, jclass, jlong functor) {
+ delete reinterpret_cast<DrawVKFunctor*>(functor);
+}
+
+void SetChromiumAwDrawVKFunction(JNIEnv*, jclass, jlong draw_function) {
+ g_aw_drawvk_function = reinterpret_cast<AwDrawVKFunction*>(draw_function);
+}
+
+const char kClassName[] = "com/android/webview/chromium/DrawVKFunctor";
+const JNINativeMethod kJniMethods[] = {
+ { "nativeCreateVKFunctor", "(J)J",
+ reinterpret_cast<void*>(CreateVKFunctor) },
+ { "nativeDestroyVKFunctor", "(J)V",
+ reinterpret_cast<void*>(DestroyVKFunctor) },
+ { "nativeSetChromiumAwDrawVKFunction", "(J)V",
+ reinterpret_cast<void*>(SetChromiumAwDrawVKFunction) },
+};
+
+} // namespace
+
+void RegisterDrawVKFunctor(JNIEnv* env) {
+ jclass clazz = env->FindClass(kClassName);
+ LOG_ALWAYS_FATAL_IF(!clazz, "Unable to find class '%s'", kClassName);
+
+ int res = env->RegisterNatives(clazz, kJniMethods, NELEM(kJniMethods));
+ LOG_ALWAYS_FATAL_IF(res < 0, "register native methods failed: res=%d", res);
+}
+
+} // namespace android
diff --git a/native/webview/plat_support/functor_utils.cpp b/native/webview/plat_support/functor_utils.cpp
new file mode 100644
index 000000000000..235762dc2679
--- /dev/null
+++ b/native/webview/plat_support/functor_utils.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "functor_utils.h"
+
+#include <errno.h>
+#include <string.h>
+#include <sys/resource.h>
+#include <utils/Log.h>
+
+namespace android {
+
+void RaiseFileNumberLimit() {
+ static bool have_raised_limit = false;
+ if (have_raised_limit)
+ return;
+
+ have_raised_limit = true;
+ struct rlimit limit_struct;
+ limit_struct.rlim_cur = 0;
+ limit_struct.rlim_max = 0;
+ if (getrlimit(RLIMIT_NOFILE, &limit_struct) == 0) {
+ limit_struct.rlim_cur = limit_struct.rlim_max;
+ if (setrlimit(RLIMIT_NOFILE, &limit_struct) != 0) {
+ ALOGE("setrlimit failed: %s", strerror(errno));
+ }
+ } else {
+ ALOGE("getrlimit failed: %s", strerror(errno));
+ }
+}
+
+} // namespace android
diff --git a/native/webview/plat_support/functor_utils.h b/native/webview/plat_support/functor_utils.h
new file mode 100644
index 000000000000..76c0bb67d275
--- /dev/null
+++ b/native/webview/plat_support/functor_utils.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#pragma once
+
+namespace android {
+
+// Raise the file handle soft limit to the hard limit since gralloc buffers
+// uses file handles.
+void RaiseFileNumberLimit();
+
+} // namespace android
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
index b55aa5c8897d..904f94486e6c 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
@@ -1904,13 +1904,18 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
+ slotId + ", state=" + state +")");
}
+ boolean becameAbsent = false;
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
Log.w(TAG, "invalid subId in handleSimStateChange()");
/* Only handle No SIM(ABSENT) due to handleServiceStateChange() handle other case */
if (state == State.ABSENT) {
updateTelephonyCapable(true);
+ // Even though the subscription is not valid anymore, we need to notify that the
+ // SIM card was removed so we can update the UI.
+ becameAbsent = true;
+ } else {
+ return;
}
- return;
}
SimData data = mSimDatas.get(subId);
@@ -1925,7 +1930,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
data.subId = subId;
data.slotId = slotId;
}
- if (changed && state != State.UNKNOWN) {
+ if ((changed || becameAbsent) && state != State.UNKNOWN) {
for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) {
diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
index 053ea67b92c8..04c427f87125 100644
--- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
+++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
@@ -88,6 +88,9 @@ public class BatteryMeterView extends LinearLayout implements
private int mShowPercentMode = MODE_DEFAULT;
private boolean mForceShowPercent;
private boolean mShowPercentAvailable;
+ // Some places may need to show the battery conditionally, and not obey the tuner
+ private boolean mIgnoreTunerUpdates;
+ private boolean mIsSubscribedForTunerUpdates;
private int mDarkModeBackgroundColor;
private int mDarkModeFillColor;
@@ -183,6 +186,44 @@ public class BatteryMeterView extends LinearLayout implements
}
/**
+ * Set {@code true} to turn off BatteryMeterView's subscribing to the tuner for updates, and
+ * thus avoid it controlling its own visibility
+ *
+ * @param ignore whether to ignore the tuner or not
+ */
+ public void setIgnoreTunerUpdates(boolean ignore) {
+ mIgnoreTunerUpdates = ignore;
+ updateTunerSubscription();
+ }
+
+ private void updateTunerSubscription() {
+ if (mIgnoreTunerUpdates) {
+ unsubscribeFromTunerUpdates();
+ } else {
+ subscribeForTunerUpdates();
+ }
+ }
+
+ private void subscribeForTunerUpdates() {
+ if (mIsSubscribedForTunerUpdates || mIgnoreTunerUpdates) {
+ return;
+ }
+
+ Dependency.get(TunerService.class)
+ .addTunable(this, StatusBarIconController.ICON_BLACKLIST);
+ mIsSubscribedForTunerUpdates = true;
+ }
+
+ private void unsubscribeFromTunerUpdates() {
+ if (!mIsSubscribedForTunerUpdates) {
+ return;
+ }
+
+ Dependency.get(TunerService.class).removeTunable(this);
+ mIsSubscribedForTunerUpdates = false;
+ }
+
+ /**
* Sets whether the battery meter view uses the wallpaperTextColor. If we're not using it, we'll
* revert back to dark-mode-based/tinted colors.
*
@@ -247,8 +288,7 @@ public class BatteryMeterView extends LinearLayout implements
getContext().getContentResolver().registerContentObserver(
Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, mUser);
updateShowPercent();
- Dependency.get(TunerService.class)
- .addTunable(this, StatusBarIconController.ICON_BLACKLIST);
+ subscribeForTunerUpdates();
Dependency.get(ConfigurationController.class).addCallback(this);
mUserTracker.startTracking();
}
@@ -259,7 +299,7 @@ public class BatteryMeterView extends LinearLayout implements
mUserTracker.stopTracking();
mBatteryController.removeCallback(this);
getContext().getContentResolver().unregisterContentObserver(mSettingObserver);
- Dependency.get(TunerService.class).removeTunable(this);
+ unsubscribeFromTunerUpdates();
Dependency.get(ConfigurationController.class).removeCallback(this);
}
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
index 416cc594051b..5c259d5c4093 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
@@ -342,13 +342,16 @@ public class BubbleController {
}
}
}
+ boolean isCall = Notification.CATEGORY_CALL.equals(n.getNotification().category)
+ && n.isOngoing();
+ boolean isMusic = n.getNotification().hasMediaSession();
+ boolean isImportantOngoing = isMusic || isCall;
Class<? extends Notification.Style> style = n.getNotification().getNotificationStyle();
- boolean isMessageType = Notification.MessagingStyle.class.equals(style)
- || Notification.CATEGORY_MESSAGE.equals(n.getNotification().category)
- || hasRemoteInput;
- return (isMessageType && autoBubbleMessages)
- || (n.isOngoing() && autoBubbleOngoing)
+ boolean isMessageType = Notification.CATEGORY_MESSAGE.equals(n.getNotification().category);
+ boolean isMessageStyle = Notification.MessagingStyle.class.equals(style);
+ return (((isMessageType && hasRemoteInput) || isMessageStyle) && autoBubbleMessages)
+ || (isImportantOngoing && autoBubbleOngoing)
|| autoBubbleAll;
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index 3b9110d31c6f..9ccdf79c37ca 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -488,6 +488,9 @@ public class KeyguardViewMediator extends SystemUI {
// MVNO SIMs can become transiently NOT_READY when switching networks,
// so we should only lock when they are ABSENT.
onSimAbsentLocked();
+ if (simWasLocked) {
+ resetStateLocked();
+ }
}
}
break;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
index e2e943a369c2..d7d3981d05d1 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
@@ -79,7 +79,7 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
mFooterIcon = (ImageView) mRootView.findViewById(R.id.footer_icon);
mFooterIconId = R.drawable.ic_info_outline;
mContext = context;
- mMainHandler = new Handler(Looper.getMainLooper());
+ mMainHandler = new Handler(Looper.myLooper());
mActivityStarter = Dependency.get(ActivityStarter.class);
mSecurityController = Dependency.get(SecurityController.class);
mHandler = new H(Dependency.get(Dependency.BG_LOOPER));
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java b/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java
index d1c2df53b5a5..ca8e824a223f 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSTileHost.java
@@ -308,7 +308,7 @@ public class QSTileHost implements QSHost, Tunable, PluginListener<QSFactory> {
protected static List<String> loadTileSpecs(Context context, String tileList) {
final Resources res = context.getResources();
final String defaultTileList = res.getString(R.string.quick_settings_tiles_default);
- if (tileList == null) {
+ if (TextUtils.isEmpty(tileList)) {
tileList = res.getString(R.string.quick_settings_tiles);
if (DEBUG) Log.d(TAG, "Loaded tile specs from config: " + tileList);
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java
index 427f638b0d30..3cecff033c91 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java
@@ -232,6 +232,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements
// Tint for the battery icons are handled in setupHost()
mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon);
mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_OFF);
+ // Don't need to worry about tuner settings for this icon
+ mBatteryRemainingIcon.setIgnoreTunerUpdates(true);
mBatteryRemainingText = findViewById(R.id.batteryRemainingText);
mBatteryRemainingText.setTextColor(fillColor);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
index 69e698ffcd39..8214ea6c7616 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
@@ -328,6 +328,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
private float mTranslationWhenRemoved;
private boolean mWasChildInGroupWhenRemoved;
private int mNotificationColorAmbient;
+ private NotificationInlineImageResolver mImageResolver;
private SystemNotificationAsyncTask mSystemNotificationAsyncTask =
new SystemNotificationAsyncTask();
@@ -1621,6 +1622,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
mFalsingManager = FalsingManager.getInstance(context);
mNotificationInflater = new NotificationInflater(this);
mMenuRow = new NotificationMenuRow(mContext);
+ mImageResolver = new NotificationInlineImageResolver(context,
+ new NotificationInlineImageCache());
initDimens();
}
@@ -1657,6 +1660,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
res.getBoolean(R.bool.config_showGroupNotificationBgWhenExpanded);
}
+ NotificationInlineImageResolver getImageResolver() {
+ return mImageResolver;
+ }
+
/**
* Resets this view so it can be re-used for an updated notification.
*/
@@ -2090,7 +2097,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
@Override
protected boolean shouldClipToActualHeight() {
- return super.shouldClipToActualHeight() && !mExpandAnimationRunning && !mChildIsExpanding;
+ return super.shouldClipToActualHeight() && !mExpandAnimationRunning;
}
@Override
@@ -3134,6 +3141,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
pw.print(", alpha: " + getAlpha());
pw.print(", translation: " + getTranslation());
pw.print(", removed: " + isRemoved());
+ pw.print(", expandAnimationRunning: " + mExpandAnimationRunning);
NotificationContentView showingLayout = getShowingLayout();
pw.print(", privateShowing: " + (showingLayout == mPrivateLayout));
pw.println();
@@ -3147,6 +3155,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
pw.println();
pw.println();
if (mIsSummaryWithChildren) {
+ pw.print(" ChildrenContainer");
+ pw.print(" visibility: " + mChildrenContainer.getVisibility());
+ pw.print(", alpha: " + mChildrenContainer.getAlpha());
+ pw.print(", translationY: " + mChildrenContainer.getTranslationY());
+ pw.println();
List<ExpandableNotificationRow> notificationChildren = getNotificationChildren();
pw.println(" Children: " + notificationChildren.size());
pw.println(" {");
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java
index 0efb1308e83e..6aadcb7b30e1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableOutlineView.java
@@ -77,8 +77,6 @@ public abstract class ExpandableOutlineView extends ExpandableView {
protected boolean mShouldTranslateContents;
private boolean mTopAmountRounded;
private float mDistanceToTopRoundness = -1;
- private float mExtraWidthForClipping;
- private int mMinimumHeightForClipping = 0;
private final ViewOutlineProvider mProvider = new ViewOutlineProvider() {
@Override
@@ -219,13 +217,15 @@ public abstract class ExpandableOutlineView extends ExpandableView {
return result;
}
+ @Override
public void setExtraWidthForClipping(float extraWidthForClipping) {
- mExtraWidthForClipping = extraWidthForClipping;
+ super.setExtraWidthForClipping(extraWidthForClipping);
invalidate();
}
+ @Override
public void setMinimumHeightForClipping(int minimumHeightForClipping) {
- mMinimumHeightForClipping = minimumHeightForClipping;
+ super.setMinimumHeightForClipping(minimumHeightForClipping);
invalidate();
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableView.java
index 1e8de076cbed..20c48163e6b1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableView.java
@@ -48,6 +48,8 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable {
private int mActualHeight;
protected int mClipTopAmount;
protected int mClipBottomAmount;
+ protected int mMinimumHeightForClipping = 0;
+ protected float mExtraWidthForClipping = 0;
private boolean mDark;
private ArrayList<View> mMatchParentViews = new ArrayList<View>();
private static Rect mClipRect = new Rect();
@@ -398,14 +400,26 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable {
protected void updateClipping() {
if (mClipToActualHeight && shouldClipToActualHeight()) {
int top = getClipTopAmount();
- mClipRect.set(0, top, getWidth(), Math.max(getActualHeight() + getExtraBottomPadding()
- - mClipBottomAmount, top));
+ int bottom = Math.max(Math.max(getActualHeight() + getExtraBottomPadding()
+ - mClipBottomAmount, top), mMinimumHeightForClipping);
+ int halfExtraWidth = (int) (mExtraWidthForClipping / 2.0f);
+ mClipRect.set(-halfExtraWidth, top, getWidth() + halfExtraWidth, bottom);
setClipBounds(mClipRect);
} else {
setClipBounds(null);
}
}
+ public void setMinimumHeightForClipping(int minimumHeightForClipping) {
+ mMinimumHeightForClipping = minimumHeightForClipping;
+ updateClipping();
+ }
+
+ public void setExtraWidthForClipping(float extraWidthForClipping) {
+ mExtraWidthForClipping = extraWidthForClipping;
+ updateClipping();
+ }
+
public float getHeaderVisibleAmount() {
return 1.0f;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInflater.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInflater.java
index ef343fac5afa..9908049984d1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInflater.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInflater.java
@@ -33,6 +33,7 @@ import android.view.View;
import android.widget.RemoteViews;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.widget.ImageMessageConsumer;
import com.android.systemui.statusbar.InflationTask;
import com.android.systemui.statusbar.notification.InflationException;
import com.android.systemui.statusbar.notification.MediaNotificationProcessor;
@@ -114,7 +115,7 @@ public class NotificationInflater {
@InflationFlag
private int mInflationFlags = REQUIRED_INFLATION_FLAGS;
- private static final InflationExecutor EXECUTOR = new InflationExecutor();
+ static final InflationExecutor EXECUTOR = new InflationExecutor();
private final ExpandableNotificationRow mRow;
private boolean mIsLowPriority;
@@ -244,6 +245,10 @@ public class NotificationInflater {
// Only inflate the ones that are set.
reInflateFlags &= mInflationFlags;
StatusBarNotification sbn = mRow.getEntry().notification;
+
+ // To check if the notification has inline image and preload inline image if necessary.
+ mRow.getImageResolver().preloadImages(sbn.getNotification());
+
AsyncInflationTask task = new AsyncInflationTask(sbn, reInflateFlags, mCachedContentViews,
mRow, mIsLowPriority, mIsChildInGroup, mUsesIncreasedHeight,
mUsesIncreasedHeadsUpHeight, mRedactAmbient, mCallback, mRemoteViewClickHandler);
@@ -520,8 +525,14 @@ public class NotificationInflater {
}
return;
}
- RemoteViews.OnViewAppliedListener listener
- = new RemoteViews.OnViewAppliedListener() {
+ RemoteViews.OnViewAppliedListener listener = new RemoteViews.OnViewAppliedListener() {
+
+ @Override
+ public void onViewInflated(View v) {
+ if (v instanceof ImageMessageConsumer) {
+ ((ImageMessageConsumer) v).setImageResolver(row.getImageResolver());
+ }
+ }
@Override
public void onViewApplied(View v) {
@@ -851,6 +862,10 @@ public class NotificationInflater {
mRow.getEntry().onInflationTaskFinished();
mRow.onNotificationUpdated();
mCallback.onAsyncInflationFinished(mRow.getEntry(), inflatedFlags);
+
+ // Notify the resolver that the inflation task has finished,
+ // try to purge unnecessary cached entries.
+ mRow.getImageResolver().purgeCache();
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInlineImageCache.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInlineImageCache.java
new file mode 100644
index 000000000000..8c8bad2ab196
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInlineImageCache.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.notification.row;
+
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.util.Log;
+
+import java.io.IOException;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * A cache for inline images of image messages.
+ */
+public class NotificationInlineImageCache implements NotificationInlineImageResolver.ImageCache {
+ private static final String TAG = NotificationInlineImageCache.class.getSimpleName();
+
+ private NotificationInlineImageResolver mResolver;
+ private final ConcurrentHashMap<Uri, PreloadImageTask> mCache;
+
+ public NotificationInlineImageCache() {
+ mCache = new ConcurrentHashMap<>();
+ }
+
+ @Override
+ public void setImageResolver(NotificationInlineImageResolver resolver) {
+ mResolver = resolver;
+ }
+
+ @Override
+ public boolean hasEntry(Uri uri) {
+ return mCache.containsKey(uri);
+ }
+
+ @Override
+ public void preload(Uri uri) {
+ PreloadImageTask newTask = new PreloadImageTask(mResolver);
+ newTask.executeOnExecutor(NotificationInflater.EXECUTOR, uri);
+ mCache.put(uri, newTask);
+ }
+
+ @Override
+ public Drawable get(Uri uri) {
+ Drawable result = null;
+ try {
+ result = mCache.get(uri).get();
+ } catch (InterruptedException | ExecutionException ex) {
+ Log.d(TAG, "get: Failed get image from " + uri);
+ }
+ return result;
+ }
+
+ @Override
+ public void purge() {
+ Set<Uri> wantedSet = mResolver.getWantedUriSet();
+ mCache.entrySet().removeIf(entry -> !wantedSet.contains(entry.getKey()));
+ }
+
+ private static class PreloadImageTask extends AsyncTask<Uri, Void, Drawable> {
+ private final NotificationInlineImageResolver mResolver;
+
+ PreloadImageTask(NotificationInlineImageResolver resolver) {
+ mResolver = resolver;
+ }
+
+ @Override
+ protected Drawable doInBackground(Uri... uris) {
+ Drawable drawable = null;
+ Uri target = uris[0];
+
+ try {
+ drawable = mResolver.resolveImage(target);
+ } catch (IOException ex) {
+ Log.d(TAG, "PreloadImageTask: Resolve failed from " + target);
+ }
+
+ return drawable;
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInlineImageResolver.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInlineImageResolver.java
new file mode 100644
index 000000000000..588246f3d2c6
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInlineImageResolver.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.notification.row;
+
+import android.app.ActivityManager;
+import android.app.Notification;
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.util.Log;
+
+import com.android.internal.widget.ImageResolver;
+import com.android.internal.widget.LocalImageResolver;
+import com.android.internal.widget.MessagingMessage;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Custom resolver with built-in image cache for image messages.
+ */
+public class NotificationInlineImageResolver implements ImageResolver {
+ private static final String TAG = NotificationInlineImageResolver.class.getSimpleName();
+
+ private final Context mContext;
+ private final ImageCache mImageCache;
+ private Set<Uri> mWantedUriSet;
+
+ /**
+ * Constructor.
+ * @param context Context.
+ * @param imageCache The implementation of internal cache.
+ */
+ public NotificationInlineImageResolver(Context context, ImageCache imageCache) {
+ mContext = context.getApplicationContext();
+ mImageCache = imageCache;
+
+ if (mImageCache != null) {
+ mImageCache.setImageResolver(this);
+ }
+ }
+
+ /**
+ * Check if this resolver has its internal cache implementation.
+ * @return True if has its internal cache, false otherwise.
+ */
+ public boolean hasCache() {
+ return mImageCache != null && !ActivityManager.isLowRamDeviceStatic();
+ }
+
+ /**
+ * To resolve image from specified uri directly.
+ * @param uri Uri of the image.
+ * @return Drawable of the image.
+ * @throws IOException Throws if failed at resolving the image.
+ */
+ Drawable resolveImage(Uri uri) throws IOException {
+ return LocalImageResolver.resolveImage(uri, mContext);
+ }
+
+ @Override
+ public Drawable loadImage(Uri uri) {
+ Drawable result = null;
+ try {
+ result = hasCache() ? mImageCache.get(uri) : resolveImage(uri);
+ } catch (IOException ex) {
+ Log.d(TAG, "loadImage: Can't load image from " + uri);
+ }
+ return result;
+ }
+
+ /**
+ * Resolve the message list from specified notification and
+ * refresh internal cache according to the result.
+ * @param notification The Notification to be resolved.
+ */
+ public void preloadImages(Notification notification) {
+ if (!hasCache()) {
+ return;
+ }
+
+ retrieveWantedUriSet(notification);
+ Set<Uri> wantedSet = getWantedUriSet();
+ wantedSet.forEach(uri -> {
+ if (!mImageCache.hasEntry(uri)) {
+ // The uri is not in the cache, we need trigger a loading task for it.
+ mImageCache.preload(uri);
+ }
+ });
+ }
+
+ /**
+ * Try to purge unnecessary cache entries.
+ */
+ public void purgeCache() {
+ if (!hasCache()) {
+ return;
+ }
+ mImageCache.purge();
+ }
+
+ private void retrieveWantedUriSet(Notification notification) {
+ Parcelable[] messages;
+ Parcelable[] historicMessages;
+ List<Notification.MessagingStyle.Message> messageList;
+ List<Notification.MessagingStyle.Message> historicList;
+ Set<Uri> result = new HashSet<>();
+
+ Bundle extras = notification.extras;
+ if (extras == null) {
+ return;
+ }
+
+ messages = extras.getParcelableArray(Notification.EXTRA_MESSAGES);
+ messageList = messages == null ? null :
+ Notification.MessagingStyle.Message.getMessagesFromBundleArray(messages);
+ if (messageList != null) {
+ for (Notification.MessagingStyle.Message message : messageList) {
+ if (MessagingMessage.hasImage(message)) {
+ result.add(message.getDataUri());
+ }
+ }
+ }
+
+ historicMessages = extras.getParcelableArray(Notification.EXTRA_HISTORIC_MESSAGES);
+ historicList = historicMessages == null ? null :
+ Notification.MessagingStyle.Message.getMessagesFromBundleArray(historicMessages);
+ if (historicList != null) {
+ for (Notification.MessagingStyle.Message historic : historicList) {
+ if (MessagingMessage.hasImage(historic)) {
+ result.add(historic.getDataUri());
+ }
+ }
+ }
+
+ mWantedUriSet = result;
+ }
+
+ Set<Uri> getWantedUriSet() {
+ return mWantedUriSet;
+ }
+
+ /**
+ * A interface for internal cache implementation of this resolver.
+ */
+ interface ImageCache {
+ /**
+ * Load the image from cache first then resolve from uri if missed the cache.
+ * @param uri The uri of the image.
+ * @return Drawable of the image.
+ */
+ Drawable get(Uri uri);
+
+ /**
+ * Set the image resolver that actually resolves image from specified uri.
+ * @param resolver The resolver implementation that resolves image from specified uri.
+ */
+ void setImageResolver(NotificationInlineImageResolver resolver);
+
+ /**
+ * Check if the uri is in the cache no matter it is loading or loaded.
+ * @param uri The uri to check.
+ * @return True if it is already in the cache; false otherwise.
+ */
+ boolean hasEntry(Uri uri);
+
+ /**
+ * Start a new loading task for the target uri.
+ * @param uri The target to load.
+ */
+ void preload(Uri uri);
+
+ /**
+ * Purge unnecessary entries in the cache.
+ */
+ void purge();
+ }
+
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index f7aaf427f118..96ec6be1f957 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -579,6 +579,7 @@ public class StatusBar extends SystemUI implements DemoMode,
private boolean mVibrateOnOpening;
private VibratorHelper mVibratorHelper;
protected NotificationPresenter mPresenter;
+ private boolean mPulsing;
@Override
public void onActiveStateChanged(int code, int uid, String packageName, boolean active) {
@@ -1544,7 +1545,7 @@ public class StatusBar extends SystemUI implements DemoMode,
}
public boolean isPulsing() {
- return mAmbientPulseManager.hasNotifications();
+ return mPulsing;
}
public boolean isLaunchTransitionFadingAway() {
@@ -2526,7 +2527,7 @@ public class StatusBar extends SystemUI implements DemoMode,
}
}
if (dismissShade) {
- if (mExpandedVisible) {
+ if (mExpandedVisible && !mBouncerShowing) {
animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */,
true /* delayed*/);
} else {
@@ -3207,6 +3208,7 @@ public class StatusBar extends SystemUI implements DemoMode,
mNotificationPanel.onAffordanceLaunchEnded();
mNotificationPanel.animate().cancel();
mNotificationPanel.setAlpha(1f);
+ updateScrimController();
Trace.endSection();
return staying;
}
@@ -3935,6 +3937,10 @@ public class StatusBar extends SystemUI implements DemoMode,
return;
}
+ // Set the state to pulsing, so ScrimController will know what to do once we ask it to
+ // execute the transition. The pulse callback will then be invoked when the scrims
+ // are black, indicating that StatusBar is ready to present the rest of the UI.
+ mPulsing = true;
mDozeScrimController.pulse(new PulseCallback() {
@Override
public void onPulseStarted() {
@@ -3948,6 +3954,7 @@ public class StatusBar extends SystemUI implements DemoMode,
@Override
public void onPulseFinished() {
+ mPulsing = false;
callback.onPulseFinished();
setPulsing(false);
}
diff --git a/packages/SystemUI/src/com/android/systemui/util/Assert.java b/packages/SystemUI/src/com/android/systemui/util/Assert.java
index 0f7c9a462c0a..096ac3fcee1d 100644
--- a/packages/SystemUI/src/com/android/systemui/util/Assert.java
+++ b/packages/SystemUI/src/com/android/systemui/util/Assert.java
@@ -18,19 +18,24 @@ package com.android.systemui.util;
import android.os.Looper;
+import com.android.internal.annotations.VisibleForTesting;
+
/**
* Helper providing common assertions.
*/
public class Assert {
+ @VisibleForTesting
+ public static Looper sMainLooper = Looper.getMainLooper();
+
public static void isMainThread() {
- if (!Looper.getMainLooper().isCurrentThread()) {
+ if (!sMainLooper.isCurrentThread()) {
throw new IllegalStateException("should be called from the main thread.");
}
}
public static void isNotMainThread() {
- if (Looper.getMainLooper().isCurrentThread()) {
+ if (sMainLooper.isCurrentThread()) {
throw new IllegalStateException("should not be called from the main thread.");
}
}
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
index 9cbe4152b5c4..7ca54231fe7b 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchTest.java
@@ -51,7 +51,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@SmallTest
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
@RunWith(AndroidTestingRunner.class)
public class KeyguardClockSwitchTest extends SysuiTestCase {
private PluginManager mPluginManager;
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java
index 359832f7a542..58870e4acbd0 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinBasedInputViewTest.java
@@ -38,7 +38,7 @@ import org.mockito.MockitoAnnotations;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class KeyguardPinBasedInputViewTest extends SysuiTestCase {
@Mock
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java
index b98ce39f5ed3..77895c97051c 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java
@@ -19,9 +19,14 @@ import android.graphics.Color;
import android.net.Uri;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.LayoutInflater;
+import androidx.slice.SliceProvider;
+import androidx.slice.SliceSpecs;
+import androidx.slice.builders.ListBuilder;
+
import com.android.systemui.SysuiTestCase;
import com.android.systemui.keyguard.KeyguardSliceProvider;
@@ -34,12 +39,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicBoolean;
-import androidx.slice.SliceProvider;
-import androidx.slice.SliceSpecs;
-import androidx.slice.builders.ListBuilder;
-
@SmallTest
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
@RunWith(AndroidTestingRunner.class)
public class KeyguardSliceViewTest extends SysuiTestCase {
private KeyguardSliceView mKeyguardSliceView;
@@ -47,6 +48,7 @@ public class KeyguardSliceViewTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
mKeyguardSliceView = (KeyguardSliceView) LayoutInflater.from(getContext())
.inflate(R.layout.keyguard_status_area, null);
mSliceUri = Uri.parse(KeyguardSliceProvider.KEYGUARD_SLICE_URI);
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
index 9e96df2c30cf..3582ab010413 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardStatusViewTest.java
@@ -20,10 +20,12 @@ import static org.mockito.Mockito.verify;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.LayoutInflater;
import com.android.systemui.SysuiTestCase;
+import com.android.systemui.util.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -32,7 +34,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
@SmallTest
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
@RunWith(AndroidTestingRunner.class)
public class KeyguardStatusViewTest extends SysuiTestCase {
@@ -45,6 +47,7 @@ public class KeyguardStatusViewTest extends SysuiTestCase {
@Before
public void setUp() {
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
mKeyguardStatusView =
(KeyguardStatusView) layoutInflater.inflate(R.layout.keyguard_status_view, null);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
index c180ff8fd30c..948e0014a451 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ExpandHelperTest.java
@@ -16,29 +16,29 @@
package com.android.systemui;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import android.animation.ObjectAnimator;
import android.content.Context;
-import android.support.test.InstrumentationRegistry;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;
+import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
+import com.android.systemui.util.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class ExpandHelperTest extends SysuiTestCase {
private ExpandableNotificationRow mRow;
@@ -47,6 +47,7 @@ public class ExpandHelperTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
Context context = getContext();
mRow = new NotificationTestHelper(context).createRow();
mCallback = mock(ExpandHelper.Callback.class);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java
index a58bc8548bd4..9c5a59243d05 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/SysuiTestCase.java
@@ -29,6 +29,7 @@ import android.testing.LeakCheck;
import android.util.Log;
import com.android.keyguard.KeyguardUpdateMonitor;
+import com.android.systemui.util.Assert;
import org.junit.After;
import org.junit.Before;
@@ -78,6 +79,8 @@ public abstract class SysuiTestCase {
public void SysuiTeardown() {
InstrumentationRegistry.registerInstance(mRealInstrumentation,
InstrumentationRegistry.getArguments());
+ // Reset the assert's main looper.
+ Assert.sMainLooper = Looper.getMainLooper();
}
protected LeakCheck getLeakCheck() {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java
index 368c814f8e0a..e1c481e4ef28 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeMachineTest.java
@@ -28,8 +28,8 @@ import static com.android.systemui.doze.DozeMachine.State.UNINITIALIZED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -40,14 +40,12 @@ import static org.mockito.Mockito.when;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
-import android.view.Display;
+import android.testing.UiThreadTest;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.util.wakelock.WakeLockFake;
-import android.testing.UiThreadTest;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
index 5c8336c8dee1..31fc625d34dd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
@@ -48,7 +48,7 @@ import org.junit.runner.RunWith;
@SmallTest
@Ignore("failing")
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class DozeTriggersTest extends SysuiTestCase {
private DozeTriggers mTriggers;
private DozeMachine mMachine;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
index 095395185f86..c1c80ce4a70a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java
@@ -55,7 +55,7 @@ import java.util.concurrent.TimeUnit;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class KeyguardSliceProviderTest extends SysuiTestCase {
@Mock
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
index 4e24354d9878..bc7d9836d6f8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java
@@ -18,39 +18,32 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-import android.app.FragmentController;
-import android.app.FragmentManagerNonConfig;
+import android.content.Context;
import android.os.Looper;
-import android.support.test.filters.FlakyTest;
+import android.support.test.filters.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.LayoutInflaterBuilder;
+import android.testing.TestableLooper;
+import android.testing.TestableLooper.RunWithLooper;
+import android.view.View;
+import android.widget.FrameLayout;
import com.android.internal.logging.MetricsLogger;
import com.android.keyguard.CarrierText;
import com.android.systemui.Dependency;
import com.android.systemui.R;
-
-import android.os.Parcelable;
-import android.support.test.filters.SmallTest;
-import android.testing.AndroidTestingRunner;
-
import com.android.systemui.SysuiBaseFragmentTest;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.policy.Clock;
import com.android.systemui.statusbar.policy.UserSwitcherController;
-import android.testing.LayoutInflaterBuilder;
-import android.testing.TestableLooper;
-import android.testing.TestableLooper.RunWithLooper;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-import android.content.Context;
-import android.view.View;
-import android.widget.FrameLayout;
-
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
@SmallTest
@Ignore
public class QSFragmentTest extends SysuiBaseFragmentTest {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
index 33b347a66b33..fd31013db429 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.pm.UserInfo;
-import android.os.Looper;
import android.os.UserManager;
import android.provider.Settings;
import android.test.suitebuilder.annotation.SmallTest;
@@ -58,7 +57,7 @@ import org.mockito.Mockito;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class QSSecurityFooterTest extends SysuiTestCase {
private final String MANAGING_ORGANIZATION = "organization";
@@ -76,7 +75,8 @@ public class QSSecurityFooterTest extends SysuiTestCase {
@Before
public void setUp() {
mDependency.injectTestDependency(SecurityController.class, mSecurityController);
- mDependency.injectTestDependency(Dependency.BG_LOOPER, Looper.getMainLooper());
+ mDependency.injectTestDependency(Dependency.BG_LOOPER,
+ TestableLooper.get(this).getLooper());
mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE,
new LayoutInflaterBuilder(mContext)
.replace("ImageView", TestableImageView.class)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSTileHostTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSTileHostTest.java
new file mode 100644
index 000000000000..78700b88d4bc
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSTileHostTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 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;
+
+
+import static junit.framework.TestCase.assertFalse;
+
+import android.support.test.filters.SmallTest;
+import android.testing.AndroidTestingRunner;
+
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+@RunWith(AndroidTestingRunner.class)
+@SmallTest
+public class QSTileHostTest extends SysuiTestCase {
+
+ @Test
+ public void testLoadTileSpecs_emptySetting() {
+ List<String> tiles = QSTileHost.loadTileSpecs(mContext, "");
+ assertFalse(tiles.isEmpty());
+ }
+
+ @Test
+ public void testLoadTileSpecs_nullSetting() {
+ List<String> tiles = QSTileHost.loadTileSpecs(mContext, null);
+ assertFalse(tiles.isEmpty());
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java
index c016a851010a..c6597b9bd534 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/external/TileServicesTest.java
@@ -24,16 +24,15 @@ import android.content.ComponentName;
import android.os.Looper;
import android.service.quicksettings.Tile;
import android.test.suitebuilder.annotation.SmallTest;
-
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.testing.TestableLooper.RunWithLooper;
+
import com.android.systemui.SysuiTestCase;
import com.android.systemui.qs.QSTileHost;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.policy.BluetoothController;
-import android.testing.TestableLooper;
-import android.testing.TestableLooper.RunWithLooper;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -45,7 +44,7 @@ import java.util.ArrayList;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class TileServicesTest extends SysuiTestCase {
private static int NUM_FAKES = TileServices.DEFAULT_MAX_BOUND * 2;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java
index 2e280d336aab..9449e297fcc5 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NonPhoneDependencyTest.java
@@ -50,7 +50,7 @@ import org.mockito.MockitoAnnotations;
*/
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
@Ignore("b/118400112")
public class NonPhoneDependencyTest extends SysuiTestCase {
@Mock private NotificationPresenter mPresenter;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java
index 63ececbe2994..65c04fe4bcd3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java
@@ -16,15 +16,12 @@
package com.android.systemui.statusbar;
-import static junit.framework.Assert.assertTrue;
-
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Notification;
import android.os.Handler;
-import android.os.Looper;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
@@ -45,7 +42,7 @@ import org.mockito.MockitoAnnotations;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class NotificationListenerTest extends SysuiTestCase {
private static final String TEST_PACKAGE_NAME = "test";
private static final int TEST_UID = 0;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java
index 72d6cd8eaeea..520a927d1ab0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java
@@ -46,6 +46,7 @@ import com.android.systemui.statusbar.notification.row.ExpandableView;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.phone.ShadeController;
+import com.android.systemui.util.Assert;
import com.google.android.collect.Lists;
@@ -60,7 +61,7 @@ import java.util.List;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class NotificationViewHierarchyManagerTest extends SysuiTestCase {
@Mock private NotificationPresenter mPresenter;
@Mock private NotificationData mNotificationData;
@@ -79,6 +80,7 @@ public class NotificationViewHierarchyManagerTest extends SysuiTestCase {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
mDependency.injectTestDependency(NotificationLockscreenUserManager.class,
mLockscreenUserManager);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java
index b7aa21b86d33..db2c8780e783 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/AboveShelfObserverTest.java
@@ -19,15 +19,15 @@ package com.android.systemui.statusbar.notification;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.widget.FrameLayout;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;
+import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import org.junit.Assert;
import org.junit.Before;
@@ -36,7 +36,7 @@ import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class AboveShelfObserverTest extends SysuiTestCase {
private AboveShelfObserver mObserver;
@@ -46,6 +46,7 @@ public class AboveShelfObserverTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
mNotificationTestHelper = new NotificationTestHelper(getContext());
mHostLayout = new FrameLayout(getContext());
mObserver = new AboveShelfObserver(mHostLayout);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java
index f94ba95999bf..8e88ed0556bf 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java
@@ -53,6 +53,7 @@ import android.service.notification.StatusBarNotification;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.util.ArraySet;
@@ -78,7 +79,7 @@ import java.util.List;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class NotificationDataTest extends SysuiTestCase {
private static final int UID_NORMAL = 123;
@@ -101,6 +102,7 @@ public class NotificationDataTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
MockitoAnnotations.initMocks(this);
when(mMockStatusBarNotification.getUid()).thenReturn(UID_NORMAL);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java
index 63d1e8dbc954..24aa772e2fc1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationViewWrapperTest.java
@@ -17,28 +17,29 @@
package com.android.systemui.statusbar.notification;
import android.content.Context;
-import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;
+import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper;
+import com.android.systemui.util.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidTestingRunner.class)
@SmallTest
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class NotificationViewWrapperTest extends SysuiTestCase {
@Test
public void constructor_doesntUseViewContext() throws Exception {
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
new TestableNotificationViewWrapper(mContext,
new View(mContext),
new NotificationTestHelper(getContext()).createRow());
@@ -50,4 +51,4 @@ public class NotificationViewWrapperTest extends SysuiTestCase {
super(ctx, view, row);
}
}
-} \ No newline at end of file
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java
index 3710fa833d50..512acd073a84 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java
@@ -37,13 +37,13 @@ import android.testing.TestableLooper;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.SysuiTestCase;
-
-import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationPresenter;
import com.android.systemui.statusbar.notification.NotificationData;
+import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
+
import com.google.android.collect.Lists;
import org.junit.Before;
@@ -58,7 +58,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class NotificationLoggerTest extends SysuiTestCase {
private static final String TEST_PACKAGE_NAME = "test";
private static final int TEST_UID = 0;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
index 2da72e7858c8..6d3553912701 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
@@ -40,6 +40,7 @@ import android.app.AppOpsManager;
import android.app.NotificationChannel;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.util.ArraySet;
import android.view.NotificationHeaderView;
@@ -64,7 +65,7 @@ import java.util.List;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class ExpandableNotificationRowTest extends SysuiTestCase {
private ExpandableNotificationRow mGroupRow;
@@ -77,6 +78,7 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
mNotificationTestHelper = new NotificationTestHelper(mContext);
mGroupRow = mNotificationTestHelper.createGroup();
mGroupRow.setHeadsUpAnimatingAwayListener(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java
index 4efab5385c0a..669b98e1b279 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java
@@ -16,10 +16,18 @@
package com.android.systemui.statusbar.notification.row;
-import com.android.systemui.SysuiTestCase;
-import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
-import com.android.systemui.statusbar.notification.NotificationEntryManager;
-import com.android.systemui.statusbar.NotificationTestHelper;
+import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE;
+import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL;
+import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_POSITIVE;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
import android.support.test.filters.FlakyTest;
@@ -28,30 +36,24 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.View;
+import com.android.systemui.SysuiTestCase;
+import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
+import com.android.systemui.statusbar.NotificationTestHelper;
+import com.android.systemui.statusbar.notification.NotificationEntryManager;
+import com.android.systemui.util.Assert;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE;
-import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL;
-import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_POSITIVE;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
/**
* Tests for {@link NotificationBlockingHelperManager}.
*/
@SmallTest
@FlakyTest
@org.junit.runner.RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
private NotificationBlockingHelperManager mBlockingHelperManager;
@@ -65,6 +67,7 @@ public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
@Before
public void setUp() {
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
MockitoAnnotations.initMocks(this);
when(mGutsManager.openGuts(
any(View.class),
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
index 766c5d2377c6..8966aca3069c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
@@ -64,6 +64,7 @@ import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager.OnSettingsClickListener;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
+import com.android.systemui.util.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -79,7 +80,7 @@ import org.mockito.junit.MockitoRule;
*/
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class NotificationGutsManagerTest extends SysuiTestCase {
private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
@@ -101,6 +102,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase {
@Before
public void setUp() {
mTestableLooper = TestableLooper.get(this);
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
mDependency.injectTestDependency(DeviceProvisionedController.class,
mDeviceProvisionedController);
mHandler = Handler.createAsync(mTestableLooper.getLooper());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java
index 51492da11d02..e4d019656072 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java
@@ -44,7 +44,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
@SmallTest
public class NotificationMenuRowTest extends LeakCheckedTest {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java
index 4b94a2523cfe..fed66af07bcc 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapperTest.java
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification.row.wrapper;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import android.widget.RemoteViews;
@@ -34,13 +35,14 @@ import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class NotificationCustomViewWrapperTest extends SysuiTestCase {
private ExpandableNotificationRow mRow;
@Before
public void setUp() throws Exception {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
mRow = new NotificationTestHelper(mContext).createRow();
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java
index 272845396e27..bbafb4e4a211 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationChildrenContainerTest.java
@@ -18,13 +18,14 @@ package com.android.systemui.statusbar.notification.stack;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.NotificationHeaderView;
import android.view.View;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;
+import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import org.junit.Assert;
import org.junit.Before;
@@ -33,16 +34,16 @@ import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class NotificationChildrenContainerTest extends SysuiTestCase {
private ExpandableNotificationRow mGroup;
- private int mId;
private NotificationTestHelper mNotificationTestHelper;
private NotificationChildrenContainer mChildrenContainer;
@Before
public void setUp() throws Exception {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
mNotificationTestHelper = new NotificationTestHelper(mContext);
mGroup = mNotificationTestHelper.createGroup();
mChildrenContainer = mGroup.getChildrenContainer();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java
index 662e016b77ff..8ae7d52a5da5 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationRoundnessManagerTest.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import com.android.systemui.SysuiTestCase;
@@ -41,7 +42,7 @@ import java.util.HashSet;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class NotificationRoundnessManagerTest extends SysuiTestCase {
private NotificationRoundnessManager mRoundnessManager = new NotificationRoundnessManager();
@@ -52,6 +53,7 @@ public class NotificationRoundnessManagerTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
mFirst = testHelper.createRow();
mFirst.setHeadsUpAnimatingAwayListener(animatingAway
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java
index c99e766ac697..4f6329cb0c57 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpAppearanceControllerTest.java
@@ -23,18 +23,18 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.View;
import android.widget.TextView;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.HeadsUpStatusBarView;
import com.android.systemui.statusbar.NotificationTestHelper;
-import com.android.systemui.statusbar.policy.DarkIconDispatcher;
+import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
+import com.android.systemui.statusbar.policy.DarkIconDispatcher;
import org.junit.Assert;
import org.junit.Before;
@@ -43,7 +43,7 @@ import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
private final NotificationStackScrollLayout mStackScroller =
@@ -58,6 +58,7 @@ public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
mFirst = testHelper.createRow();
mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
index 7f8668fa064c..f7a95c50fee8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
+import android.content.res.ColorStateList;
import android.graphics.Color;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
@@ -35,7 +36,6 @@ import android.testing.TestableLooper;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
-import android.content.res.ColorStateList;
import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardHostView;
@@ -56,7 +56,7 @@ import org.mockito.MockitoAnnotations;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class KeyguardBouncerTest extends SysuiTestCase {
@Mock
@@ -78,6 +78,7 @@ public class KeyguardBouncerTest extends SysuiTestCase {
@Before
public void setup() {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
MockitoAnnotations.initMocks(this);
DejankUtils.setImmediate(true);
final ViewGroup container = new FrameLayout(getContext());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java
index 31014b8a62e9..27ed9c5a14c8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardClockPositionAlgorithmTest.java
@@ -30,7 +30,7 @@ import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
private static final int SCREEN_HEIGHT = 2000;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java
index 54291536093c..c5875554b073 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardPresentationTest.java
@@ -20,21 +20,20 @@ import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.LayoutInflater;
-import android.view.View;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
-import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
public class KeyguardPresentationTest extends SysuiTestCase {
@Test
public void testInflation_doesntCrash() {
+ com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
LayoutInflater inflater = LayoutInflater.from(getContext());
inflater.inflate(R.layout.keyguard_presentation, null);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java
index 1783d0cf2519..cdaa2420186f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java
@@ -29,7 +29,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyFloat;
-import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -38,11 +37,6 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import com.android.systemui.R;
-import com.android.systemui.recents.OverviewProxyService;
-import com.android.systemui.shared.recents.IOverviewProxy;
-import com.android.systemui.SysuiTestCase;
-
import android.content.Context;
import android.content.res.Resources;
import android.support.test.filters.SmallTest;
@@ -51,6 +45,11 @@ import android.testing.TestableLooper.RunWithLooper;
import android.view.MotionEvent;
import android.view.View;
+import com.android.systemui.R;
+import com.android.systemui.SysuiTestCase;
+import com.android.systemui.recents.OverviewProxyService;
+import com.android.systemui.shared.recents.IOverviewProxy;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -59,7 +58,7 @@ import org.mockito.MockitoAnnotations;
/** atest QuickStepControllerTest */
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
@SmallTest
public class QuickStepControllerTest extends SysuiTestCase {
private QuickStepController mController;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
index e9e8eb785d1a..c207feff26f3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
@@ -72,6 +72,8 @@ import com.android.systemui.appops.AppOpsControllerImpl;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.bubbles.BubbleController;
import com.android.systemui.classifier.FalsingManager;
+import com.android.systemui.doze.DozeHost;
+import com.android.systemui.doze.DozeLog;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
@@ -123,6 +125,7 @@ public class StatusBarTest extends SysuiTestCase {
@Mock private IStatusBarService mBarService;
@Mock private IDreamManager mDreamManager;
@Mock private ScrimController mScrimController;
+ @Mock private DozeScrimController mDozeScrimController;
@Mock private ArrayList<Entry> mNotificationList;
@Mock private BiometricUnlockController mBiometricUnlockController;
@Mock private NotificationData mNotificationData;
@@ -211,7 +214,7 @@ public class StatusBarTest extends SysuiTestCase {
mKeyguardViewMediator, mRemoteInputManager, mock(NotificationGroupManager.class),
mock(NotificationGroupAlertTransferHelper.class), mock(FalsingManager.class),
mock(StatusBarWindowController.class), mock(NotificationIconAreaController.class),
- mock(DozeScrimController.class), mock(NotificationShelf.class),
+ mDozeScrimController, mock(NotificationShelf.class),
mLockscreenUserManager, mCommandQueue, mNotificationPresenter,
mock(BubbleController.class));
mStatusBar.mContext = mContext;
@@ -570,7 +573,28 @@ public class StatusBarTest extends SysuiTestCase {
}
@Test
+ public void testPulseWhileDozing_updatesScrimController() {
+ mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD);
+ mStatusBar.showKeyguardImpl();
+
+ // Keep track of callback to be able to stop the pulse
+ DozeHost.PulseCallback[] pulseCallback = new DozeHost.PulseCallback[1];
+ doAnswer(invocation -> {
+ pulseCallback[0] = invocation.getArgument(0);
+ return null;
+ }).when(mDozeScrimController).pulse(any(), anyInt());
+ // Starting a pulse should change the scrim controller to the pulsing state
+ mStatusBar.mDozeServiceHost.pulseWhileDozing(mock(DozeHost.PulseCallback.class),
+ DozeLog.PULSE_REASON_NOTIFICATION);
+ verify(mScrimController).transitionTo(eq(ScrimState.PULSING), any());
+
+ // Ending a pulse should take it back to keyguard state
+ pulseCallback[0].onPulseFinished();
+ verify(mScrimController).transitionTo(eq(ScrimState.KEYGUARD));
+ }
+
+ @Test
public void testSetState_changesIsFullScreenUserSwitcherState() {
mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD);
assertFalse(mStatusBar.isFullScreenUserSwitcherState());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java
index dcd531dc9eb7..090963be7ac7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java
@@ -15,6 +15,7 @@
package com.android.systemui.statusbar.phone;
import static junit.framework.Assert.assertTrue;
+
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -35,7 +36,7 @@ import org.mockito.ArgumentCaptor;
@RunWith(AndroidTestingRunner.class)
-@RunWithLooper(setAsMainLooper = true)
+@RunWithLooper
@SmallTest
public class SystemUIDialogTest extends SysuiTestCase {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java
index 3164c0469c40..b3ac6be65d36 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RemoteInputViewTest.java
@@ -32,9 +32,10 @@ import android.widget.ImageButton;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
-import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationTestHelper;
import com.android.systemui.statusbar.RemoteInputController;
+import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
+import com.android.systemui.util.Assert;
import org.junit.After;
import org.junit.Before;
@@ -44,7 +45,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@RunWith(AndroidTestingRunner.class)
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
@SmallTest
public class RemoteInputViewTest extends SysuiTestCase {
@@ -60,6 +61,7 @@ public class RemoteInputViewTest extends SysuiTestCase {
@Before
public void setUp() throws Exception {
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
MockitoAnnotations.initMocks(this);
mDependency.injectTestDependency(RemoteInputQuickSettingsDisabler.class,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java
index 43942f72993e..ab9b0c979fd3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/util/wakelock/KeepAwakeAnimationListenerTest.java
@@ -20,11 +20,13 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import android.animation.Animator;
+import android.os.Looper;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import com.android.systemui.SysuiTestCase;
+import com.android.systemui.util.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -33,7 +35,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@SmallTest
-@TestableLooper.RunWithLooper(setAsMainLooper = true)
+@TestableLooper.RunWithLooper
@RunWith(AndroidTestingRunner.class)
public class KeepAwakeAnimationListenerTest extends SysuiTestCase {
@Mock WakeLock mWakeLock;
@@ -41,6 +43,7 @@ public class KeepAwakeAnimationListenerTest extends SysuiTestCase {
@Before
public void setup() {
+ Assert.sMainLooper = TestableLooper.get(this).getLooper();
MockitoAnnotations.initMocks(this);
KeepAwakeAnimationListener.sWakeLock = mWakeLock;
mKeepAwakeAnimationListener = new KeepAwakeAnimationListener(getContext());
@@ -55,4 +58,10 @@ public class KeepAwakeAnimationListenerTest extends SysuiTestCase {
mKeepAwakeAnimationListener.onAnimationEnd((Animator) null);
verify(mWakeLock).release();
}
+
+ @Test(expected = IllegalStateException.class)
+ public void initThrows_onNonMainThread() {
+ Assert.sMainLooper = Looper.getMainLooper();
+ new KeepAwakeAnimationListener(getContext());
+ }
}
diff --git a/packages/overlays/AccentColorBlackOverlay/Android.mk b/packages/overlays/AccentColorBlackOverlay/Android.mk
new file mode 100644
index 000000000000..d316fbd8907c
--- /dev/null
+++ b/packages/overlays/AccentColorBlackOverlay/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright 2018, 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.
+#
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_RRO_THEME := AccentColorBlack
+LOCAL_CERTIFICATE := platform
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+
+LOCAL_PACKAGE_NAME := AccentColorBlackOverlay
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_RRO_PACKAGE)
diff --git a/packages/overlays/AccentColorBlackOverlay/AndroidManifest.xml b/packages/overlays/AccentColorBlackOverlay/AndroidManifest.xml
new file mode 100644
index 000000000000..3b99648d20aa
--- /dev/null
+++ b/packages/overlays/AccentColorBlackOverlay/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<!--
+/**
+ * Copyright (c) 2018, 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.
+ */
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.theme.color.black"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <overlay android:targetPackage="android" android:category="android.theme.customization.accent_color" android:priority="1"/>
+
+ <application android:label="@string/accent_color_black_overlay" android:hasCode="false"/>
+</manifest>
diff --git a/packages/overlays/AccentColorBlackOverlay/res/values/colors_device_defaults.xml b/packages/overlays/AccentColorBlackOverlay/res/values/colors_device_defaults.xml
new file mode 100644
index 000000000000..5648f915490b
--- /dev/null
+++ b/packages/overlays/AccentColorBlackOverlay/res/values/colors_device_defaults.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/**
+ * Copyright (c) 2018, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<resources>
+ <color name="accent_device_default_light">#202020</color>
+ <color name="accent_device_default_dark">#FFFFFF</color>
+</resources>
diff --git a/packages/overlays/AccentColorBlackOverlay/res/values/strings.xml b/packages/overlays/AccentColorBlackOverlay/res/values/strings.xml
new file mode 100644
index 000000000000..baf09b11ac07
--- /dev/null
+++ b/packages/overlays/AccentColorBlackOverlay/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Copyright (c) 2018, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Black accent color name application label. [CHAR LIMIT=50] -->
+ <string name="accent_color_black_overlay" translatable="false">Black Accent Color</string>
+</resources>
+
diff --git a/packages/overlays/AccentColorGreenOverlay/Android.mk b/packages/overlays/AccentColorGreenOverlay/Android.mk
new file mode 100644
index 000000000000..afc42873a4d6
--- /dev/null
+++ b/packages/overlays/AccentColorGreenOverlay/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright 2018, 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.
+#
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_RRO_THEME := AccentColorGreen
+LOCAL_CERTIFICATE := platform
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+
+LOCAL_PACKAGE_NAME := AccentColorGreenOverlay
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_RRO_PACKAGE)
diff --git a/packages/overlays/AccentColorGreenOverlay/AndroidManifest.xml b/packages/overlays/AccentColorGreenOverlay/AndroidManifest.xml
new file mode 100644
index 000000000000..609d5be8a758
--- /dev/null
+++ b/packages/overlays/AccentColorGreenOverlay/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<!--
+/**
+ * Copyright (c) 2018, 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.
+ */
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.theme.color.green"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <overlay android:targetPackage="android" android:category="android.theme.customization.accent_color" android:priority="1"/>
+
+ <application android:label="@string/accent_color_green_overlay" android:hasCode="false"/>
+</manifest>
diff --git a/packages/overlays/AccentColorGreenOverlay/res/values/colors_device_defaults.xml b/packages/overlays/AccentColorGreenOverlay/res/values/colors_device_defaults.xml
new file mode 100644
index 000000000000..089f08c6bb19
--- /dev/null
+++ b/packages/overlays/AccentColorGreenOverlay/res/values/colors_device_defaults.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/**
+ * Copyright (c) 2018, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<resources>
+ <color name="accent_device_default_light">#1B873B</color>
+ <color name="accent_device_default_dark">#84C188</color>
+</resources>
diff --git a/packages/overlays/AccentColorGreenOverlay/res/values/strings.xml b/packages/overlays/AccentColorGreenOverlay/res/values/strings.xml
new file mode 100644
index 000000000000..4de344cbb65e
--- /dev/null
+++ b/packages/overlays/AccentColorGreenOverlay/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Copyright (c) 2018, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Green accent color name application label. [CHAR LIMIT=50] -->
+ <string name="accent_color_green_overlay" translatable="false">Green Accent Color</string>
+</resources>
+
diff --git a/packages/overlays/AccentColorPurpleOverlay/Android.mk b/packages/overlays/AccentColorPurpleOverlay/Android.mk
new file mode 100644
index 000000000000..336616921d71
--- /dev/null
+++ b/packages/overlays/AccentColorPurpleOverlay/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright 2018, 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.
+#
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_RRO_THEME := AccentColorPurple
+LOCAL_CERTIFICATE := platform
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+
+LOCAL_PACKAGE_NAME := AccentColorPurpleOverlay
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_RRO_PACKAGE)
diff --git a/packages/overlays/AccentColorPurpleOverlay/AndroidManifest.xml b/packages/overlays/AccentColorPurpleOverlay/AndroidManifest.xml
new file mode 100644
index 000000000000..497a35815554
--- /dev/null
+++ b/packages/overlays/AccentColorPurpleOverlay/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<!--
+/**
+ * Copyright (c) 2018, 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.
+ */
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.theme.color.purple"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <overlay android:targetPackage="android" android:category="android.theme.customization.accent_color" android:priority="1"/>
+
+ <application android:label="@string/accent_color_purple_overlay" android:hasCode="false"/>
+</manifest>
diff --git a/packages/overlays/AccentColorPurpleOverlay/res/values/colors_device_defaults.xml b/packages/overlays/AccentColorPurpleOverlay/res/values/colors_device_defaults.xml
new file mode 100644
index 000000000000..7e34bac3d9fb
--- /dev/null
+++ b/packages/overlays/AccentColorPurpleOverlay/res/values/colors_device_defaults.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/**
+ * Copyright (c) 2018, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<resources>
+ <color name="accent_device_default_light">#725AFF</color>
+ <color name="accent_device_default_dark">#B5A9FC</color>
+</resources>
diff --git a/packages/overlays/AccentColorPurpleOverlay/res/values/strings.xml b/packages/overlays/AccentColorPurpleOverlay/res/values/strings.xml
new file mode 100644
index 000000000000..d1eb95a940ac
--- /dev/null
+++ b/packages/overlays/AccentColorPurpleOverlay/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Copyright (c) 2018, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Purple accent color name application label. [CHAR LIMIT=50] -->
+ <string name="accent_color_purple_overlay" translatable="false">Purple Accent Color</string>
+</resources>
+
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
index 0da07ae52857..944ee3390150 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java
@@ -70,10 +70,10 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.IResultReceiver;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.Preconditions;
-import com.android.server.AbstractMasterSystemService;
import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.autofill.ui.AutoFillUI;
+import com.android.server.infra.AbstractMasterSystemService;
import com.android.server.intelligence.IntelligenceManagerInternal;
import java.io.FileDescriptor;
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
index 18bc856700f7..1f229cd2a157 100644
--- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
+++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java
@@ -70,11 +70,11 @@ import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.server.AbstractPerUserSystemService;
import com.android.server.LocalServices;
import com.android.server.autofill.AutofillManagerService.AutofillCompatState;
import com.android.server.autofill.AutofillManagerService.SmartSuggestionMode;
import com.android.server.autofill.ui.AutoFillUI;
+import com.android.server.infra.AbstractPerUserSystemService;
import java.io.PrintWriter;
import java.util.ArrayList;
diff --git a/services/autofill/java/com/android/server/autofill/RemoteFillService.java b/services/autofill/java/com/android/server/autofill/RemoteFillService.java
index af6575954842..4b7d29025730 100644
--- a/services/autofill/java/com/android/server/autofill/RemoteFillService.java
+++ b/services/autofill/java/com/android/server/autofill/RemoteFillService.java
@@ -40,7 +40,7 @@ import android.service.autofill.SaveRequest;
import android.text.format.DateUtils;
import android.util.Slog;
-import com.android.server.AbstractSinglePendingRequestRemoteService;
+import com.android.server.infra.AbstractSinglePendingRequestRemoteService;
final class RemoteFillService extends AbstractSinglePendingRequestRemoteService<RemoteFillService> {
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 4c645076eb95..fb64cb28619d 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -95,10 +95,10 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.ArrayUtils;
-import com.android.server.AbstractRemoteService;
import com.android.server.autofill.AutofillManagerService.SmartSuggestionMode;
import com.android.server.autofill.ui.AutoFillUI;
import com.android.server.autofill.ui.PendingUi;
+import com.android.server.infra.AbstractRemoteService;
import com.android.server.intelligence.IntelligenceManagerInternal;
import com.android.server.intelligence.IntelligenceManagerInternal.AugmentedAutofillCallback;
@@ -2579,11 +2579,13 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
+ " when server returned null for session " + this.id);
}
+ final AutofillValue currentValue = mViewStates.get(mCurrentViewId).getCurrentValue();
+
// TODO(b/111330312): we might need to add a new state in the AutofillManager to optimize
// furgher AFM -> AFMS calls.
// TODO(b/119638958): add CTS tests
return intelligenceManagerInternal.requestAutofill(mService.getUserId(), mClient,
- mActivityToken, this.id, mCurrentViewId);
+ mActivityToken, this.id, mCurrentViewId, currentValue);
}
@GuardedBy("mLock")
diff --git a/services/core/java/com/android/server/BinderCallsStatsService.java b/services/core/java/com/android/server/BinderCallsStatsService.java
index 81f0259bfd71..11a2fc9c1e45 100644
--- a/services/core/java/com/android/server/BinderCallsStatsService.java
+++ b/services/core/java/com/android/server/BinderCallsStatsService.java
@@ -16,23 +16,33 @@
package com.android.server;
+import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
+import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
+
import android.app.AppGlobals;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Binder;
+import android.os.Process;
import android.os.RemoteException;
import android.os.SystemProperties;
+import android.os.ThreadLocalWorkSource;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.ArrayMap;
+import android.util.ArraySet;
import android.util.KeyValueListParser;
import android.util.Slog;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.BackgroundThread;
import com.android.internal.os.BinderCallsStats;
+import com.android.internal.os.BinderInternal;
+import com.android.internal.os.BinderInternal.CallSession;
import com.android.internal.os.CachedDeviceState;
import java.io.FileDescriptor;
@@ -49,6 +59,106 @@ public class BinderCallsStatsService extends Binder {
private static final String PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING
= "persist.sys.binder_calls_detailed_tracking";
+ /** Resolves the work source of an incoming binder transaction. */
+ static class WorkSourceProvider {
+ private ArraySet<Integer> mAppIdWhitelist;
+
+ WorkSourceProvider() {
+ mAppIdWhitelist = new ArraySet<>();
+ }
+
+ public int resolveWorkSourceUid() {
+ final int callingUid = getCallingUid();
+ final int appId = UserHandle.getAppId(callingUid);
+ if (mAppIdWhitelist.contains(appId)) {
+ final int workSource = getCallingWorkSourceUid();
+ final boolean isWorkSourceSet = workSource != Binder.UNSET_WORKSOURCE;
+ return isWorkSourceSet ? workSource : callingUid;
+ }
+ return callingUid;
+ }
+
+ public void systemReady(Context context) {
+ mAppIdWhitelist = createAppidWhitelist(context);
+ }
+
+ public void dump(PrintWriter pw, Map<Integer, String> appIdToPackageName) {
+ pw.println("AppIds of apps that can set the work source:");
+ final ArraySet<Integer> whitelist = mAppIdWhitelist;
+ for (Integer appId : whitelist) {
+ pw.println("\t- " + appIdToPackageName.getOrDefault(appId, String.valueOf(appId)));
+ }
+ }
+
+ protected int getCallingUid() {
+ return Binder.getCallingUid();
+ }
+
+ protected int getCallingWorkSourceUid() {
+ return Binder.getCallingWorkSourceUid();
+ }
+
+ private ArraySet<Integer> createAppidWhitelist(Context context) {
+ // Use a local copy instead of mAppIdWhitelist to prevent concurrent read access.
+ final ArraySet<Integer> whitelist = new ArraySet<>();
+
+ // We trust our own process.
+ whitelist.add(Process.myUid());
+ // We only need to initialize it once. UPDATE_DEVICE_STATS is a system permission.
+ final PackageManager pm = context.getPackageManager();
+ final String[] permissions = { android.Manifest.permission.UPDATE_DEVICE_STATS };
+ final int queryFlags = MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE;
+ final List<PackageInfo> packages =
+ pm.getPackagesHoldingPermissions(permissions, queryFlags);
+ final int packagesSize = packages.size();
+ for (int i = 0; i < packagesSize; i++) {
+ final PackageInfo pkgInfo = packages.get(i);
+ try {
+ final int uid = pm.getPackageUid(pkgInfo.packageName, queryFlags);
+ final int appId = UserHandle.getAppId(uid);
+ whitelist.add(appId);
+ } catch (NameNotFoundException e) {
+ Slog.e(TAG, "Cannot find uid for package name " + pkgInfo.packageName, e);
+ }
+ }
+ return whitelist;
+ }
+ }
+
+ /** Observer for all system server incoming binder transactions. */
+ @VisibleForTesting
+ static class BinderCallsObserver implements BinderInternal.Observer {
+ private final BinderInternal.Observer mBinderCallsStats;
+ private final WorkSourceProvider mWorkSourceProvider;
+
+ BinderCallsObserver(BinderInternal.Observer callsStats,
+ WorkSourceProvider workSourceProvider) {
+ mBinderCallsStats = callsStats;
+ mWorkSourceProvider = workSourceProvider;
+ }
+
+ @Override
+ public CallSession callStarted(Binder binder, int code) {
+ // We depend on the code in Binder#execTransact to reset the state of
+ // ThreadLocalWorkSource
+ setThreadLocalWorkSourceUid(mWorkSourceProvider.resolveWorkSourceUid());
+ return mBinderCallsStats.callStarted(binder, code);
+ }
+
+ @Override
+ public void callEnded(CallSession s, int parcelRequestSize, int parcelReplySize) {
+ mBinderCallsStats.callEnded(s, parcelRequestSize, parcelReplySize);
+ }
+
+ @Override
+ public void callThrewException(CallSession s, Exception exception) {
+ mBinderCallsStats.callThrewException(s, exception);
+ }
+
+ protected void setThreadLocalWorkSourceUid(int uid) {
+ ThreadLocalWorkSource.setUid(uid);
+ }
+ }
/** Listens for flag changes. */
private static class SettingsObserver extends ContentObserver {
@@ -63,13 +173,16 @@ public class BinderCallsStatsService extends Binder {
private final Context mContext;
private final KeyValueListParser mParser = new KeyValueListParser(',');
private final BinderCallsStats mBinderCallsStats;
+ private final BinderCallsObserver mBinderCallsObserver;
- public SettingsObserver(Context context, BinderCallsStats binderCallsStats) {
+ SettingsObserver(Context context, BinderCallsStats binderCallsStats,
+ BinderCallsObserver observer) {
super(BackgroundThread.getHandler());
mContext = context;
context.getContentResolver().registerContentObserver(mUri, false, this,
UserHandle.USER_SYSTEM);
mBinderCallsStats = binderCallsStats;
+ mBinderCallsObserver = observer;
// Always kick once to ensure that we match current state
onChange();
}
@@ -107,7 +220,7 @@ public class BinderCallsStatsService extends Binder {
mParser.getBoolean(SETTINGS_ENABLED_KEY, BinderCallsStats.ENABLED_DEFAULT);
if (mEnabled != enabled) {
if (enabled) {
- Binder.setObserver(mBinderCallsStats);
+ Binder.setObserver(mBinderCallsObserver);
Binder.setProxyTransactListener(
new Binder.PropagateWorkSourceTransactListener());
} else {
@@ -155,6 +268,7 @@ public class BinderCallsStatsService extends Binder {
public static class LifeCycle extends SystemService {
private BinderCallsStatsService mService;
private BinderCallsStats mBinderCallsStats;
+ private WorkSourceProvider mWorkSourceProvider;
public LifeCycle(Context context) {
super(context);
@@ -163,7 +277,11 @@ public class BinderCallsStatsService extends Binder {
@Override
public void onStart() {
mBinderCallsStats = new BinderCallsStats(new BinderCallsStats.Injector());
- mService = new BinderCallsStatsService(mBinderCallsStats);
+ mWorkSourceProvider = new WorkSourceProvider();
+ BinderCallsObserver binderCallsObserver =
+ new BinderCallsObserver(mBinderCallsStats, mWorkSourceProvider);
+ mService = new BinderCallsStatsService(
+ mBinderCallsStats, binderCallsObserver, mWorkSourceProvider);
publishLocalService(Internal.class, new Internal(mBinderCallsStats));
publishBinderService("binder_calls_stats", mService);
boolean detailedTrackingEnabled = SystemProperties.getBoolean(
@@ -182,21 +300,29 @@ public class BinderCallsStatsService extends Binder {
if (SystemService.PHASE_SYSTEM_SERVICES_READY == phase) {
CachedDeviceState.Readonly deviceState = getLocalService(
CachedDeviceState.Readonly.class);
- mService.systemReady(getContext());
mBinderCallsStats.setDeviceState(deviceState);
+ // It needs to be called before mService.systemReady to make sure the observer is
+ // initialized before installing it.
+ mWorkSourceProvider.systemReady(getContext());
+ mService.systemReady(getContext());
}
}
}
private SettingsObserver mSettingsObserver;
private final BinderCallsStats mBinderCallsStats;
+ private final BinderCallsObserver mBinderCallsObserver;
+ private final WorkSourceProvider mWorkSourceProvider;
- BinderCallsStatsService(BinderCallsStats binderCallsStats) {
+ BinderCallsStatsService(BinderCallsStats binderCallsStats, BinderCallsObserver observer,
+ WorkSourceProvider workSourceProvider) {
mBinderCallsStats = binderCallsStats;
+ mBinderCallsObserver = observer;
+ mWorkSourceProvider = workSourceProvider;
}
public void systemReady(Context context) {
- mSettingsObserver = new SettingsObserver(context, mBinderCallsStats);
+ mSettingsObserver = new SettingsObserver(context, mBinderCallsStats, mBinderCallsObserver);
}
public void reset() {
@@ -216,7 +342,7 @@ public class BinderCallsStatsService extends Binder {
pw.println("binder_calls_stats reset.");
return;
} else if ("--enable".equals(arg)) {
- Binder.setObserver(mBinderCallsStats);
+ Binder.setObserver(mBinderCallsObserver);
return;
} else if ("--disable".equals(arg)) {
Binder.setObserver(null);
@@ -234,6 +360,9 @@ public class BinderCallsStatsService extends Binder {
mBinderCallsStats.setDetailedTracking(false);
pw.println("Detailed tracking disabled");
return;
+ } else if ("--dump-worksource-provider".equals(arg)) {
+ mWorkSourceProvider.dump(pw, getAppIdToPackagesMap());
+ return;
} else if ("-h".equals(arg)) {
pw.println("binder_calls_stats commands:");
pw.println(" --reset: Reset stats");
@@ -272,5 +401,4 @@ public class BinderCallsStatsService extends Binder {
}
return map;
}
-
}
diff --git a/services/core/java/com/android/server/RuntimeService.java b/services/core/java/com/android/server/RuntimeService.java
index ccfac80d22a7..bb39ccc52af2 100644
--- a/services/core/java/com/android/server/RuntimeService.java
+++ b/services/core/java/com/android/server/RuntimeService.java
@@ -94,7 +94,7 @@ public class RuntimeService extends Binder {
// Add /data tz data set using the DistroVersion class (which libcore cannot use).
// This update mechanism will be removed after the time zone APEX is launched so this
// untidiness will disappear with it.
- String debugKeyPrefix = "core_library.timezone.data_";
+ String debugKeyPrefix = "core_library.timezone.source.data_";
String versionFileName = TimeZoneDataFiles.getDataTimeZoneFile(
TimeZoneDistro.DISTRO_VERSION_FILE_NAME);
addDistroVersionDebugInfo(versionFileName, debugKeyPrefix, coreLibraryDebugInfo);
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index 390126c63ab8..dbea529b72fe 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -16,6 +16,8 @@
package com.android.server;
+import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
+import static android.os.ParcelFileDescriptor.MODE_READ_WRITE;
import static android.os.storage.OnObbStateChangeListener.ERROR_ALREADY_MOUNTED;
import static android.os.storage.OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT;
import static android.os.storage.OnObbStateChangeListener.ERROR_COULD_NOT_UNMOUNT;
@@ -2758,6 +2760,14 @@ class StorageManagerService extends IStorageManager.Stub
public @Nullable ParcelFileDescriptor openProxyFileDescriptor(
int mountId, int fileId, int mode) {
Slog.v(TAG, "mountProxyFileDescriptor");
+
+ // We only support a narrow set of incoming mode flags
+ if ((mode & MODE_READ_WRITE) == MODE_READ_WRITE) {
+ mode = MODE_READ_WRITE;
+ } else {
+ mode = MODE_READ_ONLY;
+ }
+
try {
synchronized (mAppFuseLock) {
if (mAppFuseBridge == null) {
diff --git a/services/core/java/com/android/server/am/ActiveInstrumentation.java b/services/core/java/com/android/server/am/ActiveInstrumentation.java
index 8cd9d1881639..15de3def913a 100644
--- a/services/core/java/com/android/server/am/ActiveInstrumentation.java
+++ b/services/core/java/com/android/server/am/ActiveInstrumentation.java
@@ -133,7 +133,7 @@ class ActiveInstrumentation {
proto.write(ActiveInstrumentationProto.TARGET_PROCESSES, p);
}
if (mTargetInfo != null) {
- mTargetInfo.writeToProto(proto, ActiveInstrumentationProto.TARGET_INFO);
+ mTargetInfo.writeToProto(proto, ActiveInstrumentationProto.TARGET_INFO, 0);
}
proto.write(ActiveInstrumentationProto.PROFILE_FILE, mProfileFile);
proto.write(ActiveInstrumentationProto.WATCHER, mWatcher.toString());
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index a19e9287aa6c..23287cf399ca 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -1801,16 +1801,25 @@ public final class ActiveServices {
for (int i = clist.size() - 1; i >= 0; i--) {
final ConnectionRecord crec = clist.get(i);
final ServiceRecord srec = crec.binding.service;
- if (srec != null && srec.app != null
- && (srec.serviceInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) != 0) {
- if (group > 0) {
- srec.app.connectionService = srec;
- srec.app.connectionGroup = group;
- srec.app.connectionImportance = importance;
+ if (srec != null && (srec.serviceInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) != 0) {
+ if (srec.app != null) {
+ if (group > 0) {
+ srec.app.connectionService = srec;
+ srec.app.connectionGroup = group;
+ srec.app.connectionImportance = importance;
+ } else {
+ srec.app.connectionService = null;
+ srec.app.connectionGroup = 0;
+ srec.app.connectionImportance = 0;
+ }
} else {
- srec.app.connectionService = null;
- srec.app.connectionGroup = 0;
- srec.app.connectionImportance = 0;
+ if (group > 0) {
+ srec.pendingConnectionGroup = group;
+ srec.pendingConnectionImportance = importance;
+ } else {
+ srec.pendingConnectionGroup = 0;
+ srec.pendingConnectionImportance = 0;
+ }
}
}
}
@@ -2058,8 +2067,8 @@ public final class ActiveServices {
sInfo.applicationInfo.uid, name.getPackageName(),
name.getClassName());
}
- r = new ServiceRecord(mAm, ss, className, name, filter, sInfo, callingFromFg,
- res);
+ r = new ServiceRecord(mAm, ss, className, name, filter, sInfo,
+ callingFromFg, res);
res.setService(r);
smap.mServicesByInstanceName.put(name, r);
smap.mServicesByIntent.put(filter, r);
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 8842f4198206..c16f1db5c579 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -9209,6 +9209,19 @@ public class ActivityManagerService extends IActivityManager.Stub
}
sdumper.dumpWithClient();
}
+ if (dumpPackage == null) {
+ // Intentionally dropping the lock for this, because dumpBinderProxies() will make many
+ // outgoing binder calls to retrieve interface descriptors; while that is system code,
+ // there is nothing preventing an app from overriding this implementation by talking to
+ // the binder driver directly, and hang up system_server in the process. So, dump
+ // without locks held, and even then only when there is an unreasonably large number of
+ // proxies in the first place.
+ pw.println();
+ if (dumpAll) {
+ pw.println("-------------------------------------------------------------------------------");
+ }
+ dumpBinderProxies(pw, BINDER_PROXY_HIGH_WATERMARK /* minToDump */);
+ }
synchronized(this) {
pw.println();
if (dumpAll) {
@@ -9274,19 +9287,6 @@ public class ActivityManagerService extends IActivityManager.Stub
}
dumpProcessesLocked(fd, pw, args, opti, dumpAll, dumpPackage, dumpAppId);
}
- if (dumpPackage == null) {
- // Intentionally dropping the lock for this, because dumpBinderProxies() will make many
- // outgoing binder calls to retrieve interface descriptors; while that is system code,
- // there is nothing preventing an app from overriding this implementation by talking to
- // the binder driver directly, and hang up system_server in the process. So, dump
- // without locks held, and even then only when there is an unreasonably large number of
- // proxies in the first place.
- pw.println();
- if (dumpAll) {
- pw.println("-------------------------------------------------------------------------------");
- }
- dumpBinderProxies(pw, BINDER_PROXY_HIGH_WATERMARK /* minToDump */);
- }
}
/**
@@ -10266,7 +10266,8 @@ public class ActivityManagerService extends IActivityManager.Stub
if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
continue;
}
- r.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.PROCS);
+ r.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.PROCS, mProcessList.mLruProcesses.indexOf(r)
+ );
if (r.isPersistent()) {
numPers++;
}
@@ -10278,7 +10279,9 @@ public class ActivityManagerService extends IActivityManager.Stub
if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
continue;
}
- r.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.ISOLATED_PROCS);
+ r.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.ISOLATED_PROCS,
+ mProcessList.mLruProcesses.indexOf(r)
+ );
}
for (int i=0; i<mActiveInstrumentation.size(); i++) {
@@ -10376,7 +10379,7 @@ public class ActivityManagerService extends IActivityManager.Stub
writeProcessesToGcToProto(proto, ActivityManagerServiceDumpProcessesProto.GC_PROCS, dumpPackage);
mAppErrors.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.APP_ERRORS, dumpPackage);
- mAtmInternal.writeProcessesToProto(proto, dumpPackage);
+ mAtmInternal.writeProcessesToProto(proto, dumpPackage, mWakefulness, mTestPssMode);
if (dumpPackage == null) {
mUserController.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.USER_CONTROLLER);
@@ -10406,14 +10409,6 @@ public class ActivityManagerService extends IActivityManager.Stub
}
}
- if (dumpPackage == null) {
- final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS);
- proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS,
- PowerManagerInternal.wakefulnessToProtoEnum(mWakefulness));
- proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE, mTestPssMode);
- proto.end(sleepToken);
- }
-
if (mDebugApp != null || mOrigDebugApp != null || mDebugTransient
|| mOrigWaitForDebugger) {
if (dumpPackage == null || dumpPackage.equals(mDebugApp)
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 62f100926581..8cf9f1e9ae4a 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -537,40 +537,44 @@ public final class ProcessList {
}
private static String buildOomTag(String prefix, String space, int val, int base) {
- if (val == base) {
+ final int diff = val - base;
+ if (diff == 0) {
if (space == null) return prefix;
- return prefix + " ";
+ return prefix + space;
}
- return prefix + "+" + Integer.toString(val - base);
+ if (diff < 10) {
+ return prefix + "+ " + Integer.toString(diff);
+ }
+ return prefix + "+" + Integer.toString(diff);
}
public static String makeOomAdjString(int setAdj) {
if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
- return buildOomTag("cch", " ", setAdj, ProcessList.CACHED_APP_MIN_ADJ);
+ return buildOomTag("cch", " ", setAdj, ProcessList.CACHED_APP_MIN_ADJ);
} else if (setAdj >= ProcessList.SERVICE_B_ADJ) {
- return buildOomTag("svcb ", null, setAdj, ProcessList.SERVICE_B_ADJ);
+ return buildOomTag("svcb ", null, setAdj, ProcessList.SERVICE_B_ADJ);
} else if (setAdj >= ProcessList.PREVIOUS_APP_ADJ) {
- return buildOomTag("prev ", null, setAdj, ProcessList.PREVIOUS_APP_ADJ);
+ return buildOomTag("prev ", null, setAdj, ProcessList.PREVIOUS_APP_ADJ);
} else if (setAdj >= ProcessList.HOME_APP_ADJ) {
- return buildOomTag("home ", null, setAdj, ProcessList.HOME_APP_ADJ);
+ return buildOomTag("home ", null, setAdj, ProcessList.HOME_APP_ADJ);
} else if (setAdj >= ProcessList.SERVICE_ADJ) {
- return buildOomTag("svc ", null, setAdj, ProcessList.SERVICE_ADJ);
+ return buildOomTag("svc ", null, setAdj, ProcessList.SERVICE_ADJ);
} else if (setAdj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
- return buildOomTag("hvy ", null, setAdj, ProcessList.HEAVY_WEIGHT_APP_ADJ);
+ return buildOomTag("hvy ", null, setAdj, ProcessList.HEAVY_WEIGHT_APP_ADJ);
} else if (setAdj >= ProcessList.BACKUP_APP_ADJ) {
- return buildOomTag("bkup ", null, setAdj, ProcessList.BACKUP_APP_ADJ);
+ return buildOomTag("bkup ", null, setAdj, ProcessList.BACKUP_APP_ADJ);
} else if (setAdj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
- return buildOomTag("prcp ", null, setAdj, ProcessList.PERCEPTIBLE_APP_ADJ);
+ return buildOomTag("prcp ", null, setAdj, ProcessList.PERCEPTIBLE_APP_ADJ);
} else if (setAdj >= ProcessList.VISIBLE_APP_ADJ) {
- return buildOomTag("vis ", null, setAdj, ProcessList.VISIBLE_APP_ADJ);
+ return buildOomTag("vis", " ", setAdj, ProcessList.VISIBLE_APP_ADJ);
} else if (setAdj >= ProcessList.FOREGROUND_APP_ADJ) {
- return buildOomTag("fore ", null, setAdj, ProcessList.FOREGROUND_APP_ADJ);
+ return buildOomTag("fore ", null, setAdj, ProcessList.FOREGROUND_APP_ADJ);
} else if (setAdj >= ProcessList.PERSISTENT_SERVICE_ADJ) {
- return buildOomTag("psvc ", null, setAdj, ProcessList.PERSISTENT_SERVICE_ADJ);
+ return buildOomTag("psvc ", null, setAdj, ProcessList.PERSISTENT_SERVICE_ADJ);
} else if (setAdj >= ProcessList.PERSISTENT_PROC_ADJ) {
- return buildOomTag("pers ", null, setAdj, ProcessList.PERSISTENT_PROC_ADJ);
+ return buildOomTag("pers ", null, setAdj, ProcessList.PERSISTENT_PROC_ADJ);
} else if (setAdj >= ProcessList.SYSTEM_ADJ) {
- return buildOomTag("sys ", null, setAdj, ProcessList.SYSTEM_ADJ);
+ return buildOomTag("sys ", null, setAdj, ProcessList.SYSTEM_ADJ);
} else if (setAdj >= ProcessList.NATIVE_ADJ) {
return buildOomTag("ntv ", null, setAdj, ProcessList.NATIVE_ADJ);
} else {
@@ -2237,6 +2241,191 @@ public final class ProcessList {
return index;
}
+ /**
+ * Handle the case where we are inserting a process hosting client activities:
+ * Make sure any groups have their order match their importance, and take care of
+ * distributing old clients across other activity processes so they can't spam
+ * the LRU list. Processing of the list will be restricted by the indices provided,
+ * and not extend out of them.
+ *
+ * @param topApp The app at the top that has just been inserted in to the list.
+ * @param topI The position in the list where topApp was inserted; this is the start (at the
+ * top) where we are going to do our processing.
+ * @param bottomI The last position at which we will be processing; this is the end position
+ * of whichever section of the LRU list we are in. Nothing past it will be
+ * touched.
+ * @param endIndex The current end of the top being processed. Typically topI - 1. That is,
+ * where we are going to start potentially adjusting other entries in the list.
+ */
+ private void updateClientActivitiesOrdering(final ProcessRecord topApp, final int topI,
+ final int bottomI, int endIndex) {
+ if (topApp.hasActivitiesOrRecentTasks() || topApp.treatLikeActivity
+ || !topApp.hasClientActivities()) {
+ // If this is not a special process that has client activities, then there is
+ // nothing to do.
+ return;
+ }
+
+ final int uid = topApp.info.uid;
+ if (topApp.connectionGroup > 0) {
+ int endImportance = topApp.connectionImportance;
+ for (int i = endIndex; i >= bottomI; i--) {
+ final ProcessRecord subProc = mLruProcesses.get(i);
+ if (subProc.info.uid == uid
+ && subProc.connectionGroup == topApp.connectionGroup) {
+ if (i == endIndex && subProc.connectionImportance >= endImportance) {
+ // This process is already in the group, and its importance
+ // is not as strong as the process before it, so keep it
+ // correctly positioned in the group.
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Keeping in-place above " + subProc
+ + " endImportance=" + endImportance
+ + " group=" + subProc.connectionGroup
+ + " importance=" + subProc.connectionImportance);
+ endIndex--;
+ endImportance = subProc.connectionImportance;
+ } else {
+ // We want to pull this up to be with the rest of the group,
+ // and order within the group by importance.
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Pulling up " + subProc
+ + " to position in group with importance="
+ + subProc.connectionImportance);
+ boolean moved = false;
+ for (int pos = topI; pos > endIndex; pos--) {
+ final ProcessRecord posProc = mLruProcesses.get(pos);
+ if (subProc.connectionImportance
+ <= posProc.connectionImportance) {
+ mLruProcesses.remove(i);
+ mLruProcesses.add(pos, subProc);
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Moving " + subProc
+ + " from position " + i + " to above " + posProc
+ + " @ " + pos);
+ moved = true;
+ endIndex--;
+ break;
+ }
+ }
+ if (!moved) {
+ // Goes to the end of the group.
+ mLruProcesses.remove(i);
+ mLruProcesses.add(endIndex - 1, subProc);
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Moving " + subProc
+ + " from position " + i + " to end of group @ "
+ + endIndex);
+ endIndex--;
+ endImportance = subProc.connectionImportance;
+ }
+ }
+ }
+ }
+
+ }
+ // To keep it from spamming the LRU list (by making a bunch of clients),
+ // we will distribute other entries owned by it to be in-between other apps.
+ int i = endIndex;
+ while (i >= bottomI) {
+ ProcessRecord subProc = mLruProcesses.get(i);
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Looking to spread old procs, at " + subProc + " @ " + i);
+ if (subProc.info.uid != uid) {
+ // This is a different app... if we have gone through some of the
+ // target app, pull this up to be before them. We want to pull up
+ // one activity process, but any number of non-activity processes.
+ if (i < endIndex) {
+ boolean hasActivity = false;
+ int connUid = 0;
+ int connGroup = 0;
+ while (i >= bottomI) {
+ mLruProcesses.remove(i);
+ mLruProcesses.add(endIndex, subProc);
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Different app, moving to " + endIndex);
+ i--;
+ if (i < bottomI) {
+ break;
+ }
+ subProc = mLruProcesses.get(i);
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Looking at next app at " + i + ": " + subProc);
+ if (subProc.hasActivitiesOrRecentTasks() || subProc.treatLikeActivity) {
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "This is hosting an activity!");
+ if (hasActivity) {
+ // Already found an activity, done.
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Already found an activity, done");
+ break;
+ }
+ hasActivity = true;
+ } else if (subProc.hasClientActivities()) {
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "This is a client of an activity");
+ if (hasActivity) {
+ if (connUid == 0 || connUid != subProc.info.uid) {
+ // Already have an activity that is not from from a client
+ // connection or is a different client connection, done.
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Already found a different activity: connUid="
+ + connUid + " uid=" + subProc.info.uid);
+ break;
+ } else if (connGroup == 0 || connGroup != subProc.connectionGroup) {
+ // Previously saw a different group or not from a group,
+ // want to treat these as different things.
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Already found a different group: connGroup="
+ + connGroup + " group=" + subProc.connectionGroup);
+ break;
+ }
+ } else {
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "This is an activity client! uid="
+ + subProc.info.uid + " group=" + subProc.connectionGroup);
+ hasActivity = true;
+ connUid = subProc.info.uid;
+ connGroup = subProc.connectionGroup;
+ }
+ }
+ endIndex--;
+ }
+ }
+ // Find the end of the next group of processes for target app. This
+ // is after any entries of different apps (so we don't change the existing
+ // relative order of apps) and then after the next last group of processes
+ // of the target app.
+ for (endIndex--; endIndex >= bottomI; endIndex--) {
+ final ProcessRecord endProc = mLruProcesses.get(endIndex);
+ if (endProc.info.uid == uid) {
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Found next group of app: " + endProc + " @ "
+ + endIndex);
+ break;
+ }
+ }
+ if (endIndex >= bottomI) {
+ final ProcessRecord endProc = mLruProcesses.get(endIndex);
+ for (endIndex--; endIndex >= bottomI; endIndex--) {
+ final ProcessRecord nextEndProc = mLruProcesses.get(endIndex);
+ if (nextEndProc.info.uid != uid
+ || nextEndProc.connectionGroup != endProc.connectionGroup) {
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Found next group or app: " + nextEndProc + " @ "
+ + endIndex + " group=" + nextEndProc.connectionGroup);
+ break;
+ }
+ }
+ }
+ if (DEBUG_LRU) Slog.d(TAG_LRU,
+ "Bumping scan position to " + endIndex);
+ i = endIndex;
+ } else {
+ i--;
+ }
+ }
+ }
+
final void updateLruProcessLocked(ProcessRecord app, boolean activityChange,
ProcessRecord client) {
final boolean hasActivity = app.hasActivitiesOrRecentTasks() || app.hasClientActivities()
@@ -2349,91 +2538,31 @@ public final class ProcessList {
if (!app.hasActivitiesOrRecentTasks() && !app.treatLikeActivity
&& mLruProcessActivityStart < (N - 1)) {
// Process doesn't have activities, but has clients with
- // activities... move it up, but one below the top (the top
- // should always have a real activity).
+ // activities... move it up, but below the app that is binding to it.
if (DEBUG_LRU) Slog.d(TAG_LRU,
- "Adding to second-top of LRU activity list: " + app);
- mLruProcesses.add(N - 1, app);
- // If this process is part of a group, need to pull up any other processes
- // in that group to be with it.
- final int uid = app.info.uid;
- int endIndex = N - 2;
- nextActivityIndex = N - 2;
- if (app.connectionGroup > 0) {
- int endImportance = app.connectionImportance;
- for (int i = endIndex; i >= mLruProcessActivityStart; i--) {
- final ProcessRecord subProc = mLruProcesses.get(i);
- if (subProc.info.uid == uid
- && subProc.connectionGroup == subProc.connectionGroup) {
- if (i == endIndex && subProc.connectionImportance >= endImportance) {
- // This process is already in the group, and its importance
- // is not as strong as the process before it, so it keep it
- // correctly positioned in the group.
- endIndex--;
- endImportance = subProc.connectionImportance;
- } else {
- // We want to pull this up to be with the rest of the group,
- // and order within the group by importance.
- boolean moved = false;
- for (int pos = N - 1; pos > endIndex; pos--) {
- final ProcessRecord posProc = mLruProcesses.get(pos);
- if (subProc.connectionImportance
- <= posProc.connectionImportance) {
- mLruProcesses.remove(i);
- mLruProcesses.add(pos, subProc);
- moved = true;
- endIndex--;
- break;
- }
- }
- if (!moved) {
- // Goes to the end of the group.
- mLruProcesses.remove(i);
- mLruProcesses.add(endIndex - 1, subProc);
- endIndex--;
- endImportance = subProc.connectionImportance;
- }
- }
- }
+ "Adding to second-top of LRU activity list: " + app
+ + " group=" + app.connectionGroup
+ + " importance=" + app.connectionImportance);
+ int pos = N - 1;
+ while (pos > mLruProcessActivityStart) {
+ final ProcessRecord posproc = mLruProcesses.get(pos);
+ if (posproc.info.uid == app.info.uid) {
+ // Technically this app could have multiple processes with different
+ // activities and so we should be looking for the actual process that
+ // is bound to the target proc... but I don't really care, do you?
+ break;
}
-
+ pos--;
}
- // To keep it from spamming the LRU list (by making a bunch of clients),
- // we will distribute other entries owned by it to be in-between other apps.
- for (int i = endIndex; i >= mLruProcessActivityStart; i--) {
- final ProcessRecord subProc = mLruProcesses.get(i);
- if (subProc.info.uid != uid) {
- // This is a different app... if we have gone through some of the
- // target app, pull this up to be before them.
- if (i < endIndex) {
- mLruProcesses.remove(i);
- mLruProcesses.add(endIndex, subProc);
- }
- // Find the end of the next group of processes for target app. This
- // is after any entries of different apps (so we don't change the existing
- // relative order of apps) and then after the next last group of processes
- // of the target app.
- for (endIndex--; endIndex >= mLruProcessActivityStart; endIndex--) {
- final ProcessRecord endProc = mLruProcesses.get(endIndex);
- if (endProc.info.uid == uid) {
- break;
- }
- }
- if (endIndex >= mLruProcessActivityStart) {
- final ProcessRecord endProc = mLruProcesses.get(endIndex);
- for (endIndex--; endIndex >= mLruProcessActivityStart; endIndex--) {
- final ProcessRecord nextEndProc = mLruProcesses.get(endIndex);
- if (nextEndProc.info.uid != uid
- || nextEndProc.connectionGroup != endProc.connectionGroup) {
- break;
- }
- }
- }
- if (i > endIndex) {
- i = endIndex;
- }
- }
+ mLruProcesses.add(pos, app);
+ // If this process is part of a group, need to pull up any other processes
+ // in that group to be with it.
+ int endIndex = pos - 1;
+ if (endIndex < mLruProcessActivityStart) {
+ endIndex = mLruProcessActivityStart;
}
+ nextActivityIndex = endIndex;
+ updateClientActivitiesOrdering(app, pos, mLruProcessActivityStart, endIndex);
} else {
// Process has activities, put it at the very tipsy-top.
if (DEBUG_LRU) Slog.d(TAG_LRU, "Adding to top of LRU activity list: " + app);
@@ -2469,6 +2598,9 @@ public final class ProcessList {
nextIndex = index - 1;
mLruProcessActivityStart++;
mLruProcessServiceStart++;
+ if (index > 1) {
+ updateClientActivitiesOrdering(app, mLruProcessServiceStart - 1, 0, index - 1);
+ }
}
app.lruSeq = mLruSeq;
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
index 013de93c7f24..4826f486da89 100644
--- a/services/core/java/com/android/server/am/ProcessRecord.java
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
@@ -586,7 +586,7 @@ final class ProcessRecord implements WindowProcessListener {
}
origBase.makeInactive();
}
- baseProcessTracker = tracker.getProcessStateLocked(info.packageName, uid,
+ baseProcessTracker = tracker.getProcessStateLocked(info.packageName, info.uid,
info.longVersionCode, processName);
baseProcessTracker.makeActive();
for (int i=0; i<pkgList.size(); i++) {
@@ -594,7 +594,7 @@ final class ProcessRecord implements WindowProcessListener {
if (holder.state != null && holder.state != origBase) {
holder.state.makeInactive();
}
- tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), uid,
+ tracker.updateProcessStateHolderLocked(holder, pkgList.keyAt(i), info.uid,
info.longVersionCode, processName);
if (holder.state != baseProcessTracker) {
holder.state.makeActive();
@@ -760,19 +760,25 @@ final class ProcessRecord implements WindowProcessListener {
@Override
public void writeToProto(ProtoOutputStream proto, long fieldId) {
+ writeToProto(proto, fieldId, -1);
+ }
+
+ public void writeToProto(ProtoOutputStream proto, long fieldId, int lruIndex) {
long token = proto.start(fieldId);
proto.write(ProcessRecordProto.PID, pid);
proto.write(ProcessRecordProto.PROCESS_NAME, processName);
- if (info.uid < Process.FIRST_APPLICATION_UID) {
- proto.write(ProcessRecordProto.UID, uid);
- } else {
+ proto.write(ProcessRecordProto.UID, info.uid);
+ if (UserHandle.getAppId(info.uid) >= Process.FIRST_APPLICATION_UID) {
proto.write(ProcessRecordProto.USER_ID, userId);
proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
- if (uid != info.uid) {
- proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
- }
+ }
+ if (uid != info.uid) {
+ proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
}
proto.write(ProcessRecordProto.PERSISTENT, mPersistent);
+ if (lruIndex >= 0) {
+ proto.write(ProcessRecordProto.LRU_INDEX, lruIndex);
+ }
proto.end(token);
}
@@ -864,7 +870,8 @@ final class ProcessRecord implements WindowProcessListener {
ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
versionCode);
if (baseProcessTracker != null) {
- tracker.updateProcessStateHolderLocked(holder, pkg, uid, versionCode, processName);
+ tracker.updateProcessStateHolderLocked(holder, pkg, info.uid, versionCode,
+ processName);
pkgList.put(pkg, holder);
if (holder.state != baseProcessTracker) {
holder.state.makeActive();
@@ -925,7 +932,7 @@ final class ProcessRecord implements WindowProcessListener {
pkgList.clear();
ProcessStats.ProcessStateHolder holder = new ProcessStats.ProcessStateHolder(
info.longVersionCode);
- tracker.updateProcessStateHolderLocked(holder, info.packageName, uid,
+ tracker.updateProcessStateHolderLocked(holder, info.packageName, info.uid,
info.longVersionCode, processName);
pkgList.put(info.packageName, holder);
if (holder.state != baseProcessTracker) {
diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java
index 09f8c3eee3b6..da5ce1c45610 100644
--- a/services/core/java/com/android/server/am/ServiceRecord.java
+++ b/services/core/java/com/android/server/am/ServiceRecord.java
@@ -121,6 +121,8 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
long nextRestartTime; // time when restartDelay will expire.
boolean destroying; // set when we have started destroying the service
long destroyTime; // time at which destory was initiated.
+ int pendingConnectionGroup; // To be filled in to ProcessRecord once it connects
+ int pendingConnectionImportance; // To be filled in to ProcessRecord once it connects
String stringName; // caching of toString
@@ -386,6 +388,11 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
pw.print(" restartTime=");
TimeUtils.formatDuration(restartTime, now, pw);
pw.print(" createdFromFg="); pw.println(createdFromFg);
+ if (pendingConnectionGroup != 0) {
+ pw.print(prefix); pw.print(" pendingConnectionGroup=");
+ pw.print(pendingConnectionGroup);
+ pw.print(" Importance="); pw.println(pendingConnectionImportance);
+ }
if (startRequested || delayedStop || lastStartId != 0) {
pw.print(prefix); pw.print("startRequested="); pw.print(startRequested);
pw.print(" delayedStop="); pw.print(delayedStop);
@@ -461,7 +468,11 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
serviceInfo = sInfo;
appInfo = sInfo.applicationInfo;
packageName = sInfo.applicationInfo.packageName;
- processName = sInfo.processName;
+ if ((sInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) != 0) {
+ processName = sInfo.processName + ":" + instanceName.getClassName();
+ } else {
+ processName = sInfo.processName;
+ }
permission = sInfo.permission;
exported = sInfo.exported;
this.restarter = restarter;
@@ -507,6 +518,12 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
public void setProcess(ProcessRecord _proc) {
app = _proc;
+ if (pendingConnectionGroup > 0) {
+ app.connectionService = this;
+ app.connectionGroup = pendingConnectionGroup;
+ app.connectionImportance = pendingConnectionImportance;
+ pendingConnectionGroup = pendingConnectionImportance = 0;
+ }
if (ActivityManagerService.TRACK_PROCSTATS_ASSOCIATIONS) {
for (int conni = connections.size() - 1; conni >= 0; conni--) {
ArrayList<ConnectionRecord> cr = connections.valueAt(conni);
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index 353f787f9005..271b37ec7568 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -1144,7 +1144,7 @@ class UserController implements Handler.Callback {
/**
* Attempt to unlock user without a credential token. This typically
* succeeds when the device doesn't have credential-encrypted storage, or
- * when the the credential-encrypted storage isn't tied to a user-provided
+ * when the credential-encrypted storage isn't tied to a user-provided
* PIN or pattern.
*/
private boolean maybeUnlockUser(final int userId) {
diff --git a/services/core/java/com/android/server/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
index 76010b346a3b..96095d89687e 100644
--- a/services/core/java/com/android/server/AbstractMasterSystemService.java
+++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.server;
+package com.android.server.infra;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -40,6 +40,8 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.content.PackageMonitor;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.Preconditions;
+import com.android.server.LocalServices;
+import com.android.server.SystemService;
import java.io.PrintWriter;
import java.util.List;
diff --git a/services/core/java/com/android/server/AbstractMultiplePendingRequestsRemoteService.java b/services/core/java/com/android/server/infra/AbstractMultiplePendingRequestsRemoteService.java
index f532b22cb8d4..513a6a3eeec8 100644
--- a/services/core/java/com/android/server/AbstractMultiplePendingRequestsRemoteService.java
+++ b/services/core/java/com/android/server/infra/AbstractMultiplePendingRequestsRemoteService.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.server;
+package com.android.server.infra;
import android.annotation.NonNull;
import android.content.ComponentName;
diff --git a/services/core/java/com/android/server/AbstractPerUserSystemService.java b/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java
index a26102d57297..dfe8a369db44 100644
--- a/services/core/java/com/android/server/AbstractPerUserSystemService.java
+++ b/services/core/java/com/android/server/infra/AbstractPerUserSystemService.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.server;
+package com.android.server.infra;
import android.annotation.CallSuper;
import android.annotation.NonNull;
diff --git a/services/core/java/com/android/server/AbstractRemoteService.java b/services/core/java/com/android/server/infra/AbstractRemoteService.java
index f636487c666b..7af1d4ca94ef 100644
--- a/services/core/java/com/android/server/AbstractRemoteService.java
+++ b/services/core/java/com/android/server/infra/AbstractRemoteService.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.server;
+package com.android.server.infra;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
@@ -33,6 +33,7 @@ import android.os.UserHandle;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
+import com.android.server.FgThread;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
diff --git a/services/core/java/com/android/server/AbstractSinglePendingRequestRemoteService.java b/services/core/java/com/android/server/infra/AbstractSinglePendingRequestRemoteService.java
index 8e1f540a4d5e..8f8b448a7a66 100644
--- a/services/core/java/com/android/server/AbstractSinglePendingRequestRemoteService.java
+++ b/services/core/java/com/android/server/infra/AbstractSinglePendingRequestRemoteService.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.server;
+package com.android.server.infra;
import android.annotation.NonNull;
import android.content.ComponentName;
diff --git a/services/core/java/com/android/server/infra/package.html b/services/core/java/com/android/server/infra/package.html
new file mode 100644
index 000000000000..61a4c433cdaf
--- /dev/null
+++ b/services/core/java/com/android/server/infra/package.html
@@ -0,0 +1,6 @@
+<html>
+<body>
+Contains common classes providing the plumbing infrastructure necessary to implement a system
+service
+</body>
+</html> \ No newline at end of file
diff --git a/services/core/java/com/android/server/intelligence/IntelligenceManagerInternal.java b/services/core/java/com/android/server/intelligence/IntelligenceManagerInternal.java
index d5be26ac3389..f424869a428e 100644
--- a/services/core/java/com/android/server/intelligence/IntelligenceManagerInternal.java
+++ b/services/core/java/com/android/server/intelligence/IntelligenceManagerInternal.java
@@ -16,10 +16,12 @@
package com.android.server.intelligence;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.os.Bundle;
import android.os.IBinder;
import android.view.autofill.AutofillId;
+import android.view.autofill.AutofillValue;
import android.view.autofill.IAutoFillManagerClient;
/**
@@ -53,6 +55,7 @@ public abstract class IntelligenceManagerInternal {
* @param activityToken activity that originated this request.
* @param autofillSessionId autofill session id (must be used on {@code client} calls.
* @param focusedId id of the the field that triggered this request.
+ * @param focusedValue current value of the field that triggered this request.
*
* @return {@code false} if the service cannot handle this request, {@code true} otherwise.
* <b>NOTE: </b> it must return right away; typically it will return {@code false} if the
@@ -60,7 +63,8 @@ public abstract class IntelligenceManagerInternal {
*/
public abstract AugmentedAutofillCallback requestAutofill(@UserIdInt int userId,
@NonNull IAutoFillManagerClient client, @NonNull IBinder activityToken,
- int autofillSessionId, @NonNull AutofillId focusedId);
+ int autofillSessionId, @NonNull AutofillId focusedId,
+ @Nullable AutofillValue focusedValue);
/**
* Callback used by the Autofill Session to communicate with the Augmented Autofill service.
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java
index b3f0629ea2d3..ea295de5909f 100644
--- a/services/core/java/com/android/server/job/JobSchedulerService.java
+++ b/services/core/java/com/android/server/job/JobSchedulerService.java
@@ -78,7 +78,6 @@ import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IBatteryStats;
import com.android.internal.app.procstats.ProcessStats;
-import com.android.internal.os.BackgroundThread;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.IndentingPrintWriter;
@@ -97,6 +96,7 @@ import com.android.server.job.controllers.ContentObserverController;
import com.android.server.job.controllers.DeviceIdleJobsController;
import com.android.server.job.controllers.IdleController;
import com.android.server.job.controllers.JobStatus;
+import com.android.server.job.controllers.QuotaController;
import com.android.server.job.controllers.StateController;
import com.android.server.job.controllers.StorageController;
import com.android.server.job.controllers.TimeController;
@@ -245,11 +245,11 @@ public class JobSchedulerService extends com.android.server.SystemService
* Named indices into the STANDBY_BEATS array, for clarity in referring to
* specific buckets' bookkeeping.
*/
- static final int ACTIVE_INDEX = 0;
- static final int WORKING_INDEX = 1;
- static final int FREQUENT_INDEX = 2;
- static final int RARE_INDEX = 3;
- static final int NEVER_INDEX = 4;
+ public static final int ACTIVE_INDEX = 0;
+ public static final int WORKING_INDEX = 1;
+ public static final int FREQUENT_INDEX = 2;
+ public static final int RARE_INDEX = 3;
+ public static final int NEVER_INDEX = 4;
/**
* Bookkeeping about when jobs last run. We keep our own record in heartbeat time,
@@ -308,6 +308,10 @@ public class JobSchedulerService extends com.android.server.SystemService
try {
mConstants.updateConstantsLocked(Settings.Global.getString(mResolver,
Settings.Global.JOB_SCHEDULER_CONSTANTS));
+ for (int controller = 0; controller < mControllers.size(); controller++) {
+ final StateController sc = mControllers.get(controller);
+ sc.onConstantsUpdatedLocked();
+ }
} catch (IllegalArgumentException e) {
// Failed to parse the settings string, log this and move on
// with defaults.
@@ -315,8 +319,10 @@ public class JobSchedulerService extends com.android.server.SystemService
}
}
- // Reset the heartbeat alarm based on the new heartbeat duration
- setNextHeartbeatAlarm();
+ if (mConstants.USE_HEARTBEATS) {
+ // Reset the heartbeat alarm based on the new heartbeat duration
+ setNextHeartbeatAlarm();
+ }
}
}
@@ -352,6 +358,19 @@ public class JobSchedulerService extends com.android.server.SystemService
private static final String KEY_STANDBY_RARE_BEATS = "standby_rare_beats";
private static final String KEY_CONN_CONGESTION_DELAY_FRAC = "conn_congestion_delay_frac";
private static final String KEY_CONN_PREFETCH_RELAX_FRAC = "conn_prefetch_relax_frac";
+ private static final String KEY_USE_HEARTBEATS = "use_heartbeats";
+ private static final String KEY_QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS =
+ "qc_allowed_time_per_period_ms";
+ private static final String KEY_QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS =
+ "qc_in_quota_buffer_ms";
+ private static final String KEY_QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS =
+ "qc_window_size_active_ms";
+ private static final String KEY_QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS =
+ "qc_window_size_working_ms";
+ private static final String KEY_QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS =
+ "qc_window_size_frequent_ms";
+ private static final String KEY_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS =
+ "qc_window_size_rare_ms";
private static final int DEFAULT_MIN_IDLE_COUNT = 1;
private static final int DEFAULT_MIN_CHARGING_COUNT = 1;
@@ -377,6 +396,19 @@ public class JobSchedulerService extends com.android.server.SystemService
private static final int DEFAULT_STANDBY_RARE_BEATS = 130; // ~ 24 hours
private static final float DEFAULT_CONN_CONGESTION_DELAY_FRAC = 0.5f;
private static final float DEFAULT_CONN_PREFETCH_RELAX_FRAC = 0.5f;
+ private static final boolean DEFAULT_USE_HEARTBEATS = true;
+ private static final long DEFAULT_QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS =
+ 10 * 60 * 1000L; // 10 minutes
+ private static final long DEFAULT_QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS =
+ 30 * 1000L; // 30 seconds
+ private static final long DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS =
+ 10 * 60 * 1000L; // 10 minutes for ACTIVE -- ACTIVE apps can run jobs at any time
+ private static final long DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS =
+ 2 * 60 * 60 * 1000L; // 2 hours
+ private static final long DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS =
+ 8 * 60 * 60 * 1000L; // 8 hours
+ private static final long DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS =
+ 24 * 60 * 60 * 1000L; // 24 hours
/**
* Minimum # of idle jobs that must be ready in order to force the JMS to schedule things
@@ -495,6 +527,54 @@ public class JobSchedulerService extends com.android.server.SystemService
* we consider matching it against a metered network.
*/
public float CONN_PREFETCH_RELAX_FRAC = DEFAULT_CONN_PREFETCH_RELAX_FRAC;
+ /**
+ * Whether to use heartbeats or rolling window for quota management. True will use
+ * heartbeats, false will use a rolling window.
+ */
+ public boolean USE_HEARTBEATS = DEFAULT_USE_HEARTBEATS;
+
+ /** How much time each app will have to run jobs within their standby bucket window. */
+ public long QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS =
+ DEFAULT_QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS;
+
+ /**
+ * How much time the package should have before transitioning from out-of-quota to in-quota.
+ * This should not affect processing if the package is already in-quota.
+ */
+ public long QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS =
+ DEFAULT_QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS;
+
+ /**
+ * The quota window size of the particular standby bucket. Apps in this standby bucket are
+ * expected to run only {@link QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS} within the past
+ * WINDOW_SIZE_MS.
+ */
+ public long QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS =
+ DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS;
+
+ /**
+ * The quota window size of the particular standby bucket. Apps in this standby bucket are
+ * expected to run only {@link QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS} within the past
+ * WINDOW_SIZE_MS.
+ */
+ public long QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS =
+ DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS;
+
+ /**
+ * The quota window size of the particular standby bucket. Apps in this standby bucket are
+ * expected to run only {@link QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS} within the past
+ * WINDOW_SIZE_MS.
+ */
+ public long QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS =
+ DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS;
+
+ /**
+ * The quota window size of the particular standby bucket. Apps in this standby bucket are
+ * expected to run only {@link QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS} within the past
+ * WINDOW_SIZE_MS.
+ */
+ public long QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS =
+ DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS;
private final KeyValueListParser mParser = new KeyValueListParser(',');
@@ -567,6 +647,25 @@ public class JobSchedulerService extends com.android.server.SystemService
DEFAULT_CONN_CONGESTION_DELAY_FRAC);
CONN_PREFETCH_RELAX_FRAC = mParser.getFloat(KEY_CONN_PREFETCH_RELAX_FRAC,
DEFAULT_CONN_PREFETCH_RELAX_FRAC);
+ USE_HEARTBEATS = mParser.getBoolean(KEY_USE_HEARTBEATS, DEFAULT_USE_HEARTBEATS);
+ QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS = mParser.getDurationMillis(
+ KEY_QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS,
+ DEFAULT_QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS);
+ QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS = mParser.getDurationMillis(
+ KEY_QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS,
+ DEFAULT_QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS);
+ QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS = mParser.getDurationMillis(
+ KEY_QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS,
+ DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS);
+ QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS = mParser.getDurationMillis(
+ KEY_QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS,
+ DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS);
+ QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS = mParser.getDurationMillis(
+ KEY_QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS,
+ DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS);
+ QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS = mParser.getDurationMillis(
+ KEY_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS,
+ DEFAULT_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS);
}
void dump(IndentingPrintWriter pw) {
@@ -600,6 +699,19 @@ public class JobSchedulerService extends com.android.server.SystemService
pw.println('}');
pw.printPair(KEY_CONN_CONGESTION_DELAY_FRAC, CONN_CONGESTION_DELAY_FRAC).println();
pw.printPair(KEY_CONN_PREFETCH_RELAX_FRAC, CONN_PREFETCH_RELAX_FRAC).println();
+ pw.printPair(KEY_USE_HEARTBEATS, USE_HEARTBEATS).println();
+ pw.printPair(KEY_QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS,
+ QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS).println();
+ pw.printPair(KEY_QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS,
+ QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS).println();
+ pw.printPair(KEY_QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS,
+ QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS).println();
+ pw.printPair(KEY_QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS,
+ QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS).println();
+ pw.printPair(KEY_QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS,
+ QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS).println();
+ pw.printPair(KEY_QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS,
+ QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS).println();
pw.decreaseIndent();
}
@@ -629,6 +741,23 @@ public class JobSchedulerService extends com.android.server.SystemService
}
proto.write(ConstantsProto.CONN_CONGESTION_DELAY_FRAC, CONN_CONGESTION_DELAY_FRAC);
proto.write(ConstantsProto.CONN_PREFETCH_RELAX_FRAC, CONN_PREFETCH_RELAX_FRAC);
+ proto.write(ConstantsProto.USE_HEARTBEATS, USE_HEARTBEATS);
+
+ final long qcToken = proto.start(ConstantsProto.QUOTA_CONTROLLER);
+ proto.write(ConstantsProto.QuotaController.ALLOWED_TIME_PER_PERIOD_MS,
+ QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS);
+ proto.write(ConstantsProto.QuotaController.IN_QUOTA_BUFFER_MS,
+ QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS);
+ proto.write(ConstantsProto.QuotaController.ACTIVE_WINDOW_SIZE_MS,
+ QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS);
+ proto.write(ConstantsProto.QuotaController.WORKING_WINDOW_SIZE_MS,
+ QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS);
+ proto.write(ConstantsProto.QuotaController.FREQUENT_WINDOW_SIZE_MS,
+ QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS);
+ proto.write(ConstantsProto.QuotaController.RARE_WINDOW_SIZE_MS,
+ QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS);
+ proto.end(qcToken);
+
proto.end(token);
}
}
@@ -1162,6 +1291,7 @@ public class JobSchedulerService extends com.android.server.SystemService
mControllers.add(new ContentObserverController(this));
mDeviceIdleJobsController = new DeviceIdleJobsController(this);
mControllers.add(mDeviceIdleJobsController);
+ mControllers.add(new QuotaController(this));
// If the job store determined that it can't yet reschedule persisted jobs,
// we need to start watching the clock.
@@ -1225,7 +1355,9 @@ public class JobSchedulerService extends com.android.server.SystemService
mAppStateTracker = Preconditions.checkNotNull(
LocalServices.getService(AppStateTracker.class));
- setNextHeartbeatAlarm();
+ if (mConstants.USE_HEARTBEATS) {
+ setNextHeartbeatAlarm();
+ }
// Register br for package removals and user removals.
final IntentFilter filter = new IntentFilter();
@@ -1869,6 +2001,9 @@ public class JobSchedulerService extends com.android.server.SystemService
// Intentionally does not touch the alarm timing
void advanceHeartbeatLocked(long beatsElapsed) {
+ if (!mConstants.USE_HEARTBEATS) {
+ return;
+ }
mHeartbeat += beatsElapsed;
if (DEBUG_STANDBY) {
Slog.v(TAG, "Advancing standby heartbeat by " + beatsElapsed
@@ -1904,6 +2039,9 @@ public class JobSchedulerService extends com.android.server.SystemService
void setNextHeartbeatAlarm() {
final long heartbeatLength;
synchronized (mLock) {
+ if (!mConstants.USE_HEARTBEATS) {
+ return;
+ }
heartbeatLength = mConstants.STANDBY_HEARTBEAT_TIME;
}
final long now = sElapsedRealtimeClock.millis();
@@ -1976,48 +2114,51 @@ public class JobSchedulerService extends com.android.server.SystemService
return false;
}
- // If the app is in a non-active standby bucket, make sure we've waited
- // an appropriate amount of time since the last invocation. During device-
- // wide parole, standby bucketing is ignored.
- //
- // Jobs in 'active' apps are not subject to standby, nor are jobs that are
- // specifically marked as exempt.
- if (DEBUG_STANDBY) {
- Slog.v(TAG, "isReadyToBeExecutedLocked: " + job.toShortString()
- + " parole=" + mInParole + " active=" + job.uidActive
- + " exempt=" + job.getJob().isExemptedFromAppStandby());
- }
- if (!mInParole
- && !job.uidActive
- && !job.getJob().isExemptedFromAppStandby()) {
- final int bucket = job.getStandbyBucket();
+ if (mConstants.USE_HEARTBEATS) {
+ // If the app is in a non-active standby bucket, make sure we've waited
+ // an appropriate amount of time since the last invocation. During device-
+ // wide parole, standby bucketing is ignored.
+ //
+ // Jobs in 'active' apps are not subject to standby, nor are jobs that are
+ // specifically marked as exempt.
if (DEBUG_STANDBY) {
- Slog.v(TAG, " bucket=" + bucket + " heartbeat=" + mHeartbeat
- + " next=" + mNextBucketHeartbeat[bucket]);
- }
- if (mHeartbeat < mNextBucketHeartbeat[bucket]) {
- // Only skip this job if the app is still waiting for the end of its nominal
- // bucket interval. Once it's waited that long, we let it go ahead and clear.
- // The final (NEVER) bucket is special; we never age those apps' jobs into
- // runnability.
- final long appLastRan = heartbeatWhenJobsLastRun(job);
- if (bucket >= mConstants.STANDBY_BEATS.length
- || (mHeartbeat > appLastRan
- && mHeartbeat < appLastRan + mConstants.STANDBY_BEATS[bucket])) {
- // TODO: log/trace that we're deferring the job due to bucketing if we hit this
- if (job.getWhenStandbyDeferred() == 0) {
+ Slog.v(TAG, "isReadyToBeExecutedLocked: " + job.toShortString()
+ + " parole=" + mInParole + " active=" + job.uidActive
+ + " exempt=" + job.getJob().isExemptedFromAppStandby());
+ }
+ if (!mInParole
+ && !job.uidActive
+ && !job.getJob().isExemptedFromAppStandby()) {
+ final int bucket = job.getStandbyBucket();
+ if (DEBUG_STANDBY) {
+ Slog.v(TAG, " bucket=" + bucket + " heartbeat=" + mHeartbeat
+ + " next=" + mNextBucketHeartbeat[bucket]);
+ }
+ if (mHeartbeat < mNextBucketHeartbeat[bucket]) {
+ // Only skip this job if the app is still waiting for the end of its nominal
+ // bucket interval. Once it's waited that long, we let it go ahead and clear.
+ // The final (NEVER) bucket is special; we never age those apps' jobs into
+ // runnability.
+ final long appLastRan = heartbeatWhenJobsLastRun(job);
+ if (bucket >= mConstants.STANDBY_BEATS.length
+ || (mHeartbeat > appLastRan
+ && mHeartbeat < appLastRan + mConstants.STANDBY_BEATS[bucket])) {
+ // TODO: log/trace that we're deferring the job due to bucketing if we
+ // hit this
+ if (job.getWhenStandbyDeferred() == 0) {
+ if (DEBUG_STANDBY) {
+ Slog.v(TAG, "Bucket deferral: " + mHeartbeat + " < "
+ + (appLastRan + mConstants.STANDBY_BEATS[bucket])
+ + " for " + job);
+ }
+ job.setWhenStandbyDeferred(sElapsedRealtimeClock.millis());
+ }
+ return false;
+ } else {
if (DEBUG_STANDBY) {
- Slog.v(TAG, "Bucket deferral: " + mHeartbeat + " < "
- + (appLastRan + mConstants.STANDBY_BEATS[bucket])
- + " for " + job);
+ Slog.v(TAG, "Bucket deferred job aged into runnability at "
+ + mHeartbeat + " : " + job);
}
- job.setWhenStandbyDeferred(sElapsedRealtimeClock.millis());
- }
- return false;
- } else {
- if (DEBUG_STANDBY) {
- Slog.v(TAG, "Bucket deferred job aged into runnability at "
- + mHeartbeat + " : " + job);
}
}
}
@@ -2364,32 +2505,7 @@ public class JobSchedulerService extends com.android.server.SystemService
@Override
public void onAppIdleStateChanged(final String packageName, final @UserIdInt int userId,
boolean idle, int bucket, int reason) {
- final int uid = mLocalPM.getPackageUid(packageName,
- PackageManager.MATCH_UNINSTALLED_PACKAGES, userId);
- if (uid < 0) {
- if (DEBUG_STANDBY) {
- Slog.i(TAG, "App idle state change for unknown app "
- + packageName + "/" + userId);
- }
- return;
- }
-
- final int bucketIndex = standbyBucketToBucketIndex(bucket);
- // update job bookkeeping out of band
- BackgroundThread.getHandler().post(() -> {
- if (DEBUG_STANDBY) {
- Slog.i(TAG, "Moving uid " + uid + " to bucketIndex " + bucketIndex);
- }
- synchronized (mLock) {
- mJobs.forEachJobForSourceUid(uid, job -> {
- // double-check uid vs package name to disambiguate shared uids
- if (packageName.equals(job.getSourcePackageName())) {
- job.setStandbyBucket(bucketIndex);
- }
- });
- onControllerStateChanged();
- }
- });
+ // QuotaController handles this now.
}
@Override
diff --git a/services/core/java/com/android/server/job/controllers/JobStatus.java b/services/core/java/com/android/server/job/controllers/JobStatus.java
index 35fc29ee69fc..6deecbd9a83b 100644
--- a/services/core/java/com/android/server/job/controllers/JobStatus.java
+++ b/services/core/java/com/android/server/job/controllers/JobStatus.java
@@ -77,6 +77,7 @@ public final class JobStatus {
static final int CONSTRAINT_CONNECTIVITY = 1<<28;
static final int CONSTRAINT_CONTENT_TRIGGER = 1<<26;
static final int CONSTRAINT_DEVICE_NOT_DOZING = 1<<25;
+ static final int CONSTRAINT_WITHIN_QUOTA = 1 << 24;
static final int CONSTRAINT_BACKGROUND_NOT_RESTRICTED = 1<<22;
// Soft override: ignore constraints like time that don't affect API availability
@@ -192,6 +193,10 @@ public final class JobStatus {
* Flag for {@link #trackingControllers}: the time controller is currently tracking this job.
*/
public static final int TRACKING_TIME = 1<<5;
+ /**
+ * Flag for {@link #trackingControllers}: the quota controller is currently tracking this job.
+ */
+ public static final int TRACKING_QUOTA = 1 << 6;
/**
* Bit mask of controllers that are currently tracking the job.
@@ -291,6 +296,9 @@ public final class JobStatus {
*/
private boolean mReadyNotRestrictedInBg;
+ /** The job is within its quota based on its standby bucket. */
+ private boolean mReadyWithinQuota;
+
/** Provide a handle to the service that this job will be run on. */
public int getServiceToken() {
return callingUid;
@@ -675,7 +683,6 @@ public final class JobStatus {
return baseHeartbeat;
}
- // Called only by the standby monitoring code
public void setStandbyBucket(int newBucket) {
standbyBucket = newBucket;
}
@@ -876,22 +883,27 @@ public final class JobStatus {
mPersistedUtcTimes = null;
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setChargingConstraintSatisfied(boolean state) {
return setConstraintSatisfied(CONSTRAINT_CHARGING, state);
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setBatteryNotLowConstraintSatisfied(boolean state) {
return setConstraintSatisfied(CONSTRAINT_BATTERY_NOT_LOW, state);
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setStorageNotLowConstraintSatisfied(boolean state) {
return setConstraintSatisfied(CONSTRAINT_STORAGE_NOT_LOW, state);
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setTimingDelayConstraintSatisfied(boolean state) {
return setConstraintSatisfied(CONSTRAINT_TIMING_DELAY, state);
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setDeadlineConstraintSatisfied(boolean state) {
if (setConstraintSatisfied(CONSTRAINT_DEADLINE, state)) {
// The constraint was changed. Update the ready flag.
@@ -901,18 +913,22 @@ public final class JobStatus {
return false;
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setIdleConstraintSatisfied(boolean state) {
return setConstraintSatisfied(CONSTRAINT_IDLE, state);
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setConnectivityConstraintSatisfied(boolean state) {
return setConstraintSatisfied(CONSTRAINT_CONNECTIVITY, state);
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setContentTriggerConstraintSatisfied(boolean state) {
return setConstraintSatisfied(CONSTRAINT_CONTENT_TRIGGER, state);
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setDeviceNotDozingConstraintSatisfied(boolean state, boolean whitelisted) {
dozeWhitelisted = whitelisted;
if (setConstraintSatisfied(CONSTRAINT_DEVICE_NOT_DOZING, state)) {
@@ -923,6 +939,7 @@ public final class JobStatus {
return false;
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setBackgroundNotRestrictedConstraintSatisfied(boolean state) {
if (setConstraintSatisfied(CONSTRAINT_BACKGROUND_NOT_RESTRICTED, state)) {
// The constraint was changed. Update the ready flag.
@@ -932,6 +949,17 @@ public final class JobStatus {
return false;
}
+ /** @return true if the constraint was changed, false otherwise. */
+ boolean setQuotaConstraintSatisfied(boolean state) {
+ if (setConstraintSatisfied(CONSTRAINT_WITHIN_QUOTA, state)) {
+ // The constraint was changed. Update the ready flag.
+ mReadyWithinQuota = state;
+ return true;
+ }
+ return false;
+ }
+
+ /** @return true if the state was changed, false otherwise. */
boolean setUidActive(final boolean newActiveState) {
if (newActiveState != uidActive) {
uidActive = newActiveState;
@@ -940,6 +968,7 @@ public final class JobStatus {
return false; /* unchanged */
}
+ /** @return true if the constraint was changed, false otherwise. */
boolean setConstraintSatisfied(int constraint, boolean state) {
boolean old = (satisfiedConstraints&constraint) != 0;
if (old == state) {
@@ -978,9 +1007,13 @@ public final class JobStatus {
* @return Whether or not this job is ready to run, based on its requirements.
*/
public boolean isReady() {
- // Deadline constraint trumps other constraints (except for periodic jobs where deadline
- // is an implementation detail. A periodic job should only run if its constraints are
- // satisfied).
+ // Quota constraints trumps all other constraints.
+ if (!mReadyWithinQuota) {
+ return false;
+ }
+ // Deadline constraint trumps other constraints besides quota (except for periodic jobs
+ // where deadline is an implementation detail. A periodic job should only run if its
+ // constraints are satisfied).
// DeviceNotDozing implicit constraint must be satisfied
// NotRestrictedInBackground implicit constraint must be satisfied
return mReadyNotDozing && mReadyNotRestrictedInBg && (mReadyDeadlineSatisfied
@@ -1169,6 +1202,9 @@ public final class JobStatus {
if ((constraints&CONSTRAINT_BACKGROUND_NOT_RESTRICTED) != 0) {
pw.print(" BACKGROUND_NOT_RESTRICTED");
}
+ if ((constraints & CONSTRAINT_WITHIN_QUOTA) != 0) {
+ pw.print(" WITHIN_QUOTA");
+ }
if (constraints != 0) {
pw.print(" [0x");
pw.print(Integer.toHexString(constraints));
@@ -1205,6 +1241,9 @@ public final class JobStatus {
if ((constraints & CONSTRAINT_DEVICE_NOT_DOZING) != 0) {
proto.write(fieldId, JobStatusDumpProto.CONSTRAINT_DEVICE_NOT_DOZING);
}
+ if ((constraints & CONSTRAINT_WITHIN_QUOTA) != 0) {
+ proto.write(fieldId, JobStatusDumpProto.CONSTRAINT_WITHIN_QUOTA);
+ }
}
private void dumpJobWorkItem(PrintWriter pw, String prefix, JobWorkItem work, int index) {
@@ -1237,6 +1276,13 @@ public final class JobStatus {
* Returns a bucket name based on the normalized bucket indices, not the AppStandby constants.
*/
String getBucketName() {
+ return bucketName(standbyBucket);
+ }
+
+ /**
+ * Returns a bucket name based on the normalized bucket indices, not the AppStandby constants.
+ */
+ static String bucketName(int standbyBucket) {
switch (standbyBucket) {
case 0: return "ACTIVE";
case 1: return "WORKING_SET";
@@ -1367,7 +1413,8 @@ public final class JobStatus {
dumpConstraints(pw, satisfiedConstraints);
pw.println();
pw.print(prefix); pw.print("Unsatisfied constraints:");
- dumpConstraints(pw, (requiredConstraints & ~satisfiedConstraints));
+ dumpConstraints(pw,
+ ((requiredConstraints | CONSTRAINT_WITHIN_QUOTA) & ~satisfiedConstraints));
pw.println();
if (dozeWhitelisted) {
pw.print(prefix); pw.println("Doze whitelisted: true");
@@ -1375,6 +1422,9 @@ public final class JobStatus {
if (uidActive) {
pw.print(prefix); pw.println("Uid: active");
}
+ if (job.isExemptedFromAppStandby()) {
+ pw.print(prefix); pw.println("Is exempted from app standby");
+ }
}
if (trackingControllers != 0) {
pw.print(prefix); pw.print("Tracking:");
@@ -1384,6 +1434,7 @@ public final class JobStatus {
if ((trackingControllers&TRACKING_IDLE) != 0) pw.print(" IDLE");
if ((trackingControllers&TRACKING_STORAGE) != 0) pw.print(" STORAGE");
if ((trackingControllers&TRACKING_TIME) != 0) pw.print(" TIME");
+ if ((trackingControllers & TRACKING_QUOTA) != 0) pw.print(" QUOTA");
pw.println();
}
@@ -1546,8 +1597,11 @@ public final class JobStatus {
if (full) {
dumpConstraints(proto, JobStatusDumpProto.SATISFIED_CONSTRAINTS, satisfiedConstraints);
dumpConstraints(proto, JobStatusDumpProto.UNSATISFIED_CONSTRAINTS,
- (requiredConstraints & ~satisfiedConstraints));
+ ((requiredConstraints | CONSTRAINT_WITHIN_QUOTA) & ~satisfiedConstraints));
proto.write(JobStatusDumpProto.IS_DOZE_WHITELISTED, dozeWhitelisted);
+ proto.write(JobStatusDumpProto.IS_UID_ACTIVE, uidActive);
+ proto.write(JobStatusDumpProto.IS_EXEMPTED_FROM_APP_STANDBY,
+ job.isExemptedFromAppStandby());
}
// Tracking controllers
@@ -1575,6 +1629,10 @@ public final class JobStatus {
proto.write(JobStatusDumpProto.TRACKING_CONTROLLERS,
JobStatusDumpProto.TRACKING_TIME);
}
+ if ((trackingControllers & TRACKING_QUOTA) != 0) {
+ proto.write(JobStatusDumpProto.TRACKING_CONTROLLERS,
+ JobStatusDumpProto.TRACKING_QUOTA);
+ }
// Implicit constraints
final long icToken = proto.start(JobStatusDumpProto.IMPLICIT_CONSTRAINTS);
diff --git a/services/core/java/com/android/server/job/controllers/QuotaController.java b/services/core/java/com/android/server/job/controllers/QuotaController.java
new file mode 100644
index 000000000000..f73ffac96dfa
--- /dev/null
+++ b/services/core/java/com/android/server/job/controllers/QuotaController.java
@@ -0,0 +1,1299 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static com.android.server.job.JobSchedulerService.ACTIVE_INDEX;
+import static com.android.server.job.JobSchedulerService.FREQUENT_INDEX;
+import static com.android.server.job.JobSchedulerService.NEVER_INDEX;
+import static com.android.server.job.JobSchedulerService.RARE_INDEX;
+import static com.android.server.job.JobSchedulerService.WORKING_INDEX;
+import static com.android.server.job.JobSchedulerService.sElapsedRealtimeClock;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.UserIdInt;
+import android.app.AlarmManager;
+import android.app.usage.UsageStatsManagerInternal;
+import android.app.usage.UsageStatsManagerInternal.AppIdleStateChangeListener;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.BatteryManager;
+import android.os.BatteryManagerInternal;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.UserHandle;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.proto.ProtoOutputStream;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.os.BackgroundThread;
+import com.android.internal.util.IndentingPrintWriter;
+import com.android.server.LocalServices;
+import com.android.server.job.JobSchedulerService;
+import com.android.server.job.StateControllerProto;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+/**
+ * Controller that tracks whether a package has exceeded its standby bucket quota.
+ *
+ * Each job in each bucket is given 10 minutes to run within its respective time window. Active
+ * jobs can run indefinitely, working set jobs can run for 10 minutes within a 2 hour window,
+ * frequent jobs get to run 10 minutes in an 8 hour window, and rare jobs get to run 10 minutes in
+ * a 24 hour window. The windows are rolling, so as soon as a job would have some quota based on its
+ * bucket, it will be eligible to run. When a job's bucket changes, its new quota is immediately
+ * applied to it.
+ *
+ * Test: atest com.android.server.job.controllers.QuotaControllerTest
+ */
+public final class QuotaController extends StateController {
+ private static final String TAG = "JobScheduler.Quota";
+ private static final boolean DEBUG = JobSchedulerService.DEBUG
+ || Log.isLoggable(TAG, Log.DEBUG);
+
+ private static final long MINUTE_IN_MILLIS = 60 * 1000L;
+
+ private static final String ALARM_TAG_CLEANUP = "*job.cleanup*";
+ private static final String ALARM_TAG_QUOTA_CHECK = "*job.quota_check*";
+
+ /**
+ * A sparse array of ArrayMaps, which is suitable for holding (userId, packageName)->object
+ * associations.
+ */
+ private static class UserPackageMap<T> {
+ private final SparseArray<ArrayMap<String, T>> mData = new SparseArray<>();
+
+ public void add(int userId, @NonNull String packageName, @Nullable T obj) {
+ ArrayMap<String, T> data = mData.get(userId);
+ if (data == null) {
+ data = new ArrayMap<String, T>();
+ mData.put(userId, data);
+ }
+ data.put(packageName, obj);
+ }
+
+ @Nullable
+ public T get(int userId, @NonNull String packageName) {
+ ArrayMap<String, T> data = mData.get(userId);
+ if (data != null) {
+ return data.get(packageName);
+ }
+ return null;
+ }
+
+ /** Returns the userId at the given index. */
+ public int keyAt(int index) {
+ return mData.keyAt(index);
+ }
+
+ /** Returns the package name at the given index. */
+ @NonNull
+ public String keyAt(int userIndex, int packageIndex) {
+ return mData.valueAt(userIndex).keyAt(packageIndex);
+ }
+
+ /** Returns the size of the outer (userId) array. */
+ public int numUsers() {
+ return mData.size();
+ }
+
+ public int numPackagesForUser(int userId) {
+ ArrayMap<String, T> data = mData.get(userId);
+ return data == null ? 0 : data.size();
+ }
+
+ /** Returns the value T at the given user and index. */
+ @Nullable
+ public T valueAt(int userIndex, int packageIndex) {
+ return mData.valueAt(userIndex).valueAt(packageIndex);
+ }
+
+ public void forEach(Consumer<T> consumer) {
+ for (int i = numUsers() - 1; i >= 0; --i) {
+ ArrayMap<String, T> data = mData.valueAt(i);
+ for (int j = data.size() - 1; j >= 0; --j) {
+ consumer.accept(data.valueAt(j));
+ }
+ }
+ }
+ }
+
+ /**
+ * Standardize the output of userId-packageName combo.
+ */
+ private static String string(int userId, String packageName) {
+ return "<" + userId + ">" + packageName;
+ }
+
+ @VisibleForTesting
+ static final class Package {
+ public final String packageName;
+ public final int userId;
+
+ Package(int userId, String packageName) {
+ this.userId = userId;
+ this.packageName = packageName;
+ }
+
+ @Override
+ public String toString() {
+ return string(userId, packageName);
+ }
+
+ public void writeToProto(ProtoOutputStream proto, long fieldId) {
+ final long token = proto.start(fieldId);
+
+ proto.write(StateControllerProto.QuotaController.Package.USER_ID, userId);
+ proto.write(StateControllerProto.QuotaController.Package.NAME, packageName);
+
+ proto.end(token);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Package) {
+ Package other = (Package) obj;
+ return userId == other.userId && Objects.equals(packageName, other.packageName);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return packageName.hashCode() + userId;
+ }
+ }
+
+ /** List of all tracked jobs keyed by source package-userId combo. */
+ private final UserPackageMap<ArraySet<JobStatus>> mTrackedJobs = new UserPackageMap<>();
+
+ /** Timer for each package-userId combo. */
+ private final UserPackageMap<Timer> mPkgTimers = new UserPackageMap<>();
+
+ /** List of all timing sessions for a package-userId combo, in chronological order. */
+ private final UserPackageMap<List<TimingSession>> mTimingSessions = new UserPackageMap<>();
+
+ /**
+ * List of alarm listeners for each package that listen for when each package comes back within
+ * quota.
+ */
+ private final UserPackageMap<QcAlarmListener> mInQuotaAlarmListeners = new UserPackageMap<>();
+
+ private final AlarmManager mAlarmManager;
+ private final ChargingTracker mChargeTracker;
+ private final Handler mHandler;
+
+ private volatile boolean mInParole;
+
+ /**
+ * If the QuotaController should throttle apps based on their standby bucket and job activity.
+ * If false, all jobs will have their CONSTRAINT_WITHIN_QUOTA bit set to true immediately and
+ * indefinitely.
+ */
+ private boolean mShouldThrottle;
+
+ /** How much time each app will have to run jobs within their standby bucket window. */
+ private long mAllowedTimePerPeriodMs = 10 * MINUTE_IN_MILLIS;
+
+ /**
+ * How much time the package should have before transitioning from out-of-quota to in-quota.
+ * This should not affect processing if the package is already in-quota.
+ */
+ private long mQuotaBufferMs = 30 * 1000L; // 30 seconds
+
+ private long mNextCleanupTimeElapsed = 0;
+ private final AlarmManager.OnAlarmListener mSessionCleanupAlarmListener =
+ new AlarmManager.OnAlarmListener() {
+ @Override
+ public void onAlarm() {
+ mHandler.obtainMessage(MSG_CLEAN_UP_SESSIONS).sendToTarget();
+ }
+ };
+
+ /**
+ * The rolling window size for each standby bucket. Within each window, an app will have 10
+ * minutes to run its jobs.
+ */
+ private final long[] mBucketPeriodsMs = new long[] {
+ 10 * MINUTE_IN_MILLIS, // 10 minutes for ACTIVE -- ACTIVE apps can run jobs at any time
+ 2 * 60 * MINUTE_IN_MILLIS, // 2 hours for WORKING
+ 8 * 60 * MINUTE_IN_MILLIS, // 8 hours for FREQUENT
+ 24 * 60 * MINUTE_IN_MILLIS // 24 hours for RARE
+ };
+
+ /** The maximum period any bucket can have. */
+ private static final long MAX_PERIOD_MS = 24 * 60 * MINUTE_IN_MILLIS;
+
+ /** A package has reached its quota. The message should contain a {@link Package} object. */
+ private static final int MSG_REACHED_QUOTA = 0;
+ /** Drop any old timing sessions. */
+ private static final int MSG_CLEAN_UP_SESSIONS = 1;
+ /** Check if a package is now within its quota. */
+ private static final int MSG_CHECK_PACKAGE = 2;
+
+ public QuotaController(JobSchedulerService service) {
+ super(service);
+ mHandler = new QcHandler(mContext.getMainLooper());
+ mChargeTracker = new ChargingTracker();
+ mChargeTracker.startTracking();
+ mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
+
+ // Set up the app standby bucketing tracker
+ UsageStatsManagerInternal usageStats = LocalServices.getService(
+ UsageStatsManagerInternal.class);
+ usageStats.addAppIdleStateChangeListener(new StandbyTracker());
+
+ onConstantsUpdatedLocked();
+ }
+
+ @Override
+ public void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob) {
+ // Still need to track jobs even if mShouldThrottle is false in case it's set to true at
+ // some point.
+ ArraySet<JobStatus> jobs = mTrackedJobs.get(jobStatus.getSourceUserId(),
+ jobStatus.getSourcePackageName());
+ if (jobs == null) {
+ jobs = new ArraySet<>();
+ mTrackedJobs.add(jobStatus.getSourceUserId(), jobStatus.getSourcePackageName(), jobs);
+ }
+ jobs.add(jobStatus);
+ jobStatus.setTrackingController(JobStatus.TRACKING_QUOTA);
+ jobStatus.setQuotaConstraintSatisfied(!mShouldThrottle || isWithinQuotaLocked(jobStatus));
+ }
+
+ @Override
+ public void prepareForExecutionLocked(JobStatus jobStatus) {
+ if (DEBUG) Slog.d(TAG, "Prepping for " + jobStatus.toShortString());
+ final int userId = jobStatus.getSourceUserId();
+ final String packageName = jobStatus.getSourcePackageName();
+ Timer timer = mPkgTimers.get(userId, packageName);
+ if (timer == null) {
+ timer = new Timer(userId, packageName);
+ mPkgTimers.add(userId, packageName, timer);
+ }
+ timer.startTrackingJob(jobStatus);
+ }
+
+ @Override
+ public void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob,
+ boolean forUpdate) {
+ if (jobStatus.clearTrackingController(JobStatus.TRACKING_QUOTA)) {
+ Timer timer = mPkgTimers.get(jobStatus.getSourceUserId(),
+ jobStatus.getSourcePackageName());
+ if (timer != null) {
+ timer.stopTrackingJob(jobStatus);
+ }
+ ArraySet<JobStatus> jobs = mTrackedJobs.get(jobStatus.getSourceUserId(),
+ jobStatus.getSourcePackageName());
+ if (jobs != null) {
+ jobs.remove(jobStatus);
+ }
+ }
+ }
+
+ @Override
+ public void onConstantsUpdatedLocked() {
+ boolean changed = false;
+ if (mShouldThrottle == mConstants.USE_HEARTBEATS) {
+ mShouldThrottle = !mConstants.USE_HEARTBEATS;
+ changed = true;
+ }
+ long newAllowedTimeMs = Math.min(MAX_PERIOD_MS,
+ Math.max(MINUTE_IN_MILLIS, mConstants.QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS));
+ if (mAllowedTimePerPeriodMs != newAllowedTimeMs) {
+ mAllowedTimePerPeriodMs = newAllowedTimeMs;
+ changed = true;
+ }
+ long newQuotaBufferMs = Math.max(0,
+ Math.min(5 * MINUTE_IN_MILLIS, mConstants.QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS));
+ if (mQuotaBufferMs != newQuotaBufferMs) {
+ mQuotaBufferMs = newQuotaBufferMs;
+ changed = true;
+ }
+ long newActivePeriodMs = Math.max(mAllowedTimePerPeriodMs,
+ Math.min(MAX_PERIOD_MS, mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS));
+ if (mBucketPeriodsMs[ACTIVE_INDEX] != newActivePeriodMs) {
+ mBucketPeriodsMs[ACTIVE_INDEX] = newActivePeriodMs;
+ changed = true;
+ }
+ long newWorkingPeriodMs = Math.max(mAllowedTimePerPeriodMs,
+ Math.min(MAX_PERIOD_MS, mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS));
+ if (mBucketPeriodsMs[WORKING_INDEX] != newWorkingPeriodMs) {
+ mBucketPeriodsMs[WORKING_INDEX] = newWorkingPeriodMs;
+ changed = true;
+ }
+ long newFrequentPeriodMs = Math.max(mAllowedTimePerPeriodMs,
+ Math.min(MAX_PERIOD_MS, mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS));
+ if (mBucketPeriodsMs[FREQUENT_INDEX] != newFrequentPeriodMs) {
+ mBucketPeriodsMs[FREQUENT_INDEX] = newFrequentPeriodMs;
+ changed = true;
+ }
+ long newRarePeriodMs = Math.max(mAllowedTimePerPeriodMs,
+ Math.min(MAX_PERIOD_MS, mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS));
+ if (mBucketPeriodsMs[RARE_INDEX] != newRarePeriodMs) {
+ mBucketPeriodsMs[RARE_INDEX] = newRarePeriodMs;
+ changed = true;
+ }
+
+ if (changed) {
+ // Update job bookkeeping out of band.
+ BackgroundThread.getHandler().post(() -> {
+ synchronized (mLock) {
+ maybeUpdateAllConstraintsLocked();
+ }
+ });
+ }
+ }
+
+ /**
+ * Returns an appropriate standby bucket for the job, taking into account any standby
+ * exemptions.
+ */
+ private int getEffectiveStandbyBucket(@NonNull final JobStatus jobStatus) {
+ if (jobStatus.uidActive || jobStatus.getJob().isExemptedFromAppStandby()) {
+ // Treat these cases as if they're in the ACTIVE bucket so that they get throttled
+ // like other ACTIVE apps.
+ return ACTIVE_INDEX;
+ }
+ return jobStatus.getStandbyBucket();
+ }
+
+ private boolean isWithinQuotaLocked(@NonNull final JobStatus jobStatus) {
+ final int standbyBucket = getEffectiveStandbyBucket(jobStatus);
+ return isWithinQuotaLocked(jobStatus.getSourceUserId(), jobStatus.getSourcePackageName(),
+ standbyBucket);
+ }
+
+ private boolean isWithinQuotaLocked(final int userId, @NonNull final String packageName,
+ final int standbyBucket) {
+ if (standbyBucket == NEVER_INDEX) return false;
+ if (standbyBucket == ACTIVE_INDEX) return true;
+ // This check is needed in case the flag is toggled after a job has been registered.
+ if (!mShouldThrottle) return true;
+
+ // Quota constraint is not enforced while charging or when parole is on.
+ return mChargeTracker.isCharging() || mInParole
+ || getRemainingExecutionTimeLocked(userId, packageName, standbyBucket) > 0;
+ }
+
+ @VisibleForTesting
+ long getRemainingExecutionTimeLocked(@NonNull final JobStatus jobStatus) {
+ return getRemainingExecutionTimeLocked(jobStatus.getSourceUserId(),
+ jobStatus.getSourcePackageName(),
+ getEffectiveStandbyBucket(jobStatus));
+ }
+
+ @VisibleForTesting
+ long getRemainingExecutionTimeLocked(final int userId, @NonNull final String packageName) {
+ final int standbyBucket = JobSchedulerService.standbyBucketForPackage(packageName,
+ userId, sElapsedRealtimeClock.millis());
+ return getRemainingExecutionTimeLocked(userId, packageName, standbyBucket);
+ }
+
+ /**
+ * Returns the amount of time, in milliseconds, that this job has remaining to run based on its
+ * current standby bucket. Time remaining could be negative if the app was moved from a less
+ * restricted to a more restricted bucket.
+ */
+ private long getRemainingExecutionTimeLocked(final int userId,
+ @NonNull final String packageName, final int standbyBucket) {
+ if (standbyBucket == NEVER_INDEX) {
+ return 0;
+ }
+ final long bucketWindowSizeMs = mBucketPeriodsMs[standbyBucket];
+ final long trailingRunDurationMs = getTrailingExecutionTimeLocked(
+ userId, packageName, bucketWindowSizeMs);
+ return mAllowedTimePerPeriodMs - trailingRunDurationMs;
+ }
+
+ /** Returns how long the uid has had jobs running within the most recent window. */
+ @VisibleForTesting
+ long getTrailingExecutionTimeLocked(final int userId, @NonNull final String packageName,
+ final long windowSizeMs) {
+ long totalTime = 0;
+
+ Timer timer = mPkgTimers.get(userId, packageName);
+ final long nowElapsed = sElapsedRealtimeClock.millis();
+ if (timer != null && timer.isActive()) {
+ totalTime = timer.getCurrentDuration(nowElapsed);
+ }
+
+ List<TimingSession> sessions = mTimingSessions.get(userId, packageName);
+ if (sessions == null || sessions.size() == 0) {
+ return totalTime;
+ }
+
+ final long startElapsed = nowElapsed - windowSizeMs;
+ // Sessions are non-overlapping and in order of occurrence, so iterating backwards will get
+ // the most recent ones.
+ for (int i = sessions.size() - 1; i >= 0; --i) {
+ TimingSession session = sessions.get(i);
+ if (startElapsed < session.startTimeElapsed) {
+ totalTime += session.endTimeElapsed - session.startTimeElapsed;
+ } else if (startElapsed < session.endTimeElapsed) {
+ // The session started before the window but ended within the window. Only include
+ // the portion that was within the window.
+ totalTime += session.endTimeElapsed - startElapsed;
+ } else {
+ // This session ended before the window. No point in going any further.
+ return totalTime;
+ }
+ }
+ return totalTime;
+ }
+
+ @VisibleForTesting
+ void saveTimingSession(final int userId, @NonNull final String packageName,
+ @NonNull final TimingSession session) {
+ synchronized (mLock) {
+ List<TimingSession> sessions = mTimingSessions.get(userId, packageName);
+ if (sessions == null) {
+ sessions = new ArrayList<>();
+ mTimingSessions.add(userId, packageName, sessions);
+ }
+ sessions.add(session);
+
+ maybeScheduleCleanupAlarmLocked();
+ }
+ }
+
+ private final class EarliestEndTimeFunctor implements Consumer<List<TimingSession>> {
+ public long earliestEndElapsed = Long.MAX_VALUE;
+
+ @Override
+ public void accept(List<TimingSession> sessions) {
+ if (sessions != null && sessions.size() > 0) {
+ earliestEndElapsed = Math.min(earliestEndElapsed, sessions.get(0).endTimeElapsed);
+ }
+ }
+
+ void reset() {
+ earliestEndElapsed = Long.MAX_VALUE;
+ }
+ }
+
+ private final EarliestEndTimeFunctor mEarliestEndTimeFunctor = new EarliestEndTimeFunctor();
+
+ /** Schedule a cleanup alarm if necessary and there isn't already one scheduled. */
+ @VisibleForTesting
+ void maybeScheduleCleanupAlarmLocked() {
+ if (mNextCleanupTimeElapsed > sElapsedRealtimeClock.millis()) {
+ // There's already an alarm scheduled. Just stick with that one. There's no way we'll
+ // end up scheduling an earlier alarm.
+ if (DEBUG) {
+ Slog.v(TAG, "Not scheduling cleanup since there's already one at "
+ + mNextCleanupTimeElapsed + " (in " + (mNextCleanupTimeElapsed
+ - sElapsedRealtimeClock.millis()) + "ms)");
+ }
+ return;
+ }
+ mEarliestEndTimeFunctor.reset();
+ mTimingSessions.forEach(mEarliestEndTimeFunctor);
+ final long earliestEndElapsed = mEarliestEndTimeFunctor.earliestEndElapsed;
+ if (earliestEndElapsed == Long.MAX_VALUE) {
+ // Couldn't find a good time to clean up. Maybe this was called after we deleted all
+ // timing sessions.
+ if (DEBUG) Slog.d(TAG, "Didn't find a time to schedule cleanup");
+ return;
+ }
+ // Need to keep sessions for all apps up to the max period, regardless of their current
+ // standby bucket.
+ long nextCleanupElapsed = earliestEndElapsed + MAX_PERIOD_MS;
+ if (nextCleanupElapsed - mNextCleanupTimeElapsed <= 10 * MINUTE_IN_MILLIS) {
+ // No need to clean up too often. Delay the alarm if the next cleanup would be too soon
+ // after it.
+ nextCleanupElapsed += 10 * MINUTE_IN_MILLIS;
+ }
+ mNextCleanupTimeElapsed = nextCleanupElapsed;
+ mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, nextCleanupElapsed, ALARM_TAG_CLEANUP,
+ mSessionCleanupAlarmListener, mHandler);
+ if (DEBUG) Slog.d(TAG, "Scheduled next cleanup for " + mNextCleanupTimeElapsed);
+ }
+
+ private void handleNewChargingStateLocked() {
+ final long nowElapsed = sElapsedRealtimeClock.millis();
+ final boolean isCharging = mChargeTracker.isCharging();
+ if (DEBUG) Slog.d(TAG, "handleNewChargingStateLocked: " + isCharging);
+ // Deal with Timers first.
+ mPkgTimers.forEach((t) -> t.onChargingChanged(nowElapsed, isCharging));
+ // Now update jobs.
+ maybeUpdateAllConstraintsLocked();
+ }
+
+ private void maybeUpdateAllConstraintsLocked() {
+ boolean changed = false;
+ for (int u = 0; u < mTrackedJobs.numUsers(); ++u) {
+ final int userId = mTrackedJobs.keyAt(u);
+ for (int p = 0; p < mTrackedJobs.numPackagesForUser(userId); ++p) {
+ final String packageName = mTrackedJobs.keyAt(u, p);
+ changed |= maybeUpdateConstraintForPkgLocked(userId, packageName);
+ }
+ }
+ if (changed) {
+ mStateChangedListener.onControllerStateChanged();
+ }
+ }
+
+ /**
+ * Update the CONSTRAINT_WITHIN_QUOTA bit for all of the Jobs for a given package.
+ *
+ * @return true if at least one job had its bit changed
+ */
+ private boolean maybeUpdateConstraintForPkgLocked(final int userId,
+ @NonNull final String packageName) {
+ ArraySet<JobStatus> jobs = mTrackedJobs.get(userId, packageName);
+ if (jobs == null || jobs.size() == 0) {
+ return false;
+ }
+
+ // Quota is the same for all jobs within a package.
+ final int realStandbyBucket = jobs.valueAt(0).getStandbyBucket();
+ final boolean realInQuota = isWithinQuotaLocked(userId, packageName, realStandbyBucket);
+ boolean changed = false;
+ for (int i = jobs.size() - 1; i >= 0; --i) {
+ final JobStatus js = jobs.valueAt(i);
+ if (realStandbyBucket == getEffectiveStandbyBucket(js)) {
+ changed |= js.setQuotaConstraintSatisfied(realInQuota);
+ } else {
+ // This job is somehow exempted. Need to determine its own quota status.
+ changed |= js.setQuotaConstraintSatisfied(isWithinQuotaLocked(js));
+ }
+ }
+ if (!realInQuota) {
+ // Don't want to use the effective standby bucket here since that bump the bucket to
+ // ACTIVE for one of the jobs, which doesn't help with other jobs that aren't
+ // exempted.
+ maybeScheduleStartAlarmLocked(userId, packageName, realStandbyBucket);
+ } else {
+ QcAlarmListener alarmListener = mInQuotaAlarmListeners.get(userId, packageName);
+ if (alarmListener != null) {
+ mAlarmManager.cancel(alarmListener);
+ // Set the trigger time to 0 so that the alarm doesn't think it's still waiting.
+ alarmListener.setTriggerTime(0);
+ }
+ }
+ return changed;
+ }
+
+ /**
+ * Maybe schedule a non-wakeup alarm for the next time this package will have quota to run
+ * again. This should only be called if the package is already out of quota.
+ */
+ @VisibleForTesting
+ void maybeScheduleStartAlarmLocked(final int userId, @NonNull final String packageName,
+ final int standbyBucket) {
+ final String pkgString = string(userId, packageName);
+ if (standbyBucket == NEVER_INDEX) {
+ return;
+ } else if (standbyBucket == ACTIVE_INDEX) {
+ // ACTIVE apps are "always" in quota.
+ if (DEBUG) {
+ Slog.w(TAG, "maybeScheduleStartAlarmLocked called for " + pkgString
+ + " even though it is active");
+ }
+ mHandler.obtainMessage(MSG_CHECK_PACKAGE, userId, 0, packageName).sendToTarget();
+
+ QcAlarmListener alarmListener = mInQuotaAlarmListeners.get(userId, packageName);
+ if (alarmListener != null) {
+ // Cancel any pending alarm.
+ mAlarmManager.cancel(alarmListener);
+ // Set the trigger time to 0 so that the alarm doesn't think it's still waiting.
+ alarmListener.setTriggerTime(0);
+ }
+ return;
+ }
+
+ List<TimingSession> sessions = mTimingSessions.get(userId, packageName);
+ if (sessions == null || sessions.size() == 0) {
+ // If there are no sessions, then the job is probably in quota.
+ if (DEBUG) {
+ Slog.wtf(TAG, "maybeScheduleStartAlarmLocked called for " + pkgString
+ + " even though it is likely within its quota.");
+ }
+ mHandler.obtainMessage(MSG_CHECK_PACKAGE, userId, 0, packageName).sendToTarget();
+ return;
+ }
+
+ final long bucketWindowSizeMs = mBucketPeriodsMs[standbyBucket];
+ final long nowElapsed = sElapsedRealtimeClock.millis();
+ // How far back we need to look.
+ final long startElapsed = nowElapsed - bucketWindowSizeMs;
+
+ long totalTime = 0;
+ long cutoffTimeElapsed = nowElapsed;
+ for (int i = sessions.size() - 1; i >= 0; i--) {
+ TimingSession session = sessions.get(i);
+ if (startElapsed < session.startTimeElapsed) {
+ cutoffTimeElapsed = session.startTimeElapsed;
+ totalTime += session.endTimeElapsed - session.startTimeElapsed;
+ } else if (startElapsed < session.endTimeElapsed) {
+ // The session started before the window but ended within the window. Only
+ // include the portion that was within the window.
+ cutoffTimeElapsed = startElapsed;
+ totalTime += session.endTimeElapsed - startElapsed;
+ } else {
+ // This session ended before the window. No point in going any further.
+ break;
+ }
+ if (totalTime >= mAllowedTimePerPeriodMs) {
+ break;
+ }
+ }
+ if (totalTime < mAllowedTimePerPeriodMs) {
+ // Already in quota. Why was this method called?
+ if (DEBUG) {
+ Slog.w(TAG, "maybeScheduleStartAlarmLocked called for " + pkgString
+ + " even though it already has " + (mAllowedTimePerPeriodMs - totalTime)
+ + "ms in its quota.");
+ }
+ mHandler.obtainMessage(MSG_CHECK_PACKAGE, userId, 0, packageName).sendToTarget();
+ return;
+ }
+
+ QcAlarmListener alarmListener = mInQuotaAlarmListeners.get(userId, packageName);
+ if (alarmListener == null) {
+ alarmListener = new QcAlarmListener(userId, packageName);
+ mInQuotaAlarmListeners.add(userId, packageName, alarmListener);
+ }
+
+ // We add all the way back to the beginning of a session (or the window) even when we don't
+ // need to (in order to simplify the for loop above), so there might be some extra we
+ // need to add back.
+ final long extraTimeMs = totalTime - mAllowedTimePerPeriodMs;
+ // The time this app will have quota again.
+ final long inQuotaTimeElapsed =
+ cutoffTimeElapsed + extraTimeMs + mQuotaBufferMs + bucketWindowSizeMs;
+ // Only schedule the alarm if:
+ // 1. There isn't one currently scheduled
+ // 2. The new alarm is significantly earlier than the previous alarm (which could be the
+ // case if the package moves into a higher standby bucket). If it's earlier but not
+ // significantly so, then we essentially delay the job a few extra minutes.
+ // 3. The alarm is after the current alarm by more than the quota buffer.
+ // TODO: this might be overengineering. Simplify if proven safe.
+ if (!alarmListener.isWaiting()
+ || inQuotaTimeElapsed < alarmListener.getTriggerTimeElapsed() - 3 * MINUTE_IN_MILLIS
+ || alarmListener.getTriggerTimeElapsed() < inQuotaTimeElapsed - mQuotaBufferMs) {
+ if (DEBUG) Slog.d(TAG, "Scheduling start alarm for " + pkgString);
+ // If the next time this app will have quota is at least 3 minutes before the
+ // alarm is supposed to go off, reschedule the alarm.
+ mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, inQuotaTimeElapsed,
+ ALARM_TAG_QUOTA_CHECK, alarmListener, mHandler);
+ alarmListener.setTriggerTime(inQuotaTimeElapsed);
+ }
+ }
+
+ private final class ChargingTracker extends BroadcastReceiver {
+ /**
+ * Track whether we're charging. This has a slightly different definition than that of
+ * BatteryController.
+ */
+ private boolean mCharging;
+
+ ChargingTracker() {
+ }
+
+ public void startTracking() {
+ IntentFilter filter = new IntentFilter();
+
+ // Charging/not charging.
+ filter.addAction(BatteryManager.ACTION_CHARGING);
+ filter.addAction(BatteryManager.ACTION_DISCHARGING);
+ mContext.registerReceiver(this, filter);
+
+ // Initialise tracker state.
+ BatteryManagerInternal batteryManagerInternal =
+ LocalServices.getService(BatteryManagerInternal.class);
+ mCharging = batteryManagerInternal.isPowered(BatteryManager.BATTERY_PLUGGED_ANY);
+ }
+
+ public boolean isCharging() {
+ return mCharging;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ synchronized (mLock) {
+ final String action = intent.getAction();
+ if (BatteryManager.ACTION_CHARGING.equals(action)) {
+ if (DEBUG) {
+ Slog.d(TAG, "Received charging intent, fired @ "
+ + sElapsedRealtimeClock.millis());
+ }
+ mCharging = true;
+ handleNewChargingStateLocked();
+ } else if (BatteryManager.ACTION_DISCHARGING.equals(action)) {
+ if (DEBUG) {
+ Slog.d(TAG, "Disconnected from power.");
+ }
+ mCharging = false;
+ handleNewChargingStateLocked();
+ }
+ }
+ }
+ }
+
+ @VisibleForTesting
+ static final class TimingSession {
+ // Start timestamp in elapsed realtime timebase.
+ public final long startTimeElapsed;
+ // End timestamp in elapsed realtime timebase.
+ public final long endTimeElapsed;
+ // How many jobs ran during this session.
+ public final int jobCount;
+
+ TimingSession(long startElapsed, long endElapsed, int jobCount) {
+ this.startTimeElapsed = startElapsed;
+ this.endTimeElapsed = endElapsed;
+ this.jobCount = jobCount;
+ }
+
+ @Override
+ public String toString() {
+ return "TimingSession{" + startTimeElapsed + "->" + endTimeElapsed + ", " + jobCount
+ + "}";
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof TimingSession) {
+ TimingSession other = (TimingSession) obj;
+ return startTimeElapsed == other.startTimeElapsed
+ && endTimeElapsed == other.endTimeElapsed
+ && jobCount == other.jobCount;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(new long[] {startTimeElapsed, endTimeElapsed, jobCount});
+ }
+
+ public void dump(IndentingPrintWriter pw) {
+ pw.print(startTimeElapsed);
+ pw.print(" -> ");
+ pw.print(endTimeElapsed);
+ pw.print(" (");
+ pw.print(endTimeElapsed - startTimeElapsed);
+ pw.print("), ");
+ pw.print(jobCount);
+ pw.print(" jobs.");
+ pw.println();
+ }
+
+ public void dump(@NonNull ProtoOutputStream proto, long fieldId) {
+ final long token = proto.start(fieldId);
+
+ proto.write(StateControllerProto.QuotaController.TimingSession.START_TIME_ELAPSED,
+ startTimeElapsed);
+ proto.write(StateControllerProto.QuotaController.TimingSession.END_TIME_ELAPSED,
+ endTimeElapsed);
+ proto.write(StateControllerProto.QuotaController.TimingSession.JOB_COUNT, jobCount);
+
+ proto.end(token);
+ }
+ }
+
+ private final class Timer {
+ private final Package mPkg;
+
+ // List of jobs currently running for this package.
+ private final ArraySet<JobStatus> mRunningJobs = new ArraySet<>();
+ private long mStartTimeElapsed;
+ private int mJobCount;
+
+ Timer(int userId, String packageName) {
+ mPkg = new Package(userId, packageName);
+ }
+
+ void startTrackingJob(@NonNull JobStatus jobStatus) {
+ if (DEBUG) Slog.v(TAG, "Starting to track " + jobStatus.toShortString());
+ synchronized (mLock) {
+ // Always track jobs, even when charging.
+ mRunningJobs.add(jobStatus);
+ if (!mChargeTracker.isCharging()) {
+ mJobCount++;
+ if (mRunningJobs.size() == 1) {
+ // Started tracking the first job.
+ mStartTimeElapsed = sElapsedRealtimeClock.millis();
+ scheduleCutoff();
+ }
+ }
+ }
+ }
+
+ void stopTrackingJob(@NonNull JobStatus jobStatus) {
+ if (DEBUG) Slog.v(TAG, "Stopping tracking of " + jobStatus.toShortString());
+ synchronized (mLock) {
+ if (mRunningJobs.size() == 0) {
+ // maybeStopTrackingJobLocked can be called when an app cancels a job, so a
+ // timer may not be running when it's asked to stop tracking a job.
+ if (DEBUG) {
+ Slog.d(TAG, "Timer isn't tracking any jobs but still told to stop");
+ }
+ return;
+ }
+ mRunningJobs.remove(jobStatus);
+ if (!mChargeTracker.isCharging() && mRunningJobs.size() == 0) {
+ emitSessionLocked(sElapsedRealtimeClock.millis());
+ cancelCutoff();
+ }
+ }
+ }
+
+ private void emitSessionLocked(long nowElapsed) {
+ if (mJobCount <= 0) {
+ // Nothing to emit.
+ return;
+ }
+ TimingSession ts = new TimingSession(mStartTimeElapsed, nowElapsed, mJobCount);
+ saveTimingSession(mPkg.userId, mPkg.packageName, ts);
+ mJobCount = 0;
+ // Don't reset the tracked jobs list as we need to keep tracking the current number
+ // of jobs.
+ // However, cancel the currently scheduled cutoff since it's not currently useful.
+ cancelCutoff();
+ }
+
+ /**
+ * Returns true if the Timer is actively tracking, as opposed to passively ref counting
+ * during charging.
+ */
+ public boolean isActive() {
+ synchronized (mLock) {
+ return mJobCount > 0;
+ }
+ }
+
+ long getCurrentDuration(long nowElapsed) {
+ synchronized (mLock) {
+ return !isActive() ? 0 : nowElapsed - mStartTimeElapsed;
+ }
+ }
+
+ void onChargingChanged(long nowElapsed, boolean isCharging) {
+ synchronized (mLock) {
+ if (isCharging) {
+ emitSessionLocked(nowElapsed);
+ } else {
+ // Start timing from unplug.
+ if (mRunningJobs.size() > 0) {
+ mStartTimeElapsed = nowElapsed;
+ // NOTE: this does have the unfortunate consequence that if the device is
+ // repeatedly plugged in and unplugged, the job count for a package may be
+ // artificially high.
+ mJobCount = mRunningJobs.size();
+ // Schedule cutoff since we're now actively tracking for quotas again.
+ scheduleCutoff();
+ }
+ }
+ }
+ }
+
+ void rescheduleCutoff() {
+ cancelCutoff();
+ scheduleCutoff();
+ }
+
+ private void scheduleCutoff() {
+ // Each package can only be in one standby bucket, so we only need to have one
+ // message per timer. We only need to reschedule when restarting timer or when
+ // standby bucket changes.
+ synchronized (mLock) {
+ if (!isActive()) {
+ return;
+ }
+ Message msg = mHandler.obtainMessage(MSG_REACHED_QUOTA, mPkg);
+ final long timeRemainingMs = getRemainingExecutionTimeLocked(mPkg.userId,
+ mPkg.packageName);
+ if (DEBUG) {
+ Slog.i(TAG, "Job for " + mPkg + " has " + timeRemainingMs + "ms left.");
+ }
+ // If the job was running the entire time, then the system would be up, so it's
+ // fine to use uptime millis for these messages.
+ mHandler.sendMessageDelayed(msg, timeRemainingMs);
+ }
+ }
+
+ private void cancelCutoff() {
+ mHandler.removeMessages(MSG_REACHED_QUOTA, mPkg);
+ }
+
+ public void dump(IndentingPrintWriter pw, Predicate<JobStatus> predicate) {
+ pw.print("Timer{");
+ pw.print(mPkg);
+ pw.print("} ");
+ if (isActive()) {
+ pw.print("started at ");
+ pw.print(mStartTimeElapsed);
+ } else {
+ pw.print("NOT active");
+ }
+ pw.print(", ");
+ pw.print(mJobCount);
+ pw.print(" running jobs");
+ pw.println();
+ pw.increaseIndent();
+ for (int i = 0; i < mRunningJobs.size(); i++) {
+ JobStatus js = mRunningJobs.valueAt(i);
+ if (predicate.test(js)) {
+ pw.println(js.toShortString());
+ }
+ }
+
+ pw.decreaseIndent();
+ }
+
+ public void dump(ProtoOutputStream proto, long fieldId, Predicate<JobStatus> predicate) {
+ final long token = proto.start(fieldId);
+
+ mPkg.writeToProto(proto, StateControllerProto.QuotaController.Timer.PKG);
+ proto.write(StateControllerProto.QuotaController.Timer.IS_ACTIVE, isActive());
+ proto.write(StateControllerProto.QuotaController.Timer.START_TIME_ELAPSED,
+ mStartTimeElapsed);
+ proto.write(StateControllerProto.QuotaController.Timer.JOB_COUNT, mJobCount);
+ for (int i = 0; i < mRunningJobs.size(); i++) {
+ JobStatus js = mRunningJobs.valueAt(i);
+ if (predicate.test(js)) {
+ js.writeToShortProto(proto,
+ StateControllerProto.QuotaController.Timer.RUNNING_JOBS);
+ }
+ }
+
+ proto.end(token);
+ }
+ }
+
+ /**
+ * Tracking of app assignments to standby buckets
+ */
+ final class StandbyTracker extends AppIdleStateChangeListener {
+
+ @Override
+ public void onAppIdleStateChanged(final String packageName, final @UserIdInt int userId,
+ boolean idle, int bucket, int reason) {
+ // Update job bookkeeping out of band.
+ BackgroundThread.getHandler().post(() -> {
+ final int bucketIndex = JobSchedulerService.standbyBucketToBucketIndex(bucket);
+ if (DEBUG) {
+ Slog.i(TAG, "Moving pkg " + string(userId, packageName) + " to bucketIndex "
+ + bucketIndex);
+ }
+ synchronized (mLock) {
+ ArraySet<JobStatus> jobs = mTrackedJobs.get(userId, packageName);
+ if (jobs == null || jobs.size() == 0) {
+ return;
+ }
+ for (int i = jobs.size() - 1; i >= 0; i--) {
+ JobStatus js = jobs.valueAt(i);
+ js.setStandbyBucket(bucketIndex);
+ }
+ Timer timer = mPkgTimers.get(userId, packageName);
+ if (timer != null && timer.isActive()) {
+ timer.rescheduleCutoff();
+ }
+ if (!mShouldThrottle || maybeUpdateConstraintForPkgLocked(userId,
+ packageName)) {
+ mStateChangedListener.onControllerStateChanged();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onParoleStateChanged(final boolean isParoleOn) {
+ mInParole = isParoleOn;
+ if (DEBUG) Slog.i(TAG, "Global parole state now " + (isParoleOn ? "ON" : "OFF"));
+ // Update job bookkeeping out of band.
+ BackgroundThread.getHandler().post(() -> {
+ synchronized (mLock) {
+ maybeUpdateAllConstraintsLocked();
+ }
+ });
+ }
+ }
+
+ private final class DeleteTimingSessionsFunctor implements Consumer<List<TimingSession>> {
+ private final Predicate<TimingSession> mTooOld = new Predicate<TimingSession>() {
+ public boolean test(TimingSession ts) {
+ return ts.endTimeElapsed <= sElapsedRealtimeClock.millis() - MAX_PERIOD_MS;
+ }
+ };
+
+ @Override
+ public void accept(List<TimingSession> sessions) {
+ if (sessions != null) {
+ // Remove everything older than MAX_PERIOD_MS time ago.
+ sessions.removeIf(mTooOld);
+ }
+ }
+ }
+
+ private final DeleteTimingSessionsFunctor mDeleteOldSessionsFunctor =
+ new DeleteTimingSessionsFunctor();
+
+ @VisibleForTesting
+ void deleteObsoleteSessionsLocked() {
+ mTimingSessions.forEach(mDeleteOldSessionsFunctor);
+ }
+
+ private class QcHandler extends Handler {
+ QcHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ synchronized (mLock) {
+ switch (msg.what) {
+ case MSG_REACHED_QUOTA: {
+ Package pkg = (Package) msg.obj;
+ if (DEBUG) Slog.d(TAG, "Checking if " + pkg + " has reached its quota.");
+
+ long timeRemainingMs = getRemainingExecutionTimeLocked(pkg.userId,
+ pkg.packageName);
+ if (timeRemainingMs <= 50) {
+ // Less than 50 milliseconds left. Start process of shutting down jobs.
+ if (DEBUG) Slog.d(TAG, pkg + " has reached its quota.");
+ if (maybeUpdateConstraintForPkgLocked(pkg.userId, pkg.packageName)) {
+ mStateChangedListener.onControllerStateChanged();
+ }
+ } else {
+ // This could potentially happen if an old session phases out while a
+ // job is currently running.
+ // Reschedule message
+ Message rescheduleMsg = obtainMessage(MSG_REACHED_QUOTA, pkg);
+ if (DEBUG) {
+ Slog.d(TAG, pkg + " has " + timeRemainingMs + "ms left.");
+ }
+ sendMessageDelayed(rescheduleMsg, timeRemainingMs);
+ }
+ break;
+ }
+ case MSG_CLEAN_UP_SESSIONS:
+ if (DEBUG) Slog.d(TAG, "Cleaning up timing sessions.");
+ deleteObsoleteSessionsLocked();
+ maybeScheduleCleanupAlarmLocked();
+
+ break;
+ case MSG_CHECK_PACKAGE: {
+ String packageName = (String) msg.obj;
+ int userId = msg.arg1;
+ if (DEBUG) Slog.d(TAG, "Checking pkg " + string(userId, packageName));
+ if (maybeUpdateConstraintForPkgLocked(userId, packageName)) {
+ mStateChangedListener.onControllerStateChanged();
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ private class QcAlarmListener implements AlarmManager.OnAlarmListener {
+ private final int mUserId;
+ private final String mPackageName;
+ private volatile long mTriggerTimeElapsed;
+
+ QcAlarmListener(int userId, String packageName) {
+ mUserId = userId;
+ mPackageName = packageName;
+ }
+
+ boolean isWaiting() {
+ return mTriggerTimeElapsed > 0;
+ }
+
+ void setTriggerTime(long timeElapsed) {
+ mTriggerTimeElapsed = timeElapsed;
+ }
+
+ long getTriggerTimeElapsed() {
+ return mTriggerTimeElapsed;
+ }
+
+ @Override
+ public void onAlarm() {
+ mHandler.obtainMessage(MSG_CHECK_PACKAGE, mUserId, 0, mPackageName).sendToTarget();
+ mTriggerTimeElapsed = 0;
+ }
+ }
+
+ //////////////////////// TESTING HELPERS /////////////////////////////
+
+ @VisibleForTesting
+ long getAllowedTimePerPeriodMs() {
+ return mAllowedTimePerPeriodMs;
+ }
+
+ @VisibleForTesting
+ @NonNull
+ long[] getBucketWindowSizes() {
+ return mBucketPeriodsMs;
+ }
+
+ @VisibleForTesting
+ @NonNull
+ Handler getHandler() {
+ return mHandler;
+ }
+
+ @VisibleForTesting
+ long getInQuotaBufferMs() {
+ return mQuotaBufferMs;
+ }
+
+ @VisibleForTesting
+ @Nullable
+ List<TimingSession> getTimingSessions(int userId, String packageName) {
+ return mTimingSessions.get(userId, packageName);
+ }
+
+ //////////////////////////// DATA DUMP //////////////////////////////
+
+ @Override
+ public void dumpControllerStateLocked(final IndentingPrintWriter pw,
+ final Predicate<JobStatus> predicate) {
+ pw.println("Is throttling: " + mShouldThrottle);
+ pw.println("Is charging: " + mChargeTracker.isCharging());
+ pw.println("In parole: " + mInParole);
+ pw.println();
+
+ mTrackedJobs.forEach((jobs) -> {
+ for (int j = 0; j < jobs.size(); j++) {
+ final JobStatus js = jobs.valueAt(j);
+ if (!predicate.test(js)) {
+ continue;
+ }
+ pw.print("#");
+ js.printUniqueId(pw);
+ pw.print(" from ");
+ UserHandle.formatUid(pw, js.getSourceUid());
+ pw.println();
+
+ pw.increaseIndent();
+ pw.print(JobStatus.bucketName(getEffectiveStandbyBucket(js)));
+ pw.print(", ");
+ if (js.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA)) {
+ pw.print("within quota");
+ } else {
+ pw.print("not within quota");
+ }
+ pw.print(", ");
+ pw.print(getRemainingExecutionTimeLocked(js));
+ pw.print("ms remaining in quota");
+ pw.decreaseIndent();
+ pw.println();
+ }
+ });
+
+ pw.println();
+ for (int u = 0; u < mPkgTimers.numUsers(); ++u) {
+ final int userId = mPkgTimers.keyAt(u);
+ for (int p = 0; p < mPkgTimers.numPackagesForUser(userId); ++p) {
+ final String pkgName = mPkgTimers.keyAt(u, p);
+ mPkgTimers.valueAt(u, p).dump(pw, predicate);
+ pw.println();
+ List<TimingSession> sessions = mTimingSessions.get(userId, pkgName);
+ if (sessions != null) {
+ pw.increaseIndent();
+ pw.println("Saved sessions:");
+ pw.increaseIndent();
+ for (int j = sessions.size() - 1; j >= 0; j--) {
+ TimingSession session = sessions.get(j);
+ session.dump(pw);
+ }
+ pw.decreaseIndent();
+ pw.decreaseIndent();
+ pw.println();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void dumpControllerStateLocked(ProtoOutputStream proto, long fieldId,
+ Predicate<JobStatus> predicate) {
+ final long token = proto.start(fieldId);
+ final long mToken = proto.start(StateControllerProto.QUOTA);
+
+ proto.write(StateControllerProto.QuotaController.IS_CHARGING, mChargeTracker.isCharging());
+ proto.write(StateControllerProto.QuotaController.IS_IN_PAROLE, mInParole);
+
+ mTrackedJobs.forEach((jobs) -> {
+ for (int j = 0; j < jobs.size(); j++) {
+ final JobStatus js = jobs.valueAt(j);
+ if (!predicate.test(js)) {
+ continue;
+ }
+ final long jsToken = proto.start(
+ StateControllerProto.QuotaController.TRACKED_JOBS);
+ js.writeToShortProto(proto,
+ StateControllerProto.QuotaController.TrackedJob.INFO);
+ proto.write(StateControllerProto.QuotaController.TrackedJob.SOURCE_UID,
+ js.getSourceUid());
+ proto.write(
+ StateControllerProto.QuotaController.TrackedJob.EFFECTIVE_STANDBY_BUCKET,
+ getEffectiveStandbyBucket(js));
+ proto.write(StateControllerProto.QuotaController.TrackedJob.HAS_QUOTA,
+ js.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ proto.write(StateControllerProto.QuotaController.TrackedJob.REMAINING_QUOTA_MS,
+ getRemainingExecutionTimeLocked(js));
+ proto.end(jsToken);
+ }
+ });
+
+ for (int u = 0; u < mPkgTimers.numUsers(); ++u) {
+ final int userId = mPkgTimers.keyAt(u);
+ for (int p = 0; p < mPkgTimers.numPackagesForUser(userId); ++p) {
+ final String pkgName = mPkgTimers.keyAt(u, p);
+ final long psToken = proto.start(
+ StateControllerProto.QuotaController.PACKAGE_STATS);
+ mPkgTimers.valueAt(u, p).dump(proto,
+ StateControllerProto.QuotaController.PackageStats.TIMER, predicate);
+
+ List<TimingSession> sessions = mTimingSessions.get(userId, pkgName);
+ if (sessions != null) {
+ for (int j = sessions.size() - 1; j >= 0; j--) {
+ TimingSession session = sessions.get(j);
+ session.dump(proto,
+ StateControllerProto.QuotaController.PackageStats.SAVED_SESSIONS);
+ }
+ }
+
+ proto.end(psToken);
+ }
+ }
+
+ proto.end(mToken);
+ proto.end(token);
+ }
+}
diff --git a/services/core/java/com/android/server/job/controllers/StateController.java b/services/core/java/com/android/server/job/controllers/StateController.java
index c2be28336406..b439c0ddd028 100644
--- a/services/core/java/com/android/server/job/controllers/StateController.java
+++ b/services/core/java/com/android/server/job/controllers/StateController.java
@@ -53,22 +53,31 @@ public abstract class StateController {
* preexisting tasks.
*/
public abstract void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob);
+
/**
* Optionally implement logic here to prepare the job to be executed.
*/
public void prepareForExecutionLocked(JobStatus jobStatus) {
}
+
/**
* Remove task - this will happen if the task is cancelled, completed, etc.
*/
public abstract void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob,
boolean forUpdate);
+
/**
* Called when a new job is being created to reschedule an old failed job.
*/
public void rescheduleForFailureLocked(JobStatus newJob, JobStatus failureToReschedule) {
}
+ /**
+ * Called when the JobScheduler.Constants are updated.
+ */
+ public void onConstantsUpdatedLocked() {
+ }
+
public abstract void dumpControllerStateLocked(IndentingPrintWriter pw,
Predicate<JobStatus> predicate);
public abstract void dumpControllerStateLocked(ProtoOutputStream proto, long fieldId,
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 255a003bb542..daf4b8ba6d48 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -1640,7 +1640,6 @@ final class ActivityRecord extends ConfigurationContainer {
final IAppTransitionAnimationSpecsFuture specsFuture =
pendingOptions.getSpecsFuture();
if (specsFuture != null) {
- // TODO(multidisplay): Shouldn't be really used anymore from next CL.
displayContent.mAppTransition.overridePendingAppTransitionMultiThumbFuture(
specsFuture, pendingOptions.getOnAnimationStartListener(),
animationType == ANIM_THUMBNAIL_ASPECT_SCALE_UP);
@@ -1669,7 +1668,6 @@ final class ActivityRecord extends ConfigurationContainer {
.overridePendingAppTransitionStartCrossProfileApps();
break;
case ANIM_REMOTE_ANIMATION:
- // TODO(multidisplay): Will pass displayId and adjust dependencies from next CL.
displayContent.mAppTransition.overridePendingAppTransitionRemote(
pendingOptions.getRemoteAnimationAdapter());
break;
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java b/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java
index 0cdbedba7318..0fc890a39fed 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java
@@ -402,7 +402,8 @@ public abstract class ActivityTaskManagerInternal {
int wakefulness);
/** Writes the current window process states to the proto stream. */
- public abstract void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage);
+ public abstract void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage,
+ int wakeFullness, boolean testPssMode);
/** Dump the current activities state. */
public abstract boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name,
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 0967afda6d2d..61eb9d4b8abf 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -863,6 +863,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
*/
Configuration getGlobalConfigurationForCallingPid() {
final int pid = Binder.getCallingPid();
+ return getGlobalConfigurationForPid(pid);
+ }
+
+ /**
+ * Return the global configuration used by the process corresponding to the given pid.
+ */
+ Configuration getGlobalConfigurationForPid(int pid) {
if (pid == MY_PID || pid < 0) {
return getGlobalConfiguration();
}
@@ -4701,26 +4708,21 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
}
- void writeSleepStateToProto(ProtoOutputStream proto) {
+ private void writeSleepStateToProto(ProtoOutputStream proto, int wakeFullness,
+ boolean testPssMode) {
+ final long sleepToken = proto.start(ActivityManagerServiceDumpProcessesProto.SLEEP_STATUS);
+ proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.WAKEFULNESS,
+ PowerManagerInternal.wakefulnessToProtoEnum(wakeFullness));
for (ActivityTaskManagerInternal.SleepToken st : mRootActivityContainer.mSleepTokens) {
proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEP_TOKENS,
st.toString());
}
-
- if (mRunningVoice != null) {
- final long vrToken = proto.start(
- ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE);
- proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION,
- mRunningVoice.toString());
- mVoiceWakeLock.writeToProto(
- proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK);
- proto.end(vrToken);
- }
-
proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SLEEPING, mSleeping);
proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.SHUTTING_DOWN,
mShuttingDown);
- mVrController.writeToProto(proto, ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER);
+ proto.write(ActivityManagerServiceDumpProcessesProto.SleepStatus.TEST_PSS_MODE,
+ testPssMode);
+ proto.end(sleepToken);
}
int getCurrentUserId() {
@@ -6599,12 +6601,24 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
@Override
- public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage) {
+ public void writeProcessesToProto(ProtoOutputStream proto, String dumpPackage,
+ int wakeFullness, boolean testPssMode) {
synchronized (mGlobalLock) {
if (dumpPackage == null) {
getGlobalConfiguration().writeToProto(proto, GLOBAL_CONFIGURATION);
proto.write(CONFIG_WILL_CHANGE, getTopDisplayFocusedStack().mConfigWillChange);
- writeSleepStateToProto(proto);
+ writeSleepStateToProto(proto, wakeFullness, testPssMode);
+ if (mRunningVoice != null) {
+ final long vrToken = proto.start(
+ ActivityManagerServiceDumpProcessesProto.RUNNING_VOICE);
+ proto.write(ActivityManagerServiceDumpProcessesProto.Voice.SESSION,
+ mRunningVoice.toString());
+ mVoiceWakeLock.writeToProto(
+ proto, ActivityManagerServiceDumpProcessesProto.Voice.WAKELOCK);
+ proto.end(vrToken);
+ }
+ mVrController.writeToProto(proto,
+ ActivityManagerServiceDumpProcessesProto.VR_CONTROLLER);
if (mController != null) {
final long token = proto.start(CONTROLLER);
proto.write(CONTROLLER, mController.toString());
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index 581cec928334..d4bd91b008d4 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -222,6 +222,7 @@ public class DisplayPolicy {
private volatile int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
private volatile boolean mHdmiPlugged;
+ private volatile boolean mHasStatusBar;
private volatile boolean mHasNavigationBar;
// Can the navigation bar ever move to the side?
private volatile boolean mNavigationBarCanMove;
@@ -523,6 +524,7 @@ public class DisplayPolicy {
mNavigationBarCanMove = width != height && shortSizeDp < 600;
if (mDisplayContent.isDefaultDisplay) {
+ mHasStatusBar = true;
mHasNavigationBar = mContext.getResources().getBoolean(R.bool.config_showNavigationBar);
// Allow a system property to override this. Used by the emulator.
@@ -534,6 +536,7 @@ public class DisplayPolicy {
mHasNavigationBar = true;
}
} else {
+ mHasStatusBar = false;
mHasNavigationBar = mDisplayContent.getDisplay().supportsSystemDecorations();
}
}
@@ -589,6 +592,10 @@ public class DisplayPolicy {
return mHasNavigationBar;
}
+ public boolean hasStatusBar() {
+ return mHasStatusBar;
+ }
+
public boolean navigationBarCanMove() {
return mNavigationBarCanMove;
}
@@ -2493,12 +2500,19 @@ public class DisplayPolicy {
final int landscapeRotation = displayRotation.getLandscapeRotation();
final int seascapeRotation = displayRotation.getSeascapeRotation();
- mStatusBarHeightForRotation[portraitRotation] =
- mStatusBarHeightForRotation[upsideDownRotation] =
- res.getDimensionPixelSize(R.dimen.status_bar_height_portrait);
- mStatusBarHeightForRotation[landscapeRotation] =
- mStatusBarHeightForRotation[seascapeRotation] =
- res.getDimensionPixelSize(R.dimen.status_bar_height_landscape);
+ if (hasStatusBar()) {
+ mStatusBarHeightForRotation[portraitRotation] =
+ mStatusBarHeightForRotation[upsideDownRotation] =
+ res.getDimensionPixelSize(R.dimen.status_bar_height_portrait);
+ mStatusBarHeightForRotation[landscapeRotation] =
+ mStatusBarHeightForRotation[seascapeRotation] =
+ res.getDimensionPixelSize(R.dimen.status_bar_height_landscape);
+ } else {
+ mStatusBarHeightForRotation[portraitRotation] =
+ mStatusBarHeightForRotation[upsideDownRotation] =
+ mStatusBarHeightForRotation[landscapeRotation] =
+ mStatusBarHeightForRotation[seascapeRotation] = 0;
+ }
// Height of the navigation bar when presented horizontally at bottom
mNavigationBarHeightForRotationDefault[portraitRotation] =
diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java
index 88b22cb5e01e..c1e9a7353fd5 100644
--- a/services/core/java/com/android/server/wm/InputMonitor.java
+++ b/services/core/java/com/android/server/wm/InputMonitor.java
@@ -194,7 +194,7 @@ final class InputMonitor {
final boolean hasFocus, final boolean hasWallpaper) {
// Add a window to our list of input windows.
inputWindowHandle.name = child.toString();
- flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags);
+ flags = child.getSurfaceTouchableRegion(inputWindowHandle.touchableRegion, flags);
inputWindowHandle.layoutParamsFlags = flags;
inputWindowHandle.layoutParamsType = type;
inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
diff --git a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
index 4ae2a79e2697..1fb7979fa3e2 100644
--- a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
@@ -44,6 +44,7 @@ import android.app.ActivityOptions;
import android.app.WindowConfiguration;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
+import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Build;
import android.util.Slog;
@@ -526,12 +527,24 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
adjustBoundsToAvoidConflict(display, inOutBounds);
}
+ private int convertOrientationToScreenOrientation(int orientation) {
+ switch (orientation) {
+ case Configuration.ORIENTATION_LANDSCAPE:
+ return SCREEN_ORIENTATION_LANDSCAPE;
+ case Configuration.ORIENTATION_PORTRAIT:
+ return SCREEN_ORIENTATION_PORTRAIT;
+ default:
+ return SCREEN_ORIENTATION_UNSPECIFIED;
+ }
+ }
+
private int resolveOrientation(@NonNull ActivityRecord root, @NonNull ActivityDisplay display,
@NonNull Rect bounds) {
int orientation = resolveOrientation(root);
if (orientation == SCREEN_ORIENTATION_LOCKED) {
- orientation = bounds.isEmpty() ? display.getConfiguration().orientation
+ orientation = bounds.isEmpty()
+ ? convertOrientationToScreenOrientation(display.getConfiguration().orientation)
: orientationFromBounds(bounds);
if (DEBUG) {
appendLog(bounds.isEmpty() ? "locked-orientation-from-display=" + orientation
diff --git a/services/core/java/com/android/server/wm/WindowManagerInternal.java b/services/core/java/com/android/server/wm/WindowManagerInternal.java
index e83b8634925e..9f1a58770611 100644
--- a/services/core/java/com/android/server/wm/WindowManagerInternal.java
+++ b/services/core/java/com/android/server/wm/WindowManagerInternal.java
@@ -19,7 +19,6 @@ package com.android.server.wm;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ClipData;
-import android.content.res.Configuration;
import android.graphics.Rect;
import android.graphics.Region;
import android.hardware.display.DisplayManagerInternal;
@@ -449,11 +448,4 @@ public abstract class WindowManagerInternal {
* Return the display Id for given window.
*/
public abstract int getDisplayIdForWindow(IBinder windowToken);
-
- // TODO: use WindowProcessController once go/wm-unified is done.
- /**
- * Notifies the window manager that configuration of the process associated with the input pid
- * changed.
- */
- public abstract void onProcessConfigurationChanged(int pid, Configuration newConfig);
}
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 52b24b3e7307..002d6d409abe 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -735,6 +735,7 @@ public class WindowManagerService extends IWindowManager.Stub
final InputManagerService mInputManager;
final DisplayManagerInternal mDisplayManagerInternal;
final DisplayManager mDisplayManager;
+ final ActivityTaskManagerService mAtmService;
// Indicates whether this device supports wide color gamut / HDR rendering
private boolean mHasWideColorGamutSupport;
@@ -897,11 +898,10 @@ public class WindowManagerService extends IWindowManager.Stub
public static WindowManagerService main(final Context context, final InputManagerService im,
final boolean showBootMsgs, final boolean onlyCore, WindowManagerPolicy policy,
- final WindowManagerGlobalLock globalLock) {
+ ActivityTaskManagerService atm) {
DisplayThread.getHandler().runWithScissors(() ->
sInstance = new WindowManagerService(context, im, showBootMsgs, onlyCore, policy,
- globalLock),
- 0);
+ atm), 0);
return sInstance;
}
@@ -923,9 +923,10 @@ public class WindowManagerService extends IWindowManager.Stub
private WindowManagerService(Context context, InputManagerService inputManager,
boolean showBootMsgs, boolean onlyCore, WindowManagerPolicy policy,
- WindowManagerGlobalLock globalLock) {
+ ActivityTaskManagerService atm) {
installLock(this, INDEX_WINDOW);
- mGlobalLock = globalLock;
+ mGlobalLock = atm.getGlobalLock();
+ mAtmService = atm;
mContext = context;
mAllowBootMessages = showBootMsgs;
mOnlyCore = onlyCore;
@@ -7281,19 +7282,6 @@ public class WindowManagerService extends IWindowManager.Stub
return Display.INVALID_DISPLAY;
}
}
-
- @Override
- public void onProcessConfigurationChanged(int pid, Configuration newConfig) {
- synchronized (mGlobalLock) {
- Configuration currentConfig = mProcessConfigurations.get(pid);
- if (currentConfig == null) {
- currentConfig = new Configuration(newConfig);
- } else {
- currentConfig.setTo(newConfig);
- }
- mProcessConfigurations.put(pid, currentConfig);
- }
- }
}
void registerAppFreezeListener(AppFreezeListener listener) {
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 5cc36235ce75..e115fed4db9a 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -2143,7 +2143,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
}
}
- int getTouchableRegion(Region region, int flags) {
+ int getSurfaceTouchableRegion(Region region, int flags) {
final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
if (modal && mAppToken != null) {
// Limit the outer touch to the activity stack region.
@@ -2171,7 +2171,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
} else {
// Not modal or full screen modal
- getTouchableRegion(region);
+ getTouchableRegion(region, true /* forSurface */);
}
return flags;
@@ -2263,8 +2263,10 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
// For child windows we want to use the pid for the parent window in case the the child
// window was added from another process.
final int pid = getParentWindow() != null ? getParentWindow().mSession.mPid : mSession.mPid;
- mTempConfiguration.setTo(mWmService.mProcessConfigurations.get(
- pid, mWmService.mRoot.getConfiguration()));
+ final Configuration processConfig =
+ mWmService.mAtmService.getGlobalConfigurationForPid(pid);
+ mTempConfiguration.setTo(processConfig == null
+ ? mWmService.mRoot.getConfiguration() : processConfig);
return mTempConfiguration;
}
@@ -2805,7 +2807,13 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
frame.right - inset.right, frame.bottom - inset.bottom);
}
+ /** Get the touchable region in global coordinates. */
void getTouchableRegion(Region outRegion) {
+ getTouchableRegion(outRegion, false /* forSurface */);
+ }
+
+ /** If {@param forSuface} is {@code true}, the region will be translated to surface based. */
+ private void getTouchableRegion(Region outRegion, boolean forSurface) {
if (inPinnedWindowingMode() && !isFocused()) {
outRegion.setEmpty();
return;
@@ -2816,22 +2824,26 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
default:
case TOUCHABLE_INSETS_FRAME:
outRegion.set(frame);
- outRegion.translate(-frame.left, -frame.top);
break;
case TOUCHABLE_INSETS_CONTENT:
applyInsets(outRegion, frame, mGivenContentInsets);
- outRegion.translate(-frame.left, -frame.top);
break;
case TOUCHABLE_INSETS_VISIBLE:
applyInsets(outRegion, frame, mGivenVisibleInsets);
- outRegion.translate(-frame.left, -frame.top);
break;
case TOUCHABLE_INSETS_REGION: {
outRegion.set(mGivenTouchableRegion);
break;
}
}
- outRegion.translate(mAttrs.surfaceInsets.left, mAttrs.surfaceInsets.top);
+
+ if (forSurface) {
+ if (mTouchableInsets != TOUCHABLE_INSETS_REGION) {
+ outRegion.translate(-frame.left, -frame.top);
+ }
+ outRegion.getBounds(mTmpRect);
+ applyInsets(outRegion, mTmpRect, mAttrs.surfaceInsets);
+ }
}
private void cropRegionToStackBoundsIfNeeded(Region region) {
diff --git a/services/intelligence/java/com/android/server/intelligence/ContentCaptureSession.java b/services/intelligence/java/com/android/server/intelligence/ContentCaptureSession.java
index 14912c474995..05b8201f112e 100644
--- a/services/intelligence/java/com/android/server/intelligence/ContentCaptureSession.java
+++ b/services/intelligence/java/com/android/server/intelligence/ContentCaptureSession.java
@@ -16,6 +16,7 @@
package com.android.server.intelligence;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
import android.os.IBinder;
@@ -25,12 +26,13 @@ import android.service.intelligence.SmartSuggestionsService;
import android.service.intelligence.SnapshotData;
import android.util.Slog;
import android.view.autofill.AutofillId;
+import android.view.autofill.AutofillValue;
import android.view.autofill.IAutoFillManagerClient;
import android.view.intelligence.ContentCaptureEvent;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
-import com.android.server.AbstractRemoteService;
+import com.android.server.infra.AbstractRemoteService;
import com.android.server.intelligence.IntelligenceManagerInternal.AugmentedAutofillCallback;
import com.android.server.intelligence.RemoteIntelligenceService.RemoteIntelligenceServiceCallbacks;
@@ -98,8 +100,10 @@ final class ContentCaptureSession implements RemoteIntelligenceServiceCallbacks
* Requests the service to autofill the given field.
*/
public AugmentedAutofillCallback requestAutofillLocked(@NonNull IAutoFillManagerClient client,
- int autofillSessionId, @NonNull AutofillId focusedId) {
- mRemoteService.onRequestAutofillLocked(mId, client, autofillSessionId, focusedId);
+ int autofillSessionId, @NonNull AutofillId focusedId,
+ @Nullable AutofillValue focusedValue) {
+ mRemoteService.onRequestAutofillLocked(mId, client, autofillSessionId, focusedId,
+ focusedValue);
if (mAutofillCallback == null) {
mAutofillCallback = () -> mRemoteService.onDestroyAutofillWindowsRequest(mId);
}
diff --git a/services/intelligence/java/com/android/server/intelligence/IntelligenceManagerService.java b/services/intelligence/java/com/android/server/intelligence/IntelligenceManagerService.java
index b8f2ad01d502..a760cbd039e4 100644
--- a/services/intelligence/java/com/android/server/intelligence/IntelligenceManagerService.java
+++ b/services/intelligence/java/com/android/server/intelligence/IntelligenceManagerService.java
@@ -35,6 +35,7 @@ import android.os.UserManager;
import android.service.intelligence.InteractionSessionId;
import android.util.Slog;
import android.view.autofill.AutofillId;
+import android.view.autofill.AutofillValue;
import android.view.autofill.IAutoFillManagerClient;
import android.view.intelligence.ContentCaptureEvent;
import android.view.intelligence.IIntelligenceManager;
@@ -43,8 +44,8 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.IResultReceiver;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.Preconditions;
-import com.android.server.AbstractMasterSystemService;
import com.android.server.LocalServices;
+import com.android.server.infra.AbstractMasterSystemService;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -257,12 +258,13 @@ public final class IntelligenceManagerService extends
@Override
public AugmentedAutofillCallback requestAutofill(@UserIdInt int userId,
@NonNull IAutoFillManagerClient client, @NonNull IBinder activityToken,
- int autofillSessionId, @NonNull AutofillId focusedId) {
+ int autofillSessionId, @NonNull AutofillId focusedId,
+ @Nullable AutofillValue focusedValue) {
synchronized (mLock) {
final IntelligencePerUserService service = peekServiceForUserLocked(userId);
if (service != null) {
return service.requestAutofill(client, activityToken, autofillSessionId,
- focusedId);
+ focusedId, focusedValue);
}
}
return null;
diff --git a/services/intelligence/java/com/android/server/intelligence/IntelligencePerUserService.java b/services/intelligence/java/com/android/server/intelligence/IntelligencePerUserService.java
index 6f047c51633a..c8448e142902 100644
--- a/services/intelligence/java/com/android/server/intelligence/IntelligencePerUserService.java
+++ b/services/intelligence/java/com/android/server/intelligence/IntelligencePerUserService.java
@@ -40,13 +40,14 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Slog;
import android.view.autofill.AutofillId;
+import android.view.autofill.AutofillValue;
import android.view.autofill.IAutoFillManagerClient;
import android.view.intelligence.ContentCaptureEvent;
import android.view.intelligence.ContentCaptureManager;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.IResultReceiver;
-import com.android.server.AbstractPerUserSystemService;
+import com.android.server.infra.AbstractPerUserSystemService;
import com.android.server.intelligence.IntelligenceManagerInternal.AugmentedAutofillCallback;
import java.io.PrintWriter;
@@ -289,13 +290,15 @@ final class IntelligencePerUserService
}
public AugmentedAutofillCallback requestAutofill(@NonNull IAutoFillManagerClient client,
- @NonNull IBinder activityToken, int autofillSessionId, @NonNull AutofillId focusedId) {
+ @NonNull IBinder activityToken, int autofillSessionId, @NonNull AutofillId focusedId,
+ @Nullable AutofillValue focusedValue) {
synchronized (mLock) {
final ContentCaptureSession session = getSession(activityToken);
if (session != null) {
// TODO(b/111330312): log metrics
if (mMaster.verbose) Slog.v(TAG, "requestAugmentedAutofill()");
- return session.requestAutofillLocked(client, autofillSessionId, focusedId);
+ return session.requestAutofillLocked(client, autofillSessionId, focusedId,
+ focusedValue);
}
if (mMaster.debug) {
Slog.d(TAG, "requestAutofill(): no session for " + activityToken);
diff --git a/services/intelligence/java/com/android/server/intelligence/RemoteIntelligenceService.java b/services/intelligence/java/com/android/server/intelligence/RemoteIntelligenceService.java
index d9f4f20dc971..c4fbdca0ff2f 100644
--- a/services/intelligence/java/com/android/server/intelligence/RemoteIntelligenceService.java
+++ b/services/intelligence/java/com/android/server/intelligence/RemoteIntelligenceService.java
@@ -23,6 +23,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.IInterface;
import android.os.RemoteException;
+import android.os.SystemClock;
import android.service.intelligence.ContentCaptureEventsRequest;
import android.service.intelligence.IIntelligenceService;
import android.service.intelligence.InteractionContext;
@@ -32,11 +33,12 @@ import android.text.format.DateUtils;
import android.util.Slog;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillManager;
+import android.view.autofill.AutofillValue;
import android.view.autofill.IAutoFillManagerClient;
import android.view.intelligence.ContentCaptureEvent;
import com.android.internal.os.IResultReceiver;
-import com.android.server.AbstractMultiplePendingRequestsRemoteService;
+import com.android.server.infra.AbstractMultiplePendingRequestsRemoteService;
import java.util.List;
@@ -114,10 +116,10 @@ final class RemoteIntelligenceService
*/
public void onRequestAutofillLocked(@NonNull InteractionSessionId sessionId,
@NonNull IAutoFillManagerClient client, int autofillSessionId,
- @NonNull AutofillId focusedId) {
+ @NonNull AutofillId focusedId, @Nullable AutofillValue focusedValue) {
cancelScheduledUnbind();
scheduleRequest(new PendingAutofillRequest(this, sessionId, client, autofillSessionId,
- focusedId));
+ focusedId, focusedValue));
}
/**
@@ -222,16 +224,20 @@ final class RemoteIntelligenceService
private static final class PendingAutofillRequest extends MyPendingRequest {
private final @NonNull AutofillId mFocusedId;
+ private final @Nullable AutofillValue mFocusedValue;
private final @NonNull IAutoFillManagerClient mClient;
private final int mAutofillSessionId;
+ private final long mRequestTime = SystemClock.elapsedRealtime();
protected PendingAutofillRequest(@NonNull RemoteIntelligenceService service,
@NonNull InteractionSessionId sessionId, @NonNull IAutoFillManagerClient client,
- int autofillSessionId, @NonNull AutofillId focusedId) {
+ int autofillSessionId, @NonNull AutofillId focusedId,
+ @Nullable AutofillValue focusedValue) {
super(service, sessionId);
mClient = client;
mAutofillSessionId = autofillSessionId;
mFocusedId = focusedId;
+ mFocusedValue = focusedValue;
}
@Override // from MyPendingRequest
@@ -243,7 +249,7 @@ final class RemoteIntelligenceService
final IBinder realClient = resultData
.getBinder(AutofillManager.EXTRA_AUGMENTED_AUTOFILL_CLIENT);
remoteService.mService.onAutofillRequest(mSessionId, realClient,
- mAutofillSessionId, mFocusedId);
+ mAutofillSessionId, mFocusedId, mFocusedValue, mRequestTime);
}
};
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 05ff6601a477..c4d2a914facf 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -926,7 +926,7 @@ public final class SystemServer {
ConcurrentUtils.waitForFutureNoInterrupt(mSensorServiceStart, START_SENSOR_SERVICE);
mSensorServiceStart = null;
wm = WindowManagerService.main(context, inputManager, !mFirstBoot, mOnlyCore,
- new PhoneWindowManager(), mWindowManagerGlobalLock);
+ new PhoneWindowManager(), mActivityManagerService.mActivityTaskManager);
ServiceManager.addService(Context.WINDOW_SERVICE, wm, /* allowIsolated= */ false,
DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PROTO);
ServiceManager.addService(Context.INPUT_SERVICE, inputManager,
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java
new file mode 100644
index 000000000000..b2ec83583eba
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java
@@ -0,0 +1,842 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
+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.spyOn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
+import static com.android.server.job.JobSchedulerService.ACTIVE_INDEX;
+import static com.android.server.job.JobSchedulerService.FREQUENT_INDEX;
+import static com.android.server.job.JobSchedulerService.RARE_INDEX;
+import static com.android.server.job.JobSchedulerService.WORKING_INDEX;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.app.AlarmManager;
+import android.app.job.JobInfo;
+import android.app.usage.UsageStatsManager;
+import android.app.usage.UsageStatsManagerInternal;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManagerInternal;
+import android.os.BatteryManager;
+import android.os.BatteryManagerInternal;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.SystemClock;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.server.LocalServices;
+import com.android.server.job.JobSchedulerService;
+import com.android.server.job.JobSchedulerService.Constants;
+import com.android.server.job.controllers.QuotaController.TimingSession;
+
+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;
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public class QuotaControllerTest {
+ private static final long SECOND_IN_MILLIS = 1000L;
+ private static final long MINUTE_IN_MILLIS = 60 * SECOND_IN_MILLIS;
+ private static final long HOUR_IN_MILLIS = 60 * MINUTE_IN_MILLIS;
+ private static final String TAG_CLEANUP = "*job.cleanup*";
+ private static final String TAG_QUOTA_CHECK = "*job.quota_check*";
+ private static final long IN_QUOTA_BUFFER_MILLIS = 30 * SECOND_IN_MILLIS;
+ private static final int CALLING_UID = 1000;
+ private static final String SOURCE_PACKAGE = "com.android.frameworks.mockingservicestests";
+ private static final int SOURCE_USER_ID = 0;
+
+ private BroadcastReceiver mChargingReceiver;
+ private Constants mConstants;
+ private QuotaController mQuotaController;
+
+ private MockitoSession mMockingSession;
+ @Mock
+ private AlarmManager mAlarmManager;
+ @Mock
+ private Context mContext;
+ @Mock
+ private JobSchedulerService mJobSchedulerService;
+ @Mock
+ private UsageStatsManagerInternal mUsageStatsManager;
+
+ @Before
+ public void setUp() {
+ mMockingSession = mockitoSession()
+ .initMocks(this)
+ .strictness(Strictness.LENIENT)
+ .mockStatic(LocalServices.class)
+ .startMocking();
+ // Make sure constants turn on QuotaController.
+ mConstants = new Constants();
+ mConstants.USE_HEARTBEATS = false;
+
+ // Called in StateController constructor.
+ when(mJobSchedulerService.getTestableContext()).thenReturn(mContext);
+ when(mJobSchedulerService.getLock()).thenReturn(mJobSchedulerService);
+ when(mJobSchedulerService.getConstants()).thenReturn(mConstants);
+ // Called in QuotaController constructor.
+ when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
+ when(mContext.getSystemService(Context.ALARM_SERVICE)).thenReturn(mAlarmManager);
+ doReturn(mock(BatteryManagerInternal.class))
+ .when(() -> LocalServices.getService(BatteryManagerInternal.class));
+ doReturn(mUsageStatsManager)
+ .when(() -> LocalServices.getService(UsageStatsManagerInternal.class));
+ // Used in JobStatus.
+ doReturn(mock(PackageManagerInternal.class))
+ .when(() -> LocalServices.getService(PackageManagerInternal.class));
+
+ // Freeze the clocks at this moment in time
+ JobSchedulerService.sSystemClock =
+ Clock.fixed(Clock.systemUTC().instant(), ZoneOffset.UTC);
+ JobSchedulerService.sUptimeMillisClock =
+ Clock.fixed(SystemClock.uptimeMillisClock().instant(), ZoneOffset.UTC);
+ JobSchedulerService.sElapsedRealtimeClock =
+ Clock.fixed(SystemClock.elapsedRealtimeClock().instant(), ZoneOffset.UTC);
+
+ // Initialize real objects.
+ // Capture the listeners.
+ ArgumentCaptor<BroadcastReceiver> receiverCaptor =
+ ArgumentCaptor.forClass(BroadcastReceiver.class);
+ mQuotaController = new QuotaController(mJobSchedulerService);
+
+ verify(mContext).registerReceiver(receiverCaptor.capture(), any());
+ mChargingReceiver = receiverCaptor.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 setCharging() {
+ Intent intent = new Intent(BatteryManager.ACTION_CHARGING);
+ mChargingReceiver.onReceive(mContext, intent);
+ }
+
+ private void setDischarging() {
+ Intent intent = new Intent(BatteryManager.ACTION_DISCHARGING);
+ mChargingReceiver.onReceive(mContext, intent);
+ }
+
+ private void setStandbyBucket(int bucketIndex) {
+ int bucket;
+ switch (bucketIndex) {
+ case ACTIVE_INDEX:
+ bucket = UsageStatsManager.STANDBY_BUCKET_ACTIVE;
+ break;
+ case WORKING_INDEX:
+ bucket = UsageStatsManager.STANDBY_BUCKET_WORKING_SET;
+ break;
+ case FREQUENT_INDEX:
+ bucket = UsageStatsManager.STANDBY_BUCKET_FREQUENT;
+ break;
+ case RARE_INDEX:
+ bucket = UsageStatsManager.STANDBY_BUCKET_RARE;
+ break;
+ default:
+ bucket = UsageStatsManager.STANDBY_BUCKET_NEVER;
+ }
+ when(mUsageStatsManager.getAppStandbyBucket(eq(SOURCE_PACKAGE), eq(SOURCE_USER_ID),
+ anyLong())).thenReturn(bucket);
+ }
+
+ private void setStandbyBucket(int bucketIndex, JobStatus job) {
+ setStandbyBucket(bucketIndex);
+ job.setStandbyBucket(bucketIndex);
+ }
+
+ private JobStatus createJobStatus(String testTag, int jobId) {
+ JobInfo jobInfo = new JobInfo.Builder(jobId,
+ new ComponentName(mContext, "TestQuotaJobService"))
+ .setMinimumLatency(Math.abs(jobId) + 1)
+ .build();
+ return JobStatus.createFromJobInfo(
+ jobInfo, CALLING_UID, SOURCE_PACKAGE, SOURCE_USER_ID, testTag);
+ }
+
+ private TimingSession createTimingSession(long start, long duration, int count) {
+ return new TimingSession(start, start + duration, count);
+ }
+
+ @Test
+ public void testSaveTimingSession() {
+ assertNull(mQuotaController.getTimingSessions(0, "com.android.test"));
+
+ List<TimingSession> expected = new ArrayList<>();
+ TimingSession one = new TimingSession(1, 10, 1);
+ TimingSession two = new TimingSession(11, 20, 2);
+ TimingSession thr = new TimingSession(21, 30, 3);
+
+ mQuotaController.saveTimingSession(0, "com.android.test", one);
+ expected.add(one);
+ assertEquals(expected, mQuotaController.getTimingSessions(0, "com.android.test"));
+
+ mQuotaController.saveTimingSession(0, "com.android.test", two);
+ expected.add(two);
+ assertEquals(expected, mQuotaController.getTimingSessions(0, "com.android.test"));
+
+ mQuotaController.saveTimingSession(0, "com.android.test", thr);
+ expected.add(thr);
+ assertEquals(expected, mQuotaController.getTimingSessions(0, "com.android.test"));
+ }
+
+ @Test
+ public void testDeleteObsoleteSessionsLocked() {
+ final long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+ TimingSession one = createTimingSession(
+ now - 10 * MINUTE_IN_MILLIS, 9 * MINUTE_IN_MILLIS, 3);
+ TimingSession two = createTimingSession(
+ now - (70 * MINUTE_IN_MILLIS), 9 * MINUTE_IN_MILLIS, 1);
+ TimingSession thr = createTimingSession(
+ now - (3 * HOUR_IN_MILLIS + 10 * MINUTE_IN_MILLIS), 9 * MINUTE_IN_MILLIS, 1);
+ // Overlaps 24 hour boundary.
+ TimingSession fou = createTimingSession(
+ now - (24 * HOUR_IN_MILLIS + 2 * MINUTE_IN_MILLIS), 7 * MINUTE_IN_MILLIS, 1);
+ // Way past the 24 hour boundary.
+ TimingSession fiv = createTimingSession(
+ now - (25 * HOUR_IN_MILLIS), 5 * MINUTE_IN_MILLIS, 4);
+ List<TimingSession> expected = new ArrayList<>();
+ // Added in correct (chronological) order.
+ expected.add(fou);
+ expected.add(thr);
+ expected.add(two);
+ expected.add(one);
+ mQuotaController.saveTimingSession(0, "com.android.test", fiv);
+ mQuotaController.saveTimingSession(0, "com.android.test", fou);
+ mQuotaController.saveTimingSession(0, "com.android.test", thr);
+ mQuotaController.saveTimingSession(0, "com.android.test", two);
+ mQuotaController.saveTimingSession(0, "com.android.test", one);
+
+ mQuotaController.deleteObsoleteSessionsLocked();
+
+ assertEquals(expected, mQuotaController.getTimingSessions(0, "com.android.test"));
+ }
+
+ @Test
+ public void testGetTrailingExecutionTimeLocked_NoTimer() {
+ final long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+ // Added in chronological order.
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - (6 * HOUR_IN_MILLIS), 10 * MINUTE_IN_MILLIS, 5));
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(
+ now - (2 * HOUR_IN_MILLIS + MINUTE_IN_MILLIS), 6 * MINUTE_IN_MILLIS, 5));
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - (HOUR_IN_MILLIS), MINUTE_IN_MILLIS, 1));
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(
+ now - (HOUR_IN_MILLIS - 10 * MINUTE_IN_MILLIS), MINUTE_IN_MILLIS, 1));
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 5 * MINUTE_IN_MILLIS, 4 * MINUTE_IN_MILLIS, 3));
+
+ assertEquals(0, mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ MINUTE_IN_MILLIS));
+ assertEquals(2 * MINUTE_IN_MILLIS,
+ mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ 3 * MINUTE_IN_MILLIS));
+ assertEquals(4 * MINUTE_IN_MILLIS,
+ mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ 5 * MINUTE_IN_MILLIS));
+ assertEquals(4 * MINUTE_IN_MILLIS,
+ mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ 49 * MINUTE_IN_MILLIS));
+ assertEquals(5 * MINUTE_IN_MILLIS,
+ mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ 50 * MINUTE_IN_MILLIS));
+ assertEquals(6 * MINUTE_IN_MILLIS,
+ mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ HOUR_IN_MILLIS));
+ assertEquals(11 * MINUTE_IN_MILLIS,
+ mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ 2 * HOUR_IN_MILLIS));
+ assertEquals(12 * MINUTE_IN_MILLIS,
+ mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ 3 * HOUR_IN_MILLIS));
+ assertEquals(22 * MINUTE_IN_MILLIS,
+ mQuotaController.getTrailingExecutionTimeLocked(0, "com.android.test",
+ 6 * HOUR_IN_MILLIS));
+ }
+
+ @Test
+ public void testMaybeScheduleCleanupAlarmLocked() {
+ // No sessions saved yet.
+ mQuotaController.maybeScheduleCleanupAlarmLocked();
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_CLEANUP), any(), any());
+
+ // Test with only one timing session saved.
+ final long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+ final long end = now - (6 * HOUR_IN_MILLIS - 5 * MINUTE_IN_MILLIS);
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ new TimingSession(now - 6 * HOUR_IN_MILLIS, end, 1));
+ mQuotaController.maybeScheduleCleanupAlarmLocked();
+ verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(end + 24 * HOUR_IN_MILLIS), eq(TAG_CLEANUP), any(), any());
+
+ // Test with new (more recent) timing sessions saved. AlarmManger shouldn't be called again.
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 3 * HOUR_IN_MILLIS, MINUTE_IN_MILLIS, 1));
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - HOUR_IN_MILLIS, 3 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleCleanupAlarmLocked();
+ verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(end + 24 * HOUR_IN_MILLIS), eq(TAG_CLEANUP), any(), any());
+ }
+
+ @Test
+ public void testMaybeScheduleStartAlarmLocked_WorkingSet() {
+ // saveTimingSession calls maybeScheduleCleanupAlarmLocked which interferes with these tests
+ // because it schedules an alarm too. Prevent it from doing so.
+ spyOn(mQuotaController);
+ doNothing().when(mQuotaController).maybeScheduleCleanupAlarmLocked();
+
+ // Working set window size is 2 hours.
+ final int standbyBucket = WORKING_INDEX;
+
+ // No sessions saved yet.
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test with timing sessions out of window.
+ final long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 10 * HOUR_IN_MILLIS, 5 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test with timing sessions in window but still in quota.
+ final long end = now - (2 * HOUR_IN_MILLIS - 5 * MINUTE_IN_MILLIS);
+ // Counting backwards, the quota will come back one minute before the end.
+ final long expectedAlarmTime =
+ end - MINUTE_IN_MILLIS + 2 * HOUR_IN_MILLIS + IN_QUOTA_BUFFER_MILLIS;
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ new TimingSession(now - 2 * HOUR_IN_MILLIS, end, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Add some more sessions, but still in quota.
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - HOUR_IN_MILLIS, MINUTE_IN_MILLIS, 1));
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - (50 * MINUTE_IN_MILLIS), 3 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test when out of quota.
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 30 * MINUTE_IN_MILLIS, 5 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Alarm already scheduled, so make sure it's not scheduled again.
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+ }
+
+ @Test
+ public void testMaybeScheduleStartAlarmLocked_Frequent() {
+ // saveTimingSession calls maybeScheduleCleanupAlarmLocked which interferes with these tests
+ // because it schedules an alarm too. Prevent it from doing so.
+ spyOn(mQuotaController);
+ doNothing().when(mQuotaController).maybeScheduleCleanupAlarmLocked();
+
+ // Frequent window size is 8 hours.
+ final int standbyBucket = FREQUENT_INDEX;
+
+ // No sessions saved yet.
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test with timing sessions out of window.
+ final long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 10 * HOUR_IN_MILLIS, 5 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test with timing sessions in window but still in quota.
+ final long start = now - (6 * HOUR_IN_MILLIS);
+ final long expectedAlarmTime = start + 8 * HOUR_IN_MILLIS + IN_QUOTA_BUFFER_MILLIS;
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(start, 5 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Add some more sessions, but still in quota.
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 3 * HOUR_IN_MILLIS, MINUTE_IN_MILLIS, 1));
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - HOUR_IN_MILLIS, 3 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test when out of quota.
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - HOUR_IN_MILLIS, MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Alarm already scheduled, so make sure it's not scheduled again.
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+ }
+
+ @Test
+ public void testMaybeScheduleStartAlarmLocked_Rare() {
+ // saveTimingSession calls maybeScheduleCleanupAlarmLocked which interferes with these tests
+ // because it schedules an alarm too. Prevent it from doing so.
+ spyOn(mQuotaController);
+ doNothing().when(mQuotaController).maybeScheduleCleanupAlarmLocked();
+
+ // Rare window size is 24 hours.
+ final int standbyBucket = RARE_INDEX;
+
+ // No sessions saved yet.
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test with timing sessions out of window.
+ final long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 25 * HOUR_IN_MILLIS, 5 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test with timing sessions in window but still in quota.
+ final long start = now - (6 * HOUR_IN_MILLIS);
+ // Counting backwards, the first minute in the session is over the allowed time, so it
+ // needs to be excluded.
+ final long expectedAlarmTime =
+ start + MINUTE_IN_MILLIS + 24 * HOUR_IN_MILLIS + IN_QUOTA_BUFFER_MILLIS;
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(start, 5 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Add some more sessions, but still in quota.
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 3 * HOUR_IN_MILLIS, MINUTE_IN_MILLIS, 1));
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - HOUR_IN_MILLIS, 3 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Test when out of quota.
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - HOUR_IN_MILLIS, 2 * MINUTE_IN_MILLIS, 1));
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // Alarm already scheduled, so make sure it's not scheduled again.
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket);
+ verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+ }
+
+ /** Tests that the start alarm is properly rescheduled if the app's bucket is changed. */
+ @Test
+ public void testMaybeScheduleStartAlarmLocked_BucketChange() {
+ // saveTimingSession calls maybeScheduleCleanupAlarmLocked which interferes with these tests
+ // because it schedules an alarm too. Prevent it from doing so.
+ spyOn(mQuotaController);
+ doNothing().when(mQuotaController).maybeScheduleCleanupAlarmLocked();
+
+ final long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+
+ // Affects rare bucket
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 12 * HOUR_IN_MILLIS, 9 * MINUTE_IN_MILLIS, 3));
+ // Affects frequent and rare buckets
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 4 * HOUR_IN_MILLIS, 4 * MINUTE_IN_MILLIS, 3));
+ // Affects working, frequent, and rare buckets
+ final long outOfQuotaTime = now - HOUR_IN_MILLIS;
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(outOfQuotaTime, 7 * MINUTE_IN_MILLIS, 10));
+ // Affects all buckets
+ mQuotaController.saveTimingSession(0, "com.android.test",
+ createTimingSession(now - 5 * MINUTE_IN_MILLIS, 3 * MINUTE_IN_MILLIS, 3));
+
+ InOrder inOrder = inOrder(mAlarmManager);
+
+ // Start in ACTIVE bucket.
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", ACTIVE_INDEX);
+ inOrder.verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(),
+ any());
+ inOrder.verify(mAlarmManager, never()).cancel(any(AlarmManager.OnAlarmListener.class));
+
+ // And down from there.
+ final long expectedWorkingAlarmTime =
+ outOfQuotaTime + (2 * HOUR_IN_MILLIS) + IN_QUOTA_BUFFER_MILLIS;
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", WORKING_INDEX);
+ inOrder.verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedWorkingAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+
+ final long expectedFrequentAlarmTime =
+ outOfQuotaTime + (8 * HOUR_IN_MILLIS) + IN_QUOTA_BUFFER_MILLIS;
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", FREQUENT_INDEX);
+ inOrder.verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedFrequentAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+
+ final long expectedRareAlarmTime =
+ outOfQuotaTime + (24 * HOUR_IN_MILLIS) + IN_QUOTA_BUFFER_MILLIS;
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", RARE_INDEX);
+ inOrder.verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedRareAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+
+ // And back up again.
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", FREQUENT_INDEX);
+ inOrder.verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedFrequentAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", WORKING_INDEX);
+ inOrder.verify(mAlarmManager, times(1))
+ .set(anyInt(), eq(expectedWorkingAlarmTime), eq(TAG_QUOTA_CHECK), any(), any());
+
+ mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", ACTIVE_INDEX);
+ inOrder.verify(mAlarmManager, never()).set(anyInt(), anyLong(), eq(TAG_QUOTA_CHECK), any(),
+ any());
+ inOrder.verify(mAlarmManager, times(1)).cancel(any(AlarmManager.OnAlarmListener.class));
+ }
+
+ /** Tests that QuotaController doesn't throttle if throttling is turned off. */
+ @Test
+ public void testThrottleToggling() throws Exception {
+ setDischarging();
+ mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE,
+ createTimingSession(
+ JobSchedulerService.sElapsedRealtimeClock.millis() - HOUR_IN_MILLIS,
+ 10 * MINUTE_IN_MILLIS, 4));
+ JobStatus jobStatus = createJobStatus("testThrottleToggling", 1);
+ setStandbyBucket(WORKING_INDEX, jobStatus); // 2 hour window
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
+ assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+
+ mConstants.USE_HEARTBEATS = true;
+ mQuotaController.onConstantsUpdatedLocked();
+ Thread.sleep(SECOND_IN_MILLIS); // Job updates are done in the background.
+ assertTrue(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+
+ mConstants.USE_HEARTBEATS = false;
+ mQuotaController.onConstantsUpdatedLocked();
+ Thread.sleep(SECOND_IN_MILLIS); // Job updates are done in the background.
+ assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ }
+
+ @Test
+ public void testConstantsUpdating_ValidValues() {
+ mConstants.QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS = 5 * MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS = 2 * MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS = 15 * MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS = 30 * MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS = 45 * MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS = 60 * MINUTE_IN_MILLIS;
+
+ mQuotaController.onConstantsUpdatedLocked();
+
+ assertEquals(5 * MINUTE_IN_MILLIS, mQuotaController.getAllowedTimePerPeriodMs());
+ assertEquals(2 * MINUTE_IN_MILLIS, mQuotaController.getInQuotaBufferMs());
+ assertEquals(15 * MINUTE_IN_MILLIS, mQuotaController.getBucketWindowSizes()[ACTIVE_INDEX]);
+ assertEquals(30 * MINUTE_IN_MILLIS, mQuotaController.getBucketWindowSizes()[WORKING_INDEX]);
+ assertEquals(45 * MINUTE_IN_MILLIS,
+ mQuotaController.getBucketWindowSizes()[FREQUENT_INDEX]);
+ assertEquals(60 * MINUTE_IN_MILLIS, mQuotaController.getBucketWindowSizes()[RARE_INDEX]);
+ }
+
+ @Test
+ public void testConstantsUpdating_InvalidValues() {
+ // Test negatives
+ mConstants.QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS = -MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS = -MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS = -MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS = -MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS = -MINUTE_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS = -MINUTE_IN_MILLIS;
+
+ mQuotaController.onConstantsUpdatedLocked();
+
+ assertEquals(MINUTE_IN_MILLIS, mQuotaController.getAllowedTimePerPeriodMs());
+ assertEquals(0, mQuotaController.getInQuotaBufferMs());
+ assertEquals(MINUTE_IN_MILLIS, mQuotaController.getBucketWindowSizes()[ACTIVE_INDEX]);
+ assertEquals(MINUTE_IN_MILLIS, mQuotaController.getBucketWindowSizes()[WORKING_INDEX]);
+ assertEquals(MINUTE_IN_MILLIS, mQuotaController.getBucketWindowSizes()[FREQUENT_INDEX]);
+ assertEquals(MINUTE_IN_MILLIS, mQuotaController.getBucketWindowSizes()[RARE_INDEX]);
+
+ // Test larger than a day. Controller should cap at one day.
+ mConstants.QUOTA_CONTROLLER_ALLOWED_TIME_PER_PERIOD_MS = 25 * HOUR_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_IN_QUOTA_BUFFER_MS = 25 * HOUR_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_ACTIVE_MS = 25 * HOUR_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_WORKING_MS = 25 * HOUR_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_FREQUENT_MS = 25 * HOUR_IN_MILLIS;
+ mConstants.QUOTA_CONTROLLER_WINDOW_SIZE_RARE_MS = 25 * HOUR_IN_MILLIS;
+
+ mQuotaController.onConstantsUpdatedLocked();
+
+ assertEquals(24 * HOUR_IN_MILLIS, mQuotaController.getAllowedTimePerPeriodMs());
+ assertEquals(5 * MINUTE_IN_MILLIS, mQuotaController.getInQuotaBufferMs());
+ assertEquals(24 * HOUR_IN_MILLIS, mQuotaController.getBucketWindowSizes()[ACTIVE_INDEX]);
+ assertEquals(24 * HOUR_IN_MILLIS, mQuotaController.getBucketWindowSizes()[WORKING_INDEX]);
+ assertEquals(24 * HOUR_IN_MILLIS, mQuotaController.getBucketWindowSizes()[FREQUENT_INDEX]);
+ assertEquals(24 * HOUR_IN_MILLIS, mQuotaController.getBucketWindowSizes()[RARE_INDEX]);
+ }
+
+ /** Tests that TimingSessions aren't saved when the device is charging. */
+ @Test
+ public void testTimerTracking_Charging() {
+ setCharging();
+
+ JobStatus jobStatus = createJobStatus("testTimerTracking_Charging", 1);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
+
+ assertNull(mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+
+ mQuotaController.prepareForExecutionLocked(jobStatus);
+ advanceElapsedClock(5 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus, null, false);
+ assertNull(mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+ }
+
+ /** Tests that TimingSessions are saved properly when the device is discharging. */
+ @Test
+ public void testTimerTracking_Discharging() {
+ setDischarging();
+
+ JobStatus jobStatus = createJobStatus("testTimerTracking_Discharging", 1);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
+
+ assertNull(mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+
+ List<TimingSession> expected = new ArrayList<>();
+
+ long start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.prepareForExecutionLocked(jobStatus);
+ advanceElapsedClock(5 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus, null, false);
+ expected.add(createTimingSession(start, 5 * SECOND_IN_MILLIS, 1));
+ assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+
+ // Test overlapping jobs.
+ JobStatus jobStatus2 = createJobStatus("testTimerTracking_Discharging", 2);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus2, null);
+
+ JobStatus jobStatus3 = createJobStatus("testTimerTracking_Discharging", 3);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus3, null);
+
+ advanceElapsedClock(SECOND_IN_MILLIS);
+
+ start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
+ mQuotaController.prepareForExecutionLocked(jobStatus);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.prepareForExecutionLocked(jobStatus2);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus, null, false);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.prepareForExecutionLocked(jobStatus3);
+ advanceElapsedClock(20 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus3, null, false);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus2, null, false);
+ expected.add(createTimingSession(start, MINUTE_IN_MILLIS, 3));
+ assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+ }
+
+ /**
+ * Tests that TimingSessions are saved properly when the device alternates between
+ * charging and discharging.
+ */
+ @Test
+ public void testTimerTracking_ChargingAndDischarging() {
+ JobStatus jobStatus = createJobStatus("testTimerTracking_ChargingAndDischarging", 1);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
+ JobStatus jobStatus2 = createJobStatus("testTimerTracking_ChargingAndDischarging", 2);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus2, null);
+ JobStatus jobStatus3 = createJobStatus("testTimerTracking_ChargingAndDischarging", 3);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus3, null);
+ assertNull(mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+ List<TimingSession> expected = new ArrayList<>();
+
+ // A job starting while charging. Only the portion that runs during the discharging period
+ // should be counted.
+ setCharging();
+
+ mQuotaController.prepareForExecutionLocked(jobStatus);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ setDischarging();
+ long start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus, jobStatus, true);
+ expected.add(createTimingSession(start, 10 * SECOND_IN_MILLIS, 1));
+ assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+
+ advanceElapsedClock(SECOND_IN_MILLIS);
+
+ // One job starts while discharging, spans a charging session, and ends after the charging
+ // session. Only the portions during the discharging periods should be counted. This should
+ // result in two TimingSessions. A second job starts while discharging and ends within the
+ // charging session. Only the portion during the first discharging portion should be
+ // counted. A third job starts and ends within the charging session. The third job
+ // shouldn't be included in either job count.
+ setDischarging();
+ start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
+ mQuotaController.prepareForExecutionLocked(jobStatus);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.prepareForExecutionLocked(jobStatus2);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ setCharging();
+ expected.add(createTimingSession(start, 20 * SECOND_IN_MILLIS, 2));
+ mQuotaController.prepareForExecutionLocked(jobStatus3);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus3, null, false);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus2, null, false);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ setDischarging();
+ start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ advanceElapsedClock(20 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus, null, false);
+ expected.add(createTimingSession(start, 20 * SECOND_IN_MILLIS, 1));
+ assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+
+ // A job starting while discharging and ending while charging. Only the portion that runs
+ // during the discharging period should be counted.
+ setDischarging();
+ start = JobSchedulerService.sElapsedRealtimeClock.millis();
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus2, null);
+ mQuotaController.prepareForExecutionLocked(jobStatus2);
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ expected.add(createTimingSession(start, 10 * SECOND_IN_MILLIS, 1));
+ setCharging();
+ advanceElapsedClock(10 * SECOND_IN_MILLIS);
+ mQuotaController.maybeStopTrackingJobLocked(jobStatus2, null, false);
+ assertEquals(expected, mQuotaController.getTimingSessions(SOURCE_USER_ID, SOURCE_PACKAGE));
+ }
+
+ /**
+ * Tests that a job is properly updated and JobSchedulerService is notified when a job reaches
+ * its quota.
+ */
+ @Test
+ public void testTracking_OutOfQuota() {
+ JobStatus jobStatus = createJobStatus("testTracking_OutOfQuota", 1);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
+ setStandbyBucket(WORKING_INDEX, jobStatus); // 2 hour window
+ // Now the package only has two seconds to run.
+ final long remainingTimeMs = 2 * SECOND_IN_MILLIS;
+ mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE,
+ createTimingSession(
+ JobSchedulerService.sElapsedRealtimeClock.millis() - HOUR_IN_MILLIS,
+ 10 * MINUTE_IN_MILLIS - remainingTimeMs, 1));
+
+ // Start the job.
+ mQuotaController.prepareForExecutionLocked(jobStatus);
+ advanceElapsedClock(remainingTimeMs);
+
+ // Wait for some extra time to allow for job processing.
+ verify(mJobSchedulerService,
+ timeout(remainingTimeMs + 2 * SECOND_IN_MILLIS).times(1))
+ .onControllerStateChanged();
+ assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ }
+
+ /**
+ * Tests that a job is properly handled when it's at the edge of its quota and the old quota is
+ * being phased out.
+ */
+ @Test
+ public void testTracking_RollingQuota() {
+ JobStatus jobStatus = createJobStatus("testTracking_OutOfQuota", 1);
+ mQuotaController.maybeStartTrackingJobLocked(jobStatus, null);
+ setStandbyBucket(WORKING_INDEX, jobStatus); // 2 hour window
+ Handler handler = mQuotaController.getHandler();
+ spyOn(handler);
+
+ long now = JobSchedulerService.sElapsedRealtimeClock.millis();
+ final long remainingTimeMs = SECOND_IN_MILLIS;
+ // The package only has one second to run, but this session is at the edge of the rolling
+ // window, so as the package "reaches its quota" it will have more to keep running.
+ mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE,
+ createTimingSession(now - 2 * HOUR_IN_MILLIS,
+ 10 * MINUTE_IN_MILLIS - remainingTimeMs, 1));
+
+ assertEquals(remainingTimeMs, mQuotaController.getRemainingExecutionTimeLocked(jobStatus));
+ // Start the job.
+ mQuotaController.prepareForExecutionLocked(jobStatus);
+ advanceElapsedClock(remainingTimeMs);
+
+ // Wait for some extra time to allow for job processing.
+ verify(mJobSchedulerService,
+ timeout(remainingTimeMs + 2 * SECOND_IN_MILLIS).times(0))
+ .onControllerStateChanged();
+ assertTrue(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_WITHIN_QUOTA));
+ // The job used up the remaining quota, but in that time, the same amount of time in the
+ // old TimingSession also fell out of the quota window, so it should still have the same
+ // amount of remaining time left its quota.
+ assertEquals(remainingTimeMs,
+ mQuotaController.getRemainingExecutionTimeLocked(SOURCE_USER_ID, SOURCE_PACKAGE));
+ verify(handler, atLeast(1)).sendMessageDelayed(any(), eq(remainingTimeMs));
+ }
+}
diff --git a/services/tests/servicestests/src/com/android/server/BinderCallsStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/BinderCallsStatsServiceTest.java
new file mode 100644
index 000000000000..f70efdfadfd7
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/BinderCallsStatsServiceTest.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static org.junit.Assert.assertEquals;
+
+import android.os.Binder;
+import android.os.Process;
+import android.platform.test.annotations.Presubmit;
+
+import androidx.test.InstrumentationRegistry;
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.internal.os.BinderInternal;
+import com.android.internal.os.BinderInternal.CallSession;
+import com.android.server.BinderCallsStatsService.WorkSourceProvider;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+@Presubmit
+public class BinderCallsStatsServiceTest {
+ @Test
+ public void weTrustOurselves() {
+ WorkSourceProvider workSourceProvider = new WorkSourceProvider() {
+ protected int getCallingUid() {
+ return Process.myUid();
+ }
+
+ protected int getCallingWorkSourceUid() {
+ return 1;
+ }
+ };
+ workSourceProvider.systemReady(InstrumentationRegistry.getContext());
+
+ assertEquals(1, workSourceProvider.resolveWorkSourceUid());
+ }
+
+ @Test
+ public void workSourceSetIfCallerHasPermission() {
+ WorkSourceProvider workSourceProvider = new WorkSourceProvider() {
+ protected int getCallingUid() {
+ // System process uid which as UPDATE_DEVICE_STATS.
+ return 1001;
+ }
+
+ protected int getCallingWorkSourceUid() {
+ return 1;
+ }
+ };
+ workSourceProvider.systemReady(InstrumentationRegistry.getContext());
+
+ assertEquals(1, workSourceProvider.resolveWorkSourceUid());
+ }
+
+ @Test
+ public void workSourceResolvedToCallingUid() {
+ WorkSourceProvider workSourceProvider = new WorkSourceProvider() {
+ protected int getCallingUid() {
+ // UID without permissions.
+ return Integer.MAX_VALUE;
+ }
+
+ protected int getCallingWorkSourceUid() {
+ return 1;
+ }
+ };
+ workSourceProvider.systemReady(InstrumentationRegistry.getContext());
+
+ assertEquals(Integer.MAX_VALUE, workSourceProvider.resolveWorkSourceUid());
+ }
+
+ @Test
+ public void workSourceSet() {
+ TestObserver observer = new TestObserver();
+ observer.callStarted(new Binder(), 0);
+ assertEquals(true, observer.workSourceSet);
+ }
+
+ static class TestObserver extends BinderCallsStatsService.BinderCallsObserver {
+ public boolean workSourceSet = false;
+
+ TestObserver() {
+ super(new NoopObserver(), new WorkSourceProvider());
+ }
+
+ @Override
+ protected void setThreadLocalWorkSourceUid(int uid) {
+ workSourceSet = true;
+ }
+ }
+
+
+ static class NoopObserver implements BinderInternal.Observer {
+ @Override
+ public CallSession callStarted(Binder binder, int code) {
+ return null;
+ }
+
+ @Override
+ public void callEnded(CallSession s, int parcelRequestSize, int parcelReplySize) {
+ }
+
+ @Override
+ public void callThrewException(CallSession s, Exception exception) {
+ }
+ }
+}
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java
index 1d63c57e6cfe..7be331cc8a06 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTestsBase.java
@@ -79,6 +79,7 @@ public class DisplayPolicyTestsBase extends WindowTestsBase {
resources.addOverride(R.dimen.navigation_bar_width, NAV_BAR_HEIGHT);
when(mDisplayPolicy.getSystemUiContext()).thenReturn(context);
when(mDisplayPolicy.hasNavigationBar()).thenReturn(true);
+ when(mDisplayPolicy.hasStatusBar()).thenReturn(true);
final int shortSizeDp =
Math.min(DISPLAY_WIDTH, DISPLAY_HEIGHT) * DENSITY_DEFAULT / DISPLAY_DENSITY;
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
index 9569c0d5affa..105f8260022f 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskLaunchParamsModifierTests.java
@@ -22,7 +22,10 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.util.DisplayMetrics.DENSITY_DEFAULT;
import static android.view.Display.DEFAULT_DISPLAY;
@@ -750,6 +753,64 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase {
}
@Test
+ public void testUsesDisplayOrientationForNoSensorOrientation() {
+ final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
+ WINDOWING_MODE_FREEFORM);
+
+ final ActivityOptions options = ActivityOptions.makeBasic();
+ options.setLaunchDisplayId(freeformDisplay.mDisplayId);
+ options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
+
+ mActivity.info.screenOrientation = SCREEN_ORIENTATION_NOSENSOR;
+
+ assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
+ mActivity, /* source */ null, options, mCurrent, mResult));
+
+ final int orientationForDisplay = orientationFromBounds(freeformDisplay.getBounds());
+ final int orientationForTask = orientationFromBounds(mResult.mBounds);
+ assertEquals("Launch bounds orientation should be the same as the display, but"
+ + " display orientation is "
+ + ActivityInfo.screenOrientationToString(orientationForDisplay)
+ + " launch bounds orientation is "
+ + ActivityInfo.screenOrientationToString(orientationForTask),
+ orientationForDisplay, orientationForTask);
+ }
+
+ @Test
+ public void testRespectsAppRequestedOrientation_Landscape() {
+ final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
+ WINDOWING_MODE_FREEFORM);
+
+ final ActivityOptions options = ActivityOptions.makeBasic();
+ options.setLaunchDisplayId(freeformDisplay.mDisplayId);
+ options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
+
+ mActivity.info.screenOrientation = SCREEN_ORIENTATION_LANDSCAPE;
+
+ assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
+ mActivity, /* source */ null, options, mCurrent, mResult));
+
+ assertEquals(SCREEN_ORIENTATION_LANDSCAPE, orientationFromBounds(mResult.mBounds));
+ }
+
+ @Test
+ public void testRespectsAppRequestedOrientation_Portrait() {
+ final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
+ WINDOWING_MODE_FREEFORM);
+
+ final ActivityOptions options = ActivityOptions.makeBasic();
+ options.setLaunchDisplayId(freeformDisplay.mDisplayId);
+ options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
+
+ mActivity.info.screenOrientation = SCREEN_ORIENTATION_PORTRAIT;
+
+ assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
+ mActivity, /* source */ null, options, mCurrent, mResult));
+
+ assertEquals(SCREEN_ORIENTATION_PORTRAIT, orientationFromBounds(mResult.mBounds));
+ }
+
+ @Test
public void testDefaultSizeSmallerThanBigScreen() {
final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
WINDOWING_MODE_FREEFORM);
@@ -1090,6 +1151,7 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase {
display.setWindowingMode(windowingMode);
display.setBounds(/* left */ 0, /* top */ 0, /* right */ 1920, /* bottom */ 1080);
display.getConfiguration().densityDpi = DENSITY_DEFAULT;
+ display.getConfiguration().orientation = ORIENTATION_LANDSCAPE;
return display;
}
@@ -1115,6 +1177,11 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase {
}
}
+ private int orientationFromBounds(Rect bounds) {
+ return bounds.width() > bounds.height() ? SCREEN_ORIENTATION_LANDSCAPE
+ : SCREEN_ORIENTATION_PORTRAIT;
+ }
+
private static class WindowLayoutBuilder {
private int mWidth = -1;
private int mHeight = -1;
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java
index 266d88493b9e..50fd188cc00b 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceRule.java
@@ -30,6 +30,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
import android.app.ActivityManagerInternal;
import android.content.Context;
@@ -125,11 +126,12 @@ public class WindowManagerServiceRule implements TestRule {
if (input != null && input.length > 1) {
doReturn(input[1]).when(ims).monitorInput(anyString(), anyInt());
}
+ ActivityTaskManagerService atms = mock(ActivityTaskManagerService.class);
+ when(atms.getGlobalLock()).thenReturn(new WindowManagerGlobalLock());
mService = WindowManagerService.main(context, ims, false, false,
mPolicy = new TestWindowManagerPolicy(
- WindowManagerServiceRule.this::getWindowManagerService),
- new WindowManagerGlobalLock());
+ WindowManagerServiceRule.this::getWindowManagerService), atms);
mService.mTransactionFactory = () -> {
final SurfaceControl.Transaction transaction = new SurfaceControl.Transaction();
mSurfaceTransactions.add(new WeakReference<>(transaction));
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 45d914e0dfdd..fa9b76de2e6b 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -5541,19 +5541,40 @@ public class TelephonyManager {
public void requestNumberVerification(@NonNull PhoneNumberRange range, long timeoutMillis,
@NonNull @CallbackExecutor Executor executor,
@NonNull NumberVerificationCallback callback) {
+ if (executor == null) {
+ throw new NullPointerException("Executor must be non-null");
+ }
+ if (callback == null) {
+ throw new NullPointerException("Callback must be non-null");
+ }
+
INumberVerificationCallback internalCallback = new INumberVerificationCallback.Stub() {
@Override
- public void onCallReceived(String phoneNumber) throws RemoteException {
- Binder.withCleanCallingIdentity(() -> callback.onCallReceived(phoneNumber));
+ public void onCallReceived(String phoneNumber) {
+ Binder.withCleanCallingIdentity(() ->
+ executor.execute(() ->
+ callback.onCallReceived(phoneNumber)));
}
@Override
- public void onVerificationFailed(int reason) throws RemoteException {
- Binder.withCleanCallingIdentity(() -> callback.onVerificationFailed(reason));
+ public void onVerificationFailed(int reason) {
+ Binder.withCleanCallingIdentity(() ->
+ executor.execute(() ->
+ callback.onVerificationFailed(reason)));
}
};
- // TODO -- call the aidl method
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null) {
+ telephony.requestNumberVerification(range, timeoutMillis, internalCallback,
+ getOpPackageName());
+ }
+ } catch (RemoteException ex) {
+ Rlog.e(TAG, "requestNumberVerification RemoteException", ex);
+ executor.execute(() ->
+ callback.onVerificationFailed(NumberVerificationCallback.REASON_UNSPECIFIED));
+ }
}
/**
diff --git a/telephony/java/android/telephony/euicc/EuiccCardManager.java b/telephony/java/android/telephony/euicc/EuiccCardManager.java
index 3b1ef3f45993..994c49cd2315 100644
--- a/telephony/java/android/telephony/euicc/EuiccCardManager.java
+++ b/telephony/java/android/telephony/euicc/EuiccCardManager.java
@@ -155,7 +155,7 @@ public class EuiccCardManager {
* Requests all the profiles on eUicc.
*
* @param cardId The Id of the eUICC.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code and all the profiles.
*/
public void requestAllProfiles(String cardId, @CallbackExecutor Executor executor,
@@ -179,7 +179,7 @@ public class EuiccCardManager {
*
* @param cardId The Id of the eUICC.
* @param iccid The iccid of the profile.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code and profile.
*/
public void requestProfile(String cardId, String iccid, @CallbackExecutor Executor executor,
@@ -204,7 +204,7 @@ public class EuiccCardManager {
* @param cardId The Id of the eUICC.
* @param iccid The iccid of the profile.
* @param refresh Whether sending the REFRESH command to modem.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code.
*/
public void disableProfile(String cardId, String iccid, boolean refresh,
@@ -230,7 +230,7 @@ public class EuiccCardManager {
* @param cardId The Id of the eUICC.
* @param iccid The iccid of the profile to switch to.
* @param refresh Whether sending the REFRESH command to modem.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code and the EuiccProfileInfo enabled.
*/
public void switchToProfile(String cardId, String iccid, boolean refresh,
@@ -255,7 +255,7 @@ public class EuiccCardManager {
* @param cardId The Id of the eUICC.
* @param iccid The iccid of the profile.
* @param nickname The nickname of the profile.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code.
*/
public void setNickname(String cardId, String iccid, String nickname,
@@ -279,7 +279,7 @@ public class EuiccCardManager {
*
* @param cardId The Id of the eUICC.
* @param iccid The iccid of the profile.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code.
*/
public void deleteProfile(String cardId, String iccid, @CallbackExecutor Executor executor,
@@ -304,7 +304,7 @@ public class EuiccCardManager {
* @param cardId The Id of the eUICC.
* @param options Bits of the options of resetting which parts of the eUICC memory. See
* EuiccCard for details.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code.
*/
public void resetMemory(String cardId, @ResetOption int options,
@@ -327,7 +327,7 @@ public class EuiccCardManager {
* Requests the default SM-DP+ address from eUICC.
*
* @param cardId The Id of the eUICC.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code and the default SM-DP+ address.
*/
public void requestDefaultSmdpAddress(String cardId, @CallbackExecutor Executor executor,
@@ -350,7 +350,7 @@ public class EuiccCardManager {
* Requests the SM-DS address from eUICC.
*
* @param cardId The Id of the eUICC.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code and the SM-DS address.
*/
public void requestSmdsAddress(String cardId, @CallbackExecutor Executor executor,
@@ -374,7 +374,7 @@ public class EuiccCardManager {
*
* @param cardId The Id of the eUICC.
* @param defaultSmdpAddress The default SM-DP+ address to set.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback The callback to get the result code.
*/
public void setDefaultSmdpAddress(String cardId, String defaultSmdpAddress,
@@ -398,7 +398,7 @@ public class EuiccCardManager {
* Requests Rules Authorisation Table.
*
* @param cardId The Id of the eUICC.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and the rule authorisation table.
*/
public void requestRulesAuthTable(String cardId, @CallbackExecutor Executor executor,
@@ -421,7 +421,7 @@ public class EuiccCardManager {
* Requests the eUICC challenge for new profile downloading.
*
* @param cardId The Id of the eUICC.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and the challenge.
*/
public void requestEuiccChallenge(String cardId, @CallbackExecutor Executor executor,
@@ -444,7 +444,7 @@ public class EuiccCardManager {
* Requests the eUICC info1 defined in GSMA RSP v2.0+ for new profile downloading.
*
* @param cardId The Id of the eUICC.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and the info1.
*/
public void requestEuiccInfo1(String cardId, @CallbackExecutor Executor executor,
@@ -467,7 +467,7 @@ public class EuiccCardManager {
* Gets the eUICC info2 defined in GSMA RSP v2.0+ for new profile downloading.
*
* @param cardId The Id of the eUICC.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and the info2.
*/
public void requestEuiccInfo2(String cardId, @CallbackExecutor Executor executor,
@@ -500,7 +500,7 @@ public class EuiccCardManager {
* GSMA RSP v2.0+.
* @param serverCertificate ASN.1 data in byte array indicating SM-DP+ Certificate returned by
* SM-DP+ server.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and a byte array which represents a
* {@code AuthenticateServerResponse} defined in GSMA RSP v2.0+.
*/
@@ -540,7 +540,7 @@ public class EuiccCardManager {
* SM-DP+ server.
* @param smdpCertificate ASN.1 data in byte array indicating the SM-DP+ Certificate returned
* by SM-DP+ server.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and a byte array which represents a
* {@code PrepareDownloadResponse} defined in GSMA RSP v2.0+
*/
@@ -572,7 +572,7 @@ public class EuiccCardManager {
*
* @param cardId The Id of the eUICC.
* @param boundProfilePackage the Bound Profile Package data returned by SM-DP+ server.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and a byte array which represents a
* {@code LoadBoundProfilePackageResponse} defined in GSMA RSP v2.0+.
*/
@@ -601,7 +601,7 @@ public class EuiccCardManager {
* @param cardId The Id of the eUICC.
* @param transactionId the transaction ID returned by SM-DP+ server.
* @param reason the cancel reason.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and an byte[] which represents a
* {@code CancelSessionResponse} defined in GSMA RSP v2.0+.
*/
@@ -630,7 +630,7 @@ public class EuiccCardManager {
*
* @param cardId The Id of the eUICC.
* @param events bits of the event types ({@link EuiccNotification.Event}) to list.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and the list of notifications.
*/
public void listNotifications(String cardId, @EuiccNotification.Event int events,
@@ -654,7 +654,7 @@ public class EuiccCardManager {
*
* @param cardId The Id of the eUICC.
* @param events bits of the event types ({@link EuiccNotification.Event}) to list.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and the list of notifications.
*/
public void retrieveNotificationList(String cardId, @EuiccNotification.Event int events,
@@ -678,7 +678,7 @@ public class EuiccCardManager {
*
* @param cardId The Id of the eUICC.
* @param seqNumber the sequence number of the notification.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code and the notification.
*/
public void retrieveNotification(String cardId, int seqNumber,
@@ -702,7 +702,7 @@ public class EuiccCardManager {
*
* @param cardId The Id of the eUICC.
* @param seqNumber the sequence number of the notification.
- * @param executor The executor through which the callback should be invoke.
+ * @param executor The executor through which the callback should be invoked.
* @param callback the callback to get the result code.
*/
public void removeNotificationFromList(String cardId, int seqNumber,
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 32e939a0c925..399dc5255176 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -35,6 +35,7 @@ import android.telephony.ICellInfoCallback;
import android.telephony.ModemActivityInfo;
import android.telephony.NeighboringCellInfo;
import android.telephony.NetworkScanRequest;
+import android.telephony.PhoneNumberRange;
import android.telephony.RadioAccessFamily;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
@@ -49,6 +50,7 @@ import android.telephony.ims.aidl.IImsRegistration;
import android.telephony.ims.aidl.IImsRegistrationCallback;
import com.android.ims.internal.IImsServiceFeatureCallback;
import com.android.internal.telephony.CellNetworkScanResult;
+import com.android.internal.telephony.INumberVerificationCallback;
import com.android.internal.telephony.OperatorInfo;
import java.util.List;
@@ -871,6 +873,17 @@ interface ITelephony {
String getCdmaMin(int subId);
/**
+ * Request that the next incoming call from a number matching {@code range} be intercepted.
+ * @param range The range of phone numbers the caller expects a phone call from.
+ * @param timeoutMillis The amount of time to wait for such a call, or
+ * {@link #MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS}, whichever is lesser.
+ * @param callback the callback aidl
+ * @param callingPackage the calling package name.
+ */
+ void requestNumberVerification(in PhoneNumberRange range, long timeoutMillis,
+ in INumberVerificationCallback callback, String callingPackage);
+
+ /**
* Has the calling application been granted special privileges by the carrier.
*
* If any of the packages in the calling UID has carrier privileges, the
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 89b670390171..cad6d2997bfb 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -156,33 +156,39 @@ public class WifiManager {
public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL = 1;
/**
+ * Reason code if the user has disallowed "android:change_wifi_state" app-ops from the app.
+ * @see android.app.AppOpsManager#unsafeCheckOp(String, int, String).
+ */
+ public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED = 2;
+
+ /**
* Reason code if one or more of the network suggestions added already exists in platform's
* database.
* @see WifiNetworkSuggestion#equals(Object)
*/
- public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE = 2;
+ public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE = 3;
/**
* Reason code if the number of network suggestions provided by the app crosses the max
* threshold set per app.
* @see #getMaxNumberOfNetworkSuggestionsPerApp()
*/
- public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP = 3;
+ public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP = 4;
/**
* Reason code if one or more of the network suggestions removed does not exist in platform's
* database.
*/
- public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 4;
+ public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 5;
@IntDef(prefix = { "STATUS_NETWORK_SUGGESTIONS_" }, value = {
STATUS_NETWORK_SUGGESTIONS_SUCCESS,
STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL,
+ STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED,
STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE,
STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP,
STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID,
})
-
@Retention(RetentionPolicy.SOURCE)
public @interface NetworkSuggestionsStatusCode {}
diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java
index fc5caf0a47d7..acc0518dbca4 100644
--- a/wifi/java/android/net/wifi/WifiScanner.java
+++ b/wifi/java/android/net/wifi/WifiScanner.java
@@ -357,11 +357,12 @@ public class WifiScanner {
*/
private int mBucketsScanned;
/**
- * Indicates that the scan results received are as a result of a scan of all available
- * channels. This should only be expected to function for single scans.
+ * Bands scanned. One of the WIFI_BAND values.
+ * Will be {@link #WIFI_BAND_UNSPECIFIED} if the list of channels do not fully cover
+ * any of the bands.
* {@hide}
*/
- private boolean mAllChannelsScanned;
+ private int mBandScanned;
/** all scan results discovered in this scan, sorted by timestamp in ascending order */
private ScanResult mResults[];
@@ -374,12 +375,12 @@ public class WifiScanner {
}
/** {@hide} */
- public ScanData(int id, int flags, int bucketsScanned, boolean allChannelsScanned,
- ScanResult[] results) {
+ public ScanData(int id, int flags, int bucketsScanned, int bandScanned,
+ ScanResult[] results) {
mId = id;
mFlags = flags;
mBucketsScanned = bucketsScanned;
- mAllChannelsScanned = allChannelsScanned;
+ mBandScanned = bandScanned;
mResults = results;
}
@@ -387,7 +388,7 @@ public class WifiScanner {
mId = s.mId;
mFlags = s.mFlags;
mBucketsScanned = s.mBucketsScanned;
- mAllChannelsScanned = s.mAllChannelsScanned;
+ mBandScanned = s.mBandScanned;
mResults = new ScanResult[s.mResults.length];
for (int i = 0; i < s.mResults.length; i++) {
ScanResult result = s.mResults[i];
@@ -410,8 +411,8 @@ public class WifiScanner {
}
/** {@hide} */
- public boolean isAllChannelsScanned() {
- return mAllChannelsScanned;
+ public int getBandScanned() {
+ return mBandScanned;
}
public ScanResult[] getResults() {
@@ -429,7 +430,7 @@ public class WifiScanner {
dest.writeInt(mId);
dest.writeInt(mFlags);
dest.writeInt(mBucketsScanned);
- dest.writeInt(mAllChannelsScanned ? 1 : 0);
+ dest.writeInt(mBandScanned);
dest.writeInt(mResults.length);
for (int i = 0; i < mResults.length; i++) {
ScanResult result = mResults[i];
@@ -447,13 +448,13 @@ public class WifiScanner {
int id = in.readInt();
int flags = in.readInt();
int bucketsScanned = in.readInt();
- boolean allChannelsScanned = in.readInt() != 0;
+ int bandScanned = in.readInt();
int n = in.readInt();
ScanResult results[] = new ScanResult[n];
for (int i = 0; i < n; i++) {
results[i] = ScanResult.CREATOR.createFromParcel(in);
}
- return new ScanData(id, flags, bucketsScanned, allChannelsScanned, results);
+ return new ScanData(id, flags, bucketsScanned, bandScanned, results);
}
public ScanData[] newArray(int size) {
@@ -759,6 +760,7 @@ public class WifiScanner {
* Multiple requests should also not share this object.
* {@hide}
*/
+ @RequiresPermission(Manifest.permission.NETWORK_STACK)
public void registerScanListener(ScanListener listener) {
Preconditions.checkNotNull(listener, "listener cannot be null");
int key = addListener(listener);
diff --git a/wifi/tests/src/android/net/wifi/WifiScannerTest.java b/wifi/tests/src/android/net/wifi/WifiScannerTest.java
index da42dcf623c2..cf1ed8fa84c0 100644
--- a/wifi/tests/src/android/net/wifi/WifiScannerTest.java
+++ b/wifi/tests/src/android/net/wifi/WifiScannerTest.java
@@ -16,6 +16,7 @@
package android.net.wifi;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -26,6 +27,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.wifi.WifiScanner.PnoSettings;
import android.net.wifi.WifiScanner.PnoSettings.PnoNetwork;
+import android.net.wifi.WifiScanner.ScanData;
import android.net.wifi.WifiScanner.ScanSettings;
import android.os.Handler;
import android.os.Parcel;
@@ -203,4 +205,29 @@ public class WifiScannerTest {
assertNotNull(pnoNetwork.frequencies);
}
+ /**
+ * Verify parcel read/write for ScanData.
+ */
+ @Test
+ public void verifyScanDataParcel() throws Exception {
+ ScanData writeScanData = new ScanData(2, 0, 3,
+ WifiScanner.WIFI_BAND_BOTH_WITH_DFS, new ScanResult[0]);
+
+ ScanData readScanData = parcelWriteRead(writeScanData);
+ assertEquals(writeScanData.getId(), readScanData.getId());
+ assertEquals(writeScanData.getFlags(), readScanData.getFlags());
+ assertEquals(writeScanData.getBucketsScanned(), readScanData.getBucketsScanned());
+ assertEquals(writeScanData.getBandScanned(), readScanData.getBandScanned());
+ assertArrayEquals(writeScanData.getResults(), readScanData.getResults());
+ }
+
+ /**
+ * Write the provided {@link ScanData} to a parcel and deserialize it.
+ */
+ private static ScanData parcelWriteRead(ScanData writeScanData) throws Exception {
+ Parcel parcel = Parcel.obtain();
+ writeScanData.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0); // Rewind data position back to the beginning for read.
+ return ScanData.CREATOR.createFromParcel(parcel);
+ }
}