diff options
192 files changed, 3121 insertions, 2090 deletions
diff --git a/Android.bp b/Android.bp index 4b82e1d26edc..e1f5abd9ff3e 100644 --- a/Android.bp +++ b/Android.bp @@ -284,6 +284,7 @@ java_defaults { name: "framework-aidl-export-defaults", aidl: { export_include_dirs: [ + "apex/media/java", "core/java", "drm/java", "graphics/java", @@ -291,7 +292,6 @@ java_defaults { "location/java", "lowpan/java", "media/java", - "media/apex/java", "media/mca/effect/java", "media/mca/filterfw/java", "media/mca/filterpacks/java", diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg index 78e72bf39586..4d1ac0ec218c 100644 --- a/PREUPLOAD.cfg +++ b/PREUPLOAD.cfg @@ -6,6 +6,7 @@ clang_format = true clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp cmds/hid/ cmds/input/ + core/jni/ libs/input/ [Hook Scripts] diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java index 1ec96ecc561b..9310762665db 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java +++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java @@ -81,7 +81,6 @@ import com.android.internal.app.IBatteryStats; import com.android.internal.util.ArrayUtils; import com.android.internal.util.DumpUtils; import com.android.internal.util.IndentingPrintWriter; -import com.android.internal.util.Preconditions; import com.android.server.AppStateTracker; import com.android.server.DeviceIdleInternal; import com.android.server.FgThread; @@ -117,6 +116,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Objects; import java.util.function.Consumer; import java.util.function.Predicate; @@ -1283,7 +1283,7 @@ public class JobSchedulerService extends com.android.server.SystemService super(context); mLocalPM = LocalServices.getService(PackageManagerInternal.class); - mActivityManagerInternal = Preconditions.checkNotNull( + mActivityManagerInternal = Objects.requireNonNull( LocalServices.getService(ActivityManagerInternal.class)); mHandler = new JobHandler(context.getMainLooper()); @@ -1389,7 +1389,7 @@ public class JobSchedulerService extends com.android.server.SystemService controller.onSystemServicesReady(); } - mAppStateTracker = Preconditions.checkNotNull( + mAppStateTracker = Objects.requireNonNull( LocalServices.getService(AppStateTracker.class)); // Register br for package removals and user removals. diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/BackgroundJobsController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/BackgroundJobsController.java index 8b610061d3aa..aa3d74a51ff2 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/controllers/BackgroundJobsController.java +++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/BackgroundJobsController.java @@ -23,7 +23,6 @@ import android.util.Slog; import android.util.proto.ProtoOutputStream; import com.android.internal.util.IndentingPrintWriter; -import com.android.internal.util.Preconditions; import com.android.server.AppStateTracker; import com.android.server.AppStateTracker.Listener; import com.android.server.LocalServices; @@ -32,6 +31,7 @@ import com.android.server.job.JobStore; import com.android.server.job.StateControllerProto; import com.android.server.job.StateControllerProto.BackgroundJobsController.TrackedJob; +import java.util.Objects; import java.util.function.Consumer; import java.util.function.Predicate; @@ -59,7 +59,7 @@ public final class BackgroundJobsController extends StateController { public BackgroundJobsController(JobSchedulerService service) { super(service); - mAppStateTracker = Preconditions.checkNotNull( + mAppStateTracker = Objects.requireNonNull( LocalServices.getService(AppStateTracker.class)); mAppStateTracker.addListener(mForceAppStandbyListener); } diff --git a/apex/media/Android.bp b/apex/media/Android.bp new file mode 100644 index 000000000000..6bd0086681a7 --- /dev/null +++ b/apex/media/Android.bp @@ -0,0 +1,120 @@ +// Copyright (C) 2020 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +java_library { + name: "updatable-media", + + srcs: [ + ":updatable-media-srcs", + ], + + aidl: { + export_include_dirs: [ + "java", + ], + + // It would be great if we don't need to add include_dirs for public + // parcelable classes. Find a better way. + include_dirs: [ + // To refer: + // android.os.Bundle + // android.os.ResultReceiver + "frameworks/base/core/java", + ], + }, + + permitted_packages: [ + "android.media", + ], + + installable: true, + + // TODO: build against stable API surface. Use core_platform for now to avoid + // link-check failure with exoplayer building against "current". + sdk_version: "core_platform", + libs: [ + // The order matters. android_system_* library should come later. + "framework_media_annotation", + "android_system_stubs_current", + ], + + static_libs: [ + "exoplayer2-core" + ], + jarjar_rules: "jarjar_rules.txt", + + plugins: ["java_api_finder"], +} + +filegroup { + name: "updatable-media-srcs", + srcs: [ + ":mediaparser-srcs", + ":mediasession2-srcs", + ], +} + +filegroup { + name: "mediasession2-srcs", + srcs: [ + "java/android/media/Controller2Link.java", + "java/android/media/IMediaController2.aidl", + "java/android/media/IMediaSession2.aidl", + "java/android/media/IMediaSession2Service.aidl", + "java/android/media/MediaConstants.java", + "java/android/media/MediaController2.java", + "java/android/media/MediaSession2.java", + "java/android/media/MediaSession2Service.java", + "java/android/media/Session2Command.java", + "java/android/media/Session2CommandGroup.java", + "java/android/media/Session2Link.java", + "java/android/media/Session2Token.java", + ], + path: "java", +} + +filegroup { + name: "mediaparser-srcs", + srcs: [ + "java/android/media/MediaParser.java" + ], + path: "java" +} + +droidstubs { + name: "updatable-media-stubs", + srcs: [ + ":updatable-media-srcs", + ":framework-media-annotation-srcs", + ], + defaults: [ "framework-module-stubs-defaults-systemapi" ], + aidl: { + // TODO(b/135922046) remove this + include_dirs: ["frameworks/base/core/java"], + }, + sdk_version: "system_current", +} + +java_library { + name: "updatable_media_stubs", + srcs: [":updatable-media-stubs"], + sdk_version: "system_current", +} + +java_library { + name: "framework_media_annotation", + srcs: [":framework-media-annotation-srcs"], + installable: false, + sdk_version: "core_current", +} diff --git a/apex/media/OWNERS b/apex/media/OWNERS new file mode 100644 index 000000000000..0ac750cde41d --- /dev/null +++ b/apex/media/OWNERS @@ -0,0 +1,4 @@ +andrewlewis@google.com +dwkang@google.com +marcone@google.com +sungsoo@google.com diff --git a/media/jarjar_rules.txt b/apex/media/jarjar_rules.txt index d89d9d3343d1..d89d9d3343d1 100644 --- a/media/jarjar_rules.txt +++ b/apex/media/jarjar_rules.txt diff --git a/media/apex/java/android/media/BufferingParams.java b/apex/media/java/android/media/BufferingParams.java index 943f14277fc3..04af02874bbd 100644 --- a/media/apex/java/android/media/BufferingParams.java +++ b/apex/media/java/android/media/BufferingParams.java @@ -16,13 +16,9 @@ package android.media; -import android.annotation.IntDef; import android.os.Parcel; import android.os.Parcelable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - /** * Structure for source buffering management params. * diff --git a/media/apex/java/android/media/Controller2Link.aidl b/apex/media/java/android/media/Controller2Link.aidl index 64edafcb11fc..64edafcb11fc 100644 --- a/media/apex/java/android/media/Controller2Link.aidl +++ b/apex/media/java/android/media/Controller2Link.aidl diff --git a/media/apex/java/android/media/Controller2Link.java b/apex/media/java/android/media/Controller2Link.java index 04185e79b0ad..04185e79b0ad 100644 --- a/media/apex/java/android/media/Controller2Link.java +++ b/apex/media/java/android/media/Controller2Link.java diff --git a/media/apex/java/android/media/DataSourceCallback.java b/apex/media/java/android/media/DataSourceCallback.java index c297ecda249c..c297ecda249c 100644 --- a/media/apex/java/android/media/DataSourceCallback.java +++ b/apex/media/java/android/media/DataSourceCallback.java diff --git a/media/apex/java/android/media/IMediaController2.aidl b/apex/media/java/android/media/IMediaController2.aidl index 42c6e70529ec..42c6e70529ec 100644 --- a/media/apex/java/android/media/IMediaController2.aidl +++ b/apex/media/java/android/media/IMediaController2.aidl diff --git a/media/apex/java/android/media/IMediaSession2.aidl b/apex/media/java/android/media/IMediaSession2.aidl index 26e717b39afc..26e717b39afc 100644 --- a/media/apex/java/android/media/IMediaSession2.aidl +++ b/apex/media/java/android/media/IMediaSession2.aidl diff --git a/media/apex/java/android/media/IMediaSession2Service.aidl b/apex/media/java/android/media/IMediaSession2Service.aidl index 10ac1be0a36e..10ac1be0a36e 100644 --- a/media/apex/java/android/media/IMediaSession2Service.aidl +++ b/apex/media/java/android/media/IMediaSession2Service.aidl diff --git a/media/apex/java/android/media/MediaConstants.java b/apex/media/java/android/media/MediaConstants.java index ce108894b9a5..ce108894b9a5 100644 --- a/media/apex/java/android/media/MediaConstants.java +++ b/apex/media/java/android/media/MediaConstants.java diff --git a/media/apex/java/android/media/MediaController2.java b/apex/media/java/android/media/MediaController2.java index c3dd3fe4451c..c3dd3fe4451c 100644 --- a/media/apex/java/android/media/MediaController2.java +++ b/apex/media/java/android/media/MediaController2.java diff --git a/media/apex/java/android/media/MediaParser.java b/apex/media/java/android/media/MediaParser.java index ac66d1b7f4ad..ac66d1b7f4ad 100644 --- a/media/apex/java/android/media/MediaParser.java +++ b/apex/media/java/android/media/MediaParser.java diff --git a/media/apex/java/android/media/MediaSession2.java b/apex/media/java/android/media/MediaSession2.java index 081e76ab0215..081e76ab0215 100644 --- a/media/apex/java/android/media/MediaSession2.java +++ b/apex/media/java/android/media/MediaSession2.java diff --git a/media/apex/java/android/media/MediaSession2Service.java b/apex/media/java/android/media/MediaSession2Service.java index f6fd509fd245..f6fd509fd245 100644 --- a/media/apex/java/android/media/MediaSession2Service.java +++ b/apex/media/java/android/media/MediaSession2Service.java diff --git a/media/apex/java/android/media/ProxyDataSourceCallback.java b/apex/media/java/android/media/ProxyDataSourceCallback.java index 14d3ce87f03d..14d3ce87f03d 100644 --- a/media/apex/java/android/media/ProxyDataSourceCallback.java +++ b/apex/media/java/android/media/ProxyDataSourceCallback.java diff --git a/media/apex/java/android/media/RoutingDelegate.java b/apex/media/java/android/media/RoutingDelegate.java index 23598130f391..23598130f391 100644 --- a/media/apex/java/android/media/RoutingDelegate.java +++ b/apex/media/java/android/media/RoutingDelegate.java diff --git a/media/apex/java/android/media/Session2Command.aidl b/apex/media/java/android/media/Session2Command.aidl index 43a7b123ed29..43a7b123ed29 100644 --- a/media/apex/java/android/media/Session2Command.aidl +++ b/apex/media/java/android/media/Session2Command.aidl diff --git a/media/apex/java/android/media/Session2Command.java b/apex/media/java/android/media/Session2Command.java index 26f4568fa7e5..26f4568fa7e5 100644 --- a/media/apex/java/android/media/Session2Command.java +++ b/apex/media/java/android/media/Session2Command.java diff --git a/media/apex/java/android/media/Session2CommandGroup.java b/apex/media/java/android/media/Session2CommandGroup.java index 0ee5f62be128..13aabfc45ab7 100644 --- a/media/apex/java/android/media/Session2CommandGroup.java +++ b/apex/media/java/android/media/Session2CommandGroup.java @@ -38,8 +38,8 @@ import java.util.Set; public final class Session2CommandGroup implements Parcelable { private static final String TAG = "Session2CommandGroup"; - public static final @android.annotation.NonNull Parcelable.Creator<Session2CommandGroup> CREATOR = - new Parcelable.Creator<Session2CommandGroup>() { + public static final @android.annotation.NonNull Parcelable.Creator<Session2CommandGroup> + CREATOR = new Parcelable.Creator<Session2CommandGroup>() { @Override public Session2CommandGroup createFromParcel(Parcel in) { return new Session2CommandGroup(in); diff --git a/media/apex/java/android/media/Session2Link.java b/apex/media/java/android/media/Session2Link.java index 6e550e86a9fe..6e550e86a9fe 100644 --- a/media/apex/java/android/media/Session2Link.java +++ b/apex/media/java/android/media/Session2Link.java diff --git a/media/apex/java/android/media/Session2Token.aidl b/apex/media/java/android/media/Session2Token.aidl index c5980e9e77fd..c5980e9e77fd 100644 --- a/media/apex/java/android/media/Session2Token.aidl +++ b/apex/media/java/android/media/Session2Token.aidl diff --git a/media/apex/java/android/media/Session2Token.java b/apex/media/java/android/media/Session2Token.java index 6eb76b11497e..aae2e1bcb6df 100644 --- a/media/apex/java/android/media/Session2Token.java +++ b/apex/media/java/android/media/Session2Token.java @@ -52,17 +52,18 @@ import java.util.Objects; public final class Session2Token implements Parcelable { private static final String TAG = "Session2Token"; - public static final @android.annotation.NonNull Creator<Session2Token> CREATOR = new Creator<Session2Token>() { - @Override - public Session2Token createFromParcel(Parcel p) { - return new Session2Token(p); - } + public static final @android.annotation.NonNull Creator<Session2Token> CREATOR = + new Creator<Session2Token>() { + @Override + public Session2Token createFromParcel(Parcel p) { + return new Session2Token(p); + } - @Override - public Session2Token[] newArray(int size) { - return new Session2Token[size]; - } - }; + @Override + public Session2Token[] newArray(int size) { + return new Session2Token[size]; + } + }; /** * @hide diff --git a/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java b/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java index 7ed51caf23dd..e4f73000223f 100644 --- a/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java +++ b/apex/statsd/service/java/com/android/server/stats/StatsCompanionService.java @@ -23,7 +23,6 @@ import static android.os.Process.getUidForPid; import static android.os.storage.VolumeInfo.TYPE_PRIVATE; import static android.os.storage.VolumeInfo.TYPE_PUBLIC; -import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.server.am.MemoryStatUtil.readMemoryStatFromFilesystem; import static com.android.server.stats.IonMemoryUtil.readProcessSystemIonHeapSizesFromDebugfs; import static com.android.server.stats.IonMemoryUtil.readSystemIonHeapSizeFromDebugfs; @@ -1848,7 +1847,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub { int tagId, long elapsedNanos, long wallClockNanos, List<StatsLogEventWrapper> pulledData) { PowerProfile powerProfile = new PowerProfile(mContext); - checkNotNull(powerProfile); + Objects.requireNonNull(powerProfile); StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos); diff --git a/api/current.txt b/api/current.txt index c734db5196a9..f6aa0a316b70 100644 --- a/api/current.txt +++ b/api/current.txt @@ -610,6 +610,7 @@ package android { field public static final int fastScrollTextColor = 16843609; // 0x1010359 field public static final int fastScrollThumbDrawable = 16843574; // 0x1010336 field public static final int fastScrollTrackDrawable = 16843577; // 0x1010339 + field public static final int featureId = 16844301; // 0x101060d field public static final int fillAfter = 16843197; // 0x10101bd field public static final int fillAlpha = 16843980; // 0x10104cc field public static final int fillBefore = 16843196; // 0x10101bc diff --git a/api/system-current.txt b/api/system-current.txt index 6e05db9d2d2e..8a888db638b0 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4099,6 +4099,10 @@ package android.media { method public android.media.AudioRecord.Builder setSessionId(int) throws java.lang.IllegalArgumentException; } + public final class AudioRecordingConfiguration implements android.os.Parcelable { + method public int getClientUid(); + } + public class HwAudioSource { method public boolean isPlaying(); method public void start(); @@ -5693,6 +5697,7 @@ package android.net.wifi { @Deprecated public class WifiConfiguration implements android.os.Parcelable { method @Deprecated public int getAuthType(); method @Deprecated @NonNull public android.net.IpConfiguration.IpAssignment getIpAssignment(); + method @Deprecated @NonNull public android.net.IpConfiguration getIpConfiguration(); method @Deprecated @NonNull public android.net.wifi.WifiConfiguration.NetworkSelectionStatus getNetworkSelectionStatus(); method @Deprecated @NonNull public String getPrintableSsid(); method @Deprecated @NonNull public android.net.IpConfiguration.ProxySettings getProxySettings(); diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp index 887d17cb7e4b..7b96ce92e307 100644 --- a/cmds/statsd/Android.bp +++ b/cmds/statsd/Android.bp @@ -196,18 +196,6 @@ cc_library_shared { "libcutils", "libstatslog", ], - target: { - android: { - shared_libs: [ - "libutils", - ], - }, - host: { - static_libs: [ - "libutils", - ], - }, - }, } diff --git a/cmds/statsd/src/atom_field_options.proto b/cmds/statsd/src/atom_field_options.proto index 16c936c41559..6d2bd04756ac 100644 --- a/cmds/statsd/src/atom_field_options.proto +++ b/cmds/statsd/src/atom_field_options.proto @@ -85,5 +85,5 @@ extend google.protobuf.FieldOptions { optional bool allow_from_any_uid = 50003 [default = false]; - optional string log_from_module = 50004; -}
\ No newline at end of file + optional string module = 50004; +} diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 227097437c7f..815e3e668d31 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -112,9 +112,9 @@ message Atom { TouchEventReported touch_event_reported = 34; WakeupAlarmOccurred wakeup_alarm_occurred = 35; KernelWakeupReported kernel_wakeup_reported = 36; - WifiLockStateChanged wifi_lock_state_changed = 37 [(log_from_module) = "wifi"]; - WifiSignalStrengthChanged wifi_signal_strength_changed = 38 [(log_from_module) = "wifi"]; - WifiScanStateChanged wifi_scan_state_changed = 39 [(log_from_module) = "wifi"]; + WifiLockStateChanged wifi_lock_state_changed = 37 [(module) = "wifi"]; + WifiSignalStrengthChanged wifi_signal_strength_changed = 38 [(module) = "wifi"]; + WifiScanStateChanged wifi_scan_state_changed = 39 [(module) = "wifi"]; PhoneSignalStrengthChanged phone_signal_strength_changed = 40; SettingChanged setting_changed = 41; ActivityForegroundStateChanged activity_foreground_state_changed = 42; @@ -128,7 +128,7 @@ message Atom { AppStartFullyDrawn app_start_fully_drawn = 50; LmkKillOccurred lmk_kill_occurred = 51; PictureInPictureStateChanged picture_in_picture_state_changed = 52; - WifiMulticastLockStateChanged wifi_multicast_lock_state_changed = 53 [(log_from_module) = "wifi"]; + WifiMulticastLockStateChanged wifi_multicast_lock_state_changed = 53 [(module) = "wifi"]; LmkStateChanged lmk_state_changed = 54; AppStartMemoryStateCaptured app_start_memory_state_captured = 55; ShutdownSequenceReported shutdown_sequence_reported = 56; @@ -182,39 +182,27 @@ message Atom { FlagFlipUpdateOccurred flag_flip_update_occurred = 101; BinaryPushStateChanged binary_push_state_changed = 102; DevicePolicyEvent device_policy_event = 103; - DocsUIFileOperationCanceledReported docs_ui_file_op_canceled = - 104 [(log_from_module) = "docsui"]; - DocsUIFileOperationCopyMoveModeReported - docs_ui_file_op_copy_move_mode_reported = - 105 [(log_from_module) = "docsui"]; - DocsUIFileOperationFailureReported docs_ui_file_op_failure = - 106 [(log_from_module) = "docsui"]; - DocsUIFileOperationReported docs_ui_provider_file_op = - 107 [(log_from_module) = "docsui"]; - DocsUIInvalidScopedAccessRequestReported - docs_ui_invalid_scoped_access_request = - 108 [(log_from_module) = "docsui"]; - DocsUILaunchReported docs_ui_launch_reported = - 109 [(log_from_module) = "docsui"]; - DocsUIRootVisitedReported docs_ui_root_visited = - 110 [(log_from_module) = "docsui"]; - DocsUIStartupMsReported docs_ui_startup_ms = - 111 [(log_from_module) = "docsui"]; - DocsUIUserActionReported docs_ui_user_action_reported = - 112 [(log_from_module) = "docsui"]; + DocsUIFileOperationCanceledReported docs_ui_file_op_canceled = 104 [(module) = "docsui"]; + DocsUIFileOperationCopyMoveModeReported docs_ui_file_op_copy_move_mode_reported = + 105 [(module) = "docsui"]; + DocsUIFileOperationFailureReported docs_ui_file_op_failure = 106 [(module) = "docsui"]; + DocsUIFileOperationReported docs_ui_provider_file_op = 107 [(module) = "docsui"]; + DocsUIInvalidScopedAccessRequestReported docs_ui_invalid_scoped_access_request = + 108 [(module) = "docsui"]; + DocsUILaunchReported docs_ui_launch_reported = 109 [(module) = "docsui"]; + DocsUIRootVisitedReported docs_ui_root_visited = 110 [(module) = "docsui"]; + DocsUIStartupMsReported docs_ui_startup_ms = 111 [(module) = "docsui"]; + DocsUIUserActionReported docs_ui_user_action_reported = 112 [(module) = "docsui"]; WifiEnabledStateChanged wifi_enabled_state_changed = 113; WifiRunningStateChanged wifi_running_state_changed = 114; AppCompacted app_compacted = 115; - NetworkDnsEventReported network_dns_event_reported = 116 [(log_from_module) = "resolv"]; + NetworkDnsEventReported network_dns_event_reported = 116 [(module) = "resolv"]; DocsUIPickerLaunchedFromReported docs_ui_picker_launched_from_reported = - 117 [(log_from_module) = "docsui"]; - DocsUIPickResultReported docs_ui_pick_result_reported = - 118 [(log_from_module) = "docsui"]; - DocsUISearchModeReported docs_ui_search_mode_reported = - 119 [(log_from_module) = "docsui"]; - DocsUISearchTypeReported docs_ui_search_type_reported = - 120 [(log_from_module) = "docsui"]; - DataStallEvent data_stall_event = 121 [(log_from_module) = "network_stack"]; + 117 [(module) = "docsui"]; + DocsUIPickResultReported docs_ui_pick_result_reported = 118 [(module) = "docsui"]; + DocsUISearchModeReported docs_ui_search_mode_reported = 119 [(module) = "docsui"]; + DocsUISearchTypeReported docs_ui_search_type_reported = 120 [(module) = "docsui"]; + DataStallEvent data_stall_event = 121 [(module) = "network_stack"]; RescuePartyResetReported rescue_party_reset_reported = 122; SignedConfigReported signed_config_reported = 123; GnssNiEventReported gnss_ni_event_reported = 124; @@ -264,7 +252,7 @@ message Atom { ScreenTimeoutExtensionReported screen_timeout_extension_reported = 168; ProcessStartTime process_start_time = 169; PermissionGrantRequestResultReported permission_grant_request_result_reported = - 170 [(log_from_module) = "permissioncontroller"]; + 170 [(module) = "permissioncontroller"]; BluetoothSocketConnectionStateChanged bluetooth_socket_connection_state_changed = 171; DeviceIdentifierAccessDenied device_identifier_access_denied = 172; BubbleDeveloperErrorReported bubble_developer_error_reported = 173; @@ -273,21 +261,21 @@ message Atom { AssistGestureProgressReported assist_gesture_progress_reported = 176; TouchGestureClassified touch_gesture_classified = 177; HiddenApiUsed hidden_api_used = 178 [(allow_from_any_uid) = true]; - StyleUIChanged style_ui_changed = 179 [(log_from_module) = "style"]; + StyleUIChanged style_ui_changed = 179 [(module) = "style"]; PrivacyIndicatorsInteracted privacy_indicators_interacted = - 180 [(log_from_module) = "permissioncontroller"]; + 180 [(module) = "permissioncontroller"]; AppInstallOnExternalStorageReported app_install_on_external_storage_reported = 181; - NetworkStackReported network_stack_reported = 182 [(log_from_module) = "network_stack"]; + NetworkStackReported network_stack_reported = 182 [(module) = "network_stack"]; AppMovedStorageReported app_moved_storage_reported = 183; BiometricEnrolled biometric_enrolled = 184; SystemServerWatchdogOccurred system_server_watchdog_occurred = 185; TombStoneOccurred tomb_stone_occurred = 186; BluetoothClassOfDeviceReported bluetooth_class_of_device_reported = 187; IntelligenceEventReported intelligence_event_reported = - 188 [(log_from_module) = "intelligence"]; + 188 [(module) = "intelligence"]; ThermalThrottlingSeverityStateChanged thermal_throttling_severity_state_changed = 189; RoleRequestResultReported role_request_result_reported = - 190 [(log_from_module) = "permissioncontroller"]; + 190 [(module) = "permissioncontroller"]; MediametricsAudiopolicyReported mediametrics_audiopolicy_reported = 191; MediametricsAudiorecordReported mediametrics_audiorecord_reported = 192; MediametricsAudiothreadReported mediametrics_audiothread_reported = 193; @@ -301,36 +289,32 @@ message Atom { MediametricsDrmManagerReported mediametrics_drmmanager_reported = 201; CarPowerStateChanged car_power_state_changed = 203; GarageModeInfo garage_mode_info = 204; - TestAtomReported test_atom_reported = 205 [(log_from_module) = "cts"]; + TestAtomReported test_atom_reported = 205 [(module) = "cts"]; ContentCaptureCallerMismatchReported content_capture_caller_mismatch_reported = 206; ContentCaptureServiceEvents content_capture_service_events = 207; ContentCaptureSessionEvents content_capture_session_events = 208; ContentCaptureFlushed content_capture_flushed = 209; LocationManagerApiUsageReported location_manager_api_usage_reported = 210; ReviewPermissionsFragmentResultReported review_permissions_fragment_result_reported = - 211 [(log_from_module) = "permissioncontroller"]; + 211 [(module) = "permissioncontroller"]; RuntimePermissionsUpgradeResult runtime_permissions_upgrade_result = - 212 [(log_from_module) = "permissioncontroller"]; + 212 [(module) = "permissioncontroller"]; GrantPermissionsActivityButtonActions grant_permissions_activity_button_actions = - 213 [(log_from_module) = "permissioncontroller"]; + 213 [(module) = "permissioncontroller"]; LocationAccessCheckNotificationAction location_access_check_notification_action = - 214 [(log_from_module) = "permissioncontroller"]; + 214 [(module) = "permissioncontroller"]; AppPermissionFragmentActionReported app_permission_fragment_action_reported = - 215 [(log_from_module) = "permissioncontroller"]; + 215 [(module) = "permissioncontroller"]; AppPermissionFragmentViewed app_permission_fragment_viewed = - 216 [(log_from_module) = "permissioncontroller"]; + 216 [(module) = "permissioncontroller"]; AppPermissionsFragmentViewed app_permissions_fragment_viewed = - 217 [(log_from_module) = "permissioncontroller"]; + 217 [(module) = "permissioncontroller"]; PermissionAppsFragmentViewed permission_apps_fragment_viewed = - 218 [(log_from_module) = "permissioncontroller"]; - TextSelectionEvent text_selection_event = - 219 [(log_from_module) = "textclassifier"]; - TextLinkifyEvent text_linkify_event = - 220 [(log_from_module) = "textclassifier"]; - ConversationActionsEvent conversation_actions_event = - 221 [(log_from_module) = "textclassifier"]; - LanguageDetectionEvent language_detection_event = - 222 [(log_from_module) = "textclassifier"]; + 218 [(module) = "permissioncontroller"]; + TextSelectionEvent text_selection_event = 219 [(module) = "textclassifier"]; + TextLinkifyEvent text_linkify_event = 220 [(module) = "textclassifier"]; + ConversationActionsEvent conversation_actions_event = 221 [(module) = "textclassifier"]; + LanguageDetectionEvent language_detection_event = 222 [(module) = "textclassifier"]; ExclusionRectStateChanged exclusion_rect_state_changed = 223; BackGesture back_gesture_reported_reported = 224; UpdateEngineUpdateAttemptReported update_engine_update_attempt_reported = 225; @@ -338,21 +322,17 @@ message Atom { CameraActionEvent camera_action_event = 227; AppCompatibilityChangeReported app_compatibility_change_reported = 228 [(allow_from_any_uid) = true]; - PerfettoUploaded perfetto_uploaded = - 229 [(log_from_module) = "perfetto"]; + PerfettoUploaded perfetto_uploaded = 229 [(module) = "perfetto"]; VmsClientConnectionStateChanged vms_client_connection_state_changed = 230; GpsLocationStatusReported gps_location_status_reported = 231; GpsTimeToFirstFixReported gps_time_to_first_fix_reported = 232; - MediaProviderScanEvent media_provider_scan_event = - 233 [(log_from_module) = "mediaprovider"]; - MediaProviderDeletionEvent media_provider_deletion_event = - 234 [(log_from_module) = "mediaprovider"]; + MediaProviderScanEvent media_provider_scan_event = 233 [(module) = "mediaprovider"]; + MediaProviderDeletionEvent media_provider_deletion_event = 234 [(module) = "mediaprovider"]; MediaProviderPermissionEvent media_provider_permission_event = - 235 [(log_from_module) = "mediaprovider"]; - MediaProviderSchemaChange media_provider_schema_change = - 236 [(log_from_module) = "mediaprovider"]; + 235 [(module) = "mediaprovider"]; + MediaProviderSchemaChange media_provider_schema_change = 236 [(module) = "mediaprovider"]; MediaProviderIdleMaintenance media_provider_idle_maintenance = - 237 [(log_from_module) = "mediaprovider"]; + 237 [(module) = "mediaprovider"]; } // Pulled events will start at field 10000. diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 08f873494cbc..a4f6f57c097e 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -3659,7 +3659,7 @@ public final class ActivityThread extends ClientTransactionHandler { r.activity, Looper.myLooper()); } r.activity.onGetDirectActions(cancellationSignal, (actions) -> { - Preconditions.checkNotNull(actions); + Objects.requireNonNull(actions); Preconditions.checkCollectionElementsNotNull(actions, "actions"); if (!actions.isEmpty()) { final int actionCount = actions.size(); diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 86a5c762240f..69bc0c0449ef 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -51,6 +51,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.LongSparseArray; import android.util.LongSparseLongArray; +import android.util.Pools; import android.util.SparseArray; import com.android.internal.annotations.GuardedBy; @@ -1159,8 +1160,6 @@ public class AppOpsManager { }) private @interface ShouldCollectNoteOp {} - // Warning: If an permission is added here it also has to be added to - // com.android.packageinstaller.permission.utils.EventLogger private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = { // RUNTIME PERMISSIONS // Contacts @@ -2341,15 +2340,31 @@ public class AppOpsManager { */ @TestApi @SystemApi - @Immutable - @DataClass(genHiddenConstructor = true) + // @DataClass(genHiddenConstructor = true, genHiddenCopyConstructor = true) + // genHiddenCopyConstructor does not work for @hide @SystemApi classes public static final class OpEventProxyInfo implements Parcelable { /** UID of the proxy app that noted the op */ - private final @IntRange(from = 0) int mUid; + private @IntRange(from = 0) int mUid; /** Package of the proxy that noted the op */ - private final @Nullable String mPackageName; + private @Nullable String mPackageName; /** ID of the feature of the proxy that noted the op */ - private final @Nullable String mFeatureId; + private @Nullable String mFeatureId; + + /** + * Reinit existing object with new state. + * + * @param uid UID of the proxy app that noted the op + * @param packageName Package of the proxy that noted the op + * @param featureId ID of the feature of the proxy that noted the op + * + * @hide + */ + public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName, + @Nullable String featureId) { + mUid = Preconditions.checkArgumentNonnegative(uid); + mPackageName = packageName; + mFeatureId = featureId; + } @@ -2393,6 +2408,18 @@ public class AppOpsManager { } /** + * Copy constructor + * + * @hide + */ + @DataClass.Generated.Member + public OpEventProxyInfo(@NonNull OpEventProxyInfo orig) { + mUid = orig.mUid; + mPackageName = orig.mPackageName; + mFeatureId = orig.mFeatureId; + } + + /** * UID of the proxy app that noted the op */ @DataClass.Generated.Member @@ -2471,14 +2498,15 @@ public class AppOpsManager { } }; + /* @DataClass.Generated( - time = 1576194071700L, + time = 1576814974615L, codegenVersion = "1.0.14", sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", - inputSignatures = "private final @android.annotation.IntRange(from=0L) int mUid\nprivate final @android.annotation.Nullable java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mFeatureId\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)") + inputSignatures = "private @android.annotation.IntRange(from=0L) int mUid\nprivate @android.annotation.Nullable java.lang.String mPackageName\nprivate @android.annotation.Nullable java.lang.String mFeatureId\npublic void reinit(int,java.lang.String,java.lang.String)\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genHiddenCopyConstructor=true)") @Deprecated private void __metadata() {} - + */ //@formatter:on // End of generated code @@ -2490,15 +2518,48 @@ public class AppOpsManager { * * @hide */ - @Immutable //@DataClass codegen verifier is broken public static final class NoteOpEvent implements Parcelable { /** Time of noteOp event */ - public final @IntRange(from = 0) long noteTime; + private @IntRange(from = 0) long mNoteTime; /** The duration of this event (in case this is a startOp event, -1 otherwise). */ - public final @IntRange(from = -1) long duration; + private @IntRange(from = -1) long mDuration; /** Proxy information of the noteOp event */ - public final @Nullable OpEventProxyInfo proxy; + private @Nullable OpEventProxyInfo mProxy; + + /** + * Reinit existing object with new state. + * + * @param noteTime Time of noteOp event + * @param duration The duration of this event (in case this is a startOp event, + * -1 otherwise). + * @param proxy Proxy information of the noteOp event + * @param proxyPool The pool to release previous {@link OpEventProxyInfo} to + */ + public void reinit(@IntRange(from = 0) long noteTime, + @IntRange(from = -1) long duration, + @Nullable OpEventProxyInfo proxy, + @NonNull Pools.Pool<OpEventProxyInfo> proxyPool) { + mNoteTime = Preconditions.checkArgumentNonnegative(noteTime); + mDuration = Preconditions.checkArgumentInRange(duration, -1L, Long.MAX_VALUE, + "duration"); + + if (mProxy != null) { + proxyPool.release(mProxy); + } + mProxy = proxy; + } + + /** + * Copy constructor + * + * @hide + */ + public NoteOpEvent(@NonNull NoteOpEvent original) { + this(original.mNoteTime, original.mDuration, + original.mProxy != null ? new OpEventProxyInfo(original.mProxy) : null); + } + // Code below generated by codegen v1.0.14. @@ -2529,19 +2590,43 @@ public class AppOpsManager { @IntRange(from = 0) long noteTime, @IntRange(from = -1) long duration, @Nullable OpEventProxyInfo proxy) { - this.noteTime = noteTime; + this.mNoteTime = noteTime; com.android.internal.util.AnnotationValidations.validate( - IntRange.class, null, noteTime, + IntRange.class, null, mNoteTime, "from", 0); - this.duration = duration; + this.mDuration = duration; com.android.internal.util.AnnotationValidations.validate( - IntRange.class, null, duration, + IntRange.class, null, mDuration, "from", -1); - this.proxy = proxy; + this.mProxy = proxy; // onConstructed(); // You can define this method to get a callback } + /** + * Time of noteOp event + */ + @DataClass.Generated.Member + public @IntRange(from = 0) long getNoteTime() { + return mNoteTime; + } + + /** + * The duration of this event (in case this is a startOp event, -1 otherwise). + */ + @DataClass.Generated.Member + public @IntRange(from = -1) long getDuration() { + return mDuration; + } + + /** + * Proxy information of the noteOp event + */ + @DataClass.Generated.Member + public @Nullable OpEventProxyInfo getProxy() { + return mProxy; + } + @Override @DataClass.Generated.Member public void writeToParcel(@NonNull Parcel dest, int flags) { @@ -2549,11 +2634,11 @@ public class AppOpsManager { // void parcelFieldName(Parcel dest, int flags) { ... } byte flg = 0; - if (proxy != null) flg |= 0x4; + if (mProxy != null) flg |= 0x4; dest.writeByte(flg); - dest.writeLong(noteTime); - dest.writeLong(duration); - if (proxy != null) dest.writeTypedObject(proxy, flags); + dest.writeLong(mNoteTime); + dest.writeLong(mDuration); + if (mProxy != null) dest.writeTypedObject(mProxy, flags); } @Override @@ -2568,20 +2653,19 @@ public class AppOpsManager { // static FieldType unparcelFieldName(Parcel in) { ... } byte flg = in.readByte(); - long _noteTime = in.readLong(); - long _duration = in.readLong(); - OpEventProxyInfo _proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject( - OpEventProxyInfo.CREATOR); + long noteTime = in.readLong(); + long duration = in.readLong(); + OpEventProxyInfo proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject(OpEventProxyInfo.CREATOR); - this.noteTime = _noteTime; + this.mNoteTime = noteTime; com.android.internal.util.AnnotationValidations.validate( - IntRange.class, null, noteTime, + IntRange.class, null, mNoteTime, "from", 0); - this.duration = _duration; + this.mDuration = duration; com.android.internal.util.AnnotationValidations.validate( - IntRange.class, null, duration, + IntRange.class, null, mDuration, "from", -1); - this.proxy = _proxy; + this.mProxy = proxy; // onConstructed(); // You can define this method to get a callback } @@ -2602,10 +2686,10 @@ public class AppOpsManager { /* @DataClass.Generated( - time = 1574809856220L, + time = 1576811792274L, codegenVersion = "1.0.14", sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java", - inputSignatures = "public final @android.annotation.IntRange(from=0L) long noteTime\npublic final @android.annotation.IntRange(from=-1) long duration\npublic final @android.annotation.Nullable android.app.NoteOpEventProxyInfo proxy\nclass NoteOpEvent extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass") + inputSignatures = "private @android.annotation.IntRange(from=0L) long mNoteTime\nprivate @android.annotation.IntRange(from=-1) long mDuration\nprivate @android.annotation.Nullable android.app.OpEventProxyInfo mProxy\npublic void reinit(long,long,android.app.OpEventProxyInfo,android.util.Pools.Pool<android.app.OpEventProxyInfo>)\npublic @java.lang.Override java.lang.Object clone()\nclass NoteOpEvent extends java.lang.Object implements [android.os.Parcelable, java.lang.Cloneable]\n@com.android.internal.util.DataClass") @Deprecated private void __metadata() {} */ @@ -2751,7 +2835,7 @@ public class AppOpsManager { return -1; } - return lastEvent.noteTime; + return lastEvent.getNoteTime(); } /** @@ -2847,7 +2931,7 @@ public class AppOpsManager { return -1; } - return lastEvent.noteTime; + return lastEvent.getNoteTime(); } /** @@ -2922,7 +3006,7 @@ public class AppOpsManager { return -1; } - return lastEvent.duration; + return lastEvent.getDuration(); } /** @@ -3000,7 +3084,7 @@ public class AppOpsManager { return null; } - return lastEvent.proxy; + return lastEvent.getProxy(); } private static class LongSparseArrayParceling implements @@ -3304,7 +3388,7 @@ public class AppOpsManager { toUidState, flags); if (lastAccessEvent == null || (lastFeatureAccessEvent != null - && lastFeatureAccessEvent.noteTime > lastAccessEvent.noteTime)) { + && lastFeatureAccessEvent.getNoteTime() > lastAccessEvent.getNoteTime())) { lastAccessEvent = lastFeatureAccessEvent; } } @@ -3335,7 +3419,7 @@ public class AppOpsManager { return -1; } - return lastEvent.noteTime; + return lastEvent.getNoteTime(); } /** @@ -3418,7 +3502,7 @@ public class AppOpsManager { toUidState, flags); if (lastAccessEvent == null || (lastFeatureAccessEvent != null - && lastFeatureAccessEvent.noteTime > lastAccessEvent.noteTime)) { + && lastFeatureAccessEvent.getNoteTime() > lastAccessEvent.getNoteTime())) { lastAccessEvent = lastFeatureAccessEvent; } } @@ -3449,7 +3533,7 @@ public class AppOpsManager { return -1; } - return lastEvent.noteTime; + return lastEvent.getNoteTime(); } /** @@ -3544,7 +3628,7 @@ public class AppOpsManager { return -1; } - return lastEvent.duration; + return lastEvent.getDuration(); } /** @@ -3674,7 +3758,7 @@ public class AppOpsManager { return null; } - return lastEvent.proxy; + return lastEvent.getProxy(); } @@ -5517,8 +5601,8 @@ public class AppOpsManager { @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) public void getHistoricalOps(@NonNull HistoricalOpsRequest request, @NonNull Executor executor, @NonNull Consumer<HistoricalOps> callback) { - Preconditions.checkNotNull(executor, "executor cannot be null"); - Preconditions.checkNotNull(callback, "callback cannot be null"); + Objects.requireNonNull(executor, "executor cannot be null"); + Objects.requireNonNull(callback, "callback cannot be null"); try { mService.getHistoricalOps(request.mUid, request.mPackageName, request.mOpNames, request.mBeginTimeMillis, request.mEndTimeMillis, request.mFlags, @@ -5556,8 +5640,8 @@ public class AppOpsManager { @RequiresPermission(Manifest.permission.MANAGE_APPOPS) public void getHistoricalOpsFromDiskRaw(@NonNull HistoricalOpsRequest request, @Nullable Executor executor, @NonNull Consumer<HistoricalOps> callback) { - Preconditions.checkNotNull(executor, "executor cannot be null"); - Preconditions.checkNotNull(callback, "callback cannot be null"); + Objects.requireNonNull(executor, "executor cannot be null"); + Objects.requireNonNull(callback, "callback cannot be null"); try { mService.getHistoricalOpsFromDiskRaw(request.mUid, request.mPackageName, request.mOpNames, request.mBeginTimeMillis, request.mEndTimeMillis, @@ -7062,7 +7146,7 @@ public class AppOpsManager { private final IAppOpsAsyncNotedCallback mAsyncCb = new IAppOpsAsyncNotedCallback.Stub() { @Override public void opNoted(AsyncNotedAppOp op) { - Preconditions.checkNotNull(op); + Objects.requireNonNull(op); getAsyncNotedExecutor().execute(() -> onAsyncNoted(op)); } @@ -7331,7 +7415,8 @@ public class AppOpsManager { final long key = makeKey(uidState, flag); NoteOpEvent event = events.get(key); - if (lastEvent == null || event != null && event.noteTime > lastEvent.noteTime) { + if (lastEvent == null + || event != null && event.getNoteTime() > lastEvent.getNoteTime()) { lastEvent = event; } } diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java index 7f26565d760a..1c6a5615dbd5 100644 --- a/core/java/android/app/ApplicationPackageManager.java +++ b/core/java/android/app/ApplicationPackageManager.java @@ -100,7 +100,6 @@ import android.view.Display; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.os.SomeArgs; -import com.android.internal.util.Preconditions; import com.android.internal.util.UserIcons; import dalvik.system.VMRuntime; @@ -2149,7 +2148,7 @@ public class ApplicationPackageManager extends PackageManager { } else if (vol.isPrimaryPhysical()) { volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL; } else { - volumeUuid = Preconditions.checkNotNull(vol.fsUuid); + volumeUuid = Objects.requireNonNull(vol.fsUuid); } return mPM.movePackage(packageName, volumeUuid); @@ -2259,7 +2258,7 @@ public class ApplicationPackageManager extends PackageManager { } else if (vol.isPrimaryPhysical()) { volumeUuid = StorageManager.UUID_PRIMARY_PHYSICAL; } else { - volumeUuid = Preconditions.checkNotNull(vol.fsUuid); + volumeUuid = Objects.requireNonNull(vol.fsUuid); } return mPM.movePrimaryStorage(volumeUuid); @@ -2661,8 +2660,8 @@ public class ApplicationPackageManager extends PackageManager { /** @hide */ @Override public KeySet getKeySetByAlias(String packageName, String alias) { - Preconditions.checkNotNull(packageName); - Preconditions.checkNotNull(alias); + Objects.requireNonNull(packageName); + Objects.requireNonNull(alias); try { return mPM.getKeySetByAlias(packageName, alias); } catch (RemoteException e) { @@ -2673,7 +2672,7 @@ public class ApplicationPackageManager extends PackageManager { /** @hide */ @Override public KeySet getSigningKeySet(String packageName) { - Preconditions.checkNotNull(packageName); + Objects.requireNonNull(packageName); try { return mPM.getSigningKeySet(packageName); } catch (RemoteException e) { @@ -2684,8 +2683,8 @@ public class ApplicationPackageManager extends PackageManager { /** @hide */ @Override public boolean isSignedBy(String packageName, KeySet ks) { - Preconditions.checkNotNull(packageName); - Preconditions.checkNotNull(ks); + Objects.requireNonNull(packageName); + Objects.requireNonNull(ks); try { return mPM.isPackageSignedByKeySet(packageName, ks); } catch (RemoteException e) { @@ -2696,8 +2695,8 @@ public class ApplicationPackageManager extends PackageManager { /** @hide */ @Override public boolean isSignedByExactly(String packageName, KeySet ks) { - Preconditions.checkNotNull(packageName); - Preconditions.checkNotNull(ks); + Objects.requireNonNull(packageName); + Objects.requireNonNull(ks); try { return mPM.isPackageSignedByKeySetExactly(packageName, ks); } catch (RemoteException e) { diff --git a/core/java/android/app/AuthenticationRequiredException.java b/core/java/android/app/AuthenticationRequiredException.java index 0d8733688afa..847d2c4e5939 100644 --- a/core/java/android/app/AuthenticationRequiredException.java +++ b/core/java/android/app/AuthenticationRequiredException.java @@ -21,7 +21,7 @@ import android.content.ContentResolver; import android.os.Parcel; import android.os.Parcelable; -import com.android.internal.util.Preconditions; +import java.util.Objects; /** * Specialization of {@link SecurityException} that is thrown when authentication is needed from the @@ -60,7 +60,7 @@ public final class AuthenticationRequiredException extends SecurityException imp */ public AuthenticationRequiredException(Throwable cause, PendingIntent userAction) { super(cause.getMessage()); - mUserAction = Preconditions.checkNotNull(userAction); + mUserAction = Objects.requireNonNull(userAction); } /** diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index bd87fcd2565e..cd84310356b1 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -2794,7 +2794,7 @@ class ContextImpl extends Context { public ApplicationContentResolver(Context context, ActivityThread mainThread) { super(context); - mMainThread = Preconditions.checkNotNull(mainThread); + mMainThread = Objects.requireNonNull(mainThread); } @Override diff --git a/core/java/android/app/DirectAction.java b/core/java/android/app/DirectAction.java index ef3627b26a5d..0268f7ca2b73 100644 --- a/core/java/android/app/DirectAction.java +++ b/core/java/android/app/DirectAction.java @@ -172,7 +172,7 @@ public final class DirectAction implements Parcelable { * current application state. */ public Builder(@NonNull String id) { - Preconditions.checkNotNull(id); + Objects.requireNonNull(id); mId = id; } diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index 453c600d49c7..775b1d165717 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -46,7 +46,7 @@ import android.os.StrictMode; import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; -import android.sysprop.ProductProperties; +import android.sysprop.VndkProperties; import android.text.TextUtils; import android.util.AndroidRuntimeException; import android.util.ArrayMap; @@ -785,13 +785,12 @@ public final class LoadedApk { // Similar to vendor apks, we should add /product/lib for apks from product partition // when product apps are marked as unbundled. We cannot use the same way from vendor // to check if lib path exists because there is possibility that /product/lib would not - // exist from legacy device while product apks are bundled. To make this clear, new - // property ("ro.product.apps.unbundled") is defined which should be true only when - // product apks are unbundled. + // exist from legacy device while product apks are bundled. To make this clear, we use + // "ro.product.vndk.version" property. If the property is defined, we regard all product + // apks as unbundled. if (mApplicationInfo.getCodePath() != null - && mApplicationInfo.isProduct() && ProductProperties.unbundled_apps().orElse(false) - // TODO(b/128557860): Change target SDK version when version code R is available. - && getTargetSdkVersion() == Build.VERSION_CODES.CUR_DEVELOPMENT) { + && mApplicationInfo.isProduct() + && VndkProperties.product_vndk_version().isPresent()) { isBundledApp = false; } diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 31c73b90aace..ca3d0d7065c9 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -198,6 +198,7 @@ import com.android.internal.policy.PhoneLayoutInflater; import com.android.internal.util.Preconditions; import java.util.Map; +import java.util.Objects; /** * Manages all of the system services that can be returned by {@link Context#getSystemService}. @@ -1429,8 +1430,8 @@ public final class SystemServiceRegistry { @NonNull StaticServiceProducerWithBinder<TServiceClass> serviceProducer) { ensureInitializing("registerStaticService"); Preconditions.checkStringNotEmpty(serviceName); - Preconditions.checkNotNull(serviceWrapperClass); - Preconditions.checkNotNull(serviceProducer); + Objects.requireNonNull(serviceWrapperClass); + Objects.requireNonNull(serviceProducer); registerService(serviceName, serviceWrapperClass, new StaticServiceFetcher<TServiceClass>() { @@ -1453,8 +1454,8 @@ public final class SystemServiceRegistry { @NonNull StaticServiceProducerWithoutBinder<TServiceClass> serviceProducer) { ensureInitializing("registerStaticService"); Preconditions.checkStringNotEmpty(serviceName); - Preconditions.checkNotNull(serviceWrapperClass); - Preconditions.checkNotNull(serviceProducer); + Objects.requireNonNull(serviceWrapperClass); + Objects.requireNonNull(serviceProducer); registerService(serviceName, serviceWrapperClass, new StaticServiceFetcher<TServiceClass>() { @@ -1486,8 +1487,8 @@ public final class SystemServiceRegistry { @NonNull ContextAwareServiceProducerWithBinder<TServiceClass> serviceProducer) { ensureInitializing("registerContextAwareService"); Preconditions.checkStringNotEmpty(serviceName); - Preconditions.checkNotNull(serviceWrapperClass); - Preconditions.checkNotNull(serviceProducer); + Objects.requireNonNull(serviceWrapperClass); + Objects.requireNonNull(serviceProducer); registerService(serviceName, serviceWrapperClass, new CachedServiceFetcher<TServiceClass>() { @@ -1514,8 +1515,8 @@ public final class SystemServiceRegistry { @NonNull ContextAwareServiceProducerWithoutBinder<TServiceClass> serviceProducer) { ensureInitializing("registerContextAwareService"); Preconditions.checkStringNotEmpty(serviceName); - Preconditions.checkNotNull(serviceWrapperClass); - Preconditions.checkNotNull(serviceProducer); + Objects.requireNonNull(serviceWrapperClass); + Objects.requireNonNull(serviceProducer); registerService(serviceName, serviceWrapperClass, new CachedServiceFetcher<TServiceClass>() { diff --git a/core/java/android/app/VoiceInteractor.java b/core/java/android/app/VoiceInteractor.java index b37120faf281..c262ec2bf009 100644 --- a/core/java/android/app/VoiceInteractor.java +++ b/core/java/android/app/VoiceInteractor.java @@ -44,6 +44,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Objects; import java.util.concurrent.Executor; /** @@ -1129,8 +1130,8 @@ public final class VoiceInteractor { */ public boolean registerOnDestroyedCallback(@NonNull @CallbackExecutor Executor executor, @NonNull Runnable callback) { - Preconditions.checkNotNull(executor); - Preconditions.checkNotNull(callback); + Objects.requireNonNull(executor); + Objects.requireNonNull(callback); if (isDestroyed()) { Log.w(TAG, "Cannot interact with a destroyed voice interactor"); return false; @@ -1146,7 +1147,7 @@ public final class VoiceInteractor { * @return whether the callback was unregistered. */ public boolean unregisterOnDestroyedCallback(@NonNull Runnable callback) { - Preconditions.checkNotNull(callback); + Objects.requireNonNull(callback); if (isDestroyed()) { Log.w(TAG, "Cannot interact with a destroyed voice interactor"); return false; diff --git a/core/java/android/app/admin/DevicePolicyEventLogger.java b/core/java/android/app/admin/DevicePolicyEventLogger.java index 95a797392940..4c0e176c519e 100644 --- a/core/java/android/app/admin/DevicePolicyEventLogger.java +++ b/core/java/android/app/admin/DevicePolicyEventLogger.java @@ -25,6 +25,7 @@ import com.android.framework.protobuf.nano.MessageNano; import com.android.internal.util.Preconditions; import java.util.Arrays; +import java.util.Objects; /** * A wrapper for logging managed device events using {@link StatsLog}. @@ -136,7 +137,7 @@ public class DevicePolicyEventLogger { * in that order. */ public DevicePolicyEventLogger setStrings(String value, String[] values) { - Preconditions.checkNotNull(values, "values parameter cannot be null"); + Objects.requireNonNull(values, "values parameter cannot be null"); mStringArrayValue = new String[values.length + 1]; mStringArrayValue[0] = value; System.arraycopy(values, 0, mStringArrayValue, 1, values.length); @@ -150,7 +151,7 @@ public class DevicePolicyEventLogger { * and <code>values</code>, in that order. */ public DevicePolicyEventLogger setStrings(String value1, String value2, String[] values) { - Preconditions.checkNotNull(values, "values parameter cannot be null"); + Objects.requireNonNull(values, "values parameter cannot be null"); mStringArrayValue = new String[values.length + 2]; mStringArrayValue[0] = value1; mStringArrayValue[1] = value2; diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index acdf919e66a6..8daaaaa2e05c 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -115,6 +115,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -4263,7 +4264,7 @@ public class DevicePolicyManager { * {@link #WIPE_SILENTLY} is set. */ public void wipeData(int flags, @NonNull CharSequence reason) { - Preconditions.checkNotNull(reason, "reason string is null"); + Objects.requireNonNull(reason, "reason string is null"); Preconditions.checkStringNotEmpty(reason, "reason string is empty"); Preconditions.checkArgument((flags & WIPE_SILENTLY) == 0, "WIPE_SILENTLY cannot be set"); wipeDataInternal(flags, reason.toString()); @@ -10430,8 +10431,8 @@ public class DevicePolicyManager { @NonNull String packageName, @NonNull @CallbackExecutor Executor executor, @NonNull OnClearApplicationUserDataListener listener) { throwIfParentInstance("clearAppData"); - Preconditions.checkNotNull(executor); - Preconditions.checkNotNull(listener); + Objects.requireNonNull(executor); + Objects.requireNonNull(listener); try { mService.clearApplicationUserData(admin, packageName, new IPackageDataObserver.Stub() { @@ -10881,7 +10882,7 @@ public class DevicePolicyManager { @WorkerThread public @PrivateDnsModeErrorCodes int setGlobalPrivateDnsModeSpecifiedHost( @NonNull ComponentName admin, @NonNull String privateDnsHost) { throwIfParentInstance("setGlobalPrivateDnsModeSpecifiedHost"); - Preconditions.checkNotNull(privateDnsHost, "dns resolver is null"); + Objects.requireNonNull(privateDnsHost, "dns resolver is null"); if (mService == null) { return PRIVATE_DNS_SET_ERROR_FAILURE_SETTING; diff --git a/core/java/android/app/assist/AssistStructure.java b/core/java/android/app/assist/AssistStructure.java index 80c5b17cad23..22d8c87e9268 100644 --- a/core/java/android/app/assist/AssistStructure.java +++ b/core/java/android/app/assist/AssistStructure.java @@ -41,6 +41,7 @@ import com.android.internal.util.Preconditions; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * <p>This API automatically creates assist data from the platform's @@ -1889,7 +1890,7 @@ public class AssistStructure implements Parcelable { @Override public void setTextIdEntry(@NonNull String entryName) { - mNode.mTextIdEntry = Preconditions.checkNotNull(entryName); + mNode.mTextIdEntry = Objects.requireNonNull(entryName); } @Override @@ -1899,7 +1900,7 @@ public class AssistStructure implements Parcelable { @Override public void setHintIdEntry(@NonNull String entryName) { - mNode.mHintIdEntry = Preconditions.checkNotNull(entryName); + mNode.mHintIdEntry = Objects.requireNonNull(entryName); } @Override diff --git a/core/java/android/app/prediction/AppPredictionManager.java b/core/java/android/app/prediction/AppPredictionManager.java index cb5b7e7763d9..ca22721622b7 100644 --- a/core/java/android/app/prediction/AppPredictionManager.java +++ b/core/java/android/app/prediction/AppPredictionManager.java @@ -20,7 +20,7 @@ import android.annotation.SystemApi; import android.annotation.TestApi; import android.content.Context; -import com.android.internal.util.Preconditions; +import java.util.Objects; /** * Class that provides methods to create prediction clients. @@ -37,7 +37,7 @@ public final class AppPredictionManager { * @hide */ public AppPredictionManager(Context context) { - mContext = Preconditions.checkNotNull(context); + mContext = Objects.requireNonNull(context); } /** diff --git a/core/java/android/app/prediction/AppTarget.java b/core/java/android/app/prediction/AppTarget.java index 6f2149007b8d..14e32b8397a8 100644 --- a/core/java/android/app/prediction/AppTarget.java +++ b/core/java/android/app/prediction/AppTarget.java @@ -25,7 +25,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; -import com.android.internal.util.Preconditions; +import java.util.Objects; /** * A representation of a launchable target. @@ -55,9 +55,9 @@ public final class AppTarget implements Parcelable { mId = id; mShortcutInfo = null; - mPackageName = Preconditions.checkNotNull(packageName); + mPackageName = Objects.requireNonNull(packageName); mClassName = className; - mUser = Preconditions.checkNotNull(user); + mUser = Objects.requireNonNull(user); mRank = 0; } @@ -69,7 +69,7 @@ public final class AppTarget implements Parcelable { public AppTarget(@NonNull AppTargetId id, @NonNull ShortcutInfo shortcutInfo, @Nullable String className) { mId = id; - mShortcutInfo = Preconditions.checkNotNull(shortcutInfo); + mShortcutInfo = Objects.requireNonNull(shortcutInfo); mPackageName = mShortcutInfo.getPackage(); mUser = mShortcutInfo.getUserHandle(); @@ -224,9 +224,9 @@ public final class AppTarget implements Parcelable { @TestApi public Builder(@NonNull AppTargetId id, @NonNull String packageName, @NonNull UserHandle user) { - mId = Preconditions.checkNotNull(id); - mPackageName = Preconditions.checkNotNull(packageName); - mUser = Preconditions.checkNotNull(user); + mId = Objects.requireNonNull(id); + mPackageName = Objects.requireNonNull(packageName); + mUser = Objects.requireNonNull(user); } /** @@ -237,8 +237,8 @@ public final class AppTarget implements Parcelable { @SystemApi @TestApi public Builder(@NonNull AppTargetId id, @NonNull ShortcutInfo info) { - mId = Preconditions.checkNotNull(id); - mShortcutInfo = Preconditions.checkNotNull(info); + mId = Objects.requireNonNull(id); + mShortcutInfo = Objects.requireNonNull(info); mPackageName = info.getPackage(); mUser = info.getUserHandle(); } @@ -253,8 +253,8 @@ public final class AppTarget implements Parcelable { if (mPackageName != null) { throw new IllegalArgumentException("Target is already set"); } - mPackageName = Preconditions.checkNotNull(packageName); - mUser = Preconditions.checkNotNull(user); + mPackageName = Objects.requireNonNull(packageName); + mUser = Objects.requireNonNull(user); return this; } @@ -266,7 +266,7 @@ public final class AppTarget implements Parcelable { @Deprecated public Builder setTarget(@NonNull ShortcutInfo info) { setTarget(info.getPackage(), info.getUserHandle()); - mShortcutInfo = Preconditions.checkNotNull(info); + mShortcutInfo = Objects.requireNonNull(info); return this; } @@ -275,7 +275,7 @@ public final class AppTarget implements Parcelable { */ @NonNull public Builder setClassName(@NonNull String className) { - mClassName = Preconditions.checkNotNull(className); + mClassName = Objects.requireNonNull(className); return this; } diff --git a/core/java/android/app/slice/Slice.java b/core/java/android/app/slice/Slice.java index a7319f6a584f..823fdd26db1e 100644 --- a/core/java/android/app/slice/Slice.java +++ b/core/java/android/app/slice/Slice.java @@ -28,7 +28,6 @@ import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.ArrayUtils; -import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -428,7 +427,7 @@ public final class Slice implements Parcelable { * @see SliceItem#getSubType() */ public Builder addSubSlice(@NonNull Slice slice, @Nullable @SliceSubtype String subType) { - Preconditions.checkNotNull(slice); + Objects.requireNonNull(slice); mItems.add(new SliceItem(slice, SliceItem.FORMAT_SLICE, subType, slice.getHints().toArray(new String[slice.getHints().size()]))); return this; @@ -441,8 +440,8 @@ public final class Slice implements Parcelable { */ public Slice.Builder addAction(@NonNull PendingIntent action, @NonNull Slice s, @Nullable @SliceSubtype String subType) { - Preconditions.checkNotNull(action); - Preconditions.checkNotNull(s); + Objects.requireNonNull(action); + Objects.requireNonNull(s); List<String> hints = s.getHints(); s.mSpec = null; mItems.add(new SliceItem(action, s, SliceItem.FORMAT_ACTION, subType, hints.toArray( @@ -468,7 +467,7 @@ public final class Slice implements Parcelable { */ public Builder addIcon(Icon icon, @Nullable @SliceSubtype String subType, @SliceHint List<String> hints) { - Preconditions.checkNotNull(icon); + Objects.requireNonNull(icon); mItems.add(new SliceItem(icon, SliceItem.FORMAT_IMAGE, subType, hints)); return this; } @@ -481,7 +480,7 @@ public final class Slice implements Parcelable { public Slice.Builder addRemoteInput(RemoteInput remoteInput, @Nullable @SliceSubtype String subType, @SliceHint List<String> hints) { - Preconditions.checkNotNull(remoteInput); + Objects.requireNonNull(remoteInput); mItems.add(new SliceItem(remoteInput, SliceItem.FORMAT_REMOTE_INPUT, subType, hints)); return this; @@ -529,7 +528,7 @@ public final class Slice implements Parcelable { */ public Slice.Builder addBundle(Bundle bundle, @Nullable @SliceSubtype String subType, @SliceHint List<String> hints) { - Preconditions.checkNotNull(bundle); + Objects.requireNonNull(bundle); mItems.add(new SliceItem(bundle, SliceItem.FORMAT_BUNDLE, subType, hints)); return this; diff --git a/core/java/android/app/slice/SliceManager.java b/core/java/android/app/slice/SliceManager.java index 90ecce2a2170..4da1acba3927 100644 --- a/core/java/android/app/slice/SliceManager.java +++ b/core/java/android/app/slice/SliceManager.java @@ -51,6 +51,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; /** @@ -241,7 +242,7 @@ public class SliceManager { * @see Slice */ public @Nullable Slice bindSlice(@NonNull Uri uri, @NonNull Set<SliceSpec> supportedSpecs) { - Preconditions.checkNotNull(uri, "uri"); + Objects.requireNonNull(uri, "uri"); ContentResolver resolver = mContext.getContentResolver(); try (ContentProviderClient provider = resolver.acquireUnstableContentProviderClient(uri)) { if (provider == null) { @@ -336,7 +337,7 @@ public class SliceManager { } private Uri resolveStatic(@NonNull Intent intent, ContentResolver resolver) { - Preconditions.checkNotNull(intent, "intent"); + Objects.requireNonNull(intent, "intent"); Preconditions.checkArgument(intent.getComponent() != null || intent.getPackage() != null || intent.getData() != null, "Slice intent must be explicit %s", intent); @@ -371,7 +372,7 @@ public class SliceManager { */ public @Nullable Slice bindSlice(@NonNull Intent intent, @NonNull Set<SliceSpec> supportedSpecs) { - Preconditions.checkNotNull(intent, "intent"); + Objects.requireNonNull(intent, "intent"); Preconditions.checkArgument(intent.getComponent() != null || intent.getPackage() != null || intent.getData() != null, "Slice intent must be explicit %s", intent); diff --git a/core/java/android/app/usage/NetworkStatsManager.java b/core/java/android/app/usage/NetworkStatsManager.java index 74129702b487..4346d9738ec7 100644 --- a/core/java/android/app/usage/NetworkStatsManager.java +++ b/core/java/android/app/usage/NetworkStatsManager.java @@ -16,8 +16,6 @@ package android.app.usage; -import static com.android.internal.util.Preconditions.checkNotNull; - import android.annotation.Nullable; import android.annotation.SystemService; import android.annotation.TestApi; @@ -42,6 +40,8 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; +import java.util.Objects; + /** * Provides access to network usage history and statistics. Usage data is collected in * discrete bins of time called 'Buckets'. See {@link NetworkStats.Bucket} for details. @@ -418,7 +418,7 @@ public class NetworkStatsManager { /** @hide */ public void registerUsageCallback(NetworkTemplate template, int networkType, long thresholdBytes, UsageCallback callback, @Nullable Handler handler) { - checkNotNull(callback, "UsageCallback cannot be null"); + Objects.requireNonNull(callback, "UsageCallback cannot be null"); final Looper looper; if (handler == null) { diff --git a/core/java/android/app/usage/StorageStatsManager.java b/core/java/android/app/usage/StorageStatsManager.java index eecf0920fd24..1ef15637d578 100644 --- a/core/java/android/app/usage/StorageStatsManager.java +++ b/core/java/android/app/usage/StorageStatsManager.java @@ -63,8 +63,8 @@ public class StorageStatsManager { /** {@hide} */ public StorageStatsManager(Context context, IStorageStatsManager service) { - mContext = Preconditions.checkNotNull(context); - mService = Preconditions.checkNotNull(service); + mContext = Objects.requireNonNull(context); + mService = Objects.requireNonNull(service); } /** {@hide} */ diff --git a/core/java/android/bluetooth/BluetoothHearingAid.java b/core/java/android/bluetooth/BluetoothHearingAid.java index 83eaa728d54c..38498bc147b2 100644 --- a/core/java/android/bluetooth/BluetoothHearingAid.java +++ b/core/java/android/bluetooth/BluetoothHearingAid.java @@ -472,63 +472,6 @@ public final class BluetoothHearingAid implements BluetoothProfile { } /** - * Get the volume of the device. - * - * <p> The volume is between -128 dB (mute) to 0 dB. - * - * @return volume of the hearing aid device. - * @hide - */ - @RequiresPermission(Manifest.permission.BLUETOOTH) - public int getVolume() { - if (VDBG) { - log("getVolume()"); - } - final IBluetoothHearingAid service = getService(); - try { - if (service != null && isEnabled()) { - return service.getVolume(); - } - if (service == null) Log.w(TAG, "Proxy not attached to service"); - return 0; - } catch (RemoteException e) { - Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); - return 0; - } - } - - /** - * Tells remote device to adjust volume. Uses the following values: - * <ul> - * <li>{@link AudioManager#ADJUST_LOWER}</li> - * <li>{@link AudioManager#ADJUST_RAISE}</li> - * <li>{@link AudioManager#ADJUST_MUTE}</li> - * <li>{@link AudioManager#ADJUST_UNMUTE}</li> - * </ul> - * - * @param direction One of the supported adjust values. - * @hide - */ - @RequiresPermission(Manifest.permission.BLUETOOTH) - public void adjustVolume(int direction) { - if (DBG) log("adjustVolume(" + direction + ")"); - - final IBluetoothHearingAid service = getService(); - try { - if (service == null) { - Log.w(TAG, "Proxy not attached to service"); - return; - } - - if (!isEnabled()) return; - - service.adjustVolume(direction); - } catch (RemoteException e) { - Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); - } - } - - /** * Tells remote device to set an absolute volume. * * @param volume Absolute volume to be set on remote diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 47edf2e6fd3a..32803ab8f859 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -202,6 +202,7 @@ public class PackageParser { public static final String TAG_OVERLAY = "overlay"; public static final String TAG_PACKAGE = "package"; public static final String TAG_PACKAGE_VERIFIER = "package-verifier"; + public static final String TAG_FEATURE = "feature"; public static final String TAG_PERMISSION = "permission"; public static final String TAG_PERMISSION_GROUP = "permission-group"; public static final String TAG_PERMISSION_TREE = "permission-tree"; diff --git a/core/java/android/content/pm/VersionedPackage.java b/core/java/android/content/pm/VersionedPackage.java index 3e22eb21d369..21df7ecef015 100644 --- a/core/java/android/content/pm/VersionedPackage.java +++ b/core/java/android/content/pm/VersionedPackage.java @@ -96,6 +96,20 @@ public final class VersionedPackage implements Parcelable { } @Override + public boolean equals(Object o) { + return o instanceof VersionedPackage + && ((VersionedPackage) o).mPackageName.equals(mPackageName) + && ((VersionedPackage) o).mVersionCode == mVersionCode; + } + + @Override + public int hashCode() { + // Roll our own hash function without using Objects#hash which incurs the overhead + // of autoboxing. + return 31 * mPackageName.hashCode() + Long.hashCode(mVersionCode); + } + + @Override public int describeContents() { return 0; } diff --git a/core/java/android/content/pm/parsing/AndroidPackage.java b/core/java/android/content/pm/parsing/AndroidPackage.java index 0562dffc551e..990c8359e698 100644 --- a/core/java/android/content/pm/parsing/AndroidPackage.java +++ b/core/java/android/content/pm/parsing/AndroidPackage.java @@ -27,6 +27,7 @@ import android.content.pm.PackageUserState; import android.content.pm.SharedLibraryInfo; import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup; @@ -245,6 +246,9 @@ public interface AndroidPackage extends Parcelable { List<ParsedInstrumentation> getInstrumentations(); @Nullable + List<ParsedFeature> getFeatures(); + + @Nullable List<ParsedPermissionGroup> getPermissionGroups(); @Nullable diff --git a/core/java/android/content/pm/parsing/ApkParseUtils.java b/core/java/android/content/pm/parsing/ApkParseUtils.java index 3f2296729891..a001ada8df4a 100644 --- a/core/java/android/content/pm/parsing/ApkParseUtils.java +++ b/core/java/android/content/pm/parsing/ApkParseUtils.java @@ -793,6 +793,10 @@ public class ApkParseUtils { parseResult = parseKeySets(parseInput, parsingPackage, res, parser); success = parseResult.isSuccess(); break; + case PackageParser.TAG_FEATURE: + parseResult = parseFeature(parseInput, parsingPackage, res, parser); + success = parseResult.isSuccess(); + break; case PackageParser.TAG_PERMISSION_GROUP: parseResult = parsePermissionGroup(parseInput, parsingPackage, res, parser); @@ -880,6 +884,13 @@ public class ApkParseUtils { ); } + if (!ComponentParseUtils.ParsedFeature.isCombinationValid(parsingPackage.getFeatures())) { + return parseInput.error( + INSTALL_PARSE_FAILED_BAD_MANIFEST, + "Combination <feature> tags are not valid" + ); + } + convertNewPermissions(parsingPackage); convertSplitPermissions(parsingPackage); @@ -1260,6 +1271,31 @@ public class ApkParseUtils { return parseInput.success(parsingPackage); } + private static ParseResult parseFeature( + ParseInput parseInput, + ParsingPackage parsingPackage, + Resources res, + XmlResourceParser parser + ) throws IOException, XmlPullParserException { + // TODO(b/135203078): Remove, replace with ParseResult + String[] outError = new String[1]; + + ComponentParseUtils.ParsedFeature parsedFeature = + ComponentParseUtils.parseFeature(res, parser, outError); + + if (parsedFeature == null || outError[0] != null) { + return parseInput.error( + PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, + outError[0] + ); + } + + parsingPackage.addFeature(parsedFeature); + + return parseInput.success(parsingPackage); + } + + private static ParseResult parsePermissionGroup( ParseInput parseInput, ParsingPackage parsingPackage, diff --git a/core/java/android/content/pm/parsing/ComponentParseUtils.java b/core/java/android/content/pm/parsing/ComponentParseUtils.java index fc210b266040..7b24d3df92a2 100644 --- a/core/java/android/content/pm/parsing/ComponentParseUtils.java +++ b/core/java/android/content/pm/parsing/ComponentParseUtils.java @@ -24,6 +24,9 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_UNSPECIFIED; import android.annotation.CallSuper; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.StringRes; import android.annotation.UnsupportedAppUsage; import android.app.ActivityTaskManager; import android.content.ComponentName; @@ -47,6 +50,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.PatternMatcher; import android.text.TextUtils; +import android.util.ArraySet; import android.util.AttributeSet; import android.util.Log; import android.util.Slog; @@ -54,6 +58,7 @@ import android.util.TypedValue; import android.view.Gravity; import com.android.internal.R; +import com.android.internal.util.DataClass; import com.android.internal.util.XmlUtils; import org.xmlpull.v1.XmlPullParser; @@ -62,6 +67,7 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.lang.reflect.Constructor; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -931,6 +937,186 @@ public class ComponentParseUtils { }; } + /** + * A {@link android.R.styleable#AndroidManifestFeature <feature>} tag parsed from the + * manifest. + */ + // @DataClass verifier is broken, hence comment out for now + public static class ParsedFeature implements Parcelable { + /** Maximum length of featureId */ + public static final int MAX_FEATURE_ID_LEN = 50; + + /** Maximum amount of features per package */ + private static final int MAX_NUM_FEATURES = 1000; + + /** Id of the feature */ + public final @NonNull String id; + + /** User visible label fo the feature */ + public final @StringRes int label; + + /** Ids of previously declared features this feature inherits from */ + public final @NonNull List<String> inheritFrom; + + /** + * @return Is this set of features a valid combination for a single package? + */ + public static boolean isCombinationValid(@Nullable List<ParsedFeature> features) { + if (features == null) { + return true; + } + + ArraySet<String> featureIds = new ArraySet<>(features.size()); + ArraySet<String> inheritFromFeatureIds = new ArraySet<>(); + + int numFeatures = features.size(); + if (numFeatures > MAX_NUM_FEATURES) { + return false; + } + + for (int featureNum = 0; featureNum < numFeatures; featureNum++) { + boolean wasAdded = featureIds.add(features.get(featureNum).id); + if (!wasAdded) { + // feature id is not unique + return false; + } + } + + for (int featureNum = 0; featureNum < numFeatures; featureNum++) { + ParsedFeature feature = features.get(featureNum); + + int numInheritFrom = feature.inheritFrom.size(); + for (int inheritFromNum = 0; inheritFromNum < numInheritFrom; inheritFromNum++) { + String inheritFrom = feature.inheritFrom.get(inheritFromNum); + + if (featureIds.contains(inheritFrom)) { + // Cannot inherit from a feature that is still defined + return false; + } + + boolean wasAdded = inheritFromFeatureIds.add(inheritFrom); + if (!wasAdded) { + // inheritFrom is not unique + return false; + } + } + } + + return true; + } + + + + // Code below generated by codegen v1.0.14. + // + // DO NOT MODIFY! + // CHECKSTYLE:OFF Generated code + // + // To regenerate run: + // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/ComponentParseUtils.java + // + // To exclude the generated code from IntelliJ auto-formatting enable (one-time): + // Settings > Editor > Code Style > Formatter Control + //@formatter:off + + + /** + * Creates a new ParsedFeature. + * + * @param id + * Id of the feature + * @param label + * User visible label fo the feature (if defined as resource) + * @param inheritFrom + * Ids of previously declared features this feature inherits from + */ + @DataClass.Generated.Member + public ParsedFeature( + @NonNull String id, + @StringRes int label, + @NonNull List<String> inheritFrom) { + this.id = id; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, id); + this.label = label; + com.android.internal.util.AnnotationValidations.validate( + StringRes.class, null, label); + this.inheritFrom = inheritFrom; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, inheritFrom); + + // onConstructed(); // You can define this method to get a callback + } + + @Override + @DataClass.Generated.Member + public void writeToParcel(@NonNull Parcel dest, int flags) { + // You can override field parcelling by defining methods like: + // void parcelFieldName(Parcel dest, int flags) { ... } + + dest.writeString(id); + dest.writeInt(label); + dest.writeStringList(inheritFrom); + } + + @Override + @DataClass.Generated.Member + public int describeContents() { return 0; } + + /** @hide */ + @SuppressWarnings({"unchecked", "RedundantCast"}) + @DataClass.Generated.Member + protected ParsedFeature(@NonNull Parcel in) { + // You can override field unparcelling by defining methods like: + // static FieldType unparcelFieldName(Parcel in) { ... } + + String _id = in.readString(); + int _label = in.readInt(); + List<String> _inheritFrom = new ArrayList<>(); + in.readStringList(_inheritFrom); + + this.id = _id; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, id); + this.label = _label; + com.android.internal.util.AnnotationValidations.validate( + StringRes.class, null, label); + this.inheritFrom = _inheritFrom; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, inheritFrom); + + // onConstructed(); // You can define this method to get a callback + } + + @DataClass.Generated.Member + public static final @NonNull Parcelable.Creator<ParsedFeature> CREATOR + = new Parcelable.Creator<ParsedFeature>() { + @Override + public ParsedFeature[] newArray(int size) { + return new ParsedFeature[size]; + } + + @Override + public ParsedFeature createFromParcel(@NonNull Parcel in) { + return new ParsedFeature(in); + } + }; + + /*@DataClass.Generated( + time = 1576783172965L, + codegenVersion = "1.0.14", + sourceFile = "frameworks/base/core/java/android/content/pm/parsing/ComponentParseUtils.java", + inputSignatures = "public final @android.annotation.NonNull java.lang.String id\npublic final @android.annotation.StringRes int label\npublic final @android.annotation.NonNull java.util.List<java.lang.String> inheritFrom\npublic static boolean isCombinationValid(java.util.List<android.content.pm.parsing.ParsedFeature>)\nclass ParsedFeature extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass") + */ + @Deprecated + private void __metadata() {} + + + //@formatter:on + // End of generated code + + } + public static class ParsedPermission extends ParsedComponent<ParsedIntentInfo> { public String backgroundPermission; @@ -2566,6 +2752,85 @@ public class ComponentParseUtils { return result; } + public static ParsedFeature parseFeature( + Resources res, + XmlResourceParser parser, + String[] outError + ) throws IOException, XmlPullParserException { + String featureId; + int label; + List<String> inheritFrom = null; + + TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestFeature); + if (sa == null) { + outError[0] = "<feature> could not be parsed"; + return null; + } + + try { + featureId = sa.getNonConfigurationString(R.styleable.AndroidManifestFeature_featureId, + 0); + if (featureId == null) { + outError[0] = "<featureId> does not specify android:featureId"; + return null; + } + if (featureId.length() > ParsedFeature.MAX_FEATURE_ID_LEN) { + outError[0] = "<featureId> is too long. Max length is " + + ParsedFeature.MAX_FEATURE_ID_LEN; + return null; + } + + label = sa.getResourceId(R.styleable.AndroidManifestFeature_label, 0); + if (label == Resources.ID_NULL) { + outError[0] = "<featureId> does not specify android:label"; + return null; + } + } finally { + sa.recycle(); + } + + int type; + final int innerDepth = parser.getDepth(); + while ((type = parser.next()) != XmlPullParser.END_DOCUMENT + && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { + if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { + continue; + } + + String tagName = parser.getName(); + if (tagName.equals("inherit-from")) { + sa = res.obtainAttributes(parser, R.styleable.AndroidManifestFeatureInheritFrom); + if (sa == null) { + outError[0] = "<inherit-from> could not be parsed"; + return null; + } + + try { + String inheritFromId = sa.getNonConfigurationString( + R.styleable.AndroidManifestFeatureInheritFrom_featureId,0); + + if (inheritFrom == null) { + inheritFrom = new ArrayList<>(); + } + inheritFrom.add(inheritFromId); + } finally { + sa.recycle(); + } + } else { + outError[0] = "Bad element under <feature>: " + tagName; + return null; + } + } + + if (inheritFrom == null) { + inheritFrom = Collections.emptyList(); + } else { + ((ArrayList) inheritFrom).trimToSize(); + } + + return new ParsedFeature(featureId, label, inheritFrom); + } + public static ParsedPermission parsePermission( ParsingPackage parsingPackage, Resources res, diff --git a/core/java/android/content/pm/parsing/PackageImpl.java b/core/java/android/content/pm/parsing/PackageImpl.java index 18dee23dc690..8677fced18fa 100644 --- a/core/java/android/content/pm/parsing/PackageImpl.java +++ b/core/java/android/content/pm/parsing/PackageImpl.java @@ -36,6 +36,7 @@ import android.content.pm.ServiceInfo; import android.content.pm.SharedLibraryInfo; import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; import android.content.pm.parsing.ComponentParseUtils.ParsedIntentInfo; import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; @@ -175,6 +176,9 @@ public final class PackageImpl implements ParsingPackage, ParsedPackage, Android private ArrayList<ComponentParseUtils.ParsedProvider> providers; @Nullable + private ArrayList<ComponentParseUtils.ParsedFeature> features; + + @Nullable private ArrayList<ComponentParseUtils.ParsedPermission> permissions; @Nullable @@ -580,6 +584,12 @@ public final class PackageImpl implements ParsingPackage, ParsedPackage, Android return permissions; } + @Nullable + @Override + public List<ParsedFeature> getFeatures() { + return features; + } + @Override public String getCpuAbiOverride() { return cpuAbiOverride; @@ -792,6 +802,12 @@ public final class PackageImpl implements ParsingPackage, ParsedPackage, Android } @Override + public PackageImpl addFeature(ParsedFeature feature) { + this.features = ArrayUtils.add(this.features, feature); + return this; + } + + @Override public PackageImpl addPermission(ParsedPermission permission) { this.permissions = ArrayUtils.add(this.permissions, permission); return this; @@ -3021,6 +3037,7 @@ public final class PackageImpl implements ParsingPackage, ParsedPackage, Android dest.writeTypedList(this.receivers); dest.writeTypedList(this.services); dest.writeTypedList(this.providers); + dest.writeTypedList(this.features); dest.writeTypedList(this.permissions); dest.writeTypedList(this.permissionGroups); dest.writeTypedList(this.instrumentations); @@ -3173,6 +3190,7 @@ public final class PackageImpl implements ParsingPackage, ParsedPackage, Android this.receivers = in.createTypedArrayList(ParsedActivity.CREATOR); this.services = in.createTypedArrayList(ParsedService.CREATOR); this.providers = in.createTypedArrayList(ParsedProvider.CREATOR); + this.features = in.createTypedArrayList(ParsedFeature.CREATOR); this.permissions = in.createTypedArrayList(ParsedPermission.CREATOR); this.permissionGroups = in.createTypedArrayList(ParsedPermissionGroup.CREATOR); this.instrumentations = in.createTypedArrayList(ParsedInstrumentation.CREATOR); diff --git a/core/java/android/content/pm/parsing/ParsingPackage.java b/core/java/android/content/pm/parsing/ParsingPackage.java index 47dac5584c89..411c74991594 100644 --- a/core/java/android/content/pm/parsing/ParsingPackage.java +++ b/core/java/android/content/pm/parsing/ParsingPackage.java @@ -24,6 +24,7 @@ import android.content.pm.FeatureInfo; import android.content.pm.PackageParser; import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup; @@ -64,6 +65,8 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage addOverlayable(String overlayableName, String actorName); + ParsingPackage addFeature(ParsedFeature permission); + ParsingPackage addPermission(ParsedPermission permission); ParsingPackage addPermissionGroup(ParsedPermissionGroup permissionGroup); diff --git a/core/java/android/content/rollback/PackageRollbackInfo.java b/core/java/android/content/rollback/PackageRollbackInfo.java index c89796d4b1da..6378db0ebbbd 100644 --- a/core/java/android/content/rollback/PackageRollbackInfo.java +++ b/core/java/android/content/rollback/PackageRollbackInfo.java @@ -19,6 +19,7 @@ package android.content.rollback; import android.annotation.NonNull; import android.annotation.SystemApi; import android.annotation.TestApi; +import android.content.pm.PackageManager; import android.content.pm.VersionedPackage; import android.os.Parcel; import android.os.Parcelable; @@ -88,6 +89,11 @@ public final class PackageRollbackInfo implements Parcelable { private final SparseLongArray mCeSnapshotInodes; /** + * The userdata policy to execute when a rollback for this package is committed. + */ + private final int mRollbackDataPolicy; + + /** * Returns the name of the package to roll back from. */ @NonNull @@ -148,6 +154,11 @@ public final class PackageRollbackInfo implements Parcelable { } /** @hide */ + public @PackageManager.RollbackDataPolicy int getRollbackDataPolicy() { + return mRollbackDataPolicy; + } + + /** @hide */ public IntArray getSnapshottedUsers() { return mSnapshottedUsers; } @@ -181,11 +192,23 @@ public final class PackageRollbackInfo implements Parcelable { @NonNull IntArray pendingBackups, @NonNull ArrayList<RestoreInfo> pendingRestores, boolean isApex, @NonNull IntArray snapshottedUsers, @NonNull SparseLongArray ceSnapshotInodes) { + this(packageRolledBackFrom, packageRolledBackTo, pendingBackups, pendingRestores, isApex, + snapshottedUsers, ceSnapshotInodes, PackageManager.RollbackDataPolicy.RESTORE); + } + + /** @hide */ + public PackageRollbackInfo(VersionedPackage packageRolledBackFrom, + VersionedPackage packageRolledBackTo, + @NonNull IntArray pendingBackups, @NonNull ArrayList<RestoreInfo> pendingRestores, + boolean isApex, @NonNull IntArray snapshottedUsers, + @NonNull SparseLongArray ceSnapshotInodes, + @PackageManager.RollbackDataPolicy int rollbackDataPolicy) { this.mVersionRolledBackFrom = packageRolledBackFrom; this.mVersionRolledBackTo = packageRolledBackTo; this.mPendingBackups = pendingBackups; this.mPendingRestores = pendingRestores; this.mIsApex = isApex; + this.mRollbackDataPolicy = rollbackDataPolicy; this.mSnapshottedUsers = snapshottedUsers; this.mCeSnapshotInodes = ceSnapshotInodes; } @@ -198,6 +221,7 @@ public final class PackageRollbackInfo implements Parcelable { this.mPendingBackups = null; this.mSnapshottedUsers = null; this.mCeSnapshotInodes = null; + this.mRollbackDataPolicy = PackageManager.RollbackDataPolicy.RESTORE; } @Override diff --git a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java index c3ebe434ca05..6f90db424847 100644 --- a/core/java/android/hardware/camera2/impl/CameraMetadataNative.java +++ b/core/java/android/hardware/camera2/impl/CameraMetadataNative.java @@ -240,6 +240,11 @@ public class CameraMetadataNative implements Parcelable { * * <p>This value is looked up the first time, and cached subsequently.</p> * + * <p>This function may be called without cacheTag() if this is not a vendor key. + * If this is a vendor key, cacheTag() must be called first before getTag() can + * be called. Otherwise, mVendorId could be default (Long.MAX_VALUE) and vendor + * tag lookup could fail.</p> + * * @return The tag numeric value corresponding to the string */ @UnsupportedAppUsage @@ -252,6 +257,27 @@ public class CameraMetadataNative implements Parcelable { } /** + * Whether this key's tag is cached. + * + * @hide + */ + @UnsupportedAppUsage + public final boolean hasTag() { + return mHasTag; + } + + /** + * Cache this key's tag. + * + * @hide + */ + @UnsupportedAppUsage + public final void cacheTag(int tag) { + mHasTag = true; + mTag = tag; + } + + /** * Get the raw class backing the type {@code T} for this key. * * <p>The distinction is only important if {@code T} is a generic, e.g. @@ -523,7 +549,13 @@ public class CameraMetadataNative implements Parcelable { } private <T> T getBase(Key<T> key) { - int tag = nativeGetTagFromKeyLocal(key.getName()); + int tag; + if (key.hasTag()) { + tag = key.getTag(); + } else { + tag = nativeGetTagFromKeyLocal(key.getName()); + key.cacheTag(tag); + } byte[] values = readValues(tag); if (values == null) { // If the key returns null, use the fallback key if exists. @@ -1451,7 +1483,13 @@ public class CameraMetadataNative implements Parcelable { } private <T> void setBase(Key<T> key, T value) { - int tag = nativeGetTagFromKeyLocal(key.getName()); + int tag; + if (key.hasTag()) { + tag = key.getTag(); + } else { + tag = nativeGetTagFromKeyLocal(key.getName()); + key.cacheTag(tag); + } if (value == null) { // Erase the entry writeValues(tag, /*src*/null); diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index 1c4ef382ca34..3d449446af82 100644 --- a/core/java/android/os/Debug.java +++ b/core/java/android/os/Debug.java @@ -2590,4 +2590,12 @@ public final class Debug * @hide */ public static native long getIonMappedSizeKb(); + + /** + * Return whether virtually-mapped kernel stacks are enabled (CONFIG_VMAP_STACK). + * Note: caller needs config_gz read sepolicy permission + * + * @hide + */ + public static native boolean isVmapStack(); } diff --git a/core/java/android/service/controls/ControlsProviderService.java b/core/java/android/service/controls/ControlsProviderService.java index 258ef23c64cf..eca8541c9d33 100644 --- a/core/java/android/service/controls/ControlsProviderService.java +++ b/core/java/android/service/controls/ControlsProviderService.java @@ -20,7 +20,6 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.app.Service; import android.content.Intent; -import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -88,7 +87,7 @@ public abstract class ControlsProviderService extends Service { * {@link Control.StatelessBuilder}). * @param controls */ - public void onLoad(@NonNull List<Control> controls) { + public final void onLoad(@NonNull List<Control> controls) { Preconditions.checkNotNull(controls); List<Control> list = new ArrayList<>(); for (Control control: controls) { @@ -114,7 +113,7 @@ public abstract class ControlsProviderService extends Service { * their state. * @param statefulControls */ - public void onRefreshState(@NonNull List<Control> statefulControls) { + public final void onRefreshState(@NonNull List<Control> statefulControls) { Preconditions.checkNotNull(statefulControls); try { mCallback.onRefreshState(mToken, statefulControls); @@ -128,7 +127,7 @@ public abstract class ControlsProviderService extends Service { * @param controlId * @param response */ - public void onControlActionResponse( + public final void onControlActionResponse( @NonNull String controlId, @ControlAction.ResponseResult int response) { Preconditions.checkNotNull(controlId); if (!ControlAction.isValidResponse(response)) { diff --git a/core/java/android/service/controls/templates/ThermostatTemplate.aidl b/core/java/android/service/controls/templates/TemperatureControlTemplate.aidl index 1fefda42d284..7994d2651610 100644 --- a/core/java/android/service/controls/templates/ThermostatTemplate.aidl +++ b/core/java/android/service/controls/templates/TemperatureControlTemplate.aidl @@ -16,4 +16,4 @@ package android.service.controls.templates; -parcelable ThermostatTemplate;
\ No newline at end of file +parcelable TemperatureControlTemplate;
\ No newline at end of file diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 3b6a00948463..f6aaa6f1a461 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -139,6 +139,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Helper class used by TextView to handle editable text views. @@ -7062,11 +7063,11 @@ public class Editor { private final List<ResolveInfo> mSupportedActivities = new ArrayList<>(); private ProcessTextIntentActionsHandler(Editor editor) { - mEditor = Preconditions.checkNotNull(editor); - mTextView = Preconditions.checkNotNull(mEditor.mTextView); - mContext = Preconditions.checkNotNull(mTextView.getContext()); - mPackageManager = Preconditions.checkNotNull(mContext.getPackageManager()); - mPackageName = Preconditions.checkNotNull(mContext.getPackageName()); + mEditor = Objects.requireNonNull(editor); + mTextView = Objects.requireNonNull(mEditor.mTextView); + mContext = Objects.requireNonNull(mTextView.getContext()); + mPackageManager = Objects.requireNonNull(mContext.getPackageManager()); + mPackageName = Objects.requireNonNull(mContext.getPackageName()); } /** diff --git a/core/java/android/widget/Magnifier.java b/core/java/android/widget/Magnifier.java index f58b6d192fde..2924dd9bf954 100644 --- a/core/java/android/widget/Magnifier.java +++ b/core/java/android/widget/Magnifier.java @@ -62,6 +62,7 @@ import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Objects; /** * Android magnifier widget. Can be used by any view which is attached to a window. @@ -1154,7 +1155,7 @@ public final class Magnifier { * @param view the view this magnifier is attached to */ public Builder(@NonNull View view) { - mView = Preconditions.checkNotNull(view); + mView = Objects.requireNonNull(view); applyDefaults(); } diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java index d0f80936f477..4ef3f61b5280 100644 --- a/core/java/android/widget/SelectionActionModeHelper.java +++ b/core/java/android/widget/SelectionActionModeHelper.java @@ -87,7 +87,7 @@ public final class SelectionActionModeHelper { private final SmartSelectSprite mSmartSelectSprite; SelectionActionModeHelper(@NonNull Editor editor) { - mEditor = Preconditions.checkNotNull(editor); + mEditor = Objects.requireNonNull(editor); mTextView = mEditor.getTextView(); mTextClassificationHelper = new TextClassificationHelper( mTextView.getContext(), @@ -500,7 +500,7 @@ public final class SelectionActionModeHelper { private final LogAbandonRunnable mDelayedLogAbandon = new LogAbandonRunnable(); SelectionTracker(TextView textView) { - mTextView = Preconditions.checkNotNull(textView); + mTextView = Objects.requireNonNull(textView); mLogger = new SelectionMetricsLogger(textView); } @@ -703,7 +703,7 @@ public final class SelectionActionModeHelper { private String mText; SelectionMetricsLogger(TextView textView) { - Preconditions.checkNotNull(textView); + Objects.requireNonNull(textView); mEditTextLogger = textView.isTextEditable(); mTokenIterator = SelectionSessionLogger.getTokenIterator(textView.getTextLocale()); } @@ -714,7 +714,7 @@ public final class SelectionActionModeHelper { CharSequence text, int index, @InvocationMethod int invocationMethod) { try { - Preconditions.checkNotNull(text); + Objects.requireNonNull(text); Preconditions.checkArgumentInRange(index, 0, text.length(), "index"); if (mText == null || !mText.contentEquals(text)) { mText = text.toString(); @@ -972,11 +972,11 @@ public final class SelectionActionModeHelper { @NonNull Consumer<SelectionResult> selectionResultCallback, @NonNull Supplier<SelectionResult> timeOutResultSupplier) { super(textView != null ? textView.getHandler() : null); - mTextView = Preconditions.checkNotNull(textView); + mTextView = Objects.requireNonNull(textView); mTimeOutDuration = timeOut; - mSelectionResultSupplier = Preconditions.checkNotNull(selectionResultSupplier); - mSelectionResultCallback = Preconditions.checkNotNull(selectionResultCallback); - mTimeOutResultSupplier = Preconditions.checkNotNull(timeOutResultSupplier); + mSelectionResultSupplier = Objects.requireNonNull(selectionResultSupplier); + mSelectionResultCallback = Objects.requireNonNull(selectionResultCallback); + mTimeOutResultSupplier = Objects.requireNonNull(timeOutResultSupplier); // Make a copy of the original text. mOriginalText = getText(mTextView).toString(); } @@ -1051,14 +1051,14 @@ public final class SelectionActionModeHelper { TextClassificationHelper(Context context, Supplier<TextClassifier> textClassifier, CharSequence text, int selectionStart, int selectionEnd, LocaleList locales) { init(textClassifier, text, selectionStart, selectionEnd, locales); - mContext = Preconditions.checkNotNull(context); + mContext = Objects.requireNonNull(context); } @UiThread public void init(Supplier<TextClassifier> textClassifier, CharSequence text, int selectionStart, int selectionEnd, LocaleList locales) { - mTextClassifier = Preconditions.checkNotNull(textClassifier); - mText = Preconditions.checkNotNull(text).toString(); + mTextClassifier = Objects.requireNonNull(textClassifier); + mText = Objects.requireNonNull(text).toString(); mLastClassificationText = null; // invalidate. Preconditions.checkArgument(selectionEnd > selectionStart); mSelectionStart = selectionStart; diff --git a/core/java/android/widget/SmartSelectSprite.java b/core/java/android/widget/SmartSelectSprite.java index 9a84f69d120a..dc472e1bbd82 100644 --- a/core/java/android/widget/SmartSelectSprite.java +++ b/core/java/android/widget/SmartSelectSprite.java @@ -38,13 +38,12 @@ import android.text.Layout; import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; -import com.android.internal.util.Preconditions; - import java.lang.annotation.Retention; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Objects; /** * A utility class for creating and animating the Smart Select animation. @@ -75,7 +74,7 @@ final class SmartSelectSprite { private final int mTextSelectionLayout; RectangleWithTextSelectionLayout(RectF rectangle, int textSelectionLayout) { - mRectangle = Preconditions.checkNotNull(rectangle); + mRectangle = Objects.requireNonNull(rectangle); mTextSelectionLayout = textSelectionLayout; } @@ -342,7 +341,7 @@ final class SmartSelectSprite { context, android.R.interpolator.fast_out_linear_in); mFillColor = highlightColor; - mInvalidator = Preconditions.checkNotNull(invalidator); + mInvalidator = Objects.requireNonNull(invalidator); } /** diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index a4cd4f12cfe1..8d3c572024e5 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -353,7 +353,11 @@ public class ResolverActivity extends Activity implements finish(); } }); - if (isVoiceInteraction()) { + + boolean hasTouchScreen = getPackageManager() + .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN); + + if (isVoiceInteraction() || !hasTouchScreen) { rdl.setCollapsed(false); } @@ -1301,10 +1305,11 @@ public class ResolverActivity extends Activity implements // In case this method is called again (due to activity recreation), avoid adding a new // header if one is already present. - if (useHeader && listView != null && listView.getHeaderViewsCount() == 0) { + if (useHeader && listView.getHeaderViewsCount() == 0) { listView.setHeaderDividersEnabled(true); listView.addHeaderView(LayoutInflater.from(this).inflate( - R.layout.resolver_different_item_header, listView, false)); + R.layout.resolver_different_item_header, listView, false), + null, false); } } @@ -1367,6 +1372,8 @@ public class ResolverActivity extends Activity implements if (useLayoutWithDefault() && filteredPosition != ListView.INVALID_POSITION) { setAlwaysButtonEnabled(true, filteredPosition, false); mOnceButton.setEnabled(true); + // Focus the button if we already have the default option + mOnceButton.requestFocus(); return; } @@ -1499,6 +1506,7 @@ public class ResolverActivity extends Activity implements mOnceButton.setEnabled(hasValidSelection); if (hasValidSelection) { currentAdapterView.smoothScrollToPosition(checkedPos); + mOnceButton.requestFocus(); } mLastSelected = checkedPos; } else { diff --git a/core/java/com/android/internal/os/ZygoteServer.java b/core/java/com/android/internal/os/ZygoteServer.java index 4a21d37a38fb..8d281b7ce9a0 100644 --- a/core/java/com/android/internal/os/ZygoteServer.java +++ b/core/java/com/android/internal/os/ZygoteServer.java @@ -184,9 +184,8 @@ class ZygoteServer { Zygote.USAP_POOL_SECONDARY_SOCKET_NAME); } - fetchUsapPoolPolicyProps(); - mUsapPoolSupported = true; + fetchUsapPoolPolicyProps(); } void setForkChild() { diff --git a/core/java/com/android/internal/util/MemInfoReader.java b/core/java/com/android/internal/util/MemInfoReader.java index 362bc92e40ad..580c2fa66de2 100644 --- a/core/java/com/android/internal/util/MemInfoReader.java +++ b/core/java/com/android/internal/util/MemInfoReader.java @@ -107,9 +107,12 @@ public final class MemInfoReader { * Amount of RAM that is in use by the kernel for actual allocations. */ public long getKernelUsedSizeKb() { - return mInfos[Debug.MEMINFO_SHMEM] + mInfos[Debug.MEMINFO_SLAB_UNRECLAIMABLE] - + mInfos[Debug.MEMINFO_VM_ALLOC_USED] + mInfos[Debug.MEMINFO_PAGE_TABLES] - + mInfos[Debug.MEMINFO_KERNEL_STACK]; + long size = mInfos[Debug.MEMINFO_SHMEM] + mInfos[Debug.MEMINFO_SLAB_UNRECLAIMABLE] + + mInfos[Debug.MEMINFO_VM_ALLOC_USED] + mInfos[Debug.MEMINFO_PAGE_TABLES]; + if (!Debug.isVmapStack()) { + size += mInfos[Debug.MEMINFO_KERNEL_STACK]; + } + return size; } public long getSwapTotalSizeKb() { diff --git a/core/java/com/android/internal/widget/ResolverDrawerLayout.java b/core/java/com/android/internal/widget/ResolverDrawerLayout.java index 1bb2ba293186..e0c3823b40ef 100644 --- a/core/java/com/android/internal/widget/ResolverDrawerLayout.java +++ b/core/java/com/android/internal/widget/ResolverDrawerLayout.java @@ -187,7 +187,7 @@ public class ResolverDrawerLayout extends ViewGroup { public void setCollapsed(boolean collapsed) { if (!isLaidOut()) { - mOpenOnLayout = collapsed; + mOpenOnLayout = !collapsed; } else { smoothScrollTo(collapsed ? mCollapsibleHeight : 0, 0); } diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index 6e0d5d8f6461..4314eb6efb18 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -50,6 +50,7 @@ #include <memunreachable/memunreachable.h> #include <android-base/strings.h> #include "android_os_Debug.h" +#include <vintf/VintfObject.h> namespace android { @@ -835,6 +836,23 @@ static jlong android_os_Debug_getIonMappedSizeKb(JNIEnv* env, jobject clazz) { return ionPss; } +static jboolean android_os_Debug_isVmapStack(JNIEnv *env, jobject clazz) +{ + static enum { + CONFIG_UNKNOWN, + CONFIG_SET, + CONFIG_UNSET, + } cfg_state = CONFIG_UNKNOWN; + + if (cfg_state == CONFIG_UNKNOWN) { + const std::map<std::string, std::string> configs = + vintf::VintfObject::GetInstance()->getRuntimeInfo()->kernelConfigs(); + std::map<std::string, std::string>::const_iterator it = configs.find("CONFIG_VMAP_STACK"); + cfg_state = (it != configs.end() && it->second == "y") ? CONFIG_SET : CONFIG_UNSET; + } + return cfg_state == CONFIG_SET; +} + /* * JNI registration. */ @@ -884,6 +902,8 @@ static const JNINativeMethod gMethods[] = { (void*)android_os_Debug_getIonPoolsSizeKb }, { "getIonMappedSizeKb", "()J", (void*)android_os_Debug_getIonMappedSizeKb }, + { "isVmapStack", "()Z", + (void*)android_os_Debug_isVmapStack }, }; int register_android_os_Debug(JNIEnv *env) diff --git a/core/res/res/values-ar/strings.xml b/core/res/res/values-ar/strings.xml index eb1f5534fdef..00c0d302f48d 100644 --- a/core/res/res/values-ar/strings.xml +++ b/core/res/res/values-ar/strings.xml @@ -1283,7 +1283,7 @@ <string name="heavy_weight_switcher_text" msgid="6814316627367160126">"للحصول على أداء أفضل، يمكن فتح لعبة واحدة فقط من هذه الألعاب في كل مرة."</string> <string name="old_app_action" msgid="725331621042848590">"الرجوع إلى <xliff:g id="OLD_APP">%1$s</xliff:g>"</string> <string name="new_app_action" msgid="547772182913269801">"فتح <xliff:g id="NEW_APP">%1$s</xliff:g>"</string> - <string name="new_app_description" msgid="1958903080400806644">"سيتم إغلاق <xliff:g id="OLD_APP">%1$s</xliff:g> من دون حفظ"</string> + <string name="new_app_description" msgid="1958903080400806644">"سيتم إغلاق <xliff:g id="OLD_APP">%1$s</xliff:g> بدون حفظ"</string> <string name="dump_heap_notification" msgid="5316644945404825032">"لقد تجاوزت <xliff:g id="PROC">%1$s</xliff:g> حد الذاكرة."</string> <string name="dump_heap_ready_notification" msgid="2302452262927390268">"نَسْخ الذاكرة <xliff:g id="PROC">%1$s</xliff:g> جاهز"</string> <string name="dump_heap_notification_detail" msgid="8431586843001054050">"تم جمع مقدار كبير من بيانات الذاكرة. انقر للمشاركة."</string> diff --git a/core/res/res/values-nb/strings.xml b/core/res/res/values-nb/strings.xml index aa28bf2b9644..3e236798d657 100644 --- a/core/res/res/values-nb/strings.xml +++ b/core/res/res/values-nb/strings.xml @@ -665,7 +665,7 @@ <string name="policydesc_wipeData_secondaryUser" product="tablet" msgid="2336676480090926470">"Sletter denne brukerens data på dette nettbrettet uten advarsel."</string> <string name="policydesc_wipeData_secondaryUser" product="tv" msgid="2293713284515865200">"Tøm dataene til denne brukeren på denne Android TV-enheten uten advarsel."</string> <string name="policydesc_wipeData_secondaryUser" product="default" msgid="2788325512167208654">"Sletter denne brukerens data på denne telefonen uten advarsel."</string> - <string name="policylab_setGlobalProxy" msgid="215332221188670221">"Angi enhetens globale mellomtjener"</string> + <string name="policylab_setGlobalProxy" msgid="215332221188670221">"Angi enhetens globale proxy-tjener"</string> <string name="policydesc_setGlobalProxy" msgid="7149665222705519604">"Angir den globale proxy-tjeneren på enheten som skal brukes når regelen er aktivert. Bare eieren av enheten kan angi den globale proxy-tjeneren."</string> <string name="policylab_expirePassword" msgid="6015404400532459169">"Angi utløpstid for skjermlås"</string> <string name="policydesc_expirePassword" msgid="9136524319325960675">"Endrer hvor ofte PIN-koden, passordet eller mønsteret til skjermlåsen skal byttes."</string> diff --git a/core/res/res/values-sl/strings.xml b/core/res/res/values-sl/strings.xml index be173dd878e5..7aa91f7245ea 100644 --- a/core/res/res/values-sl/strings.xml +++ b/core/res/res/values-sl/strings.xml @@ -497,10 +497,8 @@ <string name="permdesc_bluetooth" product="tablet" msgid="3053222571491402635">"Aplikaciji omogoča ogled konfiguracije Bluetootha tabličnega računalnika ter vzpostavljanje in sprejemanje povezave s seznanjenimi napravami."</string> <string name="permdesc_bluetooth" product="tv" msgid="8851534496561034998">"Aplikaciji dovoljuje ogled konfiguracije vmesnika Bluetooth v napravi Android TV ter ustvarjanje in sprejemanje povezav s seznanjenimi napravami."</string> <string name="permdesc_bluetooth" product="default" msgid="2779606714091276746">"Aplikaciji omogoča ogled konfiguracije Bluetootha telefona ter ustvarjanje in sprejemanje povezave s seznanjenimi napravami."</string> - <!-- no translation found for permlab_preferredPaymentInfo (5274423844767445054) --> - <skip /> - <!-- no translation found for permdesc_preferredPaymentInfo (8583552469807294967) --> - <skip /> + <string name="permlab_preferredPaymentInfo" msgid="5274423844767445054">"Podatki o prednostni storitvi za plačevanje prek povezave NFC"</string> + <string name="permdesc_preferredPaymentInfo" msgid="8583552469807294967">"Aplikaciji omogoča pridobivanje podatkov o prednostni storitvi za plačevanje prek povezave NFC, kot so registrirani pripomočki in cilj preusmeritve."</string> <string name="permlab_nfc" msgid="1904455246837674977">"nadzor nad komunikacijo s tehnologijo bližnjega polja"</string> <string name="permdesc_nfc" msgid="8352737680695296741">"Podpira komunikacijo med računalnikom in oznakami, karticami in bralniki komunikacije s tehnologijo bližnjega polja."</string> <string name="permlab_disableKeyguard" msgid="3605253559020928505">"onemogočanje zaklepanja zaslona"</string> @@ -1663,12 +1661,6 @@ <string name="accessibility_shortcut_enabling_service" msgid="6141620395915529473">"Bližnjica funkcij za ljudi s posebnimi potrebami je vklopila <xliff:g id="SERVICE_NAME">%1$s</xliff:g>"</string> <string name="accessibility_shortcut_disabling_service" msgid="1287340429965172651">"Bližnjica funkcij za ljudi s posebnimi potrebami je izklopila <xliff:g id="SERVICE_NAME">%1$s</xliff:g>"</string> <string name="accessibility_shortcut_spoken_feedback" msgid="4228997042855695090">"Za uporabo storitve <xliff:g id="SERVICE_NAME">%1$s</xliff:g> pritisnite obe tipki za glasnost in ju pridržite tri sekunde"</string> - <string name="accessibility_button_prompt_text" msgid="1634298854002673171">"Izberite storitev, ki jo želite uporabljati, ko se dotaknete gumba za funkcije za ljudi s posebnimi potrebami:"</string> - <string name="accessibility_gesture_prompt_text" msgid="3271927619707898924">"Izberite storitev, ki jo želite zagnati s potezo za ljudi s posebnimi potrebami (vlečenje z dvema prstoma z dna zaslona navzgor):"</string> - <string name="accessibility_gesture_3finger_prompt_text" msgid="218295923313037542">"Izberite storitev, ki jo želite zagnati s potezo za ljudi s posebnimi potrebami (vlečenje s tremi prsti z dna zaslona navzgor):"</string> - <string name="accessibility_button_instructional_text" msgid="8523635009916665153">"Če želite preklopiti med storitvami, pridržite gumb za funkcije za ljudi s posebnimi potrebami."</string> - <string name="accessibility_gesture_instructional_text" msgid="927882482331885974">"Če želite preklopiti med storitvami, z dvema prstoma povlecite navzgor in pridržite."</string> - <string name="accessibility_gesture_3finger_instructional_text" msgid="7527523742771203377">"Če želite preklopiti med storitvami, s tremi prsti povlecite navzgor in pridržite."</string> <string name="accessibility_magnification_chooser_text" msgid="1502075582164931596">"Povečava"</string> <string name="user_switched" msgid="7249833311585228097">"Trenutni uporabnik <xliff:g id="NAME">%1$s</xliff:g>."</string> <string name="user_switching_message" msgid="1912993630661332336">"Preklop na uporabnika <xliff:g id="NAME">%1$s</xliff:g> …"</string> @@ -1927,11 +1919,9 @@ <string name="usb_mtp_launch_notification_title" msgid="774319638256707227">"Vzpostavljena povezava z napravo <xliff:g id="PRODUCT_NAME">%1$s</xliff:g>"</string> <string name="usb_mtp_launch_notification_description" msgid="6942535713629852684">"Dotaknite se, če si želite ogledati datoteke"</string> <string name="pin_target" msgid="8036028973110156895">"Pripenjanje"</string> - <!-- no translation found for pin_specific_target (7824671240625957415) --> - <skip /> + <string name="pin_specific_target" msgid="7824671240625957415">"Pripni aplikacijo <xliff:g id="LABEL">%1$s</xliff:g>"</string> <string name="unpin_target" msgid="3963318576590204447">"Odpenjanje"</string> - <!-- no translation found for unpin_specific_target (3859828252160908146) --> - <skip /> + <string name="unpin_specific_target" msgid="3859828252160908146">"Odpni aplikacijo <xliff:g id="LABEL">%1$s</xliff:g>"</string> <string name="app_info" msgid="6113278084877079851">"Podatki o aplikacijah"</string> <string name="negative_duration" msgid="1938335096972945232">"−<xliff:g id="TIME">%1$s</xliff:g>"</string> <string name="demo_starting_message" msgid="6577581216125805905">"Začenjanje predstavitve …"</string> diff --git a/core/res/res/values-zh-rHK/strings.xml b/core/res/res/values-zh-rHK/strings.xml index d01e8e787f47..2cc42d74f862 100644 --- a/core/res/res/values-zh-rHK/strings.xml +++ b/core/res/res/values-zh-rHK/strings.xml @@ -491,8 +491,8 @@ <string name="permdesc_bluetooth" product="tablet" msgid="3053222571491402635">"允許應用程式查看平板電腦的藍牙設定,以及建立和接受與其他配對裝置的連線。"</string> <string name="permdesc_bluetooth" product="tv" msgid="8851534496561034998">"允許應用程式查看 Android TV 裝置的藍牙設定,以及建立和接受與其他配對裝置的連線。"</string> <string name="permdesc_bluetooth" product="default" msgid="2779606714091276746">"允許應用程式查看手機的藍牙設定,以及建立和接受與其他配對裝置的連線。"</string> - <string name="permlab_preferredPaymentInfo" msgid="5274423844767445054">"首選 NFC 付款服務資訊"</string> - <string name="permdesc_preferredPaymentInfo" msgid="8583552469807294967">"允許應用程式取得首選 NFC 付款服務的資訊 (如已註冊的付款輔助和最終付款對象)。"</string> + <string name="permlab_preferredPaymentInfo" msgid="5274423844767445054">"由用戶允許授權的 NFC 付款服務資訊"</string> + <string name="permdesc_preferredPaymentInfo" msgid="8583552469807294967">"允許應用程式取得由用戶允許授權的 NFC 付款服務資訊 (如已註冊的付款輔助功能和最終付款對象)。"</string> <string name="permlab_nfc" msgid="1904455246837674977">"控制近距離無線通訊"</string> <string name="permdesc_nfc" msgid="8352737680695296741">"允許應用程式使用近距離無線通訊 (NFC) 標記、卡片及讀取程式進行通訊。"</string> <string name="permlab_disableKeyguard" msgid="3605253559020928505">"停用螢幕上鎖"</string> diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index 85f7d617352e..6435cddebd1e 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -1533,7 +1533,8 @@ <code>com.google.app.<em>appname</em></code> <p>Inside of the manifest tag, may appear the following tags - in any order: {@link #AndroidManifestPermission permission}, + in any order: {@link #AndroidManifestFeature feature}, + {@link #AndroidManifestPermission permission}, {@link #AndroidManifestPermissionGroup permission-group}, {@link #AndroidManifestPermissionTree permission-tree}, {@link #AndroidManifestUsesSdk uses-sdk}, @@ -1763,6 +1764,29 @@ The default value is {@code false}. --> <attr name="crossProfile" format="boolean" /> </declare-styleable> + + <!-- The <code>feature</code> tag declares a feature. A feature is a part of an app. E.g. + photo sharing app might include a direct messaging component. + + <p>This appears as a child tag of the root {@link #AndroidManifest manifest} tag. + + <p>In case this feature inherits from another feature, this tag can contain one or multiple + {@link #AndroidManifestFeatureInheritFrom inherit-from} tags. --> + <declare-styleable name="AndroidManifestFeature" parent="AndroidManifest"> + <!-- Required identifier for a feature. Can be passed to + {@link android.content.Context#createFeatureContext} to create a context for this feature + --> + <attr name="featureId" format="string" /> + <!-- Required user visible label for a feature. --> + <attr name="label" format="string" /> + </declare-styleable> + + <!-- Declares previously declared features this feature inherits from. --> + <declare-styleable name="AndroidManifestFeatureInheritFrom" parent="AndroidManifestFeature"> + <!-- Identifier of the feature this feature inherits from --> + <attr name="featureId" format="string" /> + </declare-styleable> + <!-- The <code>permission</code> tag declares a security permission that can be used to control access from other packages to specific components or features in your package (or other packages). See the diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 0b6351860a02..bea3920d8b71 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -3004,6 +3004,8 @@ <public name="resourcesMap" /> <public name="animatedImageDrawable"/> <public name="htmlDescription"/> + <public name="preferMinimalPostProcessing"/> + <public name="featureId" /> </public-group> <public-group type="drawable" first-id="0x010800b5"> @@ -3049,10 +3051,6 @@ <public name="accessibilitySystemActionLockScreen" /> <public name="accessibilitySystemActionTakeScreenshot" /> </public-group> - - <public-group type="attr" first-id="0x0101060c"> - <public name="preferMinimalPostProcessing"/> - </public-group> <!-- =============================================================== DO NOT ADD UN-GROUPED ITEMS HERE diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index e874ac77847a..a00296c86a40 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3209,11 +3209,6 @@ <java-symbol type="id" name="accessibility_button_target_label" /> <java-symbol type="string" name="accessibility_magnification_chooser_text" /> - <java-symbol type="string" name="accessibility_gesture_prompt_text" /> - <java-symbol type="string" name="accessibility_gesture_3finger_prompt_text" /> - <java-symbol type="string" name="accessibility_gesture_instructional_text" /> - <java-symbol type="string" name="accessibility_gesture_3finger_instructional_text" /> - <java-symbol type="drawable" name="ic_accessibility_magnification" /> <!-- com.android.internal.widget.RecyclerView --> diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java index 8622b7efeee7..c086421501b5 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java @@ -54,6 +54,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager.ShareShortcutInfo; +import android.content.res.Configuration; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -977,6 +978,7 @@ public class ChooserActivityTest { serviceTargets, TARGET_TYPE_CHOOSER_TARGET) ); + // Thread.sleep shouldn't be a thing in an integration test but it's // necessary here because of the way the code is structured // TODO: restructure the tests b/129870719 @@ -1075,7 +1077,29 @@ public class ChooserActivityTest { // This test is too long and too slow and should not be taken as an example for future tests. @Test - public void testDirectTargetLoggingWithAppTargetNotRanked() throws InterruptedException { + public void testDirectTargetLoggingWithAppTargetNotRankedPortrait() + throws InterruptedException { + testDirectTargetLoggingWithAppTargetNotRanked(Configuration.ORIENTATION_PORTRAIT, 4); + } + + @Test + public void testDirectTargetLoggingWithAppTargetNotRankedLandscape() + throws InterruptedException { + testDirectTargetLoggingWithAppTargetNotRanked(Configuration.ORIENTATION_LANDSCAPE, 8); + } + + private void testDirectTargetLoggingWithAppTargetNotRanked( + int orientation, int appTargetsExpected + ) throws InterruptedException { + Configuration configuration = + new Configuration(InstrumentationRegistry.getInstrumentation().getContext() + .getResources().getConfiguration()); + configuration.orientation = orientation; + + sOverrides.resources = Mockito.spy( + InstrumentationRegistry.getInstrumentation().getContext().getResources()); + when(sOverrides.resources.getConfiguration()).thenReturn(configuration); + Intent sendIntent = createSendTextIntent(); // We need app targets for direct targets to get displayed List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(15); @@ -1111,8 +1135,10 @@ public class ChooserActivityTest { // TODO: restructure the tests b/129870719 Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); - assertThat("Chooser should have 20 targets (4 apps, 1 direct, 15 A-Z)", - activity.getAdapter().getCount(), is(20)); + assertThat( + String.format("Chooser should have %d targets (%d apps, 1 direct, 15 A-Z)", + appTargetsExpected + 16, appTargetsExpected), + activity.getAdapter().getCount(), is(appTargetsExpected + 16)); assertThat("Chooser should have exactly one selectable direct target", activity.getAdapter().getSelectableServiceTargetCount(), is(1)); assertThat("The resolver info must match the resolver info used to create the target", diff --git a/media/Android.bp b/media/Android.bp index a1365179c53a..499d0da3079f 100644 --- a/media/Android.bp +++ b/media/Android.bp @@ -1,110 +1,3 @@ -java_library { - name: "updatable-media", - - srcs: [ - ":updatable-media-srcs", - ], - - aidl: { - export_include_dirs: [ - "apex/java", - ], - - // It would be great if we don't need to add include_dirs for public - // parcelable classes. Find a better way. - include_dirs: [ - // To refer: - // android.os.Bundle - // android.os.ResultReceiver - "frameworks/base/core/java", - ], - }, - - permitted_packages: [ - "android.media", - ], - - installable: true, - - // TODO: build against stable API surface. Use core_platform for now to avoid - // link-check failure with exoplayer building against "current". - sdk_version: "core_platform", - libs: [ - // The order matters. android_system_* library should come later. - "framework_media_annotation", - "android_system_stubs_current", - ], - - static_libs: [ - "exoplayer2-core" - ], - jarjar_rules: "jarjar_rules.txt", - - plugins: ["java_api_finder"], -} - -filegroup { - name: "updatable-media-srcs", - srcs: [ - ":mediaparser-srcs", - ":mediasession2-srcs", - ], -} - -filegroup { - name: "mediasession2-srcs", - srcs: [ - "apex/java/android/media/Controller2Link.java", - "apex/java/android/media/IMediaController2.aidl", - "apex/java/android/media/IMediaSession2.aidl", - "apex/java/android/media/IMediaSession2Service.aidl", - "apex/java/android/media/MediaConstants.java", - "apex/java/android/media/MediaController2.java", - "apex/java/android/media/MediaSession2.java", - "apex/java/android/media/MediaSession2Service.java", - "apex/java/android/media/Session2Command.java", - "apex/java/android/media/Session2CommandGroup.java", - "apex/java/android/media/Session2Link.java", - "apex/java/android/media/Session2Token.java", - ], - path: "apex/java", -} - -filegroup { - name: "mediaparser-srcs", - srcs: [ - "apex/java/android/media/MediaParser.java" - ], - path: "apex/java" -} - -droidstubs { - name: "updatable-media-stubs", - srcs: [ - ":updatable-media-srcs", - ":framework-media-annotation-srcs", - ], - defaults: [ "framework-module-stubs-defaults-systemapi" ], - aidl: { - // TODO(b/135922046) remove this - include_dirs: ["frameworks/base/core/java"], - }, - sdk_version: "system_current", -} - -java_library { - name: "updatable_media_stubs", - srcs: [":updatable-media-stubs"], - sdk_version: "system_current", -} - -java_library { - name: "framework_media_annotation", - srcs: [":framework-media-annotation-srcs"], - installable: false, - sdk_version: "core_current", -} - aidl_interface { name: "audio_common-aidl", local_include_dir: "java", diff --git a/media/apex/java/android/media/CloseGuard.java b/media/apex/java/android/media/CloseGuard.java deleted file mode 100644 index 20146739fe4c..000000000000 --- a/media/apex/java/android/media/CloseGuard.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.media; - -import android.util.Log; - -/** - * Note: This file is copied from dalvik.system package with the following modifications: - * - Remove @CorePlatformApi, @IntraCoreApi and @UnsupportedAppUsage annotations. - * - Replace System.logW() with android.util.Log.w(). - * This file should be used only within media mainline module. - * TODO: Remove this file and use dalvik.system.CloseGuard once - * @CorePlatformApi becomes stable or we have a replacement in SDK API. - * b/120419300 - * - * CloseGuard is a mechanism for flagging implicit finalizer cleanup of - * resources that should have been cleaned up by explicit close - * methods (aka "explicit termination methods" in Effective Java). - * <p> - * A simple example: <pre> {@code - * class Foo { - * - * {@literal @}ReachabilitySensitive - * private final CloseGuard guard = CloseGuard.get(); - * - * ... - * - * public Foo() { - * ...; - * guard.open("cleanup"); - * } - * - * public void cleanup() { - * guard.close(); - * ...; - * } - * - * protected void finalize() throws Throwable { - * try { - * // Note that guard could be null if the constructor threw. - * if (guard != null) { - * guard.warnIfOpen(); - * } - * cleanup(); - * } finally { - * super.finalize(); - * } - * } - * } - * }</pre> - * - * In usage where the resource to be explicitly cleaned up is - * allocated after object construction, CloseGuard protection can - * be deferred. For example: <pre> {@code - * class Bar { - * - * {@literal @}ReachabilitySensitive - * private final CloseGuard guard = CloseGuard.get(); - * - * ... - * - * public Bar() { - * ...; - * } - * - * public void connect() { - * ...; - * guard.open("cleanup"); - * } - * - * public void cleanup() { - * guard.close(); - * ...; - * } - * - * protected void finalize() throws Throwable { - * try { - * // Note that guard could be null if the constructor threw. - * if (guard != null) { - * guard.warnIfOpen(); - * } - * cleanup(); - * } finally { - * super.finalize(); - * } - * } - * } - * }</pre> - * - * When used in a constructor, calls to {@code open} should occur at - * the end of the constructor since an exception that would cause - * abrupt termination of the constructor will mean that the user will - * not have a reference to the object to cleanup explicitly. When used - * in a method, the call to {@code open} should occur just after - * resource acquisition. - * - * The @ReachabilitySensitive annotation ensures that finalize() cannot be - * called during the explicit call to cleanup(), prior to the guard.close call. - * There is an extremely small chance that, for code that neglects to call - * cleanup(), finalize() and thus cleanup() will be called while a method on - * the object is still active, but the "this" reference is no longer required. - * If missing cleanup() calls are expected, additional @ReachabilitySensitive - * annotations or reachabilityFence() calls may be required. - * - * @hide - */ -final class CloseGuard { - - /** - * True if collection of call-site information (the expensive operation - * here) and tracking via a Tracker (see below) are enabled. - * Enabled by default so we can diagnose issues early in VM startup. - * Note, however, that Android disables this early in its startup, - * but enables it with DropBoxing for system apps on debug builds. - */ - private static volatile boolean stackAndTrackingEnabled = true; - - /** - * Hook for customizing how CloseGuard issues are reported. - * Bypassed if stackAndTrackingEnabled was false when open was called. - */ - private static volatile Reporter reporter = new DefaultReporter(); - - /** - * Hook for customizing how CloseGuard issues are tracked. - */ - private static volatile Tracker currentTracker = null; // Disabled by default. - - /** - * Returns a CloseGuard instance. {@code #open(String)} can be used to set - * up the instance to warn on failure to close. - */ - public static CloseGuard get() { - return new CloseGuard(); - } - - /** - * Enables/disables stack capture and tracking. A call stack is captured - * during open(), and open/close events are reported to the Tracker, only - * if enabled is true. If a stack trace was captured, the {@link - * #getReporter() reporter} is informed of unclosed resources; otherwise a - * one-line warning is logged. - */ - public static void setEnabled(boolean enabled) { - CloseGuard.stackAndTrackingEnabled = enabled; - } - - /** - * True if CloseGuard stack capture and tracking are enabled. - */ - public static boolean isEnabled() { - return stackAndTrackingEnabled; - } - - /** - * Used to replace default Reporter used to warn of CloseGuard - * violations when stack tracking is enabled. Must be non-null. - */ - public static void setReporter(Reporter rep) { - if (rep == null) { - throw new NullPointerException("reporter == null"); - } - CloseGuard.reporter = rep; - } - - /** - * Returns non-null CloseGuard.Reporter. - */ - public static Reporter getReporter() { - return reporter; - } - - /** - * Sets the {@link Tracker} that is notified when resources are allocated and released. - * The Tracker is invoked only if CloseGuard {@link #isEnabled()} held when {@link #open()} - * was called. A null argument disables tracking. - * - * <p>This is only intended for use by {@code dalvik.system.CloseGuardSupport} class and so - * MUST NOT be used for any other purposes. - */ - public static void setTracker(Tracker tracker) { - currentTracker = tracker; - } - - /** - * Returns {@link #setTracker(Tracker) last Tracker that was set}, or null to indicate - * there is none. - * - * <p>This is only intended for use by {@code dalvik.system.CloseGuardSupport} class and so - * MUST NOT be used for any other purposes. - */ - public static Tracker getTracker() { - return currentTracker; - } - - private CloseGuard() {} - - /** - * {@code open} initializes the instance with a warning that the caller - * should have explicitly called the {@code closer} method instead of - * relying on finalization. - * - * @param closer non-null name of explicit termination method. Printed by warnIfOpen. - * @throws NullPointerException if closer is null. - */ - public void open(String closer) { - // always perform the check for valid API usage... - if (closer == null) { - throw new NullPointerException("closer == null"); - } - // ...but avoid allocating an allocation stack if "disabled" - if (!stackAndTrackingEnabled) { - closerNameOrAllocationInfo = closer; - return; - } - String message = "Explicit termination method '" + closer + "' not called"; - Throwable stack = new Throwable(message); - closerNameOrAllocationInfo = stack; - Tracker tracker = currentTracker; - if (tracker != null) { - tracker.open(stack); - } - } - - // We keep either an allocation stack containing the closer String or, when - // in disabled state, just the closer String. - // We keep them in a single field only to minimize overhead. - private Object /* String or Throwable */ closerNameOrAllocationInfo; - - /** - * Marks this CloseGuard instance as closed to avoid warnings on - * finalization. - */ - public void close() { - Tracker tracker = currentTracker; - if (tracker != null && closerNameOrAllocationInfo instanceof Throwable) { - // Invoke tracker on close only if we invoked it on open. Tracker may have changed. - tracker.close((Throwable) closerNameOrAllocationInfo); - } - closerNameOrAllocationInfo = null; - } - - /** - * Logs a warning if the caller did not properly cleanup by calling an - * explicit close method before finalization. If CloseGuard was enabled - * when the CloseGuard was created, passes the stacktrace associated with - * the allocation to the current reporter. If it was not enabled, it just - * directly logs a brief message. - */ - public void warnIfOpen() { - if (closerNameOrAllocationInfo != null) { - if (closerNameOrAllocationInfo instanceof String) { - Log.w("CloseGuard", "A resource failed to call " - + (String) closerNameOrAllocationInfo + ". "); - } else { - String message = - "A resource was acquired at attached stack trace but never released. "; - message += "See java.io.Closeable for information on avoiding resource leaks."; - Throwable stack = (Throwable) closerNameOrAllocationInfo; - reporter.report(message, stack); - } - } - } - - /** - * Interface to allow customization of tracking behaviour. - * - * <p>This is only intended for use by {@code dalvik.system.CloseGuardSupport} class and so - * MUST NOT be used for any other purposes. - */ - public interface Tracker { - void open(Throwable allocationSite); - void close(Throwable allocationSite); - } - - /** - * Interface to allow customization of reporting behavior. - * @hide - */ - public interface Reporter { - void report(String message, Throwable allocationSite); - } - - /** - * Default Reporter which reports CloseGuard violations to the log. - */ - private static final class DefaultReporter implements Reporter { - private DefaultReporter() {} - - @Override public void report (String message, Throwable allocationSite) { - Log.w("CloseGuard", message, allocationSite); - } - } -} diff --git a/media/java/android/media/AudioRecordingConfiguration.java b/media/java/android/media/AudioRecordingConfiguration.java index 5f32c0f3f4a8..f3613d3665ca 100644 --- a/media/java/android/media/AudioRecordingConfiguration.java +++ b/media/java/android/media/AudioRecordingConfiguration.java @@ -18,6 +18,7 @@ package android.media; import android.annotation.IntDef; import android.annotation.NonNull; +import android.annotation.SystemApi; import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; import android.media.audiofx.AudioEffect; @@ -224,15 +225,16 @@ public final class AudioRecordingConfiguration implements Parcelable { public String getClientPackageName() { return mClientPackageName; } /** - * @pending for SystemApi * Returns the user id of the application performing the recording. * <p>This information is only available if the caller has the * {@link android.Manifest.permission.MODIFY_AUDIO_ROUTING} * permission. * <br>The result is -1 without the permission. * @return the user id + * + * @hide */ - @UnsupportedAppUsage + @SystemApi public int getClientUid() { return mClientUid; } /** diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java index 176bb37130a7..f780d40d349b 100644 --- a/media/java/android/media/MediaCodec.java +++ b/media/java/android/media/MediaCodec.java @@ -362,7 +362,8 @@ import java.util.concurrent.locks.ReentrantLock; </tr> <tr> <td>FLAC</td> - <td>mandatory metadata block (called the STREAMINFO block),<br> + <td>"fLaC", the FLAC stream marker in ASCII,<br> + followed by the STREAMINFO block (the mandatory metadata block),<br> optionally followed by any number of other metadata blocks</td> <td class=NA>Not Used</td> <td class=NA>Not Used</td> diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java index 0be49d88d10c..910003270845 100644 --- a/media/java/android/media/MediaRouter2.java +++ b/media/java/android/media/MediaRouter2.java @@ -547,8 +547,6 @@ public class MediaRouter2 { * {@link SessionCallback#onSessionCreationFailed}. * <p> * Pass {@code null} to sessionInfo for the failure case. - * - * TODO: What should router do when the session is created by manager? */ void createControllerOnHandler(@Nullable RouteSessionInfo sessionInfo, int requestId) { SessionCreationRequest matchingRequest = null; @@ -559,40 +557,44 @@ public class MediaRouter2 { } } - if (matchingRequest == null) { - Log.w(TAG, "Ignoring session creation result for unknown request." - + " requestId=" + requestId + ", sessionInfo=" + sessionInfo); - return; - } + if (matchingRequest != null) { + mSessionCreationRequests.remove(matchingRequest); - mSessionCreationRequests.remove(matchingRequest); + MediaRoute2Info requestedRoute = matchingRequest.mRoute; + String requestedControlCategory = matchingRequest.mControlCategory; - MediaRoute2Info requestedRoute = matchingRequest.mRoute; - String requestedControlCategory = matchingRequest.mControlCategory; + if (sessionInfo == null) { + // TODO: We may need to distinguish between failure and rejection. + // One way can be introducing 'reason'. + notifySessionCreationFailed(requestedRoute, requestedControlCategory); + return; + } else if (!TextUtils.equals(requestedControlCategory, + sessionInfo.getControlCategory())) { + Log.w(TAG, "The session has different control category from what we requested. " + + "(requested=" + requestedControlCategory + + ", actual=" + sessionInfo.getControlCategory() + + ")"); + notifySessionCreationFailed(requestedRoute, requestedControlCategory); + return; + } else if (!sessionInfo.getSelectedRoutes().contains(requestedRoute.getId())) { + Log.w(TAG, "The session does not contain the requested route. " + + "(requestedRouteId=" + requestedRoute.getId() + + ", actualRoutes=" + sessionInfo.getSelectedRoutes() + + ")"); + notifySessionCreationFailed(requestedRoute, requestedControlCategory); + return; + } else if (!TextUtils.equals(requestedRoute.getProviderId(), + sessionInfo.getProviderId())) { + Log.w(TAG, "The session's provider ID does not match the requested route's. " + + "(requested route's providerId=" + requestedRoute.getProviderId() + + ", actual providerId=" + sessionInfo.getProviderId() + + ")"); + notifySessionCreationFailed(requestedRoute, requestedControlCategory); + return; + } + } - if (sessionInfo == null) { - // TODO: We may need to distinguish between failure and rejection. - // One way can be introducing 'reason'. - notifySessionCreationFailed(requestedRoute, requestedControlCategory); - } else if (!TextUtils.equals(requestedControlCategory, sessionInfo.getControlCategory())) { - Log.w(TAG, "The session has different control category from what we requested. " - + "(requested=" + requestedControlCategory - + ", actual=" + sessionInfo.getControlCategory() - + ")"); - notifySessionCreationFailed(requestedRoute, requestedControlCategory); - } else if (!sessionInfo.getSelectedRoutes().contains(requestedRoute.getId())) { - Log.w(TAG, "The session does not contain the requested route. " - + "(requestedRouteId=" + requestedRoute.getId() - + ", actualRoutes=" + sessionInfo.getSelectedRoutes() - + ")"); - notifySessionCreationFailed(requestedRoute, requestedControlCategory); - } else if (!TextUtils.equals(requestedRoute.getProviderId(), sessionInfo.getProviderId())) { - Log.w(TAG, "The session's provider ID does not match the requested route's. " - + "(requested route's providerId=" + requestedRoute.getProviderId() - + ", actual providerId=" + sessionInfo.getProviderId() - + ")"); - notifySessionCreationFailed(requestedRoute, requestedControlCategory); - } else { + if (sessionInfo != null) { RouteSessionController controller = new RouteSessionController(sessionInfo); mSessionControllers.put(controller.getUniqueSessionId(), controller); notifySessionCreated(controller); diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp index ef806e4f19ae..da52696506b5 100644 --- a/media/jni/android_media_tv_Tuner.cpp +++ b/media/jni/android_media_tv_Tuner.cpp @@ -966,7 +966,7 @@ static const JNINativeMethod gFilterMethods[] = { { "nativeStopFilter", "()I", (void *)android_media_tv_Tuner_stop_filter }, { "nativeFlushFilter", "()I", (void *)android_media_tv_Tuner_flush_filter }, { "nativeRead", "([BII)I", (void *)android_media_tv_Tuner_read_filter_fmq }, - { "nativeCloseFilter", "()I", (void *)android_media_tv_Tuner_close_filter }, + { "nativeClose", "()I", (void *)android_media_tv_Tuner_close_filter }, }; static const JNINativeMethod gDescramblerMethods[] = { @@ -975,7 +975,7 @@ static const JNINativeMethod gDescramblerMethods[] = { { "nativeRemovePid", "(IILandroid/media/tv/tuner/Tuner$Filter;)I", (void *)android_media_tv_Tuner_remove_pid }, { "nativeSetKeyToken", "([B)I", (void *)android_media_tv_Tuner_set_key_token }, - { "nativeClose", "()V", (void *)android_media_tv_Tuner_close_descrambler }, + { "nativeClose", "()I", (void *)android_media_tv_Tuner_close_descrambler }, }; static const JNINativeMethod gDvrMethods[] = { diff --git a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouterManagerTest.java b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouterManagerTest.java index 1d51c9638bf0..83c7c173e8e8 100644 --- a/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouterManagerTest.java +++ b/media/tests/MediaRouter/src/com/android/mediaroutertest/MediaRouterManagerTest.java @@ -29,6 +29,7 @@ import android.content.Intent; import android.media.MediaRoute2Info; import android.media.MediaRouter2; import android.media.MediaRouter2.RouteCallback; +import android.media.MediaRouter2.SessionCallback; import android.media.MediaRouter2Manager; import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; @@ -101,8 +102,8 @@ public class MediaRouterManagerTest { private String mPackageName; private final List<MediaRouter2Manager.Callback> mManagerCallbacks = new ArrayList<>(); - private final List<RouteCallback> mRouteCallbacks = - new ArrayList<>(); + private final List<RouteCallback> mRouteCallbacks = new ArrayList<>(); + private final List<SessionCallback> mSessionCallbacks = new ArrayList<>(); public static final List<String> CATEGORIES_ALL = new ArrayList(); public static final List<String> CATEGORIES_SPECIAL = new ArrayList(); @@ -205,27 +206,26 @@ public class MediaRouterManagerTest { } /** - * Tests if MR2.Callback.onRouteSelected is called when a route is selected from MR2Manager. - * - * TODO: Change this test so that this test check whether the route is added in a session. - * Until then, temporailiy marking @Ignore + * Tests if MR2.SessionCallback.onSessionCreated is called + * when a route is selected from MR2Manager. */ @Test - @Ignore - public void testRouterOnRouteSelected() throws Exception { + public void testRouterOnSessionCreated() throws Exception { Map<String, MediaRoute2Info> routes = waitAndGetRoutesWithManager(CATEGORIES_ALL); CountDownLatch latch = new CountDownLatch(1); addManagerCallback(new MediaRouter2Manager.Callback()); -// addRouterCallback(new RouteDiscoveryCallback() { -// @Override -// public void onRouteSelected(MediaRoute2Info route, int reason, Bundle controlHints) { -// if (route != null && TextUtils.equals(route.getId(), ROUTE_ID1)) { -// latch.countDown(); -// } -// } -// }); + //TODO: remove this when it's not necessary. + addRouterCallback(new MediaRouter2.RouteCallback()); + addSessionCallback(new SessionCallback() { + @Override + public void onSessionCreated(MediaRouter2.RouteSessionController controller) { + if (createRouteMap(controller.getSelectedRoutes()).containsKey(ROUTE_ID1)) { + latch.countDown(); + } + } + }); MediaRoute2Info routeToSelect = routes.get(ROUTE_ID1); assertNotNull(routeToSelect); @@ -446,6 +446,11 @@ public class MediaRouterManagerTest { mRouter2.registerRouteCallback(mExecutor, routeCallback); } + private void addSessionCallback(SessionCallback sessionCallback) { + mSessionCallbacks.add(sessionCallback); + mRouter2.registerSessionCallback(mExecutor, sessionCallback); + } + private void clearCallbacks() { for (MediaRouter2Manager.Callback callback : mManagerCallbacks) { mManager.unregisterCallback(callback); @@ -456,5 +461,10 @@ public class MediaRouterManagerTest { mRouter2.unregisterRouteCallback(routeCallback); } mRouteCallbacks.clear(); + + for (SessionCallback sessionCallback : mSessionCallbacks) { + mRouter2.unregisterSessionCallback(sessionCallback); + } + mSessionCallbacks.clear(); } } diff --git a/packages/SettingsLib/res/values-ar/arrays.xml b/packages/SettingsLib/res/values-ar/arrays.xml index 7fc65a36e04a..b4f5253870c1 100644 --- a/packages/SettingsLib/res/values-ar/arrays.xml +++ b/packages/SettingsLib/res/values-ar/arrays.xml @@ -170,7 +170,7 @@ <string-array name="select_logpersist_titles"> <item msgid="704720725704372366">"إيقاف"</item> <item msgid="6014837961827347618">"الكل"</item> - <item msgid="7387060437894578132">"الكل دون اللاسلكي"</item> + <item msgid="7387060437894578132">"الكل بدون اللاسلكي"</item> <item msgid="7300881231043255746">"kernel فقط"</item> </string-array> <string-array name="select_logpersist_summaries"> diff --git a/packages/SettingsLib/res/values-ar/strings.xml b/packages/SettingsLib/res/values-ar/strings.xml index d4e1b63c4ca5..43d2eceab51d 100644 --- a/packages/SettingsLib/res/values-ar/strings.xml +++ b/packages/SettingsLib/res/values-ar/strings.xml @@ -68,14 +68,14 @@ <string name="bluetooth_connecting" msgid="5871702668260192755">"جارٍ الاتصال…"</string> <string name="bluetooth_connected" msgid="8065345572198502293">"الجهاز متصل<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> <string name="bluetooth_pairing" msgid="4269046942588193600">"جارٍ الاقتران..."</string> - <string name="bluetooth_connected_no_headset" msgid="2224101138659967604">"الجهاز متصل (من دون هاتف)<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> - <string name="bluetooth_connected_no_a2dp" msgid="8566874395813947092">"الجهاز متصل (من دون وسائط)<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> - <string name="bluetooth_connected_no_map" msgid="3381860077002724689">"الجهاز متصل (من دون وصول إلى الرسائل)<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> - <string name="bluetooth_connected_no_headset_no_a2dp" msgid="2893204819854215433">"الجهاز متصل (من دون هاتف أو وسائط)<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> + <string name="bluetooth_connected_no_headset" msgid="2224101138659967604">"الجهاز متصل (بدون هاتف)<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> + <string name="bluetooth_connected_no_a2dp" msgid="8566874395813947092">"الجهاز متصل (بدون وسائط)<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> + <string name="bluetooth_connected_no_map" msgid="3381860077002724689">"الجهاز متصل (بدون وصول إلى الرسائل)<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> + <string name="bluetooth_connected_no_headset_no_a2dp" msgid="2893204819854215433">"الجهاز متصل (بدون هاتف أو وسائط)<xliff:g id="ACTIVE_DEVICE">%1$s</xliff:g>"</string> <string name="bluetooth_connected_battery_level" msgid="5410325759372259950">"الجهاز متصل، ومستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g><xliff:g id="ACTIVE_DEVICE">%2$s</xliff:g>"</string> - <string name="bluetooth_connected_no_headset_battery_level" msgid="2661863370509206428">"الجهاز متصل (من دون هاتف)، ومستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g><xliff:g id="ACTIVE_DEVICE">%2$s</xliff:g>"</string> - <string name="bluetooth_connected_no_a2dp_battery_level" msgid="6499078454894324287">"الجهاز متصل (من دون وسائط)، ومستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g><xliff:g id="ACTIVE_DEVICE">%2$s</xliff:g>"</string> - <string name="bluetooth_connected_no_headset_no_a2dp_battery_level" msgid="8477440576953067242">"الجهاز متّصل (من دون هاتف أو وسائط)، ومستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g><xliff:g id="ACTIVE_DEVICE">%2$s</xliff:g>"</string> + <string name="bluetooth_connected_no_headset_battery_level" msgid="2661863370509206428">"الجهاز متصل (بدون هاتف)، ومستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g><xliff:g id="ACTIVE_DEVICE">%2$s</xliff:g>"</string> + <string name="bluetooth_connected_no_a2dp_battery_level" msgid="6499078454894324287">"الجهاز متصل (بدون وسائط)، ومستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g><xliff:g id="ACTIVE_DEVICE">%2$s</xliff:g>"</string> + <string name="bluetooth_connected_no_headset_no_a2dp_battery_level" msgid="8477440576953067242">"الجهاز متّصل (بدون هاتف أو وسائط)، ومستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g><xliff:g id="ACTIVE_DEVICE">%2$s</xliff:g>"</string> <string name="bluetooth_active_battery_level" msgid="3450745316700494425">"نشط، ومستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g>"</string> <string name="bluetooth_active_battery_level_untethered" msgid="2706188607604205362">"مفعّلة، مستوى البطارية: <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE_0">%1$s</xliff:g>، المعدّل: <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE_1">%2$s</xliff:g>"</string> <string name="bluetooth_battery_level" msgid="2893696778200201555">"مستوى طاقة البطارية <xliff:g id="BATTERY_LEVEL_AS_PERCENTAGE">%1$s</xliff:g>"</string> diff --git a/packages/SettingsLib/res/values-eu/strings.xml b/packages/SettingsLib/res/values-eu/strings.xml index 07d5ccbb840f..3f99d1044319 100644 --- a/packages/SettingsLib/res/values-eu/strings.xml +++ b/packages/SettingsLib/res/values-eu/strings.xml @@ -227,8 +227,7 @@ <string name="tethering_hardware_offload" msgid="4116053719006939161">"Konexioa partekatzeko hardwarearen azelerazioa"</string> <string name="bluetooth_show_devices_without_names" msgid="923584526471885819">"Erakutsi Bluetooth gailuak izenik gabe"</string> <string name="bluetooth_disable_absolute_volume" msgid="1452342324349203434">"Desgaitu bolumen absolutua"</string> - <!-- no translation found for bluetooth_enable_gabeldorsche (9131730396242883416) --> - <skip /> + <string name="bluetooth_enable_gabeldorsche" msgid="9131730396242883416">"Gaitu Gabeldorsche"</string> <string name="bluetooth_select_avrcp_version_string" msgid="1710571610177659127">"Bluetooth AVRCP bertsioa"</string> <string name="bluetooth_select_avrcp_version_dialog_title" msgid="7846922290083709633">"Hautatu Bluetooth AVRCP bertsioa"</string> <string name="bluetooth_select_a2dp_codec_type" msgid="952001408455456494">"Bluetooth bidezko audioaren kodeka"</string> @@ -277,8 +276,7 @@ <string name="verify_apps_over_usb_summary" msgid="1317933737581167839">"Egiaztatu ADB/ADT bidez instalatutako aplikazioak portaera kaltegarriak atzemateko"</string> <string name="bluetooth_show_devices_without_names_summary" msgid="780964354377854507">"Bluetooth gailuak izenik gabe (MAC helbideak soilik) erakutsiko dira"</string> <string name="bluetooth_disable_absolute_volume_summary" msgid="2006309932135547681">"Bluetooth bidezko bolumen absolutuaren eginbidea desgaitu egiten du urruneko gailuetan arazoak hautematen badira; esaterako, bolumena ozenegia bada edo ezin bada kontrolatu"</string> - <!-- no translation found for bluetooth_enable_gabeldorsche_summary (8472344901097607030) --> - <skip /> + <string name="bluetooth_enable_gabeldorsche_summary" msgid="8472344901097607030">"Bluetooth Gabeldorsche eginbide sorta gaitzen du."</string> <string name="enable_terminal_title" msgid="3834790541986303654">"Tokiko terminala"</string> <string name="enable_terminal_summary" msgid="2481074834856064500">"Gaitu tokiko shell-sarbidea duen terminal-aplikazioa"</string> <string name="hdcp_checking_title" msgid="3155692785074095986">"HDCP egiaztapena"</string> diff --git a/packages/SettingsLib/res/values-hi/strings.xml b/packages/SettingsLib/res/values-hi/strings.xml index 154f38604b26..f9ac3a539216 100644 --- a/packages/SettingsLib/res/values-hi/strings.xml +++ b/packages/SettingsLib/res/values-hi/strings.xml @@ -227,8 +227,7 @@ <string name="tethering_hardware_offload" msgid="4116053719006939161">"हार्डवेयर से तेज़ी लाने के लिए टेदर करें"</string> <string name="bluetooth_show_devices_without_names" msgid="923584526471885819">"बिना नाम वाले ब्लूटूथ डिवाइस दिखाएं"</string> <string name="bluetooth_disable_absolute_volume" msgid="1452342324349203434">"ब्लूटूथ से आवाज़ के नियंत्रण की सुविधा रोकें"</string> - <!-- no translation found for bluetooth_enable_gabeldorsche (9131730396242883416) --> - <skip /> + <string name="bluetooth_enable_gabeldorsche" msgid="9131730396242883416">"Gabeldorsche चालू करें"</string> <string name="bluetooth_select_avrcp_version_string" msgid="1710571610177659127">"ब्लूटूथ एवीआरसीपी वर्शन"</string> <string name="bluetooth_select_avrcp_version_dialog_title" msgid="7846922290083709633">"ब्लूटूथ AVRCP वर्शन चुनें"</string> <string name="bluetooth_select_a2dp_codec_type" msgid="952001408455456494">"ब्लूटूथ ऑडियो कोडेक"</string> @@ -277,8 +276,7 @@ <string name="verify_apps_over_usb_summary" msgid="1317933737581167839">"नुकसानदेह व्यवहार के लिए ADB/ADT से इंस्टॉल किए गए ऐप्लिकेशन जाँचें."</string> <string name="bluetooth_show_devices_without_names_summary" msgid="780964354377854507">"बिना नाम वाले ब्लूटूथ डिवाइस (केवल MAC पते वाले) दिखाए जाएंगे"</string> <string name="bluetooth_disable_absolute_volume_summary" msgid="2006309932135547681">"दूर के डिवाइस पर आवाज़ बहुत बढ़ जाने या उससे नियंत्रण हटने जैसी समस्याएं होने पर, यह ब्लूटूथ के ज़रिए आवाज़ के नियंत्रण की सुविधा रोक देता है."</string> - <!-- no translation found for bluetooth_enable_gabeldorsche_summary (8472344901097607030) --> - <skip /> + <string name="bluetooth_enable_gabeldorsche_summary" msgid="8472344901097607030">"Bluetooth Gabeldorsche सुविधा का स्टैक चालू करें."</string> <string name="enable_terminal_title" msgid="3834790541986303654">"स्थानीय टर्मिनल"</string> <string name="enable_terminal_summary" msgid="2481074834856064500">"लोकल शेल तक पहुंचने की सुविधा देने वाले टर्मिनल ऐप को चालू करें"</string> <string name="hdcp_checking_title" msgid="3155692785074095986">"एचडीसीपी जाँच"</string> diff --git a/packages/SettingsLib/res/values-sl/arrays.xml b/packages/SettingsLib/res/values-sl/arrays.xml index 4c22bda7a79a..d946316af95d 100644 --- a/packages/SettingsLib/res/values-sl/arrays.xml +++ b/packages/SettingsLib/res/values-sl/arrays.xml @@ -82,8 +82,6 @@ <item msgid="1049450003868150455">"Zvok <xliff:g id="QUALCOMM">Qualcomm®</xliff:g> <xliff:g id="APTX">aptX™</xliff:g>"</item> <item msgid="2908219194098827570">"Zvok <xliff:g id="QUALCOMM">Qualcomm®</xliff:g> <xliff:g id="APTX_HD">aptX™ HD</xliff:g>"</item> <item msgid="3825367753087348007">"LDAC"</item> - <item msgid="5832677994279829983">"Omogoči izbirne kodeke"</item> - <item msgid="9205039209798344398">"Onemogoči izbirne kodeke"</item> </string-array> <string-array name="bluetooth_a2dp_codec_summaries"> <item msgid="8868109554557331312">"Uporabi sistemsko izbiro (privzeto)"</item> @@ -92,8 +90,6 @@ <item msgid="8627333814413492563">"Zvok <xliff:g id="QUALCOMM">Qualcomm®</xliff:g> <xliff:g id="APTX">aptX™</xliff:g>"</item> <item msgid="3517061573669307965">"Zvok <xliff:g id="QUALCOMM">Qualcomm®</xliff:g> <xliff:g id="APTX_HD">aptX™ HD</xliff:g>"</item> <item msgid="2553206901068987657">"LDAC"</item> - <item msgid="221347164942544028">"Omogoči izbirne kodeke"</item> - <item msgid="7416462860415701287">"Onemogoči izbirne kodeke"</item> </string-array> <string-array name="bluetooth_a2dp_codec_sample_rate_titles"> <item msgid="926809261293414607">"Uporabi sistemsko izbiro (privzeto)"</item> diff --git a/packages/SettingsLib/res/values-sl/strings.xml b/packages/SettingsLib/res/values-sl/strings.xml index 90d7829ae3bb..efd7c083eae4 100644 --- a/packages/SettingsLib/res/values-sl/strings.xml +++ b/packages/SettingsLib/res/values-sl/strings.xml @@ -227,6 +227,7 @@ <string name="tethering_hardware_offload" msgid="4116053719006939161">"Strojno pospeševanje za internetno povezavo prek mobilnega telefona"</string> <string name="bluetooth_show_devices_without_names" msgid="923584526471885819">"Prikaži naprave Bluetooth brez imen"</string> <string name="bluetooth_disable_absolute_volume" msgid="1452342324349203434">"Onemogočanje absolutne glasnosti"</string> + <string name="bluetooth_enable_gabeldorsche" msgid="9131730396242883416">"Omogoči Gabeldorsche"</string> <string name="bluetooth_select_avrcp_version_string" msgid="1710571610177659127">"Različica profila AVRCP za Bluetooth"</string> <string name="bluetooth_select_avrcp_version_dialog_title" msgid="7846922290083709633">"Izberite različico profila AVRCP za Bluetooth"</string> <string name="bluetooth_select_a2dp_codec_type" msgid="952001408455456494">"Zvočni kodek za Bluetooth"</string> @@ -275,6 +276,7 @@ <string name="verify_apps_over_usb_summary" msgid="1317933737581167839">"Preveri, ali so aplikacije, nameščene prek ADB/ADT, škodljive."</string> <string name="bluetooth_show_devices_without_names_summary" msgid="780964354377854507">"Prikazane bodo naprave Bluetooth brez imen (samo z naslovi MAC)"</string> <string name="bluetooth_disable_absolute_volume_summary" msgid="2006309932135547681">"Onemogoči funkcijo absolutne glasnosti za Bluetooth, če pride do težav z glasnostjo z oddaljenimi napravami, kot je nesprejemljivo visoka glasnost ali pomanjkanje nadzora."</string> + <string name="bluetooth_enable_gabeldorsche_summary" msgid="8472344901097607030">"Omogoči sklad funkcij Bluetooth Gabeldorche."</string> <string name="enable_terminal_title" msgid="3834790541986303654">"Lokalni terminal"</string> <string name="enable_terminal_summary" msgid="2481074834856064500">"Omogočanje terminalske aplikacije za dostop do lokalne lupine"</string> <string name="hdcp_checking_title" msgid="3155692785074095986">"Preverjanje HDCP"</string> @@ -379,7 +381,7 @@ <string name="daltonizer_mode_protanomaly" msgid="7805583306666608440">"Protanomalija (rdeča – zelena)"</string> <string name="daltonizer_mode_tritanomaly" msgid="7135266249220732267">"Tritanomalija (modra – rumena)"</string> <string name="accessibility_display_daltonizer_preference_title" msgid="1810693571332381974">"Popravljanje barv"</string> - <string name="accessibility_display_daltonizer_preference_subtitle" msgid="5190814747212060815">"To je preskusna funkcija in lahko vpliva na učinkovitost delovanja."</string> + <string name="accessibility_display_daltonizer_preference_subtitle" msgid="9137381746633858694">"Popravljanje barv osebam z barvno slepoto pomaga, da vidijo bolj prave barve"</string> <string name="daltonizer_type_overridden" msgid="4509604753672535721">"Preglasila nastavitev: <xliff:g id="TITLE">%1$s</xliff:g>"</string> <string name="power_remaining_settings_home_page" msgid="4885165789445462557">"<xliff:g id="PERCENTAGE">%1$s</xliff:g> – <xliff:g id="TIME_STRING">%2$s</xliff:g>"</string> <string name="power_remaining_duration_only" msgid="8264199158671531431">"Še približno <xliff:g id="TIME_REMAINING">%1$s</xliff:g>"</string> diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java index 58655a2b930a..b4b55f363020 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidProfile.java @@ -203,13 +203,6 @@ public class HearingAidProfile implements LocalBluetoothProfile { } } - public int getVolume() { - if (mService == null) { - return 0; - } - return mService.getVolume(); - } - public void setVolume(int volume) { if (mService == null) { return; @@ -224,20 +217,6 @@ public class HearingAidProfile implements LocalBluetoothProfile { return mService.getHiSyncId(device); } - public int getDeviceSide(BluetoothDevice device) { - if (mService == null) { - return BluetoothHearingAid.SIDE_LEFT; - } - return mService.getDeviceSide(device); - } - - public int getDeviceMode(BluetoothDevice device) { - if (mService == null) { - return BluetoothHearingAid.MODE_MONAURAL; - } - return mService.getDeviceMode(device); - } - public String toString() { return NAME; } diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleTouchHandler.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleTouchHandler.java index 995b35f2b5b3..fdeaf1f016c3 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleTouchHandler.java @@ -134,7 +134,8 @@ class BubbleTouchHandler implements View.OnTouchListener { if (isStack) { mViewPositionOnTouchDown.set(mStack.getStackPosition()); mStack.onDragStart(); - if (!mStack.isShowingBubbleMenu() && !mStack.isExpanded()) { + if (!mStack.isShowingBubbleMenu() && !mStack.isExpanded() + && BubbleExperimentConfig.allowBubbleScreenshotMenu(mContext)) { mShowBubbleMenuRunnable = mStack::showBubbleMenu; mStack.postDelayed(mShowBubbleMenuRunnable, ViewConfiguration.getLongPressTimeout()); diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java index d3ccbeb0afb1..77c3ad971ef0 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java @@ -27,7 +27,6 @@ import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; -import android.graphics.Point; import android.graphics.drawable.Icon; import android.hardware.display.DisplayManager; import android.hardware.display.VirtualDisplay; @@ -42,6 +41,7 @@ import android.util.DisplayMetrics; import android.util.Log; import android.util.Size; import android.view.Surface; +import android.view.WindowManager; import android.widget.Toast; import com.android.systemui.R; @@ -76,7 +76,7 @@ public class RecordingService extends Service { private static final String ACTION_DELETE = "com.android.systemui.screenrecord.DELETE"; private static final int TOTAL_NUM_TRACKS = 1; - private static final int VIDEO_BIT_RATE = 6000000; + private static final int VIDEO_BIT_RATE = 10000000; private static final int VIDEO_FRAME_RATE = 30; private static final int AUDIO_BIT_RATE = 16; private static final int AUDIO_SAMPLE_RATE = 44100; @@ -238,7 +238,9 @@ public class RecordingService extends Service { mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); // Set up video - DisplayMetrics metrics = getResources().getDisplayMetrics(); + DisplayMetrics metrics = new DisplayMetrics(); + WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); + wm.getDefaultDisplay().getRealMetrics(metrics); int screenWidth = metrics.widthPixels; int screenHeight = metrics.heightPixels; mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java b/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java index 778443c4bddf..fdb793e6da95 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputController.java @@ -33,6 +33,7 @@ import com.android.systemui.statusbar.policy.RemoteInputView; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Keeps track of the currently active {@link RemoteInputView}s. @@ -108,8 +109,8 @@ public class RemoteInputController { * @param token a token identifying the view that is managing the remote input */ public void addRemoteInput(NotificationEntry entry, Object token) { - Preconditions.checkNotNull(entry); - Preconditions.checkNotNull(token); + Objects.requireNonNull(entry); + Objects.requireNonNull(token); boolean found = pruneWeakThenRemoveAndContains( entry /* contains */, null /* remove */, token /* removeToken */); @@ -129,7 +130,7 @@ public class RemoteInputController { * entry. If null, the entry is removed regardless. */ public void removeRemoteInput(NotificationEntry entry, Object token) { - Preconditions.checkNotNull(entry); + Objects.requireNonNull(entry); pruneWeakThenRemoveAndContains(null /* contains */, entry /* remove */, token); @@ -143,8 +144,8 @@ public class RemoteInputController { * @param token the token of the view managing the remote input. */ public void addSpinning(String key, Object token) { - Preconditions.checkNotNull(key); - Preconditions.checkNotNull(token); + Objects.requireNonNull(key); + Objects.requireNonNull(token); mSpinning.put(key, token); } @@ -158,7 +159,7 @@ public class RemoteInputController { * entry. If null, the entry is removed regardless. */ public void removeSpinning(String key, Object token) { - Preconditions.checkNotNull(key); + Objects.requireNonNull(key); if (token == null || mSpinning.get(key) == token) { mSpinning.remove(key); @@ -237,7 +238,7 @@ public class RemoteInputController { public void addCallback(Callback callback) { - Preconditions.checkNotNull(callback); + Objects.requireNonNull(callback); mCallbacks.add(callback); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationListController.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationListController.java index 7b1dc074fcbc..f2765db6fd46 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationListController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationListController.java @@ -16,14 +16,14 @@ package com.android.systemui.statusbar.notification; -import static com.android.internal.util.Preconditions.checkNotNull; - import com.android.internal.statusbar.NotificationVisibility; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.stack.NotificationListContainer; import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; +import java.util.Objects; + /** * Root controller for the list of notifications in the shade. * @@ -39,9 +39,9 @@ public class NotificationListController { NotificationEntryManager entryManager, NotificationListContainer listContainer, DeviceProvisionedController deviceProvisionedController) { - mEntryManager = checkNotNull(entryManager); - mListContainer = checkNotNull(listContainer); - mDeviceProvisionedController = checkNotNull(deviceProvisionedController); + mEntryManager = Objects.requireNonNull(entryManager); + mListContainer = Objects.requireNonNull(listContainer); + mDeviceProvisionedController = Objects.requireNonNull(deviceProvisionedController); } /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java index 7f85c88865f6..7df7568875de 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java @@ -35,8 +35,6 @@ import static android.service.notification.NotificationListenerService.REASON_TI import static android.service.notification.NotificationListenerService.REASON_UNAUTOBUNDLED; import static android.service.notification.NotificationListenerService.REASON_USER_STOPPED; -import static com.android.internal.util.Preconditions.checkNotNull; - import android.annotation.IntDef; import android.annotation.MainThread; import android.annotation.NonNull; @@ -60,6 +58,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import javax.inject.Inject; import javax.inject.Singleton; @@ -170,7 +169,7 @@ public class NotifCollection { @CancellationReason int reason, @NonNull DismissedByUserStats stats) { Assert.isMainThread(); - checkNotNull(stats); + Objects.requireNonNull(stats); checkForReentrantCall(); removeNotification(entry.getKey(), null, reason, stats); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java index dd3a3e0b1505..4f4fb240162d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java @@ -29,7 +29,6 @@ import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICAT import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR; -import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_ALERTING; import android.annotation.NonNull; @@ -162,9 +161,9 @@ public final class NotificationEntry extends ListEntry { public NotificationEntry( @NonNull StatusBarNotification sbn, @NonNull Ranking ranking) { - super(checkNotNull(checkNotNull(sbn).getKey())); + super(Objects.requireNonNull(Objects.requireNonNull(sbn).getKey())); - checkNotNull(ranking); + Objects.requireNonNull(ranking); mKey = sbn.getKey(); setSbn(sbn); @@ -194,8 +193,8 @@ public final class NotificationEntry extends ListEntry { * TODO: Make this package-private */ public void setSbn(@NonNull StatusBarNotification sbn) { - checkNotNull(sbn); - checkNotNull(sbn.getKey()); + Objects.requireNonNull(sbn); + Objects.requireNonNull(sbn.getKey()); if (!sbn.getKey().equals(mKey)) { throw new IllegalArgumentException("New key " + sbn.getKey() @@ -223,8 +222,8 @@ public final class NotificationEntry extends ListEntry { * TODO: Make this package-private */ public void setRanking(@NonNull Ranking ranking) { - checkNotNull(ranking); - checkNotNull(ranking.getKey()); + Objects.requireNonNull(ranking); + Objects.requireNonNull(ranking.getKey()); if (!ranking.getKey().equals(mKey)) { throw new IllegalArgumentException("New key " + ranking.getKey() diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRowBinderImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRowBinderImpl.java index 8afbc27589d8..6c93618e5395 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRowBinderImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRowBinderImpl.java @@ -16,7 +16,6 @@ package com.android.systemui.statusbar.notification.collection; -import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENABLE_REMOTE_INPUT; import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_HEADS_UP; @@ -51,6 +50,8 @@ import com.android.systemui.statusbar.phone.NotificationGroupManager; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.policy.HeadsUpManager; +import java.util.Objects; + /** Handles inflating and updating views for notifications. */ public class NotificationRowBinderImpl implements NotificationRowBinder { @@ -265,7 +266,7 @@ public class NotificationRowBinderImpl implements NotificationRowBinder { row.inflateViews(); // bind the click event to the content area - checkNotNull(mNotificationClicker).register(row, sbn); + Objects.requireNonNull(mNotificationClicker).register(row, sbn); } private void logNotificationExpansion(String key, boolean userAction, boolean expanded) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/SectionHeaderView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/SectionHeaderView.java index b444fa50a253..add982dabf02 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/SectionHeaderView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/SectionHeaderView.java @@ -16,8 +16,6 @@ package com.android.systemui.statusbar.notification.stack; -import static com.android.internal.util.Preconditions.checkNotNull; - import android.annotation.Nullable; import android.content.Context; import android.graphics.RectF; @@ -32,6 +30,8 @@ import android.widget.TextView; import com.android.systemui.R; import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; +import java.util.Objects; + /** * Similar in size and appearance to the NotificationShelf, appears at the beginning of some * notification sections. Currently only used for gentle notifications. @@ -51,13 +51,13 @@ public class SectionHeaderView extends ActivatableNotificationView { @Override protected void onFinishInflate() { super.onFinishInflate(); - mContents = checkNotNull(findViewById(R.id.content)); + mContents = Objects.requireNonNull(findViewById(R.id.content)); bindContents(); } private void bindContents() { - mLabelView = checkNotNull(findViewById(R.id.header_label)); - mClearAllButton = checkNotNull(findViewById(R.id.btn_clear_all)); + mLabelView = Objects.requireNonNull(findViewById(R.id.header_label)); + mClearAllButton = Objects.requireNonNull(findViewById(R.id.btn_clear_all)); if (mOnClearClickListener != null) { mClearAllButton.setOnClickListener(mOnClearClickListener); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java index b1986782e914..88edf8e40972 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BrightnessMirrorController.java @@ -23,11 +23,11 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.FrameLayout; -import com.android.internal.util.Preconditions; import com.android.systemui.R; import com.android.systemui.statusbar.phone.NotificationPanelView; import com.android.systemui.statusbar.phone.StatusBarWindowView; +import java.util.Objects; import java.util.function.Consumer; /** @@ -117,7 +117,7 @@ public class BrightnessMirrorController @Override public void addCallback(BrightnessMirrorListener listener) { - Preconditions.checkNotNull(listener); + Objects.requireNonNull(listener); mBrightnessMirrorListeners.add(listener); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardStateControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardStateControllerImpl.java index 1cb2bd430199..0ab08a8fd168 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardStateControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardStateControllerImpl.java @@ -27,7 +27,6 @@ import android.os.Trace; import androidx.annotation.VisibleForTesting; -import com.android.internal.util.Preconditions; import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitorCallback; @@ -36,6 +35,7 @@ import com.android.systemui.Dumpable; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Objects; import javax.inject.Inject; import javax.inject.Singleton; @@ -98,7 +98,7 @@ public class KeyguardStateControllerImpl implements KeyguardStateController, Dum @Override public void addCallback(@NonNull Callback callback) { - Preconditions.checkNotNull(callback, "Callback must not be null. b/128895449"); + Objects.requireNonNull(callback, "Callback must not be null. b/128895449"); if (!mCallbacks.contains(callback)) { mCallbacks.add(callback); } @@ -106,7 +106,7 @@ public class KeyguardStateControllerImpl implements KeyguardStateController, Dum @Override public void removeCallback(@NonNull Callback callback) { - Preconditions.checkNotNull(callback, "Callback must not be null. b/128895449"); + Objects.requireNonNull(callback, "Callback must not be null. b/128895449"); mCallbacks.remove(callback); } diff --git a/packages/SystemUI/src/com/android/systemui/util/wakelock/SettableWakeLock.java b/packages/SystemUI/src/com/android/systemui/util/wakelock/SettableWakeLock.java index a7972878171a..37da236c2227 100644 --- a/packages/SystemUI/src/com/android/systemui/util/wakelock/SettableWakeLock.java +++ b/packages/SystemUI/src/com/android/systemui/util/wakelock/SettableWakeLock.java @@ -16,7 +16,7 @@ package com.android.systemui.util.wakelock; -import com.android.internal.util.Preconditions; +import java.util.Objects; public class SettableWakeLock { @@ -26,7 +26,7 @@ public class SettableWakeLock { private boolean mAcquired; public SettableWakeLock(WakeLock inner, String why) { - Preconditions.checkNotNull(inner, "inner wakelock required"); + Objects.requireNonNull(inner, "inner wakelock required"); mInner = inner; mWhy = why; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java index 0dcd25300633..e1e7220f1a5f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifCollectionTest.java @@ -19,7 +19,6 @@ package com.android.systemui.statusbar.notification.collection; import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL; import static android.service.notification.NotificationListenerService.REASON_CLICK; -import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.systemui.statusbar.notification.collection.NotifCollection.REASON_UNKNOWN; import static org.junit.Assert.assertEquals; @@ -65,6 +64,7 @@ import org.mockito.Spy; import java.util.Arrays; import java.util.Map; +import java.util.Objects; @SmallTest @RunWith(AndroidTestingRunner.class) @@ -99,7 +99,7 @@ public class NotifCollectionTest extends SysuiTestCase { // Capture the listener object that the collection registers with the listener service so // we can simulate listener service events in tests below verify(mListenerService).addNotificationListener(mListenerCaptor.capture()); - mServiceListener = checkNotNull(mListenerCaptor.getValue()); + mServiceListener = Objects.requireNonNull(mListenerCaptor.getValue()); mNoMan = new NoManSimulator(mServiceListener); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifListBuilderImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifListBuilderImplTest.java index 6e9c2c8adb4a..a8f3638dff32 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifListBuilderImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotifListBuilderImplTest.java @@ -16,7 +16,6 @@ package com.android.systemui.statusbar.notification.collection; -import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.systemui.statusbar.notification.collection.ListDumper.dumpList; import static org.junit.Assert.assertEquals; @@ -67,6 +66,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; @SmallTest @@ -105,7 +105,7 @@ public class NotifListBuilderImplTest extends SysuiTestCase { mListBuilder.attach(mNotifCollection); Mockito.verify(mNotifCollection).setBuildListener(mBuildListenerCaptor.capture()); - mReadyForBuildListener = checkNotNull(mBuildListenerCaptor.getValue()); + mReadyForBuildListener = Objects.requireNonNull(mBuildListenerCaptor.getValue()); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightsOutNotifControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightsOutNotifControllerTest.java index a02445487dc0..3d59d6162c0c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightsOutNotifControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightsOutNotifControllerTest.java @@ -18,8 +18,6 @@ package com.android.systemui.statusbar.phone; import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS; -import static com.android.internal.util.Preconditions.checkNotNull; - import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; @@ -50,6 +48,8 @@ import org.mockito.Captor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.Objects; + @SmallTest @RunWith(AndroidTestingRunner.class) @RunWithLooper @@ -85,11 +85,11 @@ public class LightsOutNotifControllerTest extends SysuiTestCase { // Capture the entry listener object so we can simulate events in tests below verify(mEntryManager).addNotificationEntryListener(mListenerCaptor.capture()); - mEntryListener = checkNotNull(mListenerCaptor.getValue()); + mEntryListener = Objects.requireNonNull(mListenerCaptor.getValue()); // Capture the callback object so we can simulate callback events in tests below verify(mCommandQueue).addCallback(mCallbacksCaptor.capture()); - mCallbacks = checkNotNull(mCallbacksCaptor.getValue()); + mCallbacks = Objects.requireNonNull(mCallbacksCaptor.getValue()); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/sensors/FakeSensorManager.java b/packages/SystemUI/tests/src/com/android/systemui/util/sensors/FakeSensorManager.java index e15ca1da928d..27b225e3c4fa 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/util/sensors/FakeSensorManager.java +++ b/packages/SystemUI/tests/src/com/android/systemui/util/sensors/FakeSensorManager.java @@ -30,14 +30,13 @@ import android.os.MemoryFile; import android.os.SystemClock; import android.util.ArraySet; -import com.android.internal.util.Preconditions; - import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -113,7 +112,7 @@ public class FakeSensorManager extends SensorManager { @Override protected void unregisterListenerImpl(SensorEventListener listener, Sensor sensor) { - Preconditions.checkNotNull(listener); + Objects.requireNonNull(listener); for (FakeGenericSensor s : mSensors) { if (sensor == null || s.mSensor == sensor) { s.mListeners.remove(listener); @@ -125,8 +124,8 @@ public class FakeSensorManager extends SensorManager { protected boolean registerListenerImpl(SensorEventListener listener, Sensor sensor, int delayUs, Handler handler, int maxReportLatencyUs, int reservedFlags) { - Preconditions.checkNotNull(sensor); - Preconditions.checkNotNull(listener); + Objects.requireNonNull(sensor); + Objects.requireNonNull(listener); for (FakeGenericSensor s : mSensors) { if (s.mSensor == sensor) { s.mListeners.add(listener); diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index c689ed1c64c7..03d9626cab91 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -288,7 +288,14 @@ public final class AutofillManagerService boolean isTemporary) { mAugmentedAutofillState.setServiceInfo(userId, serviceName, isTemporary); synchronized (mLock) { - getServiceForUserLocked(userId).updateRemoteAugmentedAutofillService(); + final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId); + if (service == null) { + // If we cannot get the service from the services cache, it will call + // updateRemoteAugmentedAutofillService() finally. Skip call this update again. + getServiceForUserLocked(userId); + } else { + service.updateRemoteAugmentedAutofillService(); + } } } diff --git a/services/core/java/com/android/server/AppStateTracker.java b/services/core/java/com/android/server/AppStateTracker.java index 7d5b17684843..72e170ff9532 100644 --- a/services/core/java/com/android/server/AppStateTracker.java +++ b/services/core/java/com/android/server/AppStateTracker.java @@ -63,6 +63,7 @@ import com.android.server.usage.AppStandbyInternal.AppIdleStateChangeListener; import java.io.PrintWriter; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * Class to keep track of the information related to "force app standby", which includes: @@ -416,12 +417,12 @@ public class AppStateTracker { } mStarted = true; - mIActivityManager = Preconditions.checkNotNull(injectIActivityManager()); - mActivityManagerInternal = Preconditions.checkNotNull(injectActivityManagerInternal()); - mAppOpsManager = Preconditions.checkNotNull(injectAppOpsManager()); - mAppOpsService = Preconditions.checkNotNull(injectIAppOpsService()); - mPowerManagerInternal = Preconditions.checkNotNull(injectPowerManagerInternal()); - mAppStandbyInternal = Preconditions.checkNotNull(injectAppStandbyInternal()); + mIActivityManager = Objects.requireNonNull(injectIActivityManager()); + mActivityManagerInternal = Objects.requireNonNull(injectActivityManagerInternal()); + mAppOpsManager = Objects.requireNonNull(injectAppOpsManager()); + mAppOpsService = Objects.requireNonNull(injectIAppOpsService()); + mPowerManagerInternal = Objects.requireNonNull(injectPowerManagerInternal()); + mAppStandbyInternal = Objects.requireNonNull(injectAppStandbyInternal()); mFlagsObserver = new FeatureFlagsObserver(); mFlagsObserver.register(); diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index bb78aceb3b5f..deac1e3089c9 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -47,8 +47,6 @@ import static android.os.Process.INVALID_UID; import static android.system.OsConstants.IPPROTO_TCP; import static android.system.OsConstants.IPPROTO_UDP; -import static com.android.internal.util.Preconditions.checkNotNull; - import android.annotation.NonNull; import android.annotation.Nullable; import android.app.BroadcastOptions; @@ -904,7 +902,7 @@ public class ConnectivityService extends IConnectivityManager.Stub * @see IpConnectivityMetrics.Logger */ public IpConnectivityMetrics.Logger getMetricsLogger() { - return checkNotNull(LocalServices.getService(IpConnectivityMetrics.Logger.class), + return Objects.requireNonNull(LocalServices.getService(IpConnectivityMetrics.Logger.class), "no IpConnectivityMetrics service"); } @@ -933,7 +931,7 @@ public class ConnectivityService extends IConnectivityManager.Stub IDnsResolver dnsresolver, IpConnectivityLog logger, INetd netd, Dependencies deps) { if (DBG) log("ConnectivityService starting up"); - mDeps = checkNotNull(deps, "missing Dependencies"); + mDeps = Objects.requireNonNull(deps, "missing Dependencies"); mSystemProperties = mDeps.getSystemProperties(); mNetIdManager = mDeps.makeNetIdManager(); @@ -962,14 +960,14 @@ public class ConnectivityService extends IConnectivityManager.Stub mLingerDelayMs = mSystemProperties.getInt(LINGER_DELAY_PROPERTY, DEFAULT_LINGER_DELAY_MS); - mContext = checkNotNull(context, "missing Context"); - mNMS = checkNotNull(netManager, "missing INetworkManagementService"); - mStatsService = checkNotNull(statsService, "missing INetworkStatsService"); - mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager"); - mPolicyManagerInternal = checkNotNull( + mContext = Objects.requireNonNull(context, "missing Context"); + mNMS = Objects.requireNonNull(netManager, "missing INetworkManagementService"); + mStatsService = Objects.requireNonNull(statsService, "missing INetworkStatsService"); + mPolicyManager = Objects.requireNonNull(policyManager, "missing INetworkPolicyManager"); + mPolicyManagerInternal = Objects.requireNonNull( LocalServices.getService(NetworkPolicyManagerInternal.class), "missing NetworkPolicyManagerInternal"); - mDnsResolver = checkNotNull(dnsresolver, "missing IDnsResolver"); + mDnsResolver = Objects.requireNonNull(dnsresolver, "missing IDnsResolver"); mProxyTracker = mDeps.makeProxyTracker(mContext, mHandler); mNetd = netd; @@ -5195,7 +5193,7 @@ public class ConnectivityService extends IConnectivityManager.Stub @Override public NetworkRequest pendingRequestForNetwork(NetworkCapabilities networkCapabilities, PendingIntent operation) { - checkNotNull(operation, "PendingIntent cannot be null."); + Objects.requireNonNull(operation, "PendingIntent cannot be null."); networkCapabilities = new NetworkCapabilities(networkCapabilities); enforceNetworkRequestPermissions(networkCapabilities); enforceMeteredApnPolicy(networkCapabilities); @@ -5222,7 +5220,7 @@ public class ConnectivityService extends IConnectivityManager.Stub @Override public void releasePendingNetworkRequest(PendingIntent operation) { - checkNotNull(operation, "PendingIntent cannot be null."); + Objects.requireNonNull(operation, "PendingIntent cannot be null."); mHandler.sendMessage(mHandler.obtainMessage(EVENT_RELEASE_NETWORK_REQUEST_WITH_INTENT, getCallingUid(), 0, operation)); } @@ -5280,7 +5278,7 @@ public class ConnectivityService extends IConnectivityManager.Stub @Override public void pendingListenForNetwork(NetworkCapabilities networkCapabilities, PendingIntent operation) { - checkNotNull(operation, "PendingIntent cannot be null."); + Objects.requireNonNull(operation, "PendingIntent cannot be null."); if (!hasWifiNetworkListenPermission(networkCapabilities)) { enforceAccessPermission(); } diff --git a/services/core/java/com/android/server/ExplicitHealthCheckController.java b/services/core/java/com/android/server/ExplicitHealthCheckController.java index f7c4aac2e04f..77059d918052 100644 --- a/services/core/java/com/android/server/ExplicitHealthCheckController.java +++ b/services/core/java/com/android/server/ExplicitHealthCheckController.java @@ -47,6 +47,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.function.Consumer; @@ -113,9 +114,9 @@ class ExplicitHealthCheckController { Slog.wtf(TAG, "Resetting health check controller callbacks"); } - mPassedConsumer = Preconditions.checkNotNull(passedConsumer); - mSupportedConsumer = Preconditions.checkNotNull(supportedConsumer); - mNotifySyncRunnable = Preconditions.checkNotNull(notifySyncRunnable); + mPassedConsumer = Objects.requireNonNull(passedConsumer); + mSupportedConsumer = Objects.requireNonNull(supportedConsumer); + mNotifySyncRunnable = Objects.requireNonNull(notifySyncRunnable); } } diff --git a/services/core/java/com/android/server/IpSecService.java b/services/core/java/com/android/server/IpSecService.java index a629b3fbb8fa..c98762074b53 100644 --- a/services/core/java/com/android/server/IpSecService.java +++ b/services/core/java/com/android/server/IpSecService.java @@ -25,8 +25,6 @@ import static android.system.OsConstants.EINVAL; import static android.system.OsConstants.IPPROTO_UDP; import static android.system.OsConstants.SOCK_DGRAM; -import static com.android.internal.util.Preconditions.checkNotNull; - import android.annotation.NonNull; import android.app.AppOpsManager; import android.content.Context; @@ -76,6 +74,7 @@ import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * A service to manage multiple clients that want to access the IpSec API. The service is @@ -566,7 +565,7 @@ public class IpSecService extends IIpSecService.Stub { } void put(int key, RefcountedResource<T> obj) { - checkNotNull(obj, "Null resources cannot be added"); + Objects.requireNonNull(obj, "Null resources cannot be added"); mArray.put(key, obj); } @@ -1101,7 +1100,7 @@ public class IpSecService extends IIpSecService.Stub { if (requestedSpi > 0 && requestedSpi < 256) { throw new IllegalArgumentException("ESP SPI must not be in the range of 0-255."); } - checkNotNull(binder, "Null Binder passed to allocateSecurityParameterIndex"); + Objects.requireNonNull(binder, "Null Binder passed to allocateSecurityParameterIndex"); int callingUid = Binder.getCallingUid(); UserRecord userRecord = mUserResourceTracker.getUserRecord(callingUid); @@ -1218,7 +1217,7 @@ public class IpSecService extends IIpSecService.Stub { throw new IllegalArgumentException( "Specified port number must be a valid non-reserved UDP port"); } - checkNotNull(binder, "Null Binder passed to openUdpEncapsulationSocket"); + Objects.requireNonNull(binder, "Null Binder passed to openUdpEncapsulationSocket"); int callingUid = Binder.getCallingUid(); UserRecord userRecord = mUserResourceTracker.getUserRecord(callingUid); @@ -1278,8 +1277,8 @@ public class IpSecService extends IIpSecService.Stub { String localAddr, String remoteAddr, Network underlyingNetwork, IBinder binder, String callingPackage) { enforceTunnelFeatureAndPermissions(callingPackage); - checkNotNull(binder, "Null Binder passed to createTunnelInterface"); - checkNotNull(underlyingNetwork, "No underlying network was specified"); + Objects.requireNonNull(binder, "Null Binder passed to createTunnelInterface"); + Objects.requireNonNull(underlyingNetwork, "No underlying network was specified"); checkInetAddress(localAddr); checkInetAddress(remoteAddr); @@ -1556,7 +1555,7 @@ public class IpSecService extends IIpSecService.Stub { "IPsec Tunnel Mode requires PackageManager.FEATURE_IPSEC_TUNNELS"); } - checkNotNull(callingPackage, "Null calling package cannot create IpSec tunnels"); + Objects.requireNonNull(callingPackage, "Null calling package cannot create IpSec tunnels"); switch (getAppOpsManager().noteOp(TUNNEL_OP, Binder.getCallingUid(), callingPackage)) { case AppOpsManager.MODE_DEFAULT: mContext.enforceCallingOrSelfPermission( @@ -1625,12 +1624,12 @@ public class IpSecService extends IIpSecService.Stub { @Override public synchronized IpSecTransformResponse createTransform( IpSecConfig c, IBinder binder, String callingPackage) throws RemoteException { - checkNotNull(c); + Objects.requireNonNull(c); if (c.getMode() == IpSecTransform.MODE_TUNNEL) { enforceTunnelFeatureAndPermissions(callingPackage); } checkIpSecConfig(c); - checkNotNull(binder, "Null Binder passed to createTransform"); + Objects.requireNonNull(binder, "Null Binder passed to createTransform"); final int resourceId = mNextResourceId++; UserRecord userRecord = mUserResourceTracker.getUserRecord(Binder.getCallingUid()); diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index cad917b073a5..c5f1923b0b98 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -23,7 +23,6 @@ import static android.location.LocationManager.NETWORK_PROVIDER; import static android.location.LocationManager.PASSIVE_PROVIDER; import static android.os.PowerManager.locationPowerSaveModeToString; -import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.internal.util.Preconditions.checkState; import android.Manifest; @@ -121,6 +120,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.concurrent.TimeUnit; /** @@ -821,7 +821,7 @@ public class LocationManagerService extends ILocationManager.Stub { @GuardedBy("mLock") public void attachLocked(AbstractLocationProvider provider) { - checkNotNull(provider); + Objects.requireNonNull(provider); checkState(mProvider == null); if (D) { @@ -1430,7 +1430,7 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public boolean addGnssBatchingCallback(IBatchedLocationCallback callback, String packageName, String featureId, String listenerIdentifier) { - Preconditions.checkNotNull(listenerIdentifier); + Objects.requireNonNull(listenerIdentifier); return mGnssManagerService == null ? false : mGnssManagerService.addGnssBatchingCallback( callback, packageName, featureId, listenerIdentifier); @@ -2119,7 +2119,7 @@ public class LocationManagerService extends ILocationManager.Stub { public void requestLocationUpdates(LocationRequest request, ILocationListener listener, PendingIntent intent, String packageName, String featureId, String listenerIdentifier) { - Preconditions.checkNotNull(listenerIdentifier); + Objects.requireNonNull(listenerIdentifier); synchronized (mLock) { if (request == null) request = DEFAULT_LOCATION_REQUEST; @@ -2470,7 +2470,7 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public void requestGeofence(LocationRequest request, Geofence geofence, PendingIntent intent, String packageName, String featureId, String listenerIdentifier) { - Preconditions.checkNotNull(listenerIdentifier); + Objects.requireNonNull(listenerIdentifier); if (request == null) request = DEFAULT_LOCATION_REQUEST; int allowedResolutionLevel = getCallerAllowedResolutionLevel(); @@ -2567,7 +2567,7 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public boolean addGnssMeasurementsListener(IGnssMeasurementsListener listener, String packageName, String featureId, String listenerIdentifier) { - Preconditions.checkNotNull(listenerIdentifier); + Objects.requireNonNull(listenerIdentifier); return mGnssManagerService == null ? false : mGnssManagerService.addGnssMeasurementsListener(listener, packageName, featureId, @@ -2600,7 +2600,7 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public boolean addGnssNavigationMessageListener(IGnssNavigationMessageListener listener, String packageName, String featureId, String listenerIdentifier) { - Preconditions.checkNotNull(listenerIdentifier); + Objects.requireNonNull(listenerIdentifier); return mGnssManagerService == null ? false : mGnssManagerService.addGnssNavigationMessageListener(listener, packageName, diff --git a/services/core/java/com/android/server/NativeDaemonConnector.java b/services/core/java/com/android/server/NativeDaemonConnector.java index ad02aad6e4cd..eac767f7355c 100644 --- a/services/core/java/com/android/server/NativeDaemonConnector.java +++ b/services/core/java/com/android/server/NativeDaemonConnector.java @@ -46,6 +46,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.LinkedList; +import java.util.Objects; /** * Generic connector class for interfacing with a native daemon which uses the @@ -126,7 +127,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo */ public void setWarnIfHeld(Object warnIfHeld) { Preconditions.checkState(mWarnIfHeld == null); - mWarnIfHeld = Preconditions.checkNotNull(warnIfHeld); + mWarnIfHeld = Objects.requireNonNull(warnIfHeld); } @Override diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java index 0d496b6b427d..1f736502ae42 100644 --- a/services/core/java/com/android/server/NetworkManagementService.java +++ b/services/core/java/com/android/server/NetworkManagementService.java @@ -109,6 +109,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * @hide @@ -456,7 +457,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub { @Override public void registerTetheringStatsProvider(ITetheringStatsProvider provider, String name) { NetworkStack.checkNetworkStackPermission(mContext); - Preconditions.checkNotNull(provider); + Objects.requireNonNull(provider); synchronized(mTetheringStatsProviders) { mTetheringStatsProviders.put(provider, name); } diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index 22fa8ff4a0fa..c474f473e11a 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -2102,7 +2102,7 @@ class StorageManagerService extends IStorageManager.Stub public void setVolumeNickname(String fsUuid, String nickname) { enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); - Preconditions.checkNotNull(fsUuid); + Objects.requireNonNull(fsUuid); synchronized (mLock) { final VolumeRecord rec = mRecords.get(fsUuid); rec.nickname = nickname; @@ -2115,7 +2115,7 @@ class StorageManagerService extends IStorageManager.Stub public void setVolumeUserFlags(String fsUuid, int flags, int mask) { enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); - Preconditions.checkNotNull(fsUuid); + Objects.requireNonNull(fsUuid); synchronized (mLock) { final VolumeRecord rec = mRecords.get(fsUuid); rec.userFlags = (rec.userFlags & ~mask) | (flags & mask); @@ -2128,7 +2128,7 @@ class StorageManagerService extends IStorageManager.Stub public void forgetVolume(String fsUuid) { enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS); - Preconditions.checkNotNull(fsUuid); + Objects.requireNonNull(fsUuid); synchronized (mLock) { final VolumeRecord rec = mRecords.remove(fsUuid); @@ -2534,7 +2534,7 @@ class StorageManagerService extends IStorageManager.Stub @Override public String getMountedObbPath(String rawPath) { - Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); + Objects.requireNonNull(rawPath, "rawPath cannot be null"); warnOnNotMounted(); @@ -2552,7 +2552,7 @@ class StorageManagerService extends IStorageManager.Stub @Override public boolean isObbMounted(String rawPath) { - Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); + Objects.requireNonNull(rawPath, "rawPath cannot be null"); synchronized (mObbMounts) { return mObbPathToStateMap.containsKey(rawPath); } @@ -2561,10 +2561,10 @@ class StorageManagerService extends IStorageManager.Stub @Override public void mountObb(String rawPath, String canonicalPath, String key, IObbActionListener token, int nonce, ObbInfo obbInfo) { - Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); - Preconditions.checkNotNull(canonicalPath, "canonicalPath cannot be null"); - Preconditions.checkNotNull(token, "token cannot be null"); - Preconditions.checkNotNull(obbInfo, "obbIfno cannot be null"); + Objects.requireNonNull(rawPath, "rawPath cannot be null"); + Objects.requireNonNull(canonicalPath, "canonicalPath cannot be null"); + Objects.requireNonNull(token, "token cannot be null"); + Objects.requireNonNull(obbInfo, "obbIfno cannot be null"); final int callingUid = Binder.getCallingUid(); final ObbState obbState = new ObbState(rawPath, canonicalPath, @@ -2578,7 +2578,7 @@ class StorageManagerService extends IStorageManager.Stub @Override public void unmountObb(String rawPath, boolean force, IObbActionListener token, int nonce) { - Preconditions.checkNotNull(rawPath, "rawPath cannot be null"); + Objects.requireNonNull(rawPath, "rawPath cannot be null"); final ObbState existingState; synchronized (mObbMounts) { diff --git a/services/core/java/com/android/server/SystemServerInitThreadPool.java b/services/core/java/com/android/server/SystemServerInitThreadPool.java index 5ed94e380b5b..179780d88084 100644 --- a/services/core/java/com/android/server/SystemServerInitThreadPool.java +++ b/services/core/java/com/android/server/SystemServerInitThreadPool.java @@ -28,6 +28,7 @@ import com.android.server.am.ActivityManagerService; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -73,7 +74,7 @@ public class SystemServerInitThreadPool { */ public static @NonNull Future<?> submit(@NonNull Runnable runnable, @NonNull String description) { - Preconditions.checkNotNull(description, "description cannot be null"); + Objects.requireNonNull(description, "description cannot be null"); SystemServerInitThreadPool instance; synchronized (LOCK) { diff --git a/services/core/java/com/android/server/TestNetworkService.java b/services/core/java/com/android/server/TestNetworkService.java index d19d2ddd7c3c..c27b0da780b7 100644 --- a/services/core/java/com/android/server/TestNetworkService.java +++ b/services/core/java/com/android/server/TestNetworkService.java @@ -16,8 +16,6 @@ package com.android.server; -import static com.android.internal.util.Preconditions.checkNotNull; - import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; @@ -55,6 +53,7 @@ import java.net.InterfaceAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; +import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; /** @hide */ @@ -82,9 +81,9 @@ class TestNetworkService extends ITestNetworkManager.Stub { mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); - mContext = checkNotNull(context, "missing Context"); - mNMS = checkNotNull(netManager, "missing INetworkManagementService"); - mNetd = checkNotNull(NetdService.getInstance(), "could not get netd instance"); + mContext = Objects.requireNonNull(context, "missing Context"); + mNMS = Objects.requireNonNull(netManager, "missing INetworkManagementService"); + mNetd = Objects.requireNonNull(NetdService.getInstance(), "could not get netd instance"); } /** @@ -96,7 +95,7 @@ class TestNetworkService extends ITestNetworkManager.Stub { private TestNetworkInterface createInterface(boolean isTun, LinkAddress[] linkAddrs) { enforceTestNetworkPermissions(mContext); - checkNotNull(linkAddrs, "missing linkAddrs"); + Objects.requireNonNull(linkAddrs, "missing linkAddrs"); String ifacePrefix = isTun ? TEST_TUN_PREFIX : TEST_TAP_PREFIX; String iface = ifacePrefix + sTestTunIndex.getAndIncrement(); @@ -233,8 +232,8 @@ class TestNetworkService extends ITestNetworkManager.Stub { int callingUid, @NonNull IBinder binder) throws RemoteException, SocketException { - checkNotNull(looper, "missing Looper"); - checkNotNull(context, "missing Context"); + Objects.requireNonNull(looper, "missing Looper"); + Objects.requireNonNull(context, "missing Context"); // iface and binder validity checked by caller // Build network info with special testing type @@ -267,7 +266,7 @@ class TestNetworkService extends ITestNetworkManager.Stub { // Find the currently assigned addresses, and add them to LinkProperties boolean allowIPv4 = false, allowIPv6 = false; NetworkInterface netIntf = NetworkInterface.getByName(iface); - checkNotNull(netIntf, "No such network interface found: " + netIntf); + Objects.requireNonNull(netIntf, "No such network interface found: " + netIntf); for (InterfaceAddress intfAddr : netIntf.getInterfaceAddresses()) { lp.addLinkAddress( @@ -305,8 +304,8 @@ class TestNetworkService extends ITestNetworkManager.Stub { @NonNull IBinder binder) { enforceTestNetworkPermissions(mContext); - checkNotNull(iface, "missing Iface"); - checkNotNull(binder, "missing IBinder"); + Objects.requireNonNull(iface, "missing Iface"); + Objects.requireNonNull(binder, "missing IBinder"); if (!(iface.startsWith(INetd.IPSEC_INTERFACE_PREFIX) || iface.startsWith(TEST_TUN_PREFIX))) { diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java index 5996b7d848ea..a372fca07728 100644 --- a/services/core/java/com/android/server/accounts/AccountManagerService.java +++ b/services/core/java/com/android/server/accounts/AccountManagerService.java @@ -463,7 +463,7 @@ public class AccountManagerService Log.v(TAG, "addAccountExplicitly: " + account + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } - Preconditions.checkNotNull(account, "account cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); if (!isAccountManagedByCaller(account.type, callingUid, userId)) { String msg = String.format("uid %s cannot explicitly add accounts of type: %s", callingUid, account.type); @@ -544,7 +544,7 @@ public class AccountManagerService @Override public Map<String, Integer> getPackagesAndVisibilityForAccount(Account account) { - Preconditions.checkNotNull(account, "account cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); int callingUid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId) @@ -590,8 +590,8 @@ public class AccountManagerService @Override public int getAccountVisibility(Account account, String packageName) { - Preconditions.checkNotNull(account, "account cannot be null"); - Preconditions.checkNotNull(packageName, "packageName cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); + Objects.requireNonNull(packageName, "packageName cannot be null"); int callingUid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId) @@ -659,7 +659,7 @@ public class AccountManagerService */ private Integer resolveAccountVisibility(Account account, @NonNull String packageName, UserAccounts accounts) { - Preconditions.checkNotNull(packageName, "packageName cannot be null"); + Objects.requireNonNull(packageName, "packageName cannot be null"); int uid = -1; try { long identityToken = clearCallingIdentity(); @@ -755,8 +755,8 @@ public class AccountManagerService @Override public boolean setAccountVisibility(Account account, String packageName, int newVisibility) { - Preconditions.checkNotNull(account, "account cannot be null"); - Preconditions.checkNotNull(packageName, "packageName cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); + Objects.requireNonNull(packageName, "packageName cannot be null"); int callingUid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId) @@ -1525,7 +1525,7 @@ public class AccountManagerService + ", caller's uid " + Binder.getCallingUid() + ", pid " + Binder.getCallingPid()); } - Preconditions.checkNotNull(account, "account cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); int userId = UserHandle.getCallingUserId(); long identityToken = clearCallingIdentity(); try { @@ -1563,8 +1563,8 @@ public class AccountManagerService account, key, callingUid, Binder.getCallingPid()); Log.v(TAG, msg); } - Preconditions.checkNotNull(account, "account cannot be null"); - Preconditions.checkNotNull(key, "key cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); + Objects.requireNonNull(key, "key cannot be null"); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId)) { String msg = String.format( @@ -1715,7 +1715,7 @@ public class AccountManagerService callingUid); Log.v(TAG, msg); } - Preconditions.checkNotNull(account, "account cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId)) { String msg = String.format( @@ -2401,8 +2401,8 @@ public class AccountManagerService @Override public void invalidateAuthToken(String accountType, String authToken) { int callerUid = Binder.getCallingUid(); - Preconditions.checkNotNull(accountType, "accountType cannot be null"); - Preconditions.checkNotNull(authToken, "authToken cannot be null"); + Objects.requireNonNull(accountType, "accountType cannot be null"); + Objects.requireNonNull(authToken, "authToken cannot be null"); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "invalidateAuthToken: accountType " + accountType + ", caller's uid " + callerUid @@ -2518,8 +2518,8 @@ public class AccountManagerService + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } - Preconditions.checkNotNull(account, "account cannot be null"); - Preconditions.checkNotNull(authTokenType, "authTokenType cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); + Objects.requireNonNull(authTokenType, "authTokenType cannot be null"); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId)) { String msg = String.format( @@ -2551,8 +2551,8 @@ public class AccountManagerService + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } - Preconditions.checkNotNull(account, "account cannot be null"); - Preconditions.checkNotNull(authTokenType, "authTokenType cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); + Objects.requireNonNull(authTokenType, "authTokenType cannot be null"); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId)) { String msg = String.format( @@ -2578,7 +2578,7 @@ public class AccountManagerService + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } - Preconditions.checkNotNull(account, "account cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId)) { String msg = String.format( @@ -2644,7 +2644,7 @@ public class AccountManagerService + ", caller's uid " + callingUid + ", pid " + Binder.getCallingPid()); } - Preconditions.checkNotNull(account, "account cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); int userId = UserHandle.getCallingUserId(); if (!isAccountManagedByCaller(account.type, callingUid, userId)) { String msg = String.format( @@ -3946,9 +3946,9 @@ public class AccountManagerService if (UserHandle.getAppId(Binder.getCallingUid()) != Process.SYSTEM_UID) { throw new SecurityException("Can be called only by system UID"); } - Preconditions.checkNotNull(account, "account cannot be null"); - Preconditions.checkNotNull(packageName, "packageName cannot be null"); - Preconditions.checkNotNull(userHandle, "userHandle cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); + Objects.requireNonNull(packageName, "packageName cannot be null"); + Objects.requireNonNull(userHandle, "userHandle cannot be null"); final int userId = userHandle.getIdentifier(); @@ -4022,9 +4022,9 @@ public class AccountManagerService throw new SecurityException("Can be called only by system UID"); } - Preconditions.checkNotNull(account, "account cannot be null"); - Preconditions.checkNotNull(packageName, "packageName cannot be null"); - Preconditions.checkNotNull(userHandle, "userHandle cannot be null"); + Objects.requireNonNull(account, "account cannot be null"); + Objects.requireNonNull(packageName, "packageName cannot be null"); + Objects.requireNonNull(userHandle, "userHandle cannot be null"); final int userId = userHandle.getIdentifier(); diff --git a/services/core/java/com/android/server/accounts/CryptoHelper.java b/services/core/java/com/android/server/accounts/CryptoHelper.java index 2ade673523ac..863d6b9cd68f 100644 --- a/services/core/java/com/android/server/accounts/CryptoHelper.java +++ b/services/core/java/com/android/server/accounts/CryptoHelper.java @@ -10,6 +10,7 @@ import com.android.internal.util.Preconditions; import java.security.GeneralSecurityException; import java.security.NoSuchAlgorithmException; +import java.util.Objects; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; @@ -54,7 +55,7 @@ import javax.crypto.spec.IvParameterSpec; @NonNull /* default */ Bundle encryptBundle(@NonNull Bundle bundle) throws GeneralSecurityException { - Preconditions.checkNotNull(bundle, "Cannot encrypt null bundle."); + Objects.requireNonNull(bundle, "Cannot encrypt null bundle."); Parcel parcel = Parcel.obtain(); bundle.writeToParcel(parcel, 0); byte[] clearBytes = parcel.marshall(); @@ -76,7 +77,7 @@ import javax.crypto.spec.IvParameterSpec; @Nullable /* default */ Bundle decryptBundle(@NonNull Bundle bundle) throws GeneralSecurityException { - Preconditions.checkNotNull(bundle, "Cannot decrypt null bundle."); + Objects.requireNonNull(bundle, "Cannot decrypt null bundle."); byte[] iv = bundle.getByteArray(KEY_IV); byte[] encryptedBytes = bundle.getByteArray(KEY_CIPHER); byte[] mac = bundle.getByteArray(KEY_MAC); diff --git a/services/core/java/com/android/server/accounts/TokenCache.java b/services/core/java/com/android/server/accounts/TokenCache.java index 2af2f38d8ba7..e38cf5f3ece5 100644 --- a/services/core/java/com/android/server/accounts/TokenCache.java +++ b/services/core/java/com/android/server/accounts/TokenCache.java @@ -193,7 +193,7 @@ import java.util.Objects; String packageName, byte[] sigDigest, long expiryMillis) { - Preconditions.checkNotNull(account); + Objects.requireNonNull(account); if (token == null || System.currentTimeMillis() > expiryMillis) { return; } diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index 79fe61072a44..a4c44fabfba6 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -111,6 +111,7 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -1785,7 +1786,7 @@ final class ActivityManagerShellCommand extends ShellCommand { } int runGetCurrentUser(PrintWriter pw) throws RemoteException { - UserInfo currentUser = Preconditions.checkNotNull(mInterface.getCurrentUser(), + UserInfo currentUser = Objects.requireNonNull(mInterface.getCurrentUser(), "Current user not set"); pw.println(currentUser.id); return 0; diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java index f9730a9cc3f5..eb1ab3863624 100644 --- a/services/core/java/com/android/server/am/UserController.java +++ b/services/core/java/com/android/server/am/UserController.java @@ -1723,7 +1723,7 @@ class UserController implements Handler.Callback { } void registerUserSwitchObserver(IUserSwitchObserver observer, String name) { - Preconditions.checkNotNull(name, "Observer name cannot be null"); + Objects.requireNonNull(name, "Observer name cannot be null"); checkCallingPermission(INTERACT_ACROSS_USERS_FULL, "registerUserSwitchObserver"); mUserSwitchObservers.register(observer, name); } diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index 9f23cdaf3b86..1e136617bf24 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -18,7 +18,6 @@ package com.android.server.appop; import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION; import static android.app.AppOpsManager.NoteOpEvent; -import static android.app.AppOpsManager.OpEventProxyInfo; import static android.app.AppOpsManager.OP_CAMERA; import static android.app.AppOpsManager.OP_COARSE_LOCATION; import static android.app.AppOpsManager.OP_FLAGS_ALL; @@ -26,6 +25,7 @@ import static android.app.AppOpsManager.OP_FLAG_SELF; import static android.app.AppOpsManager.OP_NONE; import static android.app.AppOpsManager.OP_PLAY_AUDIO; import static android.app.AppOpsManager.OP_RECORD_AUDIO; +import static android.app.AppOpsManager.OpEventProxyInfo; import static android.app.AppOpsManager.UID_STATE_BACKGROUND; import static android.app.AppOpsManager.UID_STATE_CACHED; import static android.app.AppOpsManager.UID_STATE_FOREGROUND; @@ -40,9 +40,12 @@ import static android.app.AppOpsManager.makeKey; import static android.app.AppOpsManager.modeToName; import static android.app.AppOpsManager.opToName; import static android.app.AppOpsManager.resolveFirstUnrestrictedUidState; +import static android.content.Intent.ACTION_PACKAGE_REMOVED; +import static android.content.Intent.EXTRA_REPLACING; import static android.content.pm.PermissionInfo.PROTECTION_DANGEROUS; import android.Manifest; +import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityManager; @@ -69,6 +72,8 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.PermissionInfo; import android.content.pm.UserInfo; +import android.content.pm.parsing.AndroidPackage; +import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; import android.database.ContentObserver; import android.hardware.camera2.CameraDevice.CAMERA_AUDIO_RESTRICTION; import android.net.Uri; @@ -98,6 +103,7 @@ import android.util.AtomicFile; import android.util.KeyValueListParser; import android.util.LongSparseArray; import android.util.Pair; +import android.util.Pools.SimplePool; import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; @@ -122,6 +128,7 @@ import com.android.internal.util.XmlUtils; import com.android.internal.util.function.pooled.PooledLambda; import com.android.server.LocalServices; import com.android.server.LockGuard; +import com.android.server.SystemServerInitThreadPool; import libcore.util.EmptyArray; @@ -195,11 +202,21 @@ public class AppOpsService extends IAppOpsService.Stub { }; private static final int MAX_UNFORWARED_OPS = 10; + private static final int MAX_UNUSED_POOLED_OBJECTS = 3; Context mContext; final AtomicFile mFile; final Handler mHandler; + /** Pool for {@link OpEventProxyInfoPool} to avoid to constantly reallocate new objects */ + @GuardedBy("this") + private final OpEventProxyInfoPool mOpEventProxyInfoPool = new OpEventProxyInfoPool(); + + /** Pool for {@link InProgressStartOpEventPool} to avoid to constantly reallocate new objects */ + @GuardedBy("this") + private final InProgressStartOpEventPool mInProgressStartOpEventPool = + new InProgressStartOpEventPool(); + private final AppOpsManagerInternalImpl mAppOpsManagerInternal = new AppOpsManagerInternalImpl(); @@ -266,6 +283,46 @@ public class AppOpsService extends IAppOpsService.Stub { private SparseArray<List<Integer>> mSwitchOpToOps; /** + * An unsynchronized pool of {@link OpEventProxyInfo} objects. + */ + private class OpEventProxyInfoPool extends SimplePool<OpEventProxyInfo> { + OpEventProxyInfoPool() { + super(MAX_UNUSED_POOLED_OBJECTS); + } + + OpEventProxyInfo acquire(@IntRange(from = 0) int uid, @Nullable String packageName, + @Nullable String featureId) { + OpEventProxyInfo recycled = acquire(); + if (recycled != null) { + recycled.reinit(uid, packageName, featureId); + return recycled; + } + + return new OpEventProxyInfo(uid, packageName, featureId); + } + } + + /** + * An unsynchronized pool of {@link InProgressStartOpEvent} objects. + */ + private class InProgressStartOpEventPool extends SimplePool<InProgressStartOpEvent> { + InProgressStartOpEventPool() { + super(MAX_UNUSED_POOLED_OBJECTS); + } + + InProgressStartOpEvent acquire(long startTime, long elapsedTime, @NonNull IBinder clientId, + @NonNull Runnable onDeath, int uidState) throws RemoteException { + InProgressStartOpEvent recycled = acquire(); + if (recycled != null) { + recycled.reinit(startTime, elapsedTime, clientId, onDeath, uidState); + return recycled; + } + + return new InProgressStartOpEvent(startTime, elapsedTime, clientId, onDeath, uidState); + } + } + + /** * All times are in milliseconds. These constants are kept synchronized with the system * global Settings. Any access to this class or its fields should be done while * holding the AppOpsService lock. @@ -468,6 +525,9 @@ public class AppOpsService extends IAppOpsService.Stub { final UidState uidState; final boolean isPrivileged; + /** Lazily populated cache of featureIds of this package */ + final @NonNull ArraySet<String> knownFeatureIds = new ArraySet<>(); + Ops(String _packageName, UidState _uidState, boolean _isPrivileged) { packageName = _packageName; uidState = _uidState; @@ -477,39 +537,97 @@ public class AppOpsService extends IAppOpsService.Stub { /** A in progress startOp->finishOp event */ private static final class InProgressStartOpEvent implements IBinder.DeathRecipient { - /** Time of startOp event */ - final long startTime; + /** Wall clock time of startOp event (not monotonic) */ + private long mStartTime; + + /** Elapsed time since boot of startOp event */ + private long mStartElapsedTime; /** Id of the client that started the event */ - final @NonNull IBinder clientId; + private @NonNull IBinder mClientId; /** To call when client dies */ - final @NonNull Runnable onDeath; + private @NonNull Runnable mOnDeath; /** uidstate used when calling startOp */ - final @AppOpsManager.UidState int uidState; + private @AppOpsManager.UidState int mUidState; /** How many times the op was started but not finished yet */ int numUnfinishedStarts; - private InProgressStartOpEvent(long startTime, @NonNull IBinder clientId, - @NonNull Runnable onDeath, int uidState) throws RemoteException { - this.startTime = startTime; - this.clientId = clientId; - this.onDeath = onDeath; - this.uidState = uidState; + /** + * Create a new {@link InProgressStartOpEvent}. + * + * @param startTime The time {@link #startOperation} was called + * @param startElapsedTime The elapsed time when {@link #startOperation} was called + * @param clientId The client id of the caller of {@link #startOperation} + * @param onDeath The code to execute on client death + * @param uidState The uidstate of the app {@link #startOperation} was called for + * + * @throws RemoteException If the client is dying + */ + private InProgressStartOpEvent(long startTime, long startElapsedTime, + @NonNull IBinder clientId, @NonNull Runnable onDeath, int uidState) + throws RemoteException { + mStartTime = startTime; + mStartElapsedTime = startElapsedTime; + mClientId = clientId; + mOnDeath = onDeath; + mUidState = uidState; clientId.linkToDeath(this, 0); } /** Clean up event */ public void finish() { - clientId.unlinkToDeath(this, 0); + mClientId.unlinkToDeath(this, 0); } @Override public void binderDied() { - onDeath.run(); + mOnDeath.run(); + } + + /** + * Reinit existing object with new state. + * + * @param startTime The time {@link #startOperation} was called + * @param startElapsedTime The elapsed time when {@link #startOperation} was called + * @param clientId The client id of the caller of {@link #startOperation} + * @param onDeath The code to execute on client death + * @param uidState The uidstate of the app {@link #startOperation} was called for + * + * @throws RemoteException If the client is dying + */ + public void reinit(long startTime, long startElapsedTime, @NonNull IBinder clientId, + @NonNull Runnable onDeath, int uidState) throws RemoteException { + mStartTime = startTime; + mStartElapsedTime = startElapsedTime; + mClientId = clientId; + mOnDeath = onDeath; + mUidState = uidState; + + clientId.linkToDeath(this, 0); + } + + /** @return Wall clock time of startOp event */ + public long getStartTime() { + return mStartTime; + } + + /** @return Elapsed time since boot of startOp event */ + public long getStartElapsedTime() { + return mStartElapsedTime; + } + + /** @return Id of the client that started the event */ + public @NonNull IBinder getClientId() { + return mClientId; + } + + /** @return uidstate used when calling startOp */ + public int getUidState() { + return mUidState; } } @@ -522,7 +640,7 @@ public class AppOpsService extends IAppOpsService.Stub { * <p>Key is {@link AppOpsManager#makeKey} */ @GuardedBy("AppOpsService.this") - private @Nullable LongSparseArray<AppOpsManager.NoteOpEvent> mAccessEvents; + private @Nullable LongSparseArray<NoteOpEvent> mAccessEvents; /** * Last rejected accesses for each uidState/opFlag combination @@ -530,7 +648,7 @@ public class AppOpsService extends IAppOpsService.Stub { * <p>Key is {@link AppOpsManager#makeKey} */ @GuardedBy("AppOpsService.this") - private @Nullable LongSparseArray<AppOpsManager.NoteOpEvent> mRejectEvents; + private @Nullable LongSparseArray<NoteOpEvent> mRejectEvents; /** * Currently in progress startOp events @@ -582,9 +700,16 @@ public class AppOpsService extends IAppOpsService.Stub { OpEventProxyInfo proxyInfo = null; if (proxyUid != Process.INVALID_UID) { - proxyInfo = new OpEventProxyInfo(proxyUid, proxyPackageName, proxyFeatureId); + proxyInfo = mOpEventProxyInfoPool.acquire(proxyUid, proxyPackageName, + proxyFeatureId); + } + + NoteOpEvent existingEvent = mAccessEvents.get(key); + if (existingEvent != null) { + existingEvent.reinit(noteTime, duration, proxyInfo, mOpEventProxyInfoPool); + } else { + mAccessEvents.put(key, new NoteOpEvent(noteTime, duration, proxyInfo)); } - mAccessEvents.put(key, new NoteOpEvent(noteTime, duration, proxyInfo)); } /** @@ -613,7 +738,12 @@ public class AppOpsService extends IAppOpsService.Stub { } // We do not collect proxy information for rejections yet - mRejectEvents.put(key, new NoteOpEvent(noteTime, -1, null)); + NoteOpEvent existingEvent = mRejectEvents.get(key); + if (existingEvent != null) { + existingEvent.reinit(noteTime, -1, null, mOpEventProxyInfoPool); + } else { + mRejectEvents.put(key, new NoteOpEvent(noteTime, -1, null)); + } } /** @@ -633,27 +763,15 @@ public class AppOpsService extends IAppOpsService.Stub { mInProgressEvents = new ArrayMap<>(1); } - InProgressStartOpEvent event = mInProgressEvents.get(clientId); if (event == null) { - event = new InProgressStartOpEvent(System.currentTimeMillis(), clientId, () -> { - // In the case the client dies without calling finish first - synchronized (AppOpsService.this) { - if (mInProgressEvents == null) { - return; - } - - InProgressStartOpEvent deadEvent = mInProgressEvents.get(clientId); - if (deadEvent != null) { - deadEvent.numUnfinishedStarts = 1; - } - - finished(clientId); - } - }, uidState); + event = mInProgressStartOpEventPool.acquire(System.currentTimeMillis(), + SystemClock.elapsedRealtime(), clientId, + PooledLambda.obtainRunnable(AppOpsService::onClientDeath, this, clientId), + uidState); mInProgressEvents.put(clientId, event); } else { - if (uidState != event.uidState) { + if (uidState != event.mUidState) { onUidStateChanged(uidState); } } @@ -697,13 +815,15 @@ public class AppOpsService extends IAppOpsService.Stub { } // startOp events don't support proxy, hence use flags==SELF - NoteOpEvent finishedEvent = new NoteOpEvent(event.startTime, - System.currentTimeMillis() - event.startTime, null); - mAccessEvents.put(makeKey(event.uidState, OP_FLAG_SELF), finishedEvent); + NoteOpEvent finishedEvent = new NoteOpEvent(event.getStartTime(), + SystemClock.elapsedRealtime() - event.getStartElapsedTime(), null); + mAccessEvents.put(makeKey(event.getUidState(), OP_FLAG_SELF), finishedEvent); mHistoricalRegistry.increaseOpAccessDuration(parent.op, parent.uid, - parent.packageName, event.uidState, AppOpsManager.OP_FLAG_SELF, - finishedEvent.duration); + parent.packageName, event.getUidState(), AppOpsManager.OP_FLAG_SELF, + finishedEvent.getDuration()); + + mInProgressStartOpEventPool.release(event); if (mInProgressEvents.isEmpty()) { mInProgressEvents = null; @@ -718,6 +838,26 @@ public class AppOpsService extends IAppOpsService.Stub { } /** + * Called in the case the client dies without calling finish first + * + * @param clientId The client that died + */ + void onClientDeath(@NonNull IBinder clientId) { + synchronized (AppOpsService.this) { + if (mInProgressEvents == null) { + return; + } + + InProgressStartOpEvent deadEvent = mInProgressEvents.get(clientId); + if (deadEvent != null) { + deadEvent.numUnfinishedStarts = 1; + } + + finished(clientId); + } + } + + /** * Notify that the state of the uid changed * * @param newState The new state @@ -731,10 +871,10 @@ public class AppOpsService extends IAppOpsService.Stub { for (int i = 0; i < numInProgressEvents; i++) { InProgressStartOpEvent event = mInProgressEvents.valueAt(i); - if (event.uidState != newState) { + if (event.getUidState() != newState) { try { - finished(event.clientId, false); - started(event.clientId, newState); + finished(event.getClientId(), false); + started(event.getClientId(), newState); } catch (RemoteException e) { if (DEBUG) Slog.e(TAG, "Cannot switch to new uidState " + newState); } @@ -742,6 +882,59 @@ public class AppOpsService extends IAppOpsService.Stub { } } + /** + * Combine {@code a} and {@code b} and return the result. The result might be {@code a} + * or {@code b}. If there is an event for the same key in both the later event is retained. + */ + private @Nullable LongSparseArray<NoteOpEvent> add(@Nullable LongSparseArray<NoteOpEvent> a, + @Nullable LongSparseArray<NoteOpEvent> b) { + if (a == null) { + return b; + } + + if (b == null) { + return a; + } + + int numEventsToAdd = b.size(); + for (int i = 0; i < numEventsToAdd; i++) { + long keyOfEventToAdd = b.keyAt(i); + NoteOpEvent bEvent = b.valueAt(i); + NoteOpEvent aEvent = a.get(keyOfEventToAdd); + + if (aEvent == null || bEvent.getNoteTime() > aEvent.getNoteTime()) { + a.put(keyOfEventToAdd, bEvent); + } + } + + return a; + } + + /** + * Add all data from the {@code featureToAdd} to this op. + * + * <p>If there is an event for the same key in both the later event is retained. + * <p>{@code opToAdd} should not be used after this method is called. + * + * @param opToAdd The op to add + */ + public void add(@NonNull FeatureOp opToAdd) { + if (opToAdd.mInProgressEvents != null) { + Slog.w(TAG, "Ignoring " + opToAdd.mInProgressEvents.size() + " running app-ops"); + + int numInProgressEvents = opToAdd.mInProgressEvents.size(); + for (int i = 0; i < numInProgressEvents; i++) { + InProgressStartOpEvent event = opToAdd.mInProgressEvents.valueAt(i); + + event.finish(); + mInProgressStartOpEventPool.release(event); + } + } + + mAccessEvents = add(mAccessEvents, opToAdd.mAccessEvents); + mRejectEvents = add(mRejectEvents, opToAdd.mRejectEvents); + } + public boolean isRunning() { return mInProgressEvents != null; } @@ -751,15 +944,30 @@ public class AppOpsService extends IAppOpsService.Stub { || (mRejectEvents != null && mRejectEvents.size() > 0); } - @NonNull OpFeatureEntry createFeatureEntryLocked() { - LongSparseArray<NoteOpEvent> accessEvents = null; - if (mAccessEvents != null) { - accessEvents = mAccessEvents.clone(); + /** + * Clone a {@link LongSparseArray} and clone all values. + */ + private @Nullable LongSparseArray<NoteOpEvent> deepClone( + @Nullable LongSparseArray<NoteOpEvent> original) { + if (original == null) { + return original; } + int size = original.size(); + LongSparseArray<NoteOpEvent> clone = new LongSparseArray<>(size); + for (int i = 0; i < size; i++) { + clone.put(original.keyAt(i), new NoteOpEvent(original.valueAt(i))); + } + + return clone; + } + + @NonNull OpFeatureEntry createFeatureEntryLocked() { + LongSparseArray<NoteOpEvent> accessEvents = deepClone(mAccessEvents); + // Add in progress events as access events if (mInProgressEvents != null) { - long now = System.currentTimeMillis(); + long now = SystemClock.elapsedRealtime(); int numInProgressEvents = mInProgressEvents.size(); if (accessEvents == null) { @@ -770,15 +978,13 @@ public class AppOpsService extends IAppOpsService.Stub { InProgressStartOpEvent event = mInProgressEvents.valueAt(i); // startOp events don't support proxy - accessEvents.append(makeKey(event.uidState, OP_FLAG_SELF), - new NoteOpEvent(event.startTime, now - event.startTime, null)); + accessEvents.append(makeKey(event.getUidState(), OP_FLAG_SELF), + new NoteOpEvent(event.getStartTime(), now - event.getStartElapsedTime(), + null)); } } - LongSparseArray<NoteOpEvent> rejectEvents = null; - if (mRejectEvents != null) { - rejectEvents = mRejectEvents.clone(); - } + LongSparseArray<NoteOpEvent> rejectEvents = deepClone(mRejectEvents); return new OpFeatureEntry(parent.op, isRunning(), accessEvents, rejectEvents); } @@ -1018,6 +1224,13 @@ public class AppOpsService extends IAppOpsService.Stub { } } + /** + * Call {@link FeatureOp#onClientDeath featureOp.onClientDeath(clientId)}. + */ + private static void onClientDeath(@NonNull FeatureOp featureOp, @NonNull IBinder clientId) { + featureOp.onClientDeath(clientId); + } + public AppOpsService(File storagePath, Handler handler) { LockGuard.installLock(this, LockGuard.INDEX_APP_OPS); mFile = new AtomicFile(storagePath, "appops"); @@ -1032,20 +1245,110 @@ public class AppOpsService extends IAppOpsService.Stub { LocalServices.addService(AppOpsManagerInternal.class, mAppOpsManagerInternal); } + /** Handler for work when packages are removed or updated */ + private BroadcastReceiver mOnPackageUpdatedReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + String pkgName = intent.getData().getEncodedSchemeSpecificPart(); + int uid = intent.getIntExtra(Intent.EXTRA_UID, Process.INVALID_UID); + + if (action.equals(ACTION_PACKAGE_REMOVED) && !intent.hasExtra(EXTRA_REPLACING)) { + synchronized (AppOpsService.this) { + UidState uidState = mUidStates.get(uid); + if (uidState == null || uidState.pkgOps == null) { + return; + } + + Ops removedOps = uidState.pkgOps.remove(pkgName); + if (removedOps != null) { + scheduleFastWriteLocked(); + } + } + } else if (action.equals(Intent.ACTION_PACKAGE_REPLACED)) { + AndroidPackage pkg = LocalServices.getService( + PackageManagerInternal.class).getPackage(pkgName); + if (pkg == null) { + return; + } + + ArrayMap<String, String> dstFeatureIds = new ArrayMap<>(); + ArraySet<String> featureIds = new ArraySet<>(); + if (pkg.getFeatures() != null) { + int numFeatures = pkg.getFeatures().size(); + for (int featureNum = 0; featureNum < numFeatures; featureNum++) { + ParsedFeature feature = pkg.getFeatures().get(featureNum); + featureIds.add(feature.id); + + int numInheritFrom = feature.inheritFrom.size(); + for (int inheritFromNum = 0; inheritFromNum < numInheritFrom; + inheritFromNum++) { + dstFeatureIds.put(feature.inheritFrom.get(inheritFromNum), + feature.id); + } + } + } + + synchronized (AppOpsService.this) { + UidState uidState = mUidStates.get(uid); + if (uidState == null || uidState.pkgOps == null) { + return; + } + + Ops ops = uidState.pkgOps.get(pkgName); + if (ops == null) { + return; + } + + ops.knownFeatureIds.clear(); + int numOps = ops.size(); + for (int opNum = 0; opNum < numOps; opNum++) { + Op op = ops.valueAt(opNum); + + int numFeatures = op.mFeatures.size(); + for (int featureNum = numFeatures - 1; featureNum >= 0; featureNum--) { + String featureId = op.mFeatures.keyAt(featureNum); + + if (featureIds.contains(featureId)) { + // feature still exist after upgrade + continue; + } + + String newFeatureId = dstFeatureIds.get(featureId); + + FeatureOp newFeatureOp = op.getOrCreateFeature(op, newFeatureId); + newFeatureOp.add(op.mFeatures.valueAt(featureNum)); + op.mFeatures.removeAt(featureNum); + + scheduleFastWriteLocked(); + } + } + } + } + } + }; + public void systemReady() { mConstants.startMonitoring(mContext.getContentResolver()); mHistoricalRegistry.systemReady(mContext.getContentResolver()); + IntentFilter packageUpdateFilter = new IntentFilter(); + packageUpdateFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); + packageUpdateFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); + packageUpdateFilter.addDataScheme("package"); + + mContext.registerReceiver(mOnPackageUpdatedReceiver, packageUpdateFilter); + synchronized (this) { - boolean changed = false; - for (int i = mUidStates.size() - 1; i >= 0; i--) { - UidState uidState = mUidStates.valueAt(i); + for (int uidNum = mUidStates.size() - 1; uidNum >= 0; uidNum--) { + int uid = mUidStates.keyAt(uidNum); + UidState uidState = mUidStates.valueAt(uidNum); - String[] packageNames = getPackagesForUid(uidState.uid); - if (ArrayUtils.isEmpty(packageNames)) { + String[] pkgsInUid = getPackagesForUid(uidState.uid); + if (ArrayUtils.isEmpty(pkgsInUid)) { uidState.clear(); - mUidStates.removeAt(i); - changed = true; + mUidStates.removeAt(uidNum); + scheduleFastWriteLocked(); continue; } @@ -1054,31 +1357,24 @@ public class AppOpsService extends IAppOpsService.Stub { continue; } - Iterator<Ops> it = pkgs.values().iterator(); - while (it.hasNext()) { - Ops ops = it.next(); - int curUid = -1; - try { - curUid = AppGlobals.getPackageManager().getPackageUid(ops.packageName, - PackageManager.MATCH_UNINSTALLED_PACKAGES, - UserHandle.getUserId(ops.uidState.uid)); - } catch (RemoteException ignored) { - } - if (curUid != ops.uidState.uid) { - Slog.i(TAG, "Pruning old package " + ops.packageName - + "/" + ops.uidState + ": new uid=" + curUid); - it.remove(); - changed = true; + int numPkgs = pkgs.size(); + for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) { + String pkg = pkgs.keyAt(pkgNum); + + String action; + if (!ArrayUtils.contains(pkgsInUid, pkg)) { + action = Intent.ACTION_PACKAGE_REMOVED; + } else { + action = Intent.ACTION_PACKAGE_REPLACED; } - } - if (uidState.isDefault()) { - mUidStates.removeAt(i); + SystemServerInitThreadPool.submit( + () -> mOnPackageUpdatedReceiver.onReceive(mContext, new Intent(action) + .setData(Uri.fromParts("package", pkg, null)) + .putExtra(Intent.EXTRA_UID, uid)), + "Update app-ops uidState in case package " + pkg + " changed"); } } - if (changed) { - scheduleFastWriteLocked(); - } } final IntentFilter packageSuspendFilter = new IntentFilter(); @@ -1192,7 +1488,7 @@ public class AppOpsService extends IAppOpsService.Stub { FeatureOp featureOp = op.mFeatures.valueAt(featureNum); while (featureOp.mInProgressEvents != null) { - featureOp.mInProgressEvents.valueAt(0).onDeath.run(); + featureOp.finished(featureOp.mInProgressEvents.keyAt(0)); } } } @@ -1382,7 +1678,7 @@ public class AppOpsService extends IAppOpsService.Stub { return Collections.emptyList(); } synchronized (this) { - Ops pkgOps = getOpsRawLocked(uid, resolvedPackageName, false /* isPrivileged */, + Ops pkgOps = getOpsRawLocked(uid, resolvedPackageName, null, false /* isPrivileged */, false /* edit */); if (pkgOps == null) { return null; @@ -1411,7 +1707,7 @@ public class AppOpsService extends IAppOpsService.Stub { .setOpNames(opNames) .setFlags(flags) .build(); - Preconditions.checkNotNull(callback, "callback cannot be null"); + Objects.requireNonNull(callback, "callback cannot be null"); mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS, Binder.getCallingPid(), Binder.getCallingUid(), "getHistoricalOps"); @@ -1436,7 +1732,7 @@ public class AppOpsService extends IAppOpsService.Stub { .setOpNames(opNames) .setFlags(flags) .build(); - Preconditions.checkNotNull(callback, "callback cannot be null"); + Objects.requireNonNull(callback, "callback cannot be null"); mContext.enforcePermission(Manifest.permission.MANAGE_APPOPS, Binder.getCallingPid(), Binder.getCallingUid(), "getHistoricalOps"); @@ -1482,7 +1778,7 @@ public class AppOpsService extends IAppOpsService.Stub { op.removeFeaturesWithNoTime(); if (op.mFeatures.size() == 0) { - Ops ops = getOpsRawLocked(uid, packageName, false /* isPrivileged */, + Ops ops = getOpsRawLocked(uid, packageName, null, false /* isPrivileged */, false /* edit */); if (ops != null) { ops.remove(op.op); @@ -1746,7 +2042,7 @@ public class AppOpsService extends IAppOpsService.Stub { boolean isPrivileged; try { - isPrivileged = verifyAndGetIsPrivileged(uid, packageName); + isPrivileged = verifyAndGetIsPrivileged(uid, packageName, null); } catch (SecurityException e) { Slog.e(TAG, "Cannot setMode", e); return; @@ -1761,7 +2057,7 @@ public class AppOpsService extends IAppOpsService.Stub { synchronized (this) { UidState uidState = getUidStateLocked(uid, false); - Op op = getOpLocked(code, uid, packageName, isPrivileged, true); + Op op = getOpLocked(code, uid, packageName, null, isPrivileged, true); if (op != null) { if (op.mode != mode) { op.mode = mode; @@ -2131,7 +2427,7 @@ public class AppOpsService extends IAppOpsService.Stub { boolean isPrivileged; try { - isPrivileged = verifyAndGetIsPrivileged(uid, packageName); + isPrivileged = verifyAndGetIsPrivileged(uid, packageName, null); } catch (SecurityException e) { Slog.e(TAG, "checkOperation", e); return AppOpsManager.opToDefaultMode(code); @@ -2141,7 +2437,7 @@ public class AppOpsService extends IAppOpsService.Stub { return AppOpsManager.MODE_IGNORED; } synchronized (this) { - if (isOpRestrictedLocked(uid, code, packageName, isPrivileged)) { + if (isOpRestrictedLocked(uid, code, packageName, null, isPrivileged)) { return AppOpsManager.MODE_IGNORED; } code = AppOpsManager.opToSwitch(code); @@ -2151,7 +2447,7 @@ public class AppOpsService extends IAppOpsService.Stub { final int rawMode = uidState.opModes.get(code); return raw ? rawMode : uidState.evalMode(code, rawMode); } - Op op = getOpLocked(code, uid, packageName, false, false); + Op op = getOpLocked(code, uid, packageName, null, false, false); if (op == null) { return AppOpsManager.opToDefaultMode(code); } @@ -2212,9 +2508,9 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public int checkPackage(int uid, String packageName) { - Preconditions.checkNotNull(packageName); + Objects.requireNonNull(packageName); try { - verifyAndGetIsPrivileged(uid, packageName); + verifyAndGetIsPrivileged(uid, packageName, null); return AppOpsManager.MODE_ALLOWED; } catch (SecurityException ignored) { @@ -2284,18 +2580,17 @@ public class AppOpsService extends IAppOpsService.Stub { private int noteOperationUnchecked(int code, int uid, String packageName, String featureId, int proxyUid, String proxyPackageName, @Nullable String proxyFeatureId, @OpFlags int flags) { - // TODO moltmann: Verify that feature is declared in package - boolean isPrivileged; try { - isPrivileged = verifyAndGetIsPrivileged(uid, packageName); + isPrivileged = verifyAndGetIsPrivileged(uid, packageName, featureId); } catch (SecurityException e) { Slog.e(TAG, "noteOperation", e); return AppOpsManager.MODE_ERRORED; } synchronized (this) { - final Ops ops = getOpsRawLocked(uid, packageName, isPrivileged, true /* edit */); + final Ops ops = getOpsRawLocked(uid, packageName, featureId, isPrivileged, + true /* edit */); if (ops == null) { scheduleOpNotedIfNeededLocked(code, uid, packageName, AppOpsManager.MODE_IGNORED); @@ -2303,9 +2598,9 @@ public class AppOpsService extends IAppOpsService.Stub { + " package " + packageName); return AppOpsManager.MODE_ERRORED; } - final Op op = getOpLocked(ops, code, true); + final Op op = getOpLocked(ops, code, uid, true); final FeatureOp featureOp = op.getOrCreateFeature(op, featureId); - if (isOpRestrictedLocked(uid, code, packageName, isPrivileged)) { + if (isOpRestrictedLocked(uid, code, packageName, featureId, isPrivileged)) { scheduleOpNotedIfNeededLocked(code, uid, packageName, AppOpsManager.MODE_IGNORED); return AppOpsManager.MODE_IGNORED; @@ -2314,7 +2609,7 @@ public class AppOpsService extends IAppOpsService.Stub { if (featureOp.isRunning()) { Slog.w(TAG, "Noting op not finished: uid " + uid + " pkg " + packageName + " code " + code + " startTime of in progress event=" - + featureOp.mInProgressEvents.valueAt(0).startTime); + + featureOp.mInProgressEvents.valueAt(0).getStartTime()); } final int switchCode = AppOpsManager.opToSwitch(code); @@ -2333,7 +2628,8 @@ public class AppOpsService extends IAppOpsService.Stub { return uidMode; } } else { - final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, true) : op; + final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, uid, true) + : op; final int mode = switchOp.evalMode(); if (mode != AppOpsManager.MODE_ALLOWED) { if (DEBUG) Slog.d(TAG, "noteOperation: reject #" + mode + " for code " @@ -2419,7 +2715,7 @@ public class AppOpsService extends IAppOpsService.Stub { Preconditions.checkArgument(!ArrayUtils.isEmpty(ops), "Ops cannot be null or empty"); Preconditions.checkArrayElementsInRange(ops, 0, AppOpsManager._NUM_OP - 1, "Invalid op code in: " + Arrays.toString(ops)); - Preconditions.checkNotNull(callback, "Callback cannot be null"); + Objects.requireNonNull(callback, "Callback cannot be null"); synchronized (this) { SparseArray<NotedCallback> callbacks = mNotedWatchers.get(callback.asBinder()); if (callbacks == null) { @@ -2436,7 +2732,7 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public void stopWatchingNoted(IAppOpsNotedCallback callback) { - Preconditions.checkNotNull(callback, "Callback cannot be null"); + Objects.requireNonNull(callback, "Callback cannot be null"); synchronized (this) { final SparseArray<NotedCallback> notedCallbacks = mNotedWatchers.remove(callback.asBinder()); @@ -2453,8 +2749,8 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public void noteAsyncOp(String callingPackageName, int uid, String packageName, int opCode, String featureId, String message) { - Preconditions.checkNotNull(message); - verifyAndGetIsPrivileged(uid, packageName); + Objects.requireNonNull(message); + verifyAndGetIsPrivileged(uid, packageName, featureId); verifyIncomingUid(uid); verifyIncomingOp(opCode); @@ -2463,7 +2759,7 @@ public class AppOpsService extends IAppOpsService.Stub { long now = System.currentTimeMillis(); if (callingPackageName != null) { - verifyAndGetIsPrivileged(callingUid, callingPackageName); + verifyAndGetIsPrivileged(callingUid, callingPackageName, featureId); } long token = Binder.clearCallingIdentity(); @@ -2522,13 +2818,13 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public void startWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback) { - Preconditions.checkNotNull(packageName); - Preconditions.checkNotNull(callback); + Objects.requireNonNull(packageName); + Objects.requireNonNull(callback); int uid = Binder.getCallingUid(); Pair<String, Integer> key = getAsyncNotedOpsKey(packageName, uid); - verifyAndGetIsPrivileged(uid, packageName); + verifyAndGetIsPrivileged(uid, packageName, null); synchronized (this) { RemoteCallbackList<IAppOpsAsyncNotedCallback> callbacks = mAsyncOpWatchers.get(key); @@ -2552,13 +2848,13 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public void stopWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback) { - Preconditions.checkNotNull(packageName); - Preconditions.checkNotNull(callback); + Objects.requireNonNull(packageName); + Objects.requireNonNull(callback); int uid = Binder.getCallingUid(); Pair<String, Integer> key = getAsyncNotedOpsKey(packageName, uid); - verifyAndGetIsPrivileged(uid, packageName); + verifyAndGetIsPrivileged(uid, packageName, null); synchronized (this) { RemoteCallbackList<IAppOpsAsyncNotedCallback> callbacks = mAsyncOpWatchers.get(key); @@ -2573,11 +2869,11 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public List<AsyncNotedAppOp> extractAsyncOps(String packageName) { - Preconditions.checkNotNull(packageName); + Objects.requireNonNull(packageName); int uid = Binder.getCallingUid(); - verifyAndGetIsPrivileged(uid, packageName); + verifyAndGetIsPrivileged(uid, packageName, null); synchronized (this) { return mUnforwardedAsyncNotedOps.remove(getAsyncNotedOpsKey(packageName, uid)); @@ -2596,22 +2892,22 @@ public class AppOpsService extends IAppOpsService.Stub { boolean isPrivileged; try { - isPrivileged = verifyAndGetIsPrivileged(uid, packageName); + isPrivileged = verifyAndGetIsPrivileged(uid, packageName, featureId); } catch (SecurityException e) { Slog.e(TAG, "startOperation", e); return AppOpsManager.MODE_ERRORED; } synchronized (this) { - final Ops ops = getOpsRawLocked(uid, resolvedPackageName, isPrivileged, + final Ops ops = getOpsRawLocked(uid, resolvedPackageName, featureId, isPrivileged, true /* edit */); if (ops == null) { if (DEBUG) Slog.d(TAG, "startOperation: no op for code " + code + " uid " + uid + " package " + resolvedPackageName); return AppOpsManager.MODE_ERRORED; } - final Op op = getOpLocked(ops, code, true); - if (isOpRestrictedLocked(uid, code, resolvedPackageName, isPrivileged)) { + final Op op = getOpLocked(ops, code, uid, true); + if (isOpRestrictedLocked(uid, code, resolvedPackageName, featureId, isPrivileged)) { return AppOpsManager.MODE_IGNORED; } final FeatureOp featureOp = op.getOrCreateFeature(op, featureId); @@ -2633,7 +2929,8 @@ public class AppOpsService extends IAppOpsService.Stub { return uidMode; } } else { - final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, true) : op; + final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, uid, true) + : op; final int mode = switchOp.evalMode(); if (mode != AppOpsManager.MODE_ALLOWED && (!startIfModeDefault || mode != AppOpsManager.MODE_DEFAULT)) { @@ -2671,14 +2968,14 @@ public class AppOpsService extends IAppOpsService.Stub { boolean isPrivileged; try { - isPrivileged = verifyAndGetIsPrivileged(uid, packageName); + isPrivileged = verifyAndGetIsPrivileged(uid, packageName, featureId); } catch (SecurityException e) { Slog.e(TAG, "Cannot finishOperation", e); return; } synchronized (this) { - Op op = getOpLocked(code, uid, resolvedPackageName, isPrivileged, true); + Op op = getOpLocked(code, uid, resolvedPackageName, featureId, isPrivileged, true); if (op == null) { return; } @@ -2909,22 +3206,24 @@ public class AppOpsService extends IAppOpsService.Stub { * * @param uid The uid the package belongs to * @param packageName The package the might belong to the uid + * @param featureId The feature in the package or {@code null} if no need to verify * * @return {@code true} iff the package is privileged */ - private boolean verifyAndGetIsPrivileged(int uid, String packageName) { + private boolean verifyAndGetIsPrivileged(int uid, String packageName, + @Nullable String featureId) { if (uid == Process.ROOT_UID) { // For backwards compatibility, don't check package name for root UID. return false; } - // Do not check if uid/packageName is already known + // Do not check if uid/packageName/featureId is already known synchronized (this) { UidState uidState = mUidStates.get(uid); if (uidState != null && uidState.pkgOps != null) { Ops ops = uidState.pkgOps.get(packageName); - if (ops != null) { + if (ops != null && (featureId == null || ops.knownFeatureIds.contains(featureId))) { return ops.isPrivileged; } } @@ -2934,19 +3233,31 @@ public class AppOpsService extends IAppOpsService.Stub { final long ident = Binder.clearCallingIdentity(); try { int pkgUid; + AndroidPackage pkg = LocalServices.getService(PackageManagerInternal.class).getPackage( + packageName); + boolean isFeatureIdValid = false; - ApplicationInfo appInfo = LocalServices.getService(PackageManagerInternal.class) - .getApplicationInfo(packageName, PackageManager.MATCH_DIRECT_BOOT_AWARE - | PackageManager.MATCH_DIRECT_BOOT_UNAWARE - | PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS - | PackageManager.MATCH_UNINSTALLED_PACKAGES - | PackageManager.MATCH_INSTANT, - Process.SYSTEM_UID, UserHandle.getUserId(uid)); - if (appInfo != null) { - pkgUid = appInfo.uid; - isPrivileged = (appInfo.privateFlags - & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0; + if (pkg != null) { + if (featureId == null) { + isFeatureIdValid = true; + } else { + if (pkg.getFeatures() != null) { + int numFeatures = pkg.getFeatures().size(); + for (int i = 0; i < numFeatures; i++) { + if (pkg.getFeatures().get(i).id.equals(featureId)) { + isFeatureIdValid = true; + } + } + } + } + + pkgUid = UserHandle.getUid( + UserHandle.getUserId(uid), UserHandle.getAppId(pkg.getUid())); + isPrivileged = pkg.isPrivileged(); } else { + // Allow any feature id for resolvable uids + isFeatureIdValid = true; + pkgUid = resolveUid(packageName); if (pkgUid >= 0) { isPrivileged = false; @@ -2956,6 +3267,12 @@ public class AppOpsService extends IAppOpsService.Stub { throw new SecurityException("Specified package " + packageName + " under uid " + uid + " but it is really " + pkgUid); } + + if (!isFeatureIdValid) { + // TODO moltmann: Switch from logging to enforcement + Slog.e(TAG, "featureId " + featureId + " not declared in manifest of " + + packageName); + } } finally { Binder.restoreCallingIdentity(ident); } @@ -2968,12 +3285,14 @@ public class AppOpsService extends IAppOpsService.Stub { * * @param uid The uid the package belongs to * @param packageName The name of the package + * @param featureId The feature in the package * @param isPrivileged If the package is privilidged (ignored if {@code edit} is false) * @param edit If an ops does not exist, create the ops? * @return */ - private Ops getOpsRawLocked(int uid, String packageName, boolean isPrivileged, boolean edit) { + private Ops getOpsRawLocked(int uid, String packageName, @Nullable String featureId, + boolean isPrivileged, boolean edit) { UidState uidState = getUidStateLocked(uid, edit); if (uidState == null) { return null; @@ -2994,6 +3313,9 @@ public class AppOpsService extends IAppOpsService.Stub { ops = new Ops(packageName, uidState, isPrivileged); uidState.pkgOps.put(packageName, ops); } + if (edit && featureId != null) { + ops.knownFeatureIds.add(featureId); + } return ops; } @@ -3004,13 +3326,14 @@ public class AppOpsService extends IAppOpsService.Stub { * * @param uid The uid the of the package * @param packageName The package name for which to get the state for + * @param featureId The feature in the package * @param edit Iff {@code true} create the {@link Ops} object if not yet created * @param isPrivileged Whether the package is privileged or not * * @return The {@link Ops state} of all ops for the package */ private @Nullable Ops getOpsRawNoVerifyLocked(int uid, @NonNull String packageName, - boolean edit, boolean isPrivileged) { + @Nullable String featureId, boolean edit, boolean isPrivileged) { UidState uidState = getUidStateLocked(uid, edit); if (uidState == null) { return null; @@ -3031,6 +3354,11 @@ public class AppOpsService extends IAppOpsService.Stub { ops = new Ops(packageName, uidState, isPrivileged); uidState.pkgOps.put(packageName, ops); } + + if (edit && featureId != null) { + ops.knownFeatureIds.add(featureId); + } + return ops; } @@ -3056,6 +3384,7 @@ public class AppOpsService extends IAppOpsService.Stub { * @param code The code of the op * @param uid The uid the of the package * @param packageName The package name for which to get the state for + * @param featureId The feature in the package * @param isPrivileged Whether the package is privileged or not (only used if {@code edit * == true}) * @param edit Iff {@code true} create the {@link Op} object if not yet created @@ -3063,21 +3392,21 @@ public class AppOpsService extends IAppOpsService.Stub { * @return The {@link Op state} of the op */ private @Nullable Op getOpLocked(int code, int uid, @NonNull String packageName, - boolean isPrivileged, boolean edit) { - Ops ops = getOpsRawNoVerifyLocked(uid, packageName, edit, isPrivileged); + @Nullable String featureId, boolean isPrivileged, boolean edit) { + Ops ops = getOpsRawNoVerifyLocked(uid, packageName, featureId, edit, isPrivileged); if (ops == null) { return null; } - return getOpLocked(ops, code, edit); + return getOpLocked(ops, code, uid, edit); } - private Op getOpLocked(Ops ops, int code, boolean edit) { + private Op getOpLocked(Ops ops, int code, int uid, boolean edit) { Op op = ops.get(code); if (op == null) { if (!edit) { return null; } - op = new Op(ops.uidState, ops.packageName, code, ops.uidState.uid); + op = new Op(ops.uidState, ops.packageName, code, uid); ops.put(code, op); } if (edit) { @@ -3095,7 +3424,7 @@ public class AppOpsService extends IAppOpsService.Stub { } private boolean isOpRestrictedLocked(int uid, int code, String packageName, - boolean isPrivileged) { + @Nullable String featureId, boolean isPrivileged) { int userHandle = UserHandle.getUserId(uid); final int restrictionSetCount = mOpUserRestrictions.size(); @@ -3107,7 +3436,7 @@ public class AppOpsService extends IAppOpsService.Stub { if (AppOpsManager.opAllowSystemBypassRestriction(code)) { // If we are the system, bypass user restrictions for certain codes synchronized (this) { - Ops ops = getOpsRawLocked(uid, packageName, isPrivileged, + Ops ops = getOpsRawLocked(uid, packageName, featureId, isPrivileged, true /* edit */); if ((ops != null) && ops.isPrivileged) { return false; @@ -3484,7 +3813,7 @@ public class AppOpsService extends IAppOpsService.Stub { out.startTag(null, "uid"); out.attribute(null, "n", Integer.toString(pkg.getUid())); synchronized (this) { - Ops ops = getOpsRawLocked(pkg.getUid(), pkg.getPackageName(), + Ops ops = getOpsRawLocked(pkg.getUid(), pkg.getPackageName(), null, false /* isPrivileged */, false /* edit */); // Should always be present as the list of PackageOps is generated // from Ops. @@ -4188,18 +4517,18 @@ public class AppOpsService extends IAppOpsService.Stub { final FeatureOp featureOp = op.mFeatures.get(featureId); if (featureOp.isRunning()) { - long earliestStartTime = Long.MAX_VALUE; + long earliestElapsedTime = Long.MAX_VALUE; long maxNumStarts = 0; int numInProgressEvents = featureOp.mInProgressEvents.size(); for (int i = 0; i < numInProgressEvents; i++) { InProgressStartOpEvent event = featureOp.mInProgressEvents.valueAt(i); - earliestStartTime = Math.min(earliestStartTime, event.startTime); + earliestElapsedTime = Math.min(earliestElapsedTime, event.getStartElapsedTime()); maxNumStarts = Math.max(maxNumStarts, event.numUnfinishedStarts); } pw.print(prefix + "Running start at: "); - TimeUtils.formatDuration(nowElapsed - earliestStartTime, pw); + TimeUtils.formatDuration(nowElapsed - earliestElapsedTime, pw); pw.println(); if (maxNumStarts > 1) { @@ -4471,7 +4800,7 @@ public class AppOpsService extends IAppOpsService.Stub { if (dumpOp >= 0 || dumpPackage != null || dumpMode >= 0) { boolean hasOp = dumpOp < 0 || (uidState.opModes != null && uidState.opModes.indexOfKey(dumpOp) >= 0); - boolean hasPackage = dumpPackage == null; + boolean hasPackage = dumpPackage == null || dumpUid == mUidStates.keyAt(i); boolean hasMode = dumpMode < 0; if (!hasMode && opModes != null) { for (int opi = 0; !hasMode && opi < opModes.size(); opi++) { @@ -4702,8 +5031,8 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public void setUserRestrictions(Bundle restrictions, IBinder token, int userHandle) { checkSystemUid("setUserRestrictions"); - Preconditions.checkNotNull(restrictions); - Preconditions.checkNotNull(token); + Objects.requireNonNull(restrictions); + Objects.requireNonNull(token); for (int i = 0; i < AppOpsManager._NUM_OP; i++) { String restriction = AppOpsManager.opToRestriction(i); if (restriction != null) { @@ -4730,7 +5059,7 @@ public class AppOpsService extends IAppOpsService.Stub { } } verifyIncomingOp(code); - Preconditions.checkNotNull(token); + Objects.requireNonNull(token); setUserRestrictionNoCheck(code, restricted, token, userHandle, exceptionPackages); } @@ -4801,7 +5130,7 @@ public class AppOpsService extends IAppOpsService.Stub { } // TODO moltmann: Allow to check for feature op activeness synchronized (AppOpsService.this) { - Ops pkgOps = getOpsRawLocked(uid, resolvedPackageName, false, false); + Ops pkgOps = getOpsRawLocked(uid, resolvedPackageName, null, false, false); if (pkgOps == null) { return false; } diff --git a/services/core/java/com/android/server/attention/AttentionManagerService.java b/services/core/java/com/android/server/attention/AttentionManagerService.java index fc67e24684bb..5ac5b29b1475 100644 --- a/services/core/java/com/android/server/attention/AttentionManagerService.java +++ b/services/core/java/com/android/server/attention/AttentionManagerService.java @@ -67,6 +67,7 @@ import com.android.server.SystemService; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.Objects; /** * An attention service implementation that runs in System Server process. @@ -120,7 +121,7 @@ public class AttentionManagerService extends SystemService { AttentionManagerService(Context context, PowerManager powerManager, Object lock, AttentionHandler handler) { super(context); - mContext = Preconditions.checkNotNull(context); + mContext = Objects.requireNonNull(context); mPowerManager = powerManager; mLock = lock; mAttentionHandler = handler; @@ -200,7 +201,7 @@ public class AttentionManagerService extends SystemService { */ @VisibleForTesting boolean checkAttention(long timeout, AttentionCallbackInternal callbackInternal) { - Preconditions.checkNotNull(callbackInternal); + Objects.requireNonNull(callbackInternal); if (!isAttentionServiceSupported()) { Slog.w(LOG_TAG, "Trying to call checkAttention() on an unsupported device."); @@ -543,9 +544,9 @@ public class AttentionManagerService extends SystemService { UserState(int userId, Context context, Object lock, Handler handler, ComponentName componentName) { mUserId = userId; - mContext = Preconditions.checkNotNull(context); - mLock = Preconditions.checkNotNull(lock); - mComponentName = Preconditions.checkNotNull(componentName); + mContext = Objects.requireNonNull(context); + mLock = Objects.requireNonNull(lock); + mComponentName = Objects.requireNonNull(componentName); mAttentionHandler = handler; } diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 114aac91fbfa..bc4dc8f4496c 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -2196,7 +2196,7 @@ public class AudioService extends IAudioService.Stub public void setVolumeIndexForAttributes(@NonNull AudioAttributes attr, int index, int flags, String callingPackage) { enforceModifyAudioRoutingPermission(); - Preconditions.checkNotNull(attr, "attr must not be null"); + Objects.requireNonNull(attr, "attr must not be null"); // @todo not hold the caller context, post message int stream = AudioProductStrategy.getLegacyStreamTypeForStrategyWithAudioAttributes(attr); final int device = getDeviceForStream(stream); @@ -2231,7 +2231,7 @@ public class AudioService extends IAudioService.Stub /** @see AudioManager#getVolumeIndexForAttributes(attr) */ public int getVolumeIndexForAttributes(@NonNull AudioAttributes attr) { enforceModifyAudioRoutingPermission(); - Preconditions.checkNotNull(attr, "attr must not be null"); + Objects.requireNonNull(attr, "attr must not be null"); int stream = AudioProductStrategy.getLegacyStreamTypeForStrategyWithAudioAttributes(attr); final int device = getDeviceForStream(stream); @@ -2241,14 +2241,14 @@ public class AudioService extends IAudioService.Stub /** @see AudioManager#getMaxVolumeIndexForAttributes(attr) */ public int getMaxVolumeIndexForAttributes(@NonNull AudioAttributes attr) { enforceModifyAudioRoutingPermission(); - Preconditions.checkNotNull(attr, "attr must not be null"); + Objects.requireNonNull(attr, "attr must not be null"); return AudioSystem.getMaxVolumeIndexForAttributes(attr); } /** @see AudioManager#getMinVolumeIndexForAttributes(attr) */ public int getMinVolumeIndexForAttributes(@NonNull AudioAttributes attr) { enforceModifyAudioRoutingPermission(); - Preconditions.checkNotNull(attr, "attr must not be null"); + Objects.requireNonNull(attr, "attr must not be null"); return AudioSystem.getMinVolumeIndexForAttributes(attr); } @@ -2510,7 +2510,7 @@ public class AudioService extends IAudioService.Stub private int getVolumeGroupIdForAttributes(@NonNull AudioAttributes attributes) { - Preconditions.checkNotNull(attributes, "attributes must not be null"); + Objects.requireNonNull(attributes, "attributes must not be null"); int volumeGroupId = getVolumeGroupIdForAttributesInt(attributes); if (volumeGroupId != AudioVolumeGroup.DEFAULT_VOLUME_GROUP) { return volumeGroupId; @@ -2521,7 +2521,7 @@ public class AudioService extends IAudioService.Stub } private int getVolumeGroupIdForAttributesInt(@NonNull AudioAttributes attributes) { - Preconditions.checkNotNull(attributes, "attributes must not be null"); + Objects.requireNonNull(attributes, "attributes must not be null"); for (final AudioProductStrategy productStrategy : AudioProductStrategy.getAudioProductStrategies()) { int volumeGroupId = productStrategy.getVolumeGroupIdForAudioAttributes(attributes); diff --git a/services/core/java/com/android/server/display/BrightnessMappingStrategy.java b/services/core/java/com/android/server/display/BrightnessMappingStrategy.java index ff0b01594bcf..28f67fe2d618 100644 --- a/services/core/java/com/android/server/display/BrightnessMappingStrategy.java +++ b/services/core/java/com/android/server/display/BrightnessMappingStrategy.java @@ -34,6 +34,7 @@ import com.android.server.display.utils.Plog; import java.io.PrintWriter; import java.util.Arrays; +import java.util.Objects; /** * A utility to map from an ambient brightness to a display's "backlight" brightness based on the @@ -702,7 +703,7 @@ public abstract class BrightnessMappingStrategy { "Nits and backlight arrays must not be empty!"); Preconditions.checkArgument(nits.length == backlight.length, "Nits and backlight arrays must be the same length!"); - Preconditions.checkNotNull(config); + Objects.requireNonNull(config); Preconditions.checkArrayElementsInRange(nits, 0, Float.MAX_VALUE, "nits"); Preconditions.checkArrayElementsInRange(backlight, PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON, "backlight"); diff --git a/services/core/java/com/android/server/display/whitebalance/AmbientSensor.java b/services/core/java/com/android/server/display/whitebalance/AmbientSensor.java index 1707a62f805a..75d00ff609c6 100644 --- a/services/core/java/com/android/server/display/whitebalance/AmbientSensor.java +++ b/services/core/java/com/android/server/display/whitebalance/AmbientSensor.java @@ -29,6 +29,7 @@ import com.android.internal.util.Preconditions; import com.android.server.display.utils.History; import java.io.PrintWriter; +import java.util.Objects; /** * The DisplayWhiteBalanceController uses the AmbientSensor to detect changes in the ambient @@ -139,8 +140,8 @@ abstract class AmbientSensor { private static void validateArguments(Handler handler, SensorManager sensorManager, int rate) { - Preconditions.checkNotNull(handler, "handler cannot be null"); - Preconditions.checkNotNull(sensorManager, "sensorManager cannot be null"); + Objects.requireNonNull(handler, "handler cannot be null"); + Objects.requireNonNull(sensorManager, "sensorManager cannot be null"); if (rate <= 0) { throw new IllegalArgumentException("rate must be positive"); } diff --git a/services/core/java/com/android/server/display/whitebalance/DisplayWhiteBalanceController.java b/services/core/java/com/android/server/display/whitebalance/DisplayWhiteBalanceController.java index 88a7077ac37a..d64fcbc20767 100644 --- a/services/core/java/com/android/server/display/whitebalance/DisplayWhiteBalanceController.java +++ b/services/core/java/com/android/server/display/whitebalance/DisplayWhiteBalanceController.java @@ -28,6 +28,7 @@ import com.android.server.display.utils.AmbientFilter; import com.android.server.display.utils.History; import java.io.PrintWriter; +import java.util.Objects; /** * The DisplayWhiteBalanceController drives display white-balance (automatically correcting the @@ -475,13 +476,13 @@ public class DisplayWhiteBalanceController implements AmbientSensor.AmbientColorTemperatureSensor colorTemperatureSensor, AmbientFilter colorTemperatureFilter, DisplayWhiteBalanceThrottler throttler) { - Preconditions.checkNotNull(brightnessSensor, "brightnessSensor must not be null"); - Preconditions.checkNotNull(brightnessFilter, "brightnessFilter must not be null"); - Preconditions.checkNotNull(colorTemperatureSensor, + Objects.requireNonNull(brightnessSensor, "brightnessSensor must not be null"); + Objects.requireNonNull(brightnessFilter, "brightnessFilter must not be null"); + Objects.requireNonNull(colorTemperatureSensor, "colorTemperatureSensor must not be null"); - Preconditions.checkNotNull(colorTemperatureFilter, + Objects.requireNonNull(colorTemperatureFilter, "colorTemperatureFilter must not be null"); - Preconditions.checkNotNull(throttler, "throttler cannot be null"); + Objects.requireNonNull(throttler, "throttler cannot be null"); } private boolean enable() { diff --git a/services/core/java/com/android/server/display/whitebalance/DisplayWhiteBalanceSettings.java b/services/core/java/com/android/server/display/whitebalance/DisplayWhiteBalanceSettings.java index 6e7889422bcd..0efb7494c5d0 100644 --- a/services/core/java/com/android/server/display/whitebalance/DisplayWhiteBalanceSettings.java +++ b/services/core/java/com/android/server/display/whitebalance/DisplayWhiteBalanceSettings.java @@ -30,6 +30,7 @@ import com.android.server.display.color.ColorDisplayService.ColorDisplayServiceI import com.android.server.display.whitebalance.DisplayWhiteBalanceController.Callbacks; import java.io.PrintWriter; +import java.util.Objects; /** * The DisplayWhiteBalanceSettings holds the state of all the settings related to @@ -144,8 +145,8 @@ public class DisplayWhiteBalanceSettings implements } private void validateArguments(Context context, Handler handler) { - Preconditions.checkNotNull(context, "context must not be null"); - Preconditions.checkNotNull(handler, "handler must not be null"); + Objects.requireNonNull(context, "context must not be null"); + Objects.requireNonNull(handler, "handler must not be null"); } private void setEnabled(boolean enabled) { diff --git a/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java b/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java index 080e6cea8333..a9e8719890ef 100755 --- a/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java +++ b/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java @@ -26,6 +26,7 @@ import com.android.server.hdmi.HdmiControlService.DevicePollingCallback; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Feature action that handles device discovery sequences. @@ -106,7 +107,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction { */ DeviceDiscoveryAction(HdmiCecLocalDevice source, DeviceDiscoveryCallback callback, int delay) { super(source); - mCallback = Preconditions.checkNotNull(callback); + mCallback = Objects.requireNonNull(callback); mDelayPeriod = delay; } diff --git a/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java b/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java index 33e12c6d4fec..b1639a948ffc 100644 --- a/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java +++ b/services/core/java/com/android/server/integrity/AppIntegrityManagerServiceImpl.java @@ -385,6 +385,9 @@ public class AppIntegrityManagerServiceImpl extends IAppIntegrityManager.Stub { String packageName = getPackageNameNormalized(packageAndCert[0]); String cert = packageAndCert[1]; packageCertMap.put(packageName, cert); + } else if (packageAndCert.length == 1 + && packageAndCert[0].equals(ADB_INSTALLER)) { + packageCertMap.put(ADB_INSTALLER, INSTALLER_CERT_NOT_APPLICABLE); } } } diff --git a/services/core/java/com/android/server/locksettings/LockSettingsService.java b/services/core/java/com/android/server/locksettings/LockSettingsService.java index bcc4c1fd902c..6c65c3680dae 100644 --- a/services/core/java/com/android/server/locksettings/LockSettingsService.java +++ b/services/core/java/com/android/server/locksettings/LockSettingsService.java @@ -151,6 +151,7 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -1594,8 +1595,8 @@ public class LockSettingsService extends ILockSettings.Stub { */ private boolean setLockCredentialInternal(LockscreenCredential credential, LockscreenCredential savedCredential, int userId, boolean isLockTiedToParent) { - Preconditions.checkNotNull(credential); - Preconditions.checkNotNull(savedCredential); + Objects.requireNonNull(credential); + Objects.requireNonNull(savedCredential); synchronized (mSpManager) { if (isSyntheticPasswordBasedCredentialLocked(userId)) { return spBasedSetLockCredentialInternalLocked(credential, savedCredential, userId, diff --git a/services/core/java/com/android/server/locksettings/SyntheticPasswordManager.java b/services/core/java/com/android/server/locksettings/SyntheticPasswordManager.java index c53647d053bc..0fe16be2188e 100644 --- a/services/core/java/com/android/server/locksettings/SyntheticPasswordManager.java +++ b/services/core/java/com/android/server/locksettings/SyntheticPasswordManager.java @@ -57,6 +57,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.Set; @@ -228,8 +229,8 @@ public class SyntheticPasswordManager { * by {@link #setEscrowData} before calling this. */ public void recreateFromEscrow(byte[] escrowSplit0) { - Preconditions.checkNotNull(mEscrowSplit1); - Preconditions.checkNotNull(mEncryptedEscrowSplit0); + Objects.requireNonNull(mEscrowSplit1); + Objects.requireNonNull(mEncryptedEscrowSplit0); recreate(escrowSplit0, mEscrowSplit1); } diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java index 1b14ce21bb92..383d5cf326c0 100644 --- a/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java +++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java @@ -75,6 +75,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -302,8 +303,8 @@ public class RecoverableKeyStoreManager { checkRecoverKeyStorePermission(); rootCertificateAlias = mTestCertHelper.getDefaultCertificateAliasIfEmpty(rootCertificateAlias); - Preconditions.checkNotNull(recoveryServiceCertFile, "recoveryServiceCertFile is null"); - Preconditions.checkNotNull(recoveryServiceSigFile, "recoveryServiceSigFile is null"); + Objects.requireNonNull(recoveryServiceCertFile, "recoveryServiceCertFile is null"); + Objects.requireNonNull(recoveryServiceSigFile, "recoveryServiceSigFile is null"); SigXml sigXml; try { @@ -393,7 +394,7 @@ public class RecoverableKeyStoreManager { */ public void setRecoveryStatus(@NonNull String alias, int status) throws RemoteException { checkRecoverKeyStorePermission(); - Preconditions.checkNotNull(alias, "alias is null"); + Objects.requireNonNull(alias, "alias is null"); long updatedRows = mDatabase.setRecoveryStatus(Binder.getCallingUid(), alias, status); if (updatedRows < 0) { throw new ServiceSpecificException( @@ -424,7 +425,7 @@ public class RecoverableKeyStoreManager { @NonNull @KeyChainProtectionParams.UserSecretType int[] secretTypes) throws RemoteException { checkRecoverKeyStorePermission(); - Preconditions.checkNotNull(secretTypes, "secretTypes is null"); + Objects.requireNonNull(secretTypes, "secretTypes is null"); int userId = UserHandle.getCallingUserId(); int uid = Binder.getCallingUid(); @@ -556,11 +557,11 @@ public class RecoverableKeyStoreManager { checkRecoverKeyStorePermission(); rootCertificateAlias = mTestCertHelper.getDefaultCertificateAliasIfEmpty(rootCertificateAlias); - Preconditions.checkNotNull(sessionId, "invalid session"); - Preconditions.checkNotNull(verifierCertPath, "verifierCertPath is null"); - Preconditions.checkNotNull(vaultParams, "vaultParams is null"); - Preconditions.checkNotNull(vaultChallenge, "vaultChallenge is null"); - Preconditions.checkNotNull(secrets, "secrets is null"); + Objects.requireNonNull(sessionId, "invalid session"); + Objects.requireNonNull(verifierCertPath, "verifierCertPath is null"); + Objects.requireNonNull(vaultParams, "vaultParams is null"); + Objects.requireNonNull(vaultChallenge, "vaultChallenge is null"); + Objects.requireNonNull(secrets, "secrets is null"); CertPath certPath; try { certPath = verifierCertPath.getCertPath(); @@ -666,13 +667,13 @@ public class RecoverableKeyStoreManager { */ public void closeSession(@NonNull String sessionId) throws RemoteException { checkRecoverKeyStorePermission(); - Preconditions.checkNotNull(sessionId, "invalid session"); + Objects.requireNonNull(sessionId, "invalid session"); mRecoverySessionStorage.remove(Binder.getCallingUid(), sessionId); } public void removeKey(@NonNull String alias) throws RemoteException { checkRecoverKeyStorePermission(); - Preconditions.checkNotNull(alias, "alias is null"); + Objects.requireNonNull(alias, "alias is null"); int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); @@ -711,7 +712,7 @@ public class RecoverableKeyStoreManager { public String generateKeyWithMetadata(@NonNull String alias, @Nullable byte[] metadata) throws RemoteException { checkRecoverKeyStorePermission(); - Preconditions.checkNotNull(alias, "alias is null"); + Objects.requireNonNull(alias, "alias is null"); int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); @@ -771,8 +772,8 @@ public class RecoverableKeyStoreManager { public @Nullable String importKeyWithMetadata(@NonNull String alias, @NonNull byte[] keyBytes, @Nullable byte[] metadata) throws RemoteException { checkRecoverKeyStorePermission(); - Preconditions.checkNotNull(alias, "alias is null"); - Preconditions.checkNotNull(keyBytes, "keyBytes is null"); + Objects.requireNonNull(alias, "alias is null"); + Objects.requireNonNull(keyBytes, "keyBytes is null"); if (keyBytes.length != RecoverableKeyGenerator.KEY_SIZE_BITS / Byte.SIZE) { Log.e(TAG, "The given key for import doesn't have the required length " + RecoverableKeyGenerator.KEY_SIZE_BITS); @@ -816,7 +817,7 @@ public class RecoverableKeyStoreManager { */ public @Nullable String getKey(@NonNull String alias) throws RemoteException { checkRecoverKeyStorePermission(); - Preconditions.checkNotNull(alias, "alias is null"); + Objects.requireNonNull(alias, "alias is null"); int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); return getAlias(userId, uid, alias); diff --git a/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java b/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java index 423001fcb84f..f8d8f9fd5fbd 100644 --- a/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java +++ b/services/core/java/com/android/server/media/MediaRoute2ProviderProxy.java @@ -286,6 +286,11 @@ final class MediaRoute2ProviderProxy extends MediaRoute2Provider implements Serv if (mActiveConnection != connection) { return; } + if (sessionInfo != null) { + sessionInfo = new RouteSessionInfo.Builder(sessionInfo) + .setProviderId(getUniqueId()) + .build(); + } mCallback.onSessionCreated(this, sessionInfo, requestId); } diff --git a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java index 0bdcc97b95c2..82d22505b303 100644 --- a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java +++ b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java @@ -1071,12 +1071,6 @@ class MediaRouter2ServiceImpl { return; } - //TODO: remove this when we are sure that request id is properly implemented. - if (matchingRequest.mClientRecord.mClientId != toClientId(requestId)) { - Slog.w(TAG, "Client id is changed. This shouldn't happen."); - return; - } - mSessionCreationRequests.remove(matchingRequest); if (sessionInfo == null) { @@ -1086,21 +1080,17 @@ class MediaRouter2ServiceImpl { return; } - RouteSessionInfo sessionInfoWithProviderId = new RouteSessionInfo.Builder(sessionInfo) - .setProviderId(provider.getUniqueId()) - .build(); - String originalRouteId = matchingRequest.mRoute.getId(); String originalCategory = matchingRequest.mControlCategory; Client2Record client2Record = matchingRequest.mClientRecord; - if (!sessionInfoWithProviderId.getSelectedRoutes().contains(originalRouteId) + if (!sessionInfo.getSelectedRoutes().contains(originalRouteId) || !TextUtils.equals(originalCategory, - sessionInfoWithProviderId.getControlCategory())) { + sessionInfo.getControlCategory())) { Slog.w(TAG, "Created session doesn't match the original request." + " originalRouteId=" + originalRouteId + ", originalCategory=" + originalCategory + ", requestId=" + requestId - + ", sessionInfo=" + sessionInfoWithProviderId); + + ", sessionInfo=" + sessionInfo); notifySessionCreationFailed(matchingRequest.mClientRecord, toClientRequestId(requestId)); return; @@ -1108,8 +1098,8 @@ class MediaRouter2ServiceImpl { // Succeeded notifySessionCreated(matchingRequest.mClientRecord, - sessionInfoWithProviderId, toClientRequestId(requestId)); - mSessionToClientMap.put(sessionInfoWithProviderId.getUniqueSessionId(), client2Record); + sessionInfo, toClientRequestId(requestId)); + mSessionToClientMap.put(sessionInfo.getUniqueSessionId(), client2Record); // TODO: Tell managers for the session creation } diff --git a/services/core/java/com/android/server/net/LockdownVpnTracker.java b/services/core/java/com/android/server/net/LockdownVpnTracker.java index 4cb41da026c7..ef8f6479cb3d 100644 --- a/services/core/java/com/android/server/net/LockdownVpnTracker.java +++ b/services/core/java/com/android/server/net/LockdownVpnTracker.java @@ -45,12 +45,12 @@ import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.net.VpnConfig; import com.android.internal.net.VpnProfile; import com.android.internal.notification.SystemNotificationChannels; -import com.android.internal.util.Preconditions; import com.android.server.ConnectivityService; import com.android.server.EventLogTags; import com.android.server.connectivity.Vpn; import java.util.List; +import java.util.Objects; /** * State tracker for lockdown mode. Watches for normal {@link NetworkInfo} to be @@ -90,11 +90,11 @@ public class LockdownVpnTracker { @NonNull Handler handler, @NonNull Vpn vpn, @NonNull VpnProfile profile) { - mContext = Preconditions.checkNotNull(context); - mConnService = Preconditions.checkNotNull(connService); - mHandler = Preconditions.checkNotNull(handler); - mVpn = Preconditions.checkNotNull(vpn); - mProfile = Preconditions.checkNotNull(profile); + mContext = Objects.requireNonNull(context); + mConnService = Objects.requireNonNull(connService); + mHandler = Objects.requireNonNull(handler); + mVpn = Objects.requireNonNull(vpn); + mProfile = Objects.requireNonNull(profile); final Intent configIntent = new Intent(ACTION_VPN_SETTINGS); mConfigIntent = PendingIntent.getActivity(mContext, 0, configIntent, 0); diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java index 99562eb28886..0171e1fd1086 100644 --- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java +++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java @@ -91,7 +91,6 @@ import static android.telephony.CarrierConfigManager.KEY_DATA_WARNING_NOTIFICATI import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; import static com.android.internal.util.ArrayUtils.appendInt; -import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.internal.util.XmlUtils.readBooleanAttribute; import static com.android.internal.util.XmlUtils.readIntAttribute; import static com.android.internal.util.XmlUtils.readLongAttribute; @@ -614,12 +613,12 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { public NetworkPolicyManagerService(Context context, IActivityManager activityManager, INetworkManagementService networkManagement, IPackageManager pm, Clock clock, File systemDir, boolean suppressDefaultPolicy) { - mContext = checkNotNull(context, "missing context"); - mActivityManager = checkNotNull(activityManager, "missing activityManager"); - mNetworkManager = checkNotNull(networkManagement, "missing networkManagement"); + mContext = Objects.requireNonNull(context, "missing context"); + mActivityManager = Objects.requireNonNull(activityManager, "missing activityManager"); + mNetworkManager = Objects.requireNonNull(networkManagement, "missing networkManagement"); mDeviceIdleController = IDeviceIdleController.Stub.asInterface(ServiceManager.getService( Context.DEVICE_IDLE_CONTROLLER)); - mClock = checkNotNull(clock, "missing Clock"); + mClock = Objects.requireNonNull(clock, "missing Clock"); mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class); mIPm = pm; @@ -646,7 +645,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { } public void bindConnectivityManager(IConnectivityManager connManager) { - mConnManager = checkNotNull(connManager, "missing IConnectivityManager"); + mConnManager = Objects.requireNonNull(connManager, "missing IConnectivityManager"); } @GuardedBy("mUidRulesFirstLock") @@ -3295,7 +3294,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { enforceSubscriptionPlanValidity(plans); for (SubscriptionPlan plan : plans) { - Preconditions.checkNotNull(plan); + Objects.requireNonNull(plan); } final long token = Binder.clearCallingIdentity(); diff --git a/services/core/java/com/android/server/net/NetworkStatsRecorder.java b/services/core/java/com/android/server/net/NetworkStatsRecorder.java index 6af962bbcc89..9eff5d1648bd 100644 --- a/services/core/java/com/android/server/net/NetworkStatsRecorder.java +++ b/services/core/java/com/android/server/net/NetworkStatsRecorder.java @@ -21,8 +21,6 @@ import static android.net.TrafficStats.KB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES; import static android.text.format.DateUtils.YEAR_IN_MILLIS; -import static com.android.internal.util.Preconditions.checkNotNull; - import android.net.NetworkStats; import android.net.NetworkStats.NonMonotonicObserver; import android.net.NetworkStatsHistory; @@ -54,6 +52,7 @@ import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.HashSet; import java.util.Map; +import java.util.Objects; /** * Logic to record deltas between periodic {@link NetworkStats} snapshots into @@ -116,9 +115,9 @@ public class NetworkStatsRecorder { */ public NetworkStatsRecorder(FileRotator rotator, NonMonotonicObserver<String> observer, DropBoxManager dropBox, String cookie, long bucketDuration, boolean onlyTags) { - mRotator = checkNotNull(rotator, "missing FileRotator"); - mObserver = checkNotNull(observer, "missing NonMonotonicObserver"); - mDropBox = checkNotNull(dropBox, "missing DropBoxManager"); + mRotator = Objects.requireNonNull(rotator, "missing FileRotator"); + mObserver = Objects.requireNonNull(observer, "missing NonMonotonicObserver"); + mDropBox = Objects.requireNonNull(dropBox, "missing DropBoxManager"); mCookie = cookie; mBucketDuration = bucketDuration; @@ -165,7 +164,7 @@ public class NetworkStatsRecorder { * as reference is valid. */ public NetworkStatsCollection getOrLoadCompleteLocked() { - checkNotNull(mRotator, "missing FileRotator"); + Objects.requireNonNull(mRotator, "missing FileRotator"); NetworkStatsCollection res = mComplete != null ? mComplete.get() : null; if (res == null) { res = loadLocked(Long.MIN_VALUE, Long.MAX_VALUE); @@ -175,7 +174,7 @@ public class NetworkStatsRecorder { } public NetworkStatsCollection getOrLoadPartialLocked(long start, long end) { - checkNotNull(mRotator, "missing FileRotator"); + Objects.requireNonNull(mRotator, "missing FileRotator"); NetworkStatsCollection res = mComplete != null ? mComplete.get() : null; if (res == null) { res = loadLocked(start, end); @@ -280,7 +279,7 @@ public class NetworkStatsRecorder { * {@link #mPersistThresholdBytes}. */ public void maybePersistLocked(long currentTimeMillis) { - checkNotNull(mRotator, "missing FileRotator"); + Objects.requireNonNull(mRotator, "missing FileRotator"); final long pendingBytes = mPending.getTotalBytes(); if (pendingBytes >= mPersistThresholdBytes) { forcePersistLocked(currentTimeMillis); @@ -293,7 +292,7 @@ public class NetworkStatsRecorder { * Force persisting any pending deltas. */ public void forcePersistLocked(long currentTimeMillis) { - checkNotNull(mRotator, "missing FileRotator"); + Objects.requireNonNull(mRotator, "missing FileRotator"); if (mPending.isDirty()) { if (LOGD) Slog.d(TAG, "forcePersistLocked() writing for " + mCookie); try { @@ -356,7 +355,7 @@ public class NetworkStatsRecorder { private final NetworkStatsCollection mCollection; public CombiningRewriter(NetworkStatsCollection collection) { - mCollection = checkNotNull(collection, "missing NetworkStatsCollection"); + mCollection = Objects.requireNonNull(collection, "missing NetworkStatsCollection"); } @Override @@ -418,7 +417,7 @@ public class NetworkStatsRecorder { } public void importLegacyNetworkLocked(File file) throws IOException { - checkNotNull(mRotator, "missing FileRotator"); + Objects.requireNonNull(mRotator, "missing FileRotator"); // legacy file still exists; start empty to avoid double importing mRotator.deleteAll(); @@ -438,7 +437,7 @@ public class NetworkStatsRecorder { } public void importLegacyUidLocked(File file) throws IOException { - checkNotNull(mRotator, "missing FileRotator"); + Objects.requireNonNull(mRotator, "missing FileRotator"); // legacy file still exists; start empty to avoid double importing mRotator.deleteAll(); diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index 0288f0c5e3cf..ec8a8e7c4c1a 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -65,7 +65,6 @@ import static android.text.format.DateUtils.HOUR_IN_MILLIS; import static android.text.format.DateUtils.MINUTE_IN_MILLIS; import static android.text.format.DateUtils.SECOND_IN_MILLIS; -import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT; import static com.android.server.NetworkManagementSocketTagger.resetKernelUidStats; import static com.android.server.NetworkManagementSocketTagger.setKernelCounterSet; @@ -148,6 +147,7 @@ import java.time.ZoneOffset; import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Objects; /** * Collect and persist detailed network statistics, and provide this data to @@ -357,17 +357,18 @@ public class NetworkStatsService extends INetworkStatsService.Stub { TelephonyManager teleManager, NetworkStatsSettings settings, NetworkStatsFactory factory, NetworkStatsObservers statsObservers, File systemDir, File baseDir) { - mContext = checkNotNull(context, "missing Context"); - mNetworkManager = checkNotNull(networkManager, "missing INetworkManagementService"); - mAlarmManager = checkNotNull(alarmManager, "missing AlarmManager"); - mClock = checkNotNull(clock, "missing Clock"); - mSettings = checkNotNull(settings, "missing NetworkStatsSettings"); - mTeleManager = checkNotNull(teleManager, "missing TelephonyManager"); - mWakeLock = checkNotNull(wakeLock, "missing WakeLock"); - mStatsFactory = checkNotNull(factory, "missing factory"); - mStatsObservers = checkNotNull(statsObservers, "missing NetworkStatsObservers"); - mSystemDir = checkNotNull(systemDir, "missing systemDir"); - mBaseDir = checkNotNull(baseDir, "missing baseDir"); + mContext = Objects.requireNonNull(context, "missing Context"); + mNetworkManager = Objects.requireNonNull(networkManager, + "missing INetworkManagementService"); + mAlarmManager = Objects.requireNonNull(alarmManager, "missing AlarmManager"); + mClock = Objects.requireNonNull(clock, "missing Clock"); + mSettings = Objects.requireNonNull(settings, "missing NetworkStatsSettings"); + mTeleManager = Objects.requireNonNull(teleManager, "missing TelephonyManager"); + mWakeLock = Objects.requireNonNull(wakeLock, "missing WakeLock"); + mStatsFactory = Objects.requireNonNull(factory, "missing factory"); + mStatsObservers = Objects.requireNonNull(statsObservers, "missing NetworkStatsObservers"); + mSystemDir = Objects.requireNonNull(systemDir, "missing systemDir"); + mBaseDir = Objects.requireNonNull(baseDir, "missing baseDir"); mUseBpfTrafficStats = new File("/sys/fs/bpf/map_netd_app_uid_stats_map").exists(); } @@ -896,11 +897,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @Override public DataUsageRequest registerUsageCallback(String callingPackage, DataUsageRequest request, Messenger messenger, IBinder binder) { - checkNotNull(callingPackage, "calling package is null"); - checkNotNull(request, "DataUsageRequest is null"); - checkNotNull(request.template, "NetworkTemplate is null"); - checkNotNull(messenger, "messenger is null"); - checkNotNull(binder, "binder is null"); + Objects.requireNonNull(callingPackage, "calling package is null"); + Objects.requireNonNull(request, "DataUsageRequest is null"); + Objects.requireNonNull(request.template, "NetworkTemplate is null"); + Objects.requireNonNull(messenger, "messenger is null"); + Objects.requireNonNull(binder, "binder is null"); int callingUid = Binder.getCallingUid(); @NetworkStatsAccess.Level int accessLevel = checkAccessLevel(callingPackage); @@ -921,7 +922,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @Override public void unregisterUsageRequest(DataUsageRequest request) { - checkNotNull(request, "DataUsageRequest is null"); + Objects.requireNonNull(request, "DataUsageRequest is null"); int callingUid = Binder.getCallingUid(); final long token = Binder.clearCallingIdentity(); @@ -1795,7 +1796,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private final ContentResolver mResolver; public DefaultNetworkStatsSettings(Context context) { - mResolver = checkNotNull(context.getContentResolver()); + mResolver = Objects.requireNonNull(context.getContentResolver()); // TODO: adjust these timings for production builds } diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 785ca7dd1fe8..04e7372a92a7 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -11319,6 +11319,12 @@ public class PackageManagerService extends IPackageManager.Stub "Static shared libs cannot declare permission groups"); } + // Static shared libs cannot declare features + if (pkg.getFeatures() != null && !pkg.getFeatures().isEmpty()) { + throw new PackageManagerException( + "Static shared libs cannot declare features"); + } + // Static shared libs cannot declare permissions if (pkg.getPermissions() != null && !pkg.getPermissions().isEmpty()) { throw new PackageManagerException( @@ -12872,7 +12878,7 @@ public class PackageManagerService extends IPackageManager.Stub @Override public String[] getUnsuspendablePackagesForUser(String[] packageNames, int userId) { - Preconditions.checkNotNull("packageNames cannot be null", packageNames); + Preconditions.checkNotNull(packageNames, "packageNames cannot be null"); mContext.enforceCallingOrSelfPermission(Manifest.permission.SUSPEND_APPS, "getUnsuspendablePackagesForUser"); final int callingUid = Binder.getCallingUid(); diff --git a/services/core/java/com/android/server/power/batterysaver/BatterySaverController.java b/services/core/java/com/android/server/power/batterysaver/BatterySaverController.java index f0e462503769..4142e6ff4d69 100644 --- a/services/core/java/com/android/server/power/batterysaver/BatterySaverController.java +++ b/services/core/java/com/android/server/power/batterysaver/BatterySaverController.java @@ -49,6 +49,7 @@ import com.android.server.power.batterysaver.BatterySavingStats.DozeState; import com.android.server.power.batterysaver.BatterySavingStats.InteractiveState; import java.util.ArrayList; +import java.util.Objects; /** * Responsible for battery saver mode transition logic. @@ -237,7 +238,7 @@ public class BatterySaverController implements BatterySaverPolicyListener { private PowerManager getPowerManager() { if (mPowerManager == null) { mPowerManager = - Preconditions.checkNotNull(mContext.getSystemService(PowerManager.class)); + Objects.requireNonNull(mContext.getSystemService(PowerManager.class)); } return mPowerManager; } diff --git a/services/core/java/com/android/server/rollback/AppDataRollbackHelper.java b/services/core/java/com/android/server/rollback/AppDataRollbackHelper.java index 1123f70b4334..e6e6e23bf714 100644 --- a/services/core/java/com/android/server/rollback/AppDataRollbackHelper.java +++ b/services/core/java/com/android/server/rollback/AppDataRollbackHelper.java @@ -16,6 +16,7 @@ package com.android.server.rollback; +import android.content.pm.PackageManager; import android.content.rollback.PackageRollbackInfo; import android.content.rollback.PackageRollbackInfo.RestoreInfo; import android.os.storage.StorageManager; @@ -119,11 +120,22 @@ public class AppDataRollbackHelper { } try { - mInstaller.restoreAppDataSnapshot(packageRollbackInfo.getPackageName(), appId, seInfo, - userId, rollbackId, storageFlags); + switch (packageRollbackInfo.getRollbackDataPolicy()) { + case PackageManager.RollbackDataPolicy.WIPE: + mInstaller.clearAppData(null, packageRollbackInfo.getPackageName(), + userId, storageFlags, 0); + break; + case PackageManager.RollbackDataPolicy.RESTORE: + mInstaller.restoreAppDataSnapshot(packageRollbackInfo.getPackageName(), appId, + seInfo, userId, rollbackId, storageFlags); + break; + default: + break; + } } catch (InstallerException ie) { - Slog.e(TAG, "Unable to restore app data snapshot: " - + packageRollbackInfo.getPackageName(), ie); + Slog.e(TAG, "Unable to restore/wipe app data: " + + packageRollbackInfo.getPackageName() + " policy=" + + packageRollbackInfo.getRollbackDataPolicy(), ie); } return changedRollback; @@ -207,13 +219,24 @@ public class AppDataRollbackHelper { if (hasPendingRestore) { try { - mInstaller.restoreAppDataSnapshot(info.getPackageName(), ri.appId, - ri.seInfo, userId, rollback.info.getRollbackId(), - Installer.FLAG_STORAGE_CE); + switch (info.getRollbackDataPolicy()) { + case PackageManager.RollbackDataPolicy.WIPE: + mInstaller.clearAppData(null, info.getPackageName(), userId, + Installer.FLAG_STORAGE_CE, 0); + break; + case PackageManager.RollbackDataPolicy.RESTORE: + mInstaller.restoreAppDataSnapshot(info.getPackageName(), ri.appId, + ri.seInfo, userId, rollback.info.getRollbackId(), + Installer.FLAG_STORAGE_CE); + break; + default: + break; + } info.removeRestoreInfo(ri); } catch (InstallerException ie) { - Slog.e(TAG, "Unable to restore app data snapshot for: " - + info.getPackageName(), ie); + Slog.e(TAG, "Unable to restore/wipe app data for: " + + info.getPackageName() + " policy=" + + info.getRollbackDataPolicy(), ie); } } } diff --git a/services/core/java/com/android/server/rollback/Rollback.java b/services/core/java/com/android/server/rollback/Rollback.java index 6898e1cd1f83..88c1564fdb60 100644 --- a/services/core/java/com/android/server/rollback/Rollback.java +++ b/services/core/java/com/android/server/rollback/Rollback.java @@ -306,7 +306,7 @@ class Rollback { * @return boolean True if the rollback was enabled successfully for the specified package. */ boolean enableForPackage(String packageName, long newVersion, long installedVersion, - boolean isApex, String sourceDir, String[] splitSourceDirs) { + boolean isApex, String sourceDir, String[] splitSourceDirs, int rollbackDataPolicy) { try { RollbackStore.backupPackageCodePath(this, packageName, sourceDir); if (!ArrayUtils.isEmpty(splitSourceDirs)) { @@ -323,7 +323,8 @@ class Rollback { new VersionedPackage(packageName, newVersion), new VersionedPackage(packageName, installedVersion), new IntArray() /* pendingBackups */, new ArrayList<>() /* pendingRestores */, - isApex, new IntArray(), new SparseLongArray() /* ceSnapshotInodes */); + isApex, new IntArray(), new SparseLongArray() /* ceSnapshotInodes */, + rollbackDataPolicy); synchronized (mLock) { info.getPackages().add(packageRollbackInfo); @@ -344,10 +345,12 @@ class Rollback { for (PackageRollbackInfo pkgRollbackInfo : info.getPackages()) { if (pkgRollbackInfo.getPackageName().equals(packageName)) { - dataHelper.snapshotAppData(info.getRollbackId(), pkgRollbackInfo, userIds); - - RollbackStore.saveRollback(this); - pkgRollbackInfo.getSnapshottedUsers().addAll(IntArray.wrap(userIds)); + if (pkgRollbackInfo.getRollbackDataPolicy() + == PackageManager.RollbackDataPolicy.RESTORE) { + dataHelper.snapshotAppData(info.getRollbackId(), pkgRollbackInfo, userIds); + pkgRollbackInfo.getSnapshottedUsers().addAll(IntArray.wrap(userIds)); + RollbackStore.saveRollback(this); + } break; } } diff --git a/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java b/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java index 6cdfcff61415..9a65ae6dba4d 100644 --- a/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java +++ b/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java @@ -841,7 +841,7 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub { ApplicationInfo appInfo = pkgInfo.applicationInfo; return rollback.enableForPackage(packageName, newPackage.versionCode, pkgInfo.getLongVersionCode(), isApex, appInfo.sourceDir, - appInfo.splitSourceDirs); + appInfo.splitSourceDirs, session.rollbackDataPolicy); } @Override diff --git a/services/core/java/com/android/server/rollback/RollbackPackageHealthObserver.java b/services/core/java/com/android/server/rollback/RollbackPackageHealthObserver.java index bb095841bbaa..162a69546318 100644 --- a/services/core/java/com/android/server/rollback/RollbackPackageHealthObserver.java +++ b/services/core/java/com/android/server/rollback/RollbackPackageHealthObserver.java @@ -120,9 +120,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve RollbackInfo rollback = getAvailableRollback(failedPackage); if (rollback == null) { - Slog.w(TAG, "Expected rollback but no valid rollback found for package: [ " - + failedPackage.getPackageName() + "] with versionCode: [" - + failedPackage.getVersionCode() + "]"); + Slog.w(TAG, "Expected rollback but no valid rollback found for " + failedPackage); return false; } rollbackPackage(rollback, failedPackage, rollbackReason); @@ -212,11 +210,7 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve RollbackManager rollbackManager = mContext.getSystemService(RollbackManager.class); for (RollbackInfo rollback : rollbackManager.getAvailableRollbacks()) { for (PackageRollbackInfo packageRollback : rollback.getPackages()) { - boolean hasFailedPackage = packageRollback.getPackageName().equals( - failedPackage.getPackageName()) - && packageRollback.getVersionRolledBackFrom().getVersionCode() - == failedPackage.getVersionCode(); - if (hasFailedPackage) { + if (packageRollback.getVersionRolledBackFrom().equals(failedPackage)) { return rollback; } } @@ -361,15 +355,6 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve } } - private VersionedPackage getVersionedPackage(String packageName) { - try { - return new VersionedPackage(packageName, mContext.getPackageManager().getPackageInfo( - packageName, 0 /* flags */).getLongVersionCode()); - } catch (PackageManager.NameNotFoundException e) { - return null; - } - } - /** * Rolls back the session that owns {@code failedPackage} * @@ -432,14 +417,8 @@ public final class RollbackPackageHealthObserver implements PackageHealthObserve List<RollbackInfo> rollbacks = rollbackManager.getAvailableRollbacks(); for (RollbackInfo rollback : rollbacks) { - String samplePackageName = rollback.getPackages().get(0).getPackageName(); - VersionedPackage sampleVersionedPackage = getVersionedPackage(samplePackageName); - if (sampleVersionedPackage == null) { - Slog.e(TAG, "Failed to rollback " + samplePackageName); - continue; - } - rollbackPackage(rollback, sampleVersionedPackage, - PackageWatchdog.FAILURE_REASON_NATIVE_CRASH); + VersionedPackage sample = rollback.getPackages().get(0).getVersionRolledBackFrom(); + rollbackPackage(rollback, sample, PackageWatchdog.FAILURE_REASON_NATIVE_CRASH); } } diff --git a/services/core/java/com/android/server/rollback/RollbackStore.java b/services/core/java/com/android/server/rollback/RollbackStore.java index 550c75442892..df75a29edd79 100644 --- a/services/core/java/com/android/server/rollback/RollbackStore.java +++ b/services/core/java/com/android/server/rollback/RollbackStore.java @@ -21,6 +21,7 @@ import static android.os.UserHandle.USER_SYSTEM; import static com.android.server.rollback.Rollback.rollbackStateFromString; import android.annotation.NonNull; +import android.content.pm.PackageManager; import android.content.pm.VersionedPackage; import android.content.rollback.PackageRollbackInfo; import android.content.rollback.PackageRollbackInfo.RestoreInfo; @@ -345,6 +346,8 @@ class RollbackStore { json.put("installedUsers", convertToJsonArray(snapshottedUsers)); json.put("ceSnapshotInodes", ceSnapshotInodesToJson(info.getCeSnapshotInodes())); + json.put("rollbackDataPolicy", info.getRollbackDataPolicy()); + return json; } @@ -367,8 +370,13 @@ class RollbackStore { final SparseLongArray ceSnapshotInodes = ceSnapshotInodesFromJson( json.getJSONArray("ceSnapshotInodes")); + // Backward compatibility: no such field for old versions. + final int rollbackDataPolicy = json.optInt("rollbackDataPolicy", + PackageManager.RollbackDataPolicy.RESTORE); + return new PackageRollbackInfo(versionRolledBackFrom, versionRolledBackTo, - pendingBackups, pendingRestores, isApex, snapshottedUsers, ceSnapshotInodes); + pendingBackups, pendingRestores, isApex, snapshottedUsers, ceSnapshotInodes, + rollbackDataPolicy); } private static JSONArray versionedPackagesToJson(List<VersionedPackage> packages) diff --git a/services/core/java/com/android/server/security/FileIntegrityService.java b/services/core/java/com/android/server/security/FileIntegrityService.java index 0bbb17950856..e90c02aabdfc 100644 --- a/services/core/java/com/android/server/security/FileIntegrityService.java +++ b/services/core/java/com/android/server/security/FileIntegrityService.java @@ -59,7 +59,7 @@ public class FileIntegrityService extends SystemService { } @Override - public boolean isAppSourceCertificateTrusted(byte[] certificateBytes) { + public boolean isAppSourceCertificateTrusted(@Nullable byte[] certificateBytes) { enforceAnyCallingPermissions( android.Manifest.permission.REQUEST_INSTALL_PACKAGES, android.Manifest.permission.INSTALL_PACKAGES); @@ -67,7 +67,10 @@ public class FileIntegrityService extends SystemService { if (!isApkVeritySupported()) { return false; } - + if (certificateBytes == null) { + Slog.w(TAG, "Received a null certificate"); + return false; + } return mTrustedCertificates.contains(toCertificate(certificateBytes)); } catch (CertificateException e) { Slog.e(TAG, "Failed to convert the certificate: " + e); @@ -122,7 +125,12 @@ public class FileIntegrityService extends SystemService { } for (File cert : files) { - collectCertificate(Files.readAllBytes(cert.toPath())); + byte[] certificateBytes = Files.readAllBytes(cert.toPath()); + if (certificateBytes == null) { + Slog.w(TAG, "The certificate file is empty, ignoring " + cert); + continue; + } + collectCertificate(certificateBytes); } } catch (IOException e) { Slog.wtf(TAG, "Failed to load fs-verity certificate from " + path, e); @@ -146,10 +154,10 @@ public class FileIntegrityService extends SystemService { * Tries to convert {@code bytes} into an X.509 certificate and store in memory. * Errors need to be surpressed in order fo the next certificates to still be collected. */ - private void collectCertificate(@Nullable byte[] bytes) { + private void collectCertificate(@NonNull byte[] bytes) { try { mTrustedCertificates.add(toCertificate(bytes)); - } catch (CertificateException | AssertionError e) { + } catch (CertificateException e) { Slog.e(TAG, "Invalid certificate, ignored: " + e); } } @@ -159,7 +167,7 @@ public class FileIntegrityService extends SystemService { * the rest. The rational is to make it harder to smuggle. */ @NonNull - private static X509Certificate toCertificate(@Nullable byte[] bytes) + private static X509Certificate toCertificate(@NonNull byte[] bytes) throws CertificateException { Certificate certificate = sCertFactory.generateCertificate(new ByteArrayInputStream(bytes)); if (!(certificate instanceof X509Certificate)) { diff --git a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareService.java b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareService.java index a7cfe1037f11..987c05fd8c9d 100644 --- a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareService.java +++ b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareService.java @@ -42,6 +42,7 @@ import com.android.server.SystemService; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; /** @@ -179,8 +180,8 @@ public class SoundTriggerMiddlewareService extends ISoundTriggerMiddlewareServic // Permission check. checkPermissions(); // Input validation. - Preconditions.checkNotNull(callback); - Preconditions.checkNotNull(callback.asBinder()); + Objects.requireNonNull(callback); + Objects.requireNonNull(callback.asBinder()); synchronized (this) { // State validation. diff --git a/services/core/java/com/android/server/soundtrigger_middleware/ValidationUtil.java b/services/core/java/com/android/server/soundtrigger_middleware/ValidationUtil.java index 4898e6b59ab2..43047d1ebaaa 100644 --- a/services/core/java/com/android/server/soundtrigger_middleware/ValidationUtil.java +++ b/services/core/java/com/android/server/soundtrigger_middleware/ValidationUtil.java @@ -29,6 +29,7 @@ import android.media.soundtrigger_middleware.SoundModelType; import com.android.internal.util.Preconditions; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -42,7 +43,7 @@ import java.util.regex.Pattern; */ public class ValidationUtil { static void validateUuid(@Nullable String uuid) { - Preconditions.checkNotNull(uuid); + Objects.requireNonNull(uuid); Matcher matcher = UuidUtil.PATTERN.matcher(uuid); if (!matcher.matches()) { throw new IllegalArgumentException( @@ -55,37 +56,37 @@ public class ValidationUtil { } static void validateModel(@Nullable SoundModel model, int expectedType) { - Preconditions.checkNotNull(model); + Objects.requireNonNull(model); if (model.type != expectedType) { throw new IllegalArgumentException("Invalid type"); } validateUuid(model.uuid); validateUuid(model.vendorUuid); - Preconditions.checkNotNull(model.data); + Objects.requireNonNull(model.data); } static void validatePhraseModel(@Nullable PhraseSoundModel model) { - Preconditions.checkNotNull(model); + Objects.requireNonNull(model); validateModel(model.common, SoundModelType.KEYPHRASE); - Preconditions.checkNotNull(model.phrases); + Objects.requireNonNull(model.phrases); for (Phrase phrase : model.phrases) { - Preconditions.checkNotNull(phrase); + Objects.requireNonNull(phrase); if ((phrase.recognitionModes & ~(RecognitionMode.VOICE_TRIGGER | RecognitionMode.USER_IDENTIFICATION | RecognitionMode.USER_AUTHENTICATION | RecognitionMode.GENERIC_TRIGGER)) != 0) { throw new IllegalArgumentException("Invalid recognitionModes"); } - Preconditions.checkNotNull(phrase.users); - Preconditions.checkNotNull(phrase.locale); - Preconditions.checkNotNull(phrase.text); + Objects.requireNonNull(phrase.users); + Objects.requireNonNull(phrase.locale); + Objects.requireNonNull(phrase.text); } } static void validateRecognitionConfig(@Nullable RecognitionConfig config) { - Preconditions.checkNotNull(config); - Preconditions.checkNotNull(config.phraseRecognitionExtras); + Objects.requireNonNull(config); + Objects.requireNonNull(config.phraseRecognitionExtras); for (PhraseRecognitionExtra extra : config.phraseRecognitionExtras) { - Preconditions.checkNotNull(extra); + Objects.requireNonNull(extra); if ((extra.recognitionModes & ~(RecognitionMode.VOICE_TRIGGER | RecognitionMode.USER_IDENTIFICATION | RecognitionMode.USER_AUTHENTICATION | RecognitionMode.GENERIC_TRIGGER)) != 0) { @@ -94,15 +95,15 @@ public class ValidationUtil { if (extra.confidenceLevel < 0 || extra.confidenceLevel > 100) { throw new IllegalArgumentException("Invalid confidenceLevel"); } - Preconditions.checkNotNull(extra.levels); + Objects.requireNonNull(extra.levels); for (ConfidenceLevel level : extra.levels) { - Preconditions.checkNotNull(level); + Objects.requireNonNull(level); if (level.levelPercent < 0 || level.levelPercent > 100) { throw new IllegalArgumentException("Invalid confidenceLevel"); } } } - Preconditions.checkNotNull(config.data); + Objects.requireNonNull(config.data); } static void validateModelParameter(int modelParam) { diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index ac1dbc4b755a..6c3b58018392 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -296,6 +296,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; /** @@ -6164,7 +6165,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { final class LocalService extends ActivityTaskManagerInternal { @Override public SleepToken acquireSleepToken(String tag, int displayId) { - Preconditions.checkNotNull(tag); + Objects.requireNonNull(tag); return ActivityTaskManagerService.this.acquireSleepToken(tag, displayId); } @@ -6221,7 +6222,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { @Override public int startActivitiesAsPackage(String packageName, int userId, Intent[] intents, Bundle bOptions) { - Preconditions.checkNotNull(intents, "intents"); + Objects.requireNonNull(intents, "intents"); final String[] resolvedTypes = new String[intents.length]; // UID of the package on user userId. diff --git a/services/core/java/com/android/server/wm/DragDropController.java b/services/core/java/com/android/server/wm/DragDropController.java index d5f403f85621..999aab982816 100644 --- a/services/core/java/com/android/server/wm/DragDropController.java +++ b/services/core/java/com/android/server/wm/DragDropController.java @@ -37,6 +37,7 @@ import android.view.View; import com.android.internal.util.Preconditions; import com.android.server.wm.WindowManagerInternal.IDragDropCallback; +import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; /** @@ -74,7 +75,7 @@ class DragDropController { } void registerCallback(IDragDropCallback callback) { - Preconditions.checkNotNull(callback); + Objects.requireNonNull(callback); mCallback.set(callback); } diff --git a/services/core/java/com/android/server/wm/WindowManagerConstants.java b/services/core/java/com/android/server/wm/WindowManagerConstants.java index 74d5c049746d..b0c5dbc6cca3 100644 --- a/services/core/java/com/android/server/wm/WindowManagerConstants.java +++ b/services/core/java/com/android/server/wm/WindowManagerConstants.java @@ -19,8 +19,6 @@ package com.android.server.wm; import static android.provider.AndroidDeviceConfig.KEY_SYSTEM_GESTURES_EXCLUDED_BY_PRE_Q_STICKY_IMMERSIVE; import static android.provider.AndroidDeviceConfig.KEY_SYSTEM_GESTURE_EXCLUSION_LIMIT_DP; -import static com.android.internal.util.Preconditions.checkNotNull; - import android.provider.AndroidDeviceConfig; import android.provider.DeviceConfig; @@ -28,6 +26,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.server.wm.utils.DeviceConfigInterface; import java.io.PrintWriter; +import java.util.Objects; import java.util.concurrent.Executor; /** @@ -74,8 +73,8 @@ final class WindowManagerConstants { WindowManagerConstants(WindowManagerGlobalLock globalLock, Runnable updateSystemGestureExclusionCallback, DeviceConfigInterface deviceConfig) { - mGlobalLock = checkNotNull(globalLock); - mUpdateSystemGestureExclusionCallback = checkNotNull(updateSystemGestureExclusionCallback); + mGlobalLock = Objects.requireNonNull(globalLock); + mUpdateSystemGestureExclusionCallback = Objects.requireNonNull(updateSystemGestureExclusionCallback); mDeviceConfig = deviceConfig; mListenerAndroid = this::onAndroidPropertiesChanged; mListenerWindowManager = this::onWindowPropertiesChanged; diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 53c5ebde05bf..9c554d997068 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -296,6 +296,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import java.util.function.Supplier; @@ -2864,7 +2865,7 @@ public class WindowManagerService extends IWindowManager.Stub != PackageManager.PERMISSION_GRANTED) { throw new SecurityException("Requires DISABLE_KEYGUARD permission"); } - Preconditions.checkNotNull(token, "token is null"); + Objects.requireNonNull(token, "token is null"); final int callingUid = Binder.getCallingUid(); final long origIdentity = Binder.clearCallingIdentity(); try { diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 153681677d78..272edf7ef26c 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -303,6 +303,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -2266,23 +2267,23 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @VisibleForTesting DevicePolicyManagerService(Injector injector) { mInjector = injector; - mContext = Preconditions.checkNotNull(injector.mContext); - mHandler = new Handler(Preconditions.checkNotNull(injector.getMyLooper())); + mContext = Objects.requireNonNull(injector.mContext); + mHandler = new Handler(Objects.requireNonNull(injector.getMyLooper())); mConstantsObserver = new DevicePolicyConstantsObserver(mHandler); mConstantsObserver.register(); mConstants = loadConstants(); - mOwners = Preconditions.checkNotNull(injector.newOwners()); + mOwners = Objects.requireNonNull(injector.newOwners()); - mUserManager = Preconditions.checkNotNull(injector.getUserManager()); - mUserManagerInternal = Preconditions.checkNotNull(injector.getUserManagerInternal()); - mUsageStatsManagerInternal = Preconditions.checkNotNull( + mUserManager = Objects.requireNonNull(injector.getUserManager()); + mUserManagerInternal = Objects.requireNonNull(injector.getUserManagerInternal()); + mUsageStatsManagerInternal = Objects.requireNonNull( injector.getUsageStatsManagerInternal()); - mIPackageManager = Preconditions.checkNotNull(injector.getIPackageManager()); - mIPlatformCompat = Preconditions.checkNotNull(injector.getIPlatformCompat()); - mIPermissionManager = Preconditions.checkNotNull(injector.getIPermissionManager()); - mTelephonyManager = Preconditions.checkNotNull(injector.getTelephonyManager()); + mIPackageManager = Objects.requireNonNull(injector.getIPackageManager()); + mIPlatformCompat = Objects.requireNonNull(injector.getIPlatformCompat()); + mIPermissionManager = Objects.requireNonNull(injector.getIPermissionManager()); + mTelephonyManager = Objects.requireNonNull(injector.getTelephonyManager()); mLocalService = new LocalService(); mLockPatternUtils = injector.newLockPatternUtils(); @@ -4047,7 +4048,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(adminReceiver, "ComponentName is null"); + Objects.requireNonNull(adminReceiver, "ComponentName is null"); enforceShell("forceRemoveActiveAdmin"); mInjector.binderWithCleanCallingIdentity(() -> { synchronized (getLockObject()) { @@ -4164,7 +4165,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); validateQualityConstant(quality); final int userId = mInjector.userHandleGetCallingUserId(); @@ -4377,7 +4378,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -4419,7 +4420,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mLockPatternUtils.hasSecureLockScreen()) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -4451,7 +4452,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mLockPatternUtils.hasSecureLockScreen()) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); Preconditions.checkArgumentNonnegative(timeout, "Timeout must be >= 0 ms"); final int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { @@ -4633,7 +4634,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { final ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -4663,7 +4664,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setPasswordMinimumLowerCase(ComponentName who, int length, boolean parent) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -4696,7 +4697,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -4728,7 +4729,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -4760,7 +4761,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -4792,7 +4793,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -5019,7 +5020,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mLockPatternUtils.hasSecureLockScreen()) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { // This API can only be called by an active device admin, @@ -5259,7 +5260,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { final ActiveAdmin ap = getActiveAdminForCallerLocked( @@ -5360,7 +5361,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mLockPatternUtils.hasSecureLockScreen()) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); Preconditions.checkArgument(timeoutMs >= 0, "Timeout must not be a negative number."); // timeoutMs with value 0 means that the admin doesn't participate // timeoutMs is clamped to the interval in case the internal constants change in the future @@ -6108,7 +6109,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setDelegatedScopes(ComponentName who, String delegatePackage, List<String> scopeList) throws SecurityException { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); Preconditions.checkStringNotEmpty(delegatePackage, "Delegate package is null or empty"); Preconditions.checkCollectionElementsNotNull(scopeList, "Scopes"); // Remove possible duplicates. @@ -6206,7 +6207,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @NonNull public List<String> getDelegatedScopes(ComponentName who, String delegatePackage) throws SecurityException { - Preconditions.checkNotNull(delegatePackage, "Delegate package is null"); + Objects.requireNonNull(delegatePackage, "Delegate package is null"); // Retrieve the user ID of the calling process. final int callingUid = mInjector.binderGetCallingUid(); @@ -6246,8 +6247,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @NonNull public List<String> getDelegatePackages(ComponentName who, String scope) throws SecurityException { - Preconditions.checkNotNull(who, "ComponentName is null"); - Preconditions.checkNotNull(scope, "Scope is null"); + Objects.requireNonNull(who, "ComponentName is null"); + Objects.requireNonNull(scope, "Scope is null"); if (!Arrays.asList(DELEGATIONS).contains(scope)) { throw new IllegalArgumentException("Unexpected delegation scope: " + scope); } @@ -6329,7 +6330,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { * @return {@code true} if the calling process is a delegate of {@code scope}. */ private boolean isCallerDelegate(String callerPackage, int callerUid, String scope) { - Preconditions.checkNotNull(callerPackage, "callerPackage is null"); + Objects.requireNonNull(callerPackage, "callerPackage is null"); if (!Arrays.asList(DELEGATIONS).contains(scope)) { throw new IllegalArgumentException("Unexpected delegation scope: " + scope); } @@ -6410,7 +6411,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { */ private void setDelegatedScopePreO(ComponentName who, String delegatePackage, String scope) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { @@ -6938,7 +6939,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return null; } synchronized (getLockObject()) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); // Only check if system user has set global proxy. We don't allow other users to set it. DevicePolicyData policy = getUserData(UserHandle.USER_SYSTEM); @@ -7066,7 +7067,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (getLockObject()) { // Check for permissions @@ -7220,7 +7221,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked(who, @@ -7287,7 +7288,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, @@ -7347,7 +7348,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); // TODO (b/145286957) Refactor security checks enforceDeviceOwnerOrProfileOwnerOnUser0OrProfileOwnerOrganizationOwned(); @@ -7369,7 +7370,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceDeviceOwnerOrProfileOwnerOnUser0OrProfileOwnerOrganizationOwned(); return mInjector.settingsGlobalGetInt(Global.AUTO_TIME, 0) > 0; @@ -7383,7 +7384,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); // TODO (b/145286957) Refactor security checks enforceDeviceOwnerOrProfileOwnerOnUser0OrProfileOwnerOrganizationOwned(); @@ -7405,7 +7406,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceDeviceOwnerOrProfileOwnerOnUser0OrProfileOwnerOrganizationOwned(); return mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) > 0; @@ -7416,7 +7417,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); // Allow setting this policy to true only if there is a split system user. if (forceEphemeralUsers && !mInjector.userManagerIsSplitSystemUser()) { throw new UnsupportedOperationException( @@ -7443,7 +7444,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { final ActiveAdmin deviceOwner = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); @@ -7472,7 +7473,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); // TODO: If an unaffiliated user is removed, the admin will be able to request a bugreport // which could still contain data related to that user. Should we disallow that, e.g. until @@ -7709,7 +7710,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked(who, @@ -7779,7 +7780,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = mInjector.userHandleGetCallingUserId(); if (isManagedProfile(userHandle)) { if (parent) { @@ -7867,7 +7868,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(packageList, "packageList is null"); + Objects.requireNonNull(packageList, "packageList is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (getLockObject()) { // Ensure the caller is a DO or a keep uninstalled packages delegate. @@ -8104,7 +8105,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void clearDeviceOwner(String packageName) { - Preconditions.checkNotNull(packageName, "packageName is null"); + Objects.requireNonNull(packageName, "packageName is null"); final int callingUid = mInjector.binderGetCallingUid(); try { int uid = mInjector.getPackageManager().getPackageUidAsUser(packageName, @@ -8259,7 +8260,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); enforceNotManagedProfile(userId, "clear profile owner"); @@ -8300,7 +8301,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setDeviceOwnerLockScreenInfo(ComponentName who, CharSequence info) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); if (!mHasFeature) { return; } @@ -8470,7 +8471,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { // Check if this is the profile owner who is calling getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -8497,7 +8498,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setProfileName(ComponentName who, String profileName) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceProfileOrDeviceOwner(who); final int userId = UserHandle.getCallingUserId(); @@ -9090,7 +9091,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void addPersistentPreferredActivity(ComponentName who, IntentFilter filter, ComponentName activity) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -9116,7 +9117,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void clearPackagePersistentPreferredActivities(ComponentName who, String packageName) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -9135,7 +9136,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setDefaultSmsApplication(ComponentName admin, String packageName) { - Preconditions.checkNotNull(admin, "ComponentName is null"); + Objects.requireNonNull(admin, "ComponentName is null"); enforceDeviceOwner(admin); mInjector.binderWithCleanCallingIdentity(() -> SmsApplication.setDefaultApplication(packageName, mContext)); @@ -9190,8 +9191,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mLockPatternUtils.hasSecureLockScreen()) { return; } - Preconditions.checkNotNull(admin, "admin is null"); - Preconditions.checkNotNull(agent, "agent is null"); + Objects.requireNonNull(admin, "admin is null"); + Objects.requireNonNull(agent, "agent is null"); final int userHandle = UserHandle.getCallingUserId(); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked(admin, @@ -9207,7 +9208,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mLockPatternUtils.hasSecureLockScreen()) { return null; } - Preconditions.checkNotNull(agent, "agent null"); + Objects.requireNonNull(agent, "agent null"); enforceFullCrossUsersPermission(userHandle); synchronized (getLockObject()) { @@ -9259,7 +9260,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setRestrictionsProvider(ComponentName who, ComponentName permissionProvider) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -9281,7 +9282,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void addCrossProfileIntentFilter(ComponentName who, IntentFilter filter, int flags) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); int callingUserId = UserHandle.getCallingUserId(); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -9330,7 +9331,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void clearCrossProfileIntentFilters(ComponentName who) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); int callingUserId = UserHandle.getCallingUserId(); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -9407,7 +9408,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); if (packageList != null) { int userId = UserHandle.getCallingUserId(); @@ -9460,7 +9461,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, @@ -9536,7 +9537,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return true; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); Preconditions.checkStringNotEmpty(packageName, "packageName is null"); enforceSystemCaller("query if an accessibility service is disabled by admin"); @@ -9587,7 +9588,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int callingUserId = mInjector.userHandleGetCallingUserId(); if (packageList != null) { List<InputMethodInfo> enabledImes = InputMethodManagerInternal.get() @@ -9627,7 +9628,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, @@ -9681,7 +9682,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return true; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); Preconditions.checkStringNotEmpty(packageName, "packageName is null"); enforceSystemCaller("query if an input method is disabled by admin"); @@ -9704,7 +9705,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int callingUserId = mInjector.userHandleGetCallingUserId(); if (!isManagedProfile(callingUserId)) { @@ -9725,7 +9726,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked( @@ -9787,8 +9788,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public UserHandle createAndManageUser(ComponentName admin, String name, ComponentName profileOwner, PersistableBundle adminExtras, int flags) { - Preconditions.checkNotNull(admin, "admin is null"); - Preconditions.checkNotNull(profileOwner, "profileOwner is null"); + Objects.requireNonNull(admin, "admin is null"); + Objects.requireNonNull(profileOwner, "profileOwner is null"); if (!admin.getPackageName().equals(profileOwner.getPackageName())) { throw new IllegalArgumentException("profileOwner " + profileOwner + " and admin " + admin + " are not in the same package"); @@ -9919,8 +9920,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean removeUser(ComponentName who, UserHandle userHandle) { - Preconditions.checkNotNull(who, "ComponentName is null"); - Preconditions.checkNotNull(userHandle, "UserHandle is null"); + Objects.requireNonNull(who, "ComponentName is null"); + Objects.requireNonNull(userHandle, "UserHandle is null"); enforceDeviceOwner(who); final int callingUserId = mInjector.userHandleGetCallingUserId(); @@ -9953,7 +9954,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean switchUser(ComponentName who, UserHandle userHandle) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); @@ -9976,8 +9977,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public int startUserInBackground(ComponentName who, UserHandle userHandle) { - Preconditions.checkNotNull(who, "ComponentName is null"); - Preconditions.checkNotNull(userHandle, "UserHandle is null"); + Objects.requireNonNull(who, "ComponentName is null"); + Objects.requireNonNull(userHandle, "UserHandle is null"); enforceDeviceOwner(who); final int userId = userHandle.getIdentifier(); @@ -10008,8 +10009,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public int stopUser(ComponentName who, UserHandle userHandle) { - Preconditions.checkNotNull(who, "ComponentName is null"); - Preconditions.checkNotNull(userHandle, "UserHandle is null"); + Objects.requireNonNull(who, "ComponentName is null"); + Objects.requireNonNull(userHandle, "UserHandle is null"); enforceDeviceOwner(who); final int userId = userHandle.getIdentifier(); @@ -10023,7 +10024,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public int logoutUser(ComponentName who) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int callingUserId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { @@ -10077,7 +10078,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public List<UserHandle> getSecondaryUsers(ComponentName who) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceDeviceOwner(who); return mInjector.binderWithCleanCallingIdentity(() -> { @@ -10096,7 +10097,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean isEphemeralUser(ComponentName who) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceProfileOrDeviceOwner(who); final int callingUserId = mInjector.userHandleGetCallingUserId(); @@ -10178,7 +10179,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setUserRestriction(ComponentName who, String key, boolean enabledFromThisOwner, boolean parent) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); if (!UserRestrictionsUtils.isValidRestriction(key)) { return; } @@ -10324,7 +10325,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { final ActiveAdmin activeAdmin = getActiveAdminForCallerLocked(who, @@ -10559,7 +10560,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin ap = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -10653,7 +10654,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -10674,7 +10675,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -10696,7 +10697,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -10717,7 +10718,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -10797,7 +10798,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -10818,7 +10819,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -10840,8 +10841,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setLockTaskPackages(ComponentName who, String[] packages) throws SecurityException { - Preconditions.checkNotNull(who, "ComponentName is null"); - Preconditions.checkNotNull(packages, "packages is null"); + Objects.requireNonNull(who, "ComponentName is null"); + Objects.requireNonNull(packages, "packages is null"); synchronized (getLockObject()) { enforceCanCallLockTaskLocked(who); @@ -10861,7 +10862,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public String[] getLockTaskPackages(ComponentName who) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = mInjector.binderGetCallingUserHandle().getIdentifier(); synchronized (getLockObject()) { @@ -10881,7 +10882,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setLockTaskFeatures(ComponentName who, int flags) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); // Throw if Overview is used without Home. boolean hasHome = (flags & LOCK_TASK_FEATURE_HOME) != 0; @@ -10908,7 +10909,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public int getLockTaskFeatures(ComponentName who) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { enforceCanCallLockTaskLocked(who); @@ -10978,7 +10979,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setGlobalSetting(ComponentName who, String setting, String value) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); DevicePolicyEventLogger .createEvent(DevicePolicyEnums.SET_GLOBAL_SETTING) @@ -11018,7 +11019,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setSystemSetting(ComponentName who, String setting, String value) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); Preconditions.checkStringNotEmpty(setting, "String setting is null or empty"); synchronized (getLockObject()) { @@ -11038,7 +11039,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setLocationEnabled(ComponentName who, boolean locationEnabled) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceDeviceOwner(who); UserHandle userHandle = mInjector.binderGetCallingUserHandle(); @@ -11057,7 +11058,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean setTime(ComponentName who, long millis) { - Preconditions.checkNotNull(who, "ComponentName is null in setTime"); + Objects.requireNonNull(who, "ComponentName is null in setTime"); enforceDeviceOwner(who); // Don't allow set time when auto time is on. if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME, 0) == 1) { @@ -11072,7 +11073,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean setTimeZone(ComponentName who, String timeZone) { - Preconditions.checkNotNull(who, "ComponentName is null in setTimeZone"); + Objects.requireNonNull(who, "ComponentName is null in setTimeZone"); enforceDeviceOwner(who); // Don't allow set timezone when auto timezone is on. if (mInjector.settingsGlobalGetInt(Global.AUTO_TIME_ZONE, 0) == 1) { @@ -11088,7 +11089,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setSecureSetting(ComponentName who, String setting, String value) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); int callingUserId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { @@ -11159,7 +11160,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setMasterVolumeMuted(ComponentName who, boolean on) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); setUserRestriction(who, UserManager.DISALLOW_UNMUTE_DEVICE, on, /* parent */ false); @@ -11173,7 +11174,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean isMasterVolumeMuted(ComponentName who) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -11186,7 +11187,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void setUserIcon(ComponentName who, Bitmap icon) { synchronized (getLockObject()) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); int userId = UserHandle.getCallingUserId(); @@ -11201,7 +11202,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean setKeyguardDisabled(ComponentName who, boolean disabled) { - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userId = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -11664,7 +11665,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public Intent createAdminSupportIntent(String restriction) { - Preconditions.checkNotNull(restriction); + Objects.requireNonNull(restriction); final int uid = mInjector.binderGetCallingUid(); final int userId = UserHandle.getUserId(uid); Intent intent = null; @@ -11922,7 +11923,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public SystemUpdateInfo getPendingSystemUpdate(ComponentName admin) { - Preconditions.checkNotNull(admin, "ComponentName is null"); + Objects.requireNonNull(admin, "ComponentName is null"); enforceProfileOrDeviceOwner(admin); return mOwners.getSystemUpdateInfo(); @@ -11964,7 +11965,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { public void setPermissionGrantState(ComponentName admin, String callerPackage, String packageName, String permission, int grantState, RemoteCallback callback) throws RemoteException { - Preconditions.checkNotNull(callback); + Objects.requireNonNull(callback); UserHandle user = mInjector.binderGetCallingUserHandle(); synchronized (getLockObject()) { @@ -12099,7 +12100,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean isProvisioningAllowed(String action, String packageName) { - Preconditions.checkNotNull(packageName); + Objects.requireNonNull(packageName); final int callingUid = mInjector.binderGetCallingUid(); final long ident = mInjector.binderClearCallingIdentity(); @@ -12119,7 +12120,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public int checkProvisioningPreCondition(String action, String packageName) { - Preconditions.checkNotNull(packageName); + Objects.requireNonNull(packageName); enforceCanManageProfileAndDeviceOwners(); return checkProvisioningPreConditionSkipPermission(action, packageName); } @@ -12359,7 +12360,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void reboot(ComponentName admin) { - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); // Make sure caller has DO. enforceDeviceOwner(admin); mInjector.binderWithCleanCallingIdentity(() -> { @@ -12380,7 +12381,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForUidLocked(who, mInjector.binderGetCallingUid()); @@ -12400,7 +12401,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForUidLocked(who, mInjector.binderGetCallingUid()); return admin.shortSupportMessage; @@ -12412,7 +12413,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForUidLocked(who, mInjector.binderGetCallingUid()); @@ -12432,7 +12433,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForUidLocked(who, mInjector.binderGetCallingUid()); return admin.longSupportMessage; @@ -12444,7 +12445,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceSystemCaller("query support message for user"); synchronized (getLockObject()) { @@ -12461,7 +12462,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceSystemCaller("query support message for user"); synchronized (getLockObject()) { @@ -12478,7 +12479,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = mInjector.userHandleGetCallingUserId(); enforceManagedProfile(userHandle, "set organization color"); synchronized (getLockObject()) { @@ -12513,7 +12514,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return ActiveAdmin.DEF_ORGANIZATION_COLOR; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceManagedProfile(mInjector.userHandleGetCallingUserId(), "get organization color"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, @@ -12542,7 +12543,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); final int userHandle = mInjector.userHandleGetCallingUserId(); synchronized (getLockObject()) { @@ -12561,7 +12562,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceManagedProfile(mInjector.userHandleGetCallingUserId(), "get organization name"); synchronized (getLockObject()) { ActiveAdmin admin = getActiveAdminForCallerLocked(who, @@ -12599,8 +12600,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public List<String> setMeteredDataDisabledPackages(ComponentName who, List<String> packageNames) { - Preconditions.checkNotNull(who); - Preconditions.checkNotNull(packageNames); + Objects.requireNonNull(who); + Objects.requireNonNull(packageNames); if (!mHasFeature) { return packageNames; @@ -12646,7 +12647,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public List<String> getMeteredDataDisabledPackages(ComponentName who) { - Preconditions.checkNotNull(who); + Objects.requireNonNull(who); if (!mHasFeature) { return new ArrayList<>(); @@ -12662,7 +12663,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean isMeteredDataDisabledPackageForUser(ComponentName who, String packageName, int userId) { - Preconditions.checkNotNull(who); + Objects.requireNonNull(who); if (!mHasFeature) { return false; @@ -12688,7 +12689,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { public void markProfileOwnerOnOrganizationOwnedDevice(ComponentName who, int userId) { // As the caller is the system, it must specify the component name of the profile owner // as a sanity / safety check. - Preconditions.checkNotNull(who); + Objects.requireNonNull(who); if (!mHasFeature) { return; @@ -12808,7 +12809,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return Collections.emptyList(); } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); synchronized (getLockObject()) { getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); return new ArrayList<String>( @@ -12877,7 +12878,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); synchronized (getLockObject()) { getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); @@ -12907,7 +12908,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { synchronized (getLockObject()) { if (!isCallerWithSystemUid()) { - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); } return mInjector.securityLogGetLoggingEnabledProperty(); @@ -12931,7 +12932,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return null; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); ensureDeviceOwnerAndAllUsersAffiliated(admin); DevicePolicyEventLogger @@ -12961,7 +12962,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return null; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); ensureDeviceOwnerAndAllUsersAffiliated(admin); if (!mInjector.securityLogGetLoggingEnabledProperty()) { @@ -13206,7 +13207,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); enforceProfileOrDeviceOwner(admin); int userId = mInjector.userHandleGetCallingUserId(); toggleBackupServiceActive(userId, enabled); @@ -13214,7 +13215,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public boolean isBackupServiceEnabled(ComponentName admin) { - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); if (!mHasFeature) { return true; } @@ -13239,14 +13240,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return false; } - Preconditions.checkNotNull(admin); - Preconditions.checkNotNull(caller); - Preconditions.checkNotNull(serviceIntent); + Objects.requireNonNull(admin); + Objects.requireNonNull(caller); + Objects.requireNonNull(serviceIntent); Preconditions.checkArgument( serviceIntent.getComponent() != null || serviceIntent.getPackage() != null, "Service intent must be explicit (with a package name or component): " + serviceIntent); - Preconditions.checkNotNull(connection); + Objects.requireNonNull(connection); Preconditions.checkArgument(mInjector.userHandleGetCallingUserId() != targetUserId, "target user id must be different from the calling user id"); @@ -13290,7 +13291,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return Collections.emptyList(); } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); synchronized (getLockObject()) { getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -13755,7 +13756,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mLockPatternUtils.hasSecureLockScreen()) { return false; } - Preconditions.checkNotNull(token); + Objects.requireNonNull(token); synchronized (getLockObject()) { final int userHandle = mInjector.userHandleGetCallingUserId(); getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -13791,9 +13792,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { @Override public void clearApplicationUserData(ComponentName admin, String packageName, IPackageDataObserver callback) { - Preconditions.checkNotNull(admin, "ComponentName is null"); - Preconditions.checkNotNull(packageName, "packageName is null"); - Preconditions.checkNotNull(callback, "callback is null"); + Objects.requireNonNull(admin, "ComponentName is null"); + Objects.requireNonNull(packageName, "packageName is null"); + Objects.requireNonNull(callback, "callback is null"); enforceProfileOrDeviceOwner(admin); final int userId = UserHandle.getCallingUserId(); @@ -13824,7 +13825,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); synchronized (getLockObject()) { ActiveAdmin deviceOwner = @@ -13865,8 +13866,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return; } - Preconditions.checkNotNull(admin, "Admin cannot be null."); - Preconditions.checkNotNull(target, "Target cannot be null."); + Objects.requireNonNull(admin, "Admin cannot be null."); + Objects.requireNonNull(target, "Target cannot be null."); enforceProfileOrDeviceOwner(admin); @@ -14001,7 +14002,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); final String startUserSessionMessageString = startUserSessionMessage != null ? startUserSessionMessage.toString() : null; @@ -14026,7 +14027,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); final String endUserSessionMessageString = endUserSessionMessage != null ? endUserSessionMessage.toString() : null; @@ -14051,7 +14052,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); synchronized (getLockObject()) { final ActiveAdmin deviceOwner = @@ -14065,7 +14066,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return null; } - Preconditions.checkNotNull(admin); + Objects.requireNonNull(admin); synchronized (getLockObject()) { final ActiveAdmin deviceOwner = @@ -14108,8 +14109,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mHasTelephonyFeature) { return -1; } - Preconditions.checkNotNull(who, "ComponentName is null in addOverrideApn"); - Preconditions.checkNotNull(apnSetting, "ApnSetting is null in addOverrideApn"); + Objects.requireNonNull(who, "ComponentName is null in addOverrideApn"); + Objects.requireNonNull(apnSetting, "ApnSetting is null in addOverrideApn"); enforceDeviceOwner(who); int operatedId = -1; @@ -14132,8 +14133,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mHasTelephonyFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null in updateOverrideApn"); - Preconditions.checkNotNull(apnSetting, "ApnSetting is null in updateOverrideApn"); + Objects.requireNonNull(who, "ComponentName is null in updateOverrideApn"); + Objects.requireNonNull(apnSetting, "ApnSetting is null in updateOverrideApn"); enforceDeviceOwner(who); if (apnId < 0) { @@ -14150,7 +14151,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mHasTelephonyFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null in removeOverrideApn"); + Objects.requireNonNull(who, "ComponentName is null in removeOverrideApn"); enforceDeviceOwner(who); return removeOverrideApnUnchecked(apnId); @@ -14171,7 +14172,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mHasTelephonyFeature) { return Collections.emptyList(); } - Preconditions.checkNotNull(who, "ComponentName is null in getOverrideApns"); + Objects.requireNonNull(who, "ComponentName is null in getOverrideApns"); enforceDeviceOwner(who); return getOverrideApnsUnchecked(); @@ -14202,7 +14203,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mHasTelephonyFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null in setOverrideApnEnabled"); + Objects.requireNonNull(who, "ComponentName is null in setOverrideApnEnabled"); enforceDeviceOwner(who); setOverrideApnsEnabledUnchecked(enabled); @@ -14220,7 +14221,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature || !mHasTelephonyFeature) { return false; } - Preconditions.checkNotNull(who, "ComponentName is null in isOverrideApnEnabled"); + Objects.requireNonNull(who, "ComponentName is null in isOverrideApnEnabled"); enforceDeviceOwner(who); Cursor enforceCursor = mInjector.binderWithCleanCallingIdentity( @@ -14304,7 +14305,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return PRIVATE_DNS_SET_ERROR_FAILURE_SETTING; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceDeviceOwner(who); final int returnCode; @@ -14342,7 +14343,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return PRIVATE_DNS_MODE_UNKNOWN; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceDeviceOwner(who); String currentMode = mInjector.settingsGlobalGetString(PRIVATE_DNS_MODE); if (currentMode == null) { @@ -14366,7 +14367,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return null; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); enforceDeviceOwner(who); return mInjector.settingsGlobalGetString(PRIVATE_DNS_SPECIFIER); @@ -14404,7 +14405,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { final ActiveAdmin admin = getActiveAdminForCallerLocked( @@ -14425,7 +14426,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return Collections.emptyList(); } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { final ActiveAdmin admin = getActiveAdminForCallerLocked( @@ -14479,8 +14480,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return; } - Preconditions.checkNotNull(who, "ComponentName is null"); - Preconditions.checkNotNull(packageNames, "Package names is null"); + Objects.requireNonNull(who, "ComponentName is null"); + Objects.requireNonNull(packageNames, "Package names is null"); synchronized (getLockObject()) { final ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); @@ -14494,7 +14495,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { if (!mHasFeature) { return Collections.emptyList(); } - Preconditions.checkNotNull(who, "ComponentName is null"); + Objects.requireNonNull(who, "ComponentName is null"); synchronized (getLockObject()) { final ActiveAdmin admin = getActiveAdminForCallerLocked( diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/TransferOwnershipMetadataManager.java b/services/devicepolicy/java/com/android/server/devicepolicy/TransferOwnershipMetadataManager.java index dd3bfc3c4a93..4b66beaa2cb0 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/TransferOwnershipMetadataManager.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/TransferOwnershipMetadataManager.java @@ -39,6 +39,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Objects; /** * Handles reading and writing of the owner transfer metadata file. @@ -185,8 +186,8 @@ class TransferOwnershipMetadataManager { @NonNull int userId, @NonNull String adminType) { this.sourceComponent = sourceComponent; this.targetComponent = targetComponent; - Preconditions.checkNotNull(sourceComponent); - Preconditions.checkNotNull(targetComponent); + Objects.requireNonNull(sourceComponent); + Objects.requireNonNull(targetComponent); Preconditions.checkStringNotEmpty(adminType); this.userId = userId; this.adminType = adminType; @@ -199,7 +200,7 @@ class TransferOwnershipMetadataManager { } private static ComponentName unflattenComponentUnchecked(String flatComponent) { - Preconditions.checkNotNull(flatComponent); + Objects.requireNonNull(flatComponent); return ComponentName.unflattenFromString(flatComponent); } diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java index 529339e48546..f553a4818fa2 100644 --- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java @@ -48,6 +48,7 @@ import android.app.AppOpsManager.PackageOps; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManagerInternal; +import android.content.pm.parsing.AndroidPackage; import android.os.Handler; import android.os.HandlerThread; import android.os.Process; @@ -68,6 +69,7 @@ import org.junit.runner.RunWith; import org.mockito.quality.Strictness; import java.io.File; +import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -138,11 +140,15 @@ public class AppOpsServiceTest { .spyStatic(Settings.Global.class) .startMocking(); - // Mock LocalServices.getService(PackageManagerInternal.class).getApplicationInfo dependency + // Mock LocalServices.getService(PackageManagerInternal.class).getPackage dependency // needed by AppOpsService PackageManagerInternal mockPackageManagerInternal = mock(PackageManagerInternal.class); - when(mockPackageManagerInternal.getApplicationInfo(eq(sMyPackageName), anyInt(), anyInt(), - anyInt())).thenReturn(sContext.getApplicationInfo()); + AndroidPackage mockMyPkg = mock(AndroidPackage.class); + when(mockMyPkg.isPrivileged()).thenReturn(false); + when(mockMyPkg.getUid()).thenReturn(mMyUid); + when(mockMyPkg.getFeatures()).thenReturn(Collections.emptyList()); + + when(mockPackageManagerInternal.getPackage(sMyPackageName)).thenReturn(mockMyPkg); doReturn(mockPackageManagerInternal).when( () -> LocalServices.getService(PackageManagerInternal.class)); diff --git a/services/tests/servicestests/AndroidTest.xml b/services/tests/servicestests/AndroidTest.xml index d34f78353e71..bbc6bdb95f6c 100644 --- a/services/tests/servicestests/AndroidTest.xml +++ b/services/tests/servicestests/AndroidTest.xml @@ -26,6 +26,11 @@ <option name="test-file-name" value="SimpleServiceTestApp.apk" /> </target_preparer> + <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> + <option name="cleanup" value="true" /> + <option name="push" value="AppIntegrityManagerServiceTestApp.apk->/data/local/tmp/AppIntegrityManagerServiceTestApp.apk" /> + </target_preparer> + <option name="test-tag" value="FrameworksServicesTests" /> <test class="com.android.tradefed.testtype.AndroidJUnitTest" > <option name="package" value="com.android.frameworks.servicestests" /> diff --git a/services/tests/servicestests/assets/AppIntegrityManagerServiceImplTest/test.apk b/services/tests/servicestests/assets/AppIntegrityManagerServiceImplTest/test.apk Binary files differdeleted file mode 100644 index 6345c986efc2..000000000000 --- a/services/tests/servicestests/assets/AppIntegrityManagerServiceImplTest/test.apk +++ /dev/null diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/MockUtils.java b/services/tests/servicestests/src/com/android/server/devicepolicy/MockUtils.java index 17e58325734f..09a681913e45 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/MockUtils.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/MockUtils.java @@ -17,7 +17,6 @@ package com.android.server.devicepolicy; import com.google.common.base.Objects; -import com.android.internal.util.Preconditions; import com.android.server.pm.UserRestrictionsUtils; import android.content.ComponentName; @@ -107,7 +106,7 @@ public class MockUtils { } public static Bundle checkUserRestrictions(String... keys) { - final Bundle expected = DpmTestUtils.newRestrictions(Preconditions.checkNotNull(keys)); + final Bundle expected = DpmTestUtils.newRestrictions(java.util.Objects.requireNonNull(keys)); final Matcher<Bundle> m = new BaseMatcher<Bundle>() { @Override public boolean matches(Object item) { diff --git a/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java b/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java index a2376a6bef1c..604efc4949fe 100644 --- a/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java +++ b/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java @@ -32,6 +32,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -64,7 +65,6 @@ import com.android.server.integrity.engine.RuleEvaluationEngine; import com.android.server.integrity.model.IntegrityCheckResult; import com.android.server.testutils.TestUtils; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -75,9 +75,6 @@ import org.mockito.junit.MockitoRule; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -86,7 +83,8 @@ import java.util.Map; /** Unit test for {@link com.android.server.integrity.AppIntegrityManagerServiceImpl} */ @RunWith(AndroidJUnit4.class) public class AppIntegrityManagerServiceImplTest { - private static final String TEST_DIR = "AppIntegrityManagerServiceImplTest"; + private static final String TEST_APP_PATH = + "/data/local/tmp/AppIntegrityManagerServiceTestApp.apk"; private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive"; private static final String VERSION = "version"; @@ -97,13 +95,19 @@ public class AppIntegrityManagerServiceImplTest { private static final String INSTALLER = TEST_FRAMEWORK_PACKAGE; // These are obtained by running the test and checking logcat. private static final String APP_CERT = - "949ADC6CB92FF09E3784D6E9504F26F9BEAC06E60D881D55A6A81160F9CD6FD1"; + "301AA3CB081134501C45F1422ABC66C24224FD5DED5FDC8F17E697176FD866AA"; private static final String INSTALLER_CERT = "301AA3CB081134501C45F1422ABC66C24224FD5DED5FDC8F17E697176FD866AA"; // We use SHA256 for package names longer than 32 characters. private static final String INSTALLER_SHA256 = "786933C28839603EB48C50B2A688DC6BE52C833627CB2731FF8466A2AE9F94CD"; + private static final String PLAY_STORE_PKG = "com.android.vending"; + private static final String ADB_INSTALLER = "adb"; + private static final String PLAY_STORE_CERT = + "play_store_cert"; + private static final String ADB_CERT = ""; + @org.junit.Rule public MockitoRule mMockitoRule = MockitoJUnit.rule(); @Mock PackageManagerInternal mPackageManagerInternal; @@ -122,11 +126,7 @@ public class AppIntegrityManagerServiceImplTest { @Before public void setup() throws Exception { - mTestApk = File.createTempFile("TestApk", /* suffix= */ null); - mTestApk.deleteOnExit(); - try (InputStream inputStream = mRealContext.getAssets().open(TEST_DIR + "/test.apk")) { - Files.copy(inputStream, mTestApk.toPath(), StandardCopyOption.REPLACE_EXISTING); - } + mTestApk = new File(TEST_APP_PATH); mService = new AppIntegrityManagerServiceImpl( @@ -141,11 +141,7 @@ public class AppIntegrityManagerServiceImplTest { when(mMockContext.getPackageManager()).thenReturn(mSpyPackageManager); when(mMockContext.getResources()).thenReturn(mMockResources); when(mMockResources.getStringArray(anyInt())).thenReturn(new String[] {}); - } - - @After - public void tearDown() throws Exception { - mTestApk.delete(); + when(mIntegrityFileManager.initialized()).thenReturn(true); } // This is not a test of the class, but more of a safeguard that we don't block any install in @@ -310,10 +306,10 @@ public class AppIntegrityManagerServiceImplTest { assertEquals(INSTALLER_CERT, appInstallMetadata.getInstallerCertificate()); assertEquals(VERSION_CODE, appInstallMetadata.getVersionCode()); assertFalse(appInstallMetadata.isPreInstalled()); - // These are hardcoded in the test apk + // These are hardcoded in the test apk android manifest assertEquals(2, allowedInstallers.size()); - assertEquals("cert_1", allowedInstallers.get("store_1")); - assertEquals("cert_2", allowedInstallers.get("store_2")); + assertEquals(PLAY_STORE_CERT, allowedInstallers.get(PLAY_STORE_PKG)); + assertEquals(ADB_CERT, allowedInstallers.get(ADB_INSTALLER)); } @Test @@ -356,6 +352,25 @@ public class AppIntegrityManagerServiceImplTest { 1, PackageManagerInternal.INTEGRITY_VERIFICATION_REJECT); } + @Test + public void handleBroadcast_notInitialized() throws Exception { + when(mIntegrityFileManager.initialized()).thenReturn(false); + ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor = + ArgumentCaptor.forClass(BroadcastReceiver.class); + verify(mMockContext) + .registerReceiver(broadcastReceiverCaptor.capture(), any(), any(), any()); + Intent intent = makeVerificationIntent(); + when(mRuleEvaluationEngine.evaluate(any(), any())).thenReturn(IntegrityCheckResult.allow()); + + broadcastReceiverCaptor.getValue().onReceive(mMockContext, intent); + runJobInHandler(); + + verify(mPackageManagerInternal) + .setIntegrityVerificationResult( + 1, PackageManagerInternal.INTEGRITY_VERIFICATION_ALLOW); + verify(mSpyPackageManager, never()).getPackageArchiveInfo(any(), anyInt()); + } + private void whitelistUsAsRuleProvider() { Resources mockResources = mock(Resources.class); when(mockResources.getStringArray(R.array.config_integrityRuleProviderPackages)) diff --git a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java index f9fc3a145953..41416f1352a8 100644 --- a/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/BaseShortcutManagerTest.java @@ -88,7 +88,6 @@ import android.util.ArrayMap; import android.util.Log; import android.util.Pair; -import com.android.internal.util.Preconditions; import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.pm.LauncherAppsService.LauncherAppsImpl; @@ -114,6 +113,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.function.BiFunction; import java.util.function.BiPredicate; @@ -1241,7 +1241,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase { protected void setCaller(String packageName, int userId) { mInjectedClientPackage = packageName; mInjectedCallingUid = - Preconditions.checkNotNull(getInjectedPackageInfo(packageName, userId, false), + Objects.requireNonNull(getInjectedPackageInfo(packageName, userId, false), "Unknown package").applicationInfo.uid; // Set up LauncherApps for this caller. diff --git a/services/tests/servicestests/test-apps/AppIntegrityManagerServiceTestApp/Android.bp b/services/tests/servicestests/test-apps/AppIntegrityManagerServiceTestApp/Android.bp new file mode 100644 index 000000000000..9aaa37d5c234 --- /dev/null +++ b/services/tests/servicestests/test-apps/AppIntegrityManagerServiceTestApp/Android.bp @@ -0,0 +1,21 @@ +// Copyright (C) 2017 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. + +android_test_helper_app { + name: "AppIntegrityManagerServiceTestApp", + + test_suites: ["device-tests"], + + certificate: "platform", +} diff --git a/services/tests/servicestests/test-apps/AppIntegrityManagerServiceTestApp/AndroidManifest.xml b/services/tests/servicestests/test-apps/AppIntegrityManagerServiceTestApp/AndroidManifest.xml new file mode 100644 index 000000000000..f5dbf43cdfd6 --- /dev/null +++ b/services/tests/servicestests/test-apps/AppIntegrityManagerServiceTestApp/AndroidManifest.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + * Copyright (C) 2019 Google Inc. + * + * 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.google.android.appintegritymanager.test.app" + android:versionCode="5000"> + + <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28" /> + + <application android:hasCode="false"> + <meta-data android:name="allowed-installers" android:value="com.android.vending|play_store_cert,adb|"/> + </application> +</manifest> + diff --git a/telephony/java/android/telephony/Annotation.java b/telephony/java/android/telephony/Annotation.java index 077b67adeef6..9e6dfef0608b 100644 --- a/telephony/java/android/telephony/Annotation.java +++ b/telephony/java/android/telephony/Annotation.java @@ -98,7 +98,13 @@ public class Annotation { TelephonyManager.NETWORK_TYPE_GSM, TelephonyManager.NETWORK_TYPE_TD_SCDMA, TelephonyManager.NETWORK_TYPE_IWLAN, - TelephonyManager.NETWORK_TYPE_LTE_CA, + + //TODO: In order for @SystemApi methods to use this class, there cannot be any + // public hidden members. This network type is marked as hidden because it is not a + // true network type and we are looking to remove it completely from the available list + // of network types. + //TelephonyManager.NETWORK_TYPE_LTE_CA, + TelephonyManager.NETWORK_TYPE_NR, }) @Retention(RetentionPolicy.SOURCE) diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java index daa85bd06669..f6699faf7a61 100644 --- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java +++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java @@ -31,6 +31,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.content.rollback.RollbackInfo; import android.content.rollback.RollbackManager; import android.os.UserManager; @@ -1122,4 +1123,39 @@ public class RollbackTest { InstallUtils.dropShellPermissionIdentity(); } } + + @Test + public void testRollbackDataPolicy() throws Exception { + try { + InstallUtils.adoptShellPermissionIdentity( + Manifest.permission.INSTALL_PACKAGES, + Manifest.permission.DELETE_PACKAGES, + Manifest.permission.TEST_MANAGE_ROLLBACKS); + + Uninstall.packages(TestApp.A, TestApp.B); + Install.multi(TestApp.A1, TestApp.B1).commit(); + // Write user data version = 1 + InstallUtils.processUserData(TestApp.A); + InstallUtils.processUserData(TestApp.B); + + Install a2 = Install.single(TestApp.A2) + .setEnableRollback(PackageManager.RollbackDataPolicy.WIPE); + Install b2 = Install.single(TestApp.B2) + .setEnableRollback(PackageManager.RollbackDataPolicy.RESTORE); + Install.multi(a2, b2).setEnableRollback().commit(); + // Write user data version = 2 + InstallUtils.processUserData(TestApp.A); + InstallUtils.processUserData(TestApp.B); + + RollbackInfo info = RollbackUtils.getAvailableRollback(TestApp.A); + RollbackUtils.rollback(info.getRollbackId()); + // Read user data version from userdata.txt + // A's user data version is -1 for user data is wiped. + // B's user data version is 1 as rollback committed. + assertThat(InstallUtils.getUserDataVersion(TestApp.A)).isEqualTo(-1); + assertThat(InstallUtils.getUserDataVersion(TestApp.B)).isEqualTo(1); + } finally { + InstallUtils.dropShellPermissionIdentity(); + } + } } diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java index bb3906d20df6..40169b8cdcd3 100644 --- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java @@ -384,6 +384,44 @@ public class StagedRollbackTest { RollbackUtils.getRollbackManager().expireRollbackForPackage(getModuleMetadataPackageName()); } + @Test + public void testRollbackDataPolicy_Phase1() throws Exception { + Uninstall.packages(TestApp.A, TestApp.B); + Install.multi(TestApp.A1, TestApp.B1).commit(); + // Write user data version = 1 + InstallUtils.processUserData(TestApp.A); + InstallUtils.processUserData(TestApp.B); + + Install a2 = Install.single(TestApp.A2).setStaged() + .setEnableRollback(PackageManager.RollbackDataPolicy.WIPE); + Install b2 = Install.single(TestApp.B2).setStaged() + .setEnableRollback(PackageManager.RollbackDataPolicy.RESTORE); + Install.multi(a2, b2).setEnableRollback().setStaged().commit(); + } + + @Test + public void testRollbackDataPolicy_Phase2() throws Exception { + assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2); + assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2); + // Write user data version = 2 + InstallUtils.processUserData(TestApp.A); + InstallUtils.processUserData(TestApp.B); + + RollbackInfo info = RollbackUtils.getAvailableRollback(TestApp.A); + RollbackUtils.rollback(info.getRollbackId()); + } + + @Test + public void testRollbackDataPolicy_Phase3() throws Exception { + assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); + assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1); + // Read user data version from userdata.txt + // A's user data version is -1 for user data is wiped. + // B's user data version is 1 as rollback committed. + assertThat(InstallUtils.getUserDataVersion(TestApp.A)).isEqualTo(-1); + assertThat(InstallUtils.getUserDataVersion(TestApp.B)).isEqualTo(1); + } + private static void runShellCommand(String cmd) { ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation() .executeShellCommand(cmd); diff --git a/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java b/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java index 8ab4c4ceda3a..4644d8aee306 100644 --- a/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +++ b/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java @@ -192,6 +192,15 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } } + @Test + public void testRollbackDataPolicy() throws Exception { + runPhase("testRollbackDataPolicy_Phase1"); + getDevice().reboot(); + runPhase("testRollbackDataPolicy_Phase2"); + getDevice().reboot(); + runPhase("testRollbackDataPolicy_Phase3"); + } + private void crashProcess(String processName, int numberOfCrashes) throws Exception { String pid = ""; String lastPid = "invalid"; diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp index b725920ba014..27960c8ed4db 100644 --- a/tools/aapt2/link/ManifestFixer.cpp +++ b/tools/aapt2/link/ManifestFixer.cpp @@ -365,6 +365,8 @@ bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor, }); manifest_action["instrumentation"]["meta-data"] = meta_data_action; + manifest_action["feature"]; + manifest_action["feature"]["inherit-from"]; manifest_action["original-package"]; manifest_action["overlay"]; manifest_action["protected-broadcast"]; diff --git a/tools/stats_log_api_gen/Android.bp b/tools/stats_log_api_gen/Android.bp index 15c327852001..d3958a65c704 100644 --- a/tools/stats_log_api_gen/Android.bp +++ b/tools/stats_log_api_gen/Android.bp @@ -25,6 +25,8 @@ cc_binary_host { "java_writer.cpp", "java_writer_q.cpp", "main.cpp", + "native_writer.cpp", + "native_writer_q.cpp", "utils.cpp", ], cflags: [ @@ -121,17 +123,5 @@ cc_library { "libcutils", ], static_libs: ["libstatssocket"], - target: { - android: { - shared_libs: [ - "libutils", - ], - }, - host: { - static_libs: [ - "libutils", - ], - }, - }, } diff --git a/tools/stats_log_api_gen/Collation.cpp b/tools/stats_log_api_gen/Collation.cpp index fa556010646c..0b82a3dcebc4 100644 --- a/tools/stats_log_api_gen/Collation.cpp +++ b/tools/stats_log_api_gen/Collation.cpp @@ -405,9 +405,9 @@ int collate_atoms(const Descriptor *descriptor, Atoms *atoms) { atomDecl.whitelisted = true; } - if (atomField->options().HasExtension(os::statsd::log_from_module)) { + if (atomField->options().HasExtension(os::statsd::module)) { atomDecl.hasModule = true; - atomDecl.moduleName = atomField->options().GetExtension(os::statsd::log_from_module); + atomDecl.moduleName = atomField->options().GetExtension(os::statsd::module); } vector<java_type_t> signature; diff --git a/tools/stats_log_api_gen/atoms_info_writer.h b/tools/stats_log_api_gen/atoms_info_writer.h index bc677825181f..12ac862871ef 100644 --- a/tools/stats_log_api_gen/atoms_info_writer.h +++ b/tools/stats_log_api_gen/atoms_info_writer.h @@ -27,8 +27,7 @@ namespace stats_log_api_gen { using namespace std; int write_atoms_info_cpp(FILE* out, const Atoms& atoms, const string& namespaceStr, - const string& importHeader, const string& statslogHeader -); + const string& importHeader, const string& statslogHeader); int write_atoms_info_header(FILE* out, const Atoms& atoms, const string& namespaceStr); diff --git a/tools/stats_log_api_gen/java_writer.cpp b/tools/stats_log_api_gen/java_writer.cpp index 712b48edbc1b..7f0872c02613 100644 --- a/tools/stats_log_api_gen/java_writer.cpp +++ b/tools/stats_log_api_gen/java_writer.cpp @@ -48,7 +48,8 @@ static int write_java_methods( FILE* out, const map<vector<java_type_t>, set<string>>& signatures_to_modules, const AtomDecl &attributionDecl, - const string& moduleName + const string& moduleName, + const bool supportQ ) { for (auto signature_to_modules_it = signatures_to_modules.begin(); signature_to_modules_it != signatures_to_modules.end(); signature_to_modules_it++) { @@ -82,8 +83,10 @@ static int write_java_methods( // Print method body. string indent(""); - if (DEFAULT_MODULE_NAME != moduleName) { - fprintf(out, " if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n"); + if (supportQ) { + // TODO(b/146235828): Use just SDK_INT check once it is incremented from Q. + fprintf(out, " if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q ||\n"); + fprintf(out, " Build.VERSION.CODENAME.equals(\"R\")) {\n"); indent = " "; } @@ -193,7 +196,7 @@ static int write_java_methods( fprintf(out, "%s StatsLog.write(builder.build());\n", indent.c_str()); // Add support for writing using Q schema if this is not the default module. - if (DEFAULT_MODULE_NAME != moduleName) { + if (supportQ) { fprintf(out, " } else {\n"); fprintf(out, " QLogger.write(code"); argIndex = 1; @@ -225,15 +228,17 @@ static int write_java_methods( int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl, const string& moduleName, const string& javaClass, - const string& javaPackage) { + const string& javaPackage, const bool supportQ) { // Print prelude fprintf(out, "// This file is autogenerated\n"); fprintf(out, "\n"); fprintf(out, "package %s;\n", javaPackage.c_str()); fprintf(out, "\n"); fprintf(out, "\n"); - fprintf(out, "import android.os.Build;\n"); - fprintf(out, "import android.os.SystemClock;\n"); + if (supportQ) { + fprintf(out, "import android.os.Build;\n"); + fprintf(out, "import android.os.SystemClock;\n"); + } if (DEFAULT_MODULE_NAME == moduleName) { // Mainline modules don't use WorkSource logging. @@ -271,12 +276,15 @@ int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl &attribut // Print write methods. fprintf(out, " // Write methods\n"); - errors += write_java_methods(out, atoms.signatures_to_modules, attributionDecl, moduleName); + errors += write_java_methods( + out, atoms.signatures_to_modules, attributionDecl, moduleName, supportQ); errors += write_java_non_chained_methods( out, atoms.non_chained_signatures_to_modules, moduleName); if (DEFAULT_MODULE_NAME == moduleName) { errors += write_java_work_source_methods(out, atoms.signatures_to_modules, moduleName); - } else { + } + + if (supportQ) { errors += write_java_q_logger_class( out, atoms.signatures_to_modules, attributionDecl, moduleName); } diff --git a/tools/stats_log_api_gen/java_writer.h b/tools/stats_log_api_gen/java_writer.h index 031266b31d07..9324b23e4025 100644 --- a/tools/stats_log_api_gen/java_writer.h +++ b/tools/stats_log_api_gen/java_writer.h @@ -32,8 +32,7 @@ using namespace std; int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl, const string& moduleName, const string& javaClass, - const string& javaPackage -); + const string& javaPackage, const bool supportQ); } // namespace stats_log_api_gen } // namespace android diff --git a/tools/stats_log_api_gen/java_writer_q.h b/tools/stats_log_api_gen/java_writer_q.h index c8f4ccf71c91..96ac745beef8 100644 --- a/tools/stats_log_api_gen/java_writer_q.h +++ b/tools/stats_log_api_gen/java_writer_q.h @@ -37,22 +37,20 @@ int write_java_methods_q_schema( const map<vector<java_type_t>, set<string>>& signatures_to_modules, const AtomDecl &attributionDecl, const string& moduleName, - const string& indent -); + const string& indent); void write_java_helpers_for_q_schema_methods( FILE * out, const AtomDecl &attributionDecl, const int requiredHelpers, - const string& indent -); + const string& indent); #if defined(STATS_SCHEMA_LEGACY) int write_stats_log_java_q(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl); -int write_stats_log_java_q_for_module(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl, - const string& moduleName, const string& javaClass, - const string& javaPackage); +int write_stats_log_java_q_for_module(FILE* out, const Atoms& atoms, + const AtomDecl &attributionDecl, const string& moduleName, const string& javaClass, + const string& javaPackage); #endif } // namespace stats_log_api_gen } // namespace android diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp index ad171da0511c..00a370484823 100644 --- a/tools/stats_log_api_gen/main.cpp +++ b/tools/stats_log_api_gen/main.cpp @@ -6,6 +6,7 @@ #include "java_writer.h" #endif #include "java_writer_q.h" +#include "native_writer.h" #include "utils.h" #include "frameworks/base/cmds/statsd/src/atoms.pb.h" @@ -27,496 +28,6 @@ namespace stats_log_api_gen { using android::os::statsd::Atom; -static int write_stats_log_cpp(FILE *out, const Atoms &atoms, const AtomDecl &attributionDecl, - const string& moduleName, const string& cppNamespace, - const string& importHeader) { - // Print prelude - fprintf(out, "// This file is autogenerated\n"); - fprintf(out, "\n"); - - fprintf(out, "#include <mutex>\n"); - fprintf(out, "#include <chrono>\n"); - fprintf(out, "#include <thread>\n"); - fprintf(out, "#ifdef __ANDROID__\n"); - fprintf(out, "#include <cutils/properties.h>\n"); - fprintf(out, "#endif\n"); - fprintf(out, "#include <stats_event_list.h>\n"); - fprintf(out, "#include <log/log.h>\n"); - fprintf(out, "#include <%s>\n", importHeader.c_str()); - fprintf(out, "#include <utils/SystemClock.h>\n"); - fprintf(out, "\n"); - - write_namespace(out, cppNamespace); - fprintf(out, "// the single event tag id for all stats logs\n"); - fprintf(out, "const static int kStatsEventTag = 1937006964;\n"); - fprintf(out, "#ifdef __ANDROID__\n"); - fprintf(out, "const static bool kStatsdEnabled = property_get_bool(\"ro.statsd.enable\", true);\n"); - fprintf(out, "#else\n"); - fprintf(out, "const static bool kStatsdEnabled = false;\n"); - fprintf(out, "#endif\n"); - - fprintf(out, "int64_t lastRetryTimestampNs = -1;\n"); - fprintf(out, "const int64_t kMinRetryIntervalNs = NS_PER_SEC * 60 * 20; // 20 minutes\n"); - fprintf(out, "static std::mutex mLogdRetryMutex;\n"); - - // Print write methods - fprintf(out, "\n"); - for (auto signature_to_modules_it = atoms.signatures_to_modules.begin(); - signature_to_modules_it != atoms.signatures_to_modules.end(); signature_to_modules_it++) { - if (!signature_needed_for_module(signature_to_modules_it->second, moduleName)) { - continue; - } - vector<java_type_t> signature = signature_to_modules_it->first; - int argIndex; - - fprintf(out, "int\n"); - fprintf(out, "try_stats_write(int32_t code"); - argIndex = 1; - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { - for (auto chainField : attributionDecl.fields) { - if (chainField.javaType == JAVA_TYPE_STRING) { - fprintf(out, ", const std::vector<%s>& %s", - cpp_type_name(chainField.javaType), - chainField.name.c_str()); - } else { - fprintf(out, ", const %s* %s, size_t %s_length", - cpp_type_name(chainField.javaType), - chainField.name.c_str(), chainField.name.c_str()); - } - } - } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) { - fprintf(out, ", const std::map<int, int32_t>& arg%d_1, " - "const std::map<int, int64_t>& arg%d_2, " - "const std::map<int, char const*>& arg%d_3, " - "const std::map<int, float>& arg%d_4", - argIndex, argIndex, argIndex, argIndex); - } else { - fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex); - } - argIndex++; - } - fprintf(out, ")\n"); - - fprintf(out, "{\n"); - argIndex = 1; - fprintf(out, " if (kStatsdEnabled) {\n"); - fprintf(out, " stats_event_list event(kStatsEventTag);\n"); - fprintf(out, " event << android::elapsedRealtimeNano();\n\n"); - fprintf(out, " event << code;\n\n"); - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { - for (const auto &chainField : attributionDecl.fields) { - if (chainField.javaType == JAVA_TYPE_STRING) { - fprintf(out, " if (%s_length != %s.size()) {\n", - attributionDecl.fields.front().name.c_str(), chainField.name.c_str()); - fprintf(out, " return -EINVAL;\n"); - fprintf(out, " }\n"); - } - } - fprintf(out, "\n event.begin();\n"); - fprintf(out, " for (size_t i = 0; i < %s_length; ++i) {\n", - attributionDecl.fields.front().name.c_str()); - fprintf(out, " event.begin();\n"); - for (const auto &chainField : attributionDecl.fields) { - if (chainField.javaType == JAVA_TYPE_STRING) { - fprintf(out, " if (%s[i] != NULL) {\n", chainField.name.c_str()); - fprintf(out, " event << %s[i];\n", chainField.name.c_str()); - fprintf(out, " } else {\n"); - fprintf(out, " event << \"\";\n"); - fprintf(out, " }\n"); - } else { - fprintf(out, " event << %s[i];\n", chainField.name.c_str()); - } - } - fprintf(out, " event.end();\n"); - fprintf(out, " }\n"); - fprintf(out, " event.end();\n\n"); - } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) { - fprintf(out, " event.begin();\n\n"); - fprintf(out, " for (const auto& it : arg%d_1) {\n", argIndex); - fprintf(out, " event.begin();\n"); - fprintf(out, " event << it.first;\n"); - fprintf(out, " event << it.second;\n"); - fprintf(out, " event.end();\n"); - fprintf(out, " }\n"); - - fprintf(out, " for (const auto& it : arg%d_2) {\n", argIndex); - fprintf(out, " event.begin();\n"); - fprintf(out, " event << it.first;\n"); - fprintf(out, " event << it.second;\n"); - fprintf(out, " event.end();\n"); - fprintf(out, " }\n"); - - fprintf(out, " for (const auto& it : arg%d_3) {\n", argIndex); - fprintf(out, " event.begin();\n"); - fprintf(out, " event << it.first;\n"); - fprintf(out, " event << it.second;\n"); - fprintf(out, " event.end();\n"); - fprintf(out, " }\n"); - - fprintf(out, " for (const auto& it : arg%d_4) {\n", argIndex); - fprintf(out, " event.begin();\n"); - fprintf(out, " event << it.first;\n"); - fprintf(out, " event << it.second;\n"); - fprintf(out, " event.end();\n"); - fprintf(out, " }\n"); - - fprintf(out, " event.end();\n\n"); - } else if (*arg == JAVA_TYPE_BYTE_ARRAY) { - fprintf(out, - " event.AppendCharArray(arg%d.arg, " - "arg%d.arg_length);\n", - argIndex, argIndex); - } else { - if (*arg == JAVA_TYPE_STRING) { - fprintf(out, " if (arg%d == NULL) {\n", argIndex); - fprintf(out, " arg%d = \"\";\n", argIndex); - fprintf(out, " }\n"); - } - fprintf(out, " event << arg%d;\n", argIndex); - } - argIndex++; - } - - fprintf(out, " return event.write(LOG_ID_STATS);\n"); - fprintf(out, " } else {\n"); - fprintf(out, " return 1;\n"); - fprintf(out, " }\n"); - fprintf(out, "}\n"); - fprintf(out, "\n"); - } - - for (auto signature_to_modules_it = atoms.signatures_to_modules.begin(); - signature_to_modules_it != atoms.signatures_to_modules.end(); signature_to_modules_it++) { - if (!signature_needed_for_module(signature_to_modules_it->second, moduleName)) { - continue; - } - vector<java_type_t> signature = signature_to_modules_it->first; - int argIndex; - - fprintf(out, "int\n"); - fprintf(out, "stats_write(int32_t code"); - argIndex = 1; - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { - for (auto chainField : attributionDecl.fields) { - if (chainField.javaType == JAVA_TYPE_STRING) { - fprintf(out, ", const std::vector<%s>& %s", - cpp_type_name(chainField.javaType), - chainField.name.c_str()); - } else { - fprintf(out, ", const %s* %s, size_t %s_length", - cpp_type_name(chainField.javaType), - chainField.name.c_str(), chainField.name.c_str()); - } - } - } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) { - fprintf(out, - ", const std::map<int, int32_t>& arg%d_1, " - "const std::map<int, int64_t>& arg%d_2, " - "const std::map<int, char const*>& arg%d_3, " - "const std::map<int, float>& arg%d_4", - argIndex, argIndex, argIndex, argIndex); - } else { - fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex); - } - argIndex++; - } - fprintf(out, ")\n"); - - fprintf(out, "{\n"); - fprintf(out, " int ret = 0;\n"); - - fprintf(out, " for(int retry = 0; retry < 2; ++retry) {\n"); - fprintf(out, " ret = try_stats_write(code"); - - argIndex = 1; - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { - for (auto chainField : attributionDecl.fields) { - if (chainField.javaType == JAVA_TYPE_STRING) { - fprintf(out, ", %s", - chainField.name.c_str()); - } else { - fprintf(out, ", %s, %s_length", - chainField.name.c_str(), chainField.name.c_str()); - } - } - } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) { - fprintf(out, ", arg%d_1, arg%d_2, arg%d_3, arg%d_4", argIndex, - argIndex, argIndex, argIndex); - } else { - fprintf(out, ", arg%d", argIndex); - } - argIndex++; - } - fprintf(out, ");\n"); - fprintf(out, " if (ret >= 0) { break; }\n"); - - fprintf(out, " {\n"); - fprintf(out, " std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n"); - fprintf(out, " if ((android::elapsedRealtimeNano() - lastRetryTimestampNs) <= " - "kMinRetryIntervalNs) break;\n"); - fprintf(out, " lastRetryTimestampNs = android::elapsedRealtimeNano();\n"); - fprintf(out, " }\n"); - fprintf(out, " std::this_thread::sleep_for(std::chrono::milliseconds(10));\n"); - fprintf(out, " }\n"); - fprintf(out, " if (ret < 0) {\n"); - fprintf(out, " note_log_drop(ret, code);\n"); - fprintf(out, " }\n"); - fprintf(out, " return ret;\n"); - fprintf(out, "}\n"); - fprintf(out, "\n"); - } - - for (auto signature_it = atoms.non_chained_signatures_to_modules.begin(); - signature_it != atoms.non_chained_signatures_to_modules.end(); signature_it++) { - if (!signature_needed_for_module(signature_it->second, moduleName)) { - continue; - } - vector<java_type_t> signature = signature_it->first; - int argIndex; - - fprintf(out, "int\n"); - fprintf(out, "try_stats_write_non_chained(int32_t code"); - argIndex = 1; - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex); - argIndex++; - } - fprintf(out, ")\n"); - - fprintf(out, "{\n"); - argIndex = 1; - fprintf(out, " if (kStatsdEnabled) {\n"); - fprintf(out, " stats_event_list event(kStatsEventTag);\n"); - fprintf(out, " event << android::elapsedRealtimeNano();\n\n"); - fprintf(out, " event << code;\n\n"); - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - if (argIndex == 1) { - fprintf(out, " event.begin();\n\n"); - fprintf(out, " event.begin();\n"); - } - if (*arg == JAVA_TYPE_STRING) { - fprintf(out, " if (arg%d == NULL) {\n", argIndex); - fprintf(out, " arg%d = \"\";\n", argIndex); - fprintf(out, " }\n"); - } - if (*arg == JAVA_TYPE_BYTE_ARRAY) { - fprintf(out, - " event.AppendCharArray(arg%d.arg, " - "arg%d.arg_length);", - argIndex, argIndex); - } else { - fprintf(out, " event << arg%d;\n", argIndex); - } - if (argIndex == 2) { - fprintf(out, " event.end();\n\n"); - fprintf(out, " event.end();\n\n"); - } - argIndex++; - } - - fprintf(out, " return event.write(LOG_ID_STATS);\n"); - fprintf(out, " } else {\n"); - fprintf(out, " return 1;\n"); - fprintf(out, " }\n"); - fprintf(out, "}\n"); - fprintf(out, "\n"); - } - - for (auto signature_it = atoms.non_chained_signatures_to_modules.begin(); - signature_it != atoms.non_chained_signatures_to_modules.end(); signature_it++) { - if (!signature_needed_for_module(signature_it->second, moduleName)) { - continue; - } - vector<java_type_t> signature = signature_it->first; - int argIndex; - - fprintf(out, "int\n"); - fprintf(out, "stats_write_non_chained(int32_t code"); - argIndex = 1; - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex); - argIndex++; - } - fprintf(out, ")\n"); - - fprintf(out, "{\n"); - - fprintf(out, " int ret = 0;\n"); - fprintf(out, " for(int retry = 0; retry < 2; ++retry) {\n"); - fprintf(out, " ret = try_stats_write_non_chained(code"); - - argIndex = 1; - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - fprintf(out, ", arg%d", argIndex); - argIndex++; - } - fprintf(out, ");\n"); - fprintf(out, " if (ret >= 0) { break; }\n"); - - fprintf(out, " {\n"); - fprintf(out, " std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n"); - fprintf(out, " if ((android::elapsedRealtimeNano() - lastRetryTimestampNs) <= " - "kMinRetryIntervalNs) break;\n"); - fprintf(out, " lastRetryTimestampNs = android::elapsedRealtimeNano();\n"); - fprintf(out, " }\n"); - - fprintf(out, " std::this_thread::sleep_for(std::chrono::milliseconds(10));\n"); - fprintf(out, " }\n"); - fprintf(out, " if (ret < 0) {\n"); - fprintf(out, " note_log_drop(ret, code);\n"); - fprintf(out, " }\n"); - fprintf(out, " return ret;\n\n"); - fprintf(out, "}\n"); - - fprintf(out, "\n"); - } - - - // Print footer - fprintf(out, "\n"); - write_closing_namespace(out, cppNamespace); - - return 0; -} - -static void write_cpp_method_header( - FILE* out, - const string& method_name, - const map<vector<java_type_t>, set<string>>& signatures_to_modules, - const AtomDecl &attributionDecl, const string& moduleName) { - - for (auto signature_to_modules_it = signatures_to_modules.begin(); - signature_to_modules_it != signatures_to_modules.end(); signature_to_modules_it++) { - // Skip if this signature is not needed for the module. - if (!signature_needed_for_module(signature_to_modules_it->second, moduleName)) { - continue; - } - - vector<java_type_t> signature = signature_to_modules_it->first; - fprintf(out, "int %s(int32_t code", method_name.c_str()); - int argIndex = 1; - for (vector<java_type_t>::const_iterator arg = signature.begin(); - arg != signature.end(); arg++) { - if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { - for (auto chainField : attributionDecl.fields) { - if (chainField.javaType == JAVA_TYPE_STRING) { - fprintf(out, ", const std::vector<%s>& %s", - cpp_type_name(chainField.javaType), chainField.name.c_str()); - } else { - fprintf(out, ", const %s* %s, size_t %s_length", - cpp_type_name(chainField.javaType), - chainField.name.c_str(), chainField.name.c_str()); - } - } - } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) { - fprintf(out, ", const std::map<int, int32_t>& arg%d_1, " - "const std::map<int, int64_t>& arg%d_2, " - "const std::map<int, char const*>& arg%d_3, " - "const std::map<int, float>& arg%d_4", - argIndex, argIndex, argIndex, argIndex); - } else { - fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex); - } - argIndex++; - } - fprintf(out, ");\n"); - - } -} - -static int -write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl, - const string& moduleName, const string& cppNamespace) -{ - // Print prelude - fprintf(out, "// This file is autogenerated\n"); - fprintf(out, "\n"); - fprintf(out, "#pragma once\n"); - fprintf(out, "\n"); - fprintf(out, "#include <stdint.h>\n"); - fprintf(out, "#include <vector>\n"); - fprintf(out, "#include <map>\n"); - fprintf(out, "#include <set>\n"); - fprintf(out, "\n"); - - write_namespace(out, cppNamespace); - fprintf(out, "\n"); - fprintf(out, "/*\n"); - fprintf(out, " * API For logging statistics events.\n"); - fprintf(out, " */\n"); - fprintf(out, "\n"); - - write_native_atom_constants(out, atoms, attributionDecl, moduleName); - - // Print constants for the enum values. - fprintf(out, "//\n"); - fprintf(out, "// Constants for enum values\n"); - fprintf(out, "//\n\n"); - for (set<AtomDecl>::const_iterator atom = atoms.decls.begin(); - atom != atoms.decls.end(); atom++) { - // Skip if the atom is not needed for the module. - if (!atom_needed_for_module(*atom, moduleName)) { - continue; - } - - for (vector<AtomField>::const_iterator field = atom->fields.begin(); - field != atom->fields.end(); field++) { - if (field->javaType == JAVA_TYPE_ENUM) { - fprintf(out, "// Values for %s.%s\n", atom->message.c_str(), - field->name.c_str()); - for (map<int, string>::const_iterator value = field->enumValues.begin(); - value != field->enumValues.end(); value++) { - fprintf(out, "const int32_t %s__%s__%s = %d;\n", - make_constant_name(atom->message).c_str(), - make_constant_name(field->name).c_str(), - make_constant_name(value->second).c_str(), - value->first); - } - fprintf(out, "\n"); - } - } - } - - fprintf(out, "struct BytesField {\n"); - fprintf(out, - " BytesField(char const* array, size_t len) : arg(array), " - "arg_length(len) {}\n"); - fprintf(out, " char const* arg;\n"); - fprintf(out, " size_t arg_length;\n"); - fprintf(out, "};\n"); - fprintf(out, "\n"); - - // Print write methods - fprintf(out, "//\n"); - fprintf(out, "// Write methods\n"); - fprintf(out, "//\n"); - write_cpp_method_header(out, "stats_write", atoms.signatures_to_modules, attributionDecl, - moduleName); - - fprintf(out, "//\n"); - fprintf(out, "// Write flattened methods\n"); - fprintf(out, "//\n"); - write_cpp_method_header(out, "stats_write_non_chained", atoms.non_chained_signatures_to_modules, - attributionDecl, moduleName); - - fprintf(out, "\n"); - write_closing_namespace(out, cppNamespace); - - return 0; -} - // Hide the JNI write helpers that are not used in the new schema. // TODO(b/145100015): Remove this and other JNI related functionality once StatsEvent migration is // complete. @@ -999,7 +510,9 @@ print_usage() fprintf(stderr, " required for java with module\n"); fprintf(stderr, " --javaClass CLASS the class name of the java class.\n"); fprintf(stderr, " Optional for Java with module.\n"); - fprintf(stderr, " Default is \"StatsLogInternal\"\n");} + fprintf(stderr, " Default is \"StatsLogInternal\"\n"); + fprintf(stderr, " --supportQ Include support for Android Q.\n"); +} /** * Do the argument parsing and execute the tasks. @@ -1020,6 +533,7 @@ run(int argc, char const*const* argv) string atomsInfoCppHeaderImport = DEFAULT_ATOMS_INFO_CPP_HEADER_IMPORT; string javaPackage = DEFAULT_JAVA_PACKAGE; string javaClass = DEFAULT_JAVA_CLASS; + bool supportQ = false; int index = 1; while (index < argc) { @@ -1110,6 +624,8 @@ run(int argc, char const*const* argv) return 1; } atomsInfoCppHeaderImport = argv[index]; + } else if (0 == strcmp("--supportQ", argv[index])) { + supportQ = true; } index++; @@ -1125,6 +641,12 @@ run(int argc, char const*const* argv) return 1; } + if (DEFAULT_MODULE_NAME == moduleName && supportQ) { + // Support for Q schema is not needed for default module. + fprintf(stderr, "%s cannot support Q schema\n", moduleName.c_str()); + return 1; + } + // Collate the parameters Atoms atoms; int errorCount = collate_atoms(Atom::descriptor(), &atoms); @@ -1179,7 +701,7 @@ run(int argc, char const*const* argv) return 1; } errorCount = android::stats_log_api_gen::write_stats_log_cpp( - out, atoms, attributionDecl, moduleName, cppNamespace, cppHeaderImport); + out, atoms, attributionDecl, moduleName, cppNamespace, cppHeaderImport, supportQ); fclose(out); } @@ -1227,7 +749,7 @@ run(int argc, char const*const* argv) javaPackage = "android.util"; } errorCount = android::stats_log_api_gen::write_stats_log_java( - out, atoms, attributionDecl, moduleName, javaClass, javaPackage); + out, atoms, attributionDecl, moduleName, javaClass, javaPackage, supportQ); #endif fclose(out); diff --git a/tools/stats_log_api_gen/native_writer.cpp b/tools/stats_log_api_gen/native_writer.cpp new file mode 100644 index 000000000000..c7a34feff94b --- /dev/null +++ b/tools/stats_log_api_gen/native_writer.cpp @@ -0,0 +1,342 @@ +/* + * Copyright (C) 2019, 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 "native_writer.h" +#include "native_writer_q.h" +#include "utils.h" + +namespace android { +namespace stats_log_api_gen { + +#if !defined(STATS_SCHEMA_LEGACY) +static void write_native_key_value_pairs_for_type(FILE* out, const int argIndex, + const int typeIndex, const string& type, const string& valueFieldName) { + fprintf(out, " for (const auto& it : arg%d_%d) {\n", argIndex, typeIndex); + fprintf(out, " pairs.push_back(" + "{ .key = it.first, .valueType = %s, .%s = it.second });\n", + type.c_str(), valueFieldName.c_str()); + fprintf(out, " }\n"); + +} + +static int write_native_stats_write_methods(FILE* out, const Atoms& atoms, + const AtomDecl& attributionDecl, const string& moduleName, const bool supportQ) { + fprintf(out, "\n"); + for (auto signature_to_modules_it = atoms.signatures_to_modules.begin(); + signature_to_modules_it != atoms.signatures_to_modules.end(); signature_to_modules_it++) { + if (!signature_needed_for_module(signature_to_modules_it->second, moduleName)) { + continue; + } + vector<java_type_t> signature = signature_to_modules_it->first; + + write_native_method_signature(out, "int stats_write", signature, + attributionDecl, " {"); + + int argIndex = 1; + if (supportQ) { + fprintf(out, " StatsEventCompat event;\n"); + fprintf(out, " event.setAtomId(code);\n"); + for (vector<java_type_t>::const_iterator arg = signature.begin(); + arg != signature.end(); arg++) { + switch (*arg) { + case JAVA_TYPE_ATTRIBUTION_CHAIN: { + const char* uidName = attributionDecl.fields.front().name.c_str(); + const char* tagName = attributionDecl.fields.back().name.c_str(); + fprintf(out, " event.writeAttributionChain(%s, %s_length, %s);\n", + uidName, uidName, tagName); + break; + } + case JAVA_TYPE_KEY_VALUE_PAIR: + fprintf(out, " event.writeKeyValuePairs(" + "arg%d_1, arg%d_2, arg%d_3, arg%d_4);\n", + argIndex, argIndex, argIndex, argIndex); + break; + case JAVA_TYPE_BYTE_ARRAY: + fprintf(out, " event.writeByteArray(arg%d.arg, arg%d.arg_length);\n", + argIndex, argIndex); + break; + case JAVA_TYPE_BOOLEAN: + fprintf(out, " event.writeBool(arg%d);\n", argIndex); + break; + case JAVA_TYPE_INT: // Fall through. + case JAVA_TYPE_ENUM: + fprintf(out, " event.writeInt32(arg%d);\n", argIndex); + break; + case JAVA_TYPE_FLOAT: + fprintf(out, " event.writeFloat(arg%d);\n", argIndex); + break; + case JAVA_TYPE_LONG: + fprintf(out, " event.writeInt64(arg%d);\n", argIndex); + break; + case JAVA_TYPE_STRING: + fprintf(out, " event.writeString(arg%d);\n", argIndex); + break; + default: + // Unsupported types: OBJECT, DOUBLE. + fprintf(stderr, "Encountered unsupported type."); + return 1; + } + argIndex++; + } + fprintf(out, " return event.writeToSocket();\n"); + } else { + fprintf(out, " struct stats_event* event = stats_event_obtain();\n"); + fprintf(out, " stats_event_set_atom_id(event, code);\n"); + for (vector<java_type_t>::const_iterator arg = signature.begin(); + arg != signature.end(); arg++) { + switch (*arg) { + case JAVA_TYPE_ATTRIBUTION_CHAIN: { + const char* uidName = attributionDecl.fields.front().name.c_str(); + const char* tagName = attributionDecl.fields.back().name.c_str(); + fprintf(out, + " stats_event_write_attribution_chain(event, " + "reinterpret_cast<const uint32_t*>(%s), %s.data(), " + "static_cast<uint8_t>(%s_length));\n", + uidName, tagName, uidName); + break; + } + case JAVA_TYPE_KEY_VALUE_PAIR: + fprintf(out, " std::vector<key_value_pair> pairs;\n"); + write_native_key_value_pairs_for_type( + out, argIndex, 1, "INT32_TYPE", "int32Value"); + write_native_key_value_pairs_for_type( + out, argIndex, 2, "INT64_TYPE", "int64Value"); + write_native_key_value_pairs_for_type( + out, argIndex, 3, "STRING_TYPE", "stringValue"); + write_native_key_value_pairs_for_type( + out, argIndex, 4, "FLOAT_TYPE", "floatValue"); + fprintf(out, + " stats_event_write_key_value_pairs(event, pairs.data(), " + "static_cast<uint8_t>(pairs.size()));\n"); + break; + case JAVA_TYPE_BYTE_ARRAY: + fprintf(out, + " stats_event_write_byte_array(event, " + "reinterpret_cast<const uint8_t*>(arg%d.arg), arg%d.arg_length);\n", + argIndex, argIndex); + break; + case JAVA_TYPE_BOOLEAN: + fprintf(out, " stats_event_write_bool(event, arg%d);\n", argIndex); + break; + case JAVA_TYPE_INT: // Fall through. + case JAVA_TYPE_ENUM: + fprintf(out, " stats_event_write_int32(event, arg%d);\n", argIndex); + break; + case JAVA_TYPE_FLOAT: + fprintf(out, " stats_event_write_float(event, arg%d);\n", argIndex); + break; + case JAVA_TYPE_LONG: + fprintf(out, " stats_event_write_int64(event, arg%d);\n", argIndex); + break; + case JAVA_TYPE_STRING: + fprintf(out, " stats_event_write_string8(event, arg%d);\n", argIndex); + break; + default: + // Unsupported types: OBJECT, DOUBLE. + fprintf(stderr, "Encountered unsupported type."); + return 1; + } + argIndex++; + } + fprintf(out, " const int ret = stats_event_write(event);\n"); + fprintf(out, " stats_event_release(event);\n"); + fprintf(out, " return ret;\n"); + } + fprintf(out, "}\n\n"); + } + return 0; +} + +static void write_native_stats_write_non_chained_methods(FILE* out, const Atoms& atoms, + const AtomDecl& attributionDecl, const string& moduleName) { + fprintf(out, "\n"); + for (auto signature_it = atoms.non_chained_signatures_to_modules.begin(); + signature_it != atoms.non_chained_signatures_to_modules.end(); signature_it++) { + if (!signature_needed_for_module(signature_it->second, moduleName)) { + continue; + } + vector<java_type_t> signature = signature_it->first; + + write_native_method_signature(out, "int stats_write_non_chained", signature, + attributionDecl, " {"); + + vector<java_type_t> newSignature; + + // First two args form the attribution node so size goes down by 1. + newSignature.reserve(signature.size() - 1); + + // First arg is Attribution Chain. + newSignature.push_back(JAVA_TYPE_ATTRIBUTION_CHAIN); + + // Followed by the originial signature except the first 2 args. + newSignature.insert(newSignature.end(), signature.begin() + 2, signature.end()); + + const char* uidName = attributionDecl.fields.front().name.c_str(); + const char* tagName = attributionDecl.fields.back().name.c_str(); + fprintf(out, " const int32_t* %s = &arg1;\n", uidName); + fprintf(out, " const size_t %s_length = 1;\n", uidName); + fprintf(out, " const std::vector<char const*> %s(1, arg2);\n", tagName); + fprintf(out, " return "); + write_native_method_call(out, "stats_write", newSignature, attributionDecl, 2); + + fprintf(out, "}\n\n"); + } + +} +#endif + +static void write_native_method_header( + FILE* out, + const string& methodName, + const map<vector<java_type_t>, set<string>>& signatures_to_modules, + const AtomDecl &attributionDecl, const string& moduleName) { + + for (auto signature_to_modules_it = signatures_to_modules.begin(); + signature_to_modules_it != signatures_to_modules.end(); signature_to_modules_it++) { + // Skip if this signature is not needed for the module. + if (!signature_needed_for_module(signature_to_modules_it->second, moduleName)) { + continue; + } + + vector<java_type_t> signature = signature_to_modules_it->first; + write_native_method_signature(out, methodName, signature, attributionDecl, ";"); + } +} + +int write_stats_log_cpp(FILE *out, const Atoms &atoms, const AtomDecl &attributionDecl, + const string& moduleName, const string& cppNamespace, + const string& importHeader, const bool supportQ) { + // Print prelude + fprintf(out, "// This file is autogenerated\n"); + fprintf(out, "\n"); + + fprintf(out, "#include <%s>\n", importHeader.c_str()); +#if defined(STATS_SCHEMA_LEGACY) + (void)supportQ; // Workaround for unused parameter error. + write_native_cpp_includes_q(out); +#else + if (supportQ) { + fprintf(out, "#include <StatsEventCompat.h>\n"); + } else { + fprintf(out, "#include <stats_event.h>\n"); + } +#endif + + fprintf(out, "\n"); + write_namespace(out, cppNamespace); + +#if defined(STATS_SCHEMA_LEGACY) + write_native_stats_log_cpp_globals_q(out); + write_native_get_timestamp_ns_q(out); + write_native_try_stats_write_methods_q(out, atoms, attributionDecl, moduleName); + write_native_stats_write_methods_q(out, "int stats_write", atoms, attributionDecl, moduleName, + "try_stats_write"); + write_native_try_stats_write_non_chained_methods_q(out, atoms, attributionDecl, moduleName); + write_native_stats_write_non_chained_methods_q(out, "int stats_write_non_chained", atoms, + attributionDecl, moduleName, "try_stats_write_non_chained"); +#else + write_native_stats_write_methods(out, atoms, attributionDecl, moduleName, supportQ); + write_native_stats_write_non_chained_methods(out, atoms, attributionDecl, moduleName); +#endif + + // Print footer + fprintf(out, "\n"); + write_closing_namespace(out, cppNamespace); + + return 0; +} + +int write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl, + const string& moduleName, const string& cppNamespace) { + // Print prelude + fprintf(out, "// This file is autogenerated\n"); + fprintf(out, "\n"); + fprintf(out, "#pragma once\n"); + fprintf(out, "\n"); + fprintf(out, "#include <stdint.h>\n"); + fprintf(out, "#include <vector>\n"); + fprintf(out, "#include <map>\n"); + fprintf(out, "#include <set>\n"); + fprintf(out, "\n"); + + write_namespace(out, cppNamespace); + fprintf(out, "\n"); + fprintf(out, "/*\n"); + fprintf(out, " * API For logging statistics events.\n"); + fprintf(out, " */\n"); + fprintf(out, "\n"); + + write_native_atom_constants(out, atoms, attributionDecl, moduleName); + + // Print constants for the enum values. + fprintf(out, "//\n"); + fprintf(out, "// Constants for enum values\n"); + fprintf(out, "//\n\n"); + for (set<AtomDecl>::const_iterator atom = atoms.decls.begin(); + atom != atoms.decls.end(); atom++) { + // Skip if the atom is not needed for the module. + if (!atom_needed_for_module(*atom, moduleName)) { + continue; + } + + for (vector<AtomField>::const_iterator field = atom->fields.begin(); + field != atom->fields.end(); field++) { + if (field->javaType == JAVA_TYPE_ENUM) { + fprintf(out, "// Values for %s.%s\n", atom->message.c_str(), + field->name.c_str()); + for (map<int, string>::const_iterator value = field->enumValues.begin(); + value != field->enumValues.end(); value++) { + fprintf(out, "const int32_t %s__%s__%s = %d;\n", + make_constant_name(atom->message).c_str(), + make_constant_name(field->name).c_str(), + make_constant_name(value->second).c_str(), + value->first); + } + fprintf(out, "\n"); + } + } + } + + fprintf(out, "struct BytesField {\n"); + fprintf(out, + " BytesField(char const* array, size_t len) : arg(array), " + "arg_length(len) {}\n"); + fprintf(out, " char const* arg;\n"); + fprintf(out, " size_t arg_length;\n"); + fprintf(out, "};\n"); + fprintf(out, "\n"); + + // Print write methods + fprintf(out, "//\n"); + fprintf(out, "// Write methods\n"); + fprintf(out, "//\n"); + write_native_method_header(out, "int stats_write", atoms.signatures_to_modules, attributionDecl, + moduleName); + + fprintf(out, "//\n"); + fprintf(out, "// Write flattened methods\n"); + fprintf(out, "//\n"); + write_native_method_header(out, "int stats_write_non_chained", + atoms.non_chained_signatures_to_modules, attributionDecl, moduleName); + + fprintf(out, "\n"); + write_closing_namespace(out, cppNamespace); + + return 0; +} + +} // namespace stats_log_api_gen +} // namespace android diff --git a/tools/stats_log_api_gen/native_writer.h b/tools/stats_log_api_gen/native_writer.h new file mode 100644 index 000000000000..aafa96ece2d0 --- /dev/null +++ b/tools/stats_log_api_gen/native_writer.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2019, 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 "Collation.h" + +#include <stdio.h> +#include <string.h> + +namespace android { +namespace stats_log_api_gen { + +using namespace std; + +int write_stats_log_cpp(FILE *out, const Atoms &atoms, const AtomDecl &attributionDecl, + const string& moduleName, const string& cppNamespace, const string& importHeader, + const bool supportQ); + +int write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl, + const string& moduleName, const string& cppNamespace); + +} // namespace stats_log_api_gen +} // namespace android diff --git a/tools/stats_log_api_gen/native_writer_q.cpp b/tools/stats_log_api_gen/native_writer_q.cpp new file mode 100644 index 000000000000..299873dad975 --- /dev/null +++ b/tools/stats_log_api_gen/native_writer_q.cpp @@ -0,0 +1,276 @@ +/* + * Copyright (C) 2019, 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 "native_writer_q.h" +#include "utils.h" + +namespace android { +namespace stats_log_api_gen { + +static void write_native_stats_write_body_q(FILE* out, const vector<java_type_t>& signature, + const AtomDecl& attributionDecl, const string& indent, const string& tryMethodName) { + fprintf(out, "%sint ret = 0;\n", indent.c_str()); + + fprintf(out, "%sfor(int retry = 0; retry < 2; ++retry) {\n", indent.c_str()); + fprintf(out, "%s ret = ", indent.c_str()); + write_native_method_call(out, tryMethodName, signature, attributionDecl); + fprintf(out, "%s if (ret >= 0) { break; }\n", indent.c_str()); + + fprintf(out, "%s {\n", indent.c_str()); + fprintf(out, "%s std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n", indent.c_str()); + fprintf(out, "%s if ((get_elapsed_realtime_ns() - lastRetryTimestampNs) <= " + "kMinRetryIntervalNs) break;\n", indent.c_str()); + fprintf(out, "%s lastRetryTimestampNs = get_elapsed_realtime_ns();\n", + indent.c_str()); + fprintf(out, "%s }\n", indent.c_str()); + fprintf(out, "%s std::this_thread::sleep_for(std::chrono::milliseconds(10));\n", + indent.c_str()); + fprintf(out, "%s}\n", indent.c_str()); + fprintf(out, "%sif (ret < 0) {\n", indent.c_str()); + fprintf(out, "%s note_log_drop(ret, code);\n", indent.c_str()); + fprintf(out, "%s}\n", indent.c_str()); + fprintf(out, "%sreturn ret;\n", indent.c_str()); +} + +void write_native_cpp_includes_q(FILE* out) { + fprintf(out, "#include <mutex>\n"); + fprintf(out, "#include <chrono>\n"); + fprintf(out, "#include <thread>\n"); + fprintf(out, "#ifdef __ANDROID__\n"); + fprintf(out, "#include <cutils/properties.h>\n"); + fprintf(out, "#endif\n"); + fprintf(out, "#include <stats_event_list.h>\n"); + fprintf(out, "#include <log/log.h>\n"); + fprintf(out, "#include <time.h>\n"); +} + +void write_native_get_timestamp_ns_q(FILE* out) { + fprintf(out, "\n"); + fprintf(out, "static int64_t get_elapsed_realtime_ns() {\n"); + fprintf(out, " struct timespec t;\n"); + fprintf(out, " t.tv_sec = t.tv_nsec = 0;\n"); + fprintf(out, " clock_gettime(CLOCK_BOOTTIME, &t);\n"); + fprintf(out, " return (int64_t)t.tv_sec * 1000000000LL + t.tv_nsec;\n"); + fprintf(out, "}\n"); +} + +void write_native_stats_log_cpp_globals_q(FILE* out) { + fprintf(out, "// the single event tag id for all stats logs\n"); + fprintf(out, "const static int kStatsEventTag = 1937006964;\n"); + fprintf(out, "#ifdef __ANDROID__\n"); + fprintf(out, + "const static bool kStatsdEnabled = property_get_bool(\"ro.statsd.enable\", true);\n"); + fprintf(out, "#else\n"); + fprintf(out, "const static bool kStatsdEnabled = false;\n"); + fprintf(out, "#endif\n"); + + fprintf(out, "int64_t lastRetryTimestampNs = -1;\n"); + fprintf(out, "const int64_t kMinRetryIntervalNs = NS_PER_SEC * 60 * 20; // 20 minutes\n"); + fprintf(out, "static std::mutex mLogdRetryMutex;\n"); +} + +void write_native_try_stats_write_methods_q(FILE* out, const Atoms& atoms, + const AtomDecl& attributionDecl, const string& moduleName) { + fprintf(out, "\n"); + for (auto signature_to_modules_it = atoms.signatures_to_modules.begin(); + signature_to_modules_it != atoms.signatures_to_modules.end(); signature_to_modules_it++) { + if (!signature_needed_for_module(signature_to_modules_it->second, moduleName)) { + continue; + } + vector<java_type_t> signature = signature_to_modules_it->first; + + write_native_method_signature(out, "static int try_stats_write", signature, + attributionDecl, " {"); + + int argIndex = 1; + fprintf(out, " if (kStatsdEnabled) {\n"); + fprintf(out, " stats_event_list event(kStatsEventTag);\n"); + fprintf(out, " event << get_elapsed_realtime_ns();\n\n"); + fprintf(out, " event << code;\n\n"); + for (vector<java_type_t>::const_iterator arg = signature.begin(); + arg != signature.end(); arg++) { + if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { + for (const auto &chainField : attributionDecl.fields) { + if (chainField.javaType == JAVA_TYPE_STRING) { + fprintf(out, " if (%s_length != %s.size()) {\n", + attributionDecl.fields.front().name.c_str(), chainField.name.c_str()); + fprintf(out, " return -EINVAL;\n"); + fprintf(out, " }\n"); + } + } + fprintf(out, "\n event.begin();\n"); + fprintf(out, " for (size_t i = 0; i < %s_length; ++i) {\n", + attributionDecl.fields.front().name.c_str()); + fprintf(out, " event.begin();\n"); + for (const auto &chainField : attributionDecl.fields) { + if (chainField.javaType == JAVA_TYPE_STRING) { + fprintf(out, " if (%s[i] != NULL) {\n", chainField.name.c_str()); + fprintf(out, " event << %s[i];\n", chainField.name.c_str()); + fprintf(out, " } else {\n"); + fprintf(out, " event << \"\";\n"); + fprintf(out, " }\n"); + } else { + fprintf(out, " event << %s[i];\n", chainField.name.c_str()); + } + } + fprintf(out, " event.end();\n"); + fprintf(out, " }\n"); + fprintf(out, " event.end();\n\n"); + } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) { + fprintf(out, " event.begin();\n\n"); + fprintf(out, " for (const auto& it : arg%d_1) {\n", argIndex); + fprintf(out, " event.begin();\n"); + fprintf(out, " event << it.first;\n"); + fprintf(out, " event << it.second;\n"); + fprintf(out, " event.end();\n"); + fprintf(out, " }\n"); + + fprintf(out, " for (const auto& it : arg%d_2) {\n", argIndex); + fprintf(out, " event.begin();\n"); + fprintf(out, " event << it.first;\n"); + fprintf(out, " event << it.second;\n"); + fprintf(out, " event.end();\n"); + fprintf(out, " }\n"); + + fprintf(out, " for (const auto& it : arg%d_3) {\n", argIndex); + fprintf(out, " event.begin();\n"); + fprintf(out, " event << it.first;\n"); + fprintf(out, " event << it.second;\n"); + fprintf(out, " event.end();\n"); + fprintf(out, " }\n"); + + fprintf(out, " for (const auto& it : arg%d_4) {\n", argIndex); + fprintf(out, " event.begin();\n"); + fprintf(out, " event << it.first;\n"); + fprintf(out, " event << it.second;\n"); + fprintf(out, " event.end();\n"); + fprintf(out, " }\n"); + + fprintf(out, " event.end();\n\n"); + } else if (*arg == JAVA_TYPE_BYTE_ARRAY) { + fprintf(out, + " event.AppendCharArray(arg%d.arg, " + "arg%d.arg_length);\n", + argIndex, argIndex); + } else { + if (*arg == JAVA_TYPE_STRING) { + fprintf(out, " if (arg%d == NULL) {\n", argIndex); + fprintf(out, " arg%d = \"\";\n", argIndex); + fprintf(out, " }\n"); + } + fprintf(out, " event << arg%d;\n", argIndex); + } + argIndex++; + } + + fprintf(out, " return event.write(LOG_ID_STATS);\n"); + fprintf(out, " } else {\n"); + fprintf(out, " return 1;\n"); + fprintf(out, " }\n"); + fprintf(out, "}\n"); + fprintf(out, "\n"); + } + +} + +void write_native_stats_write_methods_q(FILE* out, const string& methodName, const Atoms& atoms, + const AtomDecl& attributionDecl, const string& moduleName, const string& tryMethodName) { + for (auto signature_to_modules_it = atoms.signatures_to_modules.begin(); + signature_to_modules_it != atoms.signatures_to_modules.end(); + signature_to_modules_it++) { + if (!signature_needed_for_module(signature_to_modules_it->second, moduleName)) { + continue; + } + vector<java_type_t> signature = signature_to_modules_it->first; + + write_native_method_signature(out, methodName, signature, attributionDecl, " {"); + + write_native_stats_write_body_q(out, signature, attributionDecl, " ", tryMethodName); + fprintf(out, "}\n\n"); + } +} + +void write_native_stats_write_non_chained_methods_q(FILE* out, const string& methodName, + const Atoms& atoms, const AtomDecl& attributionDecl, const string& moduleName, + const string& tryMethodName) { + for (auto signature_it = atoms.non_chained_signatures_to_modules.begin(); + signature_it != atoms.non_chained_signatures_to_modules.end(); signature_it++) { + if (!signature_needed_for_module(signature_it->second, moduleName)) { + continue; + } + vector<java_type_t> signature = signature_it->first; + + write_native_method_signature(out, methodName, signature, attributionDecl, " {"); + + write_native_stats_write_body_q(out, signature, attributionDecl, " ", tryMethodName); + fprintf(out, "}\n\n"); + } +} + +void write_native_try_stats_write_non_chained_methods_q(FILE* out, const Atoms& atoms, + const AtomDecl& attributionDecl, const string& moduleName) { + for (auto signature_it = atoms.non_chained_signatures_to_modules.begin(); + signature_it != atoms.non_chained_signatures_to_modules.end(); signature_it++) { + if (!signature_needed_for_module(signature_it->second, moduleName)) { + continue; + } + vector<java_type_t> signature = signature_it->first; + + write_native_method_signature(out, "static int try_stats_write_non_chained", signature, + attributionDecl, " {"); + + int argIndex = 1; + fprintf(out, " if (kStatsdEnabled) {\n"); + fprintf(out, " stats_event_list event(kStatsEventTag);\n"); + fprintf(out, " event << get_elapsed_realtime_ns();\n\n"); + fprintf(out, " event << code;\n\n"); + for (vector<java_type_t>::const_iterator arg = signature.begin(); + arg != signature.end(); arg++) { + if (argIndex == 1) { + fprintf(out, " event.begin();\n\n"); + fprintf(out, " event.begin();\n"); + } + if (*arg == JAVA_TYPE_STRING) { + fprintf(out, " if (arg%d == NULL) {\n", argIndex); + fprintf(out, " arg%d = \"\";\n", argIndex); + fprintf(out, " }\n"); + } + if (*arg == JAVA_TYPE_BYTE_ARRAY) { + fprintf(out, + " event.AppendCharArray(arg%d.arg, " + "arg%d.arg_length);\n", + argIndex, argIndex); + } else { + fprintf(out, " event << arg%d;\n", argIndex); + } + if (argIndex == 2) { + fprintf(out, " event.end();\n\n"); + fprintf(out, " event.end();\n\n"); + } + argIndex++; + } + + fprintf(out, " return event.write(LOG_ID_STATS);\n"); + fprintf(out, " } else {\n"); + fprintf(out, " return 1;\n"); + fprintf(out, " }\n"); + fprintf(out, "}\n"); + fprintf(out, "\n"); + } +} + +} // namespace stats_log_api_gen +} // namespace android diff --git a/tools/stats_log_api_gen/native_writer_q.h b/tools/stats_log_api_gen/native_writer_q.h new file mode 100644 index 000000000000..a2ab1ae5d5e2 --- /dev/null +++ b/tools/stats_log_api_gen/native_writer_q.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2019, 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 "Collation.h" + +#include <stdio.h> +#include <string.h> + +namespace android { +namespace stats_log_api_gen { + +using namespace std; + +void write_native_cpp_includes_q(FILE* out); + +void write_native_stats_log_cpp_globals_q(FILE* out); + +void write_native_try_stats_write_methods_q(FILE* out, const Atoms& atoms, + const AtomDecl& attributionDecl, const string& moduleName); + +void write_native_stats_write_methods_q(FILE* out, const string& methodName, const Atoms& atoms, + const AtomDecl& attributionDecl, const string& moduleName, const string& tryMethodName); + +void write_native_try_stats_write_non_chained_methods_q(FILE* out, const Atoms& atoms, + const AtomDecl& attributionDecl, const string& moduleName); + +void write_native_stats_write_non_chained_methods_q(FILE* out, const string& methodName, + const Atoms& atoms, const AtomDecl& attributionDecl, const string& moduleName, + const string& tryMethodName); + +void write_native_get_timestamp_ns_q(FILE* out); + +} // namespace stats_log_api_gen +} // namespace android diff --git a/tools/stats_log_api_gen/test.proto b/tools/stats_log_api_gen/test.proto index c3e703826be5..c9a47632b4bb 100644 --- a/tools/stats_log_api_gen/test.proto +++ b/tools/stats_log_api_gen/test.proto @@ -229,8 +229,8 @@ message NoModuleAtom { message ModuleAtoms { oneof event { - ModuleOneAtom module_one_atom = 1 [(android.os.statsd.log_from_module) = "module1"]; - ModuleTwoAtom module_two_atom = 2 [(android.os.statsd.log_from_module) = "module2"]; + ModuleOneAtom module_one_atom = 1 [(android.os.statsd.module) = "module1"]; + ModuleTwoAtom module_two_atom = 2 [(android.os.statsd.module) = "module2"]; NoModuleAtom no_module_atom = 3; } -}
\ No newline at end of file +} diff --git a/tools/stats_log_api_gen/utils.cpp b/tools/stats_log_api_gen/utils.cpp index d6cfe95a34f5..c65d1901ea7e 100644 --- a/tools/stats_log_api_gen/utils.cpp +++ b/tools/stats_log_api_gen/utils.cpp @@ -204,6 +204,65 @@ void write_native_atom_constants(FILE* out, const Atoms& atoms, const AtomDecl& fprintf(out, "\n"); } +void write_native_method_signature(FILE* out, const string& methodName, + const vector<java_type_t>& signature, const AtomDecl& attributionDecl, + const string& closer) { + fprintf(out, "%s(int32_t code", methodName.c_str()); + int argIndex = 1; + for (vector<java_type_t>::const_iterator arg = signature.begin(); + arg != signature.end(); arg++) { + if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { + for (auto chainField : attributionDecl.fields) { + if (chainField.javaType == JAVA_TYPE_STRING) { + fprintf(out, ", const std::vector<%s>& %s", + cpp_type_name(chainField.javaType), + chainField.name.c_str()); + } else { + fprintf(out, ", const %s* %s, size_t %s_length", + cpp_type_name(chainField.javaType), + chainField.name.c_str(), chainField.name.c_str()); + } + } + } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) { + fprintf(out, ", const std::map<int, int32_t>& arg%d_1, " + "const std::map<int, int64_t>& arg%d_2, " + "const std::map<int, char const*>& arg%d_3, " + "const std::map<int, float>& arg%d_4", + argIndex, argIndex, argIndex, argIndex); + } else { + fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex); + } + argIndex++; + } + fprintf(out, ")%s\n", closer.c_str()); +} + +void write_native_method_call(FILE* out, const string& methodName, + const vector<java_type_t>& signature, const AtomDecl& attributionDecl, int argIndex) { + fprintf(out, "%s(code", methodName.c_str()); + for (vector<java_type_t>::const_iterator arg = signature.begin(); + arg != signature.end(); arg++) { + if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { + for (auto chainField : attributionDecl.fields) { + if (chainField.javaType == JAVA_TYPE_STRING) { + fprintf(out, ", %s", + chainField.name.c_str()); + } else { + fprintf(out, ", %s, %s_length", + chainField.name.c_str(), chainField.name.c_str()); + } + } + } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) { + fprintf(out, ", arg%d_1, arg%d_2, arg%d_3, arg%d_4", argIndex, + argIndex, argIndex, argIndex); + } else { + fprintf(out, ", arg%d", argIndex); + } + argIndex++; + } + fprintf(out, ");\n"); +} + // Java void write_java_atom_codes(FILE* out, const Atoms& atoms, const string& moduleName) { fprintf(out, " // Constants for atom codes.\n"); diff --git a/tools/stats_log_api_gen/utils.h b/tools/stats_log_api_gen/utils.h index a89387f00bce..50737a68bf89 100644 --- a/tools/stats_log_api_gen/utils.h +++ b/tools/stats_log_api_gen/utils.h @@ -56,8 +56,14 @@ void write_namespace(FILE* out, const string& cppNamespaces); void write_closing_namespace(FILE* out, const string& cppNamespaces); void write_native_atom_constants(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl, - const string& moduleName -); + const string& moduleName); + +void write_native_method_signature(FILE* out, const string& methodName, + const vector<java_type_t>& signature, const AtomDecl& attributionDecl, + const string& closer); + +void write_native_method_call(FILE* out, const string& methodName, + const vector<java_type_t>& signature, const AtomDecl& attributionDecl, int argIndex = 1); // Common Java helpers. void write_java_atom_codes(FILE* out, const Atoms& atoms, const string& moduleName); @@ -69,14 +75,12 @@ void write_java_usage(FILE* out, const string& method_name, const string& atom_c int write_java_non_chained_methods(FILE* out, const map<vector<java_type_t>, set<string>>& signatures_to_modules, - const string& moduleName -); + const string& moduleName); int write_java_work_source_methods( FILE* out, const map<vector<java_type_t>, set<string>>& signatures_to_modules, - const string& moduleName -); + const string& moduleName); } // namespace stats_log_api_gen } // namespace android diff --git a/wifi/Android.bp b/wifi/Android.bp index fb1f8661370b..81559224f700 100644 --- a/wifi/Android.bp +++ b/wifi/Android.bp @@ -42,11 +42,21 @@ filegroup { srcs: ["java/android/net/wifi/WifiAnnotations.java"], } +// list of tests that are allowed to access @hide APIs from framework-wifi +test_access_hidden_api_whitelist = [ + "//frameworks/base/wifi/tests", + "//frameworks/opt/net/wifi/tests/wifitests:__subpackages__", + + "//frameworks/opt/net/wifi/libs/WifiTrackerLib/tests", +] + java_library { name: "framework-wifi", - sdk_version: "core_platform", // TODO(b/140299412) should be core_current + // TODO(b/140299412) should be core_current once we build against framework-system-stubs + sdk_version: "core_platform", libs: [ - "framework-minus-apex", // TODO(b/140299412) should be framework-system-stubs + // TODO(b/140299412) should be framework-system-stubs once we fix all @hide dependencies + "framework-minus-apex", ], srcs: [ ":framework-wifi-updatable-sources", @@ -54,7 +64,11 @@ java_library { installable: true, optimize: { enabled: false - } + }, + visibility: [ + "//frameworks/base", // TODO(b/140299412) remove once all dependencies are fixed + "//frameworks/opt/net/wifi/service:__subpackages__", + ] + test_access_hidden_api_whitelist, } droidstubs { @@ -84,3 +98,16 @@ java_library { installable: false, } +// defaults for tests that need to build against framework-wifi's @hide APIs +java_defaults { + name: "framework-wifi-test-defaults", + sdk_version: "core_platform", // tests can use @CorePlatformApi's + libs: [ + "framework-wifi", + "framework-minus-apex", + + // if sdk_version="" this gets automatically included, but here we need to add manually. + "framework-res", + ], + visibility: test_access_hidden_api_whitelist, +} diff --git a/wifi/java/android/net/wifi/WifiClient.java b/wifi/java/android/net/wifi/WifiClient.java index 3e09580802ce..3794566f3d8f 100644 --- a/wifi/java/android/net/wifi/WifiClient.java +++ b/wifi/java/android/net/wifi/WifiClient.java @@ -22,8 +22,6 @@ import android.net.MacAddress; import android.os.Parcel; import android.os.Parcelable; -import com.android.internal.util.Preconditions; - import java.util.Objects; /** @hide */ @@ -46,7 +44,7 @@ public final class WifiClient implements Parcelable { /** @hide */ public WifiClient(@NonNull MacAddress macAddress) { - Preconditions.checkNotNull(macAddress, "mMacAddress must not be null."); + Objects.requireNonNull(macAddress, "mMacAddress must not be null."); this.mMacAddress = macAddress; } diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index e3a945de7526..2a165d390494 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -2446,10 +2446,14 @@ public class WifiConfiguration implements Parcelable { return key; } - /** @hide */ - @UnsupportedAppUsage + /** + * Get the IpConfiguration object associated with this WifiConfiguration. + * @hide + */ + @NonNull + @SystemApi public IpConfiguration getIpConfiguration() { - return mIpConfiguration; + return new IpConfiguration(mIpConfiguration); } /** diff --git a/wifi/java/android/net/wifi/WifiNetworkScoreCache.java b/wifi/java/android/net/wifi/WifiNetworkScoreCache.java index be37c229dd14..378549d62edf 100755 --- a/wifi/java/android/net/wifi/WifiNetworkScoreCache.java +++ b/wifi/java/android/net/wifi/WifiNetworkScoreCache.java @@ -29,11 +29,11 @@ import android.util.Log; import android.util.LruCache; import com.android.internal.annotations.GuardedBy; -import com.android.internal.util.Preconditions; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.List; +import java.util.Objects; /** * {@link INetworkScoreCache} implementation for Wifi Networks. @@ -290,7 +290,7 @@ public class WifiNetworkScoreCache extends INetworkScoreCache.Stub { * This cannot be null. */ public CacheListener(@NonNull Handler handler) { - Preconditions.checkNotNull(handler); + Objects.requireNonNull(handler); mHandler = handler; } diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java index 8badcc0c2552..2c39c32ac81e 100644 --- a/wifi/java/android/net/wifi/WifiScanner.java +++ b/wifi/java/android/net/wifi/WifiScanner.java @@ -40,7 +40,6 @@ import android.util.Log; import android.util.SparseArray; import com.android.internal.util.AsyncChannel; -import com.android.internal.util.Preconditions; import com.android.internal.util.Protocol; import java.lang.annotation.Retention; @@ -48,6 +47,7 @@ import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.concurrent.Executor; /** @@ -840,8 +840,8 @@ public class WifiScanner { @RequiresPermission(Manifest.permission.NETWORK_STACK) public void registerScanListener(@NonNull @CallbackExecutor Executor executor, @NonNull ScanListener listener) { - Preconditions.checkNotNull(executor, "executor cannot be null"); - Preconditions.checkNotNull(listener, "listener cannot be null"); + Objects.requireNonNull(executor, "executor cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); int key = addListener(listener, executor); if (key == INVALID_KEY) return; validateChannel(); @@ -864,7 +864,7 @@ public class WifiScanner { * #registerScanListener} */ public void unregisterScanListener(@NonNull ScanListener listener) { - Preconditions.checkNotNull(listener, "listener cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); int key = removeListener(listener); if (key == INVALID_KEY) return; validateChannel(); @@ -894,7 +894,7 @@ public class WifiScanner { @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startBackgroundScan(ScanSettings settings, ScanListener listener, WorkSource workSource) { - Preconditions.checkNotNull(listener, "listener cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); int key = addListener(listener); if (key == INVALID_KEY) return; validateChannel(); @@ -913,7 +913,7 @@ public class WifiScanner { */ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void stopBackgroundScan(ScanListener listener) { - Preconditions.checkNotNull(listener, "listener cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); int key = removeListener(listener); if (key == INVALID_KEY) return; validateChannel(); @@ -962,7 +962,7 @@ public class WifiScanner { */ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startScan(ScanSettings settings, ScanListener listener, WorkSource workSource) { - Preconditions.checkNotNull(listener, "listener cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); int key = addListener(listener); if (key == INVALID_KEY) return; validateChannel(); @@ -981,7 +981,7 @@ public class WifiScanner { */ @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void stopScan(ScanListener listener) { - Preconditions.checkNotNull(listener, "listener cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); int key = removeListener(listener); if (key == INVALID_KEY) return; validateChannel(); @@ -1036,8 +1036,8 @@ public class WifiScanner { */ public void startConnectedPnoScan(ScanSettings scanSettings, PnoSettings pnoSettings, PnoScanListener listener) { - Preconditions.checkNotNull(listener, "listener cannot be null"); - Preconditions.checkNotNull(pnoSettings, "pnoSettings cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); + Objects.requireNonNull(pnoSettings, "pnoSettings cannot be null"); int key = addListener(listener); if (key == INVALID_KEY) return; validateChannel(); @@ -1058,8 +1058,8 @@ public class WifiScanner { @RequiresPermission(android.Manifest.permission.NETWORK_STACK) public void startDisconnectedPnoScan(ScanSettings scanSettings, PnoSettings pnoSettings, PnoScanListener listener) { - Preconditions.checkNotNull(listener, "listener cannot be null"); - Preconditions.checkNotNull(pnoSettings, "pnoSettings cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); + Objects.requireNonNull(pnoSettings, "pnoSettings cannot be null"); int key = addListener(listener); if (key == INVALID_KEY) return; validateChannel(); @@ -1074,7 +1074,7 @@ public class WifiScanner { */ @RequiresPermission(android.Manifest.permission.NETWORK_STACK) public void stopPnoScan(ScanListener listener) { - Preconditions.checkNotNull(listener, "listener cannot be null"); + Objects.requireNonNull(listener, "listener cannot be null"); int key = removeListener(listener); if (key == INVALID_KEY) return; validateChannel(); |