Skip to content

Commit

Permalink
Merge pull request #40 from abertschi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
abertschi committed Oct 30, 2019
2 parents 9219aa0 + 90ee86b commit 7dda93e
Show file tree
Hide file tree
Showing 25 changed files with 785 additions and 227 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ device-2017-09-01-203214.png
phone.psd
.#CHANGELOG.md
output.json
/private/
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Changelog / Ad-Free
### v1.0, 2019-07-12

### v1.1
- Add support for miui based devices
- introduce global error handler and option for email bug report on crash
- introduce sc ad detection
- introduce option to dump spotify notification

### v1.0, 2019-06-27
- Update fdroid store information (thanks @bennettscience)
- Introduce more supported audio formats for local music: mp3, wav, m4a
- Upgrade kotlin internals
- Introduce more supported audio formats for local music: mp3, wav,
m4a
- internal: update build tools

### v0.0.4.6, 2018-02-10
- Fix notification issue introduced with version 0.0.4.4. Ad blocking notification was not shown.
Expand Down
38 changes: 19 additions & 19 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "ch.abertschi.adfree"
minSdkVersion 21
targetSdkVersion 27
versionCode 30
versionName "1.0"
versionCode 31
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand All @@ -36,36 +36,36 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile 'org.jetbrains.anko:anko-sdk23:0.9.1' // sdk19, sdk21, sdk23 are also available
compile 'org.jetbrains.anko:anko-support-v4:0.9.1' // In case you need support-v4 bindings
compile 'org.jetbrains.anko:anko-appcompat-v7:0.9.1' // For appcompat-v7 bindings
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile 'com.github.javiersantos:AppUpdater:2.6.1'
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'org.jetbrains.anko:anko-sdk23:0.9.1' // sdk19, sdk21, sdk23 are also available
implementation 'org.jetbrains.anko:anko-support-v4:0.9.1' // In case you need support-v4 bindings
implementation 'org.jetbrains.anko:anko-appcompat-v7:0.9.1' // For appcompat-v7 bindings
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'com.github.javiersantos:AppUpdater:2.6.1'

// compile 'com.github.kittinunf.fuel:fuel-android:1.5.0'
implementation 'com.github.kittinunf.fuel:fuel:2.1.0'
implementation 'com.github.kittinunf.fuel:fuel-android:2.1.0'

compile 'com.github.bmoliveira:snake-yaml:v1.18-android'
implementation 'com.github.bmoliveira:snake-yaml:v1.18-android'

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex.rxjava2:rxjava:2.0.9'
compile 'com.danikula:videocache:2.6.4'
compile 'com.github.angads25:filepicker:1.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.0.9'
implementation 'com.danikula:videocache:2.6.4'
implementation 'com.github.angads25:filepicker:1.1.1'

