From 08f25b787b462e40ee7f39965e27c32bce04dcb1 Mon Sep 17 00:00:00 2001 From: Khaled Abdelmohsen Date: Wed, 9 Oct 2019 11:31:15 +0100 Subject: [PATCH] Create evaluation engine outcome Encapsulate the result from the evaluation engine, after evaluating rules against app install metadata, in a class holding the outcome effect and the rule causing that effect. Bug: 141971373 Test: N/A Change-Id: Ib311ab5bd4cdfd233008e7a7684cc99afabd337e --- .../integrity/model/EvaluationOutcome.java | 67 +++++++++++++++++++ .../android/server/integrity/model/Rule.java | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 services/core/java/com/android/server/integrity/model/EvaluationOutcome.java diff --git a/services/core/java/com/android/server/integrity/model/EvaluationOutcome.java b/services/core/java/com/android/server/integrity/model/EvaluationOutcome.java new file mode 100644 index 0000000000000..dc30dc39f44a1 --- /dev/null +++ b/services/core/java/com/android/server/integrity/model/EvaluationOutcome.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.integrity.model; + +/** + * A class encapsulating the result from the evaluation engine after evaluating rules against app + * install metadata. + * + *

It contains the outcome effect (whether to allow or block the install), and the rule causing + * that effect. + */ +public final class EvaluationOutcome { + + public enum Effect { + ALLOW, + DENY + } + + private final Effect mEffect; + private final Rule mRule; + + private EvaluationOutcome(Effect effect, Rule rule) { + this.mEffect = effect; + this.mRule = rule; + } + + public Effect getEffect() { + return mEffect; + } + + public Rule getRule() { + return mRule; + } + + /** + * Create an ALLOW evaluation outcome. + * + * @return An evaluation outcome with ALLOW effect and empty rule. + */ + public static EvaluationOutcome allow() { + return new EvaluationOutcome(Effect.ALLOW, Rule.EMPTY); + } + + /** + * Create a DENY evaluation outcome. + * + * @param rule Rule causing the DENY effect. + * @return An evaluation outcome with DENY effect and rule causing that effect. + */ + public static EvaluationOutcome deny(Rule rule) { + return new EvaluationOutcome(Effect.DENY, rule); + } +} diff --git a/services/core/java/com/android/server/integrity/model/Rule.java b/services/core/java/com/android/server/integrity/model/Rule.java index 4fd40c1e03651..3d233abda5ed5 100644 --- a/services/core/java/com/android/server/integrity/model/Rule.java +++ b/services/core/java/com/android/server/integrity/model/Rule.java @@ -25,7 +25,7 @@ import static com.android.internal.util.Preconditions.checkNotNull; */ public final class Rule { - enum Effect { + public enum Effect { DENY }