提交 74155c92 编写于 作者: B Blankj

see 10/29 log

上级 573843b4
* `20/10/29` [add] Fix MessengerUtils startService IllegalStateException. Publish v1.30.4.
* `20/10/28` [add] Fix BusUtils ConcurrentModificationException. Publish v1.30.3.
* `20/10/27` [add] Fix AppUtils#getAppSignatures. Add DeviceUtils#isDevelopmentSettingsEnabled. Publish v1.30.2.
* `20/10/26` [add] Fix AppUtils#isAppForeground. Publish v1.30.1.
......
......@@ -14,8 +14,8 @@ class Config {
static compileSdkVersion = 29
static minSdkVersion = 14
static targetSdkVersion = 29
static versionCode = 1_030_003
static versionName = '1.30.3'// E.g. 1.9.72 => 1,009,072
static versionCode = 1_030_004
static versionName = '1.30.4'// E.g. 1.9.72 => 1,009,072
// lib version
static gradlePluginVersion = '3.5.0'
......
......@@ -2,10 +2,10 @@
Gradle:
```groovy
implementation 'com.blankj:utilcode:1.30.3'
implementation 'com.blankj:utilcode:1.30.4'
// if u use AndroidX, use the following
implementation 'com.blankj:utilcodex:1.30.3'
implementation 'com.blankj:utilcodex:1.30.4'
```
......
......@@ -2,10 +2,10 @@
Gradle:
```groovy
implementation 'com.blankj:utilcode:1.30.3'
implementation 'com.blankj:utilcode:1.30.4'
// if u use AndroidX, use the following
implementation 'com.blankj:utilcodex:1.30.3'
implementation 'com.blankj:utilcodex:1.30.4'
```
......
......@@ -6,6 +6,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
......@@ -48,8 +49,7 @@ public class MessengerUtils {
Log.i("MessengerUtils", "Server service is running.");
return;
}
Intent intent = new Intent(Utils.getApp(), ServerService.class);
Utils.getApp().startService(intent);
startServiceCompat(new Intent(Utils.getApp(), ServerService.class));
return;
}
if (sLocalClient == null) {
......@@ -118,13 +118,26 @@ public class MessengerUtils {
} else {
Intent intent = new Intent(Utils.getApp(), ServerService.class);
intent.putExtras(data);
Utils.getApp().startService(intent);
startServiceCompat(intent);
}
for (Client client : sClientMap.values()) {
client.sendMsg2Server(data);
}
}
private static void startServiceCompat(Intent intent) {
try {
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Utils.getApp().startForegroundService(intent);
} else {
Utils.getApp().startService(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
static class Client {
String mPkgName;
......
......@@ -31,7 +31,7 @@ public final class ServiceUtils {
*
* @return all of the services are running
*/
public static Set getAllRunningServices() {
public static Set<String> getAllRunningServices() {
ActivityManager am = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> info = am.getRunningServices(0x7FFFFFFF);
Set<String> names = new HashSet<>();
......@@ -61,8 +61,16 @@ public final class ServiceUtils {
* @param cls The service class.
*/
public static void startService(@NonNull final Class<?> cls) {
startService(new Intent(Utils.getApp(), cls));
}
/**
* Start the service.
*
* @param intent The intent.
*/
public static void startService(Intent intent) {
try {
Intent intent = new Intent(Utils.getApp(), cls);
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Utils.getApp().startForegroundService(intent);
......@@ -96,8 +104,22 @@ public final class ServiceUtils {
* @return {@code true}: success<br>{@code false}: fail
*/
public static boolean stopService(@NonNull final Class<?> cls) {
Intent intent = new Intent(Utils.getApp(), cls);
return Utils.getApp().stopService(intent);
return stopService(new Intent(Utils.getApp(), cls));
}
/**
* Stop the service.
*
* @param intent The intent.
* @return {@code true}: success<br>{@code false}: fail
*/
public static boolean stopService(@NonNull Intent intent) {
try {
return Utils.getApp().stopService(intent);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
......@@ -145,8 +167,33 @@ public final class ServiceUtils {
public static void bindService(@NonNull final Class<?> cls,
@NonNull final ServiceConnection conn,
final int flags) {
Intent intent = new Intent(Utils.getApp(), cls);
Utils.getApp().bindService(intent, conn, flags);
bindService(new Intent(Utils.getApp(), cls), conn, flags);
}
/**
* Bind the service.
*
* @param intent The intent.
* @param conn The ServiceConnection object.
* @param flags Operation options for the binding.
* <ul>
* <li>0</li>
* <li>{@link Context#BIND_AUTO_CREATE}</li>
* <li>{@link Context#BIND_DEBUG_UNBIND}</li>
* <li>{@link Context#BIND_NOT_FOREGROUND}</li>
* <li>{@link Context#BIND_ABOVE_CLIENT}</li>
* <li>{@link Context#BIND_ALLOW_OOM_MANAGEMENT}</li>
* <li>{@link Context#BIND_WAIVE_PRIORITY}</li>
* </ul>
*/
public static void bindService(@NonNull final Intent intent,
@NonNull final ServiceConnection conn,
final int flags) {
try {
Utils.getApp().bindService(intent, conn, flags);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册