Song Pan | 75147d5 | 2019-11-19 00:57:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.content.integrity; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.SystemApi; |
| 21 | import android.annotation.SystemService; |
| 22 | import android.content.Context; |
| 23 | import android.content.IntentSender; |
| 24 | import android.content.pm.ParceledListSlice; |
| 25 | import android.os.RemoteException; |
| 26 | |
| 27 | /** |
| 28 | * Class for pushing rules used to check the integrity of app installs. |
| 29 | * |
| 30 | * <p>Note: applications using methods of this class must be a system app and have their package |
| 31 | * name whitelisted as an integrity rule provider. Otherwise a {@link SecurityException} will be |
| 32 | * thrown. |
| 33 | * |
| 34 | * @hide |
| 35 | */ |
| 36 | @SystemApi |
| 37 | @SystemService(Context.APP_INTEGRITY_SERVICE) |
| 38 | public class AppIntegrityManager { |
| 39 | |
| 40 | /** The operation succeeded. */ |
| 41 | public static final int STATUS_SUCCESS = 0; |
| 42 | |
| 43 | /** The operation failed. */ |
| 44 | public static final int STATUS_FAILURE = 1; |
| 45 | |
| 46 | /** |
| 47 | * Current status of an operation. Will be one of {@link #STATUS_SUCCESS}, {@link |
| 48 | * #STATUS_FAILURE}. |
| 49 | * |
| 50 | * <p>More information about a status may be available through additional extras; see the |
| 51 | * individual status documentation for details. |
| 52 | * |
| 53 | * @see android.content.Intent#getIntExtra(String, int) |
| 54 | */ |
| 55 | public static final String EXTRA_STATUS = "android.content.integrity.extra.STATUS"; |
| 56 | |
| 57 | IAppIntegrityManager mManager; |
| 58 | |
| 59 | /** @hide */ |
| 60 | public AppIntegrityManager(IAppIntegrityManager manager) { |
| 61 | mManager = manager; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Update the rules to evaluate during install time. |
| 66 | * |
| 67 | * @param updateRequest request containing the data of the rule set update |
| 68 | * @param statusReceiver Called when the state of the session changes. Intents sent to this |
| 69 | * receiver contain {@link #EXTRA_STATUS}. Refer to the individual status codes on how to |
| 70 | * handle them. |
| 71 | */ |
| 72 | public void updateRuleSet( |
| 73 | @NonNull RuleSet updateRequest, @NonNull IntentSender statusReceiver) { |
| 74 | try { |
| 75 | mManager.updateRuleSet( |
| 76 | updateRequest.getVersion(), |
| 77 | new ParceledListSlice<>(updateRequest.getRules()), |
| 78 | statusReceiver); |
| 79 | } catch (RemoteException e) { |
| 80 | throw e.rethrowAsRuntimeException(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** Get the current version of the rule set. */ |
| 85 | @NonNull |
| 86 | public String getCurrentRuleSetVersion() { |
| 87 | try { |
| 88 | return mManager.getCurrentRuleSetVersion(); |
| 89 | } catch (RemoteException e) { |
| 90 | throw e.rethrowAsRuntimeException(); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** Get the name of the package that provided the current rule set. */ |
| 95 | @NonNull |
| 96 | public String getCurrentRuleSetProvider() { |
| 97 | try { |
| 98 | return mManager.getCurrentRuleSetProvider(); |
| 99 | } catch (RemoteException e) { |
| 100 | throw e.rethrowAsRuntimeException(); |
| 101 | } |
| 102 | } |
| 103 | } |