diff options
25 files changed, 1678 insertions, 269 deletions
diff --git a/api/current.txt b/api/current.txt index 617971e8122e..32fb1e7e8bfd 100644 --- a/api/current.txt +++ b/api/current.txt @@ -11672,6 +11672,7 @@ package android.content.pm { method public android.content.pm.LauncherApps.ShortcutQuery setQueryFlags(int); method public android.content.pm.LauncherApps.ShortcutQuery setShortcutIds(@Nullable java.util.List<java.lang.String>); field public static final int FLAG_GET_KEY_FIELDS_ONLY = 4; // 0x4 + field public static final int FLAG_MATCH_CACHED = 16; // 0x10 field public static final int FLAG_MATCH_DYNAMIC = 1; // 0x1 field public static final int FLAG_MATCH_MANIFEST = 8; // 0x8 field public static final int FLAG_MATCH_PINNED = 2; // 0x2 @@ -12365,6 +12366,7 @@ package android.content.pm { method @Nullable public CharSequence getShortLabel(); method public android.os.UserHandle getUserHandle(); method public boolean hasKeyFieldsOnly(); + method public boolean isCached(); method public boolean isDeclaredInManifest(); method public boolean isDynamic(); method public boolean isEnabled(); @@ -12414,14 +12416,20 @@ package android.content.pm { method @NonNull public java.util.List<android.content.pm.ShortcutInfo> getManifestShortcuts(); method public int getMaxShortcutCountPerActivity(); method @NonNull public java.util.List<android.content.pm.ShortcutInfo> getPinnedShortcuts(); + method @NonNull public java.util.List<android.content.pm.ShortcutInfo> getShortcuts(int); method public boolean isRateLimitingActive(); method public boolean isRequestPinShortcutSupported(); method public void removeAllDynamicShortcuts(); method public void removeDynamicShortcuts(@NonNull java.util.List<java.lang.String>); + method public void removeLongLivedShortcuts(@NonNull java.util.List<java.lang.String>); method public void reportShortcutUsed(String); method public boolean requestPinShortcut(@NonNull android.content.pm.ShortcutInfo, @Nullable android.content.IntentSender); method public boolean setDynamicShortcuts(@NonNull java.util.List<android.content.pm.ShortcutInfo>); method public boolean updateShortcuts(@NonNull java.util.List<android.content.pm.ShortcutInfo>); + field public static final int FLAG_MATCH_CACHED = 8; // 0x8 + field public static final int FLAG_MATCH_DYNAMIC = 2; // 0x2 + field public static final int FLAG_MATCH_MANIFEST = 1; // 0x1 + field public static final int FLAG_MATCH_PINNED = 4; // 0x4 } public class Signature implements android.os.Parcelable { diff --git a/api/system-current.txt b/api/system-current.txt index 54bc117ebb1f..0596b3d41eba 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -11801,9 +11801,9 @@ package android.telephony { field @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int LISTEN_OUTGOING_EMERGENCY_CALL = 268435456; // 0x10000000 field @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int LISTEN_OUTGOING_EMERGENCY_SMS = 536870912; // 0x20000000 field @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public static final int LISTEN_PRECISE_CALL_STATE = 2048; // 0x800 - field public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 8388608; // 0x800000 + field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 8388608; // 0x800000 field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_SRVCC_STATE_CHANGED = 16384; // 0x4000 - field public static final int LISTEN_VOICE_ACTIVATION_STATE = 131072; // 0x20000 + field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_VOICE_ACTIVATION_STATE = 131072; // 0x20000 } public final class PinResult implements android.os.Parcelable { diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 1fdc8af70f67..4b336eeb703d 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -79,111 +79,117 @@ message Atom { oneof pushed { // For StatsLog reasons, 1 is illegal and will not work. Must start at 2. BleScanStateChanged ble_scan_state_changed = 2 [(module) = "bluetooth"]; - ProcessStateChanged process_state_changed = 3; + ProcessStateChanged process_state_changed = 3 [(module) = "framework"]; BleScanResultReceived ble_scan_result_received = 4 [(module) = "bluetooth"]; - SensorStateChanged sensor_state_changed = 5; - GpsScanStateChanged gps_scan_state_changed = 6; - SyncStateChanged sync_state_changed = 7; - ScheduledJobStateChanged scheduled_job_state_changed = 8; - ScreenBrightnessChanged screen_brightness_changed = 9; - WakelockStateChanged wakelock_state_changed = 10; - LongPartialWakelockStateChanged long_partial_wakelock_state_changed = 11; - MobileRadioPowerStateChanged mobile_radio_power_state_changed = 12; - WifiRadioPowerStateChanged wifi_radio_power_state_changed = 13; - ActivityManagerSleepStateChanged activity_manager_sleep_state_changed = 14; - MemoryFactorStateChanged memory_factor_state_changed = 15; - ExcessiveCpuUsageReported excessive_cpu_usage_reported = 16; - CachedKillReported cached_kill_reported = 17; - ProcessMemoryStatReported process_memory_stat_reported = 18; + SensorStateChanged sensor_state_changed = 5 [(module) = "framework"]; + GpsScanStateChanged gps_scan_state_changed = 6 [(module) = "framework"]; + SyncStateChanged sync_state_changed = 7 [(module) = "framework"]; + ScheduledJobStateChanged scheduled_job_state_changed = 8 [(module) = "framework"]; + ScreenBrightnessChanged screen_brightness_changed = 9 [(module) = "framework"]; + WakelockStateChanged wakelock_state_changed = 10 [(module) = "framework"]; + LongPartialWakelockStateChanged long_partial_wakelock_state_changed = + 11 [(module) = "framework"]; + MobileRadioPowerStateChanged mobile_radio_power_state_changed = 12 [(module) = "framework"]; + WifiRadioPowerStateChanged wifi_radio_power_state_changed = 13 [(module) = "framework"]; + ActivityManagerSleepStateChanged activity_manager_sleep_state_changed = + 14 [(module) = "framework"]; + MemoryFactorStateChanged memory_factor_state_changed = 15 [(module) = "framework"]; + ExcessiveCpuUsageReported excessive_cpu_usage_reported = 16 [(module) = "framework"]; + CachedKillReported cached_kill_reported = 17 [(module) = "framework"]; + ProcessMemoryStatReported process_memory_stat_reported = 18 [(module) = "framework"]; LauncherUIChanged launcher_event = 19 [(module) = "sysui"]; - BatterySaverModeStateChanged battery_saver_mode_state_changed = 20; - DeviceIdleModeStateChanged device_idle_mode_state_changed = 21; - DeviceIdlingModeStateChanged device_idling_mode_state_changed = 22; - AudioStateChanged audio_state_changed = 23; - MediaCodecStateChanged media_codec_state_changed = 24; - CameraStateChanged camera_state_changed = 25; - FlashlightStateChanged flashlight_state_changed = 26; - UidProcessStateChanged uid_process_state_changed = 27; - ProcessLifeCycleStateChanged process_life_cycle_state_changed = 28; - ScreenStateChanged screen_state_changed = 29; - BatteryLevelChanged battery_level_changed = 30; - ChargingStateChanged charging_state_changed = 31; - PluggedStateChanged plugged_state_changed = 32; - InteractiveStateChanged interactive_state_changed = 33; + BatterySaverModeStateChanged battery_saver_mode_state_changed = 20 [(module) = "framework"]; + DeviceIdleModeStateChanged device_idle_mode_state_changed = 21 [(module) = "framework"]; + DeviceIdlingModeStateChanged device_idling_mode_state_changed = 22 [(module) = "framework"]; + AudioStateChanged audio_state_changed = 23 [(module) = "framework"]; + MediaCodecStateChanged media_codec_state_changed = 24 [(module) = "framework"]; + CameraStateChanged camera_state_changed = 25 [(module) = "framework"]; + FlashlightStateChanged flashlight_state_changed = 26 [(module) = "framework"]; + UidProcessStateChanged uid_process_state_changed = 27 [(module) = "framework"]; + ProcessLifeCycleStateChanged process_life_cycle_state_changed = 28 [(module) = "framework"]; + ScreenStateChanged screen_state_changed = 29 [(module) = "framework"]; + BatteryLevelChanged battery_level_changed = 30 [(module) = "framework"]; + ChargingStateChanged charging_state_changed = 31 [(module) = "framework"]; + PluggedStateChanged plugged_state_changed = 32 [(module) = "framework"]; + InteractiveStateChanged interactive_state_changed = 33 [(module) = "framework"]; TouchEventReported touch_event_reported = 34; - WakeupAlarmOccurred wakeup_alarm_occurred = 35; - KernelWakeupReported kernel_wakeup_reported = 36; + WakeupAlarmOccurred wakeup_alarm_occurred = 35 [(module) = "framework"]; + KernelWakeupReported kernel_wakeup_reported = 36 [(module) = "framework"]; 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; - IsolatedUidChanged isolated_uid_changed = 43; - PacketWakeupOccurred packet_wakeup_occurred = 44; - WallClockTimeShifted wall_clock_time_shifted = 45; + PhoneSignalStrengthChanged phone_signal_strength_changed = 40 [(module) = "framework"]; + SettingChanged setting_changed = 41 [(module) = "framework"]; + ActivityForegroundStateChanged activity_foreground_state_changed = + 42 [(module) = "framework"]; + IsolatedUidChanged isolated_uid_changed = 43 [(module) = "framework"]; + PacketWakeupOccurred packet_wakeup_occurred = 44 [(module) = "framework"]; + WallClockTimeShifted wall_clock_time_shifted = 45 [(module) = "framework"]; AnomalyDetected anomaly_detected = 46; - AppBreadcrumbReported app_breadcrumb_reported = 47 [(allow_from_any_uid) = true]; - AppStartOccurred app_start_occurred = 48; - AppStartCanceled app_start_canceled = 49; - AppStartFullyDrawn app_start_fully_drawn = 50; + AppBreadcrumbReported app_breadcrumb_reported = + 47 [(allow_from_any_uid) = true, (module) = "framework"]; + AppStartOccurred app_start_occurred = 48 [(module) = "framework"]; + AppStartCanceled app_start_canceled = 49 [(module) = "framework"]; + AppStartFullyDrawn app_start_fully_drawn = 50 [(module) = "framework"]; LmkKillOccurred lmk_kill_occurred = 51 [(module) = "lmkd"]; - PictureInPictureStateChanged picture_in_picture_state_changed = 52; + PictureInPictureStateChanged picture_in_picture_state_changed = 52 [(module) = "framework"]; WifiMulticastLockStateChanged wifi_multicast_lock_state_changed = 53 [(module) = "wifi"]; LmkStateChanged lmk_state_changed = 54 [(module) = "lmkd"]; - AppStartMemoryStateCaptured app_start_memory_state_captured = 55; - ShutdownSequenceReported shutdown_sequence_reported = 56; + AppStartMemoryStateCaptured app_start_memory_state_captured = 55 [(module) = "framework"]; + ShutdownSequenceReported shutdown_sequence_reported = 56 [(module) = "framework"]; BootSequenceReported boot_sequence_reported = 57; DaveyOccurred davey_occurred = 58 [(allow_from_any_uid) = true]; - OverlayStateChanged overlay_state_changed = 59; - ForegroundServiceStateChanged foreground_service_state_changed = 60; + OverlayStateChanged overlay_state_changed = 59 [(module) = "framework"]; + ForegroundServiceStateChanged foreground_service_state_changed + = 60 [(module) = "framework"]; CallStateChanged call_state_changed = 61 [(module) = "telecom"]; KeyguardStateChanged keyguard_state_changed = 62 [(module) = "sysui"]; KeyguardBouncerStateChanged keyguard_bouncer_state_changed = 63 [(module) = "sysui"]; KeyguardBouncerPasswordEntered keyguard_bouncer_password_entered = 64 [(module) = "sysui"]; - AppDied app_died = 65; - ResourceConfigurationChanged resource_configuration_changed = 66; - BluetoothEnabledStateChanged bluetooth_enabled_state_changed = 67; + AppDied app_died = 65 [(module) = "framework"]; + ResourceConfigurationChanged resource_configuration_changed = 66 [(module) = "framework"]; + BluetoothEnabledStateChanged bluetooth_enabled_state_changed = 67 [(module) = "framework"]; BluetoothConnectionStateChanged bluetooth_connection_state_changed = 68 [(module) = "bluetooth"]; - GpsSignalQualityChanged gps_signal_quality_changed = 69; - UsbConnectorStateChanged usb_connector_state_changed = 70; + GpsSignalQualityChanged gps_signal_quality_changed = 69 [(module) = "framework"]; + UsbConnectorStateChanged usb_connector_state_changed = 70 [(module) = "framework"]; SpeakerImpedanceReported speaker_impedance_reported = 71; HardwareFailed hardware_failed = 72; PhysicalDropDetected physical_drop_detected = 73; ChargeCyclesReported charge_cycles_reported = 74; MobileConnectionStateChanged mobile_connection_state_changed = 75 [(module) = "telephony"]; MobileRadioTechnologyChanged mobile_radio_technology_changed = 76 [(module) = "telephony"]; - UsbDeviceAttached usb_device_attached = 77; - AppCrashOccurred app_crash_occurred = 78; - ANROccurred anr_occurred = 79; - WTFOccurred wtf_occurred = 80; - LowMemReported low_mem_reported = 81; + UsbDeviceAttached usb_device_attached = 77 [(module) = "framework"]; + AppCrashOccurred app_crash_occurred = 78 [(module) = "framework"]; + ANROccurred anr_occurred = 79 [(module) = "framework"]; + WTFOccurred wtf_occurred = 80 [(module) = "framework"]; + LowMemReported low_mem_reported = 81 [(module) = "framework"]; GenericAtom generic_atom = 82; - KeyValuePairsAtom key_value_pairs_atom = 83 [(allow_from_any_uid) = true]; - VibratorStateChanged vibrator_state_changed = 84; - DeferredJobStatsReported deferred_job_stats_reported = 85; + KeyValuePairsAtom key_value_pairs_atom = + 83 [(allow_from_any_uid) = true, (module) = "framework"]; + VibratorStateChanged vibrator_state_changed = 84 [(module) = "framework"]; + DeferredJobStatsReported deferred_job_stats_reported = 85 [(module) = "framework"]; ThermalThrottlingStateChanged thermal_throttling = 86 [deprecated=true]; - BiometricAcquired biometric_acquired = 87; - BiometricAuthenticated biometric_authenticated = 88; - BiometricErrorOccurred biometric_error_occurred = 89; - UiEventReported ui_event_reported = 90; + BiometricAcquired biometric_acquired = 87 [(module) = "framework"]; + BiometricAuthenticated biometric_authenticated = 88 [(module) = "framework"]; + BiometricErrorOccurred biometric_error_occurred = 89 [(module) = "framework"]; + UiEventReported ui_event_reported = 90 [(module) = "framework"]; BatteryHealthSnapshot battery_health_snapshot = 91; SlowIo slow_io = 92; BatteryCausedShutdown battery_caused_shutdown = 93; - PhoneServiceStateChanged phone_service_state_changed = 94; - PhoneStateChanged phone_state_changed = 95; + PhoneServiceStateChanged phone_service_state_changed = 94 [(module) = "framework"]; + PhoneStateChanged phone_state_changed = 95 [(module) = "framework"]; UserRestrictionChanged user_restriction_changed = 96; SettingsUIChanged settings_ui_changed = 97; - ConnectivityStateChanged connectivity_state_changed = 98; + ConnectivityStateChanged connectivity_state_changed = 98 [(module) = "framework"]; // TODO: service state change is very noisy shortly after boot, as well // as at other transitions - coming out of doze, device plugged in, etc. // Consider removing this if it becomes a problem - ServiceStateChanged service_state_changed = 99; - ServiceLaunchReported service_launch_reported = 100; - FlagFlipUpdateOccurred flag_flip_update_occurred = 101; - BinaryPushStateChanged binary_push_state_changed = 102; - DevicePolicyEvent device_policy_event = 103; + ServiceStateChanged service_state_changed = 99 [(module) = "framework"]; + ServiceLaunchReported service_launch_reported = 100 [(module) = "framework"]; + FlagFlipUpdateOccurred flag_flip_update_occurred = 101 [(module) = "framework"]; + BinaryPushStateChanged binary_push_state_changed = 102 [(module) = "framework"]; + DevicePolicyEvent device_policy_event = 103 [(module) = "framework"]; DocsUIFileOperationCanceledReported docs_ui_file_op_canceled = 104 [(module) = "docsui"]; DocsUIFileOperationCopyMoveModeReported docs_ui_file_op_copy_move_mode_reported = 105 [(module) = "docsui"]; @@ -195,9 +201,9 @@ message Atom { 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; + WifiEnabledStateChanged wifi_enabled_state_changed = 113 [(module) = "framework"]; + WifiRunningStateChanged wifi_running_state_changed = 114 [(module) = "framework"]; + AppCompacted app_compacted = 115 [(module) = "framework"]; NetworkDnsEventReported network_dns_event_reported = 116 [(module) = "resolv"]; DocsUIPickerLaunchedFromReported docs_ui_picker_launched_from_reported = 117 [(module) = "docsui"]; @@ -205,20 +211,20 @@ message Atom { 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; + RescuePartyResetReported rescue_party_reset_reported = 122 [(module) = "framework"]; + SignedConfigReported signed_config_reported = 123 [(module) = "framework"]; + GnssNiEventReported gnss_ni_event_reported = 124 [(module) = "framework"]; BluetoothLinkLayerConnectionEvent bluetooth_link_layer_connection_event = 125 [(module) = "bluetooth"]; BluetoothAclConnectionStateChanged bluetooth_acl_connection_state_changed = 126 [(module) = "bluetooth"]; BluetoothScoConnectionStateChanged bluetooth_sco_connection_state_changed = 127 [(module) = "bluetooth"]; - AppDowngraded app_downgraded = 128; + AppDowngraded app_downgraded = 128 [(module) = "framework"]; AppOptimizedAfterDowngraded app_optimized_after_downgraded = 129; - LowStorageStateChanged low_storage_state_changed = 130; - GnssNfwNotificationReported gnss_nfw_notification_reported = 131; - GnssConfigurationReported gnss_configuration_reported = 132; + LowStorageStateChanged low_storage_state_changed = 130 [(module) = "framework"]; + GnssNfwNotificationReported gnss_nfw_notification_reported = 131 [(module) = "framework"]; + GnssConfigurationReported gnss_configuration_reported = 132 [(module) = "framework"]; UsbPortOverheatEvent usb_port_overheat_event_reported = 133; NfcErrorOccurred nfc_error_occurred = 134; NfcStateChanged nfc_state_changed = 135; @@ -228,15 +234,19 @@ message Atom { NfcHceTransactionOccurred nfc_hce_transaction_occurred = 139; SeStateChanged se_state_changed = 140; SeOmapiReported se_omapi_reported = 141; - BroadcastDispatchLatencyReported broadcast_dispatch_latency_reported = 142; - AttentionManagerServiceResultReported attention_manager_service_result_reported = 143; - AdbConnectionChanged adb_connection_changed = 144; + BroadcastDispatchLatencyReported broadcast_dispatch_latency_reported = + 142 [(module) = "framework"]; + AttentionManagerServiceResultReported attention_manager_service_result_reported = + 143 [(module) = "framework"]; + AdbConnectionChanged adb_connection_changed = 144 [(module) = "framework"]; SpeechDspStatReported speech_dsp_stat_reported = 145; - UsbContaminantReported usb_contaminant_reported = 146; - WatchdogRollbackOccurred watchdog_rollback_occurred = 147; - BiometricSystemHealthIssueDetected biometric_system_health_issue_detected = 148; + UsbContaminantReported usb_contaminant_reported = 146 [(module) = "framework"]; + WatchdogRollbackOccurred watchdog_rollback_occurred = 147 [(module) = "framework"]; + BiometricSystemHealthIssueDetected biometric_system_health_issue_detected = + 148 [(module) = "framework"]; BubbleUIChanged bubble_ui_changed = 149 [(module) = "sysui"]; - ScheduledJobConstraintChanged scheduled_job_constraint_changed = 150; + ScheduledJobConstraintChanged scheduled_job_constraint_changed = + 150 [(module) = "framework"]; BluetoothActiveDeviceChanged bluetooth_active_device_changed = 151 [(module) = "bluetooth"]; BluetoothA2dpPlaybackStateChanged bluetooth_a2dp_playback_state_changed = @@ -271,35 +281,38 @@ message Atom { 166 [(module) = "bluetooth"]; BluetoothSmpPairingEventReported bluetooth_smp_pairing_event_reported = 167 [(module) = "bluetooth"]; - ScreenTimeoutExtensionReported screen_timeout_extension_reported = 168; - ProcessStartTime process_start_time = 169; + ScreenTimeoutExtensionReported screen_timeout_extension_reported = + 168 [(module) = "framework"]; + ProcessStartTime process_start_time = 169 [(module) = "framework"]; PermissionGrantRequestResultReported permission_grant_request_result_reported = - 170 [(module) = "permissioncontroller"]; + 170 [(module) = "permissioncontroller"]; BluetoothSocketConnectionStateChanged bluetooth_socket_connection_state_changed = 171; DeviceIdentifierAccessDenied device_identifier_access_denied = 172 [(module) = "telephony_common"]; - BubbleDeveloperErrorReported bubble_developer_error_reported = 173; + BubbleDeveloperErrorReported bubble_developer_error_reported = 173 [(module) = "framework"]; AssistGestureStageReported assist_gesture_stage_reported = 174 [(module) = "sysui"]; AssistGestureFeedbackReported assist_gesture_feedback_reported = 175 [(module) = "sysui"]; AssistGestureProgressReported assist_gesture_progress_reported = 176 [(module) = "sysui"]; - TouchGestureClassified touch_gesture_classified = 177; - HiddenApiUsed hidden_api_used = 178 [(allow_from_any_uid) = true]; + TouchGestureClassified touch_gesture_classified = 177 [(module) = "framework"]; + HiddenApiUsed hidden_api_used = 178 [(allow_from_any_uid) = true, (module) = "framework"]; StyleUIChanged style_ui_changed = 179 [(module) = "sysui"]; PrivacyIndicatorsInteracted privacy_indicators_interacted = - 180 [(module) = "permissioncontroller"]; - AppInstallOnExternalStorageReported app_install_on_external_storage_reported = 181; + 180 [(module) = "permissioncontroller"]; + AppInstallOnExternalStorageReported app_install_on_external_storage_reported = + 181 [(module) = "framework"]; 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; + AppMovedStorageReported app_moved_storage_reported = 183 [(module) = "framework"]; + BiometricEnrolled biometric_enrolled = 184 [(module) = "framework"]; + SystemServerWatchdogOccurred system_server_watchdog_occurred = 185 [(module) = "framework"]; + TombStoneOccurred tomb_stone_occurred = 186 [(module) = "framework"]; BluetoothClassOfDeviceReported bluetooth_class_of_device_reported = 187 [(module) = "bluetooth"]; IntelligenceEventReported intelligence_event_reported = - 188 [(module) = "intelligence"]; - ThermalThrottlingSeverityStateChanged thermal_throttling_severity_state_changed = 189; + 188 [(module) = "intelligence"]; + ThermalThrottlingSeverityStateChanged thermal_throttling_severity_state_changed = + 189 [(module) = "framework"]; RoleRequestResultReported role_request_result_reported = - 190 [(module) = "permissioncontroller"]; + 190 [(module) = "permissioncontroller"]; MediametricsAudiopolicyReported mediametrics_audiopolicy_reported = 191; MediametricsAudiorecordReported mediametrics_audiorecord_reported = 192; MediametricsAudiothreadReported mediametrics_audiothread_reported = 193; @@ -314,38 +327,40 @@ message Atom { CarPowerStateChanged car_power_state_changed = 203 [(module) = "car"]; GarageModeInfo garage_mode_info = 204 [(module) = "car"]; 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; + ContentCaptureCallerMismatchReported content_capture_caller_mismatch_reported = + 206 [(module) = "framework"]; + ContentCaptureServiceEvents content_capture_service_events = 207 [(module) = "framework"]; + ContentCaptureSessionEvents content_capture_session_events = 208 [(module) = "framework"]; + ContentCaptureFlushed content_capture_flushed = 209 [(module) = "framework"]; + LocationManagerApiUsageReported location_manager_api_usage_reported = + 210 [(module) = "framework"]; ReviewPermissionsFragmentResultReported review_permissions_fragment_result_reported = - 211 [(module) = "permissioncontroller"]; + 211 [(module) = "permissioncontroller"]; RuntimePermissionsUpgradeResult runtime_permissions_upgrade_result = - 212 [(module) = "permissioncontroller"]; + 212 [(module) = "permissioncontroller"]; GrantPermissionsActivityButtonActions grant_permissions_activity_button_actions = - 213 [(module) = "permissioncontroller"]; + 213 [(module) = "permissioncontroller"]; LocationAccessCheckNotificationAction location_access_check_notification_action = - 214 [(module) = "permissioncontroller"]; + 214 [(module) = "permissioncontroller"]; AppPermissionFragmentActionReported app_permission_fragment_action_reported = - 215 [(module) = "permissioncontroller"]; + 215 [(module) = "permissioncontroller"]; AppPermissionFragmentViewed app_permission_fragment_viewed = - 216 [(module) = "permissioncontroller"]; + 216 [(module) = "permissioncontroller"]; AppPermissionsFragmentViewed app_permissions_fragment_viewed = - 217 [(module) = "permissioncontroller"]; + 217 [(module) = "permissioncontroller"]; PermissionAppsFragmentViewed permission_apps_fragment_viewed = - 218 [(module) = "permissioncontroller"]; + 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; + ExclusionRectStateChanged exclusion_rect_state_changed = 223 [(module) = "framework"]; BackGesture back_gesture_reported_reported = 224 [(module) = "sysui"]; UpdateEngineUpdateAttemptReported update_engine_update_attempt_reported = 225; UpdateEngineSuccessfulUpdateReported update_engine_successful_update_reported = 226; - CameraActionEvent camera_action_event = 227; + CameraActionEvent camera_action_event = 227 [(module) = "framework"]; AppCompatibilityChangeReported app_compatibility_change_reported = - 228 [(allow_from_any_uid) = true]; + 228 [(allow_from_any_uid) = true, (module) = "framework"]; PerfettoUploaded perfetto_uploaded = 229 [(module) = "perfetto"]; VmsClientConnectionStateChanged vms_client_connection_state_changed = 230 [(module) = "car"]; @@ -356,11 +371,12 @@ message Atom { MediaProviderSchemaChange media_provider_schema_change = 236 [(module) = "mediaprovider"]; MediaProviderIdleMaintenance media_provider_idle_maintenance = 237 [(module) = "mediaprovider"]; - RebootEscrowRecoveryReported reboot_escrow_recovery_reported = 238; - BootTimeEventDuration boot_time_event_duration_reported = 239; - BootTimeEventElapsedTime boot_time_event_elapsed_time_reported = 240; + RebootEscrowRecoveryReported reboot_escrow_recovery_reported = 238 [(module) = "framework"]; + BootTimeEventDuration boot_time_event_duration_reported = 239 [(module) = "framework"]; + BootTimeEventElapsedTime boot_time_event_elapsed_time_reported = + 240 [(module) = "framework"]; BootTimeEventUtcTime boot_time_event_utc_time_reported = 241; - BootTimeEventErrorCode boot_time_event_error_code_reported = 242; + BootTimeEventErrorCode boot_time_event_error_code_reported = 242 [(module) = "framework"]; UserspaceRebootReported userspace_reboot_reported = 243; NotificationReported notification_reported = 244; NotificationPanelReported notification_panel_reported = 245; @@ -376,76 +392,79 @@ message Atom { // Pulled events will start at field 10000. // Next: 10071 oneof pulled { - WifiBytesTransfer wifi_bytes_transfer = 10000; - WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001; - MobileBytesTransfer mobile_bytes_transfer = 10002; - MobileBytesTransferByFgBg mobile_bytes_transfer_by_fg_bg = 10003; - BluetoothBytesTransfer bluetooth_bytes_transfer = 10006; - KernelWakelock kernel_wakelock = 10004; + WifiBytesTransfer wifi_bytes_transfer = 10000 [(module) = "framework"]; + WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001 [(module) = "framework"]; + MobileBytesTransfer mobile_bytes_transfer = 10002 [(module) = "framework"]; + MobileBytesTransferByFgBg mobile_bytes_transfer_by_fg_bg = 10003 [(module) = "framework"]; + BluetoothBytesTransfer bluetooth_bytes_transfer = 10006 [(module) = "framework"]; + KernelWakelock kernel_wakelock = 10004 [(module) = "framework"]; SubsystemSleepState subsystem_sleep_state = 10005; - CpuTimePerFreq cpu_time_per_freq = 10008; - CpuTimePerUid cpu_time_per_uid = 10009; - CpuTimePerUidFreq cpu_time_per_uid_freq = 10010; - WifiActivityInfo wifi_activity_info = 10011; - ModemActivityInfo modem_activity_info = 10012; - BluetoothActivityInfo bluetooth_activity_info = 10007; - ProcessMemoryState process_memory_state = 10013; - SystemElapsedRealtime system_elapsed_realtime = 10014; - SystemUptime system_uptime = 10015; - CpuActiveTime cpu_active_time = 10016; - CpuClusterTime cpu_cluster_time = 10017; + CpuTimePerFreq cpu_time_per_freq = 10008 [(module) = "framework"]; + CpuTimePerUid cpu_time_per_uid = 10009 [(module) = "framework"]; + CpuTimePerUidFreq cpu_time_per_uid_freq = 10010 [(module) = "framework"]; + WifiActivityInfo wifi_activity_info = 10011 [(module) = "framework"]; + ModemActivityInfo modem_activity_info = 10012 [(module) = "framework"]; + BluetoothActivityInfo bluetooth_activity_info = 10007 [(module) = "framework"]; + ProcessMemoryState process_memory_state = 10013 [(module) = "framework"]; + SystemElapsedRealtime system_elapsed_realtime = 10014 [(module) = "framework"]; + SystemUptime system_uptime = 10015 [(module) = "framework"]; + CpuActiveTime cpu_active_time = 10016 [(module) = "framework"]; + CpuClusterTime cpu_cluster_time = 10017 [(module) = "framework"]; DiskSpace disk_space = 10018 [deprecated=true]; RemainingBatteryCapacity remaining_battery_capacity = 10019; FullBatteryCapacity full_battery_capacity = 10020; - Temperature temperature = 10021; - BinderCalls binder_calls = 10022; - BinderCallsExceptions binder_calls_exceptions = 10023; - LooperStats looper_stats = 10024; - DiskStats disk_stats = 10025; - DirectoryUsage directory_usage = 10026; - AppSize app_size = 10027; - CategorySize category_size = 10028; - ProcStats proc_stats = 10029; + Temperature temperature = 10021 [(module) = "framework"]; + BinderCalls binder_calls = 10022 [(module) = "framework"]; + BinderCallsExceptions binder_calls_exceptions = 10023 [(module) = "framework"]; + LooperStats looper_stats = 10024 [(module) = "framework"]; + DiskStats disk_stats = 10025 [(module) = "framework"]; + DirectoryUsage directory_usage = 10026 [(module) = "framework"]; + AppSize app_size = 10027 [(module) = "framework"]; + CategorySize category_size = 10028 [(module) = "framework"]; + ProcStats proc_stats = 10029 [(module) = "framework"]; BatteryVoltage battery_voltage = 10030; - NumFingerprintsEnrolled num_fingerprints_enrolled = 10031; - DiskIo disk_io = 10032; - PowerProfile power_profile = 10033; - ProcStatsPkgProc proc_stats_pkg_proc = 10034; - ProcessCpuTime process_cpu_time = 10035; - CpuTimePerThreadFreq cpu_time_per_thread_freq = 10037; + NumFingerprintsEnrolled num_fingerprints_enrolled = 10031 [(module) = "framework"]; + DiskIo disk_io = 10032 [(module) = "framework"]; + PowerProfile power_profile = 10033 [(module) = "framework"]; + ProcStatsPkgProc proc_stats_pkg_proc = 10034 [(module) = "framework"]; + ProcessCpuTime process_cpu_time = 10035 [(module) = "framework"]; + CpuTimePerThreadFreq cpu_time_per_thread_freq = 10037 [(module) = "framework"]; OnDevicePowerMeasurement on_device_power_measurement = 10038; - DeviceCalculatedPowerUse device_calculated_power_use = 10039; - DeviceCalculatedPowerBlameUid device_calculated_power_blame_uid = 10040; - DeviceCalculatedPowerBlameOther device_calculated_power_blame_other = 10041; - ProcessMemoryHighWaterMark process_memory_high_water_mark = 10042; + DeviceCalculatedPowerUse device_calculated_power_use = 10039 [(module) = "framework"]; + DeviceCalculatedPowerBlameUid device_calculated_power_blame_uid = + 10040 [(module) = "framework"]; + DeviceCalculatedPowerBlameOther device_calculated_power_blame_other = + 10041 [(module) = "framework"]; + ProcessMemoryHighWaterMark process_memory_high_water_mark = 10042 [(module) = "framework"]; BatteryLevel battery_level = 10043; - BuildInformation build_information = 10044; + BuildInformation build_information = 10044 [(module) = "framework"]; BatteryCycleCount battery_cycle_count = 10045; - DebugElapsedClock debug_elapsed_clock = 10046; - DebugFailingElapsedClock debug_failing_elapsed_clock = 10047; - NumFacesEnrolled num_faces_enrolled = 10048; - RoleHolder role_holder = 10049; - DangerousPermissionState dangerous_permission_state = 10050; + DebugElapsedClock debug_elapsed_clock = 10046 [(module) = "framework"]; + DebugFailingElapsedClock debug_failing_elapsed_clock = 10047 [(module) = "framework"]; + NumFacesEnrolled num_faces_enrolled = 10048 [(module) = "framework"]; + RoleHolder role_holder = 10049 [(module) = "framework"]; + DangerousPermissionState dangerous_permission_state = 10050 [(module) = "framework"]; TrainInfo train_info = 10051; - TimeZoneDataInfo time_zone_data_info = 10052; - ExternalStorageInfo external_storage_info = 10053; + TimeZoneDataInfo time_zone_data_info = 10052 [(module) = "framework"]; + ExternalStorageInfo external_storage_info = 10053 [(module) = "framework"]; GpuStatsGlobalInfo gpu_stats_global_info = 10054; GpuStatsAppInfo gpu_stats_app_info = 10055; - SystemIonHeapSize system_ion_heap_size = 10056 [deprecated = true]; - AppsOnExternalStorageInfo apps_on_external_storage_info = 10057; - FaceSettings face_settings = 10058; - CoolingDevice cooling_device = 10059; - AppOps app_ops = 10060; - ProcessSystemIonHeapSize process_system_ion_heap_size = 10061; + SystemIonHeapSize system_ion_heap_size = 10056 [deprecated = true, (module) = "framework"]; + AppsOnExternalStorageInfo apps_on_external_storage_info = 10057 [(module) = "framework"]; + FaceSettings face_settings = 10058 [(module) = "framework"]; + CoolingDevice cooling_device = 10059 [(module) = "framework"]; + AppOps app_ops = 10060 [(module) = "framework"]; + ProcessSystemIonHeapSize process_system_ion_heap_size = 10061 [(module) = "framework"]; SurfaceflingerStatsGlobalInfo surfaceflinger_stats_global_info = 10062; SurfaceflingerStatsLayerInfo surfaceflinger_stats_layer_info = 10063; - ProcessMemorySnapshot process_memory_snapshot = 10064; + ProcessMemorySnapshot process_memory_snapshot = 10064 [(module) = "framework"]; VmsClientStats vms_client_stats = 10065 [(module) = "car"]; - NotificationRemoteViews notification_remote_views = 10066; - DangerousPermissionStateSampled dangerous_permission_state_sampled = 10067; + NotificationRemoteViews notification_remote_views = 10066 [(module) = "framework"]; + DangerousPermissionStateSampled dangerous_permission_state_sampled = + 10067 [(module) = "framework"]; GraphicsStats graphics_stats = 10068; RuntimeAppOpsAccess runtime_app_ops_access = 10069; - IonHeapSize ion_heap_size = 10070; + IonHeapSize ion_heap_size = 10070 [(module) = "framework"]; } // DO NOT USE field numbers above 100,000 in AOSP. @@ -6895,7 +6914,8 @@ message DeviceIdentifierAccessDenied { optional string method_name = 2; // True if the package is preinstalled. - optional bool is_preinstalled = 3; + // Starting from Android 11, this boolean is not set and will always be false. + optional bool is_preinstalled = 3 [deprecated = true]; // True if the package is privileged. // Starting from Android 11, this boolean is not set and will always be false. diff --git a/core/java/android/content/pm/IShortcutService.aidl b/core/java/android/content/pm/IShortcutService.aidl index 276853d3b860..747e929eda98 100644 --- a/core/java/android/content/pm/IShortcutService.aidl +++ b/core/java/android/content/pm/IShortcutService.aidl @@ -78,4 +78,8 @@ interface IShortcutService { ParceledListSlice getShareTargets(String packageName, in IntentFilter filter, int userId); boolean hasShareTargets(String packageName, String packageToCheck, int userId); + + void removeLongLivedShortcuts(String packageName, in List shortcutIds, int userId); + + ParceledListSlice getShortcuts(String packageName, int matchFlags, int userId); }
\ No newline at end of file diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java index ed958b118650..cea0b6b5f3ad 100644 --- a/core/java/android/content/pm/LauncherApps.java +++ b/core/java/android/content/pm/LauncherApps.java @@ -324,6 +324,11 @@ public class LauncherApps { */ public static final int FLAG_MATCH_MANIFEST = 1 << 3; + /** + * Include cached shortcuts in the result. + */ + public static final int FLAG_MATCH_CACHED = 1 << 4; + /** @hide kept for unit tests */ @Deprecated public static final int FLAG_GET_MANIFEST = FLAG_MATCH_MANIFEST; @@ -345,11 +350,11 @@ public class LauncherApps { public static final int FLAG_MATCH_PINNED_BY_ANY_LAUNCHER = 1 << 10; /** - * FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST + * FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST | FLAG_MATCH_CACHED * @hide */ public static final int FLAG_MATCH_ALL_KINDS = - FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST; + FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST | FLAG_MATCH_CACHED; /** * FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST | FLAG_MATCH_ALL_PINNED @@ -386,8 +391,8 @@ public class LauncherApps { FLAG_MATCH_DYNAMIC, FLAG_MATCH_PINNED, FLAG_MATCH_MANIFEST, + FLAG_MATCH_CACHED, FLAG_GET_KEY_FIELDS_ONLY, - FLAG_MATCH_MANIFEST, }) @Retention(RetentionPolicy.SOURCE) public @interface QueryFlags {} @@ -454,6 +459,7 @@ public class LauncherApps { * <li>{@link #FLAG_MATCH_DYNAMIC} * <li>{@link #FLAG_MATCH_PINNED} * <li>{@link #FLAG_MATCH_MANIFEST} + * <li>{@link #FLAG_MATCH_CACHED} * <li>{@link #FLAG_GET_KEY_FIELDS_ONLY} * </ul> */ diff --git a/core/java/android/content/pm/ShortcutInfo.java b/core/java/android/content/pm/ShortcutInfo.java index d5fb848c2692..bde4f614a39e 100644 --- a/core/java/android/content/pm/ShortcutInfo.java +++ b/core/java/android/content/pm/ShortcutInfo.java @@ -120,6 +120,9 @@ public final class ShortcutInfo implements Parcelable { public static final int FLAG_LONG_LIVED = 1 << 13; /** @hide */ + public static final int FLAG_CACHED = 1 << 14; + + /** @hide */ @IntDef(flag = true, prefix = { "FLAG_" }, value = { FLAG_DYNAMIC, FLAG_PINNED, @@ -135,6 +138,7 @@ public final class ShortcutInfo implements Parcelable { FLAG_ICON_FILE_PENDING_SAVE, FLAG_SHADOW, FLAG_LONG_LIVED, + FLAG_CACHED, }) @Retention(RetentionPolicy.SOURCE) public @interface ShortcutFlags {} @@ -1681,6 +1685,16 @@ public final class ShortcutInfo implements Parcelable { addFlags(FLAG_LONG_LIVED); } + /** @hide */ + public void setCached() { + addFlags(FLAG_CACHED); + } + + /** Return whether a shortcut is cached. */ + public boolean isCached() { + return hasFlags(FLAG_CACHED); + } + /** Return whether a shortcut is dynamic. */ public boolean isDynamic() { return hasFlags(FLAG_DYNAMIC); @@ -1765,7 +1779,8 @@ public final class ShortcutInfo implements Parcelable { /** @hide */ public boolean isAlive() { - return hasFlags(FLAG_PINNED) || hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST); + return hasFlags(FLAG_PINNED) || hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST) + || hasFlags(FLAG_CACHED); } /** @hide */ diff --git a/core/java/android/content/pm/ShortcutManager.java b/core/java/android/content/pm/ShortcutManager.java index dde8865467a1..3eea3f62fd46 100644 --- a/core/java/android/content/pm/ShortcutManager.java +++ b/core/java/android/content/pm/ShortcutManager.java @@ -16,6 +16,7 @@ package android.content.pm; import android.Manifest; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; @@ -40,6 +41,8 @@ import android.os.ServiceManager; import com.android.internal.annotations.VisibleForTesting; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.List; /** @@ -62,6 +65,44 @@ import java.util.List; public class ShortcutManager { private static final String TAG = "ShortcutManager"; + /** + * Include manifest shortcuts in the result. + * + * @see #getShortcuts(int) + */ + public static final int FLAG_MATCH_MANIFEST = 1 << 0; + + /** + * Include dynamic shortcuts in the result. + * + * @see #getShortcuts(int) + */ + public static final int FLAG_MATCH_DYNAMIC = 1 << 1; + + /** + * Include pinned shortcuts in the result. + * + * @see #getShortcuts(int) + */ + public static final int FLAG_MATCH_PINNED = 1 << 2; + + /** + * Include cached shortcuts in the result. + * + * @see #getShortcuts(int) + */ + public static final int FLAG_MATCH_CACHED = 1 << 3; + + /** @hide */ + @IntDef(flag = true, prefix = { "FLAG_MATCH_" }, value = { + FLAG_MATCH_MANIFEST, + FLAG_MATCH_DYNAMIC, + FLAG_MATCH_PINNED, + FLAG_MATCH_CACHED, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ShortcutMatchFlags {} + private final Context mContext; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) private final IShortcutService mService; @@ -118,8 +159,8 @@ public class ShortcutManager { @NonNull public List<ShortcutInfo> getDynamicShortcuts() { try { - return mService.getDynamicShortcuts(mContext.getPackageName(), injectMyUserId()) - .getList(); + return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_DYNAMIC, + injectMyUserId()).getList(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -137,7 +178,35 @@ public class ShortcutManager { @NonNull public List<ShortcutInfo> getManifestShortcuts() { try { - return mService.getManifestShortcuts(mContext.getPackageName(), injectMyUserId()) + return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_MANIFEST, + injectMyUserId()).getList(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Returns {@link ShortcutInfo}s that match {@code matchFlags}. + * + * @param matchFlags result includes shortcuts matching this flags. Any combination of: + * <ul> + * <li>{@link #FLAG_MATCH_MANIFEST} + * <li>{@link #FLAG_MATCH_DYNAMIC} + * <li>{@link #FLAG_MATCH_PINNED} + * <li>{@link #FLAG_MATCH_CACHED} + * </ul> + + * @return list of {@link ShortcutInfo}s that match the flag. + * + * <p>At least one of the {@code MATCH} flags should be set. Otherwise no shortcuts will be + * returned. + * + * @throws IllegalStateException when the user is locked. + */ + @NonNull + public List<ShortcutInfo> getShortcuts(@ShortcutMatchFlags int matchFlags) { + try { + return mService.getShortcuts(mContext.getPackageName(), matchFlags, injectMyUserId()) .getList(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); @@ -194,6 +263,20 @@ public class ShortcutManager { } /** + * Delete long lived shortcuts by ID. + * + * @throws IllegalStateException when the user is locked. + */ + public void removeLongLivedShortcuts(@NonNull List<String> shortcutIds) { + try { + mService.removeLongLivedShortcuts(mContext.getPackageName(), shortcutIds, + injectMyUserId()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Return all pinned shortcuts from the caller app. * * <p>This API is intended to be used for examining what shortcuts are currently published. @@ -205,8 +288,8 @@ public class ShortcutManager { @NonNull public List<ShortcutInfo> getPinnedShortcuts() { try { - return mService.getPinnedShortcuts(mContext.getPackageName(), injectMyUserId()) - .getList(); + return mService.getShortcuts(mContext.getPackageName(), FLAG_MATCH_PINNED, + injectMyUserId()).getList(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/telephony/PhoneStateListener.java b/core/java/android/telephony/PhoneStateListener.java index 67cac0eb3b21..023f0005eac7 100644 --- a/core/java/android/telephony/PhoneStateListener.java +++ b/core/java/android/telephony/PhoneStateListener.java @@ -225,6 +225,9 @@ public class PhoneStateListener { /** * Listen for changes to the SRVCC state of the active call. + * + * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} + * * @see #onServiceStateChanged(ServiceState) * @hide */ @@ -253,6 +256,9 @@ public class PhoneStateListener { /** * Listen for changes to the sim voice activation state + * + * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} + * * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED * @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED @@ -266,6 +272,7 @@ public class PhoneStateListener { * @hide */ @SystemApi + @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_VOICE_ACTIVATION_STATE = 0x00020000; /** @@ -312,10 +319,13 @@ public class PhoneStateListener { /** * Listen for changes to the radio power state. * + * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} + * * @see #onRadioPowerStateChanged * @hide */ @SystemApi + @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 0x00800000; /** @@ -904,7 +914,6 @@ public class PhoneStateListener { * Callback invoked when phone capability changes. * Note, this callback triggers regardless of registered subscription. * - * Requires the READ_PRIVILEGED_PHONE_STATE permission. * @param capability the new phone capability * @hide */ @@ -934,7 +943,7 @@ public class PhoneStateListener { * subId. Otherwise, this callback applies to * {@link SubscriptionManager#getDefaultSubscriptionId()}. * - * Requires the READ_PRIVILEGED_PHONE_STATE permission. + * Requires the READ_PRECISE_PHONE_STATE permission. * @param callAttributes the call attributes * @hide */ diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index 4b969ece2e15..1ea7d6144356 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -1084,6 +1084,13 @@ static pid_t ForkCommon(JNIEnv* env, bool is_system_server, android_fdsan_error_level fdsan_error_level = android_fdsan_get_error_level(); + // Purge unused native memory in an attempt to reduce the amount of false + // sharing with the child process. By reducing the size of the libc_malloc + // region shared with the child process we reduce the number of pages that + // transition to the private-dirty state when malloc adjusts the meta-data + // on each of the pages it is managing after the fork. + mallopt(M_PURGE, 0); + pid_t pid = fork(); if (pid == 0) { diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp index 007d367a533a..1fbe7f42fff3 100644 --- a/media/jni/android_media_tv_Tuner.cpp +++ b/media/jni/android_media_tv_Tuner.cpp @@ -41,6 +41,54 @@ using ::android::hardware::tv::tuner::V1_0::DvrSettings; using ::android::hardware::tv::tuner::V1_0::FrontendAnalogSettings; using ::android::hardware::tv::tuner::V1_0::FrontendAnalogSifStandard; using ::android::hardware::tv::tuner::V1_0::FrontendAnalogType; +using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Bandwidth; +using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3CodeRate; +using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3DemodOutputFormat; +using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Fec; +using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Modulation; +using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3PlpSettings; +using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3Settings; +using ::android::hardware::tv::tuner::V1_0::FrontendAtsc3TimeInterleaveMode; +using ::android::hardware::tv::tuner::V1_0::FrontendAtscSettings; +using ::android::hardware::tv::tuner::V1_0::FrontendAtscModulation; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbcAnnex; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbcModulation; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbcOuterFec; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbcSettings; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbcSpectralInversion; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbsCodeRate; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbsModulation; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbsPilot; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbsRolloff; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbsSettings; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbsStandard; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbsVcmMode; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtBandwidth; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtCoderate; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtConstellation; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtGuardInterval; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtHierarchy; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtPlpMode; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtSettings; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtStandard; +using ::android::hardware::tv::tuner::V1_0::FrontendDvbtTransmissionMode; +using ::android::hardware::tv::tuner::V1_0::FrontendInnerFec; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Coderate; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Modulation; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Rolloff; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbs3Settings; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbsCoderate; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbsModulation; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbsRolloff; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbsSettings; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbsStreamIdType; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtBandwidth; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtCoderate; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtGuardInterval; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtMode; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtModulation; +using ::android::hardware::tv::tuner::V1_0::FrontendIsdbtSettings; +using ::android::hardware::tv::tuner::V1_0::FrontendType; using ::android::hardware::tv::tuner::V1_0::ITuner; using ::android::hardware::tv::tuner::V1_0::PlaybackSettings; using ::android::hardware::tv::tuner::V1_0::RecordSettings; @@ -493,32 +541,437 @@ static DemuxPid getDemuxPid(int pidType, int pid) { return demuxPid; } -static FrontendSettings getFrontendSettings(JNIEnv *env, int type, jobject settings) { - FrontendSettings frontendSettings; +static uint32_t getFrontendSettingsFreq(JNIEnv *env, const jobject& settings) { jclass clazz = env->FindClass("android/media/tv/tuner/frontend/FrontendSettings"); jfieldID freqField = env->GetFieldID(clazz, "mFrequency", "I"); - uint32_t freq = static_cast<uint32_t>(env->GetIntField(clazz, freqField)); - - // TODO: handle the other 8 types of settings - if (type == 1) { - // analog - clazz = env->FindClass("android/media/tv/tuner/frontend/AnalogFrontendSettings"); - FrontendAnalogType analogType = - static_cast<FrontendAnalogType>( - env->GetIntField(settings, env->GetFieldID(clazz, "mAnalogType", "I"))); - FrontendAnalogSifStandard sifStandard = - static_cast<FrontendAnalogSifStandard>( - env->GetIntField(settings, env->GetFieldID(clazz, "mSifStandard", "I"))); - FrontendAnalogSettings frontendAnalogSettings { - .frequency = freq, - .type = analogType, - .sifStandard = sifStandard, + uint32_t freq = static_cast<uint32_t>(env->GetIntField(settings, freqField)); + return freq; +} + +static FrontendSettings getAnalogFrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/AnalogFrontendSettings"); + FrontendAnalogType analogType = + static_cast<FrontendAnalogType>( + env->GetIntField(settings, env->GetFieldID(clazz, "mSignalType", "I"))); + FrontendAnalogSifStandard sifStandard = + static_cast<FrontendAnalogSifStandard>( + env->GetIntField(settings, env->GetFieldID(clazz, "mSifStandard", "I"))); + FrontendAnalogSettings frontendAnalogSettings { + .frequency = freq, + .type = analogType, + .sifStandard = sifStandard, + }; + frontendSettings.analog(frontendAnalogSettings); + return frontendSettings; +} + +static hidl_vec<FrontendAtsc3PlpSettings> getAtsc3PlpSettings( + JNIEnv *env, const jobject& settings) { + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/Atsc3FrontendSettings"); + jobjectArray plpSettings = + reinterpret_cast<jobjectArray>( + env->GetObjectField(settings, + env->GetFieldID( + clazz, + "mPlpSettings", + "[Landroid/media/tv/tuner/frontend/Atsc3PlpSettings;"))); + int len = env->GetArrayLength(plpSettings); + + jclass plpClazz = env->FindClass("android/media/tv/tuner/frontend/Atsc3PlpSettings"); + hidl_vec<FrontendAtsc3PlpSettings> plps = hidl_vec<FrontendAtsc3PlpSettings>(len); + // parse PLP settings + for (int i = 0; i < len; i++) { + jobject plp = env->GetObjectArrayElement(plpSettings, i); + uint8_t plpId = + static_cast<uint8_t>( + env->GetIntField(plp, env->GetFieldID(plpClazz, "mPlpId", "I"))); + FrontendAtsc3Modulation modulation = + static_cast<FrontendAtsc3Modulation>( + env->GetIntField(plp, env->GetFieldID(plpClazz, "mModulation", "I"))); + FrontendAtsc3TimeInterleaveMode interleaveMode = + static_cast<FrontendAtsc3TimeInterleaveMode>( + env->GetIntField( + plp, env->GetFieldID(plpClazz, "mInterleaveMode", "I"))); + FrontendAtsc3CodeRate codeRate = + static_cast<FrontendAtsc3CodeRate>( + env->GetIntField(plp, env->GetFieldID(plpClazz, "mCodeRate", "I"))); + FrontendAtsc3Fec fec = + static_cast<FrontendAtsc3Fec>( + env->GetIntField(plp, env->GetFieldID(plpClazz, "mFec", "I"))); + FrontendAtsc3PlpSettings frontendAtsc3PlpSettings { + .plpId = plpId, + .modulation = modulation, + .interleaveMode = interleaveMode, + .codeRate = codeRate, + .fec = fec, }; - frontendSettings.analog(frontendAnalogSettings); + plps[i] = frontendAtsc3PlpSettings; } + return plps; +} + +static FrontendSettings getAtsc3FrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/Atsc3FrontendSettings"); + + FrontendAtsc3Bandwidth bandwidth = + static_cast<FrontendAtsc3Bandwidth>( + env->GetIntField(settings, env->GetFieldID(clazz, "mBandwidth", "I"))); + FrontendAtsc3DemodOutputFormat demod = + static_cast<FrontendAtsc3DemodOutputFormat>( + env->GetIntField( + settings, env->GetFieldID(clazz, "mDemodOutputFormat", "I"))); + hidl_vec<FrontendAtsc3PlpSettings> plps = getAtsc3PlpSettings(env, settings); + FrontendAtsc3Settings frontendAtsc3Settings { + .frequency = freq, + .bandwidth = bandwidth, + .demodOutputFormat = demod, + .plpSettings = plps, + }; + frontendSettings.atsc3(frontendAtsc3Settings); + return frontendSettings; +} + +static FrontendSettings getAtscFrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/AtscFrontendSettings"); + FrontendAtscModulation modulation = + static_cast<FrontendAtscModulation>( + env->GetIntField(settings, env->GetFieldID(clazz, "mModulation", "I"))); + FrontendAtscSettings frontendAtscSettings { + .frequency = freq, + .modulation = modulation, + }; + frontendSettings.atsc(frontendAtscSettings); + return frontendSettings; +} + +static FrontendSettings getDvbcFrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/DvbcFrontendSettings"); + FrontendDvbcModulation modulation = + static_cast<FrontendDvbcModulation>( + env->GetIntField(settings, env->GetFieldID(clazz, "mModulation", "I"))); + FrontendInnerFec innerFec = + static_cast<FrontendInnerFec>( + env->GetLongField(settings, env->GetFieldID(clazz, "mFec", "J"))); + uint32_t symbolRate = + static_cast<uint32_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mSymbolRate", "I"))); + FrontendDvbcOuterFec outerFec = + static_cast<FrontendDvbcOuterFec>( + env->GetIntField(settings, env->GetFieldID(clazz, "mOuterFec", "I"))); + FrontendDvbcAnnex annex = + static_cast<FrontendDvbcAnnex>( + env->GetByteField(settings, env->GetFieldID(clazz, "mAnnex", "B"))); + FrontendDvbcSpectralInversion spectralInversion = + static_cast<FrontendDvbcSpectralInversion>( + env->GetIntField( + settings, env->GetFieldID(clazz, "mSpectralInversion", "I"))); + FrontendDvbcSettings frontendDvbcSettings { + .frequency = freq, + .modulation = modulation, + .fec = innerFec, + .symbolRate = symbolRate, + .outerFec = outerFec, + .annex = annex, + .spectralInversion = spectralInversion, + }; + frontendSettings.dvbc(frontendDvbcSettings); + return frontendSettings; +} + +static FrontendDvbsCodeRate getDvbsCodeRate(JNIEnv *env, const jobject& settings) { + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/DvbsFrontendSettings"); + jobject jcodeRate = + env->GetObjectField(settings, + env->GetFieldID( + clazz, + "mCodeRate", + "Landroid/media/tv/tuner/frontend/DvbsCodeRate;")); + + jclass codeRateClazz = env->FindClass("android/media/tv/tuner/frontend/DvbsCodeRate"); + FrontendInnerFec innerFec = + static_cast<FrontendInnerFec>( + env->GetLongField( + jcodeRate, env->GetFieldID(codeRateClazz, "mInnerFec", "J"))); + bool isLinear = + static_cast<bool>( + env->GetBooleanField( + jcodeRate, env->GetFieldID(codeRateClazz, "mIsLinear", "Z"))); + bool isShortFrames = + static_cast<bool>( + env->GetBooleanField( + jcodeRate, env->GetFieldID(codeRateClazz, "mIsShortFrames", "Z"))); + uint32_t bitsPer1000Symbol = + static_cast<uint32_t>( + env->GetIntField( + jcodeRate, env->GetFieldID( + codeRateClazz, "mBitsPer1000Symbol", "I"))); + FrontendDvbsCodeRate coderate { + .fec = innerFec, + .isLinear = isLinear, + .isShortFrames = isShortFrames, + .bitsPer1000Symbol = bitsPer1000Symbol, + }; + return coderate; +} + +static FrontendSettings getDvbsFrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/DvbsFrontendSettings"); + + + FrontendDvbsModulation modulation = + static_cast<FrontendDvbsModulation>( + env->GetIntField(settings, env->GetFieldID(clazz, "mModulation", "I"))); + uint32_t symbolRate = + static_cast<uint32_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mSymbolRate", "I"))); + FrontendDvbsRolloff rolloff = + static_cast<FrontendDvbsRolloff>( + env->GetIntField(settings, env->GetFieldID(clazz, "mRolloff", "I"))); + FrontendDvbsPilot pilot = + static_cast<FrontendDvbsPilot>( + env->GetIntField(settings, env->GetFieldID(clazz, "mPilot", "I"))); + uint32_t inputStreamId = + static_cast<uint32_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mInputStreamId", "I"))); + FrontendDvbsStandard standard = + static_cast<FrontendDvbsStandard>( + env->GetIntField(settings, env->GetFieldID(clazz, "mStandard", "I"))); + FrontendDvbsVcmMode vcmMode = + static_cast<FrontendDvbsVcmMode>( + env->GetIntField(settings, env->GetFieldID(clazz, "mVcmMode", "I"))); + FrontendDvbsCodeRate coderate = getDvbsCodeRate(env, settings); + + FrontendDvbsSettings frontendDvbsSettings { + .frequency = freq, + .modulation = modulation, + .coderate = coderate, + .symbolRate = symbolRate, + .rolloff = rolloff, + .pilot = pilot, + .inputStreamId = inputStreamId, + .standard = standard, + .vcmMode = vcmMode, + }; + frontendSettings.dvbs(frontendDvbsSettings); + return frontendSettings; +} + +static FrontendSettings getDvbtFrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/DvbtFrontendSettings"); + FrontendDvbtTransmissionMode transmissionMode = + static_cast<FrontendDvbtTransmissionMode>( + env->GetIntField( + settings, env->GetFieldID(clazz, "mTransmissionMode", "I"))); + FrontendDvbtBandwidth bandwidth = + static_cast<FrontendDvbtBandwidth>( + env->GetIntField(settings, env->GetFieldID(clazz, "mBandwidth", "I"))); + FrontendDvbtConstellation constellation = + static_cast<FrontendDvbtConstellation>( + env->GetIntField(settings, env->GetFieldID(clazz, "mConstellation", "I"))); + FrontendDvbtHierarchy hierarchy = + static_cast<FrontendDvbtHierarchy>( + env->GetIntField(settings, env->GetFieldID(clazz, "mHierarchy", "I"))); + FrontendDvbtCoderate hpCoderate = + static_cast<FrontendDvbtCoderate>( + env->GetIntField(settings, env->GetFieldID(clazz, "mHpCodeRate", "I"))); + FrontendDvbtCoderate lpCoderate = + static_cast<FrontendDvbtCoderate>( + env->GetIntField(settings, env->GetFieldID(clazz, "mLpCodeRate", "I"))); + FrontendDvbtGuardInterval guardInterval = + static_cast<FrontendDvbtGuardInterval>( + env->GetIntField(settings, env->GetFieldID(clazz, "mGuardInterval", "I"))); + bool isHighPriority = + static_cast<bool>( + env->GetBooleanField( + settings, env->GetFieldID(clazz, "mIsHighPriority", "Z"))); + FrontendDvbtStandard standard = + static_cast<FrontendDvbtStandard>( + env->GetIntField(settings, env->GetFieldID(clazz, "mStandard", "I"))); + bool isMiso = + static_cast<bool>( + env->GetBooleanField(settings, env->GetFieldID(clazz, "mIsMiso", "Z"))); + FrontendDvbtPlpMode plpMode = + static_cast<FrontendDvbtPlpMode>( + env->GetIntField(settings, env->GetFieldID(clazz, "mPlpMode", "I"))); + uint8_t plpId = + static_cast<uint8_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mPlpId", "I"))); + uint8_t plpGroupId = + static_cast<uint8_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mPlpGroupId", "I"))); + + FrontendDvbtSettings frontendDvbtSettings { + .frequency = freq, + .transmissionMode = transmissionMode, + .bandwidth = bandwidth, + .constellation = constellation, + .hierarchy = hierarchy, + .hpCoderate = hpCoderate, + .lpCoderate = lpCoderate, + .guardInterval = guardInterval, + .isHighPriority = isHighPriority, + .standard = standard, + .isMiso = isMiso, + .plpMode = plpMode, + .plpId = plpId, + .plpGroupId = plpGroupId, + }; + frontendSettings.dvbt(frontendDvbtSettings); + return frontendSettings; +} + +static FrontendSettings getIsdbsFrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/IsdbsFrontendSettings"); + uint16_t streamId = + static_cast<uint16_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mStreamId", "I"))); + FrontendIsdbsStreamIdType streamIdType = + static_cast<FrontendIsdbsStreamIdType>( + env->GetIntField(settings, env->GetFieldID(clazz, "mStreamIdType", "I"))); + FrontendIsdbsModulation modulation = + static_cast<FrontendIsdbsModulation>( + env->GetIntField(settings, env->GetFieldID(clazz, "mModulation", "I"))); + FrontendIsdbsCoderate coderate = + static_cast<FrontendIsdbsCoderate>( + env->GetIntField(settings, env->GetFieldID(clazz, "mCodeRate", "I"))); + uint32_t symbolRate = + static_cast<uint32_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mSymbolRate", "I"))); + FrontendIsdbsRolloff rolloff = + static_cast<FrontendIsdbsRolloff>( + env->GetIntField(settings, env->GetFieldID(clazz, "mRolloff", "I"))); + + FrontendIsdbsSettings frontendIsdbsSettings { + .frequency = freq, + .streamId = streamId, + .streamIdType = streamIdType, + .modulation = modulation, + .coderate = coderate, + .symbolRate = symbolRate, + .rolloff = rolloff, + }; + frontendSettings.isdbs(frontendIsdbsSettings); return frontendSettings; } +static FrontendSettings getIsdbs3FrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/Isdbs3FrontendSettings"); + uint16_t streamId = + static_cast<uint16_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mStreamId", "I"))); + FrontendIsdbsStreamIdType streamIdType = + static_cast<FrontendIsdbsStreamIdType>( + env->GetIntField(settings, env->GetFieldID(clazz, "mStreamIdType", "I"))); + FrontendIsdbs3Modulation modulation = + static_cast<FrontendIsdbs3Modulation>( + env->GetIntField(settings, env->GetFieldID(clazz, "mModulation", "I"))); + FrontendIsdbs3Coderate coderate = + static_cast<FrontendIsdbs3Coderate>( + env->GetIntField(settings, env->GetFieldID(clazz, "mCodeRate", "I"))); + uint32_t symbolRate = + static_cast<uint32_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mSymbolRate", "I"))); + FrontendIsdbs3Rolloff rolloff = + static_cast<FrontendIsdbs3Rolloff>( + env->GetIntField(settings, env->GetFieldID(clazz, "mRolloff", "I"))); + + FrontendIsdbs3Settings frontendIsdbs3Settings { + .frequency = freq, + .streamId = streamId, + .streamIdType = streamIdType, + .modulation = modulation, + .coderate = coderate, + .symbolRate = symbolRate, + .rolloff = rolloff, + }; + frontendSettings.isdbs3(frontendIsdbs3Settings); + return frontendSettings; +} + +static FrontendSettings getIsdbtFrontendSettings(JNIEnv *env, const jobject& settings) { + FrontendSettings frontendSettings; + uint32_t freq = getFrontendSettingsFreq(env, settings); + jclass clazz = env->FindClass("android/media/tv/tuner/frontend/IsdbtFrontendSettings"); + FrontendIsdbtModulation modulation = + static_cast<FrontendIsdbtModulation>( + env->GetIntField(settings, env->GetFieldID(clazz, "mModulation", "I"))); + FrontendIsdbtBandwidth bandwidth = + static_cast<FrontendIsdbtBandwidth>( + env->GetIntField(settings, env->GetFieldID(clazz, "mBandwidth", "I"))); + FrontendIsdbtMode mode = + static_cast<FrontendIsdbtMode>( + env->GetIntField(settings, env->GetFieldID(clazz, "mMode", "I"))); + FrontendIsdbtCoderate coderate = + static_cast<FrontendIsdbtCoderate>( + env->GetIntField(settings, env->GetFieldID(clazz, "mCodeRate", "I"))); + FrontendIsdbtGuardInterval guardInterval = + static_cast<FrontendIsdbtGuardInterval>( + env->GetIntField(settings, env->GetFieldID(clazz, "mGuardInterval", "I"))); + uint32_t serviceAreaId = + static_cast<uint32_t>( + env->GetIntField(settings, env->GetFieldID(clazz, "mServiceAreaId", "I"))); + + FrontendIsdbtSettings frontendIsdbtSettings { + .frequency = freq, + .modulation = modulation, + .bandwidth = bandwidth, + .mode = mode, + .coderate = coderate, + .guardInterval = guardInterval, + .serviceAreaId = serviceAreaId, + }; + frontendSettings.isdbt(frontendIsdbtSettings); + return frontendSettings; +} + +static FrontendSettings getFrontendSettings(JNIEnv *env, int type, jobject settings) { + ALOGD("getFrontendSettings %d", type); + + FrontendType feType = static_cast<FrontendType>(type); + switch(feType) { + case FrontendType::ANALOG: + return getAnalogFrontendSettings(env, settings); + case FrontendType::ATSC3: + return getAtsc3FrontendSettings(env, settings); + case FrontendType::ATSC: + return getAtscFrontendSettings(env, settings); + case FrontendType::DVBC: + return getDvbcFrontendSettings(env, settings); + case FrontendType::DVBS: + return getDvbsFrontendSettings(env, settings); + case FrontendType::DVBT: + return getDvbtFrontendSettings(env, settings); + case FrontendType::ISDBS: + return getIsdbsFrontendSettings(env, settings); + case FrontendType::ISDBS3: + return getIsdbs3FrontendSettings(env, settings); + case FrontendType::ISDBT: + return getIsdbtFrontendSettings(env, settings); + default: + // should never happen because a type is associated with a subclass of + // FrontendSettings and not set by users + jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", + "Unsupported frontend type %d", type); + return FrontendSettings(); + } +} + static sp<Filter> getFilter(JNIEnv *env, jobject filter) { return (Filter *)env->GetLongField(filter, gFields.filterContext); } @@ -587,23 +1040,23 @@ static void android_media_tv_Tuner_native_init(JNIEnv *env) { jclass lnbClazz = env->FindClass("android/media/tv/tuner/Lnb"); gFields.lnbInitID = - env->GetMethodID(lnbClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;I)V"); + env->GetMethodID(lnbClazz, "<init>", "(I)V"); jclass filterClazz = env->FindClass("android/media/tv/tuner/filter/Filter"); gFields.filterContext = env->GetFieldID(filterClazz, "mNativeContext", "J"); gFields.filterInitID = - env->GetMethodID(filterClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;I)V"); + env->GetMethodID(filterClazz, "<init>", "(I)V"); gFields.onFilterStatusID = env->GetMethodID(filterClazz, "onFilterStatus", "(I)V"); jclass descramblerClazz = env->FindClass("android/media/tv/tuner/Descrambler"); gFields.descramblerContext = env->GetFieldID(descramblerClazz, "mNativeContext", "J"); gFields.descramblerInitID = - env->GetMethodID(descramblerClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;)V"); + env->GetMethodID(descramblerClazz, "<init>", "()V"); jclass dvrClazz = env->FindClass("android/media/tv/tuner/dvr/Dvr"); gFields.dvrContext = env->GetFieldID(dvrClazz, "mNativeContext", "J"); - gFields.dvrInitID = env->GetMethodID(dvrClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;)V"); + gFields.dvrInitID = env->GetMethodID(dvrClazz, "<init>", "()V"); } static void android_media_tv_Tuner_native_setup(JNIEnv *env, jobject thiz) { @@ -1141,16 +1594,16 @@ static const JNINativeMethod gTunerMethods[] = { { "nativeSetLna", "(Z)I", (void *)android_media_tv_Tuner_set_lna }, { "nativeGetFrontendStatus", "([I)Landroid/media/tv/tuner/frontend/FrontendStatus;", (void *)android_media_tv_Tuner_get_frontend_status }, - { "nativeGetAvSyncHwId", "(Landroid/media/tv/tuner/Tuner/filter/Filter;)I", + { "nativeGetAvSyncHwId", "(Landroid/media/tv/tuner/filter/Filter;)I", (void *)android_media_tv_Tuner_gat_av_sync_hw_id }, { "nativeGetAvSyncTime", "(I)J", (void *)android_media_tv_Tuner_gat_av_sync_time }, { "nativeConnectCiCam", "(I)I", (void *)android_media_tv_Tuner_connect_cicam }, { "nativeDisconnectCiCam", "()I", (void *)android_media_tv_Tuner_disconnect_cicam }, - { "nativeGetFrontendInfo", "(I)Landroid/media/tv/tuner/FrontendInfo;", + { "nativeGetFrontendInfo", "(I)Landroid/media/tv/tuner/frontend/FrontendInfo;", (void *)android_media_tv_Tuner_get_frontend_info }, - { "nativeOpenFilter", "(IIJ)Landroid/media/tv/tuner/Tuner/filter/Filter;", + { "nativeOpenFilter", "(IIJ)Landroid/media/tv/tuner/filter/Filter;", (void *)android_media_tv_Tuner_open_filter }, - { "nativeOpenTimeFilter", "()Landroid/media/tv/tuner/Tuner/filter/TimeFilter;", + { "nativeOpenTimeFilter", "()Landroid/media/tv/tuner/filter/TimeFilter;", (void *)android_media_tv_Tuner_open_time_filter }, { "nativeGetLnbIds", "()Ljava/util/List;", (void *)android_media_tv_Tuner_get_lnb_ids }, @@ -1180,9 +1633,9 @@ static const JNINativeMethod gFilterMethods[] = { }; static const JNINativeMethod gTimeFilterMethods[] = { - { "nativeSetTimeStamp", "(J)I", (void *)android_media_tv_Tuner_time_filter_set_timestamp }, - { "nativeClearTimeStamp", "()I", (void *)android_media_tv_Tuner_time_filter_clear_timestamp }, - { "nativeGetTimeStamp", "()Ljava/lang/Long;", + { "nativeSetTimestamp", "(J)I", (void *)android_media_tv_Tuner_time_filter_set_timestamp }, + { "nativeClearTimestamp", "()I", (void *)android_media_tv_Tuner_time_filter_clear_timestamp }, + { "nativeGetTimestamp", "()Ljava/lang/Long;", (void *)android_media_tv_Tuner_time_filter_get_timestamp }, { "nativeGetSourceTime", "()Ljava/lang/Long;", (void *)android_media_tv_Tuner_time_filter_get_source_time }, diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java index 61e1adf2301c..7b495ce19015 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -664,7 +664,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub */ @Override public void registerSystemAction(RemoteAction action, int actionId) { - mSecurityPolicy.enforceCallingPermission(Manifest.permission.MANAGE_ACCESSIBILITY, + mSecurityPolicy.enforceCallerIsRecentsOrHasPermission( + Manifest.permission.MANAGE_ACCESSIBILITY, FUNCTION_REGISTER_SYSTEM_ACTION); mSystemActionPerformer.registerSystemAction(actionId, action); } @@ -676,7 +677,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub */ @Override public void unregisterSystemAction(int actionId) { - mSecurityPolicy.enforceCallingPermission(Manifest.permission.MANAGE_ACCESSIBILITY, + mSecurityPolicy.enforceCallerIsRecentsOrHasPermission( + Manifest.permission.MANAGE_ACCESSIBILITY, FUNCTION_UNREGISTER_SYSTEM_ACTION); mSystemActionPerformer.unregisterSystemAction(actionId); } diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilitySecurityPolicy.java b/services/accessibility/java/com/android/server/accessibility/AccessibilitySecurityPolicy.java index 7a42cd1b3cbb..96e345ea9b89 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilitySecurityPolicy.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilitySecurityPolicy.java @@ -38,6 +38,8 @@ import android.util.Slog; import android.view.accessibility.AccessibilityEvent; import com.android.internal.util.ArrayUtils; +import com.android.server.LocalServices; +import com.android.server.wm.ActivityTaskManagerInternal; import libcore.util.EmptyArray; @@ -86,6 +88,7 @@ public class AccessibilitySecurityPolicy { private final AccessibilityUserManager mAccessibilityUserManager; private AccessibilityWindowManager mAccessibilityWindowManager; + private final ActivityTaskManagerInternal mAtmInternal; /** * Constructor for AccessibilityManagerService. @@ -97,6 +100,7 @@ public class AccessibilitySecurityPolicy { mPackageManager = mContext.getPackageManager(); mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); + mAtmInternal = LocalServices.getService(ActivityTaskManagerInternal.class); } /** @@ -563,4 +567,13 @@ public class AccessibilitySecurityPolicy { + permission); } } + + /** + * Enforcing permission check to IPC caller or grant it if it's recents. + * + * @param permission The permission to check + */ + public void enforceCallerIsRecentsOrHasPermission(@NonNull String permission, String func) { + mAtmInternal.enforceCallerIsRecentsOrHasPermission(permission, func); + } } diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 68574f5fbc2c..36dd017d2c23 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -298,6 +298,12 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL | PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS; + static final int READ_PRIVILEGED_PHONE_STATE_PERMISSION_MASK = + PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT + | PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED + | PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED + | PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE; + private static final int MSG_USER_SWITCHED = 1; private static final int MSG_UPDATE_DEFAULT_SUB = 2; @@ -2536,27 +2542,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); } - if ((events & PhoneStateListener.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, null); - } - - if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); - } - - if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); - } - - if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); - } - - if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) { + if ((events & READ_PRIVILEGED_PHONE_STATE_PERMISSION_MASK) != 0) { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); } diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java index 0274aee0a168..c37ceb3bc1b0 100644 --- a/services/core/java/com/android/server/pm/ShortcutPackage.java +++ b/services/core/java/com/android/server/pm/ShortcutPackage.java @@ -310,7 +310,7 @@ class ShortcutPackage extends ShortcutPackageItem { } /** - * Remove all shortcuts that aren't pinned nor dynamic. + * Remove all shortcuts that aren't pinned, cached nor dynamic. */ private void removeOrphans() { ArrayList<String> removeList = null; // Lazily initialize. @@ -356,10 +356,10 @@ class ShortcutPackage extends ShortcutPackageItem { /** * Remove a dynamic shortcut by ID. It'll be removed from the dynamic set, but if the shortcut - * is pinned, it'll remain as a pinned shortcut, and is still enabled. + * is pinned or cached, it'll remain as a pinned or cached shortcut, and is still enabled. * - * @return true if it's actually removed because it wasn't pinned, or false if it's still - * pinned. + * @return true if it's removed, or false if it was not actually removed because it is either + * pinned or cached. */ public boolean deleteDynamicWithId(@NonNull String shortcutId, boolean ignoreInvisible) { final ShortcutInfo removed = deleteOrDisableWithId( @@ -384,6 +384,24 @@ class ShortcutPackage extends ShortcutPackageItem { } /** + * Remove a long lived shortcut by ID. If the shortcut is pinned, it'll remain as a pinned + * shortcut, and is still enabled. + * + * @return true if it's actually removed because it wasn't pinned, or false if it's still + * pinned. + */ + public boolean deleteLongLivedWithId(@NonNull String shortcutId, boolean ignoreInvisible) { + final ShortcutInfo shortcut = mShortcuts.get(shortcutId); + if (shortcut != null) { + shortcut.clearFlags(ShortcutInfo.FLAG_CACHED); + } + final ShortcutInfo removed = deleteOrDisableWithId( + shortcutId, /* disable =*/ false, /* overrideImmutable=*/ false, ignoreInvisible, + ShortcutInfo.DISABLED_REASON_NOT_DISABLED); + return removed == null; + } + + /** * Disable a dynamic shortcut by ID. It'll be removed from the dynamic set, but if the shortcut * is pinned, it'll remain as a pinned shortcut but will be disabled. */ @@ -419,7 +437,7 @@ class ShortcutPackage extends ShortcutPackageItem { if (!overrideImmutable) { ensureNotImmutable(oldShortcut, /*ignoreInvisible=*/ true); } - if (oldShortcut.isPinned()) { + if (oldShortcut.isPinned() || oldShortcut.isCached()) { oldShortcut.setRank(0); oldShortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_MANIFEST); @@ -500,7 +518,7 @@ class ShortcutPackage extends ShortcutPackageItem { } }); - // Lastly, remove the ones that are no longer pinned nor dynamic. + // Lastly, remove the ones that are no longer pinned, cached nor dynamic. removeOrphans(); } @@ -1328,6 +1346,10 @@ class ShortcutPackage extends ShortcutPackageItem { // Don't adjust ranks for manifest shortcuts. continue; } + if (si.isCached() && !si.isDynamic()) { + // Don't adjust ranks for cached shortcuts that are not dynamic anymore. + continue; + } // At this point, it must be dynamic. if (!si.isDynamic()) { s.wtf("Non-dynamic shortcut found."); @@ -1869,7 +1891,7 @@ class ShortcutPackage extends ShortcutPackageItem { // Verify each shortcut's status. for (int i = mShortcuts.size() - 1; i >= 0; i--) { final ShortcutInfo si = mShortcuts.valueAt(i); - if (!(si.isDeclaredInManifest() || si.isDynamic() || si.isPinned())) { + if (!(si.isDeclaredInManifest() || si.isDynamic() || si.isPinned() || si.isCached())) { failed = true; Log.e(TAG_VERIFY, "Package " + getPackageName() + ": shortcut " + si.getId() + " is not manifest, dynamic or pinned."); diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java index 261418ce7586..f368666a06ba 100644 --- a/services/core/java/com/android/server/pm/ShortcutService.java +++ b/services/core/java/com/android/server/pm/ShortcutService.java @@ -2123,6 +2123,33 @@ public class ShortcutService extends IShortcutService.Stub { } @Override + public void removeLongLivedShortcuts(String packageName, List shortcutIds, + @UserIdInt int userId) { + verifyCaller(packageName, userId); + Objects.requireNonNull(shortcutIds, "shortcutIds must be provided"); + + synchronized (mLock) { + throwIfUserLockedL(userId); + + final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); + + ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds, + /*ignoreInvisible=*/ true); + + for (int i = shortcutIds.size() - 1; i >= 0; i--) { + final String id = Preconditions.checkStringNotEmpty((String) shortcutIds.get(i)); + ps.deleteLongLivedWithId(id, /*ignoreInvisible=*/ true); + } + + // We may have removed dynamic shortcuts which may have left a gap, so adjust the ranks. + ps.adjustRanks(); + } + packageShortcutsChanged(packageName, userId); + + verifyStates(); + } + + @Override public ParceledListSlice<ShortcutInfo> getDynamicShortcuts(String packageName, @UserIdInt int userId) { verifyCaller(packageName, userId); @@ -2165,6 +2192,31 @@ public class ShortcutService extends IShortcutService.Stub { } @Override + public ParceledListSlice<ShortcutInfo> getShortcuts(String packageName, + @ShortcutManager.ShortcutMatchFlags int matchFlags, @UserIdInt int userId) { + verifyCaller(packageName, userId); + + synchronized (mLock) { + throwIfUserLockedL(userId); + + final boolean matchDynamic = (matchFlags & ShortcutManager.FLAG_MATCH_DYNAMIC) != 0; + final boolean matchPinned = (matchFlags & ShortcutManager.FLAG_MATCH_PINNED) != 0; + final boolean matchManifest = (matchFlags & ShortcutManager.FLAG_MATCH_MANIFEST) != 0; + final boolean matchCached = (matchFlags & ShortcutManager.FLAG_MATCH_CACHED) != 0; + + final int shortcutFlags = (matchDynamic ? ShortcutInfo.FLAG_DYNAMIC : 0) + | (matchPinned ? ShortcutInfo.FLAG_PINNED : 0) + | (matchManifest ? ShortcutInfo.FLAG_MANIFEST : 0) + | (matchCached ? ShortcutInfo.FLAG_CACHED : 0); + + return getShortcutsWithQueryLocked( + packageName, userId, ShortcutInfo.CLONE_REMOVE_FOR_CREATOR, + (ShortcutInfo si) -> + si.isVisibleToPublisher() && (si.getFlags() & shortcutFlags) != 0); + } + } + + @Override public ParceledListSlice<ShortcutManager.ShareShortcutInfo> getShareTargets(String packageName, IntentFilter filter, @UserIdInt int userId) { verifyCaller(packageName, userId); @@ -2628,6 +2680,7 @@ public class ShortcutService extends IShortcutService.Stub { final boolean matchDynamic = (queryFlags & ShortcutQuery.FLAG_MATCH_DYNAMIC) != 0; final boolean matchPinned = (queryFlags & ShortcutQuery.FLAG_MATCH_PINNED) != 0; final boolean matchManifest = (queryFlags & ShortcutQuery.FLAG_MATCH_MANIFEST) != 0; + final boolean matchCached = (queryFlags & ShortcutQuery.FLAG_MATCH_CACHED) != 0; final boolean canAccessAllShortcuts = canSeeAnyPinnedShortcut(callingPackage, launcherUserId, callingPid, callingUid); @@ -2659,6 +2712,9 @@ public class ShortcutService extends IShortcutService.Stub { if (matchManifest && si.isDeclaredInManifest()) { return true; } + if (matchCached && si.isCached()) { + return true; + } return false; }, cloneFlag, callingPackage, launcherUserId, getPinnedByAnyLauncher); } diff --git a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java index 2700f9ddc203..b136ec754f59 100644 --- a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java +++ b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java @@ -425,6 +425,7 @@ public class DeviceStorageMonitorService extends SystemService { void dumpImpl(FileDescriptor fd, PrintWriter _pw, String[] args) { final IndentingPrintWriter pw = new IndentingPrintWriter(_pw, " "); if (args == null || args.length == 0 || "-a".equals(args[0])) { + final StorageManager storage = getContext().getSystemService(StorageManager.class); pw.println("Known volumes:"); pw.increaseIndent(); for (int i = 0; i < mStates.size(); i++) { @@ -439,6 +440,19 @@ public class DeviceStorageMonitorService extends SystemService { pw.printPair("level", State.levelToString(state.level)); pw.printPair("lastUsableBytes", state.lastUsableBytes); pw.println(); + for (VolumeInfo vol : storage.getWritablePrivateVolumes()) { + final File file = vol.getPath(); + final UUID innerUuid = StorageManager.convert(vol.getFsUuid()); + if (Objects.equals(uuid, innerUuid)) { + pw.print("lowBytes="); + pw.print(storage.getStorageLowBytes(file)); + pw.print(" fullBytes="); + pw.println(storage.getStorageFullBytes(file)); + pw.print("path="); + pw.println(file); + break; + } + } pw.decreaseIndent(); } pw.decreaseIndent(); diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index f8f286ace9dd..dda11f96cc8a 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -1875,9 +1875,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } else if (newTask || !processRunning || (taskSwitch && !activityCreated)) { return STARTING_WINDOW_TYPE_SPLASH_SCREEN; } else if (taskSwitch && allowTaskSnapshot) { - return snapshot == null ? STARTING_WINDOW_TYPE_NONE - : snapshotOrientationSameAsTask(snapshot) || fromRecents - ? STARTING_WINDOW_TYPE_SNAPSHOT : STARTING_WINDOW_TYPE_SPLASH_SCREEN; + if (snapshotOrientationSameAsTask(snapshot) || (snapshot != null && fromRecents)) { + return STARTING_WINDOW_TYPE_SNAPSHOT; + } + if (!isActivityTypeHome()) { + return STARTING_WINDOW_TYPE_SPLASH_SCREEN; + } + return STARTING_WINDOW_TYPE_NONE; } else { return STARTING_WINDOW_TYPE_NONE; } diff --git a/services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java index ec928fb278be..9a7d6ea52d98 100644 --- a/services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/accessibility/AccessibilityManagerServiceTest.java @@ -145,9 +145,10 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @SmallTest public void testRegisterSystemActionWithoutPermission() throws Exception { - doThrow(SecurityException.class).when(mMockSecurityPolicy).enforceCallingPermission( - Manifest.permission.MANAGE_ACCESSIBILITY, - AccessibilityManagerService.FUNCTION_REGISTER_SYSTEM_ACTION); + doThrow(SecurityException.class).when(mMockSecurityPolicy) + .enforceCallerIsRecentsOrHasPermission( + Manifest.permission.MANAGE_ACCESSIBILITY, + AccessibilityManagerService.FUNCTION_REGISTER_SYSTEM_ACTION); try { mA11yms.registerSystemAction(TEST_ACTION, ACTION_ID); @@ -165,9 +166,10 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase { @SmallTest public void testUnregisterSystemActionWithoutPermission() throws Exception { - doThrow(SecurityException.class).when(mMockSecurityPolicy).enforceCallingPermission( - Manifest.permission.MANAGE_ACCESSIBILITY, - AccessibilityManagerService.FUNCTION_UNREGISTER_SYSTEM_ACTION); + doThrow(SecurityException.class).when(mMockSecurityPolicy) + .enforceCallerIsRecentsOrHasPermission( + Manifest.permission.MANAGE_ACCESSIBILITY, + AccessibilityManagerService.FUNCTION_UNREGISTER_SYSTEM_ACTION); try { mA11yms.unregisterSystemAction(ACTION_ID); diff --git a/services/tests/servicestests/src/com/android/server/accessibility/AccessibilitySecurityPolicyTest.java b/services/tests/servicestests/src/com/android/server/accessibility/AccessibilitySecurityPolicyTest.java index 150409766f47..fbb55fdeeb8f 100644 --- a/services/tests/servicestests/src/com/android/server/accessibility/AccessibilitySecurityPolicyTest.java +++ b/services/tests/servicestests/src/com/android/server/accessibility/AccessibilitySecurityPolicyTest.java @@ -47,6 +47,9 @@ import android.util.ArraySet; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityWindowInfo; +import com.android.server.LocalServices; +import com.android.server.wm.ActivityTaskManagerInternal; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -67,6 +70,9 @@ public class AccessibilitySecurityPolicyTest { private static final int WINDOWID2 = 0x000b; private static final int APP_UID = 10400; + private static final String PERMISSION = "test-permission"; + private static final String FUNCTION = "test-function-name"; + private static final int[] ALWAYS_DISPATCH_EVENTS = { AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED, @@ -111,6 +117,7 @@ public class AccessibilitySecurityPolicyTest { @Mock private AccessibilityWindowManager mMockA11yWindowManager; @Mock private AppWidgetManagerInternal mMockAppWidgetManager; @Mock private AccessibilitySecurityPolicy.AccessibilityUserManager mMockA11yUserManager; + @Mock private ActivityTaskManagerInternal mMockActivityTaskManagerInternal; @Before public void setUp() { @@ -119,6 +126,10 @@ public class AccessibilitySecurityPolicyTest { when(mMockContext.getSystemService(Context.USER_SERVICE)).thenReturn(mMockUserManager); when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mMockAppOpsManager); + LocalServices.removeServiceForTest(ActivityTaskManagerInternal.class); + LocalServices.addService( + ActivityTaskManagerInternal.class, mMockActivityTaskManagerInternal); + mA11ySecurityPolicy = new AccessibilitySecurityPolicy(mMockContext, mMockA11yUserManager); mA11ySecurityPolicy.setAccessibilityWindowManager(mMockA11yWindowManager); mA11ySecurityPolicy.setAppWidgetManager(mMockAppWidgetManager); @@ -469,4 +480,11 @@ public class AccessibilitySecurityPolicyTest { verify(mMockAppOpsManager).noteOpNoThrow(AppOpsManager.OPSTR_ACCESS_ACCESSIBILITY, APP_UID, PACKAGE_NAME); } + + @Test + public void testEnforceCallerIsRecentsOrHasPermission() { + mA11ySecurityPolicy.enforceCallerIsRecentsOrHasPermission(PERMISSION, FUNCTION); + verify(mMockActivityTaskManagerInternal).enforceCallerIsRecentsOrHasPermission( + PERMISSION, FUNCTION); + } } diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java index 6c917b7f8636..798420ee0137 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java @@ -82,6 +82,7 @@ import android.content.pm.LauncherApps.PinItemRequest; import android.content.pm.LauncherApps.ShortcutQuery; import android.content.pm.PackageInfo; import android.content.pm.ShortcutInfo; +import android.content.pm.ShortcutManager; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; @@ -1227,6 +1228,142 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { }); } + public void testShortcutManagerGetShortcuts_shortcutTypes() { + + // Create 3 manifest and 3 dynamic shortcuts + addManifestShortcutResource( + new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), + R.xml.shortcut_3); + updatePackageVersion(CALLING_PACKAGE_1, 1); + mService.mPackageMonitor.onReceive(getTestContext(), + genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); + + runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { + assertTrue(mManager.setDynamicShortcuts(list( + makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3")))); + }); + + // Pin 2 and 3 + runWithCaller(LAUNCHER_1, USER_0, () -> { + mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms2", "ms3", "s2", "s3"), + HANDLE_USER_0); + }); + + // Cache 1 and 2 + setCaller(CALLING_PACKAGE_1); + getCallerShortcut("s1").setCached(); + getCallerShortcut("s2").setCached(); + + // Get manifest shortcuts + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_MANIFEST), + "ms1", "ms2", "ms3"); + + // Get dynamic shortcuts + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), + "s1", "s2", "s3"); + + // Get pinned shortcuts + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED), + "ms2", "ms3", "s2", "s3"); + + // Get cached shortcuts + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), + "s1", "s2"); + + // Get manifest and dynamic shortcuts + assertShortcutIds(mManager.getShortcuts( + ShortcutManager.FLAG_MATCH_MANIFEST | ShortcutManager.FLAG_MATCH_DYNAMIC), + "ms1", "ms2", "ms3", "s1", "s2", "s3"); + + // Get manifest and pinned shortcuts + assertShortcutIds(mManager.getShortcuts( + ShortcutManager.FLAG_MATCH_MANIFEST | ShortcutManager.FLAG_MATCH_PINNED), + "ms1", "ms2", "ms3", "s2", "s3"); + + // Get manifest and cached shortcuts + assertShortcutIds(mManager.getShortcuts( + ShortcutManager.FLAG_MATCH_MANIFEST | ShortcutManager.FLAG_MATCH_CACHED), + "ms1", "ms2", "ms3", "s1", "s2"); + + // Get dynamic and pinned shortcuts + assertShortcutIds(mManager.getShortcuts( + ShortcutManager.FLAG_MATCH_DYNAMIC | ShortcutManager.FLAG_MATCH_PINNED), + "ms2", "ms3", "s1", "s2", "s3"); + + // Get dynamic and cached shortcuts + assertShortcutIds(mManager.getShortcuts( + ShortcutManager.FLAG_MATCH_DYNAMIC | ShortcutManager.FLAG_MATCH_CACHED), + "s1", "s2", "s3"); + + // Get pinned and cached shortcuts + assertShortcutIds(mManager.getShortcuts( + ShortcutManager.FLAG_MATCH_PINNED | ShortcutManager.FLAG_MATCH_CACHED), + "ms2", "ms3", "s1", "s2", "s3"); + + // Remove a dynamic cached shortcut + mManager.removeDynamicShortcuts(list("s1")); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), "s2", "s3"); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), "s1", "s2"); + + // Remove a dynamic cached and pinned shortcut + mManager.removeDynamicShortcuts(list("s2")); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), "s3"); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED), + "ms2", "ms3", "s2", "s3"); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), "s1", "s2"); + } + + public void testCachedShortcuts() { + runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { + assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1"), makeShortcut("s2"), + makeShortcut("s3"), makeShortcut("s4")))); + }); + + // Pin s2 + runWithCaller(LAUNCHER_1, USER_0, () -> { + mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2"), + HANDLE_USER_0); + }); + + // Cache 2, 3 and 4 + setCaller(CALLING_PACKAGE_1); + getCallerShortcut("s2").setCached(); + getCallerShortcut("s3").setCached(); + getCallerShortcut("s4").setCached(); + + // Get dynamic shortcuts + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), + "s1", "s2", "s3", "s4"); + // Get pinned shortcuts + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED), + "s2"); + // Get cached shortcuts + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), + "s2", "s3", "s4"); + + // Remove a dynamic cached shortcut + mManager.removeDynamicShortcuts(list("s3")); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), + "s1", "s2", "s4"); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), + "s2", "s3", "s4"); + + // Remove dynamic cached long lived shortcuts + mManager.removeLongLivedShortcuts(list("s3", "s4")); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), + "s1", "s2"); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED), + "s2"); + + // Remove a dynamic cached pinned long lived shortcut + mManager.removeLongLivedShortcuts(list("s2")); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_DYNAMIC), + "s1"); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED)); + assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_PINNED), + "s2"); + } + // === Test for launcher side APIs === public void testGetShortcuts() { @@ -1366,6 +1503,54 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { }); // TODO More tests: pinned but dynamic. + + // Cache some shortcuts + setCaller(CALLING_PACKAGE_1); + getCallerShortcut("s1").setCached(); + + setCaller(CALLING_PACKAGE_2); + getCallerShortcut("s4").setCached(); + + setCaller(CALLING_PACKAGE_3); + getCallerShortcut("s3").setCached(); + + setCaller(LAUNCHER_1); + + // Cached ones only + assertShortcutIds(assertAllNotKeyFieldsOnly( + mLauncherApps.getShortcuts(buildQuery( + /* time =*/ 0, CALLING_PACKAGE_2, + /* activity =*/ null, + ShortcutQuery.FLAG_MATCH_CACHED), + getCallingUser())), + "s4"); + + // All packages. + assertShortcutIds(assertAllNotKeyFieldsOnly( + mLauncherApps.getShortcuts(buildQuery( + /* time =*/ 0, /* package= */ null, + /* activity =*/ null, + ShortcutQuery.FLAG_MATCH_CACHED), + getCallingUser())), + "s1", "s4", "s3"); + + assertExpectException( + IllegalArgumentException.class, "package name must also be set", () -> { + mLauncherApps.getShortcuts(buildQuery( + /* time =*/ 0, /* package= */ null, list("id"), + /* activity =*/ null, /* flags */ 0), getCallingUser()); + }); + + // Change Launcher. Cached shortcuts are the same for all launchers. + setCaller(LAUNCHER_2); + // All packages. + assertShortcutIds(assertAllNotKeyFieldsOnly( + mLauncherApps.getShortcuts(buildQuery( + /* time =*/ 0, /* package= */ null, + /* activity =*/ null, + ShortcutQuery.FLAG_MATCH_CACHED), + getCallingUser())), + "s1", "s4", "s3"); } public void testGetShortcuts_shortcutKinds() throws Exception { diff --git a/startop/iorap/functional_tests/Android.bp b/startop/iorap/functional_tests/Android.bp new file mode 100644 index 000000000000..ce9dc325c76d --- /dev/null +++ b/startop/iorap/functional_tests/Android.bp @@ -0,0 +1,41 @@ +// 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. + +android_test { + name: "iorap-functional-tests", + srcs: ["src/**/*.java"], + static_libs: [ + // Non-test dependencies + // library under test + "services.startop.iorap", + // Test Dependencies + // test android dependencies + "platform-test-annotations", + "androidx.test.rules", + "androidx.test.ext.junit", + "androidx.test.uiautomator_uiautomator", + // test framework dependencies + "truth-prebuilt", + ], + dxflags: ["--multi-dex"], + test_suites: ["device-tests"], + compile_multilib: "both", + libs: [ + "android.test.base", + "android.test.runner", + ], + certificate: "platform", + platform_apis: true, +} + diff --git a/startop/iorap/functional_tests/AndroidManifest.xml b/startop/iorap/functional_tests/AndroidManifest.xml new file mode 100644 index 000000000000..6bddc4a39577 --- /dev/null +++ b/startop/iorap/functional_tests/AndroidManifest.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> +<!--suppress AndroidUnknownAttribute --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.google.android.startop.iorap.tests" + android:sharedUserId="com.google.android.startop.iorap.tests.functional" + android:versionCode="1" + android:versionName="1.0" > + + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + <!--suppress AndroidDomInspection --> + <instrumentation + android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="com.google.android.startop.iorap.tests" /> + + <!-- + 'debuggable=true' is required to properly load mockito jvmti dependencies, + otherwise it gives the following error at runtime: + + Openjdkjvmti plugin was loaded on a non-debuggable Runtime. + Plugin was loaded too late to change runtime state to DEBUGGABLE. --> + <application android:debuggable="true"> + <uses-library android:name="android.test.runner" /> + </application> +</manifest> diff --git a/startop/iorap/functional_tests/AndroidTest.xml b/startop/iorap/functional_tests/AndroidTest.xml new file mode 100644 index 000000000000..41109b43ab82 --- /dev/null +++ b/startop/iorap/functional_tests/AndroidTest.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<configuration description="Runs iorap-functional-tests."> + <option name="test-suite-tag" value="apct" /> + <option name="test-suite-tag" value="apct-instrumentation" /> + <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller"> + <option name="cleanup-apks" value="true" /> + <option name="test-file-name" value="iorap-functional-tests.apk" /> + </target_preparer> + + <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/> + + <target_preparer + class="com.android.tradefed.targetprep.DeviceSetup"> + + <!-- iorapd does not pick up the above changes until we restart it --> + <option name="run-command" value="stop iorapd" /> + + <!-- Clean up the existing iorap database. --> + <option name="run-command" value="rm -r /data/misc/iorapd/*" /> + <option name="run-command" value="sleep 1" /> + + <option name="run-command" value="start iorapd" /> + + <!-- give it some time to restart the service; otherwise the first unit test might fail --> + <option name="run-command" value="sleep 1" /> + </target_preparer> + + <test class="com.android.tradefed.testtype.AndroidJUnitTest" > + <option name="package" value="com.google.android.startop.iorap.tests" /> + <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> + </test> + + <!-- using DeviceSetup again does not work. we simply leave the device in a semi-bad + state. there is no way to clean this up as far as I know. + --> + +</configuration> + diff --git a/startop/iorap/functional_tests/src/com/google/android/startop/iorap/IorapWorkFlowTest.java b/startop/iorap/functional_tests/src/com/google/android/startop/iorap/IorapWorkFlowTest.java new file mode 100644 index 000000000000..bd8a45c2ca00 --- /dev/null +++ b/startop/iorap/functional_tests/src/com/google/android/startop/iorap/IorapWorkFlowTest.java @@ -0,0 +1,377 @@ +/* + * 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. + */ + +package com.google.android.startop.iorapd; + +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.database.DatabaseUtils; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +import androidx.test.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.File; +import java.time.Duration; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; +import java.util.function.BooleanSupplier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.List; + + +/** + * Test for the work flow of iorap. + * + * <p> This test tests the function of iorap from perfetto collection -> compilation -> + * prefetching. + * </p> + */ +@RunWith(AndroidJUnit4.class) +public class IorapWorkFlowTest { + + private static final String TAG = "IorapWorkFlowTest"; + + private static final String TEST_PACKAGE_NAME = "com.android.settings"; + private static final String TEST_ACTIVITY_NAME = "com.android.settings.Settings"; + + private static final String DB_PATH = "/data/misc/iorapd/sqlite.db"; + private static final Duration TIMEOUT = Duration.ofSeconds(20L); + + private static final String READAHEAD_INDICATOR = + "Description = /data/misc/iorapd/com.android.settings/none/com.android.settings.Settings/compiled_traces/compiled_trace.pb"; + + private UiDevice mDevice; + + @Before + public void startMainActivityFromHomeScreen() throws Exception { + // Initialize UiDevice instance + mDevice = UiDevice.getInstance(getInstrumentation()); + + // Start from the home screen + mDevice.pressHome(); + + // Wait for launcher + final String launcherPackage = mDevice.getLauncherPackageName(); + assertThat(launcherPackage, notNullValue()); + mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), TIMEOUT.getSeconds()); + } + + @Test + public void testApp() throws Exception { + assertThat(mDevice, notNullValue()); + + // Perfetto trace collection phase. + assertTrue(startAppForPerfettoTrace(/*expectPerfettoTraceCount=*/1)); + assertTrue(startAppForPerfettoTrace(/*expectPerfettoTraceCount=*/2)); + assertTrue(startAppForPerfettoTrace(/*expectPerfettoTraceCount=*/3)); + assertTrue(checkPerfettoTracesExistence(TIMEOUT, 3)); + + // Trigger maintenance service for compilation. + assertTrue(compile(TIMEOUT)); + + // Check if prefetching works. + assertTrue(waitForPrefetchingFromLogcat(/*expectPerfettoTraceCount=*/3)); + } + + /** + * Starts the testing app to collect the perfetto trace. + * + * @param expectPerfettoTraceCount is the expected count of perfetto traces. + */ + private boolean startAppForPerfettoTrace(long expectPerfettoTraceCount) + throws Exception { + // Close the specified app if it's open + closeApp(); + // Launch the specified app + startApp(); + // Wait for the app to appear + mDevice.wait(Until.hasObject(By.pkg(TEST_PACKAGE_NAME).depth(0)), TIMEOUT.getSeconds()); + + String sql = "SELECT COUNT(*) FROM activities " + + "JOIN app_launch_histories ON activities.id = app_launch_histories.activity_id " + + "JOIN raw_traces ON raw_traces.history_id = app_launch_histories.id " + + "WHERE activities.name = ?"; + return checkAndWaitEntriesNum(sql, new String[]{TEST_ACTIVITY_NAME}, expectPerfettoTraceCount, + TIMEOUT); + } + + // Invokes the maintenance to compile the perfetto traces to compiled trace. + private boolean compile(Duration timeout) throws Exception { + // The job id (283673059) is defined in class IorapForwardingService. + executeShellCommand("cmd jobscheduler run -f android 283673059"); + + // Wait for the compilation. + String sql = "SELECT COUNT(*) FROM activities JOIN prefetch_files ON " + + "activities.id = prefetch_files.activity_id " + + "WHERE activities.name = ?"; + boolean result = checkAndWaitEntriesNum(sql, new String[]{TEST_ACTIVITY_NAME}, /*count=*/1, + timeout); + if (!result) { + return false; + } + + return retryWithTimeout(timeout, () -> { + try { + String compiledTrace = getCompiledTraceFilePath(); + File compiledTraceLocal = copyFileToLocal(compiledTrace, "compiled_trace.tmp"); + return compiledTraceLocal.exists(); + } catch (Exception e) { + Log.i(TAG, e.getMessage()); + return false; + } + }); + } + + /** + * Check if all the perfetto traces in the db exist. + */ + private boolean checkPerfettoTracesExistence(Duration timeout, int expectPerfettoTraceCount) + throws Exception { + return retryWithTimeout(timeout, () -> { + try { + File dbFile = getIorapDb(); + List<String> traces = getPerfettoTracePaths(dbFile); + assertEquals(traces.size(), expectPerfettoTraceCount); + + int count = 0; + for (String trace : traces) { + File tmp = copyFileToLocal(trace, "perfetto_trace.tmp" + count); + ++count; + Log.i(TAG, "Check perfetto trace: " + trace); + if (!tmp.exists()) { + Log.i(TAG, "Perfetto trace does not exist: " + trace); + return false; + } + } + return true; + } catch (Exception e) { + Log.i(TAG, e.getMessage()); + return false; + } + }); + } + + /** + * Gets the perfetto traces file path from the db. + */ + private List<String> getPerfettoTracePaths(File dbFile) throws Exception { + String sql = "SELECT raw_traces.file_path FROM activities " + + "JOIN app_launch_histories ON activities.id = app_launch_histories.activity_id " + + "JOIN raw_traces ON raw_traces.history_id = app_launch_histories.id " + + "WHERE activities.name = ?"; + + List<String> perfettoTraces = new ArrayList<>(); + try (SQLiteDatabase db = SQLiteDatabase + .openDatabase(dbFile.getPath(), null, SQLiteDatabase.OPEN_READONLY)) { + Cursor cursor = db.rawQuery(sql, new String[]{TEST_ACTIVITY_NAME}); + while (cursor.moveToNext()) { + perfettoTraces.add(cursor.getString(0)); + } + } + return perfettoTraces; + } + + private String getCompiledTraceFilePath() throws Exception { + File dbFile = getIorapDb(); + try (SQLiteDatabase db = SQLiteDatabase + .openDatabase(dbFile.getPath(), null, SQLiteDatabase.OPEN_READONLY)) { + String sql = "SELECT prefetch_files.file_path FROM activities JOIN prefetch_files ON " + + "activities.id = prefetch_files.activity_id " + + "WHERE activities.name = ?"; + return DatabaseUtils.stringForQuery(db, sql, new String[]{TEST_ACTIVITY_NAME}); + } + } + + /** + * Checks the number of entries in the database table. + * + * <p> Keep checking until the timeout. + */ + private boolean checkAndWaitEntriesNum(String sql, String[] selectionArgs, long count, + Duration timeout) + throws Exception { + return retryWithTimeout(timeout, () -> { + try { + File db = getIorapDb(); + long curCount = getEntriesNum(db, selectionArgs, sql); + Log.i(TAG, String + .format("For %s, current count is %d, expected count is :%d.", sql, curCount, + count)); + return curCount == count; + } catch (Exception e) { + Log.i(TAG, e.getMessage()); + return false; + } + }); + } + + /** + * Retry until timeout. + */ + private boolean retryWithTimeout(Duration timeout, BooleanSupplier supplier) throws Exception { + long totalSleepTimeSeconds = 0L; + long sleepIntervalSeconds = 2L; + while (true) { + if (supplier.getAsBoolean()) { + return true; + } + TimeUnit.SECONDS.sleep(totalSleepTimeSeconds); + totalSleepTimeSeconds += sleepIntervalSeconds; + if (totalSleepTimeSeconds > timeout.getSeconds()) { + return false; + } + } + } + + /** + * Gets the number of entries in the query of sql. + */ + private long getEntriesNum(File dbFile, String[] selectionArgs, String sql) throws Exception { + try (SQLiteDatabase db = SQLiteDatabase + .openDatabase(dbFile.getPath(), null, SQLiteDatabase.OPEN_READONLY)) { + return DatabaseUtils.longForQuery(db, sql, selectionArgs); + } + } + + /** + * Gets the iorapd sqlite db file. + * + * <p> The test cannot access the db file directly under "/data/misc/iorapd". + * Copy it to the local directory and change the mode. + */ + private File getIorapDb() throws Exception { + File tmpDb = copyFileToLocal("/data/misc/iorapd/sqlite.db", "tmp.db"); + // Change the mode of the file to allow the access from test. + executeShellCommand("chmod 777 " + tmpDb.getPath()); + return tmpDb; + } + + /** + * Copys a file to local directory. + */ + private File copyFileToLocal(String src, String tgtFileName) throws Exception { + File localDir = getApplicationContext().getDir(this.getClass().getName(), Context.MODE_PRIVATE); + File localFile = new File(localDir, tgtFileName); + executeShellCommand(String.format("cp %s %s", src, localFile.getPath())); + return localFile; + } + + /** + * Starts the testing app. + */ + private void startApp() throws Exception { + Context context = getApplicationContext(); + final Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(TEST_PACKAGE_NAME); + context.startActivity(intent); + Log.i(TAG, "Started app " + TEST_PACKAGE_NAME); + } + + /** + * Closes the testing app. + * <p> Keep trying to kill the process of the app until no process of the app package + * appears.</p> + */ + private void closeApp() throws Exception { + while (true) { + String pid = executeShellCommand("pidof " + TEST_PACKAGE_NAME); + if (pid.isEmpty()) { + Log.i(TAG, "Closed app " + TEST_PACKAGE_NAME); + return; + } + executeShellCommand("kill -9 " + pid); + TimeUnit.SECONDS.sleep(1L); + } + } + + /** + * Waits for the prefetching log in the logcat. + * + * <p> When prefetching works, the perfetto traces should not be collected. </p> + */ + private boolean waitForPrefetchingFromLogcat(long expectPerfettoTraceCount) throws Exception { + if (!startAppForPerfettoTrace(expectPerfettoTraceCount)) { + return false; + } + + String log = executeShellCommand("logcat -s iorapd -d"); + + Pattern p = Pattern.compile( + ".*" + READAHEAD_INDICATOR + + ".*Total File Paths=(\\d+) \\(good: (\\d+)%\\)\n" + + ".*Total Entries=(\\d+) \\(good: (\\d+)%\\)\n" + + ".*Total Bytes=(\\d+) \\(good: (\\d+)%\\).*", + Pattern.DOTALL); + Matcher m = p.matcher(log); + + if (!m.matches()) { + Log.i(TAG, "Cannot find readahead log."); + return false; + } + + int totalFilePath = Integer.parseInt(m.group(1)); + float totalFilePathGoodRate = Float.parseFloat(m.group(2)) / 100; + int totalEntries = Integer.parseInt(m.group(3)); + float totalEntriesGoodRate = Float.parseFloat(m.group(4)) / 100; + int totalBytes = Integer.parseInt(m.group(5)); + float totalBytesGoodRate = Float.parseFloat(m.group(6)) / 100; + + Log.i(TAG, String.format( + "totalFilePath: %d (good %.2f) totalEntries: %d (good %.2f) totalBytes: %d (good %.2f)", + totalFilePath, totalFilePathGoodRate, totalEntries, totalEntriesGoodRate, totalBytes, + totalBytesGoodRate)); + + return totalFilePath > 0 && + totalEntries > 0 && + totalBytes > 100000 && + totalFilePathGoodRate > 0.5 && + totalEntriesGoodRate > 0.5 && + totalBytesGoodRate > 0.5; + } + + + /** + * Executes command in adb shell. + * + * <p> This should be run as root.</p> + */ + private String executeShellCommand(String cmd) throws Exception { + Log.i(TAG, "Execute: " + cmd); + return UiDevice.getInstance( + InstrumentationRegistry.getInstrumentation()).executeShellCommand(cmd); + } +} + + diff --git a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java index 7b3aace798f7..b89772538c6d 100644 --- a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java +++ b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java @@ -363,16 +363,10 @@ public final class TelephonyPermissions { */ private static boolean reportAccessDeniedToReadIdentifiers(Context context, int subId, int pid, int uid, String callingPackage, String message) { - boolean isPreinstalled = false; ApplicationInfo callingPackageInfo = null; try { callingPackageInfo = context.getPackageManager().getApplicationInfoAsUser( callingPackage, 0, UserHandle.getUserHandleForUid(uid)); - if (callingPackageInfo != null) { - if (callingPackageInfo.isSystemApp()) { - isPreinstalled = true; - } - } } catch (PackageManager.NameNotFoundException e) { // If the application info for the calling package could not be found then assume the // calling app is a non-preinstalled app to detect any issues with the check @@ -393,10 +387,9 @@ public final class TelephonyPermissions { } invokedMethods.add(message); TelephonyCommonStatsLog.write(TelephonyCommonStatsLog.DEVICE_IDENTIFIER_ACCESS_DENIED, - callingPackage, message, isPreinstalled, false); + callingPackage, message, /* isPreinstalled= */ false, false); } - Log.w(LOG_TAG, "reportAccessDeniedToReadIdentifiers:" + callingPackage + ":" + message - + ":isPreinstalled=" + isPreinstalled); + Log.w(LOG_TAG, "reportAccessDeniedToReadIdentifiers:" + callingPackage + ":" + message); // if the target SDK is pre-Q then check if the calling package would have previously // had access to device identifiers. if (callingPackageInfo != null && ( |