1 /* 2 * Copyright (C) 2024 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 17 package android.graphics.pdf.logging; 18 19 import android.annotation.IntDef; 20 import android.graphics.pdf.PdfStatsLog; 21 22 import java.lang.annotation.Retention; 23 import java.lang.annotation.RetentionPolicy; 24 25 /** 26 * Class to log all the PDFViewer event related data to statsD. 27 * 28 * @hide 29 */ 30 public class PdfEventLogger { 31 32 private final int mProcessId; 33 private final long mDocId; 34 35 /** 36 * Creates a new object for the PdfEventLogger class. 37 * 38 * @param processId the uid of the process which is calling PdfViewer APIs. 39 * @param docId Unique identifier for a particular loaded document. 40 */ PdfEventLogger(int processId, long docId)41 public PdfEventLogger(int processId, long docId) { 42 mProcessId = processId; 43 mDocId = docId; 44 } 45 46 /** 47 * Logs data related to Pdf search events to statsD. 48 * 49 * @param loadDurationMillis Time take to load the search result. 50 * @param queryLength The number of characters in the search query. 51 * @param queryPageNumber The page number of the query. 52 * @param apiResponse The response type of the search API call. 53 * @param numPages The number of pages in the pdf being searched 54 * @param matchCount The number of matches for a particular query. 55 * @see com.android.os.pdf.PdfSearchReported 56 */ logSearchReportedEvent( long loadDurationMillis, int queryLength, int queryPageNumber, @ApiResponseTypes.ApiResponseType int apiResponse, int numPages, int matchCount)57 public void logSearchReportedEvent( 58 long loadDurationMillis, 59 int queryLength, 60 int queryPageNumber, 61 @ApiResponseTypes.ApiResponseType int apiResponse, 62 int numPages, 63 int matchCount) { 64 PdfStatsLog.write(PdfStatsLog.PDF_SEARCH_REPORTED, mProcessId, loadDurationMillis, 65 queryLength, queryPageNumber, apiResponse, mDocId, numPages, matchCount); 66 } 67 68 /** 69 * Logs data related to Pdf load events to statsD. 70 * 71 * @param loadDurationMillis the time taken to load a PDF document in milliseconds. 72 * @param pdfSizeInKb The size of the PDF document which is loaded 73 * @param pdfLoadResult The result/ status of a PDF document which is loaded 74 * @param linearizationType The linearization type of the PDF document which is loaded 75 * @param numPages The number of pages in PDF document which is loaded 76 * @see com.android.os.pdf.PdfLoadReported 77 */ logPdfLoadReportedEvent( long loadDurationMillis, float pdfSizeInKb, @PdfLoadResults.PdfLoadResult int pdfLoadResult, @LinearizationTypes.LinearizationType int linearizationType, int numPages)78 public void logPdfLoadReportedEvent( 79 long loadDurationMillis, 80 float pdfSizeInKb, 81 @PdfLoadResults.PdfLoadResult int pdfLoadResult, 82 @LinearizationTypes.LinearizationType int linearizationType, 83 int numPages) { 84 PdfStatsLog.write(PdfStatsLog.PDF_LOAD_REPORTED, mProcessId, loadDurationMillis, 85 pdfSizeInKb, pdfLoadResult, linearizationType, numPages, mDocId); 86 } 87 88 /** 89 * Logs data related to Pdf API usage events to statsD. 90 * 91 * @param apiType The type of API being called. 92 * @param apiResponse The response type of the API call. 93 * @see com.android.os.pdf.PdfApiUsageReported 94 */ logPdfApiUsageReportedEvent( @piTypes.ApiType int apiType, @ApiResponseTypes.ApiResponseType int apiResponse)95 public void logPdfApiUsageReportedEvent( 96 @ApiTypes.ApiType int apiType, 97 @ApiResponseTypes.ApiResponseType int apiResponse) { 98 PdfStatsLog.write(PdfStatsLog.PDF_API_USAGE_REPORTED, mProcessId, mDocId, apiType, 99 apiResponse); 100 } 101 102 // Represent the linearization type of the PDF document. 103 public static final class LinearizationTypes { 104 public static final int UNKNOWN = PdfStatsLog.PDF_LOAD_REPORTED__TYPE__UNKNOWN_TYPE; 105 public static final int LINEARIZED = PdfStatsLog.PDF_LOAD_REPORTED__TYPE__LINEARIZED_TYPE; 106 public static final int NON_LINEARIZED = 107 PdfStatsLog.PDF_LOAD_REPORTED__TYPE__NON_LINEARIZED_TYPE; 108 109 @IntDef({UNKNOWN, LINEARIZED, NON_LINEARIZED}) 110 @Retention(RetentionPolicy.RUNTIME) 111 public @interface LinearizationType { 112 } 113 } 114 115 // Represents the status of the PDF load called on a document. 116 public static final class PdfLoadResults { 117 public static final int UNKNOWN = 118 PdfStatsLog.PDF_LOAD_REPORTED__LOAD_RESULT__RESULT_UNKNOWN; 119 public static final int LOADED = PdfStatsLog.PDF_LOAD_REPORTED__LOAD_RESULT__RESULT_LOADED; 120 public static final int ERROR = PdfStatsLog.PDF_LOAD_REPORTED__LOAD_RESULT__RESULT_ERROR; 121 public static final int WRONG_PASSWORD = 122 PdfStatsLog.PDF_LOAD_REPORTED__LOAD_RESULT__RESULT_WRONG_PASSWORD; 123 124 @IntDef({UNKNOWN, LOADED, ERROR, WRONG_PASSWORD}) 125 @Retention(RetentionPolicy.RUNTIME) 126 public @interface PdfLoadResult { 127 } 128 } 129 130 // Represents the types of PdfViewer API being called. 131 public static final class ApiTypes { 132 public static final int UNKNOWN = 133 PdfStatsLog.PDF_API_USAGE_REPORTED__API_TYPE__API_TYPE_UNKNOWN; 134 public static final int SELECT_CONTENT = 135 PdfStatsLog.PDF_API_USAGE_REPORTED__API_TYPE__API_TYPE_SELECT_CONTENT; 136 137 @IntDef({UNKNOWN, SELECT_CONTENT}) 138 @Retention(RetentionPolicy.RUNTIME) 139 public @interface ApiType { 140 } 141 } 142 143 // Represents the response of the API (success/failure) call. 144 public static final class ApiResponseTypes { 145 public static final int UNKNOWN = 146 PdfStatsLog.PDF_API_USAGE_REPORTED__API_RESPONSE_STATUS__RESPONSE_UNKNOWN; 147 public static final int SUCCESS = 148 PdfStatsLog.PDF_API_USAGE_REPORTED__API_RESPONSE_STATUS__RESPONSE_SUCCESS; 149 public static final int FAILURE = 150 PdfStatsLog.PDF_API_USAGE_REPORTED__API_RESPONSE_STATUS__RESPONSE_FAILURE; 151 152 @IntDef({UNKNOWN, SUCCESS, FAILURE}) 153 @Retention(RetentionPolicy.RUNTIME) 154 public @interface ApiResponseType { 155 } 156 } 157 158 } 159