|
| 1 | +/* |
| 2 | + * Copyright (c) 2021. Dylan Cai |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +@file:Suppress("unused") |
| 18 | + |
| 19 | +package com.dylanc.longan |
| 20 | + |
| 21 | +import android.os.Build |
| 22 | + |
| 23 | +inline val isXiaomiRom: Boolean get() = isRomOf("xiaomi") |
| 24 | + |
| 25 | +inline val isHuaweiRom: Boolean get() = isRomOf("huawei") |
| 26 | + |
| 27 | +inline val isOppoRom: Boolean get() = isRomOf("oppo") |
| 28 | + |
| 29 | +inline val isVivoRom: Boolean get() = isRomOf("vivo") |
| 30 | + |
| 31 | +inline val isOnePlusRom: Boolean get() = isRomOf("oneplus") |
| 32 | + |
| 33 | +inline val isSmartisanRom: Boolean get() = isRomOf("smartisan", "deltainno") |
| 34 | + |
| 35 | +inline val isMeiZuRom: Boolean get() = isRomOf("meizu") |
| 36 | + |
| 37 | +inline val isSamsungRom: Boolean get() = isRomOf("samsung") |
| 38 | + |
| 39 | +inline val isGoogleRom: Boolean get() = isRomOf("google") |
| 40 | + |
| 41 | +inline val isSonyRom: Boolean get() = isRomOf("sony") |
| 42 | + |
| 43 | +fun isRomOf(vararg names: String): Boolean = |
| 44 | + names.any { it.contains(Build.BRAND, true) || it.contains(Build.MANUFACTURER, true) } |
| 45 | + |
| 46 | +val isHarmonyOS: Boolean |
| 47 | + get() { |
| 48 | + try { |
| 49 | + val clazz = Class.forName("com.huawei.system.BuildEx") |
| 50 | + val classLoader = clazz.classLoader |
| 51 | + if (classLoader != null && classLoader.parent == null) { |
| 52 | + return clazz.getMethod("getOsBrand").invoke(clazz) == "harmony" |
| 53 | + } |
| 54 | + } catch (e: ClassNotFoundException) { |
| 55 | + } catch (e: NoSuchMethodException) { |
| 56 | + } catch (e: Exception) { |
| 57 | + } |
| 58 | + return false |
| 59 | + } |
0 commit comments