1 /*
2  * Copyright (C) 2014 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 #ifndef H_ANDROID_SPLIT_RULE
18 #define H_ANDROID_SPLIT_RULE
19 
20 #include "SplitDescription.h"
21 
22 #include <utils/RefBase.h>
23 #include <utils/StrongPointer.h>
24 #include <utils/String8.h>
25 #include <utils/Vector.h>
26 
27 namespace split {
28 
29 struct Rule : public virtual android::RefBase {
30     inline Rule();
31     Rule(const Rule& rhs);
32 
33     enum Operator {
34         LESS_THAN = 1,
35         GREATER_THAN,
36         EQUALS,
37         CONTAINS_ANY,
38         CONTAINS_ALL,
39         IS_TRUE,
40         IS_FALSE,
41         AND_SUBRULES,
42         OR_SUBRULES,
43         ALWAYS_TRUE,
44     };
45 
46     Operator op;
47 
48     enum Key {
49         NONE = 0,
50         SDK_VERSION,
51         SCREEN_DENSITY,
52         LANGUAGE,
53         NATIVE_PLATFORM,
54         TOUCH_SCREEN,
55         SCREEN_SIZE,
56         SCREEN_LAYOUT,
57     };
58 
59     Key key;
60     bool negate;
61 
62     android::Vector<android::String8> stringArgs;
63     android::Vector<int> longArgs;
64     android::Vector<double> doubleArgs;
65     android::Vector<android::sp<Rule> > subrules;
66 
67     android::String8 toJson(int indent=0) const;
68 
69     static android::sp<Rule> simplify(android::sp<Rule> rule);
70 };
71 
Rule()72 Rule::Rule()
73 : op(ALWAYS_TRUE)
74 , key(NONE)
75 , negate(false) {}
76 
77 } // namespace split
78 
79 #endif // H_ANDROID_SPLIT_RULE
80