diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 0d156937..663459aa 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -3,18 +3,9 @@ - diff --git a/.idea/misc.xml b/.idea/misc.xml index 974f06ab..f5c6d9eb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ba3c3897..f26011c6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.raincat.dolby_beta" minSdkVersion 21 targetSdkVersion 29 - versionCode 320 - versionName "3.2.0" + versionCode 321 + versionName "3.2.1" externalNativeBuild { cmake { @@ -26,7 +26,7 @@ android { buildTypes { release { buildConfigField "boolean", "LOG_DEBUG", "false" //不显示log -// shrinkResources false //资源压缩 + shrinkResources false //资源压缩 minifyEnabled false //混淆 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ba10a0b..98352b6b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,9 +4,9 @@ package="com.raincat.dolby_beta"> = Build.VERSION_CODES.M) + NotificationHelper.getInstance(context).sendUnLockNotification(context, 0x10, "UnblockNeteaseMusic产生致命错误", "UnblockNeteaseMusic产生致命错误", intent.getStringExtra("content")); + else + XposedBridge.log("UnblockNeteaseMusic产生致命错误:" + intent.getStringExtra("content")); + } } }, intentFilter); } else if (processName.equals(PACKAGE_NAME + ":play") && SettingHelper.getInstance().getSetting(SettingHelper.master_key)) { //音源代理 new ProxyHook(context, versionCode, true); IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(msg_hookPlayProcess); + intentFilter.addAction(msg_hook_play_process); context.registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context c, Intent intent) { - if (msg_hookPlayProcess.equals(intent.getAction())) { + if (msg_hook_play_process.equals(intent.getAction())) { ClassHelper.getCacheClassList(context, versionCode, () -> { new EAPIHook(context); new CdnHook(context, versionCode); @@ -126,7 +139,7 @@ public void onReceive(Context c, Intent intent) { } } }, intentFilter); - context.sendBroadcast(new Intent(msg_playProcessInitFinish)); + context.sendBroadcast(new Intent(msg_play_process_init_finish)); } } }); diff --git a/app/src/main/java/com/raincat/dolby_beta/helper/ExtraHelper.java b/app/src/main/java/com/raincat/dolby_beta/helper/ExtraHelper.java index 3fcd1a19..6fe7b518 100644 --- a/app/src/main/java/com/raincat/dolby_beta/helper/ExtraHelper.java +++ b/app/src/main/java/com/raincat/dolby_beta/helper/ExtraHelper.java @@ -28,6 +28,8 @@ public class ExtraHelper { public static final String SIGN_SONG_TIME = "sign_song_time"; //脚本运行情况 public static final String SCRIPT_STATUS = "script_status"; + //脚本运行重试 + public static final String SCRIPT_RETRY = "script_retry"; //初始化数据库 public static void init(Context context) { diff --git a/app/src/main/java/com/raincat/dolby_beta/helper/NotificationHelper.java b/app/src/main/java/com/raincat/dolby_beta/helper/NotificationHelper.java index bc663c1c..1fd8f245 100644 --- a/app/src/main/java/com/raincat/dolby_beta/helper/NotificationHelper.java +++ b/app/src/main/java/com/raincat/dolby_beta/helper/NotificationHelper.java @@ -4,7 +4,6 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -18,9 +17,7 @@ import android.service.notification.StatusBarNotification; import android.text.TextUtils; -import java.util.HashMap; import java.util.List; -import java.util.Map; import androidx.annotation.RequiresApi; @@ -55,130 +52,37 @@ private NotificationHelper(Context context) { * @param content 详细内容 */ @RequiresApi(api = Build.VERSION_CODES.M) - public void sendUnLockNotification(Context context, int appId, String ticker, String title, String content, int resId) { - sendUnLockNotification(context, appId, true, true, ticker, title, content, resId, null, null); - } - - /** - * 设置一个不常驻通知栏的Notification - * - * @param appId 标识符 - * @param isVibrate 是否震动 - * @param isSound 是否发声 - * @param ticker 通知首次出现在通知栏时提醒的文字 - * @param title 标题 - * @param content 详细内容 - */ - @RequiresApi(api = Build.VERSION_CODES.M) - public void sendUnLockNotification(Context context, int appId, boolean isVibrate, boolean isSound, String ticker, String title, String content, int resId) { - sendUnLockNotification(context, appId, isVibrate, isSound, ticker, title, content, resId, null, null); - } - - /** - * 设置一个不常驻通知栏的Notification,带点击跳转效果 - * - * @param appId 标识符 - * @param ticker 通知首次出现在通知栏时提醒的文字 - * @param title 标题 - * @param content 详细内容 - * @param className 需要跳转的Activity名字 - */ - @RequiresApi(api = Build.VERSION_CODES.M) - public void sendUnLockNotification(Context context, int appId, String ticker, String title, String content, int resId, String className) { - sendUnLockNotification(context, appId, true, true, ticker, title, content, resId, className, null); - } - - /** - * 设置一个不常驻通知栏的Notification,带点击跳转效果 - * - * @param appId 标识符 - * @param isVibrate 是否震动 - * @param isSound 是否发声 - * @param ticker 通知首次出现在通知栏时提醒的文字 - * @param title 标题 - * @param content 详细内容 - * @param className 需要跳转的Activity名字 - */ - @RequiresApi(api = Build.VERSION_CODES.M) - public void sendUnLockNotification(Context context, int appId, boolean isVibrate, boolean isSound, String ticker, String title, String content, int resId, String className) { - sendUnLockNotification(context, appId, isVibrate, isSound, ticker, title, content, resId, className, null); - } - - /** - * 设置一个不常驻通知栏的Notification,带点击跳转效果,带传参 - * - * @param appId 标识符 - * @param isVibrate 是否震动 - * @param isSound 是否发声 - * @param ticker 通知首次出现在通知栏时提醒的文字 - * @param title 标题 - * @param content 详细内容 - * @param className 需要跳转的Activity名字 - * @param param 往跳转的Activity传参 - */ - @RequiresApi(api = Build.VERSION_CODES.M) - public void sendUnLockNotification(Context context, int appId, boolean isVibrate, boolean isSound, String ticker, String title, String content, int resId, String className, HashMap param) { + public void sendUnLockNotification(Context context, int appId, String ticker, String title, String content) { Notification.Builder builder = new Notification.Builder(context); - if (resId != 0) - builder.setSmallIcon(resId); - else { - ApplicationInfo applicationInfo = context.getApplicationInfo(); - Drawable drawable = applicationInfo.loadIcon(context.getPackageManager()); - Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), - drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); - Canvas canvas = new Canvas(bitmap); - drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); - drawable.draw(canvas); - Icon icon = Icon.createWithBitmap(bitmap); - builder.setSmallIcon(icon); - } - builder.setContentTitle(title); - builder.setTicker(ticker); - builder.setAutoCancel(true); - builder.setDefaults(Notification.DEFAULT_LIGHTS); + ApplicationInfo applicationInfo = context.getApplicationInfo(); + Drawable drawable = applicationInfo.loadIcon(context.getPackageManager()); + Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), + drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); + drawable.draw(canvas); + Icon icon = Icon.createWithBitmap(bitmap); + builder.setSmallIcon(icon) + .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)) + .setContentTitle(title) + .setTicker(ticker) + .setAutoCancel(true) + .setDefaults(Notification.DEFAULT_LIGHTS); if (Build.VERSION.SDK_INT >= 26) { - NotificationChannel notificationChannel = new NotificationChannel(context.getPackageName() + appId, "通知", NotificationManager.IMPORTANCE_HIGH); - builder.setChannelId(context.getPackageName() + appId); + NotificationChannel notificationChannel = new NotificationChannel(context.getPackageName() + appId, "UnblockNeteaseMusic", NotificationManager.IMPORTANCE_HIGH); notificationChannel.enableLights(true); - notificationChannel.enableVibration(isVibrate); + notificationChannel.enableVibration(true); notificationChannel.setVibrationPattern(new long[]{200L, 200L, 200L, 200L}); - if (isSound) { - notificationChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), Notification.AUDIO_ATTRIBUTES_DEFAULT); - } else { - notificationChannel.setSound(null, null); - } - - deleteNoNumberNotification(this.mNotificationManager, "UnblockNeteaseMusic"); + notificationChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), Notification.AUDIO_ATTRIBUTES_DEFAULT); + builder.setChannelId(context.getPackageName() + appId); mNotificationManager.createNotificationChannel(notificationChannel); } else { - if (isVibrate) { - builder.setVibrate(new long[]{200L, 200L, 200L, 200L}); - } - - if (isSound) { - builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); - } + builder.setVibrate(new long[]{200L, 200L, 200L, 200L}); + builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } - if (className != null) { - Intent appIntent = new Intent(Intent.ACTION_MAIN); - appIntent.addCategory(Intent.CATEGORY_LAUNCHER); - appIntent.setComponent(new ComponentName(context.getPackageName(), context.getPackageName() + "." + className)); - appIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); - if (param != null) - for (Map.Entry p : param.entrySet()) { - appIntent.putExtra(p.getKey(), p.getValue()); - } - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, appIntent, PendingIntent.FLAG_UPDATE_CURRENT); - builder.setContentIntent(pendingIntent); - } else { - PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, new Intent(), PendingIntent.FLAG_ONE_SHOT); - builder.setContentIntent(pendingIntent); - } - - Notification notification = new Notification.BigTextStyle(builder) - .bigText(content).build(); - this.mNotificationManager.notify(appId, notification); + Notification notification = new Notification.BigTextStyle(builder).bigText(content).build(); + mNotificationManager.notify(appId, notification); } @RequiresApi(api = 26) @@ -194,7 +98,6 @@ private void deleteNoNumberNotification(NotificationManager nm, String newChanne } } } - } } diff --git a/app/src/main/java/com/raincat/dolby_beta/helper/ScriptHelper.java b/app/src/main/java/com/raincat/dolby_beta/helper/ScriptHelper.java index 32a563cf..fd706115 100644 --- a/app/src/main/java/com/raincat/dolby_beta/helper/ScriptHelper.java +++ b/app/src/main/java/com/raincat/dolby_beta/helper/ScriptHelper.java @@ -1,9 +1,10 @@ package com.raincat.dolby_beta.helper; import android.content.Context; -import android.os.Build; +import android.content.Intent; import android.text.TextUtils; +import com.raincat.dolby_beta.Hook; import com.raincat.dolby_beta.net.HTTPSTrustManager; import com.raincat.dolby_beta.utils.Tools; @@ -24,8 +25,6 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; -import de.robv.android.xposed.XposedBridge; - /** *
  *     author : RainCat
