]> git.tdb.fi Git - builder.git/commitdiff
Allow Android application permissions to be set in Build file
authorMikko Rasa <tdb@tdb.fi>
Thu, 19 Nov 2015 08:57:02 +0000 (10:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 19 Nov 2015 08:57:02 +0000 (10:57 +0200)
source/androidapplicationcomponent.cpp
source/androidapplicationcomponent.h
source/androidmanifestfile.cpp
source/androidmanifestfile.h
source/androidmanifestgenerator.cpp

index 3c07feaad35d88db4358074435893ea727086ee7..85873d4024ab46b14f51c6e05196354eb7fed4ff 100644 (file)
@@ -29,6 +29,8 @@ void AndroidApplicationComponent::create_targets() const
                                contents.push_back(inst->get_real_target());
 
        AndroidManifestFile *manifest = new AndroidManifestFile(builder, *this);
+       for(set<string>::const_iterator i=permissions.begin(); i!=permissions.end(); ++i)
+               manifest->add_permission(*i);
 
        list<Target *> 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<AndroidApplicationComponent, Component::Loader>(c)
+{
+       add("permission", &Loader::permission);
+}
+
+void AndroidApplicationComponent::Loader::permission(const string &perm)
+{
+       obj.permissions.insert(perm);
+}
index 8d023756daafc6200f61c530fd04bb5a41b183cf..35984ea31f809e48d807634f449b0f41b0c72c8e 100644 (file)
@@ -1,10 +1,24 @@
 #ifndef ANDROIDAPPLICATIONCOMPONENT_H_
 #define ANDROIDAPPLICATIONCOMPONENT_H_
 
+#include <set>
 #include "component.h"
 
 class AndroidApplicationComponent: public Component
 {
+public:
+       class Loader: public Msp::DataFile::DerivedObjectLoader<AndroidApplicationComponent, Component::Loader>
+       {
+       public:
+               Loader(AndroidApplicationComponent &);
+
+       private:
+               void permission(const std::string &);
+       };
+
+private:
+       std::set<std::string> permissions;
+
 public:
        AndroidApplicationComponent(SourcePackage &, const std::string &);
 
index 55503defe99f6c762f7a58be5d96bf5b24547f70..1653e0a2afda80b8b1152f3cfa1f2bb10b33043d 100644 (file)
@@ -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);
+}
index e421adf7ac8448d94b6245eb2a83bb3ebdeed619..0dc77926ceeb76393b5e147fb3335477b2c1a912 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef ANDROIDMANIFESTFILE_H_
 #define ANDROIDMANIFESTFILE_H_
 
+#include <set>
 #include "filetarget.h"
 
 class AndroidApplicationComponent;
@@ -13,6 +14,7 @@ class AndroidManifestFile: public FileTarget
 {
 private:
        SharedLibrary *native_lib;
+       std::set<std::string> 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<std::string> &get_permissions() const { return permissions; }
 };
 
 #endif
index b0c7f8fd82ef8779e35ead02ac75a92baa0fb034..719bf95d16672e1f53cfdc9d5c2aa8cdfa3c717a 100644 (file)
@@ -52,6 +52,9 @@ void AndroidManifestGenerator::Worker::main()
                out.write("\t\t</activity>\n");
        }
        out.write("\t</application>\n");
+       const set<string> &permissions = manifest.get_permissions();
+       for(set<string>::const_iterator i=permissions.begin(); i!=permissions.end(); ++i)
+               IO::print(out, "\t<uses-permission android:name=\"%s\" />\n", *i);
        out.write("</manifest>\n");
 
        status = Task::SUCCESS;