Skip to content

Commit

Permalink
bump to API30 (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
pazos authored Jun 7, 2021
1 parent a0d7b20 commit 56e4fb5
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 238 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ project.properties
*.iml

bin
libs
build
app/.*
app/build
assets/libs
assets/module
jni/luajit/build
tests/einkTest/build
tests/einkTest/src/org/koreader/test/eink/*EPDController.java
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ example: update clean build-luajit
find app/build/outputs/apk/ -type f -name '*.apk' -exec mv -v {} bin/ \;

lint:
./gradlew $(LINT_TASK)Release
./gradlew -PndkCustomPath=$(ANDROID_NDK_FULLPATH) $(LINT_TASK)Release

clean:
@echo "Cleaning binaries, assets and LuaJIT build"
Expand Down
17 changes: 15 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ android {
sourceSets {
main {
assets.srcDirs = [ '../assets' ]
jniLibs.srcDirs = [ '../libs' ]
}
}

dependenciesInfo {
includeInApk = false
}

externalNativeBuild {
ndkBuild {
path file('../jni/Android.mk')
Expand Down Expand Up @@ -83,11 +88,19 @@ android {

compileOptions {
coreLibraryDesugaringEnabled true
kotlinOptions.freeCompilerArgs += ['-module-name', projectName.toLowerCase()]
}

packagingOptions {
exclude 'META-INF/*.version'
exclude '/kotlin/**.kotlin_builtins'
exclude '/kotlin/**.kotlin_metadata'
exclude '/META-INF/**.kotlin_module'
exclude '/META-INF/**.version'
}

lintOptions {
xmlReport false
htmlReport false
disable 'QueryAllPackagesPermission'
}

applicationVariants.all { variant ->
Expand Down
2 changes: 1 addition & 1 deletion app/src/debug/res/mipmap-anydpi-v26/icon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/icon_red"/>
<background android:drawable="@color/icon_debug"/>
<foreground android:drawable="@mipmap/icon_foreground"/>
</adaptive-icon>
16 changes: 10 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
<!-- common android permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" android:maxSdkVersion="29" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />

<!-- These are used on API30+. Uncomment them when bumping targetSdk
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<!-- These are used on API30+ -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
-->

<application
android:name=".MainApp"
Expand All @@ -31,7 +33,8 @@
android:fullBackupContent="false"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true">
android:supportsRtl="true"
android:extractNativeLibs="true" >
<meta-data android:name="android.max_aspect" android:value="3.1" />
<activity
android:name=".MainActivity"
Expand Down Expand Up @@ -100,6 +103,7 @@
</activity>
<activity
android:label="EPDTest"
android:theme="@style/NoTitle"
android:name=".EPDTestActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/org/koreader/launcher/Assets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.Gravity
import android.view.ViewGroup
import android.widget.ProgressBar
import androidx.core.content.ContextCompat
import org.koreader.launcher.extensions.symlink
import java.io.*

class Assets {
Expand Down Expand Up @@ -80,6 +81,25 @@ class Assets {
return false
}
}
(assetName == "module/map.txt") -> {
/* Symlink binaries stored as shared libraries */
val nativeLibsDir = activity.applicationInfo.nativeLibraryDir
activity.assets.open(assetName).bufferedReader().use { text ->
Log.v(tag, "Reading symlinks map from $assetName")
text.forEachLine { line ->
try {
val array = line.split(" ").toTypedArray()
if (array.size == 2) {
val link = "$filesDir/${array[0]}"
val file = "$nativeLibsDir/${array[1]}"
File(file).symlink(link)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}
else -> {
/* Copy all regular files in assets store */
Log.v(tag, "Extracting $assetName")
Expand Down
16 changes: 10 additions & 6 deletions app/src/main/java/org/koreader/launcher/CrashReportActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.koreader.launcher

import android.content.Intent
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import org.koreader.launcher.databinding.CrashReportBinding
Expand All @@ -13,25 +14,28 @@ class CrashReportActivity : AppCompatActivity() {
intent?.extras?.let { bundle ->
binding = CrashReportBinding.inflate(layoutInflater)
setContentView(binding.root)

val log = StringBuilder().append(bundle.get("logs").toString())
binding.logs.text = log.toString()
binding.title.text = bundle.get("title").toString()
binding.reason.text = bundle.get("reason").toString()
binding.logs.text = bundle.get("logs").toString()

if (binding.reason.text.equals("")) {
binding.reason.visibility = View.GONE
}
binding.shareReport.setOnClickListener {
val intent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, binding.logs.text.toString())
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, log.toString())
}
startActivity(Intent.createChooser(intent,
resources.getString(R.string.crash_report_share_button)))
resources.getString(R.string.common_share_rationale)))
}
} ?: noCrashReportAttachedError()
}

