Skip to content

Commit

Permalink
add replace activity name
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberTianzun committed Aug 28, 2015
1 parent 6a4fa96 commit 8ff72f4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
14 changes: 14 additions & 0 deletions lib/core/defaultpolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ module.exports.rewritePackageName = function (context) {
}
}

module.exports.rewriteActivityName = function (context, name) {
if (name.match(context.oldPackageName)) {
return {
source : name,
target : name.replace(context.oldPackageName, context.newPackageName)
}
} else {
return {
source : name,
target : (context.oldPackageName + '.' + name).replace('..', '.')
}
}
}

module.exports.rewriteProvider = function (context, name, authorities) {
if (authorities) {
if (authorities.match(context.oldPackageName)) {
Expand Down
58 changes: 36 additions & 22 deletions lib/handler/manifesthandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports.rewrite = function (filename, context) {
var policy = context.policy.rewriteAction(context, attrs['android:name'])

// replace action define
context.log.i('modify action name:' + policy.source + ' => ' + policy.target)
context.log.i('modify action name: ' + policy.source + ' => ' + policy.target)
replaceHelper.replace(
file.lines,
bufferLineNumber,
Expand All @@ -103,38 +103,52 @@ module.exports.rewrite = function (filename, context) {
}
}
} else if (name.match('activity')) {
// TODO: modify android:name like android:name=".MainActivity"
// if (attrs['android:name'].match(/^\./)) {
// modified = true
// }
// modify android:name like android:name=".MainActivity"
if (attrs['android:name'].match(/^\./)) {
modified = true
var policy = context.policy.rewriteActivityName(context, attrs['android:name'])

// replace activity name define
context.log.i('modify activity name: ' + policy.name + ' => ' + policy.target)
replaceHelper.replace(
file.lines,
bufferLineNumber,
currentLineNumber,
policy.source,
policy.target
)
}
}

if (name.match('service') || name.match('receiver') || name.match('provider')) {
if (context.modifyProcess) {
if (attrs['android:process'] !== undefined) {
if (attrs['android:process'].match(/^:/)) {
return
}
// ...
} else {

modified = true
var policy = context.policy.rewriteProcess(context, name, attrs['android:name'], attrs['android:process'])
modified = true
var policy = context.policy.rewriteProcess(context, name, attrs['android:name'], attrs['android:process'])

// replace service process define
context.log.i('modify ' + name + ' process: ' + policy.source + ' => ' + policy.target)
replaceHelper.replace(
file.lines,
bufferLineNumber,
currentLineNumber,
policy.source,
policy.target
)
// replace service process define
context.log.i('modify ' + name + ' process: ' + policy.source + ' => ' + policy.target)
replaceHelper.replace(
file.lines,
bufferLineNumber,
currentLineNumber,
policy.source,
policy.target
)

// add it to context
if (context.processes === undefined) {
context.processes = { }
// add it to context
if (context.processes === undefined) {
context.processes = { }
}
context.processes[policy.source] = policy.target

}
context.processes[policy.source] = policy.target
}

}
}

Expand Down

0 comments on commit 8ff72f4

Please sign in to comment.