Bladeren bron

1.3.4 优化:在通知栏显示sn号,方便排查问题

xulh 9 maanden geleden
bovenliggende
commit
966c9bc9e7

+ 2 - 0
app/src/main/AndroidManifest.xml

@@ -5,6 +5,8 @@
 
     <uses-permission android:name="android.permission.INTERNET"/>
 
+    <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="com.dopamine.provider.READ" />
 
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

+ 13 - 13
app/src/main/java/com/hh/hhomc/keeplive/LocalService.kt

@@ -6,11 +6,11 @@ import android.content.Context
 import android.content.Intent
 import android.os.Build
 import android.os.IBinder
-import android.util.Log
 import androidx.annotation.Nullable
 import com.common.lib_base.utils.log.AppLogUtils
 import com.hh.hhomc.R
 import com.hh.hhomc.WxAidlInterface
+import com.hh.hhomc.utils.DeviceUtils
 
 
 class LocalService:Service() {
@@ -23,12 +23,12 @@ class LocalService:Service() {
 
     inner class MyBinder: WxAidlInterface.Stub(){
         override fun basicTypes(
-            anInt: Int,
-            aLong: Long,
-            aBoolean: Boolean,
-            aFloat: Float,
-            aDouble: Double,
-            aString: String?
+                anInt: Int,
+                aLong: Long,
+                aBoolean: Boolean,
+                aFloat: Float,
+                aDouble: Double,
+                aString: String?
         ) {
         }
 
@@ -54,7 +54,7 @@ class LocalService:Service() {
             var channel = NotificationChannel("101", "test", NotificationManager.IMPORTANCE_HIGH);
             notificationManager.createNotificationChannel(channel)
         }
-        startForeground(1,getNotification());
+        startForeground(1, getNotification());
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
             startService(Intent(this, InnnerService::class.java))
         }
@@ -64,7 +64,7 @@ class LocalService:Service() {
         var builder = Notification.Builder(this)
             .setSmallIcon(R.mipmap.ic_launcher)
             .setContentTitle("hhomc服务")
-            .setContentText("我正在运行");
+            .setContentText("我正在运行——SN:" + DeviceUtils.getDeviceSN());
         //设置Notification的ChannelID,否则不能正常显示
         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             builder.setChannelId("101");
@@ -80,8 +80,8 @@ class LocalService:Service() {
             //连接中断后回调
             startService(Intent(this@LocalService, RemoteService::class.java))
             bindService(
-                Intent(this@LocalService, RemoteService::class.java), serviceConnection,
-                Context.BIND_AUTO_CREATE
+                    Intent(this@LocalService, RemoteService::class.java), serviceConnection,
+                    Context.BIND_AUTO_CREATE
             )
         }
 
@@ -98,7 +98,7 @@ class LocalService:Service() {
                 var channel = NotificationChannel("101", "test", NotificationManager.IMPORTANCE_HIGH);
                 notificationManager.createNotificationChannel(channel);
             }
-            startForeground(1,getNotification())
+            startForeground(1, getNotification())
             stopSelf()
         }
 
@@ -106,7 +106,7 @@ class LocalService:Service() {
             var builder = Notification.Builder(this)
                 .setSmallIcon(R.mipmap.ic_launcher)
                 .setContentTitle("hhomc服务")
-                .setContentText("我正在运行");
+                .setContentText("我正在运行——SN:" + DeviceUtils.getDeviceSN());
             //设置Notification的ChannelID,否则不能正常显示
             if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                 builder.setChannelId("101");

+ 13 - 13
app/src/main/java/com/hh/hhomc/keeplive/RemoteService.kt

@@ -6,11 +6,11 @@ import android.content.Context
 import android.content.Intent
 import android.os.Build
 import android.os.IBinder
-import android.util.Log
 import androidx.annotation.Nullable
 import com.common.lib_base.utils.log.AppLogUtils
 import com.hh.hhomc.R
 import com.hh.hhomc.WxAidlInterface
+import com.hh.hhomc.utils.DeviceUtils
 
 
 class RemoteService: Service() {
@@ -21,12 +21,12 @@ class RemoteService: Service() {
 
     class MyBinder : WxAidlInterface.Stub(){
         override fun basicTypes(
-            anInt: Int,
-            aLong: Long,
-            aBoolean: Boolean,
-            aFloat: Float,
-            aDouble: Double,
-            aString: String?
+                anInt: Int,
+                aLong: Long,
+                aBoolean: Boolean,
+                aFloat: Float,
+                aDouble: Double,
+                aString: String?
         ) {
         }
     }
@@ -45,7 +45,7 @@ class RemoteService: Service() {
             var channel = NotificationChannel("101", "test", NotificationManager.IMPORTANCE_HIGH);
             notificationManager.createNotificationChannel(channel);
         }
-        startForeground(1,getNotification());
+        startForeground(1, getNotification());
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
             startService(Intent(this, LocalService.InnnerService::class.java))
         }
@@ -55,7 +55,7 @@ class RemoteService: Service() {
         var builder = Notification.Builder(this)
             .setSmallIcon(R.mipmap.ic_launcher)
             .setContentTitle("hhomc服务")
-            .setContentText("我正在运行");
+            .setContentText("我正在运行——SN:" + DeviceUtils.getDeviceSN());
         //设置Notification的ChannelID,否则不能正常显示
         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             builder.setChannelId("101");
@@ -81,8 +81,8 @@ class RemoteService: Service() {
             //连接中断后回调
             startService(Intent(this@RemoteService, LocalService::class.java))
             bindService(
-                Intent(this@RemoteService, LocalService::class.java), serviceConnection,
-                Context.BIND_AUTO_CREATE
+                    Intent(this@RemoteService, LocalService::class.java), serviceConnection,
+                    Context.BIND_AUTO_CREATE
             )
         }
 
@@ -100,7 +100,7 @@ class RemoteService: Service() {
                 var channel = NotificationChannel("101", "test", NotificationManager.IMPORTANCE_HIGH);
                 notificationManager.createNotificationChannel(channel);
             }
-            startForeground(1,getNotification())
+            startForeground(1, getNotification())
             stopSelf()
         }
 
@@ -108,7 +108,7 @@ class RemoteService: Service() {
             var builder = Notification.Builder(this)
                 .setSmallIcon(R.mipmap.ic_launcher)
                 .setContentTitle("hhomc服务")
-                .setContentText("我正在运行");
+                .setContentText("我正在运行——SN:" + DeviceUtils.getDeviceSN());
             //设置Notification的ChannelID,否则不能正常显示
             if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                 builder.setChannelId("101");

+ 1 - 1
app/src/main/java/com/hh/hhomc/services/BackgroundService.java

@@ -324,7 +324,7 @@ public class BackgroundService extends Service {
         Notification.Builder builder = new Notification.Builder(this)
                 .setSmallIcon(R.mipmap.ic_launcher)
                 .setContentTitle("hhomc服务")
-                .setContentText("我正在运行")
+                .setContentText("我正在运行——SN:"+DeviceUtils.getDeviceSN())
                 .setAutoCancel(true);
 
         //设置Notification的ChannelID,否则不能正常显示

+ 8 - 0
app/src/main/java/com/hh/hhomc/utils/DeviceUtils.java

@@ -9,6 +9,8 @@ import android.os.Build;
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.common.lib_base.utils.log.AppLogUtils;
+
 import java.lang.reflect.Method;
 import java.net.Inet4Address;
 import java.net.InetAddress;
@@ -53,12 +55,18 @@ public final class DeviceUtils {
         // 兼容版本11的紫鹏
         if (TextUtils.isEmpty(serial)) {
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                // 注意清单文件加上READ_PHONE_STATE权限,不然还是会获取失败
                 serial = Build.getSerial();
             }else{
                 serial = Build.SERIAL;
             }
         }
 
+        if (TextUtils.isEmpty(serial)) {
+            serial = "sn号获取失败";
+        }
+
+
         return serial;
     }
 

+ 2 - 2
config.gradle

@@ -7,8 +7,8 @@ ext {
 //            minSdkVersion    : 24,
             minSdkVersion    : 21,
             targetSdkVersion : 30,
-            versionCode      : 9,
-            versionName      : "1.3.3"
+            versionCode      : 10,
+            versionName      : "1.3.4"
     ]
     //依赖 配置
     dependencies = [