1 /*
2  * Copyright (C) 2022 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.transparency;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SystemService;
21 import android.content.Context;
22 import android.os.Bundle;
23 import android.os.RemoteException;
24 import android.util.Slog;
25 
26 import com.android.internal.os.IBinaryTransparencyService;
27 
28 import java.util.List;
29 
30 /**
31  * BinaryTransparencyManager defines a number of system interfaces that other system apps or
32  * services can make use of, when trying to get more information about the various binaries
33  * that are installed on this device.
34  * @hide
35  */
36 @SystemService(Context.BINARY_TRANSPARENCY_SERVICE)
37 public class BinaryTransparencyManager {
38     private static final String TAG = "TransparencyManager";
39 
40     private final Context mContext;
41     private final IBinaryTransparencyService mService;
42 
43     /**
44      * Constructor
45      * @param context The calling context.
46      * @param service A valid instance of IBinaryTransparencyService.
47      * @hide
48      */
BinaryTransparencyManager(Context context, IBinaryTransparencyService service)49     public BinaryTransparencyManager(Context context, IBinaryTransparencyService service) {
50         mContext = context;
51         mService = service;
52     }
53 
54 
55     /**
56      * Obtains a string containing information that describes the signed images that are installed
57      * on this device. Currently, this piece of information is identified as the VBMeta digest.
58      * @return A String containing the VBMeta Digest of the signed partitions loaded on this device.
59      */
60     @NonNull
getSignedImageInfo()61     public String getSignedImageInfo() {
62         try {
63             return mService.getSignedImageInfo();
64         } catch (RemoteException e) {
65             throw e.rethrowFromSystemServer();
66         }
67     }
68 
69     /**
70      * Collects the APEX information on the device.
71      *
72      * @param includeTestOnly Whether to include test only data in the returned ApexInfo.
73      * @return A List containing the APEX info.
74      * @hide
75      */
76     @NonNull
collectAllApexInfo(boolean includeTestOnly)77     public List<IBinaryTransparencyService.ApexInfo> collectAllApexInfo(boolean includeTestOnly) {
78         try {
79             return mService.collectAllApexInfo(includeTestOnly);
80         } catch (RemoteException e) {
81             throw e.rethrowFromSystemServer();
82         }
83     }
84 
85     /**
86      * Collects the updated preload information on the device.
87      *
88      * @return A List containing the preload info.
89      * @hide
90      */
91     @NonNull
collectAllUpdatedPreloadInfo( Bundle packagesToSkip)92     public List<IBinaryTransparencyService.AppInfo> collectAllUpdatedPreloadInfo(
93             Bundle packagesToSkip) {
94         try {
95             Slog.d(TAG, "Calling backend's collectAllUpdatedPreloadInfo()");
96             return mService.collectAllUpdatedPreloadInfo(packagesToSkip);
97         } catch (RemoteException e) {
98             throw e.rethrowFromSystemServer();
99         }
100     }
101 
102     /**
103      * Collects the silent installed MBA information on the device.
104      *
105      * @return A List containing the MBA info of silent installed.
106      * @hide
107      */
108     @NonNull
collectAllSilentInstalledMbaInfo( Bundle packagesToSkip)109     public List<IBinaryTransparencyService.AppInfo> collectAllSilentInstalledMbaInfo(
110             Bundle packagesToSkip) {
111         try {
112             Slog.d(TAG, "Calling backend's collectAllSilentInstalledMbaInfo()");
113             return mService.collectAllSilentInstalledMbaInfo(packagesToSkip);
114         } catch (RemoteException e) {
115             throw e.rethrowFromSystemServer();
116         }
117     }
118 }
119