| Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 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 | #include "Grouper.h" | 
|  | 18 |  | 
| Adam Lesinski | c3dc0b5 | 2014-11-03 12:05:15 -0800 | [diff] [blame] | 19 | #include "aapt/AaptUtil.h" | 
| Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 20 | #include "SplitDescription.h" | 
|  | 21 |  | 
|  | 22 | #include <utils/KeyedVector.h> | 
|  | 23 | #include <utils/Vector.h> | 
|  | 24 |  | 
|  | 25 | using namespace android; | 
| Adam Lesinski | c3dc0b5 | 2014-11-03 12:05:15 -0800 | [diff] [blame] | 26 | using AaptUtil::appendValue; | 
| Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 27 |  | 
|  | 28 | namespace split { | 
|  | 29 |  | 
| Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 30 | Vector<SortedVector<SplitDescription> > | 
|  | 31 | groupByMutualExclusivity(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; | 
| Adam Lesinski | c3dc0b5 | 2014-11-03 12:05:15 -0800 | [diff] [blame] | 37 | const size_t splitCount = splits.size(); | 
|  | 38 | for (size_t i = 0; i < splitCount; i++) { | 
|  | 39 | const SplitDescription& split = splits[i]; | 
| Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 40 | if (split.config.density != 0) { | 
|  | 41 | SplitDescription key(split); | 
|  | 42 | key.config.density = 0; | 
|  | 43 | key.config.sdkVersion = 0; // Ignore density so we can support anydpi. | 
| Adam Lesinski | c3dc0b5 | 2014-11-03 12:05:15 -0800 | [diff] [blame] | 44 | appendValue(densityGroups, key, split); | 
|  | 45 | } else if (split.abi != abi::Variant_none) { | 
| Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 46 | SplitDescription key(split); | 
| Adam Lesinski | c3dc0b5 | 2014-11-03 12:05:15 -0800 | [diff] [blame] | 47 | key.abi = abi::Variant_none; | 
|  | 48 | appendValue(abiGroups, key, split); | 
| Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 49 | } else { | 
|  | 50 | groups.add(); | 
|  | 51 | groups.editTop().add(split); | 
|  | 52 | } | 
|  | 53 | } | 
|  | 54 |  | 
|  | 55 | const size_t densityCount = densityGroups.size(); | 
|  | 56 | for (size_t i = 0; i < densityCount; i++) { | 
|  | 57 | groups.add(densityGroups[i]); | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | const size_t abiCount = abiGroups.size(); | 
|  | 61 | for (size_t i = 0; i < abiCount; i++) { | 
|  | 62 | groups.add(abiGroups[i]); | 
|  | 63 | } | 
|  | 64 |  | 
| Adam Lesinski | 40e8eef | 2014-09-16 14:43:29 -0700 | [diff] [blame] | 65 | return groups; | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | } // namespace split |