Skip to content

Commit 242dab4

Browse files
committed
Fix security exception in android 7 phones, bump version
1 parent ee3ed47 commit 242dab4

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.tomatodev.timerdroid"
77
minSdkVersion 18
88
targetSdkVersion 26
9-
versionCode 1412300
10-
versionName "3.0.0"
9+
versionCode 1412310
10+
versionName "3.1.0"
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
vectorDrawables.useSupportLibrary = true
1313
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<uses-permission android:name="android.permission.VIBRATE" />
66
<uses-permission android:name="android.permission.WAKE_LOCK" />
77
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
8+
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
89

910
<application
1011
android:allowBackup="true"

app/src/main/java/com/tomatodev/timerdroid/service/CustomNotificationManager.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public void startNotificationForFinishedTimer(String timerName){
200200

201201
// set alarm volume (API < 26)
202202
// TODO problem when 2 alarms go off after each other, will overwrite the system volume
203-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
203+
if (canSetVolume()){
204204
mVolumeBefore = audio.getStreamVolume(SOUND_STREAM);
205205
int max = audio.getStreamMaxVolume(SOUND_STREAM);
206206
int volume = (int) Math.round(prefs.getInt("alarm_volume", 5) * 0.1 * max);
@@ -213,11 +213,26 @@ public void startNotificationForFinishedTimer(String timerName){
213213
}
214214

215215
public void cancelSoundNotification(){
216-
// reset alarm volume
217-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ){
216+
// reset alarm volume if allowed
217+
if (canSetVolume()){
218218
mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mVolumeBefore, 0);
219219
mAudioManager.setRingerMode(mRingerModeBefore);
220220
}
221+
221222
mNotificationManager.cancel(NOTIFICATION_ID_FINISHED);
222223
}
224+
225+
private boolean canSetVolume(){
226+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
227+
return false;
228+
}
229+
230+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
231+
if (!mNotificationManager.isNotificationPolicyAccessGranted()) {
232+
return false;
233+
}
234+
}
235+
236+
return true;
237+
}
223238
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<string name="about_author_label">Author</string>
2121
<string name="about_author" translatable="false">Martin Hoffmann</string>
2222
<string name="about_version_label">Version</string>
23-
<string name="about_version" translatable="false">3.0.0</string>
23+
<string name="about_version" translatable="false">3.1.0</string>
2424
<string name="about_link"><a href="https://github.com/hoffimar/timerdroid">Website</a></string>
2525
<string name="menu_about_button_text">OK</string>
2626

0 commit comments

Comments
 (0)