123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
-
-
- var fs = require('fs');
- var xml = require('cordova-common').xmlHelpers;
-
- var DEFAULT_ORIENTATION = 'default';
-
-
- function AndroidManifest (path) {
- this.path = path;
- this.doc = xml.parseElementtreeSync(path);
- if (this.doc.getroot().tag !== 'manifest') {
- throw new Error('AndroidManifest at ' + path + ' has incorrect root node name (expected "manifest")');
- }
- }
-
- AndroidManifest.prototype.getVersionName = function () {
- return this.doc.getroot().attrib['android:versionName'];
- };
-
- AndroidManifest.prototype.setVersionName = function (versionName) {
- this.doc.getroot().attrib['android:versionName'] = versionName;
- return this;
- };
-
- AndroidManifest.prototype.getVersionCode = function () {
- return this.doc.getroot().attrib['android:versionCode'];
- };
-
- AndroidManifest.prototype.setVersionCode = function (versionCode) {
- this.doc.getroot().attrib['android:versionCode'] = versionCode;
- return this;
- };
-
- AndroidManifest.prototype.getPackageId = function () {
- return this.doc.getroot().attrib['package'];
- };
-
- AndroidManifest.prototype.setPackageId = function (pkgId) {
- this.doc.getroot().attrib['package'] = pkgId;
- return this;
- };
-
- AndroidManifest.prototype.getActivity = function () {
- var activity = this.doc.getroot().find('./application/activity');
- return {
- getName: function () {
- return activity.attrib['android:name'];
- },
- setName: function (name) {
- if (!name) {
- delete activity.attrib['android:name'];
- } else {
- activity.attrib['android:name'] = name;
- }
- return this;
- },
- getOrientation: function () {
- return activity.attrib['android:screenOrientation'];
- },
- setOrientation: function (orientation) {
- if (!orientation || orientation.toLowerCase() === DEFAULT_ORIENTATION) {
- delete activity.attrib['android:screenOrientation'];
- } else {
- activity.attrib['android:screenOrientation'] = orientation;
- }
- return this;
- },
- getLaunchMode: function () {
- return activity.attrib['android:launchMode'];
- },
- setLaunchMode: function (launchMode) {
- if (!launchMode) {
- delete activity.attrib['android:launchMode'];
- } else {
- activity.attrib['android:launchMode'] = launchMode;
- }
- return this;
- }
- };
- };
-
- AndroidManifest.prototype.getDebuggable = function () {
- return this.doc.getroot().find('./application').attrib['android:debuggable'] === 'true';
- };
-
- AndroidManifest.prototype.setDebuggable = function (value) {
- var application = this.doc.getroot().find('./application');
- if (value) {
- application.attrib['android:debuggable'] = 'true';
- } else {
-
- delete application.attrib['android:debuggable'];
- }
- return this;
- };
-
-
- AndroidManifest.prototype.write = function (destPath) {
- fs.writeFileSync(destPath || this.path, this.doc.write({ indent: 4 }), 'utf-8');
- };
-
- module.exports = AndroidManifest;
|