Skip to content

Commit

Permalink
1、修改脚本运行时机,更稳定
Browse files Browse the repository at this point in the history
2、修改通知栏推送逻辑
  • Loading branch information
nining377 committed Oct 18, 2021
1 parent 047ac32 commit 80a582d
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 163 deletions.
15 changes: 3 additions & 12 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
package="com.raincat.dolby_beta">

<application
android:allowBackup="false"
android:extractNativeLibs="false"
android:extractNativeLibs="true"
android:multiArch="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
Expand Down
33 changes: 23 additions & 10 deletions app/src/main/java/com/raincat/dolby_beta/Hook.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Environment;

import com.raincat.dolby_beta.helper.ClassHelper;
import com.raincat.dolby_beta.helper.ExtraHelper;
import com.raincat.dolby_beta.helper.FileHelper;
import com.raincat.dolby_beta.helper.NotificationHelper;
import com.raincat.dolby_beta.helper.SettingHelper;
import com.raincat.dolby_beta.hook.AdAndUpdateHook;
import com.raincat.dolby_beta.hook.AutoSignInHook;
Expand All @@ -28,6 +30,7 @@
import java.io.IOException;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

Expand All @@ -47,9 +50,11 @@ public class Hook {
public boolean playProcessInit = false;
public boolean mainProcessInit = false;
//主线程反编译dex完成后通知可以对play进程进行hook了
private final String msg_hookPlayProcess = "hookPlayProcess";
private final String msg_hook_play_process = "hookPlayProcess";
//play进程初始化完成通知主线程
private final String msg_playProcessInitFinish = "playProcessInitFinish";
private final String msg_play_process_init_finish = "playProcessInitFinish";
//脚本发信息
public static final String msg_send_notification = "sendNotification";

public Hook(XC_LoadPackage.LoadPackageParam lpparam) {
XposedHelpers.findAndHookMethod(XposedHelpers.findClass("com.netease.cloudmusic.NeteaseMusicApplication", lpparam.classLoader),
Expand Down Expand Up @@ -98,35 +103,43 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {

mainProcessInit = true;
if (mainProcessInit && playProcessInit)
context.sendBroadcast(new Intent(msg_hookPlayProcess));
context.sendBroadcast(new Intent(msg_hook_play_process));
});
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(msg_playProcessInitFinish);
intentFilter.addAction(msg_play_process_init_finish);
intentFilter.addAction(msg_send_notification);
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent intent) {
playProcessInit = true;
if (mainProcessInit && playProcessInit)
context.sendBroadcast(new Intent(msg_hookPlayProcess));
if (msg_play_process_init_finish.equals(intent.getAction())) {
playProcessInit = true;
if (mainProcessInit && playProcessInit)
context.sendBroadcast(new Intent(msg_hook_play_process));
} else if (msg_send_notification.equals(intent.getAction())) {
if (Build.VERSION.SDK_INT >= 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);
});
}
}
}, intentFilter);
context.sendBroadcast(new Intent(msg_playProcessInitFinish));
context.sendBroadcast(new Intent(msg_play_process_init_finish));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
143 changes: 23 additions & 120 deletions app/src/main/java/com/raincat/dolby_beta/helper/NotificationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String, String> 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<String, String> 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)
Expand All @@ -194,7 +98,6 @@ private void deleteNoNumberNotification(NotificationManager nm, String newChanne
}
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -24,8 +25,6 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;

import de.robv.android.xposed.XposedBridge;

/**
* <pre>
* author : RainCat
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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运行成功");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Loading

0 comments on commit 80a582d

Please sign in to comment.