renyuneyun / Easer

User-defined explicit automation for Android
https://renyuneyun.github.io/Easer/
GNU General Public License v3.0
805 stars 92 forks source link

Add Do Not Disturb USource #452

Closed mvn23 closed 2 years ago

mvn23 commented 2 years ago

Add a skill for Do Not Disturb mode. It allows you to select multiple interruption filter modes (alarms only, no interruptions, priority, normal and unknown) to customize which modes should match the trigger.

renyuneyun commented 2 years ago

Great! The functional parts look good to me. But there is one remaining issue related to compatibility (apologize I did not notice that earlier):

In general, if DoNotDisturbUSourceSkill.isCompatible() returns true, then there should not be any compatibility issues. Therefore, this method should check the SDK version.

My preference is to lower the target SDK to the minimum possible, i.e. SDK 21. But I see NotificationManager.getCurrentInterruptionFilter() requires SDK 23, which would require larger change if wanting to lower it. So maybe check SDK 23 in DoNotDisturbUSourceSkill.isCompatible() is more sensible. I also gave one idea on removing the necessity of SDK 24 for DoNotDisturbUSourceData.writeToParcel(). Maybe keep using writeIntArray() through doNotDisturbModes.toArray() also works, but I'm not familiar with it. The performance does not pose any issues in this.

Let me know how you think. I can certainly change that afterwards if needed.

mvn23 commented 2 years ago

Thank you for the suggestions and the detailed explanation. When I was writing the code I was already in doubt whether or not the SDK version would be a problem. I will try to lower the required version as much as possible.

mvn23 commented 2 years ago

While possible, using writeIntArray() was more complicated than your suggestions so I went with that. I couldn't find info on how to retrieve the Do Not Disturb status on SDK 21/22, so the minimum is at 23 for now.

renyuneyun commented 2 years ago

Merged :) Will try to make it appear in the nearest possible release as well :)