diff --git a/app/build.gradle b/app/build.gradle index af4b5c98..77fb5a4b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,16 +12,13 @@ android { minSdkVersion 26 //noinspection OldTargetApi targetSdkVersion 29 - versionCode 73 - versionName "3.43.19" + versionCode 74 + versionName "3.44.21" aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false } - buildTypes {debug { - buildConfigField 'boolean', 'PREPROD', 'true' - buildConfigField 'boolean', 'STAGING', 'false' - } + buildTypes { release { minifyEnabled true zipAlignEnabled true diff --git a/app/src/main/java/miui/statusbar/lyric/activity/SettingsActivity.java b/app/src/main/java/miui/statusbar/lyric/activity/SettingsActivity.java index c2a1ae87..ef03c926 100644 --- a/app/src/main/java/miui/statusbar/lyric/activity/SettingsActivity.java +++ b/app/src/main/java/miui/statusbar/lyric/activity/SettingsActivity.java @@ -57,8 +57,6 @@ protected void onCreate(Bundle savedInstanceState) { config = new Config(ConfigUtils.getSP(activity, "Lyric_Config")); setTitle(String.format("%s (%s)", getString(R.string.AppName), getString(R.string.SPConfigMode))); init(); - AppCenter.start(getApplication(), "1a36c976-87ea-4f22-a8d8-4aba01ad973d", - Analytics.class, Crashes.class); } catch (SecurityException ignored) { new AlertDialog.Builder(activity) .setTitle(getString(R.string.Tips)) @@ -85,7 +83,10 @@ public void init() { .setTitle(getString(R.string.Tips)) .setIcon(R.mipmap.ic_launcher) .setMessage(getString(R.string.AppTips)) - .setNegativeButton(getString(R.string.TipsIDone), (dialog, which) -> preferences.edit().putBoolean(tips, true).apply()) + .setNegativeButton(getString(R.string.TipsIDone), (dialog, which) -> { + preferences.edit().putBoolean(tips, true).apply(); + ActivityUtils.getNotice(activity); + }) .setPositiveButton(getString(R.string.Quit), (dialog, which) -> activity.finish()) .setNeutralButton(getString(R.string.PrivacyPolicy), (dialog, which) -> { Uri uri = Uri.parse("https://github.com/577fkj/MIUIStatusBarLyric/blob/main/EUAL.md"); @@ -96,7 +97,11 @@ public void init() { .setCancelable(false) .create() .show(); + } else { + ActivityUtils.getNotice(activity); } + AppCenter.start(getApplication(), "1a36c976-87ea-4f22-a8d8-4aba01ad973d", + Analytics.class, Crashes.class); //使用说明 Preference verExplain = findPreference("ver_explain"); diff --git a/app/src/main/java/miui/statusbar/lyric/hook/MainHook.java b/app/src/main/java/miui/statusbar/lyric/hook/MainHook.java index 421aafec..c44c9a43 100644 --- a/app/src/main/java/miui/statusbar/lyric/hook/MainHook.java +++ b/app/src/main/java/miui/statusbar/lyric/hook/MainHook.java @@ -11,14 +11,14 @@ import de.robv.android.xposed.XposedHelpers; import de.robv.android.xposed.callbacks.XC_LoadPackage; import miui.statusbar.lyric.config.ApiListConfig; -import miui.statusbar.lyric.hook.app.SystemUI; +import miui.statusbar.lyric.hook.app.Kugou; +import miui.statusbar.lyric.hook.app.Kuwo; import miui.statusbar.lyric.hook.app.Myplayer; import miui.statusbar.lyric.hook.app.Netease; import miui.statusbar.lyric.hook.app.NeteaseLite; +import miui.statusbar.lyric.hook.app.SystemUI; import miui.statusbar.lyric.utils.Utils; -import java.util.HashMap; - public class MainHook implements IXposedHookLoadPackage { Context context = null; @@ -56,68 +56,12 @@ protected void afterHookedMethod(MethodHookParam param) { break; case "com.kugou.android": Utils.log("正在hook酷狗音乐"); - XposedHelpers.findAndHookMethod("android.media.AudioManager", lpparam.classLoader, "isBluetoothA2dpOn", new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) throws Throwable { - super.beforeHookedMethod(param); - } - - @Override - protected void afterHookedMethod(MethodHookParam param) throws Throwable { - super.afterHookedMethod(param); - param.setResult(true); - } - }); - XposedHelpers.findAndHookMethod("com.kugou.framework.player.c", lpparam.classLoader, "a", HashMap.class, new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) throws Throwable { - super.beforeHookedMethod(param); - } - - @Override - protected void afterHookedMethod(MethodHookParam param) throws Throwable { - super.afterHookedMethod(param); - Utils.log("酷狗音乐:" + ((HashMap) param.args[0]).values().toArray()[0]); - Utils.sendLyric(context, "" + ((HashMap) param.args[0]).values().toArray()[0], "kugou"); - } - }); + new Kugou.Hook(lpparam, context); Utils.log("hook酷狗音乐结束"); break; case "cn.kuwo.player": Utils.log("正在hook酷我音乐"); - XposedHelpers.findAndHookMethod("android.bluetooth.BluetoothAdapter", lpparam.classLoader, "isEnabled", new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) throws Throwable { - super.beforeHookedMethod(param); - } - - @Override - protected void afterHookedMethod(MethodHookParam param) throws Throwable { - super.afterHookedMethod(param); - param.setResult(true); - } - }); - XposedHelpers.findAndHookMethod("cn.kuwo.mod.playcontrol.RemoteControlLyricMgr", lpparam.classLoader, "updateLyricText", Class.forName("java.lang.String"), new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) throws Throwable { - super.beforeHookedMethod(param); - String str = (String) param.args[0]; - Utils.log("酷我音乐:" + str); - if (param.args[0] != null && !str.equals("") && !str.contains(" - ")) { - Utils.sendLyric(context, "" + str, "kuwo"); - } - param.setResult(replaceHookedMethod()); - } - - private Object replaceHookedMethod() { - return null; - } - - @Override - protected void afterHookedMethod(MethodHookParam param) throws Throwable { - super.afterHookedMethod(param); - } - }); + new Kuwo.Hook(lpparam, context); Utils.log("hook酷我音乐结束"); break; case "com.tencent.qqmusic": diff --git a/app/src/main/java/miui/statusbar/lyric/hook/app/Kugou.java b/app/src/main/java/miui/statusbar/lyric/hook/app/Kugou.java index 2a42721d..3aba3835 100644 --- a/app/src/main/java/miui/statusbar/lyric/hook/app/Kugou.java +++ b/app/src/main/java/miui/statusbar/lyric/hook/app/Kugou.java @@ -10,35 +10,22 @@ public class Kugou { public static class Hook { - public Hook(XC_LoadPackage.LoadPackageParam lpparam) { + public Hook(XC_LoadPackage.LoadPackageParam lpparam, Context context) { XposedHelpers.findAndHookMethod("android.media.AudioManager", lpparam.classLoader, "isBluetoothA2dpOn", new XC_MethodHook() { @Override - protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable { - super.beforeHookedMethod(param); + protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable { + super.afterHookedMethod(param); + param.setResult(true); } - + }); + XposedHelpers.findAndHookMethod("com.kugou.framework.player.c", lpparam.classLoader, "a", HashMap.class, new XC_MethodHook() { @Override protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable { super.afterHookedMethod(param); - param.setResult(true); + Utils.log("酷狗音乐:" + ((HashMap) param.args[0]).values().toArray()[0]); + Utils.sendLyric(context, "" + ((HashMap) param.args[0]).values().toArray()[0], "kugou"); } }); - XposedHelpers.findAndHookMethod("com.kugou.framework.player.c", lpparam.classLoader, "a", HashMap.class, new - - XC_MethodHook() { - @Override - protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable { - super.beforeHookedMethod(param); - } - - @Override - protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable { - super.afterHookedMethod(param); - Context context = (Context) param.thisObject; - Utils.log("酷狗音乐:" + ((HashMap) param.args[0]).values().toArray()[0]); - Utils.sendLyric(context, "" + ((HashMap) param.args[0]).values().toArray()[0], "kugou"); - } - }); } } diff --git a/app/src/main/java/miui/statusbar/lyric/hook/app/Kuwo.java b/app/src/main/java/miui/statusbar/lyric/hook/app/Kuwo.java index 8e384517..c9b50d60 100644 --- a/app/src/main/java/miui/statusbar/lyric/hook/app/Kuwo.java +++ b/app/src/main/java/miui/statusbar/lyric/hook/app/Kuwo.java @@ -8,13 +8,8 @@ public class Kuwo { public static class Hook { - public Hook(XC_LoadPackage.LoadPackageParam lpparam) throws ClassNotFoundException { + public Hook(XC_LoadPackage.LoadPackageParam lpparam, Context context) throws ClassNotFoundException { XposedHelpers.findAndHookMethod("android.bluetooth.BluetoothAdapter", lpparam.classLoader, "isEnabled", new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) throws Throwable { - super.beforeHookedMethod(param); - } - @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); @@ -25,10 +20,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { super.beforeHookedMethod(param); - Context context = (Context) param.thisObject; String str = (String) param.args[0]; Utils.log("酷我音乐:" + str); - if (param.args[0] != null && !str.equals("") && !str.equals("好音质 用酷我") && !str.equals("正在搜索歌词...") && !str.contains(" - ")) { + if (param.args[0] != null && !str.equals("")) { Utils.sendLyric(context, "" + str, "kuwo"); } param.setResult(replaceHookedMethod()); @@ -37,11 +31,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable { private Object replaceHookedMethod() { return null; } - - @Override - protected void afterHookedMethod(MethodHookParam param) throws Throwable { - super.afterHookedMethod(param); - } }); - }} + } + } } diff --git a/app/src/main/java/miui/statusbar/lyric/utils/ActivityUtils.java b/app/src/main/java/miui/statusbar/lyric/utils/ActivityUtils.java index a1201fd4..71a303aa 100644 --- a/app/src/main/java/miui/statusbar/lyric/utils/ActivityUtils.java +++ b/app/src/main/java/miui/statusbar/lyric/utils/ActivityUtils.java @@ -85,7 +85,7 @@ public static void initIcon(Activity activity, Config config) { } } - public static void copyAssets(Activity activity, String str, String str2) { + private static void copyAssets(Activity activity, String str, String str2) { try { File file = new File(str2); InputStream open = activity.getAssets().open(str); @@ -106,6 +106,7 @@ public static void copyAssets(Activity activity, String str, String str2) { } } + //检查更新 public static void checkUpdate(Activity activity) { Handler handler = new Handler(Looper.getMainLooper(), message -> { String data = message.getData().getString("value"); @@ -114,38 +115,32 @@ public static void checkUpdate(Activity activity) { if (!getLocalVersion(activity).equals("")) { if (Integer.parseInt(jsonObject.getString("tag_name").split("v")[1]) > Utils.getLocalVersionCode(activity)) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(activity.getString(R.string.NewVer) + " [" + jsonObject.getString("name") + "]") + + new AlertDialog.Builder(activity) + .setTitle(String.format("%s [%s]", activity.getString(R.string.NewVer), jsonObject.getString("name"))) .setIcon(R.mipmap.ic_launcher) .setMessage(jsonObject.getString("body").replace("#", "")) .setPositiveButton(activity.getString(R.string.Update), (dialog, which) -> { try { Uri uri = Uri.parse(jsonObject.getJSONArray("assets").getJSONObject(0).getString("browser_download_url")); - Intent intent = new Intent(); - intent.setAction("android.intent.action.VIEW"); - intent.setData(uri); + Intent intent = new Intent( + Intent.ACTION_VIEW, uri); activity.startActivity(intent); } catch (JSONException e) { - Toast.makeText(activity, activity.getString(R.string.GetNewVerError) + e, Toast.LENGTH_LONG).show(); + showToastOnLooper(activity, activity.getString(R.string.GetNewVerError) + e); } - }).setNegativeButton(activity.getString(R.string.Cancel), null).create().show(); } else { Toast.makeText(activity, activity.getString(R.string.NoVerUpdate), Toast.LENGTH_LONG).show(); } - } else { - Toast.makeText(activity, activity.getString(R.string.CheckUpdateError), Toast.LENGTH_LONG).show(); - + return true; } - } catch (JSONException e) { - e.printStackTrace(); + } catch (JSONException ignored) { } - Looper.loop(); + showToastOnLooper(activity, activity.getString(R.string.CheckUpdateError)); return true; }); - new Thread(() -> { - Looper.prepare(); String value = HttpUtils.Get("https://api.github.com/repos/577fkj/MIUIStatusBarLyric/releases/latest"); if (!value.equals("")) { Message message = handler.obtainMessage(); @@ -154,12 +149,12 @@ public static void checkUpdate(Activity activity) { message.setData(bundle); handler.sendMessage(message); } else { - Toast.makeText(activity, activity.getString(R.string.CheckUpdateFailed), Toast.LENGTH_LONG).show(); - Looper.loop(); + showToastOnLooper(activity, activity.getString(R.string.CheckUpdateFailed)); } }).start(); } + //清除配置 public static void cleanConfig(Activity activity, Config config, ApiListConfig config2) { activity.getSharedPreferences("miui.statusbar.lyric_preferences", 0).edit().clear().apply(); PackageManager packageManager = Objects.requireNonNull(activity).getPackageManager(); @@ -200,4 +195,38 @@ public static void showToastOnLooper(final Context context, final String message e.printStackTrace(); } } -} \ No newline at end of file + + public static void getNotice(Activity activity) { + Handler handler = new Handler(Looper.getMainLooper(), message -> { + String data = message.getData().getString("value"); + try { + JSONObject jsonObject = new JSONObject(data); + if (jsonObject.getString("versionCode").equals(String.valueOf(Utils.getLocalVersionCode(activity)))) { + if (Boolean.parseBoolean(jsonObject.getString("forcibly"))) { + new AlertDialog.Builder(activity) + .setTitle(activity.getString(R.string.NewNotice)) + .setIcon(R.mipmap.ic_launcher) + .setMessage(jsonObject.getString("data")) + .setNegativeButton(activity.getString(R.string.Done), null).create().show(); + } + } + return true; + } catch (JSONException ignored) { + } + showToastOnLooper(activity, activity.getString(R.string.GetNewNoticeError)); + return true; + }); + new Thread(() -> { + String value = HttpUtils.Get("https://app.xiaowine.cc/app/notice.json"); + if (!value.equals("")) { + Message message = handler.obtainMessage(); + Bundle bundle = new Bundle(); + bundle.putString("value", value); + message.setData(bundle); + handler.sendMessage(message); + } else { +// showToastOnLooper(activity, activity.getString(R.string.GetNewNoticeError)); + } + }).start(); + } +} diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 1e5eefac..a661b5df 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -166,4 +166,6 @@ 歌词设置 图标设置 * 歌词左右位置(重启界面后1min后生效) + 新通知 + 获取新通知错误 \ No newline at end of file diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 4db01f6d..d50dfb7c 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -166,4 +166,6 @@ 歌詞設置 圖標設置 * 歌詞左右位置(重啟界面後1min後生效) + 新通知 + 獲取新通知錯誤 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b29704f..eb6f2134 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -179,4 +179,6 @@ Lyrics settings Icon settings + NewNotice + Get NewNotice Error \ No newline at end of file