compile('com.thoughtworks.xstream:xstream:1.4.7') {
implementation('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}


compile 'com.daimajia.easing:library:2.0@aar'
compile 'com.daimajia.androidanimations:library:2.3@aar'
implementation 'com.daimajia.easing:library:2.0@aar'
implementation 'com.daimajia.androidanimations:library:2.3@aar'


testCompile 'org.codehaus.groovy:groovy:2.4.11:grooid'
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.abertschi.adfree">
xmlns:tools="http://schemas.android.com/tools"
package="ch.abertschi.adfree">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Expand All @@ -13,7 +14,21 @@
android:label="@string/app_name"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<activity
android:name="ch.abertschi.adfree.crashhandler.SendCrashReportActivity"
android:process=":crashlog"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="ch.abertschi.adfree.SEND_LOG_CRASH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".view.MainActivity"
android:screenOrientation="portrait">
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/ch/abertschi/adfree/AdFreeApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import ch.abertschi.adfree.plugin.localmusic.LocalMusicPlugin
import ch.abertschi.adfree.plugin.mute.MutePlugin
import ch.abertschi.adfree.util.NotificationUtils
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.info
import org.jetbrains.anko.warn
import ch.abertschi.adfree.crashhandler.CrashExceptionHandler


/**
Expand All @@ -44,11 +43,18 @@ class AdFreeApplication : Application(), AnkoLogger {

override fun onCreate() {
super.onCreate()
Thread.setDefaultUncaughtExceptionHandler(CrashExceptionHandler(this))

prefs = PreferencesFactory(applicationContext)
adDetectors = listOf<AdDetectable>(NotificationActionDetector()

adDetectors = listOf<AdDetectable>(
NotificationActionDetector()
, SpotifyTitleDetector(TrackRepository(this, prefs))
, NotificationBundleAndroidTextDetector(),
ScDetector())
, NotificationBundleAndroidTextDetector()
, ScDetector()
, MiuiNotificationDetector()
// , SpotifyNotificationTracer(getExternalFilesDir(null)) // TODO: for debug
)

audioManager = AudioController(applicationContext, prefs)
remoteManager = RemoteManager(prefs)
Expand All @@ -70,7 +76,5 @@ class AdFreeApplication : Application(), AnkoLogger {
pluginHandler, notificationChannel)

adDetector.addObserver(adStateController)


}
}
6 changes: 4 additions & 2 deletions app/src/main/java/ch/abertschi/adfree/AudioController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

package ch.abertschi.adfree

import android.annotation.SuppressLint
import android.content.Context
import android.media.AudioManager
import ch.abertschi.adfree.model.PreferencesFactory
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.reactivex.schedulers.Schedulers.*
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.debug
import org.jetbrains.anko.info
Expand Down Expand Up @@ -56,7 +58,7 @@ class AudioController(val context: Context, val prefs: PreferencesFactory) : Ank
val am = context.applicationContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
am.setStreamVolume(AudioManager.STREAM_VOICE_CALL, prefs.loadVoiceCallAudioVolume(), AudioManager.FLAG_SHOW_UI)
Observable.just(true).delay(8000, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.subscribeOn(io())
.observeOn(AndroidSchedulers.mainThread()).subscribe {
val volume = am.getStreamVolume(AudioManager.STREAM_VOICE_CALL)
prefs.storeVoiceCallAudioVolume(volume)
Expand All @@ -70,7 +72,7 @@ class AudioController(val context: Context, val prefs: PreferencesFactory) : Ank
var counter: Int = 0
Observable.just(1).delay(25, TimeUnit.MILLISECONDS)
.repeat(times)
.subscribeOn(Schedulers.io())
.subscribeOn(io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
info { counter }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class NotificationsListeners : NotificationListenerService(), AnkoLogger {
@Deprecated("for testing only")
private fun recordNotification(sbn: StatusBarNotification) {
val path = this.getExternalFilesDir(null)
val file = File(path, "adfree.txt")
val ids = File(path, "adfree-ids.txt")
val file = File(path, "adfree-new.txt")
val ids = File(path, "adfree-ids-new.txt")

warn { XStream().toXML(sbn) }
val stream = FileOutputStream(file, true)
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/java/ch/abertschi/adfree/ad/AdDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ class AdDetector(val detectors: List<AdDetectable>,
fetchRemote()
init = true
}

// if (isAd) {
// info { "ad-detected ###" }
//// info { XStream().toXML(payload) }
// var str = XStream().toXML(payload).trim()
// str = str.replace("\n\r", "")
// val i = str.length / 2
// System.out.println(str.substring(0, i))
// System.out.flush()
// System.out.println(str.substring(i + 1))
// System.out.flush()
// DevelopUtils().serializeAndWriteToFile(payload, "ad")
// } else {
// DevelopUtils().serializeAndWriteToFile(payload, "no_ad")
// }

val eventType = if (isAd) EventType.IS_AD else EventType.NO_AD
val event = AdEvent(eventType)
submitEvent(event)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ch.abertschi.adfree.crashhandler

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import android.os.Build.MANUFACTURER
import android.os.Build.MODEL
import android.util.Log
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.text.SimpleDateFormat
import java.util.*
import kotlin.system.exitProcess

/**
* Capture app crashes and launch Activity to report error
* @author abertschi
*/
class CrashExceptionHandler(val context: Context) : Thread.UncaughtExceptionHandler {

@SuppressLint("SimpleDateFormat")
override fun uncaughtException(t: Thread?, e: Throwable?) {
e?.printStackTrace() // not all Android versions will print the stack trace automatically

val (summary, logcat) = generateReport(e)
val filename = writeLogfile(logcat)

val i = Intent()
i.action = SendCrashReportActivity.ACTION_NAME
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
i.putExtra(SendCrashReportActivity.EXTRA_LOGFILE, filename)
i.putExtra(SendCrashReportActivity.EXTRA_SUMMARY, summary)
context.startActivity(i)

System.exit(1)
exitProcess(1)
}

private fun writeLogfile(logcat: String): String {
val time = SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(Date())
val filename = "adfree-crashlog-${time}.txt"

val file = File(context.filesDir, filename)
file.writeText(logcat)
return filename
}

@SuppressLint("SimpleDateFormat")
private fun generateReport(th: Throwable?): Pair<String, String> {
val manager = context.packageManager
var info: PackageInfo? = null
try {
info = manager.getPackageInfo(context.packageName, 0)
} catch (e2: PackageManager.NameNotFoundException) {
}

var model = MODEL
if (!model.startsWith(MANUFACTURER))
model = "$MANUFACTURER $model"

val summary = StringBuilder()
summary.append("Android version: " + Build.VERSION.SDK_INT + "\n")
summary.append("Device: $model\n")
summary.append("App version: " + (info?.versionCode ?: "(null)") + "\n")
summary.append("Time: " + SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(Date()) + "\n")
summary.append("Root cause: \n" + Log.getStackTraceString(th) + "")

val logcat = StringBuilder()
logcat.append("Logcat messages: \n" + th?.message)
logcat.append(readLogcat())
return Pair(summary.toString(), logcat.toString())
}

private fun readLogcat(): String {
val process = Runtime.getRuntime().exec("logcat -d")
val bufferedReader = BufferedReader(
InputStreamReader(process.inputStream))
val log = bufferedReader.readText()
return log
}
}
Loading

0 comments on commit 7dda93e

Please sign in to comment.