private fun noCrashReportAttachedError() {
Toast.makeText(this, "No crash report", Toast.LENGTH_LONG).show()
Toast.makeText(this,
resources.getString(R.string.no_crash_attached), Toast.LENGTH_LONG).show()
finish()
}
}
60 changes: 27 additions & 33 deletions app/src/main/java/org/koreader/launcher/EPDTestActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import org.koreader.launcher.device.epd.freescale.NTXEPDController
import org.koreader.launcher.device.epd.qualcomm.QualcommEPDController
import org.koreader.launcher.device.epd.rockchip.RK30xxEPDController
import org.koreader.launcher.device.epd.rockchip.RK33xxEPDController
import java.util.Locale

/* A test activity for EPD routines. It can be called from lua using the android.einkTest() function
If the device in question doesn't play nice with the main NativeActivity it can be called from
If the device in question doesn't play nice with the main Activity it can be called from
commandline using `adb shell am start -n org.koreader.launcher/.EPDTestActivity` */

class EPDTestActivity : AppCompatActivity() {
Expand Down Expand Up @@ -43,14 +42,6 @@ class EPDTestActivity : AppCompatActivity() {
binding.info.append("Platform: $it\n")
}

binding.rk30xxButton.setOnClickListener {
runEinkTest(TEST_RK30XX)
}

binding.rk33xxButton.setOnClickListener {
runEinkTest(TEST_RK33XX)
}

binding.ntxNewButton.setOnClickListener {
runEinkTest(TEST_NTX)
}
Expand All @@ -59,61 +50,64 @@ class EPDTestActivity : AppCompatActivity() {
runEinkTest(TEST_QUALCOMM)
}

binding.rk30xxButton.setOnClickListener {
runEinkTest(TEST_RK30XX)
}

binding.rk33xxButton.setOnClickListener {
runEinkTest(TEST_RK33XX)
}

binding.shareButton.setOnClickListener {
val intent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, binding.info.text.toString())
type = "text/plain"
}
startActivity(Intent.createChooser(intent,
resources.getString(R.string.epd_test_share_button)))
resources.getString(R.string.common_share_rationale)))
}
}

