Merge "Distribute rule components in separate classes"
diff --git a/services/core/java/com/android/server/integrity/model/AtomicFormula.java b/services/core/java/com/android/server/integrity/model/AtomicFormula.java
new file mode 100644
index 0000000..38c9b57
--- /dev/null
+++ b/services/core/java/com/android/server/integrity/model/AtomicFormula.java
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import android.annotation.Nullable;
+
+/**
+ * Represents a simple formula consisting of an app install metadata field and a value.
+ *
+ * <p>Instances of this class are immutable.
+ */
+public final class AtomicFormula extends Formula {
+
+    enum Key {
+        PACKAGE_NAME,
+        APP_CERTIFICATE,
+        INSTALLER_NAME,
+        INSTALLER_CERTIFICATE,
+        VERSION_CODE,
+        PRE_INSTALLED
+    }
+
+    enum Operator {
+        EQ,
+        LT,
+        LE,
+        GT,
+        GE
+    }
+
+    private final Key mKey;
+    private final Operator mOperator;
+
+    // The value of a key can take either 1 of 3 forms: String, Integer, or Boolean.
+    // It cannot have multiple values.
+    @Nullable
+    final String mStringValue;
+    @Nullable
+    final Integer mIntValue;
+    @Nullable
+    final Boolean mBoolValue;
+
+    public AtomicFormula(Key key, Operator operator, String stringValue) {
+        // TODO: Add validators
+        this.mKey = key;
+        this.mOperator = operator;
+        this.mStringValue = stringValue;
+        this.mIntValue = null;
+        this.mBoolValue = null;
+    }
+
+    public AtomicFormula(Key key, Operator operator, Integer intValue) {
+        // TODO: Add validators
+        this.mKey = key;
+        this.mOperator = operator;
+        this.mStringValue = null;
+        this.mIntValue = intValue;
+        this.mBoolValue = null;
+    }
+
+    public AtomicFormula(Key key, Operator operator, Boolean boolValue) {
+        // TODO: Add validators
+        this.mKey = key;
+        this.mOperator = operator;
+        this.mStringValue = null;
+        this.mIntValue = null;
+        this.mBoolValue = boolValue;
+    }
+
+    public Key getKey() {
+        return mKey;
+    }
+
+    public Operator getOperator() {
+        return mOperator;
+    }
+
+    public String getStringValue() {
+        return mStringValue;
+    }
+
+    public Integer getIntValue() {
+        return mIntValue;
+    }
+
+    public Boolean getBoolValue() {
+        return mBoolValue;
+    }
+}
diff --git a/services/core/java/com/android/server/integrity/model/Formula.java b/services/core/java/com/android/server/integrity/model/Formula.java
new file mode 100644
index 0000000..4cfa2c7
--- /dev/null
+++ b/services/core/java/com/android/server/integrity/model/Formula.java
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+/**
+ * Represents a rule logic/content.
+ */
+abstract class Formula {
+
+}
diff --git a/services/core/java/com/android/server/integrity/model/OpenFormula.java b/services/core/java/com/android/server/integrity/model/OpenFormula.java
new file mode 100644
index 0000000..6b80f87
--- /dev/null
+++ b/services/core/java/com/android/server/integrity/model/OpenFormula.java
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import static com.android.internal.util.Preconditions.checkNotNull;
+
+import android.annotation.Nullable;
+
+/**
+ * Represents a complex formula consisting of other simple and complex formulas.
+ *
+ * <p>Instances of this class are immutable.
+ */
+public final class OpenFormula extends Formula {
+
+    enum Connector {
+        AND,
+        OR,
+        NOT
+    }
+
+    private final Connector mConnector;
+    private final Formula mMainFormula;
+    private final Formula mAuxiliaryFormula;
+
+    public OpenFormula(Connector connector, Formula mainFormula,
+            @Nullable Formula auxiliaryFormula) {
+        this.mConnector = checkNotNull(connector);
+        this.mMainFormula = checkNotNull(mainFormula);
+        this.mAuxiliaryFormula = auxiliaryFormula;
+    }
+
+    public Connector getConnector() {
+        return mConnector;
+    }
+
+    public Formula getMainFormula() {
+        return mMainFormula;
+    }
+
+    public Formula getAuxiliaryFormula() {
+        return mAuxiliaryFormula;
+    }
+}
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 a6e08d8..4fd40c1 100644
--- a/services/core/java/com/android/server/integrity/model/Rule.java
+++ b/services/core/java/com/android/server/integrity/model/Rule.java
@@ -18,8 +18,6 @@
 
 import static com.android.internal.util.Preconditions.checkNotNull;
 
