1/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17syntax = "proto2";
18
19package android.os.statsd.framework;
20
21import "frameworks/proto_logging/stats/atoms.proto";
22import "frameworks/proto_logging/stats/atom_field_options.proto";
23import "frameworks/proto_logging/stats/enums/hardware/biometrics/enums.proto";
24import "frameworks/proto_logging/stats/enums/app/app_enums.proto";
25
26option java_package = "com.android.os.framework";
27
28extend Atom {
29    optional FullScreenIntentLaunched full_screen_intent_launched = 631 [(module) = "framework"];
30    optional BalAllowed bal_allowed = 632 [(module) = "framework"];
31    optional InTaskActivityStarted in_task_activity_started = 685 [(module) = "framework"];
32    optional CachedAppsHighWaterMark cached_apps_high_watermark = 10189 [(module) = "framework"];
33    optional StylusPredictionMetricsReported stylus_prediction_metrics_reported = 718 [(module) = "libinput"];
34    optional UserRiskEventReported user_risk_event_reported = 725 [(module) = "framework"];
35    optional MediaProjectionStateChanged media_projection_state_changed = 729 [(module) = "framework"];
36    optional MediaProjectionTargetChanged media_projection_target_changed = 730 [(module) = "framework"];
37    optional ExcessiveBinderProxyCountReported excessive_binder_proxy_count_reported = 853
38            [(module) = "framework"];
39    optional ProxyBytesTransferByFgBg proxy_bytes_transfer_by_fg_bg = 10200 [(module) = "framework"];
40    optional MobileBytesTransferByProcState mobile_bytes_transfer_by_proc_state = 10204
41            [(module) = "framework", (truncate_timestamp) = true];
42    optional BiometricFRRNotification biometric_frr_notification = 817 [(module) = "framework"];
43    optional SensitiveContentMediaProjectionSession sensitive_content_media_projection_session = 830 [(module) = "framework"];
44    optional SensitiveNotificationAppProtectionSession sensitive_notification_app_protection_session = 831 [(module) = "framework"];
45    optional SensitiveNotificationAppProtectionApplied sensitive_notification_app_protection_applied = 832 [(module) = "framework"];
46    optional SensitiveNotificationRedaction sensitive_notification_redaction = 833
47            [(module) = "framework"];
48    optional SensitiveContentAppProtection sensitive_content_app_protection = 835 [(module) = "framework"];
49    optional AppRestrictionStateChanged app_restriction_state_changed = 866 [(module) = "framework"];
50}
51
52/**
53 * Logs when a full screen intent is launched.
54 *
55 * Logged from:
56 *   frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
57 */
58message FullScreenIntentLaunched {
59    optional int32 creator_uid = 1 [(is_uid) = true];
60    optional string activity = 2;
61}
62
63message BalAllowed {
64    optional string target_activity = 1;
65    optional Status allowed_reason = 2;
66
67    optional int32 calling_uid = 3 [(is_uid) = true];
68    optional int32 real_calling_uid = 4 [(is_uid) = true];
69
70    // caller and real caller details are only provided if available.
71    optional Status caller_allowed_reason = 5;
72    optional bool caller_opt_in = 6;
73    optional bool caller_opt_in_explicit = 7;
74
75    optional Status real_caller_allowed_reason = 8;
76    optional bool real_caller_opt_in = 9;
77    optional bool real_caller_opt_in_explicit = 10;
78
79    optional int32 caller_target_sdk = 11;
80    optional int32 real_caller_target_sdk = 12;
81
82    enum Status {
83        BAL_STATUS_UNKNOWN = 0;
84        BAL_ALLOW_DEFAULT = 1;
85        BAL_ALLOW_ALLOWLISTED_UID = 2;
86        BAL_ALLOW_ALLOWLISTED_COMPONENT = 3;
87        BAL_ALLOW_VISIBLE_WINDOW = 4;
88        BAL_ALLOW_PENDING_INTENT = 5;
89        BAL_ALLOW_BAL_PERMISSION = 6;
90        BAL_ALLOW_SAW_PERMISSION = 7;
91        BAL_ALLOW_GRACE_PERIOD = 8;
92        BAL_ALLOW_FOREGROUND = 9;
93        BAL_ALLOW_SDK_SANDBOX = 10;
94        BAL_ALLOW_NON_APP_VISIBLE_WINDOW = 11;
95    }
96
97}
98
99/**
100 * Logs when an activity is started in a task with existing visible activities.
101 *
102 * Logged from: com.android.server.wm.ActivityMetricsLogger
103 */
104message InTaskActivityStarted {
105    // The uid of the started activity.
106    optional int32 uid = 1 [(is_uid) = true];
107
108    enum TransitionType {
109        UNKNOWN = 0;
110        WARM = 1;
111        HOT = 2;
112        COLD = 3;
113        RELAUNCH = 4;
114    }
115    optional TransitionType type = 2;
116
117    // Whether the activity is opaque or translucent.
118    optional bool is_opaque = 3;
119
120    // The delay to start transition.
121    optional int32 transition_delay_millis = 4;
122
123    // How long the activity took to be drawn.
124    optional int32 windows_drawn_delay_millis = 5;
125
126    // The timestamp(SystemClock#elapsedRealtime()) when starting activity.
127    optional int64 activity_start_timestamp_millis = 6;
128}
129
130/**
131 * Logs the cached apps high water mark.
132 */
133message CachedAppsHighWaterMark {
134  // The high water mark of the number of cached apps.
135  optional int32 cached_app_high_watermark = 1;
136
137  // The uptime (in seconds) at the high watermark.
138  // Note this is going to be pull metrics, so we'll need the timestamp here.
139  optional int32 uptime_in_seconds = 2;
140
141  // The number of binder proxy at that high water mark.
142  optional int32 binder_proxy_snapshot = 3;
143
144  // Free physical memory (in kb) on device.
145  optional int32 free_in_kb = 4;
146
147  // Cched physical memory (in kb) on device.
148  optional int32 cached_in_kb = 5;
149
150  // zram (in kb) on device.
151  optional int32 zram_in_kb = 6;
152
153  // Kernel memory (in kb) on device.
154  optional int32 kernel_in_kb = 7;
155
156  // The number of apps in frozen state.
157  optional int32 num_frozen_apps = 8;
158
159  // The longest frozen time (now - last_frozen) in current frozen apps.
160  optional int32 longest_frozen_time_in_seconds = 9;
161
162  // The shortest frozen time (now - last_frozen) in current frozen apps.
163  optional int32 shortest_frozen_time_in_seconds = 10;
164
165  // The mean frozen time (now - last_frozen) in current frozen apps.
166  optional int32 mean_frozen_time_in_seconds = 11;
167
168  // The average frozen time (now - last_frozen) in current frozen apps.
169  optional int32 average_frozen_time_in_seconds = 12;
170}
171
172/**
173 * [Pushed] Log stylus prediction error metrics (go/stylus-prediction-metrics).
174 * Logged once for each time bucket per touch event.
175 *
176 * Logged from: frameworks/native/libs/input/MotionPredictorMetricsManager.cpp.
177 */
178message StylusPredictionMetricsReported {
179    // Allow data to be sliced by stylus hardware information.
180    optional int32 stylus_vendor_id = 1;
181    optional int32 stylus_product_id = 2;
182
183    // Allow data to be sliced by time bucket.
184    optional int32 delta_time_bucket_milliseconds = 3;
185
186    // General errors.
187    optional int32 along_trajectory_error_mean_millipixels = 4;
188
189    // Standard deviation of the along-trajectory error.
190    optional int32 along_trajectory_error_std_millipixels = 5;
191
192    optional int32 off_trajectory_rmse_millipixels = 6;
193
194    optional int32 pressure_rmse_milliunits = 7;
195
196    // High-velocity errors.
197    optional int32 high_velocity_along_trajectory_rmse_millipixels = 8;
198
199    optional int32 high_velocity_off_trajectory_rmse_millipixels = 9;
200
201    // Scale-invariant errors.
202    optional int32 scale_invariant_along_trajectory_rmse_millipixels = 10;
203
204    optional int32 scale_invariant_off_trajectory_rmse_millipixels = 11;
205}
206
207/**
208 * Logs user risk events sent to UserRiskManager
209 */
210message UserRiskEventReported {
211  optional EventType event_type = 1;
212
213  // Call Details
214
215  // time that an active call was connected (picked up), -1 if a call is not active
216  optional int64 call_connected_timestamp_millis = 2;
217  optional CallDirection call_direction = 3;
218  optional NumberVerificationStatus call_number_verification_status = 4;
219  // time of the last update to the contact associated with the call, -1 if there is no contact
220  optional int64 call_contact_last_updated_timestamp_millis = 5;
221  optional int32 call_log_previous_incoming_count = 6;
222  optional int32 call_log_previous_outgoing_count = 7;
223
224  // Media Projection Details
225
226  // time of MP start, -1 if MP is not active
227  optional int64 mp_start_timestamp_millis = 8;
228  optional int32 mp_app_uid = 9 [(is_uid) = true];
229  optional int32 mp_installing_app_uid = 10 [(is_uid) = true];
230  // time that the MP app was installed
231  optional int64 mp_app_first_install_timestamp_millis = 11;
232
233  // A11y details
234
235  // time of A11y grant, -1 if not granted
236  optional int64 a11y_capability_granted_timestamp_millis = 12;
237  optional int32 a11y_app_uid = 13 [(is_uid) = true];
238  optional int32 a11y_installing_app_uid = 14 [(is_uid) = true];
239  // time that the A11y app was installed
240  optional int64 a11y_app_first_install_timestamp_mills = 15;
241
242  enum EventType {
243    UNKNOWN = 0;
244    A11Y_CONSENT_DIALOG_SHOWN = 1;
245    A11Y_GRANTED = 2;
246    A11Y_DENIED = 3;
247    A11Y_APP_UNINSTALLED = 4;
248    MEDIA_PROJECTION_CONSENT_DIALOG_SHOWN = 5;
249    MEDIA_PROJECTION_GRANTED = 6;
250    MEDIA_PROJECTION_DENIED = 7;
251    MEDIA_PROJECTION_STARTED = 8;
252    ACTIVE_CALL_STARTED = 9;
253    ACTIVE_CALL_CHANGED = 10;
254    ACTIVE_CALL_ENDED = 11;
255  }
256
257  enum CallDirection {
258    UNKNOWN_DIRECTION = 0;
259    INCOMING = 1;
260    OUTGOING = 2;
261  }
262
263  enum NumberVerificationStatus {
264    UNKNOWN_STATUS = 0;
265    NOT_VERIFIED = 1;
266    PASSED = 2;
267    FAILED = 3;
268  }
269}
270
271/**
272 * Logs when MediaProjection goes through state changes.
273 *
274 * MediaProjection API allows apps to capture the contents of a display
275 * or a single app.
276 *
277 * Logged from:
278 * frameworks/base/services/core/java/com/android/server/media/projection/MediaProjectionMetricsLogger.java
279 */
280message MediaProjectionStateChanged {
281  // Unique session identifier, to identify which events belong to which session.
282  // An incrementing integer that persists across device reboots.
283  optional int32 session_id = 1 [(state_field_option).primary_field = true];
284
285  // The current state that is entered.
286  optional MediaProjectionState state = 2 [
287    (state_field_option).exclusive_state = true,
288    (state_field_option).nested = false
289  ];
290
291  // Previous state.
292  optional MediaProjectionState previous_state = 3;
293
294  // UID of the package that initiates MediaProjection.
295  // -2 - if can't report (e.g. side loaded app)
296  optional int32 host_uid = 4 [(is_uid) = true];
297
298  // UID of the package that is captured if selected.
299  // -1 - full screen sharing (app is not selected)
300  // -2 - can't report (e.g. side loaded app)
301  optional int32 target_uid = 5 [(is_uid) = true];
302
303  // Time since last active session ended in seconds. May not be set if there
304  // was no known last session. Only set when in state MEDIA_PROJECTION_STATE_INITIATED.
305  optional int32 time_since_last_active_session_seconds = 6;
306
307  // Where this session started.
308  // Only present when in state MEDIA_PROJECTION_STATE_INITIATED.
309  optional SessionCreationSource creation_source = 7;
310
311  // Possible states for a MediaProjection session.
312  enum MediaProjectionState {
313    MEDIA_PROJECTION_STATE_UNKNOWN = 0;
314    // Media projection session first initiated by the app requesting the
315    // user's consent to capture.
316    // Should be sent even if the permission dialog is not shown.
317    MEDIA_PROJECTION_STATE_INITIATED = 1;
318    // The user entered the setup flow and permission dialog is displayed.
319    // This state is not sent when the permission is already granted and
320    // we skipped showing the permission dialog.
321    MEDIA_PROJECTION_STATE_PERMISSION_REQUEST_DISPLAYED = 2;
322    // The app selector dialog is shown for the user.
323    MEDIA_PROJECTION_STATE_APP_SELECTOR_DISPLAYED = 3;
324    // The VirtualDisplay is created and capturing the selected region begins.
325    MEDIA_PROJECTION_STATE_CAPTURING_IN_PROGRESS = 4;
326    // The capturing is paused.
327    MEDIA_PROJECTION_STATE_CAPTURING_PAUSED = 5;
328    // The capturing has resumed after being in paused state.
329    MEDIA_PROJECTION_STATE_CAPTURING_IN_PROGRESS_RESUMED = 6;
330    // Capturing stopped, either normally or because of error.
331    MEDIA_PROJECTION_STATE_STOPPED = 7;
332    // Media projection setup cancelled, user dismissed the dialog
333    MEDIA_PROJECTION_STATE_CANCELLED = 8;
334  }
335
336  // The possible entry points for the session.
337  enum SessionCreationSource {
338    CREATION_SOURCE_UNKNOWN = 0;
339    // Created through public MediaProjection API, used by 1P/3P apps.
340    CREATION_SOURCE_APP = 1;
341    // Created using a SystemUI screen recorder, accessible from screen
342    // recorder quick settings tile.
343    CREATION_SOURCE_SYSTEM_UI_SCREEN_RECORDER = 2;
344    // Created through Cast SDK, e.g. screencast quick settings tile.
345    CREATION_SOURCE_CAST = 3;
346  }
347}
348
349/**
350 * Logs when the region captured in the MediaProjection session changes.
351 *
352 * This may be due to a the user changing the region, or the captured app changing
353 * windowing mode.
354 *
355 * It should be reported only after a MediaProjection session enters
356 * MEDIA_PROJECTION_STATE_CAPTURING_IN_PROGRESS state.
357 *
358 * Logged from:
359 * frameworks/base/services/core/java/com/android/server/media/projection/MediaProjectionMetricsLogger.java
360 */
361message MediaProjectionTargetChanged {
362  // Unique session identifier, to identify which events belong to which session.
363  // An incrementing integer that persists across device reboots.
364  optional int32 session_id = 1 [(state_field_option).primary_field = true];
365
366  // The area that is being captured.
367  optional TargetType target_type = 2;
368
369  // UID of the package that initiates MediaProjection.
370  // -2 - can't report (e.g. side loaded app)
371  optional int32 host_uid = 3 [(is_uid) = true];
372
373  // UID of the package that is captured by MediaProjection.
374  // Not filled if not known, for example if the user chose
375  // display capture.
376  // -2 - can't report (e.g. side loaded app)
377  optional int32 target_uid = 4 [(is_uid) = true];
378
379  // The current windowing mode of the target app.
380  optional WindowingMode target_windowing_mode = 5 [
381    (state_field_option).exclusive_state = true,
382    (state_field_option).nested = false
383  ];
384
385  // Enum that represents the type of area that is being captured.
386  enum TargetType {
387    TARGET_TYPE_UNKNOWN = 0;
388    // Capturing a single display.
389    TARGET_TYPE_DISPLAY = 1;
390    // Capturing one task of an app.
391    TARGET_TYPE_APP_TASK = 2;
392  }
393
394  // Windowing mode of the captured task, if the user chose to capture
395  // a single app instance.
396  enum WindowingMode {
397    WINDOWING_MODE_UNKNOWN = 0;
398    // The app is not visible (e.g. another app is in full-screen foreground)
399    WINDOWING_MODE_HIDDEN = 1;
400    // The app is in fullscreen mode.
401    WINDOWING_MODE_FULLSCREEN = 2;
402    // The app is in a split screen.
403    WINDOWING_MODE_SPLIT_SCREEN = 3;
404    // The app is in freeform mode
405    WINDOWING_MODE_FREEFORM = 4;
406  }
407}
408
409/**
410 * Pulls bytes transferred via network with TYPE_PROXY from NetworkStats. Each pull produces atoms
411 * that record stats of all processes that used sysproxy since device boot.
412 * Network with TYPE_PROXY is used on Wear OS to enable internet access via Bluetooth when the
413 * companion phone is connected to the watch.
414 */
415message ProxyBytesTransferByFgBg {
416  optional int32 uid = 1 [(is_uid) = true];
417
418  optional bool is_foreground = 2;
419
420  optional int64 rx_bytes = 3;
421
422  optional int64 rx_packets = 4;
423
424  optional int64 tx_bytes = 5;
425
426  optional int64 tx_packets = 6;
427}
428
429/**
430 * Pulls bytes transferred via mobile networks (separated by proc state).
431 *
432 * Pulled from:
433 *   StatsCompanionService (using BatteryStats to get which interfaces are mobile data)
434 */
435 message MobileBytesTransferByProcState {
436    optional int32 uid = 1 [(is_uid) = true];
437
438    optional android.app.ProcessStateEnum proc_state = 2;
439
440    optional int64 rx_bytes = 3;
441
442    optional int64 rx_packets = 4;
443
444    optional int64 tx_bytes = 5;
445
446    optional int64 tx_packets = 6;
447}
448
449/**
450 * Logs when an FRR notification action has been presented to the user.
451 *
452 * Logged from:
453 *   frameworks/base/services/core/java/com/android/server/biometrics
454 */
455message BiometricFRRNotification {
456    optional android.hardware.biometrics.FRRNotificationAction action = 1;
457    optional android.hardware.biometrics.ModalityEnum modality = 2;
458}
459
460/*
461 * Logs that indicate a sensitive protection session has started
462 *
463 * Logs from :
464 * packages/SystemUI/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerImpl.java
465 * frameworks/base/services/core/java/com/android/server/SensitiveContentProtectionManagerService.java
466 */
467message SensitiveContentMediaProjectionSession {
468    optional int64 session_id = 1;
469    optional int32 projection_app_uid = 2 [(is_uid) = true];
470    optional bool exempted = 3;
471    optional State state = 4;
472    enum State {
473       UNDEFINED_STATE = 0;
474       START = 1;
475       STOP = 2;
476    }
477    optional LoggingSource source = 5;
478    enum LoggingSource {
479       UNDEFINED_SOURCE = 0;
480       SYS_UI = 1;
481       FRAMEWORKS = 2;
482    }
483}
484
485/*
486 * Logs that a sensitive content session has started
487 *
488 * Logs from : frameworks/base/services/core/java/com/android/server/SensitiveContentProtectionManagerService.java
489 *
490 */
491message SensitiveNotificationAppProtectionSession {
492    // id which identifies single screen share session
493    optional int64 session_id = 1;
494    optional int32 num_notifications = 2;
495    optional int32 num_otp_notifications = 3;
496}
497
498/*
499 * Logs that an app has been opened from a sensitive context
500 *
501 * Logs from :  com.android.server.wm
502 *
503 */
504message SensitiveNotificationAppProtectionApplied {
505    // id which identifies single screen share session
506    optional int64 session_id = 1;
507    // uid of app to be protected
508    optional int32 uid = 2 [(is_uid) = true];
509}
510
511/**
512 * Reports a notification got an Adjustment with the KEY_SENSITIVE_CONTENT value set, and whether
513 * the system redacted the notification
514 *
515 * Logged from:
516 *   frameworks/base/services/core/java/com/android/server/notification/
517 */
518message SensitiveNotificationRedaction {
519     optional bool receive_adjustment_before_post = 1;
520     optional bool redact = 2;
521     optional int32 latency_ms = 3;
522}
523
524
525/**
526* Logged when a user has started screen sharing and then opens an app activity
527* which renders sensitive content (i.e. username, password) on the screen.
528*
529* Logs from: frameworks/base/services/core/java/com/android/server/SensitiveContentProtectionManagerService.java
530*/
531
532message SensitiveContentAppProtection {
533  // unique for each media projection session.
534  optional int64 session_id = 1;
535  // uid which got flag_secure applied.
536  optional int32 protected_uid = 2 [(is_uid) = true];
537  // uid starting media projection.
538  optional int32 projection_uid = 3 [(is_uid) = true];
539  enum State {
540    UNKNOWN = 0;
541    BLOCKED = 1;
542    UNBLOCKED = 2;
543  }
544  // whether an app window got blocked or unblocked as sensitive view
545  // become visible/invisible in the window.
546  optional State state = 4;
547}
548
549/**
550 * Logs when there are too many binder proxies sent from certain UID to the system.
551 *
552 * Logged from:
553 *   frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
554 *
555 */
556message ExcessiveBinderProxyCountReported {
557    optional int32 offending_uid = 1 [(is_uid) = true];
558}
559
560/**
561 * Logs when an app's restriction state changes.
562 *
563 * Logged from:
564 *   frameworks/base/services/core/java/com/android/server/am/AppRestrictionController.java
565 */
566message AppRestrictionStateChanged {
567  optional int32 uid = 1 [(is_uid) = true];
568
569  enum RestrictionType {
570    TYPE_UNKNOWN = 0;
571    TYPE_UNRESTRICTED = 1;
572    TYPE_EXEMPTED = 2;
573    TYPE_ADAPTIVE = 3;
574    TYPE_RESTRICTED_BUCKET = 4;
575    TYPE_BACKGROUND_RESTRICTED = 5;
576    TYPE_FORCE_STOPPED = 6;
577    TYPE_USER_LAUNCH_ONLY = 7;
578    TYPE_CUSTOM = 8;
579  }
580  // The type of restriction/unrestriction
581  optional RestrictionType restriction_type = 2;
582
583  // Whether the restriction type is being enabled or disabled
584  optional bool enabled = 3;
585
586  enum RestrictionChangeReason {
587    REASON_UNKNOWN = 0;
588    REASON_DEFAULT = 1;
589    REASON_DORMANT = 2;
590    REASON_USAGE = 3; // For unrestriction
591    REASON_USER = 4;
592    reserved 5;
593    REASON_SYSTEM_HEALTH = 6;
594    REASON_POLICY = 7;
595    REASON_OTHER = 8;
596  }
597  // The main reason for restriction state change
598  optional RestrictionChangeReason main_reason = 4;
599
600  // An optional sub reason that provides more detail specific to the restriction type
601  optional string sub_reason = 5; // At most 16 chars
602
603  // The threshold that was applied to make the decision
604  optional int64 threshold_exceeded = 6;
605
606  enum RestrictionChangeSource {
607    SOURCE_UNKNOWN = 0;
608    SOURCE_USER = 1;
609    SOURCE_USER_NUDGED = 2;
610    SOURCE_SYSTEM = 3;
611    SOURCE_COMMAND_LINE = 4;
612    SOURCE_REMOTE_TRIGGER = 5;
613  }
614  // The source of the change - initiated by the user, the system automatically, etc.
615  optional RestrictionChangeSource source = 7;
616}
617