@Suppress("DEPRECATION")
private fun runEinkTest(test: Int) {
var success = false
binding.info.append(String.format(Locale.US, "run test #%d -> ", test))
try {
val v = window.decorView.findViewById<View>(android.R.id.content)
when (test) {
TEST_RK30XX -> {
binding.info.append("rk30xx: ")
if (RK30xxEPDController.requestEpdMode(v, "EPD_FULL", true))
success = true
}

TEST_RK33XX -> {
binding.info.append("rk33xx: ")
if (RK33xxEPDController.requestEpdMode("EPD_FULL"))
success = true
}

TEST_NTX,
TEST_QUALCOMM -> {
// get screen width and height
val display = windowManager.defaultDisplay
val size = Point()
display.getSize(size)
val width = size.x
val height = size.y

if (test == TEST_NTX) {
binding.info.append("tolino: ")
if (NTXEPDController.requestEpdMode(v, 34, 50, 0, 0, width, height))
binding.info.append("run test for tolino: ")
if (NTXEPDController.requestEpdMode(v, 34, 50, 0, 0, size.x, size.y))
success = true
} else if (test == TEST_QUALCOMM) {
binding.info.append("qualcomm: ")
if (QualcommEPDController.requestEpdMode(v, 98, 50, 0, 0, width, height))
binding.info.append("run test for qualcomm: ")
if (QualcommEPDController.requestEpdMode(v, 98, 50, 0, 0, size.x, size.y))
success = true
}
}

TEST_RK30XX -> {
binding.info.append("run test for rk30xx: ")
if (RK30xxEPDController.requestEpdMode(v, "EPD_FULL", true))
success = true
}

TEST_RK33XX -> {
binding.info.append("run test for rk33xx: ")
if (RK33xxEPDController.requestEpdMode("EPD_FULL"))
success = true
}
}
} catch (e: Exception) {
e.printStackTrace()
} finally {
if (success)
binding.info.append("pass\n")
binding.info.append("ok\n")
else
binding.info.append("fail\n")
}
Expand Down
25 changes: 13 additions & 12 deletions app/src/main/java/org/koreader/launcher/Timeout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import android.view.WindowManager
import java.util.*

class Timeout {
private val tag = this::class.java.simpleName

private var appTimeout: Int = 0
private var systemTimeout: Int = 0
private var alwaysOn: Boolean = false
private var customTimeout: Boolean = false

companion object {
private const val TAG = "TimeoutHelper"
private const val SCREEN_ON_ENABLED = -1
private const val SCREEN_ON_DISABLED = 0
private const val TIMEOUT_MIN = 2 * 60 * 1000
Expand All @@ -33,7 +34,7 @@ class Timeout {
Settings.System.getInt(activity.applicationContext.contentResolver,
Settings.System.SCREEN_OFF_TIMEOUT)
} catch (e: Exception) {
Log.w(TAG, e.toString())
Log.w(tag, e.toString())
0
}
}
Expand All @@ -45,7 +46,7 @@ class Timeout {
customTimeout = true
appTimeout = safeTimeout(ms)
val mins = toMin(appTimeout)
Log.v(TAG, "applying activity custom timeout: $mins minutes")
Log.v(tag, "applying activity custom timeout: $mins minutes")
setSystemScreenOffTimeout(activity, appTimeout)
setScreenOn(activity, false)
}
Expand Down Expand Up @@ -79,30 +80,30 @@ class Timeout {
val logMsg = if (resumed) "onResume" else "onPause"
if (resumed) {
systemTimeout = getSystemScreenOffTimeout(activity)
Log.v(TAG, String.format(Locale.US,
Log.v(tag, String.format(Locale.US,
"%s: updating system timeout: %s", logMsg, toMin(systemTimeout)))
}
if (resumed && customTimeout) {
if (appTimeout > 0) {
Log.v(TAG, String.format(Locale.US,
Log.v(tag, String.format(Locale.US,
"%s: applying custom timeout: %s", logMsg, toMin(appTimeout)))

val safe = safeTimeout(appTimeout)
setSystemScreenOffTimeout(activity, safe)
} else {
Log.w(TAG, "$logMsg: custom timeout is 0, ignoring")
Log.w(tag, "$logMsg: custom timeout is 0, ignoring")
}
} else if (!resumed && customTimeout) {
if (systemTimeout > 0) {
Log.v(TAG, String.format(Locale.US,
Log.v(tag, String.format(Locale.US,
"applying system timeout: %s", toMin(systemTimeout)))

setSystemScreenOffTimeout(activity, systemTimeout)
} else {
Log.w(TAG, "$logMsg: system timeout is 0, ignoring")
Log.w(tag, "$logMsg: system timeout is 0, ignoring")
}
} else {
Log.v(TAG, logMsg)
Log.v(tag, logMsg)
}
}

Expand All @@ -116,12 +117,12 @@ class Timeout {

private fun setScreenOn(activity: Activity, enable: Boolean) {
if (enable != alwaysOn) {
Log.v(TAG, "screen on: switching to $enable")
Log.v(tag, "screen on: switching to $enable")
alwaysOn = enable
val flag = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
val action = if (enable) "add" else "clear"
activity.runOnUiThread {
Log.v(TAG, "$action FLAG_KEEP_SCREEN_ON")
Log.v(tag, "$action FLAG_KEEP_SCREEN_ON")
if (enable) activity.window.addFlags(flag) else activity.window.clearFlags(flag)
}
}
Expand All @@ -133,7 +134,7 @@ class Timeout {
Settings.System.putInt(activity.applicationContext.contentResolver,
Settings.System.SCREEN_OFF_TIMEOUT, timeout)
} catch (e: Exception) {
Log.w(TAG, "$e")
Log.w(tag, "$e")
}
}

Expand Down
Loading

0 comments on commit 56e4fb5

Please sign in to comment.