ApkBuilder.h revision fab50875b98e8274ac8ee44b38ba42521bbbf1f9
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 __APK_BUILDER_H 18#define __APK_BUILDER_H 19 20#include <set> 21#include <utils/Errors.h> 22#include <utils/String8.h> 23#include <utils/StrongPointer.h> 24#include <utils/Vector.h> 25 26#include "ConfigDescription.h" 27#include "OutputSet.h" 28#include "ResourceFilter.h" 29 30class ApkSplit; 31class AaptFile; 32 33class ApkBuilder : public android::RefBase { 34public: 35 ApkBuilder(const sp<WeakResourceFilter>& configFilter); 36 37 /** 38 * Tells the builder to generate a separate APK for resources that 39 * match the configurations specified. Split APKs can not have 40 * overlapping resources. 41 * 42 * NOTE: All splits should be set up before any files are added. 43 */ 44 android::status_t createSplitForConfigs(const std::set<ConfigDescription>& configs); 45 46 /** 47 * Adds a file to be written to the final APK. It's name must not collide 48 * with that of any files previously added. When a Split APK is being 49 * generated, duplicates can exist as long as they are in different splits 50 * (resources.arsc, AndroidManifest.xml). 51 */ 52 android::status_t addEntry(const String8& path, const android::sp<AaptFile>& file); 53 54 android::Vector<sp<ApkSplit> >& getSplits() { 55 return mSplits; 56 } 57 58 void print() const; 59 60private: 61 android::sp<ResourceFilter> mConfigFilter; 62 android::sp<AndResourceFilter> mDefaultFilter; 63 android::Vector<sp<ApkSplit> > mSplits; 64}; 65 66class ApkSplit : public OutputSet { 67public: 68 android::status_t addEntry(const String8& path, const android::sp<AaptFile>& file); 69 70 const std::set<OutputEntry>& getEntries() const { 71 return mFiles; 72 } 73 74 const std::set<ConfigDescription>& getConfigs() const { 75 return mConfigs; 76 } 77 78 bool matches(const sp<AaptFile>& file) const { 79 return mFilter->match(file->getGroupEntry().toParams()); 80 } 81 82 sp<ResourceFilter> getResourceFilter() const { 83 return mFilter; 84 } 85 86 const android::String8& getPrintableName() const { 87 return mName; 88 } 89 90 const android::String8& getDirectorySafeName() const { 91 return mDirName; 92 } 93 94 bool isBase() const { 95 return mIsBase; 96 } 97 98 void print() const; 99 100private: 101 friend class ApkBuilder; 102 103 ApkSplit(const std::set<ConfigDescription>& configs, const android::sp<ResourceFilter>& filter, bool isBase=false); 104 105 std::set<ConfigDescription> mConfigs; 106 const sp<ResourceFilter> mFilter; 107 const bool mIsBase; 108 String8 mName; 109 String8 mDirName; 110 std::set<OutputEntry> mFiles; 111}; 112 113#endif // __APK_BUILDER_H 114