Skip to content

Commit 74155c9

Browse files
committed
see 10/29 log
1 parent 573843b commit 74155c9

6 files changed

Lines changed: 76 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* `20/10/29` [add] Fix MessengerUtils startService IllegalStateException. Publish v1.30.4.
12
* `20/10/28` [add] Fix BusUtils ConcurrentModificationException. Publish v1.30.3.
23
* `20/10/27` [add] Fix AppUtils#getAppSignatures. Add DeviceUtils#isDevelopmentSettingsEnabled. Publish v1.30.2.
34
* `20/10/26` [add] Fix AppUtils#isAppForeground. Publish v1.30.1.

buildSrc/src/main/groovy/Config.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Config {
1414
static compileSdkVersion = 29
1515
static minSdkVersion = 14
1616
static targetSdkVersion = 29
17-
static versionCode = 1_030_003
18-
static versionName = '1.30.3'// E.g. 1.9.72 => 1,009,072
17+
static versionCode = 1_030_004
18+
static versionName = '1.30.4'// E.g. 1.9.72 => 1,009,072
1919

2020
// lib version
2121
static gradlePluginVersion = '3.5.0'

lib/utilcode/README-CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.30.3'
5+
implementation 'com.blankj:utilcode:1.30.4'
66
77
// if u use AndroidX, use the following
8-
implementation 'com.blankj:utilcodex:1.30.3'
8+
implementation 'com.blankj:utilcodex:1.30.4'
99
```
1010

1111

lib/utilcode/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.30.3'
5+
implementation 'com.blankj:utilcode:1.30.4'
66
77
// if u use AndroidX, use the following
8-
implementation 'com.blankj:utilcodex:1.30.3'
8+
implementation 'com.blankj:utilcodex:1.30.4'
99
```
1010

1111

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.Context;
77
import android.content.Intent;
88
import android.content.ServiceConnection;
9+
import android.os.Build;
910
import android.os.Bundle;
1011
import android.os.Handler;
1112
import android.os.IBinder;
@@ -48,8 +49,7 @@ public static void register() {
4849
Log.i("MessengerUtils", "Server service is running.");
4950
return;
5051
}
51-
Intent intent = new Intent(Utils.getApp(), ServerService.class);
52-
Utils.getApp().startService(intent);
52+
startServiceCompat(new Intent(Utils.getApp(), ServerService.class));
5353
return;
5454
}
5555
if (sLocalClient == null) {
@@ -118,13 +118,26 @@ public static void post(@NonNull String key, @NonNull Bundle data) {
118118
} else {
119119
Intent intent = new Intent(Utils.getApp(), ServerService.class);
120120
intent.putExtras(data);
121-
Utils.getApp().startService(intent);
121+
startServiceCompat(intent);
122122
}
123123
for (Client client : sClientMap.values()) {
124124
client.sendMsg2Server(data);
125125
}
126126
}
127127

128+
private static void startServiceCompat(Intent intent) {
129+
try {
130+
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
131+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
132+
Utils.getApp().startForegroundService(intent);
133+
} else {
134+
Utils.getApp().startService(intent);
135+
}
136+
} catch (Exception e) {
137+
e.printStackTrace();
138+
}
139+
}
140+
128141
static class Client {
129142

130143
String mPkgName;

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

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private ServiceUtils() {
3131
*
3232
* @return all of the services are running
3333
*/
34-
public static Set getAllRunningServices() {
34+
public static Set<String> getAllRunningServices() {
3535
ActivityManager am = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE);
3636
List<RunningServiceInfo> info = am.getRunningServices(0x7FFFFFFF);
3737
Set<String> names = new HashSet<>();
@@ -61,8 +61,16 @@ public static void startService(@NonNull final String className) {
6161
* @param cls The service class.
6262
*/
6363
public static void startService(@NonNull final Class<?> cls) {
64+
startService(new Intent(Utils.getApp(), cls));
65+
}
66+
67+
/**
68+
* Start the service.
69+
*
70+
* @param intent The intent.
71+
*/
72+
public static void startService(Intent intent) {
6473
try {
65-
Intent intent = new Intent(Utils.getApp(), cls);
6674
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
6775
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
6876
Utils.getApp().startForegroundService(intent);
@@ -96,8 +104,22 @@ public static boolean stopService(@NonNull final String className) {
96104
* @return {@code true}: success<br>{@code false}: fail
97105
*/
98106
public static boolean stopService(@NonNull final Class<?> cls) {
99-
Intent intent = new Intent(Utils.getApp(), cls);
100-
return Utils.getApp().stopService(intent);
107+
return stopService(new Intent(Utils.getApp(), cls));
108+
}
109+
110+
/**
111+
* Stop the service.
112+
*
113+
* @param intent The intent.
114+
* @return {@code true}: success<br>{@code false}: fail
115+
*/
116+
public static boolean stopService(@NonNull Intent intent) {
117+
try {
118+
return Utils.getApp().stopService(intent);
119+
} catch (Exception e) {
120+
e.printStackTrace();
121+
return false;
122+
}
101123
}
102124

103125
/**
@@ -145,8 +167,33 @@ public static void bindService(@NonNull final String className,
145167
public static void bindService(@NonNull final Class<?> cls,
146168
@NonNull final ServiceConnection conn,
147169
final int flags) {
148-
Intent intent = new Intent(Utils.getApp(), cls);
149-
Utils.getApp().bindService(intent, conn, flags);
170+
bindService(new Intent(Utils.getApp(), cls), conn, flags);
171+
}
172+
173+
/**
174+
* Bind the service.
175+
*
176+
* @param intent The intent.
177+
* @param conn The ServiceConnection object.
178+
* @param flags Operation options for the binding.
179+
* <ul>
180+
* <li>0</li>
181+
* <li>{@link Context#BIND_AUTO_CREATE}</li>
182+
* <li>{@link Context#BIND_DEBUG_UNBIND}</li>
183+
* <li>{@link Context#BIND_NOT_FOREGROUND}</li>
184+
* <li>{@link Context#BIND_ABOVE_CLIENT}</li>
185+
* <li>{@link Context#BIND_ALLOW_OOM_MANAGEMENT}</li>
186+
* <li>{@link Context#BIND_WAIVE_PRIORITY}</li>
187+
* </ul>
188+
*/
189+
public static void bindService(@NonNull final Intent intent,
190+
@NonNull final ServiceConnection conn,
191+
final int flags) {
192+
try {
193+
Utils.getApp().bindService(intent, conn, flags);
194+
} catch (Exception e) {
195+
e.printStackTrace();
196+
}
150197
}
151198

152199
/**

0 commit comments

Comments
 (0)