-import android.annotation.Nullable;
-
 /**
  * Represent rules to be used in the rule evaluation engine to match against app installs.
  *
@@ -27,35 +25,12 @@
  */
 public final class Rule {
 
-    // Holds an empty rule instance.
-    public static final Rule EMPTY = new Rule();
-
-    enum Key {
-        PACKAGE_NAME,
-        APP_CERTIFICATE,
-        INSTALLER_NAME,
-        INSTALLER_CERTIFICATE,
-        VERSION_CODE,
-        PRE_INSTALLED
-    }
-
     enum Effect {
         DENY
     }
 
-    enum Operator {
-        EQ,
-        LT,
-        LE,
-        GT,
-        GE
-    }
-
-    enum Connector {
-        AND,
-        OR,
-        NOT
-    }
+    // Holds an empty rule instance.
+    public static final Rule EMPTY = new Rule();
 
     private final Formula mFormula;
     private final Effect mEffect;
@@ -86,75 +61,4 @@
     public Effect getEffect() {
         return mEffect;
     }
-
-    // TODO: Consider moving the sub-components to their respective model class.
-
-    /**
-     * Represents a rule logic/content.
-     */
-    abstract static class Formula {
-
-    }
-
-    /**
-     * Represents a simple formula consisting of an app install metadata field and a value.
-     */
-    public static final class AtomicFormula extends Formula {
-
-        final Key mKey;
-        final Operator mOperator;
-
-        // The value of a key can take either 1 of 3 forms: String, Integer, or Boolean.
-        // It cannot have multiple values.
-        @Nullable
-        final String mStringValue;
-        @Nullable
-        final Integer mIntValue;
-        @Nullable
-        final Boolean mBoolValue;
-
-        public AtomicFormula(Key key, Operator operator, String stringValue) {
-            // TODO: Add validators
-            this.mKey = key;
-            this.mOperator = operator;
-            this.mStringValue = stringValue;
-            this.mIntValue = null;
-            this.mBoolValue = null;
-        }
-
-        public AtomicFormula(Key key, Operator operator, Integer intValue) {
-            // TODO: Add validators
-            this.mKey = key;
-            this.mOperator = operator;
-            this.mStringValue = null;
-            this.mIntValue = intValue;
-            this.mBoolValue = null;
-        }
-
-        public AtomicFormula(Key key, Operator operator, Boolean boolValue) {
-            // TODO: Add validators
-            this.mKey = key;
-            this.mOperator = operator;
-            this.mStringValue = null;
-            this.mIntValue = null;
-            this.mBoolValue = boolValue;
-        }
-    }
-
-    /**
-     * Represents a complex formula consisting of other simple and complex formulas.
-     */
-    public static final class OpenFormula extends Formula {
-
-        final Connector mConnector;
-        final Formula mMainFormula;
-        final Formula mAuxiliaryFormula;
-
-        public OpenFormula(Connector connector, Formula mainFormula,
-                @Nullable Formula auxiliaryFormula) {
-            this.mConnector = checkNotNull(connector);
-            this.mMainFormula = checkNotNull(mainFormula);
-            this.mAuxiliaryFormula = auxiliaryFormula;
-        }
-    }
 }
diff --git a/services/tests/servicestests/src/com/android/server/integrity/model/RuleTest.java b/services/tests/servicestests/src/com/android/server/integrity/model/RuleTest.java
index 4321c21..cf001be 100644
--- a/services/tests/servicestests/src/com/android/server/integrity/model/RuleTest.java
+++ b/services/tests/servicestests/src/com/android/server/integrity/model/RuleTest.java
@@ -29,8 +29,9 @@
 public class RuleTest {
 
     private static final Rule.Effect DENY_EFFECT = Rule.Effect.DENY;
-    private static final Rule.Formula SIMPLE_FORMULA =
-            new Rule.AtomicFormula(Rule.Key.PACKAGE_NAME, Rule.Operator.EQ, "com.test.app");
+    private static final Formula SIMPLE_FORMULA =
+            new AtomicFormula(AtomicFormula.Key.PACKAGE_NAME, AtomicFormula.Operator.EQ,
+                    "com.test.app");
 
     @Test
     public void testEmptyRule() {