Grouper.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "Grouper.h"
  17. #include "aapt/AaptUtil.h"
  18. #include "SplitDescription.h"
  19. #include <utils/KeyedVector.h>
  20. #include <utils/Vector.h>
  21. using namespace android;
  22. using AaptUtil::appendValue;
  23. namespace split {
  24. Vector<SortedVector<SplitDescription> >
  25. groupByMutualExclusivity(const Vector<SplitDescription>& splits) {
  26. Vector<SortedVector<SplitDescription> > groups;
  27. // Find mutually exclusive splits and group them.
  28. KeyedVector<SplitDescription, SortedVector<SplitDescription> > densityGroups;
  29. KeyedVector<SplitDescription, SortedVector<SplitDescription> > abiGroups;
  30. const size_t splitCount = splits.size();
  31. for (size_t i = 0; i < splitCount; i++) {
  32. const SplitDescription& split = splits[i];
  33. if (split.config.density != 0) {
  34. SplitDescription key(split);
  35. key.config.density = 0;
  36. key.config.sdkVersion = 0; // Ignore density so we can support anydpi.
  37. appendValue(densityGroups, key, split);
  38. } else if (split.abi != abi::Variant_none) {
  39. SplitDescription key(split);
  40. key.abi = abi::Variant_none;
  41. appendValue(abiGroups, key, split);
  42. } else {
  43. groups.add();
  44. groups.editTop().add(split);
  45. }
  46. }
  47. const size_t densityCount = densityGroups.size();
  48. for (size_t i = 0; i < densityCount; i++) {
  49. groups.add(densityGroups[i]);
  50. }
  51. const size_t abiCount = abiGroups.size();
  52. for (size_t i = 0; i < abiCount; i++) {
  53. groups.add(abiGroups[i]);
  54. }
  55. return groups;
  56. }
  57. } // namespace split