Skip to content

Commit f61eb1a

Browse files
committed
see 05/07 log
1 parent 5dea602 commit f61eb1a

File tree

3 files changed

+130
-35
lines changed

3 files changed

+130
-35
lines changed

config_app.gradle

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.text.SimpleDateFormat
2+
13
apply {
24
plugin "com.android.application"
35
plugin "kotlin-android"
@@ -84,9 +86,81 @@ def configApkName(Project pro) {
8486
variant.getPackageApplicationProvider().get().outputDirectory = new File("${rootDir.path}/apk")
8587
variant.getPackageApplicationProvider().get().outputScope.apkDatas.forEach { apkData ->
8688
apkData.outputFileName = "util" + suffix +
87-
"_" + variant.versionName.replace(".", "_") +
88-
".apk"
89+
"_" + variant.versionName.replace(".", "_") +
90+
".apk"
91+
}
92+
}
93+
}
94+
}
95+
96+
97+
// 打印每一个任务的时间.
98+
class TimingsListener implements TaskExecutionListener, BuildListener {
99+
private long startTime
100+
private timings = []
101+
private String filePath
102+
103+
TimingsListener(String filePath) {
104+
this.filePath = filePath
105+
}
106+
107+
@Override
108+
void beforeExecute(Task task) {
109+
startTime = System.currentTimeMillis()
110+
}
111+
112+
@Override
113+
void afterExecute(Task task, TaskState taskState) {
114+
def ms = System.currentTimeMillis() - startTime
115+
timings.add([ms, task.path])
116+
}
117+
118+
@Override
119+
void buildFinished(BuildResult result) {
120+
ArrayList array = new ArrayList()
121+
for (timing in timings) {
122+
if (timing[0] >= 100) {
123+
array.add(timing)
89124
}
90125
}
126+
try {
127+
if (!array.isEmpty()) {
128+
Collections.sort(array, new Comparator() {
129+
@Override
130+
int compare(Object o1, Object o2) {
131+
return o2[0] - o1[0]
132+
}
133+
})
134+
println "Task timings:"
135+
FileWriter fw = new FileWriter(new File(filePath), true)
136+
array.each {
137+
fw.write(String.format("%7sms %s\n", it[0], it[1]))
138+
printf "%7sms %s\n", it
139+
}
140+
fw.flush()
141+
fw.close()
142+
} else {
143+
new File(filePath).delete()
144+
}
145+
} catch (Exception e) {
146+
}
147+
array.clear()
91148
}
92-
}
149+
150+
@Override
151+
void buildStarted(Gradle gradle) {}
152+
153+
@Override
154+
void projectsEvaluated(Gradle gradle) {}
155+
156+
@Override
157+
void projectsLoaded(Gradle gradle) {}
158+
159+
@Override
160+
void settingsEvaluated(Settings settings) {}
161+
}
162+
163+
def sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss")
164+
def file = new File(rootProject.buildDir.getAbsolutePath(),
165+
"buildTime_" + sdf.format(new Date(System.currentTimeMillis())) + ".txt")
166+
gradle.addListener(new TimingsListener(file.getAbsolutePath()))

utilcode/lib/src/main/java/com/blankj/utilcode/util/PermissionUtils.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,37 @@ private static void startWriteSettingsActivity(final Activity activity, final in
143143
*/
144144
@RequiresApi(api = Build.VERSION_CODES.M)
145145
public static boolean isGrantedDrawOverlays() {
146-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
147-
AppOpsManager aom = (AppOpsManager) Utils.getApp().getSystemService(Context.APP_OPS_SERVICE);
148-
if (aom == null) return false;
149-
int mode = aom.checkOpNoThrow(
150-
"android:system_alert_window",
151-
android.os.Process.myUid(),
152-
Utils.getApp().getPackageName()
153-
);
154-
return mode == AppOpsManager.MODE_ALLOWED || mode == AppOpsManager.MODE_IGNORED;
155-
}
156146
return Settings.canDrawOverlays(Utils.getApp());
157147
}
158148

