提交 f61eb1a9 编写于 作者: B Blankj

see 05/07 log

上级 5dea602b
import java.text.SimpleDateFormat
apply {
plugin "com.android.application"
plugin "kotlin-android"
......@@ -84,9 +86,81 @@ def configApkName(Project pro) {
variant.getPackageApplicationProvider().get().outputDirectory = new File("${rootDir.path}/apk")
variant.getPackageApplicationProvider().get().outputScope.apkDatas.forEach { apkData ->
apkData.outputFileName = "util" + suffix +
"_" + variant.versionName.replace(".", "_") +
".apk"
"_" + variant.versionName.replace(".", "_") +
".apk"
}
}
}
}
// 打印每一个任务的时间.
class TimingsListener implements TaskExecutionListener, BuildListener {
private long startTime
private timings = []
private String filePath
TimingsListener(String filePath) {
this.filePath = filePath
}
@Override
void beforeExecute(Task task) {
startTime = System.currentTimeMillis()
}
@Override
void afterExecute(Task task, TaskState taskState) {
def ms = System.currentTimeMillis() - startTime
timings.add([ms, task.path])
}
@Override
void buildFinished(BuildResult result) {
ArrayList array = new ArrayList()
for (timing in timings) {
if (timing[0] >= 100) {
array.add(timing)
}
}
try {
if (!array.isEmpty()) {
Collections.sort(array, new Comparator() {
@Override
int compare(Object o1, Object o2) {
return o2[0] - o1[0]
}
})
println "Task timings:"
FileWriter fw = new FileWriter(new File(filePath), true)
array.each {
fw.write(String.format("%7sms %s\n", it[0], it[1]))
printf "%7sms %s\n", it
}
fw.flush()
fw.close()
} else {
new File(filePath).delete()
}
} catch (Exception e) {
}
array.clear()
}
}
\ No newline at end of file
@Override
void buildStarted(Gradle gradle) {}
@Override
void projectsEvaluated(Gradle gradle) {}
@Override
void projectsLoaded(Gradle gradle) {}
@Override
void settingsEvaluated(Settings settings) {}
}
def sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss")
def file = new File(rootProject.buildDir.getAbsolutePath(),
"buildTime_" + sdf.format(new Date(System.currentTimeMillis())) + ".txt")
gradle.addListener(new TimingsListener(file.getAbsolutePath()))
\ No newline at end of file
......@@ -143,21 +143,37 @@ public final class PermissionUtils {
*/
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean isGrantedDrawOverlays() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AppOpsManager aom = (AppOpsManager) Utils.getApp().getSystemService(Context.APP_OPS_SERVICE);
if (aom == null) return false;
int mode = aom.checkOpNoThrow(
"android:system_alert_window",
android.os.Process.myUid(),
Utils.getApp().getPackageName()
);
return mode == AppOpsManager.MODE_ALLOWED || mode == AppOpsManager.MODE_IGNORED;
}
return Settings.canDrawOverlays(Utils.getApp());
}
/**
* Return whether the app can draw on top of other apps.
*
* @return {@code true}: yes<br>{@code false}: no
*/
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean isGrantedDrawOverlays(final Utils.Callback<Boolean> callback) {
return Utils.UTIL_HANDLER.postDelayed(new Runnable() {
@Override
public void run() {
callback.onCall(isGrantedDrawOverlays());
}
}, 200);
}
@RequiresApi(api = Build.VERSION_CODES.M)
public static void requestDrawOverlays(final SimpleCallback callback) {
isGrantedDrawOverlays(new Utils.Callback<Boolean>() {
@Override
public void onCall(Boolean data) {
if (data) {
if (callback != null) callback.onGranted();
return;
}
sSimpleCallback4DrawOverlays = callback;
PermissionActivity.start(Utils.getApp(), PermissionActivity.TYPE_DRAW_OVERLAYS);
}
});
if (isGrantedDrawOverlays()) {
if (callback != null) callback.onGranted();
return;
......
......@@ -30,11 +30,12 @@ public final class ShellUtils {
* @param command The command.
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
* @return the task
*/
public static void execCmdAsync(final String command,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
execCmdAsync(new String[]{command}, isRooted, true, callback);
public static Utils.Task<CommandResult> execCmdAsync(final String command,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
return execCmdAsync(new String[]{command}, isRooted, true, callback);
}
/**
......@@ -43,11 +44,12 @@ public final class ShellUtils {
* @param commands The commands.
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
* @return the task
*/
public static void execCmdAsync(final List<String> commands,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
execCmdAsync(commands == null ? null : commands.toArray(new String[]{}), isRooted, true, callback);
public static Utils.Task<CommandResult> execCmdAsync(final List<String> commands,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
return execCmdAsync(commands == null ? null : commands.toArray(new String[]{}), isRooted, true, callback);
}
/**
......@@ -56,11 +58,12 @@ public final class ShellUtils {
* @param commands The commands.
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
* @return the task
*/
public static void execCmdAsync(final String[] commands,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
execCmdAsync(commands, isRooted, true, callback);
public static Utils.Task<CommandResult> execCmdAsync(final String[] commands,
final boolean isRooted,
final Utils.Callback<CommandResult> callback) {
return execCmdAsync(commands, isRooted, true, callback);
}
/**
......@@ -70,12 +73,13 @@ public final class ShellUtils {
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @param callback The callback.
* @return the task
*/
public static void execCmdAsync(final String command,
final boolean isRooted,
final boolean isNeedResultMsg,
final Utils.Callback<CommandResult> callback) {
execCmdAsync(new String[]{command}, isRooted, isNeedResultMsg, callback);
public static Utils.Task<CommandResult> execCmdAsync(final String command,
final boolean isRooted,
final boolean isNeedResultMsg,
final Utils.Callback<CommandResult> callback) {
return execCmdAsync(new String[]{command}, isRooted, isNeedResultMsg, callback);
}
/**
......@@ -85,12 +89,13 @@ public final class ShellUtils {
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @param callback The callback.
* @return the task
*/
public static void execCmdAsync(final List<String> commands,
final boolean isRooted,
final boolean isNeedResultMsg,
final Utils.Callback<CommandResult> callback) {
execCmdAsync(commands == null ? null : commands.toArray(new String[]{}),
public static Utils.Task<CommandResult> execCmdAsync(final List<String> commands,
final boolean isRooted,
final boolean isNeedResultMsg,
final Utils.Callback<CommandResult> callback) {
return execCmdAsync(commands == null ? null : commands.toArray(new String[]{}),
isRooted,
isNeedResultMsg,
callback);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册