The Customizable Android Transform Gradle Plugin
The initial intent was to wrap WakeLock calls, including those that are in the libraries, to make some behaviour changes. Then we decided to add some more transformations. So, here it is...
If you want to replace, for example, all PowerManager.WakeLock.acquire(timeout) calls in your application, including those in any used library, by your own custom static calls like this:
package com.example.kali;
public class FakeLock {
// ...
public static void smartAcquire(PowerManager.WakeLock wakeLock, long timeout) {
if (timeout > MAX_WAKE_LOCK_TIMEOUT) {
Log.w(TAG, "Long lasting WakeLock: timeout=" + timeout);
timeout = MAX_WAKE_LOCK_TIMEOUT;
}
wakeLock.acquire(timeout);
}
}then all you need is to build and deploy this plugin and then add the next lines to your build.gradle file:
buildscript {
// ...
dependencies {
// ...
classpath 'ru.mail:android-kali:1.0'
}
}
apply plugin: 'ru.mail.android-kali'
kali {
replaceCalls {
ignoreClass 'com.example.kali.FakeLock'
def wakeLockWrappers = [
'android.os.PowerManager$WakeLock.acquire(J)V': 'com.example.kali.FakeLock.smartAcquire'
]
replacements wakeLockWrappers
}
}Yeah, this is a bit of magic from the heart of Java. See How to describe the types and what is in parentheses and after it. Also note that inner class WakeLock is separated from the parent class by the '$', not by the period.
Well... more transformations, I guess.