Last active
July 10, 2025 19:29
-
-
Save Howard20181/189ea40f9bf3d89b72b3feb54896a177 to your computer and use it in GitHub Desktop.
小米妙播
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.miui.miplay.audio.api; | |
| import android.content.ActivityNotFoundException; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.pm.ApplicationInfo; | |
| import android.content.pm.PackageManager; | |
| import android.text.TextUtils; | |
| import android.util.Log; | |
| import androidx.annotation.NonNull; | |
| import java.lang.reflect.Field; | |
| public class MiuiBuild { | |
| public static final String TAG = "MiuiBuild"; | |
| public static boolean isInternationalBuild() throws SecurityException { | |
| try { | |
| Field field = Class.forName("miui.os.Build").getField("IS_INTERNATIONAL_BUILD"); | |
| field.setAccessible(true); | |
| return field.getBoolean(null); | |
| } catch (Exception e) { | |
| Log.e(TAG, "Failed to check if it is an international build", e); | |
| return false; | |
| } | |
| } | |
| public static int getMiuiVersion() { | |
| try { | |
| String str = (String) Class.forName("android.os.SystemProperties").getDeclaredMethod("get", String.class, String.class).invoke(null, "ro.miui.ui.version.code", ""); | |
| if (TextUtils.isEmpty(str)) { | |
| return 0; | |
| } | |
| return Integer.parseInt(str); | |
| } catch (Exception e) { | |
| Log.e(TAG, "Failed to get MIUI version code", e); | |
| return 0; | |
| } | |
| } | |
| public record MiPlaySDKVersion(int version, int minSdk) { | |
| public boolean isValid() { | |
| return this.minSdk > 0 && this.version > 0; | |
| } | |
| } | |
| public static MiPlaySDKVersion getMiPlaySDKVersion(@NonNull Context context) { | |
| MiPlaySDKVersion miPlaySDKVersionVar = new MiPlaySDKVersion(0, 0); | |
| try { | |
| ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo("com.milink.service", PackageManager.GET_META_DATA); | |
| return new MiPlaySDKVersion(applicationInfo.metaData.getInt("com.xiaomi.miplay.opensdk.version", -1), applicationInfo.metaData.getInt("com.xiaomi.miplay.opensdk.minSdk", -1)); | |
| } catch (Exception e) { | |
| Log.e(TAG, "Failed to get MiPlay OpenSDK version", e); | |
| return miPlaySDKVersionVar; | |
| } | |
| } | |
| public static boolean systemUIReady(@NonNull Context context) { | |
| Intent intent = new Intent("miui.intent.action.ACTIVITY_MIPLAY_DETAIL"); | |
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| try { | |
| return context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null; | |
| } catch (ActivityNotFoundException ignored) { | |
| return false; | |
| } | |
| } | |
| public static boolean supportMiPlay(@NonNull Context context) { | |
| try { | |
| if (isInternationalBuild()) { | |
| Log.i(TAG, "doesn't support miplay, reason: [international rom]"); | |
| return false; | |
| } | |
| int miuiVersion = getMiuiVersion(); | |
| if (miuiVersion < 13) { | |
| Log.i(TAG, "doesn't support miplay, reason: [miui " + miuiVersion + "<13"); | |
| return false; | |
| } | |
| MiPlaySDKVersion miPlaySDKVersion = getMiPlaySDKVersion(context); | |
| if (!miPlaySDKVersion.isValid()) { | |
| Log.i(TAG, "doesn't support miplay, reason: [invalid opensdk runtime version: " + miPlaySDKVersion.version + ", min sdk:" + miPlaySDKVersion.minSdk + "]"); | |
| return false; | |
| } | |
| if (miPlaySDKVersion.version < 0) { | |
| Log.i(TAG, "doesn't support miplay, reason: [invalid opensdk runtime version: " + miPlaySDKVersion.version + "]"); | |
| return false; | |
| } | |
| if (1 < miPlaySDKVersion.minSdk) { | |
| Log.i(TAG, "sdk doesn't support, reason: [min: " + miPlaySDKVersion.minSdk + ", sdk:1"); | |
| return false; | |
| } | |
| if (context.getClassLoader().loadClass("miui.media.MiuiAudioPlaybackRecorder") == null) { | |
| Log.i(TAG, "doesn't support miplay, reason: [bsp doesn't support]"); | |
| return false; | |
| } | |
| if (systemUIReady(context)) { | |
| return true; | |
| } | |
| Log.i(TAG, "doesn't support miplay, reason: [systemUI doesn't support]"); | |
| return false; | |
| } catch (Exception e) { | |
| Log.i(TAG, "doesn't support miplay, reason: [unknown exception, " + e.getMessage() + "]"); | |
| return false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment