Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Deezer #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "bluepie.ad_silence"
minSdk 21
targetSdk 31
versionCode 25
versionName "0.5.3"
versionCode 27
versionName "0.6.0-beta"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -23,6 +23,11 @@ android {

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}

debug {
minifyEnabled false
shrinkResources false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bluepie.ad_silence">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<queries>
<!--android 11 and above-->
<package android:name="com.slipstream.accuradio"/>
Expand All @@ -10,6 +11,10 @@
<package android:name="com.spotify.lite"/>
<package android:name="com.pandora.android"/>
<package android:name="com.slacker.radio"/>
<package android:name="com.slipstream.accuradio" />
<package android:name="com.spotify.music" />
<package android:name="com.aspiro.tidal" />
<package android:name="deezer.android.app" />
</queries>
<application
android:allowBackup="true"
Expand All @@ -27,10 +32,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".NotificationListener"
<service
android:name=".NotificationListener"
android:exported="false"
android:label="@string/notification_listener_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:exported="false">
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
Expand Down
33 changes: 29 additions & 4 deletions app/src/main/java/bluepie/ad_silence/AdSilenceActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AdSilenceActivity : Activity() {
val isSpotifyLiteInstalled = utils.isSpotifyLiteInstalled(applicationContext)
val isPandoraInstalled = utils.isPandoraInstalled(applicationContext)
val isLiveOneInstalled = utils.isLiveOneInstalled(applicationContext)
val isDeezerInstalled = utils.isDeezerInstalled(applicationContext)

findViewById<Button>(R.id.about_btn)?.setOnClickListener {
layoutInflater.inflate(R.layout.about, null)?.run {
Expand Down Expand Up @@ -224,11 +225,33 @@ class AdSilenceActivity : Activity() {
}
}


appSelectionView.findViewById<Switch>(R.id.deezer_selection)?.run {
this.isEnabled = isDeezerInstalled
this.isChecked = preference.isAppConfigured(SupportedApps.DEEZER)
"${context.getString(R.string.deezer)} ${
if (isDeezerInstalled) applicationContext.getString(R.string.beta) else (context.getString(
R.string.not_installed
))
}".also {
this.text = it
}
this.setOnClickListener {
preference.setAppConfigured(
SupportedApps.DEEZER,
!preference.isAppConfigured(SupportedApps.DEEZER)
)
}
}

appSelectionView.findViewById<Switch>(R.id.pandora_selection_switch)?.run {
this.isEnabled = isPandoraInstalled
this.isChecked = preference.isAppConfigured(SupportedApps.PANDORA)
this.isChecked =
preference.isAppConfigured(SupportedApps.PANDORA)
"${context.getString(R.string.pandora)} ${
if (isPandoraInstalled) applicationContext.getString(R.string.beta) else context.getString(R.string.not_installed)
if (isPandoraInstalled) applicationContext.getString(R.string.beta) else context.getString(
R.string.not_installed
)
}".also {
this.text = it
}
Expand All @@ -244,11 +267,13 @@ class AdSilenceActivity : Activity() {
this.isEnabled = isLiveOneInstalled
this.isChecked = preference.isAppConfigured(SupportedApps.LiveOne)
"${context.getString(R.string.liveone)} ${
if (isLiveOneInstalled) applicationContext.getString(R.string.beta) else context.getString(R.string.not_installed)
if (isLiveOneInstalled) applicationContext.getString(R.string.beta) else context.getString(
R.string.not_installed
)
}".also {
this.text = it
}
this.setOnClickListener{
this.setOnClickListener {
preference.setAppConfigured(
SupportedApps.LiveOne,
!preference.isAppConfigured(SupportedApps.LiveOne)
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/bluepie/ad_silence/NotificationParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fun AppNotification.getApp(): SupportedApps {
context.getString(R.string.spotify_lite_package_name) -> SupportedApps.SPOTIFY_LITE
context.getString(R.string.pandora_package_name) -> SupportedApps.PANDORA
context.getString(R.string.liveOne_package_name) -> SupportedApps.LiveOne
context.getString(R.string.deezer_package_name) -> SupportedApps.DEEZER
else -> SupportedApps.INVALID
}
}
Expand All @@ -33,6 +34,7 @@ fun AppNotification.adString(): List<String> {
SupportedApps.TIDAL -> listOf(context.getString(R.string.tidal_ad_string))
SupportedApps.PANDORA -> listOf(context.getString(R.string.pandora_ad_string),context.getString(R.string.pandora_ad_string_2))
SupportedApps.LiveOne -> listOf(context.getString(R.string.liveOne_ad_string), context.getString(R.string.liveOne_ad_string_2))
SupportedApps.DEEZER -> listOf(context.getString(R.string.deezer_ad_string))
else -> listOf("")
}
}
Expand All @@ -55,6 +57,7 @@ class NotificationParser(override var appNotification: AppNotification) :
SupportedApps.TIDAL -> parseTidalNotification()
SupportedApps.PANDORA -> parsePandoraNotification()
SupportedApps.LiveOne -> parseLiveOneNotification()
SupportedApps.DEEZER -> parseDeezerNotification()
else -> false
}
}
Expand Down Expand Up @@ -150,6 +153,19 @@ class NotificationParser(override var appNotification: AppNotification) :
if (this == adString) {
Log.v(TAG, "detection in Pandora: $adString")
isAd = true
}
}
}
return isAd
}

private fun parseDeezerNotification(): Boolean {
var isAd = false
this.appNotification.notification.extras?.get("android.title").toString().run {
for (adString in appNotification.adString()){
if (this == adString){
Log.v(TAG, "detection in Deezer: $adString")
isAd = true
break
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/bluepie/ad_silence/Preference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Preference(private val context: Context) {
private val PANDORA_DEFAULT = true
val LIVEONE = "Liveone"
private val LIVEONE_DEFAULT = true


val DEEZER = "Deezer"
private val DEEZER_DEFAULT = true

fun isEnabled(): Boolean {
return preference.getBoolean(APP_ENABLED, APP_ENABLED_DEFAULT)
Expand All @@ -51,6 +51,8 @@ class Preference(private val context: Context) {
SupportedApps.SPOTIFY_LITE-> preference.edit { putBoolean(SPOTIFY_LITE, status).commit() }
SupportedApps.PANDORA-> preference.edit { putBoolean(PANDORA, status).commit() }
SupportedApps.LiveOne-> preference.edit { putBoolean(LIVEONE, status).commit() }
SupportedApps.DEEZER -> preference.edit { putBoolean(DEEZER, status).commit() }
else -> {}
}
}

Expand All @@ -62,6 +64,7 @@ class Preference(private val context: Context) {
SupportedApps.SPOTIFY_LITE-> preference.getBoolean(SPOTIFY_LITE, SPOTIFY_LITE_DEFAULT)
SupportedApps.PANDORA-> preference.getBoolean(PANDORA, PANDORA_DEFAULT)
SupportedApps.LiveOne-> preference.getBoolean(LIVEONE, LIVEONE_DEFAULT)
SupportedApps.DEEZER -> preference.getBoolean(DEEZER, DEEZER_DEFAULT)
else -> false
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/bluepie/ad_silence/SupportedApps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ enum class SupportedApps {
SPOTIFY_LITE,
PANDORA,
LiveOne,
DEEZER,
INVALID
}
5 changes: 5 additions & 0 deletions app/src/main/java/bluepie/ad_silence/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Utils {
fun isLiveOneInstalled(context: Context) =
isPackageInstalled(context, context.getString(R.string.liveOne_package_name))

fun isDeezerInstalled(context: Context) =
isPackageInstalled(context, context.getString(R.string.deezer_package_name))

fun isMusicMuted(audoManager: AudioManager): Boolean {
if (Build.VERSION.SDK_INT >= 23) {
return audoManager.isStreamMute(AudioManager.STREAM_MUSIC)
Expand All @@ -77,6 +80,7 @@ class Utils {
} else {
audioManager?.setStreamMute(AudioManager.STREAM_MUSIC, true)
}
Log.v(TAG,"device music steam muted")
addNotificationHelper?.updateNotification("AdSilence, ad-detected")
}

Expand All @@ -94,6 +98,7 @@ class Utils {
} else {
audioManager?.setStreamMute(AudioManager.STREAM_MUSIC, false)
}
Log.v(TAG, "device music stream unmuted")
addNotificationHelper?.updateNotification("AdSilence, listening for ads")
}

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/app_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@
android:minHeight="48dp"
android:text="@string/liveone" />

<Switch
android:id="@+id/deezer_selection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:text="@string/deezer" />

</LinearLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<string name="spotify_package_name">com.spotify.music</string>
<string name="tidal_package_name">com.aspiro.tidal</string>
<string name="pandora_package_name">com.pandora.android</string>
<string name="deezer_package_name">deezer.android.app</string>
<string name="accuradio_ad_text">Music will resume</string>
<string name="grant_permission_text_view">App works by using Notification access</string>
<string name="grant_permission_button">Grant Permission</string>
Expand All @@ -17,6 +18,7 @@
<string name="accuradio">Accuradio</string>
<string name="spotify">Spotify</string>
<string name="tidal">Tidal</string>
<string name="deezer">Deezer</string>
<string name="about_window_text">\"Ad-silence\" silences ads on Accuradio, Spotify, Spotify-Lite, Tidal &amp; Pandora . It works utilizing the notification posted by these apps. Only Accuradio\'s, Spotify\'s, Tidal\'s &amp; Pandora\'s notifications are accessed for identification and discarded immediately after. If you are not confident with the permission, This app is OpenSource, you can check the source on github.
<![CDATA[<br/><br/>]]>

Expand Down Expand Up @@ -51,4 +53,5 @@
<string name="liveOne_ad_string_2">60 Minutes Uninterrupted Listening</string>
<string name="liveone">LiveOne</string>
<string name="beta">(Beta)</string>
<string name="deezer_ad_string">Deezer</string>
</resources>