149+
/**
150+
* Return whether the app can draw on top of other apps.
151+
*
152+
* @return {@code true}: yes<br>{@code false}: no
153+
*/
154+
@RequiresApi(api = Build.VERSION_CODES.M)
155+
public static boolean isGrantedDrawOverlays(final Utils.Callback<Boolean> callback) {
156+
return Utils.UTIL_HANDLER.postDelayed(new Runnable() {
157+
@Override
158+
public void run() {
159+
callback.onCall(isGrantedDrawOverlays());
160+
}
161+
}, 200);
162+
}
163+
159164
@RequiresApi(api = Build.VERSION_CODES.M)
160165
public static void requestDrawOverlays(final SimpleCallback callback) {
166+
isGrantedDrawOverlays(new Utils.Callback<Boolean>() {
167+
@Override
168+
public void onCall(Boolean data) {
169+
if (data) {
170+
if (callback != null) callback.onGranted();
171+
return;
172+
}
173+
sSimpleCallback4DrawOverlays = callback;
174+
PermissionActivity.start(Utils.getApp(), PermissionActivity.TYPE_DRAW_OVERLAYS);
175+
}
176+
});
161177
if (isGrantedDrawOverlays()) {
162178
if (callback != null) callback.onGranted();
163179
return;

utilcode/lib/src/main/java/com/blankj/utilcode/util/ShellUtils.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ private ShellUtils() {
3030
* @param command The command.
3131
* @param isRooted True to use root, false otherwise.
3232
* @param callback The callback.
33+
* @return the task
3334
*/
34-
public static void execCmdAsync(final String command,
35-
final boolean isRooted,
36-
final Utils.Callback<CommandResult> callback) {
37-
execCmdAsync(new String[]{command}, isRooted, true, callback);
35+
public static Utils.Task<CommandResult> execCmdAsync(final String command,
36+
final boolean isRooted,
37+
final Utils.Callback<CommandResult> callback) {
38+
return execCmdAsync(new String[]{command}, isRooted, true, callback);
3839
}
3940

4041
/**
@@ -43,11 +44,12 @@ public static void execCmdAsync(final String command,
4344
* @param commands The commands.
4445
* @param isRooted True to use root, false otherwise.
4546
* @param callback The callback.
47+
* @return the task
4648
*/
47-
public static void execCmdAsync(final List<String> commands,
48-
final boolean isRooted,
49-
final Utils.Callback<CommandResult> callback) {
50-
execCmdAsync(commands == null ? null : commands.toArray(new String[]{}), isRooted, true, callback);
49+
public static Utils.Task<CommandResult> execCmdAsync(final List<String> commands,
50+
final boolean isRooted,
51+
final Utils.Callback<CommandResult> callback) {
52+
return execCmdAsync(commands == null ? null : commands.toArray(new String[]{}), isRooted, true, callback);
5153
}
5254

5355
/**
@@ -56,11 +58,12 @@ public static void execCmdAsync(final List<String> commands,
5658
* @param commands The commands.
5759
* @param isRooted True to use root, false otherwise.
5860
* @param callback The callback.
61+
* @return the task
5962
*/
60-
public static void execCmdAsync(final String[] commands,
61-
final boolean isRooted,
62-
final Utils.Callback<CommandResult> callback) {
63-
execCmdAsync(commands, isRooted, true, callback);
63+
public static Utils.Task<CommandResult> execCmdAsync(final String[] commands,
64+
final boolean isRooted,
65+
final Utils.Callback<CommandResult> callback) {
66+
return execCmdAsync(commands, isRooted, true, callback);
6467
}
6568

6669
/**
@@ -70,12 +73,13 @@ public static void execCmdAsync(final String[] commands,
7073
* @param isRooted True to use root, false otherwise.
7174
* @param isNeedResultMsg True to return the message of result, false otherwise.
7275
* @param callback The callback.
76+
* @return the task
7377
*/
74-
public static void execCmdAsync(final String command,
75-
final boolean isRooted,
76-
final boolean isNeedResultMsg,
77-
final Utils.Callback<CommandResult> callback) {
78-
execCmdAsync(new String[]{command}, isRooted, isNeedResultMsg, callback);
78+
public static Utils.Task<CommandResult> execCmdAsync(final String command,
79+
final boolean isRooted,
80+
final boolean isNeedResultMsg,
81+
final Utils.Callback<CommandResult> callback) {
82+
return execCmdAsync(new String[]{command}, isRooted, isNeedResultMsg, callback);
7983
}
8084

8185
/**
@@ -85,12 +89,13 @@ public static void execCmdAsync(final String command,
8589
* @param isRooted True to use root, false otherwise.
8690
* @param isNeedResultMsg True to return the message of result, false otherwise.
8791
* @param callback The callback.
92+
* @return the task
8893
*/
89-
public static void execCmdAsync(final List<String> commands,
90-
final boolean isRooted,
91-
final boolean isNeedResultMsg,
92-
final Utils.Callback<CommandResult> callback) {
93-
execCmdAsync(commands == null ? null : commands.toArray(new String[]{}),
94+
public static Utils.Task<CommandResult> execCmdAsync(final List<String> commands,
95+
final boolean isRooted,
96+
final boolean isNeedResultMsg,
97+
final Utils.Callback<CommandResult> callback) {
98+
return execCmdAsync(commands == null ? null : commands.toArray(new String[]{}),
9499
isRooted,
95100
isNeedResultMsg,
96101
callback);

0 commit comments

Comments
 (0)