blob: 22685cd4e1949657f2f1d79475fcdcf1c64af61a [file] [log] [blame]
Adam Lesinski40e8eef2014-09-16 14:43:29 -07001/*
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#include "Grouper.h"
18
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080019#include "aapt/AaptUtil.h"
Adam Lesinski40e8eef2014-09-16 14:43:29 -070020#include "SplitDescription.h"
21
22#include <utils/KeyedVector.h>
23#include <utils/Vector.h>
24
25using namespace android;
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080026using AaptUtil::appendValue;
Adam Lesinski40e8eef2014-09-16 14:43:29 -070027
28namespace split {
29
Adam Lesinski40e8eef2014-09-16 14:43:29 -070030Vector<SortedVector<SplitDescription> >
31groupByMutualExclusivity(const Vector<SplitDescription>& splits) {
32 Vector<SortedVector<SplitDescription> > groups;
33
34 // Find mutually exclusive splits and group them.
35 KeyedVector<SplitDescription, SortedVector<SplitDescription> > densityGroups;
36 KeyedVector<SplitDescription, SortedVector<SplitDescription> > abiGroups;
37 KeyedVector<SplitDescription, SortedVector<SplitDescription> > localeGroups;
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080038 const size_t splitCount = splits.size();
39 for (size_t i = 0; i < splitCount; i++) {
40 const SplitDescription& split = splits[i];
Adam Lesinski40e8eef2014-09-16 14:43:29 -070041 if (split.config.density != 0) {
42 SplitDescription key(split);
43 key.config.density = 0;
44 key.config.sdkVersion = 0; // Ignore density so we can support anydpi.
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080045 appendValue(densityGroups, key, split);
46 } else if (split.abi != abi::Variant_none) {
Adam Lesinski40e8eef2014-09-16 14:43:29 -070047 SplitDescription key(split);
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080048 key.abi = abi::Variant_none;
49 appendValue(abiGroups, key, split);
Adam Lesinski40e8eef2014-09-16 14:43:29 -070050 } else if (split.config.locale != 0) {
51 SplitDescription key(split);
52 key.config.clearLocale();
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080053 appendValue(localeGroups, key, split);
Adam Lesinski40e8eef2014-09-16 14:43:29 -070054 } else {
55 groups.add();
56 groups.editTop().add(split);
57 }
58 }
59
60 const size_t densityCount = densityGroups.size();
61 for (size_t i = 0; i < densityCount; i++) {
62 groups.add(densityGroups[i]);
63 }
64
65 const size_t abiCount = abiGroups.size();
66 for (size_t i = 0; i < abiCount; i++) {
67 groups.add(abiGroups[i]);
68 }
69
70 const size_t localeCount = localeGroups.size();
71 for (size_t i = 0; i < localeCount; i++) {
72 groups.add(localeGroups[i]);
73 }
74 return groups;
75}
76
77} // namespace split