Permalink
Browse files

more changes to support collecting the set of permissions into the ma…

…nifest. Untested.
  • Loading branch information...
1 parent 016289c commit 05d221817c7063ae4df631fa7a2a29f140fb7306 dyoo committed Oct 19, 2010
View
11 doc/known-permissions.txt
@@ -0,0 +1,11 @@
+PERMISSION:LOCATION
+PERMISSION:SEND-SMS
+PERMISSION:RECEIVE-SMS
+PERMISSION:TILT
+PERMISSION:SHAKE
+PERMISSION:INTERNET
+PERMISSION:TELEPHONY
+PERMISSION:WAKE-LOCK
+PERMISSION:VIBRATE
+PERMISSION:FFI
+
View
28 src/android/android-permission.rkt
@@ -0,0 +1,28 @@
+#lang racket/base
+
+(require racket/list
+ racket/contract)
+
+;; permission->android-permissions: string (-> X)-> (or/c (listof string) X)
+;; Given a permission, translates to the permissions associated with the Google Android platform.
+(define (permission->android-permissions a-permission on-fail)
+ (define mapping '(["PERMISSION:LOCATION" "android.permission.ACCESS_COARSE_LOCATION"
+ "android.permission.ACCESS_FINE_LOCATION"]
+ ["PERMISSION:SEND-SMS" "android.permission.SEND_SMS"]
+ ["PERMISSION:RECEIVE-SMS" "android.permission.RECEIVE_SMS"]
+ ["PERMISSION:TILT"]
+ ["PERMISSION:SHAKE"]
+ ["PERMISSION:INTERNET" "android.permission.INTERNET"]
+ ["PERMISSION:TELEPHONY" "android.permission.ACCESS_COARSE_UPDATES"]
+ ["PERMISSION:WAKE-LOCK" "android.permission.WAKE_LOCK"]
+ ["PERMISSION:VIBRATE" "android.permission.VIBRATE"]
+ ["PERMISSION:FFI"]))
+ (cond [(assoc a-permission mapping)
+ =>
+ (lambda (entry) (rest entry))]
+ [else
+ (on-fail)]))
+
+(provide/contract [permission->android-permissions (string? (-> any/c)
+ . -> .
+ (or/c any/c (listof string?)))])
View
96 src/android/local-android-packager.ss
@@ -11,10 +11,11 @@
(planet dyoo/js-vm/private/write-module-records)
(planet dyoo/js-vm/private/write-runtime)
+ "android-permission.rkt"
"../config.rkt"
"../utils.rkt"
- "../compile-helpers.rkt"
- )
+ "../compile-helpers.rkt")
+
(define-runtime-path phonegap-path "../../support/phonegap-fork/android-1.5")
(define-runtime-path icon-path "../../support/icons/icon.png")
@@ -50,24 +51,26 @@
;; build-android-package-in-path: string path path -> void
;; Builds the android package and produces the binary within the path/bin.
(define (build-android-package-in-path name program-path dest)
- ;; Prepares the non-assets android package structure.
- (prepare-android-package-src-structure name dest)
-
- ;; Write out local properties so that the build system knows how to compile
- (write-local.properties dest)
-
- ;; Write out assets.
- (write-assets name program-path (build-path dest "assets"))
-
-
- (unless (file-exists? (current-ant-bin-path))
- (error 'build-android-package-in-path
- "The Apache ant binary appears to be missing from the current PATH."))
- (unless (directory-exists? (current-android-sdk-path))
- (error 'build-android-package-in-path
- "The Android SDK could not be found."))
-
- (run-ant-build.xml dest "debug"))
+ (let ([module-records (get-compiled-modules program-path)])
+ ;; Prepares the non-assets android package structure.
+ (prepare-android-package-src-structure name
+ (module-records-android-permissions module-records)
+ dest)
+
+ ;; Write out assets.
+ (write-assets name program-path module-records (build-path dest "assets"))
+
+ ;; Write out local properties so that the build system knows how to compile
+ (write-local.properties dest)
+
+ (unless (file-exists? (current-ant-bin-path))
+ (error 'build-android-package-in-path
+ "The Apache ant binary appears to be missing from the current PATH."))
+ (unless (directory-exists? (current-android-sdk-path))
+ (error 'build-android-package-in-path
+ "The Android SDK could not be found."))
+
+ (run-ant-build.xml dest "debug")))
;; write-local.properties: path -> void
@@ -85,21 +88,36 @@
-;; prepare-android-package-src-structure: string path -> void
+;; prepare-android-package-src-structure: string (listof string) path -> void
;; Prepares the directory structure we need to compile the package.
-(define (prepare-android-package-src-structure name dest)
+(define (prepare-android-package-src-structure name android-permissions dest)
(make-directory* dest)
;; write out phonegap source files so they're included in the compilation.
(copy-directory/files* phonegap-path dest)
;; Write out the Java class stubs for the build,
;; customizing the phonegap sources for this particular application.
- (write-java-class-stubs name dest)
+ (write-java-class-stubs name android-permissions dest)
;; Write out the icon.
(write-icon dest))
+;; module-records-android-permissions: (listof module-record) -> (listof string)
+;; Consumes a list of modules, and produces a list of the android permissions we need.
+(define (module-records-android-permissions module-records)
+ (let ([ht (make-hash)])
+ (for ([a-record (in-list module-records)])
+ (for ([a-permission (module-record-permissions a-record)])
+ (for ([translated-permission
+ (permission->android-permissions a-permission (lambda () empty))])
+ (hash-set! ht translated-permission #t))))
+ (for/list ([k (in-hash-keys ht)])
+ k)))
+
+
+
+
;; write-icon: path -> void
;; Write out the res/drawable icon image resource.
(define (write-icon dest)
@@ -108,9 +126,9 @@
(build-path dest "res" "drawable" "icon.png")))
-;; write-assets: string path path -> void
+;; write-assets: string path (listof module-record) path -> void
;; Write out the assets subdirectory.
-(define (write-assets name program-path assets-path)
+(define (write-assets name program-path module-records assets-path)
(make-directory* assets-path)
;; Write out index.html
(copy-or-overwrite-file (build-path javascript-support-path "index.html")
@@ -130,16 +148,15 @@
(copy-or-overwrite-file (build-path phonegap-path "assets" "phonegap.js")
(build-path assets-path "phonegap.js"))
- (let ([module-records (get-compiled-modules program-path)])
- ;; Finally, write out the Javascript-translated program.
- (write-program.js program-path module-records
- assets-path)))
+
+ ;; Finally, write out the Javascript-translated program.
+ (write-program.js program-path module-records assets-path))
-;; write-java-class-stubs: string path -> void
+;; write-java-class-stubs: string (listof string) path -> void
;; Write out the java-related files that we'll need to compile the package.
-(define (write-java-class-stubs name dest)
+(define (write-java-class-stubs name android-permissions dest)
(let* ([normal-name (normalize-name name)]
[classname (upper-camel-case normal-name)]
[package (string-append "plt.moby." classname)])
@@ -150,11 +167,7 @@
#:name name
#:package package
#:activity-class (string-append package "." classname)
- #:permissions '()
- #;(apply append
- (map permission->android-permissions
- (pinfo-permissions
- (javascript:compiled-program-pinfo compiled-program)))))
+ #:permissions android-permissions)
;; HACKS!
;; Fix build.xml so it refers to our application.
@@ -332,14 +345,19 @@
[prepare-android-package-src-structure
- (string? path-string? . -> . any)]
+ (string? (listof string?) path-string? . -> . any)]
+ [write-assets
+ (string? path? (listof module-record?) path? . -> . any)]
+
[write-local.properties
(path-string? . -> . any)]
- [write-assets
- (string? path? path? . -> . any)]
[get-apk-in-dest
(path? . -> . bytes?)]
+
+
+ [module-records-android-permissions
+ ((listof module-record?) . -> . (listof string?))]
)
View
12 src/android/server-side-packager/client-side-packager.ss
@@ -5,6 +5,8 @@
racket/list
racket/file
net/url
+
+ (prefix-in js-vm: (planet dyoo/js-vm/private/compile-moby-module))
(prefix-in lap: "../local-android-packager.ss")
(planet dyoo/pack-directory:1/pack-directory))
@@ -55,19 +57,21 @@
;; Encodes the parameters we need to pass in to get a program.
;; TODO: GZIP the data, as soon as the web server can support it.
(define (encode-parameters-in-data name program-path)
- (let* ([tmpdir (make-temporary-file "mztmp~a" 'directory #f)]
+ (let* ([module-records (js-vm:compile-moby-modules program-path)]
+ [tmpdir (make-temporary-file "mztmp~a" 'directory #f)]
[packed-dir-bytes
(dynamic-wind
(lambda () (void))
(lambda ()
- (lap:write-assets name program-path tmpdir)
+ (lap:write-assets name module-records tmpdir)
(parameterize ([current-directory tmpdir])
(pack-current-directory)))
(lambda ()
(delete-directory/files tmpdir)))])
-
(let ([op (open-output-bytes)])
- (write `((name ,name)) op)
+ (write `((name ,name)
+ (permissions ,(lap:module-records-android-permissions module-records)))
+ op)
(write-bytes packed-dir-bytes op)
(get-output-bytes op))))
View
10 src/android/server-side-packager/server-side-packager.ss
@@ -63,7 +63,9 @@
;; Lots of file system stuff here.
;; Creates the basic structure,
(lap:prepare-android-package-src-structure
- (metadata-name metadata) tmpdir)
+ (metadata-name metadata)
+ (metadata-permissions metadata)
+ tmpdir)
;; sets up compilation parameters,
(lap:write-local.properties tmpdir)
;; and customizes the assets by what's been provided
@@ -134,9 +136,15 @@
;; metadata-name: metadata -> string
;; Gets the name given in the metadata.
(define (metadata-name a-metadata)
+ ;; FIXME: do pattern matching here to check.
(second (assoc 'name a-metadata)))
+;; metadata-permissions: metadata -> (listof string)
+(define (metadata-permissions a-metadata)
+ ;; FIXME: do pattern matching here to check.
+ (rest (assoc 'permissions a-metadata)))
+
;; normalize-name-as-filename: string -> string
(define (normalize-name-as-filename a-name)

0 comments on commit 05d2218

Please sign in to comment.