Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class PermissionSettingsChannel(private val context: Context) :
companion object {
const val NAME = "com.exptech.dpip/permission_settings"
private const val TAG = "PermissionSettings"
private val nativeDndChannelSettingsManufacturers = setOf(
"google",
"sony",
"motorola",
)
}

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
Expand Down Expand Up @@ -71,7 +76,13 @@ class PermissionSettingsChannel(private val context: Context) :
result.success(openNotificationChannelSettings(channelId))
}

private fun usesNativeDndChannelSettings() =
Build.MANUFACTURER.lowercase() in nativeDndChannelSettingsManufacturers
Comment on lines +79 to +80

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

performance · low
由于设备的制造商在应用运行期间不会改变,建议将 usesNativeDndChannelSettings 改为 companion object 中的 val 属性,以避免每次调用时都重复执行 Build.MANUFACTURER.lowercase() 操作。

Suggestion:

Suggested change
private fun usesNativeDndChannelSettings() =
Build.MANUFACTURER.lowercase() in nativeDndChannelSettingsManufacturers
// 在 companion object 中定义:
private val usesNativeDndChannelSettings = Build.MANUFACTURER.lowercase() in nativeDndChannelSettingsManufacturers
// 然后在调用处使用:
if (!usesNativeDndChannelSettings) { ... }


private fun openNotificationChannelSettings(channelId: String): String {
if (!usesNativeDndChannelSettings()) {
return openNotificationSettings()
}
try {
context.startActivity(
Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
Expand Down
Loading