@@ -125,6 +124,7 @@ public static void startScript(Context context) {
                 scriptList.add("-o");
                 scriptList.addAll(Arrays.asList(origin));
                 startNodeWithArguments(scriptList.toArray(new String[0]));
+                ExtraHelper.setExtraDate(ExtraHelper.SCRIPT_STATUS, "0");
             }).start();
         }
     }
@@ -135,11 +135,12 @@ public static void startScript(Context context) {
      * @param level 日志级别
      */
     private static void getLogcatInfo(int level, String tag, String text) {
-        if (level == 4 && (text.contains("mERROR ") || text.contains("Port ") || text.contains("Please "))) {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
-                NotificationHelper.getInstance(neteaseContext).sendUnLockNotification(neteaseContext, 0x08, false, false, "UnblockNeteaseMusic产生错误", "UnblockNeteaseMusic产生错误", text, 0);
-            else
-                XposedBridge.log("UnblockNeteaseMusic产生错误:" + text);
+        if (level != 4 || text.contains("lock"))
+            return;
+        if (text.contains("Error:") || text.contains("Port ") || text.contains("Please ")) {
+            Intent intent = new Intent(Hook.msg_send_notification);
+            intent.putExtra("content", text);
+            neteaseContext.sendBroadcast(intent);
         } else if (text.contains("HTTP Server running")) {
             ExtraHelper.setExtraDate(ExtraHelper.SCRIPT_STATUS, "1");
             Tools.showToastOnLooper(neteaseContext, "UnblockNeteaseMusic运行成功");
diff --git a/app/src/main/java/com/raincat/dolby_beta/helper/UserHelper.java b/app/src/main/java/com/raincat/dolby_beta/helper/UserHelper.java
index e79a948d..fccbab97 100644
--- a/app/src/main/java/com/raincat/dolby_beta/helper/UserHelper.java
+++ b/app/src/main/java/com/raincat/dolby_beta/helper/UserHelper.java
@@ -26,6 +26,6 @@ public static void getUserInfo() {
         String userInfo = new Http("GET", "https://music.163.com/api/nuser/account/get", headers, (String) null).getResult();
         Gson gson = new Gson();
         UserInfoBean userInfoBean = gson.fromJson(userInfo, UserInfoBean.class);
-        ExtraHelper.setExtraDate(ExtraHelper.USER_ID, userInfoBean.getProfile().getUserId() + "");
+        ExtraHelper.setExtraDate(ExtraHelper.USER_ID, userInfoBean.getProfile().getUserId());
     }
 }
diff --git a/app/src/main/java/com/raincat/dolby_beta/hook/ProxyHook.java b/app/src/main/java/com/raincat/dolby_beta/hook/ProxyHook.java
index df6df201..2b977799 100644
--- a/app/src/main/java/com/raincat/dolby_beta/hook/ProxyHook.java
+++ b/app/src/main/java/com/raincat/dolby_beta/hook/ProxyHook.java
@@ -1,12 +1,12 @@
 package com.raincat.dolby_beta.hook;
 
 import android.content.Context;
-import android.content.Intent;
 import android.os.Bundle;
 
 import com.raincat.dolby_beta.helper.ExtraHelper;
 import com.raincat.dolby_beta.helper.ScriptHelper;
 import com.raincat.dolby_beta.helper.SettingHelper;
+import com.raincat.dolby_beta.utils.Tools;
 
 import java.lang.reflect.Field;
 import java.net.InetSocketAddress;
@@ -86,11 +86,16 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
         });
 
         if (isPlayProcess)
-            findAndHookMethod("com.netease.cloudmusic.service.PlayService", context.getClassLoader(), "onStartCommand", Intent.class, int.class, int.class, new XC_MethodHook() {
+            findAndHookMethod("com.netease.cloudmusic.service.PlayService", context.getClassLoader(), "onCreate", new XC_MethodHook() {
                 @Override
                 protected void afterHookedMethod(MethodHookParam param) throws Throwable {
-                    ScriptHelper.initScript(context, false);
-                    ScriptHelper.startScript(context);
+                    int retry = Integer.parseInt(ExtraHelper.getExtraDate(ExtraHelper.SCRIPT_RETRY));
+                    if (retry > 0) {
+                        ScriptHelper.initScript(context, false);
+                        ScriptHelper.startScript(context);
+                        ExtraHelper.setExtraDate(ExtraHelper.SCRIPT_RETRY, --retry);
+                    } else
+                        Tools.showToastOnLooper(context, "重试次数过多,UnblockNeteaseMusic运行失败!");
                 }
             });
 
@@ -99,6 +104,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                 @Override
                 protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                     ExtraHelper.setExtraDate(ExtraHelper.SCRIPT_STATUS, "0");
+                    ExtraHelper.setExtraDate(ExtraHelper.SCRIPT_RETRY, "3");
                 }
             });
     }
