From: Mikko Rasa Date: Thu, 19 Nov 2015 08:57:02 +0000 (+0200) Subject: Allow Android application permissions to be set in Build file X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=06a867bd33f4727f2092b1bce0fb57472e2d74e9;p=builder.git Allow Android application permissions to be set in Build file --- diff --git a/source/androidapplicationcomponent.cpp b/source/androidapplicationcomponent.cpp index 3c07fea..85873d4 100644 --- a/source/androidapplicationcomponent.cpp +++ b/source/androidapplicationcomponent.cpp @@ -29,6 +29,8 @@ void AndroidApplicationComponent::create_targets() const contents.push_back(inst->get_real_target()); AndroidManifestFile *manifest = new AndroidManifestFile(builder, *this); + for(set::const_iterator i=permissions.begin(); i!=permissions.end(); ++i) + manifest->add_permission(*i); list resource_sources; resource_sources.push_back(manifest); @@ -77,3 +79,15 @@ void AndroidApplicationComponent::create_targets() const Target *apk = apk_builder.create_target(apk_sources); builder.get_build_graph().add_primary_target(*apk); } + + +AndroidApplicationComponent::Loader::Loader(AndroidApplicationComponent &c): + DataFile::DerivedObjectLoader(c) +{ + add("permission", &Loader::permission); +} + +void AndroidApplicationComponent::Loader::permission(const string &perm) +{ + obj.permissions.insert(perm); +} diff --git a/source/androidapplicationcomponent.h b/source/androidapplicationcomponent.h index 8d02375..35984ea 100644 --- a/source/androidapplicationcomponent.h +++ b/source/androidapplicationcomponent.h @@ -1,10 +1,24 @@ #ifndef ANDROIDAPPLICATIONCOMPONENT_H_ #define ANDROIDAPPLICATIONCOMPONENT_H_ +#include #include "component.h" class AndroidApplicationComponent: public Component { +public: + class Loader: public Msp::DataFile::DerivedObjectLoader + { + public: + Loader(AndroidApplicationComponent &); + + private: + void permission(const std::string &); + }; + +private: + std::set permissions; + public: AndroidApplicationComponent(SourcePackage &, const std::string &); diff --git a/source/androidmanifestfile.cpp b/source/androidmanifestfile.cpp index 55503de..1653e0a 100644 --- a/source/androidmanifestfile.cpp +++ b/source/androidmanifestfile.cpp @@ -3,6 +3,8 @@ #include "builder.h" #include "sourcepackage.h" +using namespace std; + AndroidManifestFile::AndroidManifestFile(Builder &b, const AndroidApplicationComponent &a): FileTarget(b, a.get_package(), a.get_package().get_temp_directory()/a.get_name()/"AndroidManifest.xml"), native_lib(0) @@ -17,3 +19,8 @@ void AndroidManifestFile::set_native_library(SharedLibrary *lib) { native_lib = lib; } + +void AndroidManifestFile::add_permission(const string &perm) +{ + permissions.insert(perm); +} diff --git a/source/androidmanifestfile.h b/source/androidmanifestfile.h index e421adf..0dc7792 100644 --- a/source/androidmanifestfile.h +++ b/source/androidmanifestfile.h @@ -1,6 +1,7 @@ #ifndef ANDROIDMANIFESTFILE_H_ #define ANDROIDMANIFESTFILE_H_ +#include #include "filetarget.h" class AndroidApplicationComponent; @@ -13,6 +14,7 @@ class AndroidManifestFile: public FileTarget { private: SharedLibrary *native_lib; + std::set permissions; public: AndroidManifestFile(Builder &, const AndroidApplicationComponent &); @@ -21,6 +23,9 @@ public: void set_native_library(SharedLibrary *); SharedLibrary *get_native_library() const { return native_lib; } + + void add_permission(const std::string &); + const std::set &get_permissions() const { return permissions; } }; #endif diff --git a/source/androidmanifestgenerator.cpp b/source/androidmanifestgenerator.cpp index b0c7f8f..719bf95 100644 --- a/source/androidmanifestgenerator.cpp +++ b/source/androidmanifestgenerator.cpp @@ -52,6 +52,9 @@ void AndroidManifestGenerator::Worker::main() out.write("\t\t\n"); } out.write("\t\n"); + const set &permissions = manifest.get_permissions(); + for(set::const_iterator i=permissions.begin(); i!=permissions.end(); ++i) + IO::print(out, "\t\n", *i); out.write("\n"); status = Task::SUCCESS;