• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.os.incremental;
18 
19 import android.annotation.NonNull;
20 import android.os.PersistableBundle;
21 
22 /**
23  * Provides methods to access metrics about an app installed via Incremental
24  * @hide
25  */
26 public class IncrementalMetrics {
27     @NonNull private final PersistableBundle mData;
28 
IncrementalMetrics(@onNull PersistableBundle data)29     public IncrementalMetrics(@NonNull PersistableBundle data) {
30         mData = data;
31     }
32 
33     /**
34      * @return Milliseconds between now and when the oldest pending read happened
35      */
getMillisSinceOldestPendingRead()36     public long getMillisSinceOldestPendingRead() {
37         return mData.getLong(IIncrementalService.METRICS_MILLIS_SINCE_OLDEST_PENDING_READ, -1);
38     }
39 
40     /**
41      * @return Whether read logs are enabled
42      */
getReadLogsEnabled()43     public boolean getReadLogsEnabled() {
44         return mData.getBoolean(IIncrementalService.METRICS_READ_LOGS_ENABLED, false);
45     }
46 
47     /**
48      * @return storage health status code. @see android.os.incremental.IStorageHealthListener
49      */
getStorageHealthStatusCode()50     public int getStorageHealthStatusCode() {
51         return mData.getInt(IIncrementalService.METRICS_STORAGE_HEALTH_STATUS_CODE, -1);
52     }
53 
54     /**
55      * @return data loader status code. @see android.content.pm.IDataLoaderStatusListener
56      */
getDataLoaderStatusCode()57     public int getDataLoaderStatusCode() {
58         return mData.getInt(IIncrementalService.METRICS_DATA_LOADER_STATUS_CODE, -1);
59     }
60 
61     /**
62      * @return duration since last data loader binding attempt
63      */
getMillisSinceLastDataLoaderBind()64     public long getMillisSinceLastDataLoaderBind() {
65         return mData.getLong(IIncrementalService.METRICS_MILLIS_SINCE_LAST_DATA_LOADER_BIND, -1);
66     }
67 
68     /**
69      * @return delay in milliseconds to retry data loader binding
70      */
getDataLoaderBindDelayMillis()71     public long getDataLoaderBindDelayMillis() {
72         return mData.getLong(IIncrementalService.METRICS_DATA_LOADER_BIND_DELAY_MILLIS, -1);
73     }
74 
75     /**
76      * @return total count of delayed reads caused by pending reads
77      */
getTotalDelayedReads()78     public int getTotalDelayedReads() {
79         return mData.getInt(IIncrementalService.METRICS_TOTAL_DELAYED_READS, -1);
80     }
81 
82     /**
83      * @return total count of failed reads
84      */
getTotalFailedReads()85     public int getTotalFailedReads() {
86         return mData.getInt(IIncrementalService.METRICS_TOTAL_FAILED_READS, -1);
87     }
88 
89     /**
90      * @return total duration in milliseconds of delayed reads
91      */
getTotalDelayedReadsDurationMillis()92     public long getTotalDelayedReadsDurationMillis() {
93         return mData.getLong(IIncrementalService.METRICS_TOTAL_DELAYED_READS_MILLIS, -1);
94     }
95 
96     /**
97      * @return the uid of the last read error
98      */
getLastReadErrorUid()99     public int getLastReadErrorUid() {
100         return mData.getInt(IIncrementalService.METRICS_LAST_READ_ERROR_UID, -1);
101     }
102 
103     /**
104      * @return duration in milliseconds since the last read error
105      */
getMillisSinceLastReadError()106     public long getMillisSinceLastReadError() {
107         return mData.getLong(IIncrementalService.METRICS_MILLIS_SINCE_LAST_READ_ERROR, -1);
108     }
109 
110     /**
111      * @return the error number of the last read error
112      */
getLastReadErrorNumber()113     public int getLastReadErrorNumber() {
114         return mData.getInt(IIncrementalService.METRICS_LAST_READ_ERROR_NUMBER, -1);
115     }
116 }
117