diff --git a/app/src/main/java/com/raincat/dolby_beta/hook/SettingHook.java b/app/src/main/java/com/raincat/dolby_beta/hook/SettingHook.java
index 655ddb41..e30f86af 100644
--- a/app/src/main/java/com/raincat/dolby_beta/hook/SettingHook.java
+++ b/app/src/main/java/com/raincat/dolby_beta/hook/SettingHook.java
@@ -186,7 +186,7 @@ else if (dialogProxyRoot.getChildAt(i) instanceof BaseDialogInputItem)
     private void showSettingDialog(final Context context) {
         dialogRoot = new BaseDialogItem(context);
         dialogRoot.setOrientation(LinearLayout.VERTICAL);
-        ScrollView scrollView=new ScrollView(context);
+        ScrollView scrollView = new ScrollView(context);
         scrollView.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);
         scrollView.setVerticalScrollBarEnabled(false);
         scrollView.addView(dialogRoot);
@@ -254,6 +254,8 @@ private void showProxyDialog(final Context context) {
     }
 
     private void restartApplication(Context context) {
+        ExtraHelper.setExtraDate(ExtraHelper.SCRIPT_STATUS, "0");
+        ExtraHelper.setExtraDate(ExtraHelper.SCRIPT_RETRY, "3");
         ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
         List runningAppProcessInfoListist = activityManager.getRunningAppProcesses();
         for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcessInfoListist) {
diff --git a/app/src/main/java/com/raincat/dolby_beta/hook/UserProfileHook.java b/app/src/main/java/com/raincat/dolby_beta/hook/UserProfileHook.java
index 80dc6210..bf92f91c 100644
--- a/app/src/main/java/com/raincat/dolby_beta/hook/UserProfileHook.java
+++ b/app/src/main/java/com/raincat/dolby_beta/hook/UserProfileHook.java
@@ -36,7 +36,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                     if (nickName.equals("未登录") || nickName.length() == 0)
                         return;
                     if ((boolean) XposedHelpers.callMethod(param.thisObject, "isMe") && ExtraHelper.getExtraDate(ExtraHelper.USER_ID).equals("-1"))
-                        ExtraHelper.setExtraDate(ExtraHelper.USER_ID, XposedHelpers.callMethod(param.thisObject, "getUserId") + "");
+                        ExtraHelper.setExtraDate(ExtraHelper.USER_ID, XposedHelpers.callMethod(param.thisObject, "getUserId"));
                 